Commits
Requests to the /evaluate
endpoint with settings.commit
set to false
don't perform any side effects for actions.
This is useful, for example, to show a customer their order before they decide to place it.
To perform side effects, settings.commit
should be set to true
. This will mark any coupon codes as used and update any loyalty points. For example the following request would record a usage of code ABC123
.
curl -X 'POST' \
'https://discounts.dovetech.com/evaluate' \
-H 'accept: application/json' \
-H 'x-api-key: [API Key]' \
-H 'Content-Type: application/json' \
-d '{
"basket": {
"items": [
{
"quantity": 2,
"price": 58.99
}
]
},
"couponCodes": [
{
"code": "ABC123"
}
],
"context": {
"currencyCode": "GBP"
},
"settings": {
"dataInstance": "Live",
"commit": true
}
}'
If code ABC123
had a usage limit of 1, this code would not be able to be used again.
Any requests with commit
set to false
will validate the code, but will not mark the code as used.
The response to this request will include a commitId
. This is a UUID that identifies the commit. This can be used to rollback the commit if needed.
Rollback
To reverse the usage of a commit you use the rollback endpoint. E.g.
curl -X 'POST' \
'https://discounts.dovetech.com/commits/ccdb97cf-e7cc-4a64-8698-52b73d53c0ac/rollback' \
-H 'accept: */*' \
-H 'x-api-key: [API Key]' \
-d ''
This will attempt to reverse any actions with side-effects that were made during the commit process.
Subsequent calls to the rollback endpoint with the same ID will have no impact - No Content
will be returned if the action has already been rolled back.
The rollback endpoint returns actions detailing the rollback process. The types supported are:
RollbackCouponCodeAccepted
RollbackAccrueLoyaltyPoints
RollbackRedeemLoyaltyPoints
These correspond to the original actions with the prefix Rollback
Coupon Codes
Rolling back a commit with coupon code will reverse any usage on the coupon code.
Rollback Coupon Codes Example
The /evaluate
endpoint returned the following actions:
[
{
"type": "CouponCodeAccepted",
"id": "ebcd262d-4c4e-451d-96b6-112f9889c58b",
"code": "MJ62KTKSFX"
},
{
"id": "958a92a4-7f97-4ea4-99a6-d7e815cd5401",
"discountId": "1f461b90-91ab-4f22-a383-d7b515ded472",
"type": "AmountOffBasket",
"qualifiedCouponCode": "MJ62KTKSFX",
"amountOffType": "PercentOff",
"value": 10,
"amountOff": 11.8,
"displayMessages": []
}
]
The rollback endpoint returned the following:
{
"actions": [
{
"type": "RollbackCouponCodeAccepted",
"id": "88a64ca0-b401-4109-82c3-906756bdd7b9",
"code": "MJ62KTKSFX"
}
]
}
Loyalty
Rolling back loyalty points is more complex than coupon codes because points may have been spent or they may have expired etc.
Rolling back accrued points can fail due to:
- Points being spent. We will try and rollback any remaining points.
- Points having expired. As a result rolling back the points has no impact on the balance.
Rolling back redeemed points can fail due to:
- Original points having expired. As a result rolling back the points has no impact on the balance.
The rollback endpoint returns information about the status of the points rolled back to give you as much information as possible.
A points status
property is returned with the following possible values: Success
, Expired
or InsufficientAmount
Rollback Loyalty Points - Simple Example
In this example the points accrued haven't been spent and the points redeemed haven't expired.
The /evaluate
endpoint returned the following actions:
[
{
"id": "3a8cd6ec-6134-465f-9b16-cdab0cb5a90c",
"discountId": "a16434cd-e1d2-4ff3-917c-b654b540a14f",
"type": "AmountOffBasket",
"qualifiedCouponCode": null,
"amountOffType": "AmountOff",
"value": 1.01,
"amountOff": 1.01,
"displayMessages": []
},
{
"id": "adcfed3e-7c18-47a0-8bbf-d999f07ee048",
"discountId": "a16434cd-e1d2-4ff3-917c-b654b540a14f",
"type": "RedeemLoyaltyPoints",
"loyaltySchemeId": "05a35e84-8e55-409f-9f87-76d55cbd0e6c",
"qualifiedCouponCode": null,
"pointsRedeemed": 101,
"displayMessages": []
},
{
"id": "d92ebd06-011f-4a17-862a-eb73941a27ed",
"discountId": "eaa7edfc-79cb-4e4f-864c-ec9ebf80c546",
"type": "AccrueLoyaltyPoints",
"loyaltySchemeId": "05a35e84-8e55-409f-9f87-76d55cbd0e6c",
"qualifiedCouponCode": null,
"pointsAccrued": 1,
"startDate": null,
"expiryDate": "2024-09-11T08:19:23.0932497",
"displayMessages": []
}
]
The rollback endpoint returned the following:
{
"actions": [
{
"id": "44c35391-26dc-4d0b-946c-ccbaa0d6832b",
"type": "RollbackAccrueLoyaltyPoints",
"loyaltySchemeId": "05a35e84-8e55-409f-9f87-76d55cbd0e6c",
"originalPointsAccrued": 1,
"pointsRolledBack": 1,
"rollbackDetails": [
{
"amount": 1,
"status": "Success"
}
]
},
{
"id": "730c2550-1b47-460d-a864-3dfa19ed5415",
"type": "RollbackRedeemLoyaltyPoints",
"loyaltySchemeId": "05a35e84-8e55-409f-9f87-76d55cbd0e6c",
"loyaltySchemeEntryIdentifier": "63c71ed5-35fc-49cb-b139-5c89d9a13452",
"originalPointsRedeemed": 101,
"pointsRolledBack": 101,
"rollbackDetails": [
{
"amount": 101,
"status": "Success"
}
]
}
]
}
As you can see from the pointsRolledBack
and rollbackDetails
properties, all points were rolled back.
Rollback Loyalty Points - Accrued Points Partially Spent
Below is an example of rolling back accrued points that have been partially spent.
{
"actions": [
{
"id": "03b6d237-288d-40b4-aeea-1e29b92b9e5d",
"type": "RollbackAccrueLoyaltyPoints",
"loyaltySchemeId": "05a35e84-8e55-409f-9f87-76d55cbd0e6c",
"originalPointsAccrued": 1000,
"pointsRolledBack": 900,
"rollbackDetails": [
{
"amount": 900,
"status": "Success"
},
{
"amount": 100,
"status": "InsufficientAmount"
}
]
}
]
}
Rollback Loyalty Points - Redeem Points - Points Expired
This can happen in the following scenario:
- Points are accrued with an expiry date
- Points are redeemed within that expiry date
- Rollback the redeemed points after the expiry date
Below is an example response of rolling back redeemed points where the original points accrued have expired.
{
"actions": [
{
"id": "8f053ddd-9671-4f2d-a6be-f0107b1ea11c",
"type": "RollbackRedeemLoyaltyPoints",
"loyaltySchemeId": "05a35e84-8e55-409f-9f87-76d55cbd0e6c",
"loyaltySchemeEntryIdentifier": "123456789",
"originalPointsRedeemed": 1,
"pointsRolledBack": 0,
"rollbackDetails": [
{
"amount": 1,
"status": "Expired"
}
]
}
]
}