diff --git a/itunesReceiptValidator.php b/itunesReceiptValidator.php index 90c0df4..39cd980 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->setPassword($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) {