diff --git a/connectorconfig/flexpay.go b/connectorconfig/flexpay.go new file mode 100644 index 0000000..9693c3e --- /dev/null +++ b/connectorconfig/flexpay.go @@ -0,0 +1,81 @@ +package connectorconfig + +import ( + "encoding/json" + + "github.com/chargehive/configuration/environment" + "github.com/chargehive/configuration/v1/connector" + "github.com/chargehive/proto/golang/chargehive/chtype" +) + +type FlexPayEnvironment string + +const ( + FlexPayEnvironmentSandbox FlexPayEnvironment = "sandbox" + FlexPayEnvironmentProduction FlexPayEnvironment = "production" +) + +type FlexPayCredentials struct { + ApiKey *string `json:"apiKey" yaml:"apiKey" validate:"required"` + Environment FlexPayEnvironment `json:"environment" yaml:"environment" validate:"oneof=sandbox production"` +} + +func (c *FlexPayCredentials) GetMID() string { + return *c.ApiKey +} + +func (c *FlexPayCredentials) GetLibrary() Library { + return LibraryFlexPay +} + +func (c *FlexPayCredentials) GetSupportedTypes() []LibraryType { + return []LibraryType{LibraryTypeRecoveryAgent} +} + +func (c *FlexPayCredentials) Validate() error { + return nil +} + +func (c *FlexPayCredentials) GetSecureFields() []*string { + return []*string{c.ApiKey} +} + +func (c *FlexPayCredentials) ToConnector() connector.Connector { + con := connector.Connector{Library: string(c.GetLibrary())} + con.Configuration, _ = json.Marshal(c) + return con +} + +func (c *FlexPayCredentials) FromJson(input []byte) error { + return json.Unmarshal(input, c) +} + +func (c *FlexPayCredentials) SupportsSca() bool { + return false +} + +func (c *FlexPayCredentials) SupportsMethod(methodType chtype.PaymentMethodType, methodProvider chtype.PaymentMethodProvider) bool { + if !c.GetLibrary().SupportsMethod(methodType, methodProvider) { + return false + } + return true +} + +func (c *FlexPayCredentials) SupportsCountry(country string) bool { + return true +} + +func (c *FlexPayCredentials) CanPlanModeUse(mode environment.Mode) bool { + if mode == environment.ModeSandbox && c.Environment == FlexPayEnvironmentProduction { + return false + } + return true +} + +func (c *FlexPayCredentials) IsRecoveryAgent() bool { + return true +} + +func (c *FlexPayCredentials) Supports3RI() bool { + return false +} diff --git a/connectorconfig/library.go b/connectorconfig/library.go index 297f624..9c64891 100644 --- a/connectorconfig/library.go +++ b/connectorconfig/library.go @@ -42,6 +42,7 @@ const ( LibraryNuvei Library = "nuvei" LibraryGPayments Library = "gpayments" LibrarySandbanx Library = "sandbanx" + LibraryFlexPay Library = "flexpay" // Fraud Libraries LibraryChargeHive Library = "chargehive" @@ -351,4 +352,11 @@ var LibraryRegister = map[Library]LibraryDef{ return methodType == chtype.PAYMENT_METHOD_TYPE_CARD }, }, + LibraryFlexPay: { + DisplayName: "FlexPay", + Credentials: func() Credentials { return &FlexPayCredentials{} }, + SupportsMethod: func(methodType chtype.PaymentMethodType, methodProvider chtype.PaymentMethodProvider) bool { + return methodType == chtype.PAYMENT_METHOD_TYPE_CARD + }, + }, } diff --git a/utils/generate.go b/utils/generate.go index 3d8269a..af04d80 100644 --- a/utils/generate.go +++ b/utils/generate.go @@ -42,6 +42,7 @@ const ( confConnYapstone Template = "con_yapstone" confConnTokenEx Template = "con_tokenex" confConnTokenExNT Template = "con_tokenex_network_tokenization" + confConnFlexPay Template = "con_flexpay" // connector Pool confConnectorPool Template = "con_pool" @@ -88,6 +89,7 @@ var Templates = map[Template]string{ confConnVindicia: "Connector: Vindicia", confConnWorldPay: "Connector: Worldpay", confConnYapstone: "Connector: Yapstone", + confConnFlexPay: "Connector: FlexPay", confIntSlack: "Integration: Slack", confPolCascade: "Policy: Cascade", confPolChargeExpiry: "Policy: Charge Expiry", @@ -334,6 +336,12 @@ func buildSpec(conf Template) (object.Specification, error) { APIKey: &chg, }) return connector.Connector{Library: string(connectorconfig.LibraryTokenExNetworkTokenization), Configuration: j}, nil + case confConnFlexPay: + j, _ := json.Marshal(connectorconfig.FlexPayCredentials{ + Environment: connectorconfig.FlexPayEnvironmentSandbox, + ApiKey: &chg, + }) + return connector.Connector{Library: string(connectorconfig.LibraryFlexPay), Configuration: j}, nil case confConnectorPool: return connector.Pool{Restriction: "unrestricted", Connectors: []connector.PoolItem{{ConnectorID: chg}}}, nil case confIntSlack: diff --git a/v1/connector/connector.go b/v1/connector/connector.go index 156ec1a..7ac958c 100644 --- a/v1/connector/connector.go +++ b/v1/connector/connector.go @@ -25,7 +25,7 @@ const ( // Connector is a configuration file for a single payment processing entity type Connector struct { ProcessingState ProcessingState `json:"processingState,omitempty" yaml:"processingState,omitempty"` - Library string `json:"library" yaml:"library" validate:"omitempty,oneof=adyen bluesnap gpayments nuvei inoviopay threedsecureio sandbox sandbanx applepay authorize braintree qualpay stripe paysafe worldpay paypal-websitepaymentspro paypal-expresscheckout vindicia maxmind cybersource paysafe-accountupdater bottomline checkout kount clearhaus trust-payments cwams yapstone tokenex-accountupdater tokenex-networktokenization sticky-io googlepay"` + Library string `json:"library" yaml:"library" validate:"omitempty,oneof=flexpay adyen bluesnap gpayments nuvei inoviopay threedsecureio sandbox sandbanx applepay authorize braintree qualpay stripe paysafe worldpay paypal-websitepaymentspro paypal-expresscheckout vindicia maxmind cybersource paysafe-accountupdater bottomline checkout kount clearhaus trust-payments cwams yapstone tokenex-accountupdater tokenex-networktokenization sticky-io googlepay"` Configuration []byte `json:"configuration" yaml:"configuration" validate:"required"` ConfigID string `json:"configId,omitempty" yaml:"configId,omitempty"` ConfigAuth string `json:"configAuth,omitempty" yaml:"configAuth,omitempty"`