добавлен биллинг и тарифы

добавлена интеграция с юкасса
This commit is contained in:
2025-12-24 09:06:19 +03:00
parent b4ce819931
commit 5f35d7a75f
15 changed files with 745 additions and 212 deletions

View File

@@ -0,0 +1,47 @@
package billing
import (
"rmser/internal/domain/billing"
"github.com/google/uuid"
"gorm.io/gorm"
)
type pgRepository struct {
db *gorm.DB
}
func NewRepository(db *gorm.DB) billing.Repository {
return &pgRepository{db: db}
}
func (r *pgRepository) CreateOrder(order *billing.Order) error {
return r.db.Create(order).Error
}
func (r *pgRepository) GetOrder(id uuid.UUID) (*billing.Order, error) {
var order billing.Order
err := r.db.Where("id = ?", id).First(&order).Error
if err != nil {
return nil, err
}
return &order, nil
}
func (r *pgRepository) UpdateOrderStatus(id uuid.UUID, status billing.OrderStatus, paymentID string) error {
updates := map[string]interface{}{
"status": status,
}
if paymentID != "" {
updates["payment_id"] = paymentID
}
return r.db.Model(&billing.Order{}).Where("id = ?", id).Updates(updates).Error
}
func (r *pgRepository) GetActiveOrdersByUser(userID uuid.UUID) ([]billing.Order, error) {
var orders []billing.Order
err := r.db.Where("user_id = ? AND status = ?", userID, billing.StatusPending).
Order("created_at DESC").
Find(&orders).Error
return orders, err
}