Pass customer_id to a payment link

I have just discovered that passing customer_id to a payment link does nothing.

It returns a new client instead. This way I cannot differentiate, who has purchased subscription originally because I need to mark my customers with internal ID. So first I create a customer, then I need to create a payment link for them.

Is it even possible? If not, how do I assign a subscription with specific metadata to a client with specific metadata which was created before?

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Create a Card on File from a Payment ID
Subscription Plan Checkout
Customers API Workflows

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

Or at least read metadata from subscription, this way I can at least attach real user ID to subscription.

Thanks for sharing. It helps me a lot.

Hey @ThingsAreRatherStran!

Customer IDs with the CreatePaymentLink endpoint are derived based on the entered customer information, so the customer_id field in an order won’t apply here.

As far as passing metadata goes, I’d recommend trying something like this:

  1. In your CreatePaymentLink request, set the metadata field in your order. Alternatively, if you’re specifically looking to set an internal customer ID, you can consider using reference_id. Please note that the order created here is an order template, which is not the same order that gets paid in a subscription’s invoice.
  2. Listen for the subscription.created webhook, which will fire when a new subscription is created.
  3. In that webhook body, you’ll find an order_template_id field.
  4. If you retrieve that order_template_id via the Orders API, you’ll get back the order you created for your Payment Link, including metadata and reference_id if those were set.

Let us know if you have any follow up questions!

Hey @josh-square!

I appreciate your input. By swapping quick_pay with order I could finally get my metadata to show up.

I passed customer_id to Order according to documentation but resulting Payment had new customer_id. However, when I retrieved subscription by its ID from primary_recipient, correct customer_id was returned for that subscription_id.

However, I could not find any metadata that I have passed along with the request. I could find it in [:subscription][:phases][0][:order_template_id] inside subscription. Well, I guess it is better than nothing and at least I can put some metadata now.

I do not listen to subscription.created/subscription.updated as I need to capture each and every payment, so I listen to invoice.paid.