UniPay

A unified SDK for multiple payment gateways

Featured Project

Project Overview

UniPay is an open-source SDK that unifies multiple payment gateways into a single integration point. It provides a consistent interface for popular gateways like PayPal, Razorpay, Stripe, PhonePe, Paytm, PayU, and Easebuzz without the need to manage multiple routes or endpoints.

Available for JavaScript, PHP (Laravel), and Python (Django), UniPay allows developers to streamline payment processing without handling multiple SDKs. Published as @pushparajunipay/unipay on NPM.

Key Features

Single Integration Point

Integrate multiple payment gateways with a single endpoint

Lightweight SDK

No need to install individual payment gateway SDKs

Easy Setup

Install and configure UniPay with minimal effort

Extensible Architecture

Easily add support for more payment gateways in the future

Error Handling

Consistent error handling across different payment gateways

Scalable Structure

Designed to accommodate future expansions and additional features

Technology Stack

JavaScriptPHP (Laravel)Python (Django)TypeScriptNode.jsREST APIs

Supported Payment Gateways

StripeRazorpayBraintreeCashfreeSquarePayU

Additional gateways like PayPal, PhonePe, Paytm, and Easebuzz are in development.

Implementation Example

// JavaScript Example
import UniPay from '@pushparajunipay/unipay';

const unipay = new UniPay();

unipay.registerPaymentGateway('stripe', {
  apiKey: 'your_stripe_api_key'
});

unipay.registerPaymentGateway('razorpay', {
  apiKey: 'your_razorpay_key_id',
  apiSecret: 'your_razorpay_key_secret'
});

// Processing a Payment

try {
  const paymentResult = await unipay.initiatePayment('stripe', {
    amount: 1000,
    currency: 'USD',
    description: 'Test payment',
    customerEmail: '[email protected]',
    customerPhone: '+1234567890'
  });
  console.log('Payment processed:', paymentResult);
} catch (error) {
  console.error('Payment processing error:', error.message);
}

//Capturing a Payment

try {
  const captureResult = await unipay.capturePayment('stripe', 'payment_intent_id');
  console.log('Payment captured:', captureResult);
} catch (error) {
  console.error('Payment capture error:', error.message);
}
Checking Payment Status
try {
  const paymentStatus = await unipay.getPaymentStatus('razorpay', 'payment_id');
  console.log('Payment status:', paymentStatus);
} catch (error) {
  console.error('Payment status error:', error.message);
}

// Handling Webhooks

app.post('/webhook/stripe', async (req, res) => {
  try {
    const event = await unipay.handleWebhook('stripe', {
      body: req.body,
      signature: req.headers['stripe-signature']
    });
    console.log('Webhook handled:', event);
    res.sendStatus(200);
  } catch (error) {
    console.error('Webhook error:', error.message);
    res.sendStatus(400);
  }
});


// Error Handling

try {
  // SDK operation
} catch (error) {
  if (error instanceof UniPayError) {
    console.error('UniPay error:', error.message);
    // Handle UniPay-specific error
  } else {
    console.error('Unexpected error:', error);
    // Handle other errors
  }
}

Handling Edge Cases

Invalid Credentials

When payment gateway credentials are invalid or missing.

Solution: Implemented clear credential validation with helpful error messages.

Network Issues

Network-related errors during payment processing.

Solution: Implemented retry mechanisms with helpful feedback to users.

Payment Timeouts

Handling cases where payment processing exceeds expected time.

Solution: Added configurable timeout settings and appropriate error handling.

Project Structure

UniPay is organized into separate SDKs for different languages:

uniPay/
├── js-sdk/                        # JavaScript SDK
│   │   ├── src/
│   │   │   ├── index.js               # Main entry point
│   │   │   ├── gateways/              # Payment gateway integrations
│   │   │   │   ├── stripe.js          # Stripe integration
│   │   │   │   ├── razorpay.js        # Razorpay integration
│   │   │   │   └── ...
├── php-sdk/                       # PHP/Laravel SDK
├── python-sdk/                    # Python/Django SDK

Package Usage

The JavaScript version of UniPay can be installed using:

npm install @pushparajunipay/unipay

Note: This package is currently in development phase. Please exercise caution before using it in production.