-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_payment.js
More file actions
34 lines (27 loc) · 1.7 KB
/
Copy pathfix_payment.js
File metadata and controls
34 lines (27 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require('fs');
const pageTsxPath = 'frontend/app/dashboard/backgrounds/page.tsx';
let pageTsx = fs.readFileSync(pageTsxPath, 'utf8');
const regex = /const orderRes = await fetch\(`\$\{process\.env\.NEXT_PUBLIC_BACKEND_URL\}\/api\/payments\/create-order`[\s\S]*?body: JSON\.stringify\(\{ componentId: componentData\.id, currency \}\)\s*\}\)\s*const orderData = \(await orderRes\.json\(\)\) as any\s*if \(!orderData\.success\) \{\s*toast\.error\(orderData\.message \|\| "Failed to create order"\)\s*setIsProcessing\(false\)\s*return\s*\}\s*const options = \{\s*key: process\.env\.NEXT_PUBLIC_RAZORPAY_KEY_ID,\s*amount: orderData\.order\.amount,\s*currency: orderData\.order\.currency,\s*name: "OpnBtn",\s*description: `Purchase \$\{componentData\.name\}`,\s*order_id: orderData\.order\.id,/m;
const replacement = `const orderRes = await fetch(\`\${process.env.NEXT_PUBLIC_BACKEND_URL}/api/payments/component\`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": \`Bearer \${token}\`
},
body: JSON.stringify({ componentId: componentData.id, currency })
})
const orderData = (await orderRes.json()) as any
if (!orderData.success) {
toast.error(orderData.message || "Failed to create order")
setIsProcessing(false)
return
}
const options = {
key: process.env.NEXT_PUBLIC_RAZORPAY_KEY_ID,
amount: orderData.amount,
currency: orderData.currency,
name: "OpenButton",
description: \`Unlock \${orderData.component.name}\`,
order_id: orderData.orderId,`;
pageTsx = pageTsx.replace(regex, replacement);
fs.writeFileSync(pageTsxPath, pageTsx);