コード例 #1
0
 public static function run()
 {
     $bol_api_key = '0A1C1E282CB14EF2BB8722AD2FABAABB';
     $bol_api_format = 'json';
     $bol_api_debug_mode = 0;
     $bol_api_library_version = 'v.2.0.0';
     self::$bol_partner_site_id = '12345';
     self::$apiClient = new Client($bol_api_key, $bol_api_format, $bol_api_debug_mode);
     $servername = str_replace("www.", "", $_SERVER['SERVER_NAME']);
     self::$rooturl = 'http://' . $servername . $_SERVER['SCRIPT_NAME'];
     // convert html characters in $_REQUEST params for Cross-site scripting (XSS)
     foreach ($_REQUEST as $key => $value) {
         $params[$key] = htmlspecialchars($value);
     }
     // get action param for which data to get or post
     $action = isset($params['action']) ? $params['action'] : "search";
     switch ($action) {
         case 'default':
             self::ping();
             break;
         case 'getproduct':
             self::getProduct(false, $params);
             break;
         case 'getproductraw':
             self::getProduct(true, $params);
             break;
         case 'getrecommendations':
             self::getRecommendations(false, $params);
             break;
         case 'getrecommendationsraw':
             self::getRecommendations(true, $params);
             break;
         case 'getrelatedproducts':
             self::getRelatedProducts(false, $params);
             break;
         case 'getrelatedproductsraw':
             self::getRelatedProducts(true, $params);
             break;
         case 'getoffer':
             self::getOffer(false, $params);
             break;
         case 'getofferraw':
             self::getOffer(true, $params);
             break;
         case 'getlists':
             self::getLists(false, $params);
             break;
         case 'getlistsraw':
             self::getLists(true, $params);
             break;
         case 'search':
             return self::search(false, $params);
             break;
         case 'searchraw':
             self::search(true, $params);
             break;
         case 'sellerlists':
             self::getSellerlists(false, $params);
             break;
         case 'sellerlistsraw':
             self::getSellerlists(true, $params);
             break;
         case 'postbasket':
             self::postBasket();
             break;
         case 'getbasket':
             self::getBasket();
             break;
         case 'getbasketraw':
             self::getBasket(true);
             break;
         case 'updatequantitybasket':
             self::updateQuantityBasket(false, $params);
             break;
         case 'removefrombasket':
             self::removefromBasket(false);
             break;
         case 'addanotheritemtobasket':
             self::addAnotherItemToBasket(false, $params);
             break;
         case 'authtoken':
             self::getAuthTokens(false);
             break;
         case 'authtokenraw':
             self::getAuthtokens(true);
             break;
         case 'authtokenSuccess':
             self::getAuthtokensSuccess();
             break;
         case 'authtokenError':
             self::getAuthtokensError();
             break;
         case 'login':
             self::getLogin(false, $params);
             break;
         case 'getwishlist':
             self::getWishlist(false);
             break;
         case 'getwishlistraw':
             self::getWishlist(true);
             break;
         case 'postwishlist':
             self::postWishlist(false);
             break;
         case 'deletewishlist':
             self::deleteWishlist();
             break;
         case 'setRefferer':
             self::setRefferer(false);
             break;
         case 'setReffererraw':
             self::setRefferer(true);
             break;
         case 'setSession':
             self::setSession();
             break;
         case 'destroySession':
             self::destroySession();
             break;
     }
 }
コード例 #2
0
 public static function run()
 {
     $bol_api_key = 'YOUR_API_KEY_HERE';
     $bol_api_format = 'json';
     $bol_api_debug_mode = 0;
     $bol_api_library_version = 'v.2.0.0';
     self::$bol_partner_site_id = '12345';
     self::$apiClient = new Client($bol_api_key, $bol_api_format, $bol_api_debug_mode);
     $servername = str_replace("www.", "", $_SERVER['SERVER_NAME']);
     self::$rooturl = 'http://' . $servername . $_SERVER['SCRIPT_NAME'];
     print '<html><body style="margin:20px;"><h4>PHP example code</h4>';
     print "In this example you can test the following calls from the bol.com Open API (Version: " . $bol_api_library_version . " API version: 4):";
     print '<ul>';
     print '<li><a href="' . self::$rooturl . '?action=getproduct">GET /catalog/v4/products/</a> (<a href="' . self::$rooturl . '?action=getproductraw">* full response</a>)</li>';
     print '<li><a href="' . self::$rooturl . '?action=getrecommendations">GET /catalog/v4/recommendations/</a> (<a href="' . self::$rooturl . '?action=getrecommendationsraw">* full response</a>)</li>';
     print '<li><a href="' . self::$rooturl . '?action=getrelatedproducts">GET /catalog/v4/relatedproducts/</a> (<a href="' . self::$rooturl . '?action=getrelatedproductsraw">* full response</a>)</li>';
     print '<li><a href="' . self::$rooturl . '?action=getoffer">GET /catalog/v4/offers/</a> (<a href="' . self::$rooturl . '?action=getofferraw">* full response</a>)</li>';
     print '<li><a href="' . self::$rooturl . '?action=getlists">GET /catalog/v4/lists/</a> (<a href="' . self::$rooturl . '?action=getlistsraw">* full response</a>)</li>';
     print '<li><a href="' . self::$rooturl . '?action=search">GET /catalog/v4/search/</a> (<a href="' . self::$rooturl . '?action=searchraw">* full response</a>)</li>';
     print '<li><a href="' . self::$rooturl . '?action=setRefferer">PUT /checkout/v4/referrers/</a></li>';
     print '<li><a href="' . self::$rooturl . '?action=setSession">GET /accounts/v4/sessions/</a></li>';
     print '<li>Basket calls example steps:</li>';
     print '<ul>';
     print '<li><strong>Step 1: Get a session (above /accounts/v4/sessions/ call) for an anonymous basket or auth for your personal basket (below /accounts/v4/authtokens call) if you haven\'t already.</strong></li>';
     print '<li><strong>Step 2: Add item to basket</strong> <a href="' . self::$rooturl . '?action=postbasket">POST /checkout/v4/baskets/</a></li>';
     print '<li><strong>Step 3: Get contents of basket</strong> <a href="' . self::$rooturl . '?action=getbasket">GET /checkout/v4/baskets/</a>  (<a href="' . self::$rooturl . '?action=getbasketraw">* full response</a>)</li>';
     print '<li><strong>Step 4: Update quatity with to 3 items</strong> <a href="' . self::$rooturl . '?action=updatequantitybasket&quantity=3">PUT /checkout/v4/baskets/{basketItemId}/{quantity}</a></li>';
     print '<li><strong>Step 5: Add another item to the basket</strong> <a href="' . self::$rooturl . '?action=addanotheritemtobasket">POST /checkout/v4/baskets/</a></li>';
     print '<li><strong>Step 6: Remove item from basket</strong> <a href="' . self::$rooturl . '?action=removefrombasket">DELETE /checkout/v4/baskets/{basketItemId}</a></li>';
     print '<li><strong>Step 7: Deeplink to</strong> <a href="http://partner.bol.com/click/click?p=1&t=url&s=123456&f=API&url=https%3A%2F%2Fafrekenen.bol.com%2Fnl%2Fwinkelwagentje%2Fdirect-toevoegen%3Freturnurl%3Dhttp%3A%2F%2Fdevelopers.bol.com%2Fexamples%2Fphpexamplecodelibrary%2F%26name%3DMy%2Bshop%26logoid%3D51%26siteid%3D123456%26openapisessionid%3D' . $_SESSION['sessionid'] . '" target="_BLANK">the checkout based on session id</a></li>';
     print '</ul>';
     print '<li>Wishlist calls example steps:</li>';
     print '<ul>';
     print '<li><strong>Step 1: Get a session (above /accounts/v4/sessions/ call) for an anonymous wishlist or auth for your personal wishlist (below /accounts/v4/authtokens call) if you haven\'t already.</strong></li>';
     print '<li><strong>Step 3: Add item to wishlist</strong> <a href="' . self::$rooturl . '?action=postwishlist">POST /accounts/v4/wishlists/</a></li>';
     print '<li><strong>Step 2: Get contents of wishlist</strong> <a href="' . self::$rooturl . '?action=getwishlist">GET /accounts/v4/wishlists/</a> (<a href="' . self::$rooturl . '?action=getwishlistraw">* full response</a>)</li>';
     print '<li><strong>Step 4: Remove item from wishlist</strong> <a href="' . self::$rooturl . '?action=deletewishlist">DELETE /accounts/v4/wishlists/</a></li>';
     print '</ul>';
     print '<li>Auth for Basket and Wishlist calls steps:</li>';
     print '<ul>';
     print '<li><strong>Step 1: get private auth token and auth url</strong> <a href="' . self::$rooturl . '?action=authtoken">POST /accounts/v4/authtokens/</a> (<a href="' . self::$rooturl . '?action=authtokenraw">* full response</a>)</li>';
     print '<li><strong>Step 2: Authorise on bol.com with url from Step 1</strong></li>';
     print '<li><strong>Step 3: Get authorized session from via API</strong> <a href="' . self::$rooturl . '?action=login&privatetoken=' . $_SESSION['privatetoken'] . '">POST /auth/v4/login/</a></li>';
     print '<li><strong>Optional step 4: Remove all current active browser sessions</strong> <a href="' . self::$rooturl . '?action=destroySession">Call session_destroy() in php</a></li>';
     print '</ul>';
     print '</ul>';
     print "See the V4 beta documentation <a href='http://developers.bol.com/documentatie/handleiding-v4-beta-calls' target='_blank'>here</a>. Download this example on <a href='https://github.com/devbolcom/phpexamplecode-v4'>https://github.com/devbolcom/phpexamplecode-v4</a>.<br>";
     print '----';
     // convert html characters in $_REQUEST params for Cross-site scripting (XSS)
     foreach ($_REQUEST as $key => $value) {
         $params[$key] = htmlspecialchars($value);
     }
     // get action param for which data to get or post
     $action = isset($params['action']) ? $params['action'] : "default";
     switch ($action) {
         case 'default':
             self::ping();
             break;
         case 'getproduct':
             self::getProduct(false, $params);
             break;
         case 'getproductraw':
             self::getProduct(true, $params);
             break;
         case 'getrecommendations':
             self::getRecommendations(false, $params);
             break;
         case 'getrecommendationsraw':
             self::getRecommendations(true, $params);
             break;
         case 'getrelatedproducts':
             self::getRelatedProducts(false, $params);
             break;
         case 'getrelatedproductsraw':
             self::getRelatedProducts(true, $params);
             break;
         case 'getoffer':
             self::getOffer(false, $params);
             break;
         case 'getofferraw':
             self::getOffer(true, $params);
             break;
         case 'getlists':
             self::getLists(false, $params);
             break;
         case 'getlistsraw':
             self::getLists(true, $params);
             break;
         case 'search':
             self::search(false, $params);
             break;
         case 'searchraw':
             self::search(true, $params);
             break;
         case 'sellerlists':
             self::getSellerlists(false, $params);
             break;
         case 'sellerlistsraw':
             self::getSellerlists(true, $params);
             break;
         case 'postbasket':
             self::postBasket();
             break;
         case 'getbasket':
             self::getBasket();
             break;
         case 'getbasketraw':
             self::getBasket(true);
             break;
         case 'updatequantitybasket':
             self::updateQuantityBasket(false, $params);
             break;
         case 'removefrombasket':
             self::removefromBasket(false);
             break;
         case 'addanotheritemtobasket':
             self::addAnotherItemToBasket(false, $params);
             break;
         case 'authtoken':
             self::getAuthTokens(false);
             break;
         case 'authtokenraw':
             self::getAuthtokens(true);
             break;
         case 'authtokenSuccess':
             self::getAuthtokensSuccess();
             break;
         case 'authtokenError':
             self::getAuthtokensError();
             break;
         case 'login':
             self::getLogin(false, $params);
             break;
         case 'getwishlist':
             self::getWishlist(false);
             break;
         case 'getwishlistraw':
             self::getWishlist(true);
             break;
         case 'postwishlist':
             self::postWishlist(false);
             break;
         case 'deletewishlist':
             self::deleteWishlist();
             break;
         case 'setRefferer':
             self::setRefferer(false);
             break;
         case 'setReffererraw':
             self::setRefferer(true);
             break;
         case 'setSession':
             self::setSession();
             break;
         case 'destroySession':
             self::destroySession();
             break;
     }
 }