Skip to content

Recurring payments: record, provider contract and checkout rules (slice 1 of 5) - #1075

Merged
KrzysztofPajak merged 5 commits into
developfrom
feature/recurring-payments
Nov 20, 2026
Merged

KrzysztofPajak merged 5 commits into
developfrom
feature/recurring-payments

Conversation

@KrzysztofPajak

@KrzysztofPajak KrzysztofPajak commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Type: feature

Issue

A product can be marked recurring (cycle length, period, total cycles), and the admin and the cart show it as "billed every N months", but the shop charges once and nothing repeats: no payment method can run a schedule, and nothing records one. Any payment method is offered for such a cart, so the customer is promised cycles the shop never charges.

This is slice 1 of 5 of recurring payments (payments roadmap P5). The provider (gateway) runs the schedule; the shop records what it reports.

Solution

  • Domain: new RecurringPayment collection (store, customer, initial order, payment method, cycle, cycles paid, status Pending/Active/PastDue/Cancelled/Completed, provider reference, last error, embedded paid cycles). Order gets InitialOrderId (set on cycle orders, later slice) and RecurringCycleNumber (1 on the initial order of a recurring payment, 0 otherwise). IRecurringPaymentService with insert, update, get by id, get by initial order, and HasRecurringProducts(cart), the one recurring-cart check. Order.RecurringUseCycles is left untouched.
  • Provider contract: IPaymentProvider.SupportRecurringPayment() (default false) and CancelRecurringPayment(RecurringPayment) (default: error result), as default interface members, so every existing payment plugin compiles and behaves unchanged. IPaymentService.SupportRecurringPayment(systemName).
  • Checkout rules:
    • A guest with a recurring product gets a cart warning asking to log in or register (ShoppingCartWarningsValidator), so the cart page, the checkout and order placement all enforce it. Not on a wishlist, which buys nothing. Checkout from the cart, and the checkout pages, send such a guest to log in (back to the cart afterwards).
    • A cart with a recurring product is offered only methods whose SupportRecurringPayment() is true. When none is left, the payment step shows why, and an approval rule no longer replaces that reason.
    • A built-in order placement rule, RecurringPaymentRuleProvider, blocks a recurring order with a total of 0 (full discount, gift voucher, loyalty points) or with a method that cannot charge in cycles (a stale tab or a crafted post). Being a rule, it is checked wherever the rules are: when a payment method is saved, on the single-method shortcut, on the confirm step (shown before Confirm), and authoritatively at order placement, before any claim or payment.
  • Order placement: after the order is saved and the cart cleared, a Pending RecurringPayment is created for it (cycle copied from the order; TotalCycles = 0 stays 0, meaning until cancelled). Written after the cart is cleared, so a failed write cannot leave a full cart for a second paid order. It exists before the provider's post-process step, so a provider can pass its id to the gateway. CyclesPaid stays 0 until the provider reports the first cycle (the initial order's payment), even when the initial order is already paid; the provider contract says it reports every cycle, the first one included.

Consequence: until a provider supports recurring payments (slice 2: Stripe subscriptions), recurring products cannot be bought. Slices 1 and 2 should reach the same release.

Persisted data:

  • New collection RecurringPayment, unique index InitialOrderId in the installer and in MigrationRecurringPaymentIndex (2.5).
  • Resources in DefaultLanguage.xml and Upgrade/en_250.xml: ShoppingCart.RecurringProductsRequireAccount, Checkout.RecurringPayment.NoPaymentMethod, Checkout.RecurringPayment.PaymentMethodNotSupported, Checkout.RecurringPayment.NothingToPay.

Breaking changes

  • IPaymentService has a new member SupportRecurringPayment(string). This only affects custom implementations of the service, not payment plugins.
  • New constructor parameters: ShoppingCartWarningsValidator (IGroupService), GetPaymentMethodHandler, PlaceOrderCommandHandler, CheckoutController and ShoppingCartController (IRecurringPaymentService). This only affects code that subclasses or constructs them by hand.
  • Behaviour: a recurring product can no longer be bought with a method that charges once, and guests can no longer buy one.

IPaymentProvider is not broken: the new members have defaults.

Testing

  1. Admin → Catalog → Products: edit a product, tick Is recurring, cycle length 1, period Months, total cycles 0. Save.
  2. As a guest, add it to the cart. The cart shows "Log in or register to buy a product billed in cycles…", and Checkout opens the login page. Adding it to a guest's wishlist shows no such warning.
  3. Log in as a registered customer, with the same product in the cart. The warning is gone. Go to checkout. At the payment step no method is listed, and the page shows "None of the available payment methods can charge in cycles…" (no shipped provider supports recurring payments yet).
  4. Give the recurring product a 100% discount (or pay it fully with loyalty points). The confirm step shows "An order billed in cycles must have something to pay" and offers no Confirm button.
  5. Remove the recurring product and add a standard one. Every active payment method is offered again, and an order can be placed. In the database, the order has RecurringCycleNumber = 0 and the RecurringPayment collection is empty.
  6. Optional, with a test provider that returns SupportRecurringPayment() => true: place an order for the recurring product. RecurringPayment holds one Pending document with InitialOrderId = the order id, TotalCycles = 0 and CyclesPaid = 0. The order has RecurringCycleNumber = 1.
  7. Upgrade an existing 2.5 database: the unique InitialOrderId index exists on RecurringPayment, and the four resources are present.

Automated: dotnet build GrandNode.slnx (0 errors); Grand.Business.Checkout.Tests 972/972, Grand.Web.Tests 624/624, Grand.Modules.Tests 420/420.

Copilot AI balanced review requested due to automatic review settings November 20, 2026 08:13

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.

…recurring payment write from leading to a second order

- RecurringPaymentRuleProvider blocks a recurring order with nothing to pay or with a payment method that cannot
  charge in cycles, at the payment step, the confirm step and order placement alike
- the recurring payment is written after the cart is cleared
- a guest with a recurring product is sent to log in from the cart and the checkout
- IRecurringPaymentService.HasRecurringProducts is the one recurring-cart check
- the recurring message is no longer replaced by the approval one; no account warning on a wishlist
- unique InitialOrderId index; CyclesPaid counts cycles the provider reported, the first one included
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