-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQR.js
More file actions
99 lines (99 loc) · 2.92 KB
/
QR.js
File metadata and controls
99 lines (99 loc) · 2.92 KB
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
var createToken = function () {
var x = {"grant_type": "password",
"username": "knupo_test@knupo.com",
"password": "Password1!"
};
$.ajax({
crossDomain: true
, type: 'POST'
, url: "https://immense-badlands-72647.herokuapp.com/oauth/token"
, contentType: 'application/x-www-form-urlencoded; charset=utf-8'
, data: "grant_type=password&username=knupo_test@knupo.com&password=Password1!"
, success: function (data) {
var token = "Bearer " + data.access_token;
createTransaction(token, Math.floor(Math.random() * 10) + 1);
}
, error: function (errMsg) {
console.log(errMsg);
}
});
};
var drawQRImage = function (transactionId, div) {
const QRPrefix = 'knupo://sell?id=';
div = div ? div : 'QRImage';
$('#' + div).qrcode({
render: 'image',
minVersion: 6,
ecLevel: 'H',
left: 0,
top: 0,
size: 448 ,
fill: '#000',
background: null,
text: QRPrefix + transactionId,
radius: 0.5,
quiet: 0,
mode: 4,
mSize: 0.2,
mPosX: 0.5,
mPosY: 0.5,
image: $('#img-buffer')[0]
});
$('#'+div).children().css('max-width','100%')
};
var drawSuccessTransaction = function (div) {
div = div ? div : 'QRImage';
$('#' + div).html('<img width=256 height=256 src="success.png"/>');
};
var getTransaction = function (token, transactionId) {
var fetchingLoop = setInterval(function () {
$.ajax({
crossDomain: true
, type: 'GET'
, url: 'http://knupo.herokuapp.com/transactions/' + transactionId
, headers: {
'Authorization': token
}
, contentType: 'application/json; charset=utf-8'
, dataType: 'json'
, success: function (data) {
if (data.status == 'APPROVED') {
clearInterval(fetchingLoop);
drawSuccessTransaction('QRImage');
}
else {
console.log(data);
}
}
, error: function (errMsg) {
console.log(errMsg);
}
});
}, 1000);
};
var createTransaction = function (token, amount) {
var x = {
'amount': amount
};
$.ajax({
headers: {
'Authorization': token
}
, crossDomain: true
, type: 'POST'
, url: 'http://knupo.herokuapp.com/transactions'
, data: JSON.stringify(x)
, contentType: 'application/json; charset=utf-8'
, dataType: 'json'
, success: function (data) {
drawQRImage(data.id, 'QRImage');
getTransaction(token,data.id);
}
, error: function (errMsg) {
console.log(errMsg);
}
});
};
$(function () {
createToken()
});