fix:支付
This commit is contained in:
parent
1040f21ca6
commit
0f7514b5bd
|
@ -3,7 +3,7 @@ package constants
|
||||||
// 订单类型
|
// 订单类型
|
||||||
const (
|
const (
|
||||||
DELIVERYMETHODDIRECTMAIL int64 = 1
|
DELIVERYMETHODDIRECTMAIL int64 = 1
|
||||||
DELIVERYMETHODDSCLOUDSTORE int64 = 1
|
DELIVERYMETHODDSCLOUDSTORE int64 = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
// 货币
|
// 货币
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth
|
||||||
OriginalCurrency: string(constants.CURRENCYUSD),
|
OriginalCurrency: string(constants.CURRENCYUSD),
|
||||||
UserId: userinfo.UserId,
|
UserId: userinfo.UserId,
|
||||||
CartIds: req.CartIds,
|
CartIds: req.CartIds,
|
||||||
DeliveryMethod: req.DeliveryMethod,
|
DeliveryMethod: constants.DELIVERYMETHODDSCLOUDSTORE,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fusenapi/service/repositories"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
@ -38,7 +39,22 @@ func (l *CreatePrePaymentByBalanceLogic) CreatePrePaymentByBalance(req *types.Cr
|
||||||
return resp.SetStatus(basic.CodeUnAuth)
|
return resp.SetStatus(basic.CodeUnAuth)
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
res, err := l.svcCtx.Repositories.NewOrder.CreatePrePaymentByBalance(l.ctx, &repositories.CreatePrePaymentByBalanceReq{
|
||||||
|
UserId: userinfo.UserId,
|
||||||
|
OrderSn: req.OrderSn,
|
||||||
|
Country: "US",
|
||||||
|
Currency: "usd",
|
||||||
|
StripeKey: l.svcCtx.Config.PayConfig.Stripe.Key,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp.SetStatus(&res.ErrorCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||||
|
"order_detail": res.OrderDetail,
|
||||||
|
"order_pay": res.OrderPay,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
|
|
@ -10,8 +10,7 @@ type OrderDetailReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateOrderReq struct {
|
type CreateOrderReq struct {
|
||||||
CartIds []int64 `json:"cart_ids"`
|
CartIds []int64 `json:"cart_ids"`
|
||||||
DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreatePrePaymentByDepositReq struct {
|
type CreatePrePaymentByDepositReq struct {
|
||||||
|
|
|
@ -33,8 +33,8 @@ type OrderDetailReq {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateOrderReq {
|
type CreateOrderReq {
|
||||||
CartIds []int64 `json:"cart_ids"`
|
CartIds []int64 `json:"cart_ids"`
|
||||||
DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
|
// DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreatePrePaymentByDepositReq {
|
type CreatePrePaymentByDepositReq {
|
||||||
|
|
|
@ -82,13 +82,11 @@ type (
|
||||||
|
|
||||||
/* 预支付--尾款 */
|
/* 预支付--尾款 */
|
||||||
CreatePrePaymentByBalanceReq struct {
|
CreatePrePaymentByBalanceReq struct {
|
||||||
StripeKey string `json:"stripe_key"`
|
StripeKey string `json:"stripe_key"`
|
||||||
Currency string `json:"currency"`
|
Currency string `json:"currency"`
|
||||||
Country string `json:"country"`
|
Country string `json:"country"`
|
||||||
UserId int64 `json:"user_id"`
|
UserId int64 `json:"user_id"`
|
||||||
OrderSn string `json:"order_sn"`
|
OrderSn string `json:"order_sn"`
|
||||||
DeliveryMethod int64 `json:"delivery_method"`
|
|
||||||
DeliveryAddress *OrderAddress `json:"delivery_address"`
|
|
||||||
}
|
}
|
||||||
CreatePrePaymentByBalanceRes struct {
|
CreatePrePaymentByBalanceRes struct {
|
||||||
ErrorCode basic.StatusResponse
|
ErrorCode basic.StatusResponse
|
||||||
|
@ -143,7 +141,83 @@ type (
|
||||||
|
|
||||||
// 预支付--尾款
|
// 预支付--尾款
|
||||||
func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *CreatePrePaymentByBalanceReq) (res *CreatePrePaymentByBalanceRes, err error) {
|
func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *CreatePrePaymentByBalanceReq) (res *CreatePrePaymentByBalanceRes, err error) {
|
||||||
return nil, nil
|
var errorCode basic.StatusResponse
|
||||||
|
var order gmodel.FsOrder
|
||||||
|
model := d.MysqlConn.Where("is_del = ?", 0)
|
||||||
|
if in.UserId != 0 {
|
||||||
|
model.Where("user_id = ?", in.UserId)
|
||||||
|
}
|
||||||
|
if in.OrderSn != "" {
|
||||||
|
model.Where("order_sn = ?", in.OrderSn)
|
||||||
|
}
|
||||||
|
result := model.Take(&order)
|
||||||
|
if result.Error != nil {
|
||||||
|
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
|
errorCode = *basic.CodeErrOrderCreatePrePaymentInfoNoFound
|
||||||
|
} else {
|
||||||
|
errorCode = *basic.CodeServiceErr
|
||||||
|
}
|
||||||
|
logx.Errorf("create prePayment balance failed, err: %v", err)
|
||||||
|
return &CreatePrePaymentByBalanceRes{
|
||||||
|
ErrorCode: errorCode,
|
||||||
|
}, result.Error
|
||||||
|
}
|
||||||
|
// 非未支付
|
||||||
|
if *order.PayStatus != int64(constants.ORDERPAYSTATUSPAIDDEPOSIT) {
|
||||||
|
errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid
|
||||||
|
err = errors.New("order balance pay status is not unPaid")
|
||||||
|
logx.Errorf("create prePayment balance failed, err: %v", err)
|
||||||
|
return &CreatePrePaymentByBalanceRes{
|
||||||
|
ErrorCode: errorCode,
|
||||||
|
}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ress, err := d.OrderDetailHandler(ctx, &order)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("create prePayment balance failed DetailOrderDetailHandler, err: %v", err)
|
||||||
|
errorCode = *basic.CodeServiceErr
|
||||||
|
return &CreatePrePaymentByBalanceRes{
|
||||||
|
ErrorCode: errorCode,
|
||||||
|
}, err
|
||||||
|
}
|
||||||
|
// 支付初始化
|
||||||
|
amount := int64(ress.OrderDetailOriginal.OrderAmount.RemainingBalance.PayAmount.Current.CurrentAmount.(float64) / float64(10))
|
||||||
|
payConfig := &pay.Config{}
|
||||||
|
payConfig.Stripe.PayType = "intent"
|
||||||
|
payConfig.Stripe.Key = in.StripeKey
|
||||||
|
var generatePrepaymentReq = &pay.GeneratePrepaymentReq{
|
||||||
|
OrderSn: in.OrderSn,
|
||||||
|
ProductName: "支付尾款后期统一调整",
|
||||||
|
Amount: amount,
|
||||||
|
Currency: "usd",
|
||||||
|
Quantity: 1,
|
||||||
|
ProductDescription: "支付尾款后期统一调整",
|
||||||
|
}
|
||||||
|
payDriver := pay.NewPayDriver(1, payConfig)
|
||||||
|
|
||||||
|
prepaymentRes, err := payDriver.GeneratePrepayment(generatePrepaymentReq)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("create prePayment balance failed GeneratePrepayment, err: %v", err)
|
||||||
|
errorCode = *basic.CodeServiceErr
|
||||||
|
return &CreatePrePaymentByBalanceRes{
|
||||||
|
ErrorCode: errorCode,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
return &CreatePrePaymentByBalanceRes{
|
||||||
|
OrderDetail: ress.OrderDetail,
|
||||||
|
OrderPay: OrderPay{
|
||||||
|
ClientSecret: prepaymentRes.ClientSecret,
|
||||||
|
Country: in.Country,
|
||||||
|
Currency: in.Currency,
|
||||||
|
Method: payConfig.Stripe.PayType,
|
||||||
|
OrderSn: in.OrderSn,
|
||||||
|
PayStage: 1,
|
||||||
|
Total: OrderPayTotal{
|
||||||
|
Amount: amount,
|
||||||
|
Label: "支付尾款后期统一调整",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 预支付--定金
|
// 预支付--定金
|
||||||
|
@ -172,7 +246,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
|
||||||
|
|
||||||
// 非未支付
|
// 非未支付
|
||||||
if *order.PayStatus != int64(constants.ORDERPAYSTATUSUNPAIDDEPOSIT) {
|
if *order.PayStatus != int64(constants.ORDERPAYSTATUSUNPAIDDEPOSIT) {
|
||||||
errorCode = *basic.CodeErrOrderCreatePrePaymentInfoNoFound
|
errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid
|
||||||
err = errors.New("order pay status is not unPaidDeposit")
|
err = errors.New("order pay status is not unPaidDeposit")
|
||||||
logx.Errorf("create prePayment deposit failed, err: %v", err)
|
logx.Errorf("create prePayment deposit failed, err: %v", err)
|
||||||
return &CreatePrePaymentByDepositRes{
|
return &CreatePrePaymentByDepositRes{
|
||||||
|
@ -185,6 +259,8 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
|
||||||
ctime := *order.Ctime
|
ctime := *order.Ctime
|
||||||
ctimeTimeOut := ctime.Add(30 * time.Minute).UTC().Unix()
|
ctimeTimeOut := ctime.Add(30 * time.Minute).UTC().Unix()
|
||||||
ntimeTimeOut := ntime.Unix()
|
ntimeTimeOut := ntime.Unix()
|
||||||
|
|
||||||
|
// 测试超时支付不限制
|
||||||
if ctimeTimeOut == ntimeTimeOut {
|
if ctimeTimeOut == ntimeTimeOut {
|
||||||
errorCode = *basic.CodeErrOrderCreatePrePaymentTimeout
|
errorCode = *basic.CodeErrOrderCreatePrePaymentTimeout
|
||||||
err = errors.New("order pay timeout")
|
err = errors.New("order pay timeout")
|
||||||
|
@ -270,11 +346,11 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
|
||||||
payConfig.Stripe.Key = in.StripeKey
|
payConfig.Stripe.Key = in.StripeKey
|
||||||
var generatePrepaymentReq = &pay.GeneratePrepaymentReq{
|
var generatePrepaymentReq = &pay.GeneratePrepaymentReq{
|
||||||
OrderSn: in.OrderSn,
|
OrderSn: in.OrderSn,
|
||||||
ProductName: "支付标题",
|
ProductName: "支付首款",
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
Currency: "usd",
|
Currency: "usd",
|
||||||
Quantity: 1,
|
Quantity: 1,
|
||||||
ProductDescription: "支付描述",
|
ProductDescription: "支付首款",
|
||||||
}
|
}
|
||||||
payDriver := pay.NewPayDriver(1, payConfig)
|
payDriver := pay.NewPayDriver(1, payConfig)
|
||||||
|
|
||||||
|
|
|
@ -108,8 +108,9 @@ var (
|
||||||
CodeErrOrderCreatProductAccessoryAbsent = &StatusResponse{5305, "create order failed, accessory of product is absent"} // 订单创建失败,商品配件不存在
|
CodeErrOrderCreatProductAccessoryAbsent = &StatusResponse{5305, "create order failed, accessory of product is absent"} // 订单创建失败,商品配件不存在
|
||||||
CodeErrOrderCreatePrePaymentParam = &StatusResponse{5306, "create payment failed, the shipping address is illegal"} // 订单创建失败,商品配件不存在
|
CodeErrOrderCreatePrePaymentParam = &StatusResponse{5306, "create payment failed, the shipping address is illegal"} // 订单创建失败,商品配件不存在
|
||||||
CodeErrOrderCreatePrePaymentInfoNoFound = &StatusResponse{5307, "create payment failed, order info not found"}
|
CodeErrOrderCreatePrePaymentInfoNoFound = &StatusResponse{5307, "create payment failed, order info not found"}
|
||||||
CodeErrOrderCreatePrePaymentPaidDeposit = &StatusResponse{5308, "create payment failed, order is paid"}
|
CodeErrOrderCreatePrePaymentNoUnPaid = &StatusResponse{5308, "create payment failed, order is not unpaid"}
|
||||||
CodeErrOrderCreatePrePaymentTimeout = &StatusResponse{5309, "create payment failed, timeout"}
|
CodeErrOrderCreatePrePaymentPaid = &StatusResponse{5309, "create payment failed, order is paid"}
|
||||||
|
CodeErrOrderCreatePrePaymentTimeout = &StatusResponse{5310, "create payment failed, timeout"}
|
||||||
)
|
)
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user