From e42ad04fb54d701d2f1a56fd61adbe16e3336761 Mon Sep 17 00:00:00 2001 From: Razorpay Date: Fri, 6 Dec 2024 17:41:16 +0530 Subject: [PATCH 1/9] PLUG-2874 woocommerce checkout 360 --- woo-razorpay.php | 412 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 381 insertions(+), 31 deletions(-) diff --git a/woo-razorpay.php b/woo-razorpay.php index fe1e36db..74a33d44 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -248,6 +248,166 @@ public function getCustomOrdercreationMessage($thank_you_title, $order) return $message; } + public function generate_multicheckbox_html($key, $data) + { + $c360FieldMapping = [ + 'enable_magic_checkout_cart_page' => 'enable_1cc', + 'enable_magic_checkout_test_mode' => 'enable_1cc_test_mode', + 'enable_magic_checkout_buy_now' => 'enable_1cc_pdp_checkout', + 'enable_magic_checkout_mini_cart' => 'enable_1cc_mini_cart_checkout', + 'enable_cod_intelligence' => 'rzp_cod_intelligence_enable', + 'enable_razorpay_trusted_business_widget' => 'rzp_rtb_enable', + 'enable_razorpay_affordability_widget' => 'rzp_afd_enable' + ]; + + $field = $this->get_field_key($key); + + $defaults = array( + 'title' => '', + 'type' => 'multicheckbox', + 'description' => '', + 'desc_tip' => false, + 'options' => array(), + ); + + $data = wp_parse_args( $data, $defaults ); + + ob_start(); + ?> + + + + + +
+ $optionLabelDesc) : ?> + plugin_id . $this->id . '_' . 'enable_magic_checkout_group') + { + $option_checked = $this->getSetting($c360FieldMapping[$optionKey]); + } + elseif (isset($c360FieldMapping[$optionKey])) + { + $option_checked = get_option($c360FieldMapping[$optionKey]); + } + ?> +
+

+ +
+ + + 'enable_1cc', + 'enable_magic_checkout_test_mode' => 'enable_1cc_test_mode', + 'enable_magic_checkout_buy_now' => 'enable_1cc_pdp_checkout', + 'enable_magic_checkout_mini_cart' => 'enable_1cc_mini_cart_checkout' + ]; + + foreach ($magicC360Mapping as $c360Field => $oneCCField) + { + if (isset($data[$this->plugin_id . $this->id . '_' . $c360Field]) === true) + { + $savedData[$oneCCField] = "yes"; + } + elseif (isset($data[$this->plugin_id . $this->id . '_' . $oneCCField]) === false) + { + $savedData[$oneCCField] = "no"; + } + } + + // For other checkout360 settings + $checkout360Settings = [ + 'enable_cod_intelligence' => 'rzp_cod_intelligence_enable', + 'enable_razorpay_trusted_business_widget' => 'rzp_rtb_enable', + 'enable_razorpay_affordability_widget' => 'rzp_afd_enable' + ]; + + foreach ($checkout360Settings as $c360Field => $c360Flag) + { + if ($c360Field === 'enable_razorpay_trusted_business_widget' and + isset($data[$this->plugin_id . $this->id . '_' . $c360Field]) === true) + { + $data = [ + "rtb_widget_enabled" => true, + ]; + $rtbEnable = $this->rzpPostInstallationCall('save', $data); + + if (isset($rtbEnable['rtb_eligibility']) === false) + { + update_option($c360Flag, "yes"); + } + else + { + echo "
+

We are sorry you are not Eligible to opt RTB.

+
"; + update_option($c360Flag, "no"); + } + } + elseif (isset($data[$this->plugin_id . $this->id . '_' . $c360Field]) === true) + { + update_option($c360Flag, "yes"); + } + elseif (isset($data[$this->plugin_id . $this->id . '_' . $c360Field]) === false) + { + update_option($c360Flag, "no"); + } + } + + return update_option($optionKey, apply_filters('woocommerce_settings_api_sanitized_fields_' . $this->id, $savedData), 'yes'); + } + + return $saved; + } + + public function rzpPostInstallationCall($event, $data = []) + { + try + { + $api = $this->getRazorpayApiInstance(); + $key_id = $this->getSetting('key_id'); + + $postInstallationPayload = [ + "event" => $event, + "mode" => (substr($key_id, 0, 8) === 'rzp_live') ? 'live' : 'test', + "data" => $data + ]; + + $result = $api->request->request('POST', 'app/woocommerce/api/woocommerce-post-installation', $postInstallationPayload); + + return $result; + } + catch (\Exception $e) + { + rzpLogError($e->getMessage()); + + return ['checkout360_status' => 'no']; + } + } + /** * @param boolean $hooks Whether or not to * setup the hooks on @@ -255,7 +415,6 @@ public function getCustomOrdercreationMessage($thank_you_title, $order) */ public function __construct($hooks = true) { - $this->isHposEnabled = false; // file added in woocommerce v7.1.0, maybe removed later @@ -270,6 +429,7 @@ public function __construct($hooks = true) $is1ccAvailable = false; $isAccCreationAvailable = false; $merchantPreferences = []; + $checkout360Available = get_option('rzp_checkout360_status'); $merchantPreferences = get_transient(self::ONE_CC_MERCHANT_PREF); @@ -303,6 +463,12 @@ public function __construct($hooks = true) $isAccCreationAvailable = true; } + if (empty($checkout360Available) === true) + { + $response = $this->rzpPostInstallationCall('install'); + $checkout360Available = ($response['checkout360_status'] === true) ? 'yes' : 'no'; + update_option('rzp_checkout360_status', $checkout360Available); + } if ($is1ccAvailable) { $this->visibleSettings = array_merge($this->visibleSettings, array( @@ -324,6 +490,31 @@ public function __construct($hooks = true) )); } + if ($checkout360Available === "yes") + { + //remove 1cc fields + $magicSettingsToRemove = [ + 'enable_1cc', + 'enable_1cc_test_mode', + 'enable_1cc_pdp_checkout', + 'enable_1cc_mini_cart_checkout', + '1cc_min_cart_amount', + '1cc_min_COD_slab_amount', + '1cc_max_COD_slab_amount', + ]; + $this->visibleSettings = array_diff($this->visibleSettings, $magicSettingsToRemove); + + //add checkout 360 fields + $checkout360VisibleFields = [ + 'checkout360_header', + 'checkout360_subheader', + 'configure_checkout360', + 'enable_magic_checkout_group', + 'enable_cod_configurations_group', + 'enhance_your_checkout_group', + ]; + $this->visibleSettings = array_merge($this->visibleSettings, $checkout360VisibleFields); + } } $this->init_form_fields(); @@ -431,6 +622,80 @@ public function init_form_fields() ), ); + $checkout360Settings = array( + 'checkout360_header' => array( + 'title' => __('Upgrade to Razorpay Checkout360'), + 'type' => 'title', + ), + 'checkout360_subheader' => array( + 'title' => '

' . __('Advanced COD | Address Pre-Fills | Smart Coupons | COD Intelligence | Trust and Affordability').'

', + 'type' => 'title', + ), + 'configure_checkout360' => array( + 'title' => '' . __('Configure Checkout360 Settings').'', + 'type' => 'title', + ), + 'enable_magic_checkout_group' => array( + 'title' => __('Enable Magic Checkout'), + 'type' => 'multicheckbox', + 'label' => __('Enable Magic Checkout', $this->id), + 'options' => array( + 'enable_magic_checkout_cart_page' => array( + 'label' => __('Enable Magic Checkout', $this->id), + 'description' => __('Magic Checkout will launch when customer checkout with their cart', $this->id) + ), + 'enable_magic_checkout_buy_now' => array( + 'label' => __('Enable Magic Checkout On Buy Now Button', $this->id), + 'description' => __('Magic Checkout will launch when customer clicks on Buy Now on products page', $this->id) + ), + 'enable_magic_checkout_mini_cart' => array( + 'label' => __('Enable Magic Checkout On Mini Cart', $this->id), + 'description' => __('Magic Checkout will launch when checkout from mini cart', $this->id) + ), + 'enable_magic_checkout_test_mode' => array( + 'label' => __('Enable Magic Checkout On Test Mode', $this->id), + 'description' => __('Only logged in admin users will see Magic Checkout', $this->id) + ) + ) + ), + 'enable_cod_configurations_group' => array( + 'title' => __('Enable COD Intelligence'), + 'type' => 'multicheckbox', + 'options' => array( + 'enable_cod_intelligence' => array( + 'label' => __('Enable COD Intelligence', $this->id), + 'description' => __('Set up rules on Razorpay Dashboard to show/hide and charge for COD orders', $this->id) + ), + 'enable_cod_configuratiopn' => array( + 'label' => __('Set-up smart COD rules & RTO Prediction here', $this->id), + 'description' => __("Use Razorpay's RTO intelligence to block COD for high risk users", $this->id), + 'link' => 'http://dashboard.razorpay.com/magic' + ) + ) + ), + 'enhance_your_checkout_group' => array( + 'title' => __('Enhance Your Checkout'), + 'type' => 'multicheckbox', + 'options' => array( + 'enable_razorpay_trusted_business_widget' => array( + 'label' => __('Enable Razorpay Trusted Business Widget', $this->id), + 'description' => __('', $this->id) + ), + 'enable_razorpay_affordability_widget' => array( + 'label' => __('Enable Razorpay Affordability Widget', $this->id), + 'description' => __('', $this->id) + ), + 'enable_giftcards_coupons' => array( + 'label' => __('Set-up gift cards and coupons here', $this->id), + 'description' => __("", $this->id), + 'link' => 'http://dashboard.razorpay.com/magic' + ) + ) + ) + ); + + $defaultFormFields = array_merge( $defaultFormFields, $checkout360Settings ); + do_action_ref_array( 'setup_extra_setting_fields', array( &$defaultFormFields ) ); foreach ($defaultFormFields as $key => $value) @@ -446,6 +711,8 @@ public function init_form_fields() { try { + $checkout360status = (get_option('rzp_checkout360_status') === 'yes') ? true : false; + if (isset($_POST['woocommerce_razorpay_key_id']) and empty($_POST['woocommerce_razorpay_key_id']) === false and isset($_POST['woocommerce_razorpay_key_secret']) and @@ -467,8 +734,11 @@ public function init_form_fields() throw new Exception("Error in Api call."); } - update_option('rzp_afd_enable', 'no'); - update_option('rzp_rtb_enable', 'no'); + if ($checkout360status === false) + { + update_option('rzp_afd_enable', 'no'); + update_option('rzp_rtb_enable', 'no'); + } foreach ($merchantPreferences['assigned_features'] as $preference) { @@ -478,33 +748,39 @@ public function init_form_fields() add_action('woocommerce_sections_checkout', 'addSubSection'); add_action('woocommerce_settings_tabs_checkout', 'displayAffordabilityWidgetSettings'); add_action('woocommerce_update_options_checkout', 'updateAffordabilityWidgetSettings'); - update_option('rzp_afd_enable', 'yes'); + if ($checkout360status === false) + { + update_option('rzp_afd_enable', 'yes'); + } break; } } - $rtbActivationStatus = $api->request->request('GET', 'rtb?key_id=' . $key_id); - - if (isset($rtbActivationStatus['widget_enabled']) and - $rtbActivationStatus['widget_enabled'] === true) + if ($checkout360status === false) { - $this->form_fields['rtb_widget_title'] = array( - 'title' => '' . __('Razorpay Trusted Business'). '', - 'type' => 'title' - ); - - $this->form_fields['enable_rtb_widget'] = array( - 'title' => __('RTB Widget Enable/Disable'), - 'type' => 'checkbox', - 'desc' => __('Enable RTB Widget?'), - 'default' => 'no', - 'id' => 'rzp_rtb_enable' - ); - update_option('rzp_rtb_enable', 'yes'); - } + $rtbActivationStatus = $api->request->request('GET', 'rtb?key_id=' . $key_id); - update_option('rzp_afd_feature_checked', 'yes'); - update_option('rzp_rtb_feature_checked', 'yes'); + if (isset($rtbActivationStatus['widget_enabled']) and + $rtbActivationStatus['widget_enabled'] === true) + { + $this->form_fields['rtb_widget_title'] = array( + 'title' => '' . __('Razorpay Trusted Business'). '', + 'type' => 'title' + ); + + $this->form_fields['enable_rtb_widget'] = array( + 'title' => __('RTB Widget Enable/Disable'), + 'type' => 'checkbox', + 'desc' => __('Enable RTB Widget?'), + 'default' => 'no', + 'id' => 'rzp_rtb_enable' + ); + update_option('rzp_rtb_enable', 'yes'); + } + + update_option('rzp_afd_feature_checked', 'yes'); + update_option('rzp_rtb_feature_checked', 'yes'); + } } catch (\Exception $e) { @@ -535,6 +811,43 @@ protected function triggerValidationInstrumentation($data) $trackObject->rzpTrackDataLake('formfield.validation.error', $properties); } + public function autoPostInstallationCheck() + { + $response = $this->rzpPostInstallationCall('evaluate'); + + $checkout360Available = ($response['checkout360_status'] === true) ? 'yes' : 'no'; + + update_option('rzp_checkout360_status', $checkout360Available); + + // remove all checkou360 settings + if ($response['merchant_status'] === 'existing_checkout360_merchant' and + $checkout360Available === 'no') + { + $checkout360Fields = [ + 'enable_1cc', + 'enable_1cc_test_mode', + 'enable_1cc_pdp_checkout', + 'enable_1cc_mini_cart_checkout', + 'rzp_cod_intelligence_enable' + ]; + $optionKey = parent::get_option_key(); + $savedData = get_option($optionKey); + + foreach ($checkout360Fields as $field) + { + if ($field === 'rzp_cod_intelligence_enable')) + { + delete_option($field); + } + else + { + $savedData[$field] = 'no'; + } + } + update_option($optionKey, apply_filters('woocommerce_settings_api_sanitized_fields_' . $this->id, $savedData), 'yes'); + } + } + public function autoEnableWebhook() { $webhookExist = false; @@ -1152,6 +1465,12 @@ public function getDefaultCheckoutArguments($order) $productinfo = "Order $orderId"; + $hidePaymentMethods = []; + if (get_option('enable_cod_intelligence') === 'yes') + { + $hidePaymentMethods['method'] = "cod"; + } + return array( 'key' => $this->getSetting('key_id'), 'name' => html_entity_decode(get_bloginfo('name'), ENT_QUOTES), @@ -1163,7 +1482,14 @@ public function getDefaultCheckoutArguments($order) ), 'order_id' => $razorpayOrderId, 'callback_url' => $callbackUrl, - 'prefill' => $this->getCustomerInfo($order) + 'prefill' => $this->getCustomerInfo($order), + 'config'=> [ + 'display'=> [ + 'hide'=> [ + $hidePaymentMethods + ] + ] + ] ); } @@ -1270,6 +1596,21 @@ protected function createRazorpayOrderId($orderId, $sessionKey) $this->autoEnableWebhook(); } + // Every hour post installation check + $getPostInstallationFlag = get_option('rzp_post_installation_update_at'); + if (empty($getPostInstallationFlag) == false) + { + if ($getPostInstallationFlag + 3600 < time()) + { + $this->autoPostInstallationCheck(); + } + } + else + { + update_option('rzp_post_installation_update_at', $time); + $this->autoPostInstallationCheck(); + } + $razorpayOrderId = $razorpayOrder['id']; // Storing the razorpay order id in transient for 5 hours time. @@ -2935,11 +3276,13 @@ function razorpay_woo_plugin_links($links) function trigger_affordability_widget() { + $checkout360status = (get_option('rzp_checkout360_status') === 'yes') ? true : false; if (empty(get_option('rzp_afd_enable')) === false and get_option('rzp_afd_enable') === 'yes') { - if (empty(get_option('rzp_afd_feature_checked')) === true or - get_option('rzp_afd_feature_checked') === 'no') + if ((empty(get_option('rzp_afd_feature_checked')) === true or + get_option('rzp_afd_feature_checked') === 'no' ) and + $checkout360status === false) { try { @@ -2981,8 +3324,11 @@ function trigger_affordability_widget() function trigger_rtb_widget() { - if (empty(get_option('rzp_rtb_feature_checked')) === true or - get_option('rzp_rtb_feature_checked') === 'no') + $checkout360status = (get_option('rzp_checkout360_status') === 'yes') ? true : false; + + if ((empty(get_option('rzp_rtb_feature_checked')) === true or + get_option('rzp_rtb_feature_checked') === 'no') and + $checkout360status === false) { try { @@ -3007,11 +3353,15 @@ function trigger_rtb_widget() } } - if (empty(get_option('woocommerce_razorpay_settings')) === false and + if ((empty(get_option('woocommerce_razorpay_settings')) === false and isset(get_option('woocommerce_razorpay_settings')['enable_rtb_widget']) === true and get_option('woocommerce_razorpay_settings')['enable_rtb_widget'] === 'yes' and empty(get_option('rzp_rtb_enable')) === false and - get_option('rzp_rtb_enable') === 'yes') + get_option('rzp_rtb_enable') === 'yes') or + $checkout360status === true and + empty(get_option('rzp_rtb_enable')) === false and + get_option('rzp_rtb_enable') === 'yes' + ) { $key_id = get_option('woocommerce_razorpay_settings')['key_id']; echo ' From 9c15d680001e230f2a9b3d1e4b5d3db5671debae Mon Sep 17 00:00:00 2001 From: Razorpay Date: Wed, 11 Dec 2024 17:05:05 +0530 Subject: [PATCH 2/9] error handling from API --- woo-razorpay.php | 127 +++++++++++++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 49 deletions(-) diff --git a/woo-razorpay.php b/woo-razorpay.php index 74a33d44..77a8aae9 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -308,6 +308,38 @@ public function generate_multicheckbox_html($key, $data) return ob_get_clean(); } + public function toggleRtbWidget($action ,$widgetEnabled = false) + { + $data = [ + 'rtb_widget_enabled' => $widgetEnabled, + ]; + + $rtbEnable = $this->rzpPostInstallationCall('save', $data); + + // Experiment returned false + if (isset($rtbEnable['checkout360_status']) === true and + $rtbEnable['checkout360_status'] == false) + { + update_option('rzp_checkout360_status', 'no'); + return; + } + + if (empty($rtbEnable) === false) + { + if ($rtbEnable['rtb_eligibility'] === true) + { + $value = ($action === 'activate') ? 'yes' : 'no'; + update_option('rzp_rtb_enable', $value); + } + elseif ($rtbEnable['rtb_eligibility'] === false) + { + echo "
+

We are sorry you are not Eligible to opt RTB.

+
"; + } + } + } + public function process_admin_options() { $data = parent::get_post_data(); @@ -347,25 +379,19 @@ public function process_admin_options() foreach ($checkout360Settings as $c360Field => $c360Flag) { - if ($c360Field === 'enable_razorpay_trusted_business_widget' and - isset($data[$this->plugin_id . $this->id . '_' . $c360Field]) === true) + if ($c360Field === 'enable_razorpay_trusted_business_widget') { - $data = [ - "rtb_widget_enabled" => true, - ]; - $rtbEnable = $this->rzpPostInstallationCall('save', $data); - - if (isset($rtbEnable['rtb_eligibility']) === false) + if (isset($data[$this->plugin_id . $this->id . '_' . $c360Field]) === true and + (empty(get_option('rzp_rtb_enable')) === true) or (get_option('rzp_rtb_enable') === 'no')) { - update_option($c360Flag, "yes"); + $this->toggleRtbWidget('activate' , true); } - else + elseif (isset($data[$this->plugin_id . $this->id . '_' . $c360Field]) === false and + get_option('rzp_rtb_enable') === 'yes') { - echo "
-

We are sorry you are not Eligible to opt RTB.

-
"; - update_option($c360Flag, "no"); + $this->toggleRtbWidget('deactivate' , false); } + } elseif (isset($data[$this->plugin_id . $this->id . '_' . $c360Field]) === true) { @@ -396,7 +422,7 @@ public function rzpPostInstallationCall($event, $data = []) "data" => $data ]; - $result = $api->request->request('POST', 'app/woocommerce/api/woocommerce-post-installation', $postInstallationPayload); + $result = $api->request->request('POST', 'app/woocommerce/api/post-installation-workflow', $postInstallationPayload); return $result; } @@ -404,7 +430,7 @@ public function rzpPostInstallationCall($event, $data = []) { rzpLogError($e->getMessage()); - return ['checkout360_status' => 'no']; + return ['error' => $e->getMessage()]; } } @@ -466,8 +492,11 @@ public function __construct($hooks = true) if (empty($checkout360Available) === true) { $response = $this->rzpPostInstallationCall('install'); - $checkout360Available = ($response['checkout360_status'] === true) ? 'yes' : 'no'; - update_option('rzp_checkout360_status', $checkout360Available); + if (isset($response['error']) === false) + { + $checkout360Available = ($response['checkout360_status'] === true) ? 'yes' : 'no'; + update_option('rzp_checkout360_status', $checkout360Available); + } } if ($is1ccAvailable) { @@ -489,32 +518,32 @@ public function __construct($hooks = true) '1cc_account_creation', )); } + } - if ($checkout360Available === "yes") - { - //remove 1cc fields - $magicSettingsToRemove = [ - 'enable_1cc', - 'enable_1cc_test_mode', - 'enable_1cc_pdp_checkout', - 'enable_1cc_mini_cart_checkout', - '1cc_min_cart_amount', - '1cc_min_COD_slab_amount', - '1cc_max_COD_slab_amount', - ]; - $this->visibleSettings = array_diff($this->visibleSettings, $magicSettingsToRemove); - - //add checkout 360 fields - $checkout360VisibleFields = [ - 'checkout360_header', - 'checkout360_subheader', - 'configure_checkout360', - 'enable_magic_checkout_group', - 'enable_cod_configurations_group', - 'enhance_your_checkout_group', - ]; - $this->visibleSettings = array_merge($this->visibleSettings, $checkout360VisibleFields); - } + if ($checkout360Available === "yes") + { + //remove 1cc fields + $magicSettingsToRemove = [ + 'enable_1cc', + 'enable_1cc_test_mode', + 'enable_1cc_pdp_checkout', + 'enable_1cc_mini_cart_checkout', + '1cc_min_cart_amount', + '1cc_min_COD_slab_amount', + '1cc_max_COD_slab_amount', + ]; + $this->visibleSettings = array_diff($this->visibleSettings, $magicSettingsToRemove); + + //add checkout 360 fields + $checkout360VisibleFields = [ + 'checkout360_header', + 'checkout360_subheader', + 'configure_checkout360', + 'enable_magic_checkout_group', + 'enable_cod_configurations_group', + 'enhance_your_checkout_group', + ]; + $this->visibleSettings = array_merge($this->visibleSettings, $checkout360VisibleFields); } $this->init_form_fields(); @@ -824,18 +853,18 @@ public function autoPostInstallationCheck() $checkout360Available === 'no') { $checkout360Fields = [ - 'enable_1cc', - 'enable_1cc_test_mode', - 'enable_1cc_pdp_checkout', - 'enable_1cc_mini_cart_checkout', - 'rzp_cod_intelligence_enable' + 'enable_1cc', + 'enable_1cc_test_mode', + 'enable_1cc_pdp_checkout', + 'enable_1cc_mini_cart_checkout', + 'rzp_cod_intelligence_enable' ]; $optionKey = parent::get_option_key(); $savedData = get_option($optionKey); foreach ($checkout360Fields as $field) { - if ($field === 'rzp_cod_intelligence_enable')) + if ($field === 'rzp_cod_intelligence_enable') { delete_option($field); } From 775240db9d180091d2c0d908270ac2af75dc2945 Mon Sep 17 00:00:00 2001 From: Razorpay Date: Wed, 11 Dec 2024 17:31:16 +0530 Subject: [PATCH 3/9] cod changes --- woo-razorpay.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/woo-razorpay.php b/woo-razorpay.php index 77a8aae9..ee23fe60 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -1494,10 +1494,14 @@ public function getDefaultCheckoutArguments($order) $productinfo = "Order $orderId"; - $hidePaymentMethods = []; - if (get_option('enable_cod_intelligence') === 'yes') + $config = []; + + if (isset(get_option('rzp_checkout360_status')) === true and + get_option('rzp_checkout360_status') === 'yes' and + (empty(get_option('rzp_cod_intelligence_enable')) === true or + get_option('rzp_cod_intelligence_enable') === 'no')) { - $hidePaymentMethods['method'] = "cod"; + $config['display']['hide'] = ['method' => 'cod']; } return array( @@ -1512,13 +1516,7 @@ public function getDefaultCheckoutArguments($order) 'order_id' => $razorpayOrderId, 'callback_url' => $callbackUrl, 'prefill' => $this->getCustomerInfo($order), - 'config'=> [ - 'display'=> [ - 'hide'=> [ - $hidePaymentMethods - ] - ] - ] + 'config' => $config ); } From 0be1c58751411d48cb858c63544794cd4f4c1d32 Mon Sep 17 00:00:00 2001 From: Razorpay Date: Wed, 11 Dec 2024 18:04:24 +0530 Subject: [PATCH 4/9] added getDisplayConfig --- woo-razorpay.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/woo-razorpay.php b/woo-razorpay.php index ee23fe60..1afe86a4 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -1473,6 +1473,22 @@ public function generate_razorpay_form($orderId) return $html; } + public function getDisplayConfig() + { + $checkout360_status = get_option('rzp_checkout360_status'); + $rzp_cod_intelligence_enable = get_option('rzp_cod_intelligence_enable'); + + if (isset($checkout360_status) === true and + $checkout360_status === 'yes' and + (empty($rzp_cod_intelligence_enable) === true or + $rzp_cod_intelligence_enable === 'no')) + { + return [$config['display']['hide'] = ['method' => 'cod']]; + } + + return []; + } + /** * default parameters passed to checkout * @param WC_Order $order WC Order @@ -1494,15 +1510,7 @@ public function getDefaultCheckoutArguments($order) $productinfo = "Order $orderId"; - $config = []; - - if (isset(get_option('rzp_checkout360_status')) === true and - get_option('rzp_checkout360_status') === 'yes' and - (empty(get_option('rzp_cod_intelligence_enable')) === true or - get_option('rzp_cod_intelligence_enable') === 'no')) - { - $config['display']['hide'] = ['method' => 'cod']; - } + $config = $this->getDisplayConfig(); return array( 'key' => $this->getSetting('key_id'), From 1c1c8039ca83505eed798e29bc5eb1d4e459b49b Mon Sep 17 00:00:00 2001 From: Razorpay Date: Thu, 12 Dec 2024 11:48:07 +0530 Subject: [PATCH 5/9] changes for display config --- woo-razorpay.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/woo-razorpay.php b/woo-razorpay.php index 1afe86a4..a8fe5f9a 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -1475,6 +1475,7 @@ public function generate_razorpay_form($orderId) public function getDisplayConfig() { + $config = []; $checkout360_status = get_option('rzp_checkout360_status'); $rzp_cod_intelligence_enable = get_option('rzp_cod_intelligence_enable'); @@ -1483,10 +1484,10 @@ public function getDisplayConfig() (empty($rzp_cod_intelligence_enable) === true or $rzp_cod_intelligence_enable === 'no')) { - return [$config['display']['hide'] = ['method' => 'cod']]; + $config['display']['hide'][] = ['method' => 'cod']; } - return []; + return $config; } /** From 8b8c4d4ad4b2bbdceaf58c2164c6dd9e1a70fe6b Mon Sep 17 00:00:00 2001 From: Razorpay Date: Thu, 12 Dec 2024 12:55:28 +0530 Subject: [PATCH 6/9] changed checkout 360 links --- includes/api/api.php | 2 +- includes/razorpay-affordability-widget.php | 52 ++++++++++++---------- woo-razorpay.php | 8 ++-- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/includes/api/api.php b/includes/api/api.php index 5901531a..782e87cb 100644 --- a/includes/api/api.php +++ b/includes/api/api.php @@ -179,7 +179,7 @@ function initCartCommon() } -add_action('setup_extra_setting_fields', 'addMagicCheckoutSettingFields'); +add_action('setup_extra_setting_fields_1cc', 'addMagicCheckoutSettingFields'); function addMagicCheckoutSettingFields(&$defaultFormFields) { diff --git a/includes/razorpay-affordability-widget.php b/includes/razorpay-affordability-widget.php index 2f8cbd94..bca72007 100644 --- a/includes/razorpay-affordability-widget.php +++ b/includes/razorpay-affordability-widget.php @@ -526,37 +526,41 @@ function updateAffordabilityWidgetSettings() woocommerce_update_options(getAffordabilityWidgetSettings()); try { - if (isset($_POST['woocommerce_razorpay_key_id']) and - empty($_POST['woocommerce_razorpay_key_id']) === false and - isset($_POST['woocommerce_razorpay_key_secret']) and - empty($_POST['woocommerce_razorpay_key_secret']) === false) - { - $api = new Api($_POST['woocommerce_razorpay_key_id'], $_POST['woocommerce_razorpay_key_secret']); - } - else + $checkout360status = (get_option('rzp_checkout360_status') === 'yes') ? true : false; + + if ($checkout360status === false) { - $api = new Api(get_option('woocommerce_razorpay_settings')['key_id'],get_option('woocommerce_razorpay_settings')['key_secret']); - } + if (isset($_POST['woocommerce_razorpay_key_id']) and + empty($_POST['woocommerce_razorpay_key_id']) === false and + isset($_POST['woocommerce_razorpay_key_secret']) and + empty($_POST['woocommerce_razorpay_key_secret']) === false) + { + $api = new Api($_POST['woocommerce_razorpay_key_id'], $_POST['woocommerce_razorpay_key_secret']); + } + else + { + $api = new Api(get_option('woocommerce_razorpay_settings')['key_id'],get_option('woocommerce_razorpay_settings')['key_secret']); + } - $merchantPreferences = $api->request->request('GET', 'accounts/me/features'); + $merchantPreferences = $api->request->request('GET', 'accounts/me/features'); - if (isset($merchantPreferences) === false or - isset($merchantPreferences['assigned_features']) === false) - { - throw new Exception("Error in Api call."); - } + if (isset($merchantPreferences) === false or + isset($merchantPreferences['assigned_features']) === false) + { + throw new Exception("Error in Api call."); + } - update_option('rzp_afd_enable', 'no'); - foreach ($merchantPreferences['assigned_features'] as $preference) - { - if ($preference['name'] === 'affordability_widget' or - $preference['name'] === 'affordability_widget_set') + update_option('rzp_afd_enable', 'no'); + foreach ($merchantPreferences['assigned_features'] as $preference) { - update_option('rzp_afd_enable', 'yes'); - break; + if ($preference['name'] === 'affordability_widget' or + $preference['name'] === 'affordability_widget_set') + { + update_option('rzp_afd_enable', 'yes'); + break; + } } } - } catch (\Exception $e) { diff --git a/woo-razorpay.php b/woo-razorpay.php index a8fe5f9a..42bdf44d 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -698,7 +698,7 @@ public function init_form_fields() 'enable_cod_configuratiopn' => array( 'label' => __('Set-up smart COD rules & RTO Prediction here', $this->id), 'description' => __("Use Razorpay's RTO intelligence to block COD for high risk users", $this->id), - 'link' => 'http://dashboard.razorpay.com/magic' + 'link' => 'http://dashboard.razorpay.com/app/magic' ) ) ), @@ -717,15 +717,17 @@ public function init_form_fields() 'enable_giftcards_coupons' => array( 'label' => __('Set-up gift cards and coupons here', $this->id), 'description' => __("", $this->id), - 'link' => 'http://dashboard.razorpay.com/magic' + 'link' => 'https://dashboard.razorpay.com/app/magic/settings' ) ) ) ); + do_action_ref_array( 'setup_extra_setting_fields', array( &$defaultFormFields ) ); + $defaultFormFields = array_merge( $defaultFormFields, $checkout360Settings ); - do_action_ref_array( 'setup_extra_setting_fields', array( &$defaultFormFields ) ); + do_action_ref_array( 'setup_extra_setting_fields_1cc', array( &$defaultFormFields ) ); foreach ($defaultFormFields as $key => $value) { From 6b05b402ec5ca1e46c9641041c7865636fe42e24 Mon Sep 17 00:00:00 2001 From: Razorpay Date: Wed, 18 Dec 2024 11:36:43 +0530 Subject: [PATCH 7/9] updated configuration link --- woo-razorpay.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woo-razorpay.php b/woo-razorpay.php index 42bdf44d..1df8e437 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -661,7 +661,7 @@ public function init_form_fields() 'type' => 'title', ), 'configure_checkout360' => array( - 'title' => '' . __('Configure Checkout360 Settings').'', + 'title' => '' . __('Configure Checkout360 Settings').'', 'type' => 'title', ), 'enable_magic_checkout_group' => array( From eb425a2a83659aea7dd680235a7fb55041c9cd77 Mon Sep 17 00:00:00 2001 From: Razorpay Date: Thu, 19 Dec 2024 17:16:29 +0530 Subject: [PATCH 8/9] changed COD logic --- woo-razorpay.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/woo-razorpay.php b/woo-razorpay.php index 1df8e437..0622acf2 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -1477,16 +1477,25 @@ public function generate_razorpay_form($orderId) public function getDisplayConfig() { - $config = []; + $config = [ + 'display' => [ + 'hide' => [ + [ + 'method' => 'cod' + ] + ] + ] + ]; + $checkout360_status = get_option('rzp_checkout360_status'); $rzp_cod_intelligence_enable = get_option('rzp_cod_intelligence_enable'); - if (isset($checkout360_status) === true and - $checkout360_status === 'yes' and - (empty($rzp_cod_intelligence_enable) === true or - $rzp_cod_intelligence_enable === 'no')) + if ((isset($checkout360_status) === true) and + ($checkout360_status === 'yes') and + (empty($rzp_cod_intelligence_enable) === false) and + ($rzp_cod_intelligence_enable === 'yes')) { - $config['display']['hide'][] = ['method' => 'cod']; + unset($config['display']['hide']); } return $config; From 34b8341096ec6448bb83b61ac84cc88ac35a8f5d Mon Sep 17 00:00:00 2001 From: Razorpay Date: Fri, 20 Dec 2024 12:27:56 +0530 Subject: [PATCH 9/9] added validation checks --- woo-razorpay.php | 61 +++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/woo-razorpay.php b/woo-razorpay.php index 0622acf2..829f9333 100644 --- a/woo-razorpay.php +++ b/woo-razorpay.php @@ -324,7 +324,8 @@ public function toggleRtbWidget($action ,$widgetEnabled = false) return; } - if (empty($rtbEnable) === false) + if ((empty($rtbEnable) === false) and + (isset($rtbEnable['rtb_eligibility']) === true)) { if ($rtbEnable['rtb_eligibility'] === true) { @@ -844,38 +845,46 @@ protected function triggerValidationInstrumentation($data) public function autoPostInstallationCheck() { - $response = $this->rzpPostInstallationCall('evaluate'); - - $checkout360Available = ($response['checkout360_status'] === true) ? 'yes' : 'no'; + try + { + $response = $this->rzpPostInstallationCall('evaluate'); - update_option('rzp_checkout360_status', $checkout360Available); + $checkout360Available = ((isset($response['checkout360_status']) === true) and ($response['checkout360_status'] === true)) ? 'yes' : 'no'; - // remove all checkou360 settings - if ($response['merchant_status'] === 'existing_checkout360_merchant' and - $checkout360Available === 'no') - { - $checkout360Fields = [ - 'enable_1cc', - 'enable_1cc_test_mode', - 'enable_1cc_pdp_checkout', - 'enable_1cc_mini_cart_checkout', - 'rzp_cod_intelligence_enable' - ]; - $optionKey = parent::get_option_key(); - $savedData = get_option($optionKey); + update_option('rzp_checkout360_status', $checkout360Available); - foreach ($checkout360Fields as $field) + // remove all checkout360 settings + if ((isset($response['merchant_status']) === true) and + ($response['merchant_status'] === 'existing_checkout360_merchant') and + ($checkout360Available === 'no')) { - if ($field === 'rzp_cod_intelligence_enable') + $checkout360Fields = [ + 'enable_1cc', + 'enable_1cc_test_mode', + 'enable_1cc_pdp_checkout', + 'enable_1cc_mini_cart_checkout', + 'rzp_cod_intelligence_enable' + ]; + $optionKey = parent::get_option_key(); + $savedData = get_option($optionKey); + + foreach ($checkout360Fields as $field) { - delete_option($field); - } - else - { - $savedData[$field] = 'no'; + if ($field === 'rzp_cod_intelligence_enable') + { + delete_option($field); + } + else + { + $savedData[$field] = 'no'; + } } + update_option($optionKey, apply_filters('woocommerce_settings_api_sanitized_fields_' . $this->id, $savedData), 'yes'); } - update_option($optionKey, apply_filters('woocommerce_settings_api_sanitized_fields_' . $this->id, $savedData), 'yes'); + } + catch (\Exception $e) + { + rzpLogError($e->getMessage()); } }