Git Product home page Git Product logo

angular-stripe's Introduction

angular-stripe Build Status

Angular provider for easy interaction with 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 for validating your credit card forms. angular-stripe is powered by stripe-as-promised.

Setup

# use npm
$ npm install --save angular-stripe
# or bower
$ bower install --save angular-stripe

For Angular 1.2 support, you'll need to load angular-q-constructor first.

angular-stripe expects Stripe.js to be available as window.Stripe when it loads.

// 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.setPublishableKey(key) -> undefined

Sets your Stripe publishable key.

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

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


stripe.card

stripe.card.createToken(card [, params]) -> promise

Tokenizes a card using Stripe.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.

The following utility methods are also exposed:


stripe.bankAccount

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

Tokenizes a card using Stripe.bankAccount.createToken.

The following utility methods are also exposed:


stripe.bitcoinReceiver

stripe.bitcoinReceiver.createReceiver -> promise

Creates a bitcoin receiver using Stripe.bitcoinReceiver.createReceiver.

stripe.bitcoinReceiver.pollReceiver -> promise

Polls a bitcoin receiver using Stripe.bitcoinReceiver.pollReceiver. Note that you'll need to implement additional logic if you need to cancel receivers.

The following utility methods are also exposed:


Examples

Charging a card

app.controller('PaymentController', function ($scope, $http, stripe) {
  $scope.charge = function () {
    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 = void 0;
        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);
        }
      });
  };
});

angular-stripe's People

Contributors

bendrucker avatar jpulec avatar zanedeg avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.