|
1
|
|
|
<?php |
|
2
|
|
|
namespace CodeCloud\Bundle\ShopifyBundle\Api; |
|
3
|
|
|
|
|
4
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\AbstractEndpoint; |
|
5
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\ApplicationChargeEndpoint; |
|
6
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\ArticleEndpoint; |
|
7
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\AssetEndpoint; |
|
8
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\BlogEndpoint; |
|
9
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\CarrierServiceEndpoint; |
|
10
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\CheckoutEndpoint; |
|
11
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\CollectEndpoint; |
|
12
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\CommentEndpoint; |
|
13
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\CountryEndpoint; |
|
14
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\CustomCollectionEndpoint; |
|
15
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\CustomerAddressEndpoint; |
|
16
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\CustomerEndpoint; |
|
17
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\CustomerSavedSearchEndpoint; |
|
18
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\EventEndpoint; |
|
19
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\FulFillmentEndpoint; |
|
20
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\FulfillmentServiceEndpoint; |
|
21
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\LocationEndpoint; |
|
22
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\MetafieldEndpoint; |
|
23
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\OrderEndpoint; |
|
24
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\OrderRisksEndpoint; |
|
25
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\PageEndpoint; |
|
26
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\PolicyEndpoint; |
|
27
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\ProductImageEndpoint; |
|
28
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\ProductEndpoint; |
|
29
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\ProductVariantEndpoint; |
|
30
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\ProvinceEndpoint; |
|
31
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\RecurringApplicationChargeEndpoint; |
|
32
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\RedirectEndpoint; |
|
33
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\RefundEndpoint; |
|
34
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\ScriptTagEndpoint; |
|
35
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\ShopEndpoint; |
|
36
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\SmartCollectionEndpoint; |
|
37
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\ThemeEndpoint; |
|
38
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\TransactionEndpoint; |
|
39
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\UserEndpoint; |
|
40
|
|
|
use CodeCloud\Bundle\ShopifyBundle\Api\Endpoint\WebhookEndpoint; |
|
41
|
|
|
use GuzzleHttp\ClientInterface; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Main access point to Shopify Api. |
|
45
|
|
|
* |
|
46
|
|
|
* @property ApplicationChargeEndpoint ApplicationCharge |
|
47
|
|
|
* @property ArticleEndpoint Article |
|
48
|
|
|
* @property AssetEndpoint Asset |
|
49
|
|
|
* @property BlogEndpoint Blog |
|
50
|
|
|
* @property CarrierServiceEndpoint CarrierService |
|
51
|
|
|
* @property CheckoutEndpoint Checkout |
|
52
|
|
|
* @property CollectEndpoint Collect |
|
53
|
|
|
* @property CommentEndpoint Comment |
|
54
|
|
|
* @property CountryEndpoint Country |
|
55
|
|
|
* @property CustomCollectionEndpoint CustomCollection |
|
56
|
|
|
* @property CustomerAddressEndpoint CustomerAddress |
|
57
|
|
|
* @property CustomerEndpoint Customer |
|
58
|
|
|
* @property CustomerSavedSearchEndpoint SavedSearch |
|
59
|
|
|
* @property EventEndpoint Event |
|
60
|
|
|
* @property FulFillmentEndpoint Fulfillment |
|
61
|
|
|
* @property FulfillmentServiceEndpoint FulfillmentService |
|
62
|
|
|
* @property LocationEndpoint Location |
|
63
|
|
|
* @property MetafieldEndpoint Metafield |
|
64
|
|
|
* @property OrderEndpoint Order |
|
65
|
|
|
* @property OrderRisksEndpoint OrderRisks |
|
66
|
|
|
* @property PageEndpoint Page |
|
67
|
|
|
* @property PolicyEndpoint Policy |
|
68
|
|
|
* @property ProductImageEndpoint ProductImage |
|
69
|
|
|
* @property ProductEndpoint Product |
|
70
|
|
|
* @property ProductVariantEndpoint ProductVariant |
|
71
|
|
|
* @property ProvinceEndpoint Province |
|
72
|
|
|
* @property RecurringApplicationChargeEndpoint RecurringApplicationCharge |
|
73
|
|
|
* @property RedirectEndpoint Redirect |
|
74
|
|
|
* @property RefundEndpoint Refund |
|
75
|
|
|
* @property ScriptTagEndpoint ScriptTag |
|
76
|
|
|
* @property ShopEndpoint Shop |
|
77
|
|
|
* @property SmartCollectionEndpoint SmartCollection |
|
78
|
|
|
* @property ThemeEndpoint Theme |
|
79
|
|
|
* @property TransactionEndpoint Transaction |
|
80
|
|
|
* @property UserEndpoint User |
|
81
|
|
|
* @property WebhookEndpoint Webhook |
|
82
|
|
|
*/ |
|
83
|
|
|
class ShopifyApi |
|
84
|
|
|
{ |
|
85
|
|
|
/** |
|
86
|
|
|
* @var ClientInterface |
|
87
|
|
|
*/ |
|
88
|
|
|
private $client; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @var string[] |
|
92
|
|
|
*/ |
|
93
|
|
|
private $endpointClasses = [ |
|
94
|
|
|
'ApplicationCharge' => ApplicationChargeEndpoint::class, |
|
95
|
|
|
'Article' => ArticleEndpoint::class, |
|
96
|
|
|
'Asset' => AssetEndpoint::class, |
|
97
|
|
|
'Blog' => BlogEndpoint::class, |
|
98
|
|
|
'CarrierService' => CarrierServiceEndpoint::class, |
|
99
|
|
|
'Checkout' => CheckoutEndpoint::class, |
|
100
|
|
|
'Collect' => CollectEndpoint::class, |
|
101
|
|
|
'Comment' => CommentEndpoint::class, |
|
102
|
|
|
'Country' => CountryEndpoint::class, |
|
103
|
|
|
'CustomCollection' => CustomCollectionEndpoint::class, |
|
104
|
|
|
'CustomerAddress' => CustomerAddressEndpoint::class, |
|
105
|
|
|
'Customer' => CustomerEndpoint::class, |
|
106
|
|
|
'SavedSearch' => CustomerSavedSearchEndpoint::class, |
|
107
|
|
|
'Event' => EventEndpoint::class, |
|
108
|
|
|
'Fulfillment' => FulFillmentEndpoint::class, |
|
109
|
|
|
'FulfillmentService' => FulfillmentServiceEndpoint::class, |
|
110
|
|
|
'Location' => LocationEndpoint::class, |
|
111
|
|
|
'Metafield' => MetafieldEndpoint::class, |
|
112
|
|
|
'Order' => OrderEndpoint::class, |
|
113
|
|
|
'OrderRisks' => OrderRisksEndpoint::class, |
|
114
|
|
|
'Page' => PageEndpoint::class, |
|
115
|
|
|
'Policy' => PolicyEndpoint::class, |
|
116
|
|
|
'ProductImage' => ProductImageEndpoint::class, |
|
117
|
|
|
'Product' => ProductEndpoint::class, |
|
118
|
|
|
'ProductVariant' => ProductVariantEndpoint::class, |
|
119
|
|
|
'Province' => ProvinceEndpoint::class, |
|
120
|
|
|
'RecurringApplicationCharge' => RecurringApplicationChargeEndpoint::class, |
|
121
|
|
|
'Redirect' => RedirectEndpoint::class, |
|
122
|
|
|
'Refund' => RefundEndpoint::class, |
|
123
|
|
|
'ScriptTag' => ScriptTagEndpoint::class, |
|
124
|
|
|
'Shop' => ShopEndpoint::class, |
|
125
|
|
|
'SmartCollection' => SmartCollectionEndpoint::class, |
|
126
|
|
|
'Theme' => ThemeEndpoint::class, |
|
127
|
|
|
'Transaction' => TransactionEndpoint::class, |
|
128
|
|
|
'User' => UserEndpoint::class, |
|
129
|
|
|
'Webhook' => WebhookEndpoint::class, |
|
130
|
|
|
]; |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Holds instantiated endpoints. |
|
134
|
|
|
* |
|
135
|
|
|
* @var AbstractEndpoint[] |
|
136
|
|
|
*/ |
|
137
|
|
|
private $endpoints; |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @var string |
|
141
|
|
|
*/ |
|
142
|
|
|
private $apiVersion; |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param ClientInterface $client |
|
146
|
|
|
* @param string $apiVersion |
|
147
|
|
|
*/ |
|
148
|
|
|
public function __construct(ClientInterface $client, $apiVersion = null) |
|
149
|
|
|
{ |
|
150
|
|
|
$this->client = $client; |
|
151
|
|
|
$this->apiVersion = $apiVersion; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param string $endpoint |
|
156
|
|
|
* @return AbstractEndpoint |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getEndpoint($endpoint) |
|
159
|
|
|
{ |
|
160
|
|
|
if (isset($this->endpoints[$endpoint])) { |
|
161
|
|
|
return $this->endpoints[$endpoint]; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
if (!isset($this->endpointClasses[$endpoint])) { |
|
165
|
|
|
throw new \InvalidArgumentException(sprintf('Endpoint %s does not exist', $endpoint)); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
$class = $this->endpointClasses[$endpoint]; |
|
169
|
|
|
|
|
170
|
|
|
return $this->endpoints[$endpoint] = new $class($this->client, $this->apiVersion); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function __get($name) |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->getEndpoint($name); |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|