use of org.killbill.billing.client.model.Payments in project killbill by killbill.
the class TestPerTenantConfig method testFailedPaymentWithPerTenantRetryConfig.
@Test(groups = "slow")
public void testFailedPaymentWithPerTenantRetryConfig() throws Exception {
// Create the tenant
createTenant("tenantSuperTuned", "2367$$ffr79", true);
// Configure our plugin to fail
mockPaymentProviderPlugin.makeAllInvoicesFailWithError(true);
// Upload the config
final ObjectMapper mapper = new ObjectMapper();
final HashMap<String, String> perTenantProperties = new HashMap<String, String>();
perTenantProperties.put("org.killbill.payment.retry.days", "1,1,1");
final String perTenantConfig = mapper.writeValueAsString(perTenantProperties);
callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_CHANGE);
final TenantKeyValue tenantKey = tenantApi.uploadPerTenantConfiguration(perTenantConfig, requestOptions);
callbackServlet.assertListenerStatus();
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
final Payments payments = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(payments.size(), 1);
Assert.assertEquals(payments.get(0).getTransactions().size(), 1);
//
// Because we have specified a retry interval of one day we should see the new attempt after moving clock 1 day (and not 8 days which is default)
//
//
// Now unregister special per tenant config and when the first retry occurs one day after (and still fails), it now sets a retry date of 8 days
//
callbackServlet.pushExpectedEvents(ExtBusEventType.TENANT_CONFIG_DELETION);
tenantApi.deletePerTenantConfiguration(requestOptions);
callbackServlet.assertListenerStatus();
callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_FAILED, ExtBusEventType.PAYMENT_FAILED);
clock.addDays(1);
callbackServlet.assertListenerStatus();
final Payments payments2 = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(payments2.size(), 1);
Assert.assertEquals(payments2.get(0).getTransactions().size(), 2);
Assert.assertEquals(payments2.get(0).getTransactions().get(0).getStatus(), TransactionStatus.PAYMENT_FAILURE);
Assert.assertEquals(payments2.get(0).getTransactions().get(1).getStatus(), TransactionStatus.PAYMENT_FAILURE);
clock.addDays(1);
callbackServlet.assertListenerStatus();
// No retry with default config
final Payments payments3 = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(payments3.size(), 1);
Assert.assertEquals(payments3.get(0).getTransactions().size(), 2);
mockPaymentProviderPlugin.makeAllInvoicesFailWithError(false);
callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
clock.addDays(7);
callbackServlet.assertListenerStatus();
final Payments payments4 = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(payments4.size(), 1);
Assert.assertEquals(payments4.get(0).getTransactions().size(), 3);
Assert.assertEquals(payments4.get(0).getTransactions().get(0).getStatus(), TransactionStatus.PAYMENT_FAILURE);
Assert.assertEquals(payments4.get(0).getTransactions().get(1).getStatus(), TransactionStatus.PAYMENT_FAILURE);
Assert.assertEquals(payments4.get(0).getTransactions().get(2).getStatus(), TransactionStatus.SUCCESS);
}
use of org.killbill.billing.client.model.Payments in project killbill by killbill.
the class TestInvoicePayment method testPaymentsAndRefundsPagination.
@Test(groups = "slow", description = "Can paginate through all payments and refunds")
public void testPaymentsAndRefundsPagination() throws Exception {
InvoicePayment lastPayment = setupScenarioWithPayment(true);
for (int i = 0; i < 5; i++) {
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(lastPayment.getPaymentId());
refund.setAmount(lastPayment.getPurchasedAmount());
invoicePaymentApi.createRefundWithAdjustments(lastPayment.getPaymentId(), refund, lastPayment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final InvoicePayment invoicePayment = new InvoicePayment();
invoicePayment.setPurchasedAmount(lastPayment.getPurchasedAmount());
invoicePayment.setAccountId(lastPayment.getAccountId());
invoicePayment.setTargetInvoiceId(lastPayment.getTargetInvoiceId());
final InvoicePayment payment = invoiceApi.createInstantPayment(lastPayment.getTargetInvoiceId(), invoicePayment, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
lastPayment = payment;
}
final InvoicePayments allPayments = accountApi.getInvoicePayments(lastPayment.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(allPayments.size(), 6);
final List<PaymentTransaction> objRefundFromJson = getInvoicePaymentTransactions(allPayments, TransactionType.REFUND);
Assert.assertEquals(objRefundFromJson.size(), 5);
Payments paymentsPage = paymentApi.getPayments(0L, 1L, null, false, false, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, requestOptions);
for (int i = 0; i < 6; i++) {
Assert.assertNotNull(paymentsPage);
Assert.assertEquals(paymentsPage.size(), 1);
verifyInvoicePaymentAgainstPayment(allPayments.get(i), paymentsPage.get(0));
paymentsPage = paymentsPage.getNext();
}
assertNull(paymentsPage);
}
use of org.killbill.billing.client.model.Payments in project killbill by killbill.
the class TestInvoice method testExternalChargesWithSameInvoiceAndExternalKeys.
@Test(groups = "slow", description = "Can create multiple external charges with same invoice and external keys")
public void testExternalChargesWithSameInvoiceAndExternalKeys() throws Exception {
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Get the invoices
assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId()).size(), 2);
// Post an external charge
final BigDecimal chargeAmount = BigDecimal.TEN;
final List<InvoiceItem> externalCharges = new ArrayList<InvoiceItem>();
// Does not pass currency to test on purpose that we will default to account currency
final InvoiceItem externalCharge1 = new InvoiceItem();
externalCharge1.setAccountId(accountJson.getAccountId());
externalCharge1.setAmount(chargeAmount);
externalCharge1.setDescription(UUID.randomUUID().toString());
externalCharges.add(externalCharge1);
final InvoiceItem externalCharge2 = new InvoiceItem();
externalCharge2.setAccountId(accountJson.getAccountId());
externalCharge2.setAmount(chargeAmount);
externalCharge2.setCurrency(accountJson.getCurrency());
externalCharge2.setDescription(UUID.randomUUID().toString());
externalCharges.add(externalCharge2);
String paymentExternalKey = "anyPaymentExternalKey";
String transactionExternalKey = "anyTransactionExternalKey";
final List<InvoiceItem> createdExternalCharges = killBillClient.createExternalCharges(externalCharges, clock.getUTCToday(), true, true, paymentExternalKey, transactionExternalKey, RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).build());
assertEquals(createdExternalCharges.size(), 2);
assertEquals(createdExternalCharges.get(0).getCurrency().toString(), accountJson.getCurrency());
assertEquals(createdExternalCharges.get(1).getCurrency().toString(), accountJson.getCurrency());
// Verify the total number of invoices
assertEquals(killBillClient.getInvoicesForAccount(accountJson.getAccountId()).size(), 3);
Payments payments = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), AuditLevel.NONE, RequestOptions.empty());
assertNotNull(payments);
// Verify payment with paymentExternalKey provided
assertEquals(payments.get(payments.size() - 1).getPaymentExternalKey(), paymentExternalKey);
// Verify transactions with transactionExternalKey provided
assertEquals(payments.get(payments.size() - 1).getTransactions().get(0).getTransactionExternalKey(), transactionExternalKey);
}
use of org.killbill.billing.client.model.Payments 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.Payments 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);
}
Aggregations