PluginProbe
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / layouts / payments / paypal.php
paypal.php
106 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Layout variables
16 * -----------------
17 * @var array $data An associative array containing the transaction details.
18 * @var array $params An associative array with the payment configuration.
19 * @var array $form An associative array with the form data.
20 * @var string $payurl The PayPal end-point URL used to start the payment.
21 * @var boolean $paid True in case the payment transaction has been already made but
22 * the reservation hasn't been yet confirmed.
23 */
24 extract($displayData);
25
26 // NOTE: it is possible to override attributes of the $form
27 // array in order to change those fields that have been already
28 // filled in by the payment gateway.
29
30 if ($paid)
31 {
32 // transaction already made, display a message and wait for PayPal
33 // notifies the validation end-point
34 JFactory::getApplication()->enqueueMessage(JText::translate('VAP_PAYMENT_PAYPAL_PAID_MSG'));
35 }
36 else
37 {
38 ?>
39 <form action="<?php echo $payurl; ?>" method="post" name="paypalform">
40
41 <?php
42 foreach ($form as $k => $v)
43 {
44 // include input only if the value is not an empty string
45 if (strlen($v))
46 {
47 ?>
48 <input type="hidden" name="<?php echo $k; ?>" value="<?php echo $this->escape($v); ?>" />
49 <?php
50 }
51 }
52 ?>
53
54 <input type="image" src="<?php echo $params['image']; ?>" name="submit" id="paypal-btn" alt="PayPal - The safer, easier way to pay online!" style="border: 0;">
55
56 <?php
57 if (!empty($params['autosubmit']))
58 {
59 ?>
60 <script>
61 (function($) {
62 'use strict';
63
64 if (typeof Storage !== 'undefined') {
65 // build auto-submit key
66 const autoSubmitFlag = 'paypalAutoSubmit<?php echo $data['oid']; ?>';
67
68 // check if PayPal was already submitted
69 if (sessionStorage.getItem(autoSubmitFlag) == 1) {
70 // auto-submit only once per order
71 return false;
72 }
73
74 // register auto-submit
75 sessionStorage.setItem(autoSubmitFlag, 1);
76 }
77
78 const doAutoRedirect = () => {
79 // Auto-submit payment form.
80 // Don't need to wait for the page loading.
81 document.paypalform.submit();
82
83 // hide button after submitting the form
84 document.getElementById('paypal-btn').style.display = 'none';
85 }
86
87 // check whether both the elements are available
88 if (document.paypalform && document.getElementById('paypal-btn')) {
89 // immediately auto-redirect
90 doAutoRedirect();
91 } else {
92 // elements not yet available, wait for the page loading
93 $(function() {
94 doAutoRedirect();
95 });
96 }
97 })(jQuery);
98 </script>
99 <?php
100 }
101 ?>
102
103 </form>
104 <?php
105 }
106