Swell · Arazzo Workflow

Swell Storefront Validate and Apply Coupon

Version 1.0.0

Validate a coupon code, then apply it to the session cart only when it is valid.

1 workflow 1 source API 1 provider
View Spec View on GitHub CommerceHeadless CommerceAPI-FirstB2CB2BSubscriptionsMarketplacesWholesaleStorefrontCheckoutPaymentsCartsOrdersCatalogInternationalizationArazzoWorkflows

Provider

swell-io

Workflows

storefront-validate-and-apply-coupon
Validate a coupon code, then apply it to the cart when valid.
Gets coupon validity by code; on a valid coupon it applies the code to the session cart, otherwise it ends.
2 steps inputs: code, publicKey outputs: couponCode, discountTotal
1
validateCouponStep
frontendGetCoupon
Validate the coupon code before applying it.
2
applyCouponStep
frontendApplyCoupon
Apply the validated coupon code to the current session cart.

Source API Descriptions

Arazzo Workflow Specification

swell-io-storefront-apply-coupon-workflow.yml Raw ↑
arazzo: 1.0.1
info:
  title: Swell Storefront Validate and Apply Coupon
  summary: Validate a coupon code, then apply it to the session cart only when it is valid.
  description: >-
    A branching storefront discount flow. The workflow validates a coupon code,
    branches on the validation result, applies the coupon to the current cart
    when it is valid, and ends without acting when it is not. Each step spells
    out its request inline, including the public-key authorization, so the flow
    can be read and executed without opening the underlying OpenAPI description.
  version: 1.0.0
sourceDescriptions:
- name: swellFrontendApi
  url: ../openapi/swell-frontend-api-openapi.yml
  type: openapi
workflows:
- workflowId: storefront-validate-and-apply-coupon
  summary: Validate a coupon code, then apply it to the cart when valid.
  description: >-
    Gets coupon validity by code; on a valid coupon it applies the code to the
    session cart, otherwise it ends.
  inputs:
    type: object
    required:
    - publicKey
    - code
    properties:
      publicKey:
        type: string
        description: Public storefront key, prefixed with pk_.
      code:
        type: string
        description: The coupon code to validate and apply.
  steps:
  - stepId: validateCouponStep
    description: Validate the coupon code before applying it.
    operationId: frontendGetCoupon
    parameters:
    - name: code
      in: path
      value: $inputs.code
    - name: Authorization
      in: header
      value: $inputs.publicKey
    successCriteria:
    - condition: $statusCode == 200
    outputs:
      couponId: $response.body#/id
    onSuccess:
    - name: couponValid
      type: goto
      stepId: applyCouponStep
      criteria:
      - condition: $statusCode == 200
    onFailure:
    - name: couponInvalid
      type: end
      criteria:
      - condition: $statusCode == 404
  - stepId: applyCouponStep
    description: Apply the validated coupon code to the current session cart.
    operationId: frontendApplyCoupon
    parameters:
    - name: Authorization
      in: header
      value: $inputs.publicKey
    requestBody:
      contentType: application/json
      payload:
        code: $inputs.code
    successCriteria:
    - condition: $statusCode == 200
    outputs:
      couponCode: $response.body#/coupon_code
      discountTotal: $response.body#/discount_total
      grandTotal: $response.body#/grand_total
  outputs:
    couponCode: $steps.applyCouponStep.outputs.couponCode
    discountTotal: $steps.applyCouponStep.outputs.discountTotal