mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
fix error handling fro tracking endpoint
This commit is contained in:
parent
a4cb280fe3
commit
afc2d31852
2 changed files with 14 additions and 7 deletions
|
@ -32,7 +32,10 @@ class OrderTrackingEndpoint {
|
|||
use RequestTrait, TransactionIdHandlingTrait;
|
||||
|
||||
const ENDPOINT = 'ppc-tracking-info';
|
||||
|
||||
/**
|
||||
* The RequestData.
|
||||
*
|
||||
* @var RequestData
|
||||
*/
|
||||
protected $request_data;
|
||||
|
@ -85,7 +88,7 @@ class OrderTrackingEndpoint {
|
|||
* @param string $host The host.
|
||||
* @param Bearer $bearer The bearer.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param RequestData $request_data
|
||||
* @param RequestData $request_data The Request data.
|
||||
*/
|
||||
public function __construct(
|
||||
string $host,
|
||||
|
@ -189,11 +192,15 @@ class OrderTrackingEndpoint {
|
|||
* Gets the tracking information of a given order.
|
||||
*
|
||||
* @param int $wc_order_id The order ID.
|
||||
* @return array The tracking information.
|
||||
* @psalm-return TrackingInfo
|
||||
* @return array|null The tracking information.
|
||||
* @psalm-return TrackingInfo|null
|
||||
*/
|
||||
public function get_tracking_information( int $wc_order_id ) : array {
|
||||
$wc_order = wc_get_order( $wc_order_id );
|
||||
public function get_tracking_information( int $wc_order_id ) : ?array {
|
||||
$wc_order = wc_get_order( $wc_order_id );
|
||||
if ( ! is_a( $wc_order, WC_Order::class ) ) {
|
||||
throw new RuntimeException( 'wrong order ID' );
|
||||
}
|
||||
|
||||
$transaction_id = $wc_order->get_transaction_id();
|
||||
$tracking_number = get_post_meta( $wc_order_id, '_ppcp_paypal_tracking_number', true );
|
||||
$url = trailingslashit( $this->host ) . 'v1/shipping/trackers/' . $this->find_tracker_id( $transaction_id, $tracking_number );
|
||||
|
@ -224,7 +231,7 @@ class OrderTrackingEndpoint {
|
|||
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
|
||||
if ( 200 !== $status_code ) {
|
||||
return array();
|
||||
return null;
|
||||
}
|
||||
|
||||
return array(
|
||||
|
|
|
@ -112,7 +112,7 @@ class OrderTrackingModule implements ModuleInterface {
|
|||
static function( int $order_id ) use ( $endpoint, $logger ) {
|
||||
$tracking_information = $endpoint->get_tracking_information( $order_id );
|
||||
|
||||
if ( ! empty( $tracking_information ) ) {
|
||||
if ( $tracking_information ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue