diff --git a/initialize/currency.go b/initialize/currency.go index 25dc52f..29c5642 100644 --- a/initialize/currency.go +++ b/initialize/currency.go @@ -24,7 +24,7 @@ func Currency(ctx *svc.ServiceContext) { AccessKey string }{} tool.SystemConfigSliceReflectToStruct(currency, &configs) - + ctx.ExchangeRate = 0 // Default exchange rate to 0 ctx.Config.Currency = config.Currency{ Unit: configs.CurrencyUnit, Symbol: configs.CurrencySymbol, diff --git a/internal/logic/admin/system/updateCurrencyConfigLogic.go b/internal/logic/admin/system/updateCurrencyConfigLogic.go index 0104331..f49f490 100644 --- a/internal/logic/admin/system/updateCurrencyConfigLogic.go +++ b/internal/logic/admin/system/updateCurrencyConfigLogic.go @@ -4,6 +4,7 @@ import ( "context" "reflect" + "github.com/perfect-panel/server/initialize" "github.com/perfect-panel/server/internal/config" "github.com/perfect-panel/server/internal/model/system" "github.com/perfect-panel/server/pkg/tool" @@ -54,6 +55,7 @@ func (l *UpdateCurrencyConfigLogic) UpdateCurrencyConfig(req *types.CurrencyConf // clear cache return l.svcCtx.Redis.Del(l.ctx, config.CurrencyConfigKey, config.GlobalConfigKey).Err() }) + initialize.Currency(l.svcCtx) if err != nil { l.Errorw("[UpdateCurrencyConfig] update currency config error", logger.Field("error", err.Error())) return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update invite config error: %v", err) diff --git a/internal/logic/public/portal/purchaseCheckoutLogic.go b/internal/logic/public/portal/purchaseCheckoutLogic.go index 105e1dc..568fb05 100644 --- a/internal/logic/public/portal/purchaseCheckoutLogic.go +++ b/internal/logic/public/portal/purchaseCheckoutLogic.go @@ -51,6 +51,7 @@ func NewPurchaseCheckoutLogic(ctx context.Context, svcCtx *svc.ServiceContext) * // PurchaseCheckout processes the checkout for an order using the specified payment method // It validates the order, retrieves payment configuration, and routes to the appropriate payment handler func (l *PurchaseCheckoutLogic) PurchaseCheckout(req *types.CheckoutOrderRequest) (resp *types.CheckoutOrderResponse, err error) { + // Validate and retrieve order information orderInfo, err := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo) if err != nil { @@ -76,6 +77,7 @@ func (l *PurchaseCheckoutLogic) PurchaseCheckout(req *types.CheckoutOrderRequest // Process EPay payment - generates payment URL for redirect url, err := l.epayPayment(paymentConfig, orderInfo, req.ReturnUrl) if err != nil { + l.Logger.Error("[PurchaseCheckout] epay error", logger.Field("error", err.Error())) return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "epayPayment error: %v", err.Error()) } resp = &types.CheckoutOrderResponse{ @@ -274,6 +276,7 @@ func (l *PurchaseCheckoutLogic) epayPayment(config *payment.Payment, info *order // Convert order amount to CNY using current exchange rate amount, err = l.queryExchangeRate("CNY", info.Amount) if err != nil { + l.Logger.Error("[PurchaseCheckout] queryExchangeRate error", logger.Field("error", err.Error())) return "", err } } else { @@ -381,6 +384,11 @@ func (l *PurchaseCheckoutLogic) queryExchangeRate(to string, src int64) (amount // Convert cents to decimal amount amount = float64(src) / float64(100) + // No conversion needed if target currency matches system currency + if to == l.svcCtx.Config.Currency.Unit { + return amount, nil + } + if l.svcCtx.ExchangeRate != 0 && to == "CNY" { amount = amount * l.svcCtx.ExchangeRate return amount, nil @@ -394,6 +402,7 @@ func (l *PurchaseCheckoutLogic) queryExchangeRate(to string, src int64) (amount // Convert currency if system currency differs from target currency result, err := exchangeRate.GetExchangeRete(l.svcCtx.Config.Currency.Unit, to, l.svcCtx.Config.Currency.AccessKey, 1) if err != nil { + l.Logger.Error("[PurchaseCheckout] QueryExchangeRate error", logger.Field("error", err.Error())) return 0, err } l.svcCtx.ExchangeRate = result