Fatal error: Class 'Paypal\\Api\\Payer' not found en sdk Paypal

匿名 (未验证) 提交于 2019-12-03 01:25:01

问题:

I installed PayPal SDK with composer but my php file CHECKOUT.php the error is:

Fatal error: Class 'Paypal\Api\Payer' not found in C:\xampp\htdocs\pagos\checkout.php on line 23

checkout.php:

setPaymentMethod("paypal");  $item = new Item(); $item->setName($descripcion)     ->setCurrency('MXN')     ->setQuantity(1)     ->setPrice($precio); $itemList = new ItemList(); $itemList->setItems([$item]); 

start.php

setConfig([  'mode'=>'sandbox',  'http.ConnectionTimeOut'=>30,  'log.LogEnabled'=>false,  'log.FileName'=>'',  'log.LogLevel'=>'FINE',  'validation.level'=>'log' ]); 

回答1:

Instead of:
use Paypal\Api\Payer;
use Paypal\Api\Item;

Change it to:
use PayPal\Api\Payer;
use PayPal\Api\Item;

Just capitalize the second "P" on the word "PayPal". Hope it works :)



回答2:

I run into this problem too.

My solution was to copy inner lib/PayPal folder

from composer installation or from direct downloaded files package to some directory in src, for example to src/Components.

When add needed PayPal folders to composer :

"psr-4" : {      "PayPal\\" : "src/Components/PayPal/",     "PayPal\\Api\\" : "src/Components/PayPal/Api/",      "PayPal\\Rest\\" : "src/Components/PayPal/Rest/",      "PayPal\\Auth\\" : "src/Components/PayPal/Auth/",     "PayPal\\Exception\\" : "src/Components/PayPal/Exception/" } 

run from command line composer dump-autoload.

When you can use the classes everywhere in your project.

use PayPal\Rest\ApiContext; use PayPal\Auth\OAuthTokenCredential; use PayPal\Api\Payer; use PayPal\Api\Amount; use PayPal\Api\Transaction; use PayPal\Api\RedirectUrls; use PayPal\Api\Payment; use PayPal\Exception\PayPalConnectionException;    if ( isset( $_POST['ppalBtn'] ) ) {      $apiContext = new ApiContext(             new OAuthTokenCredential(     'ClientID',         'ClientSecret'                   )     );        $payer = new Payer();     $payer->setPaymentMethod('paypal');      $amount = new Amount();     $amount->setTotal('1.00');     $amount->setCurrency('USD');      $transaction = new Transaction();     $transaction->setAmount($amount);      $redirectUrls = new RedirectUrls();     $redirectUrls->setReturnUrl("https://domain/redirect.php")         ->setCancelUrl("https://dcancel.php");      $payment = new Payment();     $payment->setIntent('sale')         ->setPayer($payer)         ->setTransactions(array($transaction))         ->setRedirectUrls($redirectUrls);      try {         $payment->create($apiContext);         echo $payment;          echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";     }     catch (\PayPal\Exception\PayPalConnectionException $ex) {         // This will print the detailed information on the exception.         //REALLY HELPFUL FOR DEBUGGING         echo $ex->getData();     } 


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