Automattic\WooCommerce\Gateways\PayPal
Request::fetch_paypal_client_id
Fetch the PayPal client-id from the Transact platform.
Method of the class: Request{}
No Hooks.
Returns
String|null. The PayPal client-id, or null if the request fails.
Usage
$Request = new Request(); $Request->fetch_paypal_client_id(): ?string;
Request::fetch_paypal_client_id() Request::fetch paypal client id code WC 10.7.0
public function fetch_paypal_client_id(): ?string {
try {
$request_body = array(
'test_mode' => $this->gateway->testmode,
);
$response = $this->send_wpcom_proxy_request( 'GET', self::WPCOM_PROXY_CLIENT_ID_ENDPOINT, $request_body );
if ( is_wp_error( $response ) ) {
throw new Exception( 'Failed to fetch the client ID. Response error: ' . $response->get_error_message() );
}
$http_code = wp_remote_retrieve_response_code( $response );
$body = wp_remote_retrieve_body( $response );
$response_data = json_decode( $body, true );
if ( 200 !== $http_code ) {
throw new Exception( 'Failed to fetch the client ID. Response status: ' . $http_code . '. Response body: ' . $body );
}
return $response_data['client_id'] ?? null;
} catch ( Exception $e ) {
\WC_Gateway_Paypal::log( $e->getMessage() );
return null;
}
}