use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestChargeback method testMultipleChargeback.
@Test(groups = "slow", description = "Can create multiple chargebacks")
public void testMultipleChargeback() throws Exception {
final InvoicePayment payment = createAccountWithInvoiceAndPayment();
// We get a 249.95 payment so we do 4 chargeback and then the fifth should fail
final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
input.setPaymentId(payment.getPaymentId());
input.setAmount(new BigDecimal("50.00"));
int count = 4;
while (count-- > 0) {
assertNotNull(invoicePaymentApi.createChargeback(payment.getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions));
}
// Last attempt should fail because this is more than the Payment
final InvoicePayment foo = invoicePaymentApi.createChargeback(payment.getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions);
final InvoicePayments payments = accountApi.getInvoicePayments(payment.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final List<PaymentTransaction> transactions = getInvoicePaymentTransactions(payments, TransactionType.CHARGEBACK);
Assert.assertEquals(transactions.size(), 5);
int found = 0;
for (final PaymentTransaction transaction : transactions) {
if (transaction.getStatus().equals(TransactionStatus.SUCCESS)) {
assertTrue(transaction.getAmount().compareTo(input.getAmount()) == 0);
assertEquals(transaction.getPaymentId(), input.getPaymentId());
found++;
} else {
assertEquals(transaction.getStatus(), TransactionStatus.PAYMENT_FAILURE);
found++;
}
}
assertEquals(found, 5);
}
use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestInvoiceVoid method refundPayment.
private void refundPayment(final InvoicePayment payment) throws Exception {
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(payment.getPaymentId());
refund.setAmount(payment.getPurchasedAmount());
callbackServlet.pushExpectedEvents(ExtBusEventType.PAYMENT_SUCCESS, ExtBusEventType.INVOICE_PAYMENT_SUCCESS);
invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), refund, payment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
callbackServlet.assertListenerStatus();
final InvoicePayments allPayments = accountApi.getInvoicePayments(payment.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(allPayments.size(), 1);
final List<PaymentTransaction> objRefundFromJson = getInvoicePaymentTransactions(allPayments, TransactionType.REFUND);
assertEquals(objRefundFromJson.size(), 1);
}
use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestPayment method testWithTimeoutPayment.
@Test(groups = "slow")
public void testWithTimeoutPayment() throws Exception {
final Account account = createAccountWithDefaultPaymentMethod();
mockPaymentProviderPlugin.makePluginWaitSomeMilliseconds(10000);
final PaymentTransaction authTransaction = new PaymentTransaction();
authTransaction.setAmount(BigDecimal.ONE);
authTransaction.setCurrency(account.getCurrency());
authTransaction.setTransactionType(TransactionType.AUTHORIZE);
try {
accountApi.processPayment(account.getAccountId(), authTransaction, account.getPaymentMethodId(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
fail();
} catch (KillBillClientException e) {
assertEquals(504, e.getResponse().getStatusCode());
}
}
use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestPayment method testCreateRetrievePayment.
private UUID testCreateRetrievePayment(final Account account, @Nullable final UUID paymentMethodId, final String paymentExternalKey, final int paymentNb) throws Exception {
// Authorization
final String authTransactionExternalKey = UUID.randomUUID().toString();
final Payment authPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, TransactionType.AUTHORIZE, TransactionStatus.SUCCESS, BigDecimal.TEN, BigDecimal.TEN, ImmutableMap.<String, String>of(), paymentNb);
// Capture 1
final String capture1TransactionExternalKey = UUID.randomUUID().toString();
final PaymentTransaction captureTransaction = new PaymentTransaction();
captureTransaction.setPaymentId(authPayment.getPaymentId());
captureTransaction.setAmount(BigDecimal.ONE);
captureTransaction.setCurrency(account.getCurrency());
captureTransaction.setPaymentExternalKey(paymentExternalKey);
captureTransaction.setTransactionExternalKey(capture1TransactionExternalKey);
// captureAuthorization is using paymentId
final Payment capturedPayment1 = paymentApi.captureAuthorization(authPayment.getPaymentId(), captureTransaction, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
verifyPayment(account, paymentMethodId, capturedPayment1, paymentExternalKey, authTransactionExternalKey, TransactionType.AUTHORIZE, TransactionStatus.SUCCESS, BigDecimal.TEN, BigDecimal.TEN, BigDecimal.ONE, BigDecimal.ZERO, 2, paymentNb);
verifyPaymentTransaction(account, authPayment.getPaymentId(), paymentExternalKey, capturedPayment1.getTransactions().get(1), capture1TransactionExternalKey, captureTransaction.getAmount(), TransactionType.CAPTURE, TransactionStatus.SUCCESS);
// Capture 2
final String capture2TransactionExternalKey = UUID.randomUUID().toString();
captureTransaction.setTransactionExternalKey(capture2TransactionExternalKey);
// captureAuthorization is using externalKey
captureTransaction.setPaymentId(null);
final Payment capturedPayment2 = paymentApi.captureAuthorizationByExternalKey(captureTransaction, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
verifyPayment(account, paymentMethodId, capturedPayment2, paymentExternalKey, authTransactionExternalKey, TransactionType.AUTHORIZE, TransactionStatus.SUCCESS, BigDecimal.TEN, BigDecimal.TEN, new BigDecimal("2"), BigDecimal.ZERO, 3, paymentNb);
verifyPaymentTransaction(account, authPayment.getPaymentId(), paymentExternalKey, capturedPayment2.getTransactions().get(2), capture2TransactionExternalKey, captureTransaction.getAmount(), TransactionType.CAPTURE, TransactionStatus.SUCCESS);
// Refund
final String refundTransactionExternalKey = UUID.randomUUID().toString();
final PaymentTransaction refundTransaction = new PaymentTransaction();
refundTransaction.setPaymentId(authPayment.getPaymentId());
refundTransaction.setAmount(new BigDecimal("2"));
refundTransaction.setCurrency(account.getCurrency());
refundTransaction.setPaymentExternalKey(paymentExternalKey);
refundTransaction.setTransactionExternalKey(refundTransactionExternalKey);
final Payment refundPayment = paymentApi.refundPayment(authPayment.getPaymentId(), refundTransaction, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
verifyPayment(account, paymentMethodId, refundPayment, paymentExternalKey, authTransactionExternalKey, TransactionType.AUTHORIZE, TransactionStatus.SUCCESS, BigDecimal.TEN, BigDecimal.TEN, new BigDecimal("2"), new BigDecimal("2"), 4, paymentNb);
verifyPaymentTransaction(account, authPayment.getPaymentId(), paymentExternalKey, refundPayment.getTransactions().get(3), refundTransactionExternalKey, refundTransaction.getAmount(), TransactionType.REFUND, TransactionStatus.SUCCESS);
return authPayment.getPaymentId();
}
use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestPayment method testWithCanceledPayment.
@Test(groups = "slow")
public void testWithCanceledPayment() throws Exception {
final Account account = createAccountWithDefaultPaymentMethod();
mockPaymentProviderPlugin.makeNextPaymentFailWithCancellation();
final PaymentTransaction authTransaction = new PaymentTransaction();
authTransaction.setAmount(BigDecimal.ONE);
authTransaction.setCurrency(account.getCurrency());
authTransaction.setTransactionType(TransactionType.AUTHORIZE);
final Payment payment = accountApi.processPayment(account.getAccountId(), authTransaction, account.getPaymentMethodId(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
final PaymentTransaction paymentTransaction = payment.getTransactions().get(0);
assertEquals(paymentTransaction.getStatus(), TransactionStatus.PLUGIN_FAILURE);
}
Aggregations