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()));
}
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());
}
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);
}
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);
}
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;
}
Aggregations