From afd39b28df22e4f16bacea742b6a3c21d33bf6c4 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Tue, 12 Aug 2025 16:07:53 +0400 Subject: [PATCH] Use a class that uses the trait instead of calling it directly --- api/order-functions.php | 10 ++++++---- .../src/Processor/TransactionIdHandlingTrait.php | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/api/order-functions.php b/api/order-functions.php index a01829fa2..b7f8a30a5 100644 --- a/api/order-functions.php +++ b/api/order-functions.php @@ -19,14 +19,12 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Entity\Order; use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint; use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentFactoryInterface; -use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentInterface; use WooCommerce\PayPalCommerce\PPCP; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use WooCommerce\PayPalCommerce\WcGateway\Helper\RefundFeesUpdater; use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor; -use \WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait; /** * Returns the PayPal order. @@ -190,8 +188,12 @@ function ppcp_create_order_tracking( WC_Order $wc_order, string $tracking_number assert( $endpoint instanceof OrderTrackingEndpoint ); $paypal_order = ppcp_get_paypal_order( $wc_order ); - $capture_id = TransactionIdHandlingTrait::get_paypal_order_transaction_id( $paypal_order ); - $wc_order_id = $wc_order->get_id(); + $capture_id = $endpoint->get_paypal_order_transaction_id( $paypal_order ); + if ( is_null( $capture_id ) ) { + throw new RuntimeException( 'Could not retrieve transaction ID from PayPal order' ); + } + + $wc_order_id = $wc_order->get_id(); $ppcp_shipment = $shipment_factory->create_shipment( $wc_order_id, diff --git a/modules/ppcp-wc-gateway/src/Processor/TransactionIdHandlingTrait.php b/modules/ppcp-wc-gateway/src/Processor/TransactionIdHandlingTrait.php index 42e2646bc..8d2c1b50e 100644 --- a/modules/ppcp-wc-gateway/src/Processor/TransactionIdHandlingTrait.php +++ b/modules/ppcp-wc-gateway/src/Processor/TransactionIdHandlingTrait.php @@ -67,7 +67,7 @@ trait TransactionIdHandlingTrait { * * @return string|null */ - public static function get_paypal_order_transaction_id( Order $order ): ?string { + public function get_paypal_order_transaction_id( Order $order ): ?string { $purchase_unit = $order->purchase_units()[0] ?? null; if ( ! $purchase_unit ) { return null;