PHP code example of grandmasterx / safecharge
1. Go to this page and download the library: Download grandmasterx/safecharge library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
grandmasterx / safecharge example snippets
$client = new \grandmasterx\safecharge\api\RestClient([
'environment' => \grandmasterx\safecharge\api\Environment::TEST,
'merchantId' => '<your merchantId>',
'merchantSiteId' => '<your merchantSiteId>',
'merchantSecretKey' => '<your merchantSecretKey>',
]);
$client = new \grandmasterx\safecharge\api\RestClient();
$config = $client->getConfig();
$config->setEnvironment(\grandmasterx\safecharge\api\Environment::TEST);
$config->setMerchantId('<your merchantId>');
$config->setMerchantSiteId('<your merchantSiteId>');
$config->setMerchantSecretKey('<your merchantSecretKey>');
$logger = new Monolog\Logger('safecharge-php-sdk');
$logger->pushHandler(new Monolog\Handler\StreamHandler('path/to/log', Monolog\Logger::DEBUG));
$client->setLogger($logger);
$client = new \grandmasterx\safecharge\api\RestClient([
'environment' => \grandmasterx\safecharge\api\Environment::TEST,
'merchantId' => '<your merchantId>',
'merchantSiteId' => '<your merchantSiteId>',
'merchantSecretKey' => '<your merchantSecretKey>',
]);
$authenticationService = new \grandmasterx\safecharge\api\services\AuthenticationManagement($client);
$authenticationResponse = $authenticationService->getSessionToken([
'clientRequestId' => '1'
]);
$openOrderParams = [
'sessionToken' => $authenticationResponse['sessionToken'],
'currency' => 'USD',
'amount' => "10",
'amountDetails' => [
"totalShipping" => "0",
"totalHandling" => "0",
"totalDiscount" => "0",
"totalTax" => "0"
],
'items' => [
[
"id" => "1",
"name" => "name",
"price" => "10",
"quantity" => "1"
]
],
];
$orderService = new \grandmasterx\safecharge\api\services\OrdersManagement($client);
$openOrderResponse = $orderService->openOrder($openOrderParams);