swellAPI.makeRedemption(opts, successCB, errorCB)

This method is used to redeem a customer’s points for a discount. You need to pass the redemptionOptionId of the redemption option they wish to redeem. If successful the points will be deducted from the customer’s account. You can optionally pass a boolean delayPointDeduction set to true to wait until the coupon is used in an order to remove the points.

The redemption object is passed back to the successCB which has information about the discount code (if applicable) that was generated.

$(document).on("swell:setup", function() {
  // depending on your cart/checkout markup the selectors will need to be updated
  var fillAndSubmitCouponCodeForm = function(couponCode) {
    // set the value for the coupon code input
    $("#coupon-code-input-element").val(couponCode);

    // trigger a click on the submit button
    $("#coupon-code-submit-btn").click();
  };

  var redemptionOptionSelect = $("#redemption-option-select");

  var onSuccess = function(redemption) {
    fillAndSubmitCouponCodeForm(redemption.couponCode);
  };
  var onError = function(err) {
    $("#error").show();
  };

  swellAPI.makeRedemption(
    { redemptionOptionId: redemptionOptionSelect.val() },
    onSuccess,
    onError
  );
});

Options

AttributeTypeDescription
redemptionOptionIdintThe redemption option id that is being redeemed
delayPointDeductionbooleanIf true, points are not deducted until after the order is placed. (optional, defaults to false)

Redemption Object

AttributeTypeDescription
couponCodestringThe coupon code for this discount
pointsUsedintThe amount of points used for this redemption
appliesToIdintThe product, variant, or collection id this discount can be used for
discountTypestringA string representing the type of discount this redemption was for. Possible values include: fixed_amount, percentage, variable, shipping, product.
discountRateCentsintIf converting points to fixed dollar discount this is the conversion rate used in cents per point.
redemptionOptionIdintThe redemption option that was used to generate this redemption.