treasurer/internal/models/payment.go
2024-12-16 16:47:40 +03:00

94 lines
3.0 KiB
Go

package models
import (
"time"
"gitea.pena/PenaSide/treasurer/internal/models/yandex"
)
type Payment struct {
ID string `json:"id" bson:"_id,omitempty"`
UserID string `json:"userId" bson:"userId"`
PaymentID string `json:"paymentId" bson:"paymentId"`
IdempotencePaymentID string `json:"idempotencePaymentId" bson:"idempotencePaymentId"`
ClientIP string `json:"clientIp" bson:"clientIp"`
Currency string `json:"currency" bson:"currency"`
Amount int64 `json:"amount" bson:"amount"`
Type PaymentType `json:"type" bson:"type"`
Status PaymentStatus `json:"status" bson:"status"`
Completed bool `json:"completed" bson:"completed"`
IsDeleted bool `json:"isDeleted" bson:"isDeleted"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt,omitempty" bson:"deletedAt,omitempty"`
RawPaymentBody any `json:"rawPaymentBody,omitempty" bson:"rawPaymentBody,omitempty"`
/*
Список адресов в формате host:port, куда будет отправляться платёж при успешной операции
Запрос будет отправляться по протоколу GRPC
*/
CallbackHostGRPC []string `json:"callbackHostGrpc" bson:"callbackHostGrpc"`
}
func (receiver *Payment) Sanitize() *Payment {
now := time.Now()
receiver.ID = ""
receiver.CreatedAt = now
receiver.UpdatedAt = now
receiver.DeletedAt = nil
receiver.IsDeleted = false
receiver.Completed = false
return receiver
}
type CreatePaymentResult struct {
RedirectURL string
Payment *Payment
}
type CreatePayment[T any] struct {
Type PaymentType
Currency string
Amount int64
CallbackHostGRPC []string
ReturnURL string
UserID string
ClientIP string
Requisites T
}
type BankCard struct {
Number string
ExpiryYear string
ExpiryMonth string
CSC *string
CardHolderName *string
}
type PaymentType string
const (
PaymentTypeBankCard PaymentType = "bankCard"
PaymentTypeTinkoff PaymentType = "tinkoffBank"
PaymentTypeSberPay PaymentType = "sberbank"
PaymentTypeYoomoney PaymentType = "yoomoney"
PaymentTypeMobile PaymentType = "mobile"
PaymentTypeSBP PaymentType = "sbp"
PaymentTypeSberB2B PaymentType = "b2bSberbank"
)
var (
YandexPaymentTypeMap = map[PaymentType]yandex.PaymentType{
PaymentTypeBankCard: yandex.PaymentTypeBankCard,
PaymentTypeTinkoff: yandex.PaymentTypeTinkoff,
PaymentTypeSberPay: yandex.PaymentTypeSberPay,
PaymentTypeYoomoney: yandex.PaymentTypeYoomoney,
PaymentTypeMobile: yandex.PaymentTypeMobile,
PaymentTypeSBP: yandex.PaymentTypeSBP,
PaymentTypeSberB2B: yandex.PaymentTypeSberB2B,
}
)