use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestInvoicePayment method verifyRefund.
private void verifyRefund(final InvoicePayment paymentJson, final Payment paymentAfterRefund, final BigDecimal refundAmount) throws KillBillClientException {
final List<PaymentTransaction> transactions = getPaymentTransactions(ImmutableList.of(paymentAfterRefund), TransactionType.REFUND);
Assert.assertEquals(transactions.size(), 1);
final PaymentTransaction refund = transactions.get(0);
Assert.assertEquals(refund.getPaymentId(), paymentJson.getPaymentId());
Assert.assertEquals(refund.getAmount().setScale(2, RoundingMode.HALF_UP), refundAmount.setScale(2, RoundingMode.HALF_UP));
Assert.assertEquals(refund.getCurrency(), DEFAULT_CURRENCY);
Assert.assertEquals(refund.getStatus(), TransactionStatus.SUCCESS);
Assert.assertEquals(refund.getEffectiveDate().getYear(), clock.getUTCNow().getYear());
Assert.assertEquals(refund.getEffectiveDate().getMonthOfYear(), clock.getUTCNow().getMonthOfYear());
Assert.assertEquals(refund.getEffectiveDate().getDayOfMonth(), clock.getUTCNow().getDayOfMonth());
// Verify the refund via the payment API
final Payment retrievedPaymentJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(retrievedPaymentJson.getPaymentId(), paymentJson.getPaymentId());
Assert.assertEquals(retrievedPaymentJson.getPurchasedAmount().setScale(2, RoundingMode.HALF_UP), paymentJson.getPurchasedAmount().setScale(2, RoundingMode.HALF_UP));
Assert.assertEquals(retrievedPaymentJson.getAccountId(), paymentJson.getAccountId());
Assert.assertEquals(retrievedPaymentJson.getCurrency(), paymentJson.getCurrency());
Assert.assertEquals(retrievedPaymentJson.getPaymentMethodId(), paymentJson.getPaymentMethodId());
}
use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestInvoicePayment method testPaymentsAndRefundsPagination.
@Test(groups = "slow", description = "Can paginate through all payments and refunds")
public void testPaymentsAndRefundsPagination() throws Exception {
InvoicePayment lastPayment = setupScenarioWithPayment(true);
for (int i = 0; i < 5; i++) {
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(lastPayment.getPaymentId());
refund.setAmount(lastPayment.getPurchasedAmount());
invoicePaymentApi.createRefundWithAdjustments(lastPayment.getPaymentId(), refund, lastPayment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final InvoicePayment invoicePayment = new InvoicePayment();
invoicePayment.setPurchasedAmount(lastPayment.getPurchasedAmount());
invoicePayment.setAccountId(lastPayment.getAccountId());
invoicePayment.setTargetInvoiceId(lastPayment.getTargetInvoiceId());
final InvoicePayment payment = invoiceApi.createInstantPayment(lastPayment.getTargetInvoiceId(), invoicePayment, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
lastPayment = payment;
}
final InvoicePayments allPayments = accountApi.getInvoicePayments(lastPayment.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(allPayments.size(), 6);
final List<PaymentTransaction> objRefundFromJson = getInvoicePaymentTransactions(allPayments, TransactionType.REFUND);
Assert.assertEquals(objRefundFromJson.size(), 5);
Payments paymentsPage = paymentApi.getPayments(0L, 1L, null, false, false, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, requestOptions);
for (int i = 0; i < 6; i++) {
Assert.assertNotNull(paymentsPage);
Assert.assertEquals(paymentsPage.size(), 1);
verifyInvoicePaymentAgainstPayment(allPayments.get(i), paymentsPage.get(0));
paymentsPage = paymentsPage.getNext();
}
assertNull(paymentsPage);
}
use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestInvoicePayment method setupScenarioWithPayment.
private InvoicePayment setupScenarioWithPayment(final boolean invoicePaymentSuccess) throws Exception {
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice("Shotgun", invoicePaymentSuccess, true);
final List<InvoicePayment> paymentsForAccount = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(paymentsForAccount.size(), 1);
final InvoicePayment paymentJson = paymentsForAccount.get(0);
// Check the PaymentMethod from paymentMethodId returned in the Payment object
final UUID paymentMethodId = paymentJson.getPaymentMethodId();
final PaymentMethod paymentMethodJson = paymentMethodApi.getPaymentMethod(paymentMethodId, NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(paymentMethodJson.getPaymentMethodId(), paymentMethodId);
Assert.assertEquals(paymentMethodJson.getAccountId(), accountJson.getAccountId());
// Verify the refunds
final List<PaymentTransaction> objRefundFromJson = getInvoicePaymentTransactions(paymentsForAccount, TransactionType.REFUND);
Assert.assertEquals(objRefundFromJson.size(), 0);
return paymentJson;
}
use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestAccountTimeline method verifyPayments.
private void verifyPayments(final UUID accountId, final DateTime startTime, final DateTime endTime, final BigDecimal refundAmount, final BigDecimal chargebackAmount) throws Exception {
for (final AuditLevel auditLevel : AuditLevel.values()) {
final AccountTimeline timeline = getAccountTimeline(accountId, auditLevel);
Assert.assertEquals(timeline.getPayments().size(), 1);
final InvoicePayment payment = timeline.getPayments().get(0);
// Verify payments
final List<PaymentTransaction> purchaseTransactions = getInvoicePaymentTransactions(timeline.getPayments(), TransactionType.PURCHASE);
Assert.assertEquals(purchaseTransactions.size(), 1);
final PaymentTransaction purchaseTransaction = purchaseTransactions.get(0);
// Verify refunds
final List<PaymentTransaction> refundTransactions = getInvoicePaymentTransactions(timeline.getPayments(), TransactionType.REFUND);
Assert.assertEquals(refundTransactions.size(), 1);
final PaymentTransaction refundTransaction = refundTransactions.get(0);
Assert.assertEquals(refundTransaction.getPaymentId(), payment.getPaymentId());
Assert.assertEquals(refundTransaction.getAmount().compareTo(refundAmount), 0);
final List<PaymentTransaction> chargebackTransactions = getInvoicePaymentTransactions(timeline.getPayments(), TransactionType.CHARGEBACK);
Assert.assertEquals(chargebackTransactions.size(), 1);
final PaymentTransaction chargebackTransaction = chargebackTransactions.get(0);
Assert.assertEquals(chargebackTransaction.getPaymentId(), payment.getPaymentId());
Assert.assertEquals(chargebackTransaction.getAmount().compareTo(chargebackAmount), 0);
// Verify audits
final List<AuditLog> paymentAuditLogs = purchaseTransaction.getAuditLogs();
final List<AuditLog> refundAuditLogs = refundTransaction.getAuditLogs();
final List<AuditLog> chargebackAuditLogs = chargebackTransaction.getAuditLogs();
if (AuditLevel.NONE.equals(auditLevel)) {
// Audits for payments
Assert.assertEquals(paymentAuditLogs.size(), 0);
// Audits for refunds
Assert.assertEquals(refundAuditLogs.size(), 0);
// Audits for chargebacks
Assert.assertEquals(chargebackAuditLogs.size(), 0);
} else if (AuditLevel.MINIMAL.equals(auditLevel)) {
// Audits for payments
Assert.assertEquals(paymentAuditLogs.size(), 1);
verifyAuditLog(paymentAuditLogs.get(0), ChangeType.INSERT, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
// Audits for refunds
Assert.assertEquals(refundAuditLogs.size(), 1);
verifyAuditLog(refundAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
// Audits for chargebacks
Assert.assertEquals(chargebackAuditLogs.size(), 1);
verifyAuditLog(chargebackAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
} else {
// Audits for payments
Assert.assertEquals(paymentAuditLogs.size(), 2);
verifyAuditLog(paymentAuditLogs.get(0), ChangeType.INSERT, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
verifyAuditLog(paymentAuditLogs.get(1), ChangeType.UPDATE, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
// Audits for refunds
Assert.assertEquals(refundAuditLogs.size(), 2);
verifyAuditLog(refundAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
verifyAuditLog(refundAuditLogs.get(1), ChangeType.UPDATE, reason, comment, createdBy, startTime, endTime);
// Audits for chargebacks
Assert.assertEquals(chargebackAuditLogs.size(), 2);
verifyAuditLog(chargebackAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
verifyAuditLog(chargebackAuditLogs.get(1), ChangeType.UPDATE, reason, comment, createdBy, startTime, endTime);
}
}
}
use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestAdmin method doCapture.
private void doCapture(final Payment payment, final boolean expectException) throws KillBillClientException {
// Payment object does not export state, this is purely internal, so to verify that we indeed changed to Failed, we can attempt
// a capture, which should fail
final String capture1TransactionExternalKey = UUID.randomUUID().toString();
final PaymentTransaction captureTransaction = new PaymentTransaction();
captureTransaction.setPaymentId(payment.getPaymentId());
captureTransaction.setAmount(BigDecimal.ONE);
captureTransaction.setCurrency(payment.getCurrency());
captureTransaction.setPaymentExternalKey(payment.getPaymentExternalKey());
captureTransaction.setTransactionExternalKey(capture1TransactionExternalKey);
try {
paymentApi.captureAuthorization(payment.getPaymentId(), captureTransaction, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
if (expectException) {
Assert.fail("Capture should not succeed, after auth was moved to a PAYMENT_FAILURE");
}
} catch (final KillBillClientException mabeExpected) {
if (!expectException) {
throw mabeExpected;
}
}
}
Aggregations