fix: guard against accidental payment config wipe + cleanup from review

- Skip UpdatePaymentConfig when no payment fields provided (prevents wipe)
- Remove unused defaultMinRechargeAmount/defaultMaxRechargeAmount constants
- Fix mergeConfig comment to match actual behavior
This commit is contained in:
erio
2026-04-07 03:05:26 +08:00
parent e1fe15010c
commit 11701e9b5e
3 changed files with 20 additions and 9 deletions
+1 -1
View File
@@ -1 +1 @@
0.1.108.60
0.1.108.61
@@ -660,8 +660,9 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
return
}
// Update payment configuration (integrated into system settings)
if h.paymentConfigService != nil {
// Update payment configuration (integrated into system settings).
// Skip if no payment fields were provided (prevents accidental wipe).
if h.paymentConfigService != nil && hasPaymentFields(req) {
paymentReq := service.UpdatePaymentConfigRequest{
Enabled: req.PaymentEnabled,
MinAmount: req.PaymentMinAmount,
@@ -780,6 +781,17 @@ func (h *SettingHandler) UpdateSettings(c *gin.Context) {
})
}
// hasPaymentFields returns true if any payment-related field was explicitly provided.
func hasPaymentFields(req UpdateSettingsRequest) bool {
return req.PaymentEnabled != nil || req.PaymentMinAmount != nil ||
req.PaymentMaxAmount != nil || req.PaymentDailyLimit != nil ||
req.PaymentOrderTimeoutMin != nil || req.PaymentMaxPendingOrders != nil ||
req.PaymentEnabledTypes != nil || req.PaymentBalanceDisabled != nil ||
req.PaymentLoadBalanceStrat != nil || req.PaymentProductNamePrefix != nil ||
req.PaymentProductNameSuffix != nil || req.PaymentHelpImageURL != nil ||
req.PaymentHelpText != nil
}
func (h *SettingHandler) auditSettingsUpdate(c *gin.Context, before *service.SystemSettings, after *service.SystemSettings, req UpdateSettingsRequest) {
if before == nil || after == nil {
return
@@ -38,10 +38,8 @@ const (
// Default values for payment configuration settings.
const (
defaultMinRechargeAmount = 1
defaultMaxRechargeAmount = 99999999.99
defaultOrderTimeoutMin = 30
defaultMaxPendingOrders = 3
defaultOrderTimeoutMin = 30
defaultMaxPendingOrders = 3
)
// PaymentConfig holds the payment system configuration.
@@ -464,8 +462,9 @@ func (s *PaymentConfigService) UpdateProviderInstance(ctx context.Context, id in
return u.Save(ctx)
}
// mergeConfig merges new config with existing config, preserving sensitive
// fields that were not re-submitted (frontend skips masked ••••••••).
// mergeConfig merges new config with existing config. All keys from newConfig
// overwrite existing values (including empty strings to clear a field).
// Keys not present in newConfig are preserved from existing config.
func (s *PaymentConfigService) mergeConfig(ctx context.Context, id int64, newConfig map[string]string) (map[string]string, error) {
inst, err := s.entClient.PaymentProviderInstance.Get(ctx, id)
if err != nil {