-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.html
135 lines (123 loc) · 6.69 KB
/
main.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
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Pi Example</title>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, user-scalable=yes">
<!-- ios support -->
<meta name="apple-mobile-web-app-status-bar" content="#db4938" />
<meta name="theme-color" content="#db4938" />
<meta name="application-name" content="Pi Example">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="assets/js/html5shiv-pre3.6.js"></script>
<![endif]-->
<script type="text/javascript" src="jquery-3.5.1.min.js"></script>
<!--<script src="https://downloads.minepi.com/sdk/v1/dev.js"></script>-->
<!--<script src="https://downloads.minepi.com/sdk/v1/prod.js"></script>-->
<script src="https://sdk.minepi.com/pi-sdk.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</head>
<body>
<div class="container form-group" style="text-align:center">
<input id="pi_donate" name="pi_donate" class="form-text" type="number" min="0" step="0.01" lang="en-US" />
<input id="button_click" name="button_click" value="Donate" type="button" class="btn btn-primary" />
<br /><br />
</div>
<script type="text/javascript">
$(document).ready(function () {
const Pi = window.Pi;
Pi.init({ version: "2.0" });
//alert(PiNetworkClient);
async function auth() {
try {
// Identify the user with their username / unique network-wide ID, and get permission to request payments from them.
const scopes = ['username', 'payments'];
function onIncompletePaymentFound(payment) {
var data = {
'action': 'complete',
'paymentId': payment.identifier,
'txid': payment.transaction.txid,
'app_client': 'LazadaDemoTest'
};
return $.post("https://pisilkroad.com/server1.php", data).done(function (data) {
$("#button_click").prop("disabled", false);
}).fail(function () {
$("#button_click").prop("disabled", false);
});
}; // Read more about this in the SDK reference
Pi.authenticate(scopes, onIncompletePaymentFound).then(function (auth) {
$("#button_click").click(function () {
if (parseFloat($("#pi_donate").val()) > 0) {
$("#button_click").prop("disabled", true);
/*setTimeout(function ()
{
$("#button_click").prop( "disabled", false );
}, 10000);*/
transfer();
}
//alert("Click");
});
//alert('Hello ' + auth.user.username);
}).catch(function (error) {
console.error(error);
});
} catch (err) {
alert(err);
// Not able to fetch the user
}
}
async function transfer() {
try {
const payment = Pi.createPayment({
// Amount of π to be paid:
amount: parseFloat($("#pi_donate").val()),
// An explanation of the payment - will be shown to the user:
memo: "Demo transfer request", // e.g: "Digital kitten #1234",
// An arbitrary developer-provided metadata object - for your own usage:
metadata: { paymentType: "donation" /* ... */ }, // e.g: { kittenId: 1234 }
}, {
// Callbacks you need to implement - read more about those in the detailed docs linked below:
onReadyForServerApproval: function (paymentId) {
var data = {
'action': 'approve',
'paymentId': paymentId,
'txid': '',
'app_client': 'LazadaDemoTest'
};
return $.post("https://pisilkroad.com/server1.php", data).done(function (data) {
$("#button_click").prop("disabled", false);
}).fail(function () {
$("#button_click").prop("disabled", false);
});
},
onReadyForServerCompletion: function (paymentId, txid) {
var data = {
'action': 'complete',
'paymentId': paymentId,
"txid": txid,
'app_client': 'LazadaDemoTest'
};
return $.post("https://pisilkroad.com/server1.php", data).done(function (data) {
$("#button_click").prop("disabled", false);
}).fail(function () {
$("#button_click").prop("disabled", false);
});
},
onCancel: function (paymentId) { $("#button_click").prop("disabled", false); /* ... */ },
onError: function (error, payment) { $("#button_click").prop("disabled", false); /* ... */ },
});
} catch (err) {
$("#button_click").prop("disabled", false);
alert(err);
// Technical problem (eg network failure). Please try again
}
}
auth();
});
</script>
</body>
</html>