Spaces:
Paused
Paused
Deploy Bot commited on
Commit ·
c04d99a
1
Parent(s): b3850b7
Feat: Enforce strict payment logic
Browse files- src/scenes/user/checkout.js +30 -4
src/scenes/user/checkout.js
CHANGED
|
@@ -355,15 +355,32 @@ const checkoutScene = new Scenes.WizardScene(
|
|
| 355 |
const total = cart.reduce((acc, item) => acc + (item.price * item.count), 0);
|
| 356 |
ctx.wizard.state.total = total;
|
| 357 |
|
|
|
|
| 358 |
if (ctx.wizard.state.deliveryMethod === i18n.delivery_bts) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
ctx.reply(`📨 **BTS Pay**\n\n8600 ...`, navKeyboard(ctx, i18n));
|
| 360 |
return ctx.wizard.selectStep(9);
|
| 361 |
}
|
| 362 |
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
return ctx.wizard.next();
|
| 368 |
},
|
| 369 |
// Step 8: Payment Method
|
|
@@ -374,6 +391,15 @@ const checkoutScene = new Scenes.WizardScene(
|
|
| 374 |
if (nav === 'BACK') return ctx.wizard.selectStep(7);
|
| 375 |
|
| 376 |
const choice = ctx.message.text;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
if (choice === i18n.payment_cash) {
|
| 378 |
ctx.wizard.state.paymentMethod = 'Naqd';
|
| 379 |
return await finishOrder(ctx);
|
|
|
|
| 355 |
const total = cart.reduce((acc, item) => acc + (item.price * item.count), 0);
|
| 356 |
ctx.wizard.state.total = total;
|
| 357 |
|
| 358 |
+
// BTS is strictly Card (handled via pre-set or just flow)
|
| 359 |
if (ctx.wizard.state.deliveryMethod === i18n.delivery_bts) {
|
| 360 |
+
// BTS flow usually requires Card payment proof, so we treat it same as Card
|
| 361 |
+
// But existing code jumped to Step 9 directly?
|
| 362 |
+
// Line 358 in original code: return ctx.wizard.selectStep(9);
|
| 363 |
+
// We keep that behavior or merge it.
|
| 364 |
+
// Original: 358: if (ctx.wizard.state.deliveryMethod === i18n.delivery_bts) ... selectStep(9)
|
| 365 |
+
// Let's keep existing BTS logic if it was working, but here we are replacing the block.
|
| 366 |
+
// The original code handled BTS specifically at line 358.
|
| 367 |
+
// Let's replicate that logic first.
|
| 368 |
ctx.reply(`📨 **BTS Pay**\n\n8600 ...`, navKeyboard(ctx, i18n));
|
| 369 |
return ctx.wizard.selectStep(9);
|
| 370 |
}
|
| 371 |
|
| 372 |
+
// Conditional Payment Buttons
|
| 373 |
+
let paymentButtons = [];
|
| 374 |
+
if (ctx.wizard.state.deliveryMethod === i18n.delivery_pickup) {
|
| 375 |
+
// Pickup -> Cash Only
|
| 376 |
+
paymentButtons.push([i18n.payment_cash]);
|
| 377 |
+
} else {
|
| 378 |
+
// Yandex (Delivery) -> Card Only
|
| 379 |
+
paymentButtons.push([i18n.payment_card]);
|
| 380 |
+
}
|
| 381 |
+
paymentButtons.push([i18n.btn_back_nav, i18n.btn_cancel]);
|
| 382 |
+
|
| 383 |
+
ctx.reply(i18n.payment_select, Markup.keyboard(paymentButtons).resize().oneTime());
|
| 384 |
return ctx.wizard.next();
|
| 385 |
},
|
| 386 |
// Step 8: Payment Method
|
|
|
|
| 391 |
if (nav === 'BACK') return ctx.wizard.selectStep(7);
|
| 392 |
|
| 393 |
const choice = ctx.message.text;
|
| 394 |
+
|
| 395 |
+
// Validation: Verify if choice is allowed for current delivery method
|
| 396 |
+
if (ctx.wizard.state.deliveryMethod === i18n.delivery_pickup && choice !== i18n.payment_cash) {
|
| 397 |
+
return ctx.reply("⚠️ Olib ketish uchun faqat Naqd to'lov mavjud.", Markup.keyboard([[i18n.payment_cash], [i18n.btn_back_nav, i18n.btn_cancel]]).resize());
|
| 398 |
+
}
|
| 399 |
+
if (ctx.wizard.state.deliveryMethod === i18n.delivery_yandex && choice !== i18n.payment_card) {
|
| 400 |
+
return ctx.reply("⚠️ Yetkazib berish uchun faqat Karta orqali to'lov mavjud.", Markup.keyboard([[i18n.payment_card], [i18n.btn_back_nav, i18n.btn_cancel]]).resize());
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
if (choice === i18n.payment_cash) {
|
| 404 |
ctx.wizard.state.paymentMethod = 'Naqd';
|
| 405 |
return await finishOrder(ctx);
|