-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment.js
79 lines (68 loc) · 2.14 KB
/
payment.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
function check_payment()
{
if (isChromeApp())
chrome.runtime.getBackgroundPage(function(bgpage)
{
$('#debug').val("debug log is empty");
$('#paynoaccess').show();
$('#payloginprogress').show();
$('#chromeloginretry').hide();
$('#paysoonmsg').hide();
$('#paynowmsg').hide();
$('#payment').show();
bgpage.getLicense(function(res)
{
$('#payloginprogress').hide();
$('#chromeloginretry').show();
$('#debug').val(res);
res=JSON_fromString(res);
if (res.accessLevel=='FULL')
{
$('#payment').hide();
return;
}
if (!res.result) // no access at all yet, request user to sign in
{
$('#paynoaccess').show();
$('#paysoonmsg').hide();
$('#paynowmsg').hide();
$('#payment').show();
return;
}
var now=(new Date()).getTime();
var key='freetrialexpired';
if (res.createdTime < now-27*86400*1000) // expired
{
chrome.storage.local.get(key,function(exp)
{
exp=exp[key];
if (!exp)
{
exp=now+3*86400*1000;
setval={};
setval[key]=exp;
chrome.storage.local.set(setval, function(){});
}
var daysleft=(exp-now)/86400/1000;
if (daysleft>0) // show 3 days and continue
{
$('#paynoaccess').hide();
$('#paysoonmsg').show();
$('#paynowmsg').hide();
$('#freedaysleft').text(Math.round(daysleft));
$('#payment').show();
}
else // expired, require purchase
{
$('#paynoaccess').hide();
$('#paysoonmsg').hide();
$('#paynowmsg').show();
$('#payment').show();
}
});
}
else
$('#payment').hide();
});
});
}