Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wooc alert and monitor #427

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions includes/api/alert-monitor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* wooc alert and monitoring API
*/

function update1ccConfig(WP_REST_Request $request)
{
global $woocommerce;
global $wpdb;

rzpLogInfo("magic config start");

$params = $request->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;
}


37 changes: 16 additions & 21 deletions includes/api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -173,34 +189,13 @@ 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',
'description' => 'When test mode is active, only logged-in admin users will see the Razorpay Magic Checkout button',
'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',
Expand Down