1.1.7 โ€ข Published 10 months ago

unifi-payment v1.1.7

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

๐Ÿ› ๏ธ 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()

GatewaySupported
StripeโŒ
RazorpayโŒ
PayPalโŒ
Authorize.Netโœ”๏ธ

createCheckoutSession()

GatewaySupported
Stripeโœ”๏ธ
Razorpayโœ”๏ธ
PayPalโœ”๏ธ
Authorize.Netโœ”๏ธ

capturePayment()

GatewaySupported
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.

1.1.7

10 months ago

1.1.6

11 months ago

1.1.5

11 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.1.2

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago