Search in sources :

Example 11 with InvoicePayment

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

the class TestInvoice method testExternalPayment.

@Test(groups = "slow", description = "Can create an external payment")
public void testExternalPayment() throws Exception {
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Verify we didn't get any invoicePayment
    final List<InvoicePayment> noPaymentsFromJson = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId());
    assertEquals(noPaymentsFromJson.size(), 0);
    // Get the invoices
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId());
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    final UUID invoiceId = invoices.get(1).getInvoiceId();
    // Post an external invoicePayment
    final InvoicePayment invoicePayment = new InvoicePayment();
    invoicePayment.setPurchasedAmount(BigDecimal.TEN);
    invoicePayment.setAccountId(accountJson.getAccountId());
    invoicePayment.setTargetInvoiceId(invoiceId);
    killBillClient.createInvoicePayment(invoicePayment, true, createdBy, reason, comment);
    // Verify we indeed got the invoicePayment
    final List<InvoicePayment> paymentsFromJson = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId());
    assertEquals(paymentsFromJson.size(), 1);
    assertEquals(paymentsFromJson.get(0).getPurchasedAmount().compareTo(BigDecimal.TEN), 0);
    assertEquals(paymentsFromJson.get(0).getTargetInvoiceId(), invoiceId);
    // Check the PaymentMethod from paymentMethodId returned in the Payment object
    final UUID paymentMethodId = paymentsFromJson.get(0).getPaymentMethodId();
    final PaymentMethod paymentMethodJson = killBillClient.getPaymentMethod(paymentMethodId);
    assertEquals(paymentMethodJson.getPaymentMethodId(), paymentMethodId);
    assertEquals(paymentMethodJson.getAccountId(), accountJson.getAccountId());
    assertEquals(paymentMethodJson.getPluginName(), ExternalPaymentProviderPlugin.PLUGIN_NAME);
    assertNull(paymentMethodJson.getPluginInfo());
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Invoice(org.killbill.billing.client.model.Invoice) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 12 with InvoicePayment

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

the class TestExternalRefund method assertInvoicePaymentsExternalRefund.

private void assertInvoicePaymentsExternalRefund(final UUID accountId, final InvoicePayment invoicePaymentExternalRefund) throws KillBillClientException {
    final InvoicePayments invoicePaymentsForAccount = killBillClient.getInvoicePaymentsForAccount(accountId, requestOptions);
    assertEquals(invoicePaymentsForAccount.size(), 2);
    // INVOICE PAYMENT FOR ORIGINAL PURCHASE
    final InvoicePayment invoicePaymentPurchase = invoicePaymentsForAccount.get(0);
    assertEquals(invoicePaymentPurchase.getPurchasedAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
    assertEquals(invoicePaymentPurchase.getCreditedAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(invoicePaymentPurchase.getTransactions().get(0).getTransactionType(), TransactionType.PURCHASE.toString());
    assertEquals(invoicePaymentPurchase.getTransactions().get(0).getAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
    // INVOICE PAYMENT FOR EXTERNAL REFUND
    final InvoicePayment creditInvoicePayment = invoicePaymentsForAccount.get(1);
    assertTrue(creditInvoicePayment.equals(invoicePaymentExternalRefund));
    assertEquals(creditInvoicePayment.getPurchasedAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(creditInvoicePayment.getCreditedAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
    assertEquals(creditInvoicePayment.getTransactions().size(), 1);
    assertEquals(creditInvoicePayment.getTransactions().get(0).getTransactionType(), TransactionType.CREDIT.toString());
    assertEquals(creditInvoicePayment.getTransactions().get(0).getAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
}
Also used : InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoicePayments(org.killbill.billing.client.model.InvoicePayments)

Example 13 with InvoicePayment

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

the class TestExternalRefund method testManualPaymentAndExternalRefundWithAdjustments.

@Test(groups = "slow", description = "#255 - Scenario 1 - Can refund a manual payment though an external refund over item adjustments")
public void testManualPaymentAndExternalRefundWithAdjustments() 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 = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
    final Invoice unpaidInvoice = invoicesForAccount.get(1);
    assertEquals(unpaidInvoice.getBalance().compareTo(BigDecimal.valueOf(249.95)), 0);
    final Payments paymentsForAccount = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(paymentsForAccount.size(), 0);
    final InvoicePayment invoicePaymentRequest = new InvoicePayment();
    invoicePaymentRequest.setTargetInvoiceId(unpaidInvoice.getInvoiceId());
    invoicePaymentRequest.setAccountId(accountJson.getAccountId());
    invoicePaymentRequest.setCurrency(unpaidInvoice.getCurrency().toString());
    invoicePaymentRequest.setPurchasedAmount(unpaidInvoice.getAmount());
    final InvoicePayment invoicePayment = killBillClient.createInvoicePayment(invoicePaymentRequest, true, 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());
    invoicePaymentTransactionRequest.setIsAdjusted(true);
    invoicePaymentTransactionRequest.setAdjustments(unpaidInvoice.getItems());
    final InvoicePayment invoicePaymentRefund = killBillClient.createInvoicePaymentRefund(invoicePaymentTransactionRequest, requestOptions);
    assertNotNull(invoicePaymentRefund);
    assertSingleInvoicePaymentRefund(invoicePaymentRefund);
    assertRefundInvoiceAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Invoice(org.killbill.billing.client.model.Invoice) InvoicePaymentTransaction(org.killbill.billing.client.model.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 InvoicePayment

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

the class TestExternalRefund method testAutomaticPaymentAndExternalRefundWithDifferentPM.

@Test(groups = "slow", description = "#255 - Scenario 2b - Can refund an automatic payment though another existing payment method")
public void testAutomaticPaymentAndExternalRefundWithDifferentPM() 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
    killBillClient.deletePaymentMethod(accountJson.getPaymentMethodId(), true, true, requestOptions);
    // create another PM
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), accountJson.getAccountId(), false, PLUGIN_NAME, info);
    final PaymentMethod otherPaymentMethod = killBillClient.createPaymentMethod(paymentMethodJson, requestOptions);
    final Payments paymentsForAccount = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    final Invoices invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, true, 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().toString());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    invoicePaymentTransactionRequest.setIsAdjusted(true);
    invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
    final InvoicePayment invoicePaymentExternalRefund = killBillClient.createInvoicePaymentRefund(invoicePaymentTransactionRequest, true, otherPaymentMethod.getPaymentMethodId(), requestOptions);
    assertNotNull(invoicePaymentExternalRefund);
    assertEquals(invoicePaymentExternalRefund.getPaymentMethodId(), otherPaymentMethod.getPaymentMethodId());
    assertInvoicePaymentsExternalRefund(accountJson.getAccountId(), invoicePaymentExternalRefund);
    assertRefundInvoiceAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) PaymentMethodPluginDetail(org.killbill.billing.client.model.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) 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 InvoicePayment

use of org.killbill.billing.client.model.InvoicePayment 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 = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    Invoices invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, true, requestOptions);
    final List<InvoiceItem> itemsToBeAdjusted = invoices.get(1).getItems();
    // regular refund
    final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
    invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
    invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency().toString());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    final InvoicePayment invoicePaymentRefund = killBillClient.createInvoicePaymentRefund(invoicePaymentTransactionRequest, 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.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.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)

Aggregations

InvoicePayment (org.killbill.billing.client.model.InvoicePayment)25 Test (org.testng.annotations.Test)20 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)19 Payment (org.killbill.billing.client.model.Payment)14 Account (org.killbill.billing.client.model.Account)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)10 DateTime (org.joda.time.DateTime)9 Invoice (org.killbill.billing.client.model.Invoice)9 Invoices (org.killbill.billing.client.model.Invoices)8 Payments (org.killbill.billing.client.model.Payments)8 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)7 BigDecimal (java.math.BigDecimal)6 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)6 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)3 UUID (java.util.UUID)2 KillBillClientException (org.killbill.billing.client.KillBillClientException)1 AccountTimeline (org.killbill.billing.client.model.AccountTimeline)1 AuditLog (org.killbill.billing.client.model.AuditLog)1 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)1 AuditLevel (org.killbill.billing.util.api.AuditLevel)1