sameday-courier / php-sdk
Sameday Courier SDK for PHP
Installs: 135 538
Dependents: 1
Suggesters: 0
Security: 0
Stars: 19
Watchers: 4
Forks: 15
Open Issues: 10
Requires
- php: ^5.6|^7.0|^8.0
- ext-json: *
Requires (Dev)
- ext-curl: *
- guzzlehttp/guzzle: ~5.0
- phpunit/phpunit: ~5.4|>=9.5
- squizlabs/php_codesniffer: ^3.5
Suggests
- guzzlehttp/guzzle: Allows for implementation of the Guzzle HTTP client
- dev-master
- v2.4.1
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v1.8.3
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.0
- dev-SIP-643
- dev-SIP-675
- dev-SamedayGetParcelResponse
- dev-SIP-410
- dev-SIP-407
- dev-Add_postal_code_param_tests
- dev-Add_postal_code_param
This package is auto-updated.
Last update: 2025-04-29 01:30:09 UTC
README
This repository contains the open source PHP SDK that allows you to access the Sameday Courier Platform from your PHP app. It was inspired by Facebook PHP-SDK.
Installation
The Sameday PHP SDK can be installed with Composer. Run this command:
$ composer require sameday-courier/php-sdk
Usage
Note: This version of the Sameday SDK for PHP requires PHP 5.4 or greater.
Simple example to get available pickup points and services for a client, request a new AWB and download the PDF for it.
require_once __DIR__ . '/vendor/autoload.php'; // Change path as needed. // Initialization. Change user and password as needed for your account. For testing purposes (also implies different user/password) set a third parameter to 'https://sameday-api.demo.zitec.com'. $samedayClient = new \Sameday\SamedayClient('user', 'password'); $sameday = new \Sameday\Sameday($samedayClient); // Get list of available pickup points for client. $pickupPoints = $sameday->getPickupPoints(new \Sameday\Requests\SamedayGetPickupPointsRequest()); // Use first found pickup point id. These ids are different for DEMO and PROD environments. This id can be cached on your application. $pickupPointId = $pickupPoints->getPickupPoints()[0]->getId(); // Get list of available services for client. $services = $sameday->getServices(new \Sameday\Requests\SamedayGetServicesRequest()); // Use first service id. These ids are different for DEMO and PROD environments. This id can be cached on your application. // This is just for example purpose. Choose the right service for your app. // For instance if requesting with 2H service (delivery in 2 hours) and cities are different (pickup point city and recipient city) then the validation will fail. $serviceId = $services->getServices()[0]->getId(); try { $awb = $sameday->postAwb(new \Sameday\Requests\SamedayPostAwbRequest( $pickupPointId, null, // Contact person id can be left to NULL and default will be used. new \Sameday\Objects\Types\PackageType(\Sameday\Objects\Types\PackageType::PARCEL), [ // This will generate an AWB expedition with 2 parcels (packages). Only the $weight is mandatory. new \Sameday\Objects\ParcelDimensionsObject(0.5), new \Sameday\Objects\ParcelDimensionsObject(3, 15, 28, 67) ], $serviceId, new \Sameday\Objects\Types\AwbPaymentType(\Sameday\Objects\Types\AwbPaymentType::CLIENT), // Who pays for the AWB. CLIENT is the only allowed value. new \Sameday\Objects\PostAwb\Request\AwbRecipientEntityObject('Huedin', 'Cluj', 'str. Otesani', 'Nume Destinatar', '0700111111', 'destinatar.colet@gmail.com', new \Sameday\Objects\PostAwb\Request\CompanyEntityObject('nume companie SRL')), // AWB recipient. Please note that CompanyEntityObject is optional if the recipient is not company. 0, // Insured value. 100 // Cash on delivery value. Can be 0 if the payment was made online. // Other parameters may follow, see https://github.com/sameday-courier/php-sdk/blob/master/docs/reference/SamedayPostAwbRequest.md )); } catch (\Sameday\Exceptions\SamedayBadRequestException $e) { // When request fails validation. Show the list of validation errors. var_dump($e->getErrors()); exit; } // Other exceptions may be thrown, see https://github.com/sameday-courier/php-sdk/blob/master/docs/reference.md#core-exceptions $pdf = $sameday->getAwbPdf(new \Sameday\Requests\SamedayGetAwbPdfRequest($awb->getAwbNumber(), new \Sameday\Objects\Types\AwbPdfType(\Sameday\Objects\Types\AwbPdfType::A6))); echo $pdf->getPdf();
Complete documentation, installation instructions, and examples are available here.
Tests
- Composer is a prerequisite for running the tests. Install composer globally, then run
composer install
to install required files. - The tests can be executed by running this command from the root directory:
$ ./vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
License
Please see the license file for more information.