Skip to content

Instantly share code, notes, and snippets.

@JonnyCarter
Last active March 25, 2019 10:03
Show Gist options
  • Save JonnyCarter/a8e2041e9d0a4950d3819c8fa5e9aa2a to your computer and use it in GitHub Desktop.
Save JonnyCarter/a8e2041e9d0a4950d3819c8fa5e9aa2a to your computer and use it in GitHub Desktop.
<?php
include_once '/vendor/autoload.php';
function environments( $key )
{
$array = explode('_', $key);
$environment = strtoupper($array[0]);
switch ($environment) {
case 'LIVE':
return constant('Divido\MerchantSDK\Environment::' . $environment);
break;
case 'SANDBOX':
return constant("Divido\MerchantSDK\Environment::$environment");
break;
default:
return constant("Divido\MerchantSDK\Environment::SANDBOX");
break;
}
}
function get_all_finances( $api_key, $reload = false )
{
$env = $this->environments($api_key);
$client = new \GuzzleHttp\Client();
$httpClientWrapper = new \Divido\MerchantSDK\HttpClient\HttpClientWrapper(
new \Divido\MerchantSDKGuzzle6\GuzzleAdapter($client),
\Divido\MerchantSDK\Environment::CONFIGURATION[$env]['base_uri'],
$this->api_key
);
$sdk = new \Divido\MerchantSDK\Client($httpClientWrapper, $env);
$finances = false;
$transient_name = 'finances';
if ($reload ) {
$finances = get_transient($transient_name);
return $finances;
}
if (false === $finances ) {
$request_options = ( new \Divido\MerchantSDK\Handlers\ApiRequestOptions() );
// Retrieve all finance plans for the merchant.
try {
$plans = $sdk->getAllPlans($request_options);
$plans = $plans->getResources();
set_transient($transient_name, $plans);
return $plans;
} catch ( Exception $e ) {
return [];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment