Confirming a customer completed Subscription checkout

Hello. I am using the client.checkoutApi.createPaymentLink() to allow a user to complete the purchase of a subscription. I haven’t been able to confirm the subscription was paid for before updating the membership status of their profile, but I have the following idea and wanted to be sure that it would work. I am able to retrieve the “orderId” from the “createPaymentLink” response. What I need to know is if orders actually get updated when a user completes checkout in the Square payment link. If so, I should be able to create an “order.updated” webhook in order to retrieve the “COMPLETED” status of the order. Does this plan sound like it would work? I am surprised that I have not been able to find solutions to this scenario online. Maybe this can help others as well. Thank you for your time!

When a subscription for a payment link is paid for the order will be updated. Also you can subscribe to subscription webhooks to get notified when a subscription has been created. :slightly_smiling_face:

Thanks for the reply Bryan! It seems like the order “state” is updated when a card has been charged, but I would like to take this one step further: what about when a subscription includes a free-trial at the beginning? If “state” doesn’t update until the card is charged, how can we verify that a customer completed checkout? We can always implement our own logic to restrict access if the order wasn’t updated and the free-trial expires, but it would be better to require the user to complete checkout before moving forward, so they don’t forget. What steps do you recommend for this situation?

In that case you’ll want to listen to invoice.published and invoice.updated events. The invoice.published event will be trigged every time a subscription invoice is published and sent or billed to the customer. The invoice.updated event will allow you to check the status of the invoice to see when it’s paid for. Also the event payload will contain the order_id and subscription_id so you can map it back to the subscription and order. :slightly_smiling_face:

1 Like

Thanks for your help so far Bryan. Unfortunately, I am still running into a seemingly strange roadblock. My game plan is to force a user to verify that they have completed checkout by keeping track of their order and checking to see if the order.state updates from “DRAFT” to “COMPLETED”. Even without the free-trial included, I am not seeing orders updated when payments are completed. I am using client.ordersApi.searchOrders() to retrieve every order I have initiated. I have completed checkout through the Square payment link several times, and have several subscriptions returned from client.catalogApi.listCatalog(undefined,"SUBSCRIPTION_PLAN"). What is perplexing is that I don’t have a single order that has updated its state.
I’m assuming that using client.ordersApi.searchOrders() would retrieve an updated list, but it almost feels like I have to manually perform some call to update an order in Square? I can’t explain why this is happening otherwise.
Let me know if there is any more information I can provide about my situation, and again, thanks for your help!

Rather than looking to the state of the order you may want to look to net_amount_due_money and verify it’s zero since the state doesn’t change. :slightly_smiling_face:

1 Like

Excellent. You have been an awesome help Bryan. I have one more piece to add to the puzzle:

  • I can confirm that users have completed checkout :white_check_mark:

  • I can store the orderId as part of the user document in our database :white_check_mark:

  • I can retrieve all of the subscriptions we have registered with Square :white_check_mark:

My final questions are regarding the recommended ways to assign a subscription to a user in our database and how to track that a subscription is active. I see that updated orders are connected to the customerId assigned by Square, so I can also save this to a user in our database. I think what I need to know is how to connect the Square assigned customerId to a And finally, what is the best way to know that a subscription is no longer being paid for? Setup a Subscription Webhook and connect update calls to the
I think this information brings us full-circle with our subscription cycle. I want to thank you again for your help.

Using the Subscriptions API or the Subscriptions webhooks is what your going to want to use to get that information. :slightly_smiling_face: