30 lines
849 B
Go
30 lines
849 B
Go
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"`
|
|
ExpMonth string `bson:"expMonth" json:"expMonth"`
|
|
ExpYear string `bson:"expYear" json:"expYear"`
|
|
Network string `bson:"network,omitempty" json:"network,omitempty"`
|
|
Country string `bson:"country,omitempty" json:"country,omitempty"`
|
|
}
|
|
|
|
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
|
|
}
|