Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adyen #170

Merged
merged 7 commits into from
Feb 21, 2024
Merged

Adyen #170

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions connectorconfig/adyen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package connectorconfig

import (
"encoding/json"
"strings"

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

type AdyenEnvironment string

const (
AdyenEnvironmentSandbox AdyenEnvironment = "sandbox"
AdyenEnvironmentProduction AdyenEnvironment = "production"
)

type AdyenCredentials struct {
Environment AdyenEnvironment `json:"environment" yaml:"environment" validate:"required,oneof=sandbox production"`
MID string `json:"mid" yaml:"mid" validate:"required"`
}

func (c *AdyenCredentials) GetMID() string {
return c.MID
}

func (c *AdyenCredentials) GetLibrary() Library {
return LibraryAdyen
}

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

func (c *AdyenCredentials) GetSecureFields() []*string {
return nil
}

func (c *AdyenCredentials) Validate() error {
return nil
}

func (c *AdyenCredentials) ToConnector() connector.Connector {
con := connector.Connector{Library: string(c.GetLibrary())}
con.Configuration, _ = json.Marshal(c)
return con
}

func (c *AdyenCredentials) FromJson(input []byte) error {
return json.Unmarshal(input, c)
}

func (c *AdyenCredentials) SupportsSca() bool {
return false
}

func (c *AdyenCredentials) SupportsMethod(methodType chtype.PaymentMethodType, methodProvider chtype.PaymentMethodProvider) bool {
if !c.GetLibrary().SupportsMethod(methodType, methodProvider) {
return false
}
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
}

func (c *AdyenCredentials) CanPlanModeUse(mode environment.Mode) bool {

if mode == environment.ModeSandbox && c.Environment == AdyenEnvironmentSandbox {
return true
}

if mode == environment.ModeProduction && c.Environment == AdyenEnvironmentProduction {
return true
}

return false
}

func (c *AdyenCredentials) IsRecoveryAgent() bool {
return false
}
3 changes: 3 additions & 0 deletions connectorconfig/bluesnap.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (c *BlueSnapCredentials) SupportsMethod(methodType chtype.PaymentMethodType
var blueSnapAllowedCountires = []string{"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", "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", "hr", "cw", "cy", "cz", "dk", "dj", "dm", "do", "tl", "ec", "eg", "sv", "gq", "er", "ee", "et", "fk", "fo", "fj", "fi", "fr", "gf", "tf", "ga", "gm", "ge", "de", "gh", "gi", "gb", "gr", "gl", "gd", "gp", "gu", "gt", "gg", "gn", "gw", "gy", "ht", "hm", "va", "hn", "hk", "hu", "is", "in", "id", "ie", "im", "il", "it", "ci", "jm", "jp", "je", "jo", "kz", "ke", "ki", "kw", "kg", "la", "lv", "ls", "lr", "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", "na", "nr", "np", "nl", "nc", "nz", "ni", "ne", "ng", "nu", "nf", "mp", "no", "om", "pk", "pw", "ps", "pa", "pg", "py", "pe", "ph", "pn", "pl", "pf", "pt", "pr", "qa", "re", "ro", "ru", "rw", "gs", "sh", "kn", "lc", "mf", "pm", "st", "vc", "ws", "sm", "sa", "sn", "rs", "sc", "sl", "sg", "sx", "sk", "si", "sb", "so", "za", "kr", "es", "lk", "sr", "sj", "sz", "se", "ch", "tj", "tw", "tz", "th", "tg", "tk", "to", "tt", "tn", "tr", "tm", "tc", "tv", "ug", "ua", "ae", "gb", "us", "uy", "uz", "vu", "ve", "vn", "vg", "vi", "wf", "eh", "zm", "zw"}

func (c *BlueSnapCredentials) SupportsCountry(country string) bool {
if country == "" {
return true
}
for _, v := range blueSnapAllowedCountires {
if strings.EqualFold(v, country) {
return true
Expand Down
8 changes: 8 additions & 0 deletions connectorconfig/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Library string
const (
// Payment Libraries
LibrarySandbox Library = "sandbox" // Connector for testing Charge hive
LibraryAdyen Library = "adyen"
LibraryApplePay Library = "applepay"
LibraryAuthorize Library = "authorize"
LibraryBraintree Library = "braintree"
Expand Down Expand Up @@ -99,6 +100,13 @@ var LibraryRegister = map[Library]LibraryDef{
return methodType == chtype.PAYMENT_METHOD_TYPE_CARD
},
},
LibraryAdyen: {
DisplayName: "Adyen",
Credentials: func() Credentials { return &AdyenCredentials{} },
SupportsMethod: func(methodType chtype.PaymentMethodType, methodProvider chtype.PaymentMethodProvider) bool {
return methodType == chtype.PAYMENT_METHOD_TYPE_CARD
},
},
LibraryApplePay: {
DisplayName: "ApplePay",
Credentials: func() Credentials { return &ApplePayCredentials{} },
Expand Down
6 changes: 5 additions & 1 deletion connectorconfig/paysafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package connectorconfig

import (
"encoding/json"
"strings"

"github.com/chargehive/configuration/environment"
"github.com/chargehive/configuration/v1/connector"
Expand Down Expand Up @@ -116,8 +117,11 @@ func (c *PaySafeCredentials) SupportsMethod(methodType chtype.PaymentMethodType,
var paysafeAllowedCountires = []string{"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"}

func (c *PaySafeCredentials) SupportsCountry(country string) bool {
if country == "" {
return true
}
for _, v := range paysafeAllowedCountires {
if v == country {
if strings.EqualFold(v, country) {
return true
}
}
Expand Down
4 changes: 2 additions & 2 deletions connectorconfig/paysafe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func TestSupportsCountry(t *testing.T) {
"GB": true,
"XK": false,
"XX": false,
"": false,
"": true,
}

for k, v := range tests {
if credential.SupportsCountry(k) != v {
t.Errorf("Expected %v, got %v", v, !v)
t.Errorf("Expected %v, got %v for %s", v, !v, k)
}
}
}
59 changes: 34 additions & 25 deletions utils/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,34 @@ type Template string

const (
// connectors
confConnAdyen Template = "con_adyen"
confConnAuthorize Template = "con_authorize"
confConnBlueSnap Template = "con_blueSnap"
confConnBrainTree Template = "con_brainTree"
confConnChargeHive Template = "con_chargeHive"
confConnClearhaus Template = "con_clearhaus"
confConnCWAMS Template = "con_cwams"
confConnCyberSource Template = "con_cyberSource"
confConnGPayments Template = "con_gpayments"
confConnInovioPay Template = "con_inoviopay"
confConnMaxMind Template = "con_maxMind"
confConnNuvei Template = "con_nuvei"
confConnPayPalExpress Template = "con_payPalExpressCheckout"
confConnPayPalWPP Template = "con_payPalWPP"
confConnPaysafe Template = "con_paysafe"
confConnQualPay Template = "con_qualPay"
confConnSandbox Template = "con_sandbox"
confConnStripe Template = "con_stripe"
confConnTrustPayments Template = "con_trust-payments"
confConnVindicia Template = "con_vindicia"
confConnWorldPay Template = "con_worldPay"
confClearhaus Template = "con_clearhaus"
confTrustPayments Template = "con_trust-payments"
confCWAMS Template = "con_cwams"
confYapstone Template = "con_yapstone"
confInovioPay Template = "con_inoviopay"
confNuvei Template = "con_nuvei"
confGPayments Template = "con_gpayments"
confConnYapstone Template = "con_yapstone"

// connector Pool
confConnectorPool Template = "con_pool"

// integration
confSlack Template = "int_slack"
confIntSlack Template = "int_slack"

// policy
confPolCascade Template = "pol_cascade"
Expand All @@ -64,28 +65,30 @@ const (
)

var Templates = map[Template]string{
confConnAdyen: "Connector: Adyen",
confConnAuthorize: "Connector: Authorize.net",
confConnBlueSnap: "Connector: BlueSnap",
confConnBrainTree: "Connector: Braintree",
confConnChargeHive: "Connector: ChargeHive (fraud)",
confConnClearhaus: "Connector: Clearhaus",
confConnCWAMS: "Connector: CWAMS",
confConnCyberSource: "Connector: Cybersource (fraud)",
confConnectorPool: "Connector Pool",
confConnGPayments: "Connector: GPayments",
confConnInovioPay: "Connector: InovioPay",
confConnMaxMind: "Connector: MaxMind (fraud)",
confConnNuvei: "Connector: Nuvei",
confConnPayPalExpress: "Connector: Paypal Express Checkout",
confConnPayPalWPP: "Connector: Paypal Website Payments Pro",
confConnPaysafe: "Connector: Paysafe",
confConnQualPay: "Connector: QualPay",
confConnSandbox: "Connector: ChargeHive Sandbox",
confConnStripe: "Connector: Stripe",
confConnTrustPayments: "Connector: Trust Payments",
confConnVindicia: "Connector: Vindicia",
confConnWorldPay: "Connector: Worldpay",
confClearhaus: "Connector: Clearhaus",
confTrustPayments: "Connector: Trust Payments",
confCWAMS: "Connector: CWAMS",
confYapstone: "Connector: Yapstone",
confInovioPay: "Connector: InovioPay",
confNuvei: "Connector: Nuvei",
confGPayments: "Connector: GPayments",
confConnectorPool: "Connector Pool",
confSlack: "Integration: Slack",
confConnYapstone: "Connector: Yapstone",
confIntSlack: "Integration: Slack",
confPolCascade: "Policy: Cascade",
confPolChargeExpiry: "Policy: Charge Expiry",
confPolFraud: "Policy: Fraud",
Expand Down Expand Up @@ -136,6 +139,12 @@ func Generate(conf Template, version string, pretty bool) ([]byte, error) {

func buildSpec(conf Template) (object.Specification, error) {
switch conf {
case confConnAdyen:
j, _ := json.Marshal(connectorconfig.AdyenCredentials{
Environment: connectorconfig.AdyenEnvironmentSandbox,
MID: chg,
})
return connector.Connector{Library: string(connectorconfig.LibraryAdyen), Configuration: j}, nil
case confConnAuthorize:
j, _ := json.Marshal(connectorconfig.AuthorizeCredentials{APILoginID: &chg, TransactionKey: &chg, Environment: "sandbox"})
return connector.Connector{Library: string(connectorconfig.LibraryAuthorize), Configuration: j}, nil
Expand Down Expand Up @@ -245,14 +254,14 @@ func buildSpec(conf Template) (object.Specification, error) {
})

return connector.Connector{Library: string(connectorconfig.LibraryWorldpay), Configuration: j}, nil
case confClearhaus:
case confConnClearhaus:
j, _ := json.Marshal(connectorconfig.ClearhausCredentials{
MerchantID: chg,
APIKey: chg,
Environment: connectorconfig.ClearhausEnvironmentTest,
})
return connector.Connector{Library: string(connectorconfig.LibraryClearhaus), Configuration: j}, nil
case confTrustPayments:
case confConnTrustPayments:
j, _ := json.Marshal(connectorconfig.TrustPaymentsCredentials{
Username: &chg,
Password: &chg,
Expand All @@ -261,21 +270,21 @@ func buildSpec(conf Template) (object.Specification, error) {
Environment: connectorconfig.TrustPaymentsEnvironmentTest,
})
return connector.Connector{Library: string(connectorconfig.LibraryTrustPayments), Configuration: j}, nil
case confCWAMS:
case confConnCWAMS:
j, _ := json.Marshal(connectorconfig.CWAMSCredentials{
GatewayID: "12345678",
TestMode: true,
SecurityKey: &chg,
})
return connector.Connector{Library: string(connectorconfig.LibraryCWAMS), Configuration: j}, nil
case confYapstone:
case confConnYapstone:
j, _ := json.Marshal(connectorconfig.YapstoneCredentials{
ClientID: chg,
ClientSecret: chg,
Environment: connectorconfig.YapstoneEnvironmentTest,
})
return connector.Connector{Library: string(connectorconfig.LibraryYapstone), Configuration: j}, nil
case confInovioPay:
case confConnInovioPay:
j, _ := json.Marshal(connectorconfig.InovioPayCredentials{
Username: &chg,
Password: &chg,
Expand All @@ -285,15 +294,15 @@ func buildSpec(conf Template) (object.Specification, error) {
Environment: connectorconfig.InovioPayEnvironmentSandbox,
})
return connector.Connector{Library: string(connectorconfig.LibraryInovioPay), Configuration: j}, nil
case confNuvei:
case confConnNuvei:
j, _ := json.Marshal(connectorconfig.NuveiCredentials{
MerchantID: &chg,
MerchantSiteID: &chg,
MerchantSecretKey: &chg,
Environment: connectorconfig.NuveiEnvironmentSandbox,
})
return connector.Connector{Library: string(connectorconfig.LibraryNuvei), Configuration: j}, nil
case confGPayments:
case confConnGPayments:
j, _ := json.Marshal(connectorconfig.GPaymentsCredentials{
MerchantID: &chg,
MerchantCertificate: &chg,
Expand All @@ -304,7 +313,7 @@ func buildSpec(conf Template) (object.Specification, error) {
return connector.Connector{Library: string(connectorconfig.LibraryGPayments), Configuration: j}, nil
case confConnectorPool:
return connector.Pool{Restriction: "unrestricted", Connectors: []connector.PoolItem{{ConnectorID: chg}}}, nil
case confSlack:
case confIntSlack:
return integration.Slack{AccessToken: chg, TeamName: chg, TeamID: chg, TransactionNotifications: new(bool), Webhook: &integration.SlackWebhook{Url: chg, Channel: chg, ConfigurationUrl: chg}}, nil
case confPolCascade:
return policy.CascadePolicy{Rules: []policy.CascadeRule{{Library: connectorconfig.Library(chg), OriginalResponseCode: chg}}}, nil
Expand Down
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:"required,oneof=gpayments nuvei inoviopay threedsecureio sandbox sandbanx applepay authorize braintree qualpay stripe paysafe worldpay paypal-websitepaymentspro paypal-expresscheckout vindicia chargehive maxmind cybersource paysafe-accountupdater bottomline checkout kount clearhaus trust-payments cwams yapstone"`
Library string `json:"library" yaml:"library" validate:"required,oneof=adyen bluesnap gpayments nuvei inoviopay threedsecureio sandbox sandbanx applepay authorize braintree qualpay stripe paysafe worldpay paypal-websitepaymentspro paypal-expresscheckout vindicia chargehive maxmind cybersource paysafe-accountupdater bottomline checkout kount clearhaus trust-payments cwams yapstone"`
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
Loading