Calculate Order vs Update Order

I am building an e-commerce application that allow users to add items to their cart followed by checking out.
I am trying to determine what flow is recommended.
Option 1:

  • call calculateOrder any time a user adds/edits an item in the cart
  • call CreateOrder when the user is ready to make a payment, and use the order_id to process the payment.

Option 2:

  • Create an order when user adds/edits items in their cart and disregard all older orders

Option 3

  • Create an order when user adds their first item in the cart
  • call UpdateOrder when there are changes to the order

Option 1 is ideal because I don’t need to determine if the user edited an item or just deleted it, I can just re-calculate the whole order. This also doesn’t spam square with a bunch of OPEN orders that very likely will never be full-filled. The CalculateOrder endpoint is in Beta, so not sure if I should be using this. Also leaving the actual creation of the order till the user wants to pay doesn’t seem like a good user experience because they’d have to wait for the createOrder call to finish before being able to enter their credit card information.

Option2 creates a new order on any change to the cart which spams the merchant with a number of Open orders. The docs mention that the merchant will not be able to see these OPEN orders unless they are fulfilled. Is there a drawback of basically spamming OPEN orders? Do they have a TTL after which square clears them out?

Option3 is probably the most sane but requires a lot more work on the developer’s end to limit the number of orders created. This seems like the correct way to go, but I am not seeing anything in the docs that state that this option has any drawbacks.

I am also interested in this, I am developing an application right now and the cart/basket functionality is substantially easier when using the calculateOrder beta endpoint

We definitely recommend proceeding with Option 1. Here’s why:

  1. Simplified Order Calculation: By calling calculateOrder every time a user adds or edits an item in the cart, you can easily re-calculate the entire order without needing to determine if an item was edited or deleted. This simplifies the logic and reduces potential errors.
  2. Avoiding Open Order Spam: This approach avoids creating multiple unnecessary open orders, which can clutter the system and potentially cause confusion. Since calculateOrder is only called when needed, it keeps the order management clean and efficient. :slightly_smiling_face: