-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdonate.html.js
94 lines (84 loc) · 2.61 KB
/
donate.html.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
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
var payment_method = "wechat";
var auth = "";
var user_id = "";
var rec_id = get_url_param("id", "");
if (rec_id.length > 0) {
auth = authorize_and_redirect();
user_id = Cookies.get("user_id");
}
function update_payment() {
var alipay_qr = "/static/img/alipay-qr.jpg";
var wechatpay_qr = "/static/img/wechatpay-qr.jpg";
var qr = $("#payment-qr");
if (payment_method == "wechat") {
qr.attr('src', wechatpay_qr);
$("#tab-wechat").addClass("active");
$("#tab-alipay").removeClass("active");
}
else {
qr.attr('src', alipay_qr);
$("#tab-alipay").addClass("active");
$("#tab-wechat").removeClass("active");
}
}
$(function(){
update_payment();
if (rec_id.length > 0) {
$("#donate_form").show();
$.ajax({
type: "POST",
url: API_URL+"GetRecord",
data: { rec_id:rec_id, tx:"false" },
dataType: "json",
error: api_error,
success: function(d) { if (api_success(d)) {
var rec = d.result;
$("#payload").html(rec.payload);
if (rec.method != undefined) {
$("#donate_id").val(rec.donate_id);
payment_method = rec.method;
update_payment();
}
}}
});
}
$("#wechat").click(function(event){
payment_method = "wechat";
update_payment();
});
$("#alipay").click(function(event){
payment_method = "alipay";
update_payment();
});
$("#donate_form").submit(function(event){
event.preventDefault();
if (auth.length==0 || user_id.length==0) return;
var reg = /^[0-9]{6}$/;
var donate_id = $("#donate_id").val();
if (!reg.test(donate_id)) {
show_msg("请输入正确订单号");
return;
}
$.ajax({
beforeSend: function(xhr){xhr.setRequestHeader("X-Auth", auth);},
type: "POST",
url: API_URL+"UpdateRecordDonation",
data: { rec_id:rec_id, pay_method:payment_method, donate_id:donate_id },
dataType: "json",
error: api_error,
success: function(d) { if (api_success(d)) {
location = get_url_param("r", "/");
}}
});
});
setInterval(function(){
$.ajax({
type: "GET",
url: "https://blockchain.info/ticker",
dataType: "json",
success: function(d) {
$("#btc_price").html(d.USD.last);
}
});
}, 2000);
});