Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions itunesReceiptValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -24,6 +27,14 @@ function setReceipt($receipt) {
}
}

function getPassword(){
return $this->password;
}

function setPassword($password){
$this->password = $password;
}

function getEndpoint() {
return $this->endpoint;
}
Expand All @@ -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) {
Expand Down