I am developing an application with an API from a web. On the web I am required to provide http response because they send POST requests to my system.

like this

the scheme

in the first step i can send the response and save to my database, the code like this

public function notification_kredivo_v_2(){
        //set response
        ignore_user_abort(true);
        set_time_limit(0);
        ob_start();

        //data response
        header('Content-Type: application/json; charset=utf-8');

        $default = array(
            "status"  => "OK",
            "message" => "Notification has been received",
        );

        echo json_encode($default);;

        // DON'T USE CONTENT-LENGTH or IT WILL BREAK THE CODE
        header('Connection: close');
        header('Content-Length: '.ob_get_length());
        ob_end_flush();
        ob_flush();
        flush();

        //load db
        $this->load->model('kredivo_model', 'km');

        //ambil data result
        $result = json_decode(file_get_contents('php://input'), true);

        $order_id               = $result['order_id'];
        $transaction_id         = $result['transaction_id'];
        $signature_key          = $result['signature_key'];

        //masukan ke database kredivo payment
        $this->km->confirm_payment_v2(
            $order_id,
            $transaction_id,
            $signature_key
        );
}

but after that process i have to sent GET request to the another system, my code like this, i use guzzle to GET request

/*CONFIRM TO V2/UPDATE*/
        //kirim get untuk confirm order
        $url = $this->ci->config->item("kredivo_api_link_confirm");

        //load libary kredivo
        $this->load->library('CoreKredivo','corekredivo');

        //sent to v2/update
        $confirm_order = array(
            'transaction_id' => $transaction_id,
            'signature_key'  => $signature_key,
        );

        //kirim data ke confirmation core kredivo
        $confirmation = $this->corekredivo->confirmOrder($url,$confirm_order);

        //menerima data dari core kredivo dan melakukan decode
        $finalResponse_payment = json_decode($confirmation,true);

        $fraud = $finalResponse_payment['fraud_status'];
        $transaction_status = $finalResponse_payment['transaction_status'];
        $user_token = $finalResponse_payment['user_token'];

        $this->km->confirm_payment_v2(
            $fraud,
            $transaction_status,
            $user_token
        );

i try to saved to database to check whether my get request is running or not

but the get request is not working because the data is not insert to my database,

how to solved this problem? please help

0 Answers