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 / paypalec.php
vikappointments / site / layouts / payments Last commit date
fields.php 1 month ago index.html 1 month ago offcc.php 1 month ago paypal.php 1 month ago paypalec.php 1 month ago
paypalec.php
148 lines
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 $payer The billing details of the customer.
20 * @var string $sdkUrl The URL needed to load the SDK resources.
21 * @var string $notifyUrl The URL to reach to complete the payment validation.
22 */
23 extract($displayData);
24
25 JHtml::fetch('script', $sdkUrl);
26
27 ?>
28
29 <div id="paypal-button-container">
30 <!-- PayPal buttons will be rendered here -->
31 </div>
32
33 <script>
34 (function($) {
35 'use strict';
36
37 let notifyUrl = '<?php echo $notifyUrl; ?>';
38
39 // fetch customer details
40 const customer = <?php echo json_encode($payer); ?>;
41
42 // set up PayPal payer billing details
43 const payer = {};
44
45 if (customer.name) {
46 // inject name
47 payer.name = {
48 given_name: customer.first_name,
49 surname: customer.last_name,
50 };
51 }
52
53 if (customer.email) {
54 // inject e-mail address
55 payer.email_address = customer.email;
56 }
57
58 /**
59 * DO NOT pass the phone number because, in case it doesn't meet the
60 * PayPal format requirements, the whole request would fail.
61 */
62
63 if (customer.country) {
64 // inject country code
65 payer.address = {
66 country_code: customer.country,
67 };
68
69 if (customer.address1) {
70 // inject address
71 payer.address.address_line_1 = customer.address1;
72
73 if (customer.address2) {
74 // inject address
75 payer.address.address_line_2 = customer.address2;
76 }
77 }
78
79 if (customer.state) {
80 // inject state/province
81 payer.address.admin_area_1 = customer.state;
82 }
83
84 if (customer.city) {
85 // inject city
86 payer.address.admin_area_2 = customer.city;
87 }
88
89 if (customer.zip) {
90 // inject postal code
91 payer.address.postal_code = customer.zip;
92 }
93 }
94
95 $(function() {
96 paypal.Buttons({
97 style: {
98 layout: '<?php echo $params['layout']; ?>',
99 color: '<?php echo $params['color']; ?>',
100 shape: '<?php echo $params['shape']; ?>',
101 label: 'paypal',
102 tagline: <?php echo $params['layout'] == 'horizontal' && $params['tagline'] == 1 ? 'true' : 'false'; ?>,
103 },
104 createOrder: (data, actions) => {
105 // This function sets up the details of the transaction, including the amount and line item details.
106 return actions.order.create({
107 purchase_units: [{
108 custom_id: '<?php echo $order['oid']; ?>',
109 description: '<?php echo addslashes($order['transaction_name']); ?>',
110 amount: {
111 value: <?php echo (float) $order['total_to_pay']; ?>,
112 currency_code: '<?php echo $order['transaction_currency']; ?>',
113 },
114 }],
115 /**
116 * Both the `payer` and `application_context` properties are marked as deprecated
117 * on the PayPal website. We still provide them since it seems to only way to
118 * auto-complete the billing details and disable the shipping method.
119 *
120 * @link https://developer.paypal.com/docs/api/orders/v2/
121 *
122 * @since 1.7.7 Force the NO_SHIPPING flag through the PayPal experience context.
123 * @link https://developer.paypal.com/docs/api/orders/v2/#orders_create!path=payment_source/paypal/experience_context/shipping_preference&t=request
124 */
125 payer: payer,
126 payment_source: {
127 paypal: {
128 experience_context: {
129 shipping_preference: '<?php echo empty($order['shipping']) ? 'NO_SHIPPING' : 'GET_FROM_FILE'; ?>',
130 },
131 },
132 },
133 });
134 },
135 onApprove: (data, actions) => {
136 // This function captures the funds from the transaction.
137 return actions.order.capture().then((details) => {
138 document.location.href = notifyUrl.replace(/{PAYMENT_ID}/, details.id);
139 });
140 },
141 onError: (err) => {
142 // For example, redirect to a specific error page
143 console.error('onError', err);
144 },
145 }).render('#paypal-button-container');
146 });
147 })(jQuery);
148 </script>