Update readme file, Update composer.json file, Exception updates
Alle exceptions thrown in Response are now general AmazonError with json return string for full compability
This commit is contained in:
26
Readme.md
26
Readme.md
@@ -1,13 +1,19 @@
|
|||||||
# Amazon Incentives - Gift on Demand standa alone class
|
# Amazon Incentives - Gift Codes on Demand stand alone class
|
||||||
|
|
||||||
This is a abastract from (https://github.com/kamerk22/AmazonGiftCode) to be not dependend on Laravel base code.
|
This is a abastract from (https://github.com/kamerk22/AmazonGiftCode) to be not dependend on Laravel base code.
|
||||||
|
|
||||||
Uses .env file to load configuration data
|
Amazon Gift Codes On Demand (AGCOD). Integration for Amazon Incentive API.
|
||||||
|
|
||||||
|
## How to install
|
||||||
|
|
||||||
`composer request gullevek/amazon-incentives`
|
`composer request 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_KEY
|
||||||
* AWS_GIFT_CARD_SECRET
|
* AWS_GIFT_CARD_SECRET
|
||||||
* AWS_GIFT_CARD_PARTNER_ID
|
* AWS_GIFT_CARD_PARTNER_ID
|
||||||
@@ -74,6 +80,12 @@ 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 code is the curl handler error code.
|
||||||
The error message is json encoded array with the layout
|
The error message is json encoded array with the layout
|
||||||
|
|
||||||
|
Use
|
||||||
|
```php
|
||||||
|
$exception_array = gullevek\AmazonIncentives\AmazonIncentives::decodeExceptionMessage($exception_message);
|
||||||
|
```
|
||||||
|
to extract the below array from the thrown exception
|
||||||
```php
|
```php
|
||||||
[
|
[
|
||||||
'status' => 'AWS Status FAILURE or RESEND',
|
'status' => 'AWS Status FAILURE or RESEND',
|
||||||
@@ -87,9 +99,17 @@ The error message is json encoded array with the layout
|
|||||||
|
|
||||||
`status`, `code` and `type` must be checked on a failure.
|
`status`, `code` and `type` must be checked on a failure.
|
||||||
|
|
||||||
**NOTE**: if code is E999 then this is a request flood error:
|
**NOTE**: 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.
|
In this case the request has to be resend after a certain waiting period.
|
||||||
|
|
||||||
|
**NOTE**: if code is E999 some other critical error has happened
|
||||||
|
|
||||||
|
**NOTE**: if code is E001 if the return create/cancel/check calls is not an array
|
||||||
|
|
||||||
|
**NOTE**: if code is C001 a curl error has happened
|
||||||
|
|
||||||
|
**NOTE**: 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.
|
If AWS_DEBUG is set to 1 and internal array will be written with debug info.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "gullevek/amazon-incentives",
|
"name": "gullevek/amazon-incentives",
|
||||||
"description": "Amazon Gift on Demand Incentives",
|
"description": "Amazon Gift Codes, Gift on Demand, Incentives",
|
||||||
|
"keywords": ["AmazonGiftCode", "Amazon", "GiftCard", "AGCOD", "Incentives API", "Amazon Incentives API"],
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "help",
|
"license": "help",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@@ -11,9 +12,11 @@
|
|||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Clemens Schwaighofer",
|
"name": "Clemens Schwaighofer",
|
||||||
"email": "gullevek@gullevek.org"
|
"email": "gullevek@gullevek.org",
|
||||||
|
"homepage": "http://gullevek.org"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"homepage": "https://github.com/gullevek/AmazonIncentives",
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.4.0"
|
"php": ">=7.4.0"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace gullevek\AmazonIncentives\Response;
|
namespace gullevek\AmazonIncentives\Response;
|
||||||
|
|
||||||
|
use gullevek\AmazonIncentives\Exceptions\AmazonErrors;
|
||||||
use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
||||||
|
|
||||||
class CancelResponse
|
class CancelResponse
|
||||||
@@ -93,7 +94,13 @@ class CancelResponse
|
|||||||
public function parseJsonResponse(array $json_response): self
|
public function parseJsonResponse(array $json_response): self
|
||||||
{
|
{
|
||||||
if (!is_array($json_response)) {
|
if (!is_array($json_response)) {
|
||||||
throw new \RuntimeException('Response must be a scalar value');
|
throw AmazonErrors::getError(
|
||||||
|
'FAILURE',
|
||||||
|
'E001',
|
||||||
|
'NonScalarValue',
|
||||||
|
'Response must be a scalar value',
|
||||||
|
0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (array_key_exists('gcId', $json_response)) {
|
if (array_key_exists('gcId', $json_response)) {
|
||||||
$this->id = $json_response['gcId'];
|
$this->id = $json_response['gcId'];
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace gullevek\AmazonIncentives\Response;
|
namespace gullevek\AmazonIncentives\Response;
|
||||||
|
|
||||||
|
use gullevek\AmazonIncentives\Exceptions\AmazonErrors;
|
||||||
use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
||||||
|
|
||||||
class CreateBalanceResponse
|
class CreateBalanceResponse
|
||||||
@@ -110,7 +111,13 @@ class CreateBalanceResponse
|
|||||||
public function parseJsonResponse(array $json_response): self
|
public function parseJsonResponse(array $json_response): self
|
||||||
{
|
{
|
||||||
if (!is_array($json_response)) {
|
if (!is_array($json_response)) {
|
||||||
throw new \RuntimeException('Response must be a scalar value');
|
throw AmazonErrors::getError(
|
||||||
|
'FAILURE',
|
||||||
|
'E001',
|
||||||
|
'NonScalarValue',
|
||||||
|
'Response must be a scalar value',
|
||||||
|
0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (array_key_exists('amount', $json_response['availableFunds'])) {
|
if (array_key_exists('amount', $json_response['availableFunds'])) {
|
||||||
$this->amount = $json_response['availableFunds']['amount'];
|
$this->amount = $json_response['availableFunds']['amount'];
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace gullevek\AmazonIncentives\Response;
|
namespace gullevek\AmazonIncentives\Response;
|
||||||
|
|
||||||
|
use gullevek\AmazonIncentives\Exceptions\AmazonErrors;
|
||||||
use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
||||||
|
|
||||||
class CreateResponse
|
class CreateResponse
|
||||||
@@ -168,7 +169,13 @@ class CreateResponse
|
|||||||
public function parseJsonResponse(array $json_response): self
|
public function parseJsonResponse(array $json_response): self
|
||||||
{
|
{
|
||||||
if (!is_array($json_response)) {
|
if (!is_array($json_response)) {
|
||||||
throw new \RuntimeException('Response must be a scalar value');
|
throw AmazonErrors::getError(
|
||||||
|
'FAILURE',
|
||||||
|
'E001',
|
||||||
|
'NonScalarValue',
|
||||||
|
'Response must be a scalar value',
|
||||||
|
0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (array_key_exists('gcId', $json_response)) {
|
if (array_key_exists('gcId', $json_response)) {
|
||||||
$this->id = $json_response['gcId'];
|
$this->id = $json_response['gcId'];
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ $run_info_test = false;
|
|||||||
// run test to get funds info
|
// run test to get funds info
|
||||||
$run_fund_test = true;
|
$run_fund_test = true;
|
||||||
// run the normal get/cancel gift card tests
|
// run the normal get/cancel gift card tests
|
||||||
$run_gift_tests = false;
|
$run_gift_tests = true;
|
||||||
// run mock error check tests
|
// run mock error check tests
|
||||||
$run_mocks = false;
|
$run_mocks = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user