Map the business behavior

List the rule’s inputs, eligibility, and intended result before choosing an API. A discount, delivery customization, and payment customization may use different supported operations. Store configuration should be explicit so a merchant can understand what changes a promotion.

Functions execute within Shopify’s infrastructure. That does not establish a universal zero-latency guarantee or validate a specific load-test result. Check supported capabilities, generated input/output types, and limits in the pinned Function API.

Keep the decision testable

An illustrative tier helper uses integer minor units and validates its inputs. Adapt currency precision to the actual currency rather than assuming every currency has two decimal places. The output below is a business decision only; a version-specific adapter must convert it into supported Function operations.

The example thresholds and percentages are invented test fixtures, not commercial pricing or a merchant’s approved promotion.

CONCEPT / RULES
  1. 01Eligible?
  2. 02Yes → select tier
  3. 03No → no discount
Example only: evaluate eligibility before selecting a configured tier or returning no discount.
JAVASCRIPT
export function chooseDiscount({eligible, subtotalMinor, tiers}) {
  if (!Number.isSafeInteger(subtotalMinor) || subtotalMinor < 0) {
    throw new TypeError("Invalid subtotal");
  }
  for (const tier of tiers) {
    if (!Number.isSafeInteger(tier.minimumMinor) || tier.minimumMinor < 0 ||
        !Number.isInteger(tier.percent) || tier.percent < 0 || tier.percent > 100) {
      throw new TypeError("Invalid tier");
    }
  }
  if (!eligible) return 0;
  const matching = [...tiers]
    .sort((a, b) => b.minimumMinor - a.minimumMinor)
    .find(tier => subtotalMinor >= tier.minimumMinor);
  return matching?.percent ?? 0;
}

Example decision logic. An API adapter and currency-aware money handling are separate concerns.

Validate the adapter and release

  1. Test eligible and ineligible customers, missing data, and an empty cart.
  2. Test the values just below, at, and above each threshold.
  3. Confirm discount stacking and the correct currency interpretation.
  4. Validate generated input/output types against the exact API version.
  5. Exercise the app configuration and Function in a development store before release. Preserve supported recovery options and monitor errors.

Sources & review

Removed unsupported execution-time and concurrency guarantees. The JavaScript example is a complete decision helper; it is not the generated Shopify Function adapter or an offer from Mifan Studio.

Content reviewed 2026-09-08. No production benchmark is claimed.