Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (41 sloc) 1.4 KB
<?php
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
require '../vendor/autoload.php';
// For test payments we want to enable the sandbox mode. If you want to put live
// payments through then this setting needs changing to `false`.
$enableSandbox = true;
// PayPal settings. Change these to your account details and the relevant URLs
// for your site.
$paypalConfig = [
'client_id' => 'your-paypal-api-client-id',
'client_secret' => 'your-paypal-api-client-secret',
'return_url' => 'http://example.com/response.php',
'cancel_url' => 'http://example.com/payment-cancelled.html'
];
// Database settings. Change these for your database configuration.
$dbConfig = [
'host' => 'localhost',
'username' => 'user',
'password' => 'secret',
'name' => 'example_database'
];
$apiContext = getApiContext($paypalConfig['client_id'], $paypalConfig['client_secret'], $enableSandbox);
/**
* Set up a connection to the API
*
* @param string $clientId
* @param string $clientSecret
* @param bool $enableSandbox Sandbox mode toggle, true for test payments
* @return \PayPal\Rest\ApiContext
*/
function getApiContext($clientId, $clientSecret, $enableSandbox = false)
{
$apiContext = new ApiContext(
new OAuthTokenCredential($clientId, $clientSecret)
);
$apiContext->setConfig([
'mode' => $enableSandbox ? 'sandbox' : 'live'
]);
return $apiContext;
}
You can’t perform that action at this time.