PHP code example of pkge / php-sdk

1. Go to this page and download the library: Download pkge/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/ */

    

pkge / php-sdk example snippets




$api = new \Pkge\API(
    '{API_KEY}', //Your API key
    'en', //API language
    false //Expand related objects
);

$metadata = $api->getLastResponseMetaData();

//Last response status code
$metadata->responseStatusCode; 

//Requests Rate-Limit information.
$metadata->rateLimit;

//Pagination information
$metadata->pagination;

$api->couriers;

$api->packages;

$webhook = new \Pkge\Webhook('WEBHOOK_SECRET');

try {
    $event = $webhook->handleEvent(
        file_get_contents("php://input"),
        $_SERVER['HTTP_PKGE_WEBHOOK_SIGNATURE']
    );
} catch (\Pkge\Exceptions\WebhookSignatureException $e) {
    die ($e->getMessage());
}

/** @var \Pkge\Entities\Package $updatedPackage */
$updatedPackage = $event->payload;

bash
composer 
bash
php ./examples/demo.php