diff --git a/src/ReceiptValidator/Amazon/Response.php b/src/ReceiptValidator/Amazon/Response.php new file mode 100644 index 0000000..bb45ba3 --- /dev/null +++ b/src/ReceiptValidator/Amazon/Response.php @@ -0,0 +1,112 @@ +_code = $httpStatusCode; + + if ($jsonResponse !== null) { + $this->parseJsonResponse($jsonResponse); + } + } + + /** + * Get Result Code + * + * @return int + */ + public function getResultCode() + { + return $this->_code; + } + + /** + * Get receipt info + * + * @return array + */ + public function getReceipt() + { + return $this->_receipt; + } + + /** + * returns if the receipt is valid or not + * + * @return boolean + */ + public function isValid() + { + if ($this->_code == self::RESULT_OK) { + return true; + } + + return false; + } + + /** + * Parse JSON Response + * + * @param string $jsonResponse + * @return Message + */ + public function parseJsonResponse($jsonResponse = null) + { + if (!is_array($jsonResponse)) { + throw new RuntimeException('Response must be a scalar value'); + } + + $this->_receipt = $jsonResponse; + + return $this; + } +} diff --git a/src/ReceiptValidator/Amazon/Validator.php b/src/ReceiptValidator/Amazon/Validator.php new file mode 100755 index 0000000..52433ec --- /dev/null +++ b/src/ReceiptValidator/Amazon/Validator.php @@ -0,0 +1,123 @@ +_endpoint = $endpoint; + } + + + /** + * + * @param string $userId + * @return \ReceiptValidator\Amazon\Validator + */ + public function setUserId($userId) + { + $this->_userId = $userId; + + return $this; + } + + /** + * + * @param string $receiptId + * @return \ReceiptValidator\Amazon\Validator + */ + public function setReceiptId($receiptId) + { + $this->_receiptId = $receiptId; + + return $this; + } + + /** + * + * @param int $developerSecret + * @return \ReceiptValidator\Amazon\Validator + */ + public function setDeveloperSecret($developerSecret) + { + $this->_developerSecret = $developerSecret; + + return $this; + } + + + /** + * returns the Guzzle client + * + * @return \Guzzle\Http\Client + */ + protected function getClient() + { + if ($this->_client == null) { + $this->_client = new GuzzleClient($this->_endpoint); + } + + return $this->_client; + } + + /** + * validate the receipt data + * + * @return Response + */ + public function validate() + { + + $httpResponse = $this->getClient()->get(sprintf("developer/%s/user/%s/receiptId/%s", $this->_developerSecret, $this->_userId, $this->_receiptId), null, ['exceptions' => false])->send(); + + return new Response($httpResponse->getStatusCode(), $httpResponse->json()); + } +}