Razorpay for WooCommerce - Version 4.0.1

Version Description

  • Bug fix for uft8 characters.
Download this release

Release Info

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

Code changes from version 4.0.0 to 4.0.1

Files changed (3) hide show
  1. includes/plugin-instrumentation.php +83 -0
  2. readme.txt +4 -1
  3. woo-razorpay.php +227 -17
includes/plugin-instrumentation.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Razorpay\Api\Api;
4
+ use Razorpay\Api\Errors;
5
+
6
+ class TrackPluginInstrumentation
7
+ {
8
+ public $api;
9
+
10
+ public function __construct($key_id, $key_secret)
11
+ {
12
+ $this->api = new Api($key_id, $key_secret);
13
+ }
14
+
15
+ public function rzpTrackSegment($event, $properties)
16
+ {
17
+ try
18
+ {
19
+ if (empty($event) === true or
20
+ is_string($event) === false)
21
+ {
22
+ return ['status' => 'error', 'message' => 'event given as input is not valid'];
23
+ }
24
+
25
+ if (empty($properties) === true or
26
+ is_array($properties) === false)
27
+ {
28
+ return ['status' => 'error', 'message' => 'properties given as input is not valid'];
29
+ }
30
+
31
+ $data = [
32
+ 'event' => $event,
33
+ 'properties' => array_merge($properties, $this->getDefaultProperties())
34
+ ];
35
+
36
+ $response = $this->api->request->request('POST', 'plugins/segment', $data);
37
+
38
+ return $response;
39
+ }
40
+ catch (\Razorpay\Api\Errors\Error $e)
41
+ {
42
+ error_log($e->getMessage());
43
+ return ['status' => 'error'];
44
+ }
45
+ catch (\Exception $e)
46
+ {
47
+ error_log($e->getMessage());
48
+ return ['status' => 'error'];
49
+ }
50
+ }
51
+
52
+ public function rzpTrackDataLake($properties)
53
+ {
54
+ try
55
+ {
56
+
57
+ }
58
+ catch (\Razorpay\Api\Errors\Error $e)
59
+ {
60
+ error_log($e->getMessage());
61
+ }
62
+ catch (\Exception $e)
63
+ {
64
+ error_log($e->getMessage());
65
+ }
66
+ }
67
+
68
+ public function getDefaultProperties()
69
+ {
70
+ global $wp_version;
71
+ $pluginData = get_plugin_data(plugin_dir_path(__FILE__) . '/../woo-razorpay.php');
72
+
73
+ return [
74
+ 'platform' => 'WordPress',
75
+ 'platform_version' => $wp_version,
76
+ 'woocommerce_version' => WOOCOMMERCE_VERSION,
77
+ 'plugin_name' => $pluginData['Name'],
78
+ 'plugin_version' => $pluginData['Version'],
79
+ 'unique_id' => $_SERVER['HTTP_HOST'],
80
+ 'event_timestamp' => time(),
81
+ ];
82
+ }
83
+ }
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.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,9 @@ This is compatible with WooCommerce>=2.4, including the new 3.0 release. It has
41
 
42
  == Changelog ==
43
 
 
 
 
44
  = 4.0.0 =
45
  * Added support for CartBounty plugin in magic checkout.
46
  * Added debug log config on native checkout flow.
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
 
42
  == Changelog ==
43
 
44
+ = 4.0.1 =
45
+ * Bug fix for uft8 characters.
46
+
47
  = 4.0.0 =
48
  * Added support for CartBounty plugin in magic checkout.
49
  * Added debug log config on native checkout flow.
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.0
7
- * Stable tag: 4.0.0
8
  * Author: Team Razorpay
9
  * WC tested up to: 6.7.0
10
  * Author URI: https://razorpay.com
@@ -23,6 +23,7 @@ require_once __DIR__ .'/includes/razorpay-route-actions.php';
23
  require_once __DIR__.'/includes/api/api.php';
24
  require_once __DIR__.'/includes/utils.php';
25
  require_once __DIR__.'/includes/state-map.php';
 
26
  require_once __DIR__.'/includes/support/cartbounty.php';
27
 
28
  use Razorpay\Api\Api;
@@ -31,6 +32,11 @@ use Razorpay\Api\Errors;
31
  add_action('plugins_loaded', 'woocommerce_razorpay_init', 0);
32
  add_action('admin_post_nopriv_rzp_wc_webhook', 'razorpay_webhook_init', 10);
33
 
 
 
 
 
 
34
  function woocommerce_razorpay_init()
35
  {
36
  if (!class_exists('WC_Payment_Gateway'))
@@ -224,12 +230,14 @@ function woocommerce_razorpay_init()
224
 
225
  if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>='))
226
  {
 
227
  add_action("woocommerce_update_options_payment_gateways_{$this->id}", $cb);
228
  add_action( "woocommerce_update_options_payment_gateways_{$this->id}", array($this, 'autoEnableWebhook'));
229
  add_action( "woocommerce_update_options_payment_gateways_{$this->id}", array($this, 'addAdminCheckoutSettingsAlert'));
230
  }
231
  else
232
  {
 
233
  add_action('woocommerce_update_options_payment_gateways', $cb);
234
  add_action( "woocommerce_update_options_payment_gateways", array($this, 'autoEnableWebhook'));
235
  add_action( "woocommerce_update_options_payment_gateways", array($this, 'addAdminCheckoutSettingsAlert'));
@@ -338,7 +346,7 @@ function woocommerce_razorpay_init()
338
  </div>
339
  <?php
340
 
341
- error_log('Key Id and Key Secret are required.');
342
  return;
343
  }
344
 
@@ -356,7 +364,7 @@ function woocommerce_razorpay_init()
356
  </div>
357
  <?php
358
 
359
- error_log('Could not enable webhook for localhost');
360
  return;
361
  }
362
  $skip = 0;
@@ -374,7 +382,7 @@ function woocommerce_razorpay_init()
374
  }
375
  }
376
  } while ( $webhook['count'] === $count);
377
-
378
  $data = [
379
  'url' => $webhookUrl,
380
  'active' => $enabled,
@@ -396,7 +404,7 @@ function woocommerce_razorpay_init()
396
  $this->defaultWebhookEvents[$evntkey] = true;
397
  }
398
  }
399
-
400
  $data = [
401
  'url' => $webhookUrl,
402
  'active' => $enabled,
@@ -410,15 +418,126 @@ function woocommerce_razorpay_init()
410
  }
411
  if ($webhookExist)
412
  {
 
413
  $this->webhookAPI('PUT', "webhooks/".$webhookId, $data);
414
  }
415
  else
416
  {
 
417
  $this->webhookAPI('POST', "webhooks/", $data);
418
  }
419
 
420
  }
421
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
  public function generateSecret()
423
  {
424
  $alphanumericString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-=~!@#$%^&*()_+,./<>?;:[]{}|abcdefghijklmnopqrstuvwxyz';
@@ -426,6 +545,7 @@ function woocommerce_razorpay_init()
426
 
427
  return $secret;
428
  }
 
429
  // showing notice : status of 1cc active / inactive message in admin dashboard
430
  function addAdminCheckoutSettingsAlert() {
431
  $enable_1cc = $this->getSetting('enable_1cc');
@@ -466,6 +586,7 @@ function woocommerce_razorpay_init()
466
  );
467
 
468
  error_log(json_encode($log));
 
469
  }
470
 
471
  return $webhook;
@@ -604,7 +725,21 @@ function woocommerce_razorpay_init()
604
  */
605
  protected function getRazorpayPaymentParams($orderId)
606
  {
607
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
  rzpLogInfo("getRazorpayPaymentParams $orderId");
609
  $razorpayOrderId = $this->createOrGetRazorpayOrderId($orderId);
610
 
@@ -742,7 +877,7 @@ function woocommerce_razorpay_init()
742
  {
743
  rzpLogInfo("Called createRazorpayOrderId with params orderId $orderId and sessionKey $sessionKey");
744
 
745
-
746
  // Calls the helper function to create order data
747
  global $woocommerce;
748
 
@@ -773,7 +908,7 @@ function woocommerce_razorpay_init()
773
  else
774
  {
775
  update_option('webhook_enable_flag', $time);
776
- $this->autoEnableWebhook();
777
  }
778
 
779
  $razorpayOrderId = $razorpayOrder['id'];
@@ -894,8 +1029,8 @@ function woocommerce_razorpay_init()
894
  $data['line_items'][$i]['price'] = (empty($productDetails['price'])=== false) ? round(wc_get_price_excluding_tax($product)*100) + round($item->get_subtotal_tax()*100 / $item->get_quantity()) : 0;
895
  $data['line_items'][$i]['offer_price'] = (empty($productDetails['sale_price'])=== false) ? (int) $productDetails['sale_price']*100 : $productDetails['price']*100;
896
  $data['line_items'][$i]['quantity'] = (int)$item->get_quantity();
897
- $data['line_items'][$i]['name'] = substr($item->get_name(), 0, 125);
898
- $data['line_items'][$i]['description'] = substr($item->get_name(), 0, 250);
899
  $productImage = $product->get_image_id()?? null;
900
  $data['line_items'][$i]['image_url'] = $productImage? wp_get_attachment_url( $productImage ) : null;
901
  $data['line_items'][$i]['product_url'] = $product->get_permalink();
@@ -1081,7 +1216,7 @@ EOT;
1081
  rzpLogInfo("Set transient with key " . self::SESSION_KEY . " params order_id $order_id");
1082
 
1083
  $orderKey = $this->getOrderKey($order);
1084
-
1085
  if (version_compare(WOOCOMMERCE_VERSION, '2.1', '>='))
1086
  {
1087
  return array(
@@ -1130,13 +1265,13 @@ EOT;
1130
  rzpLogInfo("Called check_razorpay_response: $post_password");
1131
 
1132
  $meta_key = '_order_key';
1133
-
1134
  $postMetaData = $wpdb->get_row( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta AS P WHERE meta_key = %s AND meta_value = %s", $meta_key, $post_password ) );
1135
-
1136
  $postData = $wpdb->get_row( $wpdb->prepare("SELECT post_status FROM $wpdb->posts AS P WHERE post_type=%s and ID=%s", $post_type, $postMetaData->post_id) );
1137
-
1138
  $arrayPost = json_decode(json_encode($postMetaData), true);
1139
-
1140
  if (!empty($arrayPost) and
1141
  $arrayPost != null)
1142
  {
@@ -1391,7 +1526,7 @@ EOT;
1391
  {
1392
  $order->payment_complete($razorpayPaymentId);
1393
  }
1394
-
1395
  if(is_plugin_active('woo-save-abandoned-carts/cartbounty-abandoned-carts.php')){
1396
  handleCBRecoveredOrder($orderId);
1397
  }
@@ -2085,6 +2220,81 @@ if(is1ccEnabled())
2085
  add_filter('woocommerce_order_needs_shipping_address', '__return_true');
2086
  }
2087
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2088
  //Changes Recovery link URL to Magic cart URL to avoid redirection to checkout page
2089
  function cartbounty_alter_automation_button( $button ){
2090
  return str_replace("cartbounty=","cartbounty=magic_",$button);
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
23
  require_once __DIR__.'/includes/api/api.php';
24
  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
 
29
  use Razorpay\Api\Api;
32
  add_action('plugins_loaded', 'woocommerce_razorpay_init', 0);
33
  add_action('admin_post_nopriv_rzp_wc_webhook', 'razorpay_webhook_init', 10);
34
 
35
+ // instrumentation hooks
36
+ add_action('activated_plugin', 'razorpayPluginActivated', 10, 2 );
37
+ add_action('deactivated_plugin', 'razorpayPluginDeactivated', 10, 2 );
38
+ add_action('upgrader_process_complete', 'razorpayPluginUpgraded', 10, 2);
39
+
40
  function woocommerce_razorpay_init()
41
  {
42
  if (!class_exists('WC_Payment_Gateway'))
230
 
231
  if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>='))
232
  {
233
+ add_action( "woocommerce_update_options_payment_gateways_{$this->id}", array($this, 'pluginInstrumentation'));
234
  add_action("woocommerce_update_options_payment_gateways_{$this->id}", $cb);
235
  add_action( "woocommerce_update_options_payment_gateways_{$this->id}", array($this, 'autoEnableWebhook'));
236
  add_action( "woocommerce_update_options_payment_gateways_{$this->id}", array($this, 'addAdminCheckoutSettingsAlert'));
237
  }
238
  else
239
  {
240
+ add_action( "woocommerce_update_options_payment_gateways", array($this, 'pluginInstrumentation'));
241
  add_action('woocommerce_update_options_payment_gateways', $cb);
242
  add_action( "woocommerce_update_options_payment_gateways", array($this, 'autoEnableWebhook'));
243
  add_action( "woocommerce_update_options_payment_gateways", array($this, 'addAdminCheckoutSettingsAlert'));
346
  </div>
347
  <?php
348
 
349
+ rzpLogError('Key Id and Key Secret are required.');
350
  return;
351
  }
352
 
364
  </div>
365
  <?php
366
 
367
+ rzpLogError('Could not enable webhook for localhost');
368
  return;
369
  }
370
  $skip = 0;
382
  }
383
  }
384
  } while ( $webhook['count'] === $count);
385
+
386
  $data = [
387
  'url' => $webhookUrl,
388
  'active' => $enabled,
404
  $this->defaultWebhookEvents[$evntkey] = true;
405
  }
406
  }
407
+
408
  $data = [
409
  'url' => $webhookUrl,
410
  'active' => $enabled,
418
  }
419
  if ($webhookExist)
420
  {
421
+ rzpLogInfo('Updating razorpay webhook');
422
  $this->webhookAPI('PUT', "webhooks/".$webhookId, $data);
423
  }
424
  else
425
  {
426
+ rzpLogInfo('Creating razorpay webhook');
427
  $this->webhookAPI('POST', "webhooks/", $data);
428
  }
429
 
430
  }
431
 
432
+ public function pluginInstrumentation()
433
+ {
434
+ if (empty($_POST['woocommerce_razorpay_key_id']) or
435
+ empty($_POST['woocommerce_razorpay_key_secret']))
436
+ {
437
+ error_log('Key Id and Key Secret are required.');
438
+ return;
439
+ }
440
+
441
+ $trackObject = new TrackPluginInstrumentation($_POST['woocommerce_razorpay_key_id'], $_POST['woocommerce_razorpay_key_secret']);
442
+
443
+ $existingVersion = get_option('rzp_woocommerce_current_version');
444
+
445
+ if(isset($existingVersion))
446
+ {
447
+ update_option('rzp_woocommerce_current_version', get_plugin_data(__FILE__)['Version']);
448
+ }
449
+ else
450
+ {
451
+ add_option('rzp_woocommerce_current_version', get_plugin_data(__FILE__)['Version']);
452
+ }
453
+
454
+ try
455
+ {
456
+ global $wpdb;
457
+ $isTransactingUser = false;
458
+
459
+ $rzpTrancationData = $wpdb->get_row($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta AS P WHERE meta_key = %s AND meta_value = %s", "_payment_method", "razorpay"));
460
+
461
+ $arrayPost = json_decode(json_encode($rzpTrancationData), true);
462
+
463
+ if (empty($arrayPost) === false and
464
+ ($arrayPost == null) === false)
465
+ {
466
+ $isTransactingUser = true;
467
+ }
468
+ }
469
+ catch (\Razorpay\Api\Errors\Error $e)
470
+ {
471
+ ?>
472
+ <div class="notice error is-dismissible" >
473
+ <p><b><?php _e( 'Please check Key Id and Key Secret.'); ?></b></p>
474
+ </div>
475
+ <?php
476
+ error_log('Please check Key Id and Key Secret.');
477
+ return;
478
+ }
479
+ catch (\Exception $e)
480
+ {
481
+ ?>
482
+ <div class="notice error is-dismissible" >
483
+ <p><b><?php _e( 'something went wrong'); ?></b></p>
484
+ </div>
485
+ <?php
486
+ error_log($e->getMessage());
487
+ return;
488
+ }
489
+
490
+ $authEvent = '';
491
+ $pluginStatusEvent = '';
492
+
493
+ $authProperties = [
494
+ 'is_key_id_populated' => true,
495
+ 'is_key_secret_populated' => true,
496
+ 'page_url' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
497
+ 'auth_successful_status' => true,
498
+ 'is_plugin_activated' => (isset($_POST['woocommerce_razorpay_enabled'])) ? true :false
499
+ ];
500
+
501
+ // for enable and disable plugin
502
+ $pluginStatusProperties = [
503
+ 'current_status' => ($this->getSetting('enabled')==='yes') ? 'enabled' :'disabled',
504
+ 'is_transacting_user' => $isTransactingUser
505
+ ];
506
+
507
+ if (empty($this->getSetting('key_id')) and
508
+ empty($this->getSetting('key_secret')))
509
+ {
510
+ $authEvent = 'saving auth details';
511
+
512
+ if(empty($_POST['woocommerce_razorpay_enabled']) === false)
513
+ {
514
+ $pluginStatusEvent = 'plugin enabled';
515
+ }
516
+ }
517
+ else
518
+ {
519
+ $authEvent = 'updating auth details';
520
+ }
521
+
522
+ $response = $trackObject->rzpTrackSegment($authEvent, $authProperties);
523
+
524
+ if ((empty($_POST['woocommerce_razorpay_enabled']) === false) and
525
+ ($this->getSetting('enabled') === 'no'))
526
+ {
527
+ $pluginStatusEvent = 'plugin enabled';
528
+ }
529
+ elseif ((empty($_POST['woocommerce_razorpay_enabled']) === true) and
530
+ ($this->getSetting('enabled') === 'yes'))
531
+ {
532
+ $pluginStatusEvent = 'plugin disabled';
533
+ }
534
+
535
+ if ($pluginStatusEvent !== '')
536
+ {
537
+ $response = $trackObject->rzpTrackSegment($pluginStatusEvent, $pluginStatusProperties);
538
+ }
539
+ }
540
+
541
  public function generateSecret()
542
  {
543
  $alphanumericString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-=~!@#$%^&*()_+,./<>?;:[]{}|abcdefghijklmnopqrstuvwxyz';
545
 
546
  return $secret;
547
  }
548
+
549
  // showing notice : status of 1cc active / inactive message in admin dashboard
550
  function addAdminCheckoutSettingsAlert() {
551
  $enable_1cc = $this->getSetting('enable_1cc');
586
  );
587
 
588
  error_log(json_encode($log));
589
+ rzpLogError(json_encode($log));
590
  }
591
 
592
  return $webhook;
725
  */
726
  protected function getRazorpayPaymentParams($orderId)
727
  {
728
+ $getWebhookFlag = get_option('webhook_enable_flag');
729
+ $time = time();
730
+ if (empty($getWebhookFlag) == false)
731
+ {
732
+ if ($getWebhookFlag + 86400 < time())
733
+ {
734
+ $this->autoEnableWebhook();
735
+ }
736
+ }
737
+ else
738
+ {
739
+ update_option('webhook_enable_flag', $time);
740
+ $this->autoEnableWebhook();
741
+ }
742
+
743
  rzpLogInfo("getRazorpayPaymentParams $orderId");
744
  $razorpayOrderId = $this->createOrGetRazorpayOrderId($orderId);
745
 
877
  {
878
  rzpLogInfo("Called createRazorpayOrderId with params orderId $orderId and sessionKey $sessionKey");
879
 
880
+
881
  // Calls the helper function to create order data
882
  global $woocommerce;
883
 
908
  else
909
  {
910
  update_option('webhook_enable_flag', $time);
911
+ $this->autoEnableWebhook();
912
  }
913
 
914
  $razorpayOrderId = $razorpayOrder['id'];
1029
  $data['line_items'][$i]['price'] = (empty($productDetails['price'])=== false) ? round(wc_get_price_excluding_tax($product)*100) + round($item->get_subtotal_tax()*100 / $item->get_quantity()) : 0;
1030
  $data['line_items'][$i]['offer_price'] = (empty($productDetails['sale_price'])=== false) ? (int) $productDetails['sale_price']*100 : $productDetails['price']*100;
1031
  $data['line_items'][$i]['quantity'] = (int)$item->get_quantity();
1032
+ $data['line_items'][$i]['name'] = mb_substr($item->get_name(), 0, 125, "UTF-8");
1033
+ $data['line_items'][$i]['description'] = mb_substr($item->get_name(), 0, 250,"UTF-8");
1034
  $productImage = $product->get_image_id()?? null;
1035
  $data['line_items'][$i]['image_url'] = $productImage? wp_get_attachment_url( $productImage ) : null;
1036
  $data['line_items'][$i]['product_url'] = $product->get_permalink();
1216
  rzpLogInfo("Set transient with key " . self::SESSION_KEY . " params order_id $order_id");
1217
 
1218
  $orderKey = $this->getOrderKey($order);
1219
+
1220
  if (version_compare(WOOCOMMERCE_VERSION, '2.1', '>='))
1221
  {
1222
  return array(
1265
  rzpLogInfo("Called check_razorpay_response: $post_password");
1266
 
1267
  $meta_key = '_order_key';
1268
+
1269
  $postMetaData = $wpdb->get_row( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta AS P WHERE meta_key = %s AND meta_value = %s", $meta_key, $post_password ) );
1270
+
1271
  $postData = $wpdb->get_row( $wpdb->prepare("SELECT post_status FROM $wpdb->posts AS P WHERE post_type=%s and ID=%s", $post_type, $postMetaData->post_id) );
1272
+
1273
  $arrayPost = json_decode(json_encode($postMetaData), true);
1274
+
1275
  if (!empty($arrayPost) and
1276
  $arrayPost != null)
1277
  {
1526
  {
1527
  $order->payment_complete($razorpayPaymentId);
1528
  }
1529
+
1530
  if(is_plugin_active('woo-save-abandoned-carts/cartbounty-abandoned-carts.php')){
1531
  handleCBRecoveredOrder($orderId);
1532
  }
2220
  add_filter('woocommerce_order_needs_shipping_address', '__return_true');
2221
  }
2222
 
2223
+ // instrumentation
2224
+
2225
+ // plugin activation hook
2226
+ function razorpayPluginActivated()
2227
+ {
2228
+ $paymentSettings = get_option('woocommerce_razorpay_settings');
2229
+
2230
+ $trackObject = new TrackPluginInstrumentation($paymentSettings['key_id'], $paymentSettings['key_secret']);
2231
+
2232
+ $activateProperties = [
2233
+ 'page_url' => $_SERVER['HTTP_REFERER'],
2234
+ 'redirect_to_page' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']
2235
+ ];
2236
+
2237
+ $response = $trackObject->rzpTrackSegment('plugin activate', $activateProperties);
2238
+ }
2239
+
2240
+ // plugin deactivation hook
2241
+ function razorpayPluginDeactivated()
2242
+ {
2243
+ global $wpdb;
2244
+ $isTransactingUser = false;
2245
+
2246
+ $paymentSettings = get_option('woocommerce_razorpay_settings');
2247
+
2248
+ $trackObject = new TrackPluginInstrumentation($paymentSettings['key_id'], $paymentSettings['key_secret']);
2249
+
2250
+ $rzpTrancationData = $wpdb->get_row($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta AS P WHERE meta_key = %s AND meta_value = %s", "_payment_method", "razorpay"));
2251
+
2252
+ $arrayPost = json_decode(json_encode($rzpTrancationData), true);
2253
+
2254
+ if (empty($arrayPost) === false and
2255
+ ($arrayPost == null) === false)
2256
+ {
2257
+ $isTransactingUser = true;
2258
+ }
2259
+
2260
+ $deactivateProperties = [
2261
+ 'page_url' => $_SERVER['HTTP_REFERER'],
2262
+ 'is_transacting_user' => $isTransactingUser
2263
+ ];
2264
+
2265
+ $response = $trackObject->rzpTrackSegment('plugin deactivate', $deactivateProperties);
2266
+ }
2267
+
2268
+ // plugin upgrade hook
2269
+ function razorpayPluginUpgraded()
2270
+ {
2271
+ $paymentSettings = get_option('woocommerce_razorpay_settings');
2272
+
2273
+ $trackObject = new TrackPluginInstrumentation($paymentSettings['key_id'], $paymentSettings['key_secret']);
2274
+
2275
+ $upgradeProperties = [
2276
+ 'page_url' => $_SERVER['HTTP_REFERER'],
2277
+ 'prev_version' => get_option('rzp_woocommerce_current_version'),
2278
+ 'new_version' => get_plugin_data(__FILE__)['Version'],
2279
+ ];
2280
+
2281
+ $response = $trackObject->rzpTrackSegment('plugin upgrade', $upgradeProperties);
2282
+
2283
+ if ($response['status'] === 'success')
2284
+ {
2285
+ $existingVersion = get_option('rzp_woocommerce_current_version');
2286
+
2287
+ if(isset($existingVersion))
2288
+ {
2289
+ update_option('rzp_woocommerce_current_version', get_plugin_data(__FILE__)['Version']);
2290
+ }
2291
+ else
2292
+ {
2293
+ add_option('rzp_woocommerce_current_version', get_plugin_data(__FILE__)['Version']);
2294
+ }
2295
+ }
2296
+ }
2297
+
2298
  //Changes Recovery link URL to Magic cart URL to avoid redirection to checkout page
2299
  function cartbounty_alter_automation_button( $button ){
2300
  return str_replace("cartbounty=","cartbounty=magic_",$button);