Search in sources :

Example 36 with Account

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

the class TestPaymentMethod method testGePaymentMethodsByKey.

@Test(groups = "slow", description = "Create/retrieve by externalKey")
public void testGePaymentMethodsByKey() throws Exception {
    final Account accountJson = createAccountWithDefaultPaymentMethod("foo");
    final PaymentMethod paymentMethodJson1 = killBillClient.getPaymentMethodByKey("foo", true);
    final PaymentMethod paymentMethodJson2 = killBillClient.getPaymentMethod(accountJson.getPaymentMethodId(), true);
    Assert.assertEquals(paymentMethodJson1, paymentMethodJson2);
    final PaymentMethod paymentMethodJson3 = killBillClient.getPaymentMethodByKey("doesnotexist", true);
    Assert.assertNull(paymentMethodJson3);
}
Also used : Account(org.killbill.billing.client.model.Account) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) Test(org.testng.annotations.Test)

Example 37 with Account

use of org.killbill.billing.client.model.Account 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 38 with Account

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

the class TestPerTenantConfig method testFailedPaymentWithPerTenantRetryConfig.

@Test(groups = "slow")
public void testFailedPaymentWithPerTenantRetryConfig() throws Exception {
    // Create the tenant
    final String apiKeyTenant1 = "tenantSuperTuned";
    final String apiSecretTenant1 = "2367$$ffr79";
    loginTenant(apiKeyTenant1, apiSecretTenant1);
    final Tenant tenant1 = new Tenant();
    tenant1.setApiKey(apiKeyTenant1);
    tenant1.setApiSecret(apiSecretTenant1);
    killBillClient.createTenant(tenant1, createdBy, reason, comment);
    // Configure our plugin to fail
    mockPaymentProviderPlugin.makeAllInvoicesFailWithError(true);
    // Upload the config
    final ObjectMapper mapper = new ObjectMapper();
    final HashMap<String, String> perTenantProperties = new HashMap<String, String>();
    perTenantProperties.put("org.killbill.payment.retry.days", "1,1,1");
    final String perTenantConfig = mapper.writeValueAsString(perTenantProperties);
    final TenantKey tenantKey = killBillClient.postConfigurationPropertiesForTenant(perTenantConfig, requestOptions);
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final Payments payments = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments.size(), 1);
    Assert.assertEquals(payments.get(0).getTransactions().size(), 1);
    //
    // Because we have specified a retry interval of one day we should see the new attempt after moving clock 1 day (and not 8 days which is default)
    //
    //
    // Now unregister special per tenant config and we the first retry occurs one day after (and still fails), it now sets a retry date of 8 days
    //
    killBillClient.unregisterConfigurationForTenant(requestOptions);
    // org.killbill.tenant.broadcast.rate has been set to 1s
    crappyWaitForLackOfProperSynchonization(2000);
    clock.addDays(1);
    Awaitility.await().atMost(4, TimeUnit.SECONDS).pollInterval(Duration.ONE_SECOND).until(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return killBillClient.getPaymentsForAccount(accountJson.getAccountId()).get(0).getTransactions().size() == 2;
        }
    });
    final Payments payments2 = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments2.size(), 1);
    Assert.assertEquals(payments2.get(0).getTransactions().size(), 2);
    Assert.assertEquals(payments2.get(0).getTransactions().get(0).getStatus(), TransactionStatus.PAYMENT_FAILURE.name());
    Assert.assertEquals(payments2.get(0).getTransactions().get(1).getStatus(), TransactionStatus.PAYMENT_FAILURE.name());
    clock.addDays(1);
    crappyWaitForLackOfProperSynchonization(3000);
    // No retry with default config
    final Payments payments3 = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments3.size(), 1);
    Assert.assertEquals(payments3.get(0).getTransactions().size(), 2);
    mockPaymentProviderPlugin.makeAllInvoicesFailWithError(false);
    clock.addDays(7);
    Awaitility.await().atMost(4, TimeUnit.SECONDS).pollInterval(Duration.ONE_SECOND).until(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return killBillClient.getPaymentsForAccount(accountJson.getAccountId()).get(0).getTransactions().size() == 3;
        }
    });
    final Payments payments4 = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments4.size(), 1);
    Assert.assertEquals(payments4.get(0).getTransactions().size(), 3);
    Assert.assertEquals(payments4.get(0).getTransactions().get(0).getStatus(), TransactionStatus.PAYMENT_FAILURE.name());
    Assert.assertEquals(payments4.get(0).getTransactions().get(1).getStatus(), TransactionStatus.PAYMENT_FAILURE.name());
    Assert.assertEquals(payments4.get(0).getTransactions().get(2).getStatus(), TransactionStatus.SUCCESS.name());
}
Also used : Account(org.killbill.billing.client.model.Account) Tenant(org.killbill.billing.client.model.Tenant) HashMap(java.util.HashMap) TenantKey(org.killbill.billing.client.model.TenantKey) Payments(org.killbill.billing.client.model.Payments) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 39 with Account

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

the class TestInvoice method testExternalChargeForBundleOnExistingInvoice.

@Test(groups = "slow", description = "Can create an external charge for a bundle on an existing invoice")
public void testExternalChargeForBundleOnExistingInvoice() throws Exception {
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    final UUID invoiceId = invoices.get(1).getInvoiceId();
    final BigDecimal originalInvoiceAmount = invoices.get(1).getAmount();
    final int originalNumberOfItemsForInvoice = invoices.get(1).getItems().size();
    // Post an external charge
    final BigDecimal chargeAmount = BigDecimal.TEN;
    final UUID bundleId = UUID.randomUUID();
    final InvoiceItem externalCharge = new InvoiceItem();
    externalCharge.setAccountId(accountJson.getAccountId());
    externalCharge.setAmount(chargeAmount);
    externalCharge.setCurrency(accountJson.getCurrency());
    externalCharge.setInvoiceId(invoiceId);
    externalCharge.setBundleId(bundleId);
    final InvoiceItem createdExternalCharge = killBillClient.createExternalCharge(externalCharge, clock.getUTCToday(), false, true, createdBy, reason, comment);
    final Invoice invoiceWithItems = killBillClient.getInvoice(createdExternalCharge.getInvoiceId(), true);
    assertEquals(invoiceWithItems.getItems().size(), originalNumberOfItemsForInvoice + 1);
    assertEquals(invoiceWithItems.getItems().get(originalNumberOfItemsForInvoice).getBundleId(), bundleId);
    // Verify the new invoice balance
    final Invoice adjustedInvoice = killBillClient.getInvoice(invoiceId);
    final BigDecimal adjustedInvoiceBalance = originalInvoiceAmount.add(chargeAmount.setScale(2, RoundingMode.HALF_UP));
    assertEquals(adjustedInvoice.getBalance().compareTo(adjustedInvoiceBalance), 0);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 40 with Account

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

the class TestInvoice method testPayAllInvoices.

@Test(groups = "slow", description = "Can pay invoices")
public void testPayAllInvoices() throws Exception {
    clock.setTime(new DateTime(2012, 4, 25, 0, 3, 42, 0));
    // No payment method
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Check there was no payment made
    assertEquals(killBillClient.getPaymentsForAccount(accountJson.getAccountId()).size(), 0);
    // Get the invoices
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId());
    assertEquals(invoices.size(), 2);
    final Invoice invoiceToPay = invoices.get(1);
    assertEquals(invoiceToPay.getBalance().compareTo(BigDecimal.ZERO), 1);
    // Pay all invoices
    killBillClient.payAllInvoices(accountJson.getAccountId(), true, null, createdBy, reason, comment);
    for (final Invoice invoice : killBillClient.getInvoicesForAccount(accountJson.getAccountId())) {
        assertEquals(invoice.getBalance().compareTo(BigDecimal.ZERO), 0);
    }
    assertEquals(killBillClient.getPaymentsForAccount(accountJson.getAccountId()).size(), 1);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.Account)123 Test (org.testng.annotations.Test)109 UUID (java.util.UUID)32 DateTime (org.joda.time.DateTime)32 Invoice (org.killbill.billing.client.model.Invoice)30 BigDecimal (java.math.BigDecimal)27 Payment (org.killbill.billing.client.model.Payment)24 Subscription (org.killbill.billing.client.model.Subscription)24 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)17 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)16 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)16 KillBillClientException (org.killbill.billing.client.KillBillClientException)14 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)14 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)13 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)10 Payments (org.killbill.billing.client.model.Payments)10 Tags (org.killbill.billing.client.model.Tags)10 Invoices (org.killbill.billing.client.model.Invoices)9 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)9