PHP code example of patryk-sawicki / inpost-laravel

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

    

patryk-sawicki / inpost-laravel example snippets


INPOST_API_KEY = 'your_api_key'

use PatrykSawicki\InPost\app\Classes\InPost;

InPost::organizations()->list(array $options = [], bool $returnJson = false);

InPost::organizations()->get(int $id, bool $returnJson = false);

InPost::organizations()->statistics(int $id, bool $returnJson = false);

InPost::services()->list(bool $returnJson = false);

InPost::points()->list(array $options = [], bool $returnJson = false);

InPost::points()->get(string $name, bool $returnJson = false);

use PatrykSawicki\InPost\app\Classes\InPost;
use PatrykSawicki\InPost\app\Models\Cash as InPostCash;
use PatrykSawicki\InPost\app\Models\Dimensions as InPostDimensions;
use PatrykSawicki\InPost\app\Models\Weight as InPostWeight;
use PatrykSawicki\InPost\app\Models\Address as InPostAddress;
use PatrykSawicki\InPost\app\Models\Parcel as InPostParcel;
use PatrykSawicki\InPost\app\Models\Parcels as InPostParcels;
use PatrykSawicki\InPost\app\Models\Receiver as InPostReceiver;
use PatrykSawicki\InPost\app\Models\Sender as InPostSender;

$shipment = InPost::shipment();

/*Set organization*/
$shipment->setOrganizationId(123);

/*Receiver*/
$receiverAddress = new InPostAddress('street', 'building_number', 'city', 'post_code', 'PL');
$receiver = new InPostReceiver('name', 'company name', 'first name', 'last name', 'e-mail', 'phone', $receiverAddress);
$shipment->setReceiver($receiver);

/*Sender - Optional*/
$senderAddress = new InPostAddress('street', 'building_number', 'city', 'post_code', 'PL');
$sender = new InPostSender('name', 'company name', 'first name', 'last name', 'e-mail', 'phone', $senderAddress);
$shipment->setSender($sender);

/*Parcels*/
$dimensions = new InPostDimensions(10, 10, 10, 'mm');
$weight = new InPostWeight(10, 'kg');
$firstParcel = new InPostParcel($dimensions, $weight, 'parcel 1');

/*Second parcel is optional.*/
$dimensions = new InPostDimensions(20, 20, 20, 'mm');
$weight = new InPostWeight(5, 'kg');
$secondParcel = new InPostParcel($dimensions, $weight, 'parcel 2');

$shipment->setParcels(new InPostParcels($firstParcel, $secondParcel));

/*Insurance - Optional*/
$insurance = new InPostCash(100, 'PLN');
$shipment->setInsurance($insurance);

/*Cod - Optional*/
$cod = new InPostCash(100, 'PLN');
$shipment->setCod($cod);

/*Additional Services - Optional*/
$shipment->setAdditionalServices(['sms', 'email']);

/*Reference - Optional*/
$shipment->setReference('reference');

/*Comments - Optional*/
$shipment->setComments('comments');

/*External customer id - Optional*/
$shipment->setExternalCustomerId('external customer id');

/*MPK - Optional*/
$shipment->setMpk('mpk');

/*Is return - Optional*/
$shipment->setIsReturn(false);

/*Service*/
$shipment->setService('inpost_locker_standard');

/*Custom attributes - Optional*/
$shipment->setCustomAttributes(['target_point' => 'xxx']);

/*Only choice of offer - Optional*/
$shipment->setOnlyChoiceOfOffer(true);

/*Send shipment*/
$shipment->send(bool $returnJson = false);

InPost::shipment()->cancel(int $id, bool $returnJson = false);

return InPost::shipment()->label(int $id, string $format = 'pdf', string $type = 'normal');

InPost::tracking()->get(string $tracking_number, bool $returnJson = false);

InPost::statuses()->list(bool $returnJson = false);

use PatrykSawicki\InPost\app\Classes\InPost;
use PatrykSawicki\InPost\app\Models\Address as InPostAddress;

$dispatchOrders = InPost::dispatchOrders();

/*Set organization*/
$dispatchOrders->setOrganizationId(2324);

/*Set shipments*/
$dispatchOrders->setShipments(1, 2, 3, 4);

/*Set comments - Optional*/
$dispatchOrders->setComments('Test');

/*Set address*/
$dispatchOrders->setAddress(new InPostAddress('street', 'building_number', 'city', 'post_code', 'PL'));

/*Set office hours - Optional*/
$dispatchOrders->setOfficeHours('09:00 - 18:00');

/*Set name*/
$dispatchOrders->setName('Patryk Sawicki');

/*Set phone*/
$dispatchOrders->setPhone('+48793202257');

/*Set email - Optional*/
$dispatchOrders->setEmail('[email protected]');

/*Create a new dispatch orders.*/
$dispatchOrders->create(bool $returnJson = false);

InPost::dispatchOrders()->cancel(int $id, bool $returnJson = false);

$dispatchOrders = InPost::dispatchOrders();

/*Set organization*/
$dispatchOrders->setOrganizationId(2324);


$dispatchOrders->list(bool $returnJson = false);

$dispatchOrders->get(int $id, bool $returnJson = false);

$dispatchOrders = InPost::dispatchOrders();

/*Set organization*/
$dispatchOrders->setOrganizationId(123456);

$dispatchOrders->addComment(int $dispatch_order_id, string $comment, bool $returnJson = false);

$dispatchOrders = InPost::dispatchOrders();

/*Set organization*/
$dispatchOrders->setOrganizationId(123456);

$dispatchOrders->updateComment(int $dispatch_order_id, int $comment_id, string $comment, bool $returnJson = false);

$dispatchOrders = InPost::dispatchOrders();

/*Set organization*/
$dispatchOrders->setOrganizationId(123456);

$dispatchOrders->removeComment(int $dispatch_order_id, int $comment_id, bool $returnJson = false);