Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f60aa3e1bc | |||
| b041720a18 | |||
| be6b2be55d | |||
|
|
6163d26f50 | ||
|
|
a4c06b9a36 | ||
| 24dc8426de | |||
| 7ef4133537 | |||
| 4f90f2d916 | |||
| 192e4e54e1 |
@@ -6,7 +6,7 @@ Amazon Gift Codes On Demand (AGCOD). Integration for Amazon Incentive API.
|
|||||||
|
|
||||||
## How to install
|
## How to install
|
||||||
|
|
||||||
`composer request gullevek/amazon-incentives`
|
`composer require gullevek/amazon-incentives`
|
||||||
|
|
||||||
## _ENV variables needed
|
## _ENV variables needed
|
||||||
|
|
||||||
|
|||||||
@@ -20,5 +20,8 @@
|
|||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.4.0"
|
"php": ">=7.4.0"
|
||||||
|
},
|
||||||
|
"archive": {
|
||||||
|
"exclude": ["/test/", "/phpstan.neon", "/psalm.xml", "/.phan/", "/.vscode/"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
parameters:
|
parameters:
|
||||||
tmpDir: /tmp/phpstan-codeblocks-amazon-incentives
|
tmpDir: /tmp/phpstan-codeblocks-amazon-incentives
|
||||||
level: max
|
level: 8
|
||||||
paths:
|
paths:
|
||||||
- %currentWorkingDirectory%
|
- %currentWorkingDirectory%
|
||||||
excludes_analyse:
|
excludePaths:
|
||||||
# ignore composer
|
# ignore composer
|
||||||
- vendor
|
- vendor
|
||||||
# ignore errores with
|
# ignore errores with
|
||||||
|
|||||||
15
psalm.xml
Normal file
15
psalm.xml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<psalm
|
||||||
|
errorLevel="3"
|
||||||
|
resolveFromConfigFile="true"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="https://getpsalm.org/schema/config"
|
||||||
|
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
||||||
|
>
|
||||||
|
<projectFiles>
|
||||||
|
<directory name="src" />
|
||||||
|
<ignoreFiles>
|
||||||
|
<directory name="vendor" />
|
||||||
|
</ignoreFiles>
|
||||||
|
</projectFiles>
|
||||||
|
</psalm>
|
||||||
@@ -155,7 +155,7 @@ class AWS
|
|||||||
'Service' => $k_service_hexis,
|
'Service' => $k_service_hexis,
|
||||||
]]);
|
]]);
|
||||||
|
|
||||||
$url = 'https://' . (string)$endpoint . '/' . $service_operation;
|
$url = 'https://' . $endpoint . '/' . $service_operation;
|
||||||
$headers = $this->buildHeaders($payload, $authorization_value, $date_time_string, $service_target);
|
$headers = $this->buildHeaders($payload, $authorization_value, $date_time_string, $service_target);
|
||||||
return (new Client())->request($url, $headers, $payload);
|
return (new Client())->request($url, $headers, $payload);
|
||||||
}
|
}
|
||||||
@@ -332,7 +332,7 @@ class AWS
|
|||||||
'value' =>
|
'value' =>
|
||||||
[
|
[
|
||||||
'currencyCode' => $this->config->getCurrency(),
|
'currencyCode' => $this->config->getCurrency(),
|
||||||
'amount' => (float)$amount
|
'amount' => $amount
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
return (json_encode($payload)) ?: '';
|
return (json_encode($payload)) ?: '';
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ class Client implements ClientInterface
|
|||||||
$message = 'Could not connect to AWS (' . $url . '). Please check your '
|
$message = 'Could not connect to AWS (' . $url . '). Please check your '
|
||||||
. 'internet connection and try again. [' . $message . ']';
|
. 'internet connection and try again. [' . $message . ']';
|
||||||
break;
|
break;
|
||||||
case CURLE_SSL_CACERT:
|
|
||||||
case CURLE_SSL_PEER_CERTIFICATE:
|
case CURLE_SSL_PEER_CERTIFICATE:
|
||||||
$message = 'Could not verify AWS SSL certificate. Please make sure '
|
$message = 'Could not verify AWS SSL certificate. Please make sure '
|
||||||
. 'that your network is not intercepting certificates. '
|
. 'that your network is not intercepting certificates. '
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ interface ClientInterface
|
|||||||
*
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function request(string $url, array $headers, $params): string;
|
public function request(string $url, array $headers, $params): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,27 +7,27 @@ class Config implements ConfigInterface
|
|||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $endpoint;
|
private $endpoint = '';
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $access_key;
|
private $access_key = '';
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $secret_key;
|
private $secret_key = '';
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $partner_id;
|
private $partner_id = '';
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $currency;
|
private $currency = '';
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private $debug;
|
private $debug = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|null $key
|
* @param string|null $key
|
||||||
@@ -42,14 +42,38 @@ class Config implements ConfigInterface
|
|||||||
?string $partner,
|
?string $partner,
|
||||||
?string $endpoint,
|
?string $endpoint,
|
||||||
?string $currency,
|
?string $currency,
|
||||||
?bool $debug,
|
?bool $debug
|
||||||
) {
|
) {
|
||||||
$this->setAccessKey(($key) ?: $this->parseEnv('AWS_GIFT_CARD_KEY')); /** @phpstan-ignore-line */
|
/**
|
||||||
$this->setSecret(($secret) ?: $this->parseEnv('AWS_GIFT_CARD_SECRET')); /** @phpstan-ignore-line */
|
* @psalm-suppress InvalidScalarArgument
|
||||||
$this->setPartner(($partner) ?: $this->parseEnv('AWS_GIFT_CARD_PARTNER_ID')); /** @phpstan-ignore-line */
|
* @phpstan-ignore-next-line
|
||||||
$this->setEndpoint(($endpoint) ?: $this->parseEnv('AWS_GIFT_CARD_ENDPOINT')); /** @phpstan-ignore-line */
|
*/
|
||||||
$this->setCurrency(($currency) ?: $this->parseEnv('AWS_GIFT_CARD_CURRENCY')); /** @phpstan-ignore-line */
|
$this->setAccessKey(($key) ?: $this->parseEnv('AWS_GIFT_CARD_KEY'));
|
||||||
$this->setDebug(($debug) ?: $this->parseEnv('AWS_DEBUG')); /** @phpstan-ignore-line */
|
/**
|
||||||
|
* @psalm-suppress InvalidScalarArgument
|
||||||
|
* @phpstan-ignore-next-line
|
||||||
|
*/
|
||||||
|
$this->setSecret(($secret) ?: $this->parseEnv('AWS_GIFT_CARD_SECRET'));
|
||||||
|
/**
|
||||||
|
* @psalm-suppress InvalidScalarArgument
|
||||||
|
* @phpstan-ignore-next-line
|
||||||
|
*/
|
||||||
|
$this->setPartner(($partner) ?: $this->parseEnv('AWS_GIFT_CARD_PARTNER_ID'));
|
||||||
|
/**
|
||||||
|
* @psalm-suppress InvalidScalarArgument
|
||||||
|
* @phpstan-ignore-next-line
|
||||||
|
*/
|
||||||
|
$this->setEndpoint(($endpoint) ?: $this->parseEnv('AWS_GIFT_CARD_ENDPOINT'));
|
||||||
|
/**
|
||||||
|
* @psalm-suppress InvalidScalarArgument
|
||||||
|
* @phpstan-ignore-next-line
|
||||||
|
*/
|
||||||
|
$this->setCurrency(($currency) ?: $this->parseEnv('AWS_GIFT_CARD_CURRENCY'));
|
||||||
|
/**
|
||||||
|
* @psalm-suppress InvalidScalarArgument
|
||||||
|
* @phpstan-ignore-next-line
|
||||||
|
*/
|
||||||
|
$this->setDebug(($debug) ?: $this->parseEnv('AWS_DEBUG'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,9 +104,9 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getEndpoint(): ?string
|
public function getEndpoint(): string
|
||||||
{
|
{
|
||||||
return $this->endpoint;
|
return $this->endpoint;
|
||||||
}
|
}
|
||||||
@@ -100,9 +124,9 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getAccessKey(): ?string
|
public function getAccessKey(): string
|
||||||
{
|
{
|
||||||
return $this->access_key;
|
return $this->access_key;
|
||||||
}
|
}
|
||||||
@@ -119,9 +143,9 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getSecret(): ?string
|
public function getSecret(): string
|
||||||
{
|
{
|
||||||
return $this->secret_key;
|
return $this->secret_key;
|
||||||
}
|
}
|
||||||
@@ -138,9 +162,9 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getCurrency(): ?string
|
public function getCurrency(): string
|
||||||
{
|
{
|
||||||
return $this->currency;
|
return $this->currency;
|
||||||
}
|
}
|
||||||
@@ -158,9 +182,9 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getPartner(): ?string
|
public function getPartner(): string
|
||||||
{
|
{
|
||||||
return $this->partner_id;
|
return $this->partner_id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,68 +5,68 @@ namespace gullevek\AmazonIncentives\Config;
|
|||||||
interface ConfigInterface
|
interface ConfigInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getEndpoint(): ?string;
|
public function getEndpoint(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $endpoint
|
* @param string $endpoint
|
||||||
* @return $this
|
* @return ConfigInterface
|
||||||
*/
|
*/
|
||||||
public function setEndpoint(string $endpoint): ConfigInterface;
|
public function setEndpoint(string $endpoint): ConfigInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getAccessKey(): ?string;
|
public function getAccessKey(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return $this
|
* @return ConfigInterface
|
||||||
*/
|
*/
|
||||||
public function setAccessKey(string $key): ConfigInterface;
|
public function setAccessKey(string $key): ConfigInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getSecret(): ?string;
|
public function getSecret(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $secret
|
* @param string $secret
|
||||||
* @return $this
|
* @return ConfigInterface
|
||||||
*/
|
*/
|
||||||
public function setSecret(string $secret): ConfigInterface;
|
public function setSecret(string $secret): ConfigInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getCurrency(): ?string;
|
public function getCurrency(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $currency
|
* @param string $currency
|
||||||
* @return $this
|
* @return ConfigInterface
|
||||||
*/
|
*/
|
||||||
public function setCurrency(string $currency): ConfigInterface;
|
public function setCurrency(string $currency): ConfigInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getPartner(): ?string;
|
public function getPartner(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $partner
|
* @param string $partner
|
||||||
* @return $this
|
* @return ConfigInterface
|
||||||
*/
|
*/
|
||||||
public function setPartner(string $partner): ConfigInterface;
|
public function setPartner(string $partner): ConfigInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool|null
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getDebug(): ?bool;
|
public function getDebug(): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $debug
|
* @param bool $debug
|
||||||
* @return $this
|
* @return ConfigInterface
|
||||||
*/
|
*/
|
||||||
public function setDebug(bool $debug): ConfigInterface;
|
public function setDebug(bool $debug): ConfigInterface;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
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
|
||||||
@@ -12,25 +11,25 @@ class CancelResponse
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $id;
|
protected $id = '';
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card creationRequestId
|
* Amazon Gift Card creationRequestId
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $creation_request_id;
|
protected $creation_request_id = '';
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card status
|
* Amazon Gift Card status
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $status;
|
protected $status = '';
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card Raw JSON
|
* Amazon Gift Card Raw JSON
|
||||||
*
|
*
|
||||||
* @var array<mixed>
|
* @var array<mixed>
|
||||||
*/
|
*/
|
||||||
protected $raw_json;
|
protected $raw_json = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response constructor.
|
* Response constructor.
|
||||||
@@ -88,15 +87,6 @@ class CancelResponse
|
|||||||
*/
|
*/
|
||||||
public function parseJsonResponse(array $json_response): self
|
public function parseJsonResponse(array $json_response): self
|
||||||
{
|
{
|
||||||
if (!is_array($json_response)) {
|
|
||||||
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,7 +2,6 @@
|
|||||||
|
|
||||||
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
|
||||||
@@ -12,31 +11,31 @@ class CreateBalanceResponse
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $amount;
|
protected $amount = '';
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card Balance Currency
|
* Amazon Gift Card Balance Currency
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $currency;
|
protected $currency = '';
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card Balance Status
|
* Amazon Gift Card Balance Status
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $status;
|
protected $status = '';
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card Balance Timestamp
|
* Amazon Gift Card Balance Timestamp
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $timestamp;
|
protected $timestamp = '';
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card Raw JSON
|
* Amazon Gift Card Raw JSON
|
||||||
*
|
*
|
||||||
* @var array<mixed>
|
* @var array<mixed>
|
||||||
*/
|
*/
|
||||||
protected $raw_json;
|
protected $raw_json = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response constructor.
|
* Response constructor.
|
||||||
@@ -105,15 +104,6 @@ class CreateBalanceResponse
|
|||||||
*/
|
*/
|
||||||
public function parseJsonResponse(array $json_response): self
|
public function parseJsonResponse(array $json_response): self
|
||||||
{
|
{
|
||||||
if (!is_array($json_response)) {
|
|
||||||
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,7 +2,6 @@
|
|||||||
|
|
||||||
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
|
||||||
@@ -12,59 +11,59 @@ class CreateResponse
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $id;
|
protected $id = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card creationRequestId
|
* Amazon Gift Card creationRequestId
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $creation_request_id;
|
protected $creation_request_id = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card gcClaimCode
|
* Amazon Gift Card gcClaimCode
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $claim_code;
|
protected $claim_code = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card amount
|
* Amazon Gift Card amount
|
||||||
*
|
*
|
||||||
* @var float
|
* @var float
|
||||||
*/
|
*/
|
||||||
protected $value;
|
protected $value = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card currency
|
* Amazon Gift Card currency
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $currency;
|
protected $currency = '';
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card status
|
* Amazon Gift Card status
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $status;
|
protected $status = '';
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card Expiration Date
|
* Amazon Gift Card Expiration Date
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $expiration_date;
|
protected $expiration_date = '';
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card Expiration Date
|
* Amazon Gift Card Expiration Date
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $card_status;
|
protected $card_status = '';
|
||||||
/**
|
/**
|
||||||
* Amazon Gift Card Raw JSON
|
* Amazon Gift Card Raw JSON
|
||||||
*
|
*
|
||||||
* @var array<mixed>
|
* @var array<mixed>
|
||||||
*/
|
*/
|
||||||
protected $raw_json;
|
protected $raw_json = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response constructor.
|
* Response constructor.
|
||||||
@@ -158,20 +157,11 @@ class CreateResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<mixed> $json_response
|
* @param array<array-key,mixed|array> $json_response
|
||||||
* @return CreateResponse
|
* @return CreateResponse
|
||||||
*/
|
*/
|
||||||
public function parseJsonResponse(array $json_response): self
|
public function parseJsonResponse(array $json_response): self
|
||||||
{
|
{
|
||||||
if (!is_array($json_response)) {
|
|
||||||
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'];
|
||||||
}
|
}
|
||||||
|
|||||||
7
test/.env.example
Normal file
7
test/.env.example
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# for AWS gift card testing
|
||||||
|
AWS_GIFT_CARD_ENDPOINT=
|
||||||
|
AWS_GIFT_CARD_KEY=
|
||||||
|
AWS_GIFT_CARD_SECRET=
|
||||||
|
AWS_GIFT_CARD_PARTNER_ID=
|
||||||
|
AWS_GIFT_CARD_CURRENCY=
|
||||||
|
AWS_DEBUG=
|
||||||
@@ -76,21 +76,6 @@ print "<h1>Amazon Gift Card Incentives</h1><br>";
|
|||||||
// optional
|
// optional
|
||||||
// debug: AWS_DEBUG (if not set: off)
|
// debug: AWS_DEBUG (if not set: off)
|
||||||
|
|
||||||
// as in .env
|
|
||||||
// AWS_GIFT_CARD_ENDPOINT.TEST
|
|
||||||
// AWS_GIFT_CARD_ENDPOINT.LIVE
|
|
||||||
|
|
||||||
define('LOCATION', 'test');
|
|
||||||
foreach (
|
|
||||||
[
|
|
||||||
'AWS_GIFT_CARD_KEY', 'AWS_GIFT_CARD_SECRET', 'AWS_GIFT_CARD_PARTNER_ID',
|
|
||||||
'AWS_GIFT_CARD_ENDPOINT', 'AWS_GIFT_CARD_CURRENCY', 'AWS_DEBUG'
|
|
||||||
] as $key
|
|
||||||
) {
|
|
||||||
//
|
|
||||||
$_ENV[$key] = $_ENV[$key . '.' . strtoupper((LOCATION))] ?? $_ENV[$key] ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// open debug file output
|
// open debug file output
|
||||||
$fp = fopen('log/debug.' . date('YmdHis') . '.log', 'w');
|
$fp = fopen('log/debug.' . date('YmdHis') . '.log', 'w');
|
||||||
if (!is_resource($fp)) {
|
if (!is_resource($fp)) {
|
||||||
@@ -196,6 +181,28 @@ if ($run_gift_tests === true) {
|
|||||||
}
|
}
|
||||||
print "<br>";
|
print "<br>";
|
||||||
sleep($debug_wait);
|
sleep($debug_wait);
|
||||||
|
// request same card again and get error
|
||||||
|
try {
|
||||||
|
$aws_test = AmazonIncentives::make()->buyGiftCard((float)$value, $creation_request_id);
|
||||||
|
$request_status = $aws_test->getStatus();
|
||||||
|
// same?
|
||||||
|
$claim_code = $aws_test->getClaimCode();
|
||||||
|
$expiration_date = $aws_test->getExpirationDate();
|
||||||
|
print "AWS: buyGiftCard: CANCLED SAME CODE AGAIN: " . $request_status . ": "
|
||||||
|
. "creationRequestId: " . $creation_request_id . ", gcId: " . $gift_card_id . ", "
|
||||||
|
. "EXPIRE DATE: <b>" . dateTr($expiration_date) . "</b>, "
|
||||||
|
. "CLAIM CODE: <b>" . $claim_code . "</b>";
|
||||||
|
if ($debug_print === true) {
|
||||||
|
print "<pre>" . print_r($aws_test, true) . "</pre>";
|
||||||
|
}
|
||||||
|
fwrite($fp, writeLog((array)$aws_test));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$error = AmazonIncentives::decodeExceptionMessage($e->getMessage());
|
||||||
|
printException('buyGiftCard', $e->getCode(), $error, $debug_print);
|
||||||
|
fwrite($fp, writeLog($error));
|
||||||
|
}
|
||||||
|
print "<br>";
|
||||||
|
sleep($debug_wait);
|
||||||
|
|
||||||
// set same request ID twice to get same response test
|
// set same request ID twice to get same response test
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user