biano/star-php

此包的最新版本(1.0.0)没有提供许可信息。

1.0.0 2022-06-08 09:20 UTC

This package is auto-updated.

Last update: 2024-09-08 14:51:10 UTC


README

安装

使用 Composer 安装

composer require biano/star-php

需求

  • 此库使用 HTTPlug 进行 HTTP 客户端抽象。
  • 此库使用 HTTP Factories 来操作 HTTP 请求。

您需要安装这些抽象层的实现,才能使用此库。

创建订单

use Biano\Star\Item;
use Biano\Star\Order;
use DateTimeImmutable;

$items = [
    new Item('item-1', 1, 1230.50),
    new Item('item-2', 3, 234.90),
];
$order = new Order('order-123', 1935.20, 'CZK', 'user@your-eshop.com', new DateTimeImmutable('+1 week'), ...$items);

Biano\Star\Item 构造函数的签名如下: public function __construct(string $id, int $quantity, float $unitPrice, ?string $name = null, ?string $image = null);

  • $id 是您产品内部的 ID,您在产品数据源中将其发送给 Biano。
  • $quantity 是此订单中此产品的数量。
  • $unitPrice 是此产品每单位的价格。
  • $name 是一个可选参数,包含产品的名称。
  • $image 是一个可选的产品图片 URL。

Biano\Star\Order 构造函数的签名如下: public function __construct(string $id, float $price, string $currency, ?string $customerEmail, ?DateTimeImmutable $shippingDate, Biano\Star\Item ...$items)

  • $id 是您此订单的内部 ID。
  • $price 是此订单的总价。
  • $currency 是此订单的 ISO 4217 货币代码。
  • $customerEmail 是客户的电子邮件地址。此参数可以是 null,在这种情况下,Biano Star 不会跟踪订单。
  • $shippingDate 是此订单的预期发货日期。此参数可以是 null,在这种情况下,您应使用其他方法指定发货日期。有关更多信息,请参阅 Biano Star 手册。
  • $items 是订单项的数组。注意使用扩展运算符(...),因为此参数是可变参数。

向 Biano 发送订单

use Biano\Star\Project;
use Biano\Star\Star;
use Biano\Star\Version;

$star = new Star($httpClient, $requestFactory, $streamFactory); 
$response = $star->createPurchase(Project::cz(), Version::v1(), 'your-merchant-id', 'current-url', $order);

选择您电商平台的正确国家,提供版本参数(目前仅支持 v1),您的电商平台商家 ID,正在创建订单的页面的当前 URL(这通常是购物车的最后一步或支付网关返回的“感谢”页面),以及订单。

更新发货日期

此功能必须由 Biano 启用。首先联系您的 Biano 合作伙伴!

use Biano\Star\Project;
use Biano\Star\Star;

$star = new Star($httpClient, $requestFactory, $streamFactory);
$response = $star->updateShippingDate(Project::cz(), 'your-merchant-id', 'order-123', new DateTimeImmutable('2022-06-08'));

选择您电商平台的正确国家,提供您的电商平台商家 ID,订单 ID,以及新的发货日期。

您可以多次更新发货日期。