I have been using payment links to handle the checkout process for my customers. If I have already created an associated customer with my database. How can I create a payment link that passes that customer ID through. I think it seems to be creating a new customer every time, even when I am passing in the customer ID in the order. I saw there was an older post regarding this question, which I found here. This post is a few years old, and I was wondering if there was a way to do this or at least a workaround, so I don’t have to make my own checkout page and process.
When in sandbox mode, using the "Checkout API Sandbox Testing Panel " that appears when viewing the payment link and clicking the test payment button works completely fine. It’s when I switch to production and do real test payments that it’s creating a new customer.
If there is some way to keep the process I have by using a payment link, that would be greatly appreciated, as it would much more work to create a checkout process myself when its sooo close to working.
At this time adding a known customer to a quick pay link isn’t currently available. You’ll need to add the customer in an order. For example:
{
"idempotency_key": "{{$guid}}",
"checkout_options": {
"enable_coupon": true,
"accepted_payment_methods": {
"afterpay_clearpay": true,
"apple_pay": true,
"cash_app_pay": true,
"google_pay": true
},
"allow_tipping": true,
"ask_for_shipping_address": true,
"custom_fields": [
{
"title": "Auto color"
}
],
"enable_loyalty": true,
"shipping_fee": {
"charge": {
"amount": 100,
"currency": "USD"
},
"name": "Shipping"
}
},
"order": {
"location_id": "{{location_id}}",
"customer_id": "{{customer_id}}",
"line_items": [
{
"name": "60,000 mile maintenance",
"quantity": "1",
"base_price_money": {
"amount": 25,
"currency": "USD"
},
"note": "1st line item note"
},
{
"name": "Tire rotation and balancing",
"quantity": "1",
"base_price_money": {
"amount": 25,
"currency": "USD"
}
},
{
"name": "Wiper fluid replacement",
"quantity": "1",
"base_price_money": {
"amount": 25,
"currency": "USD"
}
},
{
"name": "Oil change",
"quantity": "1",
"base_price_money": {
"amount": 25,
"currency": "USD"
}
}
]
}
}
Thanks for the response. So I create an order and pass that order into the create Payment Link. I am using the payment.updated webhook. Would I use the order attached to that payment and grab the customer id on that. Or would I have to setup an additional webhook for orders somehow. Because the payment.updated webhook works great as it tells when the payment is complete and works with the Square POS app as well, when payments are taken say through a card reader.
This is how I am passing it into the checkoutAPI function when creating a payment link, would I just then use the customer on that order. I guess I am just a bit confused on after a payment is completed how to see what customer is associated with that payment.
const response = await client.checkoutApi.createPaymentLink({
idempotencyKey: idempotencyKey,
order: {
locationId: locationId,
lineItems: lineItems,
discounts: [],
customerId: user.customerIds[0],
},
checkoutOptions: {
redirectUrl: redirectUrl,
},
});
At this time the ability to create an order with the Orders API and then create a payment link isn’t currently available. You’ll have to pass in the customer_id
when creating a payment link with an order.
Thanks for the response, Bryan. I am still a little confused by this process.
My end goal is to take a payment through the payment link and have it associated with some existing customer. Get an update from a webhook and update my database with the new payment from that existing customer.
What I am currently doing is creating the payment link with the customer ID and passing in values for an order when I create the payment link.
When I receive the update for the payment (from payment.updated webhook) I do not receive the customer ID that I created the Payment Link with, rather one square has created. Here you said
While this process works in sandbox mode. When in production, it creates the new customer, instead of using the customer ID I pass in. Just not sure why
In regard to
I am creating the order in the payment link itself which is what contains the payment link so I am just passing in the items needed for the order, I do not create the order beforehand with the Orders API just to clear things up.
If there is anyway to have payment link, payment/order to be associated with an existing customer that would be fantastic and if you could explain the process of doing so you would be a lifesaver Bryan and I would greatly appreciate it.
Do you have a payment_id
of a payment that the customer wasn’t added to? Also with payment links the customer can be added well after a payment is completed. A payment.updated
event will be triggered but its possible that it will come well after the payment is created.