Search in sources :

Example 21 with InvoicePayment

use of org.killbill.billing.client.model.gen.InvoicePayment 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 22 with InvoicePayment

use of org.killbill.billing.client.model.gen.InvoicePayment in project killbill by killbill.

the class TestInvoice method testInvoiceCreatePayment.

@Test(groups = "slow", description = "Can create an insta-payment")
public void testInvoiceCreatePayment() throws Exception {
    clock.setTime(new DateTime(2012, 4, 25, 0, 3, 42, 0));
    // STEPH MISSING SET ACCOUNT AUTO_PAY_OFF
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    assertEquals(invoices.size(), 2);
    for (final Invoice cur : invoices) {
        if (cur.getBalance().compareTo(BigDecimal.ZERO) <= 0) {
            continue;
        }
        // CREATE PAYMENT
        final InvoicePayment invoicePayment = new InvoicePayment();
        invoicePayment.setPurchasedAmount(cur.getBalance());
        invoicePayment.setAccountId(accountJson.getAccountId());
        invoicePayment.setTargetInvoiceId(cur.getInvoiceId());
        final InvoicePayment objFromJson = invoiceApi.createInstantPayment(cur.getInvoiceId(), invoicePayment, true, ImmutableList.of(), null, requestOptions);
        assertEquals(cur.getBalance().compareTo(objFromJson.getPurchasedAmount()), 0);
    }
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Invoice(org.killbill.billing.client.model.gen.Invoice) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 23 with InvoicePayment

use of org.killbill.billing.client.model.gen.InvoicePayment in project killbill by killbill.

the class TestInvoicePayment method testManualInvoicePayment.

@Test(groups = "slow")
public void testManualInvoicePayment() throws Exception {
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    assertNotNull(accountJson);
    // Disable automatic payments
    callbackServlet.pushExpectedEvent(ExtBusEventType.TAG_CREATION);
    accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(ControlTagType.AUTO_PAY_OFF.getId()), requestOptions);
    callbackServlet.assertListenerStatus();
    // Add a bundle, subscription and move the clock to get the first invoice
    final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    assertNotNull(subscriptionJson);
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION);
    clock.addDays(32);
    callbackServlet.assertListenerStatus();
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    assertEquals(invoices.size(), 2);
    final InvoicePayment invoicePayment1 = new InvoicePayment();
    invoicePayment1.setPurchasedAmount(invoices.get(1).getBalance().add(BigDecimal.TEN));
    invoicePayment1.setAccountId(accountJson.getAccountId());
    invoicePayment1.setTargetInvoiceId(invoices.get(1).getInvoiceId());
    // Pay too too much => 400
    try {
        invoiceApi.createInstantPayment(invoicePayment1.getTargetInvoiceId(), invoicePayment1, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
        Assert.fail("InvoicePayment call should fail with 400");
    } catch (final KillBillClientException e) {
        assertTrue(true);
    }
    final InvoicePayment invoicePayment2 = new InvoicePayment();
    invoicePayment2.setPurchasedAmount(invoices.get(1).getBalance());
    invoicePayment2.setAccountId(accountJson.getAccountId());
    invoicePayment2.setTargetInvoiceId(invoices.get(1).getInvoiceId());
    // Just right, Yah! => 201
    final InvoicePayment result2 = invoiceApi.createInstantPayment(invoicePayment2.getTargetInvoiceId(), invoicePayment2, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(result2.getTransactions().size(), 1);
    assertTrue(result2.getTransactions().get(0).getAmount().compareTo(invoices.get(1).getBalance()) == 0);
    // Already paid -> 204
    final InvoicePayment result3 = invoiceApi.createInstantPayment(invoicePayment2.getTargetInvoiceId(), invoicePayment2, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNull(result3);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Invoice(org.killbill.billing.client.model.gen.Invoice) KillBillClientException(org.killbill.billing.client.KillBillClientException) Subscription(org.killbill.billing.client.model.gen.Subscription) Test(org.testng.annotations.Test)

Example 24 with InvoicePayment

use of org.killbill.billing.client.model.gen.InvoicePayment in project killbill by killbill.

the class TestInvoicePayment method testPartialRefundWithNoAdjustment.

@Test(groups = "slow", description = "Can create a partial refund with no adjustment")
public void testPartialRefundWithNoAdjustment() throws Exception {
    final InvoicePayment paymentJson = setupScenarioWithPayment(true);
    // Issue a refund for a fraction of the amount
    final BigDecimal refundAmount = getFractionOfAmount(paymentJson.getPurchasedAmount());
    final BigDecimal expectedInvoiceBalance = refundAmount;
    // Post and verify the refund
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(paymentJson.getPaymentId());
    refund.setAmount(refundAmount);
    invoicePaymentApi.createRefundWithAdjustments(paymentJson.getPaymentId(), refund, paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
    // Verify the invoice balance
    verifyInvoice(paymentJson, expectedInvoiceBalance);
}
Also used : InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 25 with InvoicePayment

use of org.killbill.billing.client.model.gen.InvoicePayment in project killbill by killbill.

the class TestInvoicePayment method testWithFailedInvoicePayment.

@Test(groups = "slow")
public void testWithFailedInvoicePayment() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
    InvoicePayments invoicePayments = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(invoicePayments.size(), 1);
    final InvoicePayment invoicePayment = invoicePayments.get(0);
    // Verify targetInvoiceId is not Null. See #593
    assertNotNull(invoicePayment.getTargetInvoiceId());
    // Verify targetInvoiceId is not null. See #1014
    assertEquals(invoicePaymentApi.getInvoicePayment(invoicePayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions).getTargetInvoiceId(), invoicePayment.getTargetInvoiceId());
    final Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    assertEquals(invoices.size(), 2);
    final Invoice invoice = invoices.get(1);
    // Verify this is the correct value
    assertEquals(invoicePayment.getTargetInvoiceId(), invoice.getInvoiceId());
    // Make a payment and verify both invoice payment point to the same targetInvoiceId
    final Invoices paidInvoices = accountApi.payAllInvoices(accountJson.getAccountId(), null, false, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(paidInvoices.size(), 1);
    invoicePayments = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(invoicePayments.size(), 2);
    for (final InvoicePayment cur : invoicePayments) {
        assertEquals(cur.getTargetInvoiceId(), invoice.getInvoiceId());
    }
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Invoice(org.killbill.billing.client.model.gen.Invoice) Invoices(org.killbill.billing.client.model.Invoices) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)34 Test (org.testng.annotations.Test)28 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)21 Account (org.killbill.billing.client.model.gen.Account)18 Invoice (org.killbill.billing.client.model.gen.Invoice)14 Payment (org.killbill.billing.client.model.gen.Payment)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)12 DateTime (org.joda.time.DateTime)9 Payments (org.killbill.billing.client.model.Payments)9 Invoices (org.killbill.billing.client.model.Invoices)8 BigDecimal (java.math.BigDecimal)7 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)7 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)6 KillBillClientException (org.killbill.billing.client.KillBillClientException)5 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)3 UUID (java.util.UUID)2 RequestOptions (org.killbill.billing.client.RequestOptions)1 AccountTimeline (org.killbill.billing.client.model.gen.AccountTimeline)1 AuditLog (org.killbill.billing.client.model.gen.AuditLog)1 PaymentMethodPluginDetail (org.killbill.billing.client.model.gen.PaymentMethodPluginDetail)1