Skip to content

Commit

Permalink
*: Refactor Alipay initialization and payment query functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 committed Dec 19, 2023
1 parent 09b01ee commit 9d3beee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
19 changes: 12 additions & 7 deletions apps/extensions/alipay.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ def __init__(self):
if not settings.USE_ALIPAY:
return
# NOTE 暂时只支持支付宝
self.alipay = AliPay(
app_notify_url="",
appid=settings.ALIPAY_APP_ID,
app_private_key_string=settings.ALIPAY_APP_PRIVATE_KEY_STRING,
alipay_public_key_string=settings.ALIPAY_PUBLIC_KEY_STRING,
config=AliPayConfig(timeout=3),
)
self.alipay = None

def init_pay(self):
if self.alipay is None:
self.alipay = AliPay(
app_notify_url="",
appid=settings.ALIPAY_APP_ID,
app_private_key_string=settings.ALIPAY_APP_PRIVATE_KEY_STRING,
alipay_public_key_string=settings.ALIPAY_PUBLIC_KEY_STRING,
config=AliPayConfig(timeout=3),
)

def trade_precreate(
self, out_trade_no, total_amount, subject, timeout_express, notify_url
):
self.init_pay()
return self.alipay.api_alipay_trade_precreate(
out_trade_no=out_trade_no,
total_amount=total_amount,
Expand Down
25 changes: 18 additions & 7 deletions templates/web/charge_center.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ <h2 class="subtitle">
codeBox.attr('class', '')
qrcode_url = results.qrcode_url
$("#id-qrcode-canvas").qrcode(qrcode_url)
queryTimer = setInterval(payquery, 3000);
queryTimer = setInterval(function () {
payquery(true);
}, 3000);
}
})
} else {
Expand All @@ -180,21 +182,30 @@ <h2 class="subtitle">
requestButton.click(payrequest)


function payquery() {
function payquery(byTicker = false) {
msgline.html('后台飞速查询结果中,请稍候...');
$.getJSON(url, function (results) {
info = results.info;
swal(info.title, info.subtitle, info.status);
if (info.status == "success") {
// 停止定时器
clearInterval(queryTimer);
if (byTicker == false) {
swal(info.title, info.subtitle, info.status);
} else {
// only show msg when success
if (info.status == "success") {
// 停止定时器
clearInterval(queryTimer);
swal(info.title, info.subtitle, info.status);
}else{
console.log(info)
}
}
});
}

// 支付查询部分
queryButton = $("#id-button-query")
queryButton.click(payquery)
queryButton.click(function () {
payquery(false);
});
</script>

{% endblock main %}

0 comments on commit 9d3beee

Please sign in to comment.