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

node-stripe-payments

v1.0.6

Published

⚡️ Node Js Package For Implementing Stripe Credit Card Payments In Express/Node Js

Downloads

10

Readme

Node Stripe Payments

⚡️ Node Js Package For Implementing Stripe Payments In Express/Node Js

Installation

Install node-stripe-payments with npm/yarn

  npm install node-stripe-payments
  yarn add node-stripe-payments

Examples

Charge A Credit Card

const { Stripe_Client } = require("node-stripe-payments");

// Create An Instance of "Stripe_Client" Class
nsp_client = new Stripe_Client(""); // Provide Your Stripe Secret Key

async function chargeCreditCard() {
  try {
    /**
     * @method card_token Creates A Card Token
     *
     * For More Information See The Reference https://stripe.com/docs/api/tokens/create_card?lang=node
     *
     * @params @required (Card No,Expiry Month, Expiry Year, CVC) Card Details From Which You Want To Charge/Take Amount
     */
    card_token = await nsp_client.card_token("4242424242424242", 12, 2025, 123); // Returns Promise

    /**
     * @method charge_card Will Call Stripe API To Charge The Card Against Token ID That You Will Get In @response of "card_token" @method
     *
     * For More Information See The Reference https://stripe.com/docs/api/charges/create?lang=node
     *
     * @params (amount, currency, source, description)
     *
     * @param amount: Amount That Will Be Charged From Credit Card (In Cents) @required
     * @param currency: Currency In Which You Want To Charge. Visit: https://stripe.com/docs/currencies @required
     * @param source: Token ID Which You Will Get In Response from "card_token" @method @required
     * @param description: Description Of Charge
     */
    card_charge = await nsp_client.charge_card(
      200000,
      "pkr",
      card_token.id,
      "Test"
    ); // Returns Promise
    console.log(card_charge); // Response Of Charge From Stripe
  } catch ({ message }) {
    console.log(message); // It Will Throw Error Message If Card Details Are Incorrect
  }
}
chargeCreditCard();

Create Checkout Session

const { Stripe_Client } = require("node-stripe-payments");

// Create An Instance of "Stripe_Client" Class
const nsp_client = new Stripe_Client(""); // Provide Your Stripe Secret Key

async function checkoutSession() {
  try {
    /**
     * @var line_items
     *
     * Line Items That Will Be Used To Show Bill And Items Along With Quantity On Checkout Page Hosted By Stripe
     *
     * For More Information See https://stripe.com/docs/api/checkout/sessions/create
     */
    const line_items = [
      {
        price_data: {
          currency: "pkr",
          unit_amount: 200000,
          product_data: {
            name: "T-shirt",
            description: "Comfortable cotton t-shirt",
            // images: [""],  You Can Provide Product Images Here
          },
        },
        quantity: 1,
      },
      {
        price_data: {
          currency: "pkr",
          unit_amount: 200000,
          product_data: {
            name: "Hoodie",
            description: "Comfortable cotton Hoodie",
            // images: [""],  You Can Provide Product Images Here
          },
        },
        quantity: 2,
      },
    ];

    /**
     * @method create_checkout_session
     *
     * @params (line_items,success_url,cancel_url) @required
     * @params (mode,payment_method_types) @optional
     */
    const session = await nsp_client.create_checkout_session(
      line_items,
      "https://www.google.com",
      "https://www.facebook.com"
    ); // Returns Promise
    console.log(session); // Returns An Object On Success. It Returns "url" in object that you can send to frontend in response and from frontend you can redirect user to url to pay amount
  } catch ({ message }) {
    console.log(message);
  }
}
checkoutSession();

Documentation

Official Page

Features

  • Credit Card Payments
  • Checkout Sessions