mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
Fix PHPcs errors
This commit is contained in:
parent
cd75b08e9e
commit
a4cb280fe3
2 changed files with 293 additions and 290 deletions
|
@ -39,21 +39,21 @@ return array(
|
|||
return new MetaBoxRenderer(
|
||||
$container->get( 'order-tracking.endpoint.controller' ),
|
||||
$container->get( 'order-tracking.allowed-shipping-statuses' ),
|
||||
$container->get( 'order-tracking.available-carriers' ),
|
||||
$container->get( 'order-tracking.available-carriers' )
|
||||
);
|
||||
},
|
||||
'order-tracking.allowed-shipping-statuses' => static function ( ContainerInterface $container ): array {
|
||||
return array('SHIPPED', 'ON_HOLD', 'DELIVERED', 'CANCELLED');
|
||||
return array( 'SHIPPED', 'ON_HOLD', 'DELIVERED', 'CANCELLED' );
|
||||
},
|
||||
'order-tracking.allowed-carriers' => static function ( ContainerInterface $container ): array {
|
||||
return require __DIR__ . '/carriers.php';
|
||||
},
|
||||
'order-tracking.available-carriers' => static function ( ContainerInterface $container ): array {
|
||||
$wc_default_country = get_option( 'woocommerce_default_country' );
|
||||
$has_state = strpos($wc_default_country, ':');
|
||||
$selected_address = $has_state ? substr($wc_default_country, 0, $has_state) : $wc_default_country;
|
||||
$allowed_carriers = $container->get('order-tracking.allowed-carriers');
|
||||
$selected_country_carriers = $allowed_carriers[$selected_address] ?? [];
|
||||
$has_state = strpos( $wc_default_country, ':' );
|
||||
$selected_address = $has_state ? substr( $wc_default_country, 0, $has_state ) : $wc_default_country;
|
||||
$allowed_carriers = $container->get( 'order-tracking.allowed-carriers' );
|
||||
$selected_country_carriers = $allowed_carriers[ $selected_address ] ?? array();
|
||||
|
||||
return array(
|
||||
$selected_country_carriers,
|
||||
|
@ -62,18 +62,18 @@ return array(
|
|||
'name' => 'Other',
|
||||
'items' => array(
|
||||
'OTHER' => _x( 'Other', 'Name of carrier', 'woocommerce-paypal-payments' ),
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
'order-tracking.is-paypal-order-edit-page' => static function ( ContainerInterface $container ): bool {
|
||||
$orderId = isset( $_GET['post'] ) ? (int)$_GET['post'] : '';
|
||||
if (empty($orderId)) {
|
||||
$order_id = isset( $_GET['post'] ) ? (int) $_GET['post'] : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( empty( $order_id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$meta = get_post_meta($orderId, PayPalGateway::ORDER_ID_META_KEY, true);
|
||||
$meta = get_post_meta( $order_id, PayPalGateway::ORDER_ID_META_KEY, true );
|
||||
|
||||
return !empty($meta);
|
||||
return ! empty( $meta );
|
||||
},
|
||||
);
|
||||
|
|
|
@ -106,17 +106,20 @@ class OrderTrackingEndpoint {
|
|||
try {
|
||||
$data = $this->request_data->read_request( $this->nonce() );
|
||||
$action = $data['action'];
|
||||
$request_body = $this->extract_tracking_information($data);
|
||||
$order_id = (int)$data['order_id'];
|
||||
$action === 'create' ? $this->add_tracking_information($request_body, $order_id) : $this->update_tracking_information($data, $order_id);
|
||||
$request_body = $this->extract_tracking_information( $data );
|
||||
$order_id = (int) $data['order_id'];
|
||||
$action === 'create' ? $this->add_tracking_information( $request_body, $order_id ) : $this->update_tracking_information( $data, $order_id );
|
||||
|
||||
$action_message = $action === 'create' ? 'created' : 'updated';
|
||||
$message = __("successfully {$action_message}",'woocommerce-paypal-payments');
|
||||
wp_send_json_success(array('message' => $message));
|
||||
return true;
|
||||
$message = sprintf(
|
||||
// translators: %1$s is the action message (created or updated).
|
||||
_x( 'successfully %1$s', 'tracking inof success message', 'woocommerce-paypal-payments' ),
|
||||
esc_html( $action_message )
|
||||
);
|
||||
|
||||
wp_send_json_success( array( 'message' => $message ) );
|
||||
} catch ( Exception $error ) {
|
||||
wp_send_json_error( $error->getMessage(), 500 );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,11 +131,11 @@ class OrderTrackingEndpoint {
|
|||
* @param int $order_id The order ID.
|
||||
* @throws RuntimeException If problem creating.
|
||||
*/
|
||||
public function add_tracking_information(array $data, int $order_id) : void {
|
||||
public function add_tracking_information( array $data, int $order_id ) : void {
|
||||
$url = trailingslashit( $this->host ) . 'v1/shipping/trackers-batch';
|
||||
|
||||
$body = array(
|
||||
'trackers' => array($data)
|
||||
'trackers' => array( $data ),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
|
@ -179,7 +182,7 @@ class OrderTrackingEndpoint {
|
|||
throw $error;
|
||||
}
|
||||
|
||||
update_post_meta($order_id, '_ppcp_paypal_tracking_number', $data['tracking_number']);
|
||||
update_post_meta( $order_id, '_ppcp_paypal_tracking_number', $data['tracking_number'] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,11 +192,11 @@ class OrderTrackingEndpoint {
|
|||
* @return array The tracking information.
|
||||
* @psalm-return TrackingInfo
|
||||
*/
|
||||
public function get_tracking_information(int $wc_order_id) : array {
|
||||
public function get_tracking_information( int $wc_order_id ) : array {
|
||||
$wc_order = wc_get_order( $wc_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);
|
||||
$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 );
|
||||
|
||||
$args = array(
|
||||
'method' => 'GET',
|
||||
|
@ -221,7 +224,7 @@ class OrderTrackingEndpoint {
|
|||
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
|
||||
if ( 200 !== $status_code ) {
|
||||
return [];
|
||||
return array();
|
||||
}
|
||||
|
||||
return array(
|
||||
|
@ -240,11 +243,11 @@ class OrderTrackingEndpoint {
|
|||
* @param int $order_id The order ID.
|
||||
* @throws RuntimeException If problem updating.
|
||||
*/
|
||||
public function update_tracking_information(array $data, int $order_id) : void {
|
||||
$tracking_info = $this->get_tracking_information($order_id);
|
||||
public function update_tracking_information( array $data, int $order_id ) : void {
|
||||
$tracking_info = $this->get_tracking_information( $order_id );
|
||||
$transaction_id = $tracking_info['transaction_id'] ?? '';
|
||||
$tracking_number = $tracking_info['tracking_number'] ?? '';
|
||||
$url = trailingslashit( $this->host ) . 'v1/shipping/trackers/'. $this->find_tracker_id($transaction_id, $tracking_number);
|
||||
$url = trailingslashit( $this->host ) . 'v1/shipping/trackers/' . $this->find_tracker_id( $transaction_id, $tracking_number );
|
||||
|
||||
$args = array(
|
||||
'method' => 'PUT',
|
||||
|
@ -290,7 +293,7 @@ class OrderTrackingEndpoint {
|
|||
throw $error;
|
||||
}
|
||||
|
||||
update_post_meta($order_id, '_ppcp_paypal_tracking_number', $data['tracking_number']);
|
||||
update_post_meta( $order_id, '_ppcp_paypal_tracking_number', $data['tracking_number'] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -310,7 +313,7 @@ class OrderTrackingEndpoint {
|
|||
* @return array A map of tracking information keys to values.
|
||||
* @psalm-return TrackingInfo
|
||||
*/
|
||||
protected function extract_tracking_information(array $data): array {
|
||||
protected function extract_tracking_information( array $data ): array {
|
||||
return array(
|
||||
'transaction_id' => $data['transaction_id'] ?? '',
|
||||
'tracking_number' => $data['tracking_number'] ?? '',
|
||||
|
@ -338,7 +341,7 @@ class OrderTrackingEndpoint {
|
|||
* @param string $tracking_number The tracking number.
|
||||
* @return string The tracker ID.
|
||||
*/
|
||||
protected function find_tracker_id(string $transaction_id, string $tracking_number): string {
|
||||
return !empty($tracking_number) ? "{$transaction_id}-{$tracking_number}" : "{$transaction_id}-NOTRACKER";
|
||||
protected function find_tracker_id( string $transaction_id, string $tracking_number ): string {
|
||||
return ! empty( $tracking_number ) ? "{$transaction_id}-{$tracking_number}" : "{$transaction_id}-NOTRACKER";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue