Skip to content

Commit ec73064

Browse files
rupamjbordoloirupam
andauthored
added osiset/basic-shopify-api as external dependency (#3)
Co-authored-by: rupam <rupam@claritytech.io>
1 parent 7ece611 commit ec73064

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ Update config/app.php with below code and in routes add `auth:shopify` as middle
6262

6363
## Set credendials
6464

65-
in your `.env` file set these values from your app
66-
`SHOPIFY_APIKEY=your-api-key`
67-
`SHOPIFY_SECRET=your-secret-key`
68-
`SHOPIFY_VERSION=admin-api-version`
65+
in your `.env` file set these values from your app \
66+
`SHOPIFY_APIKEY=your-api-key` \
67+
`SHOPIFY_SECRET=your-secret-key` \
68+
`SHOPIFY_VERSION=admin-api-version` \
69+
only if app is private \
70+
`API_PASSWORD=private-app-password`
6971

7072
## Optional Configuration (publishing)
7173

@@ -174,6 +176,20 @@ public function verifyWebhook(Request $request)
174176
}
175177

176178
```
179+
To access Admin API use
180+
181+
```php5
182+
$myshopify_domain = "example.myshopify.com";
183+
$access_token = "xxxxxxxxxxxxxxxxxxxxx";
184+
$api = Shopify::setShop($myshopify_domain, $access_token)->basicApi();
185+
186+
// For sync rest api
187+
$res = $api->rest('GET', '/admin/shop.json')
188+
189+
// For sync graphql api
190+
$res = $api->graph('{ products(first: 1) { edges { node { handle, id } } } }', [])
191+
```
192+
177193

178194
To access API resource use
179195

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"require": {
1212
"php": ">=7.3.0|8.0",
1313
"laravel/framework": "^7.0|^8.0",
14-
"psr/http-message": "^1.0"
14+
"psr/http-message": "^1.0",
15+
"osiset/basic-shopify-api": "^10.0"
1516
},
1617
"autoload": {
1718
"psr-4": {

src/Shopify/Shopify.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
use Illuminate\Support\Facades\Http;
77
use ClarityTech\Shopify\Exceptions\ShopifyApiException;
88
use ClarityTech\Shopify\Exceptions\ShopifyApiResourceNotFoundException;
9+
use Osiset\BasicShopifyAPI\BasicShopifyAPI;
10+
use Osiset\BasicShopifyAPI\Options;
11+
use Osiset\BasicShopifyAPI\Session;
912
use Psr\Http\Message\ResponseInterface;
1013

1114
class Shopify
1215
{
1316
protected static ?string $key = null;
1417
protected static ?string $secret = null;
18+
protected static ?string $api_password = null;
1519
protected static ?string $version = null;
1620
protected static ?string $shopDomain = null;
1721
protected static ?string $accessToken = null;
@@ -37,6 +41,7 @@ public function __construct()
3741
{
3842
self::$key = Config::get('shopify.key');
3943
self::$secret = Config::get('shopify.secret');
44+
self::$api_password = Config::get('shopify.api_password');
4045
self::$version = Config::get('shopify.version');
4146
}
4247

@@ -213,6 +218,28 @@ public function __call($method, $args)
213218
return $response;
214219
}
215220

221+
/**
222+
* @param bool $is_private true for private apps
223+
*
224+
* @return \ClarityTech\Shopify\BasicApi\BasicShopifyAPI $api
225+
*/
226+
public function basicApi(bool $is_private = false)
227+
{
228+
$options = new Options();
229+
$options->setVersion($this::$version);
230+
if($is_private) {
231+
$options->setType(true);
232+
$options->setApiKey(env($this::$key));
233+
$options->setApiPassword($this::$api_password);
234+
$session = new Session($this::$shopDomain);
235+
}else {
236+
$session = new Session($this::$shopDomain, $this::$accessToken);
237+
}
238+
$api = new BasicShopifyAPI($options);
239+
$api->setSession($session);
240+
return $api;
241+
}
242+
216243
public function getHeadersForSend() : array
217244
{
218245
$headers = [];

src/config/shopify.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
'key' => env("SHOPIFY_APIKEY", null),
1717
'secret' => env("SHOPIFY_SECRET", null),
1818

19+
// required only for private apps
20+
'api_password' => env("API_PASSWORD", null),
21+
1922
'version' => env("SHOPIFY_VERSION", '2020-01'),
2023

2124
// the prefix of the webhook url for uninstalled job

0 commit comments

Comments
 (0)