Skip to content

Recurring payments: record the gateway reference at checkout and ignore reports on another one - #1082

Merged
KrzysztofPajak merged 2 commits into
developfrom
feature/recurring-payments-provider-reference
Nov 22, 2026
Merged

KrzysztofPajak merged 2 commits into
developfrom
feature/recurring-payments-provider-reference

Conversation

@KrzysztofPajak

Copy link
Copy Markdown
Member

What

Two shop-side pieces the Stripe stage needs (stacked PR on top: Stripe subscriptions).

  • RecordRecurringPaymentReferenceCommand — a provider records the gateway's reference (the subscription id) as soon as it learns it, typically when the customer completes the checkout, before the first paid cycle is reported. IRecurringPaymentService.RecordProviderReference writes it under the recurring payment's lock and keeps a reference recorded already.
    • A cancel made afterwards, while the payment is still Pending, now asks the gateway to stop (until now a Pending payment without a reference was cancelled in the shop only, and the first cycle report stopped the gateway).
    • A payment cancelled before the reference arrived is stopped at the gateway when it arrives.
  • Reference cross-check — the cycle, failure and ended reports are compared with the recorded reference. A report on another subscription (for example a second one started for the same order) records nothing, logs a warning and leaves a note on the initial order: "check the payment gateway for a second subscription charging the customer". RecordRecurringPaymentEndedCommand gains ProviderReference; RecordFailure / RecordEnded take it.
    • The end of another subscription no longer cancels the one the payment runs on.
    • The check is skipped while either reference is unknown, so a provider that sends none is unaffected.

Calls made (please check)

  • A mismatched report is only noted, not stopped: the shop does not cancel a subscription it does not run on.
  • The reference command stops the gateway on every delivery to an ended payment (a resend asks twice). Stopping a stopped subscription must succeed, which the Stripe PR handles.

Tests

Grand.Business.Checkout.Tests: 1109 passed (service tests on the Mongo test repository + handler tests with mocks).

…re reports on another one

A provider can now record the gateway's reference of a recurring payment as soon as it learns it
(RecordRecurringPaymentReferenceCommand), under the recurring payment's lock. A cancel made before
the first paid cycle then stops the gateway at once; a payment cancelled before the reference was
known is stopped when the reference arrives.

The cycle, failure and ended reports are checked against the recorded reference: a report on
another subscription (for example a second one started for the same order) records nothing and
leaves a note on the initial order. RecordRecurringPaymentEndedCommand gains ProviderReference.
Copilot AI balanced review requested due to automatic review settings November 22, 2026 06:48

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.

…other subscription

The recurring payment service now returns the outcome of every gateway report (Recorded, NotFound,
Duplicate, OtherReference, Ended) with the payment it read under the lock, so the provider commands no
longer read it again to guess why nothing was recorded.

- The first reported reference is recorded whichever report brings it: a failure or an end reported
  before the reference was known now records it, as a paid cycle already did.
- The reference command stops the gateway of an ended payment only when it records the reference, so a
  resent checkout event no longer asks the gateway to cancel again.
- A failure on an ended payment records the missing reference under the lock before the gateway is
  asked to stop, instead of patching it in memory.
- A paid cycle, a failure or a reference reported on another subscription asks the provider to stop
  that subscription and leaves one note per report on the initial order; another subscription that
  ended is only logged.
- RecordRecurringPaymentFailureCommand returns true when the failure was recorded, also while the
  payment is already past due.
@KrzysztofPajak
KrzysztofPajak merged commit 8ead1d5 into develop Nov 22, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the feature/recurring-payments-provider-reference branch November 22, 2026 07:44
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