Implement Xero account service
This commit is contained in:
parent
072da66c10
commit
ce0f85f8dd
2 changed files with 38 additions and 3 deletions
|
@ -27,8 +27,8 @@ export class SettingsComponent implements OnInit {
|
||||||
useZats: boolean;
|
useZats: boolean;
|
||||||
proVersion: boolean = false;
|
proVersion: boolean = false;
|
||||||
useVKey: boolean = false;
|
useVKey: boolean = false;
|
||||||
linkMsg: String = 'Link to Xero';
|
linkMsg: string = 'Link to Xero';
|
||||||
xeroAccCod: String = '';
|
xeroAccCod: string = '';
|
||||||
saveAccOk: boolean = false;
|
saveAccOk: boolean = false;
|
||||||
|
|
||||||
coins = [
|
coins = [
|
||||||
|
@ -56,6 +56,7 @@ export class SettingsComponent implements OnInit {
|
||||||
localToken: string = '';
|
localToken: string = '';
|
||||||
clientId: string = '';
|
clientId: string = '';
|
||||||
clientIdUpdate: Observable<string>;
|
clientIdUpdate: Observable<string>;
|
||||||
|
accCodeUpdate: Observable<string>;
|
||||||
linked2Xero : boolean = false;
|
linked2Xero : boolean = false;
|
||||||
pmtServiceURL : string = '';
|
pmtServiceURL : string = '';
|
||||||
|
|
||||||
|
@ -89,6 +90,11 @@ export class SettingsComponent implements OnInit {
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
this.xeroLink = `https://login.xero.com/identity/connect/authorize?response_type=code&client_id=${this.clientId}&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Ftest&scope=accounting.transactions offline_access&state=${this.owner.address.substring(0, 6)}`
|
this.xeroLink = `https://login.xero.com/identity/connect/authorize?response_type=code&client_id=${this.clientId}&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Ftest&scope=accounting.transactions offline_access&state=${this.owner.address.substring(0, 6)}`
|
||||||
});
|
});
|
||||||
|
this.accCodeUpdate = xeroService.accCodeUpdate;
|
||||||
|
xeroService.getXeroAccountCode(this.owner.address);
|
||||||
|
this.accCodeUpdate.subscribe(accData => {
|
||||||
|
this.xeroAccCod = accData;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
|
@ -20,12 +20,15 @@ export class XeroService {
|
||||||
scope: '',
|
scope: '',
|
||||||
tokenType: ''
|
tokenType: ''
|
||||||
};
|
};
|
||||||
|
xeroAcc: string = '';
|
||||||
private _clientIdUpdated: BehaviorSubject<string> = new BehaviorSubject(this.clientId);
|
private _clientIdUpdated: BehaviorSubject<string> = new BehaviorSubject(this.clientId);
|
||||||
//private _clientSecretUpdated: BehaviorSubject<string> = new BehaviorSubject(this.clientSecret);
|
//private _clientSecretUpdated: BehaviorSubject<string> = new BehaviorSubject(this.clientSecret);
|
||||||
private _tokenUpdated: BehaviorSubject<any> = new BehaviorSubject(this.xeroToken);
|
private _tokenUpdated: BehaviorSubject<any> = new BehaviorSubject(this.xeroToken);
|
||||||
|
private _accCodeUpdated: BehaviorSubject<string> = new BehaviorSubject(this.xeroAcc);
|
||||||
public readonly clientIdUpdate: Observable<string> = this._clientIdUpdated.asObservable();
|
public readonly clientIdUpdate: Observable<string> = this._clientIdUpdated.asObservable();
|
||||||
//public readonly clientSecretUpdate: Observable<string> = this._clientSecretUpdated.asObservable();
|
//public readonly clientSecretUpdate: Observable<string> = this._clientSecretUpdated.asObservable();
|
||||||
public readonly tokenUpdate: Observable<any> = this._tokenUpdated.asObservable();
|
public readonly tokenUpdate: Observable<any> = this._tokenUpdated.asObservable();
|
||||||
|
public readonly accCodeUpdate: Observable<string> = this._accCodeUpdated.asObservable();
|
||||||
private reqHeaders: HttpHeaders;
|
private reqHeaders: HttpHeaders;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -55,7 +58,33 @@ export class XeroService {
|
||||||
|
|
||||||
getXeroAccessToken(code: string, address: string){
|
getXeroAccessToken(code: string, address: string){
|
||||||
const params = new HttpParams().append('code', code).append('address', address);
|
const params = new HttpParams().append('code', code).append('address', address);
|
||||||
let obs = this.http.get(this.beUrl + 'api/xerotoken' , {headers: this.reqHeaders, params: params, observe: 'response'})
|
let obs = this.http.get(this.beUrl + 'api/xerotoken' , {headers: this.reqHeaders, params: params, observe: 'response'});
|
||||||
|
return obs;
|
||||||
|
}
|
||||||
|
|
||||||
|
getXeroAccountCode(address: string){
|
||||||
|
const params = new HttpParams().append('address', address);
|
||||||
|
let obs = this.http.get<{message: string, code: string}>(this.beUrl + 'api/xeroaccount', {headers: this.reqHeaders, params: params, observe: 'response'});
|
||||||
|
obs.subscribe(accountResponse => {
|
||||||
|
if (accountResponse.status == 200) {
|
||||||
|
this.xeroAcc = accountResponse.body!.code;
|
||||||
|
this._accCodeUpdated.next(Object.assign({}, this).xeroAcc);
|
||||||
|
} else {
|
||||||
|
console.log('No account in DB');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return obs;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
setXeroAccountCode(address: string, code: string){
|
||||||
|
const params = new HttpParams().append('address', address).append('code', code);
|
||||||
|
let obs = this.http.post(this.beUrl + 'api/xerotoken', {}, {headers: this.reqHeaders, params: params, observe: 'response'});
|
||||||
|
obs.subscribe(responseData => {
|
||||||
|
if (responseData.status == 202) {
|
||||||
|
console.log('Account saved');
|
||||||
|
}
|
||||||
|
});
|
||||||
return obs;
|
return obs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue