致命错误:未捕获PayPal\Exception\PayPalConnectionException:获取Http响应代码403

致命错误:未捕获PayPal\Exception\PayPalConnectionException:获取Http响应代码403,paypal,Paypal,我正在尝试将PayPal checkout集成到Codeigniter中,我已经使用composer安装了PayPal SDK,但它不起作用。基本上,我在这里试图做的是包括一个PayPal智能结帐按钮,登录后它会重定向到我的服务器,在那里我创建了一个订单并执行。我不知道这段代码有什么问题,因为这里看起来一切正常,但仍然会出错。目前我正在使用我的应用程序的沙盒ClientID和secret <?php if ( ! defined('BASEPATH')) exit('No direct

我正在尝试将PayPal checkout集成到Codeigniter中,我已经使用composer安装了PayPal SDK,但它不起作用。基本上,我在这里试图做的是包括一个PayPal智能结帐按钮,登录后它会重定向到我的服务器,在那里我创建了一个订单并执行。我不知道这段代码有什么问题,因为这里看起来一切正常,但仍然会出错。目前我正在使用我的应用程序的沙盒ClientID和secret

 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require './vendor/autoload.php';


use PayPal\Api\Payment;
use PayPal\Api\PaymentExecution;
use PayPal\Api\ExecutePayment;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;




class paymentController extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -  
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */


    public function __construct()
       {
            parent::__construct();


            $this->load->helper('url');
            $this->load->helper('html');
            $this->load->helper('email');
            $this->load->library('session');

            $this->load->helper('form');
            $this->load->library('form_validation');
            $this->load->helper('cookie');
            $this->load->library('cart');




       }
    public function index()
    {
        $this->load->view('payment controller index function');
    }


    public function execute(){
        $apiContext = new \PayPal\Rest\ApiContext(
        new \PayPal\Auth\OAuthTokenCredential(
                    'AVIPqzQ05Njz9589zFa3bn_PcIC-k-rLp0p0JdCjcfot--WtdBu7gLRWbOHRkDhDCODk_tYIHKRG4SCa',     // ClientID
                    'EIus88X-MF7d0ZATg7XSek4JjAtA7WHBAHc3pe0xHRRRzk9_siHEua3wQlXmtQo2a-Xr5hMHS_Osl1eW'      // ClientSecret
                )
        );

        $paymentId = $_GET['paymentId'];
        $payment = payment::get($paymentId, $apiContext);

        $execution = new PaymentExecution();
        $execution->setPayerId($_GET['PayerID']);

        $transaction = new Transaction();
        $amount = new Amount();
        $details = new Details();

        $details->setShipping(2.2)
            ->setTax(1.3)
            ->setSubtotal(17.50);

        $amount->setCurrency('USD');
        $amount->setTotal(21);
        $amount->setDetails($details);
        $transaction->setAmount($amount);

         $execution->addTransaction($transaction);

         $result = $payment->execute($execution, $apiContext);
         print_r($result);




    }
}

您的问题应该提供403消息的更完整的响应日志,包括贝宝调试Id(如果可用)

但在查看代码时,您可能需要添加以下内容:

$apiContext->setConfig(
    array(
        'mode' => 'sandbox',
        'log.LogEnabled' => true,
        'log.FileName' => '../PayPal.log',
        'log.LogLevel' => 'DEBUG', // PLEASE USE `INFO` LEVEL FOR LOGGING IN LIVE ENVIRONMENTS
    )
改编自

如果没有这样的上下文添加,您的代码似乎试图在默认实时模式下使用沙盒ClientID和secret,这将永远不会工作,因此会导致预期的4xx错误



另外,我建议您从v1/PayPal PHP SDK切换到使用更新的v2/orders API for PHP的实现:

您的问题应该提供403消息的更完整的响应日志,包括PayPal调试Id(如果可用)

但在查看代码时,您可能需要添加以下内容:

$apiContext->setConfig(
    array(
        'mode' => 'sandbox',
        'log.LogEnabled' => true,
        'log.FileName' => '../PayPal.log',
        'log.LogLevel' => 'DEBUG', // PLEASE USE `INFO` LEVEL FOR LOGGING IN LIVE ENVIRONMENTS
    )
改编自

如果没有这样的上下文添加,您的代码似乎试图在默认实时模式下使用沙盒ClientID和secret,这将永远不会工作,因此会导致预期的4xx错误


另外,我建议您从v1/PayPal PHP SDK切换到使用更新的v2/orders API for PHP的实现: