From c9772316299ed8a5332c012a08944d0c82441f54 Mon Sep 17 00:00:00 2001 From: AnirudhaAgashe Date: Tue, 10 Mar 2015 22:51:12 +0530 Subject: [PATCH 1/4] Added password field which is used for auto renewable subscriptions --- itunesReceiptValidator.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/itunesReceiptValidator.php b/itunesReceiptValidator.php index 90c0df4..9e4be15 100644 --- a/itunesReceiptValidator.php +++ b/itunesReceiptValidator.php @@ -4,12 +4,15 @@ class itunesReceiptValidator { const SANDBOX_URL = 'https://sandbox.itunes.apple.com/verifyReceipt'; const PRODUCTION_URL = 'https://buy.itunes.apple.com/verifyReceipt'; - function __construct($endpoint, $receipt = NULL) { + function __construct($endpoint, $receipt = NULL, $password = NULL) { $this->setEndPoint($endpoint); if ($receipt) { $this->setReceipt($receipt); } + if ($password) { + $this->password; + } } function getReceipt() { @@ -24,6 +27,14 @@ function setReceipt($receipt) { } } + function getPassword(){ + return $this->password; + } + + function setPassword($password){ + $this->password = $password; + } + function getEndpoint() { return $this->endpoint; } @@ -49,7 +60,13 @@ function validateReceipt() { } private function encodeRequest() { - return json_encode(array('receipt-data' => $this->getReceipt())); + $request_data = array('receipt-data' => $this->getReceipt()); + + if ($this->getPassword()) { + $request_data['password'] = $this->getPassword(); + } + + return json_encode($request_data); } private function decodeResponse($response) { From 22dfe6abf3cbdcec79932fc6e6ef10997aa80cd4 Mon Sep 17 00:00:00 2001 From: Jimmy Forrester-Fellowes Date: Mon, 10 Aug 2015 15:35:56 +0000 Subject: [PATCH 2/4] Added custom exception types to allow granular exception handling. Minor fix for setReceipt() to allow passing in of array or object data types. --- itunesReceiptValidator.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/itunesReceiptValidator.php b/itunesReceiptValidator.php index 90c0df4..c8436a5 100644 --- a/itunesReceiptValidator.php +++ b/itunesReceiptValidator.php @@ -1,4 +1,12 @@ receipt = base64_encode($receipt); } else { $this->receipt = $receipt; @@ -38,7 +46,10 @@ function validateReceipt() { $decoded_response = $this->decodeResponse($response); if (!isset($decoded_response->status) || $decoded_response->status != 0) { - throw new Exception('Invalid receipt. Status code: ' . (!empty($decoded_response->status) ? $decoded_response->status : 'N/A')); + throw new itunesReceiptInvalidException ( + 'Invalid receipt. Status code: ' . (!empty($decoded_response->status) ? + $decoded_response->status : 'N/A') + ); } if (!is_object($decoded_response)) { From c59c3f201d24807f1635f313b28aa25fa1088539 Mon Sep 17 00:00:00 2001 From: Anirudha Agashe Date: Mon, 10 Aug 2015 22:59:16 +0530 Subject: [PATCH 3/4] fixed password setting in construct --- itunesReceiptValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/itunesReceiptValidator.php b/itunesReceiptValidator.php index 9e4be15..39cd980 100644 --- a/itunesReceiptValidator.php +++ b/itunesReceiptValidator.php @@ -11,7 +11,7 @@ function __construct($endpoint, $receipt = NULL, $password = NULL) { $this->setReceipt($receipt); } if ($password) { - $this->password; + $this->setPassword($password); } } From 158ac5061bd816c4793b3dc4992da89312dc8155 Mon Sep 17 00:00:00 2001 From: Jimmy Forrester-Fellowes Date: Wed, 21 Sep 2016 14:53:57 +0000 Subject: [PATCH 4/4] added returnAll parameter to validateReceipt which returns the receipt purchase history --- itunesReceiptValidator.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/itunesReceiptValidator.php b/itunesReceiptValidator.php index 781f186..febae79 100644 --- a/itunesReceiptValidator.php +++ b/itunesReceiptValidator.php @@ -51,7 +51,7 @@ function setEndPoint($endpoint) { $this->endpoint = $endpoint; } - function validateReceipt() { + function validateReceipt($returnAll = false) { $response = $this->makeRequest(); $decoded_response = $this->decodeResponse($response); @@ -66,8 +66,7 @@ function validateReceipt() { if (!is_object($decoded_response)) { throw new Exception('Invalid response data'); } - - return $decoded_response->receipt; + return $returnAll?$decoded_response:$decoded_response->receipt; } private function encodeRequest() {