Order订单待测试

This commit is contained in:
eson
2023-06-20 19:36:28 +08:00
parent d4d11db732
commit e50dac6b1c
18 changed files with 116 additions and 43 deletions

View File

@@ -5,9 +5,10 @@ import (
"fmt"
"fusenapi/initalize"
"fusenapi/server/canteen/internal/config"
"net/http"
"github.com/golang-jwt/jwt"
"gorm.io/gorm"
"net/http"
)
type ServiceContext struct {
@@ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
}
}
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
AuthKey := r.Header.Get("Authorization")
if len(AuthKey) <= 50 {
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
@@ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
// 返回用于验证签名的密钥
return svcCxt.Config.Auth.AccessSecret, nil
return svcCtx.Config.Auth.AccessSecret, nil
})
if err != nil {
return nil, errors.New(fmt.Sprint("Error parsing token:", err))

View File

@@ -5,9 +5,10 @@ import (
"fmt"
"fusenapi/initalize"
"fusenapi/server/data-transfer/internal/config"
"net/http"
"github.com/golang-jwt/jwt"
"gorm.io/gorm"
"net/http"
)
type ServiceContext struct {
@@ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
}
}
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
AuthKey := r.Header.Get("Authorization")
if len(AuthKey) <= 50 {
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
@@ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
// 返回用于验证签名的密钥
return svcCxt.Config.Auth.AccessSecret, nil
return svcCtx.Config.Auth.AccessSecret, nil
})
if err != nil {
return nil, errors.New(fmt.Sprint("Error parsing token:", err))

View File

@@ -7,3 +7,6 @@ Auth:
AccessSecret: fusen2023
AccessExpire: 60
RefreshAfter: 60
Stripe:
SK: "123"

View File

@@ -10,4 +10,8 @@ type Config struct {
rest.RestConf
SourceMysql string
Auth types.Auth
Stripe struct {
SK string
}
}

View File

@@ -13,6 +13,9 @@ import (
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"github.com/stripe/stripe-go/v74"
"github.com/stripe/stripe-go/v74/client"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
@@ -104,27 +107,40 @@ func (l *UserOderDeleteLogic) UserOderDelete(req *types.RequestOrderId, userinfo
CreatedAt: &CreatedAt,
}
mFsRefund := gmodel.NewFsRefundReasonModel(l.svcCtx.MysqlConn)
err = refund.Save()
mFsRefundReason := gmodel.NewFsRefundReasonModel(l.svcCtx.MysqlConn)
err = mFsRefundReason.Create(l.ctx, refund)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeDbSqlErr)
}
// 退款
// 调用第三方接口发起退款
config := GetStripeConfig()
config := &stripe.BackendConfig{
MaxNetworkRetries: stripe.Int64(0), // Zero retries
}
sc := &client.API{}
sc.Init(l.svcCtx.Config.Stripe.SK, &stripe.Backends{
API: stripe.GetBackendWithConfig(stripe.APIBackend, config),
Uploads: stripe.GetBackendWithConfig(stripe.UploadsBackend, config),
})
// ['order_number' => $order->sn, 'is_refund' => 0, 'pay_status' => 1]
pay := gmodel.NewFsPayModel(l.svcCtx.MysqlConn)
// 查询支付信息
pays, err := Pay.Find(db.Where("order_number = ? AND is_refund = ? AND pay_status = ?", order.SN, 0, 1))
pays, err := pay.GetOrderPayList(l.ctx, *order.Sn, 1, 0)
for _, pay := range pays {
stripe := stripe.New(config.SK)
_, err := stripe.Refunds.Create(stripe.RefundParams{
sc.Refunds.New(&stripe.RefundParams{
PaymentIntent: pay.TradeNo,
})
}
if err == nil && err == nil {
return ResponseSuccess(200, "Cancel successfully", order)
}
return ResponseError(500, "Cancellation failure")
// if err == nil && err == nil {
// return ResponseSuccess(200, "Cancel successfully", order)
// }
// return ResponseError(500, "Cancellation failure")
return resp.SetStatus(basic.CodeOK)
}

View File

@@ -23,7 +23,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
}
}
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
AuthKey := r.Header.Get("Authorization")
if AuthKey == "" {
return nil, nil
@@ -35,7 +35,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
// 返回用于验证签名的密钥
return []byte(svcCxt.Config.Auth.AccessSecret), nil
return []byte(svcCtx.Config.Auth.AccessSecret), nil
})
if err != nil {
return nil, errors.New(fmt.Sprint("Error parsing token:", err))

View File

@@ -5,9 +5,10 @@ import (
"fmt"
"fusenapi/initalize"
"fusenapi/server/map-library/internal/config"
"net/http"
"github.com/golang-jwt/jwt"
"gorm.io/gorm"
"net/http"
)
type ServiceContext struct {
@@ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
}
}
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
AuthKey := r.Header.Get("Authorization")
if len(AuthKey) <= 50 {
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
@@ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
// 返回用于验证签名的密钥
return svcCxt.Config.Auth.AccessSecret, nil
return svcCtx.Config.Auth.AccessSecret, nil
})
if err != nil {
return nil, errors.New(fmt.Sprint("Error parsing token:", err))

View File

@@ -5,9 +5,10 @@ import (
"fmt"
"fusenapi/initalize"
"fusenapi/server/orders/internal/config"
"net/http"
"github.com/golang-jwt/jwt"
"gorm.io/gorm"
"net/http"
)
type ServiceContext struct {
@@ -24,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
}
}
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
AuthKey := r.Header.Get("Authorization")
if len(AuthKey) <= 50 {
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
@@ -36,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
// 返回用于验证签名的密钥
return svcCxt.Config.Auth.AccessSecret, nil
return svcCtx.Config.Auth.AccessSecret, nil
})
if err != nil {
return nil, errors.New(fmt.Sprint("Error parsing token:", err))

View File

@@ -2,11 +2,13 @@ package svc
import (
"errors"
"fmt"
"fusenapi/initalize"
"fusenapi/server/product-templatev2/internal/config"
"net/http"
"github.com/golang-jwt/jwt"
"gorm.io/gorm"
"net/http"
)
type ServiceContext struct {
@@ -23,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
}
}
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
AuthKey := r.Header.Get("Authorization")
if len(AuthKey) <= 50 {
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
@@ -35,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
// 返回用于验证签名的密钥
return svcCxt.Config.Auth.AccessSecret, nil
return svcCtx.Config.Auth.AccessSecret, nil
})
if err != nil {
return nil, errors.New(fmt.Sprint("Error parsing token:", err))

View File

@@ -25,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
}
}
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
AuthKey := r.Header.Get("Authorization")
if len(AuthKey) <= 50 {
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
@@ -37,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
// 返回用于验证签名的密钥
return svcCxt.Config.Auth.AccessSecret, nil
return svcCtx.Config.Auth.AccessSecret, nil
})
if err != nil {
return nil, errors.New(fmt.Sprint("Error parsing token:", err))

View File

@@ -25,7 +25,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
}
}
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
AuthKey := r.Header.Get("Authorization")
if len(AuthKey) <= 50 {
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
@@ -37,7 +37,7 @@ func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
// 返回用于验证签名的密钥
return svcCxt.Config.Auth.AccessSecret, nil
return svcCtx.Config.Auth.AccessSecret, nil
})
if err != nil {
return nil, errors.New(fmt.Sprint("Error parsing token:", err))