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

@alexandru-paun/ngx-stripe

v1.0.0

Published

An Angular 6+ wrapper for StripeJS elements

Downloads

3

Readme

An Angular 6+ wrapper for StripeJS elements

version license

Ngx Stripe is a thin wrapper around Stripe Elements. It allows adding Elements to any Angular app. The StripeJS Reference covers complete Elements customization details. You can use Elements with any Stripe product to collect online payments. To find the right integration path for your business, explore Stripe Docs.

  • Learn how to use ngx-stripe on the new docs site 🤓

Notice

After reviewing the state of the art for React and Vue counterparts, some major changes are going to be introduced to align this project with Stripe Elements.

  1. ngx-stripe will no longer maintain its own interfaces. Instead, @stripe/stripe-js has been added as peer dependency. This will make the library easier to maintain and avoid mistakes.
  2. Stripe Service has been updated with all the missing APIs from StripeJS
  3. All the missing Element Components like IBAN, Ideal, FPX, ... have been added
  4. Request Payment Button now has full support
  5. Added Container Style functionality support
  6. A Migration guide has been added with details of what have changed
  7. The new version of library is compatible from Angular 6+ major versions. Check the Installation section to see how to install an older version.
  8. All documentation has been moved to a new docs site

In order to ease the transition, we are naming the old version of the library legacy and we have created some npm tags to make it easy to install older versions.

Features

  • Lazy script loading
  • Element Components
  • Stripe Observable wrapper

Installation

Active Versions

To install the last active version:

$ npm install ngx-stripe @stripe/stripe-js

To install an specific version for an older Angular major, use the lts npm tags or check the table below to pick the right version, for example, for v8:

$ npm install ngx-stripe@v8-lts @stripe/stripe-js

Legacy Versions

To install some of the older versions of the library use the legacy npm tags or check the table below to pick the right version, for example, for v7:

$ npm install ngx-stripe@v7-legacy

Choose the version corresponding to your Angular version:

| Angular | ngx-stripe (legacy) | ngx-stripe | | ------- | ------------------- | ----------------- | | 11 | Not Available | 11.x+ | | 10 | Not Available | 10.x+ | | 9 | v9-legacy / 9.0.x+ | v9-lts / 9.1.x+ | | 8 | v8-legacy / 7.4.4+ | v8-lts / 8.1.x+ | | 7 | v7-legacy / 7.x+ | v7-lts / 7.5.x+ | | 6 | v6-legacy / 0.6.x | v6-lts / 6.1.x+ | | 5 | 0.5.x or less | Not Available | | 4 | 0.4.x or less | Not Available |


Using the library

Most of the documentation has been moved to a new docs site. Only a very basic example has been left here:

Import the NgxStripeModule into your application

The module takes the same parameters as the global Stripe object. The APIKey and the optional options to use Stripe connect

  • apiKey: string
  • options?: { stripeAccount?: string; }
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

// Import the library
import { NgxStripeModule } from 'ngx-stripe';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    ReactiveFormsModule,
    NgxStripeModule.forRoot('***your-stripe-publishable-key***'),
    LibraryModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

Card Element Component

Once the module has been imported, you can collect credit card details using the ngx-stripe-card component.

Then you can use the Stripe Service, which is basically an Obseravble wrapper around the stripejs object, to use that information. In this example we use it to create a token, but it can be use to confirm a Payment Intent, Setup Intent, etc...

Please check the docs site to see a complete set of Stripe Element Components available and the full API of the Stripe Service.

// stripe.html

<form novalidate (ngSubmit)="createToken()" [formGroup]="stripeTest">
  <input type="text" formControlName="name" placeholder="Jane Doe">
  <ngx-stripe-card
    [options]="cardOptions"
    [elementsOptions]="elementsOptions"
  ></ngx-stripe-card>
  <button type="submit">
    CREATE TOKEN
  </button>
</form>
import { Component, OnInit, ViewChild } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';

import { StripeService, StripeCardComponent } from 'ngx-stripe';
import {
  StripeCardElementOptions,
  StripeElementsOptions
} from '@stripe/stripe-js';

@Component({
  selector: 'app-create-token',
  templateUrl: 'stripe.html'
})
export class StripeCreateTokenComponent implements OnInit {
  @ViewChild(StripeCardComponent) card: StripeCardComponent;

  cardOptions: StripeCardElementOptions = {
    style: {
      base: {
        iconColor: '#666EE8',
        color: '#31325F',
        fontWeight: '300',
        fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
        fontSize: '18px',
        '::placeholder': {
          color: '#CFD7E0'
        }
      }
    }
  };

  elementsOptions: StripeElementsOptions = {
    locale: 'es'
  };

  stripeTest: FormGroup;

  constructor(private fb: FormBuilder, private stripeService: StripeService) {}

  ngOnInit(): void {
    this.stripeTest = this.fb.group({
      name: ['', [Validators.required]]
    });
  }

  createToken(): void {
    const name = this.stripeTest.get('name').value;
    this.stripeService
      .createToken(this.card.element, { name })
      .subscribe((result) => {
        if (result.token) {
          // Use the token
          console.log(result.token.id);
        } else if (result.error) {
          // Error creating the token
          console.log(result.error.message);
        }
      });
  }
}

License

MIT © Ricardo Sánchez Gregorio