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:
1 parent
3f06675b8c
commit
cea22daae7
13 files changed
+768
-262
No files matched your search
@@ -85,19 +85,15 @@ if (empty($topic['can_view'])) :
|
||||
<span class="aksrt-forum-topic__unlock-feedback js-aksrt-action-feedback" aria-live="polite"></span>
|
||||
<?php elseif ($deny_vis === 'pay' && is_user_logged_in()) : ?>
|
||||
<?php
|
||||
$charge_amount = (float) $pay_price;
|
||||
$vip_price_raw = get_post_meta($topic_id, '_aksrt_pay_vip_price', true);
|
||||
$vip_set = ($vip_price_raw !== '' && $vip_price_raw !== null && $vip_price_raw !== false);
|
||||
$viewer_id = get_current_user_id();
|
||||
$is_vip_user = $viewer_id > 0 && function_exists('aksrt_is_vip') && aksrt_is_vip($viewer_id);
|
||||
$is_free_vip = false;
|
||||
if ($is_vip_user && $vip_set) {
|
||||
$charge_amount = max(0.0, (float) $vip_price_raw);
|
||||
$is_free_vip = $charge_amount <= 0;
|
||||
}
|
||||
$price_info = class_exists('AKSRT_Forum')
|
||||
? AKSRT_Forum::get_instance()->resolve_topic_pay_price($topic_id, $viewer_id)
|
||||
: ['amount' => (float) $pay_price, 'is_free' => false, 'label' => '', 'base' => (float) $pay_price];
|
||||
$charge_amount = (float) ($price_info['amount'] ?? 0);
|
||||
$is_free_vip = !empty($price_info['is_free']);
|
||||
?>
|
||||
<button type="button" class="aksrt-forum-topic__primary-btn js-aksrt-purchase-topic"
|
||||
data-topic-id="<?php echo esc_attr((string) $topic_id); ?>"
|
||||
<button type="button" class="aksrt-forum-topic__primary-btn"
|
||||
data-aksrt-pay-topic="<?php echo esc_attr((string) $topic_id); ?>"
|
||||
data-price="<?php echo esc_attr(number_format($charge_amount, 2, '.', '')); ?>"
|
||||
data-free="<?php echo $is_free_vip ? '1' : '0'; ?>">
|
||||
<i class="fas fa-shopping-cart"></i>
|
||||
@@ -105,7 +101,7 @@ if (empty($topic['can_view'])) :
|
||||
if ($is_free_vip) {
|
||||
esc_html_e('VIP 免费解锁', 'aksrt');
|
||||
} else {
|
||||
printf(esc_html__('余额支付 ¥%s', 'aksrt'), esc_html(number_format($charge_amount, 2, '.', '')));
|
||||
printf(esc_html__('购买解锁 ¥%s', 'aksrt'), esc_html(number_format($charge_amount, 2, '.', '')));
|
||||
}
|
||||
?>
|
||||
</button>
|
||||
@@ -168,21 +164,16 @@ if (empty($topic['can_view'])) :
|
||||
<?php elseif ($deny_vis === 'pay') : ?>
|
||||
<?php
|
||||
$viewer_id = get_current_user_id();
|
||||
$vip_price_raw = get_post_meta($topic_id, '_aksrt_pay_vip_price', true);
|
||||
$vip_set = ($vip_price_raw !== '' && $vip_price_raw !== null && $vip_price_raw !== false);
|
||||
$is_vip_user = $viewer_id > 0 && function_exists('aksrt_is_vip') && aksrt_is_vip($viewer_id);
|
||||
if (!$is_vip_user && $viewer_id > 0 && function_exists('aksrt_is_vip_exempt') && aksrt_is_vip_exempt($viewer_id)) {
|
||||
$is_vip_user = true;
|
||||
}
|
||||
$charge_amount = (float) $pay_price;
|
||||
$is_free_vip = false;
|
||||
if ($is_vip_user && $vip_set) {
|
||||
$charge_amount = max(0.0, (float) $vip_price_raw);
|
||||
$is_free_vip = $charge_amount <= 0;
|
||||
}
|
||||
$price_info = class_exists('AKSRT_Forum')
|
||||
? AKSRT_Forum::get_instance()->resolve_topic_pay_price($topic_id, $viewer_id)
|
||||
: ['amount' => (float) $pay_price, 'is_free' => false, 'is_vip_price' => false, 'base' => (float) $pay_price, 'label' => ''];
|
||||
$charge_amount = (float) ($price_info['amount'] ?? 0);
|
||||
$base_amount = (float) ($price_info['base'] ?? $charge_amount);
|
||||
$is_free_vip = !empty($price_info['is_free']);
|
||||
$is_vip_price = !empty($price_info['is_vip_price']);
|
||||
?>
|
||||
<p><?php esc_html_e('该主题为付费内容,请购买后查看。', 'aksrt'); ?></p>
|
||||
<?php if ($is_vip_user && $vip_set) : ?>
|
||||
<?php if ($is_vip_price) : ?>
|
||||
<span class="aksrt-forum-topic__pay-price">
|
||||
<?php
|
||||
if ($is_free_vip) {
|
||||
@@ -192,20 +183,20 @@ if (empty($topic['can_view'])) :
|
||||
esc_html__('VIP 价:¥%s', 'aksrt'),
|
||||
esc_html(number_format($charge_amount, 2, '.', ''))
|
||||
);
|
||||
if (!empty($pay_price) && (float) $pay_price > $charge_amount) {
|
||||
echo ' <del>' . esc_html(sprintf(__('原价 ¥%s', 'aksrt'), number_format((float) $pay_price, 2, '.', ''))) . '</del>';
|
||||
if ($base_amount > $charge_amount) {
|
||||
echo ' <del>' . esc_html(sprintf(__('原价 ¥%s', 'aksrt'), number_format($base_amount, 2, '.', ''))) . '</del>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</span>
|
||||
<?php elseif (!empty($pay_price)) : ?>
|
||||
<span class="aksrt-forum-topic__pay-price"><?php printf(esc_html__('价格:¥%s', 'aksrt'), esc_html(number_format((float) $pay_price, 2, '.', ''))); ?></span>
|
||||
<?php elseif ($charge_amount > 0 || $base_amount > 0) : ?>
|
||||
<span class="aksrt-forum-topic__pay-price"><?php printf(esc_html__('价格:¥%s', 'aksrt'), esc_html(number_format(max($charge_amount, $base_amount), 2, '.', ''))); ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!is_user_logged_in()) : ?>
|
||||
<a href="<?php echo esc_url(wp_login_url(get_permalink($topic_id))); ?>" class="aksrt-forum-topic__primary-btn"><?php esc_html_e('登录后购买', 'aksrt'); ?></a>
|
||||
<?php else : ?>
|
||||
<button type="button" class="aksrt-forum-topic__primary-btn js-aksrt-purchase-topic"
|
||||
data-topic-id="<?php echo esc_attr((string) $topic_id); ?>"
|
||||
<button type="button" class="aksrt-forum-topic__primary-btn"
|
||||
data-aksrt-pay-topic="<?php echo esc_attr((string) $topic_id); ?>"
|
||||
data-price="<?php echo esc_attr(number_format($charge_amount, 2, '.', '')); ?>"
|
||||
data-free="<?php echo $is_free_vip ? '1' : '0'; ?>">
|
||||
<i class="fas fa-shopping-cart"></i>
|
||||
@@ -213,7 +204,7 @@ if (empty($topic['can_view'])) :
|
||||
if ($is_free_vip) {
|
||||
esc_html_e('VIP 免费解锁', 'aksrt');
|
||||
} else {
|
||||
printf(esc_html__('余额支付 ¥%s', 'aksrt'), esc_html(number_format($charge_amount, 2, '.', '')));
|
||||
printf(esc_html__('购买解锁 ¥%s', 'aksrt'), esc_html(number_format($charge_amount, 2, '.', '')));
|
||||
}
|
||||
?>
|
||||
</button>
|
||||
|
||||
Reference in new issue
Block a user