Stripe.subscribeCustomer()

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.

Usage

Hover over inputs/exits for more info.

var Stripe = require('machinepack-stripe-subscriptions');


// Subscribe a customer to a pre-existing plan.

Stripe.subscribeCustomer({

apiKey: 'somestring837483749blah',

plan: 'premium',

quantity: 20,

card: 'tok_someCardIdjsd2isnsd',

customer: 'cus_4kmLwU2PvQBeqq',

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// OK.

success: function (newSubscription) {

 

},

});

Inputs

apiKey required

Your Stripe API key

'somestring837483749blah'
plan required

The plan id to subscribe the customer to.

'premium'
quantity required

If using a plan with multiple users or other dynamic elements, specify the quantity.

20
card required

The Stripe id of a saved card to charge.

'tok_someCardIdjsd2isnsd'
customer required

The Stripe id of an existing customer to subscribe to the plan.

'cus_4kmLwU2PvQBeqq'

Exits

error

An unexpected error occurred.

success

OK.

{ id: 'sub_6EOW9GHkrQ53Z2',
  plan: 
   { interval: 'month',
     name: 'Gold Plan',
     created: 1431566401,
     amount: 2000,
     currency: 'gbp',
     id: 'gold',
     object: 'plan',
     livemode: false,
     interval_count: 1,
     trial_period_days: null,
     metadata: {},
     statement_descriptor: null },
  object: 'subscription',
  start: 1431505346,
  status: 'active',
  customer: 'cus_654EF6eI4JFErdS',
  cancel_at_period_end: false,
  current_period_start: 1431507646,
  current_period_end: 1434186046,
  ended_at: null,
  trial_start: null,
  trial_end: null,
  canceled_at: null,
  quantity: 2,
  application_fee_percent: null,
  discount: null,
  tax_percent: null,
  metadata: {} }