fix:支付

This commit is contained in:
momo 2023-09-22 10:39:02 +08:00
parent c4b4b72947
commit fead7c6ae9
4 changed files with 46 additions and 22 deletions

View File

@ -11,12 +11,12 @@ type OrderDetailReq struct {
type CreateOrderReq struct {
CartIds []int64 `json:"cart_ids"`
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
}
type CreatePrePaymentByDepositReq struct {
OrderSn string `json:"order_sn"`
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
DeliveryAddress *DeliveryAddress `json:"delivery_address,optional"`
}

View File

@ -34,12 +34,12 @@ type OrderDetailReq {
type CreateOrderReq {
CartIds []int64 `json:"cart_ids"`
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
}
type CreatePrePaymentByDepositReq {
OrderSn string `json:"order_sn"`
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
DeliveryAddress *DeliveryAddress `json:"delivery_address,optional"`
}

View File

@ -34,6 +34,8 @@ type (
Create(ctx context.Context, in *CreateReq) (res *CreateRes, err error)
// 预支付--定金
CreatePrePaymentByDeposit(ctx context.Context, in *CreatePrePaymentByDepositReq) (res *CreatePrePaymentByDepositRes, err error)
// 预支付--定金
CreatePrePaymentByBalance(ctx context.Context, in *CreatePrePaymentByBalanceReq) (res *CreatePrePaymentByBalanceRes, err error)
// 列表
List(ctx context.Context, in *ListReq) (res *ListRes, err error)
// 详情
@ -69,7 +71,7 @@ type (
UserId int64 `json:"user_id"`
OrderSn string `json:"order_sn"`
DeliveryMethod int64 `json:"delivery_method"`
DeliveryAddress *OrderAddress `json:"delivery_address"` // 收货地址
DeliveryAddress *OrderAddress `json:"delivery_address"`
}
CreatePrePaymentByDepositRes struct {
ErrorCode basic.StatusResponse
@ -78,6 +80,23 @@ type (
}
/* 预支付--定金 */
/* 预支付--尾款 */
CreatePrePaymentByBalanceReq struct {
StripeKey string `json:"stripe_key"`
Currency string `json:"currency"`
Country string `json:"country"`
UserId int64 `json:"user_id"`
OrderSn string `json:"order_sn"`
DeliveryMethod int64 `json:"delivery_method"`
DeliveryAddress *OrderAddress `json:"delivery_address"`
}
CreatePrePaymentByBalanceRes struct {
ErrorCode basic.StatusResponse
OrderDetail gmodel.OrderDetail
OrderPay OrderPay
}
/* 预支付--尾款 */
/* 下单 */
CreateReq struct {
ExpectedDeliveryTime time.Time `json:"expected_delivery_time"` // 预计到货时间
@ -122,6 +141,11 @@ type (
/* 列表 */
)
// 预支付--尾款
func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *CreatePrePaymentByBalanceReq) (res *CreatePrePaymentByBalanceRes, err error) {
return nil, nil
}
// 预支付--定金
func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *CreatePrePaymentByDepositReq) (res *CreatePrePaymentByDepositRes, err error) {
var errorCode basic.StatusResponse
@ -223,6 +247,22 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
}
}
}
if len(uOrderDetail) > 0 {
err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, in.OrderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", order.Id)
if err != nil {
errorCode = *basic.CodeServiceErr
logx.Errorf("create prePayment deposit failed MetadataOrderPATCH, err: %v", err)
return &CreatePrePaymentByDepositRes{
ErrorCode: errorCode,
}, result.Error
}
}
ress.OrderDetail.OrderInfo.Utime = &ntime
ress.OrderDetail.OrderInfo.DeliveryMethod = in.DeliveryMethod
ress.OrderDetail.DeliveryAddress = orderAddress
// 支付初始化
amount := int64(ress.OrderDetailOriginal.OrderAmount.Deposit.PayAmount.Current.CurrentAmount.(float64) / float64(10))
payConfig := &pay.Config{}
@ -245,24 +285,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
return &CreatePrePaymentByDepositRes{
ErrorCode: errorCode,
}, nil
} else {
//uOrderDetail["order_amount"] = map[type]type
}
if len(uOrderDetail) > 0 {
err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, in.OrderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", order.Id)
if err != nil {
errorCode = *basic.CodeServiceErr
logx.Errorf("create prePayment deposit failed MetadataOrderPATCH, err: %v", err)
return &CreatePrePaymentByDepositRes{
ErrorCode: errorCode,
}, result.Error
}
}
ress.OrderDetail.OrderInfo.Utime = &ntime
ress.OrderDetail.OrderInfo.DeliveryMethod = in.DeliveryMethod
ress.OrderDetail.DeliveryAddress = orderAddress
return &CreatePrePaymentByDepositRes{
OrderDetail: ress.OrderDetail,
OrderPay: OrderPay{

View File

@ -79,6 +79,7 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge
case "intent":
// 密钥方式
params := &stripe.PaymentIntentParams{
Params: stripe.Params{Metadata: map[string]string{"order_sn": req.OrderSn}},
Amount: stripe.Int64(req.Amount),
Currency: stripe.String(string(req.Currency)),
PaymentMethodTypes: stripe.StringSlice([]string{