My snippets of code
'payment.service.ts'
endpoint_url = "https://api-m.sandbox.paypal.com/v1/oauth2/token"autenticaService(): Observable<Object> { const auth = `${this.client_id}:${this.client_secret}` const data = 'grant_type=client_credentials'; let authString = "Basic "+ window.btoa(auth); return this.httpClient.post( this.endpoint_url, data, { headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': `${authString}` }) } ).pipe( map( data => { console.log(data); return data; } ))}
'shoppingcart.component.ts'
acquista = () => { this.paymentService.autenticaService().subscribe( body => console.log(body));}
I receive a {"HttpErrorResponse status: 401, error: 'invalid_token', error_description: 'Token signature verification failed'} ... where i'm wrong ??The token is what i need in this case.. but it was the request for the token.. so..
Postman
In the Postman app, complete the following:
Set the verb to POST.Enter https://api-m.sandbox.paypal.com/v1/oauth2/token as the request URL.Select the Authorization tab.From the TYPE list, select Basic Auth.In the Username field, enter your client ID.In the Password field, enter your secret.Select the Body tab.Select the x-www-form-urlencoded option.In the KEY field, enter grant_type.In the VALUE field, enter client_credentials.Select Send.
Got the token via Postman..
Tryed also this code
const auth = `${this.client_id}:${this.client_secret}` //const data = 'grant_type=client_credentials'; let authString = "Basic "+ window.btoa(auth); let body = new URLSearchParams(); body.set('grant_type', 'client_credentials'); return this.httpClient.post( this.endpoint_url, body, { headers: new HttpHeaders({ 'Authorization': `${authString}` }) } ).pipe( map( data => { console.log(data); return data; } ))}
Followed this guide too : https://www.youtube.com/watch?v=MBfJEUGNNs0
Can't understand what is the problem..