@IonC wrote:
I am developing an Ionic 4 app that should scan and validate QR code for claiming, using PhoneGap Plugin BarcodeScanner. The scanning is working as expected but I’m having difficulties on validating the QR code.
My idea is that the QR code is only valid for the user if the userID and PromotionID matches the QR Code (in Firestore database). I’m using the document ID’s to generate QR code For example, QR code ’ 075u6SGzsZ3tWq1v3Trb ’ and ’ XXDzN47QXqsGZIMeySw0 ’ can only be use by user123.
Below is the implementationExample.page.ts:
qr: any; scanQRCode () { this.options= { preferFrontCamera : false, showFlipCameraButton : true, showTorchButton:true, disableSuccessBeep: false, torchOn: false, prompt: 'Scan your QRcode' }; this.subscription = this.afs.collection('claims') .snapshotChanges() .subscribe(data => { this.qr= data.map(e => { return { id: e.payload.doc.id, promotionID: e.payload.doc.data()['promotion'], userID: e.payload.doc.data()['user'], }; }) console.log(this.item); this.subscription.unsubscribe(); }); this.scanner.scan(this.options).then((data) => { this.scannedData = data; if(this.qr.promotionID && this.qr.userID == data){ this.navCtrl.navigateForward('/nextPage'); }else{ return this.presentAlert('Error','Invalid QRCODE') } }, (err) => { console.log('Error: ',err); }) }
Example.page.html
<ion-button expand="block" icon-left (click)="scanQRCode()"><ion-icon name="qr-scanner"></ion-icon>Scan code</ion-button>
I need help. Please be gentle since I am new to Ionic and Firebase. Thank you.
Posts: 1
Participants: 1