Files
payouts/internal/models/payout.go
2026-03-19 00:09:25 +03:00

108 lines
1.9 KiB
Go

package models
import (
"fmt"
"strings"
)
type PayoutType int64
const (
TypeSBP PayoutType = iota
TypeYooMoney
)
func (r PayoutType) String() string {
switch r {
case TypeSBP:
return "spb"
case TypeYooMoney:
return "yoo_money"
}
return "unknown"
}
func (r PayoutType) MarshalText() (text []byte, err error) {
return []byte(r.String()), nil
}
func (r *PayoutType) UnmarshalText(text []byte) (err error) {
s := strings.ToLower(string(text))
switch s {
case "spb":
*r = TypeSBP
case "yoo_money":
*r = TypeYooMoney
default:
err = fmt.Errorf("invalid payment type: %s", s)
}
return err
}
type PayoutStatus int64
const (
StatusCreated PayoutStatus = iota
StatusCanceled
StatusPending
StatusSucceeded
StatusFailed
)
func (r PayoutStatus) String() string {
switch r {
case StatusCreated:
return "created"
case StatusCanceled:
return "canceled"
case StatusPending:
return "pending"
case StatusSucceeded:
return "succeeded"
case StatusFailed:
return "failed"
}
return "unknown"
}
func (r PayoutStatus) MarshalText() (text []byte, err error) {
return []byte(r.String()), nil
}
func (r *PayoutStatus) UnmarshalText(text []byte) (err error) {
s := strings.ToLower(string(text))
switch s {
case "canceled":
*r = StatusCanceled
case "created":
*r = StatusCreated
case "pending":
*r = StatusPending
case "succeeded":
*r = StatusSucceeded
case "failed":
*r = StatusFailed
default:
err = fmt.Errorf("invalid payment type: %s", s)
}
return err
}
type SBPBank struct {
BankID string `json:"bank_id"`
Name string `json:"name"`
Bic string `json:"bic"`
}
type PayoutReq struct {
PayoutType PayoutType `json:"payout_type"`
AccountNumber string `json:"account_number"`
BankID string `json:"bank_id"`
Amount float32 `json:"amount"`
}
type PayoutResp struct {
ID string `json:"payout_id,omitempty"`
Status PayoutStatus `json:"payout_status,omitempty"`
}