-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbootstrap.php
50 lines (41 loc) · 1.4 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?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;
}