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 🙏

© 2025 – Pkg Stats / Ryan Hefner

better-pay

v1.0.16

Published

The payment layer for modern applications.

Downloads

22

Readme

What is Better Pay?

Better Pay is a unified, developer-first payment integration layer that supports multiple payment providers. Designed for flexibility, and simplicity, it helps you manage payment flows without diving deep into each provider's APIs. Whether you're building SaaS, e-commerce, or custom apps — Better pay is streamlines the whole payment process for you.

Integration Support

  • Stripe
  • Square (Single step)
  • Dodo Payments
  • Razorpay (Single step)
  • Coming Soon...

Get Started

  1. Installation
npm i better-pay
  1. Initialise the provider
import { BetterPay } from "better-pay";
   
const provider = new BetterPay({
  provider: " ", // or any provider
  key: " "      // keys or tokens for provider integration
})

STRIPE

Get started with our sample demo app integrated with stripe. Demo

  1. Initialise the provider
import { BetterPay } from "better-pay";
   
const provider = new BetterPay({
  provider: "stripe",
  apiKey: "API_KEY_FOR_STRIPE" 
})
  1. Create Payment

After initializing the provider:

const response = await provider.createPayment({
 amount: 10000,
 currency: 'usd',
 receiptEmail: '[email protected]', // optional
 metadata: {} // optional
})

This returns a client_secret. Send it to your frontend where the customer will enter their card details using Stripe Elements.


NOTE

Supports card elements only.


  1. Confirm Payment

Once you have the payment_method_id from the frontend:

const response = await provider.confirmPayment({
  paymentIntentId: 'YOUR_PAYMENT_INTENT_ID',
  paymentMethodId: 'YOUR_PAYMENT_METHOD_ID',
  returnUrl: 'YOUR_RETURN_URL_AFTER_SUCCESSFULL_PAYMENT'
})

STRIPE PAYMENT LINK

  1. Initialise the provider
import { BetterPay } from "better-pay";
   
const provider = new BetterPay({
  provider: "stripe",
  apiKey: "API_KEY_FOR_STRIPE" 
})
  1. Create Payment Link
  const response = provider.createPaymentLink({
    name: ['NAME_OF_YOUR_PRODUCT'], // You can add more names seperated by comma.
    amount: [1000], // You can add more amount seperated by comma.
    currency: 'usd',
    quantity: [1] // optional. By default 1. You can add more quantity seperated by comma.
    metadata: {} // optional
  })

SQUARE

Get started with our sample demo app integrated with square. Demo

NOTE

Supports card elements only.


  1. Initialise the provider
import { BetterPay } from "better-pay";
   
const provider = new BetterPay({
  provider: "square",
  apiToken: "API_TOKEN_FOR_SQUARE" 
})
  1. Confirm Payment

Get the sourceId from the client uisng the card element provided by Square.

const response = await provider.confirmPayment({
  sourceId: 'YOUR_PAYMENT_SOURCE_ID',
  amount: 100,
  currency: 'USD'
})

DODO PAYMENTS

Get started with our sample demo app integrated with Dodo Payments. Demo

  1. Initialise the provider
import { BetterPay } from "better-pay";
   
const provider = new BetterPay({
  provider: "dodopayments",
  apiKey: "API_KEY_FOR_DODO_PAYMENTS",
  isLiveMode: false // by default false  
})
  1. Create Payment

After initializing the provider:

const response = await provider.createPayment({
 amount: 100,
 currency: 'USD',
 discount: 0, // by default 0
 email: '[email protected]',
 name: 'test',
 phoneNumber: 99999999 // optional
})
  1. Confirm Payment

Get the customerId and productId from above:

const response = await provider.confirmPayment({
  customerId: 'YOUR_CUSTOMER_ID',
  productId: 'YOUR_PRODUCT_ID',
  quantity: 1 // optional. By default set to 1
  city: 'USER_CITY',
  countryIsoCode: 'USER_COUNTRY_ISO_CODE',
  state: 'USER_STATE',
  street: 'USER_STREET',
  zipCode: USER_ZIP_CODE,
  paymentLink: true, // One time payment link. By default false.
  returnUrl: 'YOUR_RETURN_URL_AFTER_SUCCESSFULL_PAYMENT', // optional
  metadata: {} //optional
})

DODO PAYMENTS PAYMENT LINK

  1. Initialise the provider
import { BetterPay } from "better-pay";
   
const provider = new BetterPay({
  provider: "dodopayments",
  apiKey: "API_KEY_FOR_STRIPE",
  isLive: false // By default false. 
})
  1. Create Payment Link
  const response = provider.createPaymentLink({
   amount: [100], // You can add more amount seperated by comma.
   currency: 'USD',
   discount: [0], // by default 0. You can add more discount seperated by comma.
   email: '[email protected]',
   name: 'test',
   phoneNumber: 99999999 // optional
   city: 'USER_CITY',
   countryIsoCode: 'USER_COUNTRY_ISO_CODE',
   state: 'USER_STATE',
   street: 'USER_STREET',
   zipCode: USER_ZIP_CODE,
   paymentLink: true, // One time payment link. By default false.
   returnUrl: 'YOUR_RETURN_URL_AFTER_SUCCESSFULL_PAYMENT', // optional
   metadata: {} //optional
  })

RAZORPAY

Get started with our sample demo app integrated with razorpay. Demo

  1. Initialise the provider
import { BetterPay } from "better-pay";
   
const provider = new BetterPay({
  provider: "razorpay",
  keyId: "KEY_ID_FOR_RAZORPAY",
  keySecret: "KEY_SECRET_FOR_RAZORPAY" 
})
  1. Create Payment Link

Get the necessary details from the user.

const response = await provider.createPaymentLink({

  upiLink: false, // UPI Link. By default false.
  amount: 1000,
  currency: 'INR',
  name: '', // optional
  phoneNumber:  , // optional
  email: '[email protected]',
  isSMS: false // Optional. By default false.
  isEmail: false // Optional. By default false.
  returnUrl: 'YOUR_RETURN_URL_AFTER_SUCCESSFULL_PAYMENT',
  metadata: {} // optional

})

POLAR

Get started with our sample demo app integrated with polar. Demo

  1. Initialise the provider
import { BetterPay } from "better-pay";
   
const provider = new BetterPay({
  provider: "polar",
  accessToken: "ACCESS_TOKEN_FOR_POLAR" 
})
  1. Create Payment

After initializing the provider:

const response = await provider.createPayment({
 name: 'NAME_OF_PRODUCT',
 amount: 10000,
 currency: 'usd',
 organizationId: 'YOUR_ORGANIZATION_ID', // optional
 metadata: {} // optional
})
  1. Confirm Payment

Get the product_id from above:

const response = await provider.confirmPayment({
  productId: ['PRODUCT_ID'], // You can add more amount seperated by comma.
  returnUrl: 'YOUR_RETURN_URL_AFTER_SUCCESSFULL_PAYMENT'
})

Community Support

Better Pay-supporters-light

Contribution

We welcome contributions from the community!

If you'd like to improve Better Pay, add support for a new provider, fix a bug or even a suggestion is much appreciated.

  • Please open an issue first to discuss what you’d like to contribute.

  • Fork this repository.

  • Create a branch with a meaningful name.

  • Make your changes and ensure everything works.

  • Open a pull request with a clear description of what you’ve done.

Before submitting:

  • Follow the existing code style.

  • Add comments or documentation where necessary.

Let's build the future of payments together 💳