Search in sources :

Example 16 with Payment

use of org.killbill.billing.client.model.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 = killBillClient.getPaymentByExternalKey(externalPaymentKey);
    assertEquals(payment.getPaymentId(), paymentId);
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), account.getAccountId(), false, PLUGIN_NAME, new PaymentMethodPluginDetail());
    final PaymentMethod nonDefaultPaymentMethod = killBillClient.createPaymentMethod(paymentMethodJson, createdBy, reason, comment);
    testCreateRetrievePayment(account, nonDefaultPaymentMethod.getPaymentMethodId(), UUID.randomUUID().toString(), 2);
}
Also used : Account(org.killbill.billing.client.model.Account) Payment(org.killbill.billing.client.model.Payment) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) PaymentMethodPluginDetail(org.killbill.billing.client.model.PaymentMethodPluginDetail) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 17 with Payment

use of org.killbill.billing.client.model.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(paymentMethodId, null, null, true, PLUGIN_NAME, info);
    final ComboPaymentTransaction comboPaymentTransaction = new ComboPaymentTransaction(accountJson, paymentMethodJson, null, ImmutableList.<PluginProperty>of(), ImmutableList.<PluginProperty>of());
    final Payment payment = killBillClient.createPayment(comboPaymentTransaction, ImmutableMap.<String, String>of(), requestOptions);
    // Client returns null in case of a 404
    Assert.assertNull(payment);
}
Also used : 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) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 18 with Payment

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

Example 19 with Payment

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

the class TestPayment method testWithCanceledPayment.

@Test(groups = "slow")
public void testWithCanceledPayment() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    mockPaymentProviderPlugin.makeNextPaymentFailWithCancellation();
    final PaymentTransaction authTransaction = new PaymentTransaction();
    authTransaction.setAmount(BigDecimal.ONE);
    authTransaction.setCurrency(account.getCurrency());
    authTransaction.setTransactionType(TransactionType.AUTHORIZE.name());
    final Payment payment = killBillClient.createPayment(account.getAccountId(), account.getPaymentMethodId(), authTransaction, ImmutableMap.<String, String>of(), requestOptions);
    final PaymentTransaction paymentTransaction = payment.getTransactions().get(0);
    assertEquals(paymentTransaction.getStatus(), TransactionStatus.PLUGIN_FAILURE.toString());
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) Payment(org.killbill.billing.client.model.Payment) Test(org.testng.annotations.Test)

Example 20 with Payment

use of org.killbill.billing.client.model.Payment 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, "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 = killBillClient.refundPayment(refundTransaction, null, pluginProperties, requestOptions);
    verifyPaymentWithPendingRefund(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, purchaseAmount, refundTransactionExternalKey, refundPayment);
    final PaymentTransaction completeTransactionWithTypeAndKey = new PaymentTransaction();
    completeTransactionWithTypeAndKey.setPaymentId(refundPayment.getPaymentId());
    completeTransactionWithTypeAndKey.setTransactionExternalKey(refundTransactionExternalKey);
    final Payment completedPaymentByTypeAndKey = killBillClient.completePayment(completeTransactionWithTypeAndKey, pluginProperties, 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());
    final Payment completedPaymentByTypeAndId = killBillClient.completePayment(completeTransactionWithTypeAndId, pluginProperties, requestOptions);
    verifyPaymentWithPendingRefund(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, purchaseAmount, refundTransactionExternalKey, completedPaymentByTypeAndId);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) Payment(org.killbill.billing.client.model.Payment) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

Payment (org.killbill.billing.client.model.Payment)42 Test (org.testng.annotations.Test)35 Account (org.killbill.billing.client.model.Account)24 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)19 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)18 BigDecimal (java.math.BigDecimal)17 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)15 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)15 UUID (java.util.UUID)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)8 Payments (org.killbill.billing.client.model.Payments)8 TransactionType (org.killbill.billing.payment.api.TransactionType)8 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)7 DateTime (org.joda.time.DateTime)6 KillBillClientException (org.killbill.billing.client.KillBillClientException)5 Invoice (org.killbill.billing.client.model.Invoice)4 Invoices (org.killbill.billing.client.model.Invoices)4 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)4 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)4 RequestOptions (org.killbill.billing.client.RequestOptions)2