fix(payment): wire balance wallet end-to-end when pay_balance_s is on

Opening 余额功能 alone now enables cash-wallet pay (unless 余额支付 is explicitly off). Drop points-as-balance fallback, stop fake method injection, expose real wallet in cashiers, and honor auto_to_balance on recharge fulfill.
This commit is contained in:
kate522 committed 2026-07-25 12:46:38 +08:00
1 parent c85774f9a0
commit 3267bee71e
12 files changed
+109 -105

No files matched your search

+17 -3
View File
@@ -120,7 +120,14 @@ trait PayHelpers {
? (class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_currency_name() : __('积分', 'aksrt'))
: '¥'));
$balance = ($uid > 0 && class_exists('\AKSRT\Credits\Credits')) ? \AKSRT\Credits\Credits::balance($uid) : 0;
// Points cashier uses Credits; cash cashier uses wallet (元). Keep both for UI.
$points_balance = ($uid > 0 && class_exists('\AKSRT\Credits\Credits'))
? (int) \AKSRT\Credits\Credits::balance($uid)
: 0;
$wallet_balance = ($uid > 0 && class_exists('\AKSRT\Credits\Balance') && \AKSRT\Credits\Balance::enabled())
? (float) \AKSRT\Credits\Balance::balance($uid)
: 0.0;
$balance = $pay_modo === 'points' ? $points_balance : $wallet_balance;
$methods = $this->available_payment_methods($pay_modo, $uid > 0);
$amount_label = $this->format_amount_label($amount, $pay_modo, $currency);
@@ -140,6 +147,11 @@ trait PayHelpers {
? aksrt_get_user_free_downloaded_number($uid) : 0;
$quota_over = $free_limit > 0 && $free_used >= $free_limit;
$payable_amount = $pay_modo === 'points' ? (int) ceil($payable) : round($payable, 2);
$balance_enough = $pay_modo === 'points'
? ($points_balance >= (int) ceil($amount))
: ($wallet_balance + 0.0001 >= (float) $payable_amount);
return [
'post_id' => $post_id,
'title' => get_the_title($post),
@@ -153,7 +165,7 @@ trait PayHelpers {
'base' => $pay_modo === 'points' ? (int) ceil($base) : round($base, 2),
'list_amount' => $pay_modo === 'points' ? (int) ceil($list_amount) : round($list_amount, 2),
'list_amount_label' => $list_label,
'payable' => $pay_modo === 'points' ? (int) ceil($payable) : round($payable, 2),
'payable' => $payable_amount,
'original' => (float) ($priced['original'] ?? 0),
'vip1' => (float) ($priced['vip1'] ?? 0),
'vip2' => (float) ($priced['vip2'] ?? 0),
@@ -181,7 +193,9 @@ trait PayHelpers {
'need_purchase' => !$has_paid && !$need_vip && $amount > 0,
'logged_in' => $uid > 0,
'balance' => $balance,
'balance_enough' => $pay_modo !== 'points' || $balance >= (int) ceil($amount),
'wallet_balance' => $wallet_balance,
'points_balance' => $points_balance,
'balance_enough' => $balance_enough,
'payment_methods' => $methods,
'login_url' => wp_login_url(get_permalink($post)),
'vip_url' => $vip_page,
+4 -4
View File
@@ -506,9 +506,12 @@ trait VipServicePackages {
* @return array<int, array{id:string,name:string}>
*/
private function available_payment_methods(): array {
if (function_exists('aksrt_list_cash_payment_methods')) {
return aksrt_list_cash_payment_methods(true);
}
$methods = [];
if (!class_exists('\AKSRT\Payment\Gateway')) {
return [['id' => 'balance', 'name' => __('站内余额', 'aksrt')]];
return $methods;
}
$gw = \AKSRT\Payment\Gateway::get_instance();
foreach (['balance', 'alipay', 'wechatpay', 'paypal', 'stripe'] as $id) {
@@ -524,9 +527,6 @@ trait VipServicePackages {
'name' => method_exists($g, 'get_name') ? (string) $g->get_name() : $id,
];
}
if ($methods === []) {
$methods[] = ['id' => 'balance', 'name' => __('站内余额', 'aksrt')];
}
return $methods;
}
+8 -2
View File
@@ -132,7 +132,12 @@ trait VipServicePurchase {
$points_packages = $this->get_points_exchange_packages($vip, $levels);
}
$balance = ($user_id > 0 && class_exists('\AKSRT\Credits\Credits')) ? \AKSRT\Credits\Credits::balance($user_id) : 0;
$points_balance = ($user_id > 0 && class_exists('\AKSRT\Credits\Credits'))
? (int) \AKSRT\Credits\Credits::balance($user_id)
: 0;
$wallet_balance = ($user_id > 0 && class_exists('\AKSRT\Credits\Balance') && \AKSRT\Credits\Balance::enabled())
? (float) \AKSRT\Credits\Balance::balance($user_id)
: 0.0;
$methods = $this->available_payment_methods();
$currency_name = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_currency_name() : __('积分', 'aksrt');
@@ -144,7 +149,8 @@ trait VipServicePurchase {
'user_expires' => $expires,
'user_is_permanent' => $is_permanent,
'user_expires_label' => $this->format_expires_label($expires, $level),
'user_points' => $balance,
'user_points' => $points_balance,
'wallet_balance' => $wallet_balance,
'currency_name' => $currency_name,
'renew_enabled' => $renew_enabled,
'upgrade_enabled' => $upgrade_enabled,