use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction in project killbill by killbill.
the class TestExternalRefund method testAutomaticPaymentAndExternalRefund.
@Test(groups = "slow", description = "#255 - Scenario 2a - Can refund an automatic payment though an external refund")
public void testAutomaticPaymentAndExternalRefund() 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);
final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
// external refund
final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency());
invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
final InvoicePayment invoicePaymentExternalRefund = invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, true, null, NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(invoicePaymentExternalRefund);
assertInvoicePaymentsExternalRefund(accountJson.getAccountId(), invoicePaymentExternalRefund);
assertRefundInvoiceNoAdjustments(accountJson.getAccountId());
assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.valueOf(249.95), BigDecimal.ZERO);
}
use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction in project killbill by killbill.
the class TestExternalRefund method testAutomaticPaymentAndRefund.
@Test(groups = "slow", description = "#255 - Scenario 0 - Can refund an automatic payment. This is a test to validate the correct behaviour.")
public void testAutomaticPaymentAndRefund() 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);
// regular refund
final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency());
invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, payment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final InvoicePayment invoicePaymentRefund = invoicePaymentApi.getInvoicePayment(payment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertSingleInvoicePaymentRefund(invoicePaymentRefund);
assertRefundInvoiceNoAdjustments(accountJson.getAccountId());
assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.valueOf(249.95), BigDecimal.ZERO);
}
use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction in project killbill by killbill.
the class TestExternalRefund method testAutomaticPaymentAndExternalRefundWithAdjustments.
@Test(groups = "slow", description = "#255 - Scenario 2a - Can refund an automatic payment though an external refund over item adjustments")
public void testAutomaticPaymentAndExternalRefundWithAdjustments() 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);
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, null, NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(invoicePaymentExternalRefund);
assertInvoicePaymentsExternalRefund(accountJson.getAccountId(), invoicePaymentExternalRefund);
assertRefundInvoiceAdjustments(accountJson.getAccountId());
assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction 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.InvoicePaymentTransaction in project killbill by killbill.
the class TestInvoicePayment method testPartialRefundWithNoAdjustment.
@Test(groups = "slow", description = "Can create a partial refund with no adjustment")
public void testPartialRefundWithNoAdjustment() throws Exception {
final InvoicePayment paymentJson = setupScenarioWithPayment(true);
// Issue a refund for a fraction of the amount
final BigDecimal refundAmount = getFractionOfAmount(paymentJson.getPurchasedAmount());
final BigDecimal expectedInvoiceBalance = refundAmount;
// Post and verify the refund
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(paymentJson.getPaymentId());
refund.setAmount(refundAmount);
invoicePaymentApi.createRefundWithAdjustments(paymentJson.getPaymentId(), refund, paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
// Verify the invoice balance
verifyInvoice(paymentJson, expectedInvoiceBalance);
}
Aggregations