PHPackages                             gullevek/amazon-incentives - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. gullevek/amazon-incentives

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

gullevek/amazon-incentives
==========================

Amazon Gift Codes, Gift on Demand, Incentives

v1.3.1(4mo ago)512.6k↓25%3MITPHPPHP &gt;=7.4.0CI passing

Since Oct 21Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/gullevek/AmazonIncentives)[ Packagist](https://packagist.org/packages/gullevek/amazon-incentives)[ Docs](https://github.com/gullevek/AmazonIncentives)[ RSS](/packages/gullevek-amazon-incentives/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (18)Used By (0)

Amazon Incentives - Gift Codes on Demand stand alone class
==========================================================

[](#amazon-incentives---gift-codes-on-demand-stand-alone-class)

This is a abastract from [https://github.com/kamerk22/AmazonGiftCod](https://github.com/kamerk22/AmazonGiftCode) to be not dependend on Laravel base code.

Amazon Gift Codes On Demand (AGCOD). Integration for Amazon Incentive API.

[General Amazon Incentives Documentation](https://developer.amazon.com/docs/incentives-api/digital-gift-cards.html)

How to install
--------------

[](#how-to-install)

`composer require gullevek/amazon-incentives`

\_ENV variables needed
----------------------

[](#_env-variables-needed)

Uses .env file to load configuration data

The below keys are searched in the \_ENV file for loading

- 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)

How to use
----------

[](#how-to-use)

The above \_ENV variables must be set (Except AWS\_DEBUG, defaults to off).

### create gift card

[](#create-gift-card)

```
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
```

#### Throttle Rates

[](#throttle-rates)

Note that you can only send 10 requests per second. On a Throttle Excepion you need to wait about 10s to create another request.

Recommended to pool requests. Or check when last requests where sent and then process them.

#### On F400 errors

[](#on-f400-errors)

1. try again
2. if failed run cancel gift card
3. if cance ok try create again with different request id
4. if 2) failed, wait a view seconds and try again
5. if 10s elapse, we need to wait a full day
6. if &gt;24h call Amazon

### cancel gift card

[](#cancel-gift-card)

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

### check balance

[](#check-balance)

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

Exceptions
----------

[](#exceptions)

If the HTTPS request does not return 220 OK it will throw an exception.

The error code is the curl handler error code. The error message is json encoded array with the layout

Use

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

to extract the below array from the thrown exception

```
[
    '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',
]
```

`status`, `code` and `type` must be checked on a failure.

Other Errors from exceptions
----------------------------

[](#other-errors-from-exceptions)

### T001

[](#t001)

if code is T001 then this is a request flood error: In this case the request has to be resend after a certain waiting period.

### E999

[](#e999)

if code is E999 some other critical error has happened

### E001

[](#e001)

if code is E001 if the return create/cancel/check calls is not an array

### C001

[](#c001)

fif code is C001 curl failed to init

### C002

[](#c002)

if code is C002 a curl error has happened

### J-number

[](#j-number)

if a JSON error was encountered during some encoding this error will be found. The number is the json error code.

### empty error code

[](#empty-error-code)

any other NON amazon error will have only 'message' set if run through decode

Debugging
---------

[](#debugging)

If AWS\_DEBUG is set to 1 and internal array will be written with debug info.

The gulleek\\AmazonIncentives\\Debug\\AmazonDebug class handles all this.

In the gulleek\\AmazonIncentives\\AmazonIncentives main class the debugger gets set

- setDebug that turns debugger on/off and if on sets unique id (getId to check)

New entries can be written with

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

On sucessful run the log data is accessable with `$aws->getLog()`On exception the log data is in the error message json (see exceptions)

Development
-----------

[](#development)

Run `composer install` or `phive install` to setup the tools

phpcs config is stored in `phpcs.xml` and should be picked up by the standard tools

- we use tabs instead of spaces for indents, the rest is standard PSR1+PSR12

### Direct tests

[](#direct-tests)

These direct run tests exist:

- `tests/aws_read_env_tests.php`: Equal to running `tests/aws_gift_card_tests.php?info=true`, will output env test data
- `test/aws_gift_card_tests.php`: The following parameters exists
    - info: set to print out info
    - fund: set to run funds get tests
    - gift: run all the gift card get/set/remove tests
    - mocks: run the error checks
    - debug: print out debug information
    - debug\_mock: print out all the debug logs too

### Phan

[](#phan)

`vendor/bin/phan --analyze-twice` or `tools/phan --analyze-twice`

### PHPstan

[](#phpstan)

`vendor/bin/phpstan` or `tools/phpstan`

> \[!notice\] Level 9 is set as we have various mixed values that cannot be easily changed into a direct value type

### PHPUnit

[](#phpunit)

Unit tests have to be run from base folder with

`vendor/bin/phpunit` or `tools/phpunit`

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance77

Regular maintenance activity

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~103 days

Recently: every ~311 days

Total

16

Last Release

125d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cfbe4e76259d200068a2bddced07a1b88e377c7d81f80898fbe5b8077e6bf3c?d=identicon)[gullevek](/maintainers/gullevek)

---

Top Contributors

[![arif-rh](https://avatars.githubusercontent.com/u/2386359?v=4)](https://github.com/arif-rh "arif-rh (2 commits)")[![gullevek](https://avatars.githubusercontent.com/u/855861?v=4)](https://github.com/gullevek "gullevek (2 commits)")[![kapierstau](https://avatars.githubusercontent.com/u/111429935?v=4)](https://github.com/kapierstau "kapierstau (1 commits)")

---

Tags

amazongiftcardAmazonGiftCodeAGCODIncentives APIAmazon Incentives API

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gullevek-amazon-incentives/health.svg)

```
[![Health](https://phpackages.com/badges/gullevek-amazon-incentives/health.svg)](https://phpackages.com/packages/gullevek-amazon-incentives)
```

###  Alternatives

[kamerk22/amazongiftcode

Laravel Package for Amazon Gift Codes.

46140.3k](/packages/kamerk22-amazongiftcode)[aws/aws-crt-php

AWS Common Runtime for PHP

420300.1M4](/packages/aws-aws-crt-php)[aws/aws-sdk-php-symfony

A Symfony bundle for v3 of the AWS SDK for PHP

36517.7M22](/packages/aws-aws-sdk-php-symfony)[async-aws/async-aws-bundle

Configure all your AsyncAws services and enjoy the autowire greatness.

243.6M2](/packages/async-aws-async-aws-bundle)[amazon/instantaccess-sdk-php

Amazon Instant Access SDK for PHP

1432.8k](/packages/amazon-instantaccess-sdk-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
