Discount Code application from an app is…to put it mildly, problematic.
As far as I can tell, there are two ways that definitely work for a public app to add a DiscountCode to a purchase, without requiring the user to manually enter the code at checkout:
-
Query string application / URL redirection
-
The Storefront API (https://shopify.dev/api/storefront/2022-01/mutations/checkoutDiscountCodeApply)
As well as possibly editing an Order from the Admin API, except that requires taking over the Order creation process from the store. Not ideal!
Now, the Storefront API is locked behind converting your app to a sales channel – a very significant functionality change, and a process that isn’t even viable for public apps that already have installed users–meaning literally the only viable method appears to be query string redirects.
This seems like EXTREMELY basic functionality that should be part of the AJAX Cart API: https://shopify.dev/api/ajax/reference/cart; it’s a very negative user experience to force them through a page redirect / refresh JUST to apply a Discount Code, and a negative (and brittle) merchant experience to inject theme code modifications to adjust the query string for checkout URL(s).