Search in sources :

Example 91 with Account

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

the class TestPayment method testComboAuthorizationAbortedPayment.

@Test(groups = "slow")
public void testComboAuthorizationAbortedPayment() throws Exception {
    final Account accountJson = getAccount();
    accountJson.setAccountId(null);
    final String paymentExternalKey = UUID.randomUUID().toString();
    final ComboPaymentTransaction comboPaymentTransaction = createComboPaymentTransaction(accountJson, paymentExternalKey);
    mockPaymentControlProviderPlugin.setAborted(true);
    try {
        killBillClient.createPayment(comboPaymentTransaction, Arrays.asList(MockPaymentControlProviderPlugin.PLUGIN_NAME), ImmutableMap.<String, String>of(), requestOptions);
        fail();
    } catch (KillBillClientException e) {
        assertEquals(e.getResponse().getStatusCode(), 422);
    }
    assertFalse(mockPaymentControlProviderPlugin.isOnFailureCallExecuted());
    assertFalse(mockPaymentControlProviderPlugin.isOnSuccessCallExecuted());
}
Also used : Account(org.killbill.billing.client.model.Account) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 92 with Account

use of org.killbill.billing.client.model.Account 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 93 with Account

use of org.killbill.billing.client.model.Account 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 94 with Account

use of org.killbill.billing.client.model.Account 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)

Example 95 with Account

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

the class TestEntitlement method testCreateEntitlementInTheFuture.

@Test(groups = "slow", description = "Can create an entitlement in the future")
public void testCreateEntitlementInTheFuture() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    final Subscription input = new Subscription();
    input.setAccountId(accountJson.getAccountId());
    input.setProductName("Shotgun");
    input.setProductCategory(ProductCategory.BASE);
    input.setBillingPeriod(BillingPeriod.MONTHLY);
    input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription entitlementJson = killBillClient.createSubscription(input, initialDate.toLocalDate().plusMonths(1), -1, requestOptions);
    Assert.assertEquals(entitlementJson.getProductName(), input.getProductName());
    Assert.assertEquals(entitlementJson.getProductCategory(), input.getProductCategory());
    Assert.assertEquals(entitlementJson.getBillingPeriod(), input.getBillingPeriod());
    Assert.assertEquals(entitlementJson.getPriceList(), input.getPriceList());
    // Retrieves with GET
    final Subscription subscription = killBillClient.getSubscription(entitlementJson.getSubscriptionId(), requestOptions);
    Assert.assertTrue(subscription.equals(entitlementJson));
    Assert.assertEquals(subscription.getPriceOverrides().size(), 2);
    Assert.assertEquals(subscription.getPriceOverrides().get(0).getPhaseName(), "shotgun-monthly-trial");
    Assert.assertEquals(subscription.getPriceOverrides().get(0).getFixedPrice(), BigDecimal.ZERO);
    Assert.assertNull(subscription.getPriceOverrides().get(0).getRecurringPrice());
    Assert.assertEquals(subscription.getPriceOverrides().get(1).getPhaseName(), "shotgun-monthly-evergreen");
    Assert.assertNull(subscription.getPriceOverrides().get(1).getFixedPrice());
    Assert.assertEquals(subscription.getPriceOverrides().get(1).getRecurringPrice(), new BigDecimal("249.95"));
}
Also used : Account(org.killbill.billing.client.model.Account) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.Account)123 Test (org.testng.annotations.Test)109 UUID (java.util.UUID)32 DateTime (org.joda.time.DateTime)32 Invoice (org.killbill.billing.client.model.Invoice)30 BigDecimal (java.math.BigDecimal)27 Payment (org.killbill.billing.client.model.Payment)24 Subscription (org.killbill.billing.client.model.Subscription)24 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)17 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)16 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)16 KillBillClientException (org.killbill.billing.client.KillBillClientException)14 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)14 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)13 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)10 Payments (org.killbill.billing.client.model.Payments)10 Tags (org.killbill.billing.client.model.Tags)10 Invoices (org.killbill.billing.client.model.Invoices)9 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)9