我已经使用 paypal RESTful 的 API PHP SDK 将我的网站与 paypal 完全集成。现在我的问题是每隔一段时间在付款过程中,一旦用户批准付款并返回我的网站执行,API 执行请求就会返回来自贝宝的以下响应。这些场景中的 HTTP 响应代码是 400 和 500。下面我列出了错误名称和错误消息,它们是我在执行操作时从 paypal 获得的 JSON 响应的一部分(https://api.paypal.com/v1 /payments/payment/PAY-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/执行):
400 PAYMENT_NOT_APPROVED_FOR_EXECUTION,付款人未批准付款 500 INTERNAL_SERVICE_ERROR,发生内部服务错误
就我用来进行该调用的代码而言,我添加了执行付款的函数。我应该补充一点,这在 98% 的情况下都有效。下面是代码:
public function getExecute()
{
    // Payment is cancelled
    if (!(Input::get('success') && Input::get('success') == 'true')) 
        return $this->runPaymentExitProcess();
    // No paymentId
    if (!Session::has('paymentId')) 
        return "No payment id to execute";
    $paymentId = Session::get('paymentId');
    $this->payment = Payment::get($paymentId, $this->apiContext);
    // The payer_id is added to the request query parameters when the user is redirected from paypal back to your site
    $this->execution->setPayer_id(Input::get('PayerID'));
    $response = $this->payment->execute($this->execution, $this->apiContext);
    // Check for paypal errors
    if (isset($response->name)) {
        // When we have a paypal error
        if ($this->hasPaypalError($response)) {
            $error = array('name' => $response->name, 'message' => $response->message);
    Session::put('error', $error);
            return (MODE == 'LIVE') ? Redirect::to('/paypalerror') : Redirect::to('/paypalerror'.MODE_PARAM);
            die;
        }   
    }   
    // Unset session
    Session::forget('paymentId');
    // execution successful
    if ($this->addPaymentIdToUser($paymentId))
        return (MODE == 'LIVE') ? Redirect::to('/') : Redirect::to('/'.MODE_PARAM);
}
代码在 laravel 中。请注意 $this->apiContext 是在类的构造函数中设置的。这也是函数是在redirect_urls下的API中设置的成功url。
有人可以帮我弄清楚这个问题是来自我还是Paypal方面?