|
@@ -5,17 +5,50 @@ import (
|
|
|
"eta/eta_mini_ht_api/common/exception"
|
|
|
"eta/eta_mini_ht_api/controllers"
|
|
|
orderService "eta/eta_mini_ht_api/domian/order"
|
|
|
+ paymentService "eta/eta_mini_ht_api/service/payment"
|
|
|
"eta/eta_mini_ht_api/service/product"
|
|
|
)
|
|
|
|
|
|
+const (
|
|
|
+ PaymentChannelWechat = "wechat"
|
|
|
+ PaymentChannelAlipay = "alipay"
|
|
|
+ PaymentStatusClosed = "closed"
|
|
|
+ PaymentStatusSuccess = "success"
|
|
|
+ PaymentStatusFailed = "failed"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ statusMap = map[string]bool{
|
|
|
+ PaymentStatusClosed: false,
|
|
|
+ PaymentStatusSuccess: true,
|
|
|
+ PaymentStatusFailed: false,
|
|
|
+ }
|
|
|
+ channelMap = map[string]int{
|
|
|
+ PaymentChannelWechat: 1,
|
|
|
+ PaymentChannelAlipay: 1,
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
type HTFuturesTradeController struct {
|
|
|
controllers.WebHookController
|
|
|
}
|
|
|
|
|
|
-type ss struct {
|
|
|
- Success bool `json:"success"`
|
|
|
- User int `json:"user"`
|
|
|
- TradeOrderNo string `json:"tradeOrderNo"`
|
|
|
+type PaymentOrderReq struct {
|
|
|
+ Status string `json:"status"`
|
|
|
+ OrderNo string `json:"order_no"`
|
|
|
+ PaymentChannel string `json:"payment_channel"`
|
|
|
+}
|
|
|
+type RefundOrderReq struct {
|
|
|
+ Status string `json:"status"`
|
|
|
+ OrderNo string `json:"order_no"`
|
|
|
+}
|
|
|
+type WechatSDKParamsReq struct {
|
|
|
+ OrderNo string `json:"order_no"`
|
|
|
+ PrepayId string `json:"prepay_id"`
|
|
|
+ Timestamp string `json:"timestamp"`
|
|
|
+ NonceStr string `json:"nonce_str"`
|
|
|
+ PaySign string `json:"pay_sign"`
|
|
|
+ SignType string `json:"sign_type"`
|
|
|
}
|
|
|
|
|
|
// InformPaymentResult 支付通知接口
|
|
@@ -25,45 +58,34 @@ type ss struct {
|
|
|
// @router /v1/payment/informPaymentResult [post]
|
|
|
func (h *HTFuturesTradeController) InformPaymentResult() {
|
|
|
controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
|
|
|
- result = h.InitWrapData("同步风险等级")
|
|
|
- s := new(ss)
|
|
|
- h.GetPostParams(s)
|
|
|
- logger.Info("支付结果通知: %v", s)
|
|
|
- if s.Success {
|
|
|
- productOrder, _ := orderService.DealPayment(s.TradeOrderNo, orderService.PaySuccess)
|
|
|
- //privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
|
|
|
- _ = product.OpenProduct(productOrder)
|
|
|
+ result = h.InitWrapData("支付结果处理失败")
|
|
|
+ req := new(PaymentOrderReq)
|
|
|
+ h.GetPostParams(req)
|
|
|
+ logger.Info("支付结果通知: %v", req)
|
|
|
+ if _, ok := channelMap[req.PaymentChannel]; !ok {
|
|
|
+ logger.Warn("支付结果通知: %v", req)
|
|
|
+ err = exception.NewWithException(exception.PaymentChannelError, "未知的支付渠道")
|
|
|
+ h.FailedResult("支付结果通知: %v", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if success, ok := statusMap[req.Status]; !ok {
|
|
|
+ logger.Warn("支付结果通知: %v", req)
|
|
|
+ err = exception.NewWithException(exception.PaymentStatusError, "未知的支付状态结果")
|
|
|
+ h.FailedResult("支付结果通知: %v", result)
|
|
|
+ return
|
|
|
} else {
|
|
|
- _, _ = orderService.DealPayment(s.TradeOrderNo, orderService.PayFail)
|
|
|
+ if success {
|
|
|
+ productOrder, _ := orderService.DealPayment(req.OrderNo, req.PaymentChannel, req.Status, orderService.PaySuccess)
|
|
|
+ //privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
|
|
|
+ _ = product.OpenProduct(productOrder)
|
|
|
+ } else {
|
|
|
+ _, _ = orderService.DealPayment(req.OrderNo, req.PaymentChannel, req.Status, orderService.PayFail)
|
|
|
+ }
|
|
|
+ result = h.InitWrapData("支付结果应答成功")
|
|
|
+ h.SuccessResult("success", nil, result)
|
|
|
+ return
|
|
|
}
|
|
|
- //htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
|
|
|
- //webhookRequest := new(WebhookRequest)
|
|
|
- //h.GetPostParams(webhookRequest)
|
|
|
- //privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
|
|
|
- //if err != nil {
|
|
|
- // err = exception.NewWithException(exception.SysError, err.Error())
|
|
|
- // logger.Error("解析私钥失败: %v", err)
|
|
|
- // h.FailedResult("解析私钥失败", result)
|
|
|
- // return
|
|
|
- //}
|
|
|
- //decodeData, err := authUtils.DecryptWithRSA(privateKey, webhookRequest.Data)
|
|
|
- //if err != nil {
|
|
|
- // err = exception.NewWithException(exception.SysError, err.Error())
|
|
|
- // logger.Error("解密请求体失败: %v", err)
|
|
|
- // h.FailedResult("解密请求体失败", result)
|
|
|
- // return
|
|
|
- //}
|
|
|
- //syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
|
|
|
- //err = json.Unmarshal(decodeData, syncCustomerRiskLevelReq)
|
|
|
- //if err != nil {
|
|
|
- // err = exception.NewWithException(exception.SyncRiskError, err.Error())
|
|
|
- // logger.Error("解析请求体失败: %v", err)
|
|
|
- // h.FailedResult("解析请求体失败", result)
|
|
|
- // return
|
|
|
- //}
|
|
|
- result = h.InitWrapData("支付结果应答成功")
|
|
|
- h.SuccessResult("success", nil, result)
|
|
|
- return
|
|
|
+
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -74,57 +96,94 @@ func (h *HTFuturesTradeController) InformPaymentResult() {
|
|
|
// @router /v1/payment/informRefundResult [post]
|
|
|
func (h *HTFuturesTradeController) InformRefundResult() {
|
|
|
controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
|
|
|
- result = h.InitWrapData("同步风险等级")
|
|
|
- s := new(ss)
|
|
|
- h.GetPostParams(s)
|
|
|
- if s.Success {
|
|
|
- productOrder, RefundErr := orderService.DealRefund(s.TradeOrderNo, orderService.RefundSuccess)
|
|
|
- if RefundErr != nil {
|
|
|
- logger.Error("退款订单处理失败: %v", err)
|
|
|
- err = exception.NewWithException(exception.RefundDealFail, err.Error())
|
|
|
- h.FailedResult("退款订单处理失败", result)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- //处理退款订单
|
|
|
- _ = product.CloseProduct(productOrder)
|
|
|
+ result = h.InitWrapData("退款订单处理失败")
|
|
|
+ refundReq := new(RefundOrderReq)
|
|
|
+ h.GetPostParams(refundReq)
|
|
|
+ logger.Warn("退款结果通知: %v", refundReq)
|
|
|
+ if success, ok := statusMap[refundReq.Status]; !ok {
|
|
|
+ err = exception.NewWithException(exception.PaymentStatusError, "未知的支付状态结果")
|
|
|
+ h.FailedResult("支付结果通知: %v", result)
|
|
|
+ return
|
|
|
} else {
|
|
|
- _, RefundErr := orderService.DealRefund(s.TradeOrderNo, orderService.RefundFail)
|
|
|
- if RefundErr != nil {
|
|
|
- logger.Error("退款订单处理失败: %v", err)
|
|
|
- err = exception.NewWithException(exception.RefundDealFail, RefundErr.Error())
|
|
|
- h.FailedResult("退款订单处理失败", result)
|
|
|
- return
|
|
|
+ if success {
|
|
|
+ productOrder, RefundErr := orderService.DealRefund(refundReq.OrderNo, refundReq.Status, orderService.RefundSuccess)
|
|
|
+ if RefundErr != nil {
|
|
|
+ logger.Error("退款订单处理失败: %v", err)
|
|
|
+ err = exception.NewWithException(exception.RefundDealFail, err.Error())
|
|
|
+ h.FailedResult("退款订单处理失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //处理退款订单
|
|
|
+ _ = product.CloseProduct(productOrder)
|
|
|
+ } else {
|
|
|
+ _, RefundErr := orderService.DealRefund(refundReq.OrderNo, refundReq.Status, orderService.RefundFail)
|
|
|
+ if RefundErr != nil {
|
|
|
+ logger.Error("退款订单处理失败: %v", err)
|
|
|
+ err = exception.NewWithException(exception.RefundDealFail, RefundErr.Error())
|
|
|
+ h.FailedResult("退款订单处理失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
+ //创建meta_info
|
|
|
+ //htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
|
|
|
+ //webhookRequest := new(WebhookRequest)
|
|
|
+ //h.GetPostParams(webhookRequest)
|
|
|
+ //privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
|
|
|
+ //if err != nil {
|
|
|
+ // err = exception.NewWithException(exception.SysError, err.Error())
|
|
|
+ // logger.Error("解析私钥失败: %v", err)
|
|
|
+ // h.FailedResult("解析私钥失败", result)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //decodeData, err := authUtils.DecryptWithRSA(privateKey, webhookRequest.Data)
|
|
|
+ //if err != nil {
|
|
|
+ // err = exception.NewWithException(exception.SysError, err.Error())
|
|
|
+ // logger.Error("解密请求体失败: %v", err)
|
|
|
+ // h.FailedResult("解密请求体失败", result)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
|
|
|
+ //err = json.Unmarshal(decodeData, syncCustomerRiskLevelReq)
|
|
|
+ //if err != nil {
|
|
|
+ // err = exception.NewWithException(exception.SyncRiskError, err.Error())
|
|
|
+ // logger.Error("解析请求体失败: %v", err)
|
|
|
+ // h.FailedResult("解析请求体失败", result)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ result = h.InitWrapData("退款结果应答成功")
|
|
|
+ h.SuccessResult("success", nil, result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// InformWechatPaymentResult 支付通知接口
|
|
|
+// @Summary 支付通知接口
|
|
|
+// @Description 支付通知接口
|
|
|
+// @Success 200 {object} controllers.BaseResponse
|
|
|
+// @router /v1/payment/sendWechatSDKParams [post]
|
|
|
+func (h *HTFuturesTradeController) InformWechatPaymentResult() {
|
|
|
+ controllers.WrapWebhook(&h.WebHookController, func() (result *controllers.WrapData, err error) {
|
|
|
+ result = h.InitWrapData("微信支付SDK参数处理失败")
|
|
|
+ sdkParams := new(WechatSDKParamsReq)
|
|
|
+ h.GetPostParams(sdkParams)
|
|
|
+ logger.Info("微信支付SDK参数通知: %v", sdkParams)
|
|
|
+ err = paymentService.DealWechatSDKParams(paymentService.WechatSDKParams{
|
|
|
+ NonceStr: sdkParams.NonceStr,
|
|
|
+ OrderNo: sdkParams.OrderNo,
|
|
|
+ PaySign: sdkParams.PaySign,
|
|
|
+ PrepayId: sdkParams.PrepayId,
|
|
|
+ SignType: sdkParams.SignType,
|
|
|
+ Timestamp: sdkParams.Timestamp,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ logger.Error("微信支付SDK参数处理失败: %v", err)
|
|
|
+ err = exception.NewWithException(exception.GetWechatSDKParamsFailed, err.Error())
|
|
|
+ h.FailedResult("微信支付SDK参数处理失败", result)
|
|
|
+ return
|
|
|
}
|
|
|
- //创建meta_info
|
|
|
- //htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
|
|
|
- //webhookRequest := new(WebhookRequest)
|
|
|
- //h.GetPostParams(webhookRequest)
|
|
|
- //privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
|
|
|
- //if err != nil {
|
|
|
- // err = exception.NewWithException(exception.SysError, err.Error())
|
|
|
- // logger.Error("解析私钥失败: %v", err)
|
|
|
- // h.FailedResult("解析私钥失败", result)
|
|
|
- // return
|
|
|
- //}
|
|
|
- //decodeData, err := authUtils.DecryptWithRSA(privateKey, webhookRequest.Data)
|
|
|
- //if err != nil {
|
|
|
- // err = exception.NewWithException(exception.SysError, err.Error())
|
|
|
- // logger.Error("解密请求体失败: %v", err)
|
|
|
- // h.FailedResult("解密请求体失败", result)
|
|
|
- // return
|
|
|
- //}
|
|
|
- //syncCustomerRiskLevelReq := new(SyncCustomerRiskLevelReq)
|
|
|
- //err = json.Unmarshal(decodeData, syncCustomerRiskLevelReq)
|
|
|
- //if err != nil {
|
|
|
- // err = exception.NewWithException(exception.SyncRiskError, err.Error())
|
|
|
- // logger.Error("解析请求体失败: %v", err)
|
|
|
- // h.FailedResult("解析请求体失败", result)
|
|
|
- // return
|
|
|
- //}
|
|
|
- result = h.InitWrapData("退款结果应答成功")
|
|
|
- h.SuccessResult("success", nil, result)
|
|
|
+ result = h.InitWrapData("微信支付SDK参数处理成功")
|
|
|
+ h.SuccessResult("success", sdkParams, result)
|
|
|
return
|
|
|
})
|
|
|
}
|