jeudi 25 février 2016

PHP, CURL ,curl_exec

I'm trying to set an API for online payment process.According to their documentation i should have like this in url http://localhost:8000/shopping/success/45?oid=XYZ-1234&amt=330&refId=0006QHT

i mean, oid="something"&amt="something"&refId="something"

i got like this in browser. But i got message like this on doing die()at end of code :

Failed to connect to dev.esewa.com.np port 80: Connection refused

I want to know what the message suggesting me .is there anything wrong,How can i solve this error

here is my code

       $site_url = 'http://ift.tt/1p8tdty';
        $esewa_url = 'http://ift.tt/21tWn4g';
        $esewa_verfication_url = 'http://ift.tt/1p8tg8M';
        $merchant_id = "xxxxxx";

        //create array of data to be posted
       // dd($_REQUEST['oid']);
        $post_data['amt'] = $_REQUEST['amt'];
        $post_data['scd'] = $merchant_id;
        $post_data['pid'] = $_REQUEST['oid'];
        $post_data['rid'] = $_REQUEST['refId'];

        //traverse array and prepare data for posting (key1=value1)
        foreach ($post_data as $key => $value) {
        $post_items[] = $key . '=' . $value;
        }

        //create the final string to be posted using implode()
        $post_string = implode('&', $post_items);

       // dd($post_string);

        //create cURL connection
        $curl_connection =
            curl_init($esewa_verfication_url);

       //dd($curl_connection);
        //set options
        curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
        curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

        //set data to be posted
        curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

        //perform our request
        $result = curl_exec($curl_connection);


        if($result === FALSE) {
          die(curl_error($curl_connection));
//here i go message like this:Failed to connect to dev.esewa.com.np port 80: Connection refused
        }

        //close the connection
        curl_close($curl_connection);


        $verification_response  = strtoupper( trim( strip_tags( $result ) ) ) ;

        if('SUCCESS' == $verification_response){
        echo '<h2><strong>SUCCESS:</strong> Transaction is successful !!!</h2>';

        return Redirect::to('/');
        }
        else{
        echo '<h2><strong>ERROR:</strong> Transaction could not be verified</h2>';

                return Redirect::to('/');


        }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire