Step 1: Download Composer and dependencies
This application requires the PHP Square SDK as well as DotEnv for reading environment variables, which you install via Composer.
First, download Composer in this directory with the instructions on this page.
After you've downloaded Composer, install the dependencies with the following command from this directory:
php composer.phar install
Step 2: Get your credentials and set the redirect URL:
Open the Developer Dashboard.
Choose Open on the card for an application.
At the top of the page, set the dashboard mode to Sandbox.
Choose OAuth in the left navigation pane. The OAuth page is shown.
In the Sandbox Redirect URL box, enter the URL for the callback you will implement to complete the OAuth flow:
http://localhost:8000/sandbox_callback.phpThis example uses localhost in the Square Sandbox. You can use HTTP for localhost but an actual web server implementation must use HTTPS.
in the Sandbox Application ID box, copy the application ID.
In the Sandbox Application Secret box, choose Show, and then copy the application secret.
Click Save.
Create the
sandbox_config.phpfile and add the following code. Follow the instructions in the file to replace the appropriateREPLACE_MEplaceholders with the Sandbox application ID and Sandbox application secret. The file should look like the following:- <?phprequire 'vendor/autoload.php';use Square\SquareClient;use Square\Exceptions\ApiException;use Square\Models\CreateCustomerRequest;use Square\Environment;$client = new SquareClient(['accessToken' => 'your access token',"environment" => Environment::SANDBOX]);//$customersApi = $client->getCustomersApi();$api_response = $client->getCustomersApi()->listCustomers();if ($api_response->isSuccess()) {$result = $api_response->getResult();} else {$errors = $api_response->getErrors();}echo json_encode($result);
- This will show the list of customers in your sandbox account
Comments
Post a Comment