-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathSquareClient.php
More file actions
324 lines (279 loc) · 9.08 KB
/
SquareClient.php
File metadata and controls
324 lines (279 loc) · 9.08 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<?php
namespace Square;
use Square\OAuth\OAuthClient;
use Square\V1Transactions\V1TransactionsClient;
use Square\ApplePay\ApplePayClient;
use Square\BankAccounts\BankAccountsClient;
use Square\Bookings\BookingsClient;
use Square\Cards\CardsClient;
use Square\Catalog\CatalogClient;
use Square\Channels\ChannelsClient;
use Square\Customers\CustomersClient;
use Square\Devices\DevicesClient;
use Square\Disputes\DisputesClient;
use Square\Employees\EmployeesClient;
use Square\Events\EventsClient;
use Square\GiftCards\GiftCardsClient;
use Square\Inventory\InventoryClient;
use Square\Invoices\InvoicesClient;
use Square\Labor\LaborClient;
use Square\Locations\LocationsClient;
use Square\Loyalty\LoyaltyClient;
use Square\Merchants\MerchantsClient;
use Square\Checkout\CheckoutClient;
use Square\Orders\OrdersClient;
use Square\Payments\PaymentsClient;
use Square\Payouts\PayoutsClient;
use Square\Refunds\RefundsClient;
use Square\Sites\SitesClient;
use Square\Snippets\SnippetsClient;
use Square\Subscriptions\SubscriptionsClient;
use Square\TeamMembers\TeamMembersClient;
use Square\Team\TeamClient;
use Square\Terminal\TerminalClient;
use Square\TransferOrders\TransferOrdersClient;
use Square\Vendors\VendorsClient;
use Square\CashDrawers\CashDrawersClient;
use Square\Webhooks\WebhooksClient;
use GuzzleHttp\ClientInterface;
use Square\Core\Client\RawClient;
use Exception;
class SquareClient
{
/**
* @var OAuthClient $oAuth
*/
public OAuthClient $oAuth;
/**
* @var V1TransactionsClient $v1Transactions
*/
public V1TransactionsClient $v1Transactions;
/**
* @var ApplePayClient $applePay
*/
public ApplePayClient $applePay;
/**
* @var BankAccountsClient $bankAccounts
*/
public BankAccountsClient $bankAccounts;
/**
* @var BookingsClient $bookings
*/
public BookingsClient $bookings;
/**
* @var CardsClient $cards
*/
public CardsClient $cards;
/**
* @var CatalogClient $catalog
*/
public CatalogClient $catalog;
/**
* @var ChannelsClient $channels
*/
public ChannelsClient $channels;
/**
* @var CustomersClient $customers
*/
public CustomersClient $customers;
/**
* @var DevicesClient $devices
*/
public DevicesClient $devices;
/**
* @var DisputesClient $disputes
*/
public DisputesClient $disputes;
/**
* @var EmployeesClient $employees
*/
public EmployeesClient $employees;
/**
* @var EventsClient $events
*/
public EventsClient $events;
/**
* @var GiftCardsClient $giftCards
*/
public GiftCardsClient $giftCards;
/**
* @var InventoryClient $inventory
*/
public InventoryClient $inventory;
/**
* @var InvoicesClient $invoices
*/
public InvoicesClient $invoices;
/**
* @var LaborClient $labor
*/
public LaborClient $labor;
/**
* @var LocationsClient $locations
*/
public LocationsClient $locations;
/**
* @var LoyaltyClient $loyalty
*/
public LoyaltyClient $loyalty;
/**
* @var MerchantsClient $merchants
*/
public MerchantsClient $merchants;
/**
* @var CheckoutClient $checkout
*/
public CheckoutClient $checkout;
/**
* @var OrdersClient $orders
*/
public OrdersClient $orders;
/**
* @var PaymentsClient $payments
*/
public PaymentsClient $payments;
/**
* @var PayoutsClient $payouts
*/
public PayoutsClient $payouts;
/**
* @var RefundsClient $refunds
*/
public RefundsClient $refunds;
/**
* @var SitesClient $sites
*/
public SitesClient $sites;
/**
* @var SnippetsClient $snippets
*/
public SnippetsClient $snippets;
/**
* @var SubscriptionsClient $subscriptions
*/
public SubscriptionsClient $subscriptions;
/**
* @var TeamMembersClient $teamMembers
*/
public TeamMembersClient $teamMembers;
/**
* @var TeamClient $team
*/
public TeamClient $team;
/**
* @var TerminalClient $terminal
*/
public TerminalClient $terminal;
/**
* @var TransferOrdersClient $transferOrders
*/
public TransferOrdersClient $transferOrders;
/**
* @var VendorsClient $vendors
*/
public VendorsClient $vendors;
/**
* @var CashDrawersClient $cashDrawers
*/
public CashDrawersClient $cashDrawers;
/**
* @var WebhooksClient $webhooks
*/
public WebhooksClient $webhooks;
/**
* @var array{
* baseUrl?: string,
* client?: ClientInterface,
* maxRetries?: int,
* timeout?: float,
* headers?: array<string, string>,
* } $options @phpstan-ignore-next-line Property is used in endpoint methods via HttpEndpointGenerator
*/
private array $options;
/**
* @var RawClient $client
*/
private RawClient $client;
/**
* @param ?string $token The token to use for authentication.
* @param ?string $version
* @param ?array{
* baseUrl?: string,
* client?: ClientInterface,
* maxRetries?: int,
* timeout?: float,
* headers?: array<string, string>,
* } $options
*/
public function __construct(
?string $token = null,
?string $version = null,
?array $options = null,
) {
$token ??= $this->getFromEnvOrThrow('SQUARE_TOKEN', 'Please pass in token or set the environment variable SQUARE_TOKEN.');
$defaultHeaders = [
'Authorization' => "Bearer $token",
'Square-Version' => '2026-01-22',
'X-Fern-Language' => 'PHP',
'X-Fern-SDK-Name' => 'Square',
'X-Fern-SDK-Version' => '44.0.0.20260122',
'User-Agent' => 'square/square/44.0.0.20260122',
];
if ($version != null) {
$defaultHeaders['Square-Version'] = $version;
}
$this->options = $options ?? [];
$this->options['headers'] = array_merge(
$defaultHeaders,
$this->options['headers'] ?? [],
);
$this->client = new RawClient(
options: $this->options,
);
$this->oAuth = new OAuthClient($this->client, $this->options);
$this->v1Transactions = new V1TransactionsClient($this->client, $this->options);
$this->applePay = new ApplePayClient($this->client, $this->options);
$this->bankAccounts = new BankAccountsClient($this->client, $this->options);
$this->bookings = new BookingsClient($this->client, $this->options);
$this->cards = new CardsClient($this->client, $this->options);
$this->catalog = new CatalogClient($this->client, $this->options);
$this->channels = new ChannelsClient($this->client, $this->options);
$this->customers = new CustomersClient($this->client, $this->options);
$this->devices = new DevicesClient($this->client, $this->options);
$this->disputes = new DisputesClient($this->client, $this->options);
$this->employees = new EmployeesClient($this->client, $this->options);
$this->events = new EventsClient($this->client, $this->options);
$this->giftCards = new GiftCardsClient($this->client, $this->options);
$this->inventory = new InventoryClient($this->client, $this->options);
$this->invoices = new InvoicesClient($this->client, $this->options);
$this->labor = new LaborClient($this->client, $this->options);
$this->locations = new LocationsClient($this->client, $this->options);
$this->loyalty = new LoyaltyClient($this->client, $this->options);
$this->merchants = new MerchantsClient($this->client, $this->options);
$this->checkout = new CheckoutClient($this->client, $this->options);
$this->orders = new OrdersClient($this->client, $this->options);
$this->payments = new PaymentsClient($this->client, $this->options);
$this->payouts = new PayoutsClient($this->client, $this->options);
$this->refunds = new RefundsClient($this->client, $this->options);
$this->sites = new SitesClient($this->client, $this->options);
$this->snippets = new SnippetsClient($this->client, $this->options);
$this->subscriptions = new SubscriptionsClient($this->client, $this->options);
$this->teamMembers = new TeamMembersClient($this->client, $this->options);
$this->team = new TeamClient($this->client, $this->options);
$this->terminal = new TerminalClient($this->client, $this->options);
$this->transferOrders = new TransferOrdersClient($this->client, $this->options);
$this->vendors = new VendorsClient($this->client, $this->options);
$this->cashDrawers = new CashDrawersClient($this->client, $this->options);
$this->webhooks = new WebhooksClient($this->client, $this->options);
}
/**
* @param string $env
* @param string $message
* @return string
*/
private function getFromEnvOrThrow(string $env, string $message): string
{
$value = getenv($env);
return $value ? (string) $value : throw new Exception($message);
}
}