Version Description
- Added, support for variable products.
- Removed, checkbox to enable affordability widget.
- Added, Divi theme support.
- Added, WATI plugin support.
- Added, Flycart changes.
Download this release
Release Info
Developer | razorpay |
Plugin | Razorpay for WooCommerce |
Version | 4.3.2 |
Comparing to | |
See all releases |
Code changes from version 4.3.1 to 4.3.2
- btn-1cc-checkout.js +355 -355
- includes/api/save-abandonment-data.php +21 -6
- includes/razorpay-affordability-widget.php +75 -15
- includes/support/wati.php +123 -0
- public/css/1cc-product-checkout.css +2 -2
- readme.txt +8 -1
- templates/rzp-mini-checkout-btn.php +0 -7
- woo-razorpay.php +46 -21
btn-1cc-checkout.js
CHANGED
@@ -1,396 +1,396 @@
|
|
1 |
if (document.readyState !== 'loading') {
|
2 |
-
|
3 |
} else {
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
}
|
8 |
|
9 |
function btnCheckout(){
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
39 |
}
|
40 |
-
});
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
let x = 0;
|
73 |
-
while (typeof quantity === 'undefined') {
|
74 |
-
var quantity = document.getElementsByClassName("qty")[x].value;
|
75 |
-
x++;
|
76 |
-
}
|
77 |
-
|
78 |
-
stickyBtn.setAttribute('quantity', quantity);
|
79 |
-
|
80 |
-
if(quantity <= 0)
|
81 |
-
{
|
82 |
-
stickyBtn.classList.add("disabled");
|
83 |
-
stickyBtn.disabled = true;
|
84 |
}
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
$.each( data.attributes, function( key, value ) {
|
104 |
-
variationArr[key] = $("[name="+key+"]").val();
|
105 |
-
});
|
106 |
-
|
107 |
-
stickyBtn.setAttribute('variations', JSON.stringify(variationArr));
|
108 |
-
|
109 |
-
}).on('hide_variation', function() {
|
110 |
-
|
111 |
-
stickyBtn.classList.add("disabled");
|
112 |
-
stickyBtn.disabled = true;
|
113 |
-
});
|
114 |
-
})(jQuery);
|
115 |
-
|
116 |
-
if (stickyBtn != null) {
|
117 |
-
stickyBtn.onclick = function(){
|
118 |
-
|
119 |
-
var pdpCheckout = stickyBtn.getAttribute('pdp_checkout');
|
120 |
-
var productId = stickyBtn.getAttribute('product_id');
|
121 |
-
var quantity = stickyBtn.getAttribute('quantity');
|
122 |
-
|
123 |
-
rzp1ccCheckoutData.pdpCheckout = pdpCheckout;
|
124 |
-
rzp1ccCheckoutData.productId = productId;
|
125 |
-
rzp1ccCheckoutData.quantity = quantity;
|
126 |
-
|
127 |
-
if (btnPdp.getAttribute('variation_id') != null) {
|
128 |
-
var variationId = stickyBtn.getAttribute('variation_id');
|
129 |
-
var variations = stickyBtn.getAttribute('variations');
|
130 |
-
|
131 |
-
rzp1ccCheckoutData.variationId = variationId;
|
132 |
-
rzp1ccCheckoutData.variations = variations;
|
133 |
-
}
|
134 |
-
|
135 |
-
//To support custom product fields plugin.
|
136 |
-
const customFieldForm = document.getElementsByClassName('wcpa_form_outer');
|
137 |
-
|
138 |
-
if (customFieldForm && customFieldForm.length > 0) {
|
139 |
-
|
140 |
-
var customProductFieldForm = customFieldForm[0];
|
141 |
-
|
142 |
-
var fieldValues = customProductFieldForm.getElementsByTagName('input');
|
143 |
-
var fieldKey = customProductFieldForm.getElementsByTagName('label');
|
144 |
-
var fieldArray = [];
|
145 |
-
var fieldObj = {};
|
146 |
-
|
147 |
-
for (i = 0; i < fieldKey.length; i++) {
|
148 |
-
fieldObj[fieldKey[i].innerText] = fieldValues[i].value;
|
149 |
-
}
|
150 |
-
|
151 |
-
rzp1ccCheckoutData.fieldObj = fieldObj;
|
152 |
-
}
|
153 |
-
}
|
154 |
-
}
|
155 |
-
|
156 |
-
if (stickyBtn !== null) {
|
157 |
-
stickyBtn.addEventListener('click', openRzpCheckout);
|
158 |
}
|
159 |
-
|
160 |
-
|
161 |
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
-
addEventListenerToMinicart('wc_fragments_refreshed');
|
164 |
-
addEventListenerToMinicart('wc_fragments_loaded');
|
165 |
-
addEventListenerToMinicart('added_to_cart');
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
|
171 |
-
|
|
|
|
|
172 |
|
173 |
-
|
174 |
-
var productId = btnPdp.getAttribute('product_id');
|
175 |
-
var quantity = btnPdp.getAttribute('quantity');
|
176 |
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
|
189 |
-
|
190 |
-
|
|
|
191 |
|
192 |
-
|
|
|
193 |
|
194 |
-
|
195 |
|
196 |
-
|
197 |
-
var fieldKey = customProductFieldForm.getElementsByTagName('label');
|
198 |
-
var fieldArray = [];
|
199 |
-
var fieldObj = {};
|
200 |
|
201 |
-
|
202 |
-
|
203 |
-
|
|
|
204 |
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
// fetch opts from server and open 1cc modal
|
210 |
-
var rzp1cc = {
|
211 |
-
orderApi: rzp1ccCheckoutData.siteurl + '/wp-json/1cc/v1/order/create',
|
212 |
-
saveAbandonedCartApi: rzp1ccCheckoutData.siteurl + '/wp-json/1cc/v1/abandoned-cart',
|
213 |
-
makeRequest: function(url, body) {
|
214 |
-
return new Promise(function(resolve, reject) {
|
215 |
-
var xhr = new XMLHttpRequest();
|
216 |
-
xhr.open('POST', url, true);
|
217 |
-
xhr.setRequestHeader('Content-Type', 'application/json');
|
218 |
-
xhr.setRequestHeader('X-WP-Nonce', rzp1ccCheckoutData.nonce);
|
219 |
-
xhr.onload = function() {
|
220 |
-
if (this.status === 200) {
|
221 |
-
resolve(rzp1cc.parseIfJson(this.response));
|
222 |
-
} else {
|
223 |
-
reject({ status: this.status, response: rzp1cc.parseIfJson(this.response) });
|
224 |
-
}
|
225 |
-
}
|
226 |
-
xhr.onerror = function () {
|
227 |
-
reject({ status: this.status, statusText: this.statusText});
|
228 |
-
};
|
229 |
-
xhr.send(JSON.stringify(body));
|
230 |
-
});
|
231 |
-
},
|
232 |
-
parseIfJson: function (str) {
|
233 |
-
try {
|
234 |
-
return JSON.parse(str);
|
235 |
-
} catch (e) {
|
236 |
-
return str;
|
237 |
-
}
|
238 |
-
},
|
239 |
-
setDisabled: function(id, state) {
|
240 |
-
if (typeof state === 'undefined') {
|
241 |
-
state = true;
|
242 |
-
}
|
243 |
-
var elem = document.getElementById(id);
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
elem.removeAttribute('disabled');
|
249 |
-
} else {
|
250 |
-
elem.setAttribute('disabled', state);
|
251 |
-
}
|
252 |
-
}
|
253 |
-
},
|
254 |
-
showSpinner: function(state) {
|
255 |
-
jQuery(document.body).trigger('wc_fragment_refresh');
|
256 |
-
if (rzpSpinnerBackdrop == null) {
|
257 |
-
rzpSpinnerBackdrop = document.getElementById('rzp-spinner-backdrop');
|
258 |
-
}
|
259 |
-
if (rzpSpinner == null) {
|
260 |
-
rzpSpinner = document.getElementById('rzp-spinner');
|
261 |
-
}
|
262 |
-
if (state === true) {
|
263 |
-
rzpSpinnerBackdrop.classList.add('show');
|
264 |
-
rzpSpinner.classList.add('show');
|
265 |
-
} else {
|
266 |
-
rzpSpinnerBackdrop.classList.remove('show');
|
267 |
-
rzpSpinner.classList.remove('show');
|
268 |
-
}
|
269 |
-
},
|
270 |
-
handleAbandonmentCart: function(rzpOrderId) {
|
271 |
-
if(rzpOrderId != null) {
|
272 |
-
var xhr = new XMLHttpRequest();
|
273 |
-
try {
|
274 |
-
var body = {
|
275 |
-
order_id: rzpOrderId
|
276 |
-
};
|
277 |
-
xhr.open('POST', rzp1cc.saveAbandonedCartApi, true);
|
278 |
-
xhr.setRequestHeader('Content-Type', 'application/json');
|
279 |
-
xhr.send(JSON.stringify(body));
|
280 |
-
} catch (e) {
|
281 |
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
async function openRzpCheckout(e) {
|
326 |
-
e.preventDefault();
|
327 |
|
328 |
-
|
329 |
-
|
330 |
-
}
|
331 |
-
rzp1cc.showSpinner(true);
|
332 |
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
rzp1cc.setDisabled('btn-1cc');
|
344 |
-
rzp1cc.setDisabled('btn-1cc-mini-cart');
|
345 |
-
rzp1cc.setDisabled('btn-1cc-pdp');
|
346 |
-
|
347 |
-
rzp1cc.makeRequest(rzp1cc.orderApi, body)
|
348 |
-
.then(data => {
|
349 |
-
rzp1cc.showSpinner(false);
|
350 |
-
try {
|
351 |
-
var razorpayCheckout = new Razorpay({
|
352 |
-
...data,
|
353 |
-
modal: {
|
354 |
-
ondismiss: function() {
|
355 |
-
rzp1cc.handleAbandonmentCart(data.order_id);
|
356 |
-
rzp1cc.enableCheckoutButtons();
|
357 |
-
},
|
358 |
-
onload: setTimeout(() => {
|
359 |
-
rzp1cc.handleAbandonmentCart(data.order_id);
|
360 |
-
rzp1cc.enableCheckoutButtons();
|
361 |
-
}, 25000),
|
362 |
-
},
|
363 |
-
});
|
364 |
-
razorpayCheckout.open();
|
365 |
-
|
366 |
-
} catch (e) {
|
367 |
-
document.getElementById('error-message').innerHTML =
|
368 |
-
"<div class='entry-content'><div class='woocommerce'><div class='woocommerce-notices-wrapper'><p class='cart-empty woocommerce-info' style='margin-left: -50px; margin-right: 75px'>Something went wrong, please try again after sometime.</p></div></div></div>";
|
369 |
-
|
370 |
-
rzp1cc.enableCheckoutButtons();
|
371 |
-
rzp1cc.showSpinner(false);
|
372 |
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
|
|
|
|
|
|
|
|
396 |
}
|
1 |
if (document.readyState !== 'loading') {
|
2 |
+
btnCheckout();
|
3 |
} else {
|
4 |
+
document.addEventListener('DOMContentLoaded', function () {
|
5 |
+
btnCheckout();
|
6 |
+
});
|
7 |
}
|
8 |
|
9 |
function btnCheckout(){
|
10 |
|
11 |
+
var btn = document.getElementById('btn-1cc');
|
12 |
+
var btnMini = document.getElementById('btn-1cc-mini-cart');
|
13 |
+
var btnPdp = document.getElementById('btn-1cc-pdp');
|
14 |
+
var rzpSpinnerBackdrop = document.getElementById('rzp-spinner-backdrop');
|
15 |
+
var rzpSpinner = document.getElementById('rzp-spinner');
|
16 |
+
var pageURL = jQuery(location).attr('href');
|
17 |
+
var url = new URL(pageURL);
|
18 |
+
var accessToken = new URLSearchParams(url.search).get('wcf_ac_token');
|
19 |
+
var referrerDomain = document.referrer.toString();
|
20 |
+
var flycartBtn = document.getElementsByClassName("woofc-action-checkout")[0];
|
21 |
+
rzp1ccCheckoutData.referrerDomain = referrerDomain;
|
22 |
+
|
23 |
+
// event triggered by wc on any cart change
|
24 |
+
// as input function is the same, duplicate event listeners are NOT called
|
25 |
+
jQuery(document.body).on('updated_cart_totals', function(event) {
|
26 |
+
var btn = document.getElementById('btn-1cc');
|
27 |
+
if (btn !== null) {
|
28 |
+
btn.addEventListener('click', openRzpCheckout);
|
29 |
+
}
|
30 |
+
|
31 |
+
var btnMini = document.getElementById('btn-1cc-mini-cart');
|
32 |
+
if (btnMini !== null) {
|
33 |
+
btnMini.addEventListener('click', openRzpCheckout);
|
34 |
+
}
|
35 |
+
|
36 |
+
var flycartBtn = document.getElementsByClassName("woofc-action-checkout")[0];
|
37 |
+
if (flycartBtn != null) {
|
38 |
+
flycartBtn.addEventListener('click', openRzpCheckout);
|
39 |
+
}
|
40 |
+
});
|
41 |
+
|
42 |
+
function addEventListenerToMinicart(wcEvent) {
|
43 |
+
jQuery(document.body).on(wcEvent, function(event) {
|
44 |
+
var btnMini = document.getElementById('btn-1cc-mini-cart');
|
45 |
+
if (btnMini !== null) {
|
46 |
+
btnMini.addEventListener('click', openRzpCheckout);
|
47 |
+
}
|
48 |
+
var flycartBtn = document.getElementsByClassName("woofc-action-checkout")[0];
|
49 |
+
if (flycartBtn != null) {
|
50 |
+
flycartBtn.addEventListener('click', openRzpCheckout);
|
51 |
+
}
|
52 |
+
});
|
53 |
+
}
|
54 |
|
55 |
+
var stickyBtn = document.querySelectorAll('#btn-1cc-pdp')[1];
|
56 |
+
|
57 |
+
if (stickyBtn != null) {
|
58 |
+
|
59 |
+
// For attaching event listener to Woodmart's sticky add-to-cart
|
60 |
+
document.addEventListener('scroll',(e)=>{
|
61 |
+
|
62 |
+
let i = 0;
|
63 |
+
while (typeof quantity === 'undefined') {
|
64 |
+
var quantity = document.getElementsByClassName("qty")[i].value;
|
65 |
+
i++;
|
66 |
}
|
|
|
67 |
|
68 |
+
stickyBtn.setAttribute('quantity', quantity);
|
69 |
+
|
70 |
+
jQuery('.qty').on('change',function(e)
|
71 |
+
{
|
72 |
+
let x = 0;
|
73 |
+
while (typeof quantity === 'undefined') {
|
74 |
+
var quantity = document.getElementsByClassName("qty")[x].value;
|
75 |
+
x++;
|
76 |
+
}
|
77 |
+
|
78 |
+
stickyBtn.setAttribute('quantity', quantity);
|
79 |
+
|
80 |
+
if(quantity <= 0)
|
81 |
+
{
|
82 |
+
stickyBtn.classList.add("disabled");
|
83 |
+
stickyBtn.disabled = true;
|
84 |
}
|
85 |
+
else
|
86 |
+
{
|
87 |
+
stickyBtn.classList.remove("disabled");
|
88 |
+
stickyBtn.disabled = false;
|
89 |
+
}
|
90 |
+
});
|
91 |
|
92 |
+
(function($){
|
93 |
+
|
94 |
+
$('form.variations_form').on('show_variation', function(event, data){
|
95 |
+
|
96 |
+
stickyBtn.classList.remove("disabled");
|
97 |
+
stickyBtn.disabled = false;
|
98 |
+
|
99 |
+
stickyBtn.setAttribute('variation_id', data.variation_id);
|
100 |
+
|
101 |
+
var variationArr = {};
|
102 |
+
|
103 |
+
$.each( data.attributes, function( key, value ) {
|
104 |
+
variationArr[key] = $("[name="+key+"]").val();
|
105 |
+
});
|
106 |
|
107 |
+
stickyBtn.setAttribute('variations', JSON.stringify(variationArr));
|
108 |
+
|
109 |
+
}).on('hide_variation', function() {
|
110 |
+
|
111 |
+
stickyBtn.classList.add("disabled");
|
112 |
+
stickyBtn.disabled = true;
|
113 |
+
});
|
114 |
+
})(jQuery);
|
115 |
+
|
116 |
+
if (stickyBtn != null) {
|
117 |
+
stickyBtn.onclick = function(){
|
118 |
+
|
119 |
+
var pdpCheckout = stickyBtn.getAttribute('pdp_checkout');
|
120 |
+
var productId = stickyBtn.getAttribute('product_id');
|
121 |
+
var quantity = stickyBtn.getAttribute('quantity');
|
122 |
|
123 |
+
rzp1ccCheckoutData.pdpCheckout = pdpCheckout;
|
124 |
+
rzp1ccCheckoutData.productId = productId;
|
125 |
+
rzp1ccCheckoutData.quantity = quantity;
|
126 |
+
|
127 |
+
if (btnPdp.getAttribute('variation_id') != null) {
|
128 |
+
var variationId = stickyBtn.getAttribute('variation_id');
|
129 |
+
var variations = stickyBtn.getAttribute('variations');
|
130 |
+
|
131 |
+
rzp1ccCheckoutData.variationId = variationId;
|
132 |
+
rzp1ccCheckoutData.variations = variations;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
}
|
134 |
+
|
135 |
+
//To support custom product fields plugin.
|
136 |
+
const customFieldForm = document.getElementsByClassName('wcpa_form_outer');
|
137 |
+
|
138 |
+
if (customFieldForm && customFieldForm.length > 0) {
|
139 |
+
|
140 |
+
var customProductFieldForm = customFieldForm[0];
|
141 |
+
|
142 |
+
var fieldValues = customProductFieldForm.getElementsByTagName('input');
|
143 |
+
var fieldKey = customProductFieldForm.getElementsByTagName('label');
|
144 |
+
var fieldArray = [];
|
145 |
+
var fieldObj = {};
|
146 |
+
|
147 |
+
for (i = 0; i < fieldKey.length; i++) {
|
148 |
+
fieldObj[fieldKey[i].innerText] = fieldValues[i].value;
|
149 |
+
}
|
150 |
+
|
151 |
+
rzp1ccCheckoutData.fieldObj = fieldObj;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
}
|
153 |
+
}
|
154 |
+
}
|
155 |
|
156 |
+
if (stickyBtn !== null) {
|
157 |
+
stickyBtn.addEventListener('click', openRzpCheckout);
|
158 |
+
}
|
159 |
+
})
|
160 |
+
}
|
161 |
|
|
|
|
|
|
|
162 |
|
163 |
+
addEventListenerToMinicart('wc_fragments_refreshed');
|
164 |
+
addEventListenerToMinicart('wc_fragments_loaded');
|
165 |
+
addEventListenerToMinicart('added_to_cart');
|
166 |
|
167 |
+
if (btnPdp != null) {
|
168 |
+
btnPdp.onclick = productInfoHandler;
|
169 |
+
}
|
170 |
|
171 |
+
function productInfoHandler(){
|
|
|
|
|
172 |
|
173 |
+
var pdpCheckout = btnPdp.getAttribute('pdp_checkout');
|
174 |
+
var productId = btnPdp.getAttribute('product_id');
|
175 |
+
var quantity = btnPdp.getAttribute('quantity');
|
176 |
|
177 |
+
rzp1ccCheckoutData.pdpCheckout = pdpCheckout;
|
178 |
+
rzp1ccCheckoutData.productId = productId;
|
179 |
+
rzp1ccCheckoutData.quantity = quantity;
|
180 |
|
181 |
+
if (btnPdp.getAttribute('variation_id') != null) {
|
182 |
+
var variationId = btnPdp.getAttribute('variation_id');
|
183 |
+
var variations = btnPdp.getAttribute('variations');
|
184 |
|
185 |
+
rzp1ccCheckoutData.variationId = variationId;
|
186 |
+
rzp1ccCheckoutData.variations = variations;
|
187 |
+
}
|
188 |
|
189 |
+
//To support custom product fields plugin.
|
190 |
+
const customFieldForm = document.getElementsByClassName('wcpa_form_outer');
|
191 |
|
192 |
+
if (customFieldForm && customFieldForm.length > 0) {
|
193 |
|
194 |
+
var customProductFieldForm = customFieldForm[0];
|
|
|
|
|
|
|
195 |
|
196 |
+
var fieldValues = customProductFieldForm.getElementsByTagName('input');
|
197 |
+
var fieldKey = customProductFieldForm.getElementsByTagName('label');
|
198 |
+
var fieldArray = [];
|
199 |
+
var fieldObj = {};
|
200 |
|
201 |
+
for (i = 0; i < fieldKey.length; i++) {
|
202 |
+
fieldObj[fieldKey[i].innerText] = fieldValues[i].value;
|
203 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
|
205 |
+
rzp1ccCheckoutData.fieldObj = fieldObj;
|
206 |
+
}
|
207 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
+
// fetch opts from server and open 1cc modal
|
210 |
+
var rzp1cc = {
|
211 |
+
orderApi: rzp1ccCheckoutData.siteurl + '/wp-json/1cc/v1/order/create',
|
212 |
+
saveAbandonedCartApi: rzp1ccCheckoutData.siteurl + '/wp-json/1cc/v1/abandoned-cart',
|
213 |
+
makeRequest: function(url, body) {
|
214 |
+
return new Promise(function(resolve, reject) {
|
215 |
+
var xhr = new XMLHttpRequest();
|
216 |
+
xhr.open('POST', url, true);
|
217 |
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
218 |
+
xhr.setRequestHeader('X-WP-Nonce', rzp1ccCheckoutData.nonce);
|
219 |
+
xhr.onload = function() {
|
220 |
+
if (this.status === 200) {
|
221 |
+
resolve(rzp1cc.parseIfJson(this.response));
|
222 |
+
} else {
|
223 |
+
reject({ status: this.status, response: rzp1cc.parseIfJson(this.response) });
|
224 |
+
}
|
225 |
+
}
|
226 |
+
xhr.onerror = function () {
|
227 |
+
reject({ status: this.status, statusText: this.statusText});
|
228 |
+
};
|
229 |
+
xhr.send(JSON.stringify(body));
|
230 |
+
});
|
231 |
+
},
|
232 |
+
parseIfJson: function (str) {
|
233 |
+
try {
|
234 |
+
return JSON.parse(str);
|
235 |
+
} catch (e) {
|
236 |
+
return str;
|
237 |
+
}
|
238 |
+
},
|
239 |
+
setDisabled: function(id, state) {
|
240 |
+
if (typeof state === 'undefined') {
|
241 |
+
state = true;
|
242 |
+
}
|
243 |
+
var elem = document.getElementById(id);
|
244 |
+
|
245 |
+
if(elem != null)
|
246 |
+
{
|
247 |
+
if (state === false) {
|
248 |
+
elem.removeAttribute('disabled');
|
249 |
+
} else {
|
250 |
+
elem.setAttribute('disabled', state);
|
251 |
+
}
|
252 |
+
}
|
253 |
+
},
|
254 |
+
showSpinner: function(state) {
|
255 |
+
jQuery(document.body).trigger('wc_fragment_refresh');
|
256 |
+
if (rzpSpinnerBackdrop == null) {
|
257 |
+
rzpSpinnerBackdrop = document.getElementById('rzp-spinner-backdrop');
|
258 |
+
}
|
259 |
+
if (rzpSpinner == null) {
|
260 |
+
rzpSpinner = document.getElementById('rzp-spinner');
|
261 |
+
}
|
262 |
+
if (state === true) {
|
263 |
+
rzpSpinnerBackdrop.classList.add('show');
|
264 |
+
rzpSpinner.classList.add('show');
|
265 |
+
} else {
|
266 |
+
rzpSpinnerBackdrop.classList.remove('show');
|
267 |
+
rzpSpinner.classList.remove('show');
|
268 |
+
}
|
269 |
+
},
|
270 |
+
handleAbandonmentCart: function(rzpOrderId) {
|
271 |
+
if(rzpOrderId != null) {
|
272 |
+
var xhr = new XMLHttpRequest();
|
273 |
+
try {
|
274 |
+
var body = {
|
275 |
+
order_id: rzpOrderId
|
276 |
+
};
|
277 |
+
xhr.open('POST', rzp1cc.saveAbandonedCartApi, true);
|
278 |
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
279 |
+
xhr.send(JSON.stringify(body));
|
280 |
+
} catch (e) {
|
281 |
+
|
282 |
+
}
|
283 |
+
}
|
284 |
+
},
|
285 |
+
enableCheckoutButtons: function() {
|
286 |
+
rzp1cc.setDisabled('btn-1cc', false);
|
287 |
+
rzp1cc.setDisabled('btn-1cc-mini-cart', false);
|
288 |
+
rzp1cc.setDisabled('btn-1cc-pdp', false);
|
289 |
+
},
|
290 |
+
getBrowserTime: function() {
|
291 |
+
var dateTime = [];
|
292 |
+
var date = new Date(),
|
293 |
+
days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
294 |
+
months = ['January', 'February', 'March', 'April', 'May', 'June',
|
295 |
+
'July', 'August', 'September', 'October', 'November', 'December'
|
296 |
+
],
|
297 |
+
hours = ['00-01', '01-02', '02-03', '03-04', '04-05', '05-06', '06-07', '07-08',
|
298 |
+
'08-09', '09-10', '10-11', '11-12', '12-13', '13-14', '14-15', '15-16', '16-17',
|
299 |
+
'17-18', '18-19', '19-20', '20-21', '21-22', '22-23', '23-24'
|
300 |
+
];
|
301 |
+
dateTime.push(hours[date.getHours()]);
|
302 |
+
dateTime.push(days[date.getDay()]);
|
303 |
+
dateTime.push(months[date.getMonth()]);
|
304 |
+
|
305 |
+
rzp1ccCheckoutData.dateTime = dateTime;
|
306 |
+
}
|
307 |
+
}
|
308 |
|
309 |
+
if (btn !== null) {
|
310 |
+
btn.addEventListener('click', openRzpCheckout);
|
311 |
+
}
|
312 |
|
313 |
+
if (btnMini !== null) {
|
314 |
+
btnMini.addEventListener('click', openRzpCheckout);
|
315 |
+
}
|
316 |
|
317 |
+
if (btnPdp !== null) {
|
318 |
+
btnPdp.addEventListener('click', openRzpCheckout);
|
319 |
+
}
|
320 |
|
321 |
+
if (flycartBtn != null) {
|
322 |
+
flycartBtn.addEventListener('click', openRzpCheckout);
|
323 |
+
}
|
|
|
|
|
|
|
324 |
|
325 |
+
async function openRzpCheckout(e) {
|
326 |
+
e.preventDefault();
|
|
|
|
|
327 |
|
328 |
+
if( btnPdp !== null && btnPdp.classList.contains('disabled')){
|
329 |
+
return;
|
330 |
+
}
|
331 |
+
rzp1cc.showSpinner(true);
|
332 |
|
333 |
+
if (accessToken !== null)
|
334 |
+
{
|
335 |
+
rzp1ccCheckoutData.token = accessToken;
|
336 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
|
338 |
+
rzp1cc.getBrowserTime();
|
339 |
+
|
340 |
+
|
341 |
+
var body = rzp1ccCheckoutData;
|
342 |
+
|
343 |
+
rzp1cc.setDisabled('btn-1cc');
|
344 |
+
rzp1cc.setDisabled('btn-1cc-mini-cart');
|
345 |
+
rzp1cc.setDisabled('btn-1cc-pdp');
|
346 |
+
|
347 |
+
rzp1cc.makeRequest(rzp1cc.orderApi, body)
|
348 |
+
.then(data => {
|
349 |
+
rzp1cc.showSpinner(false);
|
350 |
+
try {
|
351 |
+
var razorpayCheckout = new Razorpay({
|
352 |
+
...data,
|
353 |
+
modal: {
|
354 |
+
ondismiss: function() {
|
355 |
+
rzp1cc.handleAbandonmentCart(data.order_id);
|
356 |
+
rzp1cc.enableCheckoutButtons();
|
357 |
+
},
|
358 |
+
onload: setTimeout(() => {
|
359 |
+
rzp1cc.handleAbandonmentCart(data.order_id);
|
360 |
+
rzp1cc.enableCheckoutButtons();
|
361 |
+
}, 25000),
|
362 |
+
},
|
363 |
+
});
|
364 |
+
razorpayCheckout.open();
|
365 |
+
|
366 |
+
} catch (e) {
|
367 |
+
document.getElementById('error-message').innerHTML =
|
368 |
+
"<div class='entry-content'><div class='woocommerce'><div class='woocommerce-notices-wrapper'><p class='cart-empty woocommerce-info' style='margin-left: -50px; margin-right: 75px'>Something went wrong, please try again after sometime.</p></div></div></div>";
|
369 |
+
|
370 |
+
rzp1cc.enableCheckoutButtons();
|
371 |
+
rzp1cc.showSpinner(false);
|
372 |
+
|
373 |
+
}
|
374 |
+
})
|
375 |
+
.catch(e => {
|
376 |
+
// Response sent to the User when cart is empty or order creation fails
|
377 |
+
if (e.status == 400){
|
378 |
+
if (e.response.code == 'BAD_REQUEST_EMPTY_CART'){
|
379 |
+
document.getElementById('error-message').innerHTML = "<p style='margin-top: revert;text-color: #e2401c !important;color: #e80707;'>Order could not be placed as your cart is empty.</p>";
|
380 |
+
} else if (e.response.code == 'ORDER_CREATION_FAILED'){
|
381 |
+
document.getElementById('error-message').innerHTML = "<p style='margin-top: revert;text-color: #e2401c !important;color: #e80707;'>Razorpay Error: Order could not be placed, please try again after sometime.</p>";
|
382 |
+
} else if (e.response.code == 'MIN_CART_AMOUNT_CHECK_FAILED' || e.response.code == 'WOOCOMMERCE_ORDER_CREATION_FAILED'){
|
383 |
+
document.getElementById('error-message').innerHTML = "<p style='margin-top: revert;text-color: #e2401c !important;color: #e80707;'>"+e.response.message+"</p>"; // nosemgrep: insecure-innerhtml
|
384 |
+
} else {
|
385 |
+
document.getElementById('error-message').innerHTML = "<p style='margin-top: revert;text-color: #e2401c !important;color: #e80707;'>Something went wrong, please try again after sometime.</p>";
|
386 |
+
}
|
387 |
|
388 |
+
} else {
|
389 |
+
document.getElementById('error-message').innerHTML = "<p style='margin-top: revert;text-color: #e2401c !important;color: #e80707;'>Something went wrong, please try again after sometime.</p>";
|
390 |
+
}
|
391 |
+
|
392 |
+
rzp1cc.enableCheckoutButtons();
|
393 |
+
rzp1cc.showSpinner(false);
|
394 |
+
});
|
395 |
+
}
|
396 |
}
|
includes/api/save-abandonment-data.php
CHANGED
@@ -4,6 +4,7 @@
|
|
4 |
*/
|
5 |
|
6 |
require_once __DIR__ . '/../support/cartbounty.php';
|
|
|
7 |
|
8 |
function saveCartAbandonmentData(WP_REST_Request $request)
|
9 |
{
|
@@ -58,19 +59,33 @@ function saveCartAbandonmentData(WP_REST_Request $request)
|
|
58 |
$result['response'] = "";
|
59 |
$result['status_code'] = 400;
|
60 |
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
65 |
-
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
if($res['status_code'] == 200){
|
68 |
-
$result['response'] = "Data inserted for
|
69 |
$result['status_code'] = 200;
|
70 |
}else{
|
71 |
-
$result['response'] = "Failed to insert data for
|
72 |
$result['status_code'] = 400;
|
73 |
}
|
|
|
74 |
}
|
75 |
|
76 |
//Check CartBounty plugin is activated or not
|
4 |
*/
|
5 |
|
6 |
require_once __DIR__ . '/../support/cartbounty.php';
|
7 |
+
require_once __DIR__ . '/../support/wati.php';
|
8 |
|
9 |
function saveCartAbandonmentData(WP_REST_Request $request)
|
10 |
{
|
59 |
$result['response'] = "";
|
60 |
$result['status_code'] = 400;
|
61 |
|
62 |
+
//check woocommerce cart abandonment recovery plugin is activated or not
|
63 |
+
if (is_plugin_active('woo-cart-abandonment-recovery/woo-cart-abandonment-recovery.php') && empty($customerEmail) == false) {
|
64 |
|
65 |
+
//save abandonment data
|
66 |
+
$res = saveWooCartAbandonmentRecoveryData($razorpayData);
|
67 |
|
68 |
+
if($res['status_code'] == 200){
|
69 |
+
$result['response'] = "Data inserted for WooCart abandoned recovery plugin";
|
70 |
+
$result['status_code'] = 200;
|
71 |
+
}else{
|
72 |
+
$result['response'] = "Failed to insert data for WooCart abandoned recovery plugin";
|
73 |
+
$result['status_code'] = 400;
|
74 |
+
}
|
75 |
+
}
|
76 |
+
|
77 |
+
// Check Wati.io retargetting plugin is active or not
|
78 |
+
if (is_plugin_active('wati-chat-and-notification/wati-chat-and-notification.php')){
|
79 |
+
|
80 |
+
$res = saveWatiCartAbandonmentData($razorpayData);
|
81 |
if($res['status_code'] == 200){
|
82 |
+
$result['response'] = $result['response']."Data inserted for Wati plugin";
|
83 |
$result['status_code'] = 200;
|
84 |
}else{
|
85 |
+
$result['response'] = $result['response']."Failed to insert data for Wati plugin";
|
86 |
$result['status_code'] = 400;
|
87 |
}
|
88 |
+
|
89 |
}
|
90 |
|
91 |
//Check CartBounty plugin is activated or not
|
includes/razorpay-affordability-widget.php
CHANGED
@@ -15,7 +15,8 @@ function addAffordabilityWidgetHTML()
|
|
15 |
<script>
|
16 |
const key = "'.getKeyId().'";
|
17 |
const amount = parseFloat("'.getPrice().'s") * 100;
|
18 |
-
|
|
|
19 |
const widgetConfig = {
|
20 |
"key": key,
|
21 |
"amount": amount,
|
@@ -57,7 +58,69 @@ function addAffordabilityWidgetHTML()
|
|
57 |
};
|
58 |
const rzpAffordabilitySuite = new RazorpayAffordabilitySuite(widgetConfig);
|
59 |
rzpAffordabilitySuite.render();
|
60 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
</script>
|
62 |
';
|
63 |
}
|
@@ -71,7 +134,7 @@ function getKeyId()
|
|
71 |
function getPrice()
|
72 |
{
|
73 |
global $product;
|
74 |
-
if ($product->is_type('
|
75 |
{
|
76 |
if ($product->is_on_sale())
|
77 |
{
|
@@ -84,7 +147,7 @@ function getPrice()
|
|
84 |
}
|
85 |
else
|
86 |
{
|
87 |
-
$price = $product->get_price();
|
88 |
}
|
89 |
|
90 |
return $price;
|
@@ -295,13 +358,6 @@ function getAffordabilityWidgetSettings()
|
|
295 |
'desc' => '',
|
296 |
'id' => 'rzp_afd_section_title'
|
297 |
),
|
298 |
-
'enable' => array(
|
299 |
-
'title' => __('Affordability Widget Enable/Disable'),
|
300 |
-
'type' => 'checkbox',
|
301 |
-
'desc' => __('Enable Affordability Widget?'),
|
302 |
-
'default' => 'no',
|
303 |
-
'id' => 'rzp_afd_enable'
|
304 |
-
),
|
305 |
'enable_test_mode' => array(
|
306 |
'title' => __('Test Mode Enable/Disable'),
|
307 |
'type' => 'checkbox',
|
@@ -457,6 +513,10 @@ function updateAffordabilityWidgetSettings()
|
|
457 |
|
458 |
function isEnabled($feature)
|
459 |
{
|
|
|
|
|
|
|
|
|
460 |
$value = 'false';
|
461 |
|
462 |
if (empty(get_option($feature)) === false and
|
@@ -482,10 +542,10 @@ function getCustomisation($customisation)
|
|
482 |
'rzp_afd_footer_font_size' => '10'
|
483 |
];
|
484 |
|
485 |
-
$customisationValue =
|
486 |
-
if (empty($
|
487 |
{
|
488 |
-
$customisationValue = $
|
489 |
}
|
490 |
|
491 |
return $customisationValue;
|
@@ -493,7 +553,7 @@ function getCustomisation($customisation)
|
|
493 |
|
494 |
function isAffordabilityWidgetTestModeEnabled()
|
495 |
{
|
496 |
-
if(empty(get_option('rzp_afd_enable_test_mode')) === true)
|
497 |
{
|
498 |
return true;
|
499 |
}
|
15 |
<script>
|
16 |
const key = "'.getKeyId().'";
|
17 |
const amount = parseFloat("'.getPrice().'s") * 100;
|
18 |
+
addEventListener("load",
|
19 |
+
function() {
|
20 |
const widgetConfig = {
|
21 |
"key": key,
|
22 |
"amount": amount,
|
58 |
};
|
59 |
const rzpAffordabilitySuite = new RazorpayAffordabilitySuite(widgetConfig);
|
60 |
rzpAffordabilitySuite.render();
|
61 |
+
});
|
62 |
+
|
63 |
+
jQuery(function($) {
|
64 |
+
|
65 |
+
$.fn.myFunction = function()
|
66 |
+
{
|
67 |
+
var variants = (document.querySelector("form.variations_form").dataset.product_variations);
|
68 |
+
var selectedVariantID = document.querySelector("input.variation_id").value;
|
69 |
+
var selectedVariant = JSON.parse(variants).filter( variant => variant.variation_id === parseInt(selectedVariantID));
|
70 |
+
|
71 |
+
if(typeof(selectedVariant[0]) != "undefined")
|
72 |
+
{
|
73 |
+
amt = selectedVariant[0].display_price * 100;
|
74 |
+
const widgetConfig = {
|
75 |
+
"key": key,
|
76 |
+
"amount": amt,
|
77 |
+
"theme": {
|
78 |
+
"color": "'.getThemeColor().'"
|
79 |
+
},
|
80 |
+
"features": {
|
81 |
+
"offers": {
|
82 |
+
"list": '.getAdditionalOffers().',
|
83 |
+
}
|
84 |
+
},
|
85 |
+
"display": {
|
86 |
+
"offers": '.getOffers().',
|
87 |
+
"emi": '.getEmi().',
|
88 |
+
"cardlessEmi": '.getCardlessEmi().',
|
89 |
+
"paylater": '.getPayLater().',
|
90 |
+
"widget": {
|
91 |
+
"main": {
|
92 |
+
"heading": {
|
93 |
+
"color": "'.getHeadingColor().'",
|
94 |
+
"fontSize": "'.getHeadingFontSize().'px"
|
95 |
+
},
|
96 |
+
"content": {
|
97 |
+
"color": "'.getContentColor().'",
|
98 |
+
"fontSize": "'.getContentFontSize().'px"
|
99 |
+
},
|
100 |
+
"link": {
|
101 |
+
"color": "'.getLinkColor().'",
|
102 |
+
"fontSize": "'.getLinkFontSize().'px"
|
103 |
+
},
|
104 |
+
"footer": {
|
105 |
+
"color": "'.getFooterColor().'",
|
106 |
+
"fontSize": "'.getFooterFontSize().'px",
|
107 |
+
"darkLogo": '.getFooterDarkLogo().'// true is default show black text rzp logo
|
108 |
+
}
|
109 |
+
}
|
110 |
+
}
|
111 |
+
}
|
112 |
+
};
|
113 |
+
const rzpAffordabilitySuite = new RazorpayAffordabilitySuite(widgetConfig);
|
114 |
+
rzpAffordabilitySuite.render();
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
$("input.variation_id").change(function(){
|
119 |
+
$.fn.myFunction();
|
120 |
+
});
|
121 |
+
|
122 |
+
});
|
123 |
+
|
124 |
</script>
|
125 |
';
|
126 |
}
|
134 |
function getPrice()
|
135 |
{
|
136 |
global $product;
|
137 |
+
if ($product->is_type('simple') === true)
|
138 |
{
|
139 |
if ($product->is_on_sale())
|
140 |
{
|
147 |
}
|
148 |
else
|
149 |
{
|
150 |
+
$price = $product->get_price();
|
151 |
}
|
152 |
|
153 |
return $price;
|
358 |
'desc' => '',
|
359 |
'id' => 'rzp_afd_section_title'
|
360 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
'enable_test_mode' => array(
|
362 |
'title' => __('Test Mode Enable/Disable'),
|
363 |
'type' => 'checkbox',
|
513 |
|
514 |
function isEnabled($feature)
|
515 |
{
|
516 |
+
if (empty(get_option($feature)) === true)
|
517 |
+
{
|
518 |
+
return 'true';
|
519 |
+
}
|
520 |
$value = 'false';
|
521 |
|
522 |
if (empty(get_option($feature)) === false and
|
542 |
'rzp_afd_footer_font_size' => '10'
|
543 |
];
|
544 |
|
545 |
+
$customisationValue = $defaultCustomisationValues[$customisation];
|
546 |
+
if (empty(get_option($customisation)) === false)
|
547 |
{
|
548 |
+
$customisationValue = get_option($customisation);
|
549 |
}
|
550 |
|
551 |
return $customisationValue;
|
553 |
|
554 |
function isAffordabilityWidgetTestModeEnabled()
|
555 |
{
|
556 |
+
if (empty(get_option('rzp_afd_enable_test_mode')) === true)
|
557 |
{
|
558 |
return true;
|
559 |
}
|
includes/support/wati.php
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
function saveWatiCartAbandonmentData($razorpayData){
|
4 |
+
|
5 |
+
$wati = WATI_Chat_And_Notification_Aband_Cart::get_instance();
|
6 |
+
$wati->webhook_setting_script();
|
7 |
+
$wati->cart_abandonment_tracking_script();
|
8 |
+
$wati->save_cart_abandonment_data();
|
9 |
+
|
10 |
+
if ( isset( $razorpayData['customer_details']['email'] ) ) {
|
11 |
+
|
12 |
+
global $wpdb;
|
13 |
+
|
14 |
+
$cartAbandonmentTable = $wpdb->prefix . 'wati_abandonment';
|
15 |
+
$userEmail = sanitize_email( $razorpayData['customer_details']['email'] );
|
16 |
+
$sessionID = WC()->session->get( 'wcf_session_id' );
|
17 |
+
$sessionCheckoutDetails = null;
|
18 |
+
|
19 |
+
if ( isset( $sessionID ) ) {
|
20 |
+
$sessionCheckoutDetails = $wati->get_checkout_details( $sessionID );
|
21 |
+
} else {
|
22 |
+
$sessionCheckoutDetails = $wati->get_checkout_details_by_email( $userEmail );
|
23 |
+
if ( $sessionCheckoutDetails ) {
|
24 |
+
$sessionID = $sessionCheckoutDetails->session_id;
|
25 |
+
WC()->session->set( 'wcf_session_id', $sessionID );
|
26 |
+
} else {
|
27 |
+
$sessionID = md5( uniqid( wp_rand(), true ) );
|
28 |
+
}
|
29 |
+
}
|
30 |
+
|
31 |
+
$checkoutDetails = prepareAbandonmentData( $razorpayData );
|
32 |
+
|
33 |
+
if ( isset( $sessionCheckoutDetails ) && $sessionCheckoutDetails->order_status === "completed" ) {
|
34 |
+
WC()->session->__unset( 'wcf_session_id' );
|
35 |
+
$sessionID = md5( uniqid( wp_rand(), true ) );
|
36 |
+
}
|
37 |
+
|
38 |
+
if ( isset( $checkoutDetails['cart_total'] ) && $checkoutDetails['cart_total'] > 0 ) {
|
39 |
+
|
40 |
+
if ( ( ! is_null( $sessionID ) ) && ! is_null( $sessionCheckoutDetails ) ) {
|
41 |
+
|
42 |
+
// Updating row in the Database where users Session id = same as prevously saved in Session.
|
43 |
+
$wpdb->update(
|
44 |
+
$cartAbandonmentTable,
|
45 |
+
$checkoutDetails,
|
46 |
+
array( 'session_id' => $sessionID )
|
47 |
+
);
|
48 |
+
$wati->webhook_abandonedCheckout_to_wati($sessionID, '');
|
49 |
+
} else {
|
50 |
+
|
51 |
+
$checkoutDetails['session_id'] = sanitize_text_field( $sessionID );
|
52 |
+
// Inserting row into Database.
|
53 |
+
$wpdb->insert(
|
54 |
+
$cartAbandonmentTable,
|
55 |
+
$checkoutDetails
|
56 |
+
);
|
57 |
+
|
58 |
+
// Storing session_id in WooCommerce session.
|
59 |
+
WC()->session->set( 'wcf_session_id', $sessionID );
|
60 |
+
$wati->webhook_abandonedCheckout_to_wati($sessionID, '');
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
$response['status'] = true;
|
65 |
+
$response['message'] = 'Data successfully inserted for Wati plugin';
|
66 |
+
$statusCode = 200;
|
67 |
+
|
68 |
+
$result['response'] = $response;
|
69 |
+
$result['status_code'] = $statusCode;
|
70 |
+
|
71 |
+
return $result;
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
|
76 |
+
function prepareAbandonmentData( $razorpayData ) {
|
77 |
+
|
78 |
+
if ( function_exists( 'WC' ) ) {
|
79 |
+
|
80 |
+
// Retrieving cart total value and currency.
|
81 |
+
$cartTotal = WC()->cart->total;
|
82 |
+
|
83 |
+
// Retrieving cart products and their quantities.
|
84 |
+
$products = WC()->cart->get_cart();
|
85 |
+
$currentTime = current_time( 'Y-m-d H:i:s' );
|
86 |
+
$otherFields = array(
|
87 |
+
'wcf_billing_company' => "",
|
88 |
+
'wcf_billing_address_1' => $razorpayData['customer_details']['billing_address']['line1'] ?? '',
|
89 |
+
'wcf_billing_address_2' => $razorpayData['customer_details']['billing_address']['line2'] ?? '',
|
90 |
+
'wcf_billing_state' => $razorpayData['customer_details']['billing_address']['state'] ?? '',
|
91 |
+
'wcf_billing_postcode' => $razorpayData['customer_details']['billing_address']['zipcode'] ?? '',
|
92 |
+
'wcf_shipping_first_name' => $razorpayData['customer_details']['billing_address']['name'] ?? '',
|
93 |
+
'wcf_shipping_last_name' => "",
|
94 |
+
'wcf_shipping_company' => "",
|
95 |
+
'wcf_shipping_country' => $razorpayData['customer_details']['shipping_address']['country'] ?? '',
|
96 |
+
'wcf_shipping_address_1' => $razorpayData['customer_details']['shipping_address']['line1'] ?? '',
|
97 |
+
'wcf_shipping_address_2' => $razorpayData['customer_details']['shipping_address']['line2'] ?? '',
|
98 |
+
'wcf_shipping_city' => $razorpayData['customer_details']['shipping_address']['city'] ?? '',
|
99 |
+
'wcf_shipping_state' => $razorpayData['customer_details']['shipping_address']['state'] ?? '',
|
100 |
+
'wcf_shipping_postcode' => $razorpayData['customer_details']['shipping_address']['zipcode'] ?? '',
|
101 |
+
'wcf_order_comments' => "",
|
102 |
+
'wcf_first_name' => $razorpayData['customer_details']['shipping_address']['name'] ?? '',
|
103 |
+
'wcf_last_name' => "",
|
104 |
+
'wcf_phone_number' => $razorpayData['customer_details']['shipping_address']['contact'] ?? '',
|
105 |
+
'wcf_location' => $razorpayData['customer_details']['shipping_address']['country'] ?? ''.','.$razorpayData['customer_details']['shipping_address']['city'] ?? '',
|
106 |
+
);
|
107 |
+
|
108 |
+
$checkoutDetails = array(
|
109 |
+
'email' => $razorpayData['customer_details']['email'] ?? $customerEmail,
|
110 |
+
'cart_contents' => serialize( $products ),
|
111 |
+
'cart_total' => sanitize_text_field( $cartTotal ),
|
112 |
+
'time' => sanitize_text_field( $currentTime ),
|
113 |
+
'other_fields' => serialize( $otherFields ),
|
114 |
+
'checkout_id' => wc_get_page_id('cart'),
|
115 |
+
);
|
116 |
+
}
|
117 |
+
return $checkoutDetails;
|
118 |
+
}
|
119 |
+
|
120 |
+
function handleWatiRecoveredOrder($orderID){
|
121 |
+
$wati = WATI_Chat_And_Notification_Aband_Cart::get_instance();
|
122 |
+
$wati->wati_ca_update_order_status($orderID,'pending','processing');
|
123 |
+
}
|
public/css/1cc-product-checkout.css
CHANGED
@@ -13,7 +13,7 @@
|
|
13 |
position: fixed;
|
14 |
top: 0;
|
15 |
left: 0;
|
16 |
-
z-index:
|
17 |
width: 100%;
|
18 |
height: 100%;
|
19 |
background: rgba(0, 0, 0);
|
@@ -34,7 +34,7 @@
|
|
34 |
bottom: 0;
|
35 |
right: 0;
|
36 |
margin: auto;
|
37 |
-
z-index:
|
38 |
display: flex !important;
|
39 |
align-items: center;
|
40 |
justify-content: center;
|
13 |
position: fixed;
|
14 |
top: 0;
|
15 |
left: 0;
|
16 |
+
z-index: 999999999999999;
|
17 |
width: 100%;
|
18 |
height: 100%;
|
19 |
background: rgba(0, 0, 0);
|
34 |
bottom: 0;
|
35 |
right: 0;
|
36 |
margin: auto;
|
37 |
+
z-index: 999999999999999;
|
38 |
display: flex !important;
|
39 |
align-items: center;
|
40 |
justify-content: center;
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: razorpay
|
|
3 |
Tags: razorpay, payments, india, woocommerce, ecommerce
|
4 |
Requires at least: 3.9.2
|
5 |
Tested up to: 6.0.1
|
6 |
-
Stable tag: 4.3.
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -41,6 +41,13 @@ This is compatible with WooCommerce>=2.4, including the new 3.0 release. It has
|
|
41 |
|
42 |
== Changelog ==
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
= 4.3.1 =
|
45 |
* Fixed, automatic injection of affordability widget code.
|
46 |
* Added, checkbox to enable affordability widget.
|
3 |
Tags: razorpay, payments, india, woocommerce, ecommerce
|
4 |
Requires at least: 3.9.2
|
5 |
Tested up to: 6.0.1
|
6 |
+
Stable tag: 4.3.2
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
41 |
|
42 |
== Changelog ==
|
43 |
|
44 |
+
= 4.3.2 =
|
45 |
+
* Added, support for variable products.
|
46 |
+
* Removed, checkbox to enable affordability widget.
|
47 |
+
* Added, Divi theme support.
|
48 |
+
* Added, WATI plugin support.
|
49 |
+
* Added, Flycart changes.
|
50 |
+
|
51 |
= 4.3.1 =
|
52 |
* Fixed, automatic injection of affordability widget code.
|
53 |
* Added, checkbox to enable affordability widget.
|
templates/rzp-mini-checkout-btn.php
CHANGED
@@ -6,12 +6,5 @@
|
|
6 |
>CHECKOUT
|
7 |
</button>
|
8 |
</div>
|
9 |
-
<div id="rzp-spinner-backdrop"></div>
|
10 |
-
<div id="rzp-spinner">
|
11 |
-
<div id="loading-indicator"></div>
|
12 |
-
<div id="icon">
|
13 |
-
<img src="<?php echo plugin_dir_url(dirname(__FILE__)) . 'public/images/rzp-spinner.svg'; ?>" alt="Loading" id="rzp-logo" />
|
14 |
-
</div>
|
15 |
-
</div>
|
16 |
<div id="error-message">
|
17 |
</div>
|
6 |
>CHECKOUT
|
7 |
</button>
|
8 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
<div id="error-message">
|
10 |
</div>
|
woo-razorpay.php
CHANGED
@@ -3,8 +3,8 @@
|
|
3 |
* Plugin Name: Razorpay for WooCommerce
|
4 |
* Plugin URI: https://razorpay.com
|
5 |
* Description: Razorpay Payment Gateway Integration for WooCommerce
|
6 |
-
* Version: 4.3.
|
7 |
-
* Stable tag: 4.3.
|
8 |
* Author: Team Razorpay
|
9 |
* WC tested up to: 6.7.0
|
10 |
* Author URI: https://razorpay.com
|
@@ -25,6 +25,7 @@ require_once __DIR__.'/includes/utils.php';
|
|
25 |
require_once __DIR__.'/includes/state-map.php';
|
26 |
require_once __DIR__.'/includes/plugin-instrumentation.php';
|
27 |
require_once __DIR__.'/includes/support/cartbounty.php';
|
|
|
28 |
require_once __DIR__.'/includes/razorpay-affordability-widget.php';
|
29 |
|
30 |
use Razorpay\Api\Api;
|
@@ -325,12 +326,12 @@ function woocommerce_razorpay_init()
|
|
325 |
$this->form_fields[$key] = $value;
|
326 |
}
|
327 |
}
|
328 |
-
|
329 |
//Affordability Widget Code
|
330 |
try
|
331 |
{
|
332 |
if (isset($_POST['woocommerce_razorpay_key_id']) and
|
333 |
-
empty($_POST['woocommerce_razorpay_key_id']) === false and
|
334 |
isset($_POST['woocommerce_razorpay_key_secret']) and
|
335 |
empty($_POST['woocommerce_razorpay_key_secret']) === false)
|
336 |
{
|
@@ -340,11 +341,18 @@ function woocommerce_razorpay_init()
|
|
340 |
{
|
341 |
$api = $this->getRazorpayApiInstance();
|
342 |
}
|
|
|
343 |
$merchantPreferences = $api->request->request('GET', 'accounts/me/features');
|
344 |
|
345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
{
|
347 |
-
if ($preference['name'] === 'affordability_widget')
|
348 |
{
|
349 |
add_action('woocommerce_sections_checkout', 'addSubSection');
|
350 |
add_action('woocommerce_settings_tabs_checkout', 'displayAffordabilityWidgetSettings');
|
@@ -682,6 +690,15 @@ function woocommerce_razorpay_init()
|
|
682 |
**/
|
683 |
function receipt_page($orderId)
|
684 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
685 |
echo $this->generate_razorpay_form($orderId);
|
686 |
}
|
687 |
|
@@ -1604,6 +1621,11 @@ EOT;
|
|
1604 |
handleCBRecoveredOrder($orderId);
|
1605 |
}
|
1606 |
|
|
|
|
|
|
|
|
|
|
|
1607 |
$order->add_order_note("Razorpay payment successful <br/>Razorpay Id: $razorpayPaymentId");
|
1608 |
|
1609 |
if($this->getSetting('route_enable') == 'yes')
|
@@ -2208,27 +2230,30 @@ EOT;
|
|
2208 |
|
2209 |
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'razorpay_woo_plugin_links');
|
2210 |
|
2211 |
-
|
2212 |
-
get_option('rzp_afd_enable') === 'yes')
|
2213 |
{
|
2214 |
-
|
|
|
|
|
|
|
|
|
2215 |
{
|
2216 |
-
|
2217 |
-
$merchantPreferences = $api->request->request('GET', 'accounts/me/features');
|
2218 |
-
foreach ($merchantPreferences['assigned_features'] as $preference)
|
2219 |
-
{
|
2220 |
-
if ($preference['name'] === 'affordability_widget')
|
2221 |
-
{
|
2222 |
-
add_action ('woocommerce_before_add_to_cart_form', 'addAffordabilityWidgetHTML');
|
2223 |
-
}
|
2224 |
-
}
|
2225 |
}
|
2226 |
-
|
|
|
2227 |
{
|
2228 |
-
|
2229 |
-
|
|
|
|
|
2230 |
}
|
2231 |
}
|
|
|
|
|
|
|
|
|
|
|
2232 |
}
|
2233 |
|
2234 |
// This is set to a priority of 10
|
3 |
* Plugin Name: Razorpay for WooCommerce
|
4 |
* Plugin URI: https://razorpay.com
|
5 |
* Description: Razorpay Payment Gateway Integration for WooCommerce
|
6 |
+
* Version: 4.3.2
|
7 |
+
* Stable tag: 4.3.2
|
8 |
* Author: Team Razorpay
|
9 |
* WC tested up to: 6.7.0
|
10 |
* Author URI: https://razorpay.com
|
25 |
require_once __DIR__.'/includes/state-map.php';
|
26 |
require_once __DIR__.'/includes/plugin-instrumentation.php';
|
27 |
require_once __DIR__.'/includes/support/cartbounty.php';
|
28 |
+
require_once __DIR__.'/includes/support/wati.php';
|
29 |
require_once __DIR__.'/includes/razorpay-affordability-widget.php';
|
30 |
|
31 |
use Razorpay\Api\Api;
|
326 |
$this->form_fields[$key] = $value;
|
327 |
}
|
328 |
}
|
329 |
+
|
330 |
//Affordability Widget Code
|
331 |
try
|
332 |
{
|
333 |
if (isset($_POST['woocommerce_razorpay_key_id']) and
|
334 |
+
empty($_POST['woocommerce_razorpay_key_id']) === false and
|
335 |
isset($_POST['woocommerce_razorpay_key_secret']) and
|
336 |
empty($_POST['woocommerce_razorpay_key_secret']) === false)
|
337 |
{
|
341 |
{
|
342 |
$api = $this->getRazorpayApiInstance();
|
343 |
}
|
344 |
+
|
345 |
$merchantPreferences = $api->request->request('GET', 'accounts/me/features');
|
346 |
|
347 |
+
if (isset($merchantPreferences) === false or
|
348 |
+
isset($merchantPreferences['assigned_features']) === false)
|
349 |
+
{
|
350 |
+
throw new Exception("Error in Api call.");
|
351 |
+
}
|
352 |
+
|
353 |
+
foreach ($merchantPreferences['assigned_features'] as $preference)
|
354 |
{
|
355 |
+
if ($preference['name'] === 'affordability_widget')
|
356 |
{
|
357 |
add_action('woocommerce_sections_checkout', 'addSubSection');
|
358 |
add_action('woocommerce_settings_tabs_checkout', 'displayAffordabilityWidgetSettings');
|
690 |
**/
|
691 |
function receipt_page($orderId)
|
692 |
{
|
693 |
+
foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $value){
|
694 |
+
if ($value['function'] === 'output' and
|
695 |
+
stripos($value['file'], 'divi') !== false and
|
696 |
+
basename($value['file'], ".php") !== 'CheckoutPaymentInfo')
|
697 |
+
{
|
698 |
+
return;
|
699 |
+
}
|
700 |
+
}
|
701 |
+
|
702 |
echo $this->generate_razorpay_form($orderId);
|
703 |
}
|
704 |
|
1621 |
handleCBRecoveredOrder($orderId);
|
1622 |
}
|
1623 |
|
1624 |
+
// Check Wati.io retargetting plugin is active or not
|
1625 |
+
if (is1ccEnabled() && !empty($is1ccOrder) && $is1ccOrder == 'yes' && is_plugin_active('wati-chat-and-notification/wati-chat-and-notification.php')){
|
1626 |
+
handleWatiRecoveredOrder($orderId);
|
1627 |
+
}
|
1628 |
+
|
1629 |
$order->add_order_note("Razorpay payment successful <br/>Razorpay Id: $razorpayPaymentId");
|
1630 |
|
1631 |
if($this->getSetting('route_enable') == 'yes')
|
2230 |
|
2231 |
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'razorpay_woo_plugin_links');
|
2232 |
|
2233 |
+
try
|
|
|
2234 |
{
|
2235 |
+
$api = new Api(get_option('woocommerce_razorpay_settings')['key_id'], get_option('woocommerce_razorpay_settings')['key_secret']);
|
2236 |
+
$merchantPreferences = $api->request->request('GET', 'accounts/me/features');
|
2237 |
+
|
2238 |
+
if (isset($merchantPreferences) === false or
|
2239 |
+
isset($merchantPreferences['assigned_features']) === false)
|
2240 |
{
|
2241 |
+
throw new Exception("Error in Api call.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2242 |
}
|
2243 |
+
|
2244 |
+
foreach ($merchantPreferences['assigned_features'] as $preference)
|
2245 |
{
|
2246 |
+
if ($preference['name'] === 'affordability_widget')
|
2247 |
+
{
|
2248 |
+
add_action ('woocommerce_before_add_to_cart_form', 'addAffordabilityWidgetHTML');
|
2249 |
+
}
|
2250 |
}
|
2251 |
}
|
2252 |
+
catch(\Exception $e)
|
2253 |
+
{
|
2254 |
+
rzpLogError($e->getMessage());
|
2255 |
+
return;
|
2256 |
+
}
|
2257 |
}
|
2258 |
|
2259 |
// This is set to a priority of 10
|