<?php 

require_once 'config.php'; 
include_once 'dbConnect.php';

	////////////////////////
	// https://voicetrivia.com/pay/check.php?memID=4&chID=4&memEmail=sillystats@gmail.com
	// https://voicetrivia.com/pay/applepay.php?mID=4&cID=300&mE=sillystats@gmail.com&eP=1
	////////////////////////

	// EntryPass Price
	if (isset($_GET['eP'])) {
		$checkeP = $_GET['eP'];
		if ($checkeP != '') {
			//echo "Not 0";
			//echo $checkeP . "<br />";
			$cleanchars3  = preg_replace('/[^-a-zA-Z0-9_.]/', '', $checkeP);
			$removeticks3 = preg_replace("/[^a-zA-Z0-9.]+/", "", html_entity_decode($cleanchars3, ENT_QUOTES));
			$dbsafeeP = mysqli_real_escape_string($db,$removeticks3);
			//echo $dbsafeeP . "<br />";
		}
	} else {
		$warningEP = 1;
	}

	// Member/User ID
	if (isset($_GET['mID'])) {
		$checkmemID = (int)$_GET['mID'];
		if ($checkmemID != 0) {
			//echo "Not 0";
			$cleanchars  = preg_replace('/[^-a-zA-Z0-9_]/', '', $checkmemID);
			$removeticks = preg_replace("/[^a-zA-Z0-9]+/", "", html_entity_decode($cleanchars, ENT_QUOTES));
			$dbsafememID = mysqli_real_escape_string($db,$removeticks);
			//echo "checkmemID: " . $dbsafememID . "<br />";
		}
	} else {
		$warningMID = 1;
	}

	// Challenge ID
	if (isset($_GET['cID'])) {
		$checkchID = (int)$_GET['cID'];
		if ($checkchID != 0) {
			//echo "Not 0";
			$cleanchars2  = preg_replace('/[^-a-zA-Z0-9_]/', '', $checkchID);
			$removeticks2 = preg_replace("/[^a-zA-Z0-9]+/", "", html_entity_decode($cleanchars2, ENT_QUOTES));
			$dbsafechID = mysqli_real_escape_string($db,$removeticks2);
			//echo "checkchID: " . $dbsafechID . "<br />";
		}
	} else {
		$warningCID = 1;
	}

	if (isset($_GET['mE'])) {
		//$cleanEmail = filter_var($_GET['memEmail'], FILTER_SANITIZE_EMAIL);
		$sanitizedEmail = filter_var($_GET['mE'], FILTER_SANITIZE_STRING);
		$cleanEmail = filter_var($sanitizedEmail, FILTER_SANITIZE_EMAIL);
		$dbsafechEmail = mysqli_real_escape_string($db,$cleanEmail);
		//echo "cleanEmail: " . $cleanEmail . "<br />";
	} else {
		$warningME = 1;
	}

	$memInfo = $dbsafememID.",".$dbsafechID.",".$dbsafechEmail;
	// DYNAMIC VARIABLES
	$itemNumber = $dbsafememID.",".$dbsafechID.",".$dbsafechEmail;
	//$itemName = "EntryPass for Trivia Challenge ID: " . $dbsafechID;
	$itemPrice = $dbsafeeP; 
?>
<style>
	body, html {
		margin: 0; padding:0;
	}
	/*apple-pay-button apple-pay-button-white" id="btn-appl"*/
	#btn-appl {
		display: inline-block;
		width: var(--apple-pay-button-width, auto);
		/*min-width: 320px;*/
		min-height: 40px;
		height: 40px !important;
	}
	.apple-pay-btn {
		height: 40px !important;
	}

	.apple-pay-btn {
		background-color: black;
		border-top-style: none;
		border-right-style: none;
		border-bottom-style: none;
		border-left-style: none;
		color: white;
		cursor: pointer;
		font-synthesis-small-caps: none;
		font-synthesis-style: none;
		font-synthesis-weight: none;
		justify-content: center;
		position: relative;
		margin-top: 0px;
		box-sizing: var(--apple-pay-button-box-sizing, content-box);
		/*min-height: 45px !important;
		height:45px !important;*/
		height: calc(var(--apple-pay-button-height, 40px)) !important;
		min-width: var(--apple-pay-button-width-default, 320px) !important;
		width: 100% !important;
		border-top-left-radius: ;
		border-top-right-radius: ;
		border-bottom-right-radius: ;
		border-bottom-left-radius: ;
		padding-top: ;
		padding-right: ;
		padding-bottom: ;
		padding-left: ;
		-webkit-font-smoothing: antialiased;
	}

	.apple-pay-button {
		display: inline-block;
		-webkit-appearance: -apple-pay-button;
		height: 40px !important;
		min-height: 40px !important;
		-apple-pay-button-type: plain !important; /* Use any supported button type. */
		-apple-pay-button-style: plain !important;
	}

	#applepay-container {
		flex-grow: 1;
		/*width:320px !important;
		min-width:320px !important;*/
		max-width: 305px !important;
		height: 40px !important;
		min-height: 40px !important;
		margin-bottom: 0px;
		float: right;
		text-align: right;
		margin-top: 0px;
	}

	/* ################################### */
	/*            MOBILE STYLES            */
	/* ################################### */

	/* Portrait tablet to landscape and desktop */
	@media (min-width: 980px) and (max-width: 1024px) {
	}

	/* Portrait tablet to landscape and desktop */
	@media (min-width: 768px) and (max-width: 979px) {
	}

	/* Landscape phone to portrait tablet */
	@media (max-width: 767px) {
	}

	/* Landscape phones and down */
	@media (max-width: 586px) {

	}

	/* Landscape phones and down */
	@media (max-width: 480px) {
		#btn-appl {
			display: inline-block;
			width: var(--apple-pay-button-width, auto);
			/*min-width: 320px;*/
			min-height: 49px;
			height: 49px !important;
			background: none;
		}
	}

	/* Older phones with super small screens, iPhone SE */
	@media (max-width: 375px) {

	}
</style>
<!--				<script>
var scriptElem = document.createElement('script');
scriptElem.src = 'https://www.paypal.com/sdk/js?client-id=AZsMPHqx0TlbCyV_8AY5LlNzzmilpaP8lbfQQQ4iPRpk_WC8hOWFWdvnGMgln4RJAAO2oWd7g1PhhMtu&currency=USD&merchant-id=H6MLL7DW7SMQ6&components=applepay&enable-funding=venmo';
document.getElementsByTagName('head')[0].appendChild(scriptElem);
</script>-->
<!-- RANDOM &cid=<?php echo rand() ?> -->
<script defer src="https://www.paypal.com/sdk/js?client-id=AZsMPHqx0TlbCyV_8AY5LlNzzmilpaP8lbfQQQ4iPRpk_WC8hOWFWdvnGMgln4RJAAO2oWd7g1PhhMtu&currency=USD&merchant-id=H6MLL7DW7SMQ6&components=applepay" data-partner-attribution-id="APPLEPAY"> </script>

<script src="https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js"> </script>
<script src="https://voicetrivia.com/pay/app.js"> </script>

<div style="background:#ff0000 url('static/images/icons/applepay.png') no-repeat; 
width:100%; max-width:100px; height:51px;">

	<input type="hidden" id="t_amount" value="<?= $project['tamount'] ?>"
	style="width:40px; margin-left:10px">

	<input type="hidden" id="mem_ID" value="<?= $_SESSION['user']['email'] ?>"
	style="float:right;">
	<!-- Display status message -->
	<!--<div id="paymentResponse" class="hidden"></div>-->

	<p id="result-message" class="hidden"
		style="display:none; background:#00c808; color:#fff; padding:7px; text-align:center;
		-webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px; line-height:22px;">
		<!--Thank you! Your ApplePay payment was successful.-->
	</p>

	<div id="applepay-container"></div>
</div>