Developer Guides
  • Introduction
    • Welcome
  • Core
    • Overview
    • Frontend
      • Implementation & Testing
      • Using the API endpoints
      • Gift cards
        • Gift Card validation API (Optional)
      • Check stock
      • Sibling products
      • Rewards program
      • Customer signatures
      • Retail transactions
      • Shopify Local Pick-up
  • API
    • Overview
    • Quick Start
    • Accounts
    • Changelog
    • Reference
      • Customers
      • Inventory
      • Orders
      • Products
      • Rewards
      • Stores
      • Vouchers
      • Staff
Powered by GitBook
On this page
  • Endpoint
  • Adding Reward to Orders
  • Endpoints
  • UI example
  • Form validations
  • Recommended workflow
  • Adding a Gift Product to Orders

Was this helpful?

Export as PDF
  1. Core
  2. Frontend

Rewards program

DotApparel will expose an endpoint POST /api-rewardsAccount that accepts an email address and returns the details of the rewards account of the given customer.

The frontend will need to call the endpoint directly to get “rewards account” details.

If a customer does not have any rewards account in AP21, the endpoint is able to automatically create a new rewards account and proceed with the new account. (Please note that this option should be enabled in the app’s settings)

Endpoint

Request:

POST https://{shopDomain}/apps/dotapparel/api-rewardsAccount

{
  "email": "example@dotdev.com.au"
}

Response:

{
  available_rewards: "0",
  gifts: [
    {
      created_at: "2021-05-27",
      description: "Test March Gift",
      expires_at: "2023-03-06",
      gift_id: "21", // previously called "id"
      options: [
        {
          handle: "abc-123",
          shopify_id: 1234567890,
        },
      ],
    },
  ],
  join_date: "2019-03-06", 
  tier_description: "$300 - $699", 
  tier_locked_until_date: "2021-09-01",
  tier_join_date: "2021-05-27", 
  tier_name: "Tier 2", 
  next_tier_id: "4",
  next_tier_name: "Business Class",
  reward_account_id: "461116", 
  rewards: [
    {
      available: "25.00",
      id: "163421",
      created_at: "2018-08-22",
      description: "Example Reward",
      expires_at: "2023-03-06",
      redeemed: "0.00",
      total: "25.00",
    },
  ],
  spend_to_next_tier: "700.00",
}

Adding Reward to Orders

UI extension is available for this Reward Redemption process.

Endpoints

Get Reward Balance

Request:

POST https://{shopDomain}/app/dotapparel/api-rewardsBalance

{
    "email": "test@example.com"
}

Response:

{
    "data": {
        "available_rewards": "90", // Use this value as the available balance
        "join_date": "2021-05-03",
        "next_tier_name": "",
        "next_tier_id": "N/A",
        "tier_description": "Annual Spend $1800+",
        "tier_name": "Cashmere",
        "tier_join_date": "2023-06-05",
        "tier_locked_until_date": "2019-09-01",
        "rewards": [
            {
                "available": "0",
                "created_at": "2023-04-13T13:19:36",
                "description": "DotDev Rewards TEST",
                "expires_at": "2023-12-30",
                "id": "43923",
                "redeemed": "29",
                "pending_redemption": "21",
                "total": "50"
            },
            {
                "available": "40",
                "created_at": "2023-05-29T16:47:12",
                "description": "DotDev Rewards TEST3",
                "expires_at": "2023-12-30",
                "id": "43945",
                "redeemed": "10",
                "pending_redemption": "0",
                "total": "50"
            },
            {
                "available": "50",
                "created_at": "2023-05-29T17:12:23",
                "description": "DotDev Rewards TEST3",
                "expires_at": "2023-12-30",
                "id": "43946",
                "redeemed": "0",
                "pending_redemption": "0",
                "total": "50"
            }
        ],
        "reward_account_id": "22672"
    }
}

UI example

Guest checkout

Customer logged in (Hide the form if the available balance is 0)

Form validations

It is important to ensure that all necessary validations are performed before requesting the redeem reward endpoint. The following validations are crucial:

  • The "amount to redeem" must not exceed the available balance.

  • Once the cart has a "REWARD" discount applied to it, the available balance must be calculated on the front end. Please note that the "available_rewards" value won't be reflected in the "Get Rewards Balance" API until the order is created.

Recommended workflow

  • The front-end team is responsible for designing the redemption solutions and workflow on the website. This includes creating a user interface for customers to enter and apply their reward amount during the checkout process.

  • The frontend team should ensure that the Discount Application Title is set to "Reward Redemption" within the Shopify Scripts implementation. This title is crucial for correctly identifying and applying the reward amount as a discount when sending an order to AP21.

  1. Make an API call to the Get Reward Balance endpoint to retrieve the available balance (available_rewards) for the customer.

  2. When a customer wishes to use their rewards, you'll need to add a "reward_amount" to the cart to trigger the Shopify Scripts that handle the rewards redemption. Follow these steps:

    • When the customer enters an amount to redeem their reward, programmatically add the relevant line item properties to the cart item(s) using Shopify's cart API.

    • Include the necessary line item properties (i.e. _reward_amount) that will be used to trigger the Shopify Scripts. These properties will indicate that the loyalty reward has been redeemed and will initiate the discount calculation.

  3. To apply the reward amount as a discount, you need to implement a Shopify Script. This script will identify the loyalty reward amount that has been redeemed in the cart and transform the reward amount into a discount. Follow these steps:

    • Create a new Shopify Script or modify an existing one to handle the loyalty reward redemption.

    • In the script, identify the relevant info from the cart by checking the line item properties (i.e. _reward_amount)

    • Calculate and apply the discount equivalent to the reward amount.

    • Ensure that the "Discount Application Title" is set to "Reward Redemption" to correctly redeem the reward amount in Apparel21.

  4. Please note each order can only have one reward discount application.

Example discount_application of Reward Redemption in Shopify orders

discount_applications": [
    // normal discount application
    {
        "target_type": "line_item",
        "type": "script",
        "value": "65.98",
        "value_type": "fixed_amount",
        "allocation_method": "across",
        "target_selection": "explicit",
        "title": "30% Off",
        "description": "30% Off"
    },
    // Reward Redemption discount application
    {
        "target_type": "line_item",
        "type": "script",
        "value": "20.0",
        "value_type": "fixed_amount",
        "allocation_method": "across",
        "target_selection": "explicit",
        "title": "Reward Redemption", // Ensure that the correct title is used
        "description": "Reward Redemption" 
    }
],

Adding a Gift Product to Orders

  • To apply the reward amount as a discount, you need to implement a Shopify Script. This script will identify the Loyalty Reward product in the cart and transform the reward amount into a discount. Follow these steps:

    • Create a new Shopify Script or modify an existing one to handle the Loyalty Reward redemption.

    • In the script, identify the Loyalty Reward product in the cart by checking the line item properties.

    • Calculate and apply the discount equivalent to the reward amount.

    • Ensure that the "Discount Application Title" is set to "Reward Redemption" to correctly redeem the reward amount in Apparel21.

Similar to the "Rewards" redemption, DotApparel also provides the available gifts in the API response that a customer earned from a reward program.

The recommended workflow:

  1. Make an API call to the DotApparel API endpoint to retrieve the available gifts for the customer.

  2. When a customer wishes to redeem a gift, they need to add the corresponding gift product to their cart along with relevant line item properties. Follow these steps:

    • When the customer selects the option to redeem a gift, programmatically add the gift card product to their cart using Shopify's cart API.

    • Include the necessary line item properties (i.e. _gift_id) that will be used to identify the gift card and trigger the Shopify Scripts.

  3. To apply the discount to gift products, you need to implement a Shopify Script. This script will adjust the price of the gift product to zero and apply the necessary discount. Follow these steps:

    • Create a new Shopify Script or modify an existing one to handle the Gift Redemption.

    • In the script, identify the gift card product in the cart by checking the line item properties.

    • Set the price of the gift card product to zero.

    • Ensure that the "Discount Application Title" is set to "Gift Redemption" to correctly apply the discount.

  • The front-end team is responsible for designing and implementing the redemption solutions and workflow on the website. This includes creating a user-friendly interface that allows customers to easily select and apply their earned gifts during the checkout process.

  • It is important to ensure that the gift products are set to a price of zero in the order. The front-end team should ensure that the necessary adjustments are made to the price of the gift product when it is added to the customer's cart.

  • During the implementation of Shopify Scripts, the front-end team should ensure that

    • The Discount Application Title is set to "Gift Redemption."

    • The discount percentage should be set to 100%, and prevent any other discounts from applying to the gift items.

  • The Discount Application Title and percentage play a crucial role in correctly identifying and processing the gift redemption when sending the order to AP21.

Example payload of Gift Redemption discount and item in Shopify orders

{
// ...
    "discount_applications": [
        // Reward Redemption
        {
            "target_type": "line_item",
            "type": "script",
            "value": "40.0",
            "value_type": "fixed_amount",
            "allocation_method": "across",
            "target_selection": "explicit",
            "title": "Reward Redemption",
            "description": "Reward Redemption"
        },
        // Gift Redemption
        {
            "target_type": "line_item",
            "type": "script",
            "value": "29.95",
            "value_type": "fixed_amount",
            "allocation_method": "across",
            "target_selection": "explicit",
            "title": "Gift Redemption", // Ensure that the correct title is used
            "description": "Gift Redemption"
        }
    ]
    // ...
    "line_items": [
        // ...
        {},
        // gift product item
        {
            "id": 1234567890,
            "name": "T-Shirt Black",
            "properties": [
                {
                    "name": "_gift_id",
                    "value": "1234"
                }
            ],
            "price": "29.95",
            // total discount amount should match the "price"
            "total_discount_set": {
                "shop_money": {
                    "amount": "29.95",
                    "currency_code": "AUD"
                }
            },
            // ...
            // ...
            // a discount_application should appear which indicates this discount to the order.discount_allocations above
            "discount_allocations": [
                {
                    "amount": "29.95",
                    "amount_set": {
                        "shop_money": {
                            "amount": "29.95",
                            "currency_code": "AUD"
                        }
                    },
                    "discount_application_index": 1
                }
            ]
        }
    ]
}

PreviousSibling productsNextCustomer signatures

Last updated 1 year ago

Was this helpful?

Please contact support if you have the enabled.

new Shopify checkout custmosization