paypalListener

$value) {
$value = urlencode($value);
$ret .= ‘&’ . $key . ‘=’ . $value;
}

// Post IPN back to Paypal
if(USE_SANDBOX == true) {
$paypal_url = “https://www.sandbox.paypal.com/cgi-bin/webscr”;
} else {
$paypal_url = “https://www.paypal.com/cgi-bin/webscr”;
}
$rest = curl_init();
curl_setopt($rest, CURLOPT_URL, $paypal_url);
curl_setopt($rest, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($rest, CURLOPT_POST, 1);
curl_setopt($rest, CURLOPT_RETURNTRANSFER,1);
curl_setopt($rest, CURLOPT_POSTFIELDS, $ret);
curl_setopt($rest, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($rest, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($rest, CURLOPT_FORBID_REUSE, 1);
// Set TCP timeout to 30 seconds
curl_setopt($rest, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($rest, CURLOPT_HTTPHEADER, array(‘Connection: Close’));

$response = curl_exec($rest);
errLog(“TEST”);
errLog($response);

if (strcmp($response, ‘VERIFIED’) == 0) {
// Got verified. Can process IPN now
// Make a few checks to ensure IPN is valid
// Check if payment status is complete
if (strcmp($_POST[‘payment_status’], ‘Completed’) == 0) {
// Check if receiver email is correct
if (strcmp($_POST[‘receiver_email’], RECEIVER_EMAIL) == 0) {
// Checks complete.
$customArray = explode(‘,’, $_POST[‘custom’]);
$userId = $customArray[0];
$email = $customArray[1];
$itemId = $_POST[‘item_number’];
$price = $_POST[‘mc_gross’];
$subscrId = $_POST[‘subscr_id’];
$referrer = $_POST[‘option_selection1’];
// Get months from item
switch($itemId) {
case “oneMonthSub”:
$months = 1;
break;
case “twelveMonthSub”:
$months = 12;
break;
default:
$months = 0;
break;
}

// Get user from Parse table
$userUrl = ‘https://api.parse.com/1/users/’ . $userId;
$userHeader = array(
“X-Parse-Application-Id: 9s7Zfx1VQafAc1raQ9iHvWpNIfYk7nGV8YX8h5jq”,
“X-Parse-Master-Key: OteMK5EzwL4nl2gm1uR3qVXXxL54yL3PSsBDzCUl”,
“Content-Type: application/json”
);

// Set start date to current date and end date to date when billing period ends
$timezone = new DateTimeZone(“UTC”);
$startDate = new DateTime();
$endDate = new DateTime();
date_add($endDate, date_interval_create_from_date_string($months . ‘ months’));
$startDateStr = $startDate->format(‘Y-m-d\TG:i:s.u\Z’);
$endDateStr = $endDate->format(‘Y-m-d\TG:i:s.u\Z’);

$userData = ‘{“subscriptionEndDate”:{“__type”:”Date”,”iso”:”‘ . $endDateStr . ‘”},”subscriptionStartDate”:{“__type”:”Date”,”iso”:”‘ . $startDateStr . ‘”}}’;
$userRest = curl_init();
curl_setopt($userRest, CURLOPT_URL, $userUrl);
curl_setopt($userRest, CURLOPT_CUSTOMREQUEST, “PUT”);
curl_setopt($userRest, CURLOPT_HTTPHEADER, $userHeader);
curl_setopt($userRest, CURLOPT_POSTFIELDS, $userData);
curl_setopt($userRest, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($userRest, CURLOPT_RETURNTRANSFER, 1);
$userResponse = curl_exec($userRest);
curl_close($userRest);

errLog(“USER RESPONSE”);
errLog($userResponse);

// Make entry in subscription table
subTable($email, $referrer, $price, $subscrId, $itemId);
}
}
}

function errLog($error) {
error_log(print_r($error,1));
}

function subTable($email, $referrer, $price, $subscrId, $itemId) {
// If referrer is same as account email, do not add referrer
if ($referrer == $email) {
$referrer = “”;
}
$subDate = new DateTime();
$subDateStr = $subDate->format(‘Y-m-d\TG:i:s.u\Z’);
$subUrl = ‘https://api.parse.com/1/classes/Subscription’;
$subHeaders = array(
“X-Parse-Application-Id: 9s7Zfx1VQafAc1raQ9iHvWpNIfYk7nGV8YX8h5jq”,
“X-Parse-REST-API-Key: TiWvQ83bIfqAKIjl292jPN3zx3RIjDb15X5pYtKZ”,
“Content-Type: application/json”
);
$subData = ‘{“username”:”‘ . $email .'”,”subscriptionDate”:{“__type”:”Date”,”iso”:”‘ . $subDateStr . ‘”},”referrer”:”‘ . $referrer . ‘”,”price”:’ . $price . ‘,”subscriptionId”:”‘ . $subscrId . ‘”,”itemId”:”‘ . $itemId . ‘”}’;

$subRest = curl_init();
curl_setopt($subRest, CURLOPT_URL, $subUrl);
curl_setopt($subRest, CURLOPT_POST, true);
curl_setopt($subRest, CURLOPT_POSTFIELDS, $subData);
curl_setopt($subRest, CURLOPT_HTTPHEADER, $subHeaders);
curl_setopt($subRest, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($subRest, CURLOPT_RETURNTRANSFER, true);
$subResponse = curl_exec($subRest);
$subResponse = json_decode($subResponse, 1);
curl_close($subRest);
}
?>[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]

Download Now For FREE

SwingProfile golf swing analyzer and training aid is a must-have for golfers of all level.

Download on the App Store