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:
2021-10-21 10:22:17 +09:00
parent 6f9bf781f2
commit 6cc4f03cd4
6 changed files with 53 additions and 9 deletions

View File

@@ -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.
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`
## _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
@@ -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 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
[
'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.
**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.
**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
If AWS_DEBUG is set to 1 and internal array will be written with debug info.

View File

@@ -1,6 +1,7 @@
{
"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",
"license": "help",
"autoload": {
@@ -11,9 +12,11 @@
"authors": [
{
"name": "Clemens Schwaighofer",
"email": "gullevek@gullevek.org"
"email": "gullevek@gullevek.org",
"homepage": "http://gullevek.org"
}
],
"homepage": "https://github.com/gullevek/AmazonIncentives",
"minimum-stability": "dev",
"require": {
"php": ">=7.4.0"

View File

@@ -2,6 +2,7 @@
namespace gullevek\AmazonIncentives\Response;
use gullevek\AmazonIncentives\Exceptions\AmazonErrors;
use gullevek\AmazonIncentives\Debug\AmazonDebug;
class CancelResponse
@@ -93,7 +94,13 @@ class CancelResponse
public function parseJsonResponse(array $json_response): self
{
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)) {
$this->id = $json_response['gcId'];

View File

@@ -2,6 +2,7 @@
namespace gullevek\AmazonIncentives\Response;
use gullevek\AmazonIncentives\Exceptions\AmazonErrors;
use gullevek\AmazonIncentives\Debug\AmazonDebug;
class CreateBalanceResponse
@@ -110,7 +111,13 @@ class CreateBalanceResponse
public function parseJsonResponse(array $json_response): self
{
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'])) {
$this->amount = $json_response['availableFunds']['amount'];

View File

@@ -2,6 +2,7 @@
namespace gullevek\AmazonIncentives\Response;
use gullevek\AmazonIncentives\Exceptions\AmazonErrors;
use gullevek\AmazonIncentives\Debug\AmazonDebug;
class CreateResponse
@@ -168,7 +169,13 @@ class CreateResponse
public function parseJsonResponse(array $json_response): self
{
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)) {
$this->id = $json_response['gcId'];

View File

@@ -99,7 +99,7 @@ $run_info_test = false;
// run test to get funds info
$run_fund_test = true;
// run the normal get/cancel gift card tests
$run_gift_tests = false;
$run_gift_tests = true;
// run mock error check tests
$run_mocks = false;