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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 ) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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';
|
|
|
|
}
|
|
|
|
|
|
|
|
return wp_remote_get( $url, $args );
|
|
|
|
}
|
|
|
|
}
|