How to configure the session and user_id as soon as the method is called? (Codeigniter)

Asked

Viewed 20 times

0

I have these two methods responsible for adding users from another system to that system.

private function api_login ($ email, $ password) { $Curl = curl_init(); curl_setopt_array($Curl, [ CURLOPT_URL => "https://api. #.com.br/v1/driver/login", CURLOPT_RETURNTRANSFER => 1, CURLOPT_ENCODING => "", CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 3000, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode(['email' => $email, 'password' => $password, 'device_name' => 'web']), CURLOPT_HTTPHEADER => [ 'Accept: application/json', 'Content-Type: application/json' ], ]);

$response_body = curl_exec($curl);
$response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$response_error = curl_errno($curl);
$err = curl_error($curl);

curl_close($curl);
$token = false;
if (!$err) {
    if($response_code == 200){
        $json_decode = json_decode($response_body);
        $token = $json_decode->token;
    }
}

return $token;

}

private Function api_user_info(){

$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.#.com.br/v1/driver/user",
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_ENCODING => "",
    CURLOPT_SSL_VERIFYHOST => 0,
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 3000,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer '.$this->session->userdata('token_#'),
        'Accept: application/json',
        'Content-Type: application/json'
    ],
]);

$response_body = curl_exec($curl);
$response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$response_error = curl_errno($curl);
$err = curl_error($curl);

curl_close($curl);
$json_decode = '';
if (!$err) {
    if($response_code == 200){
        $json_decode = json_decode($response_body);
    }
}

return $json_decode;

}

I want to set the parameters of the following method: public Function stripe_payment ($ user_id = "", $ payment_request_from = "", $ session_id = "") {if ($ this-> session-> userdata ('user_login')! = 1 && $ payment_request_from == 'from_web') {$ this-> Session-> set_flashdata ('error_message', get_phrase ('please_login_first')); redirect ('home / login', 'update'); }

//THIS IS HOW I CHECKED THE STRIPE PAYMENT STATUS $Sponse = $this->payment_model->stripe_payment($user_id, $session_id);

if ($response['payment_status'] === 'succeeded') {
    // STUDENT ENROLMENT OPERATIONS AFTER A SUCCESSFUL PAYMENT

    $check_duplicate = $this->db->get_where('bundle_payment', array('user_id' => $user_id, 'session_id' => $session_id, 'transaction_id' => $response['transaction_id']))->num_rows();
    if($check_duplicate <= 0):
        $this->course_bundle_model->bundle_purchase('stripe', $response['paid_amount'], $response['transaction_id'], $session_id);
        $this->email_model->bundle_purchase_notification($user_id);

        $this->session->set_userdata('checkout_bundle_price', null);
        $this->session->set_userdata('checkout_bundle_id', null);
    else:
        $this->session->set_flashdata('error_message', site_phrase('session_time_out'));
        redirect('home/course_bundles', 'refresh');
    endif;

    if($payment_request_from == 'from_web'):
        $this->session->set_flashdata('flash_message', site_phrase('payment_successfully_done'));
        redirect('home/my_bundles', 'refresh');
    else:
        //for mobile
    endif;
}else{
    if($payment_request_from == 'from_web'):
        $this->session->set_flashdata('error_message', $response['status_msg']);
        redirect('home', 'refresh');
    else:
        //for mobile
    endif;

}

}

And I need to configure this params with the above API result.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.