Search in sources :

Example 6 with MockRecurringInvoiceItem

use of org.killbill.billing.payment.MockRecurringInvoiceItem in project killbill by killbill.

the class TestPaymentApi method testCreateAbortedPurchaseWithPaymentControl.

@Test(groups = "slow")
public void testCreateAbortedPurchaseWithPaymentControl() throws InvoiceApiException, EventBusException {
    final BigDecimal requestedAmount = BigDecimal.TEN;
    final UUID subscriptionId = UUID.randomUUID();
    final UUID bundleId = UUID.randomUUID();
    final LocalDate now = clock.getUTCToday();
    final Invoice invoice = testHelper.createTestInvoice(account, now, Currency.USD);
    final String paymentExternalKey = invoice.getId().toString();
    final String transactionExternalKey = "brrrrrr";
    invoice.addInvoiceItem(new MockRecurringInvoiceItem(invoice.getId(), account.getId(), subscriptionId, bundleId, "test plan", "test phase", null, now, now.plusMonths(1), BigDecimal.ONE, new BigDecimal("1.0"), Currency.USD));
    try {
        invoicePaymentApi.createPurchaseForInvoicePayment(account, invoice.getId(), account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), INVOICE_PAYMENT, callContext);
        Assert.fail("Unexpected success");
    } catch (final PaymentApiException e) {
    }
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) MockRecurringInvoiceItem(org.killbill.billing.payment.MockRecurringInvoiceItem) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 7 with MockRecurringInvoiceItem

use of org.killbill.billing.payment.MockRecurringInvoiceItem in project killbill by killbill.

the class TestPaymentApi method testCreateCancelledPurchaseWithPaymentControl.

@Test(groups = "slow")
public void testCreateCancelledPurchaseWithPaymentControl() throws PaymentApiException, InvoiceApiException, EventBusException {
    final BigDecimal requestedAmount = BigDecimal.TEN;
    final UUID subscriptionId = UUID.randomUUID();
    final UUID bundleId = UUID.randomUUID();
    final LocalDate now = clock.getUTCToday();
    final Invoice invoice = testHelper.createTestInvoice(account, now, Currency.USD);
    final String paymentExternalKey = invoice.getId().toString();
    final String transactionExternalKey = "hgjhgjgjhg33";
    mockPaymentProviderPlugin.makeNextPaymentFailWithCancellation();
    invoice.addInvoiceItem(new MockRecurringInvoiceItem(invoice.getId(), account.getId(), subscriptionId, bundleId, "test plan", "test phase", null, now, now.plusMonths(1), requestedAmount, new BigDecimal("1.0"), Currency.USD));
    try {
        invoicePaymentApi.createPurchaseForInvoicePayment(account, invoice.getId(), account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), INVOICE_PAYMENT, callContext);
    } catch (final PaymentApiException expected) {
        assertTrue(true);
    }
    final List<Payment> accountPayments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext);
    assertEquals(accountPayments.size(), 1);
    final Payment payment = accountPayments.get(0);
    assertEquals(payment.getExternalKey(), paymentExternalKey);
    assertEquals(payment.getPaymentMethodId(), account.getPaymentMethodId());
    assertEquals(payment.getAccountId(), account.getId());
    assertEquals(payment.getAuthAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(payment.getCapturedAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(payment.getPurchasedAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(payment.getRefundedAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(payment.getCurrency(), Currency.USD);
    assertEquals(payment.getTransactions().size(), 1);
    assertEquals(payment.getTransactions().get(0).getExternalKey(), transactionExternalKey);
    assertEquals(payment.getTransactions().get(0).getPaymentId(), payment.getId());
    assertEquals(payment.getTransactions().get(0).getAmount().compareTo(requestedAmount), 0);
    assertEquals(payment.getTransactions().get(0).getCurrency(), Currency.USD);
    assertEquals(payment.getTransactions().get(0).getProcessedAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(payment.getTransactions().get(0).getProcessedCurrency(), Currency.USD);
    assertEquals(payment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.PLUGIN_FAILURE);
    assertEquals(payment.getTransactions().get(0).getTransactionType(), TransactionType.PURCHASE);
    // Make sure we can retry and that works
    invoicePaymentApi.createPurchaseForInvoicePayment(account, invoice.getId(), account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), INVOICE_PAYMENT, callContext);
    final List<Payment> accountPayments2 = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext);
    assertEquals(accountPayments2.size(), 1);
    final Payment payment2 = accountPayments2.get(0);
    assertEquals(payment2.getTransactions().size(), 2);
    assertEquals(payment2.getTransactions().get(0).getExternalKey(), transactionExternalKey);
    assertEquals(payment2.getTransactions().get(0).getTransactionStatus(), TransactionStatus.PLUGIN_FAILURE);
    assertEquals(payment2.getTransactions().get(0).getTransactionType(), TransactionType.PURCHASE);
    assertEquals(payment2.getTransactions().get(1).getExternalKey(), transactionExternalKey);
    assertEquals(payment2.getTransactions().get(1).getTransactionStatus(), TransactionStatus.SUCCESS);
    assertEquals(payment2.getTransactions().get(1).getTransactionType(), TransactionType.PURCHASE);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) MockRecurringInvoiceItem(org.killbill.billing.payment.MockRecurringInvoiceItem) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 8 with MockRecurringInvoiceItem

use of org.killbill.billing.payment.MockRecurringInvoiceItem in project killbill by killbill.

the class TestPaymentApi method testCreateSuccessRefundPaymentControlWithItemAdjustments.

@Test(groups = "slow")
public void testCreateSuccessRefundPaymentControlWithItemAdjustments() throws PaymentApiException, InvoiceApiException, EventBusException {
    final BigDecimal requestedAmount = BigDecimal.TEN;
    final UUID subscriptionId = UUID.randomUUID();
    final UUID bundleId = UUID.randomUUID();
    final LocalDate now = clock.getUTCToday();
    final Invoice invoice = testHelper.createTestInvoice(account, now, Currency.USD);
    final String paymentExternalKey = invoice.getId().toString();
    final String transactionExternalKey = "hopla";
    final String transactionExternalKey2 = "chouette";
    final InvoiceItem invoiceItem = new MockRecurringInvoiceItem(invoice.getId(), account.getId(), subscriptionId, bundleId, "test plan", "test phase", null, now, now.plusMonths(1), requestedAmount, new BigDecimal("1.0"), Currency.USD);
    invoice.addInvoiceItem(invoiceItem);
    invoicePaymentApi.createPurchaseForInvoicePayment(account, invoice.getId(), account.getPaymentMethodId(), null, requestedAmount, Currency.USD, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), INVOICE_PAYMENT, callContext);
    final Payment payment = paymentApi.getPaymentByExternalKey(paymentExternalKey, false, false, ImmutableList.<PluginProperty>of(), callContext);
    final List<PluginProperty> refundProperties = new ArrayList<PluginProperty>();
    final HashMap<UUID, BigDecimal> uuidBigDecimalHashMap = new HashMap<UUID, BigDecimal>();
    uuidBigDecimalHashMap.put(invoiceItem.getId(), null);
    invoicePaymentApi.createRefundForInvoicePayment(true, uuidBigDecimalHashMap, account, payment.getId(), null, Currency.USD, null, transactionExternalKey2, refundProperties, INVOICE_PAYMENT, callContext);
    final Payment payment2 = paymentApi.getPayment(payment.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext);
    assertEquals(payment2.getTransactions().size(), 2);
    assertEquals(payment2.getExternalKey(), paymentExternalKey);
    assertEquals(payment2.getPaymentMethodId(), account.getPaymentMethodId());
    assertEquals(payment2.getAccountId(), account.getId());
    assertEquals(payment2.getAuthAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(payment2.getCapturedAmount().compareTo(BigDecimal.ZERO), 0);
    assertEquals(payment2.getPurchasedAmount().compareTo(requestedAmount), 0);
    assertEquals(payment2.getRefundedAmount().compareTo(requestedAmount), 0);
    assertEquals(payment2.getCurrency(), Currency.USD);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) MockRecurringInvoiceItem(org.killbill.billing.payment.MockRecurringInvoiceItem) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MockRecurringInvoiceItem(org.killbill.billing.payment.MockRecurringInvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

BigDecimal (java.math.BigDecimal)8 UUID (java.util.UUID)8 LocalDate (org.joda.time.LocalDate)8 Invoice (org.killbill.billing.invoice.api.Invoice)8 MockRecurringInvoiceItem (org.killbill.billing.payment.MockRecurringInvoiceItem)8 Test (org.testng.annotations.Test)7 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PaymentControlApiException (org.killbill.billing.control.plugin.api.PaymentControlApiException)1 PaymentAttemptModelDao (org.killbill.billing.payment.dao.PaymentAttemptModelDao)1