Giter Club home page Giter Club logo

trackmage-sdk-php's Introduction

TrackMage SDK for php

Build Status Total Downloads

TrackMage is your most automated shipment tracking tool ever. Discover the simple way to show your customers where their parcels are, provide support and get more great reviews

Getting Started

  1. Create a TrackMage account – First of all, you need to sign up for a TrackMage account and retrieve your clientId and clientSecret.
  2. Minimum requirements – To run the SDK you need to have installed PHP >= 5.6. We highly recommend using v7.2 or higher.
  3. Install the SDK – Using [Composer] is the recommended way to install the TrackMage SDK for PHP. The SDK is available on Packagist as the trackmage/trackmage-sdk-php package
    composer require trackmage/trackmage-sdk-php
    
  4. See the docs There are API documentation and the generated API client docs

Quick examples

Create a client

use TrackMage\Client\TrackMageClient;

$clientId = '<client-it>';
$clientSecret = '<client-secret>';
$client = new TrackMageClient($clientId, $clientSecret);
$client->setHost('https://api.stage.trackmage.com'); //optionally
$client->setLogger(new NullLogger()); //optionally

Posting a tracking number

$workspaceId = 100;

$tn = new TrackingNumberPostTrackingNumberSetTrackingNumberMeta();
$tn->setTrackingNumber('TN-1');
$tn->setWorkspace('/workspaces/'.$workspaceId);
$tn = $client->getTrackingNumberApi()->postTrackingNumberCollection($tn);

$items = $client->getTrackingNumberApi()->apiWorkspacesTrackingNumbersGetSubresource($workspaceId);

Get workspaces list

$workspaces = $client->getWorkspaceApi()->getWorkspaceCollection();

Get carriers list

$carriers = self::$client->getCarrierApi()->getCarrierCollection();

Create webhook

Here is the webhook handler example that you need to make accessible on your side.

<?php
$workflow = [
    'type' => 'webhook',
    'period' => 'immediately',
    'title' => 'Webhook for testing',
    'workspace' => '/workspaces/<id>',
    'enabled' => true,
    'concurrency' => '1',
    'url' => 'http://acme.example',
    'authType' => 'basic',
    'username' => 'webhook_user',
    'password' => 'password',
    'notificationEmails' => [
        '[email protected]', '[email protected]',
    ],
];
$response = $client->getGuzzleClient()->post(
    '/workflows', ['json' => $workflow]
);

$data = json_decode($response->getBody()->getContents(), true);
$workflowId = $data['id'];

Tests

To run the unit tests:

composer update
./vendor/bin/phpunit

API Generation

This PHP package is automatically generated by the OpenAPI Generator project:

How to generate:

Download OpenAPI Generator CLI:

wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/4.1.0/openapi-generator-cli-4.1.0.jar -O openapi-generator-cli.jar

and run the following:

java -jar openapi-generator-cli.jar generate \
   -i https://api.test.trackmage.com/docs.json \
   -g php \
   -c .openapi-config.json \
   --skip-validate-spec \
   -o .

where -c .openapi-config.json is config with php options. See all options:

java -jar openapi-generator-cli.jar config-help -l php

Fix duplicate arguments:

find ./lib/Api/ -name '*.php' -print | php .openapi-generator/dupe_args_fixer.php --fix

trackmage-sdk-php's People

Contributors

karser avatar sensum27 avatar

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.