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

@pushparajunipay/unipay

v1.0.10

Published

A unified payment gateway SDK for JavaScript.

Downloads

494

Readme

@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: '[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

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.