From 84c31bc8248a83a7aa3815e5c1b49c121673abed Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Thu, 22 Jun 2023 16:40:36 -0500 Subject: [PATCH] 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); + } }); }