feat(payment): verify Razorpay checkout callbacks
This commit is contained in:
1 parent
b1064d442a
commit
10771f1a2b
4 files changed
+36
-2
No files matched your search
@@ -343,6 +343,23 @@ export interface RazorpayConfig {
|
||||
webhookSecret: string;
|
||||
theme?: { color?: string };
|
||||
}
|
||||
export interface RazorpayCheckoutResult {
|
||||
orderId: string;
|
||||
paymentId: string;
|
||||
signature: string;
|
||||
}
|
||||
|
||||
/** Verify the signed result returned by Razorpay Standard Checkout. */
|
||||
export async function verifyRazorpayCheckoutSignature(
|
||||
result: RazorpayCheckoutResult,
|
||||
keySecret: string,
|
||||
) {
|
||||
if (!result.orderId || !result.paymentId || !result.signature || !keySecret) return false;
|
||||
return equal(
|
||||
result.signature.toLowerCase(),
|
||||
await hmac(`${result.orderId}|${result.paymentId}`, keySecret),
|
||||
);
|
||||
}
|
||||
export function razorpayGateway(config: RazorpayConfig): PaymentGateway<RazorpayConfig> {
|
||||
const auth = `Basic ${btoa(`${config.keyId}:${config.keySecret}`)}`;
|
||||
const request = (path: string, init: RequestInit = {}) =>
|
||||
|
||||
Reference in new issue
Block a user