This commit is contained in:
momo 2023-11-16 16:35:22 +08:00
parent 2aae36dfca
commit b045d44d14
7 changed files with 15 additions and 113 deletions

View File

@ -10,7 +10,7 @@ const (
type Currency string
const (
CURRENCYUSD Currency = "usd"
CURRENCYUSD Currency = "usd" // 美金
)
// 金额单位
@ -45,11 +45,11 @@ type OrderPayStatusCode int64
// 30,已付尾款
// 40,已退尾款
const (
ORDER_PAY_STATUS_UNPAIDDEPOSIT OrderPayStatusCode = 0
ORDER_PAY_STATUS_PAIDDEPOSIT OrderPayStatusCode = 10
ORDER_PAY_STATUS_REFUNDEDDEPOSIT OrderPayStatusCode = 20
ORDER_PAY_STATUS_PAIDDREMAINING OrderPayStatusCode = 30
ORDER_PAY_STATUS_REFUNDEDREMAINING OrderPayStatusCode = 40
ORDER_PAY_STATUS_UNPAIDDEPOSIT OrderPayStatusCode = 0 // 0,未付首款
ORDER_PAY_STATUS_PAIDDEPOSIT OrderPayStatusCode = 10 // 10,已付首款
ORDER_PAY_STATUS_REFUNDEDDEPOSIT OrderPayStatusCode = 20 // 20,已退首款
ORDER_PAY_STATUS_PAIDDREMAINING OrderPayStatusCode = 30 // 30,已付尾款
ORDER_PAY_STATUS_REFUNDEDREMAINING OrderPayStatusCode = 40 // 40,已退尾款
)
// 订单状态
@ -102,17 +102,17 @@ func init() {
// 订单状态名称
OrderPayStatusMessage = make(map[OrderPayStatusCode]string)
OrderPayStatusMessage[ORDER_PAY_STATUS_UNPAIDDEPOSIT] = "Deposit Payment Unpaid"
OrderPayStatusMessage[ORDER_PAY_STATUS_PAIDDEPOSIT] = "Deposit Payment Paid"
OrderPayStatusMessage[ORDER_PAY_STATUS_REFUNDEDDEPOSIT] = "Deposit Payment Refunded"
OrderPayStatusMessage[ORDER_PAY_STATUS_PAIDDREMAINING] = "Final Payment Paid"
OrderPayStatusMessage[ORDER_PAY_STATUS_REFUNDEDREMAINING] = "Final Payment Refunded"
OrderPayStatusMessage[ORDER_PAY_STATUS_UNPAIDDEPOSIT] = "Deposit Payment Unpaid" // 未支付首款
OrderPayStatusMessage[ORDER_PAY_STATUS_PAIDDEPOSIT] = "Deposit Payment Paid" // 已支付首款
OrderPayStatusMessage[ORDER_PAY_STATUS_REFUNDEDDEPOSIT] = "Deposit Payment Refunded" // 首款已回退
OrderPayStatusMessage[ORDER_PAY_STATUS_PAIDDREMAINING] = "Final Payment Paid" // 尾款未支付
OrderPayStatusMessage[ORDER_PAY_STATUS_REFUNDEDREMAINING] = "Final Payment Refunded" // 已退款
// 订单状态名称
PayStatusMessage = make(map[PayStatusCode]string)
PayStatusMessage[PAY_STATUS_UNPAID] = "Unpaid"
PayStatusMessage[PAY_STATUS_PAID] = "Paid"
PayStatusMessage[PAY_STATUS_REFUNDED] = "Refunded"
PayStatusMessage[PAY_STATUS_UNPAID] = "Unpaid" // 未支付
PayStatusMessage[PAY_STATUS_PAID] = "Paid" // 已支付
PayStatusMessage[PAY_STATUS_REFUNDED] = "Refunded" // 已退款
// 订单状态名称
OrderStatusMessage = make(map[OrderStatusCode]string)

View File

@ -4,6 +4,7 @@ import (
"errors"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"gorm.io/gorm"
"context"

View File

@ -1,35 +0,0 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/pay/internal/logic"
"fusenapi/server/pay/internal/svc"
"fusenapi/server/pay/internal/types"
)
func OrderRefundHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.OrderRefundReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewOrderRefundLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.OrderRefund(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -12,11 +12,6 @@ import (
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/api/pay/refund",
Handler: OrderRefundHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/pay/stripe-webhook",

View File

@ -1,43 +0,0 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/pay/internal/svc"
"fusenapi/server/pay/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type OrderRefundLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewOrderRefundLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderRefundLogic {
return &OrderRefundLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *OrderRefundLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *OrderRefundLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }
func (l *OrderRefundLogic) OrderRefund(req *types.OrderRefundReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
return resp.SetStatus(basic.CodeOK)
}

View File

@ -5,12 +5,6 @@ import (
"fusenapi/utils/basic"
)
type OrderRefundReq struct {
}
type OrderRefundRes struct {
}
type StripeWebhookReq struct {
Payload []byte `json:"base_byte_slice,optional"`
StripeSignature string `json:"Stripe-Signature"`

View File

@ -10,21 +10,11 @@ info (
import "basic.api"
service pay {
@handler OrderRefundHandler
post /api/pay/refund(OrderRefundReq) returns (response);
@handler StripeWebhookHandler
post /api/pay/stripe-webhook(StripeWebhookReq) returns (response);
}
// 退款
type (
OrderRefundReq struct{}
OrderRefundRes struct{}
)
// StripeWebhook支付通知
type (
StripeWebhookReq {