setono/shipmondo-php-sdk

使用此PHP SDK消费Shipmondo API

v1.0.0-beta.3 2024-04-12 06:44 UTC

This package is auto-updated.

Last update: 2024-08-29 08:21:07 UTC


README

Latest Version Software License Build Status Code Coverage Mutation testing

在PHP中消费Shipmondo API

安装

composer require setono/shipmondo-php-sdk

使用

<?php

use Setono\Shipmondo\Client\Client;

require_once __DIR__ . '/../vendor/autoload.php';

$client = new Client('api_username', 'api_key');

$paymentGateways = $client
    ->paymentGateways()
    ->get()
;

foreach ($paymentGateways as $paymentGateway) {
    print_r($paymentGateway);
}

将输出某些内容

Setono\Shipmondo\Response\PaymentGateways\PaymentGateway Object
(
    [id] => 1234
    [name] => quickpay
    [provider] => quick_pay
    [merchantNumber] => 67894321
)

生产使用

内部,此库使用CuyZ/Valinor库,该库特别适合将API响应转换为DTO。然而,此库有一些开销,并且启用缓存时表现最佳。

当你实例化Client时,使用设置缓存的机会

<?php

use CuyZ\Valinor\Cache\FileSystemCache;
use Setono\Shipmondo\Client\Client;

require_once '../vendor/autoload.php';

$cache = new FileSystemCache('path/to/cache-directory');
$client = new Client('API_USERNAME', 'API_KEY');
$client->getMapperBuilder()->withCache($cache);

您可以在此处了解更多信息:Valinor: 性能和缓存