定制 merch-one/php-api-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

merch-one/php-api-sdk

最新稳定版本:1.0.4

Composer 安装命令:

composer require merch-one/php-api-sdk

包简介

SDK for MerchOne API integration

README 文档

README

PHP SDK for MerchOne API integration

Packagist Version License Minimum PHP version GitHub last commit

This package provide a set of tools that allow developers to easily integrate with MerchOne API.

Installation

composer require merch-one/php-api-sdk

Overview

Introduction

Client provide 3 different API's to interact with.

  • Catalog API
  • Orders API
  • Shipping API

To get the list of available endpoints, please check MerchOne API Documentation

Basic Usage

Create an instance of MerchOne\PhpApiSdk\Http\Client

use MerchOne\PhpApiSdk\Http\Client;

class MyService
 {
    private Client $httpClient;
 
    public function __construct()
    {
        $this->httpClient = new Client();
    }
 
    public function doSomething(): void
     {
        // authenticate client using credentials
        $this->httpClient->auth(
            'your-store-user',
            'your-store-key'
        );
        
        // or authenticate client using base64 encoded credentials
        $this->httpClient->basicAuth(
            base64_encode('your-store-user:your-store-key'),
        );
        
        /* Interact with Catalog API */
        /** @var \MerchOne\PhpApiSdk\Contracts\Clients\CatalogApi $catalogApi */
        $catalogApi = $this->httpClient->catalog();
        
        /* Interact with Orders API */
        /** @var \MerchOne\PhpApiSdk\Contracts\Clients\OrdersApi $ordersApi */
        $ordersApi = $this->httpClient->orders();
        
        /* Interact with Shipping API */
        /** @var \MerchOne\PhpApiSdk\Contracts\Clients\ShippingApi $shippingApi */
        $shippingApi = $this->httpClient->shipping();
        
        // switch API version you interact with
        $this->httpClient->setVersion($version);
        
        // get current API version
        $this->httpClient->getVersion();
    }
}
  • The Client class accepts two parameters:
    • $version - API version to interact with. Default value is beta.
      • See Helpers for available versions.
    • $clientOptions - Custom options to use with request.
      • See Guzzle Documentation for available options.
      • The User-Agent, Accept and Content-Type headers, as well as http_error properties CAN NOT be overwritten !

Helpers

use MerchOne\PhpApiSdk\Util\MerchOneApi;

// get the list of all available API versions
MerchOneApi::getVersions();
  • Class MerchOne\PhpSdk\Util\OrderStatus provides a full list of Order statuses.

Check more in MerchOne API Documentation

Exceptions

The package can throw the following exceptions:

Exception Reason
MerchOneApiClientException Request is not correct or validation did not pass.
MerchOneApiServerException A server error occurred.
InvalidApiVersionException An invalid API version was provided to the Client.
InvalidCredentialsException Invalid API credentials was provided to the Client.

Tests

Package comes with a set of tests to ensure that everything works as expected. To run tests, execute the following command:

./vendor/bin/phpunit

统计信息

  • 总下载量: 139
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-04