stripe-as-promised
Wrap Stripe.js's asynchronous methods to return promises instead of calling callbacks.
Installing
# npm $ npm install stripe-as-promised
API
stripeAsPromised(Stripe, Promise)
-> promisifedStripe
Stripe
Required
Type: function
The Stripe.js library
Promise
Required
Type: function
A Promise constructor
The returned promisified object promisifes the following methods in addition to exposing utility methods:
card.createToken
bankAccount.createToken
piiData.createToken
bitcoinReceiver.createReceiver
bitcoinReceiver.pollReceiver
bitcoinReceiver.getReceiver
(undocumented)
Usage
Example
Below is an abbreviated version of Stripe's documented example for creating a token:
// card === {number: '42...', ...}Stripecard; { if tokenerror console; else console; }
The same logic with stripe-as-promised would be written as:
var stripe = ; stripecard ;
Bitcoin
For handling bitcoin transactions, you'll probably want to avoid using the pollReceiver
method as-is. cancelReceiverPoll
does not notify the callback passed to pollReceiver
of the cancellation, so the following code could result in a promise that never resolves:
stripebitcoinReceiver ;
If the receiver is never filled, neither statement is printed. In your application, you'll probably want to implement your own polling implementation that treats cancellations as errors that can be caught and handled downstream.
License
MIT © Ben Drucker