Updated PayPal but why “Fatal error: Class 'PayPal\REST\ApiContext' not found”?

爷,独闯天下 提交于 2020-01-25 05:15:08

问题


I am moving my PHP application from localhost to online server and I receive an error: Fatal error: Class 'PayPal\REST\ApiContext' not found. I have tired to update the PayPal SDK as suggested in other posts. Still getting this error with the ApiContext. My code for the start file is below. I have implemented the fix described in other posts to no avail. Any help would be appreciated.

<?php

use PayPal\REST\ApiContext;
use PayPal\Auth\OAuthTokenCredential;

session_start();
include('connect.php');

//determine if user signed in

if (isset($_SESSION['uid'])){
$userPAYPAL = $_SESSION['uid'];
} else {
header("Location:../../register.php");
}


require __DIR__ . '/../vendor/autoload.php';

//create new PayPal API context (ERROR OCCURS HERE)
$api = new ApiContext(
new OAuthTokenCredential(

'AZp2HH9aWL2QxjVZRO51N33ZLqweiO5x_GPIyUMWgqLYhe0yxfQSPhJaUkCyqx8OHT',

'EGpHg8K23idpNF895v6Zm4rybajrvAoED6T0As0NUk4q2fhJ7oDv82z1PKTECiHfkl'
)
);

$api->setConfig([
'mode' => 'sandbox',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => false,
'log.FileName' => '',
'log.LogLevel' => 'FINE',
'validation.level' => 'log'

]);

回答1:


I do believe you are seeing the discrepancy due to case sensitivity. You have at the top of your code:

use PayPal\REST\ApiContext;

When it is defined in their code with a Rest like:

use PayPal\Rest\ApiContext;

On a side note, the way I like to use the paypal rest sdk, is when I'm calling any of their objects or methods, I just use the full namespace... like $apiContext = new PayPal\Rest\ApiContext( .. ); and $addr = new PayPal\Api\Address(); etc. That way I don't clash my own code with the use.



来源:https://stackoverflow.com/questions/48671347/updated-paypal-but-why-fatal-error-class-paypal-rest-apicontext-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!