Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ShipStream/spscommerce-php-sdk

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPS-Commerce-PHP-SDK

A PHP library for integrating with SPS Commerce HTTP APIs and JSON Schemas.

Install

composer require shipstream/spscommerce-php-sdk

HTTP Client Usage

Here is a code sample to send a REST API request to the SPS Commerce Transaction API.

<?php
require_once(__DIR__ . '/vendor/autoload.php');

use ShipStream\SpsCommerce\HttpClient\DefaultApi
use ShipStream\SpsCommerce\HttpClient\TransactionApi;
use ShipStream\SpsCommerce\HttpClient\ValidationError;
use ShipStream\SpsCommerce\HttpClient\InternalServerError;
use InvalidArgumentException;

$client = new DefaultApi(fn() => "MYACCESSTOKEN");
$api = new TransactionApi($client);
try {
    $file_path = "in/CA584618-1-v7.7-BulkImport.json";
    $file_content = file_get_contents($file_path);
    $header = [
        'Content-Type' => 'application/octet-stream',
        'sps-meta-description' => 'Creating new Transaction at specified path',
    ];
    $result = $api->createTransaction($file_path, $header, $file_content);
    print_r($result)
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();
} catch (ApiException $e) {
    echo $e->getMessage();
} catch (ValidationError $e) {
    echo $e->getMessage();
} catch (InternalServerError $e) {
    echo $e->getMessage();
}

RSX Object Usage

Here is a code sample to load a JSON string into the appropriate RSX class:

<?php

require 'vendor/autoload.php';

$jsonString = file_get_contents('sample-files/Orders(850)/PO584616-1-v7.7-DropShip.json');
$order = \ShipStream\SpsCommerce\RSX\v777\Orders\Order::import(
    json_decode($jsonString)
);

echo json_encode(\ShipStream\SpsCommerce\RSX\v777\Orders\OrderHeaderAddressItems::export($order->header->address[0]));

Development

The "RSX" classes for mapping data types to PHP objects are all generated using json-cli.

Run the shell script generate.sh to re-generate the classes if needed.

About

PHP SDK for SPS Commerce REST APIs and RSX File Formats

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.