Subscribe a customer to a pre-existing plan.
To subscribe a customer, you must first create a customer object with a saved card and a subscription plan (You can do this in your Stripe control panel). If your API key is in test mode, the supplied card won't actually be charged, though everything else will occur as if in live mode. (Stripe assumes that the charge would have completed successfully). Also note that you can use one of the [test cards provided by Stripe](https://stripe.com/docs/testing#cards), each of which always fails in one predetermined ways.
var Stripe = require('machinepack-stripe');
// Subscribe a customer to a pre-existing plan.
Stripe.subscribeCustomer({
customer: 'cus_4kmLwU2PvQBeqq',
plan: 'premium',
: ,
source: 'tok_someCardIdjsd2isnsd',
quantity: 20,
coupon: 'HALFOFF',
trialEnd: 1471583633,
metadata: {},
}).exec({
// An unexpected error occurred.
error: function (err) {
},
// OK.
success: function (result) {
},
});
The ID of an existing customer to subscribe to the plan.
'cus_4kmLwU2PvQBeqq'
The ID of a plan to subscribe the customer to.
'premium'
The ID of a saved payment source to charge.
'tok_someCardIdjsd2isnsd'
If using a plan with multiple users or other dynamic elements, specify the quantity.
20
The code of a coupon to apply to this subscription.
'HALFOFF'
Timestamp representing the end of the trial period the customer will get before being charged for the first time.
1471583633
Metadata to attach to the subscription.
{}
An unexpected error occurred.
OK.
{
id: 'sub_929dHmk5spqvgi',
object: 'subscription',
application_fee_percent: 0,
cancel_at_period_end: false,
canceled_at: 0,
created: 1471583633,
current_period_end: 1474262033,
current_period_start: 1471583633,
customer: 'cus_92418YMzH9wiaI',
discount: 0,
ended_at: 0,
livemode: false,
metadata: {},
plan: {
id: 'pro',
object: 'plan',
amount: 3000,
created: 1471559116,
currency: 'usd',
interval: 'month',
interval_count: 1,
livemode: false,
metadata: {},
name: 'Pro',
statement_descriptor: 'Pro Plan',
trial_period_days: 0
},
quantity: 1,
start: 1471583633,
status: 'active',
tax_percent: 0,
trial_end: 0,
trial_start: 0
}