npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angularjs-stripe-elements

v1.0.1

Published

angularjs wrapper around stripe elements

Downloads

2,005

Readme

angularjs-stripe-element

npm version npm

Easily add Stripe Elements in your Angular.js apps.

Usage

Install from NPM:

npm install --save angularjs-stripe-elements

Include the Stripe.js script in your index.html

<script src="https://js.stripe.com/v3/"></script>

From the Stripe website:

To best leverage Stripe’s advanced fraud functionality, include this script on every page on your site, not just the checkout page. Including the script on every page allows Stripe to detect anomalous behavior that may be indicative of fraud as users browse your website.

Add as a dependency of your app

import angular from 'angular'
import 'angularjs-stripe-elements'

angular.module('myApp', [ 'angularjs-stripe-elements'])

Configure the provider

angular.config(function (StripeElementsProvider) {
  StripeElementsProvider.setAPIKey(STRIPE_API_PUBLISHABLE_KEY)
})

Inject the provider into a component's controller

It's a configured instance of the Stripe object.

var component = {
  templateUrl: 'templates/payment-form.html',
  controller: MyCtrl
}

function MyCtrl (StripeElements) {
  var elements = StripeElements.elements()
  var element = elements.create('card', {})

  element.on('change', handleChange)

  this.element = element

  function handleChange (e) {
    this.cardErrors = e.error ? e.error.message : ''
  }
}

Add a stripe-element element to your template and pass it your Element instance

<form method="post" id="payment-form">

  <stripe-element instance="$ctrl.element">
    <!-- a Stripe Element will be inserted here. -->
  </stripe-element>

  <!-- Used to display form errors -->
  <div id="card-errors" role="alert">{{$ctrl.cardErrors}}</div>

  <button>Submit Payment</button>
</form>

Make sure to handle the submission of the form inside your controller

<form ng-submit="$ctrl.handleSubmit" method="post" id="payment-form">
...
</form
ctrl.handleSubmit = function () {
  StripeElements.createToken(ctrl.element).then(function (result) {
    if (result.error) {
      ctrl.cardErrors = result.error.message
    } else {
      // Send the token to your server.
      console.log(result)
    }
  })
}