// Function to get the current user.
// Returns and array with two elements.
// If found, the first element will be the object id of the user and second element is true.
// If not found, the first element will be null and the second element is false.
function getCurrentUser() {
$checkUrl = 'https://api.parse.com/1/users/me';
// Headers
$checkHeaders = array(
"X-Parse-Application-Id: 9s7Zfx1VQafAc1raQ9iHvWpNIfYk7nGV8YX8h5jq",
"X-Parse-REST-API-Key: TiWvQ83bIfqAKIjl292jPN3zx3RIjDb15X5pYtKZ",
"X-Parse-Session-Token: " . $_SESSION[fusion_builder_container hundred_percent="yes" overflow="visible"][fusion_builder_row][fusion_builder_column type="1_1" background_position="left top" background_color="" border_size="" border_color="" border_style="solid" spacing="yes" background_image="" background_repeat="no-repeat" padding="" margin_top="0px" margin_bottom="0px" class="" id="" animation_type="" animation_speed="0.3" animation_direction="left" hide_on_mobile="no" center_content="no" min_height="none"]['parseSessionToken']
);
// Set up and execute curl
$checkRest = curl_init();
curl_setopt($checkRest, CURLOPT_URL, $checkUrl);
curl_setopt($checkRest, CURLOPT_HTTPGET, 1);
curl_setopt($checkRest, CURLOPT_HTTPHEADER, $checkHeaders);
curl_setopt($checkRest, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($checkRest, CURLOPT_RETURNTRANSFER, true);
$checkResponse = curl_exec($checkRest);
$checkResponse = json_decode($checkResponse,true);
curl_close($checkRest);
if (isset($checkResponse['username'])) {
// Valid session token
$currentUser = $checkResponse['objectId'];
$email = $checkResponse['email'];
return array($currentUser, $email, true);
} else {
// Invalid session token
return array(null, null, false);
}
}
session_start();
$_SESSION['lastPageVisited'] = "http://www.swingprofile.com/purchase-subscription";
$currentUser = getCurrentUser();
if ($currentUser[2] === true) {
$email = $currentUser[1];
$userId = $currentUser[0];
// Valid session token
echo 'You are currently logged in with the email address: ' . $email;
//The POST data that will be sent to the server.
// 1 month coach
$postDataCoach1 = array(
'api_key' => ‘1f2835c54842b41d14117f8fa0058ba6f4f9e41d76d533b2a3b68a189cfddd1c’,
‘merchant_id’ => ‘B2A0E41840410’,
‘contract_id’ => ‘178C8F086B417’,
‘td_email’ => $email,
‘td_first_name’ => ”,
‘td_last_name’ => ”,
‘td_address’ => ”,
‘td_city’ => ”,
‘td_country’ => ”,
‘td_user_data’ => $userId
);
// 12 month coach
$postDataCoach12 = array(
‘api_key’ => ‘1f2835c54842b41d14117f8fa0058ba6f4f9e41d76d533b2a3b68a189cfddd1c’,
‘merchant_id’ => ‘B2A0E41840410’,
‘contract_id’ => ‘1CEDD3F7E529B6’,
‘td_email’ => $email,
‘td_first_name’ => ”,
‘td_last_name’ => ”,
‘td_address’ => ”,
‘td_city’ => ”,
‘td_country’ => ”,
‘td_user_data’ => $userId
);
// 1 month elite
$postDataElite1 = array(
‘api_key’ => ‘1f2835c54842b41d14117f8fa0058ba6f4f9e41d76d533b2a3b68a189cfddd1c’,
‘merchant_id’ => ‘B2A0E41840410’,
‘contract_id’ => ‘19605552AAA0F3’,
‘td_email’ => $email,
‘td_first_name’ => ”,
‘td_last_name’ => ”,
‘td_address’ => ”,
‘td_city’ => ”,
‘td_country’ => ”,
‘td_user_data’ => $userId
);
// 12 month elite
$postDataElite12 = array(
‘api_key’ => ‘1f2835c54842b41d14117f8fa0058ba6f4f9e41d76d533b2a3b68a189cfddd1c’,
‘merchant_id’ => ‘B2A0E41840410’,
‘contract_id’ => ‘289A2221DD34D’,
‘td_email’ => $email,
‘td_first_name’ => ”,
‘td_last_name’ => ”,
‘td_address’ => ”,
‘td_city’ => ”,
‘td_country’ => ”,
‘td_user_data’ => $userId
);
//Make the request to the server
$resultCoach1 = post_to_url(“https://api.swipehq.com/createSubscriptionIdentifier.php”, $postDataCoach1);
$resultCoach12 = post_to_url(“https://api.swipehq.com/createSubscriptionIdentifier.php”, $postDataCoach12);
$resultElite1 = post_to_url(“https://api.swipehq.com/createSubscriptionIdentifier.php”, $postDataElite1);
$resultElite12 = post_to_url(“https://api.swipehq.com/createSubscriptionIdentifier.php”, $postDataElite12);
//If we have encountered an error display something back to the customer.
if ($resultCoach1 === false || $resultCoach12 === false || $resultElite1 === false || $resultElite12 === false) {
echo ‘We have encountered an error!’;
exit;
} else {
$resultCoach1 = json_decode($resultCoach1,1);
$resultCoach12 = json_decode($resultCoach12,1);
$resultElite1 = json_decode($resultElite1,1);
$resultElite12 = json_decode($resultElite12,1);
$idCoach1 = $resultCoach1[‘data’][‘identifier’];
$idCoach12 = $resultCoach12[‘data’][‘identifier’];
$idElite1 = $resultElite1[‘data’][‘identifier’];
$idElite12 = $resultElite12[‘data’][‘identifier’];
echo ‘
Subscription Options
Purchase one of the follow subscription options by clicking on the button
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
}
// TEST
/* $postDataTest = array(
‘api_key’ => ‘1f2835c54842b41d14117f8fa0058ba6f4f9e41d76d533b2a3b68a189cfddd1c’,
‘merchant_id’ => ‘B2A0E41840410’,
‘contract_id’ => ’40F5D0CA26AC3′,
‘td_email’ => $email,
‘td_first_name’ => ”,
‘td_last_name’ => ”,
‘td_address’ => ”,
‘td_city’ => ”,
‘td_country’ => ”,
‘td_user_data’ => $userId
);
$resultTest = post_to_url(“https://api.swipehq.com/createSubscriptionIdentifier.php”, $postDataTest);
if ($resultTest == false) {
echo “Error with test”;
exit;
} else {
$resultTest = json_decode($resultTest,1);
$idTest = $resultTest[‘data’][‘identifier’];
echo ‘
‘;
} */
} else {
// Not logged in, redirect to log in page
echo “Redirecting to log in page.”;
echo ‘
‘;
}
?>
[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]