use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestPayment method testAuthorizeCompletionUsingPaymentIdAndTransactionType.
@Test(groups = "slow")
public void testAuthorizeCompletionUsingPaymentIdAndTransactionType() 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 completeTransactionByPaymentIdAndInvalidTransactionType = new PaymentTransaction();
completeTransactionByPaymentIdAndInvalidTransactionType.setPaymentId(initialPayment.getPaymentId());
completeTransactionByPaymentIdAndInvalidTransactionType.setTransactionType(TransactionType.CAPTURE);
try {
paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentIdAndInvalidTransactionType, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
fail("Payment completion should fail when invalid transaction type has been provided");
} catch (final KillBillClientException expected) {
}
final PaymentTransaction completeTransactionByPaymentIdAndTransactionType = new PaymentTransaction();
completeTransactionByPaymentIdAndTransactionType.setPaymentId(initialPayment.getPaymentId());
completeTransactionByPaymentIdAndTransactionType.setTransactionType(transactionType);
paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentIdAndTransactionType, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
final Payment completedPaymentByPaymentId = paymentApi.getPayment(initialPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, 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.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, amount, amount, pluginProperties, 1);
// The payment was already completed, it should succeed (no-op)
final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
completeTransactionByPaymentId.setPaymentId(initialPayment.getPaymentId());
paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentId, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
}
use of org.killbill.billing.client.model.gen.PaymentTransaction in project killbill by killbill.
the class TestPayment method testAuthorizeCompletionUsingPaymentId.
@Test(groups = "slow")
public void testAuthorizeCompletionUsingPaymentId() 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);
// Complete operation: first, only specify the payment id
final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
completeTransactionByPaymentId.setPaymentId(initialPayment.getPaymentId());
paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentId, 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.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, TransactionStatus.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());
paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentId, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
final Payment completedPaymentByPaymentId = paymentApi.getPayment(initialPayment.getPaymentId(), pluginProperties, requestOptions);
verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType, TransactionStatus.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());
paymentApi.completeTransactionByExternalKey(completeTransactionByPaymentExternalKey, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
final Payment completedPaymentByExternalKey = paymentApi.getPayment(initialPayment.getPaymentId(), pluginProperties, requestOptions);
verifyPayment(account, paymentMethodId, completedPaymentByExternalKey, paymentExternalKey, authTransactionExternalKey, transactionType, TransactionStatus.PENDING, amount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
// Third, specify the payment id and transaction external key
final PaymentTransaction completeTransactionWithTypeAndKey = new PaymentTransaction();
completeTransactionWithTypeAndKey.setPaymentExternalKey(paymentExternalKey);
completeTransactionWithTypeAndKey.setTransactionExternalKey(authPaymentTransaction.getTransactionExternalKey());
paymentApi.completeTransactionByExternalKey(completeTransactionWithTypeAndKey, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
final Payment completedPaymentByTypeAndKey = paymentApi.getPayment(initialPayment.getPaymentId(), pluginProperties, requestOptions);
verifyPayment(account, paymentMethodId, completedPaymentByTypeAndKey, paymentExternalKey, authTransactionExternalKey, transactionType, TransactionStatus.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());
paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionWithTypeAndId, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
final Payment completedPaymentByTypeAndId = paymentApi.getPayment(initialPayment.getPaymentId(), pluginProperties, requestOptions);
verifyPayment(account, paymentMethodId, completedPaymentByTypeAndId, paymentExternalKey, authTransactionExternalKey, transactionType, TransactionStatus.PENDING, amount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
}
}
use of org.killbill.billing.client.model.gen.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);
final RequestOptions requestOptionsWithoutFollowLocation = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withFollowLocation(false).build();
try {
accountApi.processPayment(account.getAccountId(), authTransaction, account.getPaymentMethodId(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptionsWithoutFollowLocation);
fail();
} catch (final KillBillClientException e) {
assertEquals(e.getResponse().getStatusCode(), 402);
assertEquals(e.getBillingException().getMessage(), "Payment decline by gateway. Error message: gatewayError");
}
}
Aggregations