From 34b41090f0d0e9a47e181fc56d030ab3afa52941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:43:40 +0100 Subject: [PATCH 1/4] Add documents to OnboardEntityRequest --- accounts/entities.go | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/accounts/entities.go b/accounts/entities.go index 31da7b2..e6e1bcb 100644 --- a/accounts/entities.go +++ b/accounts/entities.go @@ -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"` } From a411abe065e818fa7bcbf48c4465397508b2a16c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:44:20 +0100 Subject: [PATCH 2/4] Add ChallengeNotificationUrl to nonHostedCompletion --- sessions/completion/completion.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sessions/completion/completion.go b/sessions/completion/completion.go index 4460555..9dd034a 100644 --- a/sessions/completion/completion.go +++ b/sessions/completion/completion.go @@ -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"` } ) From 293ebd4289c27ff588c3888adc5027dec7e11e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:44:43 +0100 Subject: [PATCH 3/4] Update PaymentContextDetailsResponse --- payments/contexts/contexts.go | 1 - 1 file changed, 1 deletion(-) diff --git a/payments/contexts/contexts.go b/payments/contexts/contexts.go index 787455b..9d3c34f 100644 --- a/payments/contexts/contexts.go +++ b/payments/contexts/contexts.go @@ -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"` } ) From a60c0bcbbd35314d6469de8ceb64907a666a007b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:46:40 +0100 Subject: [PATCH 4/4] Add subdomain for merchants --- .github/workflows/build-master.yml | 1 + .github/workflows/build-pull-request.yml | 1 + .github/workflows/build-release.yml | 1 + abc/checkout_previous_sdk_builder.go | 10 ++++ configuration/configuration.go | 37 ++++++++++-- configuration/environment.go | 31 ++++++++++ configuration/sdk_builder.go | 7 ++- nas/checkout_api.go | 3 + nas/checkout_default_sdk_builder.go | 10 ++++ nas/checkout_oauth_sdk_builder.go | 9 +++ test/configuration_api_test.go | 54 +++++++++++++++++ test/default_sdk_api_test.go | 71 +++++++++++++++++++++++ test/oauth_sdk_api_test.go | 74 ++++++++++++++++++++++++ test/previous_sdk_api_test.go | 71 +++++++++++++++++++++++ 14 files changed, 373 insertions(+), 7 deletions(-) create mode 100644 test/configuration_api_test.go create mode 100644 test/default_sdk_api_test.go create mode 100644 test/oauth_sdk_api_test.go create mode 100644 test/previous_sdk_api_test.go diff --git a/.github/workflows/build-master.yml b/.github/workflows/build-master.yml index 6ac37f9..6d250bf 100644 --- a/.github/workflows/build-master.yml +++ b/.github/workflows/build-master.yml @@ -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 ./... diff --git a/.github/workflows/build-pull-request.yml b/.github/workflows/build-pull-request.yml index 29f72f1..7429916 100644 --- a/.github/workflows/build-pull-request.yml +++ b/.github/workflows/build-pull-request.yml @@ -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 ./... diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 0b75ac2..a63866c 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -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 diff --git a/abc/checkout_previous_sdk_builder.go b/abc/checkout_previous_sdk_builder.go index c54bb2c..ea54e0f 100644 --- a/abc/checkout_previous_sdk_builder.go +++ b/abc/checkout_previous_sdk_builder.go @@ -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 @@ -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 } diff --git a/configuration/configuration.go b/configuration/configuration.go index 241d362..ee4aa78 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -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( @@ -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, + } +} diff --git a/configuration/environment.go b/configuration/environment.go index 723652d..49fa9ed 100644 --- a/configuration/environment.go +++ b/configuration/environment.go @@ -1,5 +1,10 @@ package configuration +import ( + "net/url" + "regexp" +) + type Environment interface { BaseUri() string AuthorizationUri() string @@ -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 diff --git a/configuration/sdk_builder.go b/configuration/sdk_builder.go index e7fc63d..d29fdfc 100644 --- a/configuration/sdk_builder.go +++ b/configuration/sdk_builder.go @@ -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 { diff --git a/nas/checkout_api.go b/nas/checkout_api.go index 27afd43..6e9bbdb 100644 --- a/nas/checkout_api.go +++ b/nas/checkout_api.go @@ -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()) } diff --git a/nas/checkout_default_sdk_builder.go b/nas/checkout_default_sdk_builder.go index 44778c5..1075424 100644 --- a/nas/checkout_default_sdk_builder.go +++ b/nas/checkout_default_sdk_builder.go @@ -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 @@ -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 } diff --git a/nas/checkout_oauth_sdk_builder.go b/nas/checkout_oauth_sdk_builder.go index 45c9716..c427ccc 100644 --- a/nas/checkout_oauth_sdk_builder.go +++ b/nas/checkout_oauth_sdk_builder.go @@ -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 @@ -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 } diff --git a/test/configuration_api_test.go b/test/configuration_api_test.go new file mode 100644 index 0000000..061731a --- /dev/null +++ b/test/configuration_api_test.go @@ -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) + }) + } +} diff --git a/test/default_sdk_api_test.go b/test/default_sdk_api_test.go new file mode 100644 index 0000000..717d7ec --- /dev/null +++ b/test/default_sdk_api_test.go @@ -0,0 +1,71 @@ +package test + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/checkout/checkout-sdk-go" + "github.com/checkout/checkout-sdk-go/configuration" + "github.com/checkout/checkout-sdk-go/nas" +) + +func TestDefaultCheckoutSdks(t *testing.T) { + var defaultApi, _ = checkout.Builder(). + StaticKeys(). + WithSecretKey(os.Getenv("CHECKOUT_DEFAULT_SECRET_KEY")). + WithPublicKey(os.Getenv("CHECKOUT_DEFAULT_PUBLIC_KEY")). + WithEnvironment(configuration.Sandbox()). + Build() + + var defaultApiSubdomain, _ = checkout.Builder(). + StaticKeys(). + WithSecretKey(os.Getenv("CHECKOUT_DEFAULT_SECRET_KEY")). + WithPublicKey(os.Getenv("CHECKOUT_DEFAULT_PUBLIC_KEY")). + WithEnvironment(configuration.Sandbox()). + WithEnvironmentSubdomain("123dmain"). + Build() + + var defaultApiBad, _ = checkout.Builder(). + StaticKeys(). + WithSecretKey("error"). + WithPublicKey("error"). + WithEnvironment(configuration.Sandbox()). + Build() + + cases := []struct { + name string + defaultApi *nas.Api + checker func(*nas.Api, error) + }{ + { + name: "should create a default checkout sdk api object", + defaultApi: defaultApi, + checker: func(token *nas.Api, err error) { + assert.NotNil(t, defaultApi) + }, + }, + { + name: "should create a default checkout sdk api object with valid subdomain", + defaultApi: defaultApiSubdomain, + checker: func(token *nas.Api, err error) { + assert.NotNil(t, defaultApiSubdomain) + }, + }, + { + name: "should fail a default checkout sdk api object", + defaultApi: defaultApiBad, + checker: func(token *nas.Api, err error) { + assert.Nil(t, defaultApiBad) + }, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + tc.checker(tc.defaultApi, nil) + }) + } + +} diff --git a/test/oauth_sdk_api_test.go b/test/oauth_sdk_api_test.go new file mode 100644 index 0000000..1e1e74a --- /dev/null +++ b/test/oauth_sdk_api_test.go @@ -0,0 +1,74 @@ +package test + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/checkout/checkout-sdk-go" + "github.com/checkout/checkout-sdk-go/configuration" + "github.com/checkout/checkout-sdk-go/nas" +) + +func TestOauthCheckoutSdks(t *testing.T) { + var oauthApi, _ = checkout.Builder(). + OAuth(). + WithClientCredentials( + os.Getenv("CHECKOUT_DEFAULT_OAUTH_CLIENT_ID"), + os.Getenv("CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET")). + WithEnvironment(configuration.Sandbox()). + Build() + + var oauthApiSubdomain, _ = checkout.Builder(). + OAuth(). + WithClientCredentials( + os.Getenv("CHECKOUT_DEFAULT_OAUTH_CLIENT_ID"), + os.Getenv("CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET")). + WithEnvironment(configuration.Sandbox()). + WithEnvironmentSubdomain("123dmain"). + Build() + + var oauthApiBad, _ = checkout.Builder(). + OAuth(). + WithClientCredentials( + "error", + "error"). + WithEnvironment(configuration.Sandbox()). + Build() + + cases := []struct { + name string + oauthApi *nas.Api + checker func(*nas.Api, error) + }{ + { + name: "should create a oauth checkout sdk api object", + oauthApi: oauthApi, + checker: func(token *nas.Api, err error) { + assert.NotNil(t, oauthApi) + }, + }, + { + name: "should create a oauth checkout sdk api object with valid subdomain", + oauthApi: oauthApiSubdomain, + checker: func(token *nas.Api, err error) { + assert.NotNil(t, oauthApiSubdomain) + }, + }, + { + name: "should fail a oauth checkout sdk api object", + oauthApi: oauthApiBad, + checker: func(token *nas.Api, err error) { + assert.Nil(t, oauthApiBad) + }, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + tc.checker(tc.oauthApi, nil) + }) + } + +} diff --git a/test/previous_sdk_api_test.go b/test/previous_sdk_api_test.go new file mode 100644 index 0000000..3cd6fde --- /dev/null +++ b/test/previous_sdk_api_test.go @@ -0,0 +1,71 @@ +package test + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/checkout/checkout-sdk-go" + "github.com/checkout/checkout-sdk-go/abc" + "github.com/checkout/checkout-sdk-go/configuration" +) + +func TestPreviousCheckoutSdks(t *testing.T) { + var previousApi, _ = checkout.Builder(). + Previous(). + WithSecretKey(os.Getenv("CHECKOUT_PREVIOUS_SECRET_KEY")). + WithPublicKey(os.Getenv("CHECKOUT_PREVIOUS_PUBLIC_KEY")). + WithEnvironment(configuration.Sandbox()). + Build() + + var previousApiSubdomain, _ = checkout.Builder(). + Previous(). + WithSecretKey(os.Getenv("CHECKOUT_PREVIOUS_SECRET_KEY")). + WithPublicKey(os.Getenv("CHECKOUT_PREVIOUS_PUBLIC_KEY")). + WithEnvironment(configuration.Sandbox()). + WithEnvironmentSubdomain("123dmain"). + Build() + + var previousApiBad, _ = checkout.Builder(). + Previous(). + WithSecretKey("error"). + WithPublicKey("error"). + WithEnvironment(configuration.Sandbox()). + Build() + + cases := []struct { + name string + previousApi *abc.Api + checker func(*abc.Api, error) + }{ + { + name: "should create a previous checkout sdk api object", + previousApi: previousApi, + checker: func(token *abc.Api, err error) { + assert.NotNil(t, previousApi) + }, + }, + { + name: "should create a previous checkout sdk api object with valid subdomain", + previousApi: previousApiSubdomain, + checker: func(token *abc.Api, err error) { + assert.NotNil(t, previousApiSubdomain) + }, + }, + { + name: "should fail a previous checkout sdk api object", + previousApi: previousApiBad, + checker: func(token *abc.Api, err error) { + assert.Nil(t, previousApiBad) + }, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + tc.checker(tc.previousApi, nil) + }) + } + +}