Search in sources :

Example 11 with PaymentTransaction

use of org.killbill.billing.client.model.gen.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 TransactionStatus 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);
    final Payment payment = accountApi.processPayment(account.getAccountId(), authTransaction, paymentMethodId, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    verifyPayment(account, paymentMethodId, payment, paymentExternalKey, transactionExternalKey, transactionType, transactionStatus, transactionAmount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
    return payment;
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.gen.ComboPaymentTransaction) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment)

Example 12 with PaymentTransaction

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

the class TestPaymentPluginProperties method testInternal.

private void testInternal(final Map<String, String> queryProperties, final List<PluginProperty> bodyProperties, final List<org.killbill.billing.payment.api.PluginProperty> expectProperties) 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);
    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, amount, pluginProperties);
    mockPaymentControlProviderPlugin.setExpectPluginProperties(expectProperties);
    // Complete operation: first, only specify the payment id
    final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
    completeTransactionByPaymentId.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentId.setProperties(bodyProperties);
    final RequestOptions basicRequestOptions = requestOptions;
    final Multimap<String, String> params = LinkedListMultimap.create(basicRequestOptions.getQueryParams());
    params.putAll(KillBillHttpClient.CONTROL_PLUGIN_NAME, ImmutableList.<String>of(PluginPropertiesVerificator.PLUGIN_NAME));
    final RequestOptions requestOptionsWithParams = basicRequestOptions.extend().withQueryParams(params).build();
    paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentId, NULL_PLUGIN_NAMES, queryProperties, requestOptionsWithParams);
    // Capture the payment
    final PaymentTransaction captureTransaction = new PaymentTransaction();
    captureTransaction.setPaymentId(initialPayment.getPaymentId());
    captureTransaction.setProperties(bodyProperties);
    captureTransaction.setAmount(BigDecimal.TEN);
    captureTransaction.setCurrency(account.getCurrency());
    paymentApi.captureAuthorization(initialPayment.getPaymentId(), captureTransaction, ImmutableList.<String>of(PluginPropertiesVerificator.PLUGIN_NAME), queryProperties, requestOptions);
    // Refund the payment
    final PaymentTransaction refundTransaction = new PaymentTransaction();
    refundTransaction.setPaymentId(initialPayment.getPaymentId());
    refundTransaction.setProperties(bodyProperties);
    refundTransaction.setAmount(BigDecimal.TEN);
    refundTransaction.setCurrency(account.getCurrency());
    paymentApi.refundPayment(initialPayment.getPaymentId(), refundTransaction, ImmutableList.<String>of(PluginPropertiesVerificator.PLUGIN_NAME), queryProperties, requestOptions);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) Payment(org.killbill.billing.client.model.gen.Payment) RequestOptions(org.killbill.billing.client.RequestOptions) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal)

Example 13 with PaymentTransaction

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

the class TestTenantKV method testPerTenantPluginPaymentStateMachineConfig.

@Test(groups = "slow", description = "Upload and retrieve a per plugin payment state machine config")
public void testPerTenantPluginPaymentStateMachineConfig() throws Exception {
    final RequestOptions requestOptionsForOriginalTenant = requestOptions;
    // Create another tenant - it will have a different state machine
    createTenant(UUID.randomUUID().toString(), UUID.randomUUID().toString(), true);
    // Verify initial state
    final TenantKeyValue emptyTenantKey = tenantApi.getPluginPaymentStateMachineConfig(PLUGIN_NAME, requestOptionsForOriginalTenant);
    assertEquals(emptyTenantKey.getValues().size(), 0);
    final TenantKeyValue emptyTenantKeyOtherTenant = tenantApi.getPluginPaymentStateMachineConfig(PLUGIN_NAME, requestOptions);
    assertEquals(emptyTenantKeyOtherTenant.getValues().size(), 0);
    callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_CHANGE);
    final String stateMachineConfig = getResourceBodyString("org/killbill/billing/server/SimplePaymentStates.xml");
    final TenantKeyValue tenantKey0 = tenantApi.uploadPluginPaymentStateMachineConfig(PLUGIN_NAME, stateMachineConfig, requestOptions);
    callbackServlet.assertListenerStatus();
    assertEquals(tenantKey0.getKey(), TenantKV.TenantKey.PLUGIN_PAYMENT_STATE_MACHINE_ + PLUGIN_NAME);
    // Verify only the other tenant has the new state machine
    final TenantKeyValue emptyTenantKey1 = tenantApi.getPluginPaymentStateMachineConfig(PLUGIN_NAME, requestOptionsForOriginalTenant);
    assertEquals(emptyTenantKey1.getValues().size(), 0);
    final TenantKeyValue tenantKey1OtherTenant = tenantApi.getPluginPaymentStateMachineConfig(PLUGIN_NAME, requestOptions);
    assertEquals(tenantKey1OtherTenant.getKey(), TenantKV.TenantKey.PLUGIN_PAYMENT_STATE_MACHINE_ + PLUGIN_NAME);
    assertEquals(tenantKey1OtherTenant.getValues().size(), 1);
    // Create an auth in both tenant
    final Payment payment = createComboPaymentTransaction(requestOptionsForOriginalTenant);
    final Payment paymentOtherTenant = createComboPaymentTransaction(requestOptions);
    // Void in the first tenant (allowed by the default state machine)
    callbackServlet.pushExpectedEvent(ExtBusEventType.PAYMENT_SUCCESS);
    paymentApi.voidPayment(payment.getPaymentId(), new PaymentTransaction(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptionsForOriginalTenant);
    callbackServlet.assertListenerStatus();
    final Payment voidPayment = paymentApi.getPayment(payment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptionsForOriginalTenant);
    assertEquals(voidPayment.getTransactions().get(0).getStatus(), TransactionStatus.SUCCESS);
    assertEquals(voidPayment.getTransactions().get(1).getStatus(), TransactionStatus.SUCCESS);
    // Void in the other tenant (disallowed)
    try {
        paymentApi.voidPayment(paymentOtherTenant.getPaymentId(), new PaymentTransaction(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
        Assert.fail();
    } catch (final KillBillClientException e) {
        assertEquals((int) e.getBillingException().getCode(), ErrorCode.PAYMENT_INVALID_OPERATION.getCode());
    }
    callbackServlet.assertListenerStatus();
    // Remove the custom state machine
    callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_DELETION);
    tenantApi.deletePluginPaymentStateMachineConfig(PLUGIN_NAME, requestOptions);
    final TenantKeyValue tenantKey2 = tenantApi.getPluginPaymentStateMachineConfig(PLUGIN_NAME, requestOptions);
    callbackServlet.assertListenerStatus();
    assertEquals(tenantKey2.getKey(), TenantKV.TenantKey.PLUGIN_PAYMENT_STATE_MACHINE_ + PLUGIN_NAME);
    assertEquals(tenantKey2.getValues().size(), 0);
    final AtomicReference<Payment> voidPaymentOtherTenant2Ref = new AtomicReference<Payment>();
    Awaitility.await().atMost(8, TimeUnit.SECONDS).pollInterval(Durations.TWO_SECONDS).until(new Callable<Boolean>() {

        @Override
        public Boolean call() {
            // The void should now go through
            try {
                callbackServlet.pushExpectedEvent(ExtBusEventType.PAYMENT_SUCCESS);
                paymentApi.voidPayment(paymentOtherTenant.getPaymentId(), new PaymentTransaction(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
                final Payment voidPaymentOtherTenant2 = paymentApi.getPayment(paymentOtherTenant.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
                callbackServlet.assertListenerStatus();
                voidPaymentOtherTenant2Ref.set(voidPaymentOtherTenant2);
                return voidPaymentOtherTenant2 != null;
            } catch (final KillBillClientException e) {
                // Invalidation hasn't happened yet
                return false;
            }
        }
    });
    assertEquals(voidPaymentOtherTenant2Ref.get().getTransactions().get(0).getStatus(), TransactionStatus.SUCCESS);
    assertEquals(voidPaymentOtherTenant2Ref.get().getTransactions().get(1).getStatus(), TransactionStatus.SUCCESS);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.gen.ComboPaymentTransaction) Payment(org.killbill.billing.client.model.gen.Payment) RequestOptions(org.killbill.billing.client.RequestOptions) TenantKeyValue(org.killbill.billing.client.model.gen.TenantKeyValue) KillBillClientException(org.killbill.billing.client.KillBillClientException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.testng.annotations.Test)

Example 14 with PaymentTransaction

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

the class TestPayment method testCompletionForSubsequentTransaction.

@Test(groups = "slow")
public void testCompletionForSubsequentTransaction() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    final String paymentExternalKey = UUID.randomUUID().toString();
    final String purchaseTransactionExternalKey = UUID.randomUUID().toString();
    final BigDecimal purchaseAmount = BigDecimal.TEN;
    // Create a successful purchase
    final Payment authPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, TransactionType.PURCHASE, TransactionStatus.SUCCESS, purchaseAmount, BigDecimal.ZERO, ImmutableMap.<String, String>of(), 1);
    final String pending = PaymentPluginStatus.PENDING.toString();
    final ImmutableMap<String, String> pluginProperties = ImmutableMap.<String, String>of(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, pending);
    // Trigger a pending refund
    final String refundTransactionExternalKey = UUID.randomUUID().toString();
    final PaymentTransaction refundTransaction = new PaymentTransaction();
    refundTransaction.setPaymentId(authPayment.getPaymentId());
    refundTransaction.setTransactionExternalKey(refundTransactionExternalKey);
    refundTransaction.setAmount(purchaseAmount);
    refundTransaction.setCurrency(authPayment.getCurrency());
    final Payment refundPayment = paymentApi.refundPayment(authPayment.getPaymentId(), refundTransaction, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    verifyPaymentWithPendingRefund(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, purchaseAmount, refundTransactionExternalKey, refundPayment);
    final PaymentTransaction completeTransactionWithTypeAndKey = new PaymentTransaction();
    completeTransactionWithTypeAndKey.setPaymentExternalKey(paymentExternalKey);
    completeTransactionWithTypeAndKey.setTransactionExternalKey(refundTransactionExternalKey);
    paymentApi.completeTransactionByExternalKey(completeTransactionWithTypeAndKey, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    final Payment completedPaymentByTypeAndKey = paymentApi.getPayment(refundPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyPaymentWithPendingRefund(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, purchaseAmount, refundTransactionExternalKey, completedPaymentByTypeAndKey);
    // Also, it should work if we specify the payment id and transaction id
    final PaymentTransaction completeTransactionWithTypeAndId = new PaymentTransaction();
    completeTransactionWithTypeAndId.setPaymentId(refundPayment.getPaymentId());
    completeTransactionWithTypeAndId.setTransactionId(refundPayment.getTransactions().get(1).getTransactionId());
    paymentApi.completeTransaction(refundPayment.getPaymentId(), completeTransactionWithTypeAndId, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    final Payment completedPaymentByTypeAndId = paymentApi.getPayment(refundPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyPaymentWithPendingRefund(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, purchaseAmount, refundTransactionExternalKey, completedPaymentByTypeAndId);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.gen.ComboPaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 15 with PaymentTransaction

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

the class TestPayment method testComboAuthorizationControlWithNullPaymentMethodId.

@Test(groups = "slow")
public void testComboAuthorizationControlWithNullPaymentMethodId() throws Exception {
    final Account accountJson = createAccount();
    // Non-default payment method
    final PaymentMethod paymentMethod = createPaymentMethod(accountJson, false);
    mockPaymentControlProviderPlugin.setAdjustedPaymentMethodId(paymentMethod.getPaymentMethodId());
    accountJson.setAccountId(null);
    final String paymentExternalKey = UUID.randomUUID().toString();
    final PaymentTransaction authTransactionJson = new PaymentTransaction();
    authTransactionJson.setPaymentExternalKey(paymentExternalKey);
    authTransactionJson.setAmount(BigDecimal.TEN);
    authTransactionJson.setTransactionType(TransactionType.AUTHORIZE);
    final ComboPaymentTransaction comboPaymentTransaction = new ComboPaymentTransaction();
    comboPaymentTransaction.setAccount(accountJson);
    comboPaymentTransaction.setTransaction(authTransactionJson);
    comboPaymentTransaction.setTransaction(authTransactionJson);
    final Payment payment = paymentApi.createComboPayment(comboPaymentTransaction, ImmutableList.<String>of(MockPaymentControlProviderPlugin.PLUGIN_NAME), requestOptions);
    verifyComboPayment(payment, paymentExternalKey, BigDecimal.TEN, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
    assertEquals(paymentApi.getPayment(payment.getPaymentId(), false, true, ImmutableMap.<String, String>of(), AuditLevel.NONE, requestOptions).getPaymentAttempts().size(), 1);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.gen.ComboPaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) ComboPaymentTransaction(org.killbill.billing.client.model.gen.ComboPaymentTransaction) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) Test(org.testng.annotations.Test)

Aggregations

PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)33 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)23 Payment (org.killbill.billing.client.model.gen.Payment)23 Account (org.killbill.billing.client.model.gen.Account)21 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)21 Test (org.testng.annotations.Test)21 BigDecimal (java.math.BigDecimal)11 UUID (java.util.UUID)11 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)8 TransactionType (org.killbill.billing.payment.api.TransactionType)8 KillBillClientException (org.killbill.billing.client.KillBillClientException)7 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)5 RequestOptions (org.killbill.billing.client.RequestOptions)3 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)3 PaymentMethodPluginDetail (org.killbill.billing.client.model.gen.PaymentMethodPluginDetail)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 DateTime (org.joda.time.DateTime)1 Payments (org.killbill.billing.client.model.Payments)1 AccountTimeline (org.killbill.billing.client.model.gen.AccountTimeline)1 AdminPayment (org.killbill.billing.client.model.gen.AdminPayment)1