feat(forum): multi-gateway cashier for pay-visibility topics

Replace balance-only AJAX topic purchase with AKSRT_Topic_Pay REST
cashier (resource orders + Payment_Gateway), reuse cms-download modal,
and unlock on aksrt_order_paid.
This commit is contained in:
kate522 committed 2026-07-15 12:27:59 +08:00
1 parent 3f06675b8c
commit cea22daae7
13 files changed
+768 -262

No files matched your search

-44
View File
@@ -675,49 +675,6 @@
});
}
function bindPurchaseButton(button) {
button.addEventListener('click', function () {
var topicId = parseInt(button.getAttribute('data-topic-id') || '0', 10);
var price = button.getAttribute('data-price') || '0';
var isFree = button.getAttribute('data-free') === '1';
var feedback = button.parentElement ? button.parentElement.querySelector('.js-aksrt-action-feedback') : null;
if (!topicId) {
return;
}
var confirmMsg = isFree
? '确认使用 VIP 免费解锁此主题?'
: ('确认使用余额支付 ¥' + price + ' 购买此主题?');
if (!window.confirm(confirmMsg)) {
return;
}
button.disabled = true;
setFeedback(feedback, isFree ? '正在解锁…' : '正在支付…', 'is-loading');
var data = new FormData();
data.append('action', 'aksrt_forum_purchase_topic');
data.append('topic_id', topicId);
data.append('_nonce', rootData.forumNonce || '');
fetch((rootData.ajaxUrl || '/wp-admin/admin-ajax.php'), {
method: 'POST',
body: data,
credentials: 'same-origin',
}).then(function (r) { return r.json(); }).then(function (payload) {
if (!payload.success) {
throw new Error((payload.data && payload.data.message) || '购买失败');
}
setFeedback(feedback, '购买成功,正在刷新…', 'is-success');
setTimeout(function () { window.location.reload(); }, 800);
}).catch(function (error) {
setFeedback(feedback, error.message || '购买失败', 'is-error');
button.disabled = false;
});
});
}
function formatFollowPayLabel(pay) {
pay = pay || {};
if (pay.is_free) {
@@ -1558,7 +1515,6 @@
document.querySelectorAll('.js-aksrt-topic-score').forEach(bindScoreButton);
document.querySelectorAll('.js-aksrt-adopt-answer').forEach(bindAdoptButton);
document.querySelectorAll('.js-aksrt-unlock-topic').forEach(bindUnlockButton);
document.querySelectorAll('.js-aksrt-purchase-topic').forEach(bindPurchaseButton);
document.querySelectorAll('.js-aksrt-follow-plate').forEach(bindFollowPlateButton);
bindForumCommentEngine();
bindForumHomeTabs();