-
Notifications
You must be signed in to change notification settings - Fork 3
/
dunkpay.js
61 lines (48 loc) · 1.23 KB
/
dunkpay.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
DunkPay JavaScript Library
https://www.DunkPay.com
Copyright 2018, Greg You
Dual licensed under the MIT or GPL Version 2 licenses.
Visit https://www.DunkPay.com/license
*/
var PREFIX = "https://www.dunkpay.com/"
var CONTEXT;
var Dunkpay = function (mode) {
if(!mode)
mode = "livenet"
this.mode = mode
CONTEXT = this
}
Dunkpay.prototype.shot = function(callback)
{
if(callback)
{
this.callback = callback
}
var PREFIX = "https://www.dunkpay.com/"
var popup = window.open(PREFIX+this.type+jsonToQueryString(this), "DunkPay.com", "width=500, height=700, toolbar=no, menubar=no, scrollbars=no, resizable=yes" );
popup.focus()
}
Dunkpay.prototype.getLink = function()
{
return PREFIX+this.type+jsonToQueryString(this)
}
function jsonToQueryString(json) {
return "?"+
Object.keys(json).map(function(key) {
return encodeURIComponent(key) + '=' +
encodeURIComponent(json[key]);
}).join('&');
}
window.addEventListener("message", receiveMessage, false);
function receiveMessage(event) {
try {
var jsonData = JSON.parse(event.data)
if(jsonData.transactionId)
{
CONTEXT.callback(undefined , jsonData)
}
}
catch(err) {
}
}