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.
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
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 Square.com/Careers. Our developer’s team is hiring!