diff --git a/src/AWS/AWS.php b/src/AWS/AWS.php index d890598..58d62fb 100644 --- a/src/AWS/AWS.php +++ b/src/AWS/AWS.php @@ -129,6 +129,16 @@ class AWS return new CreateBalanceResponse($result); } + /** + * return a new curl connection client class + * + * @return Client Curl connection Client + */ + public function newClient(): Client + { + return new Client(); + } + /** * General request method for all actions * Calls the Client class that actually runs the json request @@ -190,7 +200,7 @@ class AWS $date_time_string, $service_target ); - return (new Client())->request($url, $headers, $payload); + return ($this->newClient())->request($url, $headers, $payload); } /** diff --git a/src/AmazonIncentives.php b/src/AmazonIncentives.php index 989f2f2..ca8123b 100644 --- a/src/AmazonIncentives.php +++ b/src/AmazonIncentives.php @@ -67,7 +67,7 @@ final class AmazonIncentives */ public function buyGiftCard(float $value, string $creation_request_id = null): Response\CreateResponse { - return (new AWS($this->config))->getCode($value, $creation_request_id); + return ($this->newAWS())->getCode($value, $creation_request_id); } @@ -82,7 +82,7 @@ final class AmazonIncentives */ public function cancelGiftCard(string $creation_request_id, string $gift_card_id): Response\CancelResponse { - return (new AWS($this->config))->cancelCode($creation_request_id, $gift_card_id); + return ($this->newAWS())->cancelCode($creation_request_id, $gift_card_id); } /** @@ -94,7 +94,7 @@ final class AmazonIncentives */ public function getAvailableFunds(): Response\CreateBalanceResponse { - return (new AWS($this->config))->getBalance(); + return ($this->newAWS())->getBalance(); } /** @@ -119,6 +119,17 @@ final class 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); + } + /** * Decodes the Exception message body * Returns an array with code (Amazon error codes), type (Amazon error info) diff --git a/test/aws_gift_card_tests.php b/test/aws_gift_card_tests.php index 921dedc..9808382 100644 --- a/test/aws_gift_card_tests.php +++ b/test/aws_gift_card_tests.php @@ -88,7 +88,7 @@ $run_fund_test = true; // run the normal get/cancel gift card tests $run_gift_tests = true; // run mock error check tests -$run_mocks = false; +$run_mocks = true; // should we print debug info $debug_print = false;