I think your use case is too specific for an app to help
So on the basic plan, checkout.liquid isn’t available. The approach I recommend is to use a custom middleware server (like your external API you have) by interacting with the Shopify Admin API to create and manage dynamic discount codes, then redirecting the user to a pre-filled checkout URL.
Here is what that could look like in more detail:
Custom Frontend on Cart Page: You’d need a custom JavaScript on your cart page (or a custom “Proceed to Checkout” button). This script would capture the JWT token property from the product in the cart.
External Server (Middleware): When the customer initiates checkout, your custom JavaScript would send the JWT token to your external server. This server would then:
Call your external validation API to check the JWT.
If valid = true:
Use the Shopify Admin API to create a temporary, single-use 100% discount code specifically for that product.
Use the Shopify Admin API to create a temporary, single-use free shipping discount code.
Redirect the customer to the Shopify checkout URL, pre-applying both discount codes. The URL would look something like https://yourstore.myshopify.com/checkout?discount=PRODUCT_DISCOUNT_CODE,SHIPPING_DISCOUNT_CODE. You’d need to ensure these discount codes are unique and have strict usage limits (e.g., one use per customer, expires quickly).
If valid = false:
Redirect the customer to the standard Shopify checkout without any discount codes applied.
Discount Code Management: Your external server would also need logic to clean up these temporary discount codes after they’re used or if they expire without being used, to prevent abuse and keep your discount page clean and up to date.
Hope this helps give you an idea on how this could be done!
The two APIs that would make this doable (Shopify Functions, Checkout UI Extensions API) are unavailable for non-public apps if you’re not on Plus. So, you have two real options:
Create draft orders programmatically. When someone clicks “Check out,” instead of going straight to the Shopify checkout, have your server create a draft order, perform your discount validation logic, and then redirect them to the draft order checkout. I highly recommend against this. Draft orders use a separate checkout and very easily break other discounts. Plus, you now have another point of failure for your checkout.
After the order is placed, receive a webhook, do your JWT check, and then edit the order programmatically. I know you said you wanted this to happen before checkout, but this is probably a cleaner approach.
Ultimately, your options for writing custom checkout code are limited on Shopify Basic (by design).
Simplest way to decomplexify this is to test if your process can use customer segments to apply the specific discounts.
Then just require a customer account ,and in addition to valid = true put the customer in a segment to get access to premade automatic discounts; BEFORE checkout
So you’d only use valid = true for display logic purposes on the frontend and no where else because of possible abuse if used to control real world monetary values.
Isn’t that just setting a cart attribute, then a discount app/function to check the attributes.
The problem of course is this becomes a static public facing value in the DOM, and not dynamic; so can have serious problems ; e.g. coupon scraping sites/tools. Even a minimum it wouldn’t work to be dynamic by having some other shopify backend nonce value to compare then trash asap; as function apps can’t dynamically check a specific metafield key; e.g. shop.metafields.JWT[session] .
The carve out for VERY specific use cases is to maybe stuff the nonce values into a JSON metafield for cross checking, keep in mind size limit constraints for functions. so you can’t just use a 2million character JSON dump field, you’d have to have some rotating/rolling-window scheme for all relevant sessions.
Otherwise if trying to insist on this happening ONLY in checkout then everything @tobebuilds said holds true, so your trying to do too much in specific ways.
If you can validate the JWT token using a custom app/script on your side and store the result in a cart metafield (if you’re using hydrogen). Alternatively you could also use the cart attribute or line item attribute with a hashed version of your response.
You can then apply the product and shipping discounts you need using an app like Dollarlabs: Ultimate Discounts which can read the cart metafield / attributes and apply operations based on it.
Another approach would be to store this value in the customer metafield as that would be much more secure and easier to validate.