Square Basics

Create a config file for Square APIs and SDKs

Create a config file with helpful constants and helper functions to simplify working with Square APIs and SDKs.

You must provide credentials and location information for most Connect API and SDK calls. We recommend using a config file to keep those settings in one place and including the config file at the top of any file that will use the Connect APIs and SDKs. For example:

1require_once 'local/path/to/sq_config.php' ;

Step 1: Copy the template

Download the config file template from Github and save it as sq_config.php where it can be accessed by the rest of your application code.

Step 2: Set your credentials

In the constants section, update the REPLACE_ME strings with valid credentials from the Application Dashboard.

 1if (!defined(_SQ_SANDBOX_TOKEN)) {
 2    define('_SQ_SANDBOX_TOKEN', "REPLACE_ME") ;
 5if (!defined(_SQ_SANDBOX_APP_ID)) {
 6    define('_SQ_SANDBOX_APP_ID', "REPLACE_ME") ;
 9if (!defined(_SQ_APP_ID)) {
10    define('_SQ_APP_ID', "REPLACE_ME") ;
13if (!defined(_SQ_APP_SECRET)) {
14    define('_SQ_APP_SECRET', "REPLACE_ME") ;

You can find application credentials on the settings pages of your Square application:

  • _SQ_SANDBOX_TOKEN — the Sandbox Access Token on the Credentials page.
  • _SQ_SANDBOX_APP_ID — the Sandbox Application ID on the Credentials page.
  • _SQ_APP_ID — the Application ID on the Credentials page.
  • _SQ_APP_SECRET — the Application Secret on the OAuth page.

Step 3: Implement the helper functions

Update the getLocationId function with a valid sandbox location from the Locations settings page for your app in the Application Dashboard.

1function getLocationId() {
2  // Replace the string with a sandbox location ID
3  // from the Application Dashboard
4  return "REPLACE_ME" ;

Step 4: Autoload the Connect SDK (optional)

If you are not using a package manager, uncomment the require_once statement and update the path to autoload.php to the location where you have saved the SDK:

1require_once 'local/path/to/autoload.php';

Contact Developer Support, join our Slack channel, or ask for help on Stack Overflow