Spaces:
Sleeping
Sleeping
Update app.js
Browse files
app.js
CHANGED
|
@@ -133,11 +133,20 @@ app.post('/webhook/paystack', (req, res) => {
|
|
| 133 |
// This endpoint expects JSON body, so we attach express.json() for this route.
|
| 134 |
// Required fields in body: planId, userId, name (friendly page name) optionally: amount, redirect_url, collect_phone, fixed_amount
|
| 135 |
app.post('/create-payment-link', express.json(), async (req, res) => {
|
| 136 |
-
const { planId, userId, name, amount, redirect_url, collect_phone = false, fixed_amount = false } = req.body || {};
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
if (!planId) return res.status(400).json({ ok: false, message: 'planId is required' });
|
| 143 |
if (!userId) return res.status(400).json({ ok: false, message: 'userId is required' });
|
|
|
|
| 133 |
// This endpoint expects JSON body, so we attach express.json() for this route.
|
| 134 |
// Required fields in body: planId, userId, name (friendly page name) optionally: amount, redirect_url, collect_phone, fixed_amount
|
| 135 |
app.post('/create-payment-link', express.json(), async (req, res) => {
|
|
|
|
| 136 |
|
| 137 |
+
// If req.body was left as a Buffer (because express.raw ran), parse it:
|
| 138 |
+
let body = req.body;
|
| 139 |
+
if (Buffer.isBuffer(body)) {
|
| 140 |
+
try {
|
| 141 |
+
body = JSON.parse(body.toString('utf8'));
|
| 142 |
+
} catch (err) {
|
| 143 |
+
return res.status(400).json({ ok: false, message: 'Invalid JSON' });
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
const { planId, userId, name, amount, redirect_url, collect_phone = false, fixed_amount = false } = body || {};
|
| 148 |
+
|
| 149 |
+
|
| 150 |
|
| 151 |
if (!planId) return res.status(400).json({ ok: false, message: 'planId is required' });
|
| 152 |
if (!userId) return res.status(400).json({ ok: false, message: 'userId is required' });
|