dtinth/promptpay-qr

Can the library be used on the front end?

Opened this issue ยท 3 comments

I believe the API library is written for Node.js? Can it also be used on the front end? Thank you!

OK, I got it working using Browserify:

  1. Clone promptpay-qr
  2. npm install
  3. browserify index.js --s promptpayqr -o front.js
  4. Clone https://github.com/soldair/node-qrcode
  5. npm install
  6. npm run build

then in html file add

<canvas id="qrcode"></canvas>
<script src="front.js"></script>
<script src="qrcode.js"></script> (in node-qrcode's build/ folder)

<script>
var output = promptpayqr('123',{amount:12});
QRCode.toCanvas(document.getElementById('qrcode'), output, function (error) {
    if (error){
    	console.error(error)
	}else{
	    console.log('success!');		    		
	}
  })
 </script>

Thanks for sharing!

Yes it can be used on frontend but it needs to be compiled, e.g. using browserify/rollup/webpack. ๐Ÿ˜„