diff --git a/includes/api/alert-monitor.php b/includes/api/alert-monitor.php new file mode 100644 index 00000000..17267706 --- /dev/null +++ b/includes/api/alert-monitor.php @@ -0,0 +1,75 @@ +get_params(); + $status = 400; + + rzpLogInfo("config param :" . json_encode($params)); + + $validateInput = validateAlertConfigApi($params); + + $logObj = []; + $logObj["api"] = "validateAlertConfigApi"; + + 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 + if(isset($params['buyNowEnabled'])){ + $rzpSettingData['enable_1cc_pdp_checkout'] = $params['buyNowEnabled'] === 'true' ? 'yes' : 'no'; + } + + + //update the mini cart button config + if(isset($params['miniCartEnabled'])){ + $rzpSettingData['enable_1cc_mini_cart_checkout'] = $params['miniCartEnabled'] === 'true' ? 'yes' : 'no'; + } + + + //update the magic checkout config + if(isset($params['oneClickCheckoutEnabled'])){ + $rzpSettingData['enable_1cc'] = $params['oneClickCheckoutEnabled'] === 'true' ? 'yes' : 'no'; + } + + update_option('woocommerce_razorpay_settings', $rzpSettingData); + + return new WP_REST_Response('success', 200); + +} + + +function validateAlertConfigApi($param) +{ + $failureReason = null; + + 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 0b4741a9..e356609e 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.'/magic', + 'toggle', + array( + 'methods' => 'POST', + 'callback' => 'update1ccConfig', + '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',