fix: pass context.Context to alipay TradePreCreate call

The smartwalle/alipay/v3 Client.TradePreCreate method signature requires
a context.Context as its first argument. Add a Ctx field to
UserRechargeLinkReq, populate it from the HTTP request context in Bind,
and forward it to the TradePreCreate call to fix the build failure.
pull/725/head
copilot-swe-agent[bot] 2 months ago committed by GitHub
parent bee989fe64
commit 7bfc2a1dbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -27,8 +27,9 @@ type UserWalletBillsResp base.PageResp
type UserRechargeLinkReq struct {
BaseInfo `json:"-" form:"-" binding:"-"`
Host string `json:"-" form:"-" binding:"-"`
Amount int64 `json:"amount" form:"amount" binding:"required"`
Ctx context.Context `json:"-" form:"-" binding:"-"`
Host string `json:"-" form:"-" binding:"-"`
Amount int64 `json:"amount" form:"amount" binding:"required"`
}
type UserRechargeLinkResp struct {
@ -82,6 +83,7 @@ func (r *UserWalletBillsReq) Bind(c *gin.Context) error {
func (r *UserRechargeLinkReq) Bind(c *gin.Context) error {
r.Host = c.Request.Host
r.Ctx = c.Request.Context()
return bindAny(c, r)
}

@ -80,7 +80,7 @@ func (s *alipayPrivSrv) UserRechargeLink(req *web.UserRechargeLinkReq) (*web.Use
p.Subject = "PaoPao用户钱包充值"
p.TotalAmount = fmt.Sprintf("%.2f", float64(recharge.Amount)/100.0)
p.NotifyURL = "https://" + req.Host + "/v1/alipay/notify"
rsp, err := s.alipayClient.TradePreCreate(p)
rsp, err := s.alipayClient.TradePreCreate(req.Ctx, p)
if err != nil {
logrus.Errorf("client.TradePreCreate err: %v\n", err)
return nil, web.ErrRechargeReqFail

Loading…
Cancel
Save