use of org.killbill.billing.client.model.InvoicePayment 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
killBillClient.deletePaymentMethod(accountJson.getPaymentMethodId(), true, true, requestOptions);
final Payments paymentsForAccount = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), requestOptions);
final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
final Invoices invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, true, 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().toString());
invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
invoicePaymentTransactionRequest.setIsAdjusted(true);
invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
final InvoicePayment invoicePaymentExternalRefund = killBillClient.createInvoicePaymentRefund(invoicePaymentTransactionRequest, true, null, requestOptions);
assertNotNull(invoicePaymentExternalRefund);
assertInvoicePaymentsExternalRefund(accountJson.getAccountId(), invoicePaymentExternalRefund);
assertRefundInvoiceAdjustments(accountJson.getAccountId());
assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
use of org.killbill.billing.client.model.InvoicePayment 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 = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
final Invoice unpaidInvoice = invoicesForAccount.get(1);
assertEquals(unpaidInvoice.getBalance().compareTo(BigDecimal.valueOf(249.95)), 0);
final Payments paymentsForAccount = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), requestOptions);
assertEquals(paymentsForAccount.size(), 0);
final InvoicePayment invoicePaymentRequest = new InvoicePayment();
invoicePaymentRequest.setTargetInvoiceId(unpaidInvoice.getInvoiceId());
invoicePaymentRequest.setAccountId(accountJson.getAccountId());
invoicePaymentRequest.setCurrency(unpaidInvoice.getCurrency().toString());
invoicePaymentRequest.setPurchasedAmount(unpaidInvoice.getAmount());
final InvoicePayment invoicePayment = killBillClient.createInvoicePayment(invoicePaymentRequest, true, 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 = killBillClient.createInvoicePaymentRefund(invoicePaymentTransactionRequest, requestOptions);
assertNotNull(invoicePaymentRefund);
assertSingleInvoicePaymentRefund(invoicePaymentRefund);
assertRefundInvoiceNoAdjustments(accountJson.getAccountId());
assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.valueOf(249.95), BigDecimal.ZERO);
}
use of org.killbill.billing.client.model.InvoicePayment 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
killBillClient.deletePaymentMethod(accountJson.getPaymentMethodId(), true, true, requestOptions);
final Payments paymentsForAccount = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), 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().toString());
invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
final InvoicePayment invoicePaymentExternalRefund = killBillClient.createInvoicePaymentRefund(invoicePaymentTransactionRequest, true, null, 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.InvoicePayment in project killbill by killbill.
the class TestAccountTimeline method verifyPayments.
private void verifyPayments(final UUID accountId, final DateTime startTime, final DateTime endTime, final BigDecimal refundAmount, final BigDecimal chargebackAmount) throws Exception {
for (final AuditLevel auditLevel : AuditLevel.values()) {
final AccountTimeline timeline = getAccountTimeline(accountId, auditLevel);
Assert.assertEquals(timeline.getPayments().size(), 1);
final InvoicePayment payment = timeline.getPayments().get(0);
// Verify payments
final List<PaymentTransaction> purchaseTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.PURCHASE.toString());
Assert.assertEquals(purchaseTransactions.size(), 1);
final PaymentTransaction purchaseTransaction = purchaseTransactions.get(0);
// Verify refunds
final List<PaymentTransaction> refundTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.REFUND.toString());
Assert.assertEquals(refundTransactions.size(), 1);
final PaymentTransaction refundTransaction = refundTransactions.get(0);
Assert.assertEquals(refundTransaction.getPaymentId(), payment.getPaymentId());
Assert.assertEquals(refundTransaction.getAmount().compareTo(refundAmount), 0);
final List<PaymentTransaction> chargebackTransactions = getPaymentTransactions(timeline.getPayments(), TransactionType.CHARGEBACK.toString());
Assert.assertEquals(chargebackTransactions.size(), 1);
final PaymentTransaction chargebackTransaction = chargebackTransactions.get(0);
Assert.assertEquals(chargebackTransaction.getPaymentId(), payment.getPaymentId());
Assert.assertEquals(chargebackTransaction.getAmount().compareTo(chargebackAmount), 0);
// Verify audits
final List<AuditLog> paymentAuditLogs = purchaseTransaction.getAuditLogs();
final List<AuditLog> refundAuditLogs = refundTransaction.getAuditLogs();
final List<AuditLog> chargebackAuditLogs = chargebackTransaction.getAuditLogs();
if (AuditLevel.NONE.equals(auditLevel)) {
// Audits for payments
Assert.assertEquals(paymentAuditLogs.size(), 0);
// Audits for refunds
Assert.assertEquals(refundAuditLogs.size(), 0);
// Audits for chargebacks
Assert.assertEquals(chargebackAuditLogs.size(), 0);
} else if (AuditLevel.MINIMAL.equals(auditLevel)) {
// Audits for payments
Assert.assertEquals(paymentAuditLogs.size(), 1);
verifyAuditLog(paymentAuditLogs.get(0), ChangeType.INSERT, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
// Audits for refunds
Assert.assertEquals(refundAuditLogs.size(), 1);
verifyAuditLog(refundAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
// Audits for chargebacks
Assert.assertEquals(chargebackAuditLogs.size(), 1);
verifyAuditLog(chargebackAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
} else {
// Audits for payments
Assert.assertEquals(paymentAuditLogs.size(), 2);
verifyAuditLog(paymentAuditLogs.get(0), ChangeType.INSERT, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
verifyAuditLog(paymentAuditLogs.get(1), ChangeType.UPDATE, null, null, PAYMENT_REQUEST_PROCESSOR, startTime, endTime);
// Audits for refunds
Assert.assertEquals(refundAuditLogs.size(), 2);
verifyAuditLog(refundAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
verifyAuditLog(refundAuditLogs.get(1), ChangeType.UPDATE, reason, comment, createdBy, startTime, endTime);
// Audits for chargebacks
Assert.assertEquals(chargebackAuditLogs.size(), 2);
verifyAuditLog(chargebackAuditLogs.get(0), ChangeType.INSERT, reason, comment, createdBy, startTime, endTime);
verifyAuditLog(chargebackAuditLogs.get(1), ChangeType.UPDATE, reason, comment, createdBy, startTime, endTime);
}
}
}
use of org.killbill.billing.client.model.InvoicePayment in project killbill by killbill.
the class TestInvoice method testInvoiceCreatePayment.
@Test(groups = "slow", description = "Can create an insta-payment")
public void testInvoiceCreatePayment() throws Exception {
clock.setTime(new DateTime(2012, 4, 25, 0, 3, 42, 0));
// STEPH MISSING SET ACCOUNT AUTO_PAY_OFF
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Get the invoices
final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId());
assertEquals(invoices.size(), 2);
for (final Invoice cur : invoices) {
if (cur.getBalance().compareTo(BigDecimal.ZERO) <= 0) {
continue;
}
// CREATE PAYMENT
final InvoicePayment invoicePayment = new InvoicePayment();
invoicePayment.setPurchasedAmount(cur.getBalance());
invoicePayment.setAccountId(accountJson.getAccountId());
invoicePayment.setTargetInvoiceId(cur.getInvoiceId());
final InvoicePayment objFromJson = killBillClient.createInvoicePayment(invoicePayment, true, createdBy, reason, comment);
assertEquals(cur.getBalance().compareTo(objFromJson.getPurchasedAmount()), 0);
}
}
Aggregations