Switch to PSR12 with spaces instead of tabs

This commit is contained in:
2023-01-19 12:51:12 +09:00
parent 6f5cd028b9
commit d86ad8c051
15 changed files with 2777 additions and 2777 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -14,158 +14,158 @@ use gullevek\AmazonIncentives\Debug\AmazonDebug;
final class AmazonIncentives
{
/**
* @var Config
*/
private $config;
/**
* @var Config
*/
private $config;
/**
* AmazonGiftCode constructor.
*
* @param string|null $key Account key
* @param string|null $secret Secret key
* @param string|null $partner Partner ID
* @param string|null $endpoint Endpoint URL including https://
* @param string|null $currency Currency type. Eg USD, JPY, etc
* @param bool|null $debug Debug flag
*/
public function __construct(
string $key = null,
string $secret = null,
string $partner = null,
string $endpoint = null,
string $currency = null,
bool $debug = null
) {
// load AWS settings
// fail here if settings missing
$this->config = new Config($key, $secret, $partner, $endpoint, $currency, $debug);
// init debug
AmazonDebug::setDebug($this->config->getDebug());
}
/**
* AmazonGiftCode constructor.
*
* @param string|null $key Account key
* @param string|null $secret Secret key
* @param string|null $partner Partner ID
* @param string|null $endpoint Endpoint URL including https://
* @param string|null $currency Currency type. Eg USD, JPY, etc
* @param bool|null $debug Debug flag
*/
public function __construct(
string $key = null,
string $secret = null,
string $partner = null,
string $endpoint = null,
string $currency = null,
bool $debug = null
) {
// load AWS settings
// fail here if settings missing
$this->config = new Config($key, $secret, $partner, $endpoint, $currency, $debug);
// init debug
AmazonDebug::setDebug($this->config->getDebug());
}
// *********************************************************************
// PRIVATE HELPER METHODS
// *********************************************************************
// *********************************************************************
// PRIVATE HELPER METHODS
// *********************************************************************
// *********************************************************************
// PUBLIC METHODS
// *********************************************************************
// *********************************************************************
// PUBLIC METHODS
// *********************************************************************
/**
* Buy a gift card
*
* @param float $value Amount to purchase a gift card
* in currency value
* @param string|null $creation_request_id Override automatically created request id
* If not set will create a new one, or
* return data for created one
* @return Response\CreateResponse Returns new created response object or
* previous created if creation_request_id was used
*
* @throws AmazonErrors
*/
public function buyGiftCard(float $value, string $creation_request_id = null): Response\CreateResponse
{
return ($this->newAWS())->getCode($value, $creation_request_id);
}
/**
* Buy a gift card
*
* @param float $value Amount to purchase a gift card
* in currency value
* @param string|null $creation_request_id Override automatically created request id
* If not set will create a new one, or
* return data for created one
* @return Response\CreateResponse Returns new created response object or
* previous created if creation_request_id was used
*
* @throws AmazonErrors
*/
public function buyGiftCard(float $value, string $creation_request_id = null): Response\CreateResponse
{
return ($this->newAWS())->getCode($value, $creation_request_id);
}
/**
* Cancel a previous created gift card, if within the time frame
*
* @param string $creation_request_id Previous created request id from buyGiftCard
* @param string $gift_card_id Previous gift card id from buyGiftCard (gcId)
* @return Response\CancelResponse Returns the cancled request object
*
* @throws AmazonErrors
*/
public function cancelGiftCard(string $creation_request_id, string $gift_card_id): Response\CancelResponse
{
return ($this->newAWS())->cancelCode($creation_request_id, $gift_card_id);
}
/**
* Cancel a previous created gift card, if within the time frame
*
* @param string $creation_request_id Previous created request id from buyGiftCard
* @param string $gift_card_id Previous gift card id from buyGiftCard (gcId)
* @return Response\CancelResponse Returns the cancled request object
*
* @throws AmazonErrors
*/
public function cancelGiftCard(string $creation_request_id, string $gift_card_id): Response\CancelResponse
{
return ($this->newAWS())->cancelCode($creation_request_id, $gift_card_id);
}
/**
* Gets the current funds in this account
*
* @return Response\CreateBalanceResponse Returns the account funds object
*
* @throws AmazonErrors
*/
public function getAvailableFunds(): Response\CreateBalanceResponse
{
return ($this->newAWS())->getBalance();
}
/**
* Gets the current funds in this account
*
* @return Response\CreateBalanceResponse Returns the account funds object
*
* @throws AmazonErrors
*/
public function getAvailableFunds(): Response\CreateBalanceResponse
{
return ($this->newAWS())->getBalance();
}
/**
* AmazonIncentives creates own client and returns it as static object
*
* @param string|null $key Account key
* @param string|null $secret Secret key
* @param string|null $partner Partner ID
* @param string|null $endpoint Endpoint URL including https://
* @param string|null $currency Currency type. Eg USD, JPY, etc
* @param bool|null $debug Debug flag
* @return AmazonIncentives self class
*/
public static function make(
string $key = null,
string $secret = null,
string $partner = null,
string $endpoint = null,
string $currency = null,
bool $debug = null
): AmazonIncentives {
return new static($key, $secret, $partner, $endpoint, $currency, $debug);
}
/**
* AmazonIncentives creates own client and returns it as static object
*
* @param string|null $key Account key
* @param string|null $secret Secret key
* @param string|null $partner Partner ID
* @param string|null $endpoint Endpoint URL including https://
* @param string|null $currency Currency type. Eg USD, JPY, etc
* @param bool|null $debug Debug flag
* @return AmazonIncentives self class
*/
public static function make(
string $key = null,
string $secret = null,
string $partner = null,
string $endpoint = null,
string $currency = null,
bool $debug = null
): AmazonIncentives {
return new static($key, $secret, $partner, $endpoint, $currency, $debug);
}
/**
* wrapper to create new AWS class.
* used in all buy/cancel/get calss
*
* @return AWS Main AWS worker class
*/
public function newAWS(): AWS
{
return new AWS($this->config);
}
/**
* wrapper to create new AWS class.
* used in all buy/cancel/get calss
*
* @return AWS Main AWS worker class
*/
public function newAWS(): AWS
{
return new AWS($this->config);
}
/**
* Decodes the Exception message body
* Returns an array with code (Amazon error codes), type (Amazon error info)
* message (Amazon returned error message string)
*
* @param string $message Exception message json string
* @return array<mixed> Decoded with code, type, message fields
*
* @deprecated use \gullevek\AmazonIncentives\Exceptions\AmazonErrors::decodeExceptionMessage()
*/
public static function decodeExceptionMessage(string $message): array
{
return AmazonErrors::decodeExceptionMessage($message);
}
/**
* Decodes the Exception message body
* Returns an array with code (Amazon error codes), type (Amazon error info)
* message (Amazon returned error message string)
*
* @param string $message Exception message json string
* @return array<mixed> Decoded with code, type, message fields
*
* @deprecated use \gullevek\AmazonIncentives\Exceptions\AmazonErrors::decodeExceptionMessage()
*/
public static function decodeExceptionMessage(string $message): array
{
return AmazonErrors::decodeExceptionMessage($message);
}
// *********************************************************************
// PUBLIC TEST METHODS
// *********************************************************************
// *********************************************************************
// PUBLIC TEST METHODS
// *********************************************************************
/**
* Prints out ENV, CONFIG and KEY data
* This is for debug only, this will print out secrets.
* Use with care
*
* @return array<mixed>
*/
public function checkMe(): array
{
$data = [];
/**
* Prints out ENV, CONFIG and KEY data
* This is for debug only, this will print out secrets.
* Use with care
*
* @return array<mixed>
*/
public function checkMe(): array
{
$data = [];
$data['ENV'] = $_ENV;
$data['CONFIG'] = $this->config;
$data['KEY'] = $this->config->getAccessKey();
$data['ENV'] = $_ENV;
$data['CONFIG'] = $this->config;
$data['KEY'] = $this->config->getAccessKey();
return $data;
}
return $data;
}
}
// __END__

View File

@@ -7,113 +7,113 @@ use gullevek\AmazonIncentives\Debug\AmazonDebug;
class Client implements ClientInterface
{
/** @var int instead of JsonResponse::HTTP_OK */
private const HTTP_OK = 200;
/** @var int instead of JsonResponse::HTTP_OK */
private const HTTP_OK = 200;
/**
* Makes an request to the target url via curl
* Returns result as string (json)
*
* @param string $url The URL being requested,
* including domain and protocol
* @param array<mixed> $headers Headers to be used in the request
* @param array<mixed>|string $params Can be nested for arrays and hashes
* @return string Result as json string
*/
public function request(string $url, array $headers, $params): string
{
$handle = curl_init($url);
if ($handle === false) {
// throw Error here with all codes
throw AmazonErrors::getError(
'FAILURE',
'C001',
'CurlInitError',
'Failed to init curl with url: ' . $url,
0
);
}
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($handle, CURLOPT_FAILONERROR, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $params);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($handle);
/**
* Makes an request to the target url via curl
* Returns result as string (json)
*
* @param string $url The URL being requested,
* including domain and protocol
* @param array<mixed> $headers Headers to be used in the request
* @param array<mixed>|string $params Can be nested for arrays and hashes
* @return string Result as json string
*/
public function request(string $url, array $headers, $params): string
{
$handle = curl_init($url);
if ($handle === false) {
// throw Error here with all codes
throw AmazonErrors::getError(
'FAILURE',
'C001',
'CurlInitError',
'Failed to init curl with url: ' . $url,
0
);
}
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($handle, CURLOPT_FAILONERROR, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $params);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($handle);
if ($result === false) {
$err = curl_errno($handle);
$message = curl_error($handle);
$this->handleCurlError($url, $err, $message);
}
if ($result === false) {
$err = curl_errno($handle);
$message = curl_error($handle);
$this->handleCurlError($url, $err, $message);
}
if (curl_getinfo($handle, CURLINFO_HTTP_CODE) !== self::HTTP_OK) {
$err = curl_errno($handle);
AmazonDebug::writeLog(['CURL_REQUEST_RESULT' => $result]);
// extract all the error codes from Amazon
$result_ar = json_decode((string)$result, true);
// if message is 'Rate exceeded', set different error
if (($result_ar['message'] ?? '') == 'Rate exceeded') {
$error_status = 'RESEND';
$error_code = 'T001';
$error_type = 'RateExceeded';
$message = $result_ar['message'] ?? 'Rate exceeded';
} else {
// for all other error messages
$error_status = $result_ar['agcodResponse']['status'] ?? 'FAILURE';
$error_code = $result_ar['errorCode'] ?? 'E999';
$error_type = $result_ar['errorType'] ?? 'OtherUnknownError';
$message = $result_ar['message'] ?? 'Unknown error occured';
}
// throw Error here with all codes
throw AmazonErrors::getError(
$error_status,
$error_code,
$error_type,
$message,
$err
);
}
return (string)$result;
}
if (curl_getinfo($handle, CURLINFO_HTTP_CODE) !== self::HTTP_OK) {
$err = curl_errno($handle);
AmazonDebug::writeLog(['CURL_REQUEST_RESULT' => $result]);
// extract all the error codes from Amazon
$result_ar = json_decode((string)$result, true);
// if message is 'Rate exceeded', set different error
if (($result_ar['message'] ?? '') == 'Rate exceeded') {
$error_status = 'RESEND';
$error_code = 'T001';
$error_type = 'RateExceeded';
$message = $result_ar['message'] ?? 'Rate exceeded';
} else {
// for all other error messages
$error_status = $result_ar['agcodResponse']['status'] ?? 'FAILURE';
$error_code = $result_ar['errorCode'] ?? 'E999';
$error_type = $result_ar['errorType'] ?? 'OtherUnknownError';
$message = $result_ar['message'] ?? 'Unknown error occured';
}
// throw Error here with all codes
throw AmazonErrors::getError(
$error_status,
$error_code,
$error_type,
$message,
$err
);
}
return (string)$result;
}
/**
* handles any CURL errors and throws an error with the correct
* error message
*
* @param string $url The url that was originaly used
* @param int $errno Error number from curl handler
* @param string $message The error message string from curl
* @return void
*/
private function handleCurlError(string $url, int $errno, string $message): void
{
switch ($errno) {
case CURLE_COULDNT_CONNECT:
case CURLE_COULDNT_RESOLVE_HOST:
case CURLE_OPERATION_TIMEOUTED:
$message = 'Could not connect to AWS (' . $url . '). Please check your '
. 'internet connection and try again. [' . $message . ']';
break;
case CURLE_SSL_PEER_CERTIFICATE:
$message = 'Could not verify AWS SSL certificate. Please make sure '
. 'that your network is not intercepting certificates. '
. '(Try going to ' . $url . 'in your browser.) '
. '[' . $message . ']';
break;
case 0:
default:
$message = 'Unexpected error communicating with AWS: ' . $message;
}
/**
* handles any CURL errors and throws an error with the correct
* error message
*
* @param string $url The url that was originaly used
* @param int $errno Error number from curl handler
* @param string $message The error message string from curl
* @return void
*/
private function handleCurlError(string $url, int $errno, string $message): void
{
switch ($errno) {
case CURLE_COULDNT_CONNECT:
case CURLE_COULDNT_RESOLVE_HOST:
case CURLE_OPERATION_TIMEOUTED:
$message = 'Could not connect to AWS (' . $url . '). Please check your '
. 'internet connection and try again. [' . $message . ']';
break;
case CURLE_SSL_PEER_CERTIFICATE:
$message = 'Could not verify AWS SSL certificate. Please make sure '
. 'that your network is not intercepting certificates. '
. '(Try going to ' . $url . 'in your browser.) '
. '[' . $message . ']';
break;
case 0:
default:
$message = 'Unexpected error communicating with AWS: ' . $message;
}
// throw an error like in the normal reqeust, but set to CURL error
throw AmazonErrors::getError(
'FAILURE',
'C002',
'CurlError',
$message,
$errno
);
}
// throw an error like in the normal reqeust, but set to CURL error
throw AmazonErrors::getError(
'FAILURE',
'C002',
'CurlError',
$message,
$errno
);
}
}
// __END__

View File

@@ -4,15 +4,15 @@ namespace gullevek\AmazonIncentives\Client;
interface ClientInterface
{
/**
* @param string $url The URL being requested,
* including domain and protocol
* @param array<mixed> $headers Headers to be used in the request
* @param array<mixed>|string $params Can be nested for arrays and hashes
*
* @return String
*/
public function request(string $url, array $headers, $params): string;
/**
* @param string $url The URL being requested,
* including domain and protocol
* @param array<mixed> $headers Headers to be used in the request
* @param array<mixed>|string $params Can be nested for arrays and hashes
*
* @return String
*/
public function request(string $url, array $headers, $params): string;
}
// __END__

View File

@@ -4,210 +4,210 @@ namespace gullevek\AmazonIncentives\Config;
class Config implements ConfigInterface
{
/** @var string Endpoint URL without https:// */
private $endpoint = '';
/** @var string Access Key */
private $access_key = '';
/** @var string Secret Key */
private $secret_key = '';
/** @var string Partner ID */
private $partner_id = '';
/** @var string Currency type as USD, JPY, etc */
private $currency = '';
/** @var bool Debug flag on or off */
private $debug = false;
/** @var string Endpoint URL without https:// */
private $endpoint = '';
/** @var string Access Key */
private $access_key = '';
/** @var string Secret Key */
private $secret_key = '';
/** @var string Partner ID */
private $partner_id = '';
/** @var string Currency type as USD, JPY, etc */
private $currency = '';
/** @var bool Debug flag on or off */
private $debug = false;
/**
* @param string|null $key Access key
* @param string|null $secret Secret Key
* @param string|null $partner Partner ID
* @param string|null $endpoint Endpoing URL including https://
* @param string|null $currency Currency to use, see valid list on AWS documentation.
* valid names are like USD, JPY, etc
* @param bool|null $debug Debug flag
*/
public function __construct(
?string $key,
?string $secret,
?string $partner,
?string $endpoint,
?string $currency,
?bool $debug
) {
/**
* @psalm-suppress InvalidScalarArgument
* @phpstan-ignore-next-line
*/
$this->setAccessKey(($key) ?: $this->parseEnv('AWS_GIFT_CARD_KEY'));
/**
* @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'));
}
/**
* @param string|null $key Access key
* @param string|null $secret Secret Key
* @param string|null $partner Partner ID
* @param string|null $endpoint Endpoing URL including https://
* @param string|null $currency Currency to use, see valid list on AWS documentation.
* valid names are like USD, JPY, etc
* @param bool|null $debug Debug flag
*/
public function __construct(
?string $key,
?string $secret,
?string $partner,
?string $endpoint,
?string $currency,
?bool $debug
) {
/**
* @psalm-suppress InvalidScalarArgument
* @phpstan-ignore-next-line
*/
$this->setAccessKey(($key) ?: $this->parseEnv('AWS_GIFT_CARD_KEY'));
/**
* @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'));
}
/**
* string key to search, returns entry from _ENV
* if not matchin key, returns empty
*
* @param string $key To search in _ENV array
* @return string|bool Returns either string or true/false (DEBUG flag)
*/
private function parseEnv(string $key)
{
$return = '';
switch ($key) {
case 'AWS_DEBUG':
$return = !empty($_ENV['AWS_DEBUG']) ? true : false;
break;
case 'AWS_GIFT_CARD_KEY':
case 'AWS_GIFT_CARD_SECRET':
case 'AWS_GIFT_CARD_PARTNER_ID':
case 'AWS_GIFT_CARD_ENDPOINT':
case 'AWS_GIFT_CARD_CURRENCY':
$return = (string)($_ENV[$key] ?? '');
break;
default:
break;
}
return $return;
}
/**
* string key to search, returns entry from _ENV
* if not matchin key, returns empty
*
* @param string $key To search in _ENV array
* @return string|bool Returns either string or true/false (DEBUG flag)
*/
private function parseEnv(string $key)
{
$return = '';
switch ($key) {
case 'AWS_DEBUG':
$return = !empty($_ENV['AWS_DEBUG']) ? true : false;
break;
case 'AWS_GIFT_CARD_KEY':
case 'AWS_GIFT_CARD_SECRET':
case 'AWS_GIFT_CARD_PARTNER_ID':
case 'AWS_GIFT_CARD_ENDPOINT':
case 'AWS_GIFT_CARD_CURRENCY':
$return = (string)($_ENV[$key] ?? '');
break;
default:
break;
}
return $return;
}
/**
* @return string Returns current set endpoint, without https://
*/
public function getEndpoint(): string
{
return $this->endpoint;
}
/**
* @return string Returns current set endpoint, without https://
*/
public function getEndpoint(): string
{
return $this->endpoint;
}
/**
* @param string $endpoint Full endpoint url with https://
* @return ConfigInterface Class interface (self)
*/
public function setEndpoint(string $endpoint): ConfigInterface
{
// TODO: check valid endpoint + set region
$this->endpoint = (parse_url($endpoint, PHP_URL_HOST)) ?: '';
/**
* @param string $endpoint Full endpoint url with https://
* @return ConfigInterface Class interface (self)
*/
public function setEndpoint(string $endpoint): ConfigInterface
{
// TODO: check valid endpoint + set region
$this->endpoint = (parse_url($endpoint, PHP_URL_HOST)) ?: '';
return $this;
}
return $this;
}
/**
* @return string Current access key
*/
public function getAccessKey(): string
{
return $this->access_key;
}
/**
* @return string Current access key
*/
public function getAccessKey(): string
{
return $this->access_key;
}
/**
* @param string $key Access Key to set
* @return ConfigInterface Class interface (self)
*/
public function setAccessKey(string $key): ConfigInterface
{
$this->access_key = $key;
/**
* @param string $key Access Key to set
* @return ConfigInterface Class interface (self)
*/
public function setAccessKey(string $key): ConfigInterface
{
$this->access_key = $key;
return $this;
}
return $this;
}
/**
* @return string Current secret key
*/
public function getSecret(): string
{
return $this->secret_key;
}
/**
* @return string Current secret key
*/
public function getSecret(): string
{
return $this->secret_key;
}
/**
* @param string $secret Secret key to set
* @return ConfigInterface Class interface (self)
*/
public function setSecret(string $secret): ConfigInterface
{
$this->secret_key = $secret;
/**
* @param string $secret Secret key to set
* @return ConfigInterface Class interface (self)
*/
public function setSecret(string $secret): ConfigInterface
{
$this->secret_key = $secret;
return $this;
}
return $this;
}
/**
* @return string Current set currency
*/
public function getCurrency(): string
{
return $this->currency;
}
/**
* @return string Current set currency
*/
public function getCurrency(): string
{
return $this->currency;
}
/**
* @param string $currency Currency to set (eg USD, JPY, etc)
* @return ConfigInterface Class interface (self)
*/
public function setCurrency(string $currency): ConfigInterface
{
// TODO: check currency valid + currenc valid for region
$this->currency = $currency;
/**
* @param string $currency Currency to set (eg USD, JPY, etc)
* @return ConfigInterface Class interface (self)
*/
public function setCurrency(string $currency): ConfigInterface
{
// TODO: check currency valid + currenc valid for region
$this->currency = $currency;
return $this;
}
return $this;
}
/**
* @return string Current set partner id
*/
public function getPartner(): string
{
return $this->partner_id;
}
/**
* @return string Current set partner id
*/
public function getPartner(): string
{
return $this->partner_id;
}
/**
* @param string $partner Partner id to set
* @return ConfigInterface Class interface (self)
*/
public function setPartner(string $partner): ConfigInterface
{
$this->partner_id = $partner;
/**
* @param string $partner Partner id to set
* @return ConfigInterface Class interface (self)
*/
public function setPartner(string $partner): ConfigInterface
{
$this->partner_id = $partner;
return $this;
}
return $this;
}
/**
* @return bool Current set debug flag as bool
*/
public function getDebug(): bool
{
return $this->debug;
}
/**
* @return bool Current set debug flag as bool
*/
public function getDebug(): bool
{
return $this->debug;
}
/**
* @param bool $debug Set debug flag as bool
* @return ConfigInterface Class interface (self)
*/
public function setDebug(bool $debug): ConfigInterface
{
$this->debug = $debug;
/**
* @param bool $debug Set debug flag as bool
* @return ConfigInterface Class interface (self)
*/
public function setDebug(bool $debug): ConfigInterface
{
$this->debug = $debug;
return $this;
}
return $this;
}
}
// __END__

View File

@@ -4,71 +4,71 @@ namespace gullevek\AmazonIncentives\Config;
interface ConfigInterface
{
/**
* @return string Returns current set endpoint, without https://
*/
public function getEndpoint(): string;
/**
* @return string Returns current set endpoint, without https://
*/
public function getEndpoint(): string;
/**
* @param string $endpoint Full endpoint url with https://
* @return ConfigInterface Class interface (self)
*/
public function setEndpoint(string $endpoint): ConfigInterface;
/**
* @param string $endpoint Full endpoint url with https://
* @return ConfigInterface Class interface (self)
*/
public function setEndpoint(string $endpoint): ConfigInterface;
/**
* @return string Current access key
*/
public function getAccessKey(): string;
/**
* @return string Current access key
*/
public function getAccessKey(): string;
/**
* @param string $key Access Key to set
* @return ConfigInterface Class interface (self)
*/
public function setAccessKey(string $key): ConfigInterface;
/**
* @param string $key Access Key to set
* @return ConfigInterface Class interface (self)
*/
public function setAccessKey(string $key): ConfigInterface;
/**
* @return string Current secret key
*/
public function getSecret(): string;
/**
* @return string Current secret key
*/
public function getSecret(): string;
/**
* @param string $secret Secret key to set
* @return ConfigInterface Class interface (self)
*/
public function setSecret(string $secret): ConfigInterface;
/**
* @param string $secret Secret key to set
* @return ConfigInterface Class interface (self)
*/
public function setSecret(string $secret): ConfigInterface;
/**
* @return string Current set currency
*/
public function getCurrency(): string;
/**
* @return string Current set currency
*/
public function getCurrency(): string;
/**
* @param string $currency Currency to set (eg USD, JPY, etc)
* @return ConfigInterface Class interface (self)
*/
public function setCurrency(string $currency): ConfigInterface;
/**
* @param string $currency Currency to set (eg USD, JPY, etc)
* @return ConfigInterface Class interface (self)
*/
public function setCurrency(string $currency): ConfigInterface;
/**
* @return string Current set partner id
*/
public function getPartner(): string;
/**
* @return string Current set partner id
*/
public function getPartner(): string;
/**
* @param string $partner Partner id to set
* @return ConfigInterface Class interface (self)
*/
public function setPartner(string $partner): ConfigInterface;
/**
* @param string $partner Partner id to set
* @return ConfigInterface Class interface (self)
*/
public function setPartner(string $partner): ConfigInterface;
/**
* @return bool Current set debug flag as bool
*/
public function getDebug(): bool;
/**
* @return bool Current set debug flag as bool
*/
public function getDebug(): bool;
/**
* @param bool $debug Set debug flag as bool
* @return ConfigInterface Class interface (self)
*/
public function setDebug(bool $debug): ConfigInterface;
/**
* @param bool $debug Set debug flag as bool
* @return ConfigInterface Class interface (self)
*/
public function setDebug(bool $debug): ConfigInterface;
}
// __END__

View File

@@ -7,103 +7,103 @@ namespace gullevek\AmazonIncentives\Debug;
class AmazonDebug
{
/** @var array<mixed> Log data array log id -> array of log entries */
private static $log = [];
/** @var bool debug flag */
private static $debug = false;
/** @var string|null Last set internal log array id */
private static $id = null;
/** @var array<mixed> Log data array log id -> array of log entries */
private static $log = [];
/** @var bool debug flag */
private static $debug = false;
/** @var string|null Last set internal log array id */
private static $id = null;
/**
* set the ID for current run
* if debug is off, nothing will be set and id is null
* This is run on setFlag, if debug is true
*
* @param string|null $id If not set, will default to uniqid() call
* @return void
*/
private static function setId(?string $id = null): void
{
if (self::$debug === false) {
return;
}
if ($id === null) {
$id = uniqid();
}
self::$id = $id;
}
/**
* set the ID for current run
* if debug is off, nothing will be set and id is null
* This is run on setFlag, if debug is true
*
* @param string|null $id If not set, will default to uniqid() call
* @return void
*/
private static function setId(?string $id = null): void
{
if (self::$debug === false) {
return;
}
if ($id === null) {
$id = uniqid();
}
self::$id = $id;
}
/**
* set the debug flag.
* This is automatically run in gullevek\AmazonIncentives\AmazonIncentives::__construct
* No need to run manuall
*
* @param boolean $debug Can only be True or False
* @param string|null $id If not set, will default to uniqid() call
* @return void
*/
public static function setDebug(bool $debug, ?string $id = null): void
{
self::$debug = $debug;
if (self::$debug === false) {
return;
}
self::setId($id);
}
/**
* set the debug flag.
* This is automatically run in gullevek\AmazonIncentives\AmazonIncentives::__construct
* No need to run manuall
*
* @param boolean $debug Can only be True or False
* @param string|null $id If not set, will default to uniqid() call
* @return void
*/
public static function setDebug(bool $debug, ?string $id = null): void
{
self::$debug = $debug;
if (self::$debug === false) {
return;
}
self::setId($id);
}
/**
* returns current debug flag status
*
* @return boolean True if debug is on, False if debug is off
*/
public static function getDebug(): bool
{
return self::$debug;
}
/**
* returns current debug flag status
*
* @return boolean True if debug is on, False if debug is off
*/
public static function getDebug(): bool
{
return self::$debug;
}
/**
* get the current set ID, can return null if debug is off
*
* @return string|null Current set ID for this log run
*/
public static function getId(): ?string
{
return self::$id;
}
/**
* get the current set ID, can return null if debug is off
*
* @return string|null Current set ID for this log run
*/
public static function getId(): ?string
{
return self::$id;
}
/**
* write a log entry
* Data is as array key -> value
* Will be pushed as new array entry int log
* Main key is the set Id for this run
*
* @param array<mixed> $data Any array data to store in the log
* @return void
*/
public static function writeLog(array $data): void
{
if (self::$debug === false) {
return;
}
self::$log[self::getId() ?? ''][] = $data;
}
/**
* write a log entry
* Data is as array key -> value
* Will be pushed as new array entry int log
* Main key is the set Id for this run
*
* @param array<mixed> $data Any array data to store in the log
* @return void
*/
public static function writeLog(array $data): void
{
if (self::$debug === false) {
return;
}
self::$log[self::getId() ?? ''][] = $data;
}
/**
* get all logs written since first class run
* or get all log entries for given ID
*
* @param string|null $id If set returns only this id logs
* or empty array if not found
* @return array<mixed> Always array, empty if not data or not found
*/
public static function getLog(?string $id = null): array
{
if ($id === null) {
return self::$log;
} else {
return self::$log[$id] ?? [];
}
}
/**
* get all logs written since first class run
* or get all log entries for given ID
*
* @param string|null $id If set returns only this id logs
* or empty array if not found
* @return array<mixed> Always array, empty if not data or not found
*/
public static function getLog(?string $id = null): array
{
if ($id === null) {
return self::$log;
} else {
return self::$log[$id] ?? [];
}
}
}
// __END__

View File

@@ -7,63 +7,63 @@ use gullevek\AmazonIncentives\Debug\AmazonDebug;
final class AmazonErrors extends RuntimeException
{
/**
* Returns an Runtime exception including a json encoded string with all
* parameters including last log id and log
*
* @param string $error_status agcodResponse->status from Amazon
* @param string $error_code errorCode from Amazon
* @param string $error_type errorType from Amazon
* @param string $message Message string to ad
* @param int $_error_code Error code to set
* @return AmazonErrors Exception Class
*/
public static function getError(
string $error_status,
string $error_code,
string $error_type,
string $message,
int $_error_code
): self {
// NOTE: if xdebug.show_exception_trace is set to 1 this will print ERRORS
return new static(
(json_encode([
'status' => $error_status,
'code' => $error_code,
'type' => $error_type,
'message' => $message,
// atach log data if exists
'log_id' => AmazonDebug::getId(),
'log' => AmazonDebug::getLog(),
])) ?: 'AmazonErrors: json encode problem: ' . $message,
$_error_code
);
}
/**
* Returns an Runtime exception including a json encoded string with all
* parameters including last log id and log
*
* @param string $error_status agcodResponse->status from Amazon
* @param string $error_code errorCode from Amazon
* @param string $error_type errorType from Amazon
* @param string $message Message string to ad
* @param int $_error_code Error code to set
* @return AmazonErrors Exception Class
*/
public static function getError(
string $error_status,
string $error_code,
string $error_type,
string $message,
int $_error_code
): self {
// NOTE: if xdebug.show_exception_trace is set to 1 this will print ERRORS
return new static(
(json_encode([
'status' => $error_status,
'code' => $error_code,
'type' => $error_type,
'message' => $message,
// atach log data if exists
'log_id' => AmazonDebug::getId(),
'log' => AmazonDebug::getLog(),
])) ?: 'AmazonErrors: json encode problem: ' . $message,
$_error_code
);
}
/**
* Decodes the Exception message body
* Returns an array with code (Amazon error codes), type (Amazon error info)
* message (Amazon returned error message string)
*
* @param string $message Exception message json string
* @return array<mixed> Decoded with code, type, message fields
*/
public static function decodeExceptionMessage(string $message): array
{
$message_ar = json_decode($message, true);
// if we have an error, build empty block and only fill message
if (json_last_error()) {
$message_ar = [
'status' => '',
'code' => '',
'type' => '',
'message' => $message,
'log_id' => '',
'log' => []
];
}
return $message_ar;
}
/**
* Decodes the Exception message body
* Returns an array with code (Amazon error codes), type (Amazon error info)
* message (Amazon returned error message string)
*
* @param string $message Exception message json string
* @return array<mixed> Decoded with code, type, message fields
*/
public static function decodeExceptionMessage(string $message): array
{
$message_ar = json_decode($message, true);
// if we have an error, build empty block and only fill message
if (json_last_error()) {
$message_ar = [
'status' => '',
'code' => '',
'type' => '',
'message' => $message,
'log_id' => '',
'log' => []
];
}
return $message_ar;
}
}
// __END__

View File

@@ -6,98 +6,98 @@ use gullevek\AmazonIncentives\Debug\AmazonDebug;
class CancelResponse
{
/** @var string Amazon Gift Card gcId (gift card id). */
protected $id = '';
/** @var string Amazon Gift Card creationRequestId (creation request id) */
protected $creation_request_id = '';
/** @var string Amazon Gift Card status */
protected $status = '';
/** @var array<mixed> Amazon Gift Card Raw JSON */
protected $raw_json = [];
/** @var string Amazon Gift Card gcId (gift card id). */
protected $id = '';
/** @var string Amazon Gift Card creationRequestId (creation request id) */
protected $creation_request_id = '';
/** @var string Amazon Gift Card status */
protected $status = '';
/** @var array<mixed> Amazon Gift Card Raw JSON */
protected $raw_json = [];
/**
* Response constructor for canceling gitf cards
*
* @param array<mixed> $json_response JSON response from web request to AWS
*/
public function __construct(array $json_response)
{
$this->raw_json = $json_response;
$this->parseJsonResponse($json_response);
}
/**
* Response constructor for canceling gitf cards
*
* @param array<mixed> $json_response JSON response from web request to AWS
*/
public function __construct(array $json_response)
{
$this->raw_json = $json_response;
$this->parseJsonResponse($json_response);
}
/**
* Get log entry with current set log id
*
* @return array<mixed> Log array
*/
public function getLog(): array
{
return AmazonDebug::getLog(AmazonDebug::getId());
}
/**
* Get log entry with current set log id
*
* @return array<mixed> Log array
*/
public function getLog(): array
{
return AmazonDebug::getLog(AmazonDebug::getId());
}
/**
* The gift card id as created by the previous get code call
*
* @return string Gift card id
*/
public function getId(): string
{
return $this->id;
}
/**
* The gift card id as created by the previous get code call
*
* @return string Gift card id
*/
public function getId(): string
{
return $this->id;
}
/**
* Creation Request id from original get code call
*
* @return string Creation request id
*/
public function getCreationRequestId(): string
{
return $this->creation_request_id;
}
/**
* Creation Request id from original get code call
*
* @return string Creation request id
*/
public function getCreationRequestId(): string
{
return $this->creation_request_id;
}
/**
* Request status
*
* @return string Request status as string: SUCCESS, FAILURE, RESEND
*/
public function getStatus(): string
{
return $this->status;
}
/**
* Request status
*
* @return string Request status as string: SUCCESS, FAILURE, RESEND
*/
public function getStatus(): string
{
return $this->status;
}
/**
* Returns the request data as json string. This is a re-encode from decoded
* makeRequest call
*
* @return string JSON encoded string from the return values
*/
public function getRawJson(): string
{
return (json_encode($this->raw_json)) ?: '';
}
/**
* Returns the request data as json string. This is a re-encode from decoded
* makeRequest call
*
* @return string JSON encoded string from the return values
*/
public function getRawJson(): string
{
return (json_encode($this->raw_json)) ?: '';
}
/**
* Set class variables with response data from makeRequest and return self
*
* @param array<mixed> $json_response JSON response as array
* @return CancelResponse Return self object
*/
public function parseJsonResponse(array $json_response): self
{
if (array_key_exists('gcId', $json_response)) {
$this->id = $json_response['gcId'];
}
if (array_key_exists('creationRequestId', $json_response)) {
$this->creation_request_id = $json_response['creationRequestId'];
}
// SUCCESS, FAILURE, RESEND
if (array_key_exists('status', $json_response)) {
$this->status = $json_response['status'];
}
/**
* Set class variables with response data from makeRequest and return self
*
* @param array<mixed> $json_response JSON response as array
* @return CancelResponse Return self object
*/
public function parseJsonResponse(array $json_response): self
{
if (array_key_exists('gcId', $json_response)) {
$this->id = $json_response['gcId'];
}
if (array_key_exists('creationRequestId', $json_response)) {
$this->creation_request_id = $json_response['creationRequestId'];
}
// SUCCESS, FAILURE, RESEND
if (array_key_exists('status', $json_response)) {
$this->status = $json_response['status'];
}
return $this;
}
return $this;
}
}
// __END__

View File

@@ -6,112 +6,112 @@ use gullevek\AmazonIncentives\Debug\AmazonDebug;
class CreateBalanceResponse
{
/** @var string Amazon Gift Card Balance Amount */
protected $amount = '';
/** @var string Amazon Gift Card Balance Currency */
protected $currency = '';
/** @var string Amazon Gift Card Balance Status */
protected $status = '';
/** @var string Amazon Gift Card Balance Timestamp */
protected $timestamp = '';
/** @var array<mixed> Amazon Gift Card Raw JSON */
protected $raw_json = [];
/** @var string Amazon Gift Card Balance Amount */
protected $amount = '';
/** @var string Amazon Gift Card Balance Currency */
protected $currency = '';
/** @var string Amazon Gift Card Balance Status */
protected $status = '';
/** @var string Amazon Gift Card Balance Timestamp */
protected $timestamp = '';
/** @var array<mixed> Amazon Gift Card Raw JSON */
protected $raw_json = [];
/**
* Response constructor for requesting account funds status
*
* @param array<mixed> $json_response JSON response from web request to AWS
*/
public function __construct(array $json_response)
{
$this->raw_json = $json_response;
$this->parseJsonResponse($json_response);
}
/**
* Response constructor for requesting account funds status
*
* @param array<mixed> $json_response JSON response from web request to AWS
*/
public function __construct(array $json_response)
{
$this->raw_json = $json_response;
$this->parseJsonResponse($json_response);
}
/**
* Get log entry with current set log id
*
* @return array<mixed> Log array
*/
public function getLog(): array
{
return AmazonDebug::getLog(AmazonDebug::getId());
}
/**
* Get log entry with current set log id
*
* @return array<mixed> Log array
*/
public function getLog(): array
{
return AmazonDebug::getLog(AmazonDebug::getId());
}
/**
* Return the current available funds amount
*
* @return string Funds amount in set currency
*/
public function getAmount(): string
{
return $this->amount;
}
/**
* Return the current available funds amount
*
* @return string Funds amount in set currency
*/
public function getAmount(): string
{
return $this->amount;
}
/**
* Get the set currency type
*
* @return string Currency type. Eg USD, JPY, etc
*/
public function getCurrency(): string
{
return $this->currency;
}
/**
* Get the set currency type
*
* @return string Currency type. Eg USD, JPY, etc
*/
public function getCurrency(): string
{
return $this->currency;
}
/**
* Get timestamp as set.
* eg 20220609T061446Z
*
* @return string Timestamp string. Ymd\THis\Z
*/
public function getTimestamp(): string
{
return $this->timestamp;
}
/**
* Get timestamp as set.
* eg 20220609T061446Z
*
* @return string Timestamp string. Ymd\THis\Z
*/
public function getTimestamp(): string
{
return $this->timestamp;
}
/**
* Request status
*
* @return string Request status as string: SUCCESS, FAILURE, RESEND
*/
public function getStatus(): string
{
return $this->status;
}
/**
* Request status
*
* @return string Request status as string: SUCCESS, FAILURE, RESEND
*/
public function getStatus(): string
{
return $this->status;
}
/**
* Returns the request data as json string. This is a re-encode from decoded
* makeRequest call
*
* @return string JSON encoded string from the return values
*/
public function getRawJson(): string
{
return (json_encode($this->raw_json)) ?: '';
}
/**
* Returns the request data as json string. This is a re-encode from decoded
* makeRequest call
*
* @return string JSON encoded string from the return values
*/
public function getRawJson(): string
{
return (json_encode($this->raw_json)) ?: '';
}
/**
* Set class variables with response data from makeRequest and return self
*
* @param array<mixed> $json_response JSON response as array
* @return CreateBalanceResponse Return self object
*/
public function parseJsonResponse(array $json_response): self
{
if (array_key_exists('amount', $json_response['availableFunds'])) {
$this->amount = $json_response['availableFunds']['amount'];
}
if (array_key_exists('currencyCode', $json_response['availableFunds'])) {
$this->currency = $json_response['availableFunds']['currencyCode'];
}
// SUCCESS, FAILURE, RESEND
if (array_key_exists('status', $json_response)) {
$this->status = $json_response['status'];
}
if (array_key_exists('timestamp', $json_response)) {
$this->timestamp = $json_response['timestamp'];
}
/**
* Set class variables with response data from makeRequest and return self
*
* @param array<mixed> $json_response JSON response as array
* @return CreateBalanceResponse Return self object
*/
public function parseJsonResponse(array $json_response): self
{
if (array_key_exists('amount', $json_response['availableFunds'])) {
$this->amount = $json_response['availableFunds']['amount'];
}
if (array_key_exists('currencyCode', $json_response['availableFunds'])) {
$this->currency = $json_response['availableFunds']['currencyCode'];
}
// SUCCESS, FAILURE, RESEND
if (array_key_exists('status', $json_response)) {
$this->status = $json_response['status'];
}
if (array_key_exists('timestamp', $json_response)) {
$this->timestamp = $json_response['timestamp'];
}
return $this;
}
return $this;
}
}

View File

@@ -6,177 +6,177 @@ use gullevek\AmazonIncentives\Debug\AmazonDebug;
class CreateResponse
{
/** @var string Amazon Gift Card gcId */
protected $id = '';
/** @var string Amazon Gift Card creationRequestId */
protected $creation_request_id = '';
/** @var string Amazon Gift Card gcClaimCode */
protected $claim_code = '';
/** @var float Amazon Gift Card amount */
protected $value = 0;
/** @var string Amazon Gift Card currency */
protected $currency = '';
/** @var string Amazon Gift Card status */
protected $status = '';
/** @var string Amazon Gift Card Expiration Date */
protected $expiration_date = '';
/** @var string Amazon Gift Card Expiration Date */
protected $card_status = '';
/** @var array<mixed> Amazon Gift Card Raw JSON as array */
protected $raw_json = [];
/** @var string Amazon Gift Card gcId */
protected $id = '';
/** @var string Amazon Gift Card creationRequestId */
protected $creation_request_id = '';
/** @var string Amazon Gift Card gcClaimCode */
protected $claim_code = '';
/** @var float Amazon Gift Card amount */
protected $value = 0;
/** @var string Amazon Gift Card currency */
protected $currency = '';
/** @var string Amazon Gift Card status */
protected $status = '';
/** @var string Amazon Gift Card Expiration Date */
protected $expiration_date = '';
/** @var string Amazon Gift Card Expiration Date */
protected $card_status = '';
/** @var array<mixed> Amazon Gift Card Raw JSON as array */
protected $raw_json = [];
/**
* Response constructor for creating gift cards
*
* @param array<mixed> $json_response JSON response from web request to AWS
*/
public function __construct(array $json_response)
{
$this->raw_json = $json_response;
$this->parseJsonResponse($json_response);
}
/**
* Response constructor for creating gift cards
*
* @param array<mixed> $json_response JSON response from web request to AWS
*/
public function __construct(array $json_response)
{
$this->raw_json = $json_response;
$this->parseJsonResponse($json_response);
}
/**
* Get log entry with current set log id
*
* @return array<mixed> Log array
*/
public function getLog(): array
{
return AmazonDebug::getLog(AmazonDebug::getId());
}
/**
* Get log entry with current set log id
*
* @return array<mixed> Log array
*/
public function getLog(): array
{
return AmazonDebug::getLog(AmazonDebug::getId());
}
/**
* Gift Card ID returned from AWS. Can be used in the cancel request
*
* @return string Gift card id
*/
public function getId(): string
{
return $this->id;
}
/**
* Gift Card ID returned from AWS. Can be used in the cancel request
*
* @return string Gift card id
*/
public function getId(): string
{
return $this->id;
}
/**
* Either the one set with the method parameter, or automatically created
* during get code request
*
* @return string Creation request id
*/
public function getCreationRequestId(): string
{
return $this->creation_request_id;
}
/**
* Either the one set with the method parameter, or automatically created
* during get code request
*
* @return string Creation request id
*/
public function getCreationRequestId(): string
{
return $this->creation_request_id;
}
/**
* The actual gift code, recommended not to be stored anywhere and only shown
* to user
*
* @return string Gift order claim code on AWS
*/
public function getClaimCode(): string
{
return $this->claim_code;
}
/**
* The actual gift code, recommended not to be stored anywhere and only shown
* to user
*
* @return string Gift order claim code on AWS
*/
public function getClaimCode(): string
{
return $this->claim_code;
}
/**
* The ordered gift code value in given currency
*
* @return float Gift order value in currency
*/
public function getValue(): float
{
return $this->value;
}
/**
* The ordered gift code value in given currency
*
* @return float Gift order value in currency
*/
public function getValue(): float
{
return $this->value;
}
/**
* The currently set currency
*
* @return string Currency type. Eg USD, JPY, etc
*/
public function getCurrency(): string
{
return $this->currency;
}
/**
* The currently set currency
*
* @return string Currency type. Eg USD, JPY, etc
*/
public function getCurrency(): string
{
return $this->currency;
}
/**
* Expiration date for the ordered gift code.
* eg 20220609T061446Z
*
* @return string Timestamp until when the gift code is valid. Ymd\THis\Z
*/
public function getExpirationDate(): string
{
return $this->expiration_date;
}
/**
* Expiration date for the ordered gift code.
* eg 20220609T061446Z
*
* @return string Timestamp until when the gift code is valid. Ymd\THis\Z
*/
public function getExpirationDate(): string
{
return $this->expiration_date;
}
/**
* Gift card status. If the same creation request id is sent again and the
* gift card got cancled, this is reflected here
*
* @return string Gift card status
*/
public function getCardStatus(): string
{
return $this->card_status;
}
/**
* Gift card status. If the same creation request id is sent again and the
* gift card got cancled, this is reflected here
*
* @return string Gift card status
*/
public function getCardStatus(): string
{
return $this->card_status;
}
/**
* Request status
*
* @return string Request status as string: SUCCESS, FAILURE, RESEND
*/
public function getStatus(): string
{
return $this->status;
}
/**
* Request status
*
* @return string Request status as string: SUCCESS, FAILURE, RESEND
*/
public function getStatus(): string
{
return $this->status;
}
/**
* @Returns the request data as json string. This is a re-encode from decoded
* makeRequest call
*
* @return string JSON encoded string from the return values
*/
public function getRawJson(): string
{
return (json_encode($this->raw_json)) ?: '';
}
/**
* @Returns the request data as json string. This is a re-encode from decoded
* makeRequest call
*
* @return string JSON encoded string from the return values
*/
public function getRawJson(): string
{
return (json_encode($this->raw_json)) ?: '';
}
/**
* Set class variables with response data from makeRequest and return self
*
* @param array<mixed> $json_response JSON response as array
* @return CreateResponse Return self object
*/
public function parseJsonResponse(array $json_response): self
{
if (array_key_exists('gcId', $json_response)) {
$this->id = $json_response['gcId'];
}
if (array_key_exists('creationRequestId', $json_response)) {
$this->creation_request_id = $json_response['creationRequestId'];
}
if (array_key_exists('gcClaimCode', $json_response)) {
$this->claim_code = $json_response['gcClaimCode'];
}
if (array_key_exists('amount', $json_response['cardInfo']['value'])) {
$this->value = $json_response['cardInfo']['value']['amount'];
}
if (array_key_exists('currencyCode', $json_response['cardInfo']['value'])) {
$this->currency = $json_response['cardInfo']['value']['currencyCode'];
}
if (array_key_exists('gcExpirationDate', $json_response)) {
$this->expiration_date = $json_response['gcExpirationDate'];
}
if (array_key_exists('cardStatus', $json_response['cardInfo'])) {
$this->card_status = $json_response['cardInfo']['cardStatus'];
}
// SUCCESS, FAILURE, RESEND
if (array_key_exists('status', $json_response)) {
$this->status = $json_response['status'];
}
/**
* Set class variables with response data from makeRequest and return self
*
* @param array<mixed> $json_response JSON response as array
* @return CreateResponse Return self object
*/
public function parseJsonResponse(array $json_response): self
{
if (array_key_exists('gcId', $json_response)) {
$this->id = $json_response['gcId'];
}
if (array_key_exists('creationRequestId', $json_response)) {
$this->creation_request_id = $json_response['creationRequestId'];
}
if (array_key_exists('gcClaimCode', $json_response)) {
$this->claim_code = $json_response['gcClaimCode'];
}
if (array_key_exists('amount', $json_response['cardInfo']['value'])) {
$this->value = $json_response['cardInfo']['value']['amount'];
}
if (array_key_exists('currencyCode', $json_response['cardInfo']['value'])) {
$this->currency = $json_response['cardInfo']['value']['currencyCode'];
}
if (array_key_exists('gcExpirationDate', $json_response)) {
$this->expiration_date = $json_response['gcExpirationDate'];
}
if (array_key_exists('cardStatus', $json_response['cardInfo'])) {
$this->card_status = $json_response['cardInfo']['cardStatus'];
}
// SUCCESS, FAILURE, RESEND
if (array_key_exists('status', $json_response)) {
$this->status = $json_response['status'];
}
return $this;
}
return $this;
}
}
// __END__