Search in sources :

Example 1 with Payment

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

the class TestAccountTimeline method testAccountTimelineWithAudits.

@Test(groups = "slow", description = "Can retrieve the timeline with audits")
public void testAccountTimelineWithAudits() throws Exception {
    final DateTime startTime = clock.getUTCNow();
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final DateTime endTime = clock.getUTCNow();
    // Add credit
    final Invoice invoice = killBillClient.getInvoicesForAccount(accountJson.getAccountId()).get(1);
    final BigDecimal creditAmount = BigDecimal.ONE;
    final Credit credit = new Credit();
    credit.setAccountId(accountJson.getAccountId());
    credit.setCreditAmount(creditAmount);
    killBillClient.createCredit(credit, true, createdBy, reason, comment);
    // Add refund
    final Payment postedPayment = killBillClient.getPaymentsForAccount(accountJson.getAccountId()).get(0);
    final BigDecimal refundAmount = BigDecimal.ONE;
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(postedPayment.getPaymentId());
    refund.setAmount(refundAmount);
    killBillClient.createInvoicePaymentRefund(refund, createdBy, reason, comment);
    // Add chargeback
    final BigDecimal chargebackAmount = BigDecimal.ONE;
    final InvoicePaymentTransaction chargeback = new InvoicePaymentTransaction();
    chargeback.setPaymentId(postedPayment.getPaymentId());
    chargeback.setAmount(chargebackAmount);
    killBillClient.createInvoicePaymentChargeback(chargeback, createdBy, reason, comment);
    // Verify payments
    verifyPayments(accountJson.getAccountId(), startTime, endTime, refundAmount, chargebackAmount);
    // Verify invoices
    verifyInvoices(accountJson.getAccountId(), startTime, endTime);
    // Verify credits
    verifyCredits(accountJson.getAccountId(), startTime, endTime, creditAmount);
    // Verify bundles
    verifyBundles(accountJson.getAccountId(), startTime, endTime);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) Invoice(org.killbill.billing.client.model.Invoice) Credit(org.killbill.billing.client.model.Credit) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 2 with Payment

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

the class TestPaymentPluginProperties method testInternal.

private void testInternal(final Map<String, String> queryProperties, final List<PluginProperty> bodyProperties, final List<org.killbill.billing.payment.api.PluginProperty> expectProperties) throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    final BigDecimal amount = BigDecimal.TEN;
    final String pending = PaymentPluginStatus.PENDING.toString();
    final ImmutableMap<String, String> pluginProperties = ImmutableMap.<String, String>of(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, pending);
    TransactionType transactionType = TransactionType.AUTHORIZE;
    final String paymentExternalKey = UUID.randomUUID().toString();
    final String authTransactionExternalKey = UUID.randomUUID().toString();
    final Payment initialPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, transactionType, amount, pluginProperties);
    mockPaymentControlProviderPlugin.setExpectPluginProperties(expectProperties);
    // Complete operation: first, only specify the payment id
    final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
    completeTransactionByPaymentId.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentId.setProperties(bodyProperties);
    final RequestOptions basicRequestOptions = requestOptions;
    final Multimap<String, String> params = LinkedListMultimap.create(basicRequestOptions.getQueryParams());
    params.putAll(KillBillHttpClient.CONTROL_PLUGIN_NAME, ImmutableList.<String>of(PluginPropertiesVerificator.PLUGIN_NAME));
    final RequestOptions requestOptionsWithParams = basicRequestOptions.extend().withQueryParams(params).build();
    killBillClient.completePayment(completeTransactionByPaymentId, queryProperties, requestOptionsWithParams);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) Account(org.killbill.billing.client.model.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) Payment(org.killbill.billing.client.model.Payment) RequestOptions(org.killbill.billing.client.RequestOptions) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal)

Example 3 with Payment

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

the class TestInvoicePayment method testRetrievePayment.

@Test(groups = "slow")
public void testRetrievePayment() throws Exception {
    final InvoicePayment paymentJson = setupScenarioWithPayment();
    final Payment retrievedPaymentJson = killBillClient.getPayment(paymentJson.getPaymentId(), false);
    Assert.assertTrue(retrievedPaymentJson.equals((Payment) paymentJson));
}
Also used : InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) Test(org.testng.annotations.Test)

Example 4 with Payment

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

the class TestInvoicePayment method testPartialRefundWithInvoiceItemAdjustment.

@Test(groups = "slow", description = "Can create a partial refund with invoice item adjustment")
public void testPartialRefundWithInvoiceItemAdjustment() throws Exception {
    final InvoicePayment paymentJson = setupScenarioWithPayment();
    // Get the individual items for the invoice
    final Invoice invoice = killBillClient.getInvoice(paymentJson.getTargetInvoiceId(), true);
    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 = BigDecimal.ZERO;
    // Post and verify the refund
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(paymentJson.getPaymentId());
    refund.setIsAdjusted(true);
    final InvoiceItem adjustment = new InvoiceItem();
    adjustment.setInvoiceItemId(itemToAdjust.getInvoiceItemId());
    adjustment.setAmount(refundAmount);
    refund.setAdjustments(ImmutableList.<InvoiceItem>of(adjustment));
    final Payment paymentAfterRefundJson = killBillClient.createInvoicePaymentRefund(refund, createdBy, reason, comment);
    verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
    // Verify the invoice balance
    verifyInvoice(paymentJson, expectedInvoiceBalance);
}
Also used : InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) Invoice(org.killbill.billing.client.model.Invoice) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 5 with Payment

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

the class TestInvoicePayment method testPaymentsAndRefundsPagination.

@Test(groups = "slow", description = "Can paginate through all payments and refunds")
public void testPaymentsAndRefundsPagination() throws Exception {
    InvoicePayment lastPayment = setupScenarioWithPayment();
    for (int i = 0; i < 5; i++) {
        final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
        refund.setPaymentId(lastPayment.getPaymentId());
        refund.setAmount(lastPayment.getPurchasedAmount());
        killBillClient.createInvoicePaymentRefund(refund, createdBy, reason, comment);
        final InvoicePayment invoicePayment = new InvoicePayment();
        invoicePayment.setPurchasedAmount(lastPayment.getPurchasedAmount());
        invoicePayment.setAccountId(lastPayment.getAccountId());
        invoicePayment.setTargetInvoiceId(lastPayment.getTargetInvoiceId());
        final InvoicePayment payment = killBillClient.createInvoicePayment(invoicePayment, false, createdBy, reason, comment);
        lastPayment = payment;
    }
    final InvoicePayments allPayments = killBillClient.getInvoicePaymentsForAccount(lastPayment.getAccountId());
    Assert.assertEquals(allPayments.size(), 6);
    final List<PaymentTransaction> objRefundFromJson = getPaymentTransactions(allPayments, TransactionType.REFUND.toString());
    Assert.assertEquals(objRefundFromJson.size(), 5);
    Payments paymentsPage = killBillClient.getPayments(0L, 1L);
    for (int i = 0; i < 6; i++) {
        Assert.assertNotNull(paymentsPage);
        Assert.assertEquals(paymentsPage.size(), 1);
        Assert.assertTrue(paymentsPage.get(0).equals((Payment) allPayments.get(i)));
        paymentsPage = paymentsPage.getNext();
    }
    Assert.assertNull(paymentsPage);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Test(org.testng.annotations.Test)

Aggregations

Payment (org.killbill.billing.client.model.Payment)42 Test (org.testng.annotations.Test)35 Account (org.killbill.billing.client.model.Account)24 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)19 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)18 BigDecimal (java.math.BigDecimal)17 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)15 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)15 UUID (java.util.UUID)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)8 Payments (org.killbill.billing.client.model.Payments)8 TransactionType (org.killbill.billing.payment.api.TransactionType)8 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)7 DateTime (org.joda.time.DateTime)6 KillBillClientException (org.killbill.billing.client.KillBillClientException)5 Invoice (org.killbill.billing.client.model.Invoice)4 Invoices (org.killbill.billing.client.model.Invoices)4 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)4 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)4 RequestOptions (org.killbill.billing.client.RequestOptions)2