Search in sources :

Example 6 with PaymentTransaction

use of org.killbill.billing.client.model.PaymentTransaction 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 7 with PaymentTransaction

use of org.killbill.billing.client.model.PaymentTransaction 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 8 with PaymentTransaction

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

the class TestPayment method testWithTimeoutPayment.

@Test(groups = "slow")
public void testWithTimeoutPayment() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    mockPaymentProviderPlugin.makePluginWaitSomeMilliseconds(10000);
    final PaymentTransaction authTransaction = new PaymentTransaction();
    authTransaction.setAmount(BigDecimal.ONE);
    authTransaction.setCurrency(account.getCurrency());
    authTransaction.setTransactionType(TransactionType.AUTHORIZE.name());
    try {
        killBillClient.createPayment(account.getAccountId(), account.getPaymentMethodId(), authTransaction, ImmutableMap.<String, String>of(), requestOptions);
        fail();
    } catch (KillBillClientException e) {
        assertEquals(504, e.getResponse().getStatusCode());
    }
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 9 with PaymentTransaction

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

the class TestPayment method createVerifyTransaction.

private Payment createVerifyTransaction(final Account account, @Nullable final UUID paymentMethodId, final String paymentExternalKey, final String transactionExternalKey, final TransactionType transactionType, final String transactionStatus, final BigDecimal transactionAmount, final BigDecimal authAmount, final Map<String, String> pluginProperties, final int paymentNb) throws KillBillClientException {
    final PaymentTransaction authTransaction = new PaymentTransaction();
    authTransaction.setAmount(transactionAmount);
    authTransaction.setCurrency(account.getCurrency());
    authTransaction.setPaymentExternalKey(paymentExternalKey);
    authTransaction.setTransactionExternalKey(transactionExternalKey);
    authTransaction.setTransactionType(transactionType.toString());
    final Payment payment = killBillClient.createPayment(account.getAccountId(), paymentMethodId, authTransaction, pluginProperties, requestOptions);
    verifyPayment(account, paymentMethodId, payment, paymentExternalKey, transactionExternalKey, transactionType.toString(), transactionStatus, transactionAmount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
    return payment;
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Payment(org.killbill.billing.client.model.Payment)

Example 10 with PaymentTransaction

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

the class TestPayment method testWithCanceledPayment.

@Test(groups = "slow")
public void testWithCanceledPayment() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    mockPaymentProviderPlugin.makeNextPaymentFailWithCancellation();
    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.PLUGIN_FAILURE.toString());
}
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)

Aggregations

PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)26 Payment (org.killbill.billing.client.model.Payment)19 Account (org.killbill.billing.client.model.Account)16 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)16 Test (org.testng.annotations.Test)15 BigDecimal (java.math.BigDecimal)11 UUID (java.util.UUID)10 TransactionType (org.killbill.billing.payment.api.TransactionType)8 KillBillClientException (org.killbill.billing.client.KillBillClientException)6 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)6 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)6 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)3 RequestOptions (org.killbill.billing.client.RequestOptions)2 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)2 AccountTimeline (org.killbill.billing.client.model.AccountTimeline)1 AuditLog (org.killbill.billing.client.model.AuditLog)1 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)1 Payments (org.killbill.billing.client.model.Payments)1 AuditLevel (org.killbill.billing.util.api.AuditLevel)1