Skip to content

Commit

Permalink
added osiset/basic-shopify-api as external dependency (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: rupam <rupam@claritytech.io>
  • Loading branch information
rupamjbordoloi and rupam authored Aug 19, 2021
1 parent 7ece611 commit ec73064
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ Update config/app.php with below code and in routes add `auth:shopify` as middle

## Set credendials

in your `.env` file set these values from your app
`SHOPIFY_APIKEY=your-api-key`
`SHOPIFY_SECRET=your-secret-key`
`SHOPIFY_VERSION=admin-api-version`
in your `.env` file set these values from your app \
`SHOPIFY_APIKEY=your-api-key` \
`SHOPIFY_SECRET=your-secret-key` \
`SHOPIFY_VERSION=admin-api-version` \
only if app is private \
`API_PASSWORD=private-app-password`

## Optional Configuration (publishing)

Expand Down Expand Up @@ -174,6 +176,20 @@ public function verifyWebhook(Request $request)
}

```
To access Admin API use

```php5
$myshopify_domain = "example.myshopify.com";
$access_token = "xxxxxxxxxxxxxxxxxxxxx";
$api = Shopify::setShop($myshopify_domain, $access_token)->basicApi();

// For sync rest api
$res = $api->rest('GET', '/admin/shop.json')

// For sync graphql api
$res = $api->graph('{ products(first: 1) { edges { node { handle, id } } } }', [])
```


To access API resource use

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"require": {
"php": ">=7.3.0|8.0",
"laravel/framework": "^7.0|^8.0",
"psr/http-message": "^1.0"
"psr/http-message": "^1.0",
"osiset/basic-shopify-api": "^10.0"
},
"autoload": {
"psr-4": {
Expand Down
27 changes: 27 additions & 0 deletions src/Shopify/Shopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
use Illuminate\Support\Facades\Http;
use ClarityTech\Shopify\Exceptions\ShopifyApiException;
use ClarityTech\Shopify\Exceptions\ShopifyApiResourceNotFoundException;
use Osiset\BasicShopifyAPI\BasicShopifyAPI;
use Osiset\BasicShopifyAPI\Options;
use Osiset\BasicShopifyAPI\Session;
use Psr\Http\Message\ResponseInterface;

class Shopify
{
protected static ?string $key = null;
protected static ?string $secret = null;
protected static ?string $api_password = null;
protected static ?string $version = null;
protected static ?string $shopDomain = null;
protected static ?string $accessToken = null;
Expand All @@ -37,6 +41,7 @@ public function __construct()
{
self::$key = Config::get('shopify.key');
self::$secret = Config::get('shopify.secret');
self::$api_password = Config::get('shopify.api_password');
self::$version = Config::get('shopify.version');
}

Expand Down Expand Up @@ -213,6 +218,28 @@ public function __call($method, $args)
return $response;
}

/**
* @param bool $is_private true for private apps
*
* @return \ClarityTech\Shopify\BasicApi\BasicShopifyAPI $api
*/
public function basicApi(bool $is_private = false)
{
$options = new Options();
$options->setVersion($this::$version);
if($is_private) {
$options->setType(true);
$options->setApiKey(env($this::$key));
$options->setApiPassword($this::$api_password);
$session = new Session($this::$shopDomain);
}else {
$session = new Session($this::$shopDomain, $this::$accessToken);
}
$api = new BasicShopifyAPI($options);
$api->setSession($session);
return $api;
}

public function getHeadersForSend() : array
{
$headers = [];
Expand Down
3 changes: 3 additions & 0 deletions src/config/shopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
'key' => env("SHOPIFY_APIKEY", null),
'secret' => env("SHOPIFY_SECRET", null),

// required only for private apps
'api_password' => env("API_PASSWORD", null),

'version' => env("SHOPIFY_VERSION", '2020-01'),

// the prefix of the webhook url for uninstalled job
Expand Down

0 comments on commit ec73064

Please sign in to comment.