Skip to content

Commit

Permalink
Recaptcha Fraud Connector (#207)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
TomK authored Aug 30, 2024
1 parent 3189ca0 commit 17ad02c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
8 changes: 8 additions & 0 deletions connectorconfig/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
LibraryMaxMind Library = "maxmind"
LibraryCyberSource Library = "cybersource"
LibraryKount Library = "kount"
LibraryRecaptcha Library = "recaptcha"

// Updater Libraries
LibraryPaySafeAccountUpdater Library = "paysafe-accountupdater"
Expand Down Expand Up @@ -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{} },
Expand Down
68 changes: 68 additions & 0 deletions connectorconfig/recaptcha.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion v1/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 17ad02c

Please sign in to comment.