Skip to content

Commit

Permalink
add bizErrCheckTradePay() for client.TradePay()
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Oct 18, 2023
1 parent 68d99d5 commit d85f535
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions alipay/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ type BizErr struct {

// bizErrCheck 检查业务码是否为10000 否则返回一个BizErr
func bizErrCheck(errRsp ErrorResponse) error {
if errRsp.Code != "10000" {
return &BizErr{
Code: errRsp.Code,
Msg: errRsp.Msg,
SubCode: errRsp.SubCode,
SubMsg: errRsp.SubMsg,
}
}
return nil
}

// bizErrCheckTradePay 检查业务码是否为10000、10003,否则返回一个BizErr
func bizErrCheckTradePay(errRsp ErrorResponse) error {
if errRsp.Code != "10000" && errRsp.Code != "10003" {
return &BizErr{
Code: errRsp.Code,
Expand Down
2 changes: 1 addition & 1 deletion alipay/payment_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (a *Client) TradePay(ctx context.Context, bm gopay.BodyMap) (aliRsp *TradeP
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
if err = bizErrCheckTradePay(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
signData, signDataErr := a.getSignData(bs, aliRsp.AlipayCertSn)
Expand Down

0 comments on commit d85f535

Please sign in to comment.