feat:前台,增加支付完成后的跳转
This commit is contained in:
parent
fe0fe5123f
commit
6ac8bd8710
|
@ -18,6 +18,7 @@ type PayCommonReqBody struct {
|
||||||
Amount int `json:"amount" validate:"required" label:"支付金额,单位分"`
|
Amount int `json:"amount" validate:"required" label:"支付金额,单位分"`
|
||||||
ExtJson string `json:"ext_json" label:"扩展参数"`
|
ExtJson string `json:"ext_json" label:"扩展参数"`
|
||||||
Desc string `json:"desc" validate:"max=100" label:"商品描述"`
|
Desc string `json:"desc" validate:"max=100" label:"商品描述"`
|
||||||
|
ReturnUrl string `json:"return_url" validate:"required,max=1024" label:"支付成功后跳转的地址"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PayReqs struct {
|
type PayReqs struct {
|
||||||
|
|
|
@ -23,6 +23,7 @@ type PayParam struct {
|
||||||
ExtJson string
|
ExtJson string
|
||||||
Desc string
|
Desc string
|
||||||
ClientIp string
|
ClientIp string
|
||||||
|
ReturnUrl string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Pay struct {
|
type Pay struct {
|
||||||
|
@ -47,6 +48,7 @@ func NewPayWithPayCheck(paycheck *PayCheck) *Pay {
|
||||||
ExtJson: paycheck.Reqs.ExtJson,
|
ExtJson: paycheck.Reqs.ExtJson,
|
||||||
Desc: paycheck.Reqs.Desc,
|
Desc: paycheck.Reqs.Desc,
|
||||||
ClientIp: paycheck.AppCheck.Ip,
|
ClientIp: paycheck.AppCheck.Ip,
|
||||||
|
ReturnUrl: paycheck.Reqs.ReturnUrl,
|
||||||
},
|
},
|
||||||
RelationOrder: paycheck.OldOrder,
|
RelationOrder: paycheck.OldOrder,
|
||||||
PayCode: errorcode.Success,
|
PayCode: errorcode.Success,
|
||||||
|
@ -102,6 +104,7 @@ func (w *Pay) PayUrl() (url string) {
|
||||||
Description: w.Order.Desc,
|
Description: w.Order.Desc,
|
||||||
Amount: w.Order.Amount,
|
Amount: w.Order.Amount,
|
||||||
PayerClientIp: w.PayParam.ClientIp,
|
PayerClientIp: w.PayParam.ClientIp,
|
||||||
|
ReturnUrl: w.PayParam.ReturnUrl,
|
||||||
}
|
}
|
||||||
if payFunc, ok = PayWayList[w.PayParam.Channel.ChannelType]; !ok {
|
if payFunc, ok = PayWayList[w.PayParam.Channel.ChannelType]; !ok {
|
||||||
w.PayCode = errorcode.PayChannelNotBuild
|
w.PayCode = errorcode.PayChannelNotBuild
|
||||||
|
|
|
@ -67,6 +67,9 @@ func ALiH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, e
|
||||||
Set("total_amount", amount).
|
Set("total_amount", amount).
|
||||||
Set("subject", payOrderRequest.Description).
|
Set("subject", payOrderRequest.Description).
|
||||||
Set("notify_url", fmt.Sprintf(envConfig.PayService.Host+payCommon.ALI_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId))
|
Set("notify_url", fmt.Sprintf(envConfig.PayService.Host+payCommon.ALI_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId))
|
||||||
|
if payOrderRequest.ReturnUrl != "" {
|
||||||
|
bm.Set("return_url", payOrderRequest.ReturnUrl)
|
||||||
|
}
|
||||||
|
|
||||||
aliRsp, err := aliClient.TradeWapPay(c, bm)
|
aliRsp, err := aliClient.TradeWapPay(c, bm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -19,6 +19,7 @@ type PayOrderRequest struct {
|
||||||
Description string `json:"description"` // 商品描述
|
Description string `json:"description"` // 商品描述
|
||||||
Amount int `json:"amount"` // 金额单位为分
|
Amount int `json:"amount"` // 金额单位为分
|
||||||
PayerClientIp string `json:"payer_client_ip"` // 终端IP
|
PayerClientIp string `json:"payer_client_ip"` // 终端IP
|
||||||
|
ReturnUrl string `json:"return_url"` // 支付成功后回调地址
|
||||||
Wx WxPay `json:"wx"`
|
Wx WxPay `json:"wx"`
|
||||||
Ali AliPay `json:"ali"`
|
Ali AliPay `json:"ali"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/go-pay/gopay"
|
"github.com/go-pay/gopay"
|
||||||
"github.com/go-pay/gopay/wechat/v3"
|
"github.com/go-pay/gopay/wechat/v3"
|
||||||
"github.com/qit-team/snow-core/log/logger"
|
"github.com/qit-team/snow-core/log/logger"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -85,6 +86,12 @@ func WxH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, er
|
||||||
logger.Error(c, "WxH5PayInfo 发生错误", fmt.Sprintf("错误状态码:%d, 错误信息:%s", wxRsp.Code, wxRsp.Error))
|
logger.Error(c, "WxH5PayInfo 发生错误", fmt.Sprintf("错误状态码:%d, 错误信息:%s", wxRsp.Code, wxRsp.Error))
|
||||||
return "", errors.New(fmt.Sprintf("发起支付失败,失败状态码:%d, 失败原因:%s", wxRsp.Code, wxRsp.Error))
|
return "", errors.New(fmt.Sprintf("发起支付失败,失败状态码:%d, 失败原因:%s", wxRsp.Code, wxRsp.Error))
|
||||||
}
|
}
|
||||||
|
if payOrderRequest.ReturnUrl != "" {
|
||||||
|
values := url.Values{}
|
||||||
|
values.Set("redirect_url", payOrderRequest.ReturnUrl)
|
||||||
|
encodedStr := values.Encode()
|
||||||
|
wxRsp.Response.H5Url = wxRsp.Response.H5Url + "&" + encodedStr
|
||||||
|
}
|
||||||
return wxRsp.Response.H5Url, nil
|
return wxRsp.Response.H5Url, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,8 +236,8 @@ func WxOrderRefund(ctx context.Context, orderRefundRequest OrderRefundRequest) (
|
||||||
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||||
// 退款金额:单位是分
|
// 退款金额:单位是分
|
||||||
bm.Set("refund", orderRefundRequest.RefundAmount). //实际退款金额
|
bm.Set("refund", orderRefundRequest.RefundAmount). //实际退款金额
|
||||||
Set("total", orderRefundRequest.RefundAmount). // 折扣前总金额(不是实际退款数)
|
Set("total", orderRefundRequest.RefundAmount). // 折扣前总金额(不是实际退款数)
|
||||||
Set("currency", "CNY")
|
Set("currency", "CNY")
|
||||||
})
|
})
|
||||||
// body:参数Body
|
// body:参数Body
|
||||||
refund, err := wxClient.V3Refund(ctx, bm)
|
refund, err := wxClient.V3Refund(ctx, bm)
|
||||||
|
|
Loading…
Reference in New Issue