+address book service
Some checks failed
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
ci/woodpecker/push/bump_version Pipeline failed
Some checks failed
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
ci/woodpecker/push/bump_version Pipeline failed
This commit is contained in:
25
api/pkg/model/card.go
Normal file
25
api/pkg/model/card.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
type CardPaymentData struct {
|
||||
Pan string `bson:"pan" json:"pan"`
|
||||
FirstName string `bson:"firstName" json:"firstName"`
|
||||
LastName string `bson:"lastName" json:"lastName"`
|
||||
}
|
||||
|
||||
func (m *PaymentMethod) AsCard() (*CardPaymentData, error) {
|
||||
if m.Type != PaymentTypeCard {
|
||||
return nil, merrors.InvalidArgument(fmt.Sprintf("payment method type is %s, not card", m.Type), "type")
|
||||
}
|
||||
var d CardPaymentData
|
||||
if err := bson.Unmarshal(m.Data, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &d, nil
|
||||
}
|
||||
26
api/pkg/model/iban.go
Normal file
26
api/pkg/model/iban.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
type IbanPaymentData struct {
|
||||
Iban string `bson:"iban" json:"iban"`
|
||||
AccountHolder string `bson:"accountHolder" json:"accountHolder"`
|
||||
Bic *string `bson:"bic,omitempty" json:"bic,omitempty"`
|
||||
BankName *string `bson:"bankName,omitempty" json:"bankName,omitempty"`
|
||||
}
|
||||
|
||||
func (m *PaymentMethod) AsIban() (*IbanPaymentData, error) {
|
||||
if m.Type != PaymentTypeIban {
|
||||
return nil, merrors.InvalidArgument(fmt.Sprintf("payment method type is %s, not iban", m.Type), "type")
|
||||
}
|
||||
var d IbanPaymentData
|
||||
if err := bson.Unmarshal(m.Data, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &d, nil
|
||||
}
|
||||
66
api/pkg/model/payment.go
Normal file
66
api/pkg/model/payment.go
Normal file
@@ -0,0 +1,66 @@
|
||||
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
|
||||
)
|
||||
|
||||
var paymentTypeToString = map[PaymentType]string{
|
||||
PaymentTypeIban: "iban",
|
||||
PaymentTypeCard: "card",
|
||||
PaymentTypeBankAccount: "bankAccount",
|
||||
PaymentTypeWallet: "wallet",
|
||||
}
|
||||
|
||||
var paymentTypeFromString = map[string]PaymentType{
|
||||
"iban": PaymentTypeIban,
|
||||
"card": PaymentTypeCard,
|
||||
"bankAccount": PaymentTypeBankAccount,
|
||||
"wallet": PaymentTypeWallet,
|
||||
}
|
||||
|
||||
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"`
|
||||
IsActive bool `bson:"isActive" json:"isActive"`
|
||||
Data bson.Raw `bson:"data" json:"data"`
|
||||
}
|
||||
31
api/pkg/model/rba.go
Normal file
31
api/pkg/model/rba.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
type RussianBankAccountPaymentData struct {
|
||||
RecipientName string `bson:"recipientName" json:"recipientName"`
|
||||
Inn string `bson:"inn" json:"inn"`
|
||||
Kpp string `bson:"kpp" json:"kpp"`
|
||||
BankName string `bson:"bankName" json:"bankName"`
|
||||
Bik string `bson:"bik" json:"bik"`
|
||||
AccountNumber string `bson:"accountNumber" json:"accountNumber"`
|
||||
CorrespondentAccount string `bson:"correspondentAccount" json:"correspondentAccount"`
|
||||
}
|
||||
|
||||
func (m *PaymentMethod) AsRussianBankAccount() (*RussianBankAccountPaymentData, error) {
|
||||
if m.Type != PaymentTypeBankAccount {
|
||||
return nil, merrors.InvalidArgument(fmt.Sprintf("payment method type is %s, not bankAccount", m.Type), "type")
|
||||
}
|
||||
|
||||
var d RussianBankAccountPaymentData
|
||||
if err := bson.Unmarshal(m.Data, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &d, nil
|
||||
}
|
||||
106
api/pkg/model/recipient.go
Normal file
106
api/pkg/model/recipient.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
)
|
||||
|
||||
type RecipientStatus int
|
||||
|
||||
const (
|
||||
RecipientStatusReady RecipientStatus = iota
|
||||
RecipientStatusRegistered
|
||||
RecipientStatusNotRegistered
|
||||
)
|
||||
|
||||
var recipientStatusToString = map[RecipientStatus]string{
|
||||
RecipientStatusReady: "ready",
|
||||
RecipientStatusRegistered: "registered",
|
||||
RecipientStatusNotRegistered: "notRegistered",
|
||||
}
|
||||
|
||||
var recipientStatusFromString = map[string]RecipientStatus{
|
||||
"ready": RecipientStatusReady,
|
||||
"registered": RecipientStatusRegistered,
|
||||
"notRegistered": RecipientStatusNotRegistered,
|
||||
}
|
||||
|
||||
func (s RecipientStatus) String() string {
|
||||
if v, ok := recipientStatusToString[s]; ok {
|
||||
return v
|
||||
}
|
||||
return "ready" // дефолт, можно поменять
|
||||
}
|
||||
|
||||
// JSON: храним как строку ("ready" / "registered" / "notRegistered")
|
||||
func (s RecipientStatus) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(s.String())
|
||||
}
|
||||
|
||||
func (s *RecipientStatus) UnmarshalJSON(data []byte) error {
|
||||
var val string
|
||||
if err := json.Unmarshal(data, &val); err != nil {
|
||||
return err
|
||||
}
|
||||
v, ok := recipientStatusFromString[val]
|
||||
if !ok {
|
||||
return merrors.InvalidArgument(fmt.Sprintf("unknown RecipientStatus: %q", val))
|
||||
}
|
||||
*s = v
|
||||
return nil
|
||||
}
|
||||
|
||||
// RecipientType { internal, external }
|
||||
|
||||
type RecipientType int
|
||||
|
||||
const (
|
||||
RecipientTypeInternal RecipientType = iota
|
||||
RecipientTypeExternal
|
||||
)
|
||||
|
||||
var recipientTypeToString = map[RecipientType]string{
|
||||
RecipientTypeInternal: "internal",
|
||||
RecipientTypeExternal: "external",
|
||||
}
|
||||
|
||||
var recipientTypeFromString = map[string]RecipientType{
|
||||
"internal": RecipientTypeInternal,
|
||||
"external": RecipientTypeExternal,
|
||||
}
|
||||
|
||||
func (t RecipientType) String() string {
|
||||
if v, ok := recipientTypeToString[t]; ok {
|
||||
return v
|
||||
}
|
||||
return "internal"
|
||||
}
|
||||
|
||||
func (t RecipientType) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(t.String())
|
||||
}
|
||||
|
||||
func (t *RecipientType) UnmarshalJSON(data []byte) error {
|
||||
var val string
|
||||
if err := json.Unmarshal(data, &val); err != nil {
|
||||
return err
|
||||
}
|
||||
v, ok := recipientTypeFromString[val]
|
||||
if !ok {
|
||||
return merrors.InvalidArgument(fmt.Sprintf("unknown RecipientType: %q", val))
|
||||
}
|
||||
*t = v
|
||||
return nil
|
||||
}
|
||||
|
||||
type Recipient struct {
|
||||
PermissionBound `bson:",inline" json:",inline"`
|
||||
Describable `bson:",inline" json:",inline"`
|
||||
Email string `bson:"email" json:"email"`
|
||||
AvatarURL *string `bson:"avatarUrl,omitempty" json:"avatarUrl,omitempty"`
|
||||
|
||||
Status RecipientStatus `bson:"status" json:"status"`
|
||||
Type RecipientType `bson:"type" json:"type"`
|
||||
}
|
||||
25
api/pkg/model/wallet.go
Normal file
25
api/pkg/model/wallet.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
type WalletPaymentData struct {
|
||||
WalletID string `bson:"walletId" json:"walletId"`
|
||||
}
|
||||
|
||||
func (m *PaymentMethod) AsWallet() (*WalletPaymentData, error) {
|
||||
if m.Type != PaymentTypeWallet {
|
||||
return nil, merrors.InvalidArgument(fmt.Sprintf("payment method type is %s, not wallet", m.Type), "type")
|
||||
}
|
||||
|
||||
var d WalletPaymentData
|
||||
if err := bson.Unmarshal(m.Data, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &d, nil
|
||||
}
|
||||
Reference in New Issue
Block a user