UpdatePaySetting updates an existing payment setting @Summary Update payment setting @Description Update an existing payment setting @Tags PaySetting @Accept json @Produce json @Security BearerAuth @Param id path int true "Payment setting ID" @Param setting body PaySettingRequest true "Payment setti
(c *gin.Context)
| 125 | // @Success 200 {object} model.CommonResponse{data=model.PaySetting} |
| 126 | // @Router /api/pay_settings/{id} [put] |
| 127 | func UpdatePaySetting(c *gin.Context) { |
| 128 | id, err := strconv.ParseInt(c.Param("id"), 10, 64) |
| 129 | if err != nil { |
| 130 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse("Invalid ID")) |
| 131 | return |
| 132 | } |
| 133 | |
| 134 | eid := config.GetEID(c) |
| 135 | |
| 136 | // Get existing payment setting |
| 137 | paySetting, err := model.GetPaySettingByID(eid, id) |
| 138 | if err != nil { |
| 139 | c.JSON(http.StatusNotFound, model.NotFound.ToResponse("Payment setting not found")) |
| 140 | return |
| 141 | } |
| 142 | |
| 143 | var req PaySettingRequest |
| 144 | if err = c.ShouldBindJSON(&req); err != nil { |
| 145 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err)) |
| 146 | return |
| 147 | } |
| 148 | |
| 149 | // Validate payment type |
| 150 | if !isValidPayType(req.PayType) { |
| 151 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse("Invalid payment type")) |
| 152 | return |
| 153 | } |
| 154 | |
| 155 | // Process configuration based on payment type |
| 156 | if req.PayType == model.PayTypeWechat { |
| 157 | req.PayConfig, err = processWechatConfig(req.PayConfig) |
| 158 | if err != nil { |
| 159 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err.Error())) |
| 160 | return |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | // Update payment setting |
| 165 | paySetting.PayType = req.PayType |
| 166 | paySetting.PayConfig = req.PayConfig |
| 167 | paySetting.PayStatus = req.PayStatus |
| 168 | paySetting.ExtraConfig = req.ExtraConfig |
| 169 | |
| 170 | if err := paySetting.Update(); err != nil { |
| 171 | c.JSON(http.StatusInternalServerError, model.DBError.ToResponse(err)) |
| 172 | return |
| 173 | } |
| 174 | |
| 175 | c.JSON(http.StatusOK, model.Success.ToResponse(paySetting)) |
| 176 | } |
| 177 | |
| 178 | // DeletePaySetting deletes a payment setting |
| 179 | // @Summary Delete payment setting |
nothing calls this directly
no test coverage detected