1.1.11 • Published 9 months ago

@pushparajunipay/unipay v1.1.11

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
9 months ago

@pushparajunipay/unipay

UniPay is a unified payment gateway solution that simplifies integration with multiple payment providers. This JavaScript SDK provides a seamless way to integrate various payment gateways into your JavaScript applications.

Table of Contents

Installation

To install the UniPay SDK, run the following command:

npm i @pushparajunipay/unipay

You can also use Yarn or pnpm:

yarn add @pushparajunipay/unipay
pnpm add @pushparajunipay/unipay

Supported Payment Gateways

  • Stripe
  • Razorpay
  • Braintree
  • Cashfree
  • Square
  • PayU

Usage

Initializing a Payment Gateway

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: 'customer@example.com',
    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

The SDK uses a custom UniPayError class for error handling. All errors thrown by the SDK will be instances of this class. You can catch and handle these errors as shown in the usage examples above.

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
  }
}

Development

To set up the project for development:

  1. Clone the repository:

    git clone https://github.com/Pushparaj13811/unipay.git
  2. Navigate to the js-sdk directory:

    cd unipay/js-sdk
  3. Install dependencies:

    npm install

Testing

To run tests:

npm test

To run tests in watch mode:

npm run test:watch

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a feature branch:
    git checkout -b feature/AmazingFeature
  3. Commit your changes:
    git commit -m 'Add some AmazingFeature'
  4. Push to your branch:
    git push origin feature/AmazingFeature
  5. Open a Pull Request.

For more details, refer to the main README file in the root directory of the project.


1.1.11

9 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.6

9 months ago

1.0.7

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.2

9 months ago

1.0.3

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago