shipstream / spscommerce-php-sdk
一个用于通过HTTP与SPS Commerce集成的PHP库
2.0.0
2024-08-20 08:20 UTC
Requires
- ext-json: *
- guzzlehttp/guzzle: ^6.2.1|^7.0
- swaggest/json-schema: ^0.12
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-20 08:27:30 UTC
README
一个用于集成SPS Commerce HTTP API和JSON Schema的PHP库。
安装
composer require shipstream/spscommerce-php-sdk
HTTP客户端使用
以下是一个发送REST API请求到SPS Commerce交易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对象使用
以下是将JSON字符串加载到适当的RSX类的代码示例。
<?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]));
开发
用于将数据类型映射到PHP对象的"RSX"类都是使用 json-cli 生成的。
如果需要,运行shell脚本 generate.sh
重新生成类。