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

@wizdm/stripe

v3.1.0

Published

Stripe Elements for Angular Material

Downloads

93

Readme

Stripe for Angular and Angular Material

The @wizdm/stripe package brings all the functionalities of Stripe Elements for the web into your Angular application.

Stripe Elements is a set of prebuilt UI components available as a feature of Stripe.js v3. This package, wraps the Stripe Elements into components complying with the Angular forms API, so, to be used according to both template-driven form and reactive form patterns.

Additionally, the package supports Angular Material Form Field, so, all the Stripe Elements can smootly blend in with all the other supported form field controls.

Installation

Use npm to install the @wizdm/stripe module together with the official @stripe/stripe-js module which provides the typings:

npm install @stripe/stripe-js @wizdm/stripe

Notes

Since @stripe/stripe-js package is used for typings only, you can also npm install it as a development dependency (using the --save-dev option)

Usage

Import the StripeModule in the root NgModule of your Angular project. Call the static init() function to configure the StripeModule with your own Stripe public key along with any additional options.

import { StripeModule } from '@wizdm/stripe';

...

@NgModule({
  ...
  imports: [

    // Initialize the stripe.js module
    StripeModule.init('pk_test_xxxxxxxxxxxxxxxxxxxxx'),
    ...
  ]
})
export class AppModule();

Styling Elements

Import StripeElementsModule in your feature module to include the Angular's form API support. The requested Stripe Elements will be provided within an iframe from the Stripe's servers for PCI compliance. This means none of the styling you may provide from your app's css will influence the appearance of the provided Elements. Use the module init() function to configure the elements options instructing Elemetns about the custom fonts to load within the iframe for the elements to fit your desired styling.

import { StripeElementsModule } from '@wizdm/stripe/elements';

...

@NgModule({
  ...
  imports: [

    // Initialize the stripe.js module
    StripeElementsModule.init({

      fonts: [
        { cssSrc: 'https://fonts.googleapis.com/css?family=Ubuntu:400,700' }
      ]      
    }),
    ...
  ]
})
export class MyModule();

Customize each element style using the baseStyle input. When settle to auto the styling values will be automatically detected from the computed style of the wrapping element.

Process payments

Setup your form to collect all the payment information in your component template first:


  <form (ngSubmit)="pay()" #form="ngForm" StripeElements>

    <!-- Name -->
    <input [(ngModel)]="name" name="name" required>
      
    <!-- Email -->
    <input [(ngModel)]="email" name="email" email required>

    <!-- Amount -->
    <input [(ngModel)]="amount" required pattern="\d*"/>

    <!-- Credit Card Stripe Element -->
    <wm-stripe-card [(ngModel)]="card" baseStyle="auto" hidePostalCode name="card" required></wm-stripe-card>

    <!-- Submit button -->
    <button type="submit"[disabled]="!form.valid">Pay Now</button>

  </form>

Use the collected information with Stripe API to process the payment:


@Component({
  ...
})
export class MyComponent {

  public card: StripeCardElement;
  public email: string = '';
  public name: string = '';
  public amount: number;

  constructor(private stripe: StripeService) { }

  // Process the payment
  public pay() {

    // Starts by creating the payment intent server side
    this.createPaymentIntent({

      // Amount goes in cents
      amount: this.amount * 100,
      currency: 'usd'

    }).then( intent => {

      console.log("Confirming payment intent", intent.id);
      
      // Once creates, use the client_secret to confirm the intent with the credit card details
      // from the card element
      return this.stripe.confirmCardPayment( intent.client_secret, {
      
        payment_method: {
          card: this.card,
          billing_details: {
            name: this.name,
            email: this.email
          }
        }
      });

    }).then( result => {

      console.log("Transaction completed", result.paymentIntent?.status);
      ...

    }).catch( e => {
      
      console.log("Transaction terminated", e);
      ...
    });
  }
}

Further usage information and reference details can be found in the Wizdm documentation.