Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Shopify script | TapCart exclusive discount code

Shopify script | TapCart exclusive discount code

alex-mm
Shopify Partner
6 1 0

Hi there, 

I'm trying to limit the use of a coupon code only to be valid if applied during checkout in our mobile app (Tapcart).

From my knowledge, I can achieve this by checking the request header matches the specified mobile app header, correct?

I have a base script here. Does anyone know how far I am from making this work?

 

INPUTS:
  coupon_code: String # Specify the coupon code here.
  app_header: String # Specify the header value here.

# Check if the coupon code is being used in the mobile app.
if Input.cart.discount_code and Input.cart.discount_code.code == coupon_code and request.headers['XXXXXXX'] == app_header
  # If yes, apply the discount.
  Input.cart.discount_code = Input.cart.discount_code
else
  # If no, remove the discount.
  Input.cart.discount_code = nil
end

OUTPUT:
  # Update cart.
  Input.cart

 

 

If I don't know the header value, can I use the code below and don't apply the code if the request is coming from Shopify?

INPUTS:
  coupon_code: String # Specify the coupon code that can only be used in the mobile app.

# Check if the coupon code is being used and the request is not coming from Shopify.
if Input.cart.discount_code and Input.cart.discount_code.code == coupon_code and request.headers['X-ShopId'] == nil
  # If the coupon code is being used and the request is not coming from Shopify, apply the discount.
  Input.cart.discount_code = Input.cart.discount_code
else
  # If the coupon code is not being used or the request is coming from Shopify, remove the discount.
  Input.cart.discount_code = nil
end

OUTPUT:
  # Output the updated cart.
  Input.cart

 

Replies 0 (0)