Add session parameter to woocommerce service
This commit is contained in:
parent
313b68b6c6
commit
45ad8d8e6a
1 changed files with 6 additions and 2 deletions
|
@ -12,9 +12,11 @@ var Buffer = require('buffer/').Buffer;
|
||||||
export class WoocommerceService {
|
export class WoocommerceService {
|
||||||
beUrl = ConfigData.Be_URL;
|
beUrl = ConfigData.Be_URL;
|
||||||
private reqHeaders: HttpHeaders;
|
private reqHeaders: HttpHeaders;
|
||||||
|
private reqParams: HttpParams;
|
||||||
private ownerId: string = '';
|
private ownerId: string = '';
|
||||||
private token: string = '';
|
private token: string = '';
|
||||||
private siteurl: string = '';
|
private siteurl: string = '';
|
||||||
|
private session: null | string;
|
||||||
private _ownerIdUpdated: BehaviorSubject<string> = new BehaviorSubject(this.ownerId);
|
private _ownerIdUpdated: BehaviorSubject<string> = new BehaviorSubject(this.ownerId);
|
||||||
private _tokenUpdated: BehaviorSubject<string> = new BehaviorSubject(this.token);
|
private _tokenUpdated: BehaviorSubject<string> = new BehaviorSubject(this.token);
|
||||||
private _siteurlUpdated: BehaviorSubject<string> = new BehaviorSubject(this.siteurl);
|
private _siteurlUpdated: BehaviorSubject<string> = new BehaviorSubject(this.siteurl);
|
||||||
|
@ -27,13 +29,15 @@ export class WoocommerceService {
|
||||||
) {
|
) {
|
||||||
var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64');
|
var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64');
|
||||||
this.reqHeaders = new HttpHeaders().set('Authorization', auth);
|
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._ownerIdUpdated.next(Object.assign({}, this).ownerId);
|
||||||
this._tokenUpdated.next(Object.assign({}, this).token);
|
this._tokenUpdated.next(Object.assign({}, this).token);
|
||||||
this._siteurlUpdated.next(Object.assign({}, this).siteurl);
|
this._siteurlUpdated.next(Object.assign({}, this).siteurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
getWooToken(ownerId: string) {
|
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'});
|
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 => {
|
obs.subscribe(tokenResponse => {
|
||||||
if (tokenResponse.status == 200) {
|
if (tokenResponse.status == 200) {
|
||||||
|
@ -51,7 +55,7 @@ export class WoocommerceService {
|
||||||
}
|
}
|
||||||
|
|
||||||
createWooToken(ownerId: string) {
|
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'});
|
let obs = this.http.post(this.beUrl+'api/wootoken', {}, {headers: this.reqHeaders, params: params, observe: 'response'});
|
||||||
obs.subscribe(responseData => {
|
obs.subscribe(responseData => {
|
||||||
if (responseData.status == 202) {
|
if (responseData.status == 202) {
|
||||||
|
|
Loading…
Reference in a new issue