Skip to content

Commit

Permalink
Updated helper functions to return sandbox or production values based…
Browse files Browse the repository at this point in the history
… on an optional param whose default value requests sandbox values
  • Loading branch information
SquareGist committed Feb 3, 2020
1 parent e8061d3 commit f3325b6
Showing 1 changed file with 73 additions and 21 deletions.
94 changes: 73 additions & 21 deletions templates/php/sq_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@

// {{{ constants

/**
* Your Square sandbox location ID
* Used to make test calls against the Square sandbox
* REPLACE_ME = a sandbox location ID from the application Locations tab
*/
if (!defined('_SQ_SANDBOX_LOCATION_ID')) {
define('_SQ_SANDBOX_LOCATION_ID', "REPLACE_ME") ;
}

/**
* Your Square sandbox token
* Used to make test calls against the Square sandbox
Expand Down Expand Up @@ -43,6 +52,23 @@
define('_SQ_SANDBOX_APP_SECRET', "REPLACE_ME") ;
}

/**
* Square sandbox domain for REST API calls
*/
if (!defined('_SQ_SANDBOX_DOMAIN')) {
define('_SQ_SANDBOX_DOMAIN', "connect.squareupsandbox.com") ;
}


/**
* Your Square production location ID
* Used to make test calls against the Square production environment
* REPLACE_ME = a location ID from the application Locations tab
*/
if (!defined('_SQ_LOCATION_ID')) {
define('_SQ_LOCATION_ID', "REPLACE_ME") ;
}

/**
* Your Square application ID
* REPLACE_ME = an application ID from the application Credentials tab
Expand All @@ -60,17 +86,19 @@
}

/**
* Square domain for REST API calls
* Your Square production token
* Used to make test calls against the Square production environment
* REPLACE_ME = a production access token from the application Credentials tab
*/
if (!defined('_SQ_DOMAIN')) {
define('_SQ_DOMAIN', "connect.squareup.com") ;
if (!defined('_SQ_TOKEN')) {
define('_SQ_TOKEN', "REPLACE_ME") ;
}

/**
* Square sandbox domain for REST API calls
* Square domain for REST API calls
*/
if (!defined('_SQ_SANDBOX_DOMAIN')) {
define('_SQ_SANDBOX_DOMAIN', "connect.squareupsandbox.com") ;
if (!defined('_SQ_DOMAIN')) {
define('_SQ_DOMAIN', "connect.squareup.com") ;
}


Expand All @@ -88,13 +116,32 @@
*
* @return string a valid access token
*/
function getAccessToken() {

$accessToken = _SQ_SANDBOX_TOKEN;
function getAccessToken(bool $requestSandboxToken = TRUE) {
if ($requestSandboxToken) {
return _SQ_SANDBOX_TOKEN;
} else {
return _SQ_TOKEN;
}
}

return $accessToken;
/**
* Returns an OAuth app secret for Square API calls
*
* By default, the function below returns sandbox credentials for testing and
* development. For production, return the application secret assigned in the
* OAuth page of your app registration with the dashboard set to Production Settings.
*
* @return string a valid app secret
*/
function getAppSecret(bool $requestSandboxSecret = TRUE) {
if ($requestSandboxSecret) {
return _SQ_SANDBOX_APP_SECRET;
} else {
return _SQ_APP_SECRET;
}
}


/**
* Returns an application Id for Square API calls
*
Expand All @@ -104,28 +151,33 @@ function getAccessToken() {
*
* @return string a valid application ID token
*/
function getApplicationId() {

$accessToken = _SQ_SANDBOX_APP_ID;

return $accessToken;
function getApplicationId(bool $requestSandboxAppId = TRUE) {
if ($requestSandboxAppId) {
return _SQ_SANDBOX_APP_ID;
} else {
return _SQ_APP_ID;
}
}


/**
* Returns a location ID for Square API calls
*
* By default, the function below returns a hardcoded location ID from the
* By default, the function below returns a hardcoded sandbox location ID from the
* Application Dashboard. For production, update the function implementation
* to fetch a valid location ID programmtically.
*
* @return string a valid location ID
*/
function getLocationId() {

// Replace the string with a sandbox location ID from the Application Dashboard
return "REPLACE_ME" ;

function getLocationId(bool $requestSandboxLocation = TRUE) {

if ($requestSandboxLocation) {
// Replace the string with a sandbox location ID from the Application Dashboard
return _SQ_SANDBOX_LOCATION_ID ;
} else {
// Replace the string with a production location ID from the Application Dashboard
return _SQ_LOCATION_ID ;
}
}

// }}}
Expand Down

0 comments on commit f3325b6

Please sign in to comment.