96 lines
2.2 KiB
Go
96 lines
2.2 KiB
Go
package thirdpay
|
|
|
|
import (
|
|
"PaymentCenter/app/constants/common"
|
|
"PaymentCenter/app/constants/errorcode"
|
|
"PaymentCenter/app/http/entities/front"
|
|
"PaymentCenter/app/models/ordersmodel"
|
|
"PaymentCenter/app/services"
|
|
"PaymentCenter/app/services/thirdpay/api"
|
|
thirdpay "PaymentCenter/app/services/thirdpay/do"
|
|
"PaymentCenter/app/services/thirdpay/notify"
|
|
"context"
|
|
)
|
|
|
|
func ThirdPayUrl(check *thirdpay.PayCheck) *thirdpay.Pay {
|
|
pay := ThirdPay(check)
|
|
// 支付
|
|
pay.PayUrl()
|
|
return pay
|
|
}
|
|
|
|
func NewOrdersResp(db *ordersmodel.Orders) *api.OrdersResp {
|
|
return &api.OrdersResp{
|
|
OrderNo: db.Id,
|
|
OutTreadNo: db.OutTreadNo,
|
|
Status: db.Status,
|
|
OrderType: db.OrderType,
|
|
Amount: db.Amount,
|
|
Desc: db.Desc,
|
|
CreateTime: db.CreateTime.Format("2006-01-02 15:04:05"),
|
|
}
|
|
}
|
|
|
|
func NewOrderNotifyWithHandle(orderId int64, Status int, actualAmount int, msg string) *notify.OrderNotifyResp {
|
|
orderNotify := ¬ify.OrderNotify{
|
|
OrderId: orderId,
|
|
Status: Status,
|
|
ActualAmount: actualAmount,
|
|
Msg: msg,
|
|
Code: errorcode.Success,
|
|
}
|
|
return orderNotify.Handle()
|
|
}
|
|
|
|
func ThirdPayRefund(check *thirdpay.PayCheck) *thirdpay.Pay {
|
|
pay := thirdpay.NewPay(check)
|
|
// 创建订单
|
|
if &check.OldOrder != nil {
|
|
pay.CreateOrder(common.ORDER_TYPE_PAY)
|
|
if pay.PayCode != errorcode.Success {
|
|
return pay
|
|
}
|
|
} else {
|
|
pay.Order = check.OldOrder
|
|
}
|
|
// 支付
|
|
pay.PayUrl()
|
|
return pay
|
|
}
|
|
|
|
func ThirdPayInfoCheck(ctx context.Context, req *front.PayReqs, appCheck *services.AppCheck, ip string) (check *thirdpay.PayCheck) {
|
|
check = thirdpay.NewPayCheck(&ctx, req, appCheck, ip)
|
|
// 校验表单
|
|
check.CheckForm()
|
|
if check.CheckCode != errorcode.Success {
|
|
return
|
|
}
|
|
|
|
// 校验商户
|
|
check.CheckMerchant()
|
|
if check.CheckCode != errorcode.Success {
|
|
return
|
|
}
|
|
// 校验支付通道
|
|
check.CheckPayChannel()
|
|
if check.CheckCode != errorcode.Success {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func ThirdPay(check *thirdpay.PayCheck) (pay *thirdpay.Pay) {
|
|
pay = thirdpay.NewPay(check)
|
|
// 创建订单
|
|
if &check.OldOrder != nil {
|
|
pay.CreateOrder(common.ORDER_TYPE_PAY)
|
|
if pay.PayCode != errorcode.Success {
|
|
return pay
|
|
}
|
|
} else {
|
|
pay.Order = check.OldOrder
|
|
}
|
|
return
|
|
}
|