diff --git a/src/app/woocommerce.service.ts b/src/app/woocommerce.service.ts index a25c13d..392e237 100644 --- a/src/app/woocommerce.service.ts +++ b/src/app/woocommerce.service.ts @@ -12,9 +12,11 @@ var Buffer = require('buffer/').Buffer; export class WoocommerceService { beUrl = ConfigData.Be_URL; private reqHeaders: HttpHeaders; + private reqParams: HttpParams; private ownerId: string = ''; private token: string = ''; private siteurl: string = ''; + private session: null | string; private _ownerIdUpdated: BehaviorSubject = new BehaviorSubject(this.ownerId); private _tokenUpdated: BehaviorSubject = new BehaviorSubject(this.token); private _siteurlUpdated: BehaviorSubject = new BehaviorSubject(this.siteurl); @@ -27,13 +29,15 @@ export class WoocommerceService { ) { var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64'); this.reqHeaders = new HttpHeaders().set('Authorization', auth); + this.session = localStorage.getItem('s4z_token'); + this.reqParams = new HttpParams().append('session', this.session!); this._ownerIdUpdated.next(Object.assign({}, this).ownerId); this._tokenUpdated.next(Object.assign({}, this).token); this._siteurlUpdated.next(Object.assign({}, this).siteurl); } getWooToken(ownerId: string) { - const params = new HttpParams().append('ownerid', ownerId); + const params = this.reqParams.append('ownerid', ownerId); let obs = this.http.get<{ownerid: string, token: string, siteurl: string}>(this.beUrl + 'api/wootoken', {headers: this.reqHeaders, params: params, observe: 'response'}); obs.subscribe(tokenResponse => { if (tokenResponse.status == 200) { @@ -51,7 +55,7 @@ export class WoocommerceService { } createWooToken(ownerId: string) { - const params = new HttpParams().append('ownerid', ownerId); + const params = this.reqParams.append('ownerid', ownerId); let obs = this.http.post(this.beUrl+'api/wootoken', {}, {headers: this.reqHeaders, params: params, observe: 'response'}); obs.subscribe(responseData => { if (responseData.status == 202) {