Laravel 4.2 和贝宝 SDK
Laravel 4.2 and PayPal SDK
谁能告诉我为什么会出现以下错误:
exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'PayPal\Rest\ApiContext' not found'
这是我的控制器代码:
<?php
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\ExecutePayment;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Transaction;
class PaypalPaymentController extends BaseController {
private $_api_context;
public function __construct() {
// setup PayPal api context
$paypal_conf = Config::get('paypal');
$this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
$this->_api_context->setConfig($paypal_conf['settings']);
}
我也不确定服务提供者需要是什么...至少有人可以填写那个空白吗?
如果您使用composer下载PayPal-PHP-SDK,您需要添加include
语句来添加所有类,因为如下所示:
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
require '<location to vendor directory>/vendor/autoload.php';
如果你使用了direct download,你需要添加包含,路径如下:
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
require '<location to PayPal-PHP-SDK directory>/PayPal-PHP-SDK/autoload.php';
我刚刚在 L5 安装上安装了来自 composer 的软件包并且它可以正常工作,所以我认为这对您有帮助:
如果您不使用 composer,请删除与 paypal 相关的所有内容并使用它,这很有帮助.. 很多。
从 composer.json
、composer update
、composer dumpautoload
、php artisan cache:clear
中删除 paypal 包。
重新添加包,我是用"paypal/rest-api-sdk-php": "1.3.*"
做的。 composer update
.
使用 php artisan tinker
测试它,像这样:new PayPal\Rest\ApiContext()
,应该 return 一些描述对象的蓝线。
我真的相信这是作曲家的问题,我在另一个支付包中遇到了同样的问题,但没有命名空间,他们使用 classmap
加载,paypal 使用 psr-0。这是问题:Not namespaced, classmap loaded package required from composer makes php throw Class not found
谁能告诉我为什么会出现以下错误:
exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'PayPal\Rest\ApiContext' not found'
这是我的控制器代码:
<?php
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\ExecutePayment;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Transaction;
class PaypalPaymentController extends BaseController {
private $_api_context;
public function __construct() {
// setup PayPal api context
$paypal_conf = Config::get('paypal');
$this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
$this->_api_context->setConfig($paypal_conf['settings']);
}
我也不确定服务提供者需要是什么...至少有人可以填写那个空白吗?
如果您使用composer下载PayPal-PHP-SDK,您需要添加include
语句来添加所有类,因为如下所示:
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
require '<location to vendor directory>/vendor/autoload.php';
如果你使用了direct download,你需要添加包含,路径如下:
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
require '<location to PayPal-PHP-SDK directory>/PayPal-PHP-SDK/autoload.php';
我刚刚在 L5 安装上安装了来自 composer 的软件包并且它可以正常工作,所以我认为这对您有帮助:
如果您不使用 composer,请删除与 paypal 相关的所有内容并使用它,这很有帮助.. 很多。
从 composer.json
、composer update
、composer dumpautoload
、php artisan cache:clear
中删除 paypal 包。
重新添加包,我是用"paypal/rest-api-sdk-php": "1.3.*"
做的。 composer update
.
使用 php artisan tinker
测试它,像这样:new PayPal\Rest\ApiContext()
,应该 return 一些描述对象的蓝线。
我真的相信这是作曲家的问题,我在另一个支付包中遇到了同样的问题,但没有命名空间,他们使用 classmap
加载,paypal 使用 psr-0。这是问题:Not namespaced, classmap loaded package required from composer makes php throw Class not found