Search in sources :

Example 81 with Account

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

the class TestTenantFilter method testTenantShouldOnlySeeOwnAccount.

@Test(groups = "slow")
public void testTenantShouldOnlySeeOwnAccount() throws Exception {
    // Try to create an account without being logged-in
    logoutTenant();
    try {
        killBillClient.createAccount(getAccount(), createdBy, reason, comment);
        Assert.fail();
    } catch (final KillBillClientException e) {
        Assert.assertEquals(e.getResponse().getStatusCode(), Status.UNAUTHORIZED.getStatusCode());
    }
    // Create the tenant
    final String apiKeyTenant1 = "pierre";
    final String apiSecretTenant1 = "pierreIsFr3nch";
    loginTenant(apiKeyTenant1, apiSecretTenant1);
    final Tenant tenant1 = new Tenant();
    tenant1.setApiKey(apiKeyTenant1);
    tenant1.setApiSecret(apiSecretTenant1);
    killBillClient.createTenant(tenant1, createdBy, reason, comment);
    final Account account1 = createAccount();
    Assert.assertEquals(killBillClient.getAccount(account1.getExternalKey()), account1);
    logoutTenant();
    // Create another tenant
    final String apiKeyTenant2 = "stephane";
    final String apiSecretTenant2 = "stephane1sAlsoFr3nch";
    loginTenant(apiKeyTenant2, apiSecretTenant2);
    final Tenant tenant2 = new Tenant();
    tenant2.setApiKey(apiKeyTenant2);
    tenant2.setApiSecret(apiSecretTenant2);
    killBillClient.createTenant(tenant2, createdBy, reason, comment);
    final Account account2 = createAccount();
    Assert.assertEquals(killBillClient.getAccount(account2.getExternalKey()), account2);
    // We should not be able to retrieve the first account as tenant2
    Assert.assertNull(killBillClient.getAccount(account1.getExternalKey()));
    // Same for tenant1 and account2
    loginTenant(apiKeyTenant1, apiSecretTenant1);
    Assert.assertNull(killBillClient.getAccount(account2.getExternalKey()));
}
Also used : Account(org.killbill.billing.client.model.Account) Tenant(org.killbill.billing.client.model.Tenant) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 82 with Account

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

the class TestInvoice method testFullInvoiceItemAdjustment.

@Test(groups = "slow", description = "Can fully adjust an invoice item")
public void testFullInvoiceItemAdjustment() 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 Invoice invoice = invoices.get(1);
    // Verify the invoice we picked is non zero
    assertEquals(invoice.getAmount().compareTo(BigDecimal.ZERO), 1);
    final InvoiceItem invoiceItem = invoice.getItems().get(0);
    // Verify the item we picked is non zero
    assertEquals(invoiceItem.getAmount().compareTo(BigDecimal.ZERO), 1);
    // Adjust the full amount
    final InvoiceItem adjustmentInvoiceItem = new InvoiceItem();
    adjustmentInvoiceItem.setAccountId(accountJson.getAccountId());
    adjustmentInvoiceItem.setInvoiceId(invoice.getInvoiceId());
    adjustmentInvoiceItem.setInvoiceItemId(invoiceItem.getInvoiceItemId());
    killBillClient.adjustInvoiceItem(invoiceItem, createdBy, reason, comment);
    // Verify the new invoice balance is zero
    final Invoice adjustedInvoice = killBillClient.getInvoice(invoice.getInvoiceId(), true, AuditLevel.FULL);
    assertEquals(adjustedInvoice.getAmount().compareTo(BigDecimal.ZERO), 0);
    // Verify invoice audit logs
    Assert.assertEquals(adjustedInvoice.getAuditLogs().size(), 1);
    final AuditLog invoiceAuditLogJson = adjustedInvoice.getAuditLogs().get(0);
    Assert.assertEquals(invoiceAuditLogJson.getChangeType(), "INSERT");
    Assert.assertEquals(invoiceAuditLogJson.getChangedBy(), "SubscriptionBaseTransition");
    Assert.assertNotNull(invoiceAuditLogJson.getChangeDate());
    Assert.assertNotNull(invoiceAuditLogJson.getUserToken());
    Assert.assertNull(invoiceAuditLogJson.getReasonCode());
    Assert.assertNull(invoiceAuditLogJson.getComments());
    Assert.assertEquals(adjustedInvoice.getItems().size(), 2);
    // Verify invoice items audit logs
    // The first item is the original item
    Assert.assertEquals(adjustedInvoice.getItems().get(0).getAuditLogs().size(), 1);
    final AuditLog itemAuditLogJson = adjustedInvoice.getItems().get(0).getAuditLogs().get(0);
    Assert.assertEquals(itemAuditLogJson.getChangeType(), "INSERT");
    Assert.assertEquals(itemAuditLogJson.getChangedBy(), "SubscriptionBaseTransition");
    Assert.assertNotNull(itemAuditLogJson.getChangeDate());
    Assert.assertNotNull(itemAuditLogJson.getUserToken());
    Assert.assertNull(itemAuditLogJson.getReasonCode());
    Assert.assertNull(itemAuditLogJson.getComments());
    // The second one is the adjustment
    Assert.assertEquals(adjustedInvoice.getItems().get(1).getAuditLogs().size(), 1);
    final AuditLog adjustedItemAuditLogJson = adjustedInvoice.getItems().get(1).getAuditLogs().get(0);
    Assert.assertEquals(adjustedItemAuditLogJson.getChangeType(), "INSERT");
    Assert.assertEquals(adjustedItemAuditLogJson.getChangedBy(), createdBy);
    Assert.assertEquals(adjustedItemAuditLogJson.getReasonCode(), reason);
    Assert.assertEquals(adjustedItemAuditLogJson.getComments(), comment);
    Assert.assertNotNull(adjustedItemAuditLogJson.getChangeDate());
    Assert.assertNotNull(adjustedItemAuditLogJson.getUserToken());
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) AuditLog(org.killbill.billing.client.model.AuditLog) Test(org.testng.annotations.Test)

Example 83 with Account

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

the class TestInvoice method testExternalChargesWithSameInvoiceAndExternalKeys.

@Test(groups = "slow", description = "Can create multiple external charges with same invoice and external keys")
public void testExternalChargesWithSameInvoiceAndExternalKeys() throws Exception {
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId()).size(), 2);
    // Post an external charge
    final BigDecimal chargeAmount = BigDecimal.TEN;
    final List<InvoiceItem> externalCharges = new ArrayList<InvoiceItem>();
    // Does not pass currency to test on purpose that we will default to account currency
    final InvoiceItem externalCharge1 = new InvoiceItem();
    externalCharge1.setAccountId(accountJson.getAccountId());
    externalCharge1.setAmount(chargeAmount);
    externalCharge1.setDescription(UUID.randomUUID().toString());
    externalCharges.add(externalCharge1);
    final InvoiceItem externalCharge2 = new InvoiceItem();
    externalCharge2.setAccountId(accountJson.getAccountId());
    externalCharge2.setAmount(chargeAmount);
    externalCharge2.setCurrency(accountJson.getCurrency());
    externalCharge2.setDescription(UUID.randomUUID().toString());
    externalCharges.add(externalCharge2);
    String paymentExternalKey = "anyPaymentExternalKey";
    String transactionExternalKey = "anyTransactionExternalKey";
    final List<InvoiceItem> createdExternalCharges = killBillClient.createExternalCharges(externalCharges, clock.getUTCToday(), true, true, paymentExternalKey, transactionExternalKey, RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).build());
    assertEquals(createdExternalCharges.size(), 2);
    assertEquals(createdExternalCharges.get(0).getCurrency().toString(), accountJson.getCurrency());
    assertEquals(createdExternalCharges.get(1).getCurrency().toString(), accountJson.getCurrency());
    // Verify the total number of invoices
    assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId()).size(), 3);
    Payments payments = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), AuditLevel.NONE, RequestOptions.empty());
    assertNotNull(payments);
    // Verify payment with paymentExternalKey provided
    assertEquals(payments.get(payments.size() - 1).getPaymentExternalKey(), paymentExternalKey);
    // Verify transactions with transactionExternalKey provided
    assertEquals(payments.get(payments.size() - 1).getTransactions().get(0).getTransactionExternalKey(), transactionExternalKey);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) ArrayList(java.util.ArrayList) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 84 with Account

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

the class TestInvoice method testExternalChargeForBundleOnNewInvoice.

@Test(groups = "slow", description = "Can create an external charge for a bundle")
public void testExternalChargeForBundleOnNewInvoice() throws Exception {
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId()).size(), 2);
    // 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.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.getBalance().compareTo(chargeAmount), 0);
    assertEquals(invoiceWithItems.getItems().size(), 1);
    assertEquals(invoiceWithItems.getItems().get(0).getBundleId(), bundleId);
    // Verify the total number of invoices
    assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId()).size(), 3);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) Invoice(org.killbill.billing.client.model.Invoice) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 85 with Account

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

the class TestInvoiceNotification method createScenarioWithOneInvoice.

private Account createScenarioWithOneInvoice() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    Assert.assertNotNull(accountJson);
    final Subscription subscriptionJson = createEntitlement(accountJson.getAccountId(), "76213", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, true);
    Assert.assertNotNull(subscriptionJson);
    return accountJson;
}
Also used : Account(org.killbill.billing.client.model.Account) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime)

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