PHP code example of craymend / serve-first-php-sdk

1. Go to this page and download the library: Download craymend/serve-first-php-sdk 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/ */

    

craymend / serve-first-php-sdk example snippets




raymend\ServeFirst\Request;

$apiVersion = 'v2';

$mode = Request::MODE_SANDBOX;
// $mode = Request::MODE_PRODUCTION;

$sourceKey = 'your-key';
$sourcePin = 'your-pin';

$request = new Request($sourceKey, $sourcePin);

// the mode controls the baseUrl
echo 'baseUrl: ' . $request->getBaseUrl() . '<br>';
echo 'Switch to sandbox mode<br>';
$request->setMode($mode); // Change to sandbox mode
echo 'baseUrl: ' . $request->getBaseUrl() . '<br>';



echo "Test getting data:<br><br>";

$uri = '/products/categories';

$data = [];

$result = $request->get($uri, $data);

if (!$result->getStatus()) {
    echo 'error:<br><br>';

	$errors = $result->getErrors();
    echo json_encode($errors);
}else{
    echo 'Success! data:<br><br>';
    $data = $result->getData();
    echo 'data: ' . json_encode($data) . '<br>';
}