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

Adds and update properties. Subdomains for merchants support #103

Merged
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
1 change: 1 addition & 0 deletions .github/workflows/build-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET }}
CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID }}
CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET }}
CHECKOUT_MERCHANT_SUBDOMAIN: ${{ secrets.IT_CHECKOUT_MERCHANT_SUBDOMAIN }}
run:
go build && go test -v -timeout 5m ./...

1 change: 1 addition & 0 deletions .github/workflows/build-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ jobs:
CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET }}
CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID }}
CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET }}
CHECKOUT_MERCHANT_SUBDOMAIN: ${{ secrets.IT_CHECKOUT_MERCHANT_SUBDOMAIN }}
run:
go build && go test -v -timeout 5m ./...
1 change: 1 addition & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET }}
CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID }}
CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET }}
CHECKOUT_MERCHANT_SUBDOMAIN: ${{ secrets.IT_CHECKOUT_MERCHANT_SUBDOMAIN }}
run:
go build && go test -v -timeout 5m ./...
- id: read-version
Expand Down
10 changes: 10 additions & 0 deletions abc/checkout_previous_sdk_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func (b *CheckoutPreviousSdkBuilder) WithEnvironment(environment configuration.E
return b
}

func (b *CheckoutPreviousSdkBuilder) WithEnvironmentSubdomain(subdomain string) *CheckoutPreviousSdkBuilder {
b.EnvironmentSubdomain = configuration.NewEnvironmentSubdomain(b.Environment, subdomain)
return b
}

func (b *CheckoutPreviousSdkBuilder) WithHttpClient(client *http.Client) *CheckoutPreviousSdkBuilder {
b.HttpClient = client
return b
Expand Down Expand Up @@ -47,7 +52,12 @@ func (b *CheckoutPreviousSdkBuilder) Build() (*Api, error) {
}

sdkCredentials := configuration.NewPreviousKeysSdkCredentials(b.SecretKey, b.PublicKey)

newConfiguration := configuration.NewConfiguration(sdkCredentials, b.Environment, b.HttpClient, b.Logger)

if b.EnvironmentSubdomain != nil {
newConfiguration = configuration.NewConfigurationWithSubdomain(sdkCredentials, b.Environment, b.EnvironmentSubdomain, b.HttpClient, b.Logger)
}

return CheckoutApi(newConfiguration), nil
}
42 changes: 36 additions & 6 deletions accounts/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,51 @@ package accounts

import "github.com/checkout/checkout-sdk-go/common"

type CompanyVerificationType string

const (
IncorporationDocument CompanyVerificationType = "incorporation_document"
ArticlesOfAssociation CompanyVerificationType = "articles_of_association"
)

type TaxVerificationType string

const (
EinLetter TaxVerificationType = "ein_letter"
)

type (
CompanyVerification struct {
Type CompanyVerificationType `json:"type,omitempty"`
Front string `json:"front,omitempty"`
}

TaxVerification struct {
Type TaxVerificationType `json:"type,omitempty"`
Front string `json:"front,omitempty"`
}

OnboardSubEntityDocuments struct {
IdentityVerification *Document `json:"identity_verification,omitempty"`
CompanyVerification *CompanyVerification `json:"company_verification,omitempty"`
TaxVerification *TaxVerification `json:"tax_verification,omitempty"`
}

OnboardEntityRequest struct {
Reference string `json:"reference,omitempty"`
ContactDetails *ContactDetails `json:"contact_details,omitempty"`
Profile *Profile `json:"profile,omitempty"`
Company *Company `json:"company,omitempty"`
Individual *Individual `json:"individual,omitempty"`
Reference string `json:"reference,omitempty"`
ContactDetails *ContactDetails `json:"contact_details,omitempty"`
Profile *Profile `json:"profile,omitempty"`
Company *Company `json:"company,omitempty"`
Individual *Individual `json:"individual,omitempty"`
Documents *OnboardSubEntityDocuments `json:",omitempty"`
}

OnboardEntityResponse struct {
HttpMetadata common.HttpMetadata `json:"http_metadata,omitempty"`
Id string `json:"id,omitempty"`
Reference string `json:"reference,omitempty"`
Capabilities *Capabilities `json:"capabilities,omitempty"`
Status OnboardingStatus `json:"status,omitempty"`
Capabilities *Capabilities `json:"capabilities,omitempty"`
RequirementsDue []RequirementsDue `json:"requirements_due,omitempty"`
}

Expand Down
37 changes: 33 additions & 4 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
)

type Configuration struct {
Credentials SdkCredentials
Environment Environment
HttpClient http.Client
Logger StdLogger
Credentials SdkCredentials
Environment Environment
EnvironmentSubdomain *EnvironmentSubdomain
HttpClient http.Client
Logger StdLogger
}

func NewConfiguration(
Expand Down Expand Up @@ -38,3 +39,31 @@ func NewConfiguration(
Logger: logger,
}
}

func NewConfigurationWithSubdomain(
credentials SdkCredentials,
environment Environment,
environmentSubdomain *EnvironmentSubdomain,
client *http.Client,
logger StdLogger,
) *Configuration {
if environment == nil {
environment = Sandbox()
}

if client == nil {
client = common.BuildDefaultClient()
}

if logger == nil {
logger = DefaultLogger()
}

return &Configuration{
Credentials: credentials,
Environment: environment,
EnvironmentSubdomain: environmentSubdomain,
HttpClient: *client,
Logger: logger,
}
}
31 changes: 31 additions & 0 deletions configuration/environment.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package configuration

import (
"net/url"
"regexp"
)

type Environment interface {
BaseUri() string
AuthorizationUri() string
Expand All @@ -9,6 +14,32 @@ type Environment interface {
IsSandbox() bool
}

type EnvironmentSubdomain struct {
ApiUrl string
}

func NewEnvironmentSubdomain(environment Environment, subdomain string) *EnvironmentSubdomain {
apiUrl := addSubdomainToApiUrlEnvironment(environment, subdomain)
return &EnvironmentSubdomain{ApiUrl: apiUrl}
}

func addSubdomainToApiUrlEnvironment(environment Environment, subdomain string) string {
apiUrl := environment.BaseUri()

newEnvironment := apiUrl

regex := regexp.MustCompile("^[0-9a-z]{8}$")

if regex.MatchString(subdomain) {
merchantApiUrl, _ := url.Parse(apiUrl)
merchantApiUrl.Host = subdomain + "." + merchantApiUrl.Host

newEnvironment = merchantApiUrl.String()
}

return newEnvironment
}

type CheckoutEnv struct {
baseUri string
authorizationUri string
Expand Down
7 changes: 4 additions & 3 deletions configuration/sdk_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package configuration
import "net/http"

type SdkBuilder struct {
Environment Environment
HttpClient *http.Client
Logger StdLogger
Environment Environment
EnvironmentSubdomain *EnvironmentSubdomain
HttpClient *http.Client
Logger StdLogger
}

func (s *SdkBuilder) GetConfiguration(string, string) *Configuration {
Expand Down
3 changes: 3 additions & 0 deletions nas/checkout_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func CheckoutApi(configuration *configuration.Configuration) *Api {
}

func buildBaseClient(configuration *configuration.Configuration) client.HttpClient {
if configuration.EnvironmentSubdomain != nil {
return client.NewApiClient(configuration, configuration.EnvironmentSubdomain.ApiUrl)
}
return client.NewApiClient(configuration, configuration.Environment.BaseUri())
}

Expand Down
10 changes: 10 additions & 0 deletions nas/checkout_default_sdk_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func (b *CheckoutDefaultSdkBuilder) WithEnvironment(environment configuration.En
return b
}

func (b *CheckoutDefaultSdkBuilder) WithEnvironmentSubdomain(subdomain string) *CheckoutDefaultSdkBuilder {
b.EnvironmentSubdomain = configuration.NewEnvironmentSubdomain(b.Environment, subdomain)
return b
}

func (b *CheckoutDefaultSdkBuilder) WithHttpClient(client *http.Client) *CheckoutDefaultSdkBuilder {
b.HttpClient = client
return b
Expand Down Expand Up @@ -47,7 +52,12 @@ func (b *CheckoutDefaultSdkBuilder) Build() (*Api, error) {
}

sdkCredentials := configuration.NewDefaultKeysSdkCredentials(b.SecretKey, b.PublicKey)

newConfiguration := configuration.NewConfiguration(sdkCredentials, b.Environment, b.HttpClient, b.Logger)

if b.EnvironmentSubdomain != nil {
newConfiguration = configuration.NewConfigurationWithSubdomain(sdkCredentials, b.Environment, b.EnvironmentSubdomain, b.HttpClient, b.Logger)
}

return CheckoutApi(newConfiguration), nil
}
9 changes: 9 additions & 0 deletions nas/checkout_oauth_sdk_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func (b *CheckoutOAuthSdkBuilder) WithEnvironment(environment configuration.Envi
return b
}

func (b *CheckoutOAuthSdkBuilder) WithEnvironmentSubdomain(subdomain string) *CheckoutOAuthSdkBuilder {
b.EnvironmentSubdomain = configuration.NewEnvironmentSubdomain(b.Environment, subdomain)
return b
}

func (b *CheckoutOAuthSdkBuilder) WithHttpClient(client *http.Client) *CheckoutOAuthSdkBuilder {
b.HttpClient = client
return b
Expand Down Expand Up @@ -67,5 +72,9 @@ func (b *CheckoutOAuthSdkBuilder) Build() (*Api, error) {

newConfiguration := configuration.NewConfiguration(sdkCredentials, b.Environment, b.HttpClient, b.Logger)

if b.EnvironmentSubdomain != nil {
newConfiguration = configuration.NewConfigurationWithSubdomain(sdkCredentials, b.Environment, b.EnvironmentSubdomain, b.HttpClient, b.Logger)
}

return CheckoutApi(newConfiguration), nil
}
1 change: 0 additions & 1 deletion payments/contexts/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,5 @@ type (
HttpMetadata common.HttpMetadata
PaymentRequest *PaymentContextsResponse `json:"payment_request,omitempty"`
PartnerMetadata *PaymentContextsPartnerMetadata `json:"partner_metadata,omitempty"`
Customer map[string]interface{} `json:"customer,omitempty"`
}
)
3 changes: 2 additions & 1 deletion sessions/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type (

nonHostedCompletion struct {
CompletionInfo
CallbackUrl string `json:"callback_url,omitempty"`
CallbackUrl string `json:"callback_url,omitempty"`
ChallengeNotificationUrl string `json:"challenge_notification_url,omitempty"`
}
)

Expand Down
54 changes: 54 additions & 0 deletions test/configuration_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package test

import (
"net/http"
"testing"

"github.com/stretchr/testify/assert"

"github.com/checkout/checkout-sdk-go/configuration"
"github.com/checkout/checkout-sdk-go/mocks"
)

func TestShouldCreateConfiguration(t *testing.T) {
credentials := new(mocks.CredentialsMock)
environment := configuration.Production()
subdomain := configuration.NewEnvironmentSubdomain(environment, "123dmain")
subdomainBad := configuration.NewEnvironmentSubdomain(environment, "baddomain")

cases := []struct {
name string
configuration *configuration.Configuration
checker func(*configuration.Configuration, error)
}{
{
name: "should create a configuration object",
configuration: configuration.NewConfiguration(credentials, environment, &http.Client{}, nil),
checker: func(configuration *configuration.Configuration, err error) {
assert.NotNil(t, configuration)
},
},
{
name: "should create a configuration object with a valid subdomain",
configuration: configuration.NewConfigurationWithSubdomain(credentials, environment, subdomain, &http.Client{}, nil),
checker: func(configuration *configuration.Configuration, err error) {
assert.NotNil(t, configuration)
assert.Equal(t, "https://123dmain.api.checkout.com", configuration.EnvironmentSubdomain.ApiUrl)
},
},
{
name: "should create a configuration object with a invalid subdomain",
configuration: configuration.NewConfigurationWithSubdomain(credentials, environment, subdomainBad, &http.Client{}, nil),
checker: func(configuration *configuration.Configuration, err error) {
assert.NotNil(t, configuration)
assert.Equal(t, "https://api.checkout.com", configuration.EnvironmentSubdomain.ApiUrl)
},
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
tc.checker(tc.configuration, nil)
})
}
}
Loading
Loading