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);
}
}
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);
}
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());
}
Aggregations