Search in sources :

Example 31 with Payment

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

the class TestPayment method testCreateTagForPaymentTransaction.

@Test(groups = "slow")
public void testCreateTagForPaymentTransaction() throws Exception {
    UUID tagDefinitionId = UUID.randomUUID();
    String tagDefinitionName = "payment-transaction";
    TagDefinition tagDefinition = new TagDefinition(tagDefinitionId, false, tagDefinitionName, "description", null);
    final TagDefinition createdTagDefinition = killBillClient.createTagDefinition(tagDefinition, requestOptions);
    final Account account = createAccountWithDefaultPaymentMethod();
    final String externalPaymentKey = UUID.randomUUID().toString();
    final UUID paymentId = testCreateRetrievePayment(account, null, externalPaymentKey, 1);
    final Payment payment = killBillClient.getPaymentByExternalKey(externalPaymentKey, requestOptions);
    assertEquals(payment.getPaymentId(), paymentId);
    UUID paymentTransactionId = payment.getTransactions().get(0).getTransactionId();
    final Tags paymentTransactionTag = killBillClient.createPaymentTransactionTag(paymentTransactionId, createdTagDefinition.getId(), requestOptions);
    Assert.assertNotNull(paymentTransactionTag);
    Assert.assertEquals(paymentTransactionTag.get(0).getTagDefinitionName(), tagDefinitionName);
}
Also used : TagDefinition(org.killbill.billing.client.model.TagDefinition) Account(org.killbill.billing.client.model.Account) Payment(org.killbill.billing.client.model.Payment) UUID(java.util.UUID) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 32 with Payment

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

the class TestPayment method testWithFailedPaymentAndScheduledAttemptsGetPaymentById.

@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetPaymentById() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    Payments payments = killBillClient.searchPayments("", 0L, 100L, AuditLevel.NONE, requestOptions);
    Assert.assertNotNull(payments.get(0));
    Payment payment = killBillClient.getPayment(payments.get(0).getPaymentId(), false, true, ImmutableMap.<String, String>of(), AuditLevel.NONE, requestOptions);
    Assert.assertNotNull(payment.getPaymentAttempts());
    Assert.assertEquals(payment.getPaymentAttempts().get(0).getStateName(), "RETRIED");
    Assert.assertEquals(payment.getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
}
Also used : Payment(org.killbill.billing.client.model.Payment) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Test(org.testng.annotations.Test)

Example 33 with Payment

use of org.killbill.billing.client.model.Payment 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, pending, amount, BigDecimal.ZERO, pendingPluginProperties, 1);
    final PaymentTransaction completeTransactionByPaymentIdAndInvalidTransactionType = new PaymentTransaction();
    completeTransactionByPaymentIdAndInvalidTransactionType.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndInvalidTransactionType.setTransactionType(TransactionType.CAPTURE.name());
    try {
        killBillClient.completePayment(completeTransactionByPaymentIdAndInvalidTransactionType, 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.name());
    final Payment completedPaymentByPaymentId = killBillClient.completePayment(completeTransactionByPaymentIdAndTransactionType, pluginProperties, requestOptions);
    verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), TransactionStatus.SUCCESS.name(), amount, amount, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) Payment(org.killbill.billing.client.model.Payment) KillBillClientException(org.killbill.billing.client.KillBillClientException) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 34 with Payment

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

the class TestPayment method testAuthorizeCompletionUsingExternalKey.

@Test(groups = "slow")
public void testAuthorizeCompletionUsingExternalKey() 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, pending, amount, BigDecimal.ZERO, pendingPluginProperties, 1);
    final PaymentTransaction completeTransactionWithTypeAndKey = new PaymentTransaction();
    completeTransactionWithTypeAndKey.setPaymentId(initialPayment.getPaymentId());
    completeTransactionWithTypeAndKey.setTransactionExternalKey(authTransactionExternalKey);
    final Payment completedPaymentByPaymentId = killBillClient.completePayment(completeTransactionWithTypeAndKey, pluginProperties, requestOptions);
    verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), TransactionStatus.SUCCESS.name(), amount, amount, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) Payment(org.killbill.billing.client.model.Payment) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 35 with Payment

use of org.killbill.billing.client.model.Payment 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, pending, amount, BigDecimal.ZERO, pendingPluginProperties, 1);
    // Complete operation: first, only specify the payment id
    final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
    completeTransactionByPaymentId.setPaymentId(initialPayment.getPaymentId());
    final Payment completedPaymentByPaymentId = killBillClient.completePayment(completeTransactionByPaymentId, pluginProperties, requestOptions);
    verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), TransactionStatus.SUCCESS.name(), amount, amount, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) 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