Stacking discounts

Apply many discounts and codes to the same order.

Voucherify lets you apply many discounts to the same order. It comes down to the following steps:

  1. Redeem the first discount by calling the redemption API and pass order details in the request body. In response, Voucherify returns a unique order id with an applied discount.
  2. To apply the second and further discounts, you need to redeem each discount using a separate API call with the same order id in the request body.

How does stacking work?

With a single redemption request, you can apply only one cart-level discount or coupon code. However, if you use the same order id in different API calls, all discounts valid for the given order will be applied. When calculating discounts and amounts during the redemption, the API takes into account all discounts applied to the order with the former requests.

Let's go through an exemplary workflow and apply two discounts (auto-applied discount and coupon code) to the same order.

Apply the first discount

To apply the first discount, call the Redeem Voucher or Redeem Promotion and pass the customer's order in the redemption body.

As an example, the first discount is a product-specific 10% off code. The discount is applied to prod_0925481da544a87095 and prod_09268420af901347bb only.

{
    "customer":{
       "source_id":"[email protected]"
    },
    "order":{
       "items":[
          {
             "quantity":1,
             "price":23000,
             "product_id":"prod_09268673c85013482b"
          },
          {
             "quantity":2,
             "price":5800,
             "product_id":"prod_09268420af901347bb"
          },
          {
             "quantity":1,
             "price":89000,
             "product_id":"prod_0925481da544a87095"
          }
       ]
     }
 }
{
    "id": "r_0P6AyPLjtrQ5lgKlhl6lq2zj",
    "object": "redemption",
    "date": "2021-06-16T12:52:51.204Z",
    "customer_id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
    "tracking_id": "track_cDpq7FSJqvM8C5gzPhLG2emmOzAjGrGLUCHYmRJAcuY=",
    "order": {
        "id": "ord_0dldgQpoCmO5h8J6nqEykhuy",// internal order id, copy the id and paste to redemption request to apply another discount 
        "source_id": "order54328",// external order id, copy the id and paste to redemption request to apply another discount 
        "created_at": "2021-06-16T12:52:51.152Z",
        "updated_at": null,
        "status": "PAID",
        "amount": 123600,// order amount before applying the discount
        "items_discount_amount": 10060,// the total discount amount applied to items
        "total_discount_amount": 10060,// sum of all discounts applied to order (total of order and product-specific discounts)
        "total_amount": 113540,// total order amount after applying all discounts
        "items_applied_discount_amount": 10060,// the total product-specific discount amount applied to items with this requests
        "total_applied_discount_amount": 10060,// the total discount amount applied to order with this request (sum of order and product-specific discounts)
        "items": [
            {
                "object": "order_item",
                "product_id": "prod_09268673c85013482b",
                "quantity": 1,
                "amount": 23000,
                "price": 23000,
                "product": {
                    "id": "prod_09268673c85013482b",
                    "source_id": "yearn3625",
                    "name": "Clock Yearn 345",
                    "price": 23000
                }
            },
            {
                "object": "order_item",
                "product_id": "prod_09268420af901347bb",
                "quantity": 2,
                "amount": 11600,
                "discount_amount": 1160,
                "applied_discount_amount": 1160,
                "price": 5800,
                "product": {
                    "id": "prod_09268420af901347bb",
                    "source_id": "clocks63527",
                    "name": "Kitchen Clock Spring edition 2021",
                    "price": 5800
                }
            },
            {
                "object": "order_item",
                "product_id": "prod_0925481da544a87095",
                "quantity": 1,
                "amount": 89000,
                "discount_amount": 8900,
                "applied_discount_amount": 8900,
                "price": 89000,
                "product": {
                    "id": "prod_0925481da544a87095",
                    "source_id": "goldenline21-74646",
                    "name": "Headphone Golden Line 2021",
                    "price": 89000
                }
            }
        ],
        "customer": {
            "id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
            "object": "customer"
        },
        "customer_id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
        "referrer_id": null,
        "object": "order",
        "redemptions": {
            "r_0P6AyPLjtrQ5lgKlhl6lq2zj": {
                "date": "2021-06-16T12:52:51.204Z",
                "related_object_type": "voucher",
                "related_object_id": "v_LZITOwdcJyztAYS2TFUK6b7RvN0rL8j2"
            }
        }
    },
    "metadata": null,
    "result": "SUCCESS",
    "customer": {
        "id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
        "name": null,
        "email": null,
        "source_id": "[email protected]",
        "object": "customer"
    },
    "related_object_type": "voucher",
    "voucher": {
        "id": "v_LZITOwdcJyztAYS2TFUK6b7RvN0rL8j2",
        "code": "Weekend10off",
        "campaign_id": null,
        "type": "DISCOUNT_VOUCHER",
        "discount": {
            "type": "PERCENT",
            "effect": "APPLY_TO_ITEMS",
            "percent_off": 10
        },
        "active": true,
        "metadata": {},
        "assets": {
            "qr": {
                "id": "U2FsdGVkX19FV9OgsE8m41mCSioqqKEvwd2guuFlooRynwgoSk9UtzJzfVd/GN1MMzpdvKEHKal/25Dcm3GbiTi9Vj2b6iWQzRdtPKg5oMfhH3EyU/lhsSq9b9OSxNsWnLs0Q4n46xvDTmxa2BMoQQ==",
                "url": "https://dev.dl.voucherify.io/api/v1/assets/qr/U2FsdGVkX19FV9OgsE8m41mCSioqqKEvwd2guuFlooRynwgoSk9UtzJzfVd%2FGN1MMzpdvKEHKal%2F25Dcm3GbiTi9Vj2b6iWQzRdtPKg5oMfhH3EyU%2FlhsSq9b9OSxNsWnLs0Q4n46xvDTmxa2BMoQQ%3D%3D"
            },
            "barcode": {
                "id": "U2FsdGVkX19GBs7Zr9aOwb3K+4s1YxIoLDhX4IgYD3vm7OM/BbxYD77C+wcunj/9bLcdglnZ0BlP1np7CcVsacUxLK6WrpEc3u/V9wrAq/RZvcG7uFp2hG7FzBK944Q/k1OOOuxVrRUDscAxVwjOkg==",
                "url": "https://dev.dl.voucherify.io/api/v1/assets/barcode/U2FsdGVkX19GBs7Zr9aOwb3K%2B4s1YxIoLDhX4IgYD3vm7OM%2FBbxYD77C%2Bwcunj%2F9bLcdglnZ0BlP1np7CcVsacUxLK6WrpEc3u%2FV9wrAq%2FRZvcG7uFp2hG7FzBK944Q%2Fk1OOOuxVrRUDscAxVwjOkg%3D%3D"
            }
        },
        "is_referral_code": false,
        "created_at": "2021-06-16T12:48:46.722Z",
        "updated_at": "2021-06-16T12:52:51.207Z",
        "validation_rules_assignments": {
            "object": "list",
            "data_ref": "data",
            "data": [
                {
                    "id": "asgm_siTVyR0psNBEc2LC",
                    "rule_id": "val_PH0UfgIZUQwg",
                    "related_object_id": "v_LZITOwdcJyztAYS2TFUK6b7RvN0rL8j2",
                    "related_object_type": "voucher",
                    "object": "validation_rules_assignment"
                }
            ],
            "total": 1
        },
        "redemption": {
            "quantity": null,
            "redeemed_quantity": 1,
            "object": "list",
            "url": "/v1/vouchers/Weekend10off/redemptions?page=1&limit=10"
        },
        "publish": {
            "object": "list",
            "count": 0,
            "url": "/v1/vouchers/Weekend10off/publications?page=1&limit=10"
        },
        "object": "voucher",
        "applicable_to": {
            "data": [
                {
                    "object": "product",
                    "id": "prod_09268420af901347bb",
                    "source_id": "clocks63527",
                    "strict": false
                },
                {
                    "object": "product",
                    "id": "prod_0925481da544a87095",
                    "source_id": "goldenline21-74646",
                    "strict": false
                }
            ],
            "total": 2,
            "data_ref": "data",
            "object": "list"
        },
        "inapplicable_to": {
            "data": [],
            "total": 0,
            "data_ref": "data",
            "object": "list"
        }
    }
}

Apply the second and subsequent discounts

To apply another discount to the same order, call Redeem Voucher or Redeem Promotion and pass related order id in the request body.

🚧

Order id

Note that you should pass only the order id in the request body. Passing order details is useful if you want to overwrite the order details saved under the given order id.

As an example, the second discount is $15 from an auto-applied promotion tier. The discount is applied to the whole cart.

{
    "customer":{
       "source_id":"[email protected]"
    },
    "order":{
       "id": "ord_0dldgQpoCmO5h8J6nqEykhuy"// id of the order to which the former discount was applied to
     }
 }
{
    "id": "r_5KmvfmSWCs9U246MCbpnuJPA",
    "object": "redemption",
    "date": "2021-06-17T08:13:00.736Z",
    "customer_id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
    "tracking_id": "track_cDpq7FSJqvM8C5gzPhLG2emmOzAjGrGLUCHYmRJAcuY=",
    "order": {
        "id": "ord_0dldgQpoCmO5h8J6nqEykhuy",
        "source_id": null,
        "created_at": "2021-06-16T12:52:51.152Z",
        "updated_at": "2021-06-17T08:13:00.673Z",
        "status": "PAID",
        "amount": 123600,
        "discount_amount": 1500, //sum of applied order-related discounts (excluding product-specific discounts)
        "items_discount_amount": 10060, //sum of all product-specific discounts applied to this order
        "total_discount_amount": 11560, // sum of order-level and product-specific discounts applied to this order
        "total_amount": 112040,
        "applied_discount_amount": 1500, //order-related discount applied in this request
        "total_applied_discount_amount": 1500, // sum of all discounts (applied to whole cart and to specific products) applied to the order in this request
        "items": [
            {
                "object": "order_item",
                "product_id": "prod_09268673c85013482b",
                "quantity": 1,
                "amount": 23000,
                "price": 23000,
                "product": {
                    "id": "prod_09268673c85013482b",
                    "source_id": "yearn3625",
                    "name": "Clock Yearn 345",
                    "price": 23000
                }
            },
            {
                "object": "order_item",
                "product_id": "prod_09268420af901347bb",
                "quantity": 2,
                "amount": 11600,
                "discount_amount": 1160,
                "price": 5800,
                "product": {
                    "id": "prod_09268420af901347bb",
                    "source_id": "clocks63527",
                    "name": "Kitchen Clock Spring edition 2021",
                    "price": 5800
                }
            },
            {
                "object": "order_item",
                "product_id": "prod_0925481da544a87095",
                "quantity": 1,
                "amount": 89000,
                "discount_amount": 8900,
                "price": 89000,
                "product": {
                    "id": "prod_0925481da544a87095",
                    "source_id": "goldenline21-74646",
                    "name": "Headphone Golden Line 2021",
                    "price": 89000
                }
            }
        ],
        "customer": {
            "id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
            "object": "customer"
        },
        "customer_id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
        "referrer_id": null,
        "object": "order",
        "redemptions": {
            "r_0P6AyPLjtrQ5lgKlhl6lq2zj": {
                "date": "2021-06-16T12:52:51.204Z",
                "related_object_type": "voucher",
                "related_object_id": "v_LZITOwdcJyztAYS2TFUK6b7RvN0rL8j2"
            },
            "r_5KmvfmSWCs9U246MCbpnuJPA": {
                "date": "2021-06-17T08:13:00.736Z",
                "related_object_type": "promotion_tier",
                "related_object_id": "promo_buwoK7NLltbo0gHbDA7ROErK",
                "related_object_parent_id": "camp_nPUCJzx1oXXCoNl0Wq4vt2g5"
            }
        }
    },
    "metadata": null,
    "result": "SUCCESS",
    "customer": {
        "id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
        "name": null,
        "email": null,
        "source_id": "[email protected]",
        "object": "customer"
    },
    "related_object_type": "promotion_tier",
    "voucher": null,
    "promotion_tier": {
        "id": "promo_buwoK7NLltbo0gHbDA7ROErK",
        "name": "$15 off",
        "banner": null,
        "action": {
            "discount": {
                "type": "AMOUNT",
                "effect": "APPLY_TO_ORDER",
                "amount_off": 1500
            }
        },
        "metadata": {},
        "hierarchy": 1,
        "campaign": {
            "id": "camp_nPUCJzx1oXXCoNl0Wq4vt2g5",
            "start_date": null,
            "expiration_date": null,
            "active": true,
            "object": "campaign"
        },
        "summary": {
            "redemptions": {
                "total_redeemed": 1
            },
            "orders": {
                "total_amount": 113540,
                "total_discount_amount": 1500
            }
        },
        "object": "promotion_tier",
        "validation_rule_assignments": {
            "object": "list",
            "data_ref": "data",
            "data": [],
            "total": 0
        }
    }
}

When applying former discounts, the logic is the same. You need to invoke redemption and provide the same order id in the redemption body. As a result, the API validates the given order and if all rules are met, the discount will be applied to the order (redemption succeeds).

Calculating discounts and order amounts

In the table below, you can see the logic the API follows to calculate discounts and amounts:

Field

Calculation

Description

amount

N/A

This field shows order amount before applying any discount

total_amount

total_amount = amount - total_discount_amount

This field shows order amount after applying all the discounts

discount_amount

discount_amount = previous_discount_amonut + applied_discount_amount

This field sums up all order-level discounts applied to a patricular order

items_discount_amount

sum(items, i => i.discount_amount)

This field sums up all product-specific discounts applied to this order id

total_discount_amount

total_discount_amount = discount_amount + items_discount_amount

This field sums up all order-level and all product-specific discounts applied to this order id

applied_discount_amount

N/A

This field shows order-level discount applied in a particular request

items_applied_discount_amount

sum(items, i => i.applied_discount_amount)

This field sums up all product-specific discounts applied in a particular request

total_applied_discount_amount

total_applied_discount_amount = applied_discount_amount + items_applied_discount_amount

This field sums up all order-level and all product-specific discounts applied in a particular request

List redemptions of stacked discounts

To get all redemptions applied to the order, use Get Order endpoint. "redemptions" object in response lists all redemptions made using the particular order id.

// https://dev.api.voucherify.io/v1/orders/ord_0dldgQpoCmO5h8J6nqEykhuy

{
    "id": "ord_0dldgQpoCmO5h8J6nqEykhuy",
    "source_id": null,
    "created_at": "2021-06-16T12:52:51.152Z",
    "updated_at": "2021-06-17T08:13:01.310Z",
    "status": "PAID",
    "amount": 123600,
    "discount_amount": 1500,
    "items_discount_amount": 10060,
    "total_discount_amount": 11560,
    "total_amount": 112040,
    "items": [
        {
            "object": "order_item",
            "product_id": "prod_09268673c85013482b",
            "quantity": 1,
            "amount": 23000,
            "price": 23000,
            "product": {
                "id": "prod_09268673c85013482b",
                "source_id": "yearn3625",
                "name": "Clock Yearn 345",
                "price": 23000
            }
        },
        {
            "object": "order_item",
            "product_id": "prod_09268420af901347bb",
            "quantity": 2,
            "amount": 11600,
            "discount_amount": 1160,
            "price": 5800,
            "product": {
                "id": "prod_09268420af901347bb",
                "source_id": "clocks63527",
                "name": "Kitchen Clock Spring edition 2021",
                "price": 5800
            }
        },
        {
            "object": "order_item",
            "product_id": "prod_0925481da544a87095",
            "quantity": 1,
            "amount": 89000,
            "discount_amount": 8900,
            "price": 89000,
            "product": {
                "id": "prod_0925481da544a87095",
                "source_id": "goldenline21-74646",
                "name": "Headphone Golden Line 2021",
                "price": 89000
            }
        }
    ],
    "customer": {
        "id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
        "object": "customer"
    },
    "customer_id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
    "referrer_id": null,
    "object": "order",
    "redemptions": {
        "r_0P6AyPLjtrQ5lgKlhl6lq2zj": {
            "date": "2021-06-16T12:52:51.204Z",
            "related_object_type": "voucher",
            "related_object_id": "v_LZITOwdcJyztAYS2TFUK6b7RvN0rL8j2"
        },
        "r_5KmvfmSWCs9U246MCbpnuJPA": {
            "date": "2021-06-17T08:13:00.736Z",
            "related_object_type": "promotion_tier",
            "related_object_id": "promo_buwoK7NLltbo0gHbDA7ROErK",
            "related_object_parent_id": "camp_nPUCJzx1oXXCoNl0Wq4vt2g5"
        }
    }
}
"r_0P6AyPLjtrQ5lgKlhl6lq2zj": { // the 1st redemption applied voucher code
    "date": "2021-06-16T12:52:51.204Z",
    "related_object_type": "voucher",
    "related_object_id": "v_LZITOwdcJyztAYS2TFUK6b7RvN0rL8j2"
},
"r_5KmvfmSWCs9U246MCbpnuJPA": { // the 2nd redemption applied discount from promotion tier
    "date": "2021-06-17T08:13:00.736Z",
    "related_object_type": "promotion_tier",
    "related_object_id": "promo_buwoK7NLltbo0gHbDA7ROErK",
    "related_object_parent_id": "camp_nPUCJzx1oXXCoNl0Wq4vt2g5"
}

Order session

Each time you use particular order in your requests, the API will automatically trigger a new session linked to the order id. The session is active during the request and ends asynchronously after the request is completed. The session mechanism ensures that the particular order id can be used in one API request at once.

Rollbacks of stacked discounts

When it comes to stacked discounts, you can only roll back the last discount applied to the order. To roll back the earlier discount, firstly roll back all the discounts applied after the discount you want to revert.

{
    "id": "rr_plthzMHqkiXRo5AjZiA52y51",
    "object": "redemption_rollback",
    "date": "2021-06-17T10:13:46.713Z",
    "customer_id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
    "tracking_id": "track_cDpq7FSJqvM8C5gzPhLG2emmOzAjGrGLUCHYmRJAcuY=",
    "order": {
        "id": "ord_0dldgQpoCmO5h8J6nqEykhuy",
        "source_id": null,
        "created_at": "2021-06-16T12:52:51.152Z",
        "updated_at": "2021-06-17T10:13:47.049Z",
        "status": "CANCELED",
        "amount": 123600,
        "items_discount_amount": 10060,
        "total_discount_amount": 10060,
        "total_amount": 113540,
        "items": [
            {
                "object": "order_item",
                "product_id": "prod_09268673c85013482b",
                "quantity": 1,
                "amount": 23000,
                "price": 23000,
                "product": {
                    "name": "Clock Yearn 345",
                    "price": 23000
                }
            },
            {
                "object": "order_item",
                "product_id": "prod_09268420af901347bb",
                "quantity": 2,
                "amount": 11600,
                "discount_amount": 1160,
                "price": 5800,
                "product": {
                    "name": "Kitchen Clock Spring edition 2021",
                    "price": 5800
                }
            },
            {
                "object": "order_item",
                "product_id": "prod_0925481da544a87095",
                "quantity": 1,
                "amount": 89000,
                "discount_amount": 8900,
                "price": 89000,
                "product": {
                    "name": "Headphone Golden Line 2021",
                    "price": 89000
                }
            }
        ],
        "customer": {
            "id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
            "object": "customer"
        },
        "customer_id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
        "referrer_id": null,
        "object": "order",
        "redemptions": {
            "r_0P6AyPLjtrQ5lgKlhl6lq2zj": {
                "date": "2021-06-16T12:52:51.204Z",
                "related_object_type": "voucher",
                "related_object_id": "v_LZITOwdcJyztAYS2TFUK6b7RvN0rL8j2"
            },
            "r_5KmvfmSWCs9U246MCbpnuJPA": {
                "date": "2021-06-17T08:13:00.736Z",
                "rollback_id": "rr_plthzMHqkiXRo5AjZiA52y51",
                "rollback_date": "2021-06-17T10:13:46.713Z",
                "related_object_type": "promotion_tier",
                "related_object_id": "promo_buwoK7NLltbo0gHbDA7ROErK",
                "related_object_parent_id": "camp_nPUCJzx1oXXCoNl0Wq4vt2g5"
            }
        }
    },
    "metadata": null,
    "redemption": "r_5KmvfmSWCs9U246MCbpnuJPA",
    "result": "SUCCESS",
    "customer": {
        "id": "cust_ufbdVkwjFZXcvwShPTBMmoCY",
        "source_id": "[email protected]",
        "object": "customer"
    },
    "related_object_type": "promotion_tier",
    "voucher": null,
    "promotion_tier": {
        "id": "promo_buwoK7NLltbo0gHbDA7ROErK",
        "name": "$15 off",
        "banner": null,
        "action": {
            "discount": {
                "type": "AMOUNT",
                "effect": "APPLY_TO_ORDER",
                "amount_off": 1500
            }
        },
        "metadata": {},
        "hierarchy": 1,
        "campaign": {
            "id": "camp_nPUCJzx1oXXCoNl0Wq4vt2g5",
            "start_date": null,
            "expiration_date": null,
            "active": true,
            "object": "campaign"
        },
        "summary": {
            "redemptions": {
                "total_redeemed": 0
            },
            "orders": {
                "total_amount": 0,
                "total_discount_amount": 0
            }
        },
        "object": "promotion_tier",
        "validation_rule_assignments": null
    }
}
{
    "code": 400,
    "message": "Existing redemptions",
    "details": "Order has other stacked redemption and the redemption cannot be rolled back.",
    "key": "existing_redemptions",
    "request_id": "v-096816bf688781bc71",
    "resource_id": "rrf_lg1cU6zUw319VnET2ySq0bKZ",
    "resource_type": "redemption_rollback"
}

Did this page help you?