From 08cba123fe20f10deef584372dc5f1374c5bfef4 Mon Sep 17 00:00:00 2001 From: poojarazor Date: Wed, 8 Feb 2023 17:40:38 +0530 Subject: [PATCH 1/2] wooc alert and monitor --- includes/api/alert-monitor.php | 70 ++++++++++++++++++++++++++++++++++ includes/api/api.php | 37 ++++++++---------- 2 files changed, 86 insertions(+), 21 deletions(-) create mode 100644 includes/api/alert-monitor.php diff --git a/includes/api/alert-monitor.php b/includes/api/alert-monitor.php new file mode 100644 index 00000000..da93b1ea --- /dev/null +++ b/includes/api/alert-monitor.php @@ -0,0 +1,70 @@ +get_params(); + $status = 400; + + //dummy data for testing + $configData = ["enable_1cc" => "yes" , "enable_1cc_pdp_checkout" => "yes", "enable_1cc_mini_cart_checkout" => "yes"]; + + $validateInput = validateAlertConfigApi($params); + + $logObj = []; + $logObj["api"] = "validateAlertConfigApi"; + //$logObj["params"] = $params; + + if ($validateInput != null) { + + $res['response']["failure_reason"] = $validateInput; + $res['response']["failure_code"] = "VALIDATION_ERROR"; + $res['status_code'] = $status; + + $logObj["response"] = $result; + rzpLogError(json_encode($logObj)); + + return new WP_REST_Response($res, $status); + } + + $rzpSettingData = []; + + $rzpSettingData = get_option('woocommerce_razorpay_settings'); + + //update the Buy Now button config + $rzpSettingData['enable_1cc_pdp_checkout'] = $configData['enable_1cc_pdp_checkout']; + + //update the mini cart button config + $rzpSettingData['enable_1cc_mini_cart_checkout'] = $configData['enable_1cc_mini_cart_checkout']; + + //update the magic checkout config + $rzpSettingData['enable_1cc'] = $configData['enable_1cc']; + + update_option('woocommerce_razorpay_settings', $rzpSettingData); + + return new WP_REST_Response('success', 200); + +} + + +function validateAlertConfigApi($param) +{ + $failureReason = null; + if (empty(sanitize_text_field($param["enable_1cc"])) === true) { + $failureReason = "1cc config is required."; + } elseif (empty(sanitize_text_field($param["enable_1cc_pdp_checkout"])) === true) { + $failureReason = "1cc pdp checkout is required."; + }elseif (empty(sanitize_text_field($param["enable_1cc_mini_cart_checkout"])) === true) { + $failureReason = "1cc mini cart checkout."; + } + + return $failureReason; +} + + diff --git a/includes/api/api.php b/includes/api/api.php index 0b4741a9..a3fdcb16 100644 --- a/includes/api/api.php +++ b/includes/api/api.php @@ -15,6 +15,7 @@ require_once __DIR__ . '/../state-map.php'; require_once __DIR__ . '/save-abandonment-data.php'; require_once __DIR__ . '/giftcard-apply.php'; +require_once __DIR__ . '/alert-monitor.php'; require_once ABSPATH . 'wp-admin/includes/plugin.php'; define('RZP_1CC_ROUTES_BASE', '1cc/v1'); @@ -126,6 +127,21 @@ function rzp1ccInitRestApi() ) ); + /** + * Alerting and Monitoring on merchant disable magic + */ + + // validate gift card data + register_rest_route( + RZP_1CC_ROUTES_BASE.'/alert', + 'monitor', + array( + 'methods' => 'POST', + 'callback' => 'monitorAlertingData', + 'permission_callback' => 'checkAuthCredentials', + ) + ); + } add_action('rest_api_init', 'rzp1ccInitRestApi'); @@ -173,13 +189,6 @@ function addMagicCheckoutSettingFields(&$defaultFormFields) { $magicCheckoutConfigFields = array( - 'enable_1cc' => array( - 'title' => __('Activate Magic Checkout'), - 'type' => 'checkbox', - 'description' => "", - 'label' => __('Activate Magic Checkout'), - 'default' => 'no', - ), 'enable_1cc_test_mode' => array( 'title' => __('Activate test mode'), 'type' => 'checkbox', @@ -187,20 +196,6 @@ function addMagicCheckoutSettingFields(&$defaultFormFields) 'label' => __('Activate test mode for Magic Checkout'), 'default' => 'no', ), - 'enable_1cc_pdp_checkout' => array( - 'title' => __('Activate Buy Now Button'), - 'type' => 'checkbox', - 'description' => 'By enabling the Buy Now button, user will be able to see the Razorpay Magic Checkout button on Product display page. ', - 'label' => __('Activate Buy Now for Magic Checkout'), - 'default' => 'yes', - ), - 'enable_1cc_mini_cart_checkout' => array( - 'title' => __('Activate Mini Cart Checkout'), - 'type' => 'checkbox', - 'description' => 'By enabling the Mini Cart checkout button, user will be able to see the Razorpay Magic Checkout on click of checkout button. ', - 'label' => __('Activate Mini Cart for Magic Checkout'), - 'default' => 'yes', - ), '1cc_min_cart_amount' => array( 'title' => __('Set minimum cart amount (INR)'), 'type' => 'number', From acc8a2f042dd3531b2e73c83b25d9415f8458f20 Mon Sep 17 00:00:00 2001 From: poojarazor Date: Wed, 12 Apr 2023 16:15:28 +0530 Subject: [PATCH 2/2] update endpoints --- includes/api/alert-monitor.php | 35 +++++++++++++++++++--------------- includes/api/api.php | 6 +++--- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/includes/api/alert-monitor.php b/includes/api/alert-monitor.php index da93b1ea..17267706 100644 --- a/includes/api/alert-monitor.php +++ b/includes/api/alert-monitor.php @@ -4,22 +4,22 @@ * wooc alert and monitoring API */ -function monitorAlertingData(WP_REST_Request $request) +function update1ccConfig(WP_REST_Request $request) { global $woocommerce; global $wpdb; - //$params = $request->get_params(); + rzpLogInfo("magic config start"); + + $params = $request->get_params(); $status = 400; - //dummy data for testing - $configData = ["enable_1cc" => "yes" , "enable_1cc_pdp_checkout" => "yes", "enable_1cc_mini_cart_checkout" => "yes"]; + rzpLogInfo("config param :" . json_encode($params)); $validateInput = validateAlertConfigApi($params); $logObj = []; $logObj["api"] = "validateAlertConfigApi"; - //$logObj["params"] = $params; if ($validateInput != null) { @@ -38,13 +38,21 @@ function monitorAlertingData(WP_REST_Request $request) $rzpSettingData = get_option('woocommerce_razorpay_settings'); //update the Buy Now button config - $rzpSettingData['enable_1cc_pdp_checkout'] = $configData['enable_1cc_pdp_checkout']; - + if(isset($params['buyNowEnabled'])){ + $rzpSettingData['enable_1cc_pdp_checkout'] = $params['buyNowEnabled'] === 'true' ? 'yes' : 'no'; + } + + //update the mini cart button config - $rzpSettingData['enable_1cc_mini_cart_checkout'] = $configData['enable_1cc_mini_cart_checkout']; + if(isset($params['miniCartEnabled'])){ + $rzpSettingData['enable_1cc_mini_cart_checkout'] = $params['miniCartEnabled'] === 'true' ? 'yes' : 'no'; + } + //update the magic checkout config - $rzpSettingData['enable_1cc'] = $configData['enable_1cc']; + if(isset($params['oneClickCheckoutEnabled'])){ + $rzpSettingData['enable_1cc'] = $params['oneClickCheckoutEnabled'] === 'true' ? 'yes' : 'no'; + } update_option('woocommerce_razorpay_settings', $rzpSettingData); @@ -56,12 +64,9 @@ function monitorAlertingData(WP_REST_Request $request) function validateAlertConfigApi($param) { $failureReason = null; - if (empty(sanitize_text_field($param["enable_1cc"])) === true) { - $failureReason = "1cc config is required."; - } elseif (empty(sanitize_text_field($param["enable_1cc_pdp_checkout"])) === true) { - $failureReason = "1cc pdp checkout is required."; - }elseif (empty(sanitize_text_field($param["enable_1cc_mini_cart_checkout"])) === true) { - $failureReason = "1cc mini cart checkout."; + + if( $param["oneClickCheckoutEnabled"] == null && $param["buyNowEnabled"] == null && $param["miniCartEnabled"]== null){ + $failureReason = "Config is required"; } return $failureReason; diff --git a/includes/api/api.php b/includes/api/api.php index a3fdcb16..e356609e 100644 --- a/includes/api/api.php +++ b/includes/api/api.php @@ -133,11 +133,11 @@ function rzp1ccInitRestApi() // validate gift card data register_rest_route( - RZP_1CC_ROUTES_BASE.'/alert', - 'monitor', + RZP_1CC_ROUTES_BASE.'/magic', + 'toggle', array( 'methods' => 'POST', - 'callback' => 'monitorAlertingData', + 'callback' => 'update1ccConfig', 'permission_callback' => 'checkAuthCredentials', ) );