I am completely new to the concept of webhooks, and I have read up on the subject. But some assistance would still be appreciated.
Currently, my eCommerce app has a shopping cart that sends customers to the Square Checkout page when they want to pay via online-checkout/payment-links. What I need is for Square to notify my app when the customers have successfully completed payment. Once the customer has successfully payment, my app needs to add the customers’ name to a list within the app and send a confirmation email.
I have looked through the Square API document on webhooks, but I am not sure which webhook to use. I see there’re payment.updated and invoice.payment_made. Am I on the right track?
With our webhooks you’ll want to listen to the payments.updated events to pull the customer_id from the payment. Once you have the customer_id you can call RetrieveCustomer to get the name of the customer to send the email confirmation.
Another question related to this. Right now while I am in development mode, I can successfully send access Square’s online customer checkout page. My understanding is I cannot simulate a successful payment/transaction in that page. If that is the case, how do I test my webhooks?
You’ll be able to test in sandbox. The sandbox will allow you to preview the link and process a payment that will trigger the payment.updated webhook events.
Was a customer_id passed in the CreatePayment request? This payment is an EXTERNAL payment and there isn’t any additional information for us to infer the customer.
I didn’t use CreatePayment. I used online-checkout/payment-links. I did not notice before, but now I can see that under the order parameter. It now says customer_id is in BETA. Does that mean it’s new and is being tested? Is it ok to use?
Okay, this is sandbox and the sandbox experience isn’t great with the Payment links. It will be there in production. Unfortunately there isn’t a way to test this end to end in sandbox. 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.
No, you won’t call both for production. For testing I’m suggesting that you call CreatePayment with a customer_id to pretend to get the customer_id for testing.
Can I get clarification on customer id. Isn’t it generated randomly by Square?
It looks like the call for CreatePayment is POST /v2/payments.
If the customer is new, do I have to call POST /v2/customers to create a new customer before calling CreatePayment so that a Square-generated ID can be inputted as part of that call?
Because right now, my app generates an ID that is in a different format than that of Square.
Glad to hear your making progress. So remember you were only calling CreatePayment to test seeing the customer_id in the webhook. In production you won’t be calling CreatePayment.
You’ll call CreateCustomer if your collecting the customer information prior to creating the link and if the customer doesn’t exist within the directory already. Otherwise we will create the customer profile when the customer checkouts out through the link.