Error: Fatal error: Class 'Paypal \ Api \ Payer' not found

2

I have the following problem:

I've imported the paypal library ( paypal/rest-api-sdk-php ) with composer , but I'm getting error the following

  

"error Fatal error: Class 'Paypal \ Api \ Payer' not found"

Start.php

<?php
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
// Used for composer based installation
require __DIR__  . '/vendor/autoload.php';
// Use below for direct download installation
// require __DIR__  . '/PayPal-PHP-SDK/autoload.php';

$apiContext = new \PayPal\Rest\ApiContext(
    new \PayPal\Auth\OAuthTokenCredential(
        'hjkshkhkjkhjkjhaskjhdkjhasdjkhashdhegrfyrfyrfr',     // ClientID
        'hkshkahskjdhaskjhdkjahsdkjahskdjhakjshdkjashdkjahsdkjhaskjdhajkshdkjasd'      // ClientSecret
    )
);

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

And I send it from a form with the action "checkout.php":

Checkout.php

<?php
use Paypal\Api\Payer;
use Paypal\Api\Item;

require 'start.php';

if (!isset($_POST['descripcion'], $_POST['precio'])) {
    die();
}

$descripcion = $_POST['descripcion'];
$precio = $_POST['precio'];

$total = $precio;

$payer = new Payer();
$payer->setPaymentMethod("paypal");

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

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

Any ideas?

Now try putting with require , include .

In the start.php part, try putting:

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

Edited on 09/14/2014 Resolved:

As I do not charge require __DIR__ . '/PayPal-PHP-SDK/autoload.php'; what I did was the require from the location of the API:

require 'PayPal-PHP-SDK/paypal/rest-api-sdk-php/lib/PayPal/Api/Payer.php';
require 'PayPal-PHP-SDK/paypal/rest-api-sdk-php/lib/PayPal/Api/Item.php';

Greetings.

    
asked by Alexcode89 08.09.2016 в 19:54
source

0 answers