@paykit-sdk/razorpay 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4853 -0
- package/dist/index.mjs +4849 -0
- package/dist/razorpay-provider.d.mts +62 -0
- package/dist/razorpay-provider.d.ts +62 -0
- package/dist/razorpay-provider.js +4834 -0
- package/dist/razorpay-provider.mjs +4832 -0
- package/dist/schema.d.mts +275 -0
- package/dist/schema.d.ts +275 -0
- package/dist/schema.js +2 -0
- package/dist/schema.mjs +1 -0
- package/dist/utils/mapper.d.mts +33 -0
- package/dist/utils/mapper.d.ts +33 -0
- package/dist/utils/mapper.js +167 -0
- package/dist/utils/mapper.mjs +160 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# @paykit-sdk/razorpay
|
|
2
|
+
|
|
3
|
+
Razorpay provider for PayKit.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @paykit-sdk/razorpay
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @paykit-sdk/razorpay
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createEndpointHandlers, PayKit } from '@paykit-sdk/core';
|
|
17
|
+
import { razorpay } from '@paykit-sdk/razorpay';
|
|
18
|
+
|
|
19
|
+
export const paykit = new PayKit(razorpay());
|
|
20
|
+
export const endpoints = createEndpointHandlers(paykit);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or with direct config:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { PayKit } from '@paykit-sdk/core';
|
|
27
|
+
import { createRazorpay } from '@paykit-sdk/razorpay';
|
|
28
|
+
|
|
29
|
+
export const paykit = new PayKit(
|
|
30
|
+
createRazorpay({
|
|
31
|
+
keyId: 'rzp_test_...',
|
|
32
|
+
keySecret: '...',
|
|
33
|
+
isSandbox: true,
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Environment Variables
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
RAZORPAY_KEY_ID=rzp_test_...
|
|
42
|
+
RAZORPAY_KEY_SECRET=...
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`isSandbox` is inferred from `NODE_ENV` — set `NODE_ENV=production` for live mode. Whether requests actually hit test or live data is determined by whether `RAZORPAY_KEY_ID` is a `rzp_test_` or `rzp_live_` key, not by `isSandbox` itself.
|
|
46
|
+
|
|
47
|
+
## Next.js API Route
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// app/api/paykit/[...endpoint]/route.ts
|
|
51
|
+
import { endpoints } from '@/lib/paykit';
|
|
52
|
+
import { EndpointPath } from '@paykit-sdk/core';
|
|
53
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
54
|
+
|
|
55
|
+
export async function POST(
|
|
56
|
+
request: NextRequest,
|
|
57
|
+
{ params }: { params: Promise<{ endpoint: string[] }> },
|
|
58
|
+
) {
|
|
59
|
+
const { endpoint: endpointArray } = await params;
|
|
60
|
+
const endpoint = ('/' + endpointArray.join('/')) as EndpointPath;
|
|
61
|
+
const handler = endpoints[endpoint];
|
|
62
|
+
|
|
63
|
+
if (!handler) {
|
|
64
|
+
return NextResponse.json(
|
|
65
|
+
{ message: 'Not found' },
|
|
66
|
+
{ status: 404 },
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const { args } = await request.json();
|
|
71
|
+
const result = await handler(...args);
|
|
72
|
+
return NextResponse.json({ result });
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Webhooks
|
|
77
|
+
|
|
78
|
+
Razorpay signs webhook requests with the webhook secret you configure in the Razorpay dashboard — this is separate from your API key secret.
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
// app/api/paykit/webhooks/route.ts
|
|
82
|
+
import { paykit } from '@/lib/paykit';
|
|
83
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
84
|
+
|
|
85
|
+
export async function POST(request: NextRequest) {
|
|
86
|
+
const body = await request.text();
|
|
87
|
+
|
|
88
|
+
const webhook = paykit.webhooks
|
|
89
|
+
.setup({ webhookSecret: process.env.RAZORPAY_WEBHOOK_SECRET! })
|
|
90
|
+
.on('payment.succeeded', async event => {
|
|
91
|
+
/* payment.captured / order.paid / subscription.charged */
|
|
92
|
+
})
|
|
93
|
+
.on('payment.failed', async event => {
|
|
94
|
+
/* payment.failed */
|
|
95
|
+
})
|
|
96
|
+
.on('refund.created', async event => {
|
|
97
|
+
/* refund.created / refund.processed */
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
await webhook.handle({
|
|
101
|
+
body,
|
|
102
|
+
headersAsObject: Object.fromEntries(request.headers),
|
|
103
|
+
fullUrl: request.url,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return NextResponse.json({ received: true });
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Checkout
|
|
111
|
+
|
|
112
|
+
Razorpay checkouts are built on Payment Links and require an email customer and amount/currency in `provider_metadata`:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
const checkout = await paykit.checkouts.create({
|
|
116
|
+
customer: { email: 'user@example.com' },
|
|
117
|
+
item_id: 'plan_pro',
|
|
118
|
+
session_type: 'one_time',
|
|
119
|
+
quantity: 1,
|
|
120
|
+
success_url: 'https://example.com/success',
|
|
121
|
+
cancel_url: 'https://example.com/cancel',
|
|
122
|
+
provider_metadata: {
|
|
123
|
+
amount: '40000',
|
|
124
|
+
currency: 'INR',
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Redirect user to checkout.payment_url
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Subscriptions
|
|
132
|
+
|
|
133
|
+
Razorpay subscriptions require a pre-existing Plan created via the Razorpay dashboard or API — `item_id` maps to that `plan_id`. Razorpay also requires either `total_count` or `end_at` to create a subscription:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const subscription = await paykit.subscriptions.create({
|
|
137
|
+
customer: { email: 'user@example.com' },
|
|
138
|
+
item_id: 'plan_00000000000001',
|
|
139
|
+
quantity: 1,
|
|
140
|
+
billing_interval: 'month',
|
|
141
|
+
amount: 49900,
|
|
142
|
+
currency: 'INR',
|
|
143
|
+
metadata: null,
|
|
144
|
+
provider_metadata: {
|
|
145
|
+
total_count: 12,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Redirect user to subscription.payment_url to authorize the mandate
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Refunds
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
const refund = await paykit.refunds.create({
|
|
156
|
+
payment_id: 'pay_...',
|
|
157
|
+
amount: 40000,
|
|
158
|
+
reason: 'requested_by_customer',
|
|
159
|
+
metadata: null,
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Omit `amount` from `provider_metadata` for a full refund of the remaining captured amount.
|
|
164
|
+
|
|
165
|
+
## Unsupported
|
|
166
|
+
|
|
167
|
+
Razorpay has no delete-customer API and no cancel-payment/void API — `deleteCustomer` and `cancelPayment` throw `ProviderNotSupportedError`. Use `createRefund` to reverse a captured payment instead of canceling it.
|
|
168
|
+
|
|
169
|
+
## Documentation
|
|
170
|
+
|
|
171
|
+
Full docs at [docs.usepaykit.com/providers/razorpay](https://docs.usepaykit.com/providers/razorpay).
|
|
172
|
+
|
|
173
|
+
## Support
|
|
174
|
+
|
|
175
|
+
- [Razorpay Documentation](https://razorpay.com/docs/api/)
|
|
176
|
+
- [PayKit Issues](https://github.com/usepaykit/paykit-sdk/issues)
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
ISC
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RazorpayOptions, RazorpayProvider } from './razorpay-provider.mjs';
|
|
2
|
+
import '@paykit-sdk/core';
|
|
3
|
+
import './schema.mjs';
|
|
4
|
+
|
|
5
|
+
declare const createRazorpay: (config: RazorpayOptions) => RazorpayProvider;
|
|
6
|
+
declare const razorpay: () => RazorpayProvider;
|
|
7
|
+
|
|
8
|
+
export { RazorpayOptions, RazorpayProvider, createRazorpay, razorpay };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RazorpayOptions, RazorpayProvider } from './razorpay-provider.js';
|
|
2
|
+
import '@paykit-sdk/core';
|
|
3
|
+
import './schema.js';
|
|
4
|
+
|
|
5
|
+
declare const createRazorpay: (config: RazorpayOptions) => RazorpayProvider;
|
|
6
|
+
declare const razorpay: () => RazorpayProvider;
|
|
7
|
+
|
|
8
|
+
export { RazorpayOptions, RazorpayProvider, createRazorpay, razorpay };
|