/** * This sample file demonstrates to flow when you want to authorize your application * to connect to Afosto on behalf of the Afosto user. * * Session storage is used to demonstrate the storage of the accessToken and * demostrate persistence of the authorization */ namespace Afosto\ApiClient; use Afosto\ApiClient\Components\Storage\SessionStorage; //Change these paths accordingly require_once dirname(__FILE__) . '/vendor/autoload.php'; require_once dirname(__FILE__) . '/config.php'; //Set the caching parameters $storage = new SessionStorage(); App::run($storage, CLIENT_ID, CLIENT_SECRET); //Verify if we allready have a token or not, otherwise try to connect if (App::getInstance()->hasToken()) { //Interact with the API echo App::getInstance()->getAccessToken(); exit; } else { if (isset($_GET['code'])) { //Obtain the code from the uri App::getInstance()->authorize($_GET['code']); exit('Authorized, you can refresh the page as the accessToken is now stored in the cache'); } else { //No code give, no authorzation in place, redirect to the application to //obtain grant header('Location: ' . App::getInstance()->getAuthorizationUrl(REDIRECT_URI)); }
<?php /** * This sample file demonstrates the functionality to receive incoming * webhooks. * Use this file as a starting point to receive incoming webhooks from the API. * * Developing on your local machine? Install ngrok to transfer webhooks to your local machine. * https://ngrok.com/ */ namespace Afosto\ApiClient; use Afosto\ApiClient\Components\Storage\SessionStorage; require_once dirname(__FILE__) . '/vendor/autoload.php'; require_once dirname(__FILE__) . '/config.php'; $cache = new SessionStorage(); App::run($cache, CLIENT_ID, CLIENT_SECRET); $object = App::getWebhookModel(); switch ($object->getName()) { case 'Product': //Do things with this product break; case 'Sale': //Do things with this sale }