Skip to main content

Cancelling a session with campaign budgets

One of the things we can expect when cancelling a session is that the impact of the session's effects on campaign budgets will be reverted, except for coupon creation.

Let's cancel a customer session that involves a discount total budget limit and a coupon creation budget limit.

Before following this tutorial, we recommend that you read the generic explanation about:

Let's imagine that our customer purchased 1 pair of shoes and 1 shirt.

The customer session is part of a campaign that applies a 20% discount on the session total and creates a new coupon for the customer when they redeem a valid coupon. The value of the discount applied to this session is $20.

Closing the session during checkout

Let's use the Update customer session endpoint to change the session state from open to closed during checkout. The request contains the following body:

Session update request
{
"customerSession": {
"profileId": "ExampleUser",
"couponCodes": [
"SPRING-20-ALL-34001" // The coupon code that the customer used
],
"state": "closed",
"cartItems": [
{
"name": "shoes1",
"sku": "9696",
"quantity": 1,
"price": 60,
"category": "shoes"
},
{
"name": "shirt35",
"sku": "6078",
"quantity": 1,
"price": 40,
"category": "shirts"
}
]
},
"responseContent": [
"customerSession",
"customerProfile"
]
}

This request returns the following discount effects:

Applied discount effects
{
...
"effectType": "setDiscount",
"props": {
"name": "20% Discount promo",
"value": 20 // The monetary value of the applied discount
}
}
Applied coupon effects
{
...
"effectType": "acceptCoupon",
"props": {
"value": "SPRING-20-ALL-34001" // The coupon code that was accepted
}
},
{
...
"effectType": "couponCreated",
"props": {
"value": "SUMMER-20-ALL-35465", // The coupon code that was created
"profileId": "ExampleUser"
}
}

Our customer receives a 20% discount on their order and a new coupon code (SUMMER-20-ALL-35465) that they can use in a new order.

Let's imagine that this campaign has a $20,000 discount total budget limit and that the coupon creation budget limit is 8,000. After the session is closed, the situation of the budgets is as follows:

Limit typeBudget limitVariation in sessionRemaining amount until budget limit
Discount total$20,000$20$19,980
Coupon creation8,000 coupons1 coupon7,999 coupons

After the purchase, our customer wants to return both items.

Cancelling the session

Let's use the Update customer session endpoint to change the session state from closed to cancelled.

Because we are cancelling the session with this request, we receive a rollbackDiscount effect to undo the discount effect applied during the closing of the session, and a rollbackCoupon effect to undo the coupon redemption.

We get an effects array in the response with two rollback effects:

Rolling back the discount effect

Rollback discount effect
{
...
"effectType": "rollbackDiscount",
"props": {
"name": "20% Discount promo",
"value": 20 // The monetary value of the discount that was rolled back
}
}

The impact of the discount effect on the discount total budget is automatically reverted. The total amount of discount that can be given in our campaign is $20,000 again.

Let's use the Return cart items endpoint to return the items in the session.

At this point, he rest of the workflow happens in our e-commerce app, where we would apply the necessary steps to refund the correct amount.

Rolling back the coupon effect

Rollback coupon redemption effect
{
...
"effectType": "rollbackCoupon",
"props": {
"value": "SPRING-20-ALL-34001" // The coupon code whose usage has been rolled back
}
}

Although a rollback effect is triggered for the coupon that was redeemed by our customer, no rollback effect is triggered for the new coupon. The number of coupons that can be created is still 7,999.

note

The coupon created in this session (SUMMER-20-ALL-35465) is still redeemable, and the coupon that our customer redeemed (SPRING-20-ALL-34001) becomes redeemable again.

At this point, no further action is required on the integration layer.