Giter Site home page Giter Site logo

php-inpost-api's Introduction

Inpost ShipX PHP SDK

Installation

composer require imper86/php-inpost-api

HTTPlug note

This lib uses HTTPlug so it doesn't depend on any http client. In order to use this lib you must have some PSR-18 http client and PSR-17 http factories. If you don't know which one you shoud install you can require these:

composer require php-http/guzzle6-adapter http-interop/http-factory-guzzle

Usage

Using this library is very simple, fast example should be enough to understand how it works.

use Imper86\PhpInpostApi\InpostApi;
use Imper86\PhpInpostApi\Plugin\AcceptLanguagePlugin;

// if you want to use all resources you must ask Inpost for
// access token via their contact form
// https://inpost.pl/formularz-wsparcie
$token = 'aaaa.aaaa';

// create api client
$api = new InpostApi($token);

// this library provides optional Plugin for localizing
// error messages

$api->addPlugin(new AcceptLanguagePlugin('pl_PL'));

// from now you can use these api methods:
$api->addressBooks()->(...);
$api->batches()->(...);
$api->dispatchOrders()->(...);
$api->dispatchPoints()->(...);
$api->mpks()->(...);
$api->organizations()->(...);
$api->points()->(...);
$api->sendingMethods()->(...);
$api->services()->(...);
$api->shipments()->(...);
$api->shipmentTemplates()->(...);
$api->statuses()->(...);
$api->tracking()->(...);

// fast example:
var_dump($api->organizations()->shipments()->get('1234'));

If you use IDE with typehinting such as PHPStorm, you'll easily figure it out. If not, please take a look in Resource directory

Examples

If you still wonder how to use this lib, checkout example php scripts:

Contributing

Any help will be very appreciated :)

php-inpost-api's People

Contributors

grzegorz-pierzakowski avatar imper86 avatar wlochbozena avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

php-inpost-api's Issues

Przykłady użycia

Cześć,
czy można prosić o dodanie przykładów użycia, np. jak wygenerować i pobrać etykietę?

Get tracking number in response

We use this function for save shipping label.

$shipmentData = json_decode($response->getBody()->__toString(), true);

while ($shipmentData['status'] !== 'confirmed') {
    sleep(1);
    $response = $api->shipments()->get($shipmentData['id']);
    $shipmentData = json_decode($response->getBody()->__toString(), true);
}

$labelResponse = $api->shipments()->label()->get($shipmentData['id'], [
    'format' => 'Pdf',
    'type' => 'A6',
]);

file_put_contents('var/labels/paczkomaty_label.pdf', $labelResponse->getBody()->__toString());
  1. It is possible get help with display /get tracking number in response directly after creating the shipment / save shipping label?

  2. with this function I can get all shippments:

$response2 = $api->organizations()->shipments()->get('2773');
$response3 = json_decode($response2->getBody()->__toString(), true);

var_dump($response3);

the same way I try get status shipping tracking history:

$response2 = $api->tracking()->serviceHistory()->get('620583199331612012919687');
$response3 = json_decode($response2->getBody()->__toString(), true);

var_dump($response3);

but in response I get:
array(4) { ["timestamp"]=> string(23) "Jan 9, 2023, 6:33:35 PM" ["status"]=> int(404) ["error"]=> string(9) "Not Found" ["path"]=> string(50) "/tracking/620583199331612012919687/service_history" }

Also I try track live shipping and also return not found.

php ^7.0|^8.0 ??

Hi,
I am using your lib but his seems not to work with php 8.0.
Is there any reason for that?
Thanks,
Grzesiek

php-inpost-api[v1.1.0, ..., v1.1.7] require php ^7.1 -> your php version (8.2.11) does not satisfy that requirement.

possible to fix this ?:

Problem 1
    - imper86/php-inpost-api[dev-master, v1.1.9] require imper86/php-http-cache-plugin ^2.0 -> satisfiable by imper86/php-http-cache-plugin[2.0.0].
    - imper86/php-inpost-api[v1.1.0, ..., v1.1.7] require php ^7.1 -> your php version (8.2.11) does not satisfy that requirement.
    - imper86/php-inpost-api v1.1.8 requires lcobucci/jwt ^4.1 -> found lcobucci/jwt[4.1.0, ..., 4.4.x-dev] but it conflicts with your root composer.json require (^5.0).
    - imper86/php-http-cache-plugin 2.0.0 requires psr/cache ^1.0 -> found psr/cache[1.0.0, 1.0.1] but the package is fixed to 3.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - Root composer.json requires imper86/php-inpost-api * -> satisfiable by imper86/php-inpost-api[dev-master, v1.1.0, ..., v1.1.9, 9999999-de

Request Timeout codeigniter 3

Hello,
I try integrate this library with CI3. But everytime in Sandbox I get request timeout.

This is controller:

<?php
defined('BASEPATH') or exit('No direct script access allowed');
require FCPATH . 'vendor/autoload.php';

use Imper86\PhpInpostApi\Enum\ServiceType;
use Imper86\PhpInpostApi\InpostApi;

class Inpost_controller extends Admin_Core_Controller
{
   public function __construct()
    {
        parent::__construct();
    }
	
	
	 /**
     * Create shippment Inpost Post
     */
    public function inpost_shippment_post()
    {                
      $token = 'xxxxxxxxxxxxx';
      $organizationId = '8888';
      $isSandbox = true;

      $api = new InpostApi($token, $isSandbox);

      $response = $api->organizations()->shipments()->post($organizationId, [
      'receiver' => [
        'name' => 'Marek Kowalczyk',
        'company_name' => 'Company name',
        'first_name' => 'Jan',
        'last_name' => 'Kowalski',
        'email' => '[email protected]',
        'phone' => '881888881',
		'address' => [
		    'street' => 'Malborska',
			'building_number' => '130',
			'city' => 'Kraków',
			'post_code' => '30-624',
			'country_code' => 'PL',
		],
    ],
	'sender' => [
        'name' => 'Marek Kowalczyk',
        'company_name' => 'Company name',
        'first_name' => 'Jan',
        'last_name' => 'Kowalski',
        'email' => '[email protected]',
        'phone' => '881888881',
    ],
    'parcels' => [
        ['template' => 'small'],
    ],
    'insurance' => [
        'amount' => 25,
        'currency' => 'PLN',
    ],
    'cod' => [
        'amount' => 12.50,
        'currency' => 'PLN',
    ],
    'custom_attributes' => [
        'sending_method' => 'parcel_locker',
        'target_point' => 'KRA012',
    ],
    'service' => ServiceType::INPOST_LOCKER_STANDARD,
    'reference' => 'Test',
    'external_customer_id' => '8877xxx',
]);

$shipmentData = json_decode($response->getBody()->__toString(), true);

while ($shipmentData['status'] !== 'confirmed') {
    sleep(1);
    $response = $api->shipments()->get($shipmentData['id']);
    $shipmentData = json_decode($response->getBody()->__toString(), true);
}

$labelResponse = $api->shipments()->label()->get($shipmentData['id'], [
    'format' => 'Pdf',
    'type' => 'A6',
]);

file_put_contents('/tmp/inpost_label.pdf', $labelResponse->getBody()->__toString());
	
}

}

I have currently access API only to Paczkomaty Sandbox.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.