Repository navigation
Do not mark a canceled order as paid on Momo callbacks - #1155
Open
blurman-ai wants to merge 1 commit into
Open
blurman-ai wants to merge 1 commit into
blurman-ai wants to merge 1 commit into
Conversation
Record the payment as succeeded with a refund-required note instead.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What happens to a buyer
OrderCancellationBackgroundServicecancels orders that stay inPendingPaymentorPaymentFailedfor more than 5 minutes and puts the items back into stock. With Momo the order is created before the buyer is redirected to the Momo page, so a buyer who pays after that window is charged for an order that is already canceled.momo/resultthen sets the order toPaymentReceivedwithout checking its current status (momo/notifydoes check it, so the outcome depends on which callback arrives first). The shop sees a paid order whose stock may already have been sold to someone else.The fix
IOrderService.IsAwaitingPayment(order): true forPendingPaymentandPaymentFailed.MomoPaymentController.UpdatePaymentStatus(used by result and notify) only changes the order status when the order is awaiting payment. A canceled order stays canceled; if Momo reports success, aPaymentwith statusSucceededandFailureMessage"Payment received after the order was canceled. Refund required." is saved once per transaction id, so an operator can see that a refund is needed.momo/resulttells the buyer that the payment arrived after the order was canceled and to contact the shop.momo/notifyalso handles canceled orders, so the payment is recorded even if the buyer never returns to the result page.Test
New test project
SimplCommerce.Module.Orders.Testswith a theory overIsAwaitingPaymentfor the relevant statuses. It fails (4 of 6 cases) when the check returns true for every status and passes with this change. The controller itself is not covered: the repository has no controller tests.Open question
There is no refund-needed state:
Paymenthas onlySucceeded/Failed. I usedSucceededplus a note inFailureMessage. Would you prefer a dedicatedPaymentStatusorOrderStatusvalue (needs a migration)?Not changed
NganLuong rejects such callbacks with "Invalid order state" and does not record the payment, so the operator cannot see that money was taken. The same check could be applied there in a follow-up.