Search in sources :

Example 6 with DefaultNoOpPaymentInfoPlugin

use of org.killbill.billing.payment.provider.DefaultNoOpPaymentInfoPlugin in project killbill by killbill.

the class PaymentOperation method convertToUnknownTransactionStatusAndErroredPaymentState.

// 
// In case of exceptions, timeouts, we don't really know what happened:
// - Return an OperationResult.EXCEPTION to transition Payment State to Errored (see PaymentTransactionInfoPluginConverter#toOperationResult)
// - Construct a PaymentTransactionInfoPlugin whose PaymentPluginStatus = UNDEFINED to end up with a paymentTransactionStatus = UNKNOWN and have a chance to
// be fixed by Janitor.
// 
private OperationException convertToUnknownTransactionStatusAndErroredPaymentState(final Exception e) {
    final PaymentTransactionInfoPlugin paymentInfoPlugin = new DefaultNoOpPaymentInfoPlugin(paymentStateContext.getPaymentId(), paymentStateContext.getTransactionId(), paymentStateContext.getTransactionType(), paymentStateContext.getAmount(), paymentStateContext.getCurrency(), paymentStateContext.getCallContext().getCreatedDate(), paymentStateContext.getCallContext().getCreatedDate(), PaymentPluginStatus.UNDEFINED, null, null);
    paymentStateContext.setPaymentTransactionInfoPlugin(paymentInfoPlugin);
    if (e.getCause() instanceof OperationException) {
        return (OperationException) e.getCause();
    }
    if (e instanceof OperationException) {
        return (OperationException) e;
    }
    return new OperationException(e, OperationResult.EXCEPTION);
}
Also used : DefaultNoOpPaymentInfoPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentInfoPlugin) PaymentTransactionInfoPlugin(org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin) OperationException(org.killbill.automaton.OperationException)

Example 7 with DefaultNoOpPaymentInfoPlugin

use of org.killbill.billing.payment.provider.DefaultNoOpPaymentInfoPlugin in project killbill by killbill.

the class TestIncompletePaymentTransactionTaskWithDB method testUpdateWithinLock.

@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/809")
public void testUpdateWithinLock() throws PaymentApiException {
    final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, BigDecimal.TEN, Currency.EUR, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, PaymentPluginStatus.UNDEFINED.toString(), false)), callContext);
    final PaymentModelDao paymentModel = paymentDao.getPayment(payment.getId(), internalCallContext);
    final UUID transactionId = payment.getTransactions().get(0).getId();
    final PaymentTransactionModelDao transactionModel = paymentDao.getPaymentTransaction(transactionId, internalCallContext);
    Assert.assertEquals(paymentModel.getStateName(), "AUTH_ERRORED");
    Assert.assertEquals(transactionModel.getTransactionStatus().toString(), "UNKNOWN");
    paymentDao.updatePaymentAndTransactionOnCompletion(account.getId(), null, payment.getId(), TransactionType.AUTHORIZE, "AUTH_SUCCESS", "AUTH_SUCCESS", transactionId, TransactionStatus.SUCCESS, BigDecimal.TEN, Currency.EUR, "200", "Ok", true, internalCallContext);
    paymentApi.createCapture(account, payment.getId(), BigDecimal.TEN, Currency.EUR, null, UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, PaymentPluginStatus.PROCESSED.toString(), false)), callContext);
    final PaymentModelDao paymentAfterCapture = paymentDao.getPayment(payment.getId(), internalCallContext);
    Assert.assertEquals(paymentAfterCapture.getStateName(), "CAPTURE_SUCCESS");
    PaymentTransactionInfoPlugin paymentTransactionInfoPlugin = new DefaultNoOpPaymentInfoPlugin(payment.getId(), transactionId, TransactionType.AUTHORIZE, BigDecimal.TEN, Currency.EUR, transactionModel.getEffectiveDate(), transactionModel.getCreatedDate(), PaymentPluginStatus.PROCESSED, "200", "OK");
    incompletePaymentTransactionTask.updatePaymentAndTransactionIfNeeded(paymentModel.getAccountId(), transactionModel.getId(), payment.getTransactions().get(0).getTransactionStatus(), paymentTransactionInfoPlugin, true, internalCallContext);
    final PaymentModelDao paymentAfterJanitor = paymentDao.getPayment(payment.getId(), internalCallContext);
    Assert.assertEquals(paymentAfterJanitor.getStateName(), "CAPTURE_SUCCESS");
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Payment(org.killbill.billing.payment.api.Payment) DefaultNoOpPaymentInfoPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentInfoPlugin) PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) PaymentModelDao(org.killbill.billing.payment.dao.PaymentModelDao) PaymentTransactionInfoPlugin(org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

PaymentTransactionInfoPlugin (org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin)7 DefaultNoOpPaymentInfoPlugin (org.killbill.billing.payment.provider.DefaultNoOpPaymentInfoPlugin)7 PaymentModelDao (org.killbill.billing.payment.dao.PaymentModelDao)4 PaymentTransactionModelDao (org.killbill.billing.payment.dao.PaymentTransactionModelDao)3 Test (org.testng.annotations.Test)3 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)2 Payment (org.killbill.billing.payment.api.Payment)2 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)2 PluginProperty (org.killbill.billing.payment.api.PluginProperty)2 PaymentPluginApi (org.killbill.billing.payment.plugin.api.PaymentPluginApi)2 TenantContext (org.killbill.billing.util.callcontext.TenantContext)2 LockFailedException (org.killbill.commons.locker.LockFailedException)2 Predicate (com.google.common.base.Predicate)1 Supplier (com.google.common.base.Supplier)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 UUID (java.util.UUID)1 OperationException (org.killbill.automaton.OperationException)1