use of org.killbill.billing.client.model.Payments 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.Payments 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.Payments in project killbill by killbill.
the class TestPayment method testWithAbortedInvoicePayment.
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/1288")
public void testWithAbortedInvoicePayment() throws Exception {
mockPaymentProviderPlugin.makeNextPaymentFailWithError();
final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
// Getting Invoice #2 (first after Trial period)
final Invoice failedInvoice = accountApi.getInvoicesForAccount(account.getAccountId(), null, null, null, RequestOptions.empty()).get(1);
// Verify initial state
final Payments initialPayments = accountApi.getPaymentsForAccount(account.getAccountId(), true, false, ImmutableMap.<String, String>of(), AuditLevel.NONE, requestOptions);
Assert.assertEquals(initialPayments.size(), 1);
Assert.assertEquals(initialPayments.get(0).getTransactions().size(), 1);
Assert.assertEquals(initialPayments.get(0).getTransactions().get(0).getStatus(), TransactionStatus.PAYMENT_FAILURE);
Assert.assertEquals(initialPayments.get(0).getPaymentAttempts().size(), 2);
Assert.assertEquals(initialPayments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
Assert.assertEquals(initialPayments.get(0).getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
final InvoicePayments initialInvoicePayments = invoiceApi.getPaymentsForInvoice(failedInvoice.getInvoiceId(), requestOptions);
Assert.assertEquals(initialInvoicePayments.size(), 1);
Assert.assertEquals(initialInvoicePayments.get(0).getPaymentId(), initialPayments.get(0).getPaymentId());
// Trigger manually an invoice payment but make the control plugin abort it
mockPaymentControlProviderPlugin.setAborted(true);
final HashMultimap<String, String> queryParams = HashMultimap.create();
queryParams.putAll("controlPluginName", Arrays.<String>asList(MockPaymentControlProviderPlugin.PLUGIN_NAME));
final RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withQueryParams(queryParams).build();
final InvoicePayment invoicePayment = new InvoicePayment();
invoicePayment.setPurchasedAmount(failedInvoice.getBalance());
invoicePayment.setAccountId(failedInvoice.getAccountId());
invoicePayment.setTargetInvoiceId(failedInvoice.getInvoiceId());
final InvoicePayment invoicePaymentNull = invoiceApi.createInstantPayment(failedInvoice.getInvoiceId(), invoicePayment, ImmutableList.of(), null, inputOptions);
Assert.assertNull(invoicePaymentNull);
// Verify new state
final Payments updatedPayments = accountApi.getPaymentsForAccount(account.getAccountId(), true, false, ImmutableMap.<String, String>of(), AuditLevel.NONE, requestOptions);
Assert.assertEquals(updatedPayments.size(), 1);
Assert.assertEquals(updatedPayments.get(0).getPaymentId(), initialPayments.get(0).getPaymentId());
final InvoicePayments updatedInvoicePayments = invoiceApi.getPaymentsForInvoice(failedInvoice.getInvoiceId(), requestOptions);
Assert.assertEquals(updatedInvoicePayments.size(), 1);
Assert.assertEquals(updatedInvoicePayments.get(0).getPaymentId(), updatedPayments.get(0).getPaymentId());
}
use of org.killbill.billing.client.model.Payments in project killbill by killbill.
the class TestPayment method testWithFailedPaymentAndScheduledAttemptsGetPaymentById.
@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetPaymentById() throws Exception {
mockPaymentProviderPlugin.makeNextPaymentFailWithError();
createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
Payments payments = paymentApi.searchPayments("", 0L, 100L, false, true, null, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, requestOptions);
Assert.assertNotNull(payments.get(0));
Payment payment = paymentApi.getPayment(payments.get(0).getPaymentId(), false, true, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, requestOptions);
Assert.assertNotNull(payment.getPaymentAttempts());
Assert.assertEquals(payment.getPaymentAttempts().get(0).getStateName(), "RETRIED");
Assert.assertEquals(payment.getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
}
use of org.killbill.billing.client.model.Payments in project killbill by killbill.
the class TestPayment method testWithFailedPaymentAndScheduledAttemptsSearchPayments.
@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsSearchPayments() throws Exception {
mockPaymentProviderPlugin.makeNextPaymentFailWithError();
createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
HashMultimap<String, String> queryParams = HashMultimap.create();
queryParams.put("withAttempts", "true");
RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withQueryParams(queryParams).build();
Payments payments = paymentApi.searchPayments("", 0L, 100L, false, true, null, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, inputOptions);
Assert.assertNotNull(payments.get(0).getPaymentAttempts());
Assert.assertEquals(payments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
Assert.assertEquals(payments.get(0).getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
}
Aggregations