Merge branch 'xero' of https://gitlab.com/pitmutt/zgo into xero
This commit is contained in:
commit
87ef9ea10a
4 changed files with 43 additions and 4 deletions
|
@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||
|
||||
### Added
|
||||
|
||||
- Added new connection for Xero account code
|
||||
- Added new service for Xero integration
|
||||
|
||||
### Changed
|
||||
|
|
|
@ -20,7 +20,7 @@ const routes: Routes = [
|
|||
{ path: 'receipt/:orderId', component: ReceiptComponent},
|
||||
{ path: 'invoice/:orderId', component: InvoiceComponent},
|
||||
{ path: 'pmtservice', component: PmtserviceComponent},
|
||||
{ path: 'test', component: XeroRegComponent},
|
||||
{ path: 'xeroauth', component: XeroRegComponent},
|
||||
{ path: 'login', component: LoginComponent, resolve: { response: NodeResolverService}}
|
||||
];
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ export class SettingsComponent implements OnInit {
|
|||
useZats: boolean;
|
||||
proVersion: boolean = false;
|
||||
useVKey: boolean = false;
|
||||
linkMsg: String = 'Link to Xero';
|
||||
xeroAccCod: String = '';
|
||||
linkMsg: string = 'Link to Xero';
|
||||
xeroAccCod: string = '';
|
||||
saveAccOk: boolean = false;
|
||||
|
||||
coins = [
|
||||
|
@ -47,12 +47,16 @@ export class SettingsComponent implements OnInit {
|
|||
},{
|
||||
label: 'Australian Dollar',
|
||||
symbol: 'aud'
|
||||
},{
|
||||
label: 'New Zealand Dollar',
|
||||
symbol: 'nzd'
|
||||
}
|
||||
];
|
||||
xeroLink: string = '';
|
||||
localToken: string = '';
|
||||
clientId: string = '';
|
||||
clientIdUpdate: Observable<string>;
|
||||
accCodeUpdate: Observable<string>;
|
||||
linked2Xero : boolean = false;
|
||||
pmtServiceURL : string = '';
|
||||
|
||||
|
@ -86,6 +90,11 @@ export class SettingsComponent implements OnInit {
|
|||
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.accCodeUpdate = xeroService.accCodeUpdate;
|
||||
xeroService.getXeroAccountCode(this.owner.address);
|
||||
this.accCodeUpdate.subscribe(accData => {
|
||||
this.xeroAccCod = accData;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
|
|
@ -20,12 +20,15 @@ export class XeroService {
|
|||
scope: '',
|
||||
tokenType: ''
|
||||
};
|
||||
xeroAcc: string = '';
|
||||
private _clientIdUpdated: BehaviorSubject<string> = new BehaviorSubject(this.clientId);
|
||||
//private _clientSecretUpdated: BehaviorSubject<string> = new BehaviorSubject(this.clientSecret);
|
||||
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 clientSecretUpdate: Observable<string> = this._clientSecretUpdated.asObservable();
|
||||
public readonly tokenUpdate: Observable<any> = this._tokenUpdated.asObservable();
|
||||
public readonly accCodeUpdate: Observable<string> = this._accCodeUpdated.asObservable();
|
||||
private reqHeaders: HttpHeaders;
|
||||
|
||||
constructor(
|
||||
|
@ -55,7 +58,33 @@ export class XeroService {
|
|||
|
||||
getXeroAccessToken(code: string, address: string){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue