Files

27 lines
705 B
PHP
Raw Permalink Normal View History

<?php
declare( strict_types=1 );
namespace StreamGoals\PayPal;
/** Production transport backed by wp_remote_request. */
final class WpTransport implements HttpTransport {
public function request( string $method, string $url, array $headers, ?string $body ): array {
$args = array(
'method' => $method,
'headers' => $headers,
'timeout' => 20,
);
if ( null !== $body ) {
$args['body'] = $body;
}
$res = wp_remote_request( $url, $args );
if ( is_wp_error( $res ) ) {
throw new TransportException( $res->get_error_message() );
}
return array(
'status' => (int) wp_remote_retrieve_response_code( $res ),
'body' => (string) wp_remote_retrieve_body( $res ),
);
}
}