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.