Assets
1 year ago
Endpoint
9 months ago
Integration
9 months ago
Shipment
1 year ago
MetaBoxRenderer.php
1 year ago
OrderTrackingModule.php
9 months ago
TrackingAvailabilityTrait.php
10 months ago
TrackingAvailabilityTrait.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * The order tracking module. |
| 5 | * |
| 6 | * @package WooCommerce\PayPalCommerce\OrderTracking |
| 7 | */ |
| 8 | declare (strict_types=1); |
| 9 | namespace WooCommerce\PayPalCommerce\OrderTracking; |
| 10 | |
| 11 | use WC_Order; |
| 12 | use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer; |
| 13 | use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; |
| 14 | use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; |
| 15 | use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor; |
| 16 | trait TrackingAvailabilityTrait |
| 17 | { |
| 18 | /** |
| 19 | * Checks if tracking should be enabled for current post. |
| 20 | * |
| 21 | * @param Bearer $bearer The Bearer. |
| 22 | * @return bool |
| 23 | */ |
| 24 | protected function is_tracking_enabled(Bearer $bearer): bool |
| 25 | { |
| 26 | // phpcs:ignore WordPress.Security.NonceVerification |
| 27 | $post_id = (int) wc_clean(wp_unslash($_GET['id'] ?? $_GET['post'] ?? '')); |
| 28 | if (!$post_id) { |
| 29 | return \false; |
| 30 | } |
| 31 | $order = wc_get_order($post_id); |
| 32 | if (!is_a($order, WC_Order::class)) { |
| 33 | return \false; |
| 34 | } |
| 35 | $captured = $order->get_meta(AuthorizedPaymentsProcessor::CAPTURED_META_KEY); |
| 36 | $is_captured = empty($captured) || wc_string_to_bool($captured); |
| 37 | $is_paypal_order_edit_page = $order->get_meta(PayPalGateway::ORDER_ID_META_KEY) && !empty($order->get_transaction_id()); |
| 38 | try { |
| 39 | $token = $bearer->bearer(); |
| 40 | return $is_paypal_order_edit_page && $is_captured && $token->is_tracking_available() && apply_filters('woocommerce_paypal_payments_shipment_tracking_enabled', \true); |
| 41 | } catch (RuntimeException $exception) { |
| 42 | return \false; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 |