Skip to content

feat(core,starter): coupon box in the checkout order summary - #133

Open
moset15 wants to merge 1 commit into
emdashCommerce:mainfrom
FIKANOVA:feat/coupon-box-at-checkout
Open

moset15 wants to merge 1 commit into
emdashCommerce:mainfrom
FIKANOVA:feat/coupon-box-at-checkout

Conversation

@moset15

@moset15 moset15 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What and why

A coupon code can only be entered on /cart. The checkout order summary (CheckoutSidebarIsland) has no coupon box, so a shopper who goes from the cart drawer straight to checkout never sees one. A code applied on /cart does carry through.

Part of the roadmap in #108.

Behaviour

  • Before: no way to enter a code at checkout.
  • After: the checkout summary has a coupon box between the items and the totals. Applying or removing a code updates the summary at once.
  • /cart: looks and works the same. It now uses the same component; the markup and class names are unchanged.
  • Cart drawer: unchanged; it stays a quick view.
  • Stripe Elements: CheckoutSidebar takes a couponEntry prop (default true). The starter turns it off while its embedded Stripe Elements form is on the page, because that form creates the PaymentIntent at "Continue to payment": a code applied after that would show a discount that isn't charged. Shoppers there still enter codes on /cart.
  • Hosted and on-page checkouts through HostedCheckoutForm (Stripe Checkout, Paystack and other providers) price the cart when Pay is pressed, so they keep the box.

Changes

  • New astro/islands/CouponBox.tsx: the applied codes with a Remove button each, a code field and Apply. It calls the existing POST cart/coupon and DELETE cart/coupon/remove?code=, hands the recalculated cart back to its host, and sends a silent dashcommerce:cart-updated so other cart views refresh without opening the drawer.
  • CheckoutSidebarIsland.tsx: renders it, with the couponEntry prop; one CSS line for spacing.
  • CartPageIsland.tsx: the inline coupon block replaced by CouponBox.
  • CheckoutSidebar.astro: passes couponEntry through.
  • Starter checkout.astro: couponEntry={!useStripeElements}. Starter README: the /checkout row mentions the box.
  • Changeset: minor for core (new component and prop), patch for the starter.

No route changes.

Tests

packages/core/test/coupon-box.test.tsx, rendering with react-dom/server:

  • through the real cart/coupon route: save10 is applied to a cart, and the box rendered from the cart the route returns shows SAVE10, its discount and a labelled Remove button;
  • applied codes with their discount or "(free shipping)";
  • Apply disabled until a code is typed;
  • all controls locked while the host is busy;
  • the heading level it's given;
  • both islands render it; the summary can turn it off, and the starter does for Stripe Elements.

The tests fail without the change (with only the new component kept, the three wiring tests fail). Full suite: core 372 (364 before), paystack 105, lite 144, registry-setup 5, all passing. tsc --noEmit passes for core, astro check for the starter, Biome is clean on the new and changed lines; bun.lock is unchanged.

Review points

  • Why not on the drawer? The drawer is a quick view; checkout is where shoppers who skip /cart land.
  • Same gap for shipping with Elements: a shipping option changed in the summary after "Continue to payment" has the same problem today. Moving Elements to Stripe's deferred-intent flow (create the intent on Pay) would close both. Happy to send that separately if you want it.
  • No formatting churn: Biome reports some older lines in both islands as unformatted on main; they're left as they are.

Merge order with the shipping-options and tax rows PRs: all three edit CheckoutSidebarIsland.tsx on neighbouring lines. Each merges cleanly on its own; whichever goes in first, I'll rebase the others straight away.

@cavewebs

cavewebs commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for this. It now conflicts with main in CheckoutSidebarIsland.tsx after #132 landed, could you rebase onto main? I'll merge it once CI is green.

A code could only be entered on /cart, so a shopper who went from the
cart drawer straight to checkout never saw a coupon box. The cart page
and the checkout sidebar now share one CouponBox island that calls the
existing cart/coupon and cart/coupon/remove routes and refreshes the
totals. The drawer is unchanged.

CheckoutSidebar takes couponEntry (default true). The starter turns it
off while its embedded Stripe Elements form is on the page: that form
sets up the payment before Pay, so a code applied afterwards would show
a discount that isn't charged. Hosted and on-page checkouts fix the
amount on Pay and keep the box.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@moset15
moset15 force-pushed the feat/coupon-box-at-checkout branch from 16b595a to 88e28ba Compare December 5, 2026 22:53
@moset15

moset15 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main after #132; CheckoutSidebar now takes both shippingPicker and couponEntry. #133 and #134 change the same lines of the order summary, so whichever lands second I'll rebase straight away.

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