Skip to content

Recurring payments: My account tab and order links (slice 4 of 5) - #1078

Merged
KrzysztofPajak merged 7 commits into
developfrom
feature/recurring-payments-storefront
Nov 21, 2026
Merged

KrzysztofPajak merged 7 commits into
developfrom
feature/recurring-payments-storefront

Conversation

@KrzysztofPajak

Copy link
Copy Markdown
Member

Type: feature

Issue

Slices 1–3 (#1075, #1076, #1077) record a recurring payment, react to what the gateway reports and can cancel it, but a customer has no way to see or cancel one. On the order details page nothing links a cycle order to the order the customer placed.

This is slice 4 of 5 of recurring payments (payments roadmap P5): the storefront. The Admin and Store screens are slice 5.

Solution

My account → Recurring payments

  • New RecurringPaymentController (List, Cancel), shaped like OrderApprovalController. Both actions require a registered customer, and Cancel is a POST with antiforgery (from BasePublicController).

  • List is built by GetRecurringPaymentsHandler. Each row shows:

    • the products of the initial order;
    • the cycle ("Every month", "Every 3 months");
    • the payments made ("3 of 12", or "3, until cancelled" when TotalCycles is 0);
    • the next payment date, while the gateway still charges;
    • the status and the initial order's number.

    Paging works like the approvals list (10 per page, at most 50). Orders and products are read in one batch per page. A missing or deleted initial order still gets a row, with no link and no products.

  • Cancel loads the recurring payment and refuses it unless it belongs to the current customer and the current store. A missing id, someone else's payment and another store's payment all get the same message. Otherwise it sends the existing CancelRecurringPaymentCommand with the customer's e-mail as CancelledBy.

  • A gateway refusal is logged as a warning, and the customer sees a fixed message. The provider's text never reaches the customer. Nor does LastError: a PastDue row shows a fixed hint.

  • The tab is controlled by a new CustomerSettings.HideRecurringPaymentsTab (Admin and Store → Settings → Customer). It is shown only to a customer who has at least one recurring payment in the current store, so shops that sell nothing in cycles get no empty tab. That check is one query with pageSize: 1 on a new index; a switched-off tab runs no query.

  • A customer sees only their own recurring payments. RecurringPayment has no OwnerId, so a company owner does not see a sub-account's.

Order details

  • A cycle order shows "Payment N of a recurring order placed as order #X". The number links to the initial order, unless the initial order is deleted.
  • The initial order shows "Manage the recurring payment", which links to the tab. Only the order's own customer sees it, and not through a guest link.

Cycle text

  • RecurringCycleText.ResourceKey (Grand.Business.Core) picks RecurringPayment.Cycle.Month or ...Months and so on. Every period's enum resource is plural, which is what made "Every 1 Months".
  • The cart and the recurring payment e-mails still use the old "Every {0} {1}" text. Moving them to the new keys is left for a separate small PR.

Persisted data

  • New CustomerId_StoreId index on RecurringPayment: in the installer, and in MigrationRecurringPaymentCustomerIndex (2.5).
  • The new setting defaults to false, and a missing field reads as false, so it needs no migration.
  • 33 resources go into DefaultLanguage.xml and en_250.xml. They include Enums.Grand.Domain.Orders.RecurringPaymentStatus.*, which slice 5 will reuse.

Breaking changes

  • IRecurringPaymentService gains GetCustomerRecurringPayments. This only affects custom implementations of the service.
  • GetNavigationHandler and GetOrderDetailsHandler take one more constructor argument.

Testing

Automated:

  • dotnet build GrandNode.slnx → 0 errors.
  • Grand.Web.Tests 649/649, Grand.Business.Checkout.Tests 1082/1082.

The new tests cover:

  • the customer query (scope, order, empty arguments);
  • singular and plural cycle keys;
  • when the tab shows (with and without payments, switched off, no store);
  • the list rows: cycle, payments made, next payment only while charging, cancellable statuses, a missing or deleted initial order, no provider text in a past-due row;
  • the cancel: own payment, another customer's, another store's, an unknown id, a gateway refusal, a switched-off tab;
  • the order details links: cycle order, deleted initial order, initial order seen by its customer, by a company owner and with the tab off, and an ordinary order.

E2E on a throwaway installation (Mongo, sample data, Playwright). No shipped provider charges in cycles yet, so a temporary controller (not part of this PR) inserted initial orders, their recurring payments and a cycle order:

  1. A newly registered customer has no Recurring payments tab. Opening /account/recurringpayments directly shows "You have no recurring payments."
  2. A customer with recurring payments has the tab. One row reads "Every month · 1 of 12 · Monday, December 21, 2026 · Active · 1". A Pending one with no cycle limit reads "Every month · 0, until cancelled · Waiting for the first payment".
  3. The cycle order's details read "Payment 2 of a recurring order placed as order 1", and the number links to order 1. Order 1 shows "Manage the recurring payment", which links to the tab.
  4. A crafted cancel POST with another customer's recurring payment id → "This recurring payment cannot be cancelled." That payment stays Pending.
  5. Cancelling a Pending payment → confirm dialog → "The recurring payment has been cancelled." The status is Cancelled by the customer's e-mail, the customer and the store get their two e-mails, and the row has no Cancel button.
  6. Cancelling an Active payment paid by Cash on delivery, which cannot cancel → "The payment provider could not cancel this recurring payment…". The provider's text appears only in the log, and the payment stays Active.
  7. Admin → Settings → Customer → "Hide 'Recurring payments' tab" → the tab disappears and its URL redirects to /account/info.

Copilot AI balanced review requested due to automatic review settings November 21, 2026 12:32

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.

Comment on lines +31 to +35
catch (Exception ex)
{
logService.LogError(ex, "UpgradeProcess - RecurringPaymentCustomerIndex (2.5)");
return false;
}
support added 2 commits November 21, 2026 13:55
…nt checks

- A customer cancelling a Cancelled or Completed recurring payment is refused instead of told it was cancelled
- A registered customer without an e-mail cancels under their id rather than failing
- The initial order links the Recurring payments tab only in the store the order was placed in
- The navigation asks whether a recurring payment exists in one query
- The customer index covers the tab's newest-first sort
@KrzysztofPajak
KrzysztofPajak merged commit 709f4b9 into develop Nov 21, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the feature/recurring-payments-storefront branch November 25, 2026 09:10
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