package model import ( "fmt" "git.sendico.io/tech/sxchnge/bff/pkg/merrors" "git.sendico.io/tech/sxchnge/bff/pkg/person" "go.mongodb.org/mongo-driver/v2/bson" ) type RussianBankAccountPaymentData struct { Recipient person.Name `bson:"recipient" json:"recipient"` 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"` } // UnmarshalBSON accepts both stored recipient names and the API names in the // intermediate document built by a payment-method PATCH. func (d *RussianBankAccountPaymentData) UnmarshalBSON(data []byte) error { type stored RussianBankAccountPaymentData var decoded stored if err := bson.Unmarshal(data, &decoded); err != nil { return err } var fields struct { Recipient map[string]any `bson:"recipient"` } if err := bson.Unmarshal(data, &fields); err != nil { return err } decoded.Recipient.FirstName = firstPaymentDataString(fields.Recipient, "firstName", "first_name") decoded.Recipient.LastName = firstPaymentDataString(fields.Recipient, "lastName", "last_name") *d = RussianBankAccountPaymentData(decoded) return nil } 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 }