问题
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