I'm having this problem where ther Paypal API is not loading on my server but it loads completely normal on my localhost. I really don't know what and where it went wrong. Everything is the same as I upload files from my localhost to the server, nothing change and it's exactly the same files.
When making a payment using Paypal REST API, I had this error on my server but not on my localhost.
Fatal error: Class 'PayPal\Api\item' not found in /var/www/test.my-domain.com/public_html/controllers/credits.php on line 24
My code as below:
require_once('./inc/lib/paypal/autoload.php');
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'hidden-clientid',// ClientID
'hidden-secret'// ClientSecret
)
);
if (isset($_POST['checkout'])) {
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
$item = new \PayPal\Api\item();
$item->setName('Top Up')
->setDescription('My account.')
->setCurrency('USD')
->setQuantity(1)
->setTax(0)
->setPrice(10);
$itemList = new \PayPal\Api\itemList();
$itemList->setItems(array($item));
$details = new \PayPal\Api\details();
$details->setShipping("0")
->setTax("0")
->setSubtotal(10);
$amount = new \PayPal\Api\amount();
$amount->setCurrency("USD")
->setTotal(10)
->setDetails($details);
$transaction = new \PayPal\Api\transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Top up account")
->setInvoiceNumber(uniqid());
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl("http://".$_SERVER["HTTP_HOST"].$web_path."credits/done?status=success");
$redirectUrls->setCancelUrl("http://".$_SERVER["HTTP_HOST"].$web_path."credits/done?status=cancel");
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
$response = $payment->create($apiContext);
$redirectUrl = $response->links[1]->href;
header( "Location: $redirectUrl" );
The weird part is that it goes through $payer->setPaymentMethod('paypal');
But it does not pass at $item = new \PayPal\Api\item();
All code are the same as my localhost and it works on my localhost. The Paypal API is also uploaded on my server on the exact location (/inc/lib/paypal/).