-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.php
More file actions
57 lines (45 loc) · 1.81 KB
/
solution.php
File metadata and controls
57 lines (45 loc) · 1.81 KB
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
51
52
53
54
55
56
57
<?php
session_start();
require_once './vendor/autoload.php';
$infusionsoft = new \Infusionsoft\Infusionsoft(array(
'clientId' => 'G0IfUajhA6U0MYqiFlN8AQCYOoo6KyGJ',
'clientSecret' => '7HuC8MfmkDEpGWt4',
'redirectUri' => 'http://localhost/ian-test/solution.php',
));
// By default, the SDK uses the Guzzle HTTP library for requests. To use CURL,
// you can change the HTTP client by using following line:
// $infusionsoft->setHttpClient(new \Infusionsoft\Http\CurlClient());
// If the serialized token is available in the session storage, we tell the SDK
// to use that token for subsequent requests.
if (isset($_SESSION['token'])) {
$infusionsoft->setToken(unserialize($_SESSION['token']));
}
// If we are returning from Infusionsoft we need to exchange the code for an
// access token.
if (isset($_GET['code']) and !$infusionsoft->getToken()) {
$infusionsoft->requestAccessToken($_GET['code']);
// Save the serialized token to the current session for subsequent requests
$_SESSION['token'] = serialize($infusionsoft->getToken());
}
function updateStoreCode($infusionsoft) {
$contactId = $_GET["contactId"];
$storeCode = $_GET["storeCode"];
$data = array('_StoreCode' => '1234');
$infusionsoft->contacts('xml')->update($contactId, $data);
}
if ($infusionsoft->getToken()) {
try {
$task = updateStoreCode($infusionsoft);
}
catch (\Infusionsoft\TokenExpiredException $e) {
// If the request fails due to an expired access token, we can refresh
// the token and then do the request again.
$infusionsoft->refreshAccessToken();
// Save the serialized token to the current session for subsequent requests
$_SESSION['token'] = serialize($infusionsoft->getToken());
$task = updateStoreCode($infusionsoft);
}
}
else {
echo '<a href="' . $infusionsoft->getAuthorizationUrl() . '">Click here to authorize</a>';
}