Search in sources :

Example 11 with InvoicePaymentTransaction

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

the class TestExternalRefund method testAutomaticPaymentAndExternalRefund.

@Test(groups = "slow", description = "#255 - Scenario 2a - Can refund an automatic payment though an external refund")
public void testAutomaticPaymentAndExternalRefund() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // delete PM
    paymentMethodApi.deletePaymentMethod(accountJson.getPaymentMethodId(), true, true, NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    // external refund
    final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
    invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
    invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    final InvoicePayment invoicePaymentExternalRefund = invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, true, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(invoicePaymentExternalRefund);
    assertInvoicePaymentsExternalRefund(accountJson.getAccountId(), invoicePaymentExternalRefund);
    assertRefundInvoiceNoAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.valueOf(249.95), BigDecimal.ZERO);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) 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) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 12 with InvoicePaymentTransaction

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

the class TestExternalRefund method testAutomaticPaymentAndRefund.

@Test(groups = "slow", description = "#255 - Scenario 0 - Can refund an automatic payment. This is a test to validate the correct behaviour.")
public void testAutomaticPaymentAndRefund() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, true, false, false, null, AuditLevel.NONE, requestOptions);
    // regular refund
    final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
    invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
    invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, payment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final InvoicePayment invoicePaymentRefund = invoicePaymentApi.getInvoicePayment(payment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertSingleInvoicePaymentRefund(invoicePaymentRefund);
    assertRefundInvoiceNoAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.valueOf(249.95), BigDecimal.ZERO);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) 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) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Invoices(org.killbill.billing.client.model.Invoices) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 13 with InvoicePaymentTransaction

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

the class TestExternalRefund method testAutomaticPaymentAndExternalRefundWithAdjustments.

@Test(groups = "slow", description = "#255 - Scenario 2a - Can refund an automatic payment though an external refund over item adjustments")
public void testAutomaticPaymentAndExternalRefundWithAdjustments() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // delete PM
    paymentMethodApi.deletePaymentMethod(accountJson.getPaymentMethodId(), true, true, NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    final Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, true, false, false, null, AuditLevel.NONE, requestOptions);
    final List<InvoiceItem> itemsToBeAdjusted = invoices.get(1).getItems();
    // external refund
    final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
    invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
    invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    invoicePaymentTransactionRequest.setIsAdjusted(true);
    invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
    final InvoicePayment invoicePaymentExternalRefund = invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, true, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(invoicePaymentExternalRefund);
    assertInvoicePaymentsExternalRefund(accountJson.getAccountId(), invoicePaymentExternalRefund);
    assertRefundInvoiceAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Invoices(org.killbill.billing.client.model.Invoices) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 14 with InvoicePaymentTransaction

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

the class TestExternalRefund method testManualPaymentAndExternalRefund.

@Test(groups = "slow", description = "#255 - Scenario 1 - Can refund a manual payment though an external refund")
public void testManualPaymentAndExternalRefund() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithExternalPMBundleAndSubscriptionAndManualPayTagAndWaitForFirstInvoice();
    final Invoices invoicesForAccount = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    final Invoice unpaidInvoice = invoicesForAccount.get(1);
    assertEquals(unpaidInvoice.getBalance().compareTo(BigDecimal.valueOf(249.95)), 0);
    final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(paymentsForAccount.size(), 0);
    final InvoicePayment invoicePaymentRequest = new InvoicePayment();
    invoicePaymentRequest.setTargetInvoiceId(unpaidInvoice.getInvoiceId());
    invoicePaymentRequest.setAccountId(accountJson.getAccountId());
    invoicePaymentRequest.setCurrency(unpaidInvoice.getCurrency());
    invoicePaymentRequest.setPurchasedAmount(unpaidInvoice.getAmount());
    final InvoicePayment invoicePayment = invoiceApi.createInstantPayment(unpaidInvoice.getInvoiceId(), invoicePaymentRequest, true, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(invoicePayment.getPurchasedAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
    assertEquals(invoicePayment.getRefundedAmount().compareTo(BigDecimal.ZERO), 0);
    final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
    invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
    invoicePaymentTransactionRequest.setPaymentId(invoicePayment.getPaymentId());
    final InvoicePayment invoicePaymentRefund = invoicePaymentApi.createRefundWithAdjustments(invoicePayment.getPaymentId(), invoicePaymentTransactionRequest, invoicePayment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(invoicePaymentRefund);
    assertSingleInvoicePaymentRefund(invoicePaymentRefund);
    assertRefundInvoiceNoAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.valueOf(249.95), BigDecimal.ZERO);
}
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) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Invoices(org.killbill.billing.client.model.Invoices) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 15 with InvoicePaymentTransaction

use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction 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)

Aggregations

InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)20 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)18 Test (org.testng.annotations.Test)18 Payment (org.killbill.billing.client.model.gen.Payment)11 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)10 Account (org.killbill.billing.client.model.gen.Account)9 DateTime (org.joda.time.DateTime)8 Payments (org.killbill.billing.client.model.Payments)8 BigDecimal (java.math.BigDecimal)7 Invoice (org.killbill.billing.client.model.gen.Invoice)7 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)7 Invoices (org.killbill.billing.client.model.Invoices)6 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)4 KillBillClientException (org.killbill.billing.client.KillBillClientException)3 InvoiceItems (org.killbill.billing.client.model.InvoiceItems)1 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)1 PaymentMethodPluginDetail (org.killbill.billing.client.model.gen.PaymentMethodPluginDetail)1