Creating Integration - Custom Discount Coupons and Chekout form

Solved
Highlighted
New Member
5 0 0

Hello, we would like to build integration between our platform used to generate discount, gift card and promotion coupons / campaigns and Shopify.

Our users can generate campaigns containing discount codes and we would like to give them opportunity to use those codes in theirs Shopify Stores. Below is example how such integration could work.

 

One of requirements is the ability to use generated coupons and gift cards created by our system on checkout page of connected shop in order to apply discount to the order. After going through documentation and multiple threads on Shopify Community Forums, I got familiarized with the concept of Script Tags, Liquid templates and how to achieve the result that we desire.

From my developer's point of view, we would need to provide custom input on checkout page allowing user to enter custom code and set of buttons to apply coupon and cancel the applied discount if customer wishes to do so.

Clicking on "apply" button would send the entered code + customer info to our system validating the coupon and returning the discount that can be applied, upon that on the Shopify side we would need to apply that discount.

Now what is the best way from Shopify view to achieve that?

At the beginning we wanted to upload custom JS script in Script Tag upon shop initialization and then ask user to place some kind of HTML snippet similar to

<div id="custom-discount-input-container></div>

on checkout.liquid theme page which would get populated by JS script uploaded before, but:

1. checkout.liquid page is not accessible for regular shops, making it non available for our customers who just have simple shop (not Shopify Plus), additionally checkout.liquid is not available on development stores so we do not have a way to actually test out the integration without rolling into Shopify Plus

2. What is the best way from Shopify view to create such integration via Publicly available app from Shopify Store? The key concept for us is to send entered user code + user details from checkout page to our system in order to run our validation engine.

3. How to apply the discount on single line items or whole cart when our system returns the response that validation was successful? Should we create new Shopify Discount Coupon on the spot and apply it?

4. Are there any Shopify API webinars going on?

 

Any suggestions, help would be really appreciated, it's really important for us to do it the right way according to Shopify best practices.

 

Thanks in advance.

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 103 124

This is an accepted solution.

Hey @Voucherify ,

 

That is amazing you are looking into building integration between your platform and Shopify. I'd be happy to help out and answer the questions you have here

 

Now what is the best way from Shopify view to achieve that?

 

My first recommendation would be to avoid trying to build a solution that involves modifying or editing the Shopify Checkout. As you noted later in your post, the ability to edit the checkout.liquid is limited to merchants that are on the specific Plus Plan, and even then the modifications available are limited. This is because Shopify needs to ensure PCI level 1 compliance to protect both the merchants and their customers from potential unscrupulous behaviour.

 

It would be better for your app to do this process of accepting and validating the customer entered code + customer info before the customer enters the Shopify Checkout. And then once your app validates the customer entered code, it should create (or retrieve) the Discount Code in Shopify and then apply this Shopify Discount Code to their checkout.

 

2. What is the best way from Shopify view to create such integration via Publicly available app from Shopify Store? The key concept for us is to send entered user code + user details from checkout page to our system in order to run our validation engine.

3. How to apply the discount on single line items or whole cart when our system returns the response that validation was successful? Should we create new Shopify Discount Coupon on the spot and apply it?

You app should use the Shopify Admin API (either in REST or GraphQL) to first create the Price Rule and then the Discount Code on Shopify's end first for this particular merchant, and then once the Discount Code is made in Shopify you can use it to apply the discount on the single line item/cart (depending on your Price Rule).

 

In Shopify for most Discount types if you are using the REST Admin API, you need to first create a Price Rule before you can create a specific Discount Code based on that Price Rule (with the GraphQL Admin API you can create both at the same time or create the discount code directly). Once the Shopify Discount Code is made, you can apply it to the customer's order by redirecting them to {shop_domain}.myshopify.com/checkout?discount_code={Insert_Shopify_Discount_Code_Here}

 

Documentation on creating Price Rules: https://help.shopify.com/en/api/reference/discounts/pricerule and https://help.shopify.com/en/api/graphql-admin-api/reference/mutation/pricerulecreate

Documentation on creating Discount Codes: https://help.shopify.com/en/api/reference/discounts/discountcode

 

Are there any Shopify API webinars going on?

We do have a directory of existing webinars dedicated to Shopify Partners who would like to build apps and work with Merchants to extend Shopify's functionality: https://www.shopify.com/partners/webinars

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

1 Like
Highlighted
New Member
5 0 0

Thank you very much for the response, after doing more research we also got to the conclusion that creating discount codes on the fly and let user apply them would more safe solution and most probably we are going to follow that path.

 

Thanks for the webinars listing.

0 Likes
Highlighted
Shopify Partner
1 0 0

@hassain wrote:

You app should use the Shopify Admin API (either in REST or GraphQL) to first create the Price Rule and then the Discount Code on Shopify's end first for this particular merchant, and then once the Discount Code is made in Shopify you can use it to apply the discount on the single line item/cart (depending on your Price Rule).

 

In Shopify for most Discount types if you are using the REST Admin API, you need to first create a Price Rule before you can create a specific Discount Code based on that Price Rule (with the GraphQL Admin API you can create both at the same time or create the discount code directly). Once the Shopify Discount Code is made, you can apply it to the customer's order by redirecting them to {shop_domain}.myshopify.com/checkout?discount_code={Insert_Shopify_Discount_Code_Here}

Hi @hassain 

So for multiple automatic discount codes, if I wanted for example to have two price rules (and associated codes): 3HATS10 that gives 10% off when buying 3+ hats, and 2SHOES15 that gives 15% off when buying 2+ shoes.
The idea would be to create a single price rule and discount merging these two, and direct the customer to the checkout applying this new discount?

And also, for an app to create these discounts on the fly, when can it get this information (I'm assuming that I should use webhooks)?


0 Likes