Search in sources :

Example 31 with PaymentAttemptModelDao

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

the class TestRetryablePayment method testInitToSuccessWithPaymentExceptionNoRetries.

@Test(groups = "fast")
public void testInitToSuccessWithPaymentExceptionNoRetries() {
    mockRetryProviderPlugin.setAborted(false).setNextRetryDate(null);
    mockRetryAuthorizeOperationCallback.setResult(null).setException(new PaymentApiException(ErrorCode.__UNKNOWN_ERROR_CODE, "bla bla"));
    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 PaymentApiException...");
    } catch (final PaymentApiException e) {
        final PaymentAttemptModelDao pa = paymentDao.getPaymentAttemptByTransactionExternalKey(paymentTransactionExternalKey, internalCallContext).get(0);
        assertEquals(pa.getTransactionExternalKey(), paymentTransactionExternalKey);
        assertEquals(pa.getStateName(), "ABORTED");
        assertEquals(pa.getTransactionType(), TransactionType.AUTHORIZE);
    }
}
Also used : PaymentAttemptModelDao(org.killbill.billing.payment.dao.PaymentAttemptModelDao) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) Test(org.testng.annotations.Test)

Example 32 with PaymentAttemptModelDao

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

the class TestPaymentApi method testCreateSuccessPurchaseWithPaymentControl.

@Test(groups = "slow")
public void testCreateSuccessPurchaseWithPaymentControl() throws PaymentApiException, InvoiceApiException, EventBusException {
    final BigDecimal requestedAmount = BigDecimal.TEN;
    final UUID subscriptionId = UUID.randomUUID();
    final UUID bundleId = UUID.randomUUID();
    final LocalDate now = clock.getUTCToday();
    final Invoice invoice = testHelper.createTestInvoice(account, now, Currency.USD);
    final String paymentExternalKey = invoice.getId().toString();
    final String transactionExternalKey = "brrrrrr";
    invoice.addInvoiceItem(new MockRecurringInvoiceItem(invoice.getId(), account.getId(), subscriptionId, bundleId, "test plan", "test phase", null, now, now.plusMonths(1), requestedAmount, new BigDecimal("1.0"), Currency.USD));
    invoicePaymentApi.createPurchaseForInvoicePayment(account, invoice.getId(), account.getPaymentMethodId(), null, null, Currency.USD, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), /*
                                                           * We explicitly don't pass InvoicePaymentControlPluginApi.PLUGIN_NAME
                                                             to verify it it automatically added
                                                          */
    CONTROL_PLUGIN_OPTIONS, callContext);
    final Payment payment = paymentApi.getPaymentByExternalKey(paymentExternalKey, false, false, ImmutableList.<PluginProperty>of(), callContext);
    assertEquals(payment.getExternalKey(), paymentExternalKey);
    assertEquals(payment.getPaymentMethodId(), account.getPaymentMethodId());
    assertEquals(payment.getAccountId(), account.getId());
    assertEquals(payment.getAuthAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(payment.getCapturedAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(payment.getPurchasedAmount().compareTo(requestedAmount), 0);
    assertEquals(payment.getRefundedAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(payment.getCurrency(), Currency.USD);
    assertEquals(payment.getTransactions().size(), 1);
    assertEquals(payment.getTransactions().get(0).getExternalKey(), transactionExternalKey);
    assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId());
    assertEquals(payment.getTransactions().get(0).getAmount().compareTo(requestedAmount), 0);
    assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.USD);
    assertEquals(payment.getTransactions().get(0).getProcessedAmount().compareTo(requestedAmount), 0);
    assertEquals(payment.getTransactions().get(0).getProcessedCurrency(), Currency.USD);
    assertEquals(payment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS);
    assertEquals(payment.getTransactions().get(0).getTransactionType(), TransactionType.PURCHASE);
    assertNotNull(payment.getTransactions().get(0).getGatewayErrorMsg());
    assertNotNull(payment.getTransactions().get(0).getGatewayErrorCode());
    // Not stricly an API test but interesting to verify that we indeed went through the attempt logic
    final List<PaymentAttemptModelDao> attempts = paymentDao.getPaymentAttempts(payment.getExternalKey(), internalCallContext);
    assertEquals(attempts.size(), 1);
}
Also used : PaymentAttemptModelDao(org.killbill.billing.payment.dao.PaymentAttemptModelDao) Invoice(org.killbill.billing.invoice.api.Invoice) MockRecurringInvoiceItem(org.killbill.billing.payment.MockRecurringInvoiceItem) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 33 with PaymentAttemptModelDao

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

the class TestIncompletePaymentAttemptTaskWithDB method testHandleRuntimeExceptions.

@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/757")
public void testHandleRuntimeExceptions() throws PaymentApiException {
    final List<PaymentAttemptModelDao> paymentAttemptModelDaos = ImmutableList.<PaymentAttemptModelDao>of(new PaymentAttemptModelDao(), new PaymentAttemptModelDao());
    final Iterator<PaymentAttemptModelDao> paymentAttemptModelDaoIterator = paymentAttemptModelDaos.iterator();
    final Iterable<PaymentAttemptModelDao> itemsForIteration = new Iterable<PaymentAttemptModelDao>() {

        @Override
        public Iterator<PaymentAttemptModelDao> iterator() {
            return paymentAttemptModelDaoIterator;
        }
    };
    Assert.assertTrue(paymentAttemptModelDaoIterator.hasNext());
    final Runnable incompletePaymentAttemptTaskWithException = new IncompletePaymentAttemptTaskWithException(itemsForIteration, internalCallContextFactory, paymentConfig, paymentDao, clock, paymentControlStateMachineHelper, accountApi, pluginControlPaymentAutomatonRunner, incompletePaymentTransactionTask);
    incompletePaymentAttemptTaskWithException.run();
    // Make sure we cycled through all entries
    Assert.assertFalse(paymentAttemptModelDaoIterator.hasNext());
}
Also used : PaymentAttemptModelDao(org.killbill.billing.payment.dao.PaymentAttemptModelDao) 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