Add target customer id when creating id token

This commit is contained in:
Emili Castells Guasch 2023-10-20 16:46:02 +02:00
parent ffb279115c
commit b07ac130dc
2 changed files with 19 additions and 3 deletions

View file

@ -61,14 +61,25 @@ class UserIdToken {
/**
* Returns `id_token` which uniquely identifies the payer.
*
* @param string $target_customer_id Vaulted customer id.
*
* @return string
*
* @throws PayPalApiException If the request fails.
* @throws RuntimeException If something unexpected happens.
*/
public function id_token(): string {
public function id_token( string $target_customer_id = '' ): string {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v1/oauth2/token?grant_type=client_credentials&response_type=id_token';
$url = trailingslashit( $this->host ) . 'v1/oauth2/token?grant_type=client_credentials&response_type=id_token';
if ( $target_customer_id ) {
$url = add_query_arg(
array(
'target_customer_id' => $target_customer_id,
),
$url
);
}
$args = array(
'method' => 'POST',