Search in sources :

Example 6 with PaymentAttemptModelDao

use of org.killbill.billing.payment.dao.PaymentAttemptModelDao in project killbill by killbill.

the class TestRetryablePayment method testInitToSuccessWithResSuccess.

@Test(groups = "fast")
public void testInitToSuccessWithResSuccess() throws PaymentApiException {
    mockRetryProviderPlugin.setAborted(false).setNextRetryDate(null);
    mockRetryAuthorizeOperationCallback.setResult(OperationResult.SUCCESS).setException(null);
    runner.setOperationCallback(mockRetryAuthorizeOperationCallback).setContext(paymentStateContext);
    runner.run(true, TransactionType.AUTHORIZE, ControlOperation.AUTHORIZE, account, paymentMethodId, null, paymentExternalKey, paymentTransactionExternalKey, amount, currency, null, emptyProperties, null, callContext, internalCallContext);
    final PaymentAttemptModelDao pa = paymentDao.getPaymentAttemptByTransactionExternalKey(paymentTransactionExternalKey, internalCallContext).get(0);
    assertEquals(pa.getTransactionExternalKey(), paymentTransactionExternalKey);
    assertEquals(pa.getStateName(), "SUCCESS");
    assertEquals(pa.getTransactionType(), TransactionType.AUTHORIZE);
}
Also used : PaymentAttemptModelDao(org.killbill.billing.payment.dao.PaymentAttemptModelDao) Test(org.testng.annotations.Test)

Example 7 with PaymentAttemptModelDao

use of org.killbill.billing.payment.dao.PaymentAttemptModelDao in project killbill by killbill.

the class TestRetryablePayment method testInitToSuccessWithRuntimeExceptionAndRetries.

@Test(groups = "fast")
public void testInitToSuccessWithRuntimeExceptionAndRetries() {
    mockRetryProviderPlugin.setAborted(false).setNextRetryDate(new DateTime(clock.getUTCNow().plusDays(1)));
    mockRetryAuthorizeOperationCallback.setResult(null).setException(new RuntimeException());
    runner.setOperationCallback(mockRetryAuthorizeOperationCallback).setContext(paymentStateContext);
    try {
        runner.run(true, TransactionType.AUTHORIZE, ControlOperation.AUTHORIZE, account, paymentMethodId, null, paymentExternalKey, paymentTransactionExternalKey, amount, currency, null, emptyProperties, null, callContext, internalCallContext);
        fail("Expected Exception...");
    } catch (final PaymentApiException e) {
        final PaymentAttemptModelDao pa = paymentDao.getPaymentAttemptByTransactionExternalKey(paymentTransactionExternalKey, internalCallContext).get(0);
        assertEquals(pa.getTransactionExternalKey(), paymentTransactionExternalKey);
        assertEquals(pa.getStateName(), "RETRIED");
        assertEquals(pa.getTransactionType(), TransactionType.AUTHORIZE);
    }
}
Also used : PaymentAttemptModelDao(org.killbill.billing.payment.dao.PaymentAttemptModelDao) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 8 with PaymentAttemptModelDao

use of org.killbill.billing.payment.dao.PaymentAttemptModelDao in project killbill by killbill.

the class TestRetryablePayment method testRetryLogicFromRetriedStateWithPaymentApiException.

@Test(groups = "fast")
public void testRetryLogicFromRetriedStateWithPaymentApiException() {
    mockRetryProviderPlugin.setAborted(false).setNextRetryDate(null);
    mockRetryAuthorizeOperationCallback.setResult(null).setException(new PaymentApiException(ErrorCode.__UNKNOWN_ERROR_CODE, "foo"));
    runner.setOperationCallback(mockRetryAuthorizeOperationCallback).setContext(paymentStateContext);
    final State state = retrySMHelper.getRetriedState();
    final UUID transactionId = UUID.randomUUID();
    final UUID paymentId = UUID.randomUUID();
    final PaymentAttemptModelDao attempt = new PaymentAttemptModelDao(account.getId(), paymentMethodId, utcNow, utcNow, paymentExternalKey, transactionId, paymentTransactionExternalKey, TransactionType.AUTHORIZE, state.getName(), amount, currency, null, EMPTY_PROPERTIES);
    paymentDao.insertPaymentAttemptWithProperties(attempt, internalCallContext);
    paymentDao.insertPaymentWithFirstTransaction(new PaymentModelDao(paymentId, utcNow, utcNow, account.getId(), paymentMethodId, -1, paymentExternalKey), new PaymentTransactionModelDao(transactionId, attempt.getId(), paymentTransactionExternalKey, utcNow, utcNow, paymentId, TransactionType.AUTHORIZE, utcNow, TransactionStatus.PAYMENT_FAILURE, amount, currency, "bla", "foo"), internalCallContext);
    processor.retryPaymentTransaction(attempt.getId(), ImmutableList.<String>of(MockPaymentControlProviderPlugin.PLUGIN_NAME), internalCallContext);
    final List<PaymentAttemptModelDao> pas = paymentDao.getPaymentAttemptByTransactionExternalKey(paymentTransactionExternalKey, internalCallContext);
    assertEquals(pas.size(), 2);
    final PaymentAttemptModelDao failedAttempt = Iterables.tryFind(pas, new Predicate<PaymentAttemptModelDao>() {

        @Override
        public boolean apply(final PaymentAttemptModelDao input) {
            return input.getTransactionType() == TransactionType.AUTHORIZE && input.getStateName().equals("ABORTED");
        }
    }).orNull();
    assertNotNull(failedAttempt);
}
Also used : PaymentAttemptModelDao(org.killbill.billing.payment.dao.PaymentAttemptModelDao) PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) PaymentModelDao(org.killbill.billing.payment.dao.PaymentModelDao) State(org.killbill.automaton.State) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) UUID(java.util.UUID) Predicate(com.google.common.base.Predicate) Test(org.testng.annotations.Test)

Example 9 with PaymentAttemptModelDao

use of org.killbill.billing.payment.dao.PaymentAttemptModelDao in project killbill by killbill.

the class TestRetryablePayment method testRetryLogicFromRetriedStateWithLockFailure.

@Test(groups = "fast")
public void testRetryLogicFromRetriedStateWithLockFailure() throws LockFailedException {
    GlobalLock lock = null;
    try {
        // Grab lock so that operation later will fail...
        lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), account.getId().toString(), 1);
        mockRetryProviderPlugin.setAborted(false).setNextRetryDate(null);
        mockRetryAuthorizeOperationCallback.setResult(OperationResult.SUCCESS).setException(null);
        runner.setOperationCallback(mockRetryAuthorizeOperationCallback).setContext(paymentStateContext);
        final State state = retrySMHelper.getRetriedState();
        final UUID transactionId = UUID.randomUUID();
        final UUID paymentId = UUID.randomUUID();
        final PaymentAttemptModelDao attempt = new PaymentAttemptModelDao(account.getId(), paymentMethodId, utcNow, utcNow, paymentExternalKey, transactionId, paymentTransactionExternalKey, TransactionType.AUTHORIZE, state.getName(), amount, currency, null, EMPTY_PROPERTIES);
        paymentDao.insertPaymentAttemptWithProperties(attempt, internalCallContext);
        paymentDao.insertPaymentWithFirstTransaction(new PaymentModelDao(paymentId, utcNow, utcNow, account.getId(), paymentMethodId, -1, paymentExternalKey), new PaymentTransactionModelDao(transactionId, attempt.getId(), paymentTransactionExternalKey, utcNow, utcNow, paymentId, TransactionType.AUTHORIZE, utcNow, TransactionStatus.PAYMENT_FAILURE, amount, currency, "bla", "foo"), internalCallContext);
        processor.retryPaymentTransaction(attempt.getId(), ImmutableList.<String>of(MockPaymentControlProviderPlugin.PLUGIN_NAME), internalCallContext);
        final List<PaymentAttemptModelDao> pas = paymentDao.getPaymentAttemptByTransactionExternalKey(paymentTransactionExternalKey, internalCallContext);
        assertEquals(pas.size(), 2);
        final PaymentAttemptModelDao failedAttempt = Iterables.tryFind(pas, new Predicate<PaymentAttemptModelDao>() {

            @Override
            public boolean apply(final PaymentAttemptModelDao input) {
                return input.getTransactionType() == TransactionType.AUTHORIZE && input.getStateName().equals("ABORTED");
            }
        }).orNull();
        assertNotNull(failedAttempt);
    } finally {
        if (lock != null) {
            lock.release();
        }
    }
}
Also used : GlobalLock(org.killbill.commons.locker.GlobalLock) PaymentAttemptModelDao(org.killbill.billing.payment.dao.PaymentAttemptModelDao) PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) PaymentModelDao(org.killbill.billing.payment.dao.PaymentModelDao) State(org.killbill.automaton.State) UUID(java.util.UUID) Predicate(com.google.common.base.Predicate) Test(org.testng.annotations.Test)

Example 10 with PaymentAttemptModelDao

use of org.killbill.billing.payment.dao.PaymentAttemptModelDao in project killbill by killbill.

the class TestRetryablePayment method testRetryToSuccessWithPaymentApiExceptionAndRetry.

@Test(groups = "fast")
public void testRetryToSuccessWithPaymentApiExceptionAndRetry() {
    mockRetryProviderPlugin.setAborted(false).setNextRetryDate(new DateTime().plusDays(1));
    mockRetryAuthorizeOperationCallback.setResult(null).setException(new PaymentApiException(ErrorCode.__UNKNOWN_ERROR_CODE, "bla"));
    runner.setOperationCallback(mockRetryAuthorizeOperationCallback).setContext(paymentStateContext);
    final State state = retrySMHelper.getRetriedState();
    final UUID transactionId = UUID.randomUUID();
    paymentDao.insertPaymentAttemptWithProperties(new PaymentAttemptModelDao(account.getId(), paymentMethodId, utcNow, utcNow, paymentExternalKey, transactionId, paymentTransactionExternalKey, TransactionType.AUTHORIZE, state.getName(), amount, currency, null, EMPTY_PROPERTIES), internalCallContext);
    try {
        runner.run(state, false, TransactionType.AUTHORIZE, ControlOperation.AUTHORIZE, account, paymentMethodId, null, paymentExternalKey, paymentTransactionExternalKey, amount, currency, null, emptyProperties, null, callContext, internalCallContext);
        fail("Expecting paymentApiException...");
    } catch (final PaymentApiException e) {
        final PaymentAttemptModelDao pa = paymentDao.getPaymentAttemptByTransactionExternalKey(paymentTransactionExternalKey, internalCallContext).get(0);
        assertEquals(pa.getTransactionExternalKey(), paymentTransactionExternalKey);
        assertEquals(pa.getStateName(), "RETRIED");
        assertEquals(pa.getTransactionType(), TransactionType.AUTHORIZE);
    }
}
Also used : PaymentAttemptModelDao(org.killbill.billing.payment.dao.PaymentAttemptModelDao) State(org.killbill.automaton.State) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

PaymentAttemptModelDao (org.killbill.billing.payment.dao.PaymentAttemptModelDao)33 Test (org.testng.annotations.Test)24 UUID (java.util.UUID)16 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)15 PaymentTransactionModelDao (org.killbill.billing.payment.dao.PaymentTransactionModelDao)12 BigDecimal (java.math.BigDecimal)10 LocalDate (org.joda.time.LocalDate)10 Invoice (org.killbill.billing.invoice.api.Invoice)10 Account (org.killbill.billing.account.api.Account)8 Payment (org.killbill.billing.payment.api.Payment)8 DateTime (org.joda.time.DateTime)7 State (org.killbill.automaton.State)7 Predicate (com.google.common.base.Predicate)6 ArrayList (java.util.ArrayList)6 PaymentModelDao (org.killbill.billing.payment.dao.PaymentModelDao)6 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 AccountData (org.killbill.billing.account.api.AccountData)3 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)3 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)3