Quantcast
Channel: Active questions tagged paypal - Stack Overflow
Viewing all articles
Browse latest Browse all 516

Angular 19 . Paypal REST API - Request is not well-formed, syntactically incorrect, or violates schema

$
0
0

Where i'm wrong??

payment.service.ts

  autenticaService(): Observable<Object> {    const uri = '/v1/oauth2/token';    const data = 'grant_type=client_credentials';    let body = new URLSearchParams();    body.set('grant_type', 'client_credentials');    return this.httpClient.post(      `${this.endpoint_url}/v1/oauth2/token`, body ).pipe(        map(          data => {            return data;          }        ))  }  createOrder = (): Observable<Object> => {    let order_data_json = {'intent': 'CAPTURE','purchase_units': [{'amount': {'currency_code': 'EUR','value': '0.01'        }      }]    };    const data = JSON.stringify(order_data_json);    return this.httpClient.post(      `${this.endpoint_url}/v2/checkout/orders`, data, { headers }).pipe(        map(          data => {            console.log(data);            return data;          }        ))  }

shopping-cart.ts

acquista = () => {  //https://www.paypal.com/ncp/payment/AB32BUFY4R824  this.paymentService.autenticaService().subscribe(    body => {      let authPaymentToken = this.paymentService.parseBearer(JSON.stringify(body));      this.cookieService.set("TokenKey", 'Bearer ..here i put the token..');      this.paymentService.createOrder().subscribe(        body => {          console.log(body);          let link = Object(body);          let prodotti: IArticoli[] = [];          this.ordine = {            idord: '000002',            idutente: '123Stezza',            idorganizzazione: 'mygroup',            listaProdotti: this.prodotti,            mailverificata: false,            pagamentoeseguito: false,            date: new Date(),            codStat: 'in attesa',            linkpagamento: link['links'][3]['href']          }          console.log(this.ordine);          this.ordiniService.insOrdine(this.ordine).subscribe({            next: (response) => {              console.log(response);              //window.location.href = link['links'][1]['href'];              this.paymentService.captureOrder(this.ordine.linkpagamento).subscribe({                next: (response) => {                  console.log(response);                  //window.location.href = link['links'][1]['href'];                },                error: (error) => {                  console.log(error);                }              });            },            error: (error) => {              console.log(error);            }          });        }      )    });}

interceptor

if (req.url.indexOf(`${environment.authPaypalUri}/v1/oauth2/token`) === 0) {  const auth = `${environment.client_id}:${environment.client_secret}`;  let authString = "Basic "+ window.btoa(auth);  req = req.clone({    setHeaders: { 'Authorization': `${authString}` }  });  console.log(req);  return next.handle(req);} else if (req.url.indexOf(`${environment.authPaypalUri}/v2/checkout/orders`) === 0) {  const auth = `${environment.client_id}:${environment.client_secret}`;  let authPaymentToken = this.cookieService.get("TokenKey");  req = req.clone({    setHeaders: { 'Content-Type': 'application/json; charset=utf-8', 'Authorization': `${authPaymentToken}`, 'Accept' : 'application/json', }  });  return next.handle(req);}

I'm going crazy with this stuff.. how can i resolve?I think i'm putting everything ok.

I've followed this hints : https://developer.paypal.com/docs/api/orders/v2/#orders_get

I can get the token, sometimes, but the "createOrder()" method doesn't want to go over..

HttpRequestHttpResponse

[EDIT] I've seen now something strange, look at the httprequest, the value has been put in an array

key:'authorization'value:[ "Basic QVFwbXRrTF9RRWZLdFJGWm93R3g1SWo5bHJqcGpWVTRaenZwOWV3S1ZLTmZtTUlsWG94NmUxVVFmaUEyWHR1MmdfRTNMOVNTT1BVX1ZTb3E6RUFWUzB3TlU2UmxUQ0ZFeVFvd19maGVYTzlRem1Td2wzbnlVc2Z4cGd4UE5oY05nY2hKZjdyR2RieGx1cXkyWUw2Q3N1MU82dDRMbDhfczU=" ]

Sometimes it works with this header.. now my client has been accepted by the payment site Paypal and i don't have changed anything in the code... but sometimes it reject this message..

if i redo an other try i've got

key :'authorization'value :'Authorization'

so this is surely uncorrect... now i must understand where i do wrong

......


Viewing all articles
Browse latest Browse all 516

Trending Articles