This commit is contained in:
lwl0608 2024-05-29 10:56:52 +08:00
parent fe3cb342d6
commit cc93c10aa2
3 changed files with 72 additions and 2 deletions

View File

@ -320,7 +320,7 @@ func (v *Vas) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data
return return
} }
yeepayAlipayH5ParamStr = aggPayResp.PrePayTn yeepayAlipayH5ParamStr = aggPayResp.PrePayTn
req.Oid3 = yeepayCli.AppId req.Oid3 = yeepayCli.MerchantNo
case vasproto.PayTypeYeepayWxpayH5: case vasproto.PayTypeYeepayWxpayH5:
var aggPayResp *yeepaycli.AggPayResp var aggPayResp *yeepaycli.AggPayResp
yeepayCli := yeepaycli.GetDefaultYeepayClient() yeepayCli := yeepaycli.GetDefaultYeepayClient()
@ -342,7 +342,7 @@ func (v *Vas) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data
return return
} }
yeepayWxpayH5ParamStr = aggPayResp.PrePayTn yeepayWxpayH5ParamStr = aggPayResp.PrePayTn
req.Oid3 = yeepayCli.AppId req.Oid3 = yeepayCli.MerchantNo
} }
// 添加订单 // 添加订单
@ -3519,6 +3519,22 @@ func (v *Vas) payRefund(ctx *gin.Context, order *dbstruct.Order) error {
logger.Error("wxpayCli.RefundOne fail, orderId: %v, resp: %v, err: %v", orderId, util.ToJson(resp), err) logger.Error("wxpayCli.RefundOne fail, orderId: %v, resp: %v, err: %v", orderId, util.ToJson(resp), err)
return err return err
} }
case vasproto.PayTypeYeepayAlipayH5, vasproto.PayTypeYeepayWxpayH5:
yeepayCli := yeepaycli.GetDefaultYeepayClient()
resp, err := yeepayCli.RefundOne(ctx, &yeepaycli.RefundOneParam{
OutTradeNo: orderId,
RefundAmount: order.GetPayAmount(),
RefundReason: "用户退款",
})
if err != nil {
logger.Error("wxpayCli.RefundOne fail, orderId: %v, resp: %v, err: %v", orderId, util.ToJson(resp), err)
return err
}
if resp.Status != "SUCCESS" {
err = fmt.Errorf("退款失败,请稍后再试")
logger.Error("wxpayCli.RefundOne fail, orderId: %v, resp: %v, err: %v", orderId, util.ToJson(resp), err)
return err
}
} }
return nil return nil
} }

View File

@ -53,6 +53,7 @@ const (
NodeZoneSession // node 空间对话表 NodeZoneSession // node 空间对话表
NodeZoneThirdPartner // node 空间代运营表 NodeZoneThirdPartner // node 空间代运营表
NodeDailyStatementZoneInfo // node 空间相关每日报表 NodeDailyStatementZoneInfo // node 空间相关每日报表
NodeYeepayRefund // node 易宝支付退款
) )
func GenIdInt64(node int64) (int64, error) { func GenIdInt64(node int64) (int64, error) {
@ -252,3 +253,9 @@ func GenDailyStatementZoneInfoId() int64 {
id, _ := GenIdInt64(NodeDailyStatementZoneInfo) id, _ := GenIdInt64(NodeDailyStatementZoneInfo)
return id return id
} }
// yeepay refund
func GenYeepayRefundId() string {
id, _ := GenIdString(NodeYeepayRefund)
return id
}

View File

@ -3,6 +3,7 @@ package yeepaycli
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"github.com/yop-platform/yop-go-sdk/yop/client" "github.com/yop-platform/yop-go-sdk/yop/client"
"github.com/yop-platform/yop-go-sdk/yop/constants" "github.com/yop-platform/yop-go-sdk/yop/constants"
"github.com/yop-platform/yop-go-sdk/yop/request" "github.com/yop-platform/yop-go-sdk/yop/request"
@ -10,6 +11,7 @@ import (
"net/http" "net/http"
"service/bizcommon/util" "service/bizcommon/util"
"service/library/configcenter" "service/library/configcenter"
"service/library/idgenerator"
"service/library/logger" "service/library/logger"
"time" "time"
) )
@ -149,3 +151,48 @@ func (c *YeepayClient) AggPay(ctx context.Context, param *AggPayParam) (resp *Ag
logger.Info("yeepay AggPay param: %v, resp: %v", util.ToJson(req.Params), util.ToJson(resp)) logger.Info("yeepay AggPay param: %v, resp: %v", util.ToJson(req.Params), util.ToJson(resp))
return return
} }
// 退款
type RefundOneParam struct {
OutTradeNo string // 商家订单id我们自己的订单id
RefundAmount int64 // 退款金额,单位:分
RefundReason string // 退款理由
}
type RefundOneResp struct {
Code string `json:"code"`
Message string `json:"message"`
ParentMerchantNo string `json:"parentMerchantNo"`
MerchantNo string `json:"merchantNo"`
OrderId string `json:"orderId"`
RefundRequestId string `json:"refundRequestId"`
UniqueRefundNo string `json:"uniqueRefundNo"`
Status string `json:"status"`
RefundAmount string `json:"refundAmount"`
RefundRequestDate string `json:"refundRequestDate"`
RefundMerchantFee string `json:"refundMerchantFee"`
RefundAccountDetail string `json:"refundAccountDetail"`
RefundCsFinishDate string `json:"refundCsFinishDate"`
}
func (c *YeepayClient) RefundOne(ctx context.Context, param *RefundOneParam) (resp *RefundOneResp, err error) {
req := request.NewYopRequest(constants.POST_HTTP_METHOD, "/rest/v1.0/trade/refund")
req.AppId = c.AppId
req.IsvPriKey = request.IsvPriKey{Value: c.PrivateKey, CertType: request.RSA2048}
req.AddParam("parentMerchantNo", c.ParentMerchantNo)
req.AddParam("merchantNo", c.MerchantNo)
req.AddParam("orderId", param.OutTradeNo)
req.AddParam("refundRequestId", idgenerator.GenYeepayRefundId())
req.AddParam("refundAmount", fmt.Sprintf("%.2f", float64(param.RefundAmount)/100.0))
respMeta, err := c.client.Request(req)
if err != nil {
logger.Error("yeepay RefundOne fail, param: %v, respMeta: %v, err: %v", util.ToJson(req.Params), util.ToJson(respMeta), err)
return
}
resp = new(RefundOneResp)
b, _ := json.Marshal(respMeta.Result)
_ = json.Unmarshal(b, resp)
logger.Info("yeepay RefundOne param: %v, resp: %v", util.ToJson(req.Params), util.ToJson(resp))
return
}