Search in sources :

Example 16 with PaymentTransaction

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

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

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

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

the class TestPayment method testCompletionForInitialTransaction.

@Test(groups = "slow")
public void testCompletionForInitialTransaction() 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> pluginProperties = ImmutableMap.<String, String>of(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, pending);
    int paymentNb = 0;
    for (final TransactionType transactionType : ImmutableList.<TransactionType>of(TransactionType.AUTHORIZE, TransactionType.PURCHASE, TransactionType.CREDIT)) {
        final BigDecimal authAmount = BigDecimal.ZERO;
        final String paymentExternalKey = UUID.randomUUID().toString();
        final String authTransactionExternalKey = UUID.randomUUID().toString();
        paymentNb++;
        final Payment initialPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, transactionType, pending, amount, authAmount, pluginProperties, paymentNb);
        final PaymentTransaction authPaymentTransaction = initialPayment.getTransactions().get(0);
        // Complete operation: first, only specify the payment id
        final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
        completeTransactionByPaymentId.setPaymentId(initialPayment.getPaymentId());
        final Payment completedPaymentByPaymentId = killBillClient.completePayment(completeTransactionByPaymentId, pluginProperties, requestOptions);
        verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), pending, amount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
        // Second, only specify the payment external key
        final PaymentTransaction completeTransactionByPaymentExternalKey = new PaymentTransaction();
        completeTransactionByPaymentExternalKey.setPaymentExternalKey(initialPayment.getPaymentExternalKey());
        final Payment completedPaymentByExternalKey = killBillClient.completePayment(completeTransactionByPaymentExternalKey, pluginProperties, requestOptions);
        verifyPayment(account, paymentMethodId, completedPaymentByExternalKey, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), pending, amount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
        // Third, specify the payment id and transaction external key
        final PaymentTransaction completeTransactionWithTypeAndKey = new PaymentTransaction();
        completeTransactionWithTypeAndKey.setPaymentId(initialPayment.getPaymentId());
        completeTransactionWithTypeAndKey.setTransactionExternalKey(authPaymentTransaction.getTransactionExternalKey());
        final Payment completedPaymentByTypeAndKey = killBillClient.completePayment(completeTransactionWithTypeAndKey, pluginProperties, requestOptions);
        verifyPayment(account, paymentMethodId, completedPaymentByTypeAndKey, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), pending, amount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
        // Finally, specify the payment id and transaction id
        final PaymentTransaction completeTransactionWithTypeAndId = new PaymentTransaction();
        completeTransactionWithTypeAndId.setPaymentId(initialPayment.getPaymentId());
        completeTransactionWithTypeAndId.setTransactionId(authPaymentTransaction.getTransactionId());
        final Payment completedPaymentByTypeAndId = killBillClient.completePayment(completeTransactionWithTypeAndId, pluginProperties, requestOptions);
        verifyPayment(account, paymentMethodId, completedPaymentByTypeAndId, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), pending, amount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
    }
}
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 20 with PaymentTransaction

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

the class TestPayment method testWithFailedPaymentAndWithoutFollowLocation.

@Test(groups = "slow")
public void testWithFailedPaymentAndWithoutFollowLocation() 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 RequestOptions requestOptionsWithoutFollowLocation = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withFollowLocation(false).build();
    try {
        killBillClient.createPayment(account.getAccountId(), account.getPaymentMethodId(), authTransaction, ImmutableMap.<String, String>of(), requestOptionsWithoutFollowLocation);
        fail();
    } catch (final KillBillClientException e) {
        assertEquals(e.getResponse().getStatusCode(), 402);
        assertEquals(e.getBillingException().getMessage(), "Payment decline by gateway. Error message: gatewayError");
    }
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) RequestOptions(org.killbill.billing.client.RequestOptions) KillBillClientException(org.killbill.billing.client.KillBillClientException) 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