(SP 1) [Backend] Block checkout when PAYMENTS_ENABLED=false to preven…#279
Conversation
…t paid/none orders
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe checkout route is refactored to validate that payments are enabled before order creation, returning an early 503 error response. This eliminates subsequent complex error-handling branches that previously re-checked payment state and processed multiple conditional paths based on post-creation payment status. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5950c8625
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Description
This PR closes a payments-off edge case where
POST /api/shop/checkoutcould still create and reserve orders whenPAYMENTS_ENABLED=false, resulting in inconsistentpayment_provider='none'+payment_status='paid'orders and stock being reserved without a real payment flow.The checkout route now fail-closes early when payments are disabled, returning a
503 PAYMENTS_DISABLEDresponse before any order/inventory writes occur.Related Issue
Issue: #<issue_number>
Changes
app/api/shop/checkout/route.tsto block checkout whenisPaymentsEnabled()is false.paid/noneorders and inventory reservations when the payment system is intentionally disabled.checkout_payments_disabled) to make the behavior observable in logs.Database Changes (if applicable)
How Has This Been Tested?
Steps:
PAYMENTS_ENABLED=falseand calledPOST /api/shop/checkoutwith a valid payload and Idempotency-Key.503with codePAYMENTS_DISABLED.orders,order_items, orinventory_moves.Screenshots (if applicable)
N/A
Checklist
Before submitting
Reviewers
``
Summary by CodeRabbit