AladiaDocs

Checkout without signing in

Slices c and d of the academy website: Stripe session on the Standard seller without an account, browser token, buyer found or created by the webhook, one-time automatic sign-in, emails, seats, promo codes, instalments on the connected account, security.

Status: branch release/checkout-leads (06/10/2026). Owner spec of 06/10 (point 1, "Stripe connected" branch). Guide: Selling a course on your site. Prerequisite: Stripe Connect Standard (docs/STRIPE_CONNECT_STANDARD_PLAN.md, slice L3 direct charges). Paths are relative to backend/ and web-next/.

1. When

guestCheckoutAllowed (libs/common/src/common/leads/course-sales.rules.ts:151, only in Checkout mode: sales modes): checkout offer (verified connect and published price) and Standard account (direct charges), paid at once or in instalments (§7b). The public offer tells the site (guestCheckout); the course page (onBuy) sends guests to /checkout?courseId&cycleId without signing in. With a session, buying works as before (CheckoutView, saved cards); on a Standard seller signed-in instalments also use §7b.

The /checkout route now lives in the (course) group (app/(course)/checkout/page.tsx): with a session AppLayout + CheckoutView, without one GuestShell + GuestCheckoutView; proxy.ts lets it through without a session.

2. Flow

browser (academy site)            gateway                         payment                       Stripe (academy account)
(/checkout mount: Stripe preconnect + preloadStripe; price, course and session start TOGETHER)
GET  public/checkout-sessions/price ─► product price (+code), "checkout" fields
POST public/checkout-sessions {withAlternative} ─► course/edition lock ──► create-guest-checkout ──► 1 or 2 custom sessions IN PARALLEL
     ◄─ {sessionId, clientSecret, stripeAccountId, claimToken} ◄── guest_checkouts {claimHash}
                                     reserve-seat-count (course, ONE per pair)
"Instalments / Pay once" ──► no call: the other, already mounted checkout is shown
POST …/:id/details {name, email, fields} ──► fields validated ──► update-guest-checkout
checkout.updateEmail + confirm ─────────────────────────────────────────────────────────► payment (3DS)
                                  connect webhook checkout.session.completed (metadata.guest)
                                  prepareCompletedEvent: lookup → provision (account) → record-guest-buyer
                                  metadata.buyerId = profile ──► DirectChargeCompletion (transaction, receipt)
                                                                  course-purchased (enrollment) → markFulfilled
POST …/:id/status (every 1.5 s) ──► outcome pending|session|sign-in|expired|failed
POST …/:id/claim ──► atomic claimedAt ──► issue-session ──► Set-Cookie (__Host-accessToken)

2b. Speed and instant instalments / pay-once switch (08/10/2026)

Before: price → session → Stripe.js → Payment Element in a cascade; every "Instalments / Pay once" switch expired the session, opened a new one and remounted the Payment Element. Now:

  • Loading: app/(course)/checkout/page.tsx preconnects to js.stripe.com, api.stripe.com, m.stripe.network; GuestCheckoutView calls preloadStripe (components/billing/stripe-elements.ts) on mount and "Buy now" (BuyButton) on hover or touch; the course page prefetches /checkout for guests. Price, course and session start together.
  • Summary right away: todaySummary (lib/guest-checkout.ts) computes today's amount from the product (instalments: the edition fee, the same Price DirectCheckoutService.platformPriceIdOf sells; otherwise the full price; discount from priceDiscountData); once the session is ready Stripe's total replaces ours. Kit Skeleton as tall as the ready area (PaymentSkeleton, min-h-72).
  • Technical choice: two sessions in parallel, not a "deferred intent". With withAlternative: true GuestCheckoutService.create tries both modes (modesToOpen: requested first, unpayable one dropped) and opens the sessions with Promise.all, each with its own coupon. The second never blocks. Both guest_checkouts rows share claimHash and pairId (= first Stripe id) and store singlePayment. The browser keeps two CheckoutElementsProvider mounted (one Stripe instance per mode, fixed order), the hidden one invisible absolute + inert. A deferred intent would have moved all post-payment logic from checkout.session.completed to payment_intent.succeeded (transaction, receipt, instalment plan start, guest checkout per session, auto sign-in, dedup, conversions): too risky here.
  • Memo: GuestCheckoutMemo.alternative; paying with the alternative, payingWith makes it the main one. expire expires the whole pair; after payment the webhook closes the other (expireSiblings).
  • Server conversions: the visitor context (consent, cookies, event_id) is kept under both sessions (keepContextAs with both ids, ServerConversionsService.record): the webhook purchase finds it whichever is paid, with event_id = purchase.<paid session> like the browser.
  • Seat: one per pair. The guest checkout.session.expired frees it only if releasesSeat: no open or paid sibling, once per pair (atomic seatReleasedAt on the first).
  • Link: Link's "Save my information…" box inside the Payment Element is off (wallets.link = 'never'); card, Apple Pay and Google Pay stay. The green Express "Pay with Link" button stays (decision 08/10): set LINK_EXPRESS_BUTTON = false in lib/guest-checkout.ts to hide it.
  • Mandate text ("By providing your card information, you allow … to charge…"): written by Stripe when the session saves the card (setup_future_usage, instalments only), mandatory. The name is the academy's Stripe account statement descriptor / public business name (Stripe › Settings › Public details), cut to 22 characters (e.g. "ACCADEMIAL"); fixed in the academy's Stripe.

3. Browser token and automatic sign-in

libs/common/src/common/leads/guest-checkout.rules.ts: newClaimToken = gc_ + 32 random bytes (base64url); the database holds only the sha256 (claimHash), compared in constant time (claimTokenMatches). Without the right token every route answers 404, like a missing session.

claimOutcome: session only when the purchase is fulfilled, the profile is known, the account was born from this purchase (accountCreated), not used yet (claimedAt) and within 30 minutes of payment (paidAt); otherwise sign-in. GuestCheckoutService.claim (apps/payment/src/app/checkout-sessions/guest-checkout.service.ts:175) sets claimedAt with findOneAndUpdate({claimedAt: {$exists: false}}): two tabs at once → one session. The gateway (GuestCheckoutGatewayService.claim) asks auth.issue-session for the token (a new JWT, never an existing one) and SetCookieInterceptor sets __Host-accessToken on the calling host: on custom domains the call goes through /_api, so the cookie is first-party to the domain. web-next then sets the aladia-session flag.

Existing account: no session (the buyer hasn't proved ownership), "Sign in to start" page and an email with the course sign-in link.

Documented residual risk: whoever types someone else's email creates an account with that email (paying) and gets in once on that browser; the email owner receives the "set your password" email and takes the account over with the reset. Same behaviour as checkouts that create the account from the email (Kajabi, Thinkific).

4. Webhook and account creation (idempotency)

  • Stripe event deduplication stays provider_events (gateway, before routeEvent).
  • prepareCompletedEvent (apps/gateway/.../payment/guest-checkout/guest-checkout.service.ts:183), called by routeEvent before retrieveBuyer, under a Murlock per session: if guest_checkouts already has the profile it reuses it; otherwise AccountProvisioningService.provision (apps/gateway/.../authentication/account-provisioning.service.ts:48) → auth.provision-user (AuthService.provisionUser, apps/authentication/.../auth.service.ts:831: existing by email, or new verified and active without password, source: 'checkout'; an email race = first one wins) → profile/bucket/registration events with createUserProfile (if the profile is missing after a half-failed attempt it's created and the account counts as new) → record-guest-buyer (first time only: profileId: {$exists: false}). Then metadata.buyerId = profile and the event follows the usual direct-charge path.
  • DirectChargeCompletionService waits up to ~30 s for the new account's Aladia customer (created from the registration event) instead of failing.
  • After collection: markFulfilled (the state that unlocks the claim).
  • An error before reaching payment → the event is released and Stripe retries; retries find the recorded buyer.

AccountProvisioningService is the single point creating accounts outside sign-up: the workspace SSO (branch release/workspace-sso, createFederatedUser) should go through it when the branches meet; the workspace access mode (product only / mixed) will be checked in provision.

5. Emails

After provisioning the gateway stores the checkout fields on the person (workspace-fields.save-field-values, checkout placement) and queues checkout-sessions.guest-purchase-confirmed (GuestPurchaseConfirmedDto): notification (sendGuestPurchaseEmail, copy mail/layout/email-copy/guest-purchase.copy.ts, reply-to area account, academy theme) sends "You're enrolled in …" with Set your password (reset token, AccountProvisioningService.passwordToken, link <origin>/reset-password?token=…) for new accounts or Sign in and start (<origin>/login?redirect=/courses/:id) for existing ones. The origin is the buying site (GuestCheckoutGatewayService.buyingOrigin, apps/gateway/.../payment/guest-checkout/guest-checkout.service.ts:128): the trusted request host (MailTenantService.fromRequest: signed by the proxy on custom domains, Origin on <slug>.aladia.io) only when it belongs to the seller, otherwise FRONTEND_BASE_URL. The email goes through the MailSenderResolver (team/email-sender §7, notifications-mail.service.ts:402): forTenant({seller, site host}) for the sender (the academy Email domain when verified), the account area reply-to and theme; links built on the hub are moved to the academy base (rebase). Receipts are the usual ones (sendReceiptReadyEmail, already through the resolver); automatic sign-in sends no email.

SSO "Product only" mode

On an academy with SSO in Product only (branch release/workspace-sso) students exist only in the product: no account is born from a purchase. Choice: no guest checkout, buying happens after the product login.

  • the public offer says guestCheckout: false (leads.service.ts:120, WorkspaceSsoGatewayService.productOnly, workspace-sso-gateway.service.ts:803);
  • the course page sends visitors without a session to the product login with return_to on the purchase page (productLoginRedirect, app/(course)/courses/[courseId]/page.tsx:420); back with the SSO session they buy with the usual checkout;
  • /checkout without a session isn't public in that mode: the proxy sends it to the product login (proxy.ts:116);
  • gateway defence: sellableCourse calls assertAccountCreationAllowed (:812) and answers 403 sso_required (the same error as sign-up); the checkout page explains it. Information requests stay (they create no account). In Mixed and Aladia only guest checkout works as above.

Related fix: reset emails pointed to /password-recovery, which web-next doesn't have; proxy.ts now redirects it to /reset-password with the same query.

6. Seats, abandonment, errors, refunds

  • Seats: validateGuestPurchase (existing edition, not started, with seats) then courses.reserve-seat-count under a lock as the usual checkout (one per instalments/pay-once pair, §2b). Expiry (page left: POST …/expire; or Stripe's 30 minutes) → checkout.session.expired webhook guest branch: markExpired and courses.release-seat-count on behalf of the seller. Fix: UpdateSeatCountDto now frees the edition seat also for live courses paid at once (before only for instalment products).
  • Card declined: confirm error, the session stays open. 3-D Secure: redirect: 'if_required'; the token stays in sessionStorage (aladia-guest-checkout, 30 minutes, paying: true before confirm) and on return the page resumes waiting.
  • Refunds (refund.created with event.account): direct charges have no transfers to stop, so NO_TRANSFERS_FOR_REFUND isn't thrown anymore; access isn't removed automatically (as for every purchase today).

7. Promo codes and instalments

One source of truth: Aladia coupons and codes (CouponsService.getCheckoutCoupon, the course coupon on the academy account with SellerCouponsService.couponFor, §7e), not Stripe's allow_promotion_codes: the same codes work for signed-in buyers, purchase links and guests, and limits (expiry, used up, course) are Aladia's. The page tries a code with GET public/checkout-sessions/price?promoCode (product with priceDiscountData, 30 tries per 10 min per IP) and reopens the session pair with the code (the old one expires). Amounts show right away from the product (todaySummary, §2b); the Stripe session total replaces them once ready.

7b. Instalments on the connected account (slice d, Stripe Connect L4)

Same plan as instalments on the platform, but everything lives on the academy's Stripe account: Aladia takes no fee and moves no money.

Choice and summary (web-next): paymentChoice and planOf (lib/guest-checkout.ts:71, :80) decide whether the course is in instalments, whether the buyer can choose (allowSinglePayment) and which useSinglePayment to send. PlanChoices (components/checkout/guest-checkout-view.tsx:457, reusing PlanChoice from the purchase dialog) switches mode instantly by showing the other, already open session (§2b; the memo is per code). Totals shows today's amount (the initial fee, from the product, then from Stripe) and, below, what Stripe doesn't show: the following instalments with dates and amounts from the product plan of the chosen edition, discount included. ?useSinglePayment=true from the purchase dialog preselects "Pay once".

Session (DirectCheckoutService, apps/payment/src/app/checkout-sessions/direct-checkout.service.ts:214 paysInInstallments): in instalments the line item is the edition's initial fee (subscriptionInfo[cycleId].fee, read from Stripe), payment_intent_data.setup_future_usage: 'off_session' (:139, :206) saves the card on the account customer (no payment_method_save choice). Guests: customer created by customer_creation: 'always' from the checkout email. Invitation plans with custom instalments stay on the platform (409).

Plan start (checkout.session.completed with event.account): DirectChargeCompletionService (apps/payment/src/app/webhooks/direct-charge-completion.service.ts:202) records the initial fee as for a single purchase, then DirectInstallmentsService.startPlan (apps/payment/src/app/webhooks/direct-installments.service.ts:113): card as default payment method of the account customer, course Product in the academy catalog (SellerCatalogService.productOf, §7e: the same as checkout, no duplicates), schedule with directPlanPhases (libs/common/src/common/payments/direct-installments.rules.ts:59: trial to the first instalment, N instalments, own last phase, price_data with amounts read from the platform Prices, the course coupon on the account (SellerCouponsService.couponFor, duration forever, §7e) on all phases but the last), subscription metadata (courseId, productId, transactionId, coupon) and local subscriptions document with stripeAccountId and applicationFeeRate: 0. course-purchased carries the subscription (enrollment as for platform instalments). For guests the account is created first (§4), so the plan is on the right buyer.

Instalments (invoice.payment_succeeded / invoice.payment_failed with event.account, stripe-webhooks.service.ts:305, :349): invoicePaid (:180) skips the zero trial invoice, creates the transaction (coupon resolved as instalment or plain coupon) or marks the earlier failed one paid, sets access authorized, emits course-subscription-reactivated if it was suspended and course-installment-paid. invoiceFailed (:208) creates the failed transaction once per invoice and suspends access once (course-subscription-suspended). invoice.created is skipped for direct instalments (no Aladia fee items, :324). customer.subscription.deleted updates the local subscription as today. Cancelling (SubscriptionsService.cancel, cancelCustomerSubscriptions) goes to the seller account (SubscriptionsService.accountOf, apps/payment/src/app/subscriptions/subscriptions.service.ts:88).

Limits: a failed instalment can't be retried from Aladia's payments page yet (retryPayment works on platform invoices): Stripe retries it (the academy's Smart Retries) or the buyer pays from Stripe's invoice email; changing the card for instalments is the same. Disconnecting a Standard account with active direct instalments isn't blocked yet. Instalment transactions older than the invoice refresh window are refreshed on the platform account (refreshInvoices), like L3 direct receipts: to be fixed together.

Migration: scripts/migrations/2026-10-direct-installments.js (PHASE=plan|apply: unique index on seller_products, subscriptions.stripeAccountId). Stripe: the Connect endpoint must also send invoice.payment_succeeded, invoice.payment_failed, invoice.created and customer.subscription.deleted.

7c. Wallets (Express Checkout) and payment methods

Express Checkout (GuestPaymentPanel, components/checkout/guest-checkout-view.tsx, one per mounted session): ExpressCheckoutElement of the custom checkout above the card (Apple Pay, Google Pay, Link, shown only where available; "or pay by card" divider only when some wallet is there). onConfirm goes through the same pay as the card: name and email from the form or, if empty, from the wallet (billingDetails), checkout fields validated, details + updateEmail, then confirm({ expressCheckoutConfirmEvent }); invalid data → paymentFailed (nothing charged). The custom checkout's Express element has no onClick, so fields can't be checked before the sheet opens.

Domains (payment_method_domains on the connected account; without them wallets don't show for direct charges): PaymentDomainsService (apps/payment/src/app/connect-accounts/payment-domains.service.ts:36, :44) registers each host once (StripeService.registerPaymentMethodDomain, apps/payment/src/app/stripe/stripe.service.ts:1159: reuses and re-enables an existing one) and remembers it in connect_accounts.paymentMethodDomains. Only public https hosts (paymentDomainOf, libs/common/src/common/payments/payment-domains.rules.ts:11). Two paths, never blocking:

  • hook: WorkspaceOriginsNotifier (apps/profile/src/app/organization-branding/workspace-origins.notifier.ts:44) sends connect-accounts.ensure-payment-domains when the workspace gets <slug>.aladia.io and when the custom domain becomes active (same moment as the bucket CORS); no-op without a Standard account;
  • at checkout (backfill): guest session → buying site origin (guest-checkout.service.ts:140); signed-in direct session → FRONTEND_BASE_URL host (checkout-sessions.service.ts:213). Accounts connected after the domain was activated, and every existing domain, get registered on the first checkout, before the Element mounts.

Apple Pay on a domain also needs Stripe's domain association file: web-next doesn't serve /.well-known/apple-developer-merchantid-domain-association today: if registration answers apple_pay.status: inactive, it must be added (to check on the first live domain; Google Pay and Link don't need it).

Payment methods: chosen by the academy in its Stripe (Settings › Payment methods); the Integrations › Stripe page has a "Payment methods" section (app/(app)/settings/integrations/stripe/page.tsx:300) suggesting SEPA, Klarna, PayPal with "Manage on Stripe". The session uses Stripe's dynamic payment methods (no payment_method_types): Stripe filters what fits (e.g. no Klarna with setup_future_usage). Not done yet: Customer Portal, Klarna-specific flows.

7d. Instalment preview from Stripe

Branch release/installments-preview. The instalment summary shows amounts computed by Stripe, so discounts, rounding and (later) taxes match what will be charged. Before, they came from the product plan (InstallmentsCalculationService at publication), which with a code can differ by a few cents: fixed-amount discounts are split across instalments by the instalment coupon, percentage ones are rounded by Stripe on every invoice.

  • GET public/checkout-sessions/installments-preview?courseId&cycleId&promoCode (gateway, same per-IP limit as codes) → checkout-sessions.preview-installments → InstallmentsPreviewService.preview (apps/payment/src/app/checkout-sessions/installments-preview.service.ts).
  • Standard seller: the same phases as DirectInstallmentsService (directPlanPhases, account Product, course coupon on the account, SellerCouponsService.couponFor) and two invoices.createPreview on the account (Stripe-Account): a regular instalment (with the discount) and, if any, the last one (without). No charge, no subscription. Dates are the plan's (Stripe charges at each phase boundary).
  • Fallback: Stripe error or non-Standard seller → the product plan (source: 'plan'). The answer also carries plan and differences (cents) and the log notes when Stripe differs. 5-minute cache per product, edition and code.
  • web-next: laterRows (lib/guest-checkout.ts) uses Stripe's amounts when the preview has the same instalments as the plan, otherwise the plan; the struck-through price stays the product's. Today's amount is still read from the Stripe session.
  • Test-mode check: CHECKOUT_INSTALLMENTS_COURSE=<id> [CHECKOUT_PROMO=<code>] node web-next/e2e/help/flows/run.mjs leads/installments-preview --shots (compares Stripe and plan, attaches the differences, checks the summary shows Stripe's amounts). Unit tests: tests/unit/installments-preview.spec.ts.

7e. Course catalog on the academy Stripe account

Update 20/10/2026: no more course or event Products, Prices or coupons on the platform. The Aladia product (products) only carries amounts in cents and the instalment plan (ProductsService.createCourseProduct / createEventProduct, no Stripe call; stripeProductId, stripePriceId and the plan stripePriceIds only remain on older documents, as history). The catalog creates the Prices from the product amounts (catalogPricesOf: role, amount, currency, interval; checkoutPriceOf for checkout) and recognises them by those four fields, older seller_products documents included (platformPriceId kept as history, skippedPriceIds removed). Aladia coupons (coupons, promo_codes) are only documents keyed cpn_<id> / promo_<id> in stripeId (the metadata.coupon key); SellerCouponsService creates them on the academy account and coupons without a course link are copied from the document. Selling needs a Standard account: without one, publishing still creates the Aladia product (catalog on connect), checkout answers 404 connect-not-found, an older Custom account 409 direct-charge-not-available (no platform checkout, no invitation instalment plans). On connect the recovery also rebuilds catalog and coupons of published paid events (event-publications.list-published-paid-events, events in the outcome); reconnecting the same account creates no duplicates, a new account gets the catalog rebuilt there. Direct receipt: the coupon is the one the session applied (session.discounts). Sandbox test: scripts/billing/connect-standard-e2e.ts CATALOG; Products left on the platform: scripts/billing/legacy-platform-products.js (plan; archiving only after approval). The rest of this section describes the 07/10 model: where it mentions platform Prices, the above applies.

Decision of 07/10/2026 (Accademia Leonardo case: 4 courses with a productId, empty Stripe Product catalogue). For Standard sellers every paid course has a Product on the academy account (Stripe-Account header) with Prices copied from the platform ones; checkout and instalments use them, so sales show up per product on Stripe. Platform Products/Prices stay as they were (source of the amounts, Custom sellers, invitation instalment plans). Custom sellers: no change.

Service: SellerCatalogService (apps/payment/src/app/products/service/seller-catalog.service.ts), pure rules in libs/common/src/common/payments/seller-catalog.rules.ts.

  • ensure(product, account, { details?, refresh? }): when the product document already covers every platform Price it makes no Stripe call (unless refresh, used on publication). Otherwise: Product created or updated (name = title, description = course description as plain text ≤ 500 chars, images = cover only if its public URL answers a HEAD, metadata aladia_course_id, aladia_product_id, aladia_workspace_id, active: true); a Product deleted by hand (404) is created again. Prices: one per platform Price with amount > 0 (full = stripePriceId, fee, recurring installment and last with intervalOf(frequency) and interval_count: 1, like the direct plan phases), nickname and aladia_price_id metadata. A Price with the same role, amount, currency and interval is reused; the others of the previous catalog are archived after moving default_price (full price, else down payment).
  • priceFor(product, wanted, account) (checkout, wanted = checkoutPriceOf): starts from the stored product (not the coupon-applied one); an amount outside the catalog is added without touching the others. Zero or missing amount → PRODUCT_MISSING_FIELDS, as before.
  • archiveCourse(courseId, account?): Product active: false (never deleted) and archivedAt on the documents; republishing makes it active again.

Data model (seller_products, libs/common/src/common/models/microservices/payment/seller-product.model.ts): one document per Aladia product-account pair (unique index productId + stripeAccountId, as before) with stripeProductId, courseId, prices[] (role, platformPriceId, stripePriceId, unitAmount, currency, interval), skippedPriceIds (zero Prices), archivedAt. Every republication creates a new Aladia product: the catalog looks up the latest document of the course on the account (courseId, or the course productIds for direct-instalment documents created earlier) and reuses its Product. Index courseId + stripeAccountId: scripts/migrations/2026-10-seller-catalog.js (PHASE=plan|apply).

Where it is used:

  • publication (ConnectAccountsService.publishCourse): after the Aladia product, ensure(..., { refresh: true }) (no catalog without a Standard account); course no longer paid → archiveCourse. A catalog error is logged and does not block publication;
  • courses.course-deleted (now also in the payment service) → archiveCourse;
  • checkout with an account and without login (DirectCheckoutService): line_items: [{ price: <catalog Price>, quantity }] instead of price_data + product_data. the discount is in the session discounts with the course coupon on the account (see Coupons below);
  • direct instalments and the instalment preview: phases stay price_data (amounts and frequency of the usual plan) but with the catalog Product (productOf), which replaces sellerProductOf.

Recovery (ConnectAccountsService.syncCourseProducts, on connection and from POST /v2/payment/connect-accounts/course-products/sync): the course service now lists all published paid courses (courses.list-published-paid-courses, with productId when present). Without a product: as on publication; with a product: ensure without refresh (creates only what is missing). The result has catalog (courses whose catalog was created or updated) and coupons (courses whose coupons or promo codes were created, updated or retired; with --plan the ones still to do) besides created, reused, failed. Without credentials, from the VPS:

docker cp backend/scripts/billing/sync-seller-catalog.js aladia-monolith-1:/tmp/
docker exec aladia-monolith-1 node /tmp/sync-seller-catalog.js <workspaceId>

The script talks to the payment service over the internal TCP transport (TCP_HOST/TCP_PORT, default 127.0.0.1:4000) and prints the result. Idempotent.

Limits: two simultaneous triggers on the first catalog of a course (publication and checkout at the same instant) can create two Products on Stripe; the document keeps one, the other stays orphaned with no sales. An open checkout session (30 minutes) with a Price just archived by a republication may fail on confirmation: it is reopened. Tests: tests/unit/seller-catalog.spec.ts, course-products-on-connect.spec.ts, stripe-direct-charges.spec.ts.

Coupons (decision of 07/10/2026; SellerCouponsService, apps/payment/src/app/coupons/seller-coupons.service.ts, pure rules in libs/common/src/common/payments/seller-coupons.rules.ts). Before, course coupons lived only on the platform and were copied to the account on the first checkout (aladia_<platform coupon id>, name and value only, duration: 'once', no expiry, no product). Now, for Standard sellers, on publication (after the catalog) and on recovery every course coupon (builder › Price › Coupons, automatic in the marketplace or with promo codes) gets on the academy account:

  • a Coupon with stable id aladia_<course coupon id> (the billing.coupons id, the same across republications): name (≤ 40 chars), percent_off or amount_off + currency (product currency, §7f), redeem_by = coupon expiry (for instalment courses the course end date when later, like the platform coupon: the discount is applied again at the start of the instalment phase), applies_to.products = the course Product of the catalog, metadata aladia_coupon_id, aladia_course_id, aladia_product_id, aladia_role. No max_redemptions: Aladia coupons have no usage limit and an instalment purchase redeems the coupon more than once (one per phase). Instalment courses with a fixed-amount discount also get aladia_<id>_rate (per-instalment amount computed by Aladia, recurringCoupon);
  • duration: once for single-payment courses, forever for instalment courses;
  • Promotion Codes with the same code as in Aladia (not the platform <productId>-<code> one), expires_at = code expiry (never after redeem_by), active = coupon active in Aladia. A code Stripe refuses (characters, already active on another course of the same academy: active codes are unique per account) is logged and skipped.

Stripe doesn't allow changing value, currency, duration, redeem_by or applies_to: when one changes a new version is created (aladia_<id>_v2, _v3…; an id already taken on Stripe with other terms is skipped) and the previous one is retired: deleted for single-payment courses (deleting a Stripe coupon doesn't touch discounts already applied), kept with metadata.aladia_status = superseded for instalment courses (plans already sold re-apply the coupon at the start of the instalment phase; it expires by itself at redeem_by); its codes are deactivated and recreated on the new version. A name change only updates the name. Coupon deleted in Aladia (missing from the republished course), course deleted (courses.course-deleted) or back to free → same retirement and retiredAt on the document. Coupon edits on a published course go to the draft and become sellable at republication (platform coupons are recreated there), so the sync starts from publication.

Checkout: validation stays Aladia's (CouponsService, same expired / not available / invalid messages); SellerCouponsService.couponFor(platformCouponId, product, account) maps the chosen platform coupon to the current account version (full or rate), with no Stripe call when it is already there, recreating it when missing or outdated; coupons without a course link (invitations, unmatched old documents) are copied as before (aladia_<platform id>). Session discounts, preview and plan phases use it; metadata.coupon stays the platform id.

Per-mode coupons (decision of 08/10/2026; pure rule libs/common/src/common/payments/coupon-modes.rules.ts, twin web-next/lib/coupon-modes.ts, tests tests/unit/coupon-modes.spec.ts and lib/coupon-modes.test.mjs). The course coupon has an optional modes: appliesTo ('both' | 'single' | 'installments') and installments (type, amount, target 'both' | 'fee' | 'installments'). Missing = the usual behaviour (same value; with instalments the fixed amount split between initial fee and instalments, recurringCoupon). With installments the fixed amount is per payment, the main value applies only to paying once and "every instalment" includes the last one. On publish CouponsService.createCoupon creates the platform instalment coupon (recurringCoupon with type and target) and SellerCouponsService its aladia_<id>_rate (percentage or amount, rateType). getCheckoutCoupon picks the coupon of the mode (none if it doesn't apply to that mode) and, with no code nor couponId, applies the marketplace automatic coupon (the one the product already shows discounted). couponChargesOf: with instalments the per-mode coupon goes on the initial-fee session only if target covers it (couponFor(..., 'fee')) and on the phases only if it covers the instalments (couponFor(..., 'installments')); directPlanPhases({ perModeCoupon }) keeps the discount on every instalment phase, the last one included (older coupons don't, as before). On the platform account the same through metadata.coupon_charges. Product.fromModeCoupon discounts price, initial fee and instalment per mode (purchase dialog, checkout, instalment preview); CourseCouponRto (cards and public page) carries appliesTo and installments, the web derives the instalment line from them. Invitations keep the usual coupon.

Instalments, before/after: the docs (help/academy/sell-a-course) say the discount applies to the initial fee and the instalments, not to a last instalment with its own amount. The phases were already right (discount on trial and instalment phases, none on the last), but the account copy was once: Stripe discounted only the first invoice of the instalment phase while the preview (one-iteration phase) showed it on every instalment. Example: €1,200 course, €200 initial fee, 4 × €250, 10% coupon: initial fee €180 (checkout), preview 4 × €225; before, charged €225 then 3 × €250 (€930 instead of €900); now forever: 4 × €225, as in the preview. Preview amounts are unchanged.

Data model (seller_coupons, libs/common/src/common/models/microservices/payment/seller-coupon.model.ts): one document per course coupon-account pair (unique index courseCouponId + stripeAccountId, index courseId + stripeAccountId) with courseId, productId of the last sync, coupons[] (role, stripeCouponId, version, signature of the immutable fields, duration, name, retiredAt), promotionCodes[] (code, stripePromotionCodeId, stripeCouponId, expiresAt, active), retiredAt. coupons.courseCouponId (new) links platform coupons to the course coupon; documents created earlier are matched on recovery (same name, type, value, expiry, only when unique) and completed. Indexes: scripts/migrations/2026-10-seller-coupons.js (PHASE=plan|apply). Tests: tests/unit/seller-coupons.spec.ts.

7f. Course currency

Until 07/10/2026 StripeCreatePriceDto created every platform Price in hard-coded 'usd' (all 3464 production products), while the course page showed euros: direct and guest checkout charged the Price currency, i.e. dollars.

Rule (libs/common/src/common/payments/course-currency.rules.ts, courseCurrencyOf): a course currency is, in order,

  1. course.billing.currency, when it is a valid ISO code;
  2. the default_currency of the academy Stripe account (ConnectAccountsService.currencyOf, retrieveAccount);
  3. 'eur' (also when the account cannot be read). Never hard-coded 'usd' again.

The same currency goes into PriceDto → products.currency, the platform Prices (StripeCreatePriceDto.fromPriceDto(..., currency); invitation Prices use product.currency), coupons (product.currency, as before), the academy catalog Prices (they copy currency and amount from the platform Prices, §7e) and the course: payment-course-price-created carries currency and the course service writes it into billing.currency together with the productId. web-next shows billing.currency (course page, purchase-box, course-price.ts) and product.currency (purchase dialog, guest checkout): DEFAULT_CURRENCY = 'EUR' (lib/api/payments.ts) is only the fallback for a never-published course, equal to the backend default.

Aladia fee payout (StripeCreatePayoutDto.fromAvailableTransaction): in the currency of the balance transaction that became available, no longer 'usd' (on a euro balance the payout failed). The amount is still computed from the transaction: with charges in a currency other than the balance it needs review.

Recovery (syncCourseProducts, currencyFixOf): for a published course whose product currency differs from the rule,

  • no sales (sum of purchases over all course products = 0): regenerated like a republication (publishCourse): new product and Prices in the right currency, coupons recreated, previous product archived on Stripe, productId and billing.currency updated on the course, academy catalog with the new Price and the dollar one archived. Result currency;
  • with sales or subscriptions: no Price touched (running subscriptions stay in dollars); the course gets billing.currency = product currency, so the page shows what is really charged. Result currencyLocked: to be decided by hand (republishing with a euro price creates a new product for new purchases, existing subscriptions stay on the old one). Idempotent: a product already in the right currency is left alone.

Commands (after the release):

# count per workspace, read only
docker cp scripts/migrations/2026-10-product-currency.js aladia-mongo-1:/tmp/
docker exec aladia-mongo-1 mongosh "$URI" --quiet --file /tmp/2026-10-product-currency.js
# one workspace: plan, then apply
docker cp backend/scripts/billing/sync-seller-catalog.js aladia-monolith-1:/tmp/
docker exec aladia-monolith-1 node /tmp/sync-seller-catalog.js <workspaceId> --plan
docker exec aladia-monolith-1 node /tmp/sync-seller-catalog.js <workspaceId>

Tests: tests/unit/course-currency.spec.ts, course-products-on-connect.spec.ts (currency, regeneration, plan), seller-catalog.spec.ts (usd → eur in the catalog).

8. Security

  • Public routes with per-IP limits (FixedWindowLimiter: 20 sessions/hour, 30 code tries/10 min) and id and token formats checked before calling payment.
  • Course, price and seller are decided by the backend; the browser only says what it buys.
  • No buyer data in URLs; the token only in sessionStorage.
  • __Host- httpOnly session cookie, never readable by JavaScript; the claim answer also carries accessToken like the login (same contract).

9. Configuration

  1. Deploy backend; scripts/migrations/2026-10-guest-checkout.js (PHASE=plan|apply, guest_checkouts indexes).
  2. Deploy web-next.
  3. Stripe Connect webhook endpoint with checkout.session.completed and checkout.session.expired (already used by L3 direct charges).
  4. Check: node web-next/e2e/help/flows/run.mjs leads/guest-checkout --shots (pays with 4242 only when the session is cs_test_; CHECKOUT_INSTALLMENTS_COURSE=<id> for the instalments summary, CHECKOUT_PROMO=<code> for the recalculated plan).

10. Tests

tests/unit/direct-installments.spec.ts: plan phases (last phase, no discount on the last one, intervals), plan start on the account (default card, schedule, metadata, local subscription, product created once, missing plan), instalments paid/retried/failed/failed again (transactions, access, events, coupon). tests/unit/stripe-direct-charges.spec.ts: initial fee with setup_future_usage, single payment, invitation plans refused, plan started only in instalments. tests/unit/guest-checkout.spec.ts: token and hash, claim outcomes (new/existing/used/expired), names and origin, edition seat; payment service (Standard only, published price, code, details with the right token, buyer recorded once, claim once, window, expiry); gateway (provisioning from checkout details or Stripe, retry without new accounts, other events untouched, session only for session); provisioning (profile created, recovery after an error); AuthService.provisionUser (existing, new verified without password, race); email. web-next lib/guest-checkout.test.mjs.

On this page