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

103 lines
2.3 KiB
Vue

<template>
<div id="payment">
<img v-if="unpaid" :src="payreqURI" />
<timer v-if="showTimer" :expires="expires" :expired="expired"></timer>
<p class="paid" v-if="paid">Paid on {{paidAt}}</p>
<p class="unpaid" v-if="unpaid">UNPAID</p>
<p class="expired" v-if="expired">EXPIRED</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,
expires: 0,
}
},
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);
})
}
},
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';
},
showTimer: function(){
if (this.invoice.status !== undefined) {
return this.invoice.status != 'paid';
}
return false;
}
},
watch: {
invoice: function(val) {
if (val){
console.log("new invoice")
this.expires = 0;
this.expires = val.expires_at;
if ((new Date(val.expires_at*1000) - new Date() <= 0 ) &&
!this.paid) {
this.expired = true;
} else {
this.expired = false;
}
this.makeLnQR(val.payreq)
}
}
},
components:{
Timer,
}
}
</script>
<style>
img{
width: 340px;
height: 340px;
}
</style>