sapientpro/ebay-account-sdk-php

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

This package is not auto-updated.

Last update: 2024-11-18 17:33:38 UTC


README

The Account API gives sellers the ability to configure their eBay seller accounts, including the seller's policies (eBay business policies and seller-defined custom policies), opt in and out of eBay seller programs, configure sales tax tables, and get account information.

For details on the availability of the methods in this API, see <a href="/api-docs/sell/account/overview.html#requirements">Account API requirements and restrictions.

This PHP package is automatically generated by the Swagger Codegen project:

  • API version: v1.9.0
  • Build package: io.swagger.codegen.v3.generators.php.PhpClientCodegen

Requirements

  • PHP 8.1 or later
  • ext-json and ext-curl extensions enabled

Installation & Usage

Install the package using composer:

composer require sapientpro/ebay-account-sdk-php

Example usage

Please follow the installation procedure and then run the following:

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

Creating Models

Some SDK methods require $body variable as a parameter. It refers to a Model class that implements EbayModelInterface. There are several ways to create a Model class:

fromArray()

You can create a Model class using fromArray() method. It will throw an exception if a property does not exist in the model class.

If the model has a property of type that implements EbayModelInterface, you must create an instance of that class using fromArray() method. In this example, the property price is of type ConvertedAmount that also implements EbayModelInterface.

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

fromPlainArray()

It is also possible to create a Model from plain associative array. The previous example can be rewritten as follows:

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

fromJson()

It is also possible to create a Model from JSON string.

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

Documentation for API Endpoints

All URIs are relative to https://api.ebay.com/sell/account/v1

Documentation For Models

Documentation For Authorization

api_auth

Author

Swagger Codegen team and SapientPro