From 9a6a7471763e79d77130d99c757e783a9e7cadd7 Mon Sep 17 00:00:00 2001 From: Oke Ugwu Date: Thu, 27 Jun 2024 17:24:00 +0100 Subject: [PATCH] refactor googlePay and applePay configs to work in both embed and extend mode --- connectorconfig/applePay.go | 13 ++ connectorconfig/braintree.go | 6 +- connectorconfig/chargehive.go | 23 ++- connectorconfig/checkout.go | 4 +- connectorconfig/cwams.go | 12 +- connectorconfig/googlePay.go | 269 +++++++------------------- connectorconfig/googlePayEmebedded.go | 239 +++++++++++++++++++++++ connectorconfig/library.go | 12 +- connectorconfig/paysafe.go | 4 +- connectorconfig/worldpay.go | 4 +- utils/generate.go | 4 +- v1/connector/connector.go | 2 +- 12 files changed, 372 insertions(+), 220 deletions(-) create mode 100644 connectorconfig/googlePayEmebedded.go diff --git a/connectorconfig/applePay.go b/connectorconfig/applePay.go index 7e102cb..b29b216 100644 --- a/connectorconfig/applePay.go +++ b/connectorconfig/applePay.go @@ -248,3 +248,16 @@ func (a *ApplePayCredentials) GetAppleCardShippingPhoneReq() bool { } return a.AppleCardShippingPhoneReq } + +type ApplePayOptions interface { + GetAppleMerchantIdentifier() string + GetAppleExistingMethodRequired() bool + GetAppleExistingMethodReport() bool + GetAppleCardAllowDebit() bool + GetAppleCardAllowCredit() bool + GetAppleEmailRequired() bool + GetAppleCardBillingAddressReq() bool + GetAppleCardBillingPhoneReq() bool + GetAppleCardShippingAddressReq() bool + GetAppleCardShippingPhoneReq() bool +} diff --git a/connectorconfig/braintree.go b/connectorconfig/braintree.go index 8e6daf6..c75b397 100644 --- a/connectorconfig/braintree.go +++ b/connectorconfig/braintree.go @@ -25,9 +25,9 @@ type BraintreeCredentials struct { 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 *GooglePay `json:"googlePay,omitempty" yaml:"googlePay,omitempty"` + GooglePay *GooglePayEmbedded `json:"googlePay,omitempty" yaml:"googlePay,omitempty"` ApplePay *ApplePayEmbedded `json:"applePay,omitempty" yaml:"applePay,omitempty"` - TokenizationKey string `json:"tokenizationKey,omitempty" yaml:"tokenizationKey,omitempty" validate:"required_with=GooglePay ApplePay,omitempty,gt=0"` + TokenizationKey string `json:"tokenizationKey,omitempty" yaml:"tokenizationKey,omitempty" validate:"required_with=GooglePayEmbedded ApplePay,omitempty,gt=0"` } func (c *BraintreeCredentials) GetMID() string { @@ -109,7 +109,7 @@ func (c *BraintreeCredentials) IsRecoveryAgent() bool { return false } -func (c *BraintreeCredentials) GetGooglePay() *GooglePay { +func (c *BraintreeCredentials) GetGooglePay() *GooglePayEmbedded { return c.GooglePay } diff --git a/connectorconfig/chargehive.go b/connectorconfig/chargehive.go index 4500ffe..0020b52 100644 --- a/connectorconfig/chargehive.go +++ b/connectorconfig/chargehive.go @@ -2,6 +2,7 @@ package connectorconfig import ( "encoding/json" + "errors" "github.com/chargehive/configuration/environment" "github.com/chargehive/configuration/v1/connector" @@ -9,6 +10,8 @@ import ( ) type ChargeHiveCredentials struct { + GooglePay *GooglePayEmbedded `json:"googlePay,omitempty" yaml:"googlePay,omitempty"` + ApplePay *ApplePayEmbedded `json:"applePay,omitempty" yaml:"applePay,omitempty"` } func (c *ChargeHiveCredentials) GetMID() string { @@ -20,10 +23,20 @@ func (c *ChargeHiveCredentials) GetLibrary() Library { } func (c *ChargeHiveCredentials) GetSupportedTypes() []LibraryType { - return []LibraryType{LibraryTypeFraud} + return []LibraryType{LibraryTypePayment} } func (c *ChargeHiveCredentials) Validate() error { + if c.GooglePay != nil { + if !c.GooglePay.IsValid() { + return errors.New("invalid google pay configuration") + } + } + if c.ApplePay != nil { + if !c.ApplePay.IsValid() { + return errors.New("invalid apple pay configuration") + } + } return nil } @@ -67,3 +80,11 @@ func (c *ChargeHiveCredentials) IsRecoveryAgent() bool { func (c *ChargeHiveCredentials) Supports3RI() bool { return false } + +func (c *ChargeHiveCredentials) GetApplePay() *ApplePayEmbedded { + return c.ApplePay +} + +func (c *ChargeHiveCredentials) GetGooglePay() *GooglePayEmbedded { + return c.GooglePay +} diff --git a/connectorconfig/checkout.go b/connectorconfig/checkout.go index 2f6e544..0536eb6 100644 --- a/connectorconfig/checkout.go +++ b/connectorconfig/checkout.go @@ -25,7 +25,7 @@ type CheckoutCredentials struct { MerchantID string `json:"merchantID" yaml:"merchantID" validate:"required"` 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 *GooglePay `json:"googlePay,omitempty" yaml:"googlePay,omitempty"` + GooglePay *GooglePayEmbedded `json:"googlePay,omitempty" yaml:"googlePay,omitempty"` ApplePay *ApplePayEmbedded `json:"applePay,omitempty" yaml:"applePay,omitempty"` } @@ -40,7 +40,7 @@ func (c *CheckoutCredentials) GetMID() string { return c.MerchantID } -func (c *CheckoutCredentials) GetGooglePay() *GooglePay { +func (c *CheckoutCredentials) GetGooglePay() *GooglePayEmbedded { return c.GooglePay } diff --git a/connectorconfig/cwams.go b/connectorconfig/cwams.go index 802270b..8cfd94c 100644 --- a/connectorconfig/cwams.go +++ b/connectorconfig/cwams.go @@ -9,11 +9,11 @@ import ( ) type CWAMSCredentials struct { - GatewayID string `json:"gatewayID" yaml:"gatewayID" validate:"required"` - TestMode bool `json:"testMode" yaml:"testMode"` - SecurityKey *string `json:"securityKey" yaml:"securityKey" validate:"required"` - GooglePay *GooglePay `json:"googlePay,omitempty" yaml:"googlePay,omitempty"` - ApplePay *ApplePayEmbedded `json:"applePay,omitempty" yaml:"applePay,omitempty"` + GatewayID string `json:"gatewayID" yaml:"gatewayID" validate:"required"` + TestMode bool `json:"testMode" yaml:"testMode"` + SecurityKey *string `json:"securityKey" yaml:"securityKey" validate:"required"` + GooglePay *GooglePayEmbedded `json:"googlePay,omitempty" yaml:"googlePay,omitempty"` + ApplePay *ApplePayEmbedded `json:"applePay,omitempty" yaml:"applePay,omitempty"` } func (c *CWAMSCredentials) GetGooglePayParams() map[string]string { @@ -31,7 +31,7 @@ func (c *CWAMSCredentials) GetSecurityKey() string { return *c.SecurityKey } -func (c *CWAMSCredentials) GetGooglePay() *GooglePay { +func (c *CWAMSCredentials) GetGooglePay() *GooglePayEmbedded { return c.GooglePay } diff --git a/connectorconfig/googlePay.go b/connectorconfig/googlePay.go index 06c3b64..60f0d1a 100644 --- a/connectorconfig/googlePay.go +++ b/connectorconfig/googlePay.go @@ -1,241 +1,110 @@ package connectorconfig +import ( + "encoding/json" + + "github.com/chargehive/configuration/environment" + "github.com/chargehive/configuration/v1/connector" + "github.com/chargehive/proto/golang/chargehive/chtype" +) + type GooglePayCredential interface { - GetGooglePay() *GooglePay + GetGooglePay() *GooglePayEmbedded GetGooglePayParams() map[string]string } -type GooglePay struct { - // GoogleMerchantId REQUIRED TO ENABLE GOOGLE PAY (merchantInfo.merchantId) A Google merchant identifier issued after your website is approved by Google. Required when PaymentsClient is initialized with an environment property of PRODUCTION. See the Integration checklist for more information about the approval process and how to obtain a Google merchant identifier. (https://developers.google.com/pay/api/web/reference/request-objects#MerchantInfo) - GoogleMerchantId string `json:"googleMerchantId,omitempty" yaml:"googleMerchantId,omitempty" validate:"-"` - // GoogleEnvironment (environment) PRODUCTION: Used to return chargeable payment methods when a valid Google merchant ID is specified and configured for the domain.TEST: Dummy payment methods that are suitable for testing (default). - GoogleEnvironment GoogleEnvironment `json:"googleEnvironment,omitempty" yaml:"googleEnvironment,omitempty" validate:"required_with=GoogleMerchantId,omitempty,oneof=TEST PRODUCTION"` - // GoogleMerchantName (merchantInfo.merchantName) Merchant name encoded as UTF-8. Merchant name is rendered in the payment sheet. In TEST environment, or if a merchant isn't recognized, a “Pay Unverified Merchant” message is displayed in the payment sheet. - GoogleMerchantName string `json:"googleMerchantName,omitempty" yaml:"googleMerchantName,omitempty" validate:"required_with=GoogleMerchantId"` - // GoogleExistingMethodRequired Chargehive will not use this connector if the customer does not have a google payment method already saved - GoogleExistingMethodRequired bool `json:"googleExistingMethodRequired,omitempty" yaml:"googleExistingMethodRequired,omitempty" validate:"-"` - // GoogleExistingMethodReport Chargehive will request the existing payment method information from GooglePay - GoogleExistingMethodReport bool `json:"googleExistingMethodReport,omitempty" yaml:"googleExistingMethodReport,omitempty" validate:"-"` - // GoogleEmailReq (emailRequired) Set to true to request an email address. (https://developers.google.com/pay/api/web/reference/request-objects#PaymentDataRequest) - GoogleEmailReq bool `json:"googleEmailReq,omitempty" yaml:"googleEmailReq,omitempty" validate:"-"` - // GoogleAcceptCard (Card {type = "CARD"}) Enable this to allow card payments through GooglePay - GoogleAcceptCard bool `json:"googleAcceptCard,omitempty" yaml:"googleAcceptCard,omitempty" validate:"-"` - // GoogleCardAuthMethods (Card {parameters.allowedAuthMethods}) Fields supported to authenticate a card transaction. - GoogleCardAuthMethods []GoogleCardAuthMethod `json:"googleCardAuthMethods,omitempty" yaml:"googleCardAuthMethods,omitempty" validate:"required_with=GoogleMerchantId,dive,oneof=PAN_ONLY CRYPTOGRAM_3DS"` - // GoogleCardNetworks (Card {parameters.allowedCardNetworks}) One or more card networks that you support, also supported by the Google Pay API. - GoogleCardNetworks []GoogleCardNetwork `json:"googleCardNetworks,omitempty" yaml:"googleCardNetworks,omitempty" validate:"required_with=GoogleMerchantId,dive,oneof=AMEX DISCOVER INTERAC JCB MASTERCARD VISA"` - // GoogleCardAllowPrepaid (Card {parameters.allowPrepaidCards}) Allow customer to pay with prepaid card - GoogleCardAllowPrepaid bool `json:"googleCardAllowPrepaid,omitempty" yaml:"googleCardAllowPrepaid,omitempty" validate:"-"` - // GoogleCardAllowCredit (Card {parameters.allowCreditCards}) Allow customer to pay with credit card - GoogleCardAllowCredit bool `json:"googleCardAllowCredit,omitempty" yaml:"googleCardAllowCredit,omitempty" validate:"-"` - // GoogleCardBillingAddressReq (Card {parameters.billingAddressRequired}) Set to true if you require a billing address. A billing address should only be requested if it's required to process the transaction - GoogleCardBillingAddressReq bool `json:"googleCardBillingAddressReq,omitempty" yaml:"googleCardBillingAddressReq,omitempty" validate:"-"` - // 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"` - // 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 - GoogleCardGateway GoogleCardGateway `json:"googleCardGateway,omitempty" yaml:"googleCardGateway,omitempty" validate:"required_with=GoogleMerchantId,omitempty"` - // GoogleCardMerchantId (Card {tokenizationSpecification.parameters.gatewayMerchantId}) https://developers.google.com/pay/api/web/reference/request-objects#gateway - GoogleCardMerchantId string `json:"googleCardMerchantId,omitempty" yaml:"googleCardMerchantId,omitempty" validate:"required_with=GoogleMerchantId"` - - // GoogleCardShippingAddressReq Set to true if you require a shipping address. A shipping address should only be requested if it's required to process the transaction - 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"` -} - -func (g *GooglePay) GetSecureFields() []*string { - return nil +type GooglePayCredentials struct { + GooglePayEmbedded } -func (g *GooglePay) IsValid() bool { - if g == nil { - return false - } - return g.GetGoogleMerchantId() != "" && - g.GetGoogleCardGateway() != "" && - g.GetGoogleCardMerchantId() != "" -} - -type ( - GoogleEnvironment string - GoogleCardGateway string - GoogleCardAuthMethod string - GoogleTokenType string - GoogleCardNetwork string - GoogleCardBillingAddressReq 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. - - GoogleEnvironmentTEST GoogleEnvironment = "TEST" - GoogleEnvironmentPROD GoogleEnvironment = "PRODUCTION" - - // GoogleCardGatewayVANTIV - // Deprecated - GoogleCardGatewayVANTIV GoogleCardGateway = "vantiv" - // GoogleCardGatewayPAYSAFE - // Deprecated - GoogleCardGatewayPAYSAFE GoogleCardGateway = "paysafe" - - GoogleCardTokenTypeDIRECT GoogleTokenType = "DIRECT" - GoogleCardTokenTypeGATEWAY GoogleTokenType = "PAYMENT_GATEWAY" - - GoogleCardAuthMethodPAN GoogleCardAuthMethod = "PAN_ONLY" // This authentication method is associated with payment cards stored on file with the user's Google Account. Returned payment data includes personal account number (PAN) with the expiration month and the expiration year. - GoogleCardAuthMethod3DS GoogleCardAuthMethod = "CRYPTOGRAM_3DS" // This authentication method is associated with cards stored as Android device tokens. Returned payment data includes a 3-D Secure (3DS) cryptogram generated on the device. - - GoogleCardNetworkAMEX GoogleCardNetwork = "AMEX" - GoogleCardNetworkDISCOVER GoogleCardNetwork = "DISCOVER" - GoogleCardNetworkINTERAC GoogleCardNetwork = "INTERAC" - GoogleCardNetworkJCB GoogleCardNetwork = "JCB" - GoogleCardNetworkMASTERCARD GoogleCardNetwork = "MASTERCARD" - GoogleCardNetworkVISA GoogleCardNetwork = "VISA" -) +func (g GooglePayCredentials) GetGooglePay() *GooglePayEmbedded { + return &g.GooglePayEmbedded +} -func (g *GooglePay) GetGoogleMerchantId() string { - if g == nil { - return "" +func (g GooglePayCredentials) GetGooglePayParams() map[string]string { + return map[string]string{ + "gateway": g.GetGoogleCardGateway(), + "gatewayMerchantId": g.GetGoogleCardMerchantId(), } - return g.GoogleMerchantId } -func (g *GooglePay) GetGoogleEnvironment() GoogleEnvironment { - if g == nil { - return "" - } - return g.GoogleEnvironment +func (g *GooglePayCredentials) GetMID() string { + return g.GoogleMerchantId } -func (g *GooglePay) GetGoogleMerchantName() string { - if g == nil { - return "" - } - return g.GoogleMerchantName +func (g *GooglePayCredentials) GetLibrary() Library { + return LibraryApplePay } -func (g *GooglePay) GetGoogleExistingMethodRequired() bool { - if g == nil { - return false - } - return g.GoogleExistingMethodRequired +func (g *GooglePayCredentials) GetSupportedTypes() []LibraryType { + return []LibraryType{} } -func (g *GooglePay) GetGoogleExistingMethodReport() bool { - if g == nil { - return false - } - return g.GoogleExistingMethodReport +func (g *GooglePayCredentials) Validate() error { + return nil } -func (g *GooglePay) GetGoogleEmailReq() bool { - if g == nil { - return false - } - return g.GoogleEmailReq +func (g *GooglePayCredentials) ToConnector() connector.Connector { + con := connector.Connector{Library: string(g.GetLibrary())} + con.Configuration, _ = json.Marshal(g) + return con } -func (g *GooglePay) GetGoogleAcceptCard() bool { - if g == nil { - return false - } - return g.GoogleAcceptCard +func (g *GooglePayCredentials) FromJson(input []byte) error { + return json.Unmarshal(input, g) } -func (g *GooglePay) GetGoogleCardAuthMethods() []GoogleCardAuthMethod { - if g == nil { - return nil - } - return g.GoogleCardAuthMethods -} -func (g *GooglePay) GetGoogleCardNetworks() []GoogleCardNetwork { - if g == nil { - return nil - } - return g.GoogleCardNetworks +func (g *GooglePayCredentials) SupportsSca() bool { + return false } -func (g *GooglePay) GetGoogleCardAllowPrepaid() bool { - if g == nil { - return false - } - return g.GoogleCardAllowPrepaid +func (g *GooglePayCredentials) SupportsMethod(methodType chtype.PaymentMethodType, methodProvider chtype.PaymentMethodProvider) bool { + // this connector does not directly support any types, GooglePayEmbedded tokens are processed through another connector + return false } -func (g *GooglePay) GetGoogleCardAllowCredit() bool { - if g == nil { - return false - } - return g.GoogleCardAllowCredit +func (g *GooglePayCredentials) SupportsCountry(country string) bool { + return true } -func (g *GooglePay) GetGoogleCardBillingAddressReq() bool { - if g == nil { - return false - } - return g.GoogleCardBillingAddressReq + +func (g *GooglePayCredentials) CanPlanModeUse(mode environment.Mode) bool { + return true } -func (g *GooglePay) GetGoogleCardBillingAddressFormat() GoogleCardBillingAddressReq { - if g == nil { - return "" - } - return g.GoogleCardBillingAddressFormat +func (g *GooglePayCredentials) IsRecoveryAgent() bool { + return false } -func (g *GooglePay) GetGoogleCardBillingPhoneReq() bool { - if g == nil { - return false - } - return g.GoogleCardBillingPhoneReq + +func (g *GooglePayCredentials) Supports3RI() bool { + return false } -func (g *GooglePay) GetGoogleCardShippingAddressReq() bool { + +func (g *GooglePayCredentials) GetSecureFields() []*string { if g == nil { - return false + return nil } - return g.GoogleCardShippingAddressReq + return []*string{} } -func (g *GooglePay) GetGoogleCardShippingAddressFormat() GoogleCardBillingAddressReq { - if g == nil { - return "" - } - return g.GoogleCardShippingAddressFormat -} -func (g *GooglePay) GetGoogleCardShippingPhoneReq() bool { +func (g *GooglePayCredentials) IsValid() bool { if g == nil { return false } - return g.GoogleCardShippingPhoneReq -} -func (g *GooglePay) GetGoogleCardTokenType() GoogleTokenType { - if g == nil { - return "" - } - return g.GoogleCardTokenType -} -func (g *GooglePay) GetGoogleCardGateway() GoogleCardGateway { - if g == nil { - return "" - } - return g.GoogleCardGateway -} -func (g *GooglePay) GetGoogleCardMerchantId() string { - if g == nil { - return "" - } - return g.GoogleCardMerchantId -} -func (g *GooglePay) GetGoogleAcquirerCountry() string { - if g == nil { - return "" - } - return g.GoogleAcquirerCountry + return g.Validate() == nil +} + +type GooglePayOptions interface { + GetGoogleCardGateway() string + GetGoogleCardMerchantId() string + GetGoogleAcquirerCountry() string + GetGoogleExistingMethodRequired() bool + GetGoogleExistingMethodReport() bool + GetGoogleEmailReq() bool + GetGoogleAcceptCard() bool + GetGoogleCardAllowPrepaid() bool + GetGoogleCardAllowCredit() bool + GetGoogleCardBillingAddressReq() bool + GetGoogleCardBillingPhoneReq() bool + GetGoogleCardShippingAddressReq() bool + GetGoogleCardShippingPhoneReq() bool } diff --git a/connectorconfig/googlePayEmebedded.go b/connectorconfig/googlePayEmebedded.go new file mode 100644 index 0000000..e6f548c --- /dev/null +++ b/connectorconfig/googlePayEmebedded.go @@ -0,0 +1,239 @@ +package connectorconfig + +type GooglePayEmbedded struct { + // ConnectorID The ID of the connector that provides the GooglePay service + ConnectorID string `json:"googlePayConnectorID,omitempty" yaml:"googlePayConnectorID,omitempty" validate:"-"` + + // GoogleMerchantId REQUIRED TO ENABLE GOOGLE PAY (merchantInfo.merchantId) A Google merchant identifier issued after your website is approved by Google. Required when PaymentsClient is initialized with an environment property of PRODUCTION. See the Integration checklist for more information about the approval process and how to obtain a Google merchant identifier. (https://developers.google.com/pay/api/web/reference/request-objects#MerchantInfo) + GoogleMerchantId string `json:"googleMerchantId,omitempty" yaml:"googleMerchantId,omitempty" validate:"-"` + // GoogleEnvironment (environment) PRODUCTION: Used to return chargeable payment methods when a valid Google merchant ID is specified and configured for the domain.TEST: Dummy payment methods that are suitable for testing (default). + GoogleEnvironment GoogleEnvironment `json:"googleEnvironment,omitempty" yaml:"googleEnvironment,omitempty" validate:"required_with=GoogleMerchantId,omitempty,oneof=TEST PRODUCTION"` + // GoogleMerchantName (merchantInfo.merchantName) Merchant name encoded as UTF-8. Merchant name is rendered in the payment sheet. In TEST environment, or if a merchant isn't recognized, a “Pay Unverified Merchant” message is displayed in the payment sheet. + GoogleMerchantName string `json:"googleMerchantName,omitempty" yaml:"googleMerchantName,omitempty" validate:"required_with=GoogleMerchantId"` + // GoogleExistingMethodRequired Chargehive will not use this connector if the customer does not have a google payment method already saved + GoogleExistingMethodRequired bool `json:"googleExistingMethodRequired,omitempty" yaml:"googleExistingMethodRequired,omitempty" validate:"-"` + // GoogleExistingMethodReport Chargehive will request the existing payment method information from GooglePayEmbedded + GoogleExistingMethodReport bool `json:"googleExistingMethodReport,omitempty" yaml:"googleExistingMethodReport,omitempty" validate:"-"` + // GoogleEmailReq (emailRequired) Set to true to request an email address. (https://developers.google.com/pay/api/web/reference/request-objects#PaymentDataRequest) + GoogleEmailReq bool `json:"googleEmailReq,omitempty" yaml:"googleEmailReq,omitempty" validate:"-"` + // GoogleAcceptCard (Card {type = "CARD"}) Enable this to allow card payments through GooglePayEmbedded + GoogleAcceptCard bool `json:"googleAcceptCard,omitempty" yaml:"googleAcceptCard,omitempty" validate:"-"` + // GoogleCardAuthMethods (Card {parameters.allowedAuthMethods}) Fields supported to authenticate a card transaction. + GoogleCardAuthMethods []GoogleCardAuthMethod `json:"googleCardAuthMethods,omitempty" yaml:"googleCardAuthMethods,omitempty" validate:"required_with=GoogleMerchantId,dive,oneof=PAN_ONLY CRYPTOGRAM_3DS"` + // GoogleCardNetworks (Card {parameters.allowedCardNetworks}) One or more card networks that you support, also supported by the Google Pay API. + GoogleCardNetworks []GoogleCardNetwork `json:"googleCardNetworks,omitempty" yaml:"googleCardNetworks,omitempty" validate:"required_with=GoogleMerchantId,dive,oneof=AMEX DISCOVER INTERAC JCB MASTERCARD VISA"` + // GoogleCardAllowPrepaid (Card {parameters.allowPrepaidCards}) Allow customer to pay with prepaid card + GoogleCardAllowPrepaid bool `json:"googleCardAllowPrepaid,omitempty" yaml:"googleCardAllowPrepaid,omitempty" validate:"-"` + // GoogleCardAllowCredit (Card {parameters.allowCreditCards}) Allow customer to pay with credit card + GoogleCardAllowCredit bool `json:"googleCardAllowCredit,omitempty" yaml:"googleCardAllowCredit,omitempty" validate:"-"` + // GoogleCardBillingAddressReq (Card {parameters.billingAddressRequired}) Set to true if you require a billing address. A billing address should only be requested if it's required to process the transaction + GoogleCardBillingAddressReq bool `json:"googleCardBillingAddressReq,omitempty" yaml:"googleCardBillingAddressReq,omitempty" validate:"-"` + // 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"` + // 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 + GoogleCardGateway string `json:"googleCardGateway,omitempty" yaml:"googleCardGateway,omitempty" validate:"required_with=GoogleMerchantId,omitempty"` + // GoogleCardMerchantId (Card {tokenizationSpecification.parameters.gatewayMerchantId}) https://developers.google.com/pay/api/web/reference/request-objects#gateway + GoogleCardMerchantId string `json:"googleCardMerchantId,omitempty" yaml:"googleCardMerchantId,omitempty" validate:"required_with=GoogleMerchantId"` + + // GoogleCardShippingAddressReq Set to true if you require a shipping address. A shipping address should only be requested if it's required to process the transaction + 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"` +} + +func (g *GooglePayEmbedded) GetSecureFields() []*string { + return nil +} + +func (g *GooglePayEmbedded) IsValid() bool { + if g == nil { + return false + } + return g.ConnectorID != "" || g.GetGoogleMerchantId() != "" && + g.GetGoogleCardGateway() != "" && + g.GetGoogleCardMerchantId() != "" +} + +type ( + GoogleEnvironment string + GoogleCardGateway string + GoogleCardAuthMethod string + GoogleTokenType string + GoogleCardNetwork string + GoogleCardBillingAddressReq 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. + + GoogleEnvironmentTEST GoogleEnvironment = "TEST" + GoogleEnvironmentPROD GoogleEnvironment = "PRODUCTION" + + // GoogleCardGatewayVANTIV + // Deprecated + GoogleCardGatewayVANTIV GoogleCardGateway = "vantiv" + // GoogleCardGatewayPAYSAFE + // Deprecated + GoogleCardGatewayPAYSAFE GoogleCardGateway = "paysafe" + + GoogleCardTokenTypeDIRECT GoogleTokenType = "DIRECT" + GoogleCardTokenTypeGATEWAY GoogleTokenType = "PAYMENT_GATEWAY" + + GoogleCardAuthMethodPAN GoogleCardAuthMethod = "PAN_ONLY" // This authentication method is associated with payment cards stored on file with the user's Google Account. Returned payment data includes personal account number (PAN) with the expiration month and the expiration year. + GoogleCardAuthMethod3DS GoogleCardAuthMethod = "CRYPTOGRAM_3DS" // This authentication method is associated with cards stored as Android device tokens. Returned payment data includes a 3-D Secure (3DS) cryptogram generated on the device. + + GoogleCardNetworkAMEX GoogleCardNetwork = "AMEX" + GoogleCardNetworkDISCOVER GoogleCardNetwork = "DISCOVER" + GoogleCardNetworkINTERAC GoogleCardNetwork = "INTERAC" + GoogleCardNetworkJCB GoogleCardNetwork = "JCB" + GoogleCardNetworkMASTERCARD GoogleCardNetwork = "MASTERCARD" + GoogleCardNetworkVISA GoogleCardNetwork = "VISA" +) + +func (g *GooglePayEmbedded) GetGoogleMerchantId() string { + if g == nil { + return "" + } + return g.GoogleMerchantId +} +func (g *GooglePayEmbedded) GetGoogleEnvironment() GoogleEnvironment { + if g == nil { + return "" + } + + return g.GoogleEnvironment +} +func (g *GooglePayEmbedded) GetGoogleMerchantName() string { + if g == nil { + return "" + } + + return g.GoogleMerchantName +} +func (g *GooglePayEmbedded) GetGoogleExistingMethodRequired() bool { + if g == nil { + return false + } + + return g.GoogleExistingMethodRequired +} +func (g *GooglePayEmbedded) GetGoogleExistingMethodReport() bool { + if g == nil { + return false + } + + return g.GoogleExistingMethodReport +} +func (g *GooglePayEmbedded) GetGoogleEmailReq() bool { + if g == nil { + return false + } + + return g.GoogleEmailReq +} +func (g *GooglePayEmbedded) GetGoogleAcceptCard() bool { + if g == nil { + return false + } + + return g.GoogleAcceptCard +} +func (g *GooglePayEmbedded) GetGoogleCardAuthMethods() []GoogleCardAuthMethod { + if g == nil { + return nil + } + return g.GoogleCardAuthMethods +} +func (g *GooglePayEmbedded) GetGoogleCardNetworks() []GoogleCardNetwork { + if g == nil { + return nil + } + + return g.GoogleCardNetworks +} +func (g *GooglePayEmbedded) GetGoogleCardAllowPrepaid() bool { + if g == nil { + return false + } + + return g.GoogleCardAllowPrepaid +} +func (g *GooglePayEmbedded) GetGoogleCardAllowCredit() bool { + if g == nil { + return false + } + + return g.GoogleCardAllowCredit +} +func (g *GooglePayEmbedded) GetGoogleCardBillingAddressReq() bool { + if g == nil { + return false + } + return g.GoogleCardBillingAddressReq +} +func (g *GooglePayEmbedded) GetGoogleCardBillingAddressFormat() GoogleCardBillingAddressReq { + if g == nil { + return "" + } + + return g.GoogleCardBillingAddressFormat +} +func (g *GooglePayEmbedded) GetGoogleCardBillingPhoneReq() bool { + if g == nil { + return false + } + return g.GoogleCardBillingPhoneReq +} +func (g *GooglePayEmbedded) GetGoogleCardShippingAddressReq() bool { + if g == nil { + return false + } + return g.GoogleCardShippingAddressReq +} +func (g *GooglePayEmbedded) GetGoogleCardShippingAddressFormat() GoogleCardBillingAddressReq { + if g == nil { + return "" + } + + return g.GoogleCardShippingAddressFormat +} +func (g *GooglePayEmbedded) GetGoogleCardShippingPhoneReq() bool { + if g == nil { + return false + } + return g.GoogleCardShippingPhoneReq +} +func (g *GooglePayEmbedded) GetGoogleCardTokenType() GoogleTokenType { + if g == nil { + return "" + } + return g.GoogleCardTokenType +} +func (g *GooglePayEmbedded) GetGoogleCardGateway() string { + if g == nil { + return "" + } + return g.GoogleCardGateway +} +func (g *GooglePayEmbedded) GetGoogleCardMerchantId() string { + if g == nil { + return "" + } + return g.GoogleCardMerchantId +} +func (g *GooglePayEmbedded) GetGoogleAcquirerCountry() string { + if g == nil { + return "" + } + return g.GoogleAcquirerCountry +} diff --git a/connectorconfig/library.go b/connectorconfig/library.go index bd3353e..86f081e 100644 --- a/connectorconfig/library.go +++ b/connectorconfig/library.go @@ -19,6 +19,7 @@ const ( LibrarySandbox Library = "sandbox" // Connector for testing Charge hive LibraryAdyen Library = "adyen" LibraryApplePay Library = "applepay" + LibraryGooglePay Library = "googlepay" LibraryAuthorize Library = "authorize" LibraryBraintree Library = "braintree" LibraryBlueSnap Library = "bluesnap" @@ -125,6 +126,13 @@ var LibraryRegister = map[Library]LibraryDef{ return methodType == chtype.PAYMENT_METHOD_TYPE_CARD }, }, + LibraryGooglePay: { + DisplayName: "GooglePayEmbedded", + Credentials: func() Credentials { return &GooglePayCredentials{} }, + SupportsMethod: func(methodType chtype.PaymentMethodType, methodProvider chtype.PaymentMethodProvider) bool { + return methodType == chtype.PAYMENT_METHOD_TYPE_CARD + }, + }, LibraryAuthorize: { DisplayName: "Authorize", Credentials: func() Credentials { return &AuthorizeCredentials{} }, @@ -228,7 +236,9 @@ var LibraryRegister = map[Library]LibraryDef{ DisplayName: "ChargeHive", Credentials: func() Credentials { return &ChargeHiveCredentials{} }, SupportsMethod: func(methodType chtype.PaymentMethodType, methodProvider chtype.PaymentMethodProvider) bool { - return methodType == chtype.PAYMENT_METHOD_TYPE_CARD + return methodType == chtype.PAYMENT_METHOD_TYPE_CARD || + (methodType == chtype.PAYMENT_METHOD_TYPE_DIGITALWALLET && methodProvider == chtype.PAYMENT_METHOD_PROVIDER_APPLEPAY) || + (methodType == chtype.PAYMENT_METHOD_TYPE_DIGITALWALLET && methodProvider == chtype.PAYMENT_METHOD_PROVIDER_GOOGLEPAY) }, }, diff --git a/connectorconfig/paysafe.go b/connectorconfig/paysafe.go index db85f90..1896c2f 100644 --- a/connectorconfig/paysafe.go +++ b/connectorconfig/paysafe.go @@ -37,7 +37,7 @@ type PaySafeCredentials struct { UseVault *bool `json:"useVault" yaml:"useVault" validate:"required"` SingleUseTokenPassword *string `json:"singleUseTokenPassword" yaml:"singleUseTokenPassword" validate:"required"` // string* needs "required" to ensure nil is never returned SingleUseTokenUsername string `json:"singleUseTokenUsername" yaml:"singleUseTokenUsername" validate:"-"` // string will default to empty string - GooglePay *GooglePay `json:"googlePay,omitempty" yaml:"googlePay,omitempty"` + GooglePay *GooglePayEmbedded `json:"googlePay,omitempty" yaml:"googlePay,omitempty"` ApplePay *ApplePayEmbedded `json:"applePay,omitempty" yaml:"applePay,omitempty"` } @@ -52,7 +52,7 @@ func (c *PaySafeCredentials) GetMID() string { return c.AccountID } -func (c *PaySafeCredentials) GetGooglePay() *GooglePay { +func (c *PaySafeCredentials) GetGooglePay() *GooglePayEmbedded { return c.GooglePay } diff --git a/connectorconfig/worldpay.go b/connectorconfig/worldpay.go index 0e81eae..3787bd0 100644 --- a/connectorconfig/worldpay.go +++ b/connectorconfig/worldpay.go @@ -30,7 +30,7 @@ type WorldpayCredentials struct { CardinalApiKey *string `json:"cardinalApiKey" yaml:"cardinalApiKey" validate:"required"` CardinalOrgUnitId *string `json:"cardinalOrgUnitId" yaml:"cardinalOrgUnitId" validate:"required"` GooglePayPageId string `json:"googlePayPageId"` // vantiv:merchantPayPageId - GooglePay *GooglePay `json:"googlePay,omitempty" yaml:"googlePay,omitempty"` + GooglePay *GooglePayEmbedded `json:"googlePay,omitempty" yaml:"googlePay,omitempty"` ApplePay *ApplePayEmbedded `json:"applePay,omitempty" yaml:"applePay,omitempty"` } @@ -49,7 +49,7 @@ func (c *WorldpayCredentials) GetMID() string { return c.MerchantID } -func (c *WorldpayCredentials) GetGooglePay() *GooglePay { +func (c *WorldpayCredentials) GetGooglePay() *GooglePayEmbedded { return c.GooglePay } diff --git a/utils/generate.go b/utils/generate.go index 6ba7329..4f56d33 100644 --- a/utils/generate.go +++ b/utils/generate.go @@ -238,7 +238,7 @@ func buildSpec(conf Template) (object.Specification, error) { AppleMerchantCapabilities: []connectorconfig.AppleMerchantCapability{connectorconfig.AppleMerchantCapabilitysupports3DS}, }, GooglePayPageId: chg, - GooglePay: &connectorconfig.GooglePay{ + GooglePay: &connectorconfig.GooglePayEmbedded{ GoogleEnvironment: connectorconfig.GoogleEnvironmentTEST, GoogleMerchantId: chg, GoogleMerchantName: chg, @@ -256,7 +256,7 @@ func buildSpec(conf Template) (object.Specification, error) { GoogleCardShippingAddressFormat: connectorconfig.GoogleCardBillingAddressReqMIN, GoogleCardShippingPhoneReq: false, GoogleCardTokenType: connectorconfig.GoogleCardTokenTypeGATEWAY, - GoogleCardGateway: connectorconfig.GoogleCardGatewayVANTIV, + GoogleCardGateway: string(connectorconfig.GoogleCardGatewayVANTIV), GoogleCardMerchantId: chg, }, }) diff --git a/v1/connector/connector.go b/v1/connector/connector.go index 7d45251..a6136b7 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:"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 tokenex-accountupdater tokenex-networktokenization sticky-io"` + 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 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"`