From 65d1151b80588afa841ffbcb58de29b8f26f369a Mon Sep 17 00:00:00 2001 From: Dave Morris Date: Sat, 25 Jan 2020 15:27:45 +0000 Subject: [PATCH 01/11] Laravel 6 support --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b04efed..ca2fb09 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "homepage": "https://github.com/kamerk22/amazongiftcode", "keywords": ["Laravel", "AmazonGiftCode", "Amazon", "GiftCard", "AGCOD", "Incentives API", "Amazon Incentives API"], "require": { - "illuminate/support": "~5" + "illuminate/support": "~5|^6.0" }, "require-dev": { "phpunit/phpunit": "~7.0", From c163396503b6e369f0f0536f483ef6fc3bce45d6 Mon Sep 17 00:00:00 2001 From: Dave Morris Date: Sun, 26 Jan 2020 12:51:52 +0000 Subject: [PATCH 02/11] Added Expiration date to response. --- src/Response/CreateResponse.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Response/CreateResponse.php b/src/Response/CreateResponse.php index b1f5e87..6b988d9 100644 --- a/src/Response/CreateResponse.php +++ b/src/Response/CreateResponse.php @@ -53,6 +53,12 @@ class CreateResponse * @var string */ protected $_status; + /** + * Amazon Gift Card Expiration Date + * + * @var string + */ + protected $_expiration_date; /** * Amazon Gift Card Raw JSON @@ -122,6 +128,14 @@ public function getStatus(): string return $this->_status; } + /** + * @return string + */ + public function getExpirationDate(): string + { + return $this->_expiration_date; + } + /** * @return string @@ -155,6 +169,9 @@ public function parseJsonResponse($jsonResponse): self if (array_key_exists('currencyCode', $jsonResponse['cardInfo']['value'])) { $this->_currency = $jsonResponse['cardInfo']['value']['currencyCode']; } + if (array_key_exists('gcExpirationDate', $jsonResponse)) { + $this->_expiration_date = $jsonResponse['gcExpirationDate']; + } return $this; From b92a04fa9e6638d40050e1d56552ef8e7aa914fc Mon Sep 17 00:00:00 2001 From: Dave Morris Date: Tue, 28 Jan 2020 09:39:33 +0000 Subject: [PATCH 03/11] Added Card status to output --- src/Response/CancelResponse.php | 18 ++++++++++++++++++ src/Response/CreateResponse.php | 18 +++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Response/CancelResponse.php b/src/Response/CancelResponse.php index b0d05d5..b5de688 100644 --- a/src/Response/CancelResponse.php +++ b/src/Response/CancelResponse.php @@ -34,6 +34,13 @@ class CancelResponse */ protected $_status; + /** + * Amazon Gift Card status + * + * @var string + */ + protected $_card_status; + /** * Amazon Gift Card Raw JSON * @@ -78,6 +85,14 @@ public function getStatus(): string return $this->_status; } + /** + * @return string + */ + public function getCardStatus(): string + { + return $this->_card_status; + } + /** * @return string @@ -103,6 +118,9 @@ public function parseJsonResponse($jsonResponse): self if (array_key_exists('creationRequestId', $jsonResponse)) { $this->_creation_request_id = $jsonResponse['creationRequestId']; } + if (array_key_exists('cardStatus', $jsonResponse['cardInfo'])) { + $this->_value = $jsonResponse['cardInfo']['cardStatus']; + } return $this; diff --git a/src/Response/CreateResponse.php b/src/Response/CreateResponse.php index 6b988d9..58d3510 100644 --- a/src/Response/CreateResponse.php +++ b/src/Response/CreateResponse.php @@ -59,7 +59,12 @@ class CreateResponse * @var string */ protected $_expiration_date; - + /** + * Amazon Gift Card Expiration Date + * + * @var string + */ + protected $_card_status; /** * Amazon Gift Card Raw JSON * @@ -136,6 +141,14 @@ public function getExpirationDate(): string return $this->_expiration_date; } + /** + * @return string + */ + public function getCardStatus(): string + { + return $this->_card_status; + } + /** * @return string @@ -172,6 +185,9 @@ public function parseJsonResponse($jsonResponse): self if (array_key_exists('gcExpirationDate', $jsonResponse)) { $this->_expiration_date = $jsonResponse['gcExpirationDate']; } + if (array_key_exists('cardStatus', $jsonResponse['cardInfo'])) { + $this->_value = $jsonResponse['cardInfo']['cardStatus']; + } return $this; From dc96ae05291387cb392c582762931b6c25e7dafe Mon Sep 17 00:00:00 2001 From: Dave Morris Date: Tue, 28 Jan 2020 09:50:52 +0000 Subject: [PATCH 04/11] Fixed _card_status --- src/Response/CreateResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Response/CreateResponse.php b/src/Response/CreateResponse.php index 58d3510..d3f8d79 100644 --- a/src/Response/CreateResponse.php +++ b/src/Response/CreateResponse.php @@ -186,7 +186,7 @@ public function parseJsonResponse($jsonResponse): self $this->_expiration_date = $jsonResponse['gcExpirationDate']; } if (array_key_exists('cardStatus', $jsonResponse['cardInfo'])) { - $this->_value = $jsonResponse['cardInfo']['cardStatus']; + $this->_card_status = $jsonResponse['cardInfo']['cardStatus']; } return $this; From fe201906ddc1964be65631ed4f1352bb3c66e850 Mon Sep 17 00:00:00 2001 From: Dave Morris Date: Tue, 28 Jan 2020 12:30:22 +0000 Subject: [PATCH 05/11] Can't received Card Status on cancellations --- src/Response/CancelResponse.php | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/Response/CancelResponse.php b/src/Response/CancelResponse.php index b5de688..b0d05d5 100644 --- a/src/Response/CancelResponse.php +++ b/src/Response/CancelResponse.php @@ -34,13 +34,6 @@ class CancelResponse */ protected $_status; - /** - * Amazon Gift Card status - * - * @var string - */ - protected $_card_status; - /** * Amazon Gift Card Raw JSON * @@ -85,14 +78,6 @@ public function getStatus(): string return $this->_status; } - /** - * @return string - */ - public function getCardStatus(): string - { - return $this->_card_status; - } - /** * @return string @@ -118,9 +103,6 @@ public function parseJsonResponse($jsonResponse): self if (array_key_exists('creationRequestId', $jsonResponse)) { $this->_creation_request_id = $jsonResponse['creationRequestId']; } - if (array_key_exists('cardStatus', $jsonResponse['cardInfo'])) { - $this->_value = $jsonResponse['cardInfo']['cardStatus']; - } return $this; From 51037e12ae52cd05f1de1f5e4fc2f1c7fdbb7fe6 Mon Sep 17 00:00:00 2001 From: Dave Morris Date: Tue, 4 Feb 2020 13:13:46 +0000 Subject: [PATCH 06/11] Added retrieval of available balance --- src/AWS/AWS.php | 26 +++++ src/AmazonGiftCode.php | 9 ++ src/Response/CreateBalanceResponse.php | 125 +++++++++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 src/Response/CreateBalanceResponse.php diff --git a/src/AWS/AWS.php b/src/AWS/AWS.php index 32c78de..15c0e89 100644 --- a/src/AWS/AWS.php +++ b/src/AWS/AWS.php @@ -14,6 +14,7 @@ use kamerk22\AmazonGiftCode\Config\Config; use kamerk22\AmazonGiftCode\Exceptions\AmazonErrors; use kamerk22\AmazonGiftCode\Response\CancelResponse; +use kamerk22\AmazonGiftCode\Response\CreateBalanceResponse; use kamerk22\AmazonGiftCode\Response\CreateResponse; class AWS @@ -30,6 +31,7 @@ class AWS public const TERMINATION_STRING = 'aws4_request'; public const CREATE_GIFT_CARD_SERVICE = 'CreateGiftCard'; public const CANCEL_GIFT_CARD_SERVICE = 'CancelGiftCard'; + public const GET_AVAILABLE_FUNDS_SERVICE = 'GetAvailableFunds'; private $_config; @@ -76,6 +78,19 @@ public function cancelCode($creationRequestId, $gcId): CancelResponse return new CancelResponse($result); } + /** + * @return CreateBalanceResponse + */ + public function getBalance(): CreateBalanceResponse + { + $serviceOperation = self::GET_AVAILABLE_FUNDS_SERVICE; + $payload = $this->getAvailableFundsPayload(); + $canonicalRequest = $this->getCanonicalRequest($serviceOperation, $payload); + $dateTimeString = $this->getTimestamp(); + $result = json_decode($this->makeRequest($payload, $canonicalRequest, $serviceOperation, $dateTimeString), true); + return new CreateBalanceResponse($result); + } + /** * @param $payload * @param $canonicalRequest @@ -265,6 +280,17 @@ public function getCancelGiftCardPayload($creationRequestId, $gcId): string return json_encode($payload); } + /** + * @return string + */ + public function getAvailableFundsPayload(): string + { + $payload = [ + 'partnerId' => $this->_config->getPartner(), + ]; + return json_encode($payload); + } + /** * @param $serviceOperation * @param $payload diff --git a/src/AmazonGiftCode.php b/src/AmazonGiftCode.php index e9e3e59..b924c1b 100644 --- a/src/AmazonGiftCode.php +++ b/src/AmazonGiftCode.php @@ -47,6 +47,15 @@ public function cancelGiftCard(string $creationRequestId, string $gcId): Respons return (new AWS($this->_config))->cancelCode($creationRequestId, $gcId); } + /** + * @return Response\CreateBalanceResponse + * + * @throws AmazonErrors + */ + public function getAvailableFunds(): Response\CreateBalanceResponse + { + return (new AWS($this->_config))->getBalance(); + } /** * AmazonGiftCode make own client. diff --git a/src/Response/CreateBalanceResponse.php b/src/Response/CreateBalanceResponse.php new file mode 100644 index 0000000..70c287b --- /dev/null +++ b/src/Response/CreateBalanceResponse.php @@ -0,0 +1,125 @@ + + * + */ + + +namespace kamerk22\AmazonGiftCode\Response; + + +use Illuminate\Support\Facades\Log; + +class CreateBalanceResponse +{ + /** + * Amazon Gift Card Balance Amount + * + * @var string + */ + protected $_amount; + /** + * Amazon Gift Card Balance Currency + * + * @var string + */ + protected $_currency; + /** + * Amazon Gift Card Balance Status + * + * @var string + */ + protected $_status; + /** + * Amazon Gift Card Balance Timestamp + * + * @var string + */ + protected $_timestamp; + /** + * Amazon Gift Card Raw JSON + * + * @var string + */ + protected $_raw_json; + + /** + * Response constructor. + * @param $jsonResponse + */ + public function __construct($jsonResponse) + { + $this->_raw_json = $jsonResponse; + $this->_status = TRUE; + $this->parseJsonResponse($jsonResponse); + } + + /** + * @return string + */ + public function getAmount(): string + { + return $this->_amount; + } + + /** + * @return string + */ + public function getCurrency(): string + { + return $this->_currency; + } + + /** + * @return string + */ + public function getStatus(): string + { + return $this->_status; + } + + /** + * @return string + */ + public function getTimestamp(): string + { + return $this->_timestamp; + } + + /** + * @return string + */ + public function getRawJson(): string + { + return json_encode($this->_raw_json); + } + + /** + * @param $jsonResponse + * @return CreateBalanceResponse + */ + public function parseJsonResponse($jsonResponse): self + { + if (!is_array($jsonResponse)) { + throw new \RuntimeException('Response must be a scalar value'); + } + if (array_key_exists('amount', $jsonResponse['availableFunds'])) { + $this->_amount = $jsonResponse['availableFunds']['amount']; + } + if (array_key_exists('currencyCode', $jsonResponse['availableFunds'])) { + $this->_currency = $jsonResponse['availableFunds']['currencyCode']; + } + if (array_key_exists('status', $jsonResponse)) { + $this->_status = $jsonResponse['status']; + } + if (array_key_exists('timestamp', $jsonResponse)) { + $this->_timestamp = $jsonResponse['timestamp']; + } + + return $this; + + } + +} From 10190ba146a77dafcebe7da9c82b0cc7a07c9c1f Mon Sep 17 00:00:00 2001 From: Dave Morris Date: Tue, 4 Feb 2020 13:20:23 +0000 Subject: [PATCH 07/11] Updated ReadMe --- readme.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/readme.md b/readme.md index 2f3096f..31bf6ff 100644 --- a/readme.md +++ b/readme.md @@ -42,6 +42,10 @@ To Cancel Amazon Gift Card ```php $aws = AmazonGiftCode::make()->cancelGiftCard($creationRequestId, $gcId); ``` +To Get Available Funds Balance +```php +$aws = AmazonGiftCode::make()->getAvailableFunds(); +``` ## Available Methods @@ -156,6 +160,44 @@ $rawJson = $aws->getRawJson(); ``` +------------------- +### GetAvailableFunds + +`getStatus()` + +Get the status of perform request. (`status`) + +```php +$status = $aws->getStatus(); +``` +------------------- +`getAmount()` + +To get available balance amount. (`amount`) + + +```php +$getCurrency = $aws->getCurrency(); +``` +------------------- +`getTimestamp()` + +Get request timestamp. (`getTimestamp`) + + +```php +$timestamp = $aws->getTimestamp(); +``` + +------------------- +`getRawJson()` + +Get the raw JSON response. (original response) + + +```php +$rawJson = $aws->getRawJson(); + ## Change log From 69324e8a431db7faa96b66dbf440c95da2426872 Mon Sep 17 00:00:00 2001 From: Dave Morris Date: Tue, 4 Feb 2020 13:22:02 +0000 Subject: [PATCH 08/11] Updated ReadMe --- readme.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/readme.md b/readme.md index 31bf6ff..57a6be1 100644 --- a/readme.md +++ b/readme.md @@ -176,8 +176,18 @@ $status = $aws->getStatus(); To get available balance amount. (`amount`) +```php +$getAmount = $aws->getAmount(); +``` +------------------- +`getCurrency()` + +To get currency. (`currency`) + + ```php $getCurrency = $aws->getCurrency(); + ``` ------------------- `getTimestamp()` From e5935624add9753383221110ee514d9d5770ea25 Mon Sep 17 00:00:00 2001 From: Dave Morris Date: Tue, 4 Feb 2020 13:22:44 +0000 Subject: [PATCH 09/11] Updated ReadMe --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 57a6be1..c37271e 100644 --- a/readme.md +++ b/readme.md @@ -177,7 +177,7 @@ To get available balance amount. (`amount`) ```php -$getAmount = $aws->getAmount(); +$amount = $aws->getAmount(); ``` ------------------- `getCurrency()` @@ -186,7 +186,7 @@ To get currency. (`currency`) ```php -$getCurrency = $aws->getCurrency(); +$currency = $aws->getCurrency(); ``` ------------------- From a5fd8732a0e1e2bb566c1bb216fbc90bfe0a4822 Mon Sep 17 00:00:00 2001 From: Dave Morris Date: Tue, 4 Feb 2020 13:23:27 +0000 Subject: [PATCH 10/11] Updated ReadMe --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index c37271e..31cd93f 100644 --- a/readme.md +++ b/readme.md @@ -207,7 +207,7 @@ Get the raw JSON response. (original response) ```php $rawJson = $aws->getRawJson(); - +``` ## Change log From 5738f2412bc8a4aa131013c77e320dd6e96597be Mon Sep 17 00:00:00 2001 From: Dave Morris Date: Tue, 28 Apr 2020 10:53:16 +0100 Subject: [PATCH 11/11] Laravel 7 support --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ca2fb09..c792eef 100644 --- a/composer.json +++ b/composer.json @@ -12,10 +12,10 @@ "homepage": "https://github.com/kamerk22/amazongiftcode", "keywords": ["Laravel", "AmazonGiftCode", "Amazon", "GiftCard", "AGCOD", "Incentives API", "Amazon Incentives API"], "require": { - "illuminate/support": "~5|^6.0" + "illuminate/support": "~5|^6.0|^7.0" }, "require-dev": { - "phpunit/phpunit": "~7.0", + "phpunit/phpunit": "~7.0|~8.0", "mockery/mockery": "^1.1", "orchestra/testbench": "~3.0", "sempro/phpunit-pretty-print": "^1.0"