-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathservices.php
More file actions
350 lines (328 loc) · 14.6 KB
/
Copy pathservices.php
File metadata and controls
350 lines (328 loc) · 14.6 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
/**
* The agentic commerce services.
*
* @package WooCommerce\PayPalCommerce\StoreSync
*/
declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\StoreSync;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\Assets\AssetGetter;
use WooCommerce\PayPalCommerce\Assets\AssetGetterFactory;
use WooCommerce\WooCommerce\Logging\Logger\NullLogger;
use WooCommerce\WooCommerce\Logging\Logger\WooCommerceLogger;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\StoreSync\Config\AgenticWebhookConfiguration;
use WooCommerce\PayPalCommerce\StoreSync\Config\IngestionConfiguration;
use WooCommerce\PayPalCommerce\StoreSync\Auth\AuthServiceProvider;
use WooCommerce\PayPalCommerce\StoreSync\Auth\PayPalJwkProvider;
use WooCommerce\PayPalCommerce\StoreSync\Endpoint\CreateCartEndpoint;
use WooCommerce\PayPalCommerce\StoreSync\Endpoint\GetCartEndpoint;
use WooCommerce\PayPalCommerce\StoreSync\Endpoint\ReplaceCartEndpoint;
use WooCommerce\PayPalCommerce\StoreSync\Endpoint\CheckoutEndpoint;
use WooCommerce\PayPalCommerce\StoreSync\Ingestion\IngestionBatchProvider;
use WooCommerce\PayPalCommerce\StoreSync\Ingestion\IngestionManager;
use WooCommerce\PayPalCommerce\StoreSync\Response\ResponseFactory;
use WooCommerce\PayPalCommerce\StoreSync\Session\AgenticSessionHandler;
use WooCommerce\PayPalCommerce\StoreSync\Setting\AgenticSettingsEndpoint;
use WooCommerce\PayPalCommerce\StoreSync\Setting\AgenticSettingsDataModel;
use WooCommerce\PayPalCommerce\StoreSync\Setting\AgenticSettingsModule;
use WooCommerce\PayPalCommerce\StoreSync\Merchant\MerchantMetadataProvider;
use WooCommerce\PayPalCommerce\StoreSync\Registration\RegistrationService;
use WooCommerce\PayPalCommerce\StoreSync\Registration\RegistrationEligibility;
use WooCommerce\PayPalCommerce\StoreSync\Inspector\InspectionFormHandler;
use WooCommerce\PayPalCommerce\StoreSync\Inspector\InspectionStatusPage;
use WooCommerce\PayPalCommerce\StoreSync\Helper\AgenticCheckoutProcessor;
use WooCommerce\PayPalCommerce\StoreSync\Helper\ShippingOptionsBuilder;
use WooCommerce\PayPalCommerce\StoreSync\Helper\PayPalOrderManager;
use WooCommerce\PayPalCommerce\StoreSync\Helper\AgenticCartBuilder;
use WooCommerce\PayPalCommerce\StoreSync\Helper\ProductManager;
use WooCommerce\PayPalCommerce\StoreSync\CartValidation\ProductValidator;
use WooCommerce\PayPalCommerce\StoreSync\CartValidation\PriceValidator;
use WooCommerce\PayPalCommerce\StoreSync\CartValidation\InventoryValidator;
use WooCommerce\PayPalCommerce\StoreSync\CartValidation\CurrencyValidator;
use WooCommerce\PayPalCommerce\StoreSync\CartValidation\ShippingValidator;
use WooCommerce\PayPalCommerce\StoreSync\CartValidation\CouponValidator\CouponValidator;
use WooCommerce\PayPalCommerce\StoreSync\CartValidation\CouponValidator\CouponContextBuilder;
use WooCommerce\PayPalCommerce\StoreSync\CartValidation\CouponValidator\DiscountCalculator;
use WooCommerce\PayPalCommerce\StoreSync\CartValidation\CouponValidator\CouponResolutionBuilder;
use WooCommerce\PayPalCommerce\StoreSync\CartValidation\CouponValidator\AppliedCouponsBuilder;
use WooCommerce\PayPalCommerce\StoreSync\CartValidation\CartValidationProcessor;
use WooCommerce\PayPalCommerce\StoreSync\Inspector\InspectionSessionData;
use WooCommerce\PayPalCommerce\StoreSync\Inspector\Page\RegistrationStatusSection;
use WooCommerce\PayPalCommerce\StoreSync\Inspector\Page\CartSessionSection;
use WooCommerce\PayPalCommerce\StoreSync\Helper\AgenticSessionManager;
/**
* Using a different log-source for agentic commerce log entries makes it much easier to inspect
* agentic behavior, which is fully decoupled from browser sessions.
*
* When using log-files, this creates a separate file for agentic log entries
* When using DB logging, the source makes it easy to filter for agentic entries
*/
const LOGGER_SOURCE = 'woocommerce-paypal-agentic';
return array(
// Logging.
'agentic.logger' => static function (): LoggerInterface {
if ( ! class_exists( \WC_Logger::class ) ) {
return new NullLogger();
}
return new WooCommerceLogger( wc_get_logger(), LOGGER_SOURCE );
},
// Configuration.
'agentic.config.webhook_urls' => static function ( ContainerInterface $c ): AgenticWebhookConfiguration {
return new AgenticWebhookConfiguration(
$c->get( 'settings.connection-state' ),
);
},
'agentic.config.ingestion' => static function (): IngestionConfiguration {
return new IngestionConfiguration();
},
// Registration and merchant identification.
'agentic.merchant.provider' => static function ( ContainerInterface $c ): MerchantMetadataProvider {
return new MerchantMetadataProvider(
$c->get( 'woocommerce.core' ),
$c->get( 'settings.data.general' )
);
},
'agentic.registration.eligibility' => static function ( ContainerInterface $c ): RegistrationEligibility {
return new RegistrationEligibility(
$c->get( 'agentic.merchant.provider' )
);
},
'agentic.registration.handler' => static function ( ContainerInterface $c ): RegistrationService {
return new RegistrationService(
$c->get( 'agentic.config.webhook_urls' ),
$c->get( 'agentic.merchant.provider' ),
$c->get( 'agentic.logger' )
);
},
// Authentication services.
'agentic.auth.key_provider' => static function (): PayPalJwkProvider {
return new PayPalJwkProvider();
},
'agentic.auth.provider' => static function ( ContainerInterface $c ): AuthServiceProvider {
return new AuthServiceProvider(
$c->get( 'settings.connection-state' ),
$c->get( 'agentic.auth.key_provider' ),
$c->get( 'agentic.merchant.provider' )
);
},
// Session management.
'agentic.session.handler' => static function (): AgenticSessionHandler {
return new AgenticSessionHandler();
},
// Helper services.
'agentic.helper.product-manager' => static function (): ProductManager {
return new ProductManager();
},
'agentic.helper.session-manager' => static function ( ContainerInterface $c ): AgenticSessionManager {
return new AgenticSessionManager(
$c->get( 'woocommerce.core' )
);
},
'agentic.helper.cart-builder' => static function ( ContainerInterface $c ): AgenticCartBuilder {
return new AgenticCartBuilder(
$c->get( 'woocommerce.core' ),
$c->get( 'agentic.helper.product-manager' ),
$c->get( 'button.session.factory.card-data' ),
$c->get( 'api.factory.purchase-unit' ),
$c->get( 'agentic.logger' )
);
},
'agentic.helper.shipping-options-builder' => static function (): ShippingOptionsBuilder {
return new ShippingOptionsBuilder();
},
'agentic.helper.checkout-processor' => static function ( ContainerInterface $c ): AgenticCheckoutProcessor {
return new AgenticCheckoutProcessor(
$c->get( 'agentic.helper.paypal-order-manager' ),
$c->get( 'button.helper.wc-order-creator' ),
$c->get( 'agentic.helper.cart-builder' ),
$c->get( 'agentic.response.applied-coupons-builder' )
);
},
'agentic.helper.paypal-order-manager' => static function ( ContainerInterface $c ): PayPalOrderManager {
return new PayPalOrderManager(
$c->get( 'api.endpoint.order' ),
$c->get( 'api.endpoint.orders' ),
$c->get( 'agentic.helper.cart-builder' ),
$c->get( 'agentic.logger' )
);
},
// Validation services.
'agentic.validation.processor' => static function ( ContainerInterface $c ): CartValidationProcessor {
return new CartValidationProcessor(
$c->get( 'agentic.logger' )
);
},
'agentic.validator.product' => static function ( ContainerInterface $c ): ProductValidator {
return new ProductValidator(
$c->get( 'agentic.helper.product-manager' ),
$c->get( 'agentic.config.ingestion' )
);
},
'agentic.validator.price' => static function ( ContainerInterface $c ): PriceValidator {
return new PriceValidator(
$c->get( 'agentic.helper.product-manager' )
);
},
'agentic.validator.inventory' => static function ( ContainerInterface $c ): InventoryValidator {
return new InventoryValidator(
$c->get( 'agentic.helper.product-manager' )
);
},
'agentic.validator.shipping' => static function ( ContainerInterface $c ): ShippingValidator {
return new ShippingValidator(
$c->get( 'agentic.helper.product-manager' )
);
},
'agentic.validator.currency' => static function (): CurrencyValidator {
return new CurrencyValidator();
},
'agentic.validator.coupon.discount-calculator' => static function ( ContainerInterface $c ): DiscountCalculator {
return new DiscountCalculator(
$c->get( 'agentic.helper.product-manager' )
);
},
'agentic.validator.coupon.context-builder' => static function ( ContainerInterface $c ): CouponContextBuilder {
return new CouponContextBuilder(
$c->get( 'agentic.helper.product-manager' ),
$c->get( 'agentic.validator.coupon.discount-calculator' )
);
},
'agentic.validator.coupon.resolution-builder' => static function (): CouponResolutionBuilder {
return new CouponResolutionBuilder();
},
'agentic.validator.coupon' => static function ( ContainerInterface $c ): CouponValidator {
return new CouponValidator(
$c->get( 'agentic.validator.coupon.context-builder' ),
$c->get( 'agentic.validator.coupon.discount-calculator' ),
$c->get( 'agentic.validator.coupon.resolution-builder' )
);
},
// Response services.
'agentic.response.applied-coupons-builder' => static function ( ContainerInterface $c ): AppliedCouponsBuilder {
return new AppliedCouponsBuilder(
$c->get( 'agentic.validator.coupon.discount-calculator' )
);
},
'agentic.response.factory' => static function ( ContainerInterface $c ): ResponseFactory {
return new ResponseFactory(
$c->get( 'agentic.helper.cart-builder' ),
$c->get( 'agentic.response.applied-coupons-builder' ),
$c->get( 'agentic.helper.shipping-options-builder' )
);
},
// REST endpoints.
'agentic.rest.create_cart' => static function ( ContainerInterface $c ): CreateCartEndpoint {
return new CreateCartEndpoint(
$c->get( 'agentic.auth.provider' ),
$c->get( 'agentic.session.handler' ),
$c->get( 'agentic.helper.session-manager' ),
$c->get( 'agentic.response.factory' ),
$c->get( 'agentic.validation.processor' ),
$c->get( 'agentic.logger' ),
$c->get( 'agentic.helper.paypal-order-manager' )
);
},
'agentic.rest.get_cart' => static function ( ContainerInterface $c ): GetCartEndpoint {
return new GetCartEndpoint(
$c->get( 'agentic.auth.provider' ),
$c->get( 'agentic.session.handler' ),
$c->get( 'agentic.helper.session-manager' ),
$c->get( 'agentic.response.factory' ),
$c->get( 'agentic.validation.processor' ),
$c->get( 'agentic.logger' ),
$c->get( 'agentic.helper.paypal-order-manager' )
);
},
'agentic.rest.replace_cart' => static function ( ContainerInterface $c ): ReplaceCartEndpoint {
return new ReplaceCartEndpoint(
$c->get( 'agentic.auth.provider' ),
$c->get( 'agentic.session.handler' ),
$c->get( 'agentic.helper.session-manager' ),
$c->get( 'agentic.response.factory' ),
$c->get( 'agentic.validation.processor' ),
$c->get( 'agentic.logger' ),
$c->get( 'agentic.helper.paypal-order-manager' )
);
},
'agentic.rest.checkout' => static function ( ContainerInterface $c ): CheckoutEndpoint {
return new CheckoutEndpoint(
$c->get( 'agentic.auth.provider' ),
$c->get( 'agentic.session.handler' ),
$c->get( 'agentic.helper.session-manager' ),
$c->get( 'agentic.response.factory' ),
$c->get( 'agentic.validation.processor' ),
$c->get( 'agentic.logger' ),
$c->get( 'agentic.helper.paypal-order-manager' ),
$c->get( 'agentic.helper.checkout-processor' )
);
},
// Ingestion services.
'agentic.ingestion-batch-provider' => static function ( ContainerInterface $c ): IngestionBatchProvider {
return new IngestionBatchProvider(
$c->get( 'agentic.config.ingestion' )
);
},
'agentic.ingestion-manager' => static function ( ContainerInterface $c ): IngestionManager {
return new IngestionManager(
$c->get( 'agentic.config.ingestion' ),
$c->get( 'agentic.ingestion-batch-provider' ),
$c->get( 'agentic.config.webhook_urls' ),
$c->get( 'agentic.merchant.provider' ),
$c->get( 'agentic.logger' )
);
},
// Settings.
'agentic.settings.model' => static function (): AgenticSettingsDataModel {
return new AgenticSettingsDataModel();
},
'agentic.settings.endpoint' => static function ( ContainerInterface $c ): AgenticSettingsEndpoint {
return new AgenticSettingsEndpoint(
$c->get( 'agentic.settings.model' )
);
},
'agentic.settings.module' => static function ( ContainerInterface $c ): AgenticSettingsModule {
return new AgenticSettingsModule(
$c->get( 'agentic.settings.endpoint' ),
$c->get( 'agentic.registration.eligibility' ),
$c->get( 'agentic.asset_getter' ),
);
},
// Inspector.
'agentic.inspector.form_handler' => static function ( ContainerInterface $c ): InspectionFormHandler {
return new InspectionFormHandler(
$c->get( 'agentic.registration.handler' ),
$c->get( 'agentic.logger' )
);
},
'agentic.inspector.session_info' => static function ( ContainerInterface $c ): InspectionSessionData {
return new InspectionSessionData();
},
'agentic.inspector.page.status' => static function ( ContainerInterface $c ): RegistrationStatusSection {
return new RegistrationStatusSection(
$c->get( 'agentic.registration.handler' ),
$c->get( 'agentic.registration.eligibility' ),
$c->get( 'agentic.auth.provider' ),
$c->get( 'settings.data.general' )
);
},
'agentic.inspector.page.session' => static function ( ContainerInterface $c ): CartSessionSection {
return new CartSessionSection(
$c->get( 'agentic.inspector.session_info' ),
$c->get( 'agentic.validation.processor' )
);
},
'agentic.inspector.page' => static function ( ContainerInterface $c ): InspectionStatusPage {
return new InspectionStatusPage(
$c->get( 'agentic.inspector.form_handler' ),
$c->get( 'agentic.inspector.page.status' ),
$c->get( 'agentic.inspector.page.session' )
);
},
'agentic.asset_getter' => static function ( ContainerInterface $container ): AssetGetter {
$factory = $container->get( 'assets.asset_getter_factory' );
assert( $factory instanceof AssetGetterFactory );
return $factory->for_module( 'ppcp-store-sync' );
},
);