Search in sources :

Example 31 with Account

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

the class KillbillClient method createAccountWithExternalPMBundleAndSubscriptionAndManualPayTagAndWaitForFirstInvoice.

protected Account createAccountWithExternalPMBundleAndSubscriptionAndManualPayTagAndWaitForFirstInvoice() throws Exception {
    final Account accountJson = createAccountWithExternalPaymentMethod();
    assertNotNull(accountJson);
    final Tags accountTag = killBillClient.createAccountTag(accountJson.getAccountId(), ControlTagType.MANUAL_PAY.getId(), requestOptions);
    assertNotNull(accountTag);
    assertEquals(accountTag.get(0).getTagDefinitionId(), ControlTagType.MANUAL_PAY.getId());
    // Add a bundle, subscription and move the clock to get the first invoice
    final Subscription subscriptionJson = createEntitlement(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
    assertNotNull(subscriptionJson);
    clock.addDays(32);
    crappyWaitForLackOfProperSynchonization();
    return accountJson;
}
Also used : Account(org.killbill.billing.client.model.Account) Subscription(org.killbill.billing.client.model.Subscription) Tags(org.killbill.billing.client.model.Tags)

Example 32 with Account

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

the class TestAccount method testAccountWithBalance.

@Test(groups = "slow", description = "Can retrieve the account balance")
public void testAccountWithBalance() throws Exception {
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final Account accountWithBalance = killBillClient.getAccount(accountJson.getAccountId(), true, false, requestOptions);
    final BigDecimal accountBalance = accountWithBalance.getAccountBalance();
    Assert.assertTrue(accountBalance.compareTo(BigDecimal.ZERO) > 0);
}
Also used : Account(org.killbill.billing.client.model.Account) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 33 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 34 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 35 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)

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