All Projects → code-corps → ember-stripe-elements

code-corps / ember-stripe-elements

Licence: MIT License
A simple Ember wrapper for Stripe Elements.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to ember-stripe-elements

ember-credit-card
"make your credit card form dreamy in one line of code"
Stars: ✭ 89 (+39.06%)
Mutual labels:  ember, stripe, ember-addon
ember-deep-set
Deeply set values on an Ember Object or POJO
Stars: ✭ 30 (-53.12%)
Mutual labels:  ember, ember-addon
ember-simple-auth-token
Ember Simple Auth extension that is compatible with token-based authentication like JWT.
Stars: ✭ 356 (+456.25%)
Mutual labels:  ember, ember-addon
ember-rapid-forms
Smart, Intuitive forms for Ember.js styled with Bootstrap, Multi layouts and Validation support.
Stars: ✭ 58 (-9.37%)
Mutual labels:  ember, ember-addon
ember-bootstrap-power-select
Integrate ember-power-select into your ember-bootstrap forms
Stars: ✭ 37 (-42.19%)
Mutual labels:  ember, ember-addon
ember-do-forms
ember-do-forms handles the icky parts of forms that you don't want to, and leaves the rest to you.
Stars: ✭ 18 (-71.87%)
Mutual labels:  ember, ember-addon
ember-changeset-conditional-validations
Conditional validations for ember-changeset-validations
Stars: ✭ 26 (-59.37%)
Mutual labels:  ember, ember-addon
ember-custom-actions
Custom API actions for Ember applications
Stars: ✭ 73 (+14.06%)
Mutual labels:  ember, ember-addon
ember-headlessui
gavinjoyce.github.io/ember-headlessui/
Stars: ✭ 76 (+18.75%)
Mutual labels:  ember, ember-addon
glimmer-apollo
Ember and Glimmer integration for Apollo Client.
Stars: ✭ 32 (-50%)
Mutual labels:  ember, ember-addon
ember-uikit
The ember implementation of UIkit
Stars: ✭ 24 (-62.5%)
Mutual labels:  ember, ember-addon
ember-luxon
🕐 🌐 [deprecated] Addon thats brings Luxon to Ember applications.
Stars: ✭ 20 (-68.75%)
Mutual labels:  ember, ember-addon
nuxt-stripejs
💳 NuxtJS module for Stripe.js which loads only when required and w/ retry mechanism
Stars: ✭ 17 (-73.44%)
Mutual labels:  stripe, stripe-elements
Penny-Seed
PennySeed is an alternative crowdfunding platform where the funding goal is divided by the number of pledgers
Stars: ✭ 18 (-71.87%)
Mutual labels:  stripe, stripe-elements
ember-google-charts
Google's Material charts made easy for Ember apps - http://sir-dunxalot.github.io/ember-google-charts/
Stars: ✭ 31 (-51.56%)
Mutual labels:  ember, ember-addon
ember-fsm
[Maintenance Mode] A promise-aware finite state machine implementation for Ember
Stars: ✭ 37 (-42.19%)
Mutual labels:  ember, ember-addon
ember-google-analytics-embed
An Ember Addon for adding analytics visualizations using the Google Analytics Embed API.
Stars: ✭ 26 (-59.37%)
Mutual labels:  ember, ember-addon
ember-autoresize-modifier
Autoresize Element Modifier for Ember.js
Stars: ✭ 15 (-76.56%)
Mutual labels:  ember, ember-addon
ember-cli-daterangepicker
Just a simple component to use bootstrap-daterangepicker.
Stars: ✭ 32 (-50%)
Mutual labels:  ember, ember-addon
els-addon-typed-templates
Ember templates linting / autocomplete, based on Typescript language server
Stars: ✭ 27 (-57.81%)
Mutual labels:  ember, ember-addon



Build Status npm version Ember Observer Score Coverage Status Inline docs MIT License

ember-stripe-elements

This addon is currently unmaintained and has been superseded by @adopted-ember-addons/ember-stripe-elements

A simple Ember wrapper for Stripe Elements.

Features

  • Inject <script src="https://js.stripe.com/v3/"></script> into your application's <body>
  • Initialize Stripe with your publishable key
  • Inject a stripev3 service into your controllers so you can use the functions usually available on the stripe object (see https://stripe.com/docs/stripe-js/reference#the-stripe-object):
    • stripe.elements()
    • stripe.createToken()
    • stripe.createSource()
    • stripe.createPaymentMethod()
    • stripe.retrieveSource()
    • stripe.paymentRequest()
    • stripe.redirectToCheckout()
    • stripe.retrievePaymentIntent()
    • stripe.handleCardPayment()
    • stripe.handleCardAction()
    • stripe.confirmPaymentIntent()
    • stripe.handleCardSetup()
    • stripe.confirmCardSetup()
    • stripe.retrieveSetupIntent()
    • stripe.confirmSetupIntent()
  • Simple, configurable Ember components like {{stripe-card}} (demoed in the gif above)

Installation

$ ember install ember-stripe-elements

Note if you want to use all the functions for v3 (e.g. handleCardPayment()) you need to be using the develop branch after installing add this to your package.json

  "dependencies": {
    "ember-stripe-elements": "code-corps/ember-stripe-elements#develop"
  }

Compatibility

  • Ember.js v2.18 or above
  • Ember CLI v2.13 or above
  • Node.js v8 or above

Configuration

Stripe Publishable Key

You must set your publishable key in config/environment.js.

ENV.stripe = {
  publishableKey: 'pk_thisIsATestKey'
};

Mocking the Stripe API

You can configure the Stripe API to be mocked instead of loaded from https://js.stripe.com/v3/. This is useful for testing.

ENV.stripe = {
  mock: true
};

When enabled, a mock Stripe object will be assigned to window.Stripe when your app is initialized.

When using the Stripe mock in tests you will likely need to override the mock's methods according to the needs of your test like so:

this.owner.lookup('service:stripev3').createToken = () => ({ token: { id: 'token' } });

Lazy loading

You can configure Stripe.js to lazy load when you need it.

ENV.stripe = {
  lazyLoad: true
};

When enabled, Stripe.js will not be loaded until you call the load() function on the service. It's best to call this function in a route's beforeModel hook.

// subscription page route

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default Route.extend({
  stripe: service('stripev3'),

  beforeModel() {
    return this.get('stripe').load();
  }
});

You can also pass publishableKey to the load function.

this.get('stripe').load('pk_thisIsATestKey');

Components

Basics

Every component will:

  • Accept the same array of options accepted by Stripe Elements
  • Call update on the Stripe element if the options are updated
  • Bubble the proper JavaScript events into actions
  • Mount Stripe's own StripeElement in a <div role="mount-point"> on didInsertElement
  • Unmount on willDestroyElement
  • Provide access to the stripev3 service
  • Have the base CSS class name .ember-stripe-element
  • Have a CSS class for the specific element that matches the component's name, e.g. {{ember-stripe-card}} has the class .ember-stripe-card
  • Yield to a block
  • Accept autofocus=true passed directly in the component, e.g. {{stripe-card autofocus=true}}

Every component extends from a StripeElement base component which is not exposed to your application.

Actions

The components bubble up all of the JavaScript events that can be handled by the Stripe Element in element.on() from the Ember component using the following actions:

  • ready
  • blur
  • change (also sets/unsets the stripeError property on the component, which can be yielded with the block)
  • focus
  • complete
  • error

You could handle these actions yourself, for example:

{{stripe-card blur="onBlur"}}

Component types

This addon gives you components that match the different Element types:

Stripe recommends using the their card element - a flexible single-line input that collects all necessary card details. The {{stripe-card}} component provides this input.

Additionally Stripe provides the following elements, which you can use to build your own form to collect card details:

  • cardNumber: the card number.
  • cardExpiry: the card's expiration date.
  • cardCvc: the card's CVC number.
  • postalCode: the ZIP/postal code.

These are provided via our {{stripe-elements}} contextual component, which yields sub-components for each element type:

{{#stripe-elements as |elements|}}
  {{elements.cardNumber}}
  {{elements.cardExpiry}}
  {{elements.cardCvc}}
  {{elements.postalCode}}
{{/stripe-elements}}

The {{stripe-elements}} component is a tagless component, so does not have any classes etc on it.

Elements Options

The {{stripe-elements}} contextual component ensures all the individual elements are created from the same Stripe Elements object.

If you want to pass options to the Stripe Elements object, pass them to the {{stripe-elements}} contextual component. For example, when using the single-line card element:

{{#stripe-elements options=elementOptions as |elements|}}
  {{elements.card options=cardOptions}}
{{/stripe-elements}}

Or when creating your own form:

{{#stripe-elements options=elementsOptions as |elements|}}
  {{elements.cardNumber options=cardNumberOptions}}
  {{elements.cardExpiry}}
  {{elements.cardCvc}}
{{/stripe-elements}}

Block usage with element options

In addition to the simple usage above, like {{stripe-card}}, you can also yield to a block, which will yield both an stripeError object and the stripeElement itself.

For example, you can choose to render out the stripeError, as below (runnable in our dummy app).

{{#stripe-card options=options as |stripeElement stripeError|}}
  {{#if stripeError}}
    <p class="error">{{stripeError.message}}</p>
  {{/if}}
  <button {{action "submit" stripeElement}}>Submit</button>
  {{#if token}}
    <p>Your token: <code>{{token.id}}</code></p>
  {{/if}}
{{/stripe-card}}

Also notice the submit action which passes the stripeElement; you could define this in your controller like so:

import Ember from 'ember';
const { Controller, get, inject: { service }, set } = Ember;

export default Controller.extend({
  stripev3: service(),

  options: {
    hidePostalCode: true,
    style: {
      base: {
        color: '#333'
      }
    }
  },

  token: null,

  actions: {
    submit(stripeElement) {
      let stripe = get(this, 'stripev3');
      stripe.createToken(stripeElement).then(({token}) => {
        set(this, 'token', token);
      });
    }
  }
});

Note the naming convention stripeElement instead of element, as this could conflict with usage of element in an Ember component.

Styling

Note that you can use CSS to style some aspects of the components, but keep in mind that the styles object of the options takes precedence.

Contributing

Fork this repo, make a new branch, and send a pull request. Please add tests in order to have your change merged.

Installation

git clone [email protected]:code-corps/ember-stripe-elements.git
cd ember-stripe-elements
npm install

Running

ember serve

Visit your app at http://localhost:4200.

Running Tests

ember test

Testing autofill in browsers

There are self-signed certs in /ssl that will allow you to test autofill inside of the dummy app (or serve as a blueprint for doing this yourself in your own app).

To run using the self-signed certificate, you must:

  • Add 127.0.0.1 localhost.ssl to your hosts file
  • Run the app with ember serve --ssl
  • Add the certificate to your keychain and trust it for SSL
  • Visit the app at https://localhost.ssl:4200.

Building

ember build

For more information on using ember-cli, visit https://ember-cli.com/.

Contributors

Thanks to @begedin, @snewcomer, @filipecrosk, and @Kilowhisky for your early help on this!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].