Get user provided email from square payment link

I’m trying to work out how to get access to the email entered on the Square checkout form so that we can email a custom receipt. I can’t find any way to get access to this email below:

I have access to the order and payment:

const order = await square.ordersApi.retrieveOrder(orderId);
const fullPayment = await square.paymentsApi.getPayment(order.result.order.tenders[0].id);

I would have expected fullPayment to contain buyerEmailAddress, but it’s undefined? We aren’t creating a customer for the purchase so customerId is also undefined.

The email that is entered into the checkout will create a Square customer if one does not already exist with that email. If customer already exists, their ID will be associated with the order.

@josh-square thanks for the reply. I’ve managed to find the customer that has been created with the email, however I don’t seem to be able to link it to the payment.

When doing

const order = await square.ordersApi.retrieveOrder(orderId);

The customerId is undefined and is also undefined under the payment/tender.

I’ve been able to find the customer by doing:

const customers = await square.customersApi.listCustomers();

But then it’s just a guess at which customer made the order and it also says there may be a delay to the customer being returned in the results.

Is there anyway to get the correct customer id from the order?

Hey @aejb, do you mind providing us with the following?

  • Your applicaiton ID
  • The customer_id from your example
  • The order_id you’re expecting that customer on


@josh-square Sure, details are:

app id: sandbox-sq0idb-CbInicNI0l7tvsCgvUHLmw
customer id: 0MHKXWX61SYEVZ7SK27KDYPX5W (I’m not sure if this is the correct one for the payment as it doesn’t seem to be linked)
payment id: rJQB51mQK5q5DfsuIm1fVpvFuaB
order id: pmBmBE5cUcdY30D4R4XEqIF4h7JZY

When calling “Retrieve order” I would expect the customer_id field to be populated, or when calling “Get payment”, buyer_email_address.

I don’t actually need a customer, just the email provided.

Thanks for providing that @aejb! I’m checking what the expected behavior here is.

Hey @aejb, we actually noticed in your screenshot that you’re using the old Checkout API endpoint (CreateCheckout). It has since been replaced with CreatePaymentLink. While CreateCheckout remains available to use, I’d definitely recommend using CreatePaymentLink, if possible. It will allow for the email behavior described above and will also be the endpoint to receive new feature updates in the future.

You can read more about it here: Checkout API Overview