Redeem a reward for the currently logged-in customer. Deducts points from their balance and generates a Shopify discount code.
Usage
MageSDK.redeemReward('reward_abc').then(function(resp) {
if (resp.success) {
console.log('Discount code:', resp.data.discountCode);
} else {
console.log('Error:', resp.error);
}
});
Parameters
The ID of the reward to redeem. You can get reward IDs from getShopRewards.
Response
Whether the redemption was successful.
The generated Shopify discount code.
Details of the redeemed reward.
Type of discount applied.
Errors
| Error | Cause |
|---|
"Customer not found" | Customer is not logged in or not enrolled |
"Insufficient points" | Customer does not have enough points |
"Reward not found" | The reward ID is invalid |
<button id="redeem-btn" data-reward-id="reward_abc">
Redeem 500 points for \u00a35 off
</button>
<script>
document.getElementById('redeem-btn').addEventListener('click', function() {
var rewardId = this.getAttribute('data-reward-id');
MageSDK.redeemReward(rewardId).then(function(resp) {
if (resp.success) {
alert('Your discount code: ' + resp.data.discountCode);
} else {
alert('Error: ' + resp.error);
}
});
});
</script>