Search in sources :

Example 51 with Account

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

the class TestPayment method testWithTransactionEffectiveDate.

@Test(groups = "slow")
public void testWithTransactionEffectiveDate() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final PaymentTransaction authTransaction = new PaymentTransaction();
    authTransaction.setAmount(BigDecimal.ONE);
    authTransaction.setCurrency(account.getCurrency());
    authTransaction.setTransactionType(TransactionType.AUTHORIZE);
    final DateTime effectiveDate = new DateTime(2018, 9, 4, 3, 5, 35);
    authTransaction.setEffectiveDate(effectiveDate);
    final Payment payment = accountApi.processPayment(account.getAccountId(), authTransaction, account.getPaymentMethodId(), NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
    final PaymentTransaction paymentTransaction = payment.getTransactions().get(0);
    assertTrue(paymentTransaction.getEffectiveDate().compareTo(effectiveDate) == 0);
}
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) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 52 with Account

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

the class TestPaymentPluginProperties method testInternal.

private void testInternal(final Map<String, String> queryProperties, final List<PluginProperty> bodyProperties, final List<org.killbill.billing.payment.api.PluginProperty> expectProperties) 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);
    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, amount, pluginProperties);
    mockPaymentControlProviderPlugin.setExpectPluginProperties(expectProperties);
    // Complete operation: first, only specify the payment id
    final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
    completeTransactionByPaymentId.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentId.setProperties(bodyProperties);
    final RequestOptions basicRequestOptions = requestOptions;
    final Multimap<String, String> params = LinkedListMultimap.create(basicRequestOptions.getQueryParams());
    params.putAll(KillBillHttpClient.CONTROL_PLUGIN_NAME, ImmutableList.<String>of(PluginPropertiesVerificator.PLUGIN_NAME));
    final RequestOptions requestOptionsWithParams = basicRequestOptions.extend().withQueryParams(params).build();
    paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentId, NULL_PLUGIN_NAMES, queryProperties, requestOptionsWithParams);
    // Capture the payment
    final PaymentTransaction captureTransaction = new PaymentTransaction();
    captureTransaction.setPaymentId(initialPayment.getPaymentId());
    captureTransaction.setProperties(bodyProperties);
    captureTransaction.setAmount(BigDecimal.TEN);
    captureTransaction.setCurrency(account.getCurrency());
    paymentApi.captureAuthorization(initialPayment.getPaymentId(), captureTransaction, ImmutableList.<String>of(PluginPropertiesVerificator.PLUGIN_NAME), queryProperties, requestOptions);
    // Refund the payment
    final PaymentTransaction refundTransaction = new PaymentTransaction();
    refundTransaction.setPaymentId(initialPayment.getPaymentId());
    refundTransaction.setProperties(bodyProperties);
    refundTransaction.setAmount(BigDecimal.TEN);
    refundTransaction.setCurrency(account.getCurrency());
    paymentApi.refundPayment(initialPayment.getPaymentId(), refundTransaction, ImmutableList.<String>of(PluginPropertiesVerificator.PLUGIN_NAME), queryProperties, requestOptions);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) Payment(org.killbill.billing.client.model.gen.Payment) RequestOptions(org.killbill.billing.client.RequestOptions) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal)

Example 53 with Account

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

the class TestPayment method testGetTagsForPaymentTransaction.

@Test(groups = "slow")
public void testGetTagsForPaymentTransaction() 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();
    paymentTransactionApi.createTransactionTags(paymentTransactionId, ImmutableList.<UUID>of(createdTagDefinition.getId()), requestOptions);
    final Tags paymentTransactionTags = paymentTransactionApi.getTransactionTags(paymentTransactionId, requestOptions);
    Assert.assertNotNull(paymentTransactionTags);
    Assert.assertEquals(paymentTransactionTags.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 54 with Account

use of org.killbill.billing.client.model.gen.Account 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, TransactionStatus.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 = paymentApi.refundPayment(authPayment.getPaymentId(), refundTransaction, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    verifyPaymentWithPendingRefund(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, purchaseAmount, refundTransactionExternalKey, refundPayment);
    final PaymentTransaction completeTransactionWithTypeAndKey = new PaymentTransaction();
    completeTransactionWithTypeAndKey.setPaymentExternalKey(paymentExternalKey);
    completeTransactionWithTypeAndKey.setTransactionExternalKey(refundTransactionExternalKey);
    paymentApi.completeTransactionByExternalKey(completeTransactionWithTypeAndKey, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    final Payment completedPaymentByTypeAndKey = paymentApi.getPayment(refundPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, 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());
    paymentApi.completeTransaction(refundPayment.getPaymentId(), completeTransactionWithTypeAndId, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    final Payment completedPaymentByTypeAndId = paymentApi.getPayment(refundPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyPaymentWithPendingRefund(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, purchaseAmount, refundTransactionExternalKey, completedPaymentByTypeAndId);
}
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) 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 55 with Account

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

the class TestPayment method testComboAuthorizationControlWithNullPaymentMethodId.

@Test(groups = "slow")
public void testComboAuthorizationControlWithNullPaymentMethodId() throws Exception {
    final Account accountJson = createAccount();
    // Non-default payment method
    final PaymentMethod paymentMethod = createPaymentMethod(accountJson, false);
    mockPaymentControlProviderPlugin.setAdjustedPaymentMethodId(paymentMethod.getPaymentMethodId());
    accountJson.setAccountId(null);
    final String paymentExternalKey = UUID.randomUUID().toString();
    final PaymentTransaction authTransactionJson = new PaymentTransaction();
    authTransactionJson.setPaymentExternalKey(paymentExternalKey);
    authTransactionJson.setAmount(BigDecimal.TEN);
    authTransactionJson.setTransactionType(TransactionType.AUTHORIZE);
    final ComboPaymentTransaction comboPaymentTransaction = new ComboPaymentTransaction();
    comboPaymentTransaction.setAccount(accountJson);
    comboPaymentTransaction.setTransaction(authTransactionJson);
    comboPaymentTransaction.setTransaction(authTransactionJson);
    final Payment payment = paymentApi.createComboPayment(comboPaymentTransaction, ImmutableList.<String>of(MockPaymentControlProviderPlugin.PLUGIN_NAME), requestOptions);
    verifyComboPayment(payment, paymentExternalKey, BigDecimal.TEN, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
    assertEquals(paymentApi.getPayment(payment.getPaymentId(), false, true, ImmutableMap.<String, String>of(), AuditLevel.NONE, requestOptions).getPaymentAttempts().size(), 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) ComboPaymentTransaction(org.killbill.billing.client.model.gen.ComboPaymentTransaction) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.gen.Account)153 Test (org.testng.annotations.Test)139 DateTime (org.joda.time.DateTime)43 UUID (java.util.UUID)38 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)37 Subscription (org.killbill.billing.client.model.gen.Subscription)34 Invoice (org.killbill.billing.client.model.gen.Invoice)33 BigDecimal (java.math.BigDecimal)29 Payment (org.killbill.billing.client.model.gen.Payment)28 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)21 KillBillClientException (org.killbill.billing.client.KillBillClientException)19 Invoices (org.killbill.billing.client.model.Invoices)19 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)19 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)19 LocalDate (org.joda.time.LocalDate)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 Tags (org.killbill.billing.client.model.Tags)13 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)12 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)11 Payments (org.killbill.billing.client.model.Payments)10