Skip to content

Record every payment operation on the payment transaction - #1067

Merged
KrzysztofPajak merged 6 commits into
developfrom
feature/payment-transaction-history
Nov 19, 2026
Merged

KrzysztofPajak merged 6 commits into
developfrom
feature/payment-transaction-history

Conversation

@KrzysztofPajak

@KrzysztofPajak KrzysztofPajak commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Type: feature

Issue

PaymentTransaction.PaidAmount and RefundedAmount are 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 only MarkAsPaid wrote 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: VoidOfflineCommandHandler set the transaction to Voided and saved it, and only then asked CanVoidOfflineQuery, which requires Authorized. The check therefore always failed after the save: the transaction stayed Voided, the order was never updated, and the panel showed an error. 2.4.x has the same code.

Solution

  • PaymentTransactionEntry, a collection of its own (like OrderNote): PaymentTransactionId, operation type (Payment, Authorization, Capture, Refund, Void), amount, CreatedOnUtc, RecordedBy, optional Reference and Note. 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.Record writes 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 its Can* query, adds neither. The amount is rounded to the currency's NumberDecimal and written with that many decimals (1.235 KWD, 1,250 JPY).
  • Void records only when the transaction ends up Voided, Capture only when it ends up Paid. A capture the gateway settles later no longer sets PaidAmount to the full amount; the payment is recorded when it is marked paid.
  • Who did it is not taken from ambient context in Grand.Business.*: the commands gain CreatedBy (and Reference/Note on MarkAsPaid, PartiallyPaidOffline, PartiallyRefund, PartiallyRefundOffline). The panel sends the staff e-mail. A command without CreatedBy (e.g. from an older plugin) still records the entry, and its note says "recorded" without "by".
  • Checkout: PlaceOrderCommandHandler records a Payment of the paid amount, or an Authorization, by the payment method's system name. A pending payment records nothing until it is paid.
  • Payments.StripeCheckout: the webhook no longer adds paymentIntent.Amount / 100 to PaidAmount before MarkAsPaidCommand. That addition used integer division, and MarkAsPaid sets PaidAmount = TransactionAmount anyway; 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).
  • Merchandise returns: the refund passes RefundedBy and Merchandise return #N to the partial refund commands.
  • VoidOfflineCommandHandler checks CanVoidOfflineQuery before changing anything.
  • Panel (Admin and Store, shared controller and views): an "Operation history" card on the transaction screen; Reference and Note fields in the partial paid popup and in the offline partial refund popup. "Mark as paid" and "Refund offline" now open a popup with the amounts and the same two fields instead of a confirm dialog. Transactions from before this change show "No operations recorded. Operations made before this version are not listed."
  • Resources in DefaultLanguage.xml and Upgrade/en_250.xml. Index PaymentTransactionId_CreatedOnUtc in the installer and in MigrationPaymentTransactionEntryIndex (2.5). No backfill.
  • .ai/skills/plugin-payment.md: a redirect plugin's return handler records money through MarkAsPaidCommand / MarkAsAuthorizedCommand, not by setting PaidAmount and calling UpdatePaymentTransaction, 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 of PaidAmount / RefundedAmount when two operations save the same transaction at once (the history is no longer affected by it).

Breaking changes

  • BasePaymentTransactionController and both PaymentTransactionControllers take an extra IContextAccessor and IPaymentTransactionHistoryService. A subclass outside this repository has to pass them.
  • The ten payment command handlers take IPaymentTransactionHistoryService.
  • The POST actions MarkPaymentTransactionAsPaid and RefundPaymentTransactionOffline are replaced by MarkAsPaidPopup and RefundOfflinePopup (GET and POST).
  • A capture the provider reports as still pending no longer sets PaidAmount.
  • The ten payment commands gain optional properties. Existing senders compile and keep working.
  • The order note written by "Mark as paid" changes from "Order has been marked as paid" to the new format.
  • Void (offline) now actually voids an authorized transaction (see Issue).

Testing

  1. Place an order with an offline method (e.g. Check / Money order) and open Sales → Payment transactions → the transaction.
  2. "Partial paid (offline)": enter an amount, a reference and a note. The Operation history card shows a Payment row with them, and the order's notes show Payment of … recorded by <your e-mail>. Reference: …. Note: ….
  3. "Mark as paid": the popup shows the transaction and paid amounts; with a reference it adds a second Payment row with the remaining amount.
  4. "Partial refund (offline)" with a reference: a Refund row and a third order note. "Partial refund" (online) shows no Reference/Note fields.
  5. Open a transaction created before this change: the card shows the empty-state text.
  6. Repeat 2–4 in the Store panel as a store manager.
  7. 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.StripeCheckout has no test project; its change was verified by building it.

Copilot AI balanced review requested due to automatic review settings November 18, 2026 19:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

…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
@KrzysztofPajak
KrzysztofPajak merged commit 1861e8e into develop Nov 19, 2026
8 of 9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the feature/payment-transaction-history branch November 19, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants