Files
rmser/internal/domain/billing/entity.go
SERTY 5f35d7a75f добавлен биллинг и тарифы
добавлена интеграция с юкасса
2025-12-24 09:06:19 +03:00

58 lines
2.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// internal/domain/billing/entity.go
package billing
import (
"time"
"github.com/google/uuid"
)
type TariffType string
const (
TariffPack TariffType = "PACK" // Пакет накладных
TariffSubscription TariffType = "SUBSCRIPTION" // Подписка (безлимит на время)
)
type OrderStatus string
const (
StatusPending OrderStatus = "PENDING"
StatusPaid OrderStatus = "PAID"
StatusCanceled OrderStatus = "CANCELED"
)
// Tariff - Описание услуги
type Tariff struct {
ID string `json:"id"`
Name string `json:"name"`
Type TariffType `json:"type"`
Price float64 `json:"price"`
InvoicesCount int `json:"invoices_count"` // Для PACK - сколько штук, для SUBSCRIPTION - 1000 (лимит)
DurationDays int `json:"duration_days"`
}
// Order - Заказ на покупку тарифа
type Order struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
UserID uuid.UUID `gorm:"type:uuid;not null;index" json:"user_id"` // Кто платит
TargetServerID uuid.UUID `gorm:"type:uuid;not null;index" json:"target_server_id"` // Кому начисляем
TariffID string `gorm:"type:varchar(50);not null" json:"tariff_id"`
Amount float64 `gorm:"type:numeric(19,4);not null" json:"amount"`
Status OrderStatus `gorm:"type:varchar(20);default:'PENDING'" json:"status"`
PaymentID string `gorm:"type:varchar(100)" json:"payment_id"` // ID транзакции в ЮКассе
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Repository для работы с заказами
type Repository interface {
CreateOrder(order *Order) error
GetOrder(id uuid.UUID) (*Order, error)
UpdateOrderStatus(id uuid.UUID, status OrderStatus, paymentID string) error
GetActiveOrdersByUser(userID uuid.UUID) ([]Order, error)
}