Search in sources :

Example 1 with Payments

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

the class TestExternalRefund method testAutomaticPaymentAndRefundWithAdjustments.

@Test(groups = "slow", description = "#255 - Scenario 0 - Can refund an automatic payment over item adjustments. This is a test to validate the correct behaviour.")
public void testAutomaticPaymentAndRefundWithAdjustments() 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);
    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());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    invoicePaymentTransactionRequest.setIsAdjusted(true);
    invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
    invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, payment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final InvoicePayment invoicePaymentRefund = invoicePaymentApi.getInvoicePayment(payment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(invoicePaymentRefund);
    assertSingleInvoicePaymentRefund(invoicePaymentRefund);
    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 2 with Payments

use of org.killbill.billing.client.model.Payments 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
    paymentMethodApi.deletePaymentMethod(accountJson.getPaymentMethodId(), true, true, NULL_PLUGIN_PROPERTIES, requestOptions);
    // create another PM
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), accountJson.getAccountId(), false, PLUGIN_NAME, info, null);
    final PaymentMethod otherPaymentMethod = accountApi.createPaymentMethod(accountJson.getAccountId(), paymentMethodJson, NULL_PLUGIN_NAMES, 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, otherPaymentMethod.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, 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.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) PaymentMethodPluginDetail(org.killbill.billing.client.model.gen.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.gen.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 3 with Payments

use of org.killbill.billing.client.model.Payments 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 = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, 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());
    invoicePaymentTransactionRequest.setIsAdjusted(true);
    invoicePaymentTransactionRequest.setAdjustments(unpaidInvoice.getItems());
    final InvoicePayment invoicePaymentRefund = invoicePaymentApi.createRefundWithAdjustments(invoicePayment.getPaymentId(), invoicePaymentTransactionRequest, false, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(invoicePaymentRefund);
    assertSingleInvoicePaymentRefund(invoicePaymentRefund);
    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) 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 4 with Payments

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

the class TestPayment method testWithFailedPaymentAndScheduledAttemptsGetPayments.

@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetPayments() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
    HashMultimap<String, String> queryParams = HashMultimap.create();
    queryParams.put("withAttempts", "true");
    RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withQueryParams(queryParams).build();
    Payments payments = paymentApi.getPayments(0L, 100L, null, false, true, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, inputOptions);
    Assert.assertNotNull(payments.get(0).getPaymentAttempts());
    Assert.assertEquals(payments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
    Assert.assertEquals(payments.get(0).getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
}
Also used : RequestOptions(org.killbill.billing.client.RequestOptions) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Payments(org.killbill.billing.client.model.Payments) Test(org.testng.annotations.Test)

Example 5 with Payments

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

the class TestPayment method verifyPaymentNoTransaction.

private void verifyPaymentNoTransaction(final Account account, @Nullable final UUID paymentMethodId, final Payment payment, final String paymentExternalKey, final BigDecimal authAmount, final BigDecimal capturedAmount, final BigDecimal refundedAmount, final int nbTransactions, final int paymentNb) throws KillBillClientException {
    assertEquals(payment.getAccountId(), account.getAccountId());
    assertEquals(payment.getPaymentMethodId(), MoreObjects.firstNonNull(paymentMethodId, account.getPaymentMethodId()));
    Assert.assertNotNull(payment.getPaymentId());
    Assert.assertNotNull(payment.getPaymentNumber());
    assertEquals(payment.getPaymentExternalKey(), paymentExternalKey);
    assertEquals(payment.getAuthAmount().compareTo(authAmount), 0);
    assertEquals(payment.getCapturedAmount().compareTo(capturedAmount), 0);
    assertEquals(payment.getRefundedAmount().compareTo(refundedAmount), 0);
    assertEquals(payment.getCurrency(), account.getCurrency());
    assertEquals(payment.getTransactions().size(), nbTransactions);
    final Payments Payments = paymentApi.getPayments(null, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(Payments.size(), paymentNb);
    assertEquals(Payments.get(paymentNb - 1), payment);
    final Payment retrievedPayment = paymentApi.getPayment(payment.getPaymentId(), false, false, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, requestOptions);
    assertEquals(retrievedPayment, payment);
    final Payments paymentsForAccount = accountApi.getPaymentsForAccount(account.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(paymentsForAccount.size(), paymentNb);
    assertEquals(paymentsForAccount.get(paymentNb - 1), payment);
}
Also used : InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Payments(org.killbill.billing.client.model.Payments)

Aggregations

Payments (org.killbill.billing.client.model.Payments)17 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)16 Test (org.testng.annotations.Test)15 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)11 Account (org.killbill.billing.client.model.gen.Account)10 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)8 DateTime (org.joda.time.DateTime)7 Payment (org.killbill.billing.client.model.gen.Payment)7 Invoices (org.killbill.billing.client.model.Invoices)6 RequestOptions (org.killbill.billing.client.RequestOptions)4 Invoice (org.killbill.billing.client.model.gen.Invoice)3 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)3 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Account (org.killbill.billing.client.model.Account)1 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)1 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)1 PaymentMethodPluginDetail (org.killbill.billing.client.model.gen.PaymentMethodPluginDetail)1 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)1