use of org.killbill.billing.client.model.gen.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, TransactionStatus.PENDING, amount, BigDecimal.ZERO, pendingPluginProperties, 1);
final PaymentTransaction completeTransactionByPaymentIdAndInvalidTransactionId = new PaymentTransaction();
completeTransactionByPaymentIdAndInvalidTransactionId.setPaymentId(initialPayment.getPaymentId());
completeTransactionByPaymentIdAndInvalidTransactionId.setTransactionId(UUID.randomUUID());
try {
paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentIdAndInvalidTransactionId, NULL_PLUGIN_NAMES, 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());
paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentIdAndTransactionId, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
final Payment completedPaymentByPaymentId = paymentApi.getPayment(initialPayment.getPaymentId(), pluginProperties, requestOptions);
verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType, TransactionStatus.SUCCESS, amount, amount, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
}
use of org.killbill.billing.client.model.gen.Payment in project killbill by killbill.
the class TestPayment method testWithTransactionEffectiveDate.
@Test(groups = "slow")
public void testWithTransactionEffectiveDate() throws Exception {
final Account account = createAccountWithDefaultPaymentMethod();
final PaymentTransaction authTransaction = new PaymentTransaction();
authTransaction.setAmount(BigDecimal.ONE);
authTransaction.setCurrency(account.getCurrency());
authTransaction.setTransactionType(TransactionType.AUTHORIZE);
final DateTime effectiveDate = new DateTime(2018, 9, 4, 3, 5, 35);
authTransaction.setEffectiveDate(effectiveDate);
final Payment payment = accountApi.processPayment(account.getAccountId(), authTransaction, account.getPaymentMethodId(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
final PaymentTransaction paymentTransaction = payment.getTransactions().get(0);
assertTrue(paymentTransaction.getEffectiveDate().compareTo(effectiveDate) == 0);
}
use of org.killbill.billing.client.model.gen.Payment 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;
}
use of org.killbill.billing.client.model.gen.Payment 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);
}
use of org.killbill.billing.client.model.gen.Payment 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);
}
Aggregations