๐ฆ Installation
Package Installation
Install via npm:
npm install unified-pay-core
Or using yarn:
yarn add unified-pay-core
Prerequisites
Before using unified-pay-core, ensure you have:
- Node.js >= 14.x
- API credentials for at least one supported gateway:
- Webhook endpoints configured (optional, for real-time events)
โก Quick Start
1. Basic Configuration
import { createGateways } from "unified-pay-core";
const gateways = [
{
gateway: "stripe",
config: {
apiKey: "pk_test_xxx", // Stripe publishable key
apiSecret: "sk_test_xxx", // Stripe secret key
webhookSecret: "whsec_xxx", // Stripe webhook secret
},
},
{
gateway: "paypal",
config: {
apiKey: "client_id_xxx", // PayPal client ID
apiSecret: "secret_xxx", // PayPal secret
sandbox: true, // Use sandbox for testing
returnUrl: "https://your-app.com/success",
cancelUrl: "https://your-app.com/cancel",
},
},
];
const paymentGateways = createGateways(gateways);
โ ๏ธ Security Note: Replace
xxx
with your actual API credentials from each gateway dashboard. Never commit real credentials to your repository.
2. Environment Variables (Recommended)
For security, store credentials in environment variables:
# .env.local
STRIPE_PUBLISHABLE_KEY=pk_test_xxx
STRIPE_SECRET_KEY=sk_test_xxx
STRIPE_WEBHOOK_ID=whsec_xxx
PAYPAL_CLIENT_ID=client_id_xxx
PAYPAL_SECRET=secret_xxx
Use them in your configuration:
import { createGateways } from "unified-pay-core";
const gateways = [
{
gateway: "stripe",
config: {
apiKey: process.env.STRIPE_PUBLISHABLE_KEY!,
apiSecret: process.env.STRIPE_SECRET_KEY!,
webhookId: process.env.STRIPE_WEBHOOK_ID,
},
},
{
gateway: "paypal",
config: {
apiKey: process.env.PAYPAL_CLIENT_ID!,
apiSecret: process.env.PAYPAL_SECRET!,
sandbox: true,
returnUrl: "https://your-app.com/success",
cancelUrl: "https://your-app.com/cancel",
},
},
];
const paymentGateways = createGateways(gateways);
๐งช Testing
All gateways support sandbox/test modes for safe development:
Stripe Testing
- Use test API keys that start with
pk_test_...
andsk_test_...
- Use Stripe's test card numbers for testing different scenarios
PayPal Testing
- Set
sandbox: true
in your PayPal configuration - Use PayPal's sandbox environment for testing
Razorpay Testing
- Use test API keys that start with
rzp_test_...
- Use Razorpay's test card numbers for testing different scenarios
๐ Supported Gateways
Gateway | Status | Test Mode | Webhooks |
---|---|---|---|
Stripe | โ Active | โ Yes | โ Yes |
PayPal | โ Active | โ Yes | โ Yes |
Razorpay | โ Active | โ Yes | โ Yes |
Square | ๐ง Coming Soon | - | - |
๐ Next Steps
Now that you have unified-pay-core installed and configured:
- Learn about core functionality
- Explore the API reference
- Check out practical examples
- Review best practices