Skip to content

Commit

Permalink
refactor googlePay and applePay configs to work in both embed and ext…
Browse files Browse the repository at this point in the history
…end mode
  • Loading branch information
fobilow committed Jun 27, 2024
1 parent aeed624 commit 9a6a747
Show file tree
Hide file tree
Showing 12 changed files with 372 additions and 220 deletions.
13 changes: 13 additions & 0 deletions connectorconfig/applePay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions connectorconfig/braintree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -109,7 +109,7 @@ func (c *BraintreeCredentials) IsRecoveryAgent() bool {
return false
}

func (c *BraintreeCredentials) GetGooglePay() *GooglePay {
func (c *BraintreeCredentials) GetGooglePay() *GooglePayEmbedded {
return c.GooglePay
}

Expand Down
23 changes: 22 additions & 1 deletion connectorconfig/chargehive.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package connectorconfig

import (
"encoding/json"
"errors"

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

type ChargeHiveCredentials struct {
GooglePay *GooglePayEmbedded `json:"googlePay,omitempty" yaml:"googlePay,omitempty"`
ApplePay *ApplePayEmbedded `json:"applePay,omitempty" yaml:"applePay,omitempty"`
}

func (c *ChargeHiveCredentials) GetMID() string {
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions connectorconfig/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand All @@ -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
}

Expand Down
12 changes: 6 additions & 6 deletions connectorconfig/cwams.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
Loading

0 comments on commit 9a6a747

Please sign in to comment.