Phase 5 complete: - guard purchase event per transaction in sessionStorage - restore saved consent before GTM and purchase - add centered Przelewy24 countdown redirect
120 lines
4.2 KiB
PHP
120 lines
4.2 KiB
PHP
<?php
|
|
$purchaseDataLayerJson = null;
|
|
if (is_array($this->purchase_data_layer ?? null)) {
|
|
$purchaseDataLayerJson = json_encode(
|
|
$this->purchase_data_layer,
|
|
JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_INVALID_UTF8_SUBSTITUTE
|
|
);
|
|
}
|
|
?>
|
|
|
|
<?php if($purchaseDataLayerJson) : ?>
|
|
<script type="text/javascript">
|
|
(function() {
|
|
var purchaseDataLayer = <?= $purchaseDataLayerJson; ?>;
|
|
var transactionId = purchaseDataLayer &&
|
|
purchaseDataLayer.ecommerce &&
|
|
purchaseDataLayer.ecommerce.transaction_id;
|
|
var purchaseSent = false;
|
|
|
|
if (transactionId) {
|
|
try {
|
|
var storageKey = 'brzezovka_purchase_sent_' + transactionId;
|
|
purchaseSent = sessionStorage.getItem(storageKey) === '1';
|
|
|
|
if (!purchaseSent) {
|
|
sessionStorage.setItem(storageKey, '1');
|
|
}
|
|
} catch (error) {
|
|
purchaseSent = false;
|
|
}
|
|
}
|
|
|
|
if (!purchaseSent) {
|
|
window.dataLayer = window.dataLayer || [];
|
|
window.dataLayer.push({ ecommerce: null });
|
|
window.dataLayer.push(purchaseDataLayer);
|
|
}
|
|
})();
|
|
</script>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
$clientData = $this->order;
|
|
$merchant_id = $this->settings['p24']['merchant_id'];
|
|
$pos_id = $this->settings['p24']['pos_id'];
|
|
|
|
$crc_key = '';
|
|
|
|
if($this->settings['p24']['sandbox']) {
|
|
$crc_key = $this->settings['p24']['sandbox_crc_key'];
|
|
} else {
|
|
$crc_key = $this->settings['p24']['crc_key'];
|
|
}
|
|
?>
|
|
|
|
<div class="spinner_container">
|
|
<?= \Tpl::view( 'components/spinner'); ?>
|
|
</div>
|
|
|
|
<form
|
|
action="<?= $this -> settings['p24']['sandbox'] ? 'https://sandbox.przelewy24.pl/trnDirect' : 'https://secure.przelewy24.pl/trnDirect';?>"
|
|
method="post" class="form" id="form_data" accept-charset="ISO-8859-2">
|
|
<input type="hidden" name="p24_session_id" value="<?= $this -> przelewy24_hash; ?>" />
|
|
<input type="hidden" name="p24_merchant_id" value="<?= $merchant_id; ?>" />
|
|
<input type="hidden" name="p24_pos_id" value="<?= $pos_id; ?>" />
|
|
<input type="hidden" name="p24_amount" value="<?= $clientData['order_price'] * 100;?>" />
|
|
<input type="hidden" name="p24_currency" value="PLN" />
|
|
<input type="hidden" name="p24_description" value="Zamówienie nr <?= $clientData['id']; ?>" />
|
|
<input type="hidden" name="p24_client" value="<?= $clientData['name'] . ' ' . $clientData['surname'];?>" />
|
|
<input type="hidden" name="p24_zip" value="<?= $clientData['zip_code']; ?>" />
|
|
<input type="hidden" name="p24_city" value="<?= $clientData['city']; ?>" />
|
|
<input type="hidden" name="p24_country" value="PL" />
|
|
<input type="hidden" name="p24_email" value="<?= $clientData['email']; ?>" />
|
|
<input type="hidden" name="p24_language" value="pl" />
|
|
<input type="hidden" name="p24_url_status"
|
|
value="https://<?= $_SERVER['SERVER_NAME'];?>/tickets/przelewy24_response/" />
|
|
<input type="hidden" name="p24_url_return"
|
|
value="https://<?= $_SERVER['SERVER_NAME'];?>/tickets/order_confirm/order=<?= $this -> order['hash'];?>" />
|
|
<input type="hidden" name="p24_api_version" value="3.2" />
|
|
<input type="hidden" name="p24_wait_for_result" value="1">
|
|
<input type="hidden" name="p24_method" value="227">
|
|
<input type="hidden" name="p24_sign"
|
|
value="<?= md5( $this -> przelewy24_hash . '|' . $merchant_id . '|' . ( $clientData['order_price'] * 100 ) . '|PLN|' . $crc_key );?>" />
|
|
|
|
<div class="container py-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-12 col-md-8 col-lg-6">
|
|
<div class="alert alert-info text-center shadow-sm mb-0" role="alert">
|
|
<h4 class="alert-heading mb-3">Przekierowanie do platnosci</h4>
|
|
<p class="mb-2">Za chwile nastapi automatyczne przejscie do Przelewy24.</p>
|
|
<p class="mb-0">
|
|
Pozostalo
|
|
<strong><span id="redirectCountdown">5</span> s</strong>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
<script type="text/javascript">
|
|
$(document).ready(function() {
|
|
var secondsLeft = 5;
|
|
var countdownElement = $("#redirectCountdown");
|
|
|
|
var countdownInterval = setInterval(function() {
|
|
secondsLeft -= 1;
|
|
countdownElement.text(secondsLeft);
|
|
|
|
if (secondsLeft <= 0) {
|
|
clearInterval(countdownInterval);
|
|
}
|
|
}, 1000);
|
|
|
|
setTimeout(function() {
|
|
$("#form_data").submit();
|
|
}, 5000);
|
|
});
|
|
</script>
|