Skip to content

Commit

Permalink
Merge branch 'master' into definitionholder
Browse files Browse the repository at this point in the history
  • Loading branch information
TomK authored Dec 13, 2024
2 parents f19e537 + 64c0b86 commit 3740b29
Show file tree
Hide file tree
Showing 27 changed files with 607 additions and 150 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
env:
TEST_ENV: github
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.19
go-version: "1.22"

- name: Build
run: |
Expand Down
28 changes: 9 additions & 19 deletions connectorconfig/adyen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package connectorconfig

import (
"encoding/json"
"strings"

"github.com/chargehive/configuration/environment"
"github.com/chargehive/configuration/v1/connector"
Expand All @@ -17,13 +16,14 @@ const (
)

type AdyenCredentials struct {
Environment AdyenEnvironment `json:"environment" yaml:"environment" validate:"required,oneof=sandbox production"`
MerchantAccount string `json:"merchantAccount" yaml:"merchantAccount" validate:"required"`
ApiKey *string `json:"apiKey" yaml:"apiKey" validate:"required"`
ApiPrefix string `json:"apiPrefix" yaml:"apiPrefix" validate:"required"`
HMACKey *string `json:"hmacKey" yaml:"hmacKey" validate:"required"`
GooglePay *GooglePayCredentials `json:"googlePay,omitempty" yaml:"googlePay,omitempty"`
ApplePay *ApplePayCredentials `json:"applePay,omitempty" yaml:"applePay,omitempty"`
Environment AdyenEnvironment `json:"environment" yaml:"environment" validate:"required,oneof=sandbox production"`
MerchantAccount string `json:"merchantAccount" yaml:"merchantAccount" validate:"required"`
MerchantDescriptor string `json:"merchantDescriptor" yaml:"merchantDescriptor" validate:"-"`
ApiKey *string `json:"apiKey" yaml:"apiKey" validate:"required"`
ApiPrefix string `json:"apiPrefix" yaml:"apiPrefix" validate:"required"`
HMACKey *string `json:"hmacKey" yaml:"hmacKey" validate:"required"`
GooglePay *GooglePayCredentials `json:"googlePay,omitempty" yaml:"googlePay,omitempty"`
ApplePay *ApplePayCredentials `json:"applePay,omitempty" yaml:"applePay,omitempty"`
}

func (c *AdyenCredentials) GetMID() string {
Expand Down Expand Up @@ -67,18 +67,8 @@ func (c *AdyenCredentials) SupportsMethod(methodType chtype.PaymentMethodType, m
return true
}

var adyenAllowedCountires = []string{"AT", "AU", "BE", "CA", "CH", "CY", "CZ", "DE", "DK", "EE", "ES", "FI", "FR", "GB", "GR", "IE", "IT", "LI", "LT", "LU", "LV", "MC", "MT", "NL", "NO", "PL", "PT", "SE", "SI", "SK", "US"}

func (c *AdyenCredentials) SupportsCountry(country string) bool {
if country == "" {
return true
}
for _, v := range adyenAllowedCountires {
if strings.EqualFold(v, country) {
return true
}
}
return false
return true
}

func (c *AdyenCredentials) CanPlanModeUse(mode environment.Mode) bool {
Expand Down
19 changes: 10 additions & 9 deletions connectorconfig/braintree.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ const (

// https://articles.braintreepayments.com/control-panel/important-gateway-credentials
type BraintreeCredentials struct {
PublicKey *string `json:"publicKey" yaml:"publicKey" validate:"required,gt=0"`
PrivateKey *string `json:"privateKey" yaml:"privateKey" validate:"required,gt=0"`
MerchantID string `json:"merchantID" yaml:"merchantID" validate:"required"`
MerchantAccountID string `json:"merchantAccountID" yaml:"merchantAccountID" validate:"-"`
Currency string `json:"currency" yaml:"currency" validate:"oneof=AED AMD AOA ARS AUD AWG AZN BAM BBD BDT BGN BIF BMD BND BOB BRL BSD BWP BYN BZD CAD CHF CLP CNY COP CRC CVE CZK DJF DKK DOP DZD EGP ETB EUR FJD FKP GBP GEL GHS GIP GMD GNF GTQ GYD HKD HNL HRK HTG HUF IDR ILS INR ISK JMD JPY KES KGS KHR KMF KRW KYD KZT LAK LBP LKR LRD LSL LTL MAD MDL MKD MNT MOP MUR MVR MWK MXN MYR MZN NAD NGN NIO NOK NPR NZD PAB PEN PGK PHP PKR PLN PYG QAR RON RSD RUB RWF SAR SBD SCR SEK SGD SHP SLL SOS SRD STD SVC SYP SZL THB TJS TOP TRY TTD TWD TZS UAH UGX USD UYU UZS VES VND VUV WST XAF XCD XOF XPF YER ZAR ZMK ZWD"`
Environment BraintreeEnvironment `json:"environment" yaml:"environment" validate:"oneof=sandbox production"`
GooglePay *GooglePayCredentials `json:"googlePay,omitempty" yaml:"googlePay,omitempty"`
ApplePay *ApplePayCredentials `json:"applePay,omitempty" yaml:"applePay,omitempty"`
TokenizationKey string `json:"tokenizationKey,omitempty" yaml:"tokenizationKey,omitempty" validate:"required_with=GooglePayEmbedded ApplePay,omitempty,gt=0"`
PublicKey *string `json:"publicKey" yaml:"publicKey" validate:"required,gt=0"`
PrivateKey *string `json:"privateKey" yaml:"privateKey" validate:"required,gt=0"`
MerchantID string `json:"merchantID" yaml:"merchantID" validate:"required"`
MerchantAccountID string `json:"merchantAccountID" yaml:"merchantAccountID" validate:"-"`
MerchantDescriptor string `json:"merchantDescriptor" yaml:"merchantDescriptor" validate:"-"`
Currency string `json:"currency" yaml:"currency" validate:"oneof=AED AMD AOA ARS AUD AWG AZN BAM BBD BDT BGN BIF BMD BND BOB BRL BSD BWP BYN BZD CAD CHF CLP CNY COP CRC CVE CZK DJF DKK DOP DZD EGP ETB EUR FJD FKP GBP GEL GHS GIP GMD GNF GTQ GYD HKD HNL HRK HTG HUF IDR ILS INR ISK JMD JPY KES KGS KHR KMF KRW KYD KZT LAK LBP LKR LRD LSL LTL MAD MDL MKD MNT MOP MUR MVR MWK MXN MYR MZN NAD NGN NIO NOK NPR NZD PAB PEN PGK PHP PKR PLN PYG QAR RON RSD RUB RWF SAR SBD SCR SEK SGD SHP SLL SOS SRD STD SVC SYP SZL THB TJS TOP TRY TTD TWD TZS UAH UGX USD UYU UZS VES VND VUV WST XAF XCD XOF XPF YER ZAR ZMK ZWD"`
Environment BraintreeEnvironment `json:"environment" yaml:"environment" validate:"oneof=sandbox production"`
GooglePay *GooglePayCredentials `json:"googlePay,omitempty" yaml:"googlePay,omitempty"`
ApplePay *ApplePayCredentials `json:"applePay,omitempty" yaml:"applePay,omitempty"`
TokenizationKey string `json:"tokenizationKey,omitempty" yaml:"tokenizationKey,omitempty" validate:"required_with=GooglePayEmbedded ApplePay,omitempty,gt=0"`
}

func (c *BraintreeCredentials) GetMID() string {
Expand Down
1 change: 1 addition & 0 deletions connectorconfig/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type CheckoutCredentials struct {
Platform *string `json:"platform" yaml:"platform" validate:"required,oneof=default previous"`
ProcessingChannelID string `json:"processingChannelId" yaml:"processingChannelId"`
MerchantID string `json:"merchantID" yaml:"merchantID" validate:"required"`
MerchantDescriptor string `json:"merchantDescriptor" yaml:"merchantDescriptor" validate:"-"`
Currency string `json:"currency" yaml:"currency" validate:"oneof=AED AFN ALL AMD ANG AOA ARS AUD AWG AZN BAM BBD BDT BGN BHD BIF BMD BND BOB BRL BSD BTN BWP BYN BZD CAD CDF CHF CLF CLP CNY COP CRC CUP CVE CZK DJF DKK DOP DZD EEK EGP ERN ETB EUR FJD FKP GBP GEL GHS GIP GMD GNF GTQ GYD HKD HNL HRK HTG HUF IDR ILS INR IQD IRR ISK JMD JOD JPY KES KGS KHR KMF KPW KRW KWD KYD KZT LAK LBP LKR LRD LSL LTL LVL LYD MAD MDL MGA MKD MMK MNT MOP MRO MUR MVR MWK MXN MYR MZN NAD NGN NIO NOK NPR NZD OMR PAB PEN PGK PHP PKR PLN PYG QAR RON RSD RUB RWF SAR SBD SCR SDG SEK SGD SHP SLL SOS SRD STD SVC SYP SZL THB TJS TMT TND TOP TRY TTD TWD TZS UAH UGX USD UYU UZS VEF VND VUV WST XAF XCD XOF XPF YER ZAR ZMW ZWL"`
Environment CheckoutEnvironment `json:"environment" yaml:"environment" validate:"oneof=sandbox production"`
GooglePay *GooglePayCredentials `json:"googlePay,omitempty" yaml:"googlePay,omitempty"`
Expand Down
30 changes: 11 additions & 19 deletions connectorconfig/googlePay.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type GooglePayCredential interface {
GetGoogleCardAllowPrepaid() bool
GetGoogleCardAllowCredit() bool
GetGoogleCardBillingAddressReq() bool
GetGoogleCardBillingAddressFormat() GoogleCardBillingAddressFormat
GetGoogleCardBillingPhoneReq() bool
GetGoogleCardShippingAddressReq() bool
GetGoogleCardShippingPhoneReq() bool
Expand Down Expand Up @@ -62,7 +63,7 @@ type GooglePayCredentials struct {
// GoogleCardBillingPhoneReq (Card {parameters.billingAddressParameters.phoneNumberRequired) Set to true if a phone number is required to process the transaction.
GoogleCardBillingPhoneReq bool `json:"googleCardBillingPhoneReq,omitempty" yaml:"googleCardBillingPhoneReq,omitempty" validate:"-"`
// GoogleCardBillingAddressFormat (Card {parameters.billingAddressParameters.format) Billing address format required to complete the transaction.
GoogleCardBillingAddressFormat GoogleCardBillingAddressReq `json:"googleCardBillingAddressFormat,omitempty" yaml:"googleCardBillingAddressFormat,omitempty" validate:"required_with=GoogleMerchantId,omitempty,oneof=MIN FULL"`
GoogleCardBillingAddressFormat GoogleCardBillingAddressFormat `json:"googleCardBillingAddressFormat,omitempty" yaml:"googleCardBillingAddressFormat,omitempty" validate:"required_with=GoogleMerchantId,omitempty,oneof=MIN FULL"`
// GoogleCardTokenType (Card {tokenizationSpecification.type})
GoogleCardTokenType GoogleTokenType `json:"googleCardTokenType,omitempty" yaml:"googleCardTokenType,omitempty" validate:"required_with=GoogleMerchantId,omitempty,oneof=DIRECT PAYMENT_GATEWAY"`
// GoogleCardGateway (Card {tokenizationSpecification.parameters.gateway}) https://developers.google.com/pay/api/web/reference/request-objects#gateway
Expand All @@ -74,8 +75,6 @@ type GooglePayCredentials struct {
GoogleCardShippingAddressReq bool `json:"googleCardShippingAddressReq,omitempty" yaml:"googleCardShippingAddressReq,omitempty" validate:"-"`
// GoogleCardShippingPhoneReq Set to true if a phone number is required to process the transaction.
GoogleCardShippingPhoneReq bool `json:"googleCardShippingPhoneReq,omitempty" yaml:"googleCardShippingPhoneReq,omitempty" validate:"-"`
// GoogleCardShippingAddressFormat (Card {parameters.shippingAddressParameters.format) Shipping address format required to complete the transaction.
GoogleCardShippingAddressFormat GoogleCardBillingAddressReq `json:"googleCardShippingAddressFormat,omitempty" yaml:"googleCardShippingAddressFormat,omitempty" validate:"omitempty,oneof=MIN FULL"`

// GoogleAcquirerCountry The ISO 3166-1 alpha-2 country code where the transaction is processed. This property is required for merchants who process transactions in European Economic Area (EEA) countries and any other countries that are subject to Strong Customer Authentication (SCA). Merchants must specify the acquirer bank country code.
GoogleAcquirerCountry string `json:"googleAcquirerCountry,omitempty" yaml:"googleAcquirerCountry,omitempty" validate:"omitempty,oneof=AF AX AL DZ AS AD AO AI AQ AG AR AM AW AU AT AZ BS BH BD BB BY BE BZ BJ BM BT BO BQ BA BW BV BR IO BN BG BF BI KH CM CA CV KY CF TD CL CN CX CC CO KM CG CD CK CR CI HR CU CW CY CZ DK DJ DM DO EC EG SV GQ ER EE ET FK FO FJ FI FR GF PF TF GA GM GE DE GH GI GR GL GD GP GU GT GG GN GW GY HT HM HN HK HU IS IN ID IR IQ IE IM IL IT JM JP JE JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV ML MT MH MQ MR MU YT MX FM MD MC MN ME MS MA MZ MM NA NR NP NC NZ NI NE NG NU NF MP NO OM PK PW PS PA PG PY PE PH PN PL PT PR QA RE RO RU RW BL SH KN LC MF VC WS SM ST SA SN RS SC SL SG SX SK SI SB SO ZA GS SS ES LK PM SD SR SJ SZ SE CH SY TW TJ TZ TH NL TL TG TK TO TT TN TR TM TC TV UG UA AE GB US UM UY UZ VU VA VE VN VG VI WF EH YE ZM ZW"`
Expand Down Expand Up @@ -237,7 +236,7 @@ func (g *GooglePayCredentials) GetGoogleCardBillingAddressReq() bool {
}
return g.GoogleCardBillingAddressReq
}
func (g *GooglePayCredentials) GetGoogleCardBillingAddressFormat() GoogleCardBillingAddressReq {
func (g *GooglePayCredentials) GetGoogleCardBillingAddressFormat() GoogleCardBillingAddressFormat {
if g == nil {
return ""
}
Expand All @@ -256,13 +255,6 @@ func (g *GooglePayCredentials) GetGoogleCardShippingAddressReq() bool {
}
return g.GoogleCardShippingAddressReq
}
func (g *GooglePayCredentials) GetGoogleCardShippingAddressFormat() GoogleCardBillingAddressReq {
if g == nil {
return ""
}

return g.GoogleCardShippingAddressFormat
}
func (g *GooglePayCredentials) GetGoogleCardShippingPhoneReq() bool {
if g == nil {
return false
Expand Down Expand Up @@ -295,17 +287,17 @@ func (g *GooglePayCredentials) GetGoogleAcquirerCountry() string {
}

type (
GoogleEnvironment string
GoogleCardGateway string
GoogleCardAuthMethod string
GoogleTokenType string
GoogleCardNetwork string
GoogleCardBillingAddressReq string
GoogleEnvironment string
GoogleCardGateway string
GoogleCardAuthMethod string
GoogleTokenType string
GoogleCardNetwork string
GoogleCardBillingAddressFormat string
)

const (
GoogleCardBillingAddressReqMIN GoogleCardBillingAddressReq = "MIN" // Name, country code, and postal code (default).
GoogleCardBillingAddressReqFULL GoogleCardBillingAddressReq = "FULL" // Name, street address, locality, region, country code, and postal code.
GoogleCardBillingAddressReqMIN GoogleCardBillingAddressFormat = "MIN" // Name, country code, and postal code (default).
GoogleCardBillingAddressReqFULL GoogleCardBillingAddressFormat = "FULL" // Name, street address, locality, region, country code, and postal code.

GoogleEnvironmentTEST GoogleEnvironment = "TEST"
GoogleEnvironmentPROD GoogleEnvironment = "PRODUCTION"
Expand Down
2 changes: 1 addition & 1 deletion connectorconfig/gpayments.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (c *GPaymentsCredentials) GetLibrary() Library {
}

func (c *GPaymentsCredentials) GetSupportedTypes() []LibraryType {
return []LibraryType{LibraryTypePayment}
return []LibraryType{LibraryTypeAuthentication}
}

func (c *GPaymentsCredentials) Validate() error {
Expand Down
20 changes: 13 additions & 7 deletions connectorconfig/kount.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ const (
KountEnvironmentProduction KountEnvironment = "production"
)

type KountCustomData struct {
Key string `json:"key" yaml:"key" validate:"required"`
Value string `json:"value" yaml:"value"`
}

type KountCredentials struct {
SiteID string `json:"siteID" yaml:"siteID" validate:"required"`
MerchantID string `json:"merchantID" yaml:"merchantID" validate:"required"`
ConfigKey string `json:"configKey" yaml:"configKey" validate:"required"`
APIKey string `json:"apiKey" yaml:"apiKey" validate:"required"`
DataCollectorURL string `json:"dataCollectorURL" yaml:"dataCollectorURL" validate:"required"`
RiskInquiryServiceURL string `json:"riskInquiryServiceURL" yaml:"riskInquiryServiceURL" validate:"required"`
Environment KountEnvironment `json:"environment" yaml:"environment" validate:"oneof=test production"`
SiteID string `json:"siteID" yaml:"siteID" validate:"required"`
MerchantID string `json:"merchantID" yaml:"merchantID" validate:"required"`
ConfigKey string `json:"configKey" yaml:"configKey" validate:"required"`
APIKey string `json:"apiKey" yaml:"apiKey" validate:"required"`
DataCollectorURL string `json:"dataCollectorURL" yaml:"dataCollectorURL" validate:"required"`
RiskInquiryServiceURL string `json:"riskInquiryServiceURL" yaml:"riskInquiryServiceURL" validate:"required"`
Environment KountEnvironment `json:"environment" yaml:"environment" validate:"oneof=test production"`
DefaultCustomData []KountCustomData `json:"defaultCustomData" yaml:"defaultCustomData"`
}

func (c *KountCredentials) GetMID() string {
Expand Down
20 changes: 18 additions & 2 deletions connectorconfig/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ const (
LibraryMaxMind Library = "maxmind"
LibraryCyberSource Library = "cybersource"
LibraryKount Library = "kount"
LibraryRecaptcha Library = "recaptcha"

// Updater Libraries
LibraryPaySafeAccountUpdater Library = "paysafe-accountupdater"
LibraryTokenExAccountUpdater Library = "tokenex-accountupdater"
LibraryPaySafeAccountUpdater Library = "paysafe-accountupdater"
LibraryTokenExAccountUpdater Library = "tokenex-accountupdater"
LibraryTokenExApiAccountUpdater Library = "tokenex-api-accountupdater"

// Scheduler Libraries
LibraryStickyIO Library = "sticky-io"
Expand Down Expand Up @@ -265,6 +267,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 Expand Up @@ -337,6 +346,13 @@ var LibraryRegister = map[Library]LibraryDef{
return methodType == chtype.PAYMENT_METHOD_TYPE_CARD
},
},
LibraryTokenExApiAccountUpdater: {
DisplayName: "TokenEx API Account Updater",
Credentials: func() Credentials { return &TokenExApiAccountUpdaterCredentials{} },
SupportsMethod: func(methodType chtype.PaymentMethodType, methodProvider chtype.PaymentMethodProvider) bool {
return methodType == chtype.PAYMENT_METHOD_TYPE_CARD
},
},
LibraryTokenExNetworkTokenization: {
DisplayName: "TokenEx Network Tokenization",
Credentials: func() Credentials { return &TokenExNetworkTokenizationCredentials{} },
Expand Down
1 change: 1 addition & 0 deletions connectorconfig/paysafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
type PaySafeCredentials struct {
Acquirer string `json:"acquirer" yaml:"acquirer" validate:"-"`
MerchantURL string `json:"merchantURL" yaml:"merchantURL" validate:"required"`
MerchantDescriptor string `json:"merchantDescriptor" yaml:"merchantDescriptor" validate:"-"`
AccountID string `json:"accountID" yaml:"accountID" validate:"required"`
APIUsername *string `json:"apiUsername" yaml:"apiUsername" validate:"required,gt=0"`
APIPassword *string `json:"apiPassword" yaml:"apiPassword" validate:"required,gt=0"`
Expand Down
74 changes: 74 additions & 0 deletions connectorconfig/recaptcha.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package connectorconfig

import (
"encoding/json"

"github.com/chargehive/configuration/environment"
"github.com/chargehive/configuration/v1/connector"
"github.com/chargehive/proto/golang/chargehive/chtype"
)

type RecaptchaSuggestionRange struct {
Min float32 `json:"min" yaml:"min" validate:"required"`
Max float32 `json:"max" yaml:"max" validate:"required"`
Action string `json:"action" yaml:"action" validate:"required, oneof=review allow deny"`
}

type RecaptchaCredentials struct {
SiteKey string `json:"siteKey" yaml:"siteKey" validate:"required"`
ProjectID string `json:"projectId" yaml:"projectId" validate:"required"`
Suggestions []RecaptchaSuggestionRange `json:"suggestions" yaml:"suggestions"`
}

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
}
File renamed without changes.
Loading

0 comments on commit 3740b29

Please sign in to comment.