Subscription
Subscription: Update
- PHP
$result = $gateway->subscription()->update('a_subscription_id', [
'id' => 'new_id',
'paymentMethodToken' => 'new_payment_method_token',
'price' => '12.34',
'planId' => 'new_plan',
'merchantAccountId' => 'another_merchant_account'
]);
Braintree\Exception\NotFound
exception.
Arguments
id
required, stringAdditional Parameters
The collection of add-ons associated with a subscription. Add-on details can only be managed within the Control Panel.
'add'
array'amount'
String'inheritedFromId'
string'neverExpires'
bool'numberOfBillingCycles'
string'quantity'
int'remove'
array'update'
array'amount'
String'existingId'
string'neverExpires'
bool'numberOfBillingCycles'
string'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'
String'inheritedFromId'
string'neverExpires'
bool'numberOfBillingCycles'
string'quantity'
int'remove'
array'update'
array'amount'
String'existingId'
string'neverExpires'
bool'numberOfBillingCycles'
string'quantity'
int'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'
boolWhether a subscription's billing cycle is set to never expire instead of running for a specific number of billing cycles. If this is set to true, numberOfBillingCycles will be set to null as a subscription can't have a limited number of billing cycles and never expire. If set to false, numberOfBillingCycles can't be null.
The number of billing cycles of the subscription. If this is set to a non-null value, neverExpires will be set to false as a subscription can't both have a limited number of billing cycles and never expire. This value must be greater than or equal to the value of currentBillingCycle
.
'description'
string'prorateCharges'
boolWhen set to true, the plan's add-ons and discounts are removed, setting the value to 0. This parameter can also be used in conjunction with the add parameters to replace a plan's existing add-ons and discounts with those specified.
By default, if the transaction for the prorated amount fails, the subscription is reverted. If you would like to continue with the update to the subscription and add the prorated amount to the balance even though the transaction failed, you should set this field to false.
'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 owns the subscription
'paymentMethodToken'
stringAn alphanumeric value that references a specific payment method stored in your Vault. If provided, this will change the payment method associated with the subscription. Under certain circumstances, you can pass a paymentMethodNonce
instead.
'planId'
string'price'
StringThe 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. You must update the price in this parameter; updating the planId will not automatically change the price of a subscription. You can't update the price of a Past Due, Expired, or Canceled subscription. Price can't be greater than the maximum allowed by the processor. Contact us for your specific limit.
Examples
Add-ons and discounts
- New add-ons/discounts can be added
- Existing add-ons/discounts associated with the subscription can be updated
- Existing add-ons/discounts associated with the subscription can be removed
- PHP
$result = $gateway->subscription()->update('theSubscriptionId', [
'addOns' => [
'add' => [
[ 'inheritedFromId' => 'addOnId1', 'amount' => '25.00' ],
],
'update' => [
[ 'existingId' => 'addOnId2', 'amount' => '50.00' ],
],
'remove' => ['addOnId3']
],
'discounts' => [
'add' => [
[ 'inheritedFromId' => 'discountId1', 'amount' => '7.00' ],
],
'update' => [
[ 'existingId' => 'discountId2', 'amount' => '15.00' ],
],
'remove' => ['discountId3']
]
]);
Update with 3D Secure enriched payment method nonce
If you use 3D Secure and need to apply 3DS to the next transaction of an existing subscription, you
must update the subscription using a
3DS-enriched nonce. See the
3D Secure guide for details on how to
properly obtain a 3DS-enriched nonce, and see the
3D Secure for Recurring Transactions
page for more information on utilizing 3DS for subscription transactions. Once you've obtained a
3DS-enriched nonce, provide it on the subscription update call:
- PHP
$result = $gateway->subscription()->update([
'paymentMethodNonce' => 'nonce_from_the_client',
'id' => 'subscription_id'
]);
Multiple updates
You can also add, update and remove multiple add-ons/discounts at the same time.
- PHP
$result = $gateway->subscription()->update("the_subscription_id", [
'addOns' => [
'add' => [
[ 'inheritedFromId' => 'addOnId1', 'amount' => '20.00' ],
[ 'inheritedFromId' => 'addOnId2', 'amount' => '30.00' ]
],
'update' => [
[ 'existingId' => 'addOnId3', 'quantity' => 2 ],
[ 'existingId' => 'addOnId4', 'quantity' => 3 ]
],
'remove' => ['addOnId5', 'addOnId6']
]
]);
Override details
When adding add-ons/discounts, all details will be inherited from the add-on/discount specified by
the inheritedFromId. You can override any of the following:
- amount
- numberOfBillingCycles or neverExpires
- quantity
- PHP
$result = $gateway->subscription()->update('theSubscriptionId', [
'addOns' => [
'add' => [
[
'inheritedFromId' => 'addOnId1',
'amount' => '25.00',
'numberOfBillingCycles' => 2,
'quantity' => 4
]
],
'update' => [
[
'existingId' => 'addOnId2',
'amount' => '25.00',
'numberOfBillingCycles' => 2,
'quantity' => 4
]
]
]
]);
Remove add-ons and discounts
If you prefer to update a subscription and remove all existing add-ons and discounts, you can pass
the replaceAllAddOnsAndDiscounts option.
- PHP
$result = $gateway->subscription()->update('theSubscriptionId', [
'options' => [
'replaceAllAddOnsAndDiscounts' => true
]
]);