Jump to content

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


Recommended Posts

Hello im trying to send an http request to initiate order from a prestashop 1.7 payment module to a remote payment gateway, but have no idea on how to do so with prestashop functoins . Need some help

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More