Time-to-live for "checkout link" from product creation and stock assignment

When you use the interface to “create a checkout link” for any item in your store, square creates a referral link to “https://checkout.square.site/buy/”.

I can not seem to nail down the time to live on that link, after creating a product, variation, and associating stock. Sometimes the link is up quickly, sometimes not.

The project requires that the sale of a specific product, be purchased during a limited window of time (10-15 minutes max).

My workflow, which i am open for suggestions on how to modify, is as follows:
just befor the timed sale is to begin, the the api is utilized to

  1. create a product and variation, associated to a pre-existing category and location

  2. a modifier for a shipping fee is created (some customers are local and will want to pick up)

  3. available stock is assigned to the product.

  4. the response for these actions is recorded in our db,

  5. during the timed sale, when a customer navigates to a static url on our site, the currently active sale item’s id’s are used to forward the customer to the active checkout link

  6. when a sale occurs, a webhook for stock adjustment is used to adjust the available quantity in our db which we display to customers.

7 .once the timer on the sale runs out, or sales have depleted the stock the sale ends.

  1. Product, variation, and modifier are then deleted via api.

The issue is that the checkout link sometimes works during the sale window, and sometimes does not.

The sales occur over live stream and can vary, so on-the-fly creation or atleast activation, needs to occur. Customers need to have a single link that they can click on that directs them to the active sale item, which we handle via redirect from our site, but the active sale link need to be live.

Ive considered instead of creating parent, and variation, simply using static parent object, and creating a variation. As well the same function with a modifer may work…
any suggestions?

@Lance-Square you suggest, ill code and test…lol.

Hey @Horticode! Have you looked into using the Checkout API? It allows you to programmatically generate payment links, which seems like it would be a good fit for your use case.

thanks @josh-square ,
yes, it seems it is going to be a few extra steps for the same result, which is… if there is a delay between the creation of the item via the api, or even associating stock and the “online checkout” system reading the current informaiton the item does not show up, or says out of stock.
I’m guessing the database that your ecomm system is querying is probably utilizing table caching to some extent, which is entirely understandable considering the traffic you guys probably see…

After testing through out the night, I was not experiencing a delay between creating the product, assigning stock and then navigating to "https://checkout.square.site/buy/ until about 8:30am est…as of now, im only seeing a slight lag in the product going from out of stock, to in_stock. It’s probably due to increase in transactions right around coffee shop time…lol

I’d guess that you payment link table, has almost no caching as the link NEEDS to be live as soon as the api returns the response…but even that would be dependent on the item being available, and having stock. Technically, our api calls to create and stock a product occur 30 seconds before the sale timer starts. I guess in the off chance that a customer would attempt to purchase the item immediately after the sale starts, having the customer fill out their information on our site, which is then piped to the create payment link endpoint would buy some additional time for the product and inventory to be cached , But not sure if it will be enough as yesterday the link was not yet available after the sale timer had counted down past 3 minutes.

It also occurs to me that I could create al items on a daily basis in advance, and change the “sellable” or “available_online” attributes on the fly. But again, if traffic slows down table caching… i’d think the same result will occur.

Il write a script to loop through the proccess of product creation, requesting the url until available, and deletion of items, and log times to see if I can get you guys any solid numbers and i’ll give the “create payment link” endpoint a shot.
Feel free to let me know if my theories are entirely off base…It might save me some time and carpal tunnel pain…lol

Hey @Horticode, yeah I definitely encourage you to try out CreatePaymentLink, as it’ll be better suited for integrating into an application’s flow. I can’t personally speak to backend details when links are created through the seller dashboard interface, but I appreciate the effort of digging into it!

Let me know if you have any questions once you’ve had a chance to give that a try!