All checks were successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/tech/sendico/pkg/merrors"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
type PaymentType int
|
|
|
|
const (
|
|
PaymentTypeIban PaymentType = iota
|
|
PaymentTypeCard
|
|
PaymentTypeBankAccount
|
|
PaymentTypeWallet
|
|
PaymentTypeCryptoAddress
|
|
)
|
|
|
|
var paymentTypeToString = map[PaymentType]string{
|
|
PaymentTypeIban: "iban",
|
|
PaymentTypeCard: "card",
|
|
PaymentTypeBankAccount: "bankAccount",
|
|
PaymentTypeWallet: "wallet",
|
|
PaymentTypeCryptoAddress: "cryptoAddress",
|
|
}
|
|
|
|
var paymentTypeFromString = map[string]PaymentType{
|
|
"iban": PaymentTypeIban,
|
|
"card": PaymentTypeCard,
|
|
"bankAccount": PaymentTypeBankAccount,
|
|
"wallet": PaymentTypeWallet,
|
|
"cryptoAddress": PaymentTypeCryptoAddress,
|
|
}
|
|
|
|
func (t PaymentType) String() string {
|
|
if v, ok := paymentTypeToString[t]; ok {
|
|
return v
|
|
}
|
|
return "iban"
|
|
}
|
|
|
|
func (t PaymentType) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(t.String())
|
|
}
|
|
|
|
func (t *PaymentType) UnmarshalJSON(data []byte) error {
|
|
var val string
|
|
if err := json.Unmarshal(data, &val); err != nil {
|
|
return err
|
|
}
|
|
v, ok := paymentTypeFromString[val]
|
|
if !ok {
|
|
return merrors.InvalidArgument(fmt.Sprintf("unknown PaymentType: %q", val))
|
|
}
|
|
*t = v
|
|
return nil
|
|
}
|
|
|
|
type PaymentMethod struct {
|
|
PermissionBound `bson:",inline" json:",inline"`
|
|
|
|
RecipientRef primitive.ObjectID `bson:"recipientRef" json:"recipientRef"`
|
|
Type PaymentType `bson:"type" json:"type"`
|
|
Data bson.Raw `bson:"data" json:"data"`
|
|
}
|