PaymentCenter/app/services/thirdpay/pay.go

81 lines
2.0 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/types"
"context"
"github.com/jinzhu/copier"
)
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,
OutTradeNo: db.OutTradeNo,
Status: db.Status,
OrderType: db.OrderType,
Amount: db.Amount,
PayerTotal: db.PayerTotal,
Desc: db.Desc,
CreateTime: db.CreateTime.Format("2006-01-02 15:04:05"),
}
}
func ThirdPayInfoCheck(ctx context.Context, payReq *front.PayReqs, appCheck *services.AppCheck, ip string) (check *thirdpay.PayCheck) {
var req types.Reqs
copier.Copy(&req, payReq)
check = thirdpay.NewPayCheck(&ctx, &req, appCheck, ip)
// 校验表单
check.CheckPayInfo()
if check.CheckCode != errorcode.Success {
return
}
return
}
func ThirdPayRefund(ctx context.Context, refundReq *front.RefundReqs, appCheck *services.AppCheck, ip string) (refund *thirdpay.Pay) {
var req types.Reqs
copier.Copy(&req, refundReq)
check := thirdpay.NewPayCheck(&ctx, &req, appCheck, ip)
// 校验表单
check.CheckPayInfo()
if check.CheckCode != errorcode.Success {
return
}
check.CheckOrderRefund()
if check.CheckCode != errorcode.Success {
return
}
refund = thirdpay.NewPayWithPayCheck(check)
refund.CreateOrder(common.ORDER_TYPE_REFUND)
refund.Refund()
return
}
func ThirdPay(check *thirdpay.PayCheck) (pay *thirdpay.Pay) {
pay = thirdpay.NewPayWithPayCheck(check)
// 创建订单
if check.OldOrder != nil {
pay.Order = check.OldOrder
} else {
pay.CreateOrder(common.ORDER_TYPE_PAY)
if pay.PayCode != errorcode.Success {
return pay
}
}
return
}