Build 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.

Web

Warning

Configuration files contain sensitive information. Always store production configuration files in a secure, non-public area of your application.

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:

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

Step 1: Copy the template
Permalink Get a link to this section

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
Permalink Get a link to this section

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

if (!defined(_SQ_SANDBOX_TOKEN)) {
    define('_SQ_SANDBOX_TOKEN', "REPLACE_ME") ;
}

if (!defined(_SQ_SANDBOX_APP_ID)) {
    define('_SQ_SANDBOX_APP_ID', "REPLACE_ME") ;
}

if (!defined(_SQ_APP_ID)) {
    define('_SQ_APP_ID', "REPLACE_ME") ;
}

if (!defined(_SQ_APP_SECRET)) {
    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
Permalink Get a link to this section

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

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

Step 4: Autoload the Connect SDK (optional)
Permalink Get a link to this section

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:

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