Razorpay for WooCommerce - Version 4.1.0

Version Description

  • Bug fix for jquery undefined issue.
  • Bug fix for duplicate wooc orderId and Razorpay ID form same carthash.
  • Bug fix for nonce issue
Download this release

Release Info

Developer razorpay
Plugin Icon 128x128 Razorpay for WooCommerce
Version 4.1.0
Comparing to
See all releases

Code changes from version 4.0.1 to 4.1.0

btn-1cc-checkout.js CHANGED
@@ -1,4 +1,12 @@
1
- window.addEventListener('DOMContentLoaded', function() {
 
 
 
 
 
 
 
 
2
 
3
  var btn = document.getElementById('btn-1cc');
4
  var btnMini = document.getElementById('btn-1cc-mini-cart');
@@ -253,4 +261,4 @@ window.addEventListener('DOMContentLoaded', function() {
253
  rzp1cc.showSpinner(false);
254
  });
255
  }
256
- });
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');
261
  rzp1cc.showSpinner(false);
262
  });
263
  }
264
+ }
includes/api/api.php CHANGED
@@ -206,3 +206,15 @@ function addMagicCheckoutSettingFields(&$defaultFormFields)
206
  $defaultFormFields = array_merge($defaultFormFields, $magicCheckoutConfigFields);
207
 
208
  }
 
 
 
 
 
 
 
 
 
 
 
 
206
  $defaultFormFields = array_merge($defaultFormFields, $magicCheckoutConfigFields);
207
 
208
  }
209
+
210
+ //To handle rest cookies invalid issue
211
+ add_filter("nonce_user_logged_out", function ($uid, $action) {
212
+ if ($uid === 0 && $action === 'wp_rest') {
213
+ return null;
214
+ }
215
+ return $uid;
216
+ }, 10, 2);
217
+
218
+ add_filter( 'rest_authentication_errors', function( $maybe_error ) {
219
+ return true;
220
+ });
includes/api/order.php CHANGED
@@ -98,8 +98,9 @@ function createWcOrder(WP_REST_Request $request)
98
  updateOrderStatus($orderId, 'draft');
99
  } else {
100
  $existingOrder = wc_get_order($orderIdFromHash);
 
101
  $existingOrder->calculate_totals();
102
- if ($existingOrder->needs_payment() == false) {
103
  $woocommerce->session->__unset(RZP_1CC_CART_HASH . $cartHash);
104
  $checkout = WC()->checkout();
105
  $orderId = $checkout->create_order(array());
98
  updateOrderStatus($orderId, 'draft');
99
  } else {
100
  $existingOrder = wc_get_order($orderIdFromHash);
101
+ $orderStatus = $existingOrder->get_status();
102
  $existingOrder->calculate_totals();
103
+ if ($orderStatus != 'draft' && $existingOrder->needs_payment() == false) {
104
  $woocommerce->session->__unset(RZP_1CC_CART_HASH . $cartHash);
105
  $checkout = WC()->checkout();
106
  $orderId = $checkout->create_order(array());
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.0.1
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
  = 4.0.1 =
45
  * Bug fix for uft8 characters.
46
 
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.1.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
+ = 4.1.0 =
45
+ * Bug fix for jquery undefined issue.
46
+ * Bug fix for duplicate wooc orderId and Razorpay ID form same carthash.
47
+ * Bug fix for nonce issue
48
+
49
  = 4.0.1 =
50
  * Bug fix for uft8 characters.
51
 
templates/rzp-pdp-checkout-btn.php CHANGED
@@ -7,6 +7,7 @@ $productData = wp_json_encode(['id' => $product->get_id(), 'quantity' => 1]);
7
  class="button alt single_add_to_cart_button"
8
  type="button"
9
  product_id="<?php echo esc_attr($product->get_id()); ?>"
 
10
  pdp_checkout="<?php echo true; ?>"
11
  >BUY NOW
12
  </button>
7
  class="button alt single_add_to_cart_button"
8
  type="button"
9
  product_id="<?php echo esc_attr($product->get_id()); ?>"
10
+ value="<?php echo esc_attr($product->get_id()); ?>"
11
  pdp_checkout="<?php echo true; ?>"
12
  >BUY NOW
13
  </button>
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.0.1
7
- * Stable tag: 4.0.1
8
  * Author: Team Razorpay
9
  * WC tested up to: 6.7.0
10
  * Author URI: https://razorpay.com
@@ -665,7 +665,7 @@ function woocommerce_razorpay_init()
665
  // If we don't have an Order
666
  // or the if the order is present in transient but doesn't match what we have saved
667
  if (($razorpayOrderId === false) or
668
- (($razorpayOrderId and ($this->verifyOrderAmount($razorpayOrderId, $orderId)) === false)))
669
  {
670
  $create = true;
671
  }
@@ -928,7 +928,7 @@ function woocommerce_razorpay_init()
928
  return $razorpayOrderId;
929
  }
930
 
931
- protected function verifyOrderAmount($razorpayOrderId, $orderId)
932
  {
933
  rzpLogInfo("Called verifyOrderAmount with params orderId $orderId and rzporderId $razorpayOrderId");
934
  $order = wc_get_order($orderId);
@@ -950,11 +950,16 @@ function woocommerce_razorpay_init()
950
 
951
  $razorpayOrderArgs = array(
952
  'id' => $razorpayOrderId,
953
- 'amount' => $orderCreationData['amount'],
954
  'currency' => $orderCreationData['currency'],
955
  'receipt' => (string) $orderId,
956
  );
957
 
 
 
 
 
 
 
958
  $orderKeys = array_keys($razorpayOrderArgs);
959
 
960
  foreach ($orderKeys as $key)
3
  * Plugin Name: Razorpay for WooCommerce
4
  * Plugin URI: https://razorpay.com
5
  * Description: Razorpay Payment Gateway Integration for WooCommerce
6
+ * Version: 4.1.0
7
+ * Stable tag: 4.1.0
8
  * Author: Team Razorpay
9
  * WC tested up to: 6.7.0
10
  * Author URI: https://razorpay.com
665
  // If we don't have an Order
666
  // or the if the order is present in transient but doesn't match what we have saved
667
  if (($razorpayOrderId === false) or
668
+ (($razorpayOrderId and ($this->verifyOrderAmount($razorpayOrderId, $orderId, $is1ccCheckout)) === false)))
669
  {
670
  $create = true;
671
  }
928
  return $razorpayOrderId;
929
  }
930
 
931
+ protected function verifyOrderAmount($razorpayOrderId, $orderId, $is1ccCheckout = 'no')
932
  {
933
  rzpLogInfo("Called verifyOrderAmount with params orderId $orderId and rzporderId $razorpayOrderId");
934
  $order = wc_get_order($orderId);
950
 
951
  $razorpayOrderArgs = array(
952
  'id' => $razorpayOrderId,
 
953
  'currency' => $orderCreationData['currency'],
954
  'receipt' => (string) $orderId,
955
  );
956
 
957
+ if($is1ccCheckout == 'no'){
958
+ $razorpayOrderArgs['amount'] = $orderCreationData['amount'];
959
+ }else{
960
+ $razorpayOrderArgs['line_items_total'] = $orderCreationData['amount'];
961
+ }
962
+
963
  $orderKeys = array_keys($razorpayOrderArgs);
964
 
965
  foreach ($orderKeys as $key)