Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
cb9b8ed6fd
3
go.mod
3
go.mod
|
@ -18,7 +18,7 @@ require (
|
|||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
github.com/streadway/amqp v1.1.0
|
||||
github.com/stripe/stripe-go/v74 v74.30.0
|
||||
github.com/stripe/stripe-go/v75 v75.7.0
|
||||
github.com/zeromicro/go-zero v1.5.4
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8
|
||||
golang.org/x/oauth2 v0.10.0
|
||||
|
@ -68,7 +68,6 @@ require (
|
|||
github.com/rogpeppe/go-internal v1.9.0 // indirect
|
||||
github.com/schollz/progressbar v1.0.0 // indirect
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
|
||||
github.com/stripe/stripe-go/v75 v75.7.0 // indirect
|
||||
github.com/valyala/fastrand v1.1.0 // indirect
|
||||
github.com/valyala/histogram v1.2.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.14.0 // indirect
|
||||
|
|
7
go.sum
7
go.sum
|
@ -83,7 +83,6 @@ github.com/aws/aws-sdk-go v1.44.295 h1:SGjU1+MqttXfRiWHD6WU0DRhaanJgAFY+xIhEaugV
|
|||
github.com/aws/aws-sdk-go v1.44.295/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
|
||||
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
|
@ -184,7 +183,6 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
|
|||
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
|
||||
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
|
@ -346,7 +344,6 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y
|
|||
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
|
||||
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
|
||||
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
|
@ -359,7 +356,6 @@ github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0b
|
|||
github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
|
||||
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
|
||||
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
|
||||
github.com/kataras/golog v0.0.9/go.mod h1:12HJgwBIZFNGL0EJnMRhmvGA0PQGx8VFwrZtM4CqbAk=
|
||||
|
@ -438,7 +434,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
|
|||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/nacos-group/nacos-sdk-go/v2 v2.2.3 h1:sUQx4f1bXDeeOOEQZjGAitzxYApbYY9fVDbxVCaBW+I=
|
||||
github.com/nacos-group/nacos-sdk-go/v2 v2.2.3/go.mod h1:UL4U89WYdnyajgKJUMpuT1Rr6iNmbjrxOO40JRgtA00=
|
||||
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
|
||||
|
@ -553,8 +548,6 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
|
|||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stripe/stripe-go/v74 v74.30.0 h1:0Kf0KkeFnY7iRhOwvTerX0Ia1BRw+eV1CVJ51mGYAUY=
|
||||
github.com/stripe/stripe-go/v74 v74.30.0/go.mod h1:f9L6LvaXa35ja7eyvP6GQswoaIPaBRvGAimAO+udbBw=
|
||||
github.com/stripe/stripe-go/v75 v75.7.0 h1:Zk7trlj0kClZOwnpjGz7FgVQRBI0Koi28/eaNATgAs0=
|
||||
github.com/stripe/stripe-go/v75 v75.7.0/go.mod h1:wT44gah+eCY8Z0aSpY/vQlYYbicU9uUAbAqdaUxxDqE=
|
||||
github.com/tidwall/gjson v1.12.0 h1:61wEp/qfvFnqKH/WCI3M8HuRut+mHT6Mr82QrFmM2SY=
|
||||
|
|
|
@ -2,17 +2,19 @@ package gmodel
|
|||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (a *FsAddressModel) GetOne(ctx context.Context, id int64, userId int64) (resp *FsAddress, err error) {
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`id` = ? and `user_id` = ? and `status` = ? ", id, userId, 1).Take(&resp).Error
|
||||
func (a *FsAddressModel) GetOne(ctx context.Context, addressId int64, userId int64) (resp *FsAddress, err error) {
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`address_id` = ? and `user_id` = ? and `status` = ? ", addressId, userId, 1).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []FsAddress, err error) {
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = ?", userId, 1).Order("`id` DESC").Find(&resp).Error
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = ?", userId, 1).Order("`ltime` DESC").Find(&resp).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -21,8 +23,8 @@ func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (r
|
|||
|
||||
func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (result *FsAddress, err error) {
|
||||
|
||||
err = a.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
// now := time.Now().UTC().Unix()
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
||||
now := time.Now().UTC()
|
||||
result = &FsAddress{
|
||||
UserId: address.UserId,
|
||||
AddressName: address.AddressName,
|
||||
|
@ -37,9 +39,26 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res
|
|||
ZipCode: address.ZipCode,
|
||||
Status: address.Status,
|
||||
IsDefault: address.IsDefault,
|
||||
Ctime: &now,
|
||||
Utime: &now,
|
||||
Ltime: &now,
|
||||
}
|
||||
|
||||
return tx.Create(result).Error
|
||||
// lastOne := &FsAddress{}
|
||||
// err = tx.Where("user_id = ?", lastOne.UserId).Order("ltime ASC").Take(&lastOne).Error
|
||||
// if err == gorm.ErrRecordNotFound {
|
||||
// result.Ltime = &now
|
||||
// return tx.Model(&FsAddress{}).Create(result).Error
|
||||
// }
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// // 根据lastOne处理时间
|
||||
|
||||
// ltime := (*lastOne.Ltime).Add(-time.Second)
|
||||
// result.Ltime = <ime
|
||||
return tx.Model(&FsAddress{}).Create(result).Error
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -61,3 +80,28 @@ func (a *FsAddressModel) UpdateAddAddress(ctx context.Context, address *FsAddres
|
|||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId int64, addressId int64) (resp []FsAddress, err error) {
|
||||
|
||||
a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
now := time.Now().UTC()
|
||||
|
||||
err = tx.Where(" `user_id` = ? and `status` = ? and `address_id = ?` ", userId, 1, addressId).
|
||||
UpdateColumn("ltime", now.Add(time.Hour*24*365*290)).
|
||||
UpdateColumn("utime", now).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.Where(" `user_id` = ? and `status` = ? and `address_id != ? and `ltime` > ?` ", userId, 1, addressId, now.Add(time.Hour*24*365)).
|
||||
UpdateColumn("ltime", now).Error
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
func AddressAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.AddressNameRequest
|
||||
var req types.AddressRequest
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
|
@ -30,11 +31,60 @@ func NewAddressAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Addres
|
|||
// func (l *AddressAddLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *AddressAddLogic) AddressAdd(req *types.AddressNameRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
func (l *AddressAddLogic) AddressAdd(req *types.AddressRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
// 确认这个IsDefault的值范围
|
||||
if !auth.CheckValueRange(req.IsDefault, 0, 1) {
|
||||
return resp.SetStatus(basic.CodeSafeValueRangeErr) // IsDefault值超出范围, 返回安全值范围错误
|
||||
}
|
||||
|
||||
m := l.svcCtx.AllModels.FsAddress // 创建地址模型
|
||||
|
||||
// 如果ID为0, 表示新增地址
|
||||
|
||||
var (
|
||||
country string = "USA" // 国家默认为美国
|
||||
isDefautl int64 = 1 // 默认地址为1
|
||||
status int64 = 1 // 默认地址状态为1(正常)
|
||||
)
|
||||
|
||||
createOne := &gmodel.FsAddress{ // 构建FsAddress结构体
|
||||
AddressName: &req.AddressName,
|
||||
FirstName: &req.FirstName,
|
||||
LastName: &req.LastName,
|
||||
Mobile: &req.Mobile,
|
||||
Street: &req.Street,
|
||||
Suite: &req.Suite,
|
||||
City: &req.City,
|
||||
State: &req.State,
|
||||
Country: &country,
|
||||
Status: &status,
|
||||
UserId: &userinfo.UserId,
|
||||
ZipCode: &req.ZipCode,
|
||||
IsDefault: &isDefautl,
|
||||
}
|
||||
_, err := m.CreateOne(l.ctx, createOne) // 新增地址
|
||||
if err != nil {
|
||||
logx.Error(err) // 日志记录错误
|
||||
return resp.SetStatus(basic.CodeDbCreateErr) // 返回数据库创建错误
|
||||
}
|
||||
|
||||
addresses, err := m.GetUserAllAddress(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr) // 返回数据库创建错误
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, map[string]any{
|
||||
"address_list": addresses,
|
||||
}) // 返回成功并返回地址ID
|
||||
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
|
|
|
@ -34,6 +34,10 @@ func (l *AddressDefaultLogic) AddressDefault(req *types.AddressIdRequest, userin
|
|||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ type UserInfoRequest struct {
|
|||
}
|
||||
|
||||
type AddressObjectRequest struct {
|
||||
AddressId int64 `json:"address_id"` // 地址id
|
||||
Address string `json:"address"` // 地址
|
||||
AddressId int64 `json:"address_id"` // 地址id
|
||||
AddressName string `json:"address_name"` // 地址
|
||||
}
|
||||
|
||||
type AddressIdRequest struct {
|
||||
|
@ -19,7 +19,20 @@ type AddressIdRequest struct {
|
|||
}
|
||||
|
||||
type AddressNameRequest struct {
|
||||
Address string `json:"address"` // 地址
|
||||
AddressName string `json:"address_name"` // 地址
|
||||
}
|
||||
|
||||
type AddressRequest struct {
|
||||
IsDefault int64 `json:"is_default"` //是否默认
|
||||
AddressName string `json:"address_name"` //收货人
|
||||
FirstName string `json:"first_name"` //first_name
|
||||
LastName string `json:"last_name"` //last_name
|
||||
Mobile string `json:"mobile"` //手机
|
||||
ZipCode string `json:"zip_code"` //邮编
|
||||
Street string `json:"street"` //街道
|
||||
Suite string `json:"suite"` //房号
|
||||
City string `json:"city"` //城市
|
||||
State string `json:"state"` //州
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
|
|
|
@ -16,8 +16,8 @@ import (
|
|||
"fusenapi/server/pay/internal/svc"
|
||||
"fusenapi/server/pay/internal/types"
|
||||
|
||||
"github.com/stripe/stripe-go/v74"
|
||||
"github.com/stripe/stripe-go/v74/webhook"
|
||||
"github.com/stripe/stripe-go/v75"
|
||||
"github.com/stripe/stripe-go/v75/webhook"
|
||||
"github.com/zeromicro/go-zero/core/logc"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
@ -73,24 +73,30 @@ func (l *StripeWebhookLogic) StripeWebhook(req *types.StripeWebhookReq, userinfo
|
|||
var payMethod = int64(constants.PAYMETHOD_STRIPE)
|
||||
var nowTime = time.Now().UTC()
|
||||
var eventData = []byte(event.Data.Raw)
|
||||
eventType := string(event.Type)
|
||||
l.HandlePayEventCreate(&gmodel.FsOrderTradeEvent{
|
||||
PayMethod: &payMethod,
|
||||
EventId: &event.ID,
|
||||
EventType: &event.Type,
|
||||
EventType: &eventType,
|
||||
EventData: &eventData,
|
||||
Ctime: &nowTime,
|
||||
})
|
||||
|
||||
// Unmarshal the event data into an appropriate struct depending on its Type
|
||||
fmt.Println("事件类型", event.Type)
|
||||
switch event.Type {
|
||||
case "charge.succeeded":
|
||||
// var charge stripe.Charge
|
||||
// err := json.Unmarshal(event.Data.Raw, &charge)
|
||||
// if err != nil {
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type charge.succeeded")
|
||||
// }
|
||||
|
||||
var charge stripe.Charge
|
||||
err := json.Unmarshal(event.Data.Raw, &charge)
|
||||
if err != nil {
|
||||
logx.Errorf("err:%+v,desc:%s", err, "pay notify Unmarshal fail event.Type charge.succeeded")
|
||||
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type charge.succeeded")
|
||||
}
|
||||
err = l.HandleChargeSucceeded(&charge, event.ID)
|
||||
if err != nil {
|
||||
logx.Errorf("err:%+v,desc:%s", err, "pay notify handle payment_intent.succeeded")
|
||||
return resp.SetStatusWithMessage(basic.CodePaybackNotOk, "pay notify handle payment_intent.succeeded")
|
||||
}
|
||||
case "checkout.session.completed":
|
||||
// checkout checkout.session.completed 处理逻辑
|
||||
// var session stripe.CheckoutSession
|
||||
|
@ -105,24 +111,24 @@ func (l *StripeWebhookLogic) StripeWebhook(req *types.StripeWebhookReq, userinfo
|
|||
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "checkout.session.completed fail")
|
||||
// }
|
||||
case "payment_intent.succeeded":
|
||||
var paymentIntent stripe.PaymentIntent
|
||||
err := json.Unmarshal(event.Data.Raw, &paymentIntent)
|
||||
if err != nil {
|
||||
logx.Errorf("err:%+v,desc:%s", err, "pay notify Unmarshal fail event.Type payment_intent.succeeded")
|
||||
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type payment_intent.succeeded")
|
||||
}
|
||||
err = l.HandlePaymentIntentSucceeded(&paymentIntent, event.ID)
|
||||
if err != nil {
|
||||
logx.Errorf("err:%+v,desc:%s", err, "pay notify handle payment_intent.succeeded")
|
||||
return resp.SetStatusWithMessage(basic.CodePaybackNotOk, "pay notify handle payment_intent.succeeded")
|
||||
}
|
||||
// var paymentIntent stripe.PaymentIntent
|
||||
// err := json.Unmarshal(event.Data.Raw, &paymentIntent)
|
||||
// if err != nil {
|
||||
// logx.Errorf("err:%+v,desc:%s", err, "pay notify Unmarshal fail event.Type payment_intent.succeeded")
|
||||
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type payment_intent.succeeded")
|
||||
// }
|
||||
// err = l.HandlePaymentIntentSucceeded(&paymentIntent, event.ID)
|
||||
// if err != nil {
|
||||
// logx.Errorf("err:%+v,desc:%s", err, "pay notify handle payment_intent.succeeded")
|
||||
// return resp.SetStatusWithMessage(basic.CodePaybackNotOk, "pay notify handle payment_intent.succeeded")
|
||||
// }
|
||||
case "payment_method.attached":
|
||||
var paymentMethod stripe.PaymentMethod
|
||||
err := json.Unmarshal(event.Data.Raw, &paymentMethod)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type payment_method.attached")
|
||||
}
|
||||
// var paymentMethod stripe.PaymentMethod
|
||||
// err := json.Unmarshal(event.Data.Raw, &paymentMethod)
|
||||
// if err != nil {
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type payment_method.attached")
|
||||
// }
|
||||
case "charge.refunded":
|
||||
var chargeRefunded stripe.Charge
|
||||
err := json.Unmarshal(event.Data.Raw, &chargeRefunded)
|
||||
|
@ -235,11 +241,10 @@ func (l *StripeWebhookLogic) handlePaymentSessionCompleted(sessionId string, tra
|
|||
}
|
||||
|
||||
// 付款成功
|
||||
func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe.PaymentIntent, eventId string) error {
|
||||
fmt.Println(paymentIntent)
|
||||
func (l *StripeWebhookLogic) HandleChargeSucceeded(charge *stripe.Charge, eventId string) error {
|
||||
// 支付成功
|
||||
if paymentIntent.Status == "succeeded" {
|
||||
model, ok := paymentIntent.Metadata["model"]
|
||||
if charge.Status == "succeeded" {
|
||||
model, ok := charge.Metadata["model"]
|
||||
if !ok {
|
||||
err := errors.New("model is empty")
|
||||
logc.Errorf(l.ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", eventId, err)
|
||||
|
@ -250,7 +255,7 @@ func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe.
|
|||
res, err := l.svcCtx.Repositories.NewOrder.PaymentSuccessful(l.ctx, &repositories.PaymentSuccessfulReq{
|
||||
EventId: eventId,
|
||||
PaymentMethod: 1,
|
||||
PaymentIntent: paymentIntent,
|
||||
Charge: charge,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -32,8 +32,8 @@ type (
|
|||
}
|
||||
|
||||
AddressObjectRequest {
|
||||
AddressId int64 `json:"address_id"` // 地址id
|
||||
AddressName string `json:"address_name"` // 地址
|
||||
AddressId int64 `json:"address_id"` // 地址id
|
||||
AddressName string `json:"address_name"` // 地址
|
||||
}
|
||||
|
||||
AddressIdRequest {
|
||||
|
@ -43,4 +43,17 @@ type (
|
|||
AddressNameRequest {
|
||||
AddressName string `json:"address_name"` // 地址
|
||||
}
|
||||
|
||||
AddressRequest {
|
||||
IsDefault int64 `json:"is_default"` //是否默认
|
||||
AddressName string `json:"address_name"` //收货人
|
||||
FirstName string `json:"first_name"` //first_name
|
||||
LastName string `json:"last_name"` //last_name
|
||||
Mobile string `json:"mobile"` //手机
|
||||
ZipCode string `json:"zip_code"` //邮编
|
||||
Street string `json:"street"` //街道
|
||||
Suite string `json:"suite"` //房号
|
||||
City string `json:"city"` //城市
|
||||
State string `json:"state"` //州
|
||||
}
|
||||
)
|
|
@ -15,7 +15,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/stripe/stripe-go/v74"
|
||||
"github.com/stripe/stripe-go/v75"
|
||||
"github.com/zeromicro/go-zero/core/logc"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
|
@ -80,7 +80,7 @@ type (
|
|||
PaymentSuccessfulReq struct {
|
||||
EventId string
|
||||
PaymentMethod int64
|
||||
PaymentIntent *stripe.PaymentIntent
|
||||
Charge *stripe.Charge
|
||||
}
|
||||
PaymentSuccessfulRes struct{}
|
||||
/* 支付成功 */
|
||||
|
@ -174,43 +174,43 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
|
|||
var payAmount int64
|
||||
var payTitle string
|
||||
var payTime time.Time
|
||||
if in.PaymentIntent != nil {
|
||||
paymentIntent := in.PaymentIntent
|
||||
orderSn, ok = paymentIntent.Metadata["order_sn"]
|
||||
if in.Charge != nil {
|
||||
charge := in.Charge
|
||||
orderSn, ok = charge.Metadata["order_sn"]
|
||||
if !ok || orderSn == "" {
|
||||
err = errors.New("order_sn is empty")
|
||||
logc.Errorf(ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", in.EventId, err)
|
||||
return &PaymentSuccessfulRes{}, err
|
||||
}
|
||||
payStage, ok = paymentIntent.Metadata["pay_stage"]
|
||||
payStage, ok = charge.Metadata["pay_stage"]
|
||||
if !ok || payStage == "" {
|
||||
err = errors.New("pay_stage is empty")
|
||||
logc.Errorf(ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", in.EventId, err)
|
||||
return &PaymentSuccessfulRes{}, err
|
||||
}
|
||||
country, ok = paymentIntent.Metadata["country"]
|
||||
country, ok = charge.Metadata["country"]
|
||||
if !ok || country == "" {
|
||||
err = errors.New("country is empty")
|
||||
logc.Errorf(ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", in.EventId, err)
|
||||
return &PaymentSuccessfulRes{}, err
|
||||
}
|
||||
if paymentIntent.LatestCharge.PaymentMethodDetails != nil {
|
||||
if paymentIntent.LatestCharge.PaymentMethodDetails.Card != nil {
|
||||
if paymentIntent.LatestCharge.PaymentMethodDetails.Card.Last4 != "" {
|
||||
card = paymentIntent.LatestCharge.PaymentMethodDetails.Card.Last4
|
||||
if charge.PaymentMethodDetails != nil {
|
||||
if charge.PaymentMethodDetails.Card != nil {
|
||||
if charge.PaymentMethodDetails.Card.Last4 != "" {
|
||||
card = charge.PaymentMethodDetails.Card.Last4
|
||||
}
|
||||
if paymentIntent.LatestCharge.PaymentMethodDetails.Card.Brand != "" {
|
||||
brand = string(paymentIntent.LatestCharge.PaymentMethodDetails.Card.Brand)
|
||||
if charge.PaymentMethodDetails.Card.Brand != "" {
|
||||
brand = string(charge.PaymentMethodDetails.Card.Brand)
|
||||
}
|
||||
}
|
||||
}
|
||||
if paymentIntent.Currency != "" {
|
||||
currency = string(paymentIntent.Currency)
|
||||
if charge.Currency != "" {
|
||||
currency = string(charge.Currency)
|
||||
}
|
||||
tradeSn = paymentIntent.ID
|
||||
payAmount = paymentIntent.Amount
|
||||
payTitle = paymentIntent.Description
|
||||
payTime = time.Unix(paymentIntent.Created, 0)
|
||||
tradeSn = charge.ID
|
||||
payAmount = charge.Amount
|
||||
payTitle = charge.Description
|
||||
payTime = time.Unix(charge.Created, 0)
|
||||
}
|
||||
err = d.MysqlConn.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var orderInfo gmodel.FsOrder
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package pay
|
||||
|
||||
import (
|
||||
"github.com/stripe/stripe-go/v74"
|
||||
"github.com/stripe/stripe-go/v74/checkout/session"
|
||||
"github.com/stripe/stripe-go/v74/paymentintent"
|
||||
"github.com/stripe/stripe-go/v74/refund"
|
||||
"github.com/stripe/stripe-go/v75"
|
||||
"github.com/stripe/stripe-go/v75/checkout/session"
|
||||
"github.com/stripe/stripe-go/v75/paymentintent"
|
||||
"github.com/stripe/stripe-go/v75/refund"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user