# stripe-as-promised

> Wrap Stripe.js async methods to return promises

Latest version **2.1.1** (published 2016-12-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install stripe-as-promised
pnpm add stripe-as-promised
yarn add stripe-as-promised
bun add stripe-as-promised
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2016-12-02 |
| First published | 2015-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Ben Drucker |
| Maintainers | bendrucker |
| Keywords | stripe, payments, promise, async, callback |

## Links

- npm: https://www.npmjs.com/package/stripe-as-promised
- Repository: https://github.com/bendrucker/stripe-as-promised
- Issues: https://github.com/bendrucker/stripe-as-promised/issues
- npm.io page: https://npm.io/package/stripe-as-promised

## Dependencies (3)

- [pify](https://npm.io/package/pify.md) ~2.3.0
- [dot-prop](https://npm.io/package/dot-prop.md) ~2.1.0
- [stripe-errback](https://npm.io/package/stripe-errback.md) ~1.0.1

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 2.1.1 (latest) — 2016-12-02
- 2.1.0 — 2016-07-30
- 2.0.0 — 2015-06-04
- 1.0.2 — 2015-04-23
- 1.0.1 — 2015-04-23
- 1.0.0 — 2015-04-10

## README

# stripe-as-promised [![Build Status](https://travis-ci.org/bendrucker/stripe-as-promised.svg?branch=master)](https://travis-ci.org/bendrucker/stripe-as-promised)

> Wrap [Stripe.js](https://stripe.com/docs/stripe.js)'s asynchronous methods to return promises instead of calling callbacks.

## Installing

```sh
# 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`](https://stripe.com/docs/stripe.js#card-createToken)
* [`bankAccount.createToken`](https://stripe.com/docs/stripe.js#bank-account-createToken)
* [`piiData.createToken`](https://stripe.com/docs/stripe.js?#pii-data-createToken)
* [`bitcoinReceiver.createReceiver`](https://stripe.com/docs/stripe.js#bitcoinreceiver-createreceiver)
* [`bitcoinReceiver.pollReceiver`](https://stripe.com/docs/stripe.js#bitcoinreceiver-pollreceiver)
* `bitcoinReceiver.getReceiver` (undocumented)


## Usage

### Example

Below is an abbreviated version of Stripe's [documented example for creating a token](https://stripe.com/docs/stripe.js#collecting-card-details):

```js
// card === {number: '42...', ...}
Stripe.card.createToken(card, stripeResponseHandler);

function stripeResponseHandler(status, token) {
  if (token.error) {
    console.error('Tokenization failed');
  } else {
    console.log('Created token', token.id);
  }
}
```

The same logic with stripe-as-promised would be written as:

```js
var stripe = stripeAsPromised(Stripe, Promise);

stripe.card.createToken(card)
  .then(function (token) {
    console.log('Created token', token.id);
  })
  .catch(function (err) {
    console.error(err);
  });
```

### 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:

```js
stripe.bitcoinReceiver.createReceiver(payment)
  .then(function (receiver) {
    return stripe.bitcoinReceiver.pollReceiver(receiver.id);
  })
  .then(function (receiver) {
    console.log('Payment received!');
  })
  .catch(function (err) {
    console.error('Payment error', err);
  });
```

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](http://bendrucker.me)

---
_Source: https://npm.io/package/stripe-as-promised · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
