Files
opsx-licence/backend/internal/dto/commerce.go
T
Logan.LiandCursor bac72e6945 fix: 按评审报告止血支付漏洞并加固授权链路
废除浏览器回跳自助结算,通用 webhook 强制密钥鉴权,Waffo 支持验签与未知事件忽略;重构订单状态机/激活占座/SQLite WAL,并补备份、readyz、限流与前端导出/登录页安全修复。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-12 21:26:58 +08:00

203 lines
7.9 KiB
Go

package dto
// PlanCreate 创建定价计划请求 // Logan.Li
type PlanCreate struct {
ProductID uint `json:"product_id" binding:"required"`
Name string `json:"name" binding:"required"`
PlanType string `json:"plan_type" binding:"required"` // perpetual / monthly / yearly / lifetime
Price float64 `json:"price" binding:"required"`
Currency string `json:"currency"`
Duration int `json:"duration"`
MaxDevices int `json:"max_devices"`
Features []string `json:"features"`
SortOrder int `json:"sort_order"`
Status *int `json:"status"`
}
// PlanUpdate 更新定价计划请求 // Logan.Li
type PlanUpdate struct {
Name string `json:"name"`
Price *float64 `json:"price"`
Currency string `json:"currency"`
Duration *int `json:"duration"`
MaxDevices *int `json:"max_devices"`
Features []string `json:"features"`
SortOrder *int `json:"sort_order"`
Status *int `json:"status"`
}
// PlanResponse 定价计划响应 // Logan.Li
type PlanResponse struct {
ID uint `json:"id"`
ProductID uint `json:"product_id"`
ProductName string `json:"product_name"`
Name string `json:"name"`
PlanType string `json:"plan_type"`
Price float64 `json:"price"`
Currency string `json:"currency"`
Duration int `json:"duration"`
MaxDevices int `json:"max_devices"`
Features []string `json:"features"`
SortOrder int `json:"sort_order"`
Status int `json:"status"`
}
// OrderResponse 订单响应 // Logan.Li
type OrderResponse struct {
ID uint `json:"id"`
OrderNo string `json:"order_no"`
CustomerID uint `json:"customer_id"`
CustomerName string `json:"customer_name"`
ProductID uint `json:"product_id"`
ProductName string `json:"product_name"`
PlanID uint `json:"plan_id"`
PlanName string `json:"plan_name"`
LicenseID uint `json:"license_id"`
Amount float64 `json:"amount"`
Currency string `json:"currency"`
Status string `json:"status"`
PaymentGateway string `json:"payment_gateway"`
CreatedAt string `json:"created_at"`
PaidAt string `json:"paid_at,omitempty"`
}
// CreateOrderRequest 创建订单请求(客户端购买入口) // Logan.Li
type CreateOrderRequest struct {
CustomerEmail string `json:"customer_email" binding:"required,email"`
CustomerName string `json:"customer_name"`
ProductID uint `json:"product_id"`
PlanID uint `json:"plan_id"`
ProductCode string `json:"product_code"` // preferred by desktop clients
PlanType string `json:"plan_type"` // e.g. perpetual
DeviceID string `json:"device_id"`
ReturnURL string `json:"return_url"`
CancelURL string `json:"cancel_url"`
}
// CreateOrderResponse 创建订单响应 // Logan.Li
type CreateOrderResponse struct {
OrderNo string `json:"order_no"`
CheckoutURL string `json:"checkout_url"`
Amount float64 `json:"amount"`
Currency string `json:"currency"`
Status string `json:"status"`
Gateway string `json:"gateway"`
ExpiresAt string `json:"expires_at"`
}
// CheckoutRequest desktop-friendly checkout (product_code + email). // Logan.Li
type CheckoutRequest struct {
CustomerEmail string `json:"customer_email" binding:"required,email"`
CustomerName string `json:"customer_name"`
ProductCode string `json:"product_code"`
PlanType string `json:"plan_type"`
DeviceID string `json:"device_id"`
ReturnURL string `json:"return_url"`
CancelURL string `json:"cancel_url"`
}
// ClaimPurchaseRequest fetch license after payment. // Logan.Li
type ClaimPurchaseRequest struct {
CustomerEmail string `json:"customer_email"`
OrderNo string `json:"order_no"`
ProductCode string `json:"product_code"`
DeviceID string `json:"device_id"`
}
// ClaimPurchaseResponse returned after successful payment. // Logan.Li
type ClaimPurchaseResponse struct {
LicenseKey string `json:"license_key"`
OrderNo string `json:"order_no,omitempty"`
Status string `json:"status"`
Message string `json:"message,omitempty"`
}
// ProductWithPlansResponse for GET /v1/products/code/:code // Logan.Li
type ProductWithPlansResponse struct {
Product ProductResponse `json:"product"`
Plans []PlanResponse `json:"plans"`
}
// PaymentWebhookRequest 支付回调请求 // Logan.Li
type PaymentWebhookRequest struct {
EventType string `json:"event_type"`
OrderNo string `json:"order_no"`
GatewayOrderNo string `json:"gateway_order_no"`
Status string `json:"status" binding:"required"` // paid / failed / refunded
Amount float64 `json:"amount"`
Currency string `json:"currency"`
CustomerEmail string `json:"customer_email"`
Gateway string `json:"gateway" binding:"required"`
Signature string `json:"signature"`
Payload string `json:"payload"`
}
// ManualGrantRequest 手动发放 License 请求(管理后台) // Logan.Li
type ManualGrantRequest struct {
CustomerEmail string `json:"customer_email" binding:"required,email"`
CustomerName string `json:"customer_name"`
ProductID uint `json:"product_id" binding:"required"`
PlanID uint `json:"plan_id" binding:"required"`
DeviceID string `json:"device_id"`
Notes string `json:"notes"`
}
// EntitlementResponse 客户权益响应 // Logan.Li
type EntitlementResponse struct {
ID uint `json:"id"`
CustomerID uint `json:"customer_id"`
CustomerName string `json:"customer_name"`
ProductID uint `json:"product_id"`
ProductName string `json:"product_name"`
PlanID uint `json:"plan_id"`
PlanName string `json:"plan_name"`
PlanType string `json:"plan_type"`
LicenseKey string `json:"license_key"`
Status string `json:"status"`
ValidFrom string `json:"valid_from"`
ValidUntil *string `json:"valid_until,omitempty"`
DaysLeft int `json:"days_left"`
Renewable bool `json:"renewable"`
MaxDevices int `json:"max_devices"`
CurrentDevices int `json:"current_devices"`
}
// DuplicatePurchaseCheckRequest 防重复购买检测请求 // Logan.Li
type DuplicatePurchaseCheckRequest struct {
CustomerEmail string `json:"customer_email" binding:"required,email"`
ProductID uint `json:"product_id" binding:"required"`
}
// DuplicatePurchaseCheckResponse 防重复购买检测响应 // Logan.Li
type DuplicatePurchaseCheckResponse struct {
AllowPurchase bool `json:"allow_purchase"`
Reason string `json:"reason,omitempty"`
ExistingEntitlementID uint `json:"existing_entitlement_id,omitempty"`
ExistingLicenseKey string `json:"existing_license_key,omitempty"`
ExistingPlanType string `json:"existing_plan_type,omitempty"`
CanUpgrade bool `json:"can_upgrade"`
UpgradeOptions []PlanResponse `json:"upgrade_options,omitempty"`
}
// CheckPurchaseStatusRequest 购买状态查询请求 // Logan.Li
type CheckPurchaseStatusRequest struct {
CustomerEmail string `json:"customer_email" binding:"required,email"`
ProductID uint `json:"product_id" binding:"required"`
}
// CheckPurchaseStatusResponse 购买状态查询响应 // Logan.Li
type CheckPurchaseStatusResponse struct {
Purchased bool `json:"purchased"`
HasActiveLicense bool `json:"has_active_license"`
LicenseKey string `json:"license_key,omitempty"`
LicenseStatus string `json:"license_status,omitempty"`
PlanType string `json:"plan_type,omitempty"`
ValidUntil *string `json:"valid_until,omitempty"`
DaysLeft int `json:"days_left,omitempty"`
Renewable bool `json:"renewable"`
MaxDevices int `json:"max_devices,omitempty"`
CurrentDevices int `json:"current_devices,omitempty"`
EntitlementID uint `json:"entitlement_id,omitempty"`
Message string `json:"message,omitempty"`
}