I have multiple plans that my customers can subscribe to. My application needs to be alerted when the customer’s subscription is activated and each subsequent renewal.
I understand how to create a Checkout link for the subscription.
However, it is entirely unclear after reading through the documentation, how you are meant to handle the subscription.
According to the documentation, the Checkout will automatically create a customer. This does not appear to be the case; perhaps something to do with the sandbox mode? It’s also not clear how I would pass in a customer ID to this endpoint, if that is possible.
I read on this forum to pass in a “reference_id”, but I cannot find where this is mentioned in the documentation.
What is the recommended setup to correlate subscription activation and renewal with the users in my database?
You first want to create a customer and get the customer ID. Then you want to create a card on file using customer ID and card token. Then use both customer ID + Card ID to create the subscription. When you view the customer you will see both the sub and card on file under their account.
With the Square provided payment links for subscriptions we will generate the customer_id and add it to the subscription. The sandbox experience doesn’t exactly mirror production at this time. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team.
If you want to test the Square Dashboard generated subscription links at this time you’ll need to test in production. You can create some $1.00 subscriptions to test and then refund them when you’re finished.
Are you going to be using webhooks to listen for events? If so you’ll want to use the Subscriptions webhooks for any created and updated notifications. For notifications on payments of a subscription you’ll want to listen to Invoices webhooks.
When the subscription is create the subscription.create event will have the Square customer_id. With the customer_id you can call RetrieveCustomer to get the customer details.
Okay, in that case you can add the customer_id value in your database to the redirect_url. Once the customer pays you’ll get the customer_id and the subscription_id in the redirect. For example if the redirect_url is: https://www.redirect.com/?customField=value You’ll get the following when the customer pays: https://www.redirect.com/?customField=value&subscriptionId=792954ce-6416-4e0f-a40b-321105b726d7