Razorpay for WooCommerce - Version 3.7.1

Version Description

  • Bug fix for auto webhook.
  • Added supported subscription webhook events
Download this release

Release Info

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

Code changes from version 3.7.0 to 3.7.1

Files changed (3) hide show
  1. includes/razorpay-webhook.php +14 -17
  2. readme.txt +5 -1
  3. woo-razorpay.php +35 -28
includes/razorpay-webhook.php CHANGED
@@ -76,18 +76,15 @@ class RZP_Webhook
76
  return;
77
  }
78
 
79
- $enabled = $this->razorpay->getSetting('enable_webhook');
80
-
81
- if (($enabled === 'yes') and
82
- (empty($data['event']) === false)) {
83
  // Skip the webhook if not the valid data and event
84
  if ($this->shouldConsumeWebhook($data) === false) {
85
  return;
86
  }
87
-
88
  if (isset($_SERVER['HTTP_X_RAZORPAY_SIGNATURE']) === true) {
89
- $razorpayWebhookSecret = $this->razorpay->getSetting('webhook_secret');
90
-
91
  //
92
  // If the webhook secret isn't set on wordpress, return
93
  //
@@ -203,7 +200,7 @@ class RZP_Webhook
203
  rzpLogInfo("Woocommerce orderId: $orderId webhook process intitiated for payment authorized event");
204
 
205
  if(!empty($orderId))
206
- {
207
  $order = $this->checkIsObject($orderId);
208
  }
209
  //To give the priority to callback script to compleate the execution fist adding this locking.
@@ -228,12 +225,12 @@ class RZP_Webhook
228
 
229
  return;
230
  }
231
-
232
  if($orderStatus == 'draft')
233
  {
234
  updateOrderStatus($orderId, 'wc-pending');
235
  }
236
-
237
  $razorpayPaymentId = $data['payload']['payment']['entity']['id'];
238
 
239
  $payment = $this->getPaymentEntity($razorpayPaymentId, $data);
@@ -312,7 +309,7 @@ class RZP_Webhook
312
  rzpLogInfo("Woocommerce orderId: $orderId webhook process intitiated for COD method payment pending event");
313
 
314
  if(!empty($orderId))
315
- {
316
  $order = $this->checkIsObject($orderId);
317
  }
318
  //To give the priority to callback script to compleate the execution fist adding this locking.
@@ -337,12 +334,12 @@ class RZP_Webhook
337
 
338
  return;
339
  }
340
-
341
  if($orderStatus == 'draft')
342
  {
343
  updateOrderStatus($orderId, 'wc-pending');
344
  }
345
-
346
  $razorpayPaymentId = $data['payload']['payment']['entity']['id'];
347
 
348
  $payment = $this->getPaymentEntity($razorpayPaymentId, $data);
@@ -379,7 +376,7 @@ class RZP_Webhook
379
  $orderId = $data['payload']['payment']['entity']['notes']['woocommerce_order_number'];
380
 
381
  if(!empty($orderId))
382
- {
383
  $order = $this->checkIsObject($orderId);
384
  }
385
  // If it is already marked as paid, ignore the event
@@ -467,7 +464,7 @@ class RZP_Webhook
467
  {
468
  if ((isset($data['event']) === true) and
469
  (in_array($data['event'], $this->eventsArray) === true) and
470
- isset($data['payload']['payment']['entity']['notes']['woocommerce_order_number']) === true) {
471
  return true;
472
  }
473
 
@@ -518,10 +515,10 @@ class RZP_Webhook
518
  $orderId = $payment['notes']['woocommerce_order_number'];
519
 
520
  if(!empty($orderId))
521
- {
522
  $order = $this->checkIsObject($orderId);
523
  }
524
-
525
  // If it is already marked as unpaid, ignore the event
526
  if ($order->needs_payment() === true) {
527
  return;
76
  return;
77
  }
78
 
79
+
80
+
81
+ if (empty($data['event']) === false) {
 
82
  // Skip the webhook if not the valid data and event
83
  if ($this->shouldConsumeWebhook($data) === false) {
84
  return;
85
  }
 
86
  if (isset($_SERVER['HTTP_X_RAZORPAY_SIGNATURE']) === true) {
87
+ $razorpayWebhookSecret = get_option('rzp_webhook_secret');
 
88
  //
89
  // If the webhook secret isn't set on wordpress, return
90
  //
200
  rzpLogInfo("Woocommerce orderId: $orderId webhook process intitiated for payment authorized event");
201
 
202
  if(!empty($orderId))
203
+ {
204
  $order = $this->checkIsObject($orderId);
205
  }
206
  //To give the priority to callback script to compleate the execution fist adding this locking.
225
 
226
  return;
227
  }
228
+
229
  if($orderStatus == 'draft')
230
  {
231
  updateOrderStatus($orderId, 'wc-pending');
232
  }
233
+
234
  $razorpayPaymentId = $data['payload']['payment']['entity']['id'];
235
 
236
  $payment = $this->getPaymentEntity($razorpayPaymentId, $data);
309
  rzpLogInfo("Woocommerce orderId: $orderId webhook process intitiated for COD method payment pending event");
310
 
311
  if(!empty($orderId))
312
+ {
313
  $order = $this->checkIsObject($orderId);
314
  }
315
  //To give the priority to callback script to compleate the execution fist adding this locking.
334
 
335
  return;
336
  }
337
+
338
  if($orderStatus == 'draft')
339
  {
340
  updateOrderStatus($orderId, 'wc-pending');
341
  }
342
+
343
  $razorpayPaymentId = $data['payload']['payment']['entity']['id'];
344
 
345
  $payment = $this->getPaymentEntity($razorpayPaymentId, $data);
376
  $orderId = $data['payload']['payment']['entity']['notes']['woocommerce_order_number'];
377
 
378
  if(!empty($orderId))
379
+ {
380
  $order = $this->checkIsObject($orderId);
381
  }
382
  // If it is already marked as paid, ignore the event
464
  {
465
  if ((isset($data['event']) === true) and
466
  (in_array($data['event'], $this->eventsArray) === true) and
467
+ (isset($data['payload']['payment']['entity']['notes']['woocommerce_order_number']) === true or isset($data['payload']['subscription']['entity']['notes']['woocommerce_order_id']) === true)) {
468
  return true;
469
  }
470
 
515
  $orderId = $payment['notes']['woocommerce_order_number'];
516
 
517
  if(!empty($orderId))
518
+ {
519
  $order = $this->checkIsObject($orderId);
520
  }
521
+
522
  // If it is already marked as unpaid, ignore the event
523
  if ($order->needs_payment() === true) {
524
  return;
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: 5.9
6
- Stable tag: 3.7.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,10 @@ This is compatible with WooCommerce>=2.4, including the new 3.0 release. It has
41
 
42
  == Changelog ==
43
 
 
 
 
 
44
  = 3.7.0 =
45
  * Magic Checkout support for Klaviyo plugin.
46
  * Bug fix for warning message on place order and callback script.
3
  Tags: razorpay, payments, india, woocommerce, ecommerce
4
  Requires at least: 3.9.2
5
  Tested up to: 5.9
6
+ Stable tag: 3.7.1
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
+ = 3.7.1 =
45
+ * Bug fix for auto webhook.
46
+ * Added supported subscription webhook events
47
+
48
  = 3.7.0 =
49
  * Magic Checkout support for Klaviyo plugin.
50
  * Bug fix for warning message on place order and callback script.
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: 3.7.0
7
- * Stable tag: 3.7.0
8
  * Author: Team Razorpay
9
  * WC tested up to: 6.4.1
10
  * Author URI: https://razorpay.com
@@ -61,7 +61,10 @@ function woocommerce_razorpay_init()
61
  'payment.authorized',
62
  'payment.pending',
63
  'refund.created',
64
- 'virtual_account.credited'
 
 
 
65
  );
66
 
67
  protected $defaultWebhookEvents = array(
@@ -157,7 +160,7 @@ function woocommerce_razorpay_init()
157
  $this->icon = "https://cdn.razorpay.com/static/assets/logo/payment.svg";
158
  // 1cc flags should be enabled only if merchant has access to 1cc feature
159
  $is1ccAvailable = false;
160
-
161
  // Load preference API call only for administrative interface page.
162
  if (is_admin())
163
  {
@@ -297,7 +300,7 @@ function woocommerce_razorpay_init()
297
  }
298
 
299
  public function autoEnableWebhook()
300
- {
301
  $webhookExist = false;
302
  $webhookUrl = esc_url(admin_url('admin-post.php')) . '?action=rzp_wc_webhook';
303
 
@@ -306,7 +309,7 @@ function woocommerce_razorpay_init()
306
  $enabled = true;
307
  $alphanumericString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-=~!@#$%^&*()_+,./<>?;:[]{}|abcdefghijklmnopqrstuvwxyz';
308
  $secret = substr(str_shuffle($alphanumericString), 0, 20);
309
-
310
  $getWebhookFlag = get_option('webhook_enable_flag');
311
  $time = time();
312
 
@@ -331,14 +334,13 @@ function woocommerce_razorpay_init()
331
  return;
332
  }
333
 
334
-
335
  $domain = parse_url($webhookUrl, PHP_URL_HOST);
336
 
337
  $domain_ip = gethostbyname($domain);
338
 
339
  if (!filter_var($domain_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))
340
  {
341
- $this->update_option( 'enable_webhook', 'no' );
342
 
343
  ?>
344
  <div class="notice error is-dismissible" >
@@ -362,31 +364,31 @@ function woocommerce_razorpay_init()
362
  {
363
  $webhookItems[] = $value;
364
  }
365
- }
366
  } while ( $webhook['count'] >= 1);
367
-
368
  $data = [
369
  'url' => $webhookUrl,
370
  'active' => $enabled,
371
  'events' => $this->defaultWebhookEvents,
372
  'secret' => $secret,
373
  ];
374
-
375
  if (count($webhookItems) > 0)
376
- {
377
  foreach ($webhookItems as $key => $value)
378
  {
379
  if ($value['url'] === $webhookUrl)
380
- {
381
  foreach ($value['events'] as $evntkey => $evntval)
382
  {
383
- if (($evntval == 1) and
384
  (in_array($evntkey, $this->supportedWebhookEvents) === true))
385
  {
386
  $this->defaultWebhookEvents[$evntkey] = true;
387
  }
388
  }
389
-
390
  $data = [
391
  'url' => $webhookUrl,
392
  'active' => $enabled,
@@ -397,7 +399,7 @@ function woocommerce_razorpay_init()
397
  $webhookId = $value['id'];
398
  }
399
  }
400
- }
401
  if ($webhookExist)
402
  {
403
  $this->webhookAPI('PUT', "webhooks/".$webhookId, $data);
@@ -588,13 +590,18 @@ function woocommerce_razorpay_init()
588
  protected function getRazorpayPaymentParams($orderId)
589
  {
590
  $getWebhookFlag = get_option('webhook_enable_flag');
591
-
592
  if (!empty($getWebhookFlag))
593
  {
594
  if ($getWebhookFlag + 86400 < time())
595
  {
596
- $this->autoEnableWebhook();
597
  }
 
 
 
 
 
598
  }
599
  rzpLogInfo("getRazorpayPaymentParams $orderId");
600
  $razorpayOrderId = $this->createOrGetRazorpayOrderId($orderId);
@@ -1439,7 +1446,7 @@ EOT;
1439
 
1440
  if ($isStoreShippingEnabled == 'yes')
1441
  {
1442
- foreach ($shippingData as $key => $value)
1443
  {
1444
  $item = new WC_Order_Item_Shipping();
1445
  //$item->set_method_id($test[$key]['rate_id']);
@@ -1468,13 +1475,13 @@ EOT;
1468
  wc_update_order_item_meta( $itemId, $itemkey, $itemval);
1469
  }
1470
  }
1471
-
1472
  }
1473
  }
1474
  else
1475
  {
1476
  $item = new WC_Order_Item_Shipping();
1477
-
1478
  // if shipping charges zero
1479
  if ($razorpayData['shipping_fee'] == 0)
1480
  {
@@ -1490,12 +1497,12 @@ EOT;
1490
  $item->set_total( $razorpayData['shipping_fee']/100 );
1491
 
1492
  $order->add_item( $item );
1493
-
1494
  $item->save();
1495
  }
1496
  // Calculate totals and save
1497
  $order->calculate_totals();
1498
-
1499
  }
1500
  }
1501
 
@@ -1629,7 +1636,7 @@ EOT;
1629
  return $zone;
1630
  }
1631
 
1632
-
1633
 
1634
 
1635
  // Update user billing and shipping information
@@ -1659,7 +1666,7 @@ EOT;
1659
  if (isset($cut_off_time))
1660
  {
1661
  $cartCutOffTime = intval($cutOffTime) * 60;
1662
- }
1663
  else
1664
  {
1665
  $cartCutOffTime = 60 * 60;
@@ -1675,7 +1682,7 @@ EOT;
1675
  $userType = 'GUEST';
1676
  $userId = get_post_meta($wcOrderId, 'abandoned_user_id', true);
1677
  }
1678
-
1679
  $results = $wpdb->get_results( // phpcs:ignore
1680
  $wpdb->prepare(
1681
  'SELECT * FROM `' . $wpdb->prefix . 'ac_abandoned_cart_history_lite` WHERE user_id = %s AND cart_ignored = %s AND recovered_cart = %s AND user_type = %s',
@@ -1782,7 +1789,7 @@ EOT;
1782
  'SELECT * FROM `' . $wpdb->prefix . 'wcfm_marketplace_orders` WHERE vendor_id = %d AND order_id = %d',
1783
  $vendorId,
1784
  $orderId
1785
- )
1786
  );
1787
 
1788
  if (count($commission) > 0)
@@ -1925,7 +1932,7 @@ function addMiniCheckoutButton()
1925
  $tempTest = RZP_PATH . 'templates/rzp-mini-checkout-btn.php';
1926
  load_template( $tempTest, false, array() );
1927
  }
1928
-
1929
  }
1930
 
1931
  //To add 1CC button on product page.
3
  * Plugin Name: Razorpay for WooCommerce
4
  * Plugin URI: https://razorpay.com
5
  * Description: Razorpay Payment Gateway Integration for WooCommerce
6
+ * Version: 3.7.1
7
+ * Stable tag: 3.7.1
8
  * Author: Team Razorpay
9
  * WC tested up to: 6.4.1
10
  * Author URI: https://razorpay.com
61
  'payment.authorized',
62
  'payment.pending',
63
  'refund.created',
64
+ 'virtual_account.credited',
65
+ 'subscription.cancelled',
66
+ 'subscription.paused',
67
+ 'subscription.resumed'
68
  );
69
 
70
  protected $defaultWebhookEvents = array(
160
  $this->icon = "https://cdn.razorpay.com/static/assets/logo/payment.svg";
161
  // 1cc flags should be enabled only if merchant has access to 1cc feature
162
  $is1ccAvailable = false;
163
+
164
  // Load preference API call only for administrative interface page.
165
  if (is_admin())
166
  {
300
  }
301
 
302
  public function autoEnableWebhook()
303
+ {
304
  $webhookExist = false;
305
  $webhookUrl = esc_url(admin_url('admin-post.php')) . '?action=rzp_wc_webhook';
306
 
309
  $enabled = true;
310
  $alphanumericString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-=~!@#$%^&*()_+,./<>?;:[]{}|abcdefghijklmnopqrstuvwxyz';
311
  $secret = substr(str_shuffle($alphanumericString), 0, 20);
312
+ update_option('rzp_webhook_secret', $secret);
313
  $getWebhookFlag = get_option('webhook_enable_flag');
314
  $time = time();
315
 
334
  return;
335
  }
336
 
337
+
338
  $domain = parse_url($webhookUrl, PHP_URL_HOST);
339
 
340
  $domain_ip = gethostbyname($domain);
341
 
342
  if (!filter_var($domain_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))
343
  {
 
344
 
345
  ?>
346
  <div class="notice error is-dismissible" >
364
  {
365
  $webhookItems[] = $value;
366
  }
367
+ }
368
  } while ( $webhook['count'] >= 1);
369
+
370
  $data = [
371
  'url' => $webhookUrl,
372
  'active' => $enabled,
373
  'events' => $this->defaultWebhookEvents,
374
  'secret' => $secret,
375
  ];
376
+
377
  if (count($webhookItems) > 0)
378
+ {
379
  foreach ($webhookItems as $key => $value)
380
  {
381
  if ($value['url'] === $webhookUrl)
382
+ {
383
  foreach ($value['events'] as $evntkey => $evntval)
384
  {
385
+ if (($evntval == 1) and
386
  (in_array($evntkey, $this->supportedWebhookEvents) === true))
387
  {
388
  $this->defaultWebhookEvents[$evntkey] = true;
389
  }
390
  }
391
+
392
  $data = [
393
  'url' => $webhookUrl,
394
  'active' => $enabled,
399
  $webhookId = $value['id'];
400
  }
401
  }
402
+ }
403
  if ($webhookExist)
404
  {
405
  $this->webhookAPI('PUT', "webhooks/".$webhookId, $data);
590
  protected function getRazorpayPaymentParams($orderId)
591
  {
592
  $getWebhookFlag = get_option('webhook_enable_flag');
593
+ $time = time();
594
  if (!empty($getWebhookFlag))
595
  {
596
  if ($getWebhookFlag + 86400 < time())
597
  {
598
+ $this->autoEnableWebhook();
599
  }
600
+ }
601
+ else
602
+ {
603
+ update_option('webhook_enable_flag', $time);
604
+ $this->autoEnableWebhook();
605
  }
606
  rzpLogInfo("getRazorpayPaymentParams $orderId");
607
  $razorpayOrderId = $this->createOrGetRazorpayOrderId($orderId);
1446
 
1447
  if ($isStoreShippingEnabled == 'yes')
1448
  {
1449
+ foreach ($shippingData as $key => $value)
1450
  {
1451
  $item = new WC_Order_Item_Shipping();
1452
  //$item->set_method_id($test[$key]['rate_id']);
1475
  wc_update_order_item_meta( $itemId, $itemkey, $itemval);
1476
  }
1477
  }
1478
+
1479
  }
1480
  }
1481
  else
1482
  {
1483
  $item = new WC_Order_Item_Shipping();
1484
+
1485
  // if shipping charges zero
1486
  if ($razorpayData['shipping_fee'] == 0)
1487
  {
1497
  $item->set_total( $razorpayData['shipping_fee']/100 );
1498
 
1499
  $order->add_item( $item );
1500
+
1501
  $item->save();
1502
  }
1503
  // Calculate totals and save
1504
  $order->calculate_totals();
1505
+
1506
  }
1507
  }
1508
 
1636
  return $zone;
1637
  }
1638
 
1639
+
1640
 
1641
 
1642
  // Update user billing and shipping information
1666
  if (isset($cut_off_time))
1667
  {
1668
  $cartCutOffTime = intval($cutOffTime) * 60;
1669
+ }
1670
  else
1671
  {
1672
  $cartCutOffTime = 60 * 60;
1682
  $userType = 'GUEST';
1683
  $userId = get_post_meta($wcOrderId, 'abandoned_user_id', true);
1684
  }
1685
+
1686
  $results = $wpdb->get_results( // phpcs:ignore
1687
  $wpdb->prepare(
1688
  'SELECT * FROM `' . $wpdb->prefix . 'ac_abandoned_cart_history_lite` WHERE user_id = %s AND cart_ignored = %s AND recovered_cart = %s AND user_type = %s',
1789
  'SELECT * FROM `' . $wpdb->prefix . 'wcfm_marketplace_orders` WHERE vendor_id = %d AND order_id = %d',
1790
  $vendorId,
1791
  $orderId
1792
+ )
1793
  );
1794
 
1795
  if (count($commission) > 0)
1932
  $tempTest = RZP_PATH . 'templates/rzp-mini-checkout-btn.php';
1933
  load_template( $tempTest, false, array() );
1934
  }
1935
+
1936
  }
1937
 
1938
  //To add 1CC button on product page.