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

unifi-payment

v1.1.7

Published

unifi-payment is a versatile Node.js library designed to simplify payment processing by integrating with multiple payment gateway This library provides a unified interface for handling payments across various platforms, allowing you to manage transactions

Downloads

779

Readme

🛠️ Unipay Library

Unipay is a unified library that integrates multiple payment gateways—Stripe, Razorpay, PayPal, and Authorize.Net—into your Node.js applications. This library provides a single interface for creating payment sessions, capturing payments, and creating payment intents across different payment providers.

📚 Table of Contents

  1. 🌟 Features
  2. 🚀 Getting Started
  3. 📚 API Reference
  4. 🛠️ Example Implementations
  5. 💻 Contributing
  6. 🔧 License

🌟 Features

  • Unified Interface: Simplifies interaction with multiple payment gateways.
  • Multi-Gateway Support: Supports Stripe, Razorpay, PayPal, and Authorize.Net.
  • Flexible Payment Management: Create payment sessions, capture payments, and create payment intents with ease.
  • Error Handling: Includes robust error handling for different payment providers.
  • Asynchronous Operations: Uses modern async/await syntax for efficient payment processing.

🚀 Getting Started

Installation

Install the Unipay library via npm

npm install unifi-payment

Configuration

Configure Unipay with the necessary API keys for each payment provider you want to use. Here’s an example of how to set up the configuration:

 import Unipay from 'unifi-payment';

 const unipay = new Unipay({
   // Stripe API key
   StripeApiKey: 'your-stripe-api-key',
  
   // Razorpay API key and secret
   RazorpayKeyId: 'your-razorpay-key-id',
   RazorpayKey_secret: 'your-razorpay-key-secret',

   // Authorize.Net API login ID and transaction key
   ApiTransactionKey: 'your-authorize-net-transaction-key',
   apiLoginId: 'your-authorize-net-login-id',

   // PayPal client ID and secret
   PaypalClientSecret: 'your-paypal-client-secret',
   PaypalclientId: 'your-paypal-client-id',
   PaypalMode: 'sandbox', // or 'production'
});

📚 API Reference

Unipay(config)

  • config: object - Configuration object with API keys for each gateway:
    • Stripe: { StripeApiKey: 'your-stripe-api-key' }
    • Razorpay: { RazorpayKeyId: 'your-razorpay-key-id', RazorpayKey_secret: 'your-razorpay-key-secret' }
    • Authorize.Net: { ApiTransactionKey: 'your-authorize-net-transaction-key', apiLoginId: 'your-authorize-net-login-id' }
    • PayPal: { PaypalClientSecret: 'your-paypal-client-secret', PaypalclientId: 'your-paypal-client-id', PaypalMode: 'sandbox' }

createCheckoutSession(data)

  • data: object - Payment session details:
    • amount: number - Amount to be charged in the smallest unit of the currency (e.g., cents).
    • currency: string - Currency code (e.g., 'USD', 'EUR').
    • returnUrl: string - URL to redirect to after successful payment (required for PayPal).
    • cancelUrl: string - URL to redirect to if payment is canceled (required for PayPal).
    • provider: array - List of providers to use (e.g., ["stripe", "paypal"]).

capturePayment(data)

  • data: object - Contains:
    • paymentId: string - ID of the payment to capture.
    • provider: array - List of providers to use (e.g., ["stripe"]).

createPaymentIntent(data)

  • data: object - Contains:
    • amount: number - Amount to be charged in the smallest unit of the currency.
    • currency: string - Currency code (e.g., 'USD', 'EUR').
    • description: string - (Optional) Description of the payment.
    • provider: array - List of providers to use (e.g., ["stripe"]).

🛠️ Example Implementations

Using Multiple Payment Gateways with Unipay

 import Unipay from 'unifi-payment';

 // Initialize Unipay with configuration for multiple gateways
  const unipay = new Unipay({
   // Stripe API key
   StripeApiKey: 'your-stripe-api-key',

   // Razorpay API key and secret
   RazorpayKeyId: 'your-razorpay-key-id',
   RazorpayKey_secret: 'your-razorpay-key-secret',

   // Authorize.Net API login ID and transaction key
   ApiTransactionKey: 'your-authorize-net-transaction-key',
   apiLoginId: 'your-authorize-net-login-id',

   // PayPal client ID and secret
   PaypalClientSecret: 'your-paypal-client-secret',
   PaypalclientId: 'your-paypal-client-id',
   PaypalMode: 'sandbox', // or 'production'
});

 // Define payment details
 const paymentDetails = {
   amount: 5000,
   currency: 'USD',
   returnUrl: 'https://your-site.com/success',
   cancelUrl: 'https://your-site.com/cancel',
   provider: ['stripe', 'razorpay', 'paypal', 'authorizenet'] // List of providers to use
};

// Create checkout sessions with multiple gateways
 unipay.createCheckoutSession(paymentDetails)
   .then(results => {
     console.log('Payment sessions created successfully:', results);
   })
   .catch(error => {
     console.error('Error creating payment sessions:', error);
  });

Using Single Payment Gateways with Unipay

Stripe

 import Unipay from 'unifi-payment';

 const unipay = new Unipay({
   StripeApiKey: 'your-stripe-api-key',
 });

 unipay.createCheckoutSession({
   amount: 1000,
   currency: 'USD',
   provider: ['stripe'],
})
  .then(result => console.log(result))
  .catch(err => console.error(err));` 

Razorpay


 import Unipay from 'unifi-payment';

 const unipay = new Unipay({
   RazorpayKeyId: 'your-razorpay-key-id',
   RazorpayKey_secret: 'your-razorpay-key-secret',
});

 unipay.createCheckoutSession({
   amount: 1000,
   currency: 'INR',
   provider: ['razorpay'],
})
  .then(result => console.log(result))
  .catch(err => console.error(err));` 

PayPal

 import Unipay from 'unifi-payment';

 const unipay = new Unipay({
   PaypalClientSecret: 'your-paypal-client-secret',
   PaypalclientId: 'your-paypal-client-id',
   PaypalMode: 'sandbox', // or 'production'
});

 unipay.createCheckoutSession({
   amount: 50.00,
   currency: 'USD',
   returnUrl: 'https://your-site.com/success',
   cancelUrl: 'https://your-site.com/cancel',
   provider: ['paypal'],
})
  .then(result => console.log(result))
  .catch(err => console.error(err));

Authorize.Net

import Unipay from 'unifi-payment';

const unipay = new Unipay({
  ApiTransactionKey: 'your-authorize-net-transaction-key',
  apiLoginId: 'your-authorize-net-login-id',
});

unipay.createCheckoutSession({
  amount: 5000,
  currency: 'USD',
  provider: ['authorizenet'],
})
  .then(result => console.log(result))
  .catch(err => console.error(err));

createPaymentIntent()

| Gateway | Supported | |----------------|-----------| | Stripe | ❌ | | Razorpay | ❌ | | PayPal | ❌ | | Authorize.Net | ✔️ |

createCheckoutSession()

| Gateway | Supported | |----------------|-----------| | Stripe | ✔️ | | Razorpay | ✔️ | | PayPal | ✔️ | | Authorize.Net | ✔️ |

capturePayment()

| Gateway | Supported | |----------------|-----------| | Stripe | ✔️ | | Razorpay | ✔️ | | PayPal | ✔️ | | Authorize.Net | ✔️ |

💻 Contributing

Contributions to enhance functionality or add more payment gateways are welcome. Please fork the repository and submit a pull request. Make sure to follow the code of conduct and guidelines provided in the repository.