75 lines
1.2 KiB
Go
75 lines
1.2 KiB
Go
package orm
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
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 Payout struct {
|
|
gorm.Model
|
|
|
|
UserID uint
|
|
User User
|
|
|
|
Description string
|
|
IdempotenceKey string
|
|
PayoutID string
|
|
Type string
|
|
AccountNumber string
|
|
Amount float32
|
|
Currency string
|
|
Status PayoutStatus
|
|
Test bool
|
|
}
|