Search in sources :

Example 6 with Account

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

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

the class TestAdmin method testAdminInvoiceEndpoint.

@Test(groups = "slow")
public void testAdminInvoiceEndpoint() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final List<UUID> accounts = new LinkedList<UUID>();
    for (int i = 0; i < 5; i++) {
        final Account accountJson = createAccountWithDefaultPaymentMethod();
        assertNotNull(accountJson);
        accounts.add(accountJson.getAccountId());
        createEntitlement(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
        clock.addDays(2);
        crappyWaitForLackOfProperSynchonization();
        Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), i + 1);
        final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), false, false, false, AuditLevel.NONE, requestOptions);
        assertEquals(invoices.size(), 1);
    }
    // Trigger first non-trial invoice
    clock.addDays(32);
    crappyWaitForLackOfProperSynchonization();
    Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
    for (final UUID accountId : accounts) {
        final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountId, false, false, false, AuditLevel.NONE, requestOptions);
        assertEquals(invoices.size(), 2);
    }
    // Upload the config
    final ObjectMapper mapper = new ObjectMapper();
    final Map<String, String> perTenantProperties = new HashMap<String, String>();
    perTenantProperties.put("org.killbill.invoice.enabled", "false");
    final String perTenantConfig = mapper.writeValueAsString(perTenantProperties);
    killBillClient.postConfigurationPropertiesForTenant(perTenantConfig, requestOptions);
    crappyWaitForLackOfProperSynchonization();
    // Verify the second invoice isn't generated
    clock.addDays(32);
    crappyWaitForLackOfProperSynchonization();
    Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
    for (final UUID accountId : accounts) {
        final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountId, false, false, false, AuditLevel.NONE, requestOptions);
        assertEquals(invoices.size(), 2);
    }
    // Fix one account
    final Response response = triggerInvoiceGenerationForParkedAccounts(1);
    Assert.assertEquals(response.getResponseBody(), "{\"" + accounts.get(0) + "\":\"OK\"}");
    Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 11);
    // Fix all accounts
    final Response response2 = triggerInvoiceGenerationForParkedAccounts(5);
    final Map<String, String> fixedAccounts = mapper.readValue(response2.getResponseBody(), new TypeReference<Map<String, String>>() {
    });
    Assert.assertEquals(fixedAccounts.size(), 4);
    Assert.assertEquals(fixedAccounts.get(accounts.get(1).toString()), "OK");
    Assert.assertEquals(fixedAccounts.get(accounts.get(2).toString()), "OK");
    Assert.assertEquals(fixedAccounts.get(accounts.get(3).toString()), "OK");
    Assert.assertEquals(fixedAccounts.get(accounts.get(4).toString()), "OK");
    Assert.assertEquals(killBillClient.getInvoices(requestOptions).getPaginationMaxNbRecords(), 15);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) HashMap(java.util.HashMap) DateTime(org.joda.time.DateTime) LinkedList(java.util.LinkedList) Response(com.ning.http.client.Response) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 8 with Account

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

the class TestBundle method testBundleNonExistent.

@Test(groups = "slow", description = "Can handle non existent bundle")
public void testBundleNonExistent() throws Exception {
    final Account accountJson = createAccount();
    // ID
    Assert.assertNull(killBillClient.getBundle(UUID.randomUUID(), requestOptions));
    // External Key
    Assert.assertNull(killBillClient.getBundle(UUID.randomUUID().toString(), requestOptions));
    Assert.assertTrue(killBillClient.getAllBundlesForExternalKey(UUID.randomUUID().toString(), requestOptions).isEmpty());
    // Account Id
    Assert.assertTrue(killBillClient.getAccountBundles(accountJson.getAccountId(), "98374982743892", requestOptions).isEmpty());
    Assert.assertTrue(killBillClient.getAccountBundles(accountJson.getAccountId(), requestOptions).isEmpty());
}
Also used : Account(org.killbill.billing.client.model.Account) Test(org.testng.annotations.Test)

Example 9 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 10 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)

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