Webhook beginner

I am trying to learn how to properly set up webhooks and a listener on my server in order to process the webhooks.

My end game is to make a mysql database entry every time i have some purchase an item with their name and a couple of the item details.

I am hoping to set this up in PHP. I have a generic rest api set up but I am trying to learn how to configure it to read one of these square webhooks.

Does any one have example php of a listener which reads the square webhooks? Or familiarity with what I am trying to accomplish?

Hi @pkdiscgolf welcome to the forums!

We have a very basic example here: https://developer.squareup.com/docs/webhooks-api/validate-notifications (note you need to switch to PHP in the top code switcher). It technically is showing you how to validate the notifications, but in doing so, you’ll see how to receive the webhooks as well. If you still have questions, let me know and I will try to assist!

Thank you for getting back to me!

I have set my app up to receive ebooks. I now have an “event id” in my app.

How do I make the call to squares server to get the information I need from a given event id?

I need:
Customer name
Customer email
Customer phone
And the status of whether they chose any choices within the specific item (in my case. Whether they chose yes or no on a checkbox charging them an extra $5)

Thank you

What webhook are you currently listening to? Customer information would be retrieved using the Customers API, but depending on what webhook you are getting would depend on how you get there. For example, if you’re receiving payment webhooks, you would need to call GetPayment, then the payment should have a customer_id attached to it, and then you can use RetrieveCustomer to get the customer information.

Anything related to the itemization would be retrieved using the Orders API.

I am listening to the orders webhook. I chose that one because I wanted to log that persons information and purchase details to my own system when they order a specific online item.

Do you have any general or php specific information on making the connection to the square api so that I can make the GetPayment and RetrieveCustomer calls?

If you’re using the PHP SDK you can see some basic functionality in the README found here: https://github.com/square/square-php-sdk. If you’re not using the SDK, then you’ll need to build out your own HTTP requests within PHP. This can be done using the built in cURL, or any other third-party HTTP library (like Guzzle). You’ll need to set the headers, any body parameters, and the URL which can be seen in the above links that I provided. In the right-hand side it shows how to do the requests in cURL or one of the SDKs.