@fireflysemantics/angular-stripe-service
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

Angular Stripe Service

Stripe service used to integrate Stripe Elements with Angular.

Documentation

Integrating Stripe Elements with Angular

Stackblitz

Stackblitz Demo

Usage

  constructor(
    private cd: ChangeDetectorRef,
    private stripeService:AngularStripeService) {}

  ngAfterViewInit() {
    this.stripeService.setPublishableKey('pk_test_2syov9fTMRwOxYG97AAXbOgt008X6NL46o').then(
      stripe=> {
        this.stripe = stripe;
    const elements = stripe.elements();    
    this.card = elements.create('card');
    this.card.mount(this.cardInfo.nativeElement);
    this.card.addEventListener('change', this.cardHandler);
    });
}

Why?

The @fireflysemantics/angular-stripe-service service injects the Stripe scripts for us and waits for it to load before attempting to initialize elements.

The reason this is important is that if our component containing the Stripe form is loaded before Stripe has a chance to initialize elements then the form will not paint correctly.

In other words the Stripe API download and subsequent elements construction is racing the construction of the credit card form component.

If the form component wins that race, the component does not get constructed right, because elements is not yet available.

Firefly Semantics Slice State Manager

Want simple and lightweight reactive state management for Angular supporting all types, business entities, and object in general then Checkout Firefly Semantics Slice.

Package Sidebar

Install

npm i @fireflysemantics/angular-stripe-service

Weekly Downloads

511

Version

1.0.7

License

MIT

Unpacked Size

32.6 kB

Total Files

14

Last publish

Collaborators

  • ole.ersoy