# How to handle subscription events?

**URL:** <https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970>\
**Category:** Questions\
**Tags:** subscriptions-api, webhooks-api\
**Created:** [December 16, 2022, 7:20pm UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970 "2022-12-16T19:20:05Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://developer.squareup.com/forums/u/kevin)\
**Post date:** [December 16, 2022, 7:20pm UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/1 "2022-12-16T19:20:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![alphasquareuser](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@alphasquareuser](https://developer.squareup.com/forums/u/alphasquareuser)\
**Post date:** [December 16, 2022, 7:27pm UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/2 "2022-12-16T19:27:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [December 16, 2022, 7:33pm UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/3 "2022-12-16T19:33:00Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://developer.squareup.com/forums/u/kevin)\
**Post date:** [December 17, 2022, 9:18pm UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/4 "2022-12-17T21:18:38Z")

</div>

Thanks for the response.

How do I test your API if the sandbox is not comparable to the actual site?

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [December 19, 2022, 6:56pm UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/5 "2022-12-19T18:56:01Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://developer.squareup.com/forums/u/kevin)\
**Post date:** [December 21, 2022, 1:01am UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/6 "2022-12-21T01:01:58Z")

</div>

The documentation does not adequately say how to handle subscriptions.

And you’re saying I can’t test it without wasting my actual money on every run?

Is there an example application? Anything that shows how to handle subscriptions beyond just creating and deleting them?

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://developer.squareup.com/forums/u/kevin)\
**Post date:** [December 21, 2022, 1:07am UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/7 "2022-12-21T01:07:22Z")

</div>

All I need to do is:

- **✔** Create a checkout link for a subscription
- Associate this subscription with my user
- Receive an alert when the user has paid or failed to pay

On Square’s competitor’s API, it is incredibly clear how to do this in the docs, with an accompanied example application.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [December 21, 2022, 1:34am UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/8 "2022-12-21T01:34:03Z")

</div>

Are you going to be using webhooks to listen for events? If so you’ll want to use the [Subscriptions webhooks](https://developer.squareup.com/reference/square/subscriptions-api/webhooks) for any created and updated notifications. For notifications on payments of a subscription you’ll want to listen to [Invoices webhooks](https://developer.squareup.com/reference/square/invoices-api/webhooks). 🙂

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://developer.squareup.com/forums/u/kevin)\
**Post date:** [December 21, 2022, 2:45am UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/9 "2022-12-21T02:45:01Z")

</div>

I understand that.

The problem is how do I associate the checkout subscription with a user in my database? The http response of the checkout endpoint is unhelpful.

In code.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [December 21, 2022, 4:59pm UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/10 "2022-12-21T16:59:15Z")

</div>

When the subscription is create the [subscription.create](https://developer.squareup.com/reference/square/subscriptions-api/webhooks/subscription.created) event will have the Square `customer_id`. With the `customer_id` you can call [RetrieveCustomer](https://developer.squareup.com/reference/square/customers-api/retrieve-customer) to get the customer details. 🙂

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://developer.squareup.com/forums/u/kevin)\
**Post date:** [December 22, 2022, 1:01am UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/11 "2022-12-22T01:01:12Z")

</div>

How do I associate the new subscription with the user (as in, the user in my database) who created the checkout link?

While creating the checkout link, can I pass in a customer email or UUID? If so, how?

Thanks

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [December 22, 2022, 1:53am UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/12 "2022-12-22T01:53:25Z")

</div>

Do you know who the customer is before they subscribe and your wanting to pass a unique ID from your database to identify them after they subscribe? 🙂

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://developer.squareup.com/forums/u/kevin)\
**Post date:** [December 22, 2022, 2:57am UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/13 "2022-12-22T02:57:23Z")

</div>

That is correct.

* * *

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [December 22, 2022, 5:34pm UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/14 "2022-12-22T17:34:43Z")

</div>

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` 🙂

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://developer.squareup.com/forums/u/kevin)\
**Post date:** [December 23, 2022, 1:20am UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/15 "2022-12-23T01:20:57Z")

</div>

Am I missing a huge section of your documentation???

In which field do I put the redirect url?

{  
“idempotency\_key”: “%s”,  
“quick\_pay”: {  
“name”: “xxx”,  
“price\_money”: {  
“amount”: %d,  
“currency”: “USD”  
},  
“location\_id”: “xxx”  
},  
“checkout\_options”: {  
“subscription\_plan\_id”: “%s”  
}  
}

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://developer.squareup.com/forums/u/kevin)\
**Post date:** [December 23, 2022, 1:22am UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/16 "2022-12-23T01:22:07Z")

</div>

Please point me to it if I am missing it, but it seems like 40% of the API is undocumented.

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [December 23, 2022, 1:24am UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/17 "2022-12-23T01:24:20Z")

</div>

It’s in the [checkout\_options](https://developer.squareup.com/reference/square/objects/CheckoutOptions#definition__property-redirect_url). 🙂

---

<div class="post-metadata">

**Author:** ![kevin](https://avatars.discourse-cdn.com/v4/letter/k/2acd7d/32.png) [@kevin](https://developer.squareup.com/forums/u/kevin)\
**Post date:** [December 29, 2022, 9:53pm UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/18 "2022-12-29T21:53:25Z")

</div>

This advice got me BANNED from Square.

DO NOT LISTEN TO THIS ADVICE

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [December 29, 2022, 10:20pm UTC](https://developer.squareup.com/forums/t/how-to-handle-subscription-events/7970/19 "2022-12-29T22:20:07Z")

</div>

What do you mean it got you banned from Square? What’s your application ID so we can take a look? 🙂
