lightspeedhq/ls-retail-guzzle

LightSpeed Retail 的 Guzzle HTTP 客户端扩展。

v1.0 2017-09-29 17:17 UTC

This package is auto-updated.

Last update: 2024-09-29 05:01:29 UTC


README

该类是 Guzzle 6 PHP HTTP 客户端的扩展,用于与 LightSpeed Retail API 一起使用。

它的工作方式与标准 Guzzle 客户端相同,但会处理刷新访问令牌和速率限制。

此软件包是为演示目的创建的,不提供任何保证。

安装

使用以下命令使用 Composer 安装

$ composer require lightspeedhq/ls-retail-guzzle:~1.0

或者,您可以添加以下行到您的 composer.json 文件中

    "require": {
        "lightspeedhq/ls-retail-guzzle": "~1.0"
    }

使用示例

<?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>';