fix:支付

This commit is contained in:
momo
2023-09-21 19:01:48 +08:00
parent f10e556a0a
commit be786a4d4c
13 changed files with 480 additions and 58 deletions

View File

@@ -11,4 +11,12 @@ type Config struct {
SourceMysql string
Auth types.Auth
SourceRabbitMq string
PayConfig struct {
Stripe struct {
EndpointSecret string
Key string
CancelURL string
SuccessURL string
}
}
}

View File

@@ -33,6 +33,10 @@ func NewCreatePrePaymentByBalanceLogic(ctx context.Context, svcCtx *svc.ServiceC
func (l *CreatePrePaymentByBalanceLogic) CreatePrePaymentByBalance(req *types.CreatePrePaymentByBalanceReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
if !userinfo.IsUser() {
// 如果是,返回未授权的错误码
return resp.SetStatus(basic.CodeUnAuth)
}
return resp.SetStatus(basic.CodeOK)
}

View File

@@ -1,6 +1,8 @@
package logic
import (
"fusenapi/constants"
"fusenapi/service/repositories"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
@@ -33,8 +35,43 @@ func NewCreatePrePaymentByDepositLogic(ctx context.Context, svcCtx *svc.ServiceC
func (l *CreatePrePaymentByDepositLogic) CreatePrePaymentByDeposit(req *types.CreatePrePaymentByDepositReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
if !userinfo.IsUser() {
// 如果是,返回未授权的错误码
return resp.SetStatus(basic.CodeUnAuth)
}
if req.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL {
if req.DeliveryAddress == nil {
return resp.SetStatus(basic.CodeErrOrderCreatePrePaymentParam)
} else {
if req.DeliveryAddress.Address == "" || req.DeliveryAddress.Mobile == "" || req.DeliveryAddress.Name == "" {
return resp.SetStatus(basic.CodeErrOrderCreatePrePaymentParam)
}
}
}
var orderAddress repositories.OrderAddress
if req.DeliveryAddress != nil {
orderAddress.Address = req.DeliveryAddress.Address
orderAddress.Mobile = req.DeliveryAddress.Mobile
orderAddress.Name = req.DeliveryAddress.Name
}
res, err := l.svcCtx.Repositories.NewOrder.CreatePrePaymentByDeposit(l.ctx, &repositories.CreatePrePaymentByDepositReq{
UserId: userinfo.UserId,
OrderSn: req.OrderSn,
DeliveryMethod: req.DeliveryMethod,
DeliveryAddress: &orderAddress,
Country: "US",
Currency: "usd",
StripeKey: l.svcCtx.Config.PayConfig.Stripe.Key,
})
return resp.SetStatus(basic.CodeOK)
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 必须重新处理

View File

@@ -43,7 +43,7 @@ func (l *OrderDetailLogic) OrderDetail(req *types.OrderDetailReq, userinfo *auth
UserId: userinfo.UserId,
})
if err != nil {
return resp.SetStatus(basic.CodeApiErr)
return resp.SetStatus(&res.ErrorCode)
}
return resp.SetStatus(basic.CodeOK, map[string]interface{}{

View File

@@ -1,6 +1,7 @@
package logic
import (
"fusenapi/service/repositories"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
@@ -33,8 +34,25 @@ func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderLi
func (l *OrderListLogic) OrderList(req *types.OrderListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
if !userinfo.IsUser() {
// 如果是,返回未授权的错误码
return resp.SetStatus(basic.CodeUnAuth)
}
res, err := l.svcCtx.Repositories.NewOrder.List(l.ctx, &repositories.ListReq{
UserId: userinfo.UserId,
DeliveryMethod: req.DeliveryMethod,
OrderCycle: req.OrderCycle,
CurrentPage: req.CurrentPage,
PerPage: req.PerPage,
})
if err != nil {
return resp.SetStatus(basic.CodeApiErr)
}
return resp.SetStatus(basic.CodeOK)
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
"list": res.OrderDetailList,
"meta": res.Meta,
})
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理

View File

@@ -15,12 +15,12 @@ type CreateOrderReq struct {
}
type CreatePrePaymentByDepositReq struct {
OrderSn string `json:"order_sn"`
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
DeliveryAddres DeliveryAddres `json:"delivery_addres,optional"`
OrderSn string `json:"order_sn"`
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
DeliveryAddress *DeliveryAddress `json:"delivery_address,optional"`
}
type DeliveryAddres struct {
type DeliveryAddress struct {
Address string `json:"address,optional"`
Name string `json:"name,optional"`
Mobile string `json:"mobile,optional"`
@@ -32,9 +32,9 @@ type CreatePrePaymentByBalanceReq struct {
type OrderListReq struct {
DeliveryMethod int64 `json:"delivery_method,options=[0,1,2],optional"`
OrderCycle string `json:"order_cycle,optional"`
Current_page int64 `json:"current_page,optional,default=1"`
Page_size int64 `json:"page_size,optional,default=10"`
OrderCycle string `json:"order_cycle,optional,options=[within_one_month,within_three_month,within_six_month,within_one_year]"`
CurrentPage int64 `json:"current_page,optional,default=1"`
PerPage int64 `json:"per_page,optional,default=10"`
}
type Request struct {