Checkout API Webhooks for Recurring Payments

Hi, I am following Subscription Plan Checkout and trying to create a payment link that subscribes the customer to a recurring subscription.

I have created my payment link and saved the order_id provided in my database. I then subscribe to the payment_updated webhook to detect a successful payment and match it back to the user via the order_id provided in this webhook. This works, however I believe it will only work for the first payment, and not any recurring payments, since the order_id will presumably change.
So how would I trace back a payment to the original payment link for subsequent recurring payments? I cannot see any information in the payment webhooks that would allow this, and I cannot find any other webhooks being fired that will achieve this. I have subscribed to all webhooks and can only see order and payment webhooks being triggered, none of which have information that would allow me to identify the original payment link.

Side note: The tutorial doesn’t work using the latest Square API versions (create payment link request fails due to subscription plan object having changed I believe), I had to rollback to 2023-05-17 in order to get it to work. Just thought I should mention this as could be worth updating it.

Cheers

Instead of listening to payment.updated events you can listen for invoice.payment.made. This will have the subscription_id of the subscription that you can map too. Also it will have the invoice_id. With the invoice_id you can GetInvoice. The response will have the order_id and with that ID you can call RetrieveOrder. That response will have the payment_id. :slightly_smiling_face: