Search in sources :

Example 11 with Payment

use of org.killbill.billing.client.model.Payment in project killbill by killbill.

the class TestPayment method verifyPaymentNoTransaction.

private void verifyPaymentNoTransaction(final Account account, @Nullable final UUID paymentMethodId, final Payment payment, final String paymentExternalKey, final BigDecimal authAmount, final BigDecimal capturedAmount, final BigDecimal refundedAmount, final int nbTransactions, final int paymentNb) throws KillBillClientException {
    assertEquals(payment.getAccountId(), account.getAccountId());
    assertEquals(payment.getPaymentMethodId(), MoreObjects.firstNonNull(paymentMethodId, account.getPaymentMethodId()));
    Assert.assertNotNull(payment.getPaymentId());
    Assert.assertNotNull(payment.getPaymentNumber());
    assertEquals(payment.getPaymentExternalKey(), paymentExternalKey);
    assertEquals(payment.getAuthAmount().compareTo(authAmount), 0);
    assertEquals(payment.getCapturedAmount().compareTo(capturedAmount), 0);
    assertEquals(payment.getRefundedAmount().compareTo(refundedAmount), 0);
    assertEquals(payment.getCurrency(), account.getCurrency());
    assertEquals(payment.getTransactions().size(), nbTransactions);
    final Payments Payments = killBillClient.getPayments();
    assertEquals(Payments.size(), paymentNb);
    assertEquals(Payments.get(paymentNb - 1), payment);
    final Payment retrievedPayment = killBillClient.getPayment(payment.getPaymentId());
    assertEquals(retrievedPayment, payment);
    final Payments paymentsForAccount = killBillClient.getPaymentsForAccount(account.getAccountId());
    assertEquals(paymentsForAccount.size(), paymentNb);
    assertEquals(paymentsForAccount.get(paymentNb - 1), payment);
}
Also used : Payment(org.killbill.billing.client.model.Payment) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments)

Example 12 with Payment

use of org.killbill.billing.client.model.Payment in project killbill by killbill.

the class TestPayment method testAuthorizeCompletionUsingPaymentIdAndTransactionExternalKey.

@Test(groups = "slow")
public void testAuthorizeCompletionUsingPaymentIdAndTransactionExternalKey() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    final BigDecimal amount = BigDecimal.TEN;
    final String pending = PaymentPluginStatus.PENDING.toString();
    final ImmutableMap<String, String> pendingPluginProperties = ImmutableMap.<String, String>of(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, pending);
    final ImmutableMap<String, String> pluginProperties = ImmutableMap.of();
    TransactionType transactionType = TransactionType.AUTHORIZE;
    final String paymentExternalKey = UUID.randomUUID().toString();
    final String authTransactionExternalKey = UUID.randomUUID().toString();
    final Payment initialPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, transactionType, pending, amount, BigDecimal.ZERO, pendingPluginProperties, 1);
    final PaymentTransaction completeTransactionByPaymentIdAndInvalidTransactionExternalKey = new PaymentTransaction();
    completeTransactionByPaymentIdAndInvalidTransactionExternalKey.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndInvalidTransactionExternalKey.setTransactionExternalKey("bozo");
    try {
        killBillClient.completePayment(completeTransactionByPaymentIdAndInvalidTransactionExternalKey, pluginProperties, requestOptions);
        fail("Payment completion should fail when invalid transaction externalKey has been provided");
    } catch (final KillBillClientException expected) {
    }
    final PaymentTransaction completeTransactionByPaymentIdAndTransactionExternalKey = new PaymentTransaction();
    completeTransactionByPaymentIdAndTransactionExternalKey.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndTransactionExternalKey.setTransactionExternalKey(authTransactionExternalKey);
    final Payment completedPaymentByPaymentId = killBillClient.completePayment(completeTransactionByPaymentIdAndTransactionExternalKey, pluginProperties, requestOptions);
    verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), TransactionStatus.SUCCESS.name(), amount, amount, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) Payment(org.killbill.billing.client.model.Payment) KillBillClientException(org.killbill.billing.client.KillBillClientException) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 13 with Payment

use of org.killbill.billing.client.model.Payment in project killbill by killbill.

the class TestPayment method testCreateRetrievePayment.

private UUID testCreateRetrievePayment(final Account account, @Nullable final UUID paymentMethodId, final String paymentExternalKey, final int paymentNb) throws Exception {
    // Authorization
    final String authTransactionExternalKey = UUID.randomUUID().toString();
    final Payment authPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, TransactionType.AUTHORIZE, "SUCCESS", BigDecimal.TEN, BigDecimal.TEN, ImmutableMap.<String, String>of(), paymentNb);
    // Capture 1
    final String capture1TransactionExternalKey = UUID.randomUUID().toString();
    final PaymentTransaction captureTransaction = new PaymentTransaction();
    captureTransaction.setPaymentId(authPayment.getPaymentId());
    captureTransaction.setAmount(BigDecimal.ONE);
    captureTransaction.setCurrency(account.getCurrency());
    captureTransaction.setPaymentExternalKey(paymentExternalKey);
    captureTransaction.setTransactionExternalKey(capture1TransactionExternalKey);
    // captureAuthorization is using paymentId
    final Payment capturedPayment1 = killBillClient.captureAuthorization(captureTransaction, requestOptions);
    verifyPayment(account, paymentMethodId, capturedPayment1, paymentExternalKey, authTransactionExternalKey, "AUTHORIZE", "SUCCESS", BigDecimal.TEN, BigDecimal.TEN, BigDecimal.ONE, BigDecimal.ZERO, 2, paymentNb);
    verifyPaymentTransaction(account, authPayment.getPaymentId(), paymentExternalKey, capturedPayment1.getTransactions().get(1), capture1TransactionExternalKey, captureTransaction.getAmount(), "CAPTURE", "SUCCESS");
    // Capture 2
    final String capture2TransactionExternalKey = UUID.randomUUID().toString();
    captureTransaction.setTransactionExternalKey(capture2TransactionExternalKey);
    // captureAuthorization is using externalKey
    captureTransaction.setPaymentId(null);
    final Payment capturedPayment2 = killBillClient.captureAuthorization(captureTransaction, requestOptions);
    verifyPayment(account, paymentMethodId, capturedPayment2, paymentExternalKey, authTransactionExternalKey, "AUTHORIZE", "SUCCESS", BigDecimal.TEN, BigDecimal.TEN, new BigDecimal("2"), BigDecimal.ZERO, 3, paymentNb);
    verifyPaymentTransaction(account, authPayment.getPaymentId(), paymentExternalKey, capturedPayment2.getTransactions().get(2), capture2TransactionExternalKey, captureTransaction.getAmount(), "CAPTURE", "SUCCESS");
    // Refund
    final String refundTransactionExternalKey = UUID.randomUUID().toString();
    final PaymentTransaction refundTransaction = new PaymentTransaction();
    refundTransaction.setPaymentId(authPayment.getPaymentId());
    refundTransaction.setAmount(new BigDecimal("2"));
    refundTransaction.setCurrency(account.getCurrency());
    refundTransaction.setPaymentExternalKey(paymentExternalKey);
    refundTransaction.setTransactionExternalKey(refundTransactionExternalKey);
    final Payment refundPayment = killBillClient.refundPayment(refundTransaction, requestOptions);
    verifyPayment(account, paymentMethodId, refundPayment, paymentExternalKey, authTransactionExternalKey, "AUTHORIZE", "SUCCESS", BigDecimal.TEN, BigDecimal.TEN, new BigDecimal("2"), new BigDecimal("2"), 4, paymentNb);
    verifyPaymentTransaction(account, authPayment.getPaymentId(), paymentExternalKey, refundPayment.getTransactions().get(3), refundTransactionExternalKey, refundTransaction.getAmount(), "REFUND", "SUCCESS");
    return authPayment.getPaymentId();
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Payment(org.killbill.billing.client.model.Payment) BigDecimal(java.math.BigDecimal)

Example 14 with Payment

use of org.killbill.billing.client.model.Payment in project killbill by killbill.

the class TestPayment method testWithFailedPayment.

@Test(groups = "slow")
public void testWithFailedPayment() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final PaymentTransaction authTransaction = new PaymentTransaction();
    authTransaction.setAmount(BigDecimal.ONE);
    authTransaction.setCurrency(account.getCurrency());
    authTransaction.setTransactionType(TransactionType.AUTHORIZE.name());
    final Payment payment = killBillClient.createPayment(account.getAccountId(), account.getPaymentMethodId(), authTransaction, ImmutableMap.<String, String>of(), requestOptions);
    final PaymentTransaction paymentTransaction = payment.getTransactions().get(0);
    assertEquals(paymentTransaction.getStatus(), TransactionStatus.PAYMENT_FAILURE.toString());
    assertEquals(paymentTransaction.getGatewayErrorCode(), MockPaymentProviderPlugin.GATEWAY_ERROR_CODE);
    assertEquals(paymentTransaction.getGatewayErrorMsg(), MockPaymentProviderPlugin.GATEWAY_ERROR);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) Payment(org.killbill.billing.client.model.Payment) Test(org.testng.annotations.Test)

Example 15 with Payment

use of org.killbill.billing.client.model.Payment in project killbill by killbill.

the class TestPayment method testGetTagsForPaymentTransaction.

@Test(groups = "slow")
public void testGetTagsForPaymentTransaction() throws Exception {
    UUID tagDefinitionId = UUID.randomUUID();
    String tagDefinitionName = "payment-transaction";
    TagDefinition tagDefinition = new TagDefinition(tagDefinitionId, false, tagDefinitionName, "description", null);
    final TagDefinition createdTagDefinition = killBillClient.createTagDefinition(tagDefinition, requestOptions);
    final Account account = createAccountWithDefaultPaymentMethod();
    final String externalPaymentKey = UUID.randomUUID().toString();
    final UUID paymentId = testCreateRetrievePayment(account, null, externalPaymentKey, 1);
    final Payment payment = killBillClient.getPaymentByExternalKey(externalPaymentKey, requestOptions);
    assertEquals(payment.getPaymentId(), paymentId);
    UUID paymentTransactionId = payment.getTransactions().get(0).getTransactionId();
    killBillClient.createPaymentTransactionTag(paymentTransactionId, createdTagDefinition.getId(), requestOptions);
    final Tags paymentTransactionTags = killBillClient.getPaymentTransactionTags(paymentTransactionId, requestOptions);
    Assert.assertNotNull(paymentTransactionTags);
    Assert.assertEquals(paymentTransactionTags.get(0).getTagDefinitionName(), tagDefinitionName);
}
Also used : TagDefinition(org.killbill.billing.client.model.TagDefinition) Account(org.killbill.billing.client.model.Account) Payment(org.killbill.billing.client.model.Payment) UUID(java.util.UUID) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Aggregations

Payment (org.killbill.billing.client.model.Payment)42 Test (org.testng.annotations.Test)35 Account (org.killbill.billing.client.model.Account)24 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)19 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)18 BigDecimal (java.math.BigDecimal)17 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)15 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)15 UUID (java.util.UUID)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)8 Payments (org.killbill.billing.client.model.Payments)8 TransactionType (org.killbill.billing.payment.api.TransactionType)8 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)7 DateTime (org.joda.time.DateTime)6 KillBillClientException (org.killbill.billing.client.KillBillClientException)5 Invoice (org.killbill.billing.client.model.Invoice)4 Invoices (org.killbill.billing.client.model.Invoices)4 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)4 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)4 RequestOptions (org.killbill.billing.client.RequestOptions)2