Read about Version 2 here (Released October 18th, 2013)
npm install stripe
Documentation is available at https://stripe.com/docs/api/node.
Every resource is accessed via your stripe
instance:
var stripe = require('stripe')(' your stripe API key ');
// stripe.{ RESOURCE_NAME }.{ METHOD_NAME }
Every resource method accepts an optional callback as the last argument:
stripe.customers.create(
{ email: '[email protected]' },
function(err, customer) {
err; // null if no error occurred
customer; // the created customer object
}
);
Additionally, every resource method returns a promise, so you don't have to use the regular callback. E.g.
// Create a new customer and then a new charge for that customer:
stripe.customers.create({
email: '[email protected]'
}).then(function(customer) {
return stripe.charges.create({
amount: 1600,
currency: 'usd',
customer: customer.id
});
}).then(function(charge) {
// New charge created on a new customer
}, function(err) {
// Deal with an error
});
Where you see params
it is a plain JavaScript object, e.g. { email: '[email protected]' }
- account
retrieve()
- balance
retrieve()
listTransactions([params])
retrieveTransaction(transactionId)
- charges
create(params)
list([params])
retrieve(chargeId)
capture(chargeId[, params])
refund(chargeId[, params])
update(chargeId[, params])
updateDispute(chargeId[, params])
closeDispute(chargeId[, params])
setMetadata(chargeId, metadataObject)
(metadata info)setMetadata(chargeId, key, value)
getMetadata(chargeId)
markAsSafe(chargeId)
markAsFraudulent(chargeId)
- coupons
create(params)
list([params])
retrieve(chargeId)
del(chargeId)
- customers
create(params)
list([params])
update(customerId[, params])
retrieve(customerId)
del(customerId)
setMetadata(customerId, metadataObject)
(metadata info)setMetadata(customerId, key, value)
getMetadata(customerId)
createSubscription(customerId, params)
updateSubscription(customerId, subscriptionId, [, params])
cancelSubscription(customerId, subscriptionId, [, params])
listSubscriptions(params)
createCard(customerId[, params])
listCards(customerId)
retrieveCard(customerId, cardId)
updateCard(customerId, cardId[, params])
deleteCard(customerId, cardId)
deleteDiscount(customerId)
- events (types of events)
list([params])
retrieve(eventId)
- invoiceItems
create(params)
list([params])
update(invoiceItemId[, params])
retrieve(invoiceItemId)
del(invoiceItemId)
- invoices
create(params)
list([params])
update(invoiceId[, params])
retrieve(invoiceId)
retrieveLines(invoiceId)
retrieveUpcoming(customerId[, subscriptionId])
pay(invoiceId)
- plans
create(params)
list([params])
update(planId[, params])
retrieve(planId)
del(planId)
- recipients
create(params)
list([params])
update(recipientId[, params])
retrieve(recipientId)
del(recipientId)
setMetadata(recipientId, metadataObject)
(metadata info)setMetadata(recipientId, key, value)
getMetadata(recipientId)
- tokens
create(params)
retrieve(tokenId)
- transfers
create(params)
list([params])
retrieve(transferId)
update(transferId[, params])
cancel(transferId)
listTransactions(transferId[, params])
setMetadata(transferId, metadataObject)
(metadata info)setMetadata(transferId, key, value)
getMetadata(transferId)
- bitcoinReceivers
create(params)
retrieve(receiverId)
list([params])
getMetadata(receiverId)
stripe.setApiKey(' your secret api key ');
stripe.setTimeout(20000); // in ms
(default is node's default:120000ms
)
To run the tests you'll need a Stripe Test API key (from your Stripe Dashboard):
$ npm install -g mocha
$ npm test
Note: On Windows use SET
instead of export
for setting the STRIPE_TEST_API_KEY
environment variable.
If you don't have a prefixed key (in the form sk_test_...
) you can get one by rolling your "Test Secret Key". This can be done under your dashboard (Account Setting -> API Keys -> Click the roll icon next to the "test secret key"). This should give you a new prefixed key ('sk_test_..'), which will then be usable by the node mocha tests.
Originally by Ask Bjørn Hansen ([email protected]). Development was sponsored by YellowBot. Now officially maintained by Stripe.