github-bishwajeet / ls-retail-guzzle
用于 Lightspeed Retail 的 Guzzle HTTP 客户端扩展。
v2.3.4
2023-03-03 07:30 UTC
Requires
- php: >=5.6
- guzzlehttp/guzzle: ~6.0
This package is auto-updated.
Last update: 2024-09-14 10:56:03 UTC
README
该类是 Guzzle 6 PHP HTTP 客户端的扩展,用于与 Lightspeed Retail API 一起使用。
它的工作方式与标准 Guzzle 客户端相同,但负责刷新访问令牌和速率限制。
此包是为演示目的创建的,不提供任何保证。
安装
使用此命令使用 Composer 安装
$ composer require github-bishwajeet/ls-retail-guzzle
或者,您可以将以下行添加到您的 composer.json
文件中
"require": { "github-bishwajeet/ls-retail-guzzle": "2.*" }
使用示例
<?php require 'vendor/autoload.php'; use LightspeedHQ\Retail\RetailClient; // Replace these with your own values for testing. // API tokens and client credentials should not be stored in your code! $account_id = XXXXX; $refresh_token = '****'; $client_id = '****'; $client_secret = '****'; $client = new RetailClient($account_id, $refresh_token, $client_id, $client_secret); // GET request with some URL paramters. We'll get the first ItemShop // from this item and dump it. $query = [ 'load_relations' => '["ItemShops"]', 'description' => '~,%test%', 'limit' => 1 ]; $response = $client->get('Item', ['query' => $query]); $items = json_decode($response->getBody(), true)['Item']; echo '<h3>GET Test</h3>'; echo '<pre>'; var_dump($items['ItemShops']['ItemShop'][0]) echo '</pre>' // POST request to create an Item $payload = [ 'description' => 'Rest Test', 'Prices' => [ 'ItemPrice' => [ 'amount' => 100, 'useType' => 'Default' ] ] ]; $response = $client->post('Item', ['json' => $payload]); echo '<h3>POST Test</h3>'; echo '<pre>'; var_dump(json_decode($response->getBody(), true)); echo '</pre>';