-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
182 lines (173 loc) · 4.76 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<html lang="en">
<head>
<title>Pay via PayNow QR</title>
<meta name='viewport' content='width=device-width, initial-scale=1, viewport-fit=cover' />
<style>
body {
background: #f8f8f8;
text-align: center;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
#content {
position: relative;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 100%;
height: 100%;
}
#card {
background: #fff;
padding: 20px;
box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
#card > div {
max-width: 250px;
}
#amount:not(:empty):before {
content: "Amount: "
}
#ref:not(:empty):before {
content: "Reference: "
}
h3 {
margin: 0 0 .1em;
}
#uen {
color: #777;
margin-bottom: .8em;
}
#qr {
width: 250px;
height: 250px;
display: flex;
justify-content: center;
align-items: center;
z-index: 1;
opacity: 0;
transform: scale(.4);
transition: all .3s .2s linear;
}
#qr:not(:empty) {
opacity: 1;
transform: scale(1);
}
#qr img {
width: 250px;
height: 250px;
filter: contrast(0.61) sepia() brightness(1.5) hue-rotate(255deg) saturate(2.4) contrast(2.2);
}
#qr:empty:before {
content: "";
width: 20px;
height: 20px;
border: 3px solid #771976;
border-left-color: transparent;
border-radius: 50%;
animation: rotate 1s linear infinite;
transform: rotate(0deg);
}
@keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#qr + img {
position: relative;
top: -125px;
width: 60px;
height: 36px;
margin: -19px -31px;
border: 2px solid #fff;
background-color: #fff;
object-fit: contain;
z-index: 2;
opacity: 1;
transform: scale(1);
transition: all .5s ease-out;
}
#qr:empty + img {
opacity: 0;
transform: scale(4);
}
#scan {
width: 188px;
border-radius: 3px;
background: #771976;
color: #fff;
font-weight: bold;
padding: .5em 1em;
margin: 0 auto 1em;
}
#qr:empty + img + #scan {
visibility: hidden;
}
#info {
font-size: .8em;
color: #777;
width: 250px;
}
#info a {
color: #777;
}
body.iframe {
background: #fff;
}
</style>
</head>
<body>
<div id="content">
<div id="card">
<h3 id="entity"></h3>
<div id="uen"></div>
<div id="amount"></div>
<div id="ref"></div>
<div id="qr"></div>
<img id="logo" src="./paynow.png" alt="PayNow Logo" />
<div id="scan">SCAN TO PAY</div>
</div>
<div id="info">
<p>Compatible with any PayNow enabled Singapore Banking App.</p>
<a href="https://www.abs.org.sg/consumer-banking/pay-now" target="_blank" rel="noopener noreferrer nofollow">Learn more about PayNow</a>
</div>
</div>
<script>
const uen = '201207337D' // CHANGE TO YOUR UEN
const entity = 'Nerdherd Pte Ltd' // CHANGE TO YOUR ENTITY NAME
const isIframe = location !== top.location
const query = new URL(location).searchParams
const amount = parseFloat(query.get('amount'))
const validAmount = !isNaN(amount) && amount >= 1
const reference = (query.get('reference') || '').replace(/[^a-z0-9 -]/gi, ' ').replace(/ /g, ' ').substr(0, 35)
document.title = `Pay ${entity} via PayNow QR`
if (isIframe) {
document.body.classList.add('iframe')
document.getElementById('content').innerHTML = document.getElementById('qr').outerHTML + document.getElementById('logo').outerHTML
} else {
document.getElementById('entity').innerText = entity
document.getElementById('uen').innerText = uen
document.getElementById('amount').innerText = validAmount ? amount.toLocaleString(undefined, { style: 'currency', currency: 'SGD', maximumFractionDigits: 2, minimumFractionDigits: 2 }) : ''
document.getElementById('ref').innerText = reference
}
</script>
<script src="./qrcode.js"></script>
<script src="./paynow.js"></script>
<script>
const payNowString = generatePayNow({
uen,
editable: validAmount ? '0' : '1',
amount: validAmount ? amount.toFixed(2) : undefined,
entity,
refNumber: reference || undefined
})
const qr = qrcode(0, 'Q')
qr.addData(payNowString)
qr.make()
document.getElementById('qr').innerHTML = qr.createImgTag(6)
</script>
</body>
</html>