A simple Ebay class that uses OAuth 2.0 Authentication and PSR-16 cache
Basic usage: First initialize the EbayRequest. I use Redis for cache driver.
<?php
use Phpfastcache\Helper\Psr16Adapter;
use BrainStorm\Ebay\EbayRequest;
$args = [
'env' => 'production', //use sandbox for test
'devId' => '', //devID param from Ebay
'appId' => '', //appID param from Ebay
'certId' => '', //certID param from Ebay
'RuName' => '', //RuName param from Ebay
'version' => '967', //Ebay API Version
'siteid' => '0', //SiteID (See Ebay for other SiteID)
'scope' => 'https://api.ebay.com/oauth/api_scope https://api.ebay.com/oauth/api_scope/buy.order.readonly https://api.ebay.com/oauth/api_scope/buy.guest.order https://api.ebay.com/oauth/api_scope/sell.marketing.readonly https://api.ebay.com/oauth/api_scope/sell.marketing https://api.ebay.com/oauth/api_scope/sell.inventory.readonly https://api.ebay.com/oauth/api_scope/sell.inventory https://api.ebay.com/oauth/api_scope/sell.account.readonly https://api.ebay.com/oauth/api_scope/sell.account https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly https://api.ebay.com/oauth/api_scope/sell.fulfillment https://api.ebay.com/oauth/api_scope/sell.analytics.readonly https://api.ebay.com/oauth/api_scope/sell.marketplace.insights.readonly https://api.ebay.com/oauth/api_scope/commerce.catalog.readonly https://api.ebay.com/oauth/api_scope/buy.shopping.cart https://api.ebay.com/oauth/api_scope/buy.offer.auction https://api.ebay.com/oauth/api_scope/commerce.identity.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.email.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.phone.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.address.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.name.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.status.readonly https://api.ebay.com/oauth/api_scope/sell.finances https://api.ebay.com/oauth/api_scope/sell.item.draft https://api.ebay.com/oauth/api_scope/sell.payment.dispute https://api.ebay.com/oauth/api_scope/sell.item https://api.ebay.com/oauth/api_scope/sell.reputation https://api.ebay.com/oauth/api_scope/sell.reputation.readonly'
];
$Psr16Adapter = new Psr16Adapter('Redis');
$client = new EbayRequest($args, $Psr16Adapter);
/**
* Do your stuff with $data
*/
After, you need an user account to generate token to access API. The user must click to the link generated by:
echo $client->getUrlUserConsent();
You must configure a return URL in your Ebay application (from Ebay panel) that point to a route that cointains this code:
$usercode = $_GET['code'];
$expire = $_GET['expires_in'];
$refresh_token = $client->setAuthToken($usercode, $expire);
/**
* Store $refresh_token into DB
*/
You must save the $refresh_token into a safe place (DB preferred). It will be used to generate a new user token for every API call (after user token expire). This operations are needed to generate the refresh token (if not exists or is expired). With the refresh token, you can call the Ebay API that you need:
<?php
use Phpfastcache\Helper\Psr16Adapter;
use BrainStorm\Ebay\EbayRequest;
use BrainStorm\Ebay\Trading\GetCategories;
$args = [
'env' => 'production', //use sandbox for test
'devId' => '', //devID param from Ebay
'appId' => '', //appID param from Ebay
'certId' => '', //certID param from Ebay
'RuName' => '', //RuName param from Ebay
'version' => '967', //Ebay API Version
'siteid' => '0', //SiteID (See Ebay for other SiteID)
'scope' => 'https://api.ebay.com/oauth/api_scope https://api.ebay.com/oauth/api_scope/buy.order.readonly https://api.ebay.com/oauth/api_scope/buy.guest.order https://api.ebay.com/oauth/api_scope/sell.marketing.readonly https://api.ebay.com/oauth/api_scope/sell.marketing https://api.ebay.com/oauth/api_scope/sell.inventory.readonly https://api.ebay.com/oauth/api_scope/sell.inventory https://api.ebay.com/oauth/api_scope/sell.account.readonly https://api.ebay.com/oauth/api_scope/sell.account https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly https://api.ebay.com/oauth/api_scope/sell.fulfillment https://api.ebay.com/oauth/api_scope/sell.analytics.readonly https://api.ebay.com/oauth/api_scope/sell.marketplace.insights.readonly https://api.ebay.com/oauth/api_scope/commerce.catalog.readonly https://api.ebay.com/oauth/api_scope/buy.shopping.cart https://api.ebay.com/oauth/api_scope/buy.offer.auction https://api.ebay.com/oauth/api_scope/commerce.identity.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.email.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.phone.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.address.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.name.readonly https://api.ebay.com/oauth/api_scope/commerce.identity.status.readonly https://api.ebay.com/oauth/api_scope/sell.finances https://api.ebay.com/oauth/api_scope/sell.item.draft https://api.ebay.com/oauth/api_scope/sell.payment.dispute https://api.ebay.com/oauth/api_scope/sell.item https://api.ebay.com/oauth/api_scope/sell.reputation https://api.ebay.com/oauth/api_scope/sell.reputation.readonly'
];
$Psr16Adapter = new Psr16Adapter('Redis');
$client = new EbayRequest($args, $Psr16Adapter);
$trading = new GetCategories($client);
echo $trading->doRequest($refresh_token);