Search code examples
phppdopaypalpaypal-sandboxpaypal-rest-sdk

Paypal SDK Problems with OAuthTokenCredential


I'm having some problems with the PayPal-SDK aplication for developers, i was just trying to follow a tutorial about, to learn how to use it, but i have an error than stop me of continuing and i can't make it to work because of a function.

This is the code:

<?php

use PayPal\Rest\ApiContext;

session_start();

$_SESSION['User_id'] = 1;

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

// API
$api = new ApiContext(
    new OAuthTokenCredential(
        'SomeClientidCode', // Client Id
        'SomeSecretCode' // Secret
        )
    );

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

$db = new PDO('mysql:host=localhost;dbname=paypal', 'root', 'Pass01');

$user = $db->prepare("
    SELECT * FROM user
    WHERE id = :User_id
");

$user->execute(['User_id' => $_SESSION['User_id']]);

$user = $user->fetchObject();
?>

the error in the console is:

[Thu Mar 05 12:36:05.793555 2015] [:error] [pid 480:tid 1756] [client ::1:2820] PHP Fatal error:  Class 'OAuthTokenCredential' not found in C:\\UniServerZ\\www\\PayPal\\scr\\start.php on line 13, referer: http://localhost:1313/index.php

That line is: ' new OAuthTokenCredential( ' in the code i show just up here

Any orientation, question for improve this same question, comment, advice or request of clarification/more info about it, etc[...] than help to reach the solution of the problem would be much apreciated.

Thanks a lot in advance


Solution

  • You did not put in the use statement for OAuthTokenCredential.