<?php
// Include the configuration file
require_once 'config.php';
include_once 'dbConnect.php';
header('Access-Control-Allow-Origin: *'); //for al
//header( 'Access-Control-Allow-Headers: Accept, Accept-Encoding, Accept-Language, Authorization, Cache-Control, Pragma, Content-Type, Origin, Referer, Sec-Fetch-Dest, Sec-Fetch-Mode, Sec-Fetch-Site, User-Agent, X-Requested-With');

////////////////////////
// https://crowdkode.com/pay/check.php?memID=4&chID=4&memEmail=sillystats@gmail.com
// https://crowdkode.com/pay/?mID=4&cID=300&mE=sillystats@gmail.com&eP=0.25
// NEW   
// https://crowdkode.com/pay/?mID=4&cR=300&mE=sillystats@gmail.com&eP=0.01
////////////////////////

// Credits 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;
//}
// PRICE
if (isset($_POST['eP'])) {
	$checkeP = $_POST['eP']. "<br />";
	//echo "eP: " . $checkeP;
	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;
}

/* mID=4&cR=300&mE=sillystats@gmail.com&eP=0.01 */

// 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;
//}
// MEMBER ID
if (isset($_POST['mID'])) {
	$checkmemID = (int)$_POST['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;
}

// Credits Total/Amount
if (isset($_GET['cR'])) {
	$checkchID = (int)$_GET['cR'];
	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 />";
	}
	
	// GET THE CHALLENGE INFO
//	$sqlQ2 = "SELECT title FROM projects WHERE id = ?";
//	$stmt2 = $db->prepare($sqlQ2);
//	$stmt2->bind_param("s", $dbsafechID);
//	$stmt2->execute();
//	$stmt2->store_result();
//
//	if ($stmt2->num_rows > 0) {
//		// Get transaction details
//		$stmt2->bind_result($challengeTitle);
//		$stmt2->fetch();
//	}
} else {
	$warningCID = 1;
}

// TOTAL VOTES
if (isset($_POST['cR'])) {
	$checkchID = (int)$_POST['cR'];
	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;
}
// MEMBER EMAIL
//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;
//}

if (isset($_POST['mE'])) {
	//$cleanEmail = filter_var($_GET['memEmail'], FILTER_SANITIZE_EMAIL);
	$sanitizedEmail = filter_var($_POST['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 = "CrowdKode Credits: " . $dbsafechID;
$itemPrice = $dbsafeeP; 

//$queryString .= "&invoice=" . urlencode($invoiceContent); // this one works
//$queryString .= "&invoice_id=invoiceIDparam123";
//$queryString .= "&on0=OrderID";
//$queryString .= "&os0=" . urlencode($orderid);
//$queryString .= "&handling_cart=" . urlencode($transactionfee);
// https://crowdkode.com/pay/?mID?mID=4&cID=300&mE=sillystats@gmail.com&eP=0.01
?>

<!DOCTYPE html>
<html lang="en-US">
	<head>
		<title>CrowdKode Checkout</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">

		<link rel="preconnect" href="https://fonts.googleapis.com">
		<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
		<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
		<link href='//fonts.googleapis.com/css?family=Open+Sans:400,600,700,300' rel='stylesheet' type='text/css'>

		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<link rel="apple-touch-icon" href="/assets/logo.png" />

		<style>
			body, html {
				background:#eee;
				font-family: Montserrat,Helvetica,Verdana,sans-serif;
			}
			a, a:active, a:visited, a:link {
				text-decoration: none;
			}
			h1, h2, h3, h4, h5, h6 {
				font-family: Montserrat,Helvetica,Verdana,sans-serif;
			}
			/*body {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100vh;
			margin: 0;
			}*/

			/*.container {
			display: flex;
			flex-direction: column;
			text-align: center;
			background-color: lightgray;
			max-width: 500px;
			min-height: 15em;
			padding: 20px;
			}*/
			#btn-appl {
				display: inline-block;
				width: var(--apple-pay-button-width, auto);
				min-width: 340px !important;
				width:  340px !important;
				min-height: 45px;
				height: 45px !important;
			}
			.apple-pay-btn {
				height: 45px !important;
				width:  340px !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, 45px)) !important;
				min-width: var(--apple-pay-button-width-default, 340px) !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: 45px !important;
				min-height: 45px !important;
				-apple-pay-button-type: black !important; /* Use any supported button type. */
				-apple-pay-button-style: black !important;
			}

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

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

			/* Portrait tablet to landscape and desktop */
			@media (min-width: 980px) and (max-width: 1024px) {
				.logintext {
					margin-bottom: 7px;
				}
			}

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

			}

			/* Landscape phone to portrait tablet */
			@media (max-width: 767px) {
				.logintext {
					margin-bottom: 7px;
				}
			}

			/* Landscape phones and down */
			@media (max-width: 586px) {
				.spacer {
					padding-top: 56px !important;
				}
				.logintext {
					margin-bottom: 7px;
				}
				.half {
					float: none;
					width: 100%;
					display: block;
					overflow: hidden;
					padding-bottom: 35px;
				}
			}

			/* Landscape phones and down */
			@media (max-width: 480px) {
				.logintext {
					margin-bottom: 7px;
				}
			}

			/* Older phones with super small screens, iPhone SE */
			@media (max-width: 375px) {
				.logintext {
					margin-bottom: 7px;
				}
				#applepay-container {
					flex-grow: 1;
					/*width:320px !important;
					min-width:320px !important;*/
					max-width: 330px !important;
					height: 45px !important;
					min-height: 45px !important;
					margin-bottom: 15px;
				}
				apple-pay-button {
					--apple-pay-button-width: 330px;
					--apple-pay-button-height: 47px;
					--apple-pay-button-border-radius: 5px;
					--apple-pay-button-padding: 5px 0px;
				}
				#btn-appl {
					display: inline-block;
					width: var(--apple-pay-button-width, auto);
					/*min-width: 320px;*/
					max-width:330px !important;
					min-height: 45px;
					height: 45px !important;
				}

				button.apple-pay-btn.black {
					height: 45px !important;
				}

				.apple-pay-btn-wrapper.buy.en-US, .apple-pay-btn-wrapper {
					min-height: 45px !important;
					height: 45px !important;
				}

				.apple-pay-btn-wrapper .apple-pay-btn {
					height: calc(var(--apple-pay-button-height, 45px)) !important;
				}

				.apple-pay-button {
					height: 45px !important;
					min-height: 45px !important;
				}
				.apple-pay-button-black {
					-apple-pay-button-style: black;
					height: 45px !important;
					min-height: 45px !important;
				}
			}
		</style>

		<!-- Stylesheet file -->
		<link rel="stylesheet" href="css/style.css">

		<!-- PayPal JS SDK -->
		<!--<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID&currency=USD&buyer-country=US&merchant-id=SUB_MERCHANT_ID&components=applepay"></script>-->
		<!-- THIS IS THE OFFICIAL SCRIPT THAT WORKS -->
		<script src="https://www.paypal.com/sdk/js?client-id=AZsMPHqx0TlbCyV_8AY5LlNzzmilpaP8lbfQQQ4iPRpk_WC8hOWFWdvnGMgln4RJAAO2oWd7g1PhhMtu&currency=USD&merchant-id=H6MLL7DW7SMQ6&components=buttons,applepay&enable-funding=venmo&disable-funding=paylater" data-partner-attribution-id="APPLEPAY"> </script>
		<!-- data-partner-attribution-id="APPLEPAY"  -->
		<script src="https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js"> </script>
		<script src="app.js"> </script>
		
		<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" 
		type="text/javascript"> </script>
		<script type="text/javascript" 
		src="//ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"> </script>
		<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
	</head>
	<body>
	
	<script type="text/javascript">
		$(document).ready(function() {
			//alert('doc ready works!');
			// App Mode Detection
			var standalone = window.navigator.standalone,
			userAgent = window.navigator.userAgent.toLowerCase(),
			//safari = /safari/.test( userAgent ),
			safari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
			ios = /iphone|ipod|ipad/.test( userAgent );
			android = (window.matchMedia('(display-mode: standalone)').matches);

			if (android == true) {
			}

			if (window.navigator.standalone == true) {
				//alert("You're using our Hybrid App!");
				// Super small phones
				if ($(window).width() <= 375) {
				}
				// iPad Portrait
				if ($(window).width() == 768) {
					//alert("You're using our Hybrid App!");
				}
				if ($(window).width() >= 1024) {
					//alert("You're using our Hybrid App and this is probably an iPad!");
				}
			} else {
				//alert('Not stand-alone');
				// NOT STAND-ALONE
				if ( ios ) {
					if ( !standalone && !safari ) {
						//alert("You're using the Native App.");
					};
					if ( !standalone && safari ) {
						//alert("You're using Mobile Safari.");
						// iPad Portrait
						//if ($(window).width() == 768) {
						//	alert("You're using our iPad upright version!");
						//}
					};
				} else {
					//alert("You're using desktop");
					if (safari) {
						//alert('Desktop AND Safari');
					} else {
						//alert('Desktop, but NOT Safari');
						document.querySelector("#applepay-container").classList.add("hidden");	
					}
//					if (!android) {
//						// alert('Not iOS and not Hybrid App');
//					}
//					if (window.matchMedia("(max-width: 480px)").matches) {
//					}
				}
			}
		});
	</script>
	
<!--	<script>
		var PAYPAL_SCRIPT = 'https://www.paypal.com/sdk/js?client-id=AZsMPHqx0TlbCyV_8AY5LlNzzmilpaP8lbfQQQ4iPRpk_WC8hOWFWdvnGMgln4RJAAO2oWd7g1PhhMtu&currency=USD&merchant-id=H6MLL7DW7SMQ6&components=buttons,applepay&enable-funding=venmo" data-partner-attribution-id="APPLEPAY';
		var script = document.createElement('script');
		script.setAttribute('src', PAYPAL_SCRIPT);
		document.head.appendChild(script);
	</script>-->

		<!--XMLHttpRequest cannot load https://www.paypal.com/xoplatform/logger/api/logger?disableSetCookie=true due to access control checks.-->
	<div style="position:absolute; top:15; left:20; width:30px;">
		<a href="/load" style="color:#000; font-weight:500; font-size:24px;">
		<i class="fa fa-angle-left" aria-hidden="true"></i></a> 
	</div>
	<div class="container">
	
			<center><img src="/static/client/crowd_kode_logo_black.png"
				style="max-width:350px; width:85%;" alt="CrowdKode" /></center>
				
			<h1 style="color:#000; font-weight:400; font-size:22px !important; margin-top:0px">
				<img src="/static/images/icons/green_lock_icon.png" alt="Lock"
				align="absmiddle" style="height:30px; margin-bottom:0px; margin-top:-5px">Secure 
				Checkout <span style="font-size:15px; color:#ccc;">v7.1</span>
			</h1>
			<div class="panel" style="-webkit-border-radius: 12px; -moz-border-radius: 12px; 
				border-radius: 12px; padding-top:15px; margin-bottom:10px;">
				<div class="overlay hidden">
					<div class="overlay-content"><img src="css/loading.gif" alt="Processing..." /></div>
				</div>

				<div class="panel-heading" style="background:none; border-bottom:1px dashed #ddd;
					margin:0 20px; padding:0; min-height:45px; text-align:center; font-size:22px">

					<!--<h3 class="panel-title">Charge <?php echo '$'.$itemPrice; ?> with PayPal</h3>-->

					<!-- Product Info -->
					<!--<p><b>Item Name:</b> <?php echo $itemName; ?></p>-->
					<!--<p><b>Price:</b> <?php echo '$'.$itemPrice.' '.$currency; ?></p>-->

					<div style="text-transform: uppercase; letter-spacing: 2px; font-size:12px;
						text-align:center; font-weight:600">
						CrowdKode Vote Credits:
					</div>
					<div class="clear"></div>
					<span style="color:#18bf38; 
						font-size:34px; font-weight:500"><?php echo $dbsafechID ?></span> <img 
					src="/static/system/animated_checkmark_vote.gif" alt="X" 
					align="absmiddle" style="height:22px; margin:-15px 3px 0 0;"> for $<?php echo $itemPrice ?>
					
					<!--<p style="margin:0; padding:0 0 0px 0">
						<?php echo substr($challengeTitle,0,35); ?>
					</p>-->
					
					<input type="hidden" id="t_amount" value="<?php echo $dbsafeeP ?>" 
					style="width:40px;">
				
					<input type="hidden" id="mem_ID" value="<?php echo $memInfo ?>" style="float:right;">
					<input type="hidden" id="ch_ID" value="<?php echo $dbsafechID ?>" style="float:right;">
				</div> 
				<div class="panel-body">
					<!-- Display status message -->
					<div id="paymentResponse" class="hidden"></div>

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

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

					<!-- Set up a container element for the button -->
					<div id="paypal-button-container"></div>
				</div>
				<div class="clear"></div>
				<div style="color:#ccc; margin-bottom:5px; text-align:center;">
					<a href="/load" style="color:#ccc; font-weight:500; font-size:14px;">
					<i class="fa fa-angle-left" aria-hidden="true"></i> Back to Load page</a> 
					<!--&nbsp; | &nbsp;&nbsp; 
						<a href="javascript:top.frames.location.reload();"
					class="refresh" style="color:#ccc; font-weight:500; font-size:17px;">
					<i class="fa fa-refresh" aria-hidden="true"></i> Refresh</a>-->
				</div>
				<div class="clear"></div>
			</div><!-- END OF PANEL -->
					
			<div style="text-align:center; max-width:350px; margin:0 auto; padding:0 10px; 
			  font-size:14px; color:#aaa; line-height:17px">
				  <img src="/static/images/icons/green_lock_icon.png" alt="Lock" 
				  align="absmiddle" style="height:20px; margin-bottom:5px"> Secure Checkout powered by 
				  Paypal is PCI-Compliant &amp; uses SSL to protect your payment method(s).
				  <br><br>
			  	<span style="font-weight:400;">We accept...</span>
			  	<br>
			  	<img src="/static/client/credit_card_icons_transparent.png" 
				  alt="CC We Accept" style="max-width:200px; width:100%; margin-top:2px;
				  -webkit-border-radius: 8px; -moz-border-radius: 8px; border-radius: 8px;">
				  <br /><br />
				  <!-- Λ -->
			  		© 2024
			  	<a href="https://crowdkode.com" title="CrowdKode" 
			  	style="color:#999; font-weight:300; text-decoration:none">CrowdKode, LLC</a> • All 
			  	rights reserved • Made in Chicago by
				<a href="https://dev11.com/" title="dev11" target="_blank" 
				  style="color:#999; font-weight:400; text-decoration:none">dev11</a> &bull;
				<a href="javascript:top.frames.location.reload();" class="refresh" 
				  style="text-decoration:none; color:#999">Reload</a>
			  	<br><br>	  	
			  	
			</div>	
		</div>

		<script>
			paypal.Buttons({
				// Sets up the transaction when a payment button is clicked
//				invoice: invoiceid_txt,
//				invoice_id: invoiceid_txt,
//				item_number_1: '5',
//				item_number1: '1',
//				item_number: '4',
//				reference_id: 'referenceID',
				createOrder: (data, actions) => {
					return actions.order.create({
						"purchase_units": [{
								"custom_id": "<?php echo $itemNumber; ?>",
								"description": "<?php echo $itemName; ?>",
								"item_number_1": "CrowdKodeCredits",
								"item_number1": "CrowdKodeCredits2",
								"reference_id": "CrowdKodeRefID",
								"invoice": "CrowdKodeInv",
								"invoice_id": "CrowdKodeInv2",
								"amount": {
									"currency_code": "<?php echo $currency; ?>",
									"value": <?php echo $itemPrice; ?>,
									"breakdown": {
										"item_total": {  /* Required when including the items array */
											"currency_code": "<?php echo $currency; ?>",
											"value": <?php echo $itemPrice; ?>
										}
									}
								},
								"items": [
									{
										"name": "<?php echo $itemName; ?>", /* Shows within upper-right dropdown during payment approval */
										"description": "<?php echo $itemName; ?>", /* Item details will also be in the completed paypal.com transaction view */
										"unit_amount": {
											"currency_code": "<?php echo $currency; ?>",
											"value": <?php echo $itemPrice; ?>
										},
										"quantity": "1",
										"category": "DIGITAL_GOODS",
										"shipping_preference": "NO_SHIPPING"
									},
								]
						}],
						"payment_source": {
							"paypal": {
								"experience_context": {
									"shipping_preference": "NO_SHIPPING",
								}
							}
						}
					});
				},
				// Finalize the transaction after payer approval
				onApprove: (data, actions) => {
					return actions.order.capture().then(function(orderData) { //console.log(orderData);
						// Successful capture! For dev/demo purposes:
						//console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
						//const transaction = orderData.purchase_units[0].payments.captures[0]; //console.log(transaction);
						//alert(`Transaction ${transaction.status}: ${transaction.id}\n\nSee console for all available details`);
						// When ready to go live, remove the alert and show a success message within this page. For example:
						// const element = document.getElementById('paypal-button-container');
						// element.innerHTML = '<h3>Thank you for your payment!</h3>';
						// Or go to another URL:  actions.redirect('thank_you.html');

						setProcessing(true);

						var postData = {paypal_order_check: 1, order_id: orderData.id};
						fetch('paypal_checkout_validate.php', {
							method: 'POST',
							headers: {'Accept': 'application/json'},
							body: encodeFormData(postData)
						})
						.then((response) => response.json())
						.then((result) => {
							if (result.status == 1) {
								window.location.href = "payment-status.php?checkout_ref_id="+result.ref_id;
							} else {
								const messageContainer = document.querySelector("#paymentResponse");
								messageContainer.classList.remove("hidden");
								messageContainer.textContent = result.msg;

								setTimeout(function () {
									messageContainer.classList.add("hidden");
									messageText.textContent = "";
								}, 5000);
							}
							setProcessing(false);
						})
						.catch(error => console.log(error));
					});
				}
			}).render('#paypal-button-container');

			const encodeFormData = (data) => {
				var form_data = new FormData();

				for ( var key in data ) {
					form_data.append(key, data[key]);
				}
				return form_data;
			}

			// Show a loader on payment form processing
			const setProcessing = (isProcessing) => {
				if (isProcessing) {
					document.querySelector(".overlay").classList.remove("hidden");
				} else {
					document.querySelector(".overlay").classList.add("hidden");
				}
			}
			//  document.querySelector("#applepay-container").classList.add("hidden");			
		</script>
	</body>
</html>