Skip to content

Latest commit

 

History

History
167 lines (106 loc) · 6.77 KB

README.md

File metadata and controls

167 lines (106 loc) · 6.77 KB

Transactions

Overview

A transaction is the purchase of a shipping label from a shipping provider for a specific service. You can print purchased labels and used them to ship a parcel with a carrier, such as USPS or FedEx.

Available Operations

  • list - List all shipping labels
  • create - Create a shipping label
  • get - Retrieve a shipping label

list

Returns a list of all transaction objects.

Example Usage

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use \Shippo\API;
use \Shippo\API\Models\Components;
use \Shippo\API\Models\Operations;

$security = new Components\Security();
$security->apiKeyHeader = '<YOUR_API_KEY_HERE>';

$sdk = API\ShippoSDK::builder()
    ->setShippoApiVersion('2018-02-08')
    ->setSecurity($security)->build();

try {
        $request = new Operations\ListTransactionsRequest();
    $request->rate = '<value>';
    $request->objectStatus = Components\TransactionStatusEnum::Success;
    $request->trackingStatus = Components\TrackingStatusEnum::Delivered;
    $request->page = 768578;
    $request->results = 99895;;

    $response = $sdk->transactions->list($request);

    if ($response->transactionPaginatedList !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

Parameters

Parameter Type Required Description
$request \Shippo\API\Models\Operations\ListTransactionsRequest ✔️ The request object to use for the request.

Response

?\Shippo\API\Models\Operations\ListTransactionsResponse

create

Creates a new transaction object and purchases the shipping label using a rate object that has previously been created.
OR
Creates a new transaction object and purchases the shipping label instantly using shipment details, an existing carrier account, and an existing service level token.

Example Usage

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use \Shippo\API;
use \Shippo\API\Models\Components;
use \Shippo\API\Models\Operations;

$security = new Components\Security();
$security->apiKeyHeader = '<YOUR_API_KEY_HERE>';

$sdk = API\ShippoSDK::builder()
    ->setShippoApiVersion('2018-02-08')
    ->setSecurity($security)->build();

try {
    

    $response = $sdk->transactions->create('<value>', '2018-02-08');

    if ($response->transaction !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

Parameters

Parameter Type Required Description Example
requestBody mixed ✔️ Examples.
shippoApiVersion string String used to pick a non-default API version to use 2018-02-08

Response

?\Shippo\API\Models\Operations\CreateTransactionResponse

get

Returns an existing transaction using an object ID.

Example Usage

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use \Shippo\API;
use \Shippo\API\Models\Components;
use \Shippo\API\Models\Operations;

$security = new Components\Security();
$security->apiKeyHeader = '<YOUR_API_KEY_HERE>';

$sdk = API\ShippoSDK::builder()
    ->setShippoApiVersion('2018-02-08')
    ->setSecurity($security)->build();

try {
    

    $response = $sdk->transactions->get('<value>', '2018-02-08');

    if ($response->transaction !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

Parameters

Parameter Type Required Description Example
transactionId string ✔️ Object ID of the transaction to update
shippoApiVersion string String used to pick a non-default API version to use 2018-02-08

Response

?\Shippo\API\Models\Operations\GetTransactionResponse