use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestInvoice method testInvoiceTransferCreditAccountNoParent.
@Test(groups = "slow", description = "Fail to transfer credit from an account without parent account", expectedExceptions = KillBillClientException.class, expectedExceptionsMessageRegExp = ".* does not have a Parent Account associated")
public void testInvoiceTransferCreditAccountNoParent() throws Exception {
final Account account = createAccount();
// transfer credit to parent account
accountApi.transferChildCreditToParent(account.getAccountId(), requestOptions);
}
use of org.killbill.billing.client.model.gen.Account 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());
}
use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestExternalRefund method testAutomaticPaymentAndRefundWithAdjustments.
@Test(groups = "slow", description = "#255 - Scenario 0 - Can refund an automatic payment over item adjustments. This is a test to validate the correct behaviour.")
public void testAutomaticPaymentAndRefundWithAdjustments() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, true, false, false, null, AuditLevel.NONE, requestOptions);
final List<InvoiceItem> itemsToBeAdjusted = invoices.get(1).getItems();
// regular refund
final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency());
invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
invoicePaymentTransactionRequest.setIsAdjusted(true);
invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, payment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final InvoicePayment invoicePaymentRefund = invoicePaymentApi.getInvoicePayment(payment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(invoicePaymentRefund);
assertSingleInvoicePaymentRefund(invoicePaymentRefund);
assertRefundInvoiceAdjustments(accountJson.getAccountId());
assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestExternalRefund method testAutomaticPaymentAndExternalRefundWithDifferentPM.
@Test(groups = "slow", description = "#255 - Scenario 2b - Can refund an automatic payment though another existing payment method")
public void testAutomaticPaymentAndExternalRefundWithDifferentPM() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
// delete PM
paymentMethodApi.deletePaymentMethod(accountJson.getPaymentMethodId(), true, true, NULL_PLUGIN_PROPERTIES, requestOptions);
// create another PM
final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), accountJson.getAccountId(), false, PLUGIN_NAME, info, null);
final PaymentMethod otherPaymentMethod = accountApi.createPaymentMethod(accountJson.getAccountId(), paymentMethodJson, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
final Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, true, false, false, null, AuditLevel.NONE, requestOptions);
final List<InvoiceItem> itemsToBeAdjusted = invoices.get(1).getItems();
// external refund
final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency());
invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
invoicePaymentTransactionRequest.setIsAdjusted(true);
invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
final InvoicePayment invoicePaymentExternalRefund = invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, true, otherPaymentMethod.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(invoicePaymentExternalRefund);
assertEquals(invoicePaymentExternalRefund.getPaymentMethodId(), otherPaymentMethod.getPaymentMethodId());
assertInvoicePaymentsExternalRefund(accountJson.getAccountId(), invoicePaymentExternalRefund);
assertRefundInvoiceAdjustments(accountJson.getAccountId());
assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.
the class TestExternalRefund method testManualPaymentAndExternalRefundWithAdjustments.
@Test(groups = "slow", description = "#255 - Scenario 1 - Can refund a manual payment though an external refund over item adjustments")
public void testManualPaymentAndExternalRefundWithAdjustments() 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, false, false, false, null, AuditLevel.NONE, 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());
invoicePaymentTransactionRequest.setIsAdjusted(true);
invoicePaymentTransactionRequest.setAdjustments(unpaidInvoice.getItems());
final InvoicePayment invoicePaymentRefund = invoicePaymentApi.createRefundWithAdjustments(invoicePayment.getPaymentId(), invoicePaymentTransactionRequest, false, null, NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(invoicePaymentRefund);
assertSingleInvoicePaymentRefund(invoicePaymentRefund);
assertRefundInvoiceAdjustments(accountJson.getAccountId());
assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
Aggregations