Merge branch 'development' with phpDoc changes
This commit is contained in:
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -1,5 +1,6 @@
|
|||||||
test/ export-ignore
|
test/ export-ignore
|
||||||
.gitattributes export-ignore
|
|
||||||
phpstan.neon export-ignore
|
phpstan.neon export-ignore
|
||||||
|
phpunit.xml export-ignore
|
||||||
psalm.xml export-ignore
|
psalm.xml export-ignore
|
||||||
.phan/ export-ignore
|
.phan/ export-ignore
|
||||||
|
.* export-ignore
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
"exclude": ["/test/", "/test/*", "/phpstan.neon", "/psalm.xml", "/.phan/", "/.vscode/", "/phpunit.xml"]
|
"exclude": ["/test/", "/test/*", "/phpstan.neon", "/psalm.xml", "/.phan/", "/.vscode/", "/phpunit.xml"]
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^9"
|
"phpunit/phpunit": "^9",
|
||||||
|
"gullevek/dotenv": "dev-master"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
||||||
>
|
>
|
||||||
<projectFiles>
|
<projectFiles>
|
||||||
<directory name="src" />
|
<directory name="." />
|
||||||
<ignoreFiles>
|
<ignoreFiles>
|
||||||
<directory name="vendor" />
|
<directory name="vendor" />
|
||||||
<directory name="test" />
|
<directory name="test" />
|
||||||
|
|||||||
259
src/AWS/AWS.php
259
src/AWS/AWS.php
@@ -12,26 +12,40 @@ use gullevek\AmazonIncentives\Response\CreateResponse;
|
|||||||
|
|
||||||
class AWS
|
class AWS
|
||||||
{
|
{
|
||||||
|
/** @var string What AWS Service to use: Gift Card on Demand (GCOD) */
|
||||||
public const SERVICE_NAME = 'AGCODService';
|
public const SERVICE_NAME = 'AGCODService';
|
||||||
|
/** @var string */
|
||||||
public const ACCEPT_HEADER = 'accept';
|
public const ACCEPT_HEADER = 'accept';
|
||||||
|
/** @var string content-type */
|
||||||
public const CONTENT_HEADER = 'content-type';
|
public const CONTENT_HEADER = 'content-type';
|
||||||
|
/** @var string */
|
||||||
public const HOST_HEADER = 'host';
|
public const HOST_HEADER = 'host';
|
||||||
|
/** @var string */
|
||||||
public const X_AMZ_DATE_HEADER = 'x-amz-date';
|
public const X_AMZ_DATE_HEADER = 'x-amz-date';
|
||||||
|
/** @var string */
|
||||||
public const X_AMZ_TARGET_HEADER = 'x-amz-target';
|
public const X_AMZ_TARGET_HEADER = 'x-amz-target';
|
||||||
|
/** @var string */
|
||||||
public const AUTHORIZATION_HEADER = 'Authorization';
|
public const AUTHORIZATION_HEADER = 'Authorization';
|
||||||
|
/** @var string type of encryption type */
|
||||||
public const AWS_SHA256_ALGORITHM = 'AWS4-HMAC-SHA256';
|
public const AWS_SHA256_ALGORITHM = 'AWS4-HMAC-SHA256';
|
||||||
|
/** @var string key type to use */
|
||||||
public const KEY_QUALIFIER = 'AWS4';
|
public const KEY_QUALIFIER = 'AWS4';
|
||||||
|
/** @var string */
|
||||||
public const TERMINATION_STRING = 'aws4_request';
|
public const TERMINATION_STRING = 'aws4_request';
|
||||||
|
/** @var string Service to use: Create Gift Card */
|
||||||
public const CREATE_GIFT_CARD_SERVICE = 'CreateGiftCard';
|
public const CREATE_GIFT_CARD_SERVICE = 'CreateGiftCard';
|
||||||
|
/** @var string Service to use: Cancle Gift Card */
|
||||||
public const CANCEL_GIFT_CARD_SERVICE = 'CancelGiftCard';
|
public const CANCEL_GIFT_CARD_SERVICE = 'CancelGiftCard';
|
||||||
|
/** @var string Service to use: Get Available Funds */
|
||||||
public const GET_AVAILABLE_FUNDS_SERVICE = 'GetAvailableFunds';
|
public const GET_AVAILABLE_FUNDS_SERVICE = 'GetAvailableFunds';
|
||||||
|
|
||||||
/**
|
/** @var Config Configuration class with all settings */
|
||||||
* @var Config
|
|
||||||
*/
|
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Initialize the main AWS class. This class prepares and sends all the actions
|
||||||
|
* and returns reponses as defined in in the CreateResponse class
|
||||||
|
*
|
||||||
* @param Config $config
|
* @param Config $config
|
||||||
*/
|
*/
|
||||||
public function __construct(Config $config)
|
public function __construct(Config $config)
|
||||||
@@ -41,9 +55,13 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param float $amount
|
* Bug a gift card
|
||||||
* @param string|null $creation_id
|
*
|
||||||
* @return CreateResponse
|
* @param float $amount Amount to buy a gifr card in set currencty
|
||||||
|
* @param string|null $creation_id Override creation id, if not set will
|
||||||
|
* be created automatically. If not valid error
|
||||||
|
* will be thrown
|
||||||
|
* @return CreateResponse Object with AWS response data
|
||||||
*
|
*
|
||||||
* @throws AmazonErrors
|
* @throws AmazonErrors
|
||||||
*/
|
*/
|
||||||
@@ -64,9 +82,11 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $creation_request_id
|
* Cancle an ordered gift card, only possible within the the time limit
|
||||||
* @param string $gift_card_id
|
*
|
||||||
* @return CancelResponse
|
* @param string $creation_request_id Previously created creation request id
|
||||||
|
* @param string $gift_card_id Previously created gift card id
|
||||||
|
* @return CancelResponse Object with AWS response data
|
||||||
*
|
*
|
||||||
* @throws AmazonErrors
|
* @throws AmazonErrors
|
||||||
*/
|
*/
|
||||||
@@ -87,7 +107,9 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return CreateBalanceResponse
|
* Get current account funds
|
||||||
|
*
|
||||||
|
* @return CreateBalanceResponse Object with AWS response data
|
||||||
*
|
*
|
||||||
* @throws AmazonErrors
|
* @throws AmazonErrors
|
||||||
*/
|
*/
|
||||||
@@ -108,11 +130,17 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $payload
|
* General request method for all actions
|
||||||
* @param string $canonical_request
|
* Calls the Client class that actually runs the json request
|
||||||
* @param string $service_operation
|
* For service_operation valid data see AWS GCOD documentation
|
||||||
* @param string $date_time_string
|
*
|
||||||
* @return string
|
* @param string $payload The data needed for this request
|
||||||
|
* @param string $canonical_request Header data to send for this request
|
||||||
|
* @param string $service_operation Service operation. CREATE_GIFT_CARD_SERVICE,
|
||||||
|
* CANCEL_GIFT_CARD_SERVICE or
|
||||||
|
* GET_AVAILABLE_FUNDS_SERVICE constant values
|
||||||
|
* @param string $date_time_string Ymd\THis\Z encoded timestamp, getTimestamp()
|
||||||
|
* @return string Request result as string, json data
|
||||||
*/
|
*/
|
||||||
public function makeRequest(
|
public function makeRequest(
|
||||||
string $payload,
|
string $payload,
|
||||||
@@ -156,16 +184,25 @@ class AWS
|
|||||||
]]);
|
]]);
|
||||||
|
|
||||||
$url = 'https://' . $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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $payload
|
* Build the headers used in the makeRequest method.
|
||||||
* @param string $authorization_value
|
* These are the HTML headers used with curl
|
||||||
* @param string $date_time_string
|
*
|
||||||
* @param string $service_target
|
* @param string $payload Paylout to create this header for
|
||||||
* @return array<mixed>
|
* @param string $authorization_value Auth string
|
||||||
|
* @param string $date_time_string Ymd\THis\Z encoded timestamp, getTimestamp()
|
||||||
|
* @param string $service_target Target service in the agcod string:
|
||||||
|
* Value like com.amazonaws.agcod.<sn>.<so>
|
||||||
|
* @return array<mixed> Header data as array for curl request
|
||||||
*/
|
*/
|
||||||
public function buildHeaders(
|
public function buildHeaders(
|
||||||
string $payload,
|
string $payload,
|
||||||
@@ -188,8 +225,33 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $string_to_sign
|
* The request string build with the actauly request data created by
|
||||||
* @return string
|
* getCanonicalRequest(). This string is used in the auth signature call
|
||||||
|
*
|
||||||
|
* @param string $canonical_request_hash sha256 hash to build from
|
||||||
|
* @return string String to send to buildAuthSignature()
|
||||||
|
*/
|
||||||
|
public function buildStringToSign($canonical_request_hash): string
|
||||||
|
{
|
||||||
|
$AWS_SHA256_ALGORITHM = self::AWS_SHA256_ALGORITHM;
|
||||||
|
$TERMINATION_STRING = self::TERMINATION_STRING;
|
||||||
|
$SERVICE_NAME = self::SERVICE_NAME;
|
||||||
|
$region_name = $this->getRegion();
|
||||||
|
$date_time_string = $this->getTimestamp();
|
||||||
|
$date_string = $this->getDateString();
|
||||||
|
$string_to_sign = "$AWS_SHA256_ALGORITHM\n"
|
||||||
|
. "$date_time_string\n"
|
||||||
|
. "$date_string/$region_name/$SERVICE_NAME/$TERMINATION_STRING\n"
|
||||||
|
. "$canonical_request_hash";
|
||||||
|
|
||||||
|
return $string_to_sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the authentication signature used in the buildHeaders method
|
||||||
|
*
|
||||||
|
* @param string $string_to_sign Data to sign, buildStringToSign()
|
||||||
|
* @return string Authorized value as string
|
||||||
*/
|
*/
|
||||||
public function buildAuthSignature(string $string_to_sign): string
|
public function buildAuthSignature(string $string_to_sign): string
|
||||||
{
|
{
|
||||||
@@ -224,28 +286,12 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $canonical_request_hash
|
* Build the derived key to build the final hmac signature string
|
||||||
* @return string
|
*
|
||||||
*/
|
* @param bool $rawOutput Set to true to create the hash based message
|
||||||
public function buildStringToSign($canonical_request_hash): string
|
* authenticator string as normal text string or
|
||||||
{
|
* lowercase hexbits
|
||||||
$AWS_SHA256_ALGORITHM = self::AWS_SHA256_ALGORITHM;
|
* @return string Derived key (hmac type)
|
||||||
$TERMINATION_STRING = self::TERMINATION_STRING;
|
|
||||||
$SERVICE_NAME = self::SERVICE_NAME;
|
|
||||||
$region_name = $this->getRegion();
|
|
||||||
$date_time_string = $this->getTimestamp();
|
|
||||||
$date_string = $this->getDateString();
|
|
||||||
$string_to_sign = "$AWS_SHA256_ALGORITHM\n"
|
|
||||||
. "$date_time_string\n"
|
|
||||||
. "$date_string/$region_name/$SERVICE_NAME/$TERMINATION_STRING\n"
|
|
||||||
. "$canonical_request_hash";
|
|
||||||
|
|
||||||
return $string_to_sign;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $rawOutput
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function buildDerivedKey(bool $rawOutput = true): string
|
public function buildDerivedKey(bool $rawOutput = true): string
|
||||||
{
|
{
|
||||||
@@ -293,7 +339,7 @@ class AWS
|
|||||||
* MXN for MX
|
* MXN for MX
|
||||||
* GBP for UK
|
* GBP for UK
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string Region string depending on given endpoint url
|
||||||
*/
|
*/
|
||||||
public function getRegion(): string
|
public function getRegion(): string
|
||||||
{
|
{
|
||||||
@@ -320,9 +366,15 @@ class AWS
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param float $amount
|
* The actual data to send as json encoded string for creating a gift card.
|
||||||
* @param string|null $creation_id
|
* The creation request id must be in the format:
|
||||||
* @return string
|
* <partner_id>_<unique id 13 characters>
|
||||||
|
*
|
||||||
|
* @param float $amount Amount of currencty to create the gift card
|
||||||
|
* request for
|
||||||
|
* @param string|null $creation_id The creation id, if not set will be created here
|
||||||
|
* @return string JSON encoded array to be used as payload
|
||||||
|
* in get gift card call
|
||||||
*/
|
*/
|
||||||
public function getGiftCardPayload(float $amount, ?string $creation_id = null): string
|
public function getGiftCardPayload(float $amount, ?string $creation_id = null): string
|
||||||
{
|
{
|
||||||
@@ -339,9 +391,12 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $creation_request_id
|
* The actual data to send as json encoded string to cancel a created gift card
|
||||||
* @param string $gift_card_id
|
*
|
||||||
* @return string
|
* @param string $creation_request_id Creation request id from previous get gift card
|
||||||
|
* @param string $gift_card_id Gift card id from previous get gift card
|
||||||
|
* @return string JSON encoded array to be used as payload
|
||||||
|
* in cancle gift card call
|
||||||
*/
|
*/
|
||||||
public function getCancelGiftCardPayload(string $creation_request_id, string $gift_card_id): string
|
public function getCancelGiftCardPayload(string $creation_request_id, string $gift_card_id): string
|
||||||
{
|
{
|
||||||
@@ -354,7 +409,10 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* The actualy data to send as json encoded string for getting the current
|
||||||
|
* account funds
|
||||||
|
*
|
||||||
|
* @return string JSON encoded array to be used as payload in funds call
|
||||||
*/
|
*/
|
||||||
public function getAvailableFundsPayload(): string
|
public function getAvailableFundsPayload(): string
|
||||||
{
|
{
|
||||||
@@ -365,9 +423,34 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $service_operation
|
* Heeders used in the getCanonicalRequest()
|
||||||
* @param string $payload
|
*
|
||||||
* @return string
|
* @param string $service_operation Service operation code in the service string request
|
||||||
|
* Value is: com.amazonaws.agcod.AGCODService.<so>
|
||||||
|
* @return string Header string to be used
|
||||||
|
*/
|
||||||
|
public function buildCanonicalHeaders(string $service_operation): string
|
||||||
|
{
|
||||||
|
$ACCEPT_HEADER = self::ACCEPT_HEADER;
|
||||||
|
$HOST_HEADER = self::HOST_HEADER;
|
||||||
|
$X_AMZ_DATE_HEADER = self::X_AMZ_DATE_HEADER;
|
||||||
|
$X_AMZ_TARGET_HEADER = self::X_AMZ_TARGET_HEADER;
|
||||||
|
$date_time_string = $this->getTimestamp();
|
||||||
|
$endpoint = $this->config->getEndpoint();
|
||||||
|
$content_type = $this->getContentType();
|
||||||
|
return "$ACCEPT_HEADER:$content_type\n"
|
||||||
|
. "$HOST_HEADER:$endpoint\n"
|
||||||
|
. "$X_AMZ_DATE_HEADER:$date_time_string\n"
|
||||||
|
. "$X_AMZ_TARGET_HEADER:com.amazonaws.agcod.AGCODService.$service_operation";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Headers used in the get/cancel/funds requests
|
||||||
|
*
|
||||||
|
* @param string $service_operation Service operation code to be used in header request
|
||||||
|
* and main request call
|
||||||
|
* @param string $payload Payload from get/cancle Code or funds call
|
||||||
|
* @return string Full POST service request code
|
||||||
*/
|
*/
|
||||||
public function getCanonicalRequest(string $service_operation, string $payload): string
|
public function getCanonicalRequest(string $service_operation, string $payload): string
|
||||||
{
|
{
|
||||||
@@ -386,8 +469,10 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $data
|
* Build sha256 hash from given data
|
||||||
* @return string
|
*
|
||||||
|
* @param string $data Data to be hashed with sha256
|
||||||
|
* @return string sha256 hash
|
||||||
*/
|
*/
|
||||||
public function buildHash(string $data): string
|
public function buildHash(string $data): string
|
||||||
{
|
{
|
||||||
@@ -395,18 +480,13 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Create a sha256 based Hash-Based Message Authentication Code
|
||||||
*/
|
* with the given key and data
|
||||||
public function getTimestamp()
|
*
|
||||||
{
|
* @param string $data Data to be hashed with key below
|
||||||
return gmdate('Ymd\THis\Z');
|
* @param string $key Key to be used for creating the hash
|
||||||
}
|
* @param bool $raw Returning data as ascii string or hexibits
|
||||||
|
* @return string Hash-Based Message Authentication Code
|
||||||
/**
|
|
||||||
* @param string $data
|
|
||||||
* @param string $key
|
|
||||||
* @param bool $raw
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function hmac(string $data, string $key, bool $raw = true): string
|
public function hmac(string $data, string $key, bool $raw = true): string
|
||||||
{
|
{
|
||||||
@@ -414,7 +494,21 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Build timestamp in the format used by AWS services
|
||||||
|
* eg 20211009\T102030\Z
|
||||||
|
*
|
||||||
|
* @return string date string based on current time. Ymd\THis\Z
|
||||||
|
*/
|
||||||
|
public function getTimestamp()
|
||||||
|
{
|
||||||
|
return gmdate('Ymd\THis\Z');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get only the date string from the getTimestamp
|
||||||
|
* eg 20211009
|
||||||
|
*
|
||||||
|
* @return string Date string YYYYmmdd extracted from getTimestamp()
|
||||||
*/
|
*/
|
||||||
public function getDateString()
|
public function getDateString()
|
||||||
{
|
{
|
||||||
@@ -422,31 +516,14 @@ class AWS
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Fixed content type for submission, is json
|
||||||
|
*
|
||||||
|
* @return string 'application/json' string
|
||||||
*/
|
*/
|
||||||
public function getContentType(): string
|
public function getContentType(): string
|
||||||
{
|
{
|
||||||
return 'application/json';
|
return 'application/json';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $service_operation
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function buildCanonicalHeaders(string $service_operation): string
|
|
||||||
{
|
|
||||||
$ACCEPT_HEADER = self::ACCEPT_HEADER;
|
|
||||||
$HOST_HEADER = self::HOST_HEADER;
|
|
||||||
$X_AMZ_DATE_HEADER = self::X_AMZ_DATE_HEADER;
|
|
||||||
$X_AMZ_TARGET_HEADER = self::X_AMZ_TARGET_HEADER;
|
|
||||||
$date_time_string = $this->getTimestamp();
|
|
||||||
$endpoint = $this->config->getEndpoint();
|
|
||||||
$content_type = $this->getContentType();
|
|
||||||
return "$ACCEPT_HEADER:$content_type\n"
|
|
||||||
. "$HOST_HEADER:$endpoint\n"
|
|
||||||
. "$X_AMZ_DATE_HEADER:$date_time_string\n"
|
|
||||||
. "$X_AMZ_TARGET_HEADER:com.amazonaws.agcod.AGCODService.$service_operation";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ final class AmazonIncentives
|
|||||||
/**
|
/**
|
||||||
* AmazonGiftCode constructor.
|
* AmazonGiftCode constructor.
|
||||||
*
|
*
|
||||||
* @param string|null $key
|
* @param string|null $key Account key
|
||||||
* @param string|null $secret
|
* @param string|null $secret Secret key
|
||||||
* @param string|null $partner
|
* @param string|null $partner Partner ID
|
||||||
* @param string|null $endpoint
|
* @param string|null $endpoint Endpoint URL including https://
|
||||||
* @param string|null $currency
|
* @param string|null $currency Currency type. Eg USD, JPY, etc
|
||||||
* @param bool|null $debug
|
* @param bool|null $debug Debug flag
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $key = null,
|
string $key = null,
|
||||||
@@ -53,9 +53,15 @@ final class AmazonIncentives
|
|||||||
// *********************************************************************
|
// *********************************************************************
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param float $value
|
* Buy a gift card
|
||||||
* @param string|null $creation_request_id AWS creationRequestId
|
*
|
||||||
* @return Response\CreateResponse
|
* @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
|
* @throws AmazonErrors
|
||||||
*/
|
*/
|
||||||
@@ -66,9 +72,13 @@ final class AmazonIncentives
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $creation_request_id AWS creationRequestId
|
* Cancel a previous created gift card, if within the time frame
|
||||||
* @param string $gift_card_id AWS gcId
|
*
|
||||||
* @return Response\CancelResponse
|
* @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
|
public function cancelGiftCard(string $creation_request_id, string $gift_card_id): Response\CancelResponse
|
||||||
{
|
{
|
||||||
@@ -76,7 +86,9 @@ final class AmazonIncentives
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Response\CreateBalanceResponse
|
* Gets the current funds in this account
|
||||||
|
*
|
||||||
|
* @return Response\CreateBalanceResponse Returns the account funds object
|
||||||
*
|
*
|
||||||
* @throws AmazonErrors
|
* @throws AmazonErrors
|
||||||
*/
|
*/
|
||||||
@@ -86,15 +98,15 @@ final class AmazonIncentives
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AmazonIncentives make own client.
|
* AmazonIncentives creates own client and returns it as static object
|
||||||
*
|
*
|
||||||
* @param string|null $key
|
* @param string|null $key Account key
|
||||||
* @param string|null $secret
|
* @param string|null $secret Secret key
|
||||||
* @param string|null $partner
|
* @param string|null $partner Partner ID
|
||||||
* @param string|null $endpoint
|
* @param string|null $endpoint Endpoint URL including https://
|
||||||
* @param string|null $currency
|
* @param string|null $currency Currency type. Eg USD, JPY, etc
|
||||||
* @param bool|null $debug
|
* @param bool|null $debug Debug flag
|
||||||
* @return AmazonIncentives
|
* @return AmazonIncentives self class
|
||||||
*/
|
*/
|
||||||
public static function make(
|
public static function make(
|
||||||
string $key = null,
|
string $key = null,
|
||||||
@@ -137,6 +149,10 @@ final class AmazonIncentives
|
|||||||
// *********************************************************************
|
// *********************************************************************
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Prints out ENV, CONFIG and KEY data
|
||||||
|
* This is for debug only, this will print out secrets.
|
||||||
|
* Use with care
|
||||||
|
*
|
||||||
* @return array<mixed>
|
* @return array<mixed>
|
||||||
*/
|
*/
|
||||||
public function checkMe(): array
|
public function checkMe(): array
|
||||||
|
|||||||
@@ -7,17 +7,18 @@ use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
|||||||
|
|
||||||
class Client implements ClientInterface
|
class Client implements ClientInterface
|
||||||
{
|
{
|
||||||
// instead of JsonResponse::HTTP_OK
|
/** @var int instead of JsonResponse::HTTP_OK */
|
||||||
private const HTTP_OK = 200;
|
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 string $url The URL being requested,
|
||||||
|
* including domain and protocol
|
||||||
* @param array<mixed> $headers Headers to be used in the request
|
* @param array<mixed> $headers Headers to be used in the request
|
||||||
* @param array<mixed>|string $params Can be nested for arrays and hashes
|
* @param array<mixed>|string $params Can be nested for arrays and hashes
|
||||||
*
|
* @return string Result as json string
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function request(string $url, array $headers, $params): string
|
public function request(string $url, array $headers, $params): string
|
||||||
{
|
{
|
||||||
@@ -76,11 +77,12 @@ class Client implements ClientInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* handles any CURL errors and throws an error with the correct
|
||||||
|
* error message
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url The url that was originaly used
|
||||||
* @param int $errno
|
* @param int $errno Error number from curl handler
|
||||||
* @param string $message
|
* @param string $message The error message string from curl
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function handleCurlError(string $url, int $errno, string $message): void
|
private function handleCurlError(string $url, int $errno, string $message): void
|
||||||
|
|||||||
@@ -4,37 +4,27 @@ namespace gullevek\AmazonIncentives\Config;
|
|||||||
|
|
||||||
class Config implements ConfigInterface
|
class Config implements ConfigInterface
|
||||||
{
|
{
|
||||||
/**
|
/** @var string Endpoint URL without https:// */
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $endpoint = '';
|
private $endpoint = '';
|
||||||
/**
|
/** @var string Access Key */
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $access_key = '';
|
private $access_key = '';
|
||||||
/**
|
/** @var string Secret Key */
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $secret_key = '';
|
private $secret_key = '';
|
||||||
/**
|
/** @var string Partner ID */
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $partner_id = '';
|
private $partner_id = '';
|
||||||
/**
|
/** @var string Currency type as USD, JPY, etc */
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $currency = '';
|
private $currency = '';
|
||||||
/**
|
/** @var bool Debug flag on or off */
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $debug = false;
|
private $debug = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|null $key
|
* @param string|null $key Access key
|
||||||
* @param string|null $secret
|
* @param string|null $secret Secret Key
|
||||||
* @param string|null $partner
|
* @param string|null $partner Partner ID
|
||||||
* @param string|null $endpoint
|
* @param string|null $endpoint Endpoing URL including https://
|
||||||
* @param string|null $currency
|
* @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(
|
public function __construct(
|
||||||
?string $key,
|
?string $key,
|
||||||
@@ -104,7 +94,7 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string Returns current set endpoint, without https://
|
||||||
*/
|
*/
|
||||||
public function getEndpoint(): string
|
public function getEndpoint(): string
|
||||||
{
|
{
|
||||||
@@ -112,8 +102,8 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $endpoint
|
* @param string $endpoint Full endpoint url with https://
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setEndpoint(string $endpoint): ConfigInterface
|
public function setEndpoint(string $endpoint): ConfigInterface
|
||||||
{
|
{
|
||||||
@@ -124,7 +114,7 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string Current access key
|
||||||
*/
|
*/
|
||||||
public function getAccessKey(): string
|
public function getAccessKey(): string
|
||||||
{
|
{
|
||||||
@@ -132,8 +122,8 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $key
|
* @param string $key Access Key to set
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setAccessKey(string $key): ConfigInterface
|
public function setAccessKey(string $key): ConfigInterface
|
||||||
{
|
{
|
||||||
@@ -143,7 +133,7 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string Current secret key
|
||||||
*/
|
*/
|
||||||
public function getSecret(): string
|
public function getSecret(): string
|
||||||
{
|
{
|
||||||
@@ -151,8 +141,8 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $secret
|
* @param string $secret Secret key to set
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setSecret(string $secret): ConfigInterface
|
public function setSecret(string $secret): ConfigInterface
|
||||||
{
|
{
|
||||||
@@ -162,7 +152,7 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string Current set currency
|
||||||
*/
|
*/
|
||||||
public function getCurrency(): string
|
public function getCurrency(): string
|
||||||
{
|
{
|
||||||
@@ -170,8 +160,8 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $currency
|
* @param string $currency Currency to set (eg USD, JPY, etc)
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setCurrency(string $currency): ConfigInterface
|
public function setCurrency(string $currency): ConfigInterface
|
||||||
{
|
{
|
||||||
@@ -182,7 +172,7 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string Current set partner id
|
||||||
*/
|
*/
|
||||||
public function getPartner(): string
|
public function getPartner(): string
|
||||||
{
|
{
|
||||||
@@ -190,8 +180,8 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $partner
|
* @param string $partner Partner id to set
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setPartner(string $partner): ConfigInterface
|
public function setPartner(string $partner): ConfigInterface
|
||||||
{
|
{
|
||||||
@@ -201,7 +191,7 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool Current set debug flag as bool
|
||||||
*/
|
*/
|
||||||
public function getDebug(): bool
|
public function getDebug(): bool
|
||||||
{
|
{
|
||||||
@@ -209,8 +199,8 @@ class Config implements ConfigInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $debug
|
* @param bool $debug Set debug flag as bool
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setDebug(bool $debug): ConfigInterface
|
public function setDebug(bool $debug): ConfigInterface
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,68 +5,68 @@ namespace gullevek\AmazonIncentives\Config;
|
|||||||
interface ConfigInterface
|
interface ConfigInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string Returns current set endpoint, without https://
|
||||||
*/
|
*/
|
||||||
public function getEndpoint(): string;
|
public function getEndpoint(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $endpoint
|
* @param string $endpoint Full endpoint url with https://
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setEndpoint(string $endpoint): ConfigInterface;
|
public function setEndpoint(string $endpoint): ConfigInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string Current access key
|
||||||
*/
|
*/
|
||||||
public function getAccessKey(): string;
|
public function getAccessKey(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $key
|
* @param string $key Access Key to set
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setAccessKey(string $key): ConfigInterface;
|
public function setAccessKey(string $key): ConfigInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string Current secret key
|
||||||
*/
|
*/
|
||||||
public function getSecret(): string;
|
public function getSecret(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $secret
|
* @param string $secret Secret key to set
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setSecret(string $secret): ConfigInterface;
|
public function setSecret(string $secret): ConfigInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string Current set currency
|
||||||
*/
|
*/
|
||||||
public function getCurrency(): string;
|
public function getCurrency(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $currency
|
* @param string $currency Currency to set (eg USD, JPY, etc)
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setCurrency(string $currency): ConfigInterface;
|
public function setCurrency(string $currency): ConfigInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string Current set partner id
|
||||||
*/
|
*/
|
||||||
public function getPartner(): string;
|
public function getPartner(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $partner
|
* @param string $partner Partner id to set
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setPartner(string $partner): ConfigInterface;
|
public function setPartner(string $partner): ConfigInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool Current set debug flag as bool
|
||||||
*/
|
*/
|
||||||
public function getDebug(): bool;
|
public function getDebug(): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $debug
|
* @param bool $debug Set debug flag as bool
|
||||||
* @return ConfigInterface
|
* @return ConfigInterface Class interface (self)
|
||||||
*/
|
*/
|
||||||
public function setDebug(bool $debug): ConfigInterface;
|
public function setDebug(bool $debug): ConfigInterface;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,11 @@ namespace gullevek\AmazonIncentives\Debug;
|
|||||||
|
|
||||||
class AmazonDebug
|
class AmazonDebug
|
||||||
{
|
{
|
||||||
/**
|
/** @var array<mixed> Log data array log id -> array of log entries */
|
||||||
* @var array<mixed>
|
|
||||||
*/
|
|
||||||
private static $log = [];
|
private static $log = [];
|
||||||
/**
|
/** @var bool debug flag */
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private static $debug = false;
|
private static $debug = false;
|
||||||
/**
|
/** @var string|null Last set internal log array id */
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private static $id = null;
|
private static $id = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,12 +8,15 @@ use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
|||||||
final class AmazonErrors extends RuntimeException
|
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_status agcodResponse->status from Amazon
|
||||||
* @param string $error_code errorCode from Amazon
|
* @param string $error_code errorCode from Amazon
|
||||||
* @param string $error_type errorType from Amazon
|
* @param string $error_type errorType from Amazon
|
||||||
* @param string $message
|
* @param string $message Message string to ad
|
||||||
* @param int $_error_code
|
* @param int $_error_code Error code to set
|
||||||
* @return AmazonErrors
|
* @return AmazonErrors Exception Class
|
||||||
*/
|
*/
|
||||||
public static function getError(
|
public static function getError(
|
||||||
string $error_status,
|
string $error_status,
|
||||||
|
|||||||
@@ -6,34 +6,19 @@ use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
|||||||
|
|
||||||
class CancelResponse
|
class CancelResponse
|
||||||
{
|
{
|
||||||
/**
|
/** @var string Amazon Gift Card gcId (gift card id). */
|
||||||
* Amazon Gift Card gcId.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $id = '';
|
protected $id = '';
|
||||||
/**
|
/** @var string Amazon Gift Card creationRequestId (creation request id) */
|
||||||
* Amazon Gift Card creationRequestId
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $creation_request_id = '';
|
protected $creation_request_id = '';
|
||||||
/**
|
/** @var string Amazon Gift Card status */
|
||||||
* Amazon Gift Card status
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $status = '';
|
protected $status = '';
|
||||||
/**
|
/** @var array<mixed> Amazon Gift Card Raw JSON */
|
||||||
* Amazon Gift Card Raw JSON
|
|
||||||
*
|
|
||||||
* @var array<mixed>
|
|
||||||
*/
|
|
||||||
protected $raw_json = [];
|
protected $raw_json = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response constructor.
|
* Response constructor for canceling gitf cards
|
||||||
* @param array<mixed> $json_response
|
*
|
||||||
|
* @param array<mixed> $json_response JSON response from web request to AWS
|
||||||
*/
|
*/
|
||||||
public function __construct(array $json_response)
|
public function __construct(array $json_response)
|
||||||
{
|
{
|
||||||
@@ -42,7 +27,9 @@ class CancelResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<mixed>
|
* Get log entry with current set log id
|
||||||
|
*
|
||||||
|
* @return array<mixed> Log array
|
||||||
*/
|
*/
|
||||||
public function getLog(): array
|
public function getLog(): array
|
||||||
{
|
{
|
||||||
@@ -50,7 +37,9 @@ class CancelResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* The gift card id as created by the previous get code call
|
||||||
|
*
|
||||||
|
* @return string Gift card id
|
||||||
*/
|
*/
|
||||||
public function getId(): string
|
public function getId(): string
|
||||||
{
|
{
|
||||||
@@ -58,7 +47,9 @@ class CancelResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Creation Request id from original get code call
|
||||||
|
*
|
||||||
|
* @return string Creation request id
|
||||||
*/
|
*/
|
||||||
public function getCreationRequestId(): string
|
public function getCreationRequestId(): string
|
||||||
{
|
{
|
||||||
@@ -66,7 +57,9 @@ class CancelResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Request status
|
||||||
|
*
|
||||||
|
* @return string Request status as string: SUCCESS, FAILURE, RESEND
|
||||||
*/
|
*/
|
||||||
public function getStatus(): string
|
public function getStatus(): string
|
||||||
{
|
{
|
||||||
@@ -74,7 +67,10 @@ class CancelResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* 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
|
public function getRawJson(): string
|
||||||
{
|
{
|
||||||
@@ -82,8 +78,10 @@ class CancelResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<mixed> $json_response
|
* Set class variables with response data from makeRequest and return self
|
||||||
* @return CancelResponse
|
*
|
||||||
|
* @param array<mixed> $json_response JSON response as array
|
||||||
|
* @return CancelResponse Return self object
|
||||||
*/
|
*/
|
||||||
public function parseJsonResponse(array $json_response): self
|
public function parseJsonResponse(array $json_response): self
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,41 +6,21 @@ use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
|||||||
|
|
||||||
class CreateBalanceResponse
|
class CreateBalanceResponse
|
||||||
{
|
{
|
||||||
/**
|
/** @var string Amazon Gift Card Balance Amount */
|
||||||
* Amazon Gift Card Balance Amount
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $amount = '';
|
protected $amount = '';
|
||||||
/**
|
/** @var string Amazon Gift Card Balance Currency */
|
||||||
* Amazon Gift Card Balance Currency
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $currency = '';
|
protected $currency = '';
|
||||||
/**
|
/** @var string Amazon Gift Card Balance Status */
|
||||||
* Amazon Gift Card Balance Status
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $status = '';
|
protected $status = '';
|
||||||
/**
|
/** @var string Amazon Gift Card Balance Timestamp */
|
||||||
* Amazon Gift Card Balance Timestamp
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $timestamp = '';
|
protected $timestamp = '';
|
||||||
/**
|
/** @var array<mixed> Amazon Gift Card Raw JSON */
|
||||||
* Amazon Gift Card Raw JSON
|
|
||||||
*
|
|
||||||
* @var array<mixed>
|
|
||||||
*/
|
|
||||||
protected $raw_json = [];
|
protected $raw_json = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response constructor.
|
* Response constructor for requesting account funds status
|
||||||
*
|
*
|
||||||
* @param array<mixed> $json_response
|
* @param array<mixed> $json_response JSON response from web request to AWS
|
||||||
*/
|
*/
|
||||||
public function __construct(array $json_response)
|
public function __construct(array $json_response)
|
||||||
{
|
{
|
||||||
@@ -49,7 +29,9 @@ class CreateBalanceResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<mixed>
|
* Get log entry with current set log id
|
||||||
|
*
|
||||||
|
* @return array<mixed> Log array
|
||||||
*/
|
*/
|
||||||
public function getLog(): array
|
public function getLog(): array
|
||||||
{
|
{
|
||||||
@@ -57,7 +39,9 @@ class CreateBalanceResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Return the current available funds amount
|
||||||
|
*
|
||||||
|
* @return string Funds amount in set currency
|
||||||
*/
|
*/
|
||||||
public function getAmount(): string
|
public function getAmount(): string
|
||||||
{
|
{
|
||||||
@@ -65,7 +49,9 @@ class CreateBalanceResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Get the set currency type
|
||||||
|
*
|
||||||
|
* @return string Currency type. Eg USD, JPY, etc
|
||||||
*/
|
*/
|
||||||
public function getCurrency(): string
|
public function getCurrency(): string
|
||||||
{
|
{
|
||||||
@@ -73,15 +59,10 @@ class CreateBalanceResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Get timestamp as set.
|
||||||
*/
|
* eg 20220609T061446Z
|
||||||
public function getStatus(): string
|
*
|
||||||
{
|
* @return string Timestamp string. Ymd\THis\Z
|
||||||
return $this->status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getTimestamp(): string
|
public function getTimestamp(): string
|
||||||
{
|
{
|
||||||
@@ -89,7 +70,20 @@ class CreateBalanceResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* 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
|
public function getRawJson(): string
|
||||||
{
|
{
|
||||||
@@ -97,10 +91,10 @@ class CreateBalanceResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Set class variables with response data from makeRequest and return self
|
||||||
*
|
*
|
||||||
* @param array<mixed> $json_response
|
* @param array<mixed> $json_response JSON response as array
|
||||||
* @return CreateBalanceResponse
|
* @return CreateBalanceResponse Return self object
|
||||||
*/
|
*/
|
||||||
public function parseJsonResponse(array $json_response): self
|
public function parseJsonResponse(array $json_response): self
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,68 +6,29 @@ use gullevek\AmazonIncentives\Debug\AmazonDebug;
|
|||||||
|
|
||||||
class CreateResponse
|
class CreateResponse
|
||||||
{
|
{
|
||||||
/**
|
/** @var string Amazon Gift Card gcId */
|
||||||
* Amazon Gift Card gcId.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $id = '';
|
protected $id = '';
|
||||||
|
/** @var string Amazon Gift Card creationRequestId */
|
||||||
/**
|
|
||||||
* Amazon Gift Card creationRequestId
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $creation_request_id = '';
|
protected $creation_request_id = '';
|
||||||
|
/** @var string Amazon Gift Card gcClaimCode */
|
||||||
/**
|
|
||||||
* Amazon Gift Card gcClaimCode
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $claim_code = '';
|
protected $claim_code = '';
|
||||||
|
/** @var float Amazon Gift Card amount */
|
||||||
/**
|
|
||||||
* Amazon Gift Card amount
|
|
||||||
*
|
|
||||||
* @var float
|
|
||||||
*/
|
|
||||||
protected $value = 0;
|
protected $value = 0;
|
||||||
|
/** @var string Amazon Gift Card currency */
|
||||||
/**
|
|
||||||
* Amazon Gift Card currency
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $currency = '';
|
protected $currency = '';
|
||||||
/**
|
/** @var string Amazon Gift Card status */
|
||||||
* Amazon Gift Card status
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $status = '';
|
protected $status = '';
|
||||||
/**
|
/** @var string Amazon Gift Card Expiration Date */
|
||||||
* Amazon Gift Card Expiration Date
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $expiration_date = '';
|
protected $expiration_date = '';
|
||||||
/**
|
/** @var string Amazon Gift Card Expiration Date */
|
||||||
* Amazon Gift Card Expiration Date
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $card_status = '';
|
protected $card_status = '';
|
||||||
/**
|
/** @var array<mixed> Amazon Gift Card Raw JSON as array */
|
||||||
* Amazon Gift Card Raw JSON
|
|
||||||
*
|
|
||||||
* @var array<mixed>
|
|
||||||
*/
|
|
||||||
protected $raw_json = [];
|
protected $raw_json = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response constructor.
|
* Response constructor for creating gift cards
|
||||||
* @param array<mixed> $json_response
|
*
|
||||||
|
* @param array<mixed> $json_response JSON response from web request to AWS
|
||||||
*/
|
*/
|
||||||
public function __construct(array $json_response)
|
public function __construct(array $json_response)
|
||||||
{
|
{
|
||||||
@@ -76,7 +37,9 @@ class CreateResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<mixed>
|
* Get log entry with current set log id
|
||||||
|
*
|
||||||
|
* @return array<mixed> Log array
|
||||||
*/
|
*/
|
||||||
public function getLog(): array
|
public function getLog(): array
|
||||||
{
|
{
|
||||||
@@ -84,7 +47,9 @@ class CreateResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Gift Card ID returned from AWS. Can be used in the cancel request
|
||||||
|
*
|
||||||
|
* @return string Gift card id
|
||||||
*/
|
*/
|
||||||
public function getId(): string
|
public function getId(): string
|
||||||
{
|
{
|
||||||
@@ -92,7 +57,10 @@ class CreateResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Either the one set with the method parameter, or automatically created
|
||||||
|
* during get code request
|
||||||
|
*
|
||||||
|
* @return string Creation request id
|
||||||
*/
|
*/
|
||||||
public function getCreationRequestId(): string
|
public function getCreationRequestId(): string
|
||||||
{
|
{
|
||||||
@@ -100,7 +68,10 @@ class CreateResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* 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
|
public function getClaimCode(): string
|
||||||
{
|
{
|
||||||
@@ -108,7 +79,9 @@ class CreateResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return float
|
* The ordered gift code value in given currency
|
||||||
|
*
|
||||||
|
* @return float Gift order value in currency
|
||||||
*/
|
*/
|
||||||
public function getValue(): float
|
public function getValue(): float
|
||||||
{
|
{
|
||||||
@@ -116,7 +89,9 @@ class CreateResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* The currently set currency
|
||||||
|
*
|
||||||
|
* @return string Currency type. Eg USD, JPY, etc
|
||||||
*/
|
*/
|
||||||
public function getCurrency(): string
|
public function getCurrency(): string
|
||||||
{
|
{
|
||||||
@@ -124,15 +99,10 @@ class CreateResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Expiration date for the ordered gift code.
|
||||||
*/
|
* eg 20220609T061446Z
|
||||||
public function getStatus(): string
|
*
|
||||||
{
|
* @return string Timestamp until when the gift code is valid. Ymd\THis\Z
|
||||||
return $this->status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
public function getExpirationDate(): string
|
public function getExpirationDate(): string
|
||||||
{
|
{
|
||||||
@@ -140,16 +110,31 @@ class CreateResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* 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
|
public function getCardStatus(): string
|
||||||
{
|
{
|
||||||
return $this->card_status;
|
return $this->card_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request status
|
||||||
|
*
|
||||||
|
* @return string Request status as string: SUCCESS, FAILURE, RESEND
|
||||||
|
*/
|
||||||
|
public function getStatus(): string
|
||||||
|
{
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @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
|
public function getRawJson(): string
|
||||||
{
|
{
|
||||||
@@ -157,8 +142,10 @@ class CreateResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<array-key,mixed|array> $json_response
|
* Set class variables with response data from makeRequest and return self
|
||||||
* @return CreateResponse
|
*
|
||||||
|
* @param array<mixed> $json_response JSON response as array
|
||||||
|
* @return CreateResponse Return self object
|
||||||
*/
|
*/
|
||||||
public function parseJsonResponse(array $json_response): self
|
public function parseJsonResponse(array $json_response): self
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,8 +57,6 @@ $loader = require '../vendor/autoload.php';
|
|||||||
// need to add this or it will not load here
|
// need to add this or it will not load here
|
||||||
$loader->addPsr4('gullevek\\', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src');
|
$loader->addPsr4('gullevek\\', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src');
|
||||||
// print "LOADER: <pre>" . print_r($loader, true) . "</pre>";
|
// print "LOADER: <pre>" . print_r($loader, true) . "</pre>";
|
||||||
// env file loader (simple)
|
|
||||||
require 'read_env_file.php';
|
|
||||||
|
|
||||||
use gullevek\AmazonIncentives\AmazonIncentives;
|
use gullevek\AmazonIncentives\AmazonIncentives;
|
||||||
use gullevek\dotEnv\DotEnv;
|
use gullevek\dotEnv\DotEnv;
|
||||||
@@ -103,8 +101,9 @@ $mock_wait = 2;
|
|||||||
|
|
||||||
if ($run_info_test === true) {
|
if ($run_info_test === true) {
|
||||||
$aws = new AmazonIncentives();
|
$aws = new AmazonIncentives();
|
||||||
print "checkMe: <pre>" . print_r($aws->checkMe(), true) . "</pre>";
|
$aws_check_me = $aws->checkMe();
|
||||||
fwrite($fp, writeLog($aws->checkMe()));
|
print "checkMe: <pre>" . print_r($aws_check_me, true) . "</pre>";
|
||||||
|
fwrite($fp, writeLog($aws_check_me));
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
test/aws_read_env_tests.php
Normal file
23
test/aws_read_env_tests.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// just print out env data nd connect data
|
||||||
|
// checkMe from AmazonIntentives call is requal to
|
||||||
|
// run_info_test === true in aws_gift_card_tests.php
|
||||||
|
|
||||||
|
$loader = require '../vendor/autoload.php';
|
||||||
|
// need to add this or it will not load here
|
||||||
|
$loader->addPsr4('gullevek\\', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src');
|
||||||
|
// print "LOADER: <pre>" . print_r($loader, true) . "</pre>";
|
||||||
|
|
||||||
|
use gullevek\AmazonIncentives\AmazonIncentives;
|
||||||
|
use gullevek\dotEnv\DotEnv;
|
||||||
|
|
||||||
|
// load env data with dotenv
|
||||||
|
DotEnv::readEnvFile(__DIR__);
|
||||||
|
|
||||||
|
print "_ENV: <pre>" . print_r($_ENV, true) . "</pre>";
|
||||||
|
|
||||||
|
$aws = new AmazonIncentives();
|
||||||
|
print "checkMe: <pre>" . print_r($aws->checkMe(), true) . "</pre>";
|
||||||
|
|
||||||
|
// __END__
|
||||||
Reference in New Issue
Block a user