Jump to content

How to send an http request to initiate order from a prestashop payment module to a remote payment gateway


Recommended Posts

I'm not so sure if Prestashop has specific functions to do an HTTP Post. 

I would recommend you to use Curl, I used this for the module I'm currently working on.

    private static function doPost($postUrl, array $params){
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => $postUrl,
            CURLOPT_SSL_VERIFYPEER => 0,
            CURLOPT_SSL_VERIFYHOST => 0,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POST => 1,
            CURLOPT_POSTFIELDS => $params,
        ));

        $response = curl_exec($curl);

        $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        curl_close($curl);

        switch ($http_status){
            case 200:
				return $response;
            case 400:
            default:
                return false;
        }
        
    }

It''s a POST method, but can be easily modified to GET.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...