You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于PayPal REST支付执行流程的Guzzle适配及疑问咨询

PayPal REST Payment Execution: Guzzle Conversion & 500 Error Troubleshooting

Hey there, let's work through your two issues one by one:

1. Converting the cURL Command to Guzzle

Absolutely, the Authorization: Bearer Access-Token header does need to be included in the request headers, just like Content-Type: application/json. Guzzle handles headers explicitly, so you'll define both there.

Here's how to translate that cURL call to a Guzzle 7+ implementation (this works for most modern Guzzle versions):

use GuzzleHttp\Client;

$client = new Client();

try {
    $response = $client->post('https://api.sandbox.paypal.com/v1/payments/payment/{payment_id}/execute/', [
        'headers' => [
            'Content-Type' => 'application/json',
            'Authorization' => 'Bearer YOUR_SANDBOX_ACCESS_TOKEN' // Replace with your actual token
        ],
        'json' => [
            'payer_id' => 'YOUR_PAYER_ID' // Replace with the payer ID from your authorization flow
        ]
    ]);

    // Handle successful response
    $data = json_decode($response->getBody(), true);
    print_r($data);
} catch (\GuzzleHttp\Exception\RequestException $e) {
    // Catch and log errors
    echo "Error: " . $e->getMessage();
    if ($e->hasResponse()) {
        echo "\nResponse body: " . $e->getResponse()->getBody()->getContents();
    }
}

A quick breakdown:

  • The headers array directly maps to the -H flags in cURL
  • Using the json option automatically encodes the array to JSON and sets the Content-Type header (though including it explicitly doesn't hurt for clarity)
  • Don't forget to replace {payment_id}, YOUR_SANDBOX_ACCESS_TOKEN, and YOUR_PAYER_ID with your actual values from the PayPal flow

2. Troubleshooting the 500 Error & Sandbox Console Issue

First, that 500 error from PayPal's sandbox is a server-side issue on their end, but it often ties back to invalid request data from your side. Here are some things to check:

  • Verify your access token: Make sure you're using a sandbox-generated access token (not production). You can get one via the /v1/oauth2/token endpoint with your sandbox client ID and secret.
  • Validate payment_id and payer_id: Ensure the payment_id is a valid, unexecuted payment from your sandbox account, and the payer_id is the one returned when the user authorized the payment (usually from the PayerID query parameter in the redirect URL).
  • Check for typos: Double-check the API endpoint URL (no extra slashes, correct sandbox domain) and JSON structure (missing commas, incorrect key names can cause unexpected server errors).

As for the sandbox console error "Something went wrong fetching sandbox API calls. Try again.", that's almost always a temporary glitch with PayPal's sandbox infrastructure. Try these fixes:

  • Wait 10-15 minutes and refresh the page—PayPal's sandbox tools can have occasional uptime blips
  • Clear your browser cache and cookies, or try a different browser
  • If you need immediate visibility into your requests, enable debug mode in Guzzle to log the full request/response details (add 'debug' => true to the request options array)

内容的提问来源于stack exchange,提问作者Sandy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:03:11