-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathShopifyServiceProvider.php
103 lines (88 loc) · 3.17 KB
/
ShopifyServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace Statamic\Addons\Shopify;
use OhMyBrew\BasicShopifyAPI;
use Statamic\Addons\Shopify\Service\CartManager;
use Statamic\Addons\Shopify\Service\CartSerializer;
use Statamic\Addons\Shopify\Service\CheckoutClient;
use Statamic\Addons\Shopify\Service\CheckoutManager;
use Statamic\Addons\Shopify\Service\ProductSerializer;
use Statamic\Addons\Shopify\Service\ProductVariantSerializer;
use Statamic\Addons\Shopify\Service\ShopifyRepository;
use Statamic\Extend\ServiceProvider;
class ShopifyServiceProvider extends ServiceProvider
{
// The API version used for the API calls.
const SHOPIFY_API_VERSION = '2022-10';
protected $defer = true;
/**
* {@inheritDoc}
*/
public function register()
{
$this->registerShopifyClient();
$this->registerShopifyRepository();
$this->registerProductSerializer();
$this->registerProductVariantSerializer();
$this->registerCartManager();
$this->registerCheckoutManager();
$this->registerCartSerializer();
$this->registerCheckoutClient();
}
private function registerShopifyClient()
{
$this->app->singleton(BasicShopifyAPI::class, function () {
$client = (new BasicShopifyAPI(true))
->setVersion(self::SHOPIFY_API_VERSION)
->setShop($this->getConfig('store_url'))
->setApiKey($this->getConfig('api_key'))
->setApiPassword($this->getConfig('password'))
->setApiSecret($this->getConfig('shared_secret'));
if ($this->getConfigBool('rate_limiting_enable', false)) {
$client->enableRateLimiting();
}
return $client;
});
}
private function registerShopifyRepository()
{
$this->app->singleton(ShopifyRepository::class, function ($app) {
return new ShopifyRepository($app[BasicShopifyAPI::class]);
});
}
private function registerProductSerializer()
{
$this->app->singleton(ProductSerializer::class, function () {
return new ProductSerializer();
});
}
private function registerProductVariantSerializer()
{
$this->app->singleton(ProductVariantSerializer::class, function () {
return new ProductVariantSerializer();
});
}
private function registerCartManager()
{
$this->app->singleton(CartManager::class, function () {
return new CartManager();
});
}
private function registerCheckoutManager()
{
$this->app->singleton(CheckoutManager::class, function ($app) {
return new CheckoutManager($app[CheckoutClient::class]);
});
}
private function registerCartSerializer()
{
$this->app->singleton(CartSerializer::class, function ($app) {
return new CartSerializer($app[ShopifyRepository::class], $app[ProductVariantSerializer::class]);
});
}
private function registerCheckoutClient()
{
$this->app->singleton(CheckoutClient::class, function ($app) {
return new CheckoutClient($app[BasicShopifyAPI::class], $this->getConfig('storefront_access_token', ''));
});
}
}