You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bit4sat/web/src/Pay.vue

89 lines
2.0 KiB
Vue

<template>
<div id="payment">
<img :src="payreqURI" />
<timer v-if="invoice.status != 'paid'" :expires="invoice.expires_at" :expired="expired"></timer>
<p v-if="invoice.status == 'paid'">Paid on {{paidAt}}</p>
<p class='paid' v-if="paid">PAID</p>
<p class='unpaid' v-if="unpaid">UNPAID</p>
<p class='expired' v-if="expired">UNPAID</p>
<canvas id="canvas" hidden>
</div>
</template>
<script charset="utf-8">
import QRCode from 'qrcode';
import Timer from './Timer.vue';
export default {
data() {
return {
payreqURI: "",
expired: false,
}
},
props: ['invoice', 'uploadId', 'status'],
methods:{
makeLnQR(payreq) {
let canvas = this.$el.querySelector('#canvas')
QRCode.toDataURL(canvas, payreq.toUpperCase(), {
margin: 4,
width: 340,
errorCorrectionLevel: 'H',
type: 'png',
renderOpts:{
quality: 1,
}
})
.then(url => {
this.payreqURI = url;
})
.catch(err =>{
console.error(err);
})
}
},
mounted(){
this.expired = (this.invoice.status === 'expired')
},
computed: {
paidAt: function(){
return new Date(this.invoice.paid_at).toGMTString();
},
paid: function() {
return this.invoice.status == 'paid';
},
unpaid: function(){
return this.invoice.status == 'unpaid';
},
},
watch: {
invoice: function(val) {
if (new Date(val.expires_at*1000) - new Date() <= 0){
this.expired = true;
}
this.makeLnQR(val.payreq)
}
},
components:{
Timer,
}
}
</script>
<style>
img{
width: 340px;
height: 340px;
}
</style>