diff --git a/README.md b/README.md new file mode 100644 index 0000000..b613e03 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Shoptet SDK +Simple Shoptet SDK. + +## Installation +```shell +composer require adbros/shoptet-sdk +``` + +## Usage + +```php +getOAuthAccessToken( + code: $_GET['code'], + redirectUri: 'https://example.com/install', +); + +// Get apiAccessToken before API call +$apiAccessToken = $oAuth->getApiAccessToken( + oAuthAccessToken: $oAuthAccessToken->accessToken, +); + +// Initialize SDK +$sdk = new Sdk( + apiAccessToken: $apiAccessToken->accessToken, +); + +// Get customers +$page = 1; + +do { + $customers = $sdk->getCustomers($page); + + foreach ($customers->customers as $customer) { + // Get customer + $customerDetail = $sdk->getCustomer($customer->guid); + } +} while ($page++ < $customers->paginator->pageCount); +``` diff --git a/src/OAuth.php b/src/OAuth.php index 432148d..1feb8fc 100644 --- a/src/OAuth.php +++ b/src/OAuth.php @@ -14,14 +14,20 @@ class OAuth private Client $httpClient; + private readonly string $oAuthAccessTokenUrl; + + private readonly string $apiAccessTokenUrl; + public function __construct( private readonly string $clientId, private readonly string $clientSecret, - private readonly string $oAuthAccessTokenUrl, - private readonly string $apiAccessTokenUrl, + private readonly string $eshopUrl, ) { $this->httpClient = new Client(); + + $this->oAuthAccessTokenUrl = rtrim($this->eshopUrl, '/') . '/action/ApiOAuthServer/token'; + $this->apiAccessTokenUrl = rtrim($this->eshopUrl, '/') . '/action/ApiOAuthServer/getAccessToken'; } public function getOAuthAccessToken(string $code, string $redirectUri): OAuthAccessToken // @phpcs:ignore Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps