Search code examples
phpcurlcs-cart

How to stop the creation of user in cscart using update_profile hook


function fn_user_registered_test_update_profile($action, $user_data, 
$current_user_data){

$encoded=json_encode($user_data);
extract(json_decode($encoded, true));

if($user_type == "C"){

if ($action == "add"){

  $url = 'http://199.99.999.99:9999/api/users'; // url is different
  $data = array('email'=>$email,'name'=>$firstname,'type'=>'customer');
  $data_json = json_encode($data);

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  $result = curl_exec($ch);
  curl_close($ch);
  }
  }

Im creating a new user from the CSCart and registering a blockchain,

If the blockchain is down , i want the creation of the user to be stopped at cs cart

I want the user creation to stop if the response from this is anything other than status 200

Is there a way to stop the creation of user using flags?


Solution

  • When this hook is called, new user already added to database. In this case you should use the fn_delete_user($user_data['user_id']); function to delete new user from database