0

I am just getting started with Paypal's API and PHP. I have mostly using this as a reference: https://github.com/paypal/PayPal-PHP-SDK

Right now, I am just attempting to get everything working - to make a first sample call, but I have run into an issue loading the autoload.php file. Here is my current code:

test.php

<?php
require __DIR__ . '/bootstrap.php';

use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;

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

$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal(5.55);

$transaction = new Transaction();
$transaction->setAmmount($amount)->setDescription("Purchase from Leisurely Diversion")->setInvoiceNumber(uniqid());

$redirectURLs = new RedirectUrls();
$redirectURLs->setReturnUrl("confirmation.php")->setCancelUrl("index.php");

$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setTransactions(array($transaction))->setRedirectUrls($redirectURLs);

try {
$payment->create($apiContext);
} catch(Exception $e) {
echo "<h2> Error Sending Payment!</h2>";
}
?>

and bootstrap.php

<?php
require __DIR__ . '/PayPal-PHP-SDK/autoload.php';

use PayPal\Auth\OAuthTokenCredential;
use PayPal\Rest\ApiContext;

$clientID = 'AmyClientID';
$secretID = 'mySecredID';

$apiContext = setContext($clientID, $secretID);
return $apiContext;

function setContext($client, $secret) {

$apiContext = new ApiContext(
new OAuthTokenCredential($client, $secret)
); 

$apiContext->setConfig(
array(
'mode' => 'sandbox',
'log.LogEnabled' => true,
'log.LogFileName' => '../PayPal.log',
'log.LogLeve' => 'DEBUG',
)
);

return $apiContext;

}
?>

I am receiving the following error when I execute test.php:

Warning: require(C:\xampp\htdocs\leisurelydiversion\PayPal-PHP-SDK\autoload.php): failed to open stream: Permission denied in C:\xampp\htdocs\leisurelydiversion\bootstrap.php on line 2

Fatal error: require(): Failed opening required 'C:\xampp\htdocs\leisurelydiversion/PayPal-PHP-SDK/autoload.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\leisurelydiversion\bootstrap.php on line 2

I am really very new to interacting with PayPal's API and REST in general, so I definitely would appreciate any guidance.

Also, I did the manual install rather than using composer.

Using Windows Explorer, I set the file to allow all users full access. I checked the PHP settings - all appears fine. Still no success.

KellyM
  • 2,472
  • 6
  • 46
  • 90
  • According to the docs, autoload.php is shipped with direct download release of PayPal SDK. Can you see the file in the folder? What if the error is right and your permissions are broken? – Denis Mysenko May 17 '16 at 00:14
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew May 17 '16 at 13:33
  • I can see the file. I have set the permissions to Full Control for all users with no success. Whenever I navigate directly to the file in my browser, I get this: Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Fatal error: Unknown: Failed opening required 'C:/xampp/htdocs/leisurelydiversion/Paypal-PHP-SDK/autoload.php' (include_path='.;C:\xampp\php\PEAR') in Unknown on line 0 – KellyM May 19 '16 at 00:19
  • did you echo the full path that you are including as mentioned in step 1 of the troubleshooting guide ? – Vic Seedoubleyew May 19 '16 at 19:37

0 Answers0