# angular-stripe

> Angular service provider for interacting with Stripe

Latest version **5.0.0** (published 2017-05-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install angular-stripe
pnpm add angular-stripe
yarn add angular-stripe
bun add angular-stripe
```

## 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 | 5.0.0 |
| Published | 2017-05-15 |
| First published | 2014-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 331 |
| Author | Ben Drucker |
| Maintainers | bendrucker |
| Keywords | angular, stripe, promise, wrapper |

## Links

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

## Dependencies (9)

- [ap](https://npm.io/package/ap.md) ~0.2.0
- [pify](https://npm.io/package/pify.md) ~2.3.0
- [dot-prop](https://npm.io/package/dot-prop.md) ~3.0.0
- [lazy-async](https://npm.io/package/lazy-async.md) ~1.0.1
- [stripe-errback](https://npm.io/package/stripe-errback.md) ~1.0.2
- [load-script-global](https://npm.io/package/load-script-global.md) ~1.0.2
- [stripe-as-promised](https://npm.io/package/stripe-as-promised.md) ~2.1.0
- [angular-q-promisify](https://npm.io/package/angular-q-promisify.md) ~3.0.0
- [angular-assert-q-constructor](https://npm.io/package/angular-assert-q-constructor.md) ~1.0.1

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@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

## Recent versions

- 5.0.0 (latest) — 2017-05-15
- 4.2.13 — 2017-04-10
- 4.2.12 — 2016-03-10
- 4.2.11 — 2016-02-08
- 4.2.10 — 2016-02-08
- 4.2.9 — 2016-02-08
- 4.2.8 — 2015-06-15
- 4.2.7 — 2015-06-15
- 4.2.6 — 2015-06-15
- 4.2.5 — 2015-06-15
- 4.2.4 — 2015-05-25
- 4.2.3 — 2015-05-01
- 4.2.2 — 2015-04-23
- 4.2.1 — 2015-04-23
- 4.2.0 — 2015-04-20
- … 10 more at https://npm.io/package/angular-stripe/versions

## README

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

Angular provider for easy interaction with [Stripe.js](https://stripe.com/docs/stripe.js). angular-stripe wraps Stripe.js's async operations in `$q` promises, making response handling easier and eliminating `$scope.$apply` calls and other repetitive boilerplate in your application. Check out [angular-credit-cards](https://github.com/bendrucker/angular-credit-cards) for validating your credit card forms.

## Installing

```sh
npm install --save angular-stripe
```

## Usage

angular-stripe will load Stripe.js when it's first called. You don't need to directly [include Stripe.js via a `<script>` tag](https://stripe.com/docs/stripe.js#including-stripejs).

```js
// node module exports the string 'angular-stripe' for convenience
angular.module('myApp', [
  require('angular-stripe')
])

// otherwise, include the code first then the module name
angular.module('myApp', [
  'angular-stripe'
])
```

## API

### `stripeProvider`

angular-stripe exposes `stripeProvider` for configuring Stripe.js.

##### `stripeProvider.url`

The URL that will be used to fetch the Stripe.js library.

##### `stripeProvider.setPublishableKey(key)` -> `undefined`

Sets your Stripe [publishable key](https://stripe.com/docs/stripe.js#setting-publishable-key). 

```js
angular
  .module('myApp', [
    'angular-stripe'
  ])
  .config(function (stripeProvider) {
    stripeProvider.setPublishableKey('my_key')
  })
```

<hr>

### `stripe`

Inject `stripe` into your services or controllers to access the API methods. `createToken` returns a `$q` promise. If Stripe responds with an error, the promise will be rejected. 

---

##### `stripe.setPublishableKey(key)` -> `undefined`

Same as [`stripeProvider.setPublishableKey`](#stripeprovidersetpublishablekeykey---undefined)

---

### `stripe.card`

##### `stripe.card.createToken(card [, params])` -> `promise`
 
Tokenizes a card using [`Stripe.card.createToken`](https://stripe.com/docs/stripe.js#card-createToken). You can optionally pass a `key` property under `params` to use a different publishable key than the default to create that token. This is especially useful for applications using [Stripe Connect](https://stripe.com/connect).

The following utility methods are also exposed:

* [`validateCardNumber`](https://stripe.com/docs/stripe.js#card-validateCardNumber)
* [`validateExpiry`](https://stripe.com/docs/stripe.js#card-validateExpiry)
* [`validateCVC`](https://stripe.com/docs/stripe.js#card-validateCVC)
* [`cardType`](https://stripe.com/docs/stripe.js#card-cardType)

---

#### `stripe.bankAccount`
 
##### `stripe.bankAccount.createToken(bankAccount [, params])` -> `promise`

Tokenizes a card using [`Stripe.bankAccount.createToken`](https://stripe.com/docs/stripe.js#bank-account-createToken).

The following utility methods are also exposed:

* [`validateRoutingNumber`](https://stripe.com/docs/stripe.js#bank-account-validateRoutingNumber)
* [`validateAccountNumber`](https://stripe.com/docs/stripe.js#bank-account-validateAccountNumber)

---

#### `stripe.bitcoinReceiver`

##### `stripe.bitcoinReceiver.createReceiver` -> `promise`

Creates a bitcoin receiver using [`Stripe.bitcoinReceiver.createReceiver`](https://stripe.com/docs/stripe.js#bitcoinreceiver-createreceiver).

##### `stripe.bitcoinReceiver.pollReceiver` -> `promise`

Polls a bitcoin receiver using [`Stripe.bitcoinReceiver.pollReceiver`](https://stripe.com/docs/stripe.js#bitcoinreceiver-pollreceiver). Note that you'll need to implement [additional logic if you need to cancel receivers](https://github.com/bendrucker/stripe-as-promised#bitcoin).

The following utility methods are also exposed:

* [`cancelReceiverPoll`](https://stripe.com/docs/stripe.js#bitcoinreceiver-cancelreceiverpoll)

---

## Examples

#### Charging a card

```js
app.controller('PaymentController', function ($scope, $http, stripe) {
  $scope.charge = function charge () {
    return stripe.card.createToken($scope.payment.card)
      .then(function (response) {
        console.log('token created for card ending in ', response.card.last4)
        var payment = angular.copy($scope.payment)
        payment.card = undefined
        payment.token = response.id
        return $http.post('https://yourserver.com/payments', payment)
      })
      .then(function (payment) {
        console.log('successfully submitted payment for $', payment.amount)
      })
      .catch(function (err) {
        if (err.type && /^Stripe/.test(err.type)) {
          console.log('Stripe error: ', err.message)
        }
        else {
          console.log('Other error occurred, possibly with your API', err.message)
        }
      })
  }
})
```

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