forked from jbillimoria/JavaScriptButtons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qr.js
38 lines (27 loc) · 900 Bytes
/
qr.js
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
'use strict';
var constants = require('./constants'),
template = require('./util/template');
module.exports = function Qr(data, config) {
var model = {}, url, key;
// Defaults
config = config || {};
config.size = config.size || constants.QR_SIZE;
config.host = config.host || constants.DEFAULT_HOST;
// Construct URL
url = constants.PAYPAL_URL;
url = url.replace('{host}', config.host);
url = url + '?';
for (key in data.items) {
if (data.items.hasOwnProperty(key)) {
url += key + '=' + encodeURIComponent(data.get(key)) + '&';
}
}
url = encodeURIComponent(url);
// Render
model.url = constants.QR_URL
.replace('{host}', config.host)
.replace('{url}', url)
.replace('{pattern}', constants.QR_PATTERN)
.replace('{size}', config.size);
return template(constants.TEMPLATES.qr, model);
};