Repository navigation
Conversation
Shoppers can enter a coupon code on the cart. A coupon takes a percentage or a fixed amount off the item subtotal, or removes the flat shipping, with an optional minimum subtotal, UTC start and end dates and a use limit. One coupon per cart. - Coupon rules are core's validateCoupon/resolveDiscount; coupons live in a new coupons collection keyed by the upper-cased code. - Uses are the paid orders that carry the code (new couponCode index), counted when needed, so the webhook makes no extra calls and a fully refunded order gives its use back. - New routes cart/coupon and cart/coupon/remove. The cart view gains discountTotal and coupon. - Checkout re-reads the coupon in a request of its own (kept on the cart like the products), drops it with COUPON_INVALID if it was turned off, expired or used up, and charges the discount through a single-use Stripe coupon so the hosted total matches the order. Every request stays within 8 bridge calls. - Orders record couponCode and discountTotal; the order page and CSV export show them. New Block Kit Coupons admin page. - Storefront kit: applyCoupon/removeCoupon, and a coupon field and discount line in Cart.astro (copied into the starter). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014cPGCx1ERBtVzqTiRTtsJw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds coupon codes to DashCommerce Lite, the sandboxed plugin in the EmDash registry. This is the first item on the plan to bring Lite closer to core's feature set.
What shoppers and merchants get
Shoppers enter a code on the cart. A coupon can take:
Optional rules: a minimum subtotal, start and end dates (UTC days) and a use limit. One coupon per cart; a new code replaces the old one. Codes are not case sensitive.
Merchants get a new Block Kit Coupons page: list, create, edit, turn off and delete. The page shows the use count of a coupon that has a limit. The order page and the CSV export show the coupon code and discount.
How it works
Couponand callsvalidateCouponandresolveDiscount. These are added toshared.ts, so both plugins apply the same rules.couponCodeindex) with payment statuspaidorpartially-refunded.countcall, only when the coupon has a limit.CHECKOUT_CONTINUE.COUPON_INVALIDwith the updated cart.CART_CHANGED.createOneTimeCoupon:amount_off= cart discount,duration=once). It's created with an idempotency key derived from the checkout attempt, so a double submit reuses it. The hosted page charges exactly the order total, so the webhook's amount check is unchanged. A free-shipping coupon needs no Stripe coupon.applyCouponandremoveCoupon. The cart view gainsdiscountTotalandcoupon.Cart.astrogets a coupon field and a discount line (coupons={false}hides the field). The starter's copies are updated withkit:sync.Sandbox limits
cart/couponuses at most 5 calls,cart/coupon/remove3, and every Coupons admin interaction stays within 8 (all asserted in tests).backend.jsgrows from 60.6 KB to 73.5 KB (cap 128 KB per file;bun run sizeworking budget 96 KB). Total 82.4 KB, 26.5 KB gzipped.couponsstorage collection, two order indexes and the Coupons admin page.emdash-plugin validatepasses.Testing
test/unit/coupons.test.ts, 20 tests:CART_CHANGEDcountwith aninfilter on the new indexes.bun run typecheck,bun run build,bun run test: Lite 164 pass, core 243 pass, 0 fail.validate,bundle+size,test:sandbox(7/7).bun install --frozen-lockfileand Biome format/lint on the changed files.Cart.astro(the starter's Astro check passes), and no live Stripe test-mode checkout.Release
Lite is private on npm and released to the registry by hand (
PUBLISHING.md), so the Lite version isn't bumped; the changelog entry is under Unreleased. A patch changeset is included for@dashcommerce/starter, whose sandboxed cart component changed.Generated by Claude Code