@storecraft/payments-razorpay
v1.4.2
Published
Official Razorpay payment gateway integration for Storecraft
Maintainers
Readme
Razorpay payment gateway for StoreCraft
Razorpay payment gateway integration for StoreCraft. Razorpay is the dominant payment gateway in India and South Asia, supporting UPI, Netbanking, Cards, and Wallets.
Features
- Create checkouts (Razorpay order creation)
capture,refundactions- Synchronous payment completion with signature verification
- Webhook support for async payment events
- Buy link HTML with Razorpay Standard Checkout UI
- Supports both
manualandautomaticcapture modes
Install
npm i @storecraft/payments-razorpayConfiguration
import { Razorpay } from '@storecraft/payments-razorpay';
const gateway = new Razorpay({
key_id: process.env.RAZORPAY_KEY_ID,
key_secret: process.env.RAZORPAY_KEY_SECRET,
default_currency_code: 'INR',
capture_mode: 'manual',
});If key_id and key_secret are not passed in config, they are read
automatically from env variables RAZORPAY_KEY_ID and RAZORPAY_KEY_SECRET.
In StoreCraft App
import { App } from '@storecraft/core';
import { NodePlatform } from '@storecraft/core/platform/node';
import { MongoDB } from '@storecraft/database-mongodb';
import { Razorpay } from '@storecraft/payments-razorpay';
const app = new App(config)
.withPlatform(new NodePlatform())
.withDatabase(new MongoDB())
.withPaymentGateways({
razorpay: new Razorpay(),
})
.init();Webhook setup
- go to your razorpay dashboard -> settings -> webhooks
- set the webhook url to
https://your-domain.com/api/gateways/razorpay/webhook - select events:
payment.authorized,payment.captured,payment.failed,refund.processed - copy the webhook secret and set it as env variable
RAZORPAY_WEBHOOK_SECRET
the gateway handles these four events. all other events are ignored and return
null so storecraft takes no action.
Testing
get test api keys from https://dashboard.razorpay.com/app/keys (switch to test mode).
test card numbers (from https://razorpay.com/docs/payments/payments/test-card-details/):
| card network | number | cvv | expiry | |--------------|---------------------|-------|------------| | visa | 4111 1111 1111 1111 | any 3 | any future | | mastercard | 5267 3181 8797 5449 | any 3 | any future |
create tests/.env with your test credentials:
RAZORPAY_KEY_ID=rzp_test_XXXXXXXXXXXXXXXX
RAZORPAY_KEY_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXto run the unit tests:
cd packages/payments/payments-razorpay
npm testto run the full integration test against razorpay test mode:
cd packages/payments/payments-razorpay
node --env-file=tests/.env tests/app.test.local.jsAuthor: nischaldoescode
