Razorpay for WooCommerce - Version 2.3.0

Version Description

  • Support for HDFC VAS merchant with hosted checkout.
  • Tested upto WordPress 5.2.4 and WooCommerce 3.7.1
Download this release

Release Info

Developer ramprak
Plugin Icon 128x128 Razorpay for WooCommerce
Version 2.3.0
Comparing to
See all releases

Code changes from version 2.2.0 to 2.3.0

Files changed (3) hide show
  1. readme.txt +7 -2
  2. script.js +49 -45
  3. woo-razorpay.php +60 -9
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: razorpay
3
  Tags: razorpay, payments, india, woocommerce, ecommerce
4
  Requires at least: 3.9.2
5
- Tested up to: 5.2.2
6
- Stable tag: 2.2.0
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,11 @@ This is compatible with WooCommerce>=2.4, including the new 3.0 release. It has
41
 
42
  == Changelog ==
43
 
 
 
 
 
 
44
  = 2.2.0 =
45
  * Adds webhook for handling subscription cancellation.
46
  * Tested upto WordPress 5.2.2 and WooCommerce 3.7.0
2
  Contributors: razorpay
3
  Tags: razorpay, payments, india, woocommerce, ecommerce
4
  Requires at least: 3.9.2
5
+ Tested up to: 5.2.4
6
+ Stable tag: 2.3.0
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
+ = 2.3.0 =
45
+ * Support for HDFC VAS merchant with hosted checkout.
46
+ * Tested upto WordPress 5.2.4 and WooCommerce 3.7.1
47
+
48
+
49
  = 2.2.0 =
50
  * Adds webhook for handling subscription cancellation.
51
  * Tested upto WordPress 5.2.2 and WooCommerce 3.7.0
script.js CHANGED
@@ -1,57 +1,61 @@
1
  (function() {
2
  var data = razorpay_wc_checkout_vars;
3
- var setDisabled = function(id, state) {
4
- if (typeof state === 'undefined') {
5
- state = true;
6
- }
7
- var elem = document.getElementById(id);
8
- if (state === false) {
9
- elem.removeAttribute('disabled');
10
- } else {
11
- elem.setAttribute('disabled', state);
12
- }
13
- };
 
 
 
14
 
15
- // Payment was closed without handler getting called
16
- data.modal = {
17
- ondismiss: function() {
18
- setDisabled('btn-razorpay', false);
19
- },
20
- };
21
 
22
- data.handler = function(payment) {
23
- setDisabled('btn-razorpay-cancel');
24
- var successMsg = document.getElementById('msg-razorpay-success');
25
- successMsg.style.display = 'block';
26
- document.getElementById('razorpay_payment_id').value =
27
- payment.razorpay_payment_id;
28
- document.getElementById('razorpay_signature').value =
29
- payment.razorpay_signature;
30
- document.razorpayform.submit();
31
- };
32
 
33
- var razorpayCheckout = new Razorpay(data);
34
 
35
- // global method
36
- function openCheckout() {
37
- // Disable the pay button
38
- setDisabled('btn-razorpay');
39
- razorpayCheckout.open();
40
- }
41
 
42
- function addEvent(element, evnt, funct) {
43
- if (element.attachEvent) {
44
- return element.attachEvent('on' + evnt, funct);
45
- } else return element.addEventListener(evnt, funct, false);
46
- }
47
 
48
- if (document.readyState === 'complete') {
49
- addEvent(document.getElementById('btn-razorpay'), 'click', openCheckout);
50
- openCheckout();
51
- } else {
52
- document.addEventListener('DOMContentLoaded', function() {
53
  addEvent(document.getElementById('btn-razorpay'), 'click', openCheckout);
54
  openCheckout();
55
- });
 
 
 
 
 
56
  }
57
  })();
1
  (function() {
2
  var data = razorpay_wc_checkout_vars;
3
+ if(data === 'checkoutForm') {
4
+ document.getElementById("checkoutForm").submit();
5
+ } else {
6
+ var setDisabled = function(id, state) {
7
+ if (typeof state === 'undefined') {
8
+ state = true;
9
+ }
10
+ var elem = document.getElementById(id);
11
+ if (state === false) {
12
+ elem.removeAttribute('disabled');
13
+ } else {
14
+ elem.setAttribute('disabled', state);
15
+ }
16
+ };
17
 
18
+ // Payment was closed without handler getting called
19
+ data.modal = {
20
+ ondismiss: function() {
21
+ setDisabled('btn-razorpay', false);
22
+ },
23
+ };
24
 
25
+ data.handler = function(payment) {
26
+ setDisabled('btn-razorpay-cancel');
27
+ var successMsg = document.getElementById('msg-razorpay-success');
28
+ successMsg.style.display = 'block';
29
+ document.getElementById('razorpay_payment_id').value =
30
+ payment.razorpay_payment_id;
31
+ document.getElementById('razorpay_signature').value =
32
+ payment.razorpay_signature;
33
+ document.razorpayform.submit();
34
+ };
35
 
36
+ var razorpayCheckout = new Razorpay(data);
37
 
38
+ // global method
39
+ function openCheckout() {
40
+ // Disable the pay button
41
+ setDisabled('btn-razorpay');
42
+ razorpayCheckout.open();
43
+ }
44
 
45
+ function addEvent(element, evnt, funct) {
46
+ if (element.attachEvent) {
47
+ return element.attachEvent('on' + evnt, funct);
48
+ } else return element.addEventListener(evnt, funct, false);
49
+ }
50
 
51
+ if (document.readyState === 'complete') {
 
 
 
 
52
  addEvent(document.getElementById('btn-razorpay'), 'click', openCheckout);
53
  openCheckout();
54
+ } else {
55
+ document.addEventListener('DOMContentLoaded', function() {
56
+ addEvent(document.getElementById('btn-razorpay'), 'click', openCheckout);
57
+ openCheckout();
58
+ });
59
+ }
60
  }
61
  })();
woo-razorpay.php CHANGED
@@ -3,10 +3,10 @@
3
  * Plugin Name: Razorpay for WooCommerce
4
  * Plugin URI: https://razorpay.com
5
  * Description: Razorpay Payment Gateway Integration for WooCommerce
6
- * Version: 2.2.0
7
- * Stable tag: 2.2.0
8
  * Author: Team Razorpay
9
- * WC tested up to: 3.7.0
10
  * Author URI: https://razorpay.com
11
  */
12
 
@@ -566,13 +566,21 @@ function woocommerce_razorpay_init()
566
 
567
  private function enqueueCheckoutScripts($data)
568
  {
569
- wp_register_script('razorpay_checkout',
570
- 'https://checkout.razorpay.com/v1/checkout.js',
 
571
  null, null);
572
-
573
- wp_register_script('razorpay_wc_script', plugin_dir_url(__FILE__) . 'script.js',
 
 
574
  array('razorpay_checkout'));
575
 
 
 
 
 
 
576
  wp_localize_script('razorpay_wc_script',
577
  'razorpay_wc_checkout_vars',
578
  $data
@@ -581,15 +589,57 @@ function woocommerce_razorpay_init()
581
  wp_enqueue_script('razorpay_wc_script');
582
  }
583
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
584
  /**
585
  * Generates the order form
586
  **/
587
  function generateOrderForm($data)
588
  {
589
  $redirectUrl = $this->getRedirectUrl();
590
- $this->enqueueCheckoutScripts($data);
591
 
592
- return <<<EOT
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
593
  <form name='razorpayform' action="$redirectUrl" method="POST">
594
  <input type="hidden" name="razorpay_payment_id" id="razorpay_payment_id">
595
  <input type="hidden" name="razorpay_signature" id="razorpay_signature" >
@@ -604,6 +654,7 @@ Please wait while we are processing your payment.
604
  <button id="btn-razorpay-cancel" onclick="document.razorpayform.submit()">Cancel</button>
605
  </p>
606
  EOT;
 
607
  }
608
 
609
  /**
3
  * Plugin Name: Razorpay for WooCommerce
4
  * Plugin URI: https://razorpay.com
5
  * Description: Razorpay Payment Gateway Integration for WooCommerce
6
+ * Version: 2.3.0
7
+ * Stable tag: 2.3.0
8
  * Author: Team Razorpay
9
+ * WC tested up to: 3.7.1
10
  * Author URI: https://razorpay.com
11
  */
12
 
566
 
567
  private function enqueueCheckoutScripts($data)
568
  {
569
+ if($data === 'checkoutForm')
570
+ {
571
+ wp_register_script('razorpay_wc_script', plugin_dir_url(__FILE__) . 'script.js',
572
  null, null);
573
+ }
574
+ else
575
+ {
576
+ wp_register_script('razorpay_wc_script', plugin_dir_url(__FILE__) . 'script.js',
577
  array('razorpay_checkout'));
578
 
579
+ wp_register_script('razorpay_checkout',
580
+ 'https://checkout.razorpay.com/v1/checkout.js',
581
+ null, null);
582
+ }
583
+
584
  wp_localize_script('razorpay_wc_script',
585
  'razorpay_wc_checkout_vars',
586
  $data
589
  wp_enqueue_script('razorpay_wc_script');
590
  }
591
 
592
+ private function hostCheckoutScripts($data)
593
+ {
594
+ $url = Api::getFullUrl("checkout/embedded");
595
+
596
+ $formFields = "";
597
+ foreach ($data as $fieldKey => $val) {
598
+ if(in_array($fieldKey, array('notes', 'prefill', '_')))
599
+ {
600
+ foreach ($data[$fieldKey] as $field => $fieldVal) {
601
+ $formFields .= "<input type='hidden' name='$fieldKey" ."[$field]"."' value='$fieldVal'> \n";
602
+ }
603
+ }
604
+ }
605
+
606
+ return '<form method="POST" action="'.$url.'" id="checkoutForm">
607
+ <input type="hidden" name="key_id" value="'.$data['key'].'">
608
+ <input type="hidden" name="order_id" value="'.$data['order_id'].'">
609
+ <input type="hidden" name="name" value="'.$data['name'].'">
610
+ <input type="hidden" name="description" value="'.$data['description'].'">
611
+ <input type="hidden" name="image" value="'.$data['preference']['image'].'">
612
+ <input type="hidden" name="callback_url" value="'.$data['callback_url'].'">
613
+ <input type="hidden" name="cancel_url" value="'.$data['callback_url'].'">
614
+ '. $formFields .'
615
+ </form>';
616
+
617
+ }
618
+
619
+
620
  /**
621
  * Generates the order form
622
  **/
623
  function generateOrderForm($data)
624
  {
625
  $redirectUrl = $this->getRedirectUrl();
 
626
 
627
+ $api = new Api($this->getSetting('key_id'),"");
628
+
629
+ $merchantPreferences = $api->request->request("GET", "preferences");
630
+
631
+ if(isset($merchantPreferences['options']['redirect']) && $merchantPreferences['options']['redirect'] === true)
632
+ {
633
+ $this->enqueueCheckoutScripts('checkoutForm');
634
+
635
+ $data['preference']['image'] = $merchantPreferences['options']['image'];
636
+
637
+ return $this->hostCheckoutScripts($data);
638
+
639
+ } else {
640
+ $this->enqueueCheckoutScripts($data);
641
+
642
+ return <<<EOT
643
  <form name='razorpayform' action="$redirectUrl" method="POST">
644
  <input type="hidden" name="razorpay_payment_id" id="razorpay_payment_id">
645
  <input type="hidden" name="razorpay_signature" id="razorpay_signature" >
654
  <button id="btn-razorpay-cancel" onclick="document.razorpayform.submit()">Cancel</button>
655
  </p>
656
  EOT;
657
+ }
658
  }
659
 
660
  /**