82 lines
2.4 KiB
Go
82 lines
2.4 KiB
Go
package models
|
|
|
|
import (
|
|
"apskel-pos-be/internal/constants"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type Payment struct {
|
|
ID uuid.UUID
|
|
OrderID uuid.UUID
|
|
PaymentMethodID uuid.UUID
|
|
Amount float64
|
|
Status constants.PaymentTransactionStatus
|
|
TransactionID *string
|
|
SplitNumber int
|
|
SplitTotal int
|
|
SplitDescription *string
|
|
RefundAmount float64
|
|
RefundReason *string
|
|
RefundedAt *time.Time
|
|
RefundedBy *uuid.UUID
|
|
Metadata map[string]interface{}
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
type CreatePaymentRequest struct {
|
|
OrderID uuid.UUID `validate:"required"`
|
|
PaymentMethodID uuid.UUID `validate:"required"`
|
|
Amount float64 `validate:"required,min=0"`
|
|
TransactionID *string `validate:"omitempty"`
|
|
SplitNumber int `validate:"omitempty,min=1"`
|
|
SplitTotal int `validate:"omitempty,min=1"`
|
|
SplitDescription *string `validate:"omitempty,max=255"`
|
|
PaymentOrderItems []CreatePaymentOrderItemRequest `validate:"omitempty,dive"`
|
|
Metadata map[string]interface{}
|
|
}
|
|
|
|
type UpdatePaymentRequest struct {
|
|
Status *constants.PaymentTransactionStatus
|
|
TransactionID *string
|
|
Notes *string `validate:"omitempty,max=1000"`
|
|
}
|
|
|
|
type PaymentResponse struct {
|
|
ID uuid.UUID
|
|
OrderID uuid.UUID
|
|
PaymentMethodID uuid.UUID
|
|
Amount float64
|
|
Status constants.PaymentTransactionStatus
|
|
TransactionID *string
|
|
SplitNumber int
|
|
SplitTotal int
|
|
SplitDescription *string
|
|
RefundAmount float64
|
|
RefundReason *string
|
|
RefundedAt *time.Time
|
|
RefundedBy *uuid.UUID
|
|
Metadata map[string]interface{}
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
PaymentOrderItems []PaymentOrderItemResponse
|
|
}
|
|
|
|
func (p *Payment) IsSuccessful() bool {
|
|
return p.Status == constants.PaymentTransactionStatusCompleted
|
|
}
|
|
|
|
func (p *Payment) IsPending() bool {
|
|
return p.Status == constants.PaymentTransactionStatusPending
|
|
}
|
|
|
|
func (p *Payment) CanBeRefunded() bool {
|
|
return p.Status == constants.PaymentTransactionStatusCompleted
|
|
}
|
|
|
|
func (p *Payment) IsProcessed() bool {
|
|
return p.Status == constants.PaymentTransactionStatusCompleted || p.Status == constants.PaymentTransactionStatusFailed
|
|
}
|