Search in sources :

Example 36 with Payment

use of org.killbill.billing.client.model.gen.Payment 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);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.gen.ComboPaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 37 with Payment

use of org.killbill.billing.client.model.gen.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", ImmutableList.<ObjectType>of(ObjectType.TRANSACTION), null);
    final TagDefinition createdTagDefinition = tagDefinitionApi.createTagDefinition(tagDefinition, requestOptions);
    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);
    UUID paymentTransactionId = payment.getTransactions().get(0).getTransactionId();
    final Tags paymentTransactionTag = paymentTransactionApi.createTransactionTags(paymentTransactionId, ImmutableList.<UUID>of(createdTagDefinition.getId()), requestOptions);
    Assert.assertNotNull(paymentTransactionTag);
    Assert.assertEquals(paymentTransactionTag.get(0).getTagDefinitionName(), tagDefinitionName);
}
Also used : TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) UUID(java.util.UUID) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 38 with Payment

use of org.killbill.billing.client.model.gen.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, 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);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.gen.ComboPaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 39 with Payment

use of org.killbill.billing.client.model.gen.Payment 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);
    }
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.gen.ComboPaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 40 with Payment

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

the class TestPaymentPluginProperties method createVerifyTransaction.

private Payment createVerifyTransaction(final Account account, @Nullable final UUID paymentMethodId, final String paymentExternalKey, final String transactionExternalKey, final TransactionType transactionType, final BigDecimal transactionAmount, final Map<String, String> pluginProperties) 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);
    return payment;
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) Payment(org.killbill.billing.client.model.gen.Payment)

Aggregations

Payment (org.killbill.billing.client.model.gen.Payment)41 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)36 Test (org.testng.annotations.Test)34 Account (org.killbill.billing.client.model.gen.Account)28 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)23 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)18 BigDecimal (java.math.BigDecimal)16 UUID (java.util.UUID)14 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)13 TransactionType (org.killbill.billing.payment.api.TransactionType)8 DateTime (org.joda.time.DateTime)7 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)7 Payments (org.killbill.billing.client.model.Payments)7 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)7 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)5 KillBillClientException (org.killbill.billing.client.KillBillClientException)4 Invoices (org.killbill.billing.client.model.Invoices)4 Invoice (org.killbill.billing.client.model.gen.Invoice)4 PaymentMethodPluginDetail (org.killbill.billing.client.model.gen.PaymentMethodPluginDetail)4 RequestOptions (org.killbill.billing.client.RequestOptions)2