diff --git a/controller/topup.go b/controller/topup.go index 8705b4eb7f18..204582b89c30 100644 --- a/controller/topup.go +++ b/controller/topup.go @@ -118,16 +118,15 @@ func GetTopUpInfo(c *gin.Context) { } data := gin.H{ - "enable_online_topup": isEpayTopUpEnabled(), - "enable_stripe_topup": isStripeTopUpEnabled(), - "enable_creem_topup": isCreemTopUpEnabled(), - "enable_oen_topup": enableOen, - "enable_waffo_topup": enableWaffo, - "enable_waffo_pancake_topup": enableWaffoPancake, - "enable_manual_bank_transfer_topup": isManualBankTransferTopUpEnabled(), - "enable_redemption": complianceConfirmed, - "payment_compliance_confirmed": complianceConfirmed, - "payment_compliance_terms_version": operation_setting.CurrentComplianceTermsVersion, + "enable_online_topup": isEpayTopUpEnabled(), + "enable_stripe_topup": isStripeTopUpEnabled(), + "enable_creem_topup": isCreemTopUpEnabled(), + "enable_oen_topup": enableOen, + "enable_waffo_topup": enableWaffo, + "enable_waffo_pancake_topup": enableWaffoPancake, + "enable_redemption": complianceConfirmed, + "payment_compliance_confirmed": complianceConfirmed, + "payment_compliance_terms_version": operation_setting.CurrentComplianceTermsVersion, "waffo_pay_methods": func() interface{} { if enableWaffo { return setting.GetWaffoPayMethods() diff --git a/controller/topup_manual_bank_transfer.go b/controller/topup_manual_bank_transfer.go index ea7d13868e3c..03853257b2d7 100644 --- a/controller/topup_manual_bank_transfer.go +++ b/controller/topup_manual_bank_transfer.go @@ -17,9 +17,7 @@ import ( "github.com/shopspring/decimal" ) -type ManualBankTransferPayRequest struct { - Amount int64 `json:"amount"` -} +const manualBankTransferPaymentType = "manual_bank_transfer" func isManualBankTransferTopUpEnabled() bool { config := operation_setting.GetManualBankTransferConfig() @@ -35,20 +33,22 @@ func appendManualBankTransferPayMethod(payMethods []map[string]string) []map[str return payMethods } for _, method := range payMethods { - if method["type"] == model.PaymentMethodManualBankTransfer { + if method["type"] == manualBankTransferPaymentType { return payMethods } } return append(payMethods, map[string]string{ "name": "Manual Bank Transfer", - "type": model.PaymentMethodManualBankTransfer, + "type": manualBankTransferPaymentType, "icon": "LuLandmark", "color": "#0F766E", "min_topup": strconv.FormatInt(getMinTopup(), 10), }) } -func RequestManualBankTransferPay(c *gin.Context) { +// CreateManualBankTransferTopUp adapts manual transfers to the existing TopUp +// lifecycle. AdminCompleteTopUp remains the only path that credits the order. +func CreateManualBankTransferTopUp(c *gin.Context) { if !requirePaymentCompliance(c) { return } @@ -57,7 +57,7 @@ func RequestManualBankTransferPay(c *gin.Context) { return } - var request ManualBankTransferPayRequest + var request AmountRequest if err := c.ShouldBindJSON(&request); err != nil { common.ApiErrorMsg(c, "参数错误") return @@ -99,8 +99,8 @@ func RequestManualBankTransferPay(c *gin.Context) { Amount: normalizedAmount, Money: payMoney, TradeNo: tradeNo, - PaymentMethod: model.PaymentMethodManualBankTransfer, - PaymentProvider: model.PaymentProviderManualBankTransfer, + PaymentMethod: manualBankTransferPaymentType, + PaymentProvider: manualBankTransferPaymentType, CreateTime: time.Now().Unix(), Status: common.TopUpStatusPending, } diff --git a/controller/topup_manual_bank_transfer_test.go b/controller/topup_manual_bank_transfer_test.go index cbf703e6c243..27c3aef91183 100644 --- a/controller/topup_manual_bank_transfer_test.go +++ b/controller/topup_manual_bank_transfer_test.go @@ -17,7 +17,7 @@ import ( "gorm.io/gorm" ) -func TestRequestManualBankTransferPayWaitsForAdminCompletionBeforeCreditingQuota(t *testing.T) { +func TestCreateManualBankTransferTopUpWaitsForAdminCompletionBeforeCreditingQuota(t *testing.T) { oldDB := model.DB oldLogDB := model.LOG_DB oldMainDatabaseType := common.MainDatabaseType() @@ -88,12 +88,12 @@ func TestRequestManualBankTransferPayWaitsForAdminCompletionBeforeCreditingQuota ctx.Set("id", user.Id) ctx.Request = httptest.NewRequest( http.MethodPost, - "/api/user/manual-bank-transfer/pay", + "/api/user/topup/manual-bank-transfer", strings.NewReader(`{"amount":10}`), ) ctx.Request.Header.Set("Content-Type", "application/json") - RequestManualBankTransferPay(ctx) + CreateManualBankTransferTopUp(ctx) assert.Equal(t, http.StatusOK, recorder.Code) var response struct { @@ -119,7 +119,7 @@ func TestRequestManualBankTransferPayWaitsForAdminCompletionBeforeCreditingQuota assert.Equal(t, user.Id, topUp.UserId) assert.Equal(t, int64(10), topUp.Amount) assert.Equal(t, float64(350), topUp.Money) - assert.Equal(t, model.PaymentProviderManualBankTransfer, topUp.PaymentProvider) + assert.Equal(t, manualBankTransferPaymentType, topUp.PaymentProvider) assert.Equal(t, common.TopUpStatusPending, topUp.Status) var reloaded model.User diff --git a/model/topup_manual_bank_transfer.go b/model/topup_manual_bank_transfer.go deleted file mode 100644 index 8be6d799b0d1..000000000000 --- a/model/topup_manual_bank_transfer.go +++ /dev/null @@ -1,6 +0,0 @@ -package model - -const ( - PaymentMethodManualBankTransfer = "manual_bank_transfer" - PaymentProviderManualBankTransfer = "manual_bank_transfer" -) diff --git a/router/api-router.go b/router/api-router.go index 377367acdde5..b29679d0b658 100644 --- a/router/api-router.go +++ b/router/api-router.go @@ -109,7 +109,7 @@ func SetApiRouter(router *gin.Engine) { selfRoute.POST("/creem/pay", middleware.CriticalRateLimit(), controller.RequestCreemPay) selfRoute.POST("/oen/amount", controller.RequestOenAmount) selfRoute.POST("/oen/pay", middleware.CriticalRateLimit(), controller.RequestOenPay) - selfRoute.POST("/manual-bank-transfer/pay", middleware.CriticalRateLimit(), controller.RequestManualBankTransferPay) + selfRoute.POST("/topup/manual-bank-transfer", middleware.CriticalRateLimit(), controller.CreateManualBankTransferTopUp) selfRoute.POST("/waffo/amount", controller.RequestWaffoAmount) selfRoute.POST("/waffo/pay", middleware.CriticalRateLimit(), controller.RequestWaffoPay) selfRoute.POST("/waffo-pancake/amount", controller.RequestWaffoPancakeAmount) diff --git a/web/src/features/wallet/api.ts b/web/src/features/wallet/api.ts index e0d763be6dab..03a119bcf47a 100644 --- a/web/src/features/wallet/api.ts +++ b/web/src/features/wallet/api.ts @@ -156,7 +156,7 @@ export async function requestOenPayment( export async function requestManualBankTransferPayment( request: AmountRequest ): Promise { - const res = await api.post('/api/user/manual-bank-transfer/pay', request, { + const res = await api.post('/api/user/topup/manual-bank-transfer', request, { skipBusinessError: true, } as Record) return res.data diff --git a/web/src/features/wallet/components/recharge-form-card.tsx b/web/src/features/wallet/components/recharge-form-card.tsx index d6a170d59c5a..02e8c01fda73 100644 --- a/web/src/features/wallet/components/recharge-form-card.tsx +++ b/web/src/features/wallet/components/recharge-form-card.tsx @@ -143,11 +143,14 @@ export function RechargeFormCard({ } } + const hasManualBankTransfer = topupInfo?.pay_methods?.some( + (method) => method.type === PAYMENT_TYPES.MANUAL_BANK_TRANSFER + ) const hasConfigurableTopup = topupInfo?.enable_online_topup || topupInfo?.enable_stripe_topup || topupInfo?.enable_oen_topup || - topupInfo?.enable_manual_bank_transfer_topup || + hasManualBankTransfer || enableWaffoTopup || enableWaffoPancakeTopup const hasAnyTopup = hasConfigurableTopup || enableCreemTopup diff --git a/web/src/features/wallet/lib/payment.ts b/web/src/features/wallet/lib/payment.ts index 64e5e29a3ae0..a241ba4176f7 100644 --- a/web/src/features/wallet/lib/payment.ts +++ b/web/src/features/wallet/lib/payment.ts @@ -153,10 +153,6 @@ export function getDefaultPaymentType(topupInfo: TopupInfo | null): string { return PAYMENT_TYPES.OEN } - if (topupInfo.enable_manual_bank_transfer_topup) { - return PAYMENT_TYPES.MANUAL_BANK_TRANSFER - } - if (topupInfo.enable_waffo_topup) { return PAYMENT_TYPES.WAFFO } @@ -188,10 +184,6 @@ export function getMinTopupAmount(topupInfo: TopupInfo | null): number { return topupInfo.oen_min_topup || DEFAULT_MIN_TOPUP } - if (topupInfo.enable_manual_bank_transfer_topup) { - return topupInfo.min_topup || DEFAULT_MIN_TOPUP - } - if (topupInfo.enable_waffo_topup) { return topupInfo.waffo_min_topup || DEFAULT_MIN_TOPUP } diff --git a/web/src/features/wallet/types.ts b/web/src/features/wallet/types.ts index 7e95b22606b9..71c5724f9c13 100644 --- a/web/src/features/wallet/types.ts +++ b/web/src/features/wallet/types.ts @@ -143,8 +143,6 @@ export interface TopupInfo { enable_stripe_topup: boolean /** Whether OEN Payment topup is enabled */ enable_oen_topup?: boolean - /** Whether manual bank transfer topup is enabled */ - enable_manual_bank_transfer_topup?: boolean /** Available payment methods */ pay_methods: PaymentMethod[] /** Minimum topup amount for online topup */