Skip to content

Muhammad-Owais-Warsi/Better-Pay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Better Pay

Better Pay

The payment layer for modern applications.

Better Pay

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: 'test@gmail.com', // 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: 'test@gmail.com',
 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: 'test@gmail.com',
   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: 'test@gamil.com',
  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 💳

About

The payment layer for modern applications.

Topics

Resources

Stars

Watchers

Forks

Contributors