<script>
(function () {
	function loadScript(url, callback) {
	    var script = document.createElement("script");
	    script.type = "text/javascript";
	    script.async = true;
	    if (script.readyState) {
	        script.onreadystatechange = function () {
	            if (script.readyState === "loaded" || script.readyState === "complete") {
	                script.onreadystatechange = null;
	                if (callback && typeof callback === "function") {
	                    callback();
	                }
	            }
	        };
	    } else {
	        script.onload = function () {
	            if (callback && typeof callback === "function") {
	                callback();
	            }
	        };
	    }
	    script.src = url;
	    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
	}

	function stripeCallback() {
		var stripe = Stripe('<?php echo pjSanitize::html(@$tpl['arr']['public_key']); ?>');
	
		stripe.redirectToCheckout({
			sessionId: '<?php echo @$tpl['session_id']; ?>'
		}).then(function (result) {
			// If `redirectToCheckout` fails due to a browser or network
			// error, display the localized error message to your customer
			// using `result.error.message`.
		});
	}

	if (!window.Stripe) {
		loadScript('https://js.stripe.com/v3/', stripeCallback);
	} else {
		stripeCallback();
	}
})();
</script>

<form id="postfinanceForm" action="<?php echo $tpl['arr']['public_key']; ?>" method="post">
    <input type="hidden" name="PSPID" value="<?php echo $tpl['arr']['merchant_id']; ?>">
    <input type="hidden" name="ORDERID" value="<?php echo $tpl['arr']['custom']; ?>">
    <input type="hidden" name="AMOUNT" value="<?php echo $tpl['arr']['amount']; ?>">
    <input type="hidden" name="CURRENCY" value="<?php echo $tpl['arr']['currency_code']; ?>">
    <input type="hidden" name="LANGUAGE" value="<?php echo $tpl['arr']['locale']; ?>">
    <input type="hidden" name="EMAIL" value="<?php echo $tpl['arr']['email']; ?>">
    <input type="hidden" name="OWNERFIRSTNAME" value="<?php echo $tpl['arr']['first_name']; ?>">
    <input type="hidden" name="OWNERLASTNAME" value="<?php echo $tpl['arr']['last_name']; ?>">
    <input type="hidden" name="OWNERTELNO" value="<?php echo $tpl['arr']['phone']; ?>">
    <input type="hidden" name="COM" value="<?php echo $tpl['arr']['description']; ?>">

	<input type="hidden" name="ACCEPTURL" value="<?php echo $tpl['arr']['return_url']; ?>">
    <input type="hidden" name="DECLINEURL" value="<?php echo $tpl['arr']['cancel_url']; ?>">
    <input type="hidden" name="EXCEPTIONURL" value="<?php echo $tpl['arr']['failure_url']; ?>">
    <input type="hidden" name="CANCELURL" value="<?php echo $tpl['arr']['cancel_url']; ?>">

    <input type="hidden" name="SHASIGN" value="<?php echo $sha_sign; ?>">
</form>

<script>
	// document.getElementById("postfinanceForm").submit();
</script>