UpdatePayConfig updates the payment configuration @Summary Update payment configuration @Description Update the configuration of an existing payment setting @Tags PaySetting @Accept json @Produce json @Security BearerAuth @Param id path int true "Payment setting ID" @Param setting body PayConfigRequ
(c *gin.Context)
| 309 | // @Success 200 {object} model.CommonResponse{data=model.PaySetting} |
| 310 | // @Router /api/pay_settings/{id}/config [patch] |
| 311 | func UpdatePayConfig(c *gin.Context) { |
| 312 | id, err := strconv.ParseInt(c.Param("id"), 10, 64) |
| 313 | if err != nil { |
| 314 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse("Invalid ID")) |
| 315 | return |
| 316 | } |
| 317 | |
| 318 | paySetting, err := model.GetPaySettingByID(config.GetEID(c), id) |
| 319 | if err != nil { |
| 320 | c.JSON(http.StatusNotFound, model.NotFound.ToResponse(nil)) |
| 321 | return |
| 322 | } |
| 323 | |
| 324 | var req PayConfigRequest |
| 325 | if err = c.ShouldBindJSON(&req); err != nil { |
| 326 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err)) |
| 327 | return |
| 328 | } |
| 329 | |
| 330 | // Validate configuration based on payment type |
| 331 | if paySetting.PayType == model.PayTypeWechat { |
| 332 | paySetting.PayConfig, err = processWechatConfig(req.PayConfig) |
| 333 | if err != nil { |
| 334 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err.Error())) |
| 335 | return |
| 336 | } |
| 337 | } else { |
| 338 | paySetting.PayConfig = req.PayConfig |
| 339 | } |
| 340 | paySetting.ExtraConfig = req.ExtraConfig |
| 341 | |
| 342 | if err = paySetting.Update(); err != nil { |
| 343 | c.JSON(http.StatusInternalServerError, model.DBError.ToResponse(err)) |
| 344 | return |
| 345 | } |
| 346 | |
| 347 | payText, err := model.GetPayTypeText(paySetting.PayType) |
| 348 | if err != nil { |
| 349 | c.JSON(http.StatusInternalServerError, model.DBError.ToResponse(err)) |
| 350 | return |
| 351 | } |
| 352 | |
| 353 | log := model.SystemLog{ |
| 354 | Eid: config.GetEID(c), |
| 355 | UserID: config.GetUserId(c), |
| 356 | Nickname: config.GetUserNickname(c), |
| 357 | Module: model.SystemLogModulePayment, |
| 358 | Action: model.SystemLogActionUpdate, |
| 359 | Content: fmt.Sprintf("设置%s", payText), |
| 360 | IP: utils.GetClientIP(c), |
| 361 | } |
| 362 | model.CreateSystemLog(&log) |
| 363 | |
| 364 | c.JSON(http.StatusOK, model.Success.ToResponse(paySetting)) |
| 365 | } |
| 366 | |
| 367 | // UpdatePayStatus updates the payment status |
| 368 | // @Summary Update payment status |
nothing calls this directly
no test coverage detected