|
14 | 14 | use WooCommerce\PayPalCommerce\Button\Assets\DisabledSmartButton; |
15 | 15 | use WooCommerce\PayPalCommerce\Button\Assets\SmartButton; |
16 | 16 | use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface; |
17 | | -use WooCommerce\PayPalCommerce\Button\Endpoint\ApproveOrderEndpoint; |
| 17 | +use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\ApproveOrderEndpoint; |
18 | 18 | use WooCommerce\PayPalCommerce\Button\Endpoint\ApproveSubscriptionEndpoint; |
19 | 19 | use WooCommerce\PayPalCommerce\Button\Endpoint\CartScriptParamsEndpoint; |
20 | | -use WooCommerce\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint; |
21 | | -use WooCommerce\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint; |
| 20 | +use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\ChangeCartEndpoint; |
| 21 | +use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\CreateOrderEndpoint; |
22 | 22 | use WooCommerce\PayPalCommerce\Button\Endpoint\DataClientIdEndpoint; |
23 | 23 | use WooCommerce\PayPalCommerce\Button\Endpoint\GetOrderEndpoint; |
24 | | -use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData; |
| 24 | +use WooCommerce\PayPalCommerce\OrderEndpoints\Endpoint\RequestData; |
25 | 25 | use WooCommerce\PayPalCommerce\Button\Endpoint\SaveCheckoutFormEndpoint; |
26 | 26 | use WooCommerce\PayPalCommerce\Button\Endpoint\SimulateCartEndpoint; |
27 | 27 | use WooCommerce\PayPalCommerce\Button\Endpoint\ValidateCheckoutEndpoint; |
28 | | -use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException; |
29 | | -use WooCommerce\PayPalCommerce\Button\Helper\CartProductsHelper; |
| 28 | +use WooCommerce\PayPalCommerce\OrderEndpoints\Helper\CartProductsHelper; |
30 | 29 | use WooCommerce\PayPalCommerce\Button\Helper\CheckoutFormSaver; |
31 | 30 | use WooCommerce\PayPalCommerce\Button\Helper\Context; |
32 | 31 | use WooCommerce\PayPalCommerce\Button\Helper\DisabledFundingSources; |
33 | | -use WooCommerce\PayPalCommerce\Button\Helper\EarlyOrderHandler; |
| 32 | +use WooCommerce\PayPalCommerce\OrderEndpoints\Helper\EarlyOrderHandler; |
34 | 33 | use WooCommerce\PayPalCommerce\Button\Helper\IsolatedCartSimulator; |
35 | 34 | use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply; |
36 | 35 | use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure; |
37 | | -use WooCommerce\PayPalCommerce\Button\Helper\WooCommerceOrderCreator; |
| 36 | +use WooCommerce\PayPalCommerce\OrderEndpoints\Helper\WooCommerceOrderCreator; |
38 | 37 | use WooCommerce\PayPalCommerce\Button\Session\CartDataFactory; |
39 | 38 | use WooCommerce\PayPalCommerce\Button\Session\CartDataTransientStorage; |
40 | 39 | use WooCommerce\PayPalCommerce\Button\Validation\CheckoutFormValidator; |
|
161 | 160 | return $factory->for_module( 'ppcp-button' ); |
162 | 161 | }, |
163 | 162 | 'button.pay-now-contexts' => static function ( ContainerInterface $container ): array { |
164 | | - $defaults = array( 'checkout', 'pay-now' ); |
165 | | - |
166 | | - if ( $container->get( 'button.handle-shipping-in-paypal' ) ) { |
167 | | - return array_merge( $defaults, array( 'cart', 'product', 'mini-cart' ) ); |
168 | | - } |
169 | | - |
170 | | - return $defaults; |
| 163 | + return $container->get( 'order-endpoints.pay-now-contexts' ); |
171 | 164 | }, |
172 | 165 | 'button.request-data' => static function ( ContainerInterface $container ): RequestData { |
173 | | - return new RequestData(); |
| 166 | + return $container->get( 'order-endpoints.request-data' ); |
174 | 167 | }, |
175 | 168 | 'button.endpoint.simulate-cart' => static function ( ContainerInterface $container ): SimulateCartEndpoint { |
176 | 169 | return new SimulateCartEndpoint( |
|
182 | 175 | ); |
183 | 176 | }, |
184 | 177 | 'button.endpoint.change-cart' => static function ( ContainerInterface $container ): ChangeCartEndpoint { |
185 | | - if ( ! \WC()->cart ) { |
186 | | - throw new RuntimeException( 'cant initialize endpoint at this moment' ); |
187 | | - } |
188 | | - $cart = WC()->cart; |
189 | | - $shipping = WC()->shipping(); |
190 | | - $request_data = $container->get( 'button.request-data' ); |
191 | | - $purchase_unit_factory = $container->get( 'api.factory.purchase-unit' ); |
192 | | - $cart_products = $container->get( 'button.helper.cart-products' ); |
193 | | - $logger = $container->get( 'woocommerce.logger.woocommerce' ); |
194 | | - return new ChangeCartEndpoint( $cart, $shipping, $request_data, $purchase_unit_factory, $cart_products, $logger ); |
| 178 | + return $container->get( 'order-endpoints.endpoint.change-cart' ); |
195 | 179 | }, |
196 | 180 | 'button.endpoint.create-order' => static function ( ContainerInterface $container ): CreateOrderEndpoint { |
197 | | - $request_data = $container->get( 'button.request-data' ); |
198 | | - $purchase_unit_factory = $container->get( 'api.factory.purchase-unit' ); |
199 | | - $order_endpoint = $container->get( 'api.endpoint.order' ); |
200 | | - $payer_factory = $container->get( 'api.factory.payer' ); |
201 | | - $session_handler = $container->get( 'session.handler' ); |
202 | | - $settings_provider = $container->get( 'settings.settings-provider' ); |
203 | | - $early_order_handler = $container->get( 'button.helper.early-order-handler' ); |
204 | | - $registration_needed = $container->get( 'button.current-user-must-register' ); |
205 | | - $logger = $container->get( 'woocommerce.logger.woocommerce' ); |
206 | | - return new CreateOrderEndpoint( |
207 | | - $request_data, |
208 | | - $purchase_unit_factory, |
209 | | - $container->get( 'api.factory.shipping-preference' ), |
210 | | - $container->get( 'api.factory.return-url' ), |
211 | | - $container->get( 'api.factory.contact-preference' ), |
212 | | - $container->get( 'wcgateway.builder.experience-context' ), |
213 | | - $order_endpoint, |
214 | | - $payer_factory, |
215 | | - $session_handler, |
216 | | - $settings_provider, |
217 | | - $early_order_handler, |
218 | | - $container->get( 'button.session.factory.card-data' ), |
219 | | - $container->get( 'button.session.storage.card-data.transient' ), |
220 | | - $registration_needed, |
221 | | - $container->get( 'wcgateway.settings.card_billing_data_mode' ), |
222 | | - $container->get( 'button.early-wc-checkout-validation-enabled' ), |
223 | | - $container->get( 'button.pay-now-contexts' ), |
224 | | - $container->get( 'button.handle-shipping-in-paypal' ), |
225 | | - $container->get( 'wcgateway.server-side-shipping-callback-enabled' ), |
226 | | - $container->get( 'wcgateway.funding-sources-without-redirect' ), |
227 | | - $logger |
228 | | - ); |
| 181 | + return $container->get( 'order-endpoints.endpoint.create-order' ); |
229 | 182 | }, |
230 | 183 | 'button.helper.early-order-handler' => static function ( ContainerInterface $container ): EarlyOrderHandler { |
231 | | - return new EarlyOrderHandler( |
232 | | - $container->get( 'settings.flag.is-connected' ), |
233 | | - $container->get( 'wcgateway.order-processor' ), |
234 | | - $container->get( 'session.handler' ) |
235 | | - ); |
| 184 | + return $container->get( 'order-endpoints.helper.early-order-handler' ); |
236 | 185 | }, |
237 | 186 | 'button.endpoint.approve-order' => static function ( ContainerInterface $container ): ApproveOrderEndpoint { |
238 | | - $request_data = $container->get( 'button.request-data' ); |
239 | | - $order_endpoint = $container->get( 'api.endpoint.order' ); |
240 | | - $session_handler = $container->get( 'session.handler' ); |
241 | | - $three_d_secure = $container->get( 'button.helper.three-d-secure' ); |
242 | | - $settings_provider = $container->get( 'settings.settings-provider' ); |
243 | | - $settings_model = $container->get( 'settings.data.settings' ); |
244 | | - $dcc_applies = $container->get( 'api.helpers.dccapplies' ); |
245 | | - $order_helper = $container->get( 'api.order-helper' ); |
246 | | - $final_review_enabled = $container->get( 'blocks.settings.final_review_enabled' ); |
247 | | - $wc_order_creator = $container->get( 'button.helper.wc-order-creator' ); |
248 | | - $gateway = $container->get( 'wcgateway.paypal-gateway' ); |
249 | | - $logger = $container->get( 'woocommerce.logger.woocommerce' ); |
250 | | - $context = $container->get( 'button.helper.context' ); |
251 | | - |
252 | | - return new ApproveOrderEndpoint( |
253 | | - $request_data, |
254 | | - $order_endpoint, |
255 | | - $session_handler, |
256 | | - $three_d_secure, |
257 | | - $settings_provider, |
258 | | - $settings_model, |
259 | | - $dcc_applies, |
260 | | - $order_helper, |
261 | | - $final_review_enabled, |
262 | | - $gateway, |
263 | | - $wc_order_creator, |
264 | | - $logger, |
265 | | - $context |
266 | | - ); |
| 187 | + return $container->get( 'order-endpoints.endpoint.approve-order' ); |
267 | 188 | }, |
268 | 189 | 'button.endpoint.approve-subscription' => static function ( ContainerInterface $container ): ApproveSubscriptionEndpoint { |
269 | 190 | return new ApproveSubscriptionEndpoint( |
|
333 | 254 | ); |
334 | 255 | }, |
335 | 256 | 'button.helper.cart-products' => static function ( ContainerInterface $container ): CartProductsHelper { |
336 | | - $data_store = \WC_Data_Store::load( 'product' ); |
337 | | - return new CartProductsHelper( $data_store ); |
| 257 | + return $container->get( 'order-endpoints.helper.cart-products' ); |
338 | 258 | }, |
339 | 259 | 'button.helper.isolated-cart-simulator' => static function ( ContainerInterface $container ): IsolatedCartSimulator { |
340 | 260 | return new IsolatedCartSimulator( |
|
363 | 283 | ); |
364 | 284 | }, |
365 | 285 | 'button.is-logged-in' => static function ( ContainerInterface $container ): bool { |
366 | | - return is_user_logged_in(); |
| 286 | + return $container->get( 'order-endpoints.is-logged-in' ); |
367 | 287 | }, |
368 | 288 | 'button.registration-required' => static function ( ContainerInterface $container ): bool { |
369 | | - return WC()->checkout()->is_registration_required(); |
| 289 | + return $container->get( 'order-endpoints.registration-required' ); |
370 | 290 | }, |
371 | 291 | 'button.current-user-must-register' => static function ( ContainerInterface $container ): bool { |
372 | | - return ! $container->get( 'button.is-logged-in' ) && |
373 | | - $container->get( 'button.registration-required' ); |
| 292 | + return $container->get( 'order-endpoints.current-user-must-register' ); |
374 | 293 | }, |
375 | 294 |
|
376 | 295 | 'button.basic-checkout-validation-enabled' => static function ( ContainerInterface $container ): bool { |
|
381 | 300 | return (bool) apply_filters( 'woocommerce_paypal_payments_basic_checkout_validation_enabled', false ); |
382 | 301 | }, |
383 | 302 | 'button.early-wc-checkout-validation-enabled' => static function ( ContainerInterface $container ): bool { |
384 | | - /** |
385 | | - * The filter allowing to disable the WC validation of the checkout form |
386 | | - * when the PayPal button is clicked. |
387 | | - * The validation is triggered in a non-standard way and may cause issues on some sites. |
388 | | - */ |
389 | | - return (bool) apply_filters( 'woocommerce_paypal_payments_early_wc_checkout_validation_enabled', true ); |
| 303 | + return $container->get( 'order-endpoints.early-wc-checkout-validation-enabled' ); |
390 | 304 | }, |
391 | 305 | 'button.validation.wc-checkout-validator' => static function ( ContainerInterface $container ): CheckoutFormValidator { |
392 | 306 | return new CheckoutFormValidator(); |
|
415 | 329 | }; |
416 | 330 | }, |
417 | 331 |
|
418 | | - /** |
419 | | - * If true, the shipping methods are sent to PayPal allowing the customer to select it inside the popup. |
420 | | - * May result in slower popup performance, additional loading. |
421 | | - */ |
422 | 332 | 'button.handle-shipping-in-paypal' => static function ( ContainerInterface $container ): bool { |
423 | | - return ! $container->get( 'blocks.settings.final_review_enabled' ); |
| 333 | + return $container->get( 'order-endpoints.handle-shipping-in-paypal' ); |
424 | 334 | }, |
425 | 335 |
|
426 | 336 | 'button.helper.wc-order-creator' => static function ( ContainerInterface $container ): WooCommerceOrderCreator { |
427 | | - return new WooCommerceOrderCreator( |
428 | | - $container->get( 'wcgateway.funding-source.renderer' ), |
429 | | - $container->get( 'session.handler' ), |
430 | | - $container->get( 'wc-subscriptions.helper' ), |
431 | | - $container->get( 'button.session.factory.card-data' ), |
432 | | - $container->get( 'api.factory.shipping' ), |
433 | | - $container->get( 'api.factory.payer' ) |
434 | | - ); |
| 337 | + return $container->get( 'order-endpoints.helper.wc-order-creator' ); |
435 | 338 | }, |
436 | 339 |
|
437 | 340 | 'button.session.factory.card-data' => static function ( ContainerInterface $container ): CartDataFactory { |
|
0 commit comments