use of org.killbill.billing.client.model.gen.Invoice 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());
createSubscription(accountJson.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
clock.addDays(2);
Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), i + 1);
final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(invoices.size(), 1);
}
// Trigger first non-trial invoice
for (int i = 0; i < 5; i++) {
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
}
clock.addDays(32);
callbackServlet.assertListenerStatus();
Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
for (final UUID accountId : accounts) {
final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountId, null, null, false, false, false, null, 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);
callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_CHANGE);
tenantApi.uploadPerTenantConfiguration(perTenantConfig, requestOptions);
callbackServlet.assertListenerStatus();
// Verify the second invoice isn't generated
for (int i = 0; i < 5; i++) {
callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_CREATION);
}
clock.addDays(32);
callbackServlet.assertListenerStatus();
Assert.assertEquals(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 10);
for (final UUID accountId : accounts) {
final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountId, null, null, false, false, false, null, 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(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 11);
// Fix all accounts
final Response response2 = triggerInvoiceGenerationForParkedAccounts(4);
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(invoiceApi.getInvoices(requestOptions).getPaginationMaxNbRecords(), 15);
}
use of org.killbill.billing.client.model.gen.Invoice 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 = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).get(1);
final BigDecimal creditAmount = BigDecimal.ONE;
final InvoiceItem credit = new InvoiceItem();
credit.setAccountId(accountJson.getAccountId());
credit.setAmount(creditAmount);
final InvoiceItems credits = new InvoiceItems();
credits.add(credit);
creditApi.createCredits(credits, true, NULL_PLUGIN_PROPERTIES, requestOptions);
// Add refund
final Payment postedPayment = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions).get(0);
final BigDecimal refundAmount = BigDecimal.ONE;
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(postedPayment.getPaymentId());
refund.setAmount(refundAmount);
invoicePaymentApi.createRefundWithAdjustments(postedPayment.getPaymentId(), refund, accountJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
// Add chargeback
final BigDecimal chargebackAmount = BigDecimal.ONE;
final InvoicePaymentTransaction chargeback = new InvoicePaymentTransaction();
chargeback.setPaymentId(postedPayment.getPaymentId());
chargeback.setAmount(chargebackAmount);
invoicePaymentApi.createChargeback(postedPayment.getPaymentId(), chargeback, NULL_PLUGIN_PROPERTIES, requestOptions);
// 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);
}
use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestInvoice method testExternalChargeOnNewInvoice.
@Test(groups = "slow", description = "Can create an external charge")
public void testExternalChargeOnNewInvoice() throws Exception {
final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Get the invoices
final Invoices originalInvoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(originalInvoices.size(), 2);
final UUID firstInvoiceItemId = originalInvoices.get(0).getItems().get(0).getInvoiceItemId();
// Post an external charge
final BigDecimal chargeAmount = BigDecimal.TEN;
final InvoiceItem externalCharge = new InvoiceItem();
externalCharge.setAccountId(accountJson.getAccountId());
externalCharge.setAmount(chargeAmount);
externalCharge.setCurrency(accountJson.getCurrency());
externalCharge.setPlanName("SomePlan");
externalCharge.setProductName("SomeProduct");
externalCharge.setDescription(UUID.randomUUID().toString());
externalCharge.setItemDetails("Item Details");
externalCharge.setLinkedInvoiceItemId(firstInvoiceItemId);
final LocalDate startDate = clock.getUTCToday();
externalCharge.setStartDate(startDate);
final LocalDate endDate = startDate.plusDays(10);
externalCharge.setEndDate(endDate);
final InvoiceItems itemsForCharge = new InvoiceItems();
itemsForCharge.add(externalCharge);
final List<InvoiceItem> createdExternalCharges = invoiceApi.createExternalCharges(accountJson.getAccountId(), itemsForCharge, clock.getUTCToday(), true, NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(createdExternalCharges.size(), 1);
final Invoice invoiceWithItems = invoiceApi.getInvoice(createdExternalCharges.get(0).getInvoiceId(), false, AuditLevel.NONE, requestOptions);
assertEquals(invoiceWithItems.getBalance().compareTo(chargeAmount), 0);
assertEquals(invoiceWithItems.getItems().size(), 1);
assertEquals(invoiceWithItems.getItems().get(0).getDescription(), externalCharge.getDescription());
assertNull(invoiceWithItems.getItems().get(0).getBundleId());
assertEquals(invoiceWithItems.getItems().get(0).getStartDate().compareTo(startDate), 0);
assertEquals(invoiceWithItems.getItems().get(0).getEndDate().compareTo(endDate), 0);
assertEquals(invoiceWithItems.getItems().get(0).getItemDetails(), "Item Details");
assertEquals(invoiceWithItems.getItems().get(0).getLinkedInvoiceItemId(), firstInvoiceItemId);
assertEquals(invoiceWithItems.getItems().get(0).getPlanName().compareTo("SomePlan"), 0);
assertEquals(invoiceWithItems.getItems().get(0).getProductName().compareTo("SomeProduct"), 0);
// Verify the total number of invoices
assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).size(), 3);
}
use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestInvoice method testAddTaxItemsOnNewInvoice.
@Test(groups = "slow", description = "Can create tax items for a bundle")
public void testAddTaxItemsOnNewInvoice() throws Exception {
final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Get the invoices
assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions).size(), 2);
// Post an external charge
final BigDecimal taxAmount = BigDecimal.TEN;
final UUID bundleId = UUID.randomUUID();
final InvoiceItem taxItem = new InvoiceItem();
taxItem.setAccountId(accountJson.getAccountId());
taxItem.setAmount(taxAmount);
taxItem.setCurrency(accountJson.getCurrency());
taxItem.setBundleId(bundleId);
final InvoiceItems input = new InvoiceItems();
input.add(taxItem);
final List<InvoiceItem> createdTaxItems = invoiceApi.createTaxItems(accountJson.getAccountId(), input, true, clock.getUTCToday(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(createdTaxItems.size(), 1);
final Invoice invoiceWithItems = invoiceApi.getInvoice(createdTaxItems.get(0).getInvoiceId(), null, AuditLevel.NONE, requestOptions);
assertEquals(invoiceWithItems.getBalance().compareTo(taxAmount), 0);
assertEquals(invoiceWithItems.getItems().size(), 1);
assertEquals(invoiceWithItems.getItems().get(0).getBundleId(), bundleId);
assertEquals(invoiceWithItems.getItems().get(0).getItemType(), InvoiceItemType.TAX);
// Verify the total number of invoices
assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).size(), 3);
}
use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestInvoice method testExternalPayment.
@Test(groups = "slow", description = "Can create an external payment")
public void testExternalPayment() throws Exception {
final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Verify we didn't get any invoicePayment
final List<InvoicePayment> noPaymentsFromJson = accountApi.getInvoicePayments(accountJson.getAccountId(), null, requestOptions);
assertEquals(noPaymentsFromJson.size(), 0);
// Get the invoices
final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
// 2 invoices but look for the non zero dollar one
assertEquals(invoices.size(), 2);
final UUID invoiceId = invoices.get(1).getInvoiceId();
// Post an external invoicePayment
final InvoicePayment invoicePayment = new InvoicePayment();
invoicePayment.setPurchasedAmount(BigDecimal.TEN);
invoicePayment.setAccountId(accountJson.getAccountId());
invoicePayment.setTargetInvoiceId(invoiceId);
invoiceApi.createInstantPayment(invoiceId, invoicePayment, true, ImmutableList.of(), null, requestOptions);
// Verify we indeed got the invoicePayment
final List<InvoicePayment> paymentsFromJson = accountApi.getInvoicePayments(accountJson.getAccountId(), null, requestOptions);
assertEquals(paymentsFromJson.size(), 1);
assertEquals(paymentsFromJson.get(0).getPurchasedAmount().compareTo(BigDecimal.TEN), 0);
assertEquals(paymentsFromJson.get(0).getTargetInvoiceId(), invoiceId);
// Check the PaymentMethod from paymentMethodId returned in the Payment object
final UUID paymentMethodId = paymentsFromJson.get(0).getPaymentMethodId();
final PaymentMethod paymentMethodJson = paymentMethodApi.getPaymentMethod(paymentMethodId, null, requestOptions);
assertEquals(paymentMethodJson.getPaymentMethodId(), paymentMethodId);
assertEquals(paymentMethodJson.getAccountId(), accountJson.getAccountId());
assertEquals(paymentMethodJson.getPluginName(), ExternalPaymentProviderPlugin.PLUGIN_NAME);
assertNull(paymentMethodJson.getPluginInfo());
}
Aggregations