Skip to content

Commit

Permalink
Merge pull request #491 from razorpay/hpos-fix
Browse files Browse the repository at this point in the history
instrument fix
  • Loading branch information
poojarazor authored Aug 3, 2023
2 parents 5ddf933 + 010ff12 commit b1d4ce8
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions includes/plugin-instrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,12 @@ class TrackPluginInstrumentation
{
protected $api;
protected $mode;
protected $isHposEnabled;

public function __construct($api, $key_id)
{
$this->api = $api;
$this->mode = (substr($key_id, 0, 8) === 'rzp_live') ? 'live' : 'test';

$this->isHposEnabled = false;

if (class_exists('Automattic\WooCommerce\Utilities\OrderUtil') and
OrderUtil::custom_orders_table_usage_is_enabled())
{
$this->isHposEnabled = true;
}

register_activation_hook(PLUGIN_MAIN_FILE, [$this, 'razorpayPluginActivated'], 10, 2);
register_deactivation_hook(PLUGIN_MAIN_FILE, [$this, 'razorpayPluginDeactivated'], 10, 2);
add_action('upgrader_process_complete', [$this, 'razorpayPluginUpgraded'], 10, 2);
Expand All @@ -48,7 +39,7 @@ function razorpayPluginActivated()

function hposInstrumentation()
{
if ($this->isHposEnabled and
if (class_exists('Automattic\WooCommerce\Utilities\OrderUtil') && OrderUtil::custom_orders_table_usage_is_enabled() and
(empty(get_option('rzp_hpos')) or
get_option('rzp_hpos') === 'no'))
{
Expand All @@ -61,7 +52,7 @@ function hposInstrumentation()

update_option('rzp_hpos', 'yes');
}
else if($this->isHposEnabled === false and
else if(class_exists('Automattic\WooCommerce\Utilities\OrderUtil') && OrderUtil::custom_orders_table_usage_is_enabled() === false and
get_option('rzp_hpos') === 'yes')
{
$properties = [
Expand Down Expand Up @@ -89,7 +80,7 @@ function razorpayPluginDeactivated()

$orderTable = $wpdb->prefix . 'wc_orders';

if ($this->isHposEnabled)
if(class_exists('Automattic\WooCommerce\Utilities\OrderUtil') && OrderUtil::custom_orders_table_usage_is_enabled())
{
$rzpTrancationData = $wpdb->get_row($wpdb->prepare("SELECT id FROM $orderTable AS P WHERE payment_method = %s", "razorpay"));
}
Expand Down Expand Up @@ -326,4 +317,4 @@ function rzpInstrumentation()

wp_die();
}
add_action("wp_ajax_rzpInstrumentation", "rzpInstrumentation");
add_action("wp_ajax_rzpInstrumentation", "rzpInstrumentation");

0 comments on commit b1d4ce8

Please sign in to comment.