2021-10-18 18:24:38 +09:00
|
|
|
<?php
|
|
|
|
|
|
2021-10-21 09:55:32 +09:00
|
|
|
namespace gullevek\AmazonIncentives\Response;
|
|
|
|
|
|
|
|
|
|
use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
2021-10-18 18:24:38 +09:00
|
|
|
|
|
|
|
|
class CreateBalanceResponse
|
|
|
|
|
{
|
2022-06-09 16:02:25 +09:00
|
|
|
/** @var string Amazon Gift Card Balance Amount */
|
2021-10-21 14:57:29 +09:00
|
|
|
protected $amount = '';
|
2022-06-09 16:02:25 +09:00
|
|
|
/** @var string Amazon Gift Card Balance Currency */
|
2021-10-21 14:57:29 +09:00
|
|
|
protected $currency = '';
|
2022-06-09 16:02:25 +09:00
|
|
|
/** @var string Amazon Gift Card Balance Status */
|
2021-10-21 14:57:29 +09:00
|
|
|
protected $status = '';
|
2022-06-09 16:02:25 +09:00
|
|
|
/** @var string Amazon Gift Card Balance Timestamp */
|
2021-10-21 14:57:29 +09:00
|
|
|
protected $timestamp = '';
|
2022-06-09 16:02:25 +09:00
|
|
|
/** @var array<mixed> Amazon Gift Card Raw JSON */
|
2021-10-21 14:57:29 +09:00
|
|
|
protected $raw_json = [];
|
2021-10-18 18:24:38 +09:00
|
|
|
|
|
|
|
|
/**
|
2022-06-09 16:02:25 +09:00
|
|
|
* Response constructor for requesting account funds status
|
2021-10-18 18:24:38 +09:00
|
|
|
*
|
2022-06-09 16:02:25 +09:00
|
|
|
* @param array<mixed> $json_response JSON response from web request to AWS
|
2021-10-18 18:24:38 +09:00
|
|
|
*/
|
|
|
|
|
public function __construct(array $json_response)
|
|
|
|
|
{
|
|
|
|
|
$this->raw_json = $json_response;
|
|
|
|
|
$this->parseJsonResponse($json_response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-06-09 16:02:25 +09:00
|
|
|
* Get log entry with current set log id
|
|
|
|
|
*
|
|
|
|
|
* @return array<mixed> Log array
|
2021-10-18 18:24:38 +09:00
|
|
|
*/
|
|
|
|
|
public function getLog(): array
|
|
|
|
|
{
|
2021-10-21 13:29:50 +09:00
|
|
|
return AmazonDebug::getLog(AmazonDebug::getId());
|
2021-10-18 18:24:38 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-06-09 16:02:25 +09:00
|
|
|
* Return the current available funds amount
|
|
|
|
|
*
|
|
|
|
|
* @return string Funds amount in set currency
|
2021-10-18 18:24:38 +09:00
|
|
|
*/
|
|
|
|
|
public function getAmount(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-06-09 16:02:25 +09:00
|
|
|
* Get the set currency type
|
|
|
|
|
*
|
|
|
|
|
* @return string Currency type. Eg USD, JPY, etc
|
2021-10-18 18:24:38 +09:00
|
|
|
*/
|
|
|
|
|
public function getCurrency(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->currency;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-06-09 16:02:25 +09:00
|
|
|
* Get timestamp as set.
|
|
|
|
|
* eg 20220609T061446Z
|
|
|
|
|
*
|
|
|
|
|
* @return string Timestamp string. Ymd\THis\Z
|
2021-10-18 18:24:38 +09:00
|
|
|
*/
|
2022-06-09 16:02:25 +09:00
|
|
|
public function getTimestamp(): string
|
2021-10-18 18:24:38 +09:00
|
|
|
{
|
2022-06-09 16:02:25 +09:00
|
|
|
return $this->timestamp;
|
2021-10-18 18:24:38 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-06-09 16:02:25 +09:00
|
|
|
* Request status
|
|
|
|
|
*
|
|
|
|
|
* @return string Request status as string: SUCCESS, FAILURE, RESEND
|
2021-10-18 18:24:38 +09:00
|
|
|
*/
|
2022-06-09 16:02:25 +09:00
|
|
|
public function getStatus(): string
|
2021-10-18 18:24:38 +09:00
|
|
|
{
|
2022-06-09 16:02:25 +09:00
|
|
|
return $this->status;
|
2021-10-18 18:24:38 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-06-09 16:02:25 +09:00
|
|
|
* 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
|
2021-10-18 18:24:38 +09:00
|
|
|
*/
|
|
|
|
|
public function getRawJson(): string
|
|
|
|
|
{
|
2021-10-21 13:29:50 +09:00
|
|
|
return (json_encode($this->raw_json)) ?: '';
|
2021-10-18 18:24:38 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-06-09 16:02:25 +09:00
|
|
|
* Set class variables with response data from makeRequest and return self
|
2021-10-18 18:24:38 +09:00
|
|
|
*
|
2022-06-09 16:02:25 +09:00
|
|
|
* @param array<mixed> $json_response JSON response as array
|
|
|
|
|
* @return CreateBalanceResponse Return self object
|
2021-10-18 18:24:38 +09:00
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|