fix(payment): honor schema defaults for balance recharge and fix withdrawal warning
Fixes two issues:
1. **Balance recharge disabled on fresh install**: The `pay_balance_s`
setting has `default: true` in SchemaPayment but was treated as
disabled when the key was absent from the database. This meant users
had to toggle it off and back on to activate the feature.
Fixed by using `!isset() || !empty()` pattern to honor the schema
default when the key is missing.
2. **PHP Warning in withdrawal settings**: `get_withdrawal_settings()`
passed `$s['affiliate_withdrawal_reset_time']` directly to
`preg_match()` without extracting it first, causing "Undefined
array key" warnings when the option was unset.
Fixed by extracting to `$reset_time_raw` before the regex check.
Changed:
- `PaymentRuntime::get_payment_recharge_settings()`: enabled defaults to true
- `PaymentRuntime::get_payment_gateway_settings()`: balance_enabled defaults to true
- `PaymentRuntime::is_gateway_enabled('balance')`: defaults to true
- `PaymentRuntime::get_withdrawal_settings()`: no longer warns on missing key
Added test script `tools/test-payment-runtime-defaults.php` to verify
the fix works with empty settings (fresh install).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
030baa511e
commit
1549d5b25d
2 files changed
+106
-5
No files matched your search
@@ -88,7 +88,7 @@ class PaymentRuntime {
|
||||
$desc = sanitize_textarea_field((string) ($settings['pay_balance_desc'] ?? ''));
|
||||
|
||||
return [
|
||||
'enabled' => !empty($settings['pay_balance_s']),
|
||||
'enabled' => !isset($settings['pay_balance_s']) || !empty($settings['pay_balance_s']),
|
||||
'withdraw_enabled' => !empty($settings['pay_balance_withdraw_s']),
|
||||
'desc' => $desc,
|
||||
'packages_raw' => $packages,
|
||||
@@ -377,7 +377,7 @@ class PaymentRuntime {
|
||||
}
|
||||
$paypal_enabled = !empty($settings['pay_paypal_sdk_s']);
|
||||
$stripe_enabled = !empty($settings['pay_stripe_sdk_s']);
|
||||
$balance_enabled = !empty($settings['pay_balance_s']);
|
||||
$balance_enabled = !isset($settings['pay_balance_s']) || !empty($settings['pay_balance_s']);
|
||||
// 卡密收款接口随三个兑换开关任一生效(余额 / 积分 / 会员)。
|
||||
$card_pass_enabled = !empty($settings['pay_balance_pass_charge_s'])
|
||||
|| !empty($settings['points_pass_exchange_s'])
|
||||
@@ -512,13 +512,14 @@ class PaymentRuntime {
|
||||
$s = Settings::get_all();
|
||||
$channels = array_values(array_intersect(['alipay', 'wechat'], array_map('sanitize_key', (array) ($s['affiliate_payout_channels'] ?? ['alipay', 'wechat']))));
|
||||
if (!$channels) { $channels = ['alipay', 'wechat']; }
|
||||
$reset_time_raw = (string) ($s['affiliate_withdrawal_reset_time'] ?? '00:00');
|
||||
return [
|
||||
'min_amount' => self::money_decimal($s['affiliate_min_withdrawal'] ?? '50.00', '50.00', 99999900),
|
||||
'service_charge_rate' => max(0, min(100, (int) ($s['affiliate_withdrawal_fee'] ?? 5))),
|
||||
'daily_count' => max(0, min(99999, (int) ($s['affiliate_daily_withdrawal_count'] ?? 3))),
|
||||
'daily_limit' => self::money_decimal($s['affiliate_daily_withdrawal_limit'] ?? '500.00', '500.00', 99999900),
|
||||
'reset_time' => preg_match('/^(?:[01]\\d|2[0-3]):[0-5]\\d$/', (string) ($s['affiliate_withdrawal_reset_time'] ?? '00:00'))
|
||||
? (string) $s['affiliate_withdrawal_reset_time']
|
||||
'reset_time' => preg_match('/^(?:[01]\\d|2[0-3]):[0-5]\\d$/', $reset_time_raw)
|
||||
? $reset_time_raw
|
||||
: '00:00',
|
||||
'payout_channels' => $channels,
|
||||
];
|
||||
@@ -553,7 +554,7 @@ class PaymentRuntime {
|
||||
case 'stripe':
|
||||
return !empty($settings['pay_stripe_sdk_s']);
|
||||
case 'balance':
|
||||
return !empty($settings['pay_balance_s']);
|
||||
return !isset($settings['pay_balance_s']) || !empty($settings['pay_balance_s']);
|
||||
case 'card_pass':
|
||||
// 收款接口随三个兑换开关任一生效(余额 / 积分 / 会员)。
|
||||
return !empty($settings['pay_balance_pass_charge_s'])
|
||||
|
||||
Reference in new issue
Block a user