use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestExternalRefund method testManualPaymentAndExternalRefund.
@Test(groups = "slow", description = "#255 - Scenario 1 - Can refund a manual payment though an external refund")
public void testManualPaymentAndExternalRefund() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account accountJson = createAccountWithExternalPMBundleAndSubscriptionAndManualPayTagAndWaitForFirstInvoice();
final Invoices invoicesForAccount = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
final Invoice unpaidInvoice = invoicesForAccount.get(1);
assertEquals(unpaidInvoice.getBalance().compareTo(BigDecimal.valueOf(249.95)), 0);
final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(paymentsForAccount.size(), 0);
final InvoicePayment invoicePaymentRequest = new InvoicePayment();
invoicePaymentRequest.setTargetInvoiceId(unpaidInvoice.getInvoiceId());
invoicePaymentRequest.setAccountId(accountJson.getAccountId());
invoicePaymentRequest.setCurrency(unpaidInvoice.getCurrency());
invoicePaymentRequest.setPurchasedAmount(unpaidInvoice.getAmount());
final InvoicePayment invoicePayment = invoiceApi.createInstantPayment(unpaidInvoice.getInvoiceId(), invoicePaymentRequest, true, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(invoicePayment.getPurchasedAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
assertEquals(invoicePayment.getRefundedAmount().compareTo(BigDecimal.ZERO), 0);
final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
invoicePaymentTransactionRequest.setPaymentId(invoicePayment.getPaymentId());
final InvoicePayment invoicePaymentRefund = invoicePaymentApi.createRefundWithAdjustments(invoicePayment.getPaymentId(), invoicePaymentTransactionRequest, invoicePayment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(invoicePaymentRefund);
assertSingleInvoicePaymentRefund(invoicePaymentRefund);
assertRefundInvoiceNoAdjustments(accountJson.getAccountId());
assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.valueOf(249.95), BigDecimal.ZERO);
}
use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestInvoiceItem method testCustomFields.
@Test(groups = "slow", description = "Add custom fields to invoice item")
public void testCustomFields() throws Exception {
final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
final Invoices invoicesJson = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
Assert.assertNotNull(invoicesJson);
Assert.assertEquals(invoicesJson.size(), 2);
final List<InvoiceItem> invoiceItems = invoicesJson.get(0).getItems();
Assert.assertNotNull(invoiceItems);
final CustomFields customFields = new CustomFields();
customFields.add(new CustomField(null, invoiceItems.get(0).getInvoiceItemId(), ObjectType.INVOICE_ITEM, "1", "value1", null));
customFields.add(new CustomField(null, invoiceItems.get(0).getInvoiceItemId(), ObjectType.INVOICE_ITEM, "2", "value2", null));
customFields.add(new CustomField(null, invoiceItems.get(0).getInvoiceItemId(), ObjectType.INVOICE_ITEM, "3", "value3", null));
invoiceItemApi.createInvoiceItemCustomFields(invoiceItems.get(0).getInvoiceItemId(), customFields, requestOptions);
final List<CustomField> invoiceItemCustomFields = invoiceItemApi.getInvoiceItemCustomFields(invoiceItems.get(0).getInvoiceItemId(), requestOptions);
Assert.assertEquals(invoiceItemCustomFields.size(), 3);
// Delete all custom fields for account
invoiceItemApi.deleteInvoiceItemCustomFields(invoiceItems.get(0).getInvoiceItemId(), null, requestOptions);
final List<CustomField> remainingCustomFields = invoiceItemApi.getInvoiceItemCustomFields(invoiceItems.get(0).getInvoiceItemId(), requestOptions);
Assert.assertEquals(remainingCustomFields.size(), 0);
}
use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestInvoiceItem method testTags.
@Test(groups = "slow", description = "Add tags to invoice item")
public void testTags() throws Exception {
final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
final Invoices invoicesJson = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
Assert.assertNotNull(invoicesJson);
Assert.assertEquals(invoicesJson.size(), 2);
final List<InvoiceItem> invoiceItems = invoicesJson.get(0).getItems();
Assert.assertNotNull(invoiceItems);
// Create tag definition
final TagDefinition input = new TagDefinition(null, false, "tagtest", "invoice item tag test", ImmutableList.<ObjectType>of(ObjectType.INVOICE_ITEM), null);
final TagDefinition objFromJson = tagDefinitionApi.createTagDefinition(input, requestOptions);
Assert.assertNotNull(objFromJson);
Assert.assertEquals(objFromJson.getName(), input.getName());
Assert.assertEquals(objFromJson.getDescription(), input.getDescription());
// Add a tag
final Multimap<String, String> followQueryParams = HashMultimap.create();
followQueryParams.put(JaxrsResource.QUERY_ACCOUNT_ID, accountJson.getAccountId().toString());
final RequestOptions followRequestOptions = requestOptions.extend().withQueryParamsForFollow(followQueryParams).build();
invoiceItemApi.createInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), ImmutableList.<UUID>of(objFromJson.getId()), followRequestOptions);
// Retrieves all tags
final List<Tag> tags1 = invoiceItemApi.getInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), accountJson.getAccountId(), null, AuditLevel.FULL, requestOptions);
Assert.assertEquals(tags1.size(), 1);
Assert.assertEquals(tags1.get(0).getTagDefinitionId(), objFromJson.getId());
// Verify adding the same tag a second time doesn't do anything
invoiceItemApi.createInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), ImmutableList.<UUID>of(objFromJson.getId()), followRequestOptions);
// Retrieves all tags again
final List<Tag> tags2 = invoiceItemApi.getInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), accountJson.getAccountId(), null, AuditLevel.FULL, requestOptions);
Assert.assertEquals(tags2, tags1);
// Verify audit logs
Assert.assertEquals(tags2.get(0).getAuditLogs().size(), 1);
final AuditLog auditLogJson = tags2.get(0).getAuditLogs().get(0);
Assert.assertEquals(auditLogJson.getChangeType(), "INSERT");
Assert.assertEquals(auditLogJson.getChangedBy(), createdBy);
Assert.assertEquals(auditLogJson.getReasonCode(), reason);
Assert.assertEquals(auditLogJson.getComments(), comment);
Assert.assertNotNull(auditLogJson.getChangeDate());
Assert.assertNotNull(auditLogJson.getUserToken());
// remove it
invoiceItemApi.deleteInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), ImmutableList.<UUID>of(objFromJson.getId()), requestOptions);
final List<Tag> tags3 = invoiceItemApi.getInvoiceItemTags(invoiceItems.get(0).getInvoiceItemId(), accountJson.getAccountId(), null, AuditLevel.FULL, requestOptions);
Assert.assertEquals(tags3.size(), 0);
tagDefinitionApi.deleteTagDefinition(objFromJson.getId(), requestOptions);
List<TagDefinition> objsFromJson = tagDefinitionApi.getTagDefinitions(requestOptions);
Assert.assertNotNull(objsFromJson);
Boolean isFound = false;
for (TagDefinition tagDefinition : objsFromJson) {
isFound |= tagDefinition.getId().equals(objFromJson.getId());
}
Assert.assertFalse(isFound);
}
use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestInvoiceVoid method testParentVoidInvoice.
@Test(groups = "slow", description = "Void a parent invoice")
public void testParentVoidInvoice() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
final LocalDate triggeredDate = new LocalDate(2012, 5, 26);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account parentAccount = createAccount();
final Account childAccount1 = createAccount(parentAccount.getAccountId());
// Add a bundle and subscription
createSubscription(childAccount1.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
// trigger an invoice generation
callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_CREATION);
invoiceApi.createFutureInvoice(childAccount1.getAccountId(), triggeredDate, requestOptions);
callbackServlet.assertListenerStatus();
List<Invoice> child1Invoices = accountApi.getInvoicesForAccount(childAccount1.getAccountId(), null, null, false, false, true, null, AuditLevel.NONE, requestOptions);
assertEquals(child1Invoices.size(), 2);
// move one day so that the parent invoice is committed
callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_FAILED);
clock.addDays(1);
callbackServlet.assertListenerStatus();
List<Invoice> parentInvoices = accountApi.getInvoicesForAccount(parentAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(parentInvoices.size(), 1);
// try to void parent invoice
callbackServlet.pushExpectedEvent(ExtBusEventType.INVOICE_ADJUSTMENT);
invoiceApi.voidInvoice(parentInvoices.get(0).getInvoiceId(), requestOptions);
callbackServlet.assertListenerStatus();
// move the clock 1 month to check if invoices change
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE);
clock.addDays(31);
callbackServlet.assertListenerStatus();
// since the child did not have any change, the parent does not have an invoice
// after the void.
parentInvoices = accountApi.getInvoicesForAccount(parentAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(parentInvoices.size(), 0);
// the child does not have any change
child1Invoices = accountApi.getInvoicesForAccount(childAccount1.getAccountId(), null, null, false, false, true, null, AuditLevel.NONE, requestOptions);
assertEquals(child1Invoices.size(), 2);
}
use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestInvoiceVoid method testInvoiceVoid.
@Test(groups = "slow", description = "Can void an invoice")
public void testInvoiceVoid() throws Exception {
final Account accountJson = createAccountWithExternalPMBundleAndSubscriptionAndManualPayTagAndWaitForFirstInvoice();
assertNotNull(accountJson);
// Verify we didn't get any invoicePayment
final List<InvoicePayment> noPaymentsFromJson = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(noPaymentsFromJson.size(), 0);
// Get the invoices
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);
// verify account balance
Account account = accountApi.getAccount(accountJson.getAccountId(), true, true, AuditLevel.NONE, requestOptions);
assertEquals(account.getAccountBalance().compareTo(invoices.get(1).getBalance()), 0);
// void the invoice
callbackServlet.pushExpectedEvent(ExtBusEventType.INVOICE_ADJUSTMENT);
invoiceApi.voidInvoice(invoices.get(1).getInvoiceId(), requestOptions);
callbackServlet.assertListenerStatus();
// Get the invoices excluding voided
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
// the voided invoice should not be returned
assertEquals(invoices.size(), 1);
// Get the invoices including voided
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, true, null, AuditLevel.NONE, requestOptions);
assertEquals(invoices.size(), 2);
assertEquals(invoices.get(1).getStatus(), InvoiceStatus.VOID);
assertEquals(invoices.get(1).getBalance().compareTo(BigDecimal.ZERO), 0);
// check that account balance is zero
account = accountApi.getAccount(accountJson.getAccountId(), true, true, AuditLevel.NONE, requestOptions);
assertEquals(account.getAccountBalance().compareTo(BigDecimal.ZERO), 0);
// After invoice was voided verify the subscription is re-invoiced on a new invoice
// trigger an invoice generation
callbackServlet.pushExpectedEvent(ExtBusEventType.INVOICE_CREATION);
invoiceApi.createFutureInvoice(accountJson.getAccountId(), clock.getToday(DateTimeZone.forID(accountJson.getTimeZone())), requestOptions);
callbackServlet.assertListenerStatus();
// Get the invoices excluding voided
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
// the voided invoice should not be returned
assertEquals(invoices.size(), 2);
// process payment
final InvoicePayment invoicePayment = processPayment(accountJson, invoices.get(1), false);
// try to void invoice
try {
invoiceApi.voidInvoice(invoices.get(1).getInvoiceId(), requestOptions);
Assert.fail("VoidInvoice call should fail with 400");
} catch (final KillBillClientException e) {
assertTrue(true);
}
// refund payment
refundPayment(invoicePayment);
// Void invoice
callbackServlet.pushExpectedEvent(ExtBusEventType.INVOICE_ADJUSTMENT);
invoiceApi.voidInvoice(invoices.get(1).getInvoiceId(), requestOptions);
callbackServlet.assertListenerStatus();
// check that account balance is zero
account = accountApi.getAccount(accountJson.getAccountId(), true, true, AuditLevel.NONE, requestOptions);
assertEquals(account.getAccountBalance().compareTo(BigDecimal.ZERO), 0);
}
Aggregations