message ) ) { $response->message = sprintf( /* translators: %1$d - HTTP status code number (404, 500, ...) */ __( 'Unknown error while connecting to PayPal. Status code: %1$d.', 'woocommerce-paypal-payments' ), $this->status_code ); } if ( ! isset( $response->name ) ) { $response->name = __( 'Error', 'woocommerce-paypal-payments' ); } if ( ! isset( $response->details ) ) { $response->details = array(); } if ( ! isset( $response->links ) || ! is_array( $response->links ) ) { $response->links = array(); } /** * The JSON response object. * * @var \stdClass $response */ $this->response = $response; $this->status_code = $status_code; $message = $response->message; if ( $response->name ) { $message = '[' . $response->name . '] ' . $message; } foreach ( $response->links as $link ) { if ( isset( $link->rel ) && 'information_link' === $link->rel ) { $message .= ' ' . $link->href; } } parent::__construct( $message, $status_code ); } /** * The name of the exception. * * @return string */ public function name(): string { return $this->response->name; } /** * The details of the Exception. * * @return array */ public function details(): array { return $this->response->details; } /** * Whether a certain detail is part of the exception reason. * * @param string $issue The issue. * * @return bool */ public function has_detail( string $issue ): bool { foreach ( $this->details() as $detail ) { if ( isset( $detail->issue ) && $detail->issue === $issue ) { return true; } } return false; } /** * Returns response issues. * * @return array */ public function issues(): array { return $this->response->issues ?? array(); } /** * The HTTP status code. * * @return int */ public function status_code(): int { return $this->status_code; } }