use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction 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.InvoicePaymentTransaction in project killbill by killbill.
the class TestChargeback method testInvoicePaymentDoesNotExist.
@Test(groups = "slow", description = "Cannot add a chargeback for non existent payment")
public void testInvoicePaymentDoesNotExist() {
final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
input.setPaymentId(input.getPaymentId());
input.setAmount(BigDecimal.TEN);
try {
invoicePaymentApi.createChargeback(input.getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions);
fail();
} catch (NullPointerException e) {
} catch (KillBillClientException e) {
fail();
}
}
use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction in project killbill by killbill.
the class TestChargeback method testMultipleChargeback.
@Test(groups = "slow", description = "Can create multiple chargebacks")
public void testMultipleChargeback() throws Exception {
final InvoicePayment payment = createAccountWithInvoiceAndPayment();
// We get a 249.95 payment so we do 4 chargeback and then the fifth should fail
final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
input.setPaymentId(payment.getPaymentId());
input.setAmount(new BigDecimal("50.00"));
int count = 4;
while (count-- > 0) {
assertNotNull(invoicePaymentApi.createChargeback(payment.getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions));
}
// Last attempt should fail because this is more than the Payment
final InvoicePayment foo = invoicePaymentApi.createChargeback(payment.getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions);
final InvoicePayments payments = accountApi.getInvoicePayments(payment.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final List<PaymentTransaction> transactions = getInvoicePaymentTransactions(payments, TransactionType.CHARGEBACK);
Assert.assertEquals(transactions.size(), 5);
int found = 0;
for (final PaymentTransaction transaction : transactions) {
if (transaction.getStatus().equals(TransactionStatus.SUCCESS)) {
assertTrue(transaction.getAmount().compareTo(input.getAmount()) == 0);
assertEquals(transaction.getPaymentId(), input.getPaymentId());
found++;
} else {
assertEquals(transaction.getStatus(), TransactionStatus.PAYMENT_FAILURE);
found++;
}
}
assertEquals(found, 5);
}
use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction in project killbill by killbill.
the class TestExceptions method testExceptionMapping.
@Test(groups = "slow", enabled = false)
public void testExceptionMapping() throws Exception {
final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
final List<InvoicePayment> payments = accountApi.getInvoicePayments(account.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
input.setPaymentId(payments.get(0).getPaymentId());
input.setAmount(BigDecimal.TEN.negate());
try {
invoicePaymentApi.createChargeback(payments.get(0).getPaymentId(), input, NULL_PLUGIN_PROPERTIES, requestOptions);
fail();
} catch (final KillBillClientException e) {
Assert.assertEquals(e.getBillingException().getClassName(), InvoiceApiException.class.getName());
Assert.assertEquals(e.getBillingException().getCode(), (Integer) ErrorCode.CHARGE_BACK_AMOUNT_IS_NEGATIVE.getCode());
Assert.assertFalse(e.getBillingException().getStackTrace().isEmpty());
}
}
use of org.killbill.billing.client.model.gen.InvoicePaymentTransaction 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);
}
Aggregations