request_data = $request_data; $this->identity_token = $identity_token; } /** * Returns the nonce. * * @return string */ public static function nonce(): string { return self::ENDPOINT; } /** * Handles the request. * * @return bool */ public function handle_request(): bool { try { $this->request_data->read_request( $this->nonce() ); $user_id = get_current_user_id(); $token = $this->identity_token->generate_for_customer( $user_id ); wp_send_json( array( 'token' => $token->token(), 'expiration' => $token->expiration_timestamp(), 'user' => get_current_user_id(), ) ); return true; } catch ( RuntimeException $error ) { wp_send_json_error( array( 'name' => is_a( $error, PayPalApiException::class ) ? $error->name() : '', 'message' => $error->getMessage(), 'code' => $error->getCode(), 'details' => is_a( $error, PayPalApiException::class ) ? $error->details() : array(), ) ); return false; } } }