Repository navigation
Record every payment operation on the payment transaction - #1067
Merged
Merged
Conversation
added 5 commits
November 18, 2026 19:51
…appened Each money operation is now a PaymentTransactionEntry record of its own, written once by IPaymentTransactionHistoryService together with its order note. A save of the transaction from a stale copy can no longer drop an entry, and the ten handlers no longer repeat the note-writing code. - Void and Capture record an entry only when the transaction ends up Voided or Paid; a capture the gateway settles later no longer raises PaidAmount - Stripe records the amount the PaymentIntent reports (MarkAsPaidCommand.Amount) - Amounts are kept and written in the currency's precision (NumberDecimal) - Mark as paid and Refund offline open a popup with Reference and Note - The partial refund popup takes online/offline from the model - Index PaymentTransactionId_CreatedOnUtc: installer and 2.5 migration - plugin-payment skill: return handlers record money through the commands
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.
Type: feature
Issue
PaymentTransaction.PaidAmountandRefundedAmountare running totals. A store taking bank transfers or selling on account cannot tell from the transaction when each payment or refund came in, how much it was, who recorded it, or which transfer title or receipt it matches. Of the payment command handlers onlyMarkAsPaidwrote an order note ("Order has been marked as paid"); partial payment, refund, void and capture left no trace on the order.Found on the way:
VoidOfflineCommandHandlerset the transaction toVoidedand saved it, and only then askedCanVoidOfflineQuery, which requiresAuthorized. The check therefore always failed after the save: the transaction stayedVoided, the order was never updated, and the panel showed an error.2.4.xhas the same code.Solution
PaymentTransactionEntry, a collection of its own (likeOrderNote):PaymentTransactionId, operation type (Payment,Authorization,Capture,Refund,Void), amount,CreatedOnUtc,RecordedBy, optionalReferenceandNote. Each entry is a single insert that is never changed, so a save of the transaction from a stale copy (a webhook and a staff action at the same time) cannot drop it, as it could if the list were embedded in the transaction document.IPaymentTransactionHistoryService.Recordwrites the entry and the matching order note, e.g.Payment of 1,250.00 EUR recorded by staff@shop.com. Reference: TR-881. Each of the ten money handlers (MarkAsPaid,MarkAsAuthorized,PartiallyPaidOffline,RefundOffline,PartiallyRefundOffline,VoidOffline,Capture,Refund,PartiallyRefund,Void) calls it once after saving. A gateway operation that returns errors, or an operation refused by itsCan*query, adds neither. The amount is rounded to the currency'sNumberDecimaland written with that many decimals (1.235 KWD,1,250 JPY).Voided, Capture only when it ends upPaid. A capture the gateway settles later no longer setsPaidAmountto the full amount; the payment is recorded when it is marked paid.Grand.Business.*: the commands gainCreatedBy(andReference/NoteonMarkAsPaid,PartiallyPaidOffline,PartiallyRefund,PartiallyRefundOffline). The panel sends the staff e-mail. A command withoutCreatedBy(e.g. from an older plugin) still records the entry, and its note says "recorded" without "by".PlaceOrderCommandHandlerrecords aPaymentof the paid amount, or anAuthorization, by the payment method's system name. A pending payment records nothing until it is paid.Payments.StripeCheckout: the webhook no longer addspaymentIntent.Amount / 100toPaidAmountbeforeMarkAsPaidCommand. That addition used integer division, andMarkAsPaidsetsPaidAmount = TransactionAmountanyway; with it in place the entry would have recorded 0. The webhook now sends the plugin's system name, the payment intent id as the reference, and the amount the intent reports (MarkAsPaidCommand.Amount, optional; without it the entry records what was still to pay).RefundedByandMerchandise return #Nto the partial refund commands.VoidOfflineCommandHandlerchecksCanVoidOfflineQuerybefore changing anything.DefaultLanguage.xmlandUpgrade/en_250.xml. IndexPaymentTransactionId_CreatedOnUtcin the installer and inMigrationPaymentTransactionEntryIndex(2.5). No backfill..ai/skills/plugin-payment.md: a redirect plugin's return handler records money throughMarkAsPaidCommand/MarkAsAuthorizedCommand, not by settingPaidAmountand callingUpdatePaymentTransaction, which would leave the history empty.Out of scope: removing the amounts duplicated on
Order; API exposure (the API module exposes no payment transactions); the pre-existing lost update ofPaidAmount/RefundedAmountwhen two operations save the same transaction at once (the history is no longer affected by it).Breaking changes
BasePaymentTransactionControllerand bothPaymentTransactionControllers take an extraIContextAccessorandIPaymentTransactionHistoryService. A subclass outside this repository has to pass them.IPaymentTransactionHistoryService.MarkPaymentTransactionAsPaidandRefundPaymentTransactionOfflineare replaced byMarkAsPaidPopupandRefundOfflinePopup(GET and POST).PaidAmount.Testing
Payment of … recorded by <your e-mail>. Reference: …. Note: ….dotnet test src/Tests/Grand.Business.Checkout.Tests(920 passed),dotnet test src/Tests/Grand.Web.Admin.Tests(2059 passed),dotnet test src/Tests/Grand.Web.Store.Tests(241 passed).Payments.StripeCheckouthas no test project; its change was verified by building it.