Search in sources :

Example 26 with InvoicePayment

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

the class TestInvoicePayment method testPartialRefundWithFullInvoiceItemAdjustment.

@Test(groups = "slow", description = "Cannot create invoice item adjustments for more than the refund amount")
public void testPartialRefundWithFullInvoiceItemAdjustment() throws Exception {
    final InvoicePayment paymentJson = setupScenarioWithPayment(true);
    // Get the individual items for the invoice
    final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), false, AuditLevel.NONE, requestOptions);
    final InvoiceItem itemToAdjust = invoice.getItems().get(0);
    // Issue a refund for a fraction of the amount
    final BigDecimal refundAmount = getFractionOfAmount(itemToAdjust.getAmount());
    final BigDecimal expectedInvoiceBalance = invoice.getBalance();
    // Post and verify the refund
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(paymentJson.getPaymentId());
    refund.setAmount(refundAmount);
    refund.setIsAdjusted(true);
    final InvoiceItem adjustment = new InvoiceItem();
    adjustment.setInvoiceItemId(itemToAdjust.getInvoiceItemId());
    // Ask for an adjustment for the full amount (bigger than the refund amount)
    adjustment.setAmount(itemToAdjust.getAmount());
    refund.setAdjustments(ImmutableList.<InvoiceItem>of(adjustment));
    invoicePaymentApi.createRefundWithAdjustments(paymentJson.getPaymentId(), refund, paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    // The refund did go through
    verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
    // But not the adjustments
    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) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 27 with InvoicePayment

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

the class TestInvoicePayment method testFullRefundWithNoAdjustment.

@Test(groups = "slow", description = "Can create a full refund with no adjustment")
public void testFullRefundWithNoAdjustment() throws Exception {
    final InvoicePayment invoicePaymentJson = setupScenarioWithPayment(true);
    // Issue a refund for the full amount
    final BigDecimal refundAmount = invoicePaymentJson.getPurchasedAmount();
    final BigDecimal expectedInvoiceBalance = refundAmount;
    // Post and verify the refund
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(invoicePaymentJson.getPaymentId());
    refund.setAmount(refundAmount);
    invoicePaymentApi.createRefundWithAdjustments(invoicePaymentJson.getPaymentId(), refund, invoicePaymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment paymentAfterRefundJson = paymentApi.getPayment(invoicePaymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyRefund(invoicePaymentJson, paymentAfterRefundJson, refundAmount);
    // Verify the invoice balance
    verifyInvoice(invoicePaymentJson, 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 28 with InvoicePayment

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

the class TestInvoicePayment method testInvoicePaymentCompletion.

@Test(groups = "slow")
public void testInvoicePaymentCompletion() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentPending();
    final InvoicePayment paymentJson = setupScenarioWithPayment(false);
    final Payment retrievedPaymentJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyInvoicePaymentAgainstPayment(paymentJson, retrievedPaymentJson);
    Assert.assertEquals(retrievedPaymentJson.getTransactions().size(), 1);
    Assert.assertEquals(retrievedPaymentJson.getTransactions().get(0).getStatus(), TransactionStatus.PENDING);
    final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
    completeTransactionByPaymentId.setPaymentId(retrievedPaymentJson.getPaymentId());
    final Account accountWithBalance = accountApi.getAccount(paymentJson.getAccountId(), true, false, AuditLevel.NONE, requestOptions);
    Assert.assertTrue(accountWithBalance.getAccountBalance().compareTo(BigDecimal.ZERO) > 0);
    invoicePaymentApi.completeInvoicePaymentTransaction(retrievedPaymentJson.getPaymentId(), new PaymentTransaction(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment completedPayment = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(completedPayment.getTransactions().get(0).getStatus(), TransactionStatus.SUCCESS);
    final Account accountWithBalance2 = accountApi.getAccount(paymentJson.getAccountId(), true, false, AuditLevel.NONE, requestOptions);
    Assert.assertEquals(accountWithBalance2.getAccountBalance().compareTo(BigDecimal.ZERO), 0);
}
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) Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) Test(org.testng.annotations.Test)

Example 29 with InvoicePayment

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

the class TestInvoicePayment method testRefundWithFullInvoiceItemAdjustment.

@Test(groups = "slow", description = "Can create a full refund with invoice item adjustment")
public void testRefundWithFullInvoiceItemAdjustment() throws Exception {
    final InvoicePayment paymentJson = setupScenarioWithPayment(true);
    // Get the individual items for the invoice
    final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), false, AuditLevel.NONE, requestOptions);
    final InvoiceItem itemToAdjust = invoice.getItems().get(0);
    // Issue a refund for the full amount
    final BigDecimal refundAmount = itemToAdjust.getAmount();
    final BigDecimal expectedInvoiceBalance = BigDecimal.ZERO;
    // Post and verify the refund
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(paymentJson.getPaymentId());
    refund.setAmount(refundAmount);
    refund.setIsAdjusted(true);
    final InvoiceItem adjustment = new InvoiceItem();
    adjustment.setInvoiceItemId(itemToAdjust.getInvoiceItemId());
    // null amount means full adjustment for that item
    refund.setAdjustments(ImmutableList.<InvoiceItem>of(adjustment));
    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) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 30 with InvoicePayment

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

the class TestPayment method testWithAbortedInvoicePayment.

@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/1288")
public void testWithAbortedInvoicePayment() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
    // Getting Invoice #2 (first after Trial period)
    final Invoice failedInvoice = accountApi.getInvoicesForAccount(account.getAccountId(), null, null, null, RequestOptions.empty()).get(1);
    // Verify initial state
    final Payments initialPayments = accountApi.getPaymentsForAccount(account.getAccountId(), true, false, ImmutableMap.<String, String>of(), AuditLevel.NONE, requestOptions);
    Assert.assertEquals(initialPayments.size(), 1);
    Assert.assertEquals(initialPayments.get(0).getTransactions().size(), 1);
    Assert.assertEquals(initialPayments.get(0).getTransactions().get(0).getStatus(), TransactionStatus.PAYMENT_FAILURE);
    Assert.assertEquals(initialPayments.get(0).getPaymentAttempts().size(), 2);
    Assert.assertEquals(initialPayments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
    Assert.assertEquals(initialPayments.get(0).getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
    final InvoicePayments initialInvoicePayments = invoiceApi.getPaymentsForInvoice(failedInvoice.getInvoiceId(), requestOptions);
    Assert.assertEquals(initialInvoicePayments.size(), 1);
    Assert.assertEquals(initialInvoicePayments.get(0).getPaymentId(), initialPayments.get(0).getPaymentId());
    // Trigger manually an invoice payment but make the control plugin abort it
    mockPaymentControlProviderPlugin.setAborted(true);
    final HashMultimap<String, String> queryParams = HashMultimap.create();
    queryParams.putAll("controlPluginName", Arrays.<String>asList(MockPaymentControlProviderPlugin.PLUGIN_NAME));
    final RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withQueryParams(queryParams).build();
    final InvoicePayment invoicePayment = new InvoicePayment();
    invoicePayment.setPurchasedAmount(failedInvoice.getBalance());
    invoicePayment.setAccountId(failedInvoice.getAccountId());
    invoicePayment.setTargetInvoiceId(failedInvoice.getInvoiceId());
    final InvoicePayment invoicePaymentNull = invoiceApi.createInstantPayment(failedInvoice.getInvoiceId(), invoicePayment, ImmutableList.of(), null, inputOptions);
    Assert.assertNull(invoicePaymentNull);
    // Verify new state
    final Payments updatedPayments = accountApi.getPaymentsForAccount(account.getAccountId(), true, false, ImmutableMap.<String, String>of(), AuditLevel.NONE, requestOptions);
    Assert.assertEquals(updatedPayments.size(), 1);
    Assert.assertEquals(updatedPayments.get(0).getPaymentId(), initialPayments.get(0).getPaymentId());
    final InvoicePayments updatedInvoicePayments = invoiceApi.getPaymentsForInvoice(failedInvoice.getInvoiceId(), requestOptions);
    Assert.assertEquals(updatedInvoicePayments.size(), 1);
    Assert.assertEquals(updatedInvoicePayments.get(0).getPaymentId(), updatedPayments.get(0).getPaymentId());
}
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) RequestOptions(org.killbill.billing.client.RequestOptions) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) 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