I am using webhooks to record orders into my MySQL database.
After the main order form where the user enters his/her credit card details, we have a series of upsell pages on which the user can buy more products or decline. After the last upsell, the user is taken to a thank-you page which displays the order details from the MySQL databse and send a mail with the details to the user.
But there is one major issue. It seems that sending data to the webhook is not immediate. At the thank-you page, the last item bought doesn’t populate on the thank-you page. If I refresh the thank-you page after 15 seconds, it (the last item bought) shows.
What can be done to show all the items bought / ordered on the thank-you page ?
I don’t think that’s enough to clearly understand your process. Is the thank you page picking up the last item from your DB or is the item getting forwarded to the thank you page from the upsell page. Is the DB only getting updated from the webhook or can you (or are you) using a middle ware script from the upsell page to the thank you page that does the update? There are a lot of ways to build that model and to answer this it might require a bit more clarity
All the items are picked up from the database. The last item gets populated to the database after a few seconds after about 10 - 15 seconds. But, by that time the user goes to the thank-you page which doesn’t show the last upsell product. But if I refresh the thank-you page after a few seconds, it shows. But we can’t expect the user the refresh the thank-you page.
So instead of relying on the webhook for upsells, why don’t you send the information from the upsell to an endpoint that immediately updates the table and then redirect to the thank you page?
Our website is on WordPress, the upsell pages are on other subdomains also powered by WordPress (powered by WP- Engine) but the final thankyou page is on a subdomain called shop.mydomain.com which is on a DigitalOcean LAMP stack server that shows the final page with all the products bought and sends the email receipt to the user. So I am not tracking the details on the WordPress sites - except for InfusionSoft’s query parameters that gets passed on to the subsequent upsell pages with the customer id etc.
Ok, so if it were me, I’d read the contacts most recent order (or get it from the backend database if it already existed). Then the upsell could be both added to IS and the DB at the same time. I’ve had to solve for similar cases before and the trick isn’t so much in being able to code for it but rather knowing where you can exploit the information at the right time.
OMG ! Retrieving the orders from the API is a much better and faster solution as it’s real-time. But I relied on webhooks to store the data into the MySQL database and wrote a script to retrieve it from the database.
$url = "https://api.infusionsoft.com/crm/rest/v1/orders?access_token=$token&contact_id=".$contact_id;
Thank You very much for your input and solution.