diff --git a/config/shopify.php b/config/shopify.php index 2ef3800..3c2ddce 100644 --- a/config/shopify.php +++ b/config/shopify.php @@ -5,14 +5,9 @@ 'credentials' => [ /* - * The API key from private app credentials. + * The API access token from the private app. */ - 'api_key' => env('SHOPIFY_API_KEY', ''), - - /* - * The password from private app credentials. - */ - 'password' => env('SHOPIFY_PASSWORD', ''), + 'api_access_token' => env('SHOPIFY_API_ACCESS_TOKEN', ''), /* * The shopify domain for your shop. diff --git a/src/Factory.php b/src/Factory.php index 3fe6ecd..2815fa1 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -7,8 +7,7 @@ class Factory public static function fromConfig(): Shopify { return new Shopify( - config('shopify.credentials.api_key'), - config('shopify.credentials.password'), + config('shopify.credentials.api_access_token'), config('shopify.credentials.domain'), config('shopify.credentials.api_version'), ); @@ -17,8 +16,7 @@ public static function fromConfig(): Shopify public static function fromArray(array $data): Shopify { return new Shopify( - $data['api_key'], - $data['password'], + $data['api_access_token'], $data['domain'], $data['api_version'] ); diff --git a/src/Shopify.php b/src/Shopify.php index 52c9f34..d2c2492 100644 --- a/src/Shopify.php +++ b/src/Shopify.php @@ -57,9 +57,9 @@ class Shopify protected ?PendingRequest $httpClient = null; - public function __construct(string $apiKey, string $password, string $domain, string $apiVersion) + public function __construct(string $accessToken, string $domain, string $apiVersion) { - $this->withCredentials($apiKey, $password, $domain, $apiVersion); + $this->withCredentials($accessToken, $domain, $apiVersion); } public function cursor(Collection $results): Cursor @@ -70,13 +70,13 @@ public function cursor(Collection $results): Cursor public function getHttpClient(): PendingRequest { return $this->httpClient ??= Http::baseUrl($this->getBaseUrl()) - ->withBasicAuth($this->apiKey, $this->password); + ->withHeaders(['X-Shopify-Access-Token' => $this->accessToken]); } public function graphQl(): PendingRequest { return Http::baseUrl("https://{$this->domain}/admin/api/graphql.json") - ->withHeaders(['X-Shopify-Access-Token' => $this->password]); + ->withHeaders(['X-Shopify-Access-Token' => $this->accessToken]); } public function getBaseUrl(): string @@ -91,10 +91,9 @@ public function tap(callable $callback): self return $this; } - public function withCredentials(string $apiKey, string $password, string $domain, string $apiVersion): self + public function withCredentials(string $accessToken, string $domain, string $apiVersion): self { - $this->apiKey = $apiKey; - $this->password = $password; + $this->accessToken = $accessToken; $this->domain = $domain; $this->apiVersion = $apiVersion;