简体   繁体   中英

No response on paypal api with php curl

I'm trying to get the response from the PayPal api regarding an order with php and cURL. Here is my code, I have of course replaced the token, which is not the problem here. With the following command, everything works fine in my terminal, I don't understand why it doesn't work. (If I do a var_dump($response) , I get string(0) "" .

Code:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://api-m.sandbox.paypal.com/v2/checkout/orders/".$_GET['transacid']);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $headers = [
        "Content-Type: application/json",
        "Authorization: Bearer my_oauth_token"
    ];
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $response= curl_exec($ch);
    curl_close($ch);
    var_dump($response);

And, the CLI command:

curl -v -X GET https://api-m.sandbox.paypal.com/v2/checkout/orders/my_order_id\
-H "Content-Type: application/json" \
-H "Authorization: Bearer my_oauth_token"

I think I can get the result with an exec(), but it's really not clean, especially with a GET variable.

Thanks !

(Posting as answer after commenting)

Just a remark that might not be related but in the terminal, you are doing a GET request while on the php side you are doing a POST request (cf. CURLOPT_POST which is set to 1). So you are not doing the same type of request already. First do that and then we can troubleshoot further if needed. And eventually, that might be the only thing causing your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM