-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/pimob 4287 add subdomain prefix #302
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
base: master
Are you sure you want to change the base?
Changes from all commits
ed27d58
8c5b4c9
80963da
2861377
0a5ee24
57e489a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ import com.checkout.base.model.Environment | |||||||||||||||||||||||||||
| import com.checkout.logging.EventLoggerProvider | ||||||||||||||||||||||||||||
| import com.checkout.logging.Logger | ||||||||||||||||||||||||||||
| import com.checkout.logging.model.LoggingEvent | ||||||||||||||||||||||||||||
| import com.checkout.logging.utils.toBaseUrl | ||||||||||||||||||||||||||||
| import com.checkout.network.OkHttpProvider | ||||||||||||||||||||||||||||
| import com.checkout.risk.FramesOptions | ||||||||||||||||||||||||||||
| import com.checkout.threedsecure.Executor | ||||||||||||||||||||||||||||
|
|
@@ -40,6 +41,7 @@ public object CheckoutApiServiceFactory { | |||||||||||||||||||||||||||
| publicKey: String, | ||||||||||||||||||||||||||||
| environment: Environment, | ||||||||||||||||||||||||||||
| context: Context, | ||||||||||||||||||||||||||||
| baseUrlPrefix: String? | ||||||||||||||||||||||||||||
| ): CheckoutApiService { | ||||||||||||||||||||||||||||
|
Comment on lines
+44
to
45
|
||||||||||||||||||||||||||||
| baseUrlPrefix: String? | |
| ): CheckoutApiService { | |
| ): CheckoutApiService { | |
| return create(publicKey, environment, context, null) | |
| } | |
| @JvmStatic | |
| public fun create( | |
| publicKey: String, | |
| environment: Environment, | |
| context: Context, | |
| baseUrlPrefix: String? = null, | |
| ): CheckoutApiService { |
Copilot
AI
Mar 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two spaces before { in the return type declaration (): TokenRepository {), which may be flagged by ktlint. Remove the extra whitespace to match the repo’s enforced Kotlin formatting.
| ): TokenRepository { | |
| ): TokenRepository { |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,6 @@ | ||||||||||||||||||||||||||||||||||
| package com.checkout.base.model | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import com.checkout.base.util.EnvironmentConstants | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| public enum class Environment(public val url: String) { | ||||||||||||||||||||||||||||||||||
| PRODUCTION(EnvironmentConstants.PRODUCTION_SERVER_URL), | ||||||||||||||||||||||||||||||||||
| SANDBOX(EnvironmentConstants.SANDBOX_SERVER_URL), | ||||||||||||||||||||||||||||||||||
| public enum class Environment { | ||||||||||||||||||||||||||||||||||
| PRODUCTION, | ||||||||||||||||||||||||||||||||||
| SANDBOX | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| SANDBOX | |
| SANDBOX; | |
| @Deprecated( | |
| message = "Environment.url is deprecated. Use the appropriate configuration or tokenization URL accessor instead." | |
| ) | |
| public val url: String | |
| get() = when (this) { | |
| PRODUCTION -> PRODUCTION_URL | |
| SANDBOX -> SANDBOX_URL | |
| } | |
| private companion object { | |
| private const val PRODUCTION_URL: String = "https://api.checkout.com/tokens" | |
| private const val SANDBOX_URL: String = "https://api.sandbox.checkout.com/tokens" | |
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,18 @@ | ||||||
| package com.checkout.logging.utils | ||||||
|
|
||||||
| import com.checkout.base.model.Environment | ||||||
| import com.checkout.base.util.EnvironmentConstants.PRODUCTION_SERVER_URL | ||||||
| import com.checkout.base.util.EnvironmentConstants.SANDBOX_SERVER_URL | ||||||
|
|
||||||
|
|
||||||
| internal fun Environment.toBaseUrl(baseUrlPrefix: String? = null) = when(this) { | ||||||
|
||||||
| internal fun Environment.toBaseUrl(baseUrlPrefix: String? = null) = when(this) { | |
| internal fun Environment.toBaseUrl(baseUrlPrefix: String? = null) = when (this) { |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,92 @@ | ||||||||||||||||||||||
| package com.checkout | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import com.checkout.base.model.Environment | ||||||||||||||||||||||
| import com.checkout.base.util.EnvironmentConstants | ||||||||||||||||||||||
| import com.checkout.base.util.EnvironmentConstants.PRODUCTION_SERVER_URL | ||||||||||||||||||||||
| import com.checkout.logging.utils.toBaseUrl | ||||||||||||||||||||||
| import org.junit.Assert.assertEquals | ||||||||||||||||||||||
| import org.junit.Test | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| internal class EnvironmentExtensionTest { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| fun `when toBaseUrl PRODUCTION with null subDomainPrefix returns production server URL`() { | ||||||||||||||||||||||
| val result = Environment.PRODUCTION.toBaseUrl(null) | ||||||||||||||||||||||
| assertEquals(EnvironmentConstants.PRODUCTION_SERVER_URL, result) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| fun `when toBaseUrl PRODUCTION with no subDomainPrefix argument returns production server URL`() { | ||||||||||||||||||||||
| val result = Environment.PRODUCTION.toBaseUrl() | ||||||||||||||||||||||
| assertEquals(EnvironmentConstants.PRODUCTION_SERVER_URL, result) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| fun `when toBaseUrl PRODUCTION with subDomainPrefix returns custom production URL`() { | ||||||||||||||||||||||
| val result = Environment.PRODUCTION.toBaseUrl("custom") | ||||||||||||||||||||||
| assertEquals("https://custom.api.checkout.com/tokens", result) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| fun `when toBaseUrl PRODUCTION with alphanumeric subDomainPrefix returns custom production URL`() { | ||||||||||||||||||||||
| val result = Environment.PRODUCTION.toBaseUrl("mySubdomain123") | ||||||||||||||||||||||
| assertEquals("https://mySubdomain123.api.checkout.com/tokens", result) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| fun `when toBaseUrl SANDBOX with null subDomainPrefix returns sandbox server URL`() { | ||||||||||||||||||||||
| val result = Environment.SANDBOX.toBaseUrl(null) | ||||||||||||||||||||||
| assertEquals(EnvironmentConstants.SANDBOX_SERVER_URL, result) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| fun `when toBaseUrl SANDBOX with no subDomainPrefix argument returns sandbox server URL`() { | ||||||||||||||||||||||
| val result = Environment.SANDBOX.toBaseUrl() | ||||||||||||||||||||||
| assertEquals(EnvironmentConstants.SANDBOX_SERVER_URL, result) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| fun `when toBaseUrl SANDBOX with subDomainPrefix returns custom sandbox URL`() { | ||||||||||||||||||||||
| val result = Environment.SANDBOX.toBaseUrl("custom") | ||||||||||||||||||||||
| assertEquals("https://custom.api.sandbox.checkout.com/tokens", result) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| fun `when toBaseUrl SANDBOX with alphanumeric subDomainPrefix returns custom sandbox URL`() { | ||||||||||||||||||||||
| val result = Environment.SANDBOX.toBaseUrl("test99") | ||||||||||||||||||||||
| assertEquals("https://test99.api.sandbox.checkout.com/tokens", result) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @Test | ||||||||||||||||||||||
| fun `when toBaseUrl with empty string subDomainPrefix uses default URL for production`() { | ||||||||||||||||||||||
| val result = Environment.PRODUCTION.toBaseUrl("") | ||||||||||||||||||||||
| assertEquals("https://api.checkout.com/tokens", result) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| fun `toBaseUrl PRODUCTION returns default URL for any non-alphanumeric prefix`() { | ||||||||||||||||||||||
|
||||||||||||||||||||||
| val invalidPrefixList = listOf( | ||||||||||||||||||||||
| "invalid_prefix", | ||||||||||||||||||||||
| "invalid-prefix", | ||||||||||||||||||||||
| "invalid.prefix", | ||||||||||||||||||||||
| "invalid@prefix", | ||||||||||||||||||||||
| "invalid!prefix", | ||||||||||||||||||||||
| "invalid#prefix", | ||||||||||||||||||||||
| "invalid\$prefix", | ||||||||||||||||||||||
| "invalid%prefix", | ||||||||||||||||||||||
| "invalid^prefix", | ||||||||||||||||||||||
| "invalid&prefix", | ||||||||||||||||||||||
| "invalid*prefix", | ||||||||||||||||||||||
| "invalid(prefix", | ||||||||||||||||||||||
| "invalid)prefix", | ||||||||||||||||||||||
| "invalid prefix", | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| invalidPrefixList.map { invalidPrefix -> | ||||||||||||||||||||||
| val result = Environment.PRODUCTION.toBaseUrl(invalidPrefix) | ||||||||||||||||||||||
| assertEquals( | ||||||||||||||||||||||
| result, | ||||||||||||||||||||||
| PRODUCTION_SERVER_URL, | ||||||||||||||||||||||
|
Comment on lines
+84
to
+88
|
||||||||||||||||||||||
| invalidPrefixList.map { invalidPrefix -> | |
| val result = Environment.PRODUCTION.toBaseUrl(invalidPrefix) | |
| assertEquals( | |
| result, | |
| PRODUCTION_SERVER_URL, | |
| invalidPrefixList.forEach { invalidPrefix -> | |
| val result = Environment.PRODUCTION.toBaseUrl(invalidPrefix) | |
| assertEquals( | |
| PRODUCTION_SERVER_URL, | |
| result, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A (sandbox) secret key is committed into source control via
SECRET_KEY. Even sandbox secret keys should not be checked in; replace this with a placeholder and load it from a secure local/developer-only mechanism (e.g., gradle properties/env var), and rotate/revoke the exposed key.