incenteev/async-amazon-incentives

基于async-aws项目结构的Amazon Incentives API的SDK

v1.1.0 2024-05-03 12:29 UTC

This package is auto-updated.

Last update: 2024-09-03 13:24:42 UTC


README

此包为Amazon Incentives API提供了一个非官方的SDK。

安装

使用Composer安装库

$ composer require incenteev/async-amazon-incentives

使用方法

use AsyncAws\Core\Configuration;
use Incenteev\AsyncAmazonIncentives\AmazonIncentivesClient;
use Incenteev\AsyncAmazonIncentives\Enum\CurrencyCode;
use Incenteev\AsyncAmazonIncentives\Exception\SystemTemporarilyUnavailableException;
use Incenteev\AsyncAmazonIncentives\Region;
use Incenteev\AsyncAmazonIncentives\ValueObject\MoneyAmount;

// Get your credentials in the Amazon Incentives portal
$accessKey = '';
$secretKey = '';
$partnerId = '';

// Choose the region corresponding to your partnership, with either the sandbox or production one.
$region = Region::EUROPE_AND_ASIA_SANDBOX;

$client = new AmazonIncentivesClient([
    Configuration::OPTION_ACCESS_KEY_ID => $accessKey,
    Configuration::OPTION_SECRET_ACCESS_KEY => $secretKey,
    Configuration::OPTION_REGION => $region,
]);

try {
    $result = $client->createGiftCard([
        'partnerId' => $partnerId,
        'creationRequestId' => '', // Create the proper request id
        'value' => new MoneyAmount(['amount' => 10, 'currencyCode' => CurrencyCode::EUR]),
    ]);

    $code = $result->getGcClaimCode();
} catch (SystemTemporarilyUnavailableException $e) {
    // TODO handle temporary failures according to the Amazon Incentives best practices
}

注意:由于项目异步特性,异常并非在调用createGiftCard时抛出,而是在Result对象解析时抛出。

许可证

本包采用MIT许可证

报告问题或功能请求

问题和功能请求在GitHub问题跟踪器中跟踪。