Subscription
Subscription: Create
- Java
SubscriptionRequest request = new SubscriptionRequest()
.paymentMethodToken("the_token")
.planId("the_plan_id");
Result<subscription> result = gateway.subscription().create(request);
Parameters
The collection of add-ons associated with a subscription. Add-on details can only be managed within the Control Panel.
.add(…)
array.amount(…)
BigDecimal.inheritedFromId(…)
string.neverExpires(…)
boolean.quantity(…)
int.remove(…)
array.update(…)
array.amount(…)
BigDecimal.existingId(…)
string.neverExpires(…)
boolean.quantity(…)
intDynamic descriptors are not enabled on all accounts by default. If you receive a validation error of 92203
or if your dynamic descriptors are not displaying as expected, please contact us.
Dynamic descriptors are sent on a per-transaction basis and define what will appear on your customers' credit card statements for a specific purchase. The clearer the description of your product, the less likely customers will issue chargebacks due to confusion or non-recognition.
See the dynamic descriptor example for additional information.
.name(…)
stringThe value in the business name field of a customer's statement. The specific length/character requirements for this value depend on your processor. Contact us for assistance.
.phone(…)
string.url(…)
stringA collection of discounts associated with this subscription. Discount details can only be managed within the Control Panel.
.add(…)
array.amount(…)
BigDecimal.inheritedFromId(…)
string.neverExpires(…)
boolean.quantity(…)
int.remove(…)
array.update(…)
array.amount(…)
BigDecimal.existingId(…)
string.neverExpires(…)
boolean.quantity(…)
int.firstBillingDate(…)
Calendar.id(…)
string.merchantAccountId(…)
stringThe merchant account ID used to create the subscription's transactions. Currency is also determined by merchant account ID and it must match the Plan's currency. See the Transaction merchantAccountId()
parameter for more information.
.neverExpires(…)
booleanWhen true, the subscription never expires.
When true, the plan's add-ons and discounts are ignored for this subscription.
.description(…)
string.startImmediately(…)
boolean.paymentMethodNonce(…)
stringOne-time-use reference to a payment method provided by your customer, such as a credit card or PayPal account.
A payment method must be vaulted before you can associate it with a subscription, so it's usually simplest to refer to the payment method using its paymentMethodToken. However, there are 2 cases where you can pass a payment method nonce instead of a payment method token:
- If the nonce was generated by our Drop-in UI and you passed a customerId when generating the client token, or
- If the nonce was generated from a vaulted payment method belonging to the customer that will own the subscription
.paymentMethodToken(…)
stringAn alphanumeric value that references a specific payment method stored in your Vault. It is required when creating a subscription unless you pass a paymentMethodNonce()
instead, which can be done under certain circumstances.
.planId(…)
string-
, and _
. Plans must be created in the Control Panel. .price(…)
BigDecimalThe price specified for a subscription. Billing price must be formatted like 10
or 10.00
. If you provide a price, it can't be an empty string and can't be greater than the maximum allowed by the processor (contact us for your specific limit). If you omit the price, the subscription will inherit the price from the plan.
The trial timeframe specified in a plan. Specifying a trial duration via the API will override the subscription's plan details. It is required if trial period is set to true and must be 1-3 digits. If you specify a trial duration of 0, the gateway will start the subscription immediately and not consider it to include a trial period.
.trialDurationUnit(…)
stringday
or month
. Specifying a trial duration unit via the API will override the subscription's plan details..trialPeriod(…)
booleanExamples
Specify merchant account
If you have multiple merchant accounts, you can pass the merchant account ID to specify which
merchant account to use to process transactions for the subscription. If a merchant account ID is
not passed, we'll use your default merchant account. If you would like to change which merchant
account is default, contact us.
- Java
SubscriptionRequest request = new SubscriptionRequest()
.paymentMethodToken("the_token")
.planId("silver_plan_gbp")
.merchantAccountId("gbp_account");
Result<subscription> result = gateway.subscription().create(request);
Create with 3D Secure enriched payment method nonce
If you use 3D Secure and need to apply 3DS to the first transaction of a new subscription, you must
create the subscription using a 3DS-enriched nonce. See
3D Secure for Recurring Transactions
for details on how to properly obtain and use a 3DS-enriched nonce for subscription transactions.
Once you've obtained a 3DS-enriched nonce, provide it on the subscription create call:
- Java
SubscriptionRequest request = new SubscriptionRequest()
.paymentMethodNonce("nonce_from_the_client")
.planId("the_plan_id");
Result<subscription> result = gateway.subscription().create(request);
Override plan details
When creating the subscription, you can modify the default behavior in three ways:
- New add-ons/discounts can be added to the subscription.
- Add-ons/discounts that would be inherited from the plan can be updated on the subscription.
- Add-ons/discounts that would be inherited from the plan can be removed from the subscription.
- Java
SubscriptionRequest request = new SubscriptionRequest()
.paymentMethodToken("the_token")
.planId("the_plan_id")
.addOns()
.add()
.inheritedFromId("add_on_id_1")
.amount(new BigDecimal("20.00"))
.done()
.add()
.inheritedFromId("add_on_id_2")
.amount(new BigDecimal("30.00"))
.done()
.update("add_on_id_3")
.quantity(2)
.done()
.update("add_on_id_4")
.quantity(3)
.done()
.remove("add_on_id_5", "add_on_id_6")
.done()
.discounts()
.add()
.inheritedFromId("discount_id_1")
.amount(new BigDecimal("7.00"))
.done()
.update("discount_id_2")
.amount(new BigDecimal("15.00"))
.done()
.remove("discount_id_3")
.done();
Result<subscription> result = gateway.subscription().create(request);
- amount
- numberOfBillingCycles or neverExpires
- quantity
- Java
SubscriptionRequest request = new SubscriptionRequest()
.paymentMethodToken("the_token")
.planId("the_plan_id")
.addOns()
.add()
.inheritedFromId("add_on_id_1")
.amount(new BigDecimal("20.00"))
.numberOfBillingCycles(2)
.quantity(4)
.done()
.update("add_on_id_2")
.amount(new BigDecimal("15.00"))
.neverExpires(true)
.quantity(2)
.done()
.done()
.discounts()
.add()
.inheritedFromId("discount_id_1")
.amount(new BigDecimal("20.00"))
.numberOfBillingCycles(2)
.quantity(4)
.done()
.update("discount_id_2")
.amount(new BigDecimal("15.00"))
.neverExpires(true)
.quantity(2)
.done()
.done();
Result<subscription> result = gateway.subscription().create(request);
Override trial details
- Java
SubscriptionRequest request = new SubscriptionRequest()
.paymentMethodToken("the_token")
.planId("the_plan_id")
.trialPeriod(false)
.trialDuration(3)
.trialDurationUnit(DurationUnit.MONTH);
Result<subscription> result = gateway.subscription().create(request);
- If you specify a trialDuration of 0, we will start the subscription immediately and not consider it in a trial period.
- Valid values for trialDurationUnit are day and month.
- You can disable the trial period (if the plan has one) by passing trialPeriod as false.
Set start date
You can override the start date from the plan in three different ways:
- Set firstBillingDate to a specific date.
- Set billingDayOfMonth.
- Set the option startImmediately, which overrides any plan start date and starts the subscription immediately.
- Java
Calendar date = Calendar.getInstance();
date.add(Calendar.DAY_OF_MONTH, 3);
SubscriptionRequest request = new SubscriptionRequest()
.paymentMethodToken("the_token")
.planId("silver_plan")
.firstBillingDate(date);
Result<subscription> result = gateway.subscription().create(request);
result.getTarget().getStatus(); // Pending
- Java
SubscriptionRequest request = new SubscriptionRequest()
.paymentMethodToken("the_token")
.planId("silver_plan")
.billingDayOfMonth(15);
Result<subscription> result = gateway.subscription().create(request);
result.getTarget().getStatus(); // Pending
result.getTarget().getBillingDayOfMonth(); // 15
- Java
SubscriptionRequest request = new SubscriptionRequest()
.paymentMethodToken("the_token")
.planId("silver_plan")
.options()
.startImmediately(true)
.done();
Result<subscription> result = gateway.subscription().create(request);
result.getTarget().getStatus(); // Active
result.getTarget().getTransactions().size(); // 1
Dynamic descriptors
- Java
SubscriptionRequest request = new SubscriptionRequest()
.paymentMethodToken("the_token")
.planId("plan_without_trial")
.descriptor()
.name("company*my product")
.phone("3125551212")
.url("company.com")
.done();
Result<subscription> result = gateway.subscription().create(request);
Subscription subscription = result.getTarget();
subscription.getDescriptor().getName(); // "company*my product"
subscription.getDescriptor().getPhone(); // "3125551212"
Transaction transaction = subscription.getTransactions().get(0);
transaction.getDescriptor().getName(); // "company*my product"
transaction.getDescriptor().getPhone(); // "3125551212"