gullevek/amazon-incentives

亚马逊礼品卡,即时礼品,奖励

v1.2.5 2023-01-19 03:51 UTC

This package is auto-updated.

Last update: 2024-09-21 02:43:07 UTC


README

这是从 https://github.com/kamerk22/AmazonGiftCod 的摘要,以不依赖于Laravel基础代码。

亚马逊礼品卡即时(AGCOD)。亚马逊激励API集成。

一般亚马逊激励文档

如何安装

composer require gullevek/amazon-incentives

需要的环境变量

使用 .env 文件加载配置数据

以下键将在 _ENV 文件中搜索以加载

  • AWS_GIFT_CARD_KEY
  • AWS_GIFT_CARD_SECRET
  • AWS_GIFT_CARD_PARTNER_ID
  • AWS_GIFT_CARD_ENDPOINT
  • AWS_GIFT_CARD_CURRENCY
  • AWS_DEBUG (1/0)

如何使用

上述环境变量必须设置(AWS_DEBUG除外,默认为关闭)。

创建礼品卡

use gullevek\AmazonIncentives\AmazonIncentives;
// buy a gift card with a value
$value = 500;
$aws_gc = AmazonIncentives::make()->buyGiftCard((float)$value);
// the two below are need if we want to cancel the card
// get gift card id (gcID)
$aws_gc->getId();
// get creation request id (creationRequestId)
$aws_gc->getCreationRequestId();
// the one below must be printed to the user
$aws_gc->getClaimCode();
// check status (SUCCESS/RESEND/FAILURE)
$aws_gc->getStatus();
// others:
// getAmount, getCurrency

节流速率

请注意,您每秒只能发送10个请求。在节流异常情况下,您需要等待约10秒才能创建另一个请求。

建议池化请求。或者检查上次请求发送的时间,然后处理它们。

在F400错误时

  1. 重试
  2. 如果失败,运行取消礼品卡
  3. 如果取消成功,尝试用不同的请求ID再次创建
  4. 如果2)失败,等待几秒钟后重试
  5. 如果10秒过去,我们需要等待整整一天
  6. 如果>24小时,请联系亚马逊

取消礼品卡

// use getCreationRequestId() and getId() from request
$aws_gc = gullevek\AmazonIncentives\AmazonIncentives::make()->cancelGiftCard($creation_request_id, $gift_card_id);
// return is as above

检查余额

$aws_gc = gullevek\AmazonIncentives\AmazonIncentives::make()->getAvailableFunds();

异常

如果HTTPS请求没有返回220 OK,将抛出异常。

错误代码是curl处理程序错误代码。错误信息是json编码的数组,格式如下

使用

$exception_array = gullevek\AmazonIncentives\AmazonIncentives::decodeExceptionMessage($exception_message);

从抛出的异常中提取以下数组

[
    'status' => 'AWS Status FAILURE or RESEND',
    'code' => 'AWS Error Code Fnnn',
    'type' => 'AWS Error info',
    'message' => 'AWS long error message',
    'log_id' => 'If logging is on the current log id',
    'log' => 'The complete log collected over all calls',
]

在失败时必须检查statuscodetype

来自异常的其他错误

T001

如果代码是T001,那么这是一个请求洪水错误:在这种情况下,请求必须在一定等待期后重新发送。

E999

如果代码是E999,则发生了某些其他关键错误

E001

如果代码是E001,如果返回的创建/取消/检查调用不是数组

C001

如果代码是C001,curl初始化失败

C002

如果代码是C002,发生了curl错误

空错误代码

任何其他非亚马逊错误将通过解码仅设置'message'。

调试

如果AWS_DEBUG设置为1,则将内部数组写入调试信息。

gulleek\AmazonIncentives\Debug\AmazonDebug类处理所有这些。

在gulleek\AmazonIncentives\AmazonIncentives主类中设置调试器

  • setDebug打开/关闭调试器,如果开启,则设置唯一ID(getId检查)

可以使用以下方法写入新条目

AmazonDebug::writeLog(['foo' => 'bar']);

在成功运行后,日志数据可通过$aws->getLog()访问。在异常情况下,日志数据在错误信息的json中(请参阅异常)