if ($e->getCode() == 401) { // access denied, in case the access token is expired, try to refresh it try { // refresh tokens using the session saved refresh token $client->refreshAccessToken($session['refresh_token']); $_SESSION['sdk']['access_token'] = $client->getAccessToken(); $_SESSION['sdk']['refresh_token'] = $client->getRefreshToken(); // Sesssion refreshed with valid tokens header("Location: " . $client->getCurrentURI(array(), array('code', 'login', 'error', 'logout', 'order_id', 'spid_page'))); exit; } catch (Exception $e2) { /* falls back to $e message bellow */ } } if ($e->getCode() == 400) { header("Location: " . $client->getLoginURI(array('redirect_uri' => $client->getCurrentURI(array(), array('logout', 'error', 'code', 'order_id', 'spid_page'))))); exit; } // API exception, show message, remove session as it is probably not usable unset($_SESSION['sdk']); echo '<h3 id="error" style="color:red">' . $e->getCode() . ' : ' . $e->getMessage() . '</h3>'; } echo '<p><a id="login-link" href="' . $client->getAccountURI(array('redirect_uri' => $client->getCurrentURI(array(), array('logout', 'error', 'code', 'order_id', 'spid_page')))) . '">My Account</a></p>'; // Show a logout link echo '<p><a id="login-link" href="' . $client->getLogoutURI(array('redirect_uri' => $client->getCurrentURI(array('logout' => 1), array('error', 'code', 'order_id', 'spid_page')))) . '">Logout</a></p>'; echo '<p><a id="login-link" href="' . $client->getPurchaseURI(array('redirect_uri' => $client->getCurrentURI(array(), array('logout', 'error', 'code', 'order_id', 'spid_page')), 'cancel_redirect_uri' => $client->getCurrentURI(array('cancel' => 1), array('logout', 'error', 'code', 'order_id', 'spid_page')))) . '">Buy something</a> (standard checkout flow)</p>'; echo '<p><a id="login-link" href="' . $client->getPurchaseURI(array('campaign_id' => 1, 'redirect_uri' => $client->getCurrentURI(array('cameback' => 2), array('logout', 'error', 'code', 'order_id', 'spid_page')), 'cancel_redirect_uri' => $client->getCurrentURI(array('cancel' => 1), array('logout', 'error', 'code', 'order_id', 'spid_page')))) . '">Campaign Flow</a> (checkout flow with campaign specified</p>'; } else { // No session, user must log in echo '<h3 id="message">Please log in</h3>'; // Show a login link
?> ">Account page</a></li> <li><a href="<?php echo $client->getPurchaseHistoryURI(); ?> ">Purchase history page</a></li> </ul> </div> </div> <div id="output"> <img id="loader" src="images/loader-small.gif" alt="loading.." /> <pre class="prettyprint"> </pre> </div> <?php } else { ?> <div style="text-align:center;margin-top:200px;"> <strong><a href="<?php echo $client->getLoginURI(array('redirect_uri' => $client->getCurrentURI(array(), array('logout')))); ?> ">Login</a></strong> </div> <?php } ?> </body> </html>