Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.launchmystore.io/llms.txt

Use this file to discover all available pages before exploring further.

Functions

Functions allow your app to run custom business logic at key points in the commerce flow. Unlike extensions (which add UI), functions modify behavior.

Function Types

Shipping Rate

Add custom shipping options and rates

Payment Customization

Hide, rename, or reorder payment methods

Delivery Customization

Modify delivery option display

Cart Transform

Modify cart line items, merge/split products

Order Validation

Block orders that don’t meet criteria

Discount

Apply custom discount logic

How Functions Work

Functions are declarative JSON manifests that describe the logic to apply. The LaunchMyStore backend executes them at the appropriate time.

Function Manifest

Functions are defined in your app’s extension directory:
// app.json
{
  "handle": "my-shipping-app",
  "functions": {
    "shipping_rate": {
      "handle": "custom-shipping",
      "name": "Custom Shipping Rates",
      "config": {
        "freeShippingThreshold": 5000,
        "baseRate": 499,
        "expressRate": 1299
      }
    }
  }
}

Execution Points

Function TypeWhen It RunsWhat It Modifies
shipping_rateverifyCart()Adds shipping options
payment_customizationverifyCart()Payment method list
delivery_customizationverifyCart()Delivery option labels
cart_transformverifyCart()Cart line items
order_validationaddClientOrder()Blocks/allows order
discountverifyCart()Applies discounts

Input Data

Functions receive context about the current cart and checkout:
interface FunctionInput {
  cart: {
    items: CartItem[];
    total: number;
    subtotal: number;
    currency: string;
    discountCodes?: string[];
  };
  shippingAddress?: {
    country: string;
    province: string;
    city: string;
    zip: string;
  };
  customer?: {
    id: string;
    email: string;
    tags?: string[];
  };
  shop: {
    id: string;
    name: string;
    currency: string;
  };
}

Output Format

Each function type has a specific output format:

Shipping Rate Output

{
  "rates": [
    {
      "name": "Free Shipping",
      "price": 0,
      "description": "Free on orders over $50"
    },
    {
      "name": "Express",
      "price": 1299,
      "description": "2-3 business days"
    }
  ]
}

Payment Customization Output

{
  "operations": [
    { "hide": { "paymentMethodId": "cod" } },
    { "rename": { "paymentMethodId": "card", "name": "Secure Card Payment" } },
    { "reorder": { "paymentMethodId": "paypal", "position": 0 } }
  ]
}

Order Validation Output

{
  "valid": false,
  "errors": [
    {
      "code": "INVALID_QUANTITY",
      "message": "Maximum 5 items per order"
    }
  ]
}

Testing Functions

Use the Function Sandbox in the developer portal to test your functions before deployment:
  1. Go to Apps → Your App → Functions
  2. Select the function type
  3. Enter test input JSON
  4. Click Run Test
  5. View the output and execution time

Rate Limits

Functions must complete within:
  • Execution timeout: 2 seconds
  • Memory limit: 128 MB
Functions that exceed limits will fail and the default behavior will be used.

Best Practices

Functions run synchronously during checkout. Slow functions hurt conversion rates.
Always return valid output, even for unexpected input. Use sensible defaults.
Use the sandbox to test with various cart configurations before deploying.
Use app versioning to roll back if a function causes issues.