PluginProbe ʕ •ᴥ•ʔ
Razorpay for WooCommerce / 4.8.6
Razorpay for WooCommerce v4.8.6
4.8.6 4.8.5 4.8.4 trunk 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.0-beta 1.6.1 1.6.2 1.6.3 1.6.5 2.0.0 2.0.1 2.1.0 2.2.0 2.3.0 2.3.1 2.3.2 2.4.0 2.4.1 2.4.2 2.4.3 2.5.0 2.6.0 2.7.0 2.7.1 2.7.2 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 3.0.0 3.0.1 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.7.0 3.7.1 3.7.2 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.0.1 4.1.0 4.2.0 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.4.0 4.4.1 4.4.2 4.4.3 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3
woo-razorpay / includes / razorpay-affordability-widget.php
woo-razorpay / includes Last commit date
Errors 8 years ago api 2 months ago cron 2 years ago support 5 months ago debug.php 4 years ago plugin-instrumentation.php 3 months ago razorpay-affordability-widget.php 4 weeks ago razorpay-route-actions.php 2 years ago razorpay-route.php 4 weeks ago razorpay-webhook.php 5 months ago state-map.php 4 years ago utils.php 3 years ago
razorpay-affordability-widget.php
596 lines
1 <?php
2
3 use Razorpay\Api\Api;
4
5 function addAffordabilityWidgetHTML()
6 {
7 $current_user = wp_get_current_user();
8 if ((isAffordabilityWidgetTestModeEnabled() === false) or
9 (isAffordabilityWidgetTestModeEnabled() and
10 ($current_user->has_cap('administrator') or
11 preg_match('/@razorpay.com$/i', $current_user->user_email))))
12 {
13 echo '<div id="razorpay-affordability-widget" style="display: block;"></div>
14 <script src="https://cdn.razorpay.com/widgets/affordability/affordability.js">
15 </script>
16
17 <script>
18 const key = "'.getKeyId().'";
19 const amount = parseFloat("'.getPrice().'s") * 100;
20 addEventListener("load",
21 function() {
22 const widgetConfig = {
23 "key": key,
24 "amount": amount,
25 "theme": {
26 "color": "'.getThemeColor().'"
27 },
28 "features": {
29 "offers": {
30 "list": '.getAdditionalOffers().',
31 }
32 },
33 "display": {
34 "offers": '.getOffers().',
35 "emi": '.getEmi().',
36 "cardlessEmi": '.getCardlessEmi().',
37 "paylater": '.getPayLater().',
38 "widget": {
39 "main": {
40 "heading": {
41 "color": "'.getHeadingColor().'",
42 "fontSize": "'.getHeadingFontSize().'px"
43 },
44 "content": {
45 "color": "'.getContentColor().'",
46 "fontSize": "'.getContentFontSize().'px"
47 },
48 "link": {
49 "color": "'.getLinkColor().'",
50 "fontSize": "'.getLinkFontSize().'px"
51 },
52 "footer": {
53 "color": "'.getFooterColor().'",
54 "fontSize": "'.getFooterFontSize().'px",
55 "darkLogo": '.getFooterDarkLogo().'// true is default show black text rzp logo
56 }
57 }
58 }
59 }
60 };
61 const rzpAffordabilitySuite = new RazorpayAffordabilitySuite(widgetConfig);
62 rzpAffordabilitySuite.render();
63 });
64
65 jQuery(function($) {
66
67 $.fn.myFunction = function()
68 {
69 var variants = (document.querySelector("form.variations_form").dataset.product_variations);
70 var selectedVariantID = document.querySelector("input.variation_id").value;
71 var selectedVariant = JSON.parse(variants).filter( variant => variant.variation_id === parseInt(selectedVariantID));
72
73 if(typeof(selectedVariant[0]) != "undefined")
74 {
75 amt = selectedVariant[0].display_price * 100;
76 const widgetConfig = {
77 "key": key,
78 "amount": amt,
79 "theme": {
80 "color": "'.getThemeColor().'"
81 },
82 "features": {
83 "offers": {
84 "list": '.getAdditionalOffers().',
85 }
86 },
87 "display": {
88 "offers": '.getOffers().',
89 "emi": '.getEmi().',
90 "cardlessEmi": '.getCardlessEmi().',
91 "paylater": '.getPayLater().',
92 "widget": {
93 "main": {
94 "heading": {
95 "color": "'.getHeadingColor().'",
96 "fontSize": "'.getHeadingFontSize().'px"
97 },
98 "content": {
99 "color": "'.getContentColor().'",
100 "fontSize": "'.getContentFontSize().'px"
101 },
102 "link": {
103 "color": "'.getLinkColor().'",
104 "fontSize": "'.getLinkFontSize().'px"
105 },
106 "footer": {
107 "color": "'.getFooterColor().'",
108 "fontSize": "'.getFooterFontSize().'px",
109 "darkLogo": '.getFooterDarkLogo().'// true is default show black text rzp logo
110 }
111 }
112 }
113 }
114 };
115 const rzpAffordabilitySuite = new RazorpayAffordabilitySuite(widgetConfig);
116 rzpAffordabilitySuite.render();
117 }
118 }
119
120 $("input.variation_id").change(function(){
121 $.fn.myFunction();
122 });
123
124 });
125
126 </script>
127 ';
128 }
129 }
130
131 function getKeyId()
132 {
133 return get_option('woocommerce_razorpay_settings')['key_id'];
134 }
135
136 function getPrice()
137 {
138 global $product;
139
140 return wc_get_price_to_display($product);
141 }
142
143 function getOffers()
144 {
145 $offers = isEnabled('rzp_afd_enable_offers');
146
147 if (empty(get_option('rzp_afd_limited_offers')) === false and
148 $offers != 'false')
149 {
150 $offers = '{ "offerIds": [';
151 foreach (explode(',', get_option('rzp_afd_limited_offers')) as $provider)
152 {
153 $offers = $offers.'"'.$provider.'"';
154 $offers = $offers.',';
155 }
156 $offers = $offers.']';
157 }
158 if (empty(get_option('rzp_afd_show_discount_amount')) === false and
159 $offers != 'false')
160 {
161 if ($offers != 'true')
162 {
163 $offers = $offers.',';
164 }
165 else
166 {
167 $offers = '{';
168 }
169 $offers = $offers.'"showDiscount": ';
170 $showDiscount = isEnabled('rzp_afd_show_discount_amount');
171 $offers = $offers.$showDiscount;
172 $offers = $offers.'}';
173 }
174
175 return $offers;
176 }
177
178 function getAdditionalOffers()
179 {
180 $additionalOffers = '[]';
181 if (empty(get_option('rzp_afd_additional_offers')) === false and
182 getOffers() != 'false')
183 {
184 $additionalOffers = '[';
185 foreach (explode(",", get_option('rzp_afd_additional_offers')) as $provider)
186 {
187 $additionalOffers = $additionalOffers.'"'.$provider.'"';
188 $additionalOffers = $additionalOffers.',';
189 }
190 $additionalOffers = $additionalOffers.']';
191 }
192
193 return $additionalOffers;
194 }
195
196 function getEmi()
197 {
198 $emi = isEnabled('rzp_afd_enable_emi');
199
200 if (empty(get_option('rzp_afd_limited_emi_providers')) === false and
201 $emi != 'false')
202 {
203 $emi = '{ "issuers": [';
204 foreach (explode(",", get_option('rzp_afd_limited_emi_providers')) as $provider)
205 {
206 $emi = $emi.'"'.$provider.'"';
207 $emi = $emi.',';
208 }
209 $emi = $emi.'] }';
210 }
211
212 return $emi;
213 }
214
215 function getCardlessEmi()
216 {
217 $cardlessEmi = isEnabled('rzp_afd_enable_cardless_emi');
218
219 if (empty(get_option('rzp_afd_limited_cardless_emi_providers')) === false and
220 $cardlessEmi != 'false')
221 {
222 $cardlessEmi = '{ "providers": [';
223 foreach (explode(",", get_option('rzp_afd_limited_cardless_emi_providers')) as $provider)
224 {
225 $cardlessEmi = $cardlessEmi.'"'.$provider.'"';
226 $cardlessEmi = $cardlessEmi.',';
227 }
228 $cardlessEmi = $cardlessEmi.'] }';
229 }
230
231 return $cardlessEmi;
232 }
233
234 function getPayLater()
235 {
236 $payLater = isEnabled('rzp_afd_enable_pay_later');
237
238 if (empty(get_option('rzp_afd_limited_pay_later_providers')) === false and
239 $payLater != 'false')
240 {
241 $payLater = '{ "providers": [';
242 foreach (explode(",", get_option('rzp_afd_limited_pay_later_providers')) as $provider)
243 {
244 $payLater = $payLater.'"'.$provider.'"';
245 $payLater = $payLater.',';
246 }
247 $payLater = $payLater.'] }';
248 }
249
250 return $payLater;
251 }
252
253 function getThemeColor()
254 {
255 return getCustomisation('rzp_afd_theme_color');
256 }
257
258 function getHeadingColor()
259 {
260 return getCustomisation('rzp_afd_heading_color');
261 }
262
263 function getHeadingFontSize()
264 {
265 return getCustomisation('rzp_afd_heading_font_size');
266 }
267
268 function getContentColor()
269 {
270 return getCustomisation('rzp_afd_content_color');
271 }
272
273 function getContentFontSize()
274 {
275 return getCustomisation('rzp_afd_content_font_size');
276 }
277
278 function getLinkColor()
279 {
280 return getCustomisation('rzp_afd_link_color');
281 }
282
283 function getLinkFontSize()
284 {
285 return getCustomisation('rzp_afd_link_font_size');
286 }
287
288 function getFooterColor()
289 {
290 return getCustomisation('rzp_afd_footer_color');
291 }
292
293 function getFooterFontSize()
294 {
295 return getCustomisation('rzp_afd_footer_font_size');
296 }
297
298 function getFooterDarkLogo()
299 {
300 $footerDarkLogo = isEnabled('rzp_afd_enable_dark_logo');
301
302 return $footerDarkLogo;
303 }
304
305 function addSubSection()
306 {
307 global $current_section;
308
309 $tab_id = 'checkout';
310
311 $sections = array(
312 'razorpay' => __('Plugin Settings'),
313 'affordability-widget' => __('Affordability Widget'),
314 );
315
316 echo '<ul class="subsubsub">';
317
318 $array_keys = array_keys($sections);
319
320 foreach ($sections as $id => $label)
321 {
322 if ($current_section === 'razorpay' or
323 $current_section === 'affordability-widget')
324 {
325 echo '<li><a href="'.admin_url('admin.php?page=wc-settings&tab='.$tab_id.
326 '&section='.sanitize_title( $id )).'" class="'.($current_section === $id ? 'current' : '').'">'.
327 $label.'</a> '.(end($array_keys) === $id ? '' : '|').' </li>';
328 }
329 }
330
331 echo '</ul><br class="clear" />';
332 }
333
334 function getAffordabilityWidgetSettings()
335 {
336 global $current_section;
337 $settings = array();
338
339 if ($current_section === 'affordability-widget')
340 {
341 $settings = array(
342 'section_title' => array(
343 'name' => __('Affordability Widget Settings'),
344 'type' => 'title',
345 'desc' => '',
346 'id' => 'rzp_afd_section_title'
347 ),
348 'enable' => array(
349 'title' => __('Affordability Widget Enable/Disable'),
350 'type' => 'hidden',
351 'desc' => __('Enable Affordability Widget?'),
352 'default' => 'no',
353 'id' => 'rzp_afd_enable'
354 ),
355 'enable_test_mode' => array(
356 'title' => __('Test Mode Enable/Disable'),
357 'type' => 'checkbox',
358 'desc' => __('Enable Test Mode?'),
359 'default' => 'no',
360 'id' => 'rzp_afd_enable_test_mode'
361 ),
362 'enable_offers' => array(
363 'title' => __('Offers Enable/Disable'),
364 'type' => 'checkbox',
365 'desc' => __('Enable offers?'),
366 'default' => 'yes',
367 'id' => 'rzp_afd_enable_offers'
368 ),
369 'additional_offers' => array(
370 'title' => __('Additional Offers'),
371 'type' => 'textarea',
372 'desc' => __('Enter offer id for offer that did not have the \'Show Offer on Checkout\' option enabled at the time of creation.'),
373 'id' => 'rzp_afd_additional_offers'
374 ),
375 'limited_offers' => array(
376 'title' => __('Limited Offers'),
377 'type' => 'textarea',
378 'desc' => __('In case you want to display limited offers on the widget, enter the offer_id of your choice that you want to display.'),
379 'id' => 'rzp_afd_limited_offers'
380 ),
381 'show_discount_amount' => array(
382 'title' => __('Show Discount Amount'),
383 'type' => 'checkbox',
384 'desc' => __('Display the exact amount of discount on offers'),
385 'default' => 'yes',
386 'id' => 'rzp_afd_show_discount_amount'
387 ),
388 'enable_emi' => array(
389 'title' => __('Card EMI Enable/Disable'),
390 'type' => 'checkbox',
391 'desc' => __('Enable Card EMI?'),
392 'default' => 'yes',
393 'id' => 'rzp_afd_enable_emi'
394 ),
395 'limited_emi_providers' => array(
396 'title' => __('Limited Card EMI Providers'),
397 'type' => 'textarea',
398 'desc' => __('In case you want to display limited EMI options on the widget, enter the list of provider codes based on your requirement.Please find the list of <a href="https://razorpay.com/docs/payments/payment-gateway/affordability/faqs/#2-what-are-the-standard-credit-card-interest">provider codes</a> here.'),
399 'id' => 'rzp_afd_limited_emi_providers'
400 ),
401 'enable_cardless_emi' => array(
402 'title' => __('Cardless EMI Enable/Disable'),
403 'type' => 'checkbox',
404 'desc' => __('Enable Cardless EMI?'),
405 'default' => 'yes',
406 'id' => 'rzp_afd_enable_cardless_emi'
407 ),
408 'limited_cardles_emi_providers' => array(
409 'title' => __('Limited Cardless EMI Providers'),
410 'type' => 'textarea',
411 'desc' => __('In case you want to display limited Cardless EMI options on the widget, enter the list of provider codes based on your requirement.Please find the list of <a href="https://razorpay.com/docs/payments/payment-methods/emi/cardless-emi/">provider codes</a> here.'),
412 'id' => 'rzp_afd_limited_cardless_emi_providers'
413 ),
414 'enable_pay_later' => array(
415 'title' => __('Pay Later Enable/Disable'),
416 'type' => 'checkbox',
417 'desc' => __('Enable Pay Later?'),
418 'default' => 'yes',
419 'id' => 'rzp_afd_enable_pay_later'
420 ),
421 'limited_pay_later_providers' => array(
422 'title' => __('Limited Pay Later Providers'),
423 'type' => 'textarea',
424 'desc' => __('In case you want to display limited Pay Later options on the widget, enter the list of provider codes based on your requirement.Please find the list of <a href="https://razorpay.com/docs/payments/payment-methods/pay-later/">provider codes</a> here.'),
425 'id' => 'rzp_afd_limited_pay_later_providers'
426 ),
427 'theme_color' => array(
428 'title' => __('Theme Color'),
429 'type' => 'text',
430 'desc' => __('Enter the 6 character hex code of the theme color based on your requirement. Default is blue.'),
431 'id' => 'rzp_afd_theme_color'
432 ),
433 'heading_color' => array(
434 'title' => __('Heading Color'),
435 'type' => 'text',
436 'desc' => __('Enter the heading color based on your requirement. Default is black.' ),
437 'id' => 'rzp_afd_heading_color'
438 ),
439 'heading_font_size' => array(
440 'title' => __('Heading Font Size'),
441 'type' => 'text',
442 'desc' => __('Enter the font size of heading in px based on your requirement. Default is 10px.'),
443 'id' => 'rzp_afd_heading_font_size'
444 ),
445 'content_color' => array(
446 'title' => __('Content Color'),
447 'type' => 'text',
448 'desc' => __('Enter the content color based on your requirement. Default is grey.'),
449 'id' => 'rzp_afd_content_color'
450 ),
451 'content_font_size' => array(
452 'title' => __('Content Font Size'),
453 'type' => 'text',
454 'desc' => __('Enter the font size of content in px based on your requirement. Default is 10px.'),
455 'id' => 'rzp_afd_content_font_size'
456 ),
457 'link_color' => array(
458 'title' => __('Link Color'),
459 'type' => 'text',
460 'desc' => __('Enter the color based on your requirement. Default is blue.'),
461 'id' => 'rzp_afd_link_color'
462 ),
463 'link_font_size' => array(
464 'title' => __('Link Font Size'),
465 'type' => 'text',
466 'desc' => __('Enter the font size of link in px based on your requirement. Default is 10px.'),
467 'id' => 'rzp_afd_link_font_size'
468 ),
469 'footer_color' => array(
470 'title' => __('Footer Color'),
471 'type' => 'text',
472 'desc' => __('Enter the color based on your requirement. Default is grey.'),
473 'id' => 'rzp_afd_footer_color'
474 ),
475 'footer_font_size' => array(
476 'title' => __('Footer Font Size'),
477 'type' => 'text',
478 'desc' => __('Enter the font size of footer in px based on your requirement. Default is 10px.'),
479 'id' => 'rzp_afd_footer_font_size'
480 ),
481 'dark_logo' => array(
482 'title' => __('Dark Logo Enable/Disable'),
483 'type' => 'checkbox',
484 'desc' => __('Enable Dark Logo?'),
485 'default' => 'yes',
486 'id' => 'rzp_afd_enable_dark_logo'
487 ),
488 'section_end' => array(
489 'type' => 'sectionend',
490 'id' => 'wc_settings_tab_demo_section_end'
491 ),
492 );
493 }
494
495 return apply_filters('wc_affordability_widget_settings', $settings);
496 }
497
498 function displayAffordabilityWidgetSettings()
499 {
500 if (function_exists('woocommerce_admin_fields') === false)
501 {
502 if (defined('WC_ABSPATH')) {
503 include_once WC_ABSPATH . 'includes/admin/wc-admin-functions.php';
504 }
505 }
506 woocommerce_admin_fields(getAffordabilityWidgetSettings());
507 }
508
509 function updateAffordabilityWidgetSettings()
510 {
511 woocommerce_update_options(getAffordabilityWidgetSettings());
512 try
513 {
514 if (isset($_POST['woocommerce_razorpay_key_id']) and
515 empty($_POST['woocommerce_razorpay_key_id']) === false and
516 isset($_POST['woocommerce_razorpay_key_secret']) and
517 empty($_POST['woocommerce_razorpay_key_secret']) === false)
518 {
519 $keyId = $_POST['woocommerce_razorpay_key_id'];
520 $api = new Api($keyId, $_POST['woocommerce_razorpay_key_secret']);
521 }
522 else
523 {
524 $keyId = get_option('woocommerce_razorpay_settings')['key_id'];
525 $api = new Api($keyId, get_option('woocommerce_razorpay_settings')['key_secret']);
526 }
527
528 $modeCode = (strpos($keyId, 'rzp_test_') === 0) ? 2 : 1;
529 $widgetSetResp = $api->request->request('GET', 'app/merchant/api/verify/3/' . $modeCode);
530 $widgetResp = $api->request->request('GET', 'app/merchant/api/verify/4/' . $modeCode);
531
532 $afdEnabled = (isset($widgetSetResp['enabled']) and $widgetSetResp['enabled'] === true) or
533 (isset($widgetResp['enabled']) and $widgetResp['enabled'] === true);
534
535 update_option('rzp_afd_enable', $afdEnabled ? 'yes' : 'no');
536
537 }
538 catch (\Exception $e)
539 {
540 rzpLogError($e->getMessage());
541 return;
542 }
543 }
544
545 function isEnabled($feature)
546 {
547 if (empty(get_option($feature)) === true)
548 {
549 return 'true';
550 }
551 $value = 'false';
552
553 if (empty(get_option($feature)) === false and
554 get_option($feature) === 'yes')
555 {
556 $value = 'true';
557 }
558
559 return $value;
560 }
561
562 function getCustomisation($customisation)
563 {
564 $defaultCustomisationValues = [
565 'rzp_afd_theme_color' => '#8BBFFF',
566 'rzp_afd_heading_color' => 'black',
567 'rzp_afd_heading_font_size' => '10',
568 'rzp_afd_content_color' => 'grey',
569 'rzp_afd_content_font_size' => '10',
570 'rzp_afd_link_color' => 'blue',
571 'rzp_afd_link_font_size' => '10',
572 'rzp_afd_footer_color' => 'grey',
573 'rzp_afd_footer_font_size' => '10'
574 ];
575
576 $customisationValue = $defaultCustomisationValues[$customisation];
577 if (empty(get_option($customisation)) === false)
578 {
579 $customisationValue = get_option($customisation);
580 }
581
582 return $customisationValue;
583 }
584
585 function isAffordabilityWidgetTestModeEnabled()
586 {
587 if (empty(get_option('rzp_afd_enable_test_mode')) === true)
588 {
589 return false;
590 }
591 return (
592 empty(get_option('rzp_afd_enable_test_mode')) === false and
593 get_option('rzp_afd_enable_test_mode') === 'yes'
594 );
595 }
596