Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 422fc66137 | |||
| 308794488d |
11
Readme.md
11
Readme.md
@@ -1,9 +1,11 @@
|
|||||||
# 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/AmazonGiftCode) to be not dependend on Laravel base code.
|
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.
|
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`
|
`composer require gullevek/amazon-incentives`
|
||||||
@@ -82,10 +84,13 @@ 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
|
Use
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$exception_array = gullevek\AmazonIncentives\AmazonIncentives::decodeExceptionMessage($exception_message);
|
$exception_array = gullevek\AmazonIncentives\AmazonIncentives::decodeExceptionMessage($exception_message);
|
||||||
```
|
```
|
||||||
|
|
||||||
to extract the below array from the thrown exception
|
to extract the below array from the thrown exception
|
||||||
|
|
||||||
```php
|
```php
|
||||||
[
|
[
|
||||||
'status' => 'AWS Status FAILURE or RESEND',
|
'status' => 'AWS Status FAILURE or RESEND',
|
||||||
@@ -106,7 +111,7 @@ to extract the below array from the thrown exception
|
|||||||
if code is T001 then this is a request flood error:
|
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.
|
||||||
|
|
||||||
### E9999
|
### E999
|
||||||
|
|
||||||
if code is E999 some other critical error has happened
|
if code is E999 some other critical error has happened
|
||||||
|
|
||||||
@@ -117,6 +122,7 @@ 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
|
fif code is C001 curl failed to init
|
||||||
|
|
||||||
### C002
|
### C002
|
||||||
|
|
||||||
if code is C002 a curl error has happened
|
if code is C002 a curl error has happened
|
||||||
@@ -132,6 +138,7 @@ 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.
|
The gulleek\AmazonIncentives\Debug\AmazonDebug class handles all this.
|
||||||
|
|
||||||
In the gulleek\AmazonIncentives\AmazonIncentives main class the debugger gets set
|
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)
|
* setDebug that turns debugger on/off and if on sets unique id (getId to check)
|
||||||
|
|
||||||
New entries can be written with
|
New entries can be written with
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ final class AmazonIncentivesTest extends TestCase
|
|||||||
'Assert creation request id starts with partner id'
|
'Assert creation request id starts with partner id'
|
||||||
);
|
);
|
||||||
// gift card id is number
|
// gift card id is number
|
||||||
$this->assertIsNumeric(
|
$this->assertIsString(
|
||||||
$response->getId(),
|
$response->getId(),
|
||||||
'Assert gift card id is numeric'
|
'Assert gift card id is numeric'
|
||||||
);
|
);
|
||||||
@@ -487,8 +487,31 @@ final class AmazonIncentivesTest extends TestCase
|
|||||||
$response->getClaimCode(),
|
$response->getClaimCode(),
|
||||||
'Assert claim code is string'
|
'Assert claim code is string'
|
||||||
);
|
);
|
||||||
|
// card status
|
||||||
|
$this->assertEquals(
|
||||||
|
'Fulfilled',
|
||||||
|
$response->getCardStatus(),
|
||||||
|
'Assert card status'
|
||||||
|
);
|
||||||
|
// value/amount of gitft
|
||||||
|
$this->assertEquals(
|
||||||
|
$amount,
|
||||||
|
$response->getValue(),
|
||||||
|
'Assert card amount value'
|
||||||
|
);
|
||||||
|
// check currency
|
||||||
|
$this->assertEquals(
|
||||||
|
$agcod->checkMe()['CONFIG']->getCurrency(),
|
||||||
|
$response->getCurrency(),
|
||||||
|
'Assert card amount currency'
|
||||||
|
);
|
||||||
// only for requests outside US/Australia cards
|
// only for requests outside US/Australia cards
|
||||||
// expiration date: Thu Jun 10 14:59:59 UTC 2032
|
// expiration date: Thu Jun 10 14:59:59 UTC 2032
|
||||||
|
$this->assertMatchesRegularExpression(
|
||||||
|
"/^[A-Z]{1}[a-z]{2} [A-Z]{1}[a-z]{2} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} [A-Z]{3} \d{4}$/",
|
||||||
|
$response->getExpirationDate(),
|
||||||
|
'Assert expiration date regex'
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// value match to mock response
|
// value match to mock response
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@@ -496,6 +519,21 @@ final class AmazonIncentivesTest extends TestCase
|
|||||||
$response->getStatus(),
|
$response->getStatus(),
|
||||||
'Assert mock status'
|
'Assert mock status'
|
||||||
);
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$mock_response['cardInfo']['cardStatus'],
|
||||||
|
$response->getCardStatus(),
|
||||||
|
'Assert mock card status'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$mock_response['cardInfo']['value']['amount'],
|
||||||
|
$response->getValue(),
|
||||||
|
'Assert mock card amount value'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$mock_response['cardInfo']['value']['currencyCode'],
|
||||||
|
$response->getCurrency(),
|
||||||
|
'Assert mock card amount currency'
|
||||||
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$mock_response['creationRequestId'],
|
$mock_response['creationRequestId'],
|
||||||
$response->getCreationRequestId(),
|
$response->getCreationRequestId(),
|
||||||
@@ -555,6 +593,21 @@ final class AmazonIncentivesTest extends TestCase
|
|||||||
$response_b->getStatus(),
|
$response_b->getStatus(),
|
||||||
'Assert status'
|
'Assert status'
|
||||||
);
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$response_a->getCardStatus(),
|
||||||
|
$response_b->getCardStatus(),
|
||||||
|
'Assert card status'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$response_a->getValue(),
|
||||||
|
$response_b->getValue(),
|
||||||
|
'Assert card amount value'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$response_a->getCurrency(),
|
||||||
|
$response_b->getCurrency(),
|
||||||
|
'Assert card amount currency'
|
||||||
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$response_a->getCreationRequestId(),
|
$response_a->getCreationRequestId(),
|
||||||
$response_b->getCreationRequestId(),
|
$response_b->getCreationRequestId(),
|
||||||
@@ -609,7 +662,7 @@ final class AmazonIncentivesTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Cancel a bought gift card
|
||||||
*
|
*
|
||||||
* @dataProvider amazonIncentivesProviderCancel
|
* @dataProvider amazonIncentivesProviderCancel
|
||||||
* @testdox AWS Incentives cancel gift card [$_dataName]
|
* @testdox AWS Incentives cancel gift card [$_dataName]
|
||||||
@@ -651,7 +704,7 @@ final class AmazonIncentivesTest extends TestCase
|
|||||||
'Assert creation request id starts with partner id'
|
'Assert creation request id starts with partner id'
|
||||||
);
|
);
|
||||||
// gift card id is number
|
// gift card id is number
|
||||||
$this->assertIsNumeric(
|
$this->assertIsString(
|
||||||
$response->getId(),
|
$response->getId(),
|
||||||
'Assert gift card id is numeric'
|
'Assert gift card id is numeric'
|
||||||
);
|
);
|
||||||
@@ -678,6 +731,96 @@ final class AmazonIncentivesTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function amazonIncentivesProviderRefunded(): array
|
||||||
|
{
|
||||||
|
// get connectors
|
||||||
|
$connectors = $this->awsIncentivesProvider();
|
||||||
|
// 0: connect array (env file, env folder, parameters array)
|
||||||
|
// 1: mock or normal call
|
||||||
|
// 2: if mock connect response must be defined here
|
||||||
|
// 3: exepcted response array
|
||||||
|
return [
|
||||||
|
'non mock test data' => [
|
||||||
|
'connect' => $connectors['env_test'],
|
||||||
|
'mock' => false,
|
||||||
|
'mock_response' => null,
|
||||||
|
],
|
||||||
|
'mock data test' => [
|
||||||
|
'connect' => $connectors['parameter_dummy'],
|
||||||
|
'mock' => true,
|
||||||
|
'mock_response' => [
|
||||||
|
'cardInfo' => [
|
||||||
|
'cardNumber' => null,
|
||||||
|
'cardStatus' => 'RefundedToPurchaser',
|
||||||
|
'expirationDate' => null,
|
||||||
|
'value' => [
|
||||||
|
'amount' => 1000.0,
|
||||||
|
'currencyCode' => 'JPY',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'gcClaimCode' => 'LJ49-AKDUV6-UYCP',
|
||||||
|
'creationRequestId' => 'PartnerId_62a309167e7a4',
|
||||||
|
'gcId' => '5535125272070255',
|
||||||
|
'status' => 'SUCCESS',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @dataProvider amazonIncentivesProviderRefunded
|
||||||
|
* @testdox AWS Incentives request cancled gift card [$_dataName]
|
||||||
|
*
|
||||||
|
* @param array $connect
|
||||||
|
* @param bool $mock
|
||||||
|
* @param array|null $mock_response
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testAwsIncentivesRequestRefundedGiftCard(
|
||||||
|
array $connect,
|
||||||
|
bool $mock,
|
||||||
|
?array $mock_response
|
||||||
|
): void {
|
||||||
|
// load class
|
||||||
|
$agcod = $this->awsIncentivesStartUp(
|
||||||
|
$connect,
|
||||||
|
$mock,
|
||||||
|
$mock_response,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($mock === false) {
|
||||||
|
// get a gift card
|
||||||
|
$purchase = $agcod->buyGiftCard(500.0);
|
||||||
|
// then cancel it
|
||||||
|
$agcod->cancelGiftCard(
|
||||||
|
$purchase->getCreationRequestId(),
|
||||||
|
$purchase->getId()
|
||||||
|
);
|
||||||
|
// buy again with same getCreationRequestId id will now have
|
||||||
|
$purchase_again = $agcod->buyGiftCard(500.0, $purchase->getCreationRequestId());
|
||||||
|
// should return like purchase put with RefundedToPurchaser
|
||||||
|
$this->assertEquals(
|
||||||
|
'RefundedToPurchaser',
|
||||||
|
$purchase_again->getCardStatus(),
|
||||||
|
'Assert gift card purchased again after cancel with same code'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$response = $agcod->buyGiftCard(500.0);
|
||||||
|
$this->assertEquals(
|
||||||
|
$mock_response['cardInfo']['cardStatus'],
|
||||||
|
$response->getCardStatus(),
|
||||||
|
'Assert mock card status'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list of AWS mock codes for AWS side mock testing
|
* list of AWS mock codes for AWS side mock testing
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user