Customers – Square Corner Blog – Medium

This is the third post in our series illustrating how to make a dashboard for your sandbox developer account. For more context, take a peek at Part 1 and Part 2.

In previous posts, we added the ability to view location information as well as a full record of all transactions. For the third installment of our Sandbox Dashboard series, we’ll add functionality to display and interact with our sandbox customers. Let’s take a look at where we ended up last time:

Adding additional structure

First things first, we’re going to add a new item in the navigation bar so that we can access the customers page, as well as create a new php file for all the code. Now our navbar looks like this:

To display the customers, we can take a similar approach to the transaction page by using a table of all customers and their associated information. To do this, we can call the ListCustomers endpoint and iterate though the array of customers that gets returned.

Now we have a new page listing all sandbox customers as well as any other contact information customers choose to provide: an email address or phone number, as well as a link to delete the customer. One of the most important uses of a dashboard or any GUI is to give you access to run commands in a way that is usually a little easier than running them from the command line.

Deleting Customers

Whenever you hit the “delete” button, it calls a javascript function that initiates an AJAX request to a PHP script that does the deleting and sends the id of the customer to be deleted as a POST variable. It also creates a dialog to confirm the deletion, as well as some logging to the developer console if something went wrong.

The PHP script that actually deletes a customer is very simple. It does a couple error checks, and then uses Square’s PHP SDK to call the deleteCustomer() method on the supplied id.

That sums it up for our sandbox dashboard customer’s tab! You can see the work in progress for this example on GitHub, and feel free to add any comments if you have feedback or suggestions.

If you think you might be interested in working on projects like these, take a look at our open positions on Our developer’s team is hiring!

Source link