Search in sources :

Example 21 with Payment

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

the class TestPayment method testAuthorizeCompletionUsingPaymentIdAndTransactionId.

@Test(groups = "slow")
public void testAuthorizeCompletionUsingPaymentIdAndTransactionId() 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 completeTransactionByPaymentIdAndInvalidTransactionId = new PaymentTransaction();
    completeTransactionByPaymentIdAndInvalidTransactionId.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndInvalidTransactionId.setTransactionId(UUID.randomUUID());
    try {
        killBillClient.completePayment(completeTransactionByPaymentIdAndInvalidTransactionId, pluginProperties, requestOptions);
        fail("Payment completion should fail when invalid transaction id has been provided");
    } catch (final KillBillClientException expected) {
    }
    final PaymentTransaction completeTransactionByPaymentIdAndTransactionId = new PaymentTransaction();
    completeTransactionByPaymentIdAndTransactionId.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndTransactionId.setTransactionId(initialPayment.getTransactions().get(0).getTransactionId());
    final Payment completedPaymentByPaymentId = killBillClient.completePayment(completeTransactionByPaymentIdAndTransactionId, 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 22 with Payment

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

the class TestPayment method testAuthorizeInvalidCompletionUsingPaymentId.

@Test(groups = "slow")
public void testAuthorizeInvalidCompletionUsingPaymentId() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    final BigDecimal amount = BigDecimal.TEN;
    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, TransactionStatus.SUCCESS.name(), amount, amount, pluginProperties, 1);
    // The payment was already completed, it should succeed (no-op)
    final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
    completeTransactionByPaymentId.setPaymentId(initialPayment.getPaymentId());
    killBillClient.completePayment(completeTransactionByPaymentId, pluginProperties, requestOptions);
}
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) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 23 with Payment

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

the class TestPaymentPluginProperties method createVerifyTransaction.

private Payment createVerifyTransaction(final Account account, @Nullable final UUID paymentMethodId, final String paymentExternalKey, final String transactionExternalKey, final TransactionType transactionType, final BigDecimal transactionAmount, final Map<String, String> pluginProperties) 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);
    return payment;
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) Payment(org.killbill.billing.client.model.Payment)

Example 24 with Payment

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

the class TestTenantKV method createComboPaymentTransaction.

private Payment createComboPaymentTransaction(final RequestOptions requestOptions) throws KillBillClientException {
    final Account accountJson = getAccount();
    accountJson.setAccountId(null);
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    info.setProperties(null);
    final String paymentMethodExternalKey = UUID.randomUUID().toString();
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, paymentMethodExternalKey, null, true, PLUGIN_NAME, info);
    final String authTransactionExternalKey = UUID.randomUUID().toString();
    final PaymentTransaction authTransactionJson = new PaymentTransaction();
    authTransactionJson.setAmount(BigDecimal.TEN);
    authTransactionJson.setCurrency(accountJson.getCurrency());
    authTransactionJson.setPaymentExternalKey(UUID.randomUUID().toString());
    authTransactionJson.setTransactionExternalKey(authTransactionExternalKey);
    authTransactionJson.setTransactionType("AUTHORIZE");
    final ComboPaymentTransaction comboAuthorization = new ComboPaymentTransaction(accountJson, paymentMethodJson, authTransactionJson, ImmutableList.<PluginProperty>of(), ImmutableList.<PluginProperty>of());
    final Payment payment = killBillClient.createPayment(comboAuthorization, ImmutableMap.<String, String>of(), requestOptions);
    Assert.assertEquals(payment.getTransactions().get(0).getStatus(), TransactionStatus.SUCCESS.toString());
    return payment;
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Payment(org.killbill.billing.client.model.Payment) PaymentMethodPluginDetail(org.killbill.billing.client.model.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.PaymentMethod)

Example 25 with Payment

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

the class TestPayment method testComboAuthorization.

@Test(groups = "slow")
public void testComboAuthorization() throws Exception {
    final Account accountJson = getAccount();
    accountJson.setAccountId(null);
    final String paymentExternalKey = UUID.randomUUID().toString();
    final ComboPaymentTransaction comboPaymentTransaction = createComboPaymentTransaction(accountJson, paymentExternalKey);
    final Payment payment = killBillClient.createPayment(comboPaymentTransaction, ImmutableMap.<String, String>of(), requestOptions);
    verifyComboPayment(payment, paymentExternalKey, BigDecimal.TEN, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
    // Void payment using externalKey
    final String voidTransactionExternalKey = UUID.randomUUID().toString();
    final Payment voidPayment = killBillClient.voidPayment(null, paymentExternalKey, voidTransactionExternalKey, null, ImmutableMap.<String, String>of(), requestOptions);
    verifyPaymentTransaction(accountJson, voidPayment.getPaymentId(), paymentExternalKey, voidPayment.getTransactions().get(1), voidTransactionExternalKey, null, "VOID", "SUCCESS");
}
Also used : Account(org.killbill.billing.client.model.Account) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Payment(org.killbill.billing.client.model.Payment) 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