0

I use this code to process Paypal payment data transfer (PDT):

            $pp_hostname = "www.sandbox.paypal.com"; // Change to www.sandbox.paypal.com to test against sandbox
        // read the post from PayPal system and add 'cmd'
        $req = 'cmd=_notify-synch';

        $tx_token = $_GET['tx'];
        $auth_token = "my_token";
        $req .= "&tx=$tx_token&at=$auth_token";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
        //set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
        //if your server does not bundled with default verisign certificates.
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname"));
        $res = curl_exec($ch);
        curl_close($ch);

        if(!$res){
            echo "HTTP ERROR";
        }else{ ...

But it does not work, my code tells me that the request fails, and it outputs HTTP ERROR because $res is empty. Why?

  • You can change the CURLOPT_SSL_VERIFYPEER value to 0 , then try again. – Zhao Samanta Feb 19 '16 at 07:46
  • I tried to change it and it still doesn't work. I tried to make the API in Postman with the same URL: www.sandbox.paypal.com with the same parameters (cmd, at, tx) and I got success response. What I did wrong? – user3084703 Feb 19 '16 at 11:28
  • Did you get PDT token from sandbox account ? also refer to https://github.com/paypal/TLS-update ,please make sure the PHP environment is adequate. – Zhao Samanta Feb 22 '16 at 06:24
  • Yes, the PDT token was takken from the sandbox account (it works in Postman with the same cmd, at, tx). I also tried to use a different code and I'm getting: `Curl error: SSL connect error status: 0` Thanks!! – user3084703 Feb 22 '16 at 09:58
  • You can refer to github.com/paypal/TLS-update ,please make sure the PHP environment is adequate – Zhao Samanta Feb 23 '16 at 06:11

0 Answers0