-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathindex.php
155 lines (119 loc) · 4.93 KB
/
index.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use QuickBooksOnline\API\DataService\DataService;
$config = include('config.php');
session_start();
$dataService = DataService::Configure(array(
'auth_mode' => 'oauth2',
'ClientID' => $config['client_id'],
'ClientSecret' => $config['client_secret'],
'RedirectURI' => $config['oauth_redirect_uri'],
'scope' => $config['oauth_scope'],
'baseUrl' => "development"
));
$OAuth2LoginHelper = $dataService->getOAuth2LoginHelper();
$authUrl = $OAuth2LoginHelper->getAuthorizationCodeURL();
// Store the url in PHP Session Object;
$_SESSION['authUrl'] = $authUrl;
//set the access token using the auth object
if (isset($_SESSION['sessionAccessToken'])) {
$accessToken = $_SESSION['sessionAccessToken'];
$accessTokenJson = array('token_type' => 'bearer',
'access_token' => $accessToken->getAccessToken(),
'refresh_token' => $accessToken->getRefreshToken(),
'x_refresh_token_expires_in' => $accessToken->getRefreshTokenExpiresAt(),
'expires_in' => $accessToken->getAccessTokenExpiresAt()
);
$dataService->updateOAuth2Token($accessToken);
$oauthLoginHelper = $dataService -> getOAuth2LoginHelper();
$CompanyInfo = $dataService->getCompanyInfo();
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="apple-touch-icon icon shortcut" type="image/png" href="https://plugin.intuitcdn.net/sbg-web-shell-ui/6.3.0/shell/harmony/images/QBOlogo.png">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="views/common.css">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script>
var url = '<?php echo $authUrl; ?>';
var OAuthCode = function(url) {
this.loginPopup = function (parameter) {
this.loginPopupUri(parameter);
}
this.loginPopupUri = function (parameter) {
// Launch Popup
var parameters = "location=1,width=800,height=650";
parameters += ",left=" + (screen.width - 800) / 2 + ",top=" + (screen.height - 650) / 2;
var win = window.open(url, 'connectPopup', parameters);
var pollOAuth = window.setInterval(function () {
try {
if (win.document.URL.indexOf("code") != -1) {
window.clearInterval(pollOAuth);
win.close();
location.reload();
}
} catch (e) {
console.log(e)
}
}, 100);
}
}
var apiCall = function() {
this.getCompanyInfo = function() {
/*
AJAX Request to retrieve getCompanyInfo
*/
$.ajax({
type: "GET",
url: "apiCall.php",
}).done(function( msg ) {
$( '#apiCall' ).html( msg );
});
}
this.refreshToken = function() {
$.ajax({
type: "POST",
url: "refreshToken.php",
}).done(function( msg ) {
});
}
}
var oauth = new OAuthCode(url);
var apiCall = new apiCall();
</script>
</head>
<body>
<div class="container">
<h1>
<a href="http://developer.intuit.com">
<img src="views/quickbooks_logo_horz.png" id="headerLogo">
</a>
</h1>
<hr>
<div class="well text-center">
<h1>QuickBooks HelloWorld sample application</h1>
<h2>Demonstrate Connect to QuickBooks flow and API Request</h2>
<br>
</div>
<p>If there is no access token or the access token is invalid, click the <b>Connect to QuickBooks</b> button below.</p>
<pre id="accessToken">
<style="background-color:#efefef;overflow-x:scroll"><?php
$displayString = isset($accessTokenJson) ? $accessTokenJson : "No Access Token Generated Yet";
echo json_encode($displayString, JSON_PRETTY_PRINT); ?>
</pre>
<a class="imgLink" href="#" onclick="oauth.loginPopup()"><img src="views/C2QB_green_btn_lg_default.png" width="178" /></a>
<hr />
<h2>Make an API call</h2>
<p>If there is no access token or the access token is invalid, click either the <b>Connect to QuickBooks</b> button above.</p>
<pre id="apiCall"></pre>
<button type="button" class="btn btn-success" onclick="apiCall.getCompanyInfo()">Get Company Info</button>
<hr />
</div>
</body>
</html>