UNPKG

paiementfactory

Version:

Unified SDK for multiple payment gateways (Easebuzz, Razorpay, etc.)

148 lines (108 loc) 3.72 kB
# 💳PaiementFactory **PaiementFactory** is a simple, powerful, and flexible Node.js module that allows you to integrate multiple payment gateways through a single, unified interface. Whether you're starting with one provider or planning to support many, PaiementFactory makes it easy to plug in different payment gateways and switch between them effortlessly with zero hassle and minimal code changes. --- ## ✨ Features - 🔌 **Plug & Play** Integrate gateways like Razorpay, Easebuzz, and more (coming soon) - 🧼 **Unified API** One clean, consistent interface for all providers - **Quick Integration** Get up and running in minutes --- ## 📚 Available Methods Each payment gateway has the following common methods: ---- ``` create(gateway, config) { } #Initializes the payment gateway with the provided configuration. ``` ``` initiatePayment(data) { return Promise.resolve(); } #Initiates a payment with the given data. Parameters: data (Object): Includes amount, customer info, callback URL, etc. Returns: Promise: Resolves with the payment initiation response from the gateway. ``` ``` checkPaymentStatus(data) { return Promise.resolve(); } Checks the current status of a transaction or payment using provided identifiers. Parameters: data (Object): Includes transaction ID, order ID, or reference ID. Returns: Promise: Resolves with the status response. ``` ``` validateSignature(data) { } #Validates the gateway's signature to confirm the authenticity of received data. Parameters: data (Object): Typically contains payload and signature. Returns: boolean: true if the signature is valid; otherwise false. ``` ## 📦 Installation To install the package, run: ```bash npm install paiementfactory ``` ## 🚀 Quick Start with Razorpay Here's a simple example of how to use **PaiementFactory** with Razorpay: ```js const PaymentFactory = require('paiementfactory') const config = { RAZORPAY_KEY: process.env.RAZORPAY_KEY, RAZORPAY_SECRET: process.env.RAZORPAY_SECRET, } const paymentGateway = PaymentFactory.create('razorpay', config) const data = { amount: 100 user: { name : "John Doe", email : "john@example.com", phone_number : "9876543211", } description = "Testing PG Integration" callback_url = "http://localhost:3000/success" //Front End url notes = { order_id: 'TEST_ORD_12345', user_id: 'TEST_USER_98765', purpose: 'Test Membership Purchase' } } const result = await paymentGateway.initiatePayment(data) console.log(result); ``` ## 🚀 Quick Start with Easebuzz Here's a simple example of how to use **PaiementFactory** with Easebuzz: ENV Test: ---------- EASEBUZZ_HOST=https://testpay.easebuzz.in EASEBUZZ_HOST_DASHBOARD=https://testdashboard.easebuzz.in ENV Prod: --------- EASEBUZZ_HOST=https://pay.easebuzz.in EASEBUZZ_HOST_DASHBOARD=https://dashboard.easebuzz.in ```js const PaymentFactory = require('paiementfactory') const config = { EASEBUZZ_KEY: process.env.EASEBUZZ_KEY, EASEBUZZ_SALT: process.env.EASEBUZZ_SALT, EASEBUZZ_HOST: process.env.EASEBUZZ_HOST, EASEBUZZ_HOST_DASHBOARD: process.env.EASEBUZZ_HOST_DASHBOARD, } const paymentGateway = PaymentFactory.create('easebuzz', config) const data = { transactionID: 'tnxid123', amount: 1, productinfo: 'OnlinePayment', user: { name: 'John Doe', phone_number: '9876543211', email: 'test@test.com' } } const result = await paymentGateway.initiatePayment(data) console.log(result); ```