Disclaimer - I have 12 years java development experience and completely new to liquid/shopify development. We have a custom app with some endpoints (/offers) that call shopify APIs and add some user tags dynamically with special offers. I have set up an app proxy for this endpoint and can call it manually via the shop proxy url and see the tags getting added correctly.
We have a checkout script that looks at the users tags and auto applies offers to the cart based on the user tags. We need a way to invoke the app proxy endpoint before the checkout scripts run. It should happen as close to the checkout experience as possible. We also need the customerid passed to the /offers endpoint as a parameter. Obviously I could add some ajax call to the endpoint in the checkout.liquid script but I dont want to since that is not guaranteed to complete before the checkout script runs. There is no way to make a proxy app call in the checkout script itself. Is it possible to insert a blocking call in the checkout.liquid page and what would that look like (yeah probably not best practice but please still answer the question if its possible)? Anything else we can do to guarentee the remote app completes invocation before the checkout loads (like any page or script that always runs just before the checkout page loads)?
We also would like a second endpoint to be called after the checkout notifying us the offer was used (worst case I can look at webhooks but those are also not real time and we would want something immediately).
We have a checkout script that looks at the users tags and auto applies offers to the cart based on the user tags
Are you talking about Shopify Scripts here?
When the cart/checkout change Scripts will run but there's no action built into that tool that would allow for a pause step, or a step that calls an external system.
You could certainly take the checkout template and "break" it based on certain properties in the cart or customer object but that feels hackier than I generally like. And depending on how the customer gets to checkout and what accelerated gateways are in place you might find that aspects of that could be bypassed.
Webhooks could be useful but if you must use something else perhaps you could use the thankyou page to trigger a get action from your middleware, or simply poll the API for new orders.
I saw another post from your and certainly intruiged by the need. Have you discussed this your the Merchant Success team on Shopify side?