1.0.32 • Published 9 months ago

payment-stripe-v2 v1.0.32

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

payment-stripe-v2

A reusable Stripe payments wrapper for NextJS and EmberJS projects.

Installation

npm install payment-stripe-v2

Usage

NextJS TypeScript Example

  import { StripeClient } from 'payment-stripe-v2';

  const stripeClient = new StripeClient({
    publicKey: process.env.NEXT_PUBLIC_STRIPE_KEY!,
  });

  // Create payment method
  const { paymentMethod, error } = await stripeClient.createPaymentMethod({
    type: 'card',
    card: elements.getElement('card'),
    billing_details: {
      name: 'John Doe',
    },
  });
  // Confirm payment
  const { paymentIntent } = await stripeClient.confirmCardPayment(clientSecret, {
    payment_method: paymentMethod.id,
  });

EmberJS Example

  import Component from '@glimmer/component';
  import { StripeClient } from 'payment-stripe-v2';
  export default class PaymentComponent extends Component {
      stripeClient = new StripeClient({
      publicKey: config.stripeKey,
    });
    async handlePayment() {
      const { paymentMethod } = await this.stripeClient.createPaymentMethod({
        type: 'card',
        card: this.cardElement,
      });
      // Handle payment confirmation
    }
  }

To use this package:

  1. Build and publish to npm:
npm run build
npm publish
  1. Install in your project:
npm install payment-stripe-v2
  1. Usage in NextJS:
  import { StripeClient } from 'payment-stripe-v2';
  const stripeClient = new StripeClient({
    publicKey: process.env.NEXT_PUBLIC_STRIPE_KEY!,
  });
  // Use the client methods
  1. Usage in EmberJS:
  import { StripeClient } from 'payment-stripe-v2';
  const stripeClient = new StripeClient({
    publicKey: config.stripeKey,
  });
  // Use the client methods

This package provides a consistent interface for both frameworks while handling the Stripe.js initialization and common payment operations. The TypeScript types ensure type safety in TypeScript projects while still being usable in JavaScript projects like EmberJS.

1.0.32

9 months ago

1.0.30

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago