woocommerce-paypal-payments/modules/ppcp-api-client/src/Endpoint/class-requesttrait.php

52 lines
1.2 KiB
PHP
Raw Normal View History

2020-09-01 09:00:45 +03:00
<?php
/**
* The RequestTrait wraps the wp_remote_get functionality for the API client.
*
2020-09-11 14:11:10 +03:00
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
2020-09-01 09:00:45 +03:00
*/
declare(strict_types=1);
2020-09-11 14:11:10 +03:00
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
2020-09-01 09:00:45 +03:00
2021-09-13 15:59:01 +02:00
use WooCommerce\WooCommerce\Logging\Logger\WooCommerceLogger;
2020-09-01 09:00:45 +03:00
/**
* Trait RequestTrait
*/
trait RequestTrait {
/**
* Performs a request
*
* @param string $url The URL to request.
* @param array $args The arguments by which to request.
*
* @return array|\WP_Error
*/
private function request( string $url, array $args ) {
$args['timeout'] = 30;
2020-09-01 09:00:45 +03:00
/**
* This filter can be used to alter the request args.
* For example, during testing, the PayPal-Mock-Response header could be
* added here.
*/
$args = apply_filters( 'ppcp_request_args', $args, $url );
if ( ! isset( $args['headers']['PayPal-Partner-Attribution-Id'] ) ) {
$args['headers']['PayPal-Partner-Attribution-Id'] = 'Woo_PPCP';
}
2021-09-13 13:38:58 +02:00
$response = wp_remote_get( $url, $args );
2021-09-13 15:59:01 +02:00
if ( $this->logger instanceof WooCommerceLogger ) {
2021-09-14 12:46:41 +02:00
$this->logger->logRequestResponse( $url, $args, $response, $this->host );
2021-09-13 13:38:58 +02:00
}
return $response;
2020-09-01 09:00:45 +03:00
}
2021-09-13 15:59:01 +02:00
2020-09-01 09:00:45 +03:00
}