From 2cd0ee76c08007f689c1961ef021b4e7d5afbb18 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 20 Jun 2023 14:10:10 -0500 Subject: [PATCH 1/9] Correct title --- src/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.html b/src/index.html index ed575f5..eeac14a 100644 --- a/src/index.html +++ b/src/index.html @@ -2,7 +2,7 @@ - Z-Go! + ZGo - The Zcash Register From 92865a6ee32d4a93ab1560fcc9ad902c22354734 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 20 Jun 2023 14:10:44 -0500 Subject: [PATCH 2/9] Correct language in invoice and receipt --- src/app/language.service.ts | 3 +++ src/app/receipt.service.ts | 19 ++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app/language.service.ts b/src/app/language.service.ts index 475eb45..60aa026 100644 --- a/src/app/language.service.ts +++ b/src/app/language.service.ts @@ -22,6 +22,7 @@ export class LanguageService { private loginURL = ConfigData.Be_URL + 'getloginlang'; private mainURL = ConfigData.Be_URL + 'getmainlang'; private scanURL = ConfigData.Be_URL + 'getscanlang'; + private invoiceURL = ConfigData.Be_URL + 'getinvoicelang'; public zgoLanguage: string = ''; @@ -58,6 +59,8 @@ export class LanguageService { return this.http.get(this.mainURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params}); } else if (viewName === 'scan') { return this.http.get(this.scanURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params}); + } else if (viewName === 'invoice') { + return this.http.get(this.invoiceURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params}); } else { return this.http.get(this.baseURL + '/?lang=' + this.zgoLanguage + diff --git a/src/app/receipt.service.ts b/src/app/receipt.service.ts index 68dd993..36e9bbe 100644 --- a/src/app/receipt.service.ts +++ b/src/app/receipt.service.ts @@ -14,7 +14,8 @@ var Buffer = require('buffer/').Buffer; }) export class ReceiptService { beUrl = ConfigData.Be_URL; - private dataStore: {order: Order, owner: Owner } = { + private dataStore: {order: Order, owner: Owner, name: string } = { + name: '', owner: { _id: '', name: '', @@ -58,34 +59,30 @@ export class ReceiptService { public readonly orderUpdate: Observable = this._orderUpdated.asObservable(); public _nameUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.owner.name); public readonly nameUpdate: Observable= this._nameUpdated.asObservable(); - public readonly ownerUpdate; + //public readonly ownerUpdate; private reqHeaders: HttpHeaders; - private session: null|string; private params: HttpParams; constructor( private http: HttpClient, public userService: UserService ) { - this.session = localStorage.getItem('s4z_token'); + //this.session = localStorage.getItem('s4z_token'); this.params = new HttpParams(); var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64'); this.reqHeaders = new HttpHeaders().set('Authorization', auth); - this.ownerUpdate = userService.ownerUpdate; + //this.ownerUpdate = userService.ownerUpdate; } getOrderById(id:string, token: string) { - let obs = this.http.get<{message: string, order: any}>(this.beUrl+'order/'+id, { headers:this.reqHeaders, params: this.params.append("token", token), observe: 'response'}); + let obs = this.http.get<{message: string, order: any, shop: string}>(this.beUrl+'order/'+id, { headers:this.reqHeaders, params: this.params.append("token", token), observe: 'response'}); obs.subscribe((OrderDataResponse) => { if (OrderDataResponse.status == 200) { this.dataStore.order = OrderDataResponse.body!.order; + this.dataStore.name = OrderDataResponse.body!.shop; this._orderUpdated.next(Object.assign({}, this.dataStore).order); - this.userService.getOwner(); - this.ownerUpdate.subscribe((owner) => { - this.dataStore.owner = owner; - this._nameUpdated.next(Object.assign({}, this.dataStore).owner.name); - }); + this._nameUpdated.next(Object.assign({}, this.dataStore).name); } else { this._orderUpdated.next(Object.assign({}, this.dataStore).order); console.log('No order found'); From c9bf50170dd73c8960c7c1429363129ddc77eff8 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 20 Jun 2023 14:11:18 -0500 Subject: [PATCH 3/9] Enhance viewing key saving --- src/app/invoice/invoice.component.html | 6 +-- src/app/order/order.component.ts | 3 +- src/app/settings/settings.component.html | 2 +- src/app/settings/settings.component.ts | 65 ++++++++++++------------ src/app/user.service.ts | 45 ++++++++++++++-- 5 files changed, 80 insertions(+), 41 deletions(-) diff --git a/src/app/invoice/invoice.component.html b/src/app/invoice/invoice.component.html index 923f99b..91ac922 100644 --- a/src/app/invoice/invoice.component.html +++ b/src/app/invoice/invoice.component.html @@ -89,14 +89,14 @@
-
{{ vE.invoiceScanQrcode }}
-
{{ vE.settingsVkeyLbl }} - diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts index 1d1a431..30c73e7 100644 --- a/src/app/settings/settings.component.ts +++ b/src/app/settings/settings.component.ts @@ -29,7 +29,6 @@ export class SettingsComponent implements OnInit { owner: Owner; useZats: boolean; proVersion: boolean = false; - useVKey: boolean = false; linkMsg: string = ''; xeroAccCod: string = ''; saveAccOk: boolean = false; @@ -117,6 +116,7 @@ export class SettingsComponent implements OnInit { }; // languageRdy = new Subject(); + vKaccess = true; // ------------------------------------------------------------ constructor( @@ -128,13 +128,11 @@ export class SettingsComponent implements OnInit { private dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: {o: Owner}) { this.useZats = data.o.zats; - this.useVKey = data.o.payconf; this.settingsForm = fb.group({ name: [data.o.name, Validators.required], currency: [data.o.currency, Validators.required], useZats: [data.o.zats, Validators.required], useVKey: [data.o.payconf, Validators.required], - // proVersion: [data.invoices, Validators.required], vKey: [data.o.viewkey] }); this.accCodForm = fb.group ({ @@ -142,7 +140,8 @@ export class SettingsComponent implements OnInit { }); if (data.o.payconf) { - this.settingsForm.get('vKey')!.enable(); + this.vKaccess = false; + //this.settingsForm.get('vKey')!.enable(); } this.owner = data.o; this.viewkey = data.o.viewkey; @@ -181,23 +180,24 @@ export class SettingsComponent implements OnInit { ngOnInit() { - this.settingsForm.get('vKey')!.disable(); - // - this.chgUILanguage(); - //console.log('SETTINGS: Return from chgUILanguage()'); - // - this.languageRdy.subscribe ( - data => { - this.linkMsg = this.vE.settingsLink2Xero; - this.pmtServiceURL + ''; - if ( this.linked2Xero ) { - this.linkMsg = this.vE.settingsRelink2Xero; //'Relink to Xero'; - this.pmtServiceURL = - 'https://zgo.cash/pmtservice?owner=' + - this.owner._id + - '&invoiceNo=[INVOICENUMBER]¤cy=[CURRENCY]&amount=[AMOUNTDUE]&shortCode=[SHORTCODE]'; - } - }); + //this.settingsForm.get('vKey')!.disable(); + // + this.vKaccess = true; + this.chgUILanguage(); + //console.log('SETTINGS: Return from chgUILanguage()'); + // + this.languageRdy.subscribe ( + data => { + this.linkMsg = this.vE.settingsLink2Xero; + this.pmtServiceURL + ''; + if ( this.linked2Xero ) { + this.linkMsg = this.vE.settingsRelink2Xero; //'Relink to Xero'; + this.pmtServiceURL = + 'https://zgo.cash/pmtservice?owner=' + + this.owner._id + + '&invoiceNo=[INVOICENUMBER]¤cy=[CURRENCY]&amount=[AMOUNTDUE]&shortCode=[SHORTCODE]'; + } + }); } safeURL(s: string){ @@ -206,7 +206,7 @@ export class SettingsComponent implements OnInit { close() { - this.dialogRef.close(); + this.dialogRef.close(null); } closeIntegration() { @@ -223,8 +223,8 @@ export class SettingsComponent implements OnInit { this.owner.currency = this.settingsForm.value.currency; this.owner.zats = this.settingsForm.value.useZats; this.owner.payconf = this.settingsForm.value.useVKey; - this.viewkey = this.settingsForm.value.vKey; - //this.owner.invoices = this.settingsForm.value.proVersion + this.owner.viewkey = this.settingsForm.value.vKey; + console.log('Settings component key: ' + this.owner.viewkey); this.dialogRef.close(this.owner); } @@ -237,15 +237,16 @@ export class SettingsComponent implements OnInit { } onChangeVKeyOn(ob: MatSlideToggleChange) { -// console.log("Viewing key switch is " + -// ( ob.checked ? "[ON]." : "[OFF]." ) ); - - this.useVKey = ob.checked; + // console.log("Viewing key switch is " + + // ( ob.checked ? "[ON]." : "[OFF]." ) ); - if ( ob.checked ) - this.settingsForm.get('vKey')!.enable(); - else - this.settingsForm.get('vKey')!.disable(); + if ( ob.checked ) { + //this.settingsForm.get('vKey')!.enable(); + this.vKaccess = false; + } else { + //this.settingsForm.get('vKey')!.disable(); + this.vKaccess = true; + } } diff --git a/src/app/user.service.ts b/src/app/user.service.ts index 5756115..d21baba 100644 --- a/src/app/user.service.ts +++ b/src/app/user.service.ts @@ -162,17 +162,54 @@ export class UserService{ } saveOwnerSettings(o: Owner) { - let obs = this.http.post(this.beUrl + 'api/ownersettings', {payload: o}, {headers: this.reqHeaders, params: this.reqParams}); + console.log('saveOwnerSettings: ' + o.viewkey); + if(o.viewkey.length > 20) { + this.saveOwnerViewingKey(o.viewkey).subscribe({ + next: () => { + let obs = this.http.post(this.beUrl + 'api/ownersettings', {payload: o}, {headers: this.reqHeaders, params: this.reqParams}); + obs.subscribe({ + next: () => { + this.getOwner(); + }, + error: (error) => { + if ( error.status == 500 ){ + this.notifierService.showNotification("Saving settings failed", "Close", "error") + } + } + }); + } + }); + } else { + let obs = this.http.post(this.beUrl + 'api/ownersettings', {payload: o}, {headers: this.reqHeaders, params: this.reqParams}); + obs.subscribe({ + next: () => { + this.getOwner(); + }, + error: (error) => { + if ( error.status == 500 ){ + this.notifierService.showNotification("Saving settings failed", "Close", "error") + } + } + }); + } + } + + saveOwnerViewingKey(vk: string){ + let obs = this.http.post(this.beUrl + 'api/ownervk', {payload: vk}, {headers: this.reqHeaders, params: this.reqParams}); obs.subscribe({ next: () => { this.getOwner(); }, error: (error) => { - if ( error.status == 500 ){ - this.notifierService.showNotification("Saving settings failed", "Close", "error") + if (error.status == 400) { + this.notifierService.showNotification('Invalid viewing key, changes not saved', 'Close', 'error'); + } else if (error.status == 403) { + this.notifierService.showNotification('Viewing key does not match shop, changes not saved', 'Close', 'error'); } } - }) + }); + + return obs; } getOwner() { From 9f7a10bcd32b127416fafc4b441bf0794c8992d5 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Tue, 20 Jun 2023 14:11:40 -0500 Subject: [PATCH 4/9] Correct authentication for xero --- src/app/pmtservice/pmtservice.component.ts | 4 ++-- src/app/xero.service.ts | 4 ++-- src/app/xeroreg/xeroreg.component.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/pmtservice/pmtservice.component.ts b/src/app/pmtservice/pmtservice.component.ts index 5a3cba0..c357007 100644 --- a/src/app/pmtservice/pmtservice.component.ts +++ b/src/app/pmtservice/pmtservice.component.ts @@ -182,7 +182,7 @@ vE = { // console.log('received amount -> ' + reqData.amount); const ownParams = new HttpParams().append('id', reqData.ownerId); let obs = this.http.get<{message:string, owner: any}> - ( this.beUrl+'api/ownerid', + ( this.beUrl+'ownerid', { headers: this.reqHeaders, params: ownParams, observe: 'response'}); @@ -227,7 +227,7 @@ vE = { invParams = invParams.append('address', this.owner.address); invParams = invParams.append('inv', reqData.invoice); let inv = this.http.get<{message:string, invData: any}> - ( this.beUrl+'api/invdata', + ( this.beUrl+'invdata', { headers: this.reqHeaders, params: invParams, observe: 'response'}); diff --git a/src/app/xero.service.ts b/src/app/xero.service.ts index b2c1107..cc49000 100644 --- a/src/app/xero.service.ts +++ b/src/app/xero.service.ts @@ -65,8 +65,8 @@ export class XeroService { return obs; } - getXeroAccessToken(code: string, address: string){ - const params = this.reqParams.append('code', code).append('address', address); + getXeroAccessToken(code: string){ + const params = this.reqParams.append('code', code); let obs = this.http.get(this.beUrl + 'api/xerotoken' , {headers: this.reqHeaders, params: params, observe: 'response'}); return obs; } diff --git a/src/app/xeroreg/xeroreg.component.ts b/src/app/xeroreg/xeroreg.component.ts index 2984bf7..a425621 100644 --- a/src/app/xeroreg/xeroreg.component.ts +++ b/src/app/xeroreg/xeroreg.component.ts @@ -77,7 +77,7 @@ export class XeroRegComponent implements OnInit { this.activatedRoute.queryParams.subscribe((params) => { //console.log(params); if (params.state === this.owner.address.substring(0,6)) { - this.xeroService.getXeroAccessToken(params.code, this.owner.address).subscribe(tokenData => { + this.xeroService.getXeroAccessToken(params.code).subscribe(tokenData => { if (tokenData.status == 200) { //console.log(tokenData.body!); this.flag = true; From cb8df58cfcbed1666c695a326af8f92f8e51db30 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Wed, 21 Jun 2023 15:19:27 -0500 Subject: [PATCH 5/9] Update to next version --- CHANGELOG.md | 1 + package.json | 2 +- src/app/app.component.html | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36626ff..ede7a5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Modified order service to query API using `token`. - Modified receipt component to use the new `token`. - Modified invoice component to use the new `token`. +- Modified payment service component to remove order-creation logic. ### Fixed diff --git a/package.json b/package.json index 544bf31..dc6e7b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zgo", - "version": "2.2.0", + "version": "2.3.0", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/src/app/app.component.html b/src/app/app.component.html index 6506163..811f00b 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -45,7 +45,7 @@ style="margin-top: 10px; margin-bottom: 20px;">
© 2023 Vergara Technologies LLC
-
Version 2.2.0
+
Version 2.3.0
{{ vE.mainPriceData }}
From 9a501e966501d274fb40a1fd626d0a205df12d8b Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Wed, 21 Jun 2023 15:21:37 -0500 Subject: [PATCH 6/9] Remove order-creation logic from component --- src/app/pmtservice/pmtservice.component.html | 6 +- src/app/pmtservice/pmtservice.component.ts | 719 +++++++------------ 2 files changed, 270 insertions(+), 455 deletions(-) diff --git a/src/app/pmtservice/pmtservice.component.html b/src/app/pmtservice/pmtservice.component.html index 885987e..b804e64 100644 --- a/src/app/pmtservice/pmtservice.component.html +++ b/src/app/pmtservice/pmtservice.component.html @@ -24,11 +24,11 @@
{{ vE.pmtservicePmtsrvNot }}
{{ vE.pmtserviceEnabledFor }}
- {{ owner.name}} + {{ shop }}
@@ -253,4 +253,4 @@
- \ No newline at end of file + diff --git a/src/app/pmtservice/pmtservice.component.ts b/src/app/pmtservice/pmtservice.component.ts index c357007..7593ab5 100644 --- a/src/app/pmtservice/pmtservice.component.ts +++ b/src/app/pmtservice/pmtservice.component.ts @@ -4,8 +4,6 @@ import { HttpClient, HttpParams, HttpHeaders } from "@angular/common/http"; import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; import { PmtData } from "./pmtservice.model"; import { XeroInvoice } from "./xeroinvoice.model"; -import { Owner } from '../owner.model'; -// import { Item } from '../items/item.model' import { Order } from '../order/order.model' import { ConfigData } from '../configdata'; import { faCheck, faHourglass } from '@fortawesome/free-solid-svg-icons'; @@ -19,481 +17,298 @@ var Buffer = require('buffer/').Buffer; import { LanguageService } from '../language.service'; @Component({ - selector: 'app-pmtservice', - templateUrl: './pmtservice.component.html', - styleUrls: ['./pmtservice.component.css'] + selector: 'app-pmtservice', + templateUrl: './pmtservice.component.html', + styleUrls: ['./pmtservice.component.css'] }) export class PmtserviceComponent implements OnInit { - faCheck = faCheck; - faHourglass = faHourglass; + faCheck = faCheck; + faHourglass = faHourglass; - beUrl = ConfigData.Be_URL; - private reqHeaders: HttpHeaders = new HttpHeaders(); + beUrl = ConfigData.Be_URL; + private reqHeaders: HttpHeaders = new HttpHeaders(); - public pmtData : PmtData = { - ownerId :'', - invoice: '', - amount: 0, - currency: '', - shortcode: '' - }; + public shop: string = ''; + public pmtData : PmtData = { + ownerId :'', + invoice: '', + amount: 0, + currency: '', + shortcode: '' + }; - public invData : XeroInvoice = { - inv_Type : '', - inv_Id : '', - inv_No : '', - inv_Contact : '', - inv_Currency : '', - inv_CurrencyRate : 0, - inv_Status : '', - inv_Total : 0, - inv_Date : new Date(), - inv_shortCode : '', - inv_ProcDate : new Date() - }; + public invData : XeroInvoice = { + inv_Type : '', + inv_Id : '', + inv_No : '', + inv_Contact : '', + inv_Currency : '', + inv_CurrencyRate : 0, + inv_Status : '', + inv_Total : 0, + inv_Date : new Date(), + inv_shortCode : '', + inv_ProcDate : new Date() + }; - public owner: Owner = { - _id: '', - address: '', - name: '', - currency: 'usd', - tax: false, - taxValue: 0, - vat: false, - vatValue: 0, - paid: false, - zats: false, - invoices: false, - expiration: new Date(Date.now()).toISOString(), - payconf: false, - crmToken: '', - viewkey: '' - }; -public order: Order = { - _id : '', - address: '', - session: '', - timestamp: '', - closed: false, - currency: '', - price: 0, - total: 0, - totalZec: 0, - paid: false, - externalInvoice: '', - shortCode: '', - token: '', - lines: [ - { - qty: 1, - name: '', - cost:0 - } - ] - }; + public order: Order = { + _id : '', + address: '', + session: '', + timestamp: '', + closed: false, + currency: '', + price: 0, + total: 0, + totalZec: 0, + paid: false, + externalInvoice: '', + shortCode: '', + token: '', + lines: [ + { + qty: 1, + name: '', + cost:0 + } + ] + }; - private invData_raw : string = ''; - private invData_buff : any = null; + private invData_raw : string = ''; + private invData_buff : any = null; - public reportType = 1000; - public Status = 0; + public reportType = 1000; + public Status = 0; - codeString: string = ''; - zcashUrl: SafeUrl = ''; - zPrice: number = 1.0; - name: string = ''; - error: boolean = false; - orderId : string = ''; -// ------------------------------------- -// Language Support -// -vE = { - pmtserviceInvalidOwnerid : '', - pmtserviceNotservClose : '', - pmtserviceNotservError : '', - pmtserviceCopyNotavail : '', - pmtserviceCopyaddressError : '', - pmtserviceCopyamountError : '', - pmtserviceCopymemoError : '', - pmtservicePaymentNotprocessed : '', - pmtservicePmtsrvNot : '', - pmtserviceEnabledFor : '', - pmtserviceConnectoXero : '', - pmtserviceServerFailed : '', - pmtserviceInvoiceNum : '', - pmtserviceInvoiceNotfound : '', - pmtserviceInvoiceInvalid : '', - pmtserviceInvoicePaid : '', - pmtserviceInvoiceCurrency : '', - pmtserviceCurrencyNotsup : '', - pmtserviceAmountDoesnot : '', - pmtserviceMatchValue : '', - pmtserviceReportedByxero : '', - pmtserviceHdrTxt1 : '', - pmtserviceHdrTxt2 : '', - pmtserviceHdrTxt3 : '', - pmtserviceZecdataPrice : '', - pmtserviceZecdataTotal : '', - pmtserviceInvoiceItem : '', - pmtserviceInvoiceQty : '', - pmtserviceInvoicePrice : '', - pmtserviceInvoiceTotal : '', - pmtservicePaymentConfirmed : '', - pmtservicePaymentPending : '', - pmtserviceScanQrcode : '', - pmtserviceCantScan : '', - pmtserviceUseThis : '', - pmtserviceWalletLink : '', - pmtserviceCopyAddress : '', - pmtserviceCopyAmount : '', - pmtserviceCopyMemo : '' -} -// - constructor(private activatedRoute : ActivatedRoute, - private http : HttpClient, - private sanitizer: DomSanitizer, - private notifierService : NotifierService, - private languageService : LanguageService ) {} + codeString: string = ''; + zcashUrl: SafeUrl = ''; + zPrice: number = 1.0; + name: string = ''; + error: boolean = false; + orderId : string = ''; + // ------------------------------------- + // Language Support + // + vE = { + pmtserviceInvalidOwnerid : '', + pmtserviceNotservClose : '', + pmtserviceNotservError : '', + pmtserviceCopyNotavail : '', + pmtserviceCopyaddressError : '', + pmtserviceCopyamountError : '', + pmtserviceCopymemoError : '', + pmtservicePaymentNotprocessed : '', + pmtservicePmtsrvNot : '', + pmtserviceEnabledFor : '', + pmtserviceConnectoXero : '', + pmtserviceServerFailed : '', + pmtserviceInvoiceNum : '', + pmtserviceInvoiceNotfound : '', + pmtserviceInvoiceInvalid : '', + pmtserviceInvoicePaid : '', + pmtserviceInvoiceCurrency : '', + pmtserviceCurrencyNotsup : '', + pmtserviceAmountDoesnot : '', + pmtserviceMatchValue : '', + pmtserviceReportedByxero : '', + pmtserviceHdrTxt1 : '', + pmtserviceHdrTxt2 : '', + pmtserviceHdrTxt3 : '', + pmtserviceZecdataPrice : '', + pmtserviceZecdataTotal : '', + pmtserviceInvoiceItem : '', + pmtserviceInvoiceQty : '', + pmtserviceInvoicePrice : '', + pmtserviceInvoiceTotal : '', + pmtservicePaymentConfirmed : '', + pmtservicePaymentPending : '', + pmtserviceScanQrcode : '', + pmtserviceCantScan : '', + pmtserviceUseThis : '', + pmtserviceWalletLink : '', + pmtserviceCopyAddress : '', + pmtserviceCopyAmount : '', + pmtserviceCopyMemo : '' + } + // + constructor(private activatedRoute : ActivatedRoute, + private http : HttpClient, + private sanitizer: DomSanitizer, + private notifierService : NotifierService, + private languageService : LanguageService ){ + + } - ngOnInit() { - var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64'); - this.reqHeaders = new HttpHeaders().set('Authorization', auth); - this.activatedRoute.queryParams.subscribe((params) => { - this.pmtData.ownerId = params["owner"]; - this.pmtData.invoice = params["invoiceNo"]; - this.pmtData.amount = params["amount"]; - this.pmtData.currency = params["currency"]; - this.pmtData.shortcode = params["shortCode"]; - this.getInvoiceData( this.pmtData ); - }); - this.chgUILanguage(); - } + ngOnInit() { + var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64'); + this.reqHeaders = new HttpHeaders().set('Authorization', auth); + this.activatedRoute.queryParams.subscribe((params) => { + this.pmtData.ownerId = params["owner"]; + this.pmtData.invoice = params["invoiceNo"]; + this.pmtData.amount = params["amount"]; + this.pmtData.currency = params["currency"]; + this.pmtData.shortcode = params["shortCode"]; + this.getInvoiceData( this.pmtData ); + }); + this.chgUILanguage(); + } - getInvoiceData( reqData : PmtData ) { - - // - // Verify owner id ( Status = 1 if not exists ) - // ( Status = 2 if service not available for user ) - // -// console.log('getOwner -> '+ reqData.ownerId); -// console.log('received amount -> ' + reqData.amount); - const ownParams = new HttpParams().append('id', reqData.ownerId); - let obs = this.http.get<{message:string, owner: any}> - ( this.beUrl+'ownerid', - { headers: this.reqHeaders, - params: ownParams, - observe: 'response'}); - obs.subscribe((OwnerDataResponse) => { - //console.log('api/getowner', OwnerDataResponse.status); - if (OwnerDataResponse.status == 200) { - this.owner = OwnerDataResponse.body!.owner; - console.log('Owner => ' + this.owner.name ); -// -// ==> remove "== false" for production enviroment -// - if ( this.owner.invoices ) { - // process data - console.log("Owner check passed!!!"); - this.getXeroInvoiceData( reqData ); - } else { - console.log("Owner check failed!!!") - this.reportType = 2; - }; - } else { - if ( OwnerDataResponse.status == 204 ) { - console.log('Res.Status = ' + OwnerDataResponse.status) - console.log('Owner id not found!!!'); - this.reportType = 1; - } - }}); - } + getInvoiceData( reqData : PmtData ) { + //this.getXeroInvoiceData( reqData ); + let obs = this.http.post<{reportType: number, order: Order, shop: string}> + (this.beUrl+'invdata', + {payload: reqData}, + {headers: this.reqHeaders, observe: 'response' } + ); + obs.subscribe((invoiceData) => { + this.reportType = invoiceData.body!.reportType; + this.order = invoiceData.body!.order; + this.shop = invoiceData.body!.shop; + this.orderId = String(this.order._id); - getXeroInvoiceData( reqData : PmtData ) { + // console.log('Generating QRCode....') -/* - // Call test Xero API - let url : string = "http://localhost:3000/xero/" + reqData.invoice; - this.http - .get(url) -*/ - console.log('>> find current zcash price'); - this.getPrice(this.owner.currency); + this.codeString = `zcash:${this.order.address}?amount=${this.order.totalZec.toFixed(8)}&memo=${URLSafeBase64.encode(Buffer.from('ZGo Order::'.concat(this.orderId).concat(' Invoice: ').concat(this.order.externalInvoice)))}`; - console.log('get Invoice -> ' + reqData.invoice); - let invParams = new HttpParams(); - invParams = invParams.append('address', this.owner.address); - invParams = invParams.append('inv', reqData.invoice); - let inv = this.http.get<{message:string, invData: any}> - ( this.beUrl+'invdata', - { headers: this.reqHeaders, - params: invParams, - observe: 'response'}); - inv.subscribe( invDataResponse => { -// console.log('Response from ZGo-Xero'); -// console.log(invDataResponse.status); - this.invData_buff = invDataResponse.body; - this.invData.inv_Type = this.invData_buff.invdata.inv_Type; - this.invData.inv_Id = this.invData_buff.invdata.inv_Id; - this.invData.inv_No = this.invData_buff.invdata.inv_No; - this.invData.inv_Contact = this.invData_buff.invdata.inv_Contact; - this.invData.inv_Currency = this.invData_buff.invdata.inv_Currency; - this.invData.inv_CurrencyRate = this.invData_buff.invdata.inv_CurrencyRate; - this.invData.inv_Total = this.invData_buff.invdata.inv_Total; - this.invData.inv_Status = this.invData_buff.invdata.inv_Status; - this.invData.inv_Date = this.invData_buff.invdata.inv_Date; - this.invData.inv_shortCode = reqData.shortcode; - /* - console.log('>>> inv_Type -> ' + this.invData.inv_Type); - console.log('>>> inv_Id -> ' + this.invData.inv_Id); - console.log('>>> inv_No -> ' + this.invData.inv_No); - console.log('>>> inv_Contact -> ' + this.invData.inv_Contact); - console.log('>>> inv_Currency-> ' + this.invData.inv_Currency); - console.log('>>> inv_CurrencyRate -> ' + this.invData.inv_CurrencyRate); - console.log('>>> inv_Total -> ' + this.invData.inv_Total); - console.log('>>> inv_Status-> ' + this.invData.inv_Status); - console.log('>>> inv_Date -> ' + this.invData.inv_Date); -*/ - if ( this.invData.inv_Type == 'ACCREC' ) { - console.log('Invoice type is correct!!'); - // Test if invoice is not already paid - if ( this.invData.inv_Status == 'AUTHORISED') { - console.log('invoice is payable'); - // Test if Invoice's currency is supported - if ( this.invData.inv_Currency == reqData.currency ) { - console.log('Invoice currency supported'); - // Test if requested amount is as reported by Xero - if ( this.invData.inv_Total == reqData.amount ) { - console.log('Invoice amount Ok - create Order'); - // =====> Create order here - this.createOrder(); - // - } else { - console.log('Invoice amount does not match') - this.reportType = 8; - } - } else { - console.log('Invoice currency not supported'); - this.reportType = 7; - } - } else { - console.log('Invoice already paid'); - this.reportType = 6; - } - } else { - console.log('Invoice type is invalid' ); - this.reportType = 5; - } - }, - error => { - console.log("Error while getting invData!!!"); - console.log(error); - console.log(error.status); - if ( error.status == 500 ) { - // Assume that invoice was not found by haskell server - this.reportType = 4; - } + var qrcode = new QRCode(document.getElementById("payment-qr"), { + text: this.codeString, + logo: "/assets/zcash.png", + width: 180, + height: 180, + logoWidth: 50, + logoHeight: 50, + correctLevel: QRCode.CorrectLevel.H + }); - }); - } + this.zcashUrl = this.sanitizer.bypassSecurityTrustUrl(this.codeString); + }); + } - createOrder() { - this.reportType = 0; -// console.log('Starting order generation'); -// console.log('>> find current zcash price'); + getIconStyle(order : Order) { + if( order.paid ) + return "font-size: 14px; color: #72cc50; margin-bottom: -2px;"; + return "color: #FB4F14; margin-bottom: -2px; cursor: pointer;"; - this.order = { - _id: '', - address: this.owner.address, - session: 'Xero-' + this.owner._id, - currency: this.owner.currency, - timestamp: new Date(Date.now()).toISOString(), - closed: true, - totalZec: this.invData.inv_Total/this.zPrice, - price: this.zPrice, - total: this.invData.inv_Total, - paid: false, - externalInvoice: this.invData.inv_No, - shortCode: this.invData.inv_shortCode, - token: '', - lines: [{qty: 1, - name: 'Invoice from ' + this.owner.name + '[' + this.invData.inv_No + ']', - cost: this.invData.inv_Total}] - }; - - let obs = this.http.post<{message: string, order: Order}> - (this.beUrl+'api/orderx', - {payload: this.order}, - { headers: this.reqHeaders } - ); - obs.subscribe((orderData) => { -// console.log('Order created'); + } -// console.log(orderData.order); - this.order = orderData.order - console.log('>> order -> ' + JSON.stringify(this.order)); - this.orderId = String(this.order._id); + copyAddress() { + if (!navigator.clipboard) { + // alert("Copy functionality not supported"); + this.notifierService + .showNotification(this.vE.pmtserviceCopyNotavail, + this.vE.pmtserviceNotservClose, + "error", + this.vE.pmtserviceNotservError); + } + try { + navigator.clipboard.writeText(this.order.address); + } catch (err) { + this.notifierService + .showNotification(this.vE.pmtserviceCopyaddressError, + this.vE.pmtserviceNotservClose, + "error", + this.vE.pmtserviceNotservError); + // console.error("Error", err); + } + } -// console.log('Generating QRCode....') + copyAmount() { + if (!navigator.clipboard) { + // alert("Copy functionality not supported"); + this.notifierService + .showNotification(this.vE.pmtserviceCopyNotavail, + this.vE.pmtserviceNotservClose, + "error", + this.vE.pmtserviceNotservError); + } + try { + navigator.clipboard.writeText(this.order.totalZec.toString()); + } catch (err) { + this.notifierService + .showNotification(this.vE.pmtserviceCopyamountError, + this.vE.pmtserviceNotservClose, + "error", + this.vE.pmtserviceNotservError); + // console.error("Error", err); + } + } - this.codeString = `zcash:${this.order.address}?amount=${this.order.totalZec.toFixed(8)}&memo=${URLSafeBase64.encode(Buffer.from('ZGo Order::'.concat(this.orderId).concat(' Invoice: ').concat(orderData.order.externalInvoice)))}`; + copyMemo() { + if (!navigator.clipboard) { + // alert("Copy functionality not supported"); + this.notifierService + .showNotification(this.vE.pmtserviceCopyNotavail, + this.vE.pmtserviceNotservClose, + "error", + this.vE.pmtserviceNotservError); + } + try { + navigator.clipboard.writeText("ZGo Order::" + this.orderId + " Invoice: " + this.order.externalInvoice); + } catch (err) { + this.notifierService + .showNotification(this.vE.pmtserviceCopymemoError, + this.vE.pmtserviceNotservClose, + "error", + this.vE.pmtserviceNotservError); + // console.error("Error", err); + } + } - var qrcode = new QRCode(document.getElementById("payment-qr"), { - text: this.codeString, - logo: "/assets/zcash.png", - width: 180, - height: 180, - logoWidth: 50, - logoHeight: 50, - correctLevel: QRCode.CorrectLevel.H - }); + chgUILanguage(){ + console.log('PMTSERVICE.chgUILanguage Called '); + this.languageService.getViewElements('pmtservice').subscribe( + response => { + console.log('Received >> ', response ); + console.log('Language Code : ', response.language); + console.log('Component Name : ',response.component); + console.log('Language data : ',response.data); - this.zcashUrl = this.sanitizer.bypassSecurityTrustUrl(this.codeString); - }, error => { - console.log(error.message); - - }); - } + this.vE.pmtserviceInvalidOwnerid = response.data.pmtservice_invalid_ownerid; + this.vE.pmtserviceNotservClose = response.data.pmtservice_notserv_close; + this.vE.pmtserviceNotservError = response.data.pmtservice_notserv_error; + this.vE.pmtserviceCopyNotavail = response.data.pmtservice_copy_notavail; + this.vE.pmtserviceCopyaddressError = response.data.pmtservice_copyaddress_error; + this.vE.pmtserviceCopyamountError = response.data.pmtservice_copyamount_error; + this.vE.pmtserviceCopymemoError = response.data.pmtservice_copymemo_error; + this.vE.pmtservicePaymentNotprocessed = response.data.pmtservice_payment_notprocessed; + this.vE.pmtservicePmtsrvNot = response.data.pmtservice_pmtsrv_not; + this.vE.pmtserviceEnabledFor = response.data.pmtservice_enabled_for; + this.vE.pmtserviceConnectoXero = response.data.pmtservice_connecto_xero; + this.vE.pmtserviceServerFailed = response.data.pmtservice_server_failed; + this.vE.pmtserviceInvoiceNum = response.data.pmtservice_invoice_num; + this.vE.pmtserviceInvoiceNotfound = response.data.pmtservice_invoice_notfound; + this.vE.pmtserviceInvoiceInvalid = response.data.pmtservice_invoice_invalid; + this.vE.pmtserviceInvoicePaid = response.data.pmtservice_invoice_paid; + this.vE.pmtserviceInvoiceCurrency = response.data.pmtservice_invoice_currency; + this.vE.pmtserviceCurrencyNotsup = response.data.pmtservice_currensy_notsup; + this.vE.pmtserviceAmountDoesnot = response.data.pmtservice_amount_doesnot; + this.vE.pmtserviceMatchValue = response.data.pmtservice_match_value; + this.vE.pmtserviceReportedByxero = response.data.pmtservice_reported_byxero; + this.vE.pmtserviceHdrTxt1 = response.data.pmtservice_hdr_txt1; + this.vE.pmtserviceHdrTxt2 = response.data.pmtservice_hdr_txt2; + this.vE.pmtserviceHdrTxt3 = response.data.pmtservice_hdr_txt3; + this.vE.pmtserviceZecdataPrice = response.data.pmtservice_zecdata_price; + this.vE.pmtserviceZecdataTotal = response.data.pmtservice_zecdata_total; + this.vE.pmtserviceInvoiceItem = response.data.pmtservice_invoice_item; + this.vE.pmtserviceInvoiceQty = response.data.pmtservice_invoice_qty; + this.vE.pmtserviceInvoicePrice = response.data.pmtservice_invoice_price; + this.vE.pmtserviceInvoiceTotal = response.data.pmtservice_invoice_total; + this.vE.pmtservicePaymentConfirmed = response.data.pmtservice_payment_confirmed; + this.vE.pmtservicePaymentPending = response.data.pmtservice_payment_pending; + this.vE.pmtserviceScanQrcode = response.data.pmtservice_scan_qrcode; + this.vE.pmtserviceCantScan = response.data.pmtservice_cant_scan; + this.vE.pmtserviceUseThis = response.data.pmtservice_use_this; + this.vE.pmtserviceWalletLink = response.data.pmtservice_wallet_link; + this.vE.pmtserviceCopyAddress = response.data.pmtservice_copy_address; + this.vE.pmtserviceCopyAmount = response.data.pmtservice_copy_amount; + this.vE.pmtserviceCopyMemo = response.data.pmtservice_copy_memo; - getIconStyle(order : Order) { - if( order.paid ) - return "font-size: 14px; color: #72cc50; margin-bottom: -2px;"; - return "color: #FB4F14; margin-bottom: -2px; cursor: pointer;"; - - } - - getPrice(currency: string){ - //var currency = 'usd'; - const params = new HttpParams().append('currency', currency); - let obs = this.http.get<{message: string, price: any}>(this.beUrl+'api/price', { headers:this.reqHeaders, params: params, observe: 'response'}); - obs.subscribe((PriceData) => { - if (PriceData.status == 200) { - this.zPrice = PriceData.body!.price.price; - console.log("price", this.zPrice); - } else { - console.log('No price found for currency', currency); - this.zPrice = 1.0; - } - }); - return obs; - } - - copyAddress() { - if (!navigator.clipboard) { -// alert("Copy functionality not supported"); - this.notifierService - .showNotification(this.vE.pmtserviceCopyNotavail, - this.vE.pmtserviceNotservClose, - "error", - this.vE.pmtserviceNotservError); - } - try { - navigator.clipboard.writeText(this.order.address); - } catch (err) { - this.notifierService - .showNotification(this.vE.pmtserviceCopyaddressError, - this.vE.pmtserviceNotservClose, - "error", - this.vE.pmtserviceNotservError); -// console.error("Error", err); - } - } - copyAmount() { - if (!navigator.clipboard) { -// alert("Copy functionality not supported"); - this.notifierService - .showNotification(this.vE.pmtserviceCopyNotavail, - this.vE.pmtserviceNotservClose, - "error", - this.vE.pmtserviceNotservError); - } - try { - navigator.clipboard.writeText(this.order.totalZec.toString()); - } catch (err) { - this.notifierService - .showNotification(this.vE.pmtserviceCopyamountError, - this.vE.pmtserviceNotservClose, - "error", - this.vE.pmtserviceNotservError); -// console.error("Error", err); - } - } - - copyMemo() { - if (!navigator.clipboard) { -// alert("Copy functionality not supported"); - this.notifierService - .showNotification(this.vE.pmtserviceCopyNotavail, - this.vE.pmtserviceNotservClose, - "error", - this.vE.pmtserviceNotservError); - } - try { - navigator.clipboard.writeText("ZGo Order::" + this.orderId + " Invoice: " + this.order.externalInvoice); - } catch (err) { - this.notifierService - .showNotification(this.vE.pmtserviceCopymemoError, - this.vE.pmtserviceNotservClose, - "error", - this.vE.pmtserviceNotservError); -// console.error("Error", err); - } - } - - chgUILanguage(){ - console.log('PMTSERVICE.chgUILanguage Called '); - this.languageService.getViewElements('pmtservice').subscribe( - response => { - console.log('Received >> ', response ); - console.log('Language Code : ', response.language); - console.log('Component Name : ',response.component); - console.log('Language data : ',response.data); - - this.vE.pmtserviceInvalidOwnerid = response.data.pmtservice_invalid_ownerid; - this.vE.pmtserviceNotservClose = response.data.pmtservice_notserv_close; - this.vE.pmtserviceNotservError = response.data.pmtservice_notserv_error; - this.vE.pmtserviceCopyNotavail = response.data.pmtservice_copy_notavail; - this.vE.pmtserviceCopyaddressError = response.data.pmtservice_copyaddress_error; - this.vE.pmtserviceCopyamountError = response.data.pmtservice_copyamount_error; - this.vE.pmtserviceCopymemoError = response.data.pmtservice_copymemo_error; - this.vE.pmtservicePaymentNotprocessed = response.data.pmtservice_payment_notprocessed; - this.vE.pmtservicePmtsrvNot = response.data.pmtservice_pmtsrv_not; - this.vE.pmtserviceEnabledFor = response.data.pmtservice_enabled_for; - this.vE.pmtserviceConnectoXero = response.data.pmtservice_connecto_xero; - this.vE.pmtserviceServerFailed = response.data.pmtservice_server_failed; - this.vE.pmtserviceInvoiceNum = response.data.pmtservice_invoice_num; - this.vE.pmtserviceInvoiceNotfound = response.data.pmtservice_invoice_notfound; - this.vE.pmtserviceInvoiceInvalid = response.data.pmtservice_invoice_invalid; - this.vE.pmtserviceInvoicePaid = response.data.pmtservice_invoice_paid; - this.vE.pmtserviceInvoiceCurrency = response.data.pmtservice_invoice_currency; - this.vE.pmtserviceCurrencyNotsup = response.data.pmtservice_currensy_notsup; - this.vE.pmtserviceAmountDoesnot = response.data.pmtservice_amount_doesnot; - this.vE.pmtserviceMatchValue = response.data.pmtservice_match_value; - this.vE.pmtserviceReportedByxero = response.data.pmtservice_reported_byxero; - this.vE.pmtserviceHdrTxt1 = response.data.pmtservice_hdr_txt1; - this.vE.pmtserviceHdrTxt2 = response.data.pmtservice_hdr_txt2; - this.vE.pmtserviceHdrTxt3 = response.data.pmtservice_hdr_txt3; - this.vE.pmtserviceZecdataPrice = response.data.pmtservice_zecdata_price; - this.vE.pmtserviceZecdataTotal = response.data.pmtservice_zecdata_total; - this.vE.pmtserviceInvoiceItem = response.data.pmtservice_invoice_item; - this.vE.pmtserviceInvoiceQty = response.data.pmtservice_invoice_qty; - this.vE.pmtserviceInvoicePrice = response.data.pmtservice_invoice_price; - this.vE.pmtserviceInvoiceTotal = response.data.pmtservice_invoice_total; - this.vE.pmtservicePaymentConfirmed = response.data.pmtservice_payment_confirmed; - this.vE.pmtservicePaymentPending = response.data.pmtservice_payment_pending; - this.vE.pmtserviceScanQrcode = response.data.pmtservice_scan_qrcode; - this.vE.pmtserviceCantScan = response.data.pmtservice_cant_scan; - this.vE.pmtserviceUseThis = response.data.pmtservice_use_this; - this.vE.pmtserviceWalletLink = response.data.pmtservice_wallet_link; - this.vE.pmtserviceCopyAddress = response.data.pmtservice_copy_address; - this.vE.pmtserviceCopyAmount = response.data.pmtservice_copy_amount; - this.vE.pmtserviceCopyMemo = response.data.pmtservice_copy_memo; - - }, - error => { console.log('Error >> ',error); } - ); - } + }, + error => { console.log('Error >> ',error); } + ); + } } From 2cd9ded783c865c2534c5551e751c53bf5587ebf Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Wed, 21 Jun 2023 15:42:34 -0500 Subject: [PATCH 7/9] Correct datatype of invoice amount --- src/app/pmtservice/pmtservice.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/pmtservice/pmtservice.component.ts b/src/app/pmtservice/pmtservice.component.ts index 7593ab5..e755311 100644 --- a/src/app/pmtservice/pmtservice.component.ts +++ b/src/app/pmtservice/pmtservice.component.ts @@ -148,7 +148,7 @@ export class PmtserviceComponent implements OnInit { this.activatedRoute.queryParams.subscribe((params) => { this.pmtData.ownerId = params["owner"]; this.pmtData.invoice = params["invoiceNo"]; - this.pmtData.amount = params["amount"]; + this.pmtData.amount = +params["amount"]; this.pmtData.currency = params["currency"]; this.pmtData.shortcode = params["shortCode"]; this.getInvoiceData( this.pmtData ); From a05b76ebedc0ebb0171f255f6011e9117eac68f9 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Wed, 21 Jun 2023 16:00:43 -0500 Subject: [PATCH 8/9] New logic for language API call for pmtservice --- src/app/language.service.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/app/language.service.ts b/src/app/language.service.ts index 60aa026..cda0886 100644 --- a/src/app/language.service.ts +++ b/src/app/language.service.ts @@ -23,6 +23,7 @@ export class LanguageService { private mainURL = ConfigData.Be_URL + 'getmainlang'; private scanURL = ConfigData.Be_URL + 'getscanlang'; private invoiceURL = ConfigData.Be_URL + 'getinvoicelang'; + private pmtservURL = ConfigData.Be_URL + 'getpmtservicelang'; public zgoLanguage: string = ''; @@ -61,6 +62,8 @@ export class LanguageService { return this.http.get(this.scanURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params}); } else if (viewName === 'invoice') { return this.http.get(this.invoiceURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params}); + } else if (viewName === 'pmtservice') { + return this.http.get(this.pmtservURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params}); } else { return this.http.get(this.baseURL + '/?lang=' + this.zgoLanguage + From 84c31bc8248a83a7aa3815e5c1b49c121673abed Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Thu, 22 Jun 2023 16:40:36 -0500 Subject: [PATCH 9/9] Fix QR code generation for Xero invoice --- src/app/pmtservice/pmtservice.component.html | 4 +- src/app/pmtservice/pmtservice.component.ts | 48 +++++++++++--------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/app/pmtservice/pmtservice.component.html b/src/app/pmtservice/pmtservice.component.html index b804e64..d3aba0d 100644 --- a/src/app/pmtservice/pmtservice.component.html +++ b/src/app/pmtservice/pmtservice.component.html @@ -131,7 +131,7 @@
+ >
{{ vE.pmtserviceHdrTxt1 }}
{{ vE.pmtserviceHdrTxt2 }}{{orderId}}
{{ vE.pmtserviceHdrTxt3 }}{{order.timestamp | date}} @@ -206,7 +206,7 @@
diff --git a/src/app/pmtservice/pmtservice.component.ts b/src/app/pmtservice/pmtservice.component.ts index e755311..b324e65 100644 --- a/src/app/pmtservice/pmtservice.component.ts +++ b/src/app/pmtservice/pmtservice.component.ts @@ -80,10 +80,10 @@ export class PmtserviceComponent implements OnInit { private invData_raw : string = ''; private invData_buff : any = null; - public reportType = 1000; + public reportType = 0; public Status = 0; - codeString: string = ''; + codeString: string = 'ZGo - The Zcash Register'; zcashUrl: SafeUrl = ''; zPrice: number = 1.0; name: string = ''; @@ -139,10 +139,6 @@ export class PmtserviceComponent implements OnInit { private sanitizer: DomSanitizer, private notifierService : NotifierService, private languageService : LanguageService ){ - - } - - ngOnInit() { var auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64'); this.reqHeaders = new HttpHeaders().set('Authorization', auth); this.activatedRoute.queryParams.subscribe((params) => { @@ -156,6 +152,9 @@ export class PmtserviceComponent implements OnInit { this.chgUILanguage(); } + ngOnInit() { + } + getInvoiceData( reqData : PmtData ) { //this.getXeroInvoiceData( reqData ); let obs = this.http.post<{reportType: number, order: Order, shop: string}> @@ -164,26 +163,31 @@ export class PmtserviceComponent implements OnInit { {headers: this.reqHeaders, observe: 'response' } ); obs.subscribe((invoiceData) => { - this.reportType = invoiceData.body!.reportType; - this.order = invoiceData.body!.order; - this.shop = invoiceData.body!.shop; - this.orderId = String(this.order._id); + if(invoiceData.status == 201) { + this.reportType = invoiceData.body!.reportType; + this.order = invoiceData.body!.order; + this.shop = invoiceData.body!.shop; + this.orderId = String(this.order._id); - // console.log('Generating QRCode....') + // console.log('Generating QRCode....') - this.codeString = `zcash:${this.order.address}?amount=${this.order.totalZec.toFixed(8)}&memo=${URLSafeBase64.encode(Buffer.from('ZGo Order::'.concat(this.orderId).concat(' Invoice: ').concat(this.order.externalInvoice)))}`; + this.codeString = `zcash:${this.order.address}?amount=${this.order.totalZec.toFixed(8)}&memo=${URLSafeBase64.encode(Buffer.from('ZGo Order::'.concat(this.orderId).concat(' Invoice: ').concat(this.order.externalInvoice)))}`; - var qrcode = new QRCode(document.getElementById("payment-qr"), { - text: this.codeString, - logo: "/assets/zcash.png", - width: 180, - height: 180, - logoWidth: 50, - logoHeight: 50, - correctLevel: QRCode.CorrectLevel.H - }); + var qrcode = new QRCode(document.getElementById("invoice-qr"), { + text: this.codeString, + logo: "/assets/zcash.png", + width: 180, + height: 180, + logoWidth: 50, + logoHeight: 50, + correctLevel: QRCode.CorrectLevel.H + }); - this.zcashUrl = this.sanitizer.bypassSecurityTrustUrl(this.codeString); + this.zcashUrl = this.sanitizer.bypassSecurityTrustUrl(this.codeString); + } else { + this.reportType = invoiceData.body!.reportType; + console.log('reportType ' + invoiceData.body!.reportType + ' code ' + invoiceData.status); + } }); }