From 17ad02cce357d69f61aa942e5a6e3a3bc260f68b Mon Sep 17 00:00:00 2001 From: Tom Kay Date: Fri, 30 Aug 2024 13:05:05 +0100 Subject: [PATCH] Recaptcha Fraud Connector (#207) * add Recaptcha policy * remove unused consts * rename to secretKey * set spec version to v1 * update field * update type * include clientKey * rename to SiteKey * fix tags * replace with fraud connector * add recaptcha to library register * add recaptcha to library validation * remove secret key as secure field, it's needed in assemble * remove required validation. allows omitting threshold (or setting it to zero) to permit all traffic --- connectorconfig/library.go | 8 +++++ connectorconfig/recaptcha.go | 68 ++++++++++++++++++++++++++++++++++++ v1/connector/connector.go | 2 +- 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 connectorconfig/recaptcha.go diff --git a/connectorconfig/library.go b/connectorconfig/library.go index 9c64891..fcce0ab 100644 --- a/connectorconfig/library.go +++ b/connectorconfig/library.go @@ -49,6 +49,7 @@ const ( LibraryMaxMind Library = "maxmind" LibraryCyberSource Library = "cybersource" LibraryKount Library = "kount" + LibraryRecaptcha Library = "recaptcha" // Updater Libraries LibraryPaySafeAccountUpdater Library = "paysafe-accountupdater" @@ -265,6 +266,13 @@ var LibraryRegister = map[Library]LibraryDef{ return methodType == chtype.PAYMENT_METHOD_TYPE_CARD }, }, + LibraryRecaptcha: { + DisplayName: "Recaptcha", + Credentials: func() Credentials { return &RecaptchaCredentials{} }, + SupportsMethod: func(methodType chtype.PaymentMethodType, methodProvider chtype.PaymentMethodProvider) bool { + return true + }, + }, LibraryClearhaus: { DisplayName: "Clearhaus", Credentials: func() Credentials { return &ClearhausCredentials{} }, diff --git a/connectorconfig/recaptcha.go b/connectorconfig/recaptcha.go new file mode 100644 index 0000000..84c2577 --- /dev/null +++ b/connectorconfig/recaptcha.go @@ -0,0 +1,68 @@ +package connectorconfig + +import ( + "encoding/json" + + "github.com/chargehive/configuration/environment" + "github.com/chargehive/configuration/v1/connector" + "github.com/chargehive/proto/golang/chargehive/chtype" +) + +type RecaptchaCredentials struct { + SiteKey string `json:"siteKey" yaml:"siteKey" validate:"required"` + SecretKey string `json:"secretKey" yaml:"secretKey" validate:"required"` + BlockThreshold float32 `json:"blockThreshold" yaml:"blockThreshold" validate:"min=0,max=1"` +} + +func (c *RecaptchaCredentials) GetLibrary() Library { + return LibraryRecaptcha +} + +func (c *RecaptchaCredentials) GetSupportedTypes() []LibraryType { + return []LibraryType{LibraryTypeFraud} +} + +func (c *RecaptchaCredentials) Validate() error { + return nil +} + +func (c *RecaptchaCredentials) GetSecureFields() []*string { + return []*string{} +} + +func (c *RecaptchaCredentials) ToConnector() connector.Connector { + con := connector.Connector{Library: string(c.GetLibrary())} + con.Configuration, _ = json.Marshal(c) + return con +} + +func (c *RecaptchaCredentials) FromJson(input []byte) error { + return json.Unmarshal(input, c) +} + +func (c *RecaptchaCredentials) SupportsSca() bool { + return true +} + +func (c *RecaptchaCredentials) SupportsMethod(methodType chtype.PaymentMethodType, methodProvider chtype.PaymentMethodProvider) bool { + if !c.GetLibrary().SupportsMethod(methodType, methodProvider) { + return false + } + return true +} + +func (c *RecaptchaCredentials) SupportsCountry(country string) bool { + return true +} + +func (c *RecaptchaCredentials) CanPlanModeUse(mode environment.Mode) bool { + return true +} + +func (c *RecaptchaCredentials) IsRecoveryAgent() bool { + return false +} + +func (c *RecaptchaCredentials) Supports3RI() bool { + return false +} diff --git a/v1/connector/connector.go b/v1/connector/connector.go index 7ac958c..28b53f7 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=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"` + Library string `json:"library" yaml:"library" validate:"omitempty,oneof=recaptcha 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"`