use of org.killbill.billing.client.model.gen.Payment in project killbill by killbill.
the class TestPayment method testWithFailedPayment.
@Test(groups = "slow")
public void testWithFailedPayment() 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 Payment payment = accountApi.processPayment(account.getAccountId(), authTransaction, account.getPaymentMethodId(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
final PaymentTransaction paymentTransaction = payment.getTransactions().get(0);
assertEquals(paymentTransaction.getStatus(), TransactionStatus.PAYMENT_FAILURE);
assertEquals(paymentTransaction.getGatewayErrorCode(), MockPaymentProviderPlugin.GATEWAY_ERROR_CODE);
assertEquals(paymentTransaction.getGatewayErrorMsg(), MockPaymentProviderPlugin.GATEWAY_ERROR);
}
use of org.killbill.billing.client.model.gen.Payment in project killbill by killbill.
the class TestPayment method testCreateRetrievePayment.
@Test(groups = "slow")
public void testCreateRetrievePayment() throws Exception {
final Account account = createAccountWithDefaultPaymentMethod();
final String externalPaymentKey = UUID.randomUUID().toString();
final UUID paymentId = testCreateRetrievePayment(account, null, externalPaymentKey, 1);
final Payment payment = paymentApi.getPaymentByExternalKey(externalPaymentKey, NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(payment.getPaymentId(), paymentId);
final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), account.getAccountId(), false, PLUGIN_NAME, new PaymentMethodPluginDetail(), null);
final PaymentMethod nonDefaultPaymentMethod = accountApi.createPaymentMethod(account.getAccountId(), paymentMethodJson, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
testCreateRetrievePayment(account, nonDefaultPaymentMethod.getPaymentMethodId(), UUID.randomUUID().toString(), 2);
}
use of org.killbill.billing.client.model.gen.Payment in project killbill by killbill.
the class TestPayment method testAuthorizeCompletionUsingPaymentIdAndTransactionExternalKey.
@Test(groups = "slow")
public void testAuthorizeCompletionUsingPaymentIdAndTransactionExternalKey() 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 completeTransactionByPaymentIdAndInvalidTransactionExternalKey = new PaymentTransaction();
completeTransactionByPaymentIdAndInvalidTransactionExternalKey.setPaymentId(initialPayment.getPaymentId());
completeTransactionByPaymentIdAndInvalidTransactionExternalKey.setTransactionExternalKey("bozo");
try {
paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentIdAndInvalidTransactionExternalKey, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
fail("Payment completion should fail when invalid transaction externalKey has been provided");
} catch (final KillBillClientException expected) {
}
final PaymentTransaction completeTransactionByPaymentIdAndTransactionExternalKey = new PaymentTransaction();
completeTransactionByPaymentIdAndTransactionExternalKey.setPaymentExternalKey(paymentExternalKey);
completeTransactionByPaymentIdAndTransactionExternalKey.setTransactionExternalKey(authTransactionExternalKey);
paymentApi.completeTransactionByExternalKey(completeTransactionByPaymentIdAndTransactionExternalKey, 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.Payment in project killbill by killbill.
the class TestPayment method verifyPaymentNoTransaction.
private void verifyPaymentNoTransaction(final Account account, @Nullable final UUID paymentMethodId, final Payment payment, final String paymentExternalKey, final BigDecimal authAmount, final BigDecimal capturedAmount, final BigDecimal refundedAmount, final int nbTransactions, final int paymentNb) throws KillBillClientException {
assertEquals(payment.getAccountId(), account.getAccountId());
assertEquals(payment.getPaymentMethodId(), MoreObjects.firstNonNull(paymentMethodId, account.getPaymentMethodId()));
Assert.assertNotNull(payment.getPaymentId());
Assert.assertNotNull(payment.getPaymentNumber());
assertEquals(payment.getPaymentExternalKey(), paymentExternalKey);
assertEquals(payment.getAuthAmount().compareTo(authAmount), 0);
assertEquals(payment.getCapturedAmount().compareTo(capturedAmount), 0);
assertEquals(payment.getRefundedAmount().compareTo(refundedAmount), 0);
assertEquals(payment.getCurrency(), account.getCurrency());
assertEquals(payment.getTransactions().size(), nbTransactions);
final Payments Payments = paymentApi.getPayments(null, NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(Payments.size(), paymentNb);
assertEquals(Payments.get(paymentNb - 1), payment);
final Payment retrievedPayment = paymentApi.getPayment(payment.getPaymentId(), false, false, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, requestOptions);
assertEquals(retrievedPayment, payment);
final Payments paymentsForAccount = accountApi.getPaymentsForAccount(account.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(paymentsForAccount.size(), paymentNb);
assertEquals(paymentsForAccount.get(paymentNb - 1), payment);
}
use of org.killbill.billing.client.model.gen.Payment in project killbill by killbill.
the class TestPayment method testComboAuthorizationInvalidPaymentMethod.
@Test(groups = "slow")
public void testComboAuthorizationInvalidPaymentMethod() throws Exception {
final Account accountJson = getAccount();
accountJson.setAccountId(null);
final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
info.setProperties(null);
final UUID paymentMethodId = UUID.randomUUID();
final PaymentMethod paymentMethodJson = new PaymentMethod();
paymentMethodJson.setPluginName(PLUGIN_NAME);
paymentMethodJson.setPluginInfo(info);
paymentMethodJson.setIsDefault(true);
paymentMethodJson.setPaymentMethodId(paymentMethodId);
final ComboPaymentTransaction comboPaymentTransaction = new ComboPaymentTransaction(accountJson, paymentMethodJson, new PaymentTransaction(), ImmutableList.<PluginProperty>of(), ImmutableList.<PluginProperty>of(), null);
final Payment payment = paymentApi.createComboPayment(comboPaymentTransaction, NULL_PLUGIN_NAMES, requestOptions);
// Client returns null in case of a 404
Assert.assertNull(payment);
}
Aggregations