Search in sources :

Example 16 with PaymentTransaction

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());
}
Also used : InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment)

Example 17 with PaymentTransaction

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);
}
Also used : InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Test(org.testng.annotations.Test)

Example 18 with PaymentTransaction

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;
}
Also used : InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) UUID(java.util.UUID)

Example 19 with PaymentTransaction

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);
        }
    }
}
Also used : InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) AuditLevel(org.killbill.billing.util.api.AuditLevel) AccountTimeline(org.killbill.billing.client.model.gen.AccountTimeline) AuditLog(org.killbill.billing.client.model.gen.AuditLog)

Example 20 with PaymentTransaction

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;
        }
    }
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) KillBillClientException(org.killbill.billing.client.KillBillClientException)

Aggregations

PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)33 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)23 Payment (org.killbill.billing.client.model.gen.Payment)23 Account (org.killbill.billing.client.model.gen.Account)21 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)21 Test (org.testng.annotations.Test)21 BigDecimal (java.math.BigDecimal)11 UUID (java.util.UUID)11 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)8 TransactionType (org.killbill.billing.payment.api.TransactionType)8 KillBillClientException (org.killbill.billing.client.KillBillClientException)7 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)5 RequestOptions (org.killbill.billing.client.RequestOptions)3 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)3 PaymentMethodPluginDetail (org.killbill.billing.client.model.gen.PaymentMethodPluginDetail)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 DateTime (org.joda.time.DateTime)1 Payments (org.killbill.billing.client.model.Payments)1 AccountTimeline (org.killbill.billing.client.model.gen.AccountTimeline)1 AdminPayment (org.killbill.billing.client.model.gen.AdminPayment)1