Stripe.createCharge()

Create a new charge for a customer.

To charge a source (e.g. a credit card), you create a new charge object. If your API key is in test mode, the supplied source 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');


// Create a new charge for a customer.

Stripe.createCharge({

amount: 500,

currency: 'usd',

source: 'tok_someCardIdjsd2isnsd',

capture: true,

: ,

customer: 'cus_4kmLwU2PvQBeqq',

description: 'This notable charge was for several gallons of mayonnaise!',

metadata: {},

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// OK.

success: function (result) {

 

},

});

Inputs

amount required

The amount to charge, in the smallest currency unit (e.g. 500 to charge $5.00).

500
currency required

3-letter ISO code for currency.

'usd'
source required

The Stripe id of a saved source to charge.

'tok_someCardIdjsd2isnsd'
capture required

Whether to capture payment immediately, or just authorize it.

true
undefined

customer

The Stripe id of an existing customer to charge.

'cus_4kmLwU2PvQBeqq'
description

An arbitrary string to attach to the charge object in Stripe.

'This notable charge was for several gallons of mayonnaise!'
metadata

Arbitrary metadata to attach to the new customer.

{}

Exits

error

An unexpected error occurred.

success

OK.

{ id: 'ch_18k5K7AE8iIXJx4mUZo8Pqgf',
  object: 'charge',
  amount: 100,
  amount_refunded: 0,
  application_fee: 0,
  balance_transaction: 'txn_18k5K7AE8iIXJx4mrCfIcn0X',
  captured: true,
  created: 1471583623,
  currency: 'usd',
  customer: 'cus_92418YMzH9wiaI',
  description: 'My First Test Charge (created for API docs)',
  failure_code: '',
  failure_message: '',
  livemode: false,
  metadata: {},
  paid: true,
  receipt_email: '',
  receipt_number: '',
  shipping: '',
  source: 
   { id: 'card_18epPlAE8iIXJx4mjtBTiliY',
     object: 'card',
     address_city: '',
     address_country: '',
     address_line1: '',
     address_line1_check: '',
     address_line2: '',
     address_state: '',
     address_zip: '',
     address_zip_check: '',
     brand: 'Visa',
     country: 'US',
     customer: 'cus_92418YMzH9wiaI',
     cvc_check: '',
     dynamic_last4: '',
     exp_month: 8,
     exp_year: 2017,
     funding: 'credit',
     last4: '4242',
     metadata: {},
     name: '',
     tokenization_method: '' },
  source_transfer: '',
  statement_descriptor: '',
  status: 'succeeded' }