sapientpro / ebay-account-sdk-php

v1.0.0 2023-06-27 14:50 UTC

This package is not auto-updated.

Last update: 2024-09-23 16:53:52 UTC


README

账户 API 使卖家能够配置他们的 eBay 卖家账户,包括卖家的政策(eBay 商业政策和卖家定义的自定义政策)、选择加入或退出 eBay 卖家计划、配置销售税表和获取账户信息。

关于此 API 中方法可用性的详细信息,请参阅 <a href="/api-docs/sell/account/overview.html#requirements">账户 API 要求和限制。

此 PHP 包由 Swagger Codegen 项目自动生成

  • API 版本:v1.9.0
  • 打包构建:io.swagger.codegen.v3.generators.php.PhpClientCodegen

要求

  • PHP 8.1 或更高版本
  • 启用 ext-json 和 ext-curl 扩展

安装和用法

使用 composer 安装此包

composer require sapientpro/ebay-account-sdk-php

示例用法

请遵循 安装程序,然后运行以下命令

<?php
use SapientPro\EbayAccountSDK\Configuration;
use SapientPro\EbayAccountSDK\Api\CustomPolicyApi;
use SapientPro\EbayAccountSDK\Models\CustomPolicyCreateRequest;
use SapientPro\EbayAccountSDK\Enums\MarketplaceIdEnum;
use SapientPro\EbayAccountSDK\Enums\CustomPolicyTypeEnum;

// Configure OAuth2 access token for authorization: api_auth
$config = Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');

$apiInstance = new CustomPolicyApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    ebayClient:  GuzzleHttp\Client(),
    config: $config
);

// you can create and fill a Model class that implements EbayModelInterface using fromArray() method
// exception will be thrown if a property does not exist in the model class
$body = CustomPolicyCreateRequest::fromArray([
'description' => 'description_example',
'name' => 'name_example',
'label' => 'label_example',
'custom_policy_type_enum' => CustomPolicyTypeEnum::PRODUCT_COMPLIANCE,
]);

try {
    $result = $apiInstance->createCustomPolicy($body, MarketplaceIdEnum::EBAY_US);
    print_r($result);
// there is also a custom ApiException for non 2xx responses
} catch (Exception $e) {
    echo 'Exception when calling CustomPolicyApi->createCustomPolicy: ', $e->getMessage(), PHP_EOL;
}

创建模型

一些 SDK 方法需要 $body 变量作为参数。它指的是实现了 EbayModelInterface 的模型类。有几种方法可以创建模型类

fromArray()

您可以使用 fromArray() 方法创建模型类。如果模型类中不存在该属性,则会抛出异常。

如果模型具有实现了 EbayModelInterface 的类型的属性,则必须使用 fromArray() 方法创建该类的实例。在此示例中,price 属性的类型为 ConvertedAmount,也实现了 EbayModelInterface。

Item::fromArray([
    'price' => ConvertedAmount::fromArray([
        'value' => '6.90',
        'currency' => CurrencyCodeEnum::USD
    )]
])

fromPlainArray()

也可以从普通关联数组创建模型。前面的示例可以重写如下

Item::fromPlainArray([
    'price' => [
        'value' => '6.90',
        'currency' => CurrencyCodeEnum::USD
    ]
])

fromJson()

也可以从 JSON 字符串创建模型。

Item::fromJson('{"price": {"value": "6.90", "currency": "USD"}}')

API 端点文档

所有 URI 都是相对于 https://api.ebay.com/sell/account/v1

模型文档

授权文档

api_auth

作者

Swagger Codegen 团队SapientPro