Skip to content

Commit

Permalink
Move ForageConfig to core.services
Browse files Browse the repository at this point in the history
ForageConfig while, often consumed by UI components, is a standalone
data structure making the .services package a more appropriate home.
This also aligns things well with the Pos SDK because the
ForageTerminalSDK, a service, consumes the ForageConfig. And, while UI
may depend on services, services should never depend on UI facilities
(else it ought to live in .ui!!)

Signed-off-by: Devin Morgan <[email protected]>
  • Loading branch information
devinmorgan committed Jun 13, 2024
1 parent 67cada7 commit 7a0a4df
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.joinforage.forage.android.core.services

import com.joinforage.forage.android.BuildConfig
import com.joinforage.forage.android.core.ui.element.ForageConfig

internal enum class EnvOption(val value: String) {
LOCAL("local"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.joinforage.forage.android.core.services

/**
* The configuration details that Forage needs to create a functional [ForageElement].
*
* Pass a [ForageConfig] instance in a call to
* [setForageConfig][com.joinforage.forage.android.ui.ForageElement.setForageConfig] to
* configure an Element.
*
* @property merchantId A unique Merchant ID that Forage provides during onboarding
* onboarding preceded by "mid/". For example, `mid/123ab45c67`.
* The Merchant ID can be found in the Forage [Sandbox](https://dashboard.sandbox.joinforage.app/login/)
* or [Production](https://dashboard.joinforage.app/login/) Dashboard.
*
* @property sessionToken A short-lived token that authenticates front-end requests to Forage.
* To create one, send a server-side `POST` request from your backend to the
* [`/session_token/`](https://docs.joinforage.app/reference/create-session-token) endpoint.
*
* @constructor Creates an instance of the [ForageConfig] data class.
*/
data class ForageConfig(
val merchantId: String,
val sessionToken: String
) {
internal val envConfig = EnvConfig.fromForageConfig(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.joinforage.datadog.android.log.Logs
import com.joinforage.datadog.android.log.LogsConfiguration
import com.joinforage.datadog.android.privacy.TrackingConsent
import com.joinforage.forage.android.core.services.EnvConfig
import com.joinforage.forage.android.core.ui.element.ForageConfig
import com.joinforage.forage.android.core.services.ForageConfig
import kotlin.random.Random

internal interface Log {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.joinforage.forage.android.core.ui.element

import com.joinforage.forage.android.core.services.ForageConfig

internal class ForageConfigManager(
// designated method that subclass can run all the
// side-effect things exactly once the first time
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
package com.joinforage.forage.android.core.ui.element

import android.graphics.Typeface
import com.joinforage.forage.android.core.services.EnvConfig
import com.joinforage.forage.android.core.services.ForageConfig
import com.joinforage.forage.android.core.ui.element.state.ElementState

/**
* The configuration details that Forage needs to create a functional [ForageElement].
*
* Pass a [ForageConfig] instance in a call to
* [setForageConfig][com.joinforage.forage.android.ui.ForageElement.setForageConfig] to
* configure an Element.
*
* @property merchantId A unique Merchant ID that Forage provides during onboarding
* onboarding preceded by "mid/". For example, `mid/123ab45c67`.
* The Merchant ID can be found in the Forage [Sandbox](https://dashboard.sandbox.joinforage.app/login/)
* or [Production](https://dashboard.joinforage.app/login/) Dashboard.
*
* @property sessionToken A short-lived token that authenticates front-end requests to Forage.
* To create one, send a server-side `POST` request from your backend to the
* [`/session_token/`](https://docs.joinforage.app/reference/create-session-token) endpoint.
*
* @constructor Creates an instance of the [ForageConfig] data class.
*/
data class ForageConfig(
val merchantId: String,
val sessionToken: String
) {
internal val envConfig = EnvConfig.fromForageConfig(this)
}

interface DynamicEnvElement {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.joinforage.forage.android.R
import com.joinforage.forage.android.core.services.EnvConfig
import com.joinforage.forage.android.core.services.ForageConfig
import com.joinforage.forage.android.core.services.ForageConfigNotSetException
import com.joinforage.forage.android.core.services.telemetry.Log
import com.joinforage.forage.android.core.ui.element.state.FocusState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.joinforage.forage.android.ecom.services

import com.joinforage.forage.android.core.services.EnvConfig
import com.joinforage.forage.android.core.services.ForageConfig
import com.joinforage.forage.android.core.services.ForageConfigNotSetException
import com.joinforage.forage.android.core.services.forageapi.encryptkey.EncryptionKeyService
import com.joinforage.forage.android.core.services.forageapi.network.ForageApiResponse
Expand All @@ -17,7 +18,6 @@ import com.joinforage.forage.android.core.services.vault.CapturePaymentRepositor
import com.joinforage.forage.android.core.services.vault.CheckBalanceRepository
import com.joinforage.forage.android.core.services.vault.DeferPaymentCaptureRepository
import com.joinforage.forage.android.core.services.vault.TokenizeCardService
import com.joinforage.forage.android.core.ui.element.ForageConfig
import com.joinforage.forage.android.core.ui.element.ForagePanElement
import com.joinforage.forage.android.ecom.ui.element.ForagePINEditText

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import android.graphics.Typeface
import android.util.AttributeSet
import com.joinforage.forage.android.R
import com.joinforage.forage.android.core.services.EnvConfig
import com.joinforage.forage.android.core.services.ForageConfig
import com.joinforage.forage.android.core.services.ForageConfigNotSetException
import com.joinforage.forage.android.core.services.VaultType
import com.joinforage.forage.android.core.services.launchdarkly.LDManager
import com.joinforage.forage.android.core.services.telemetry.Log
import com.joinforage.forage.android.core.services.vault.AbstractVaultSubmitter
import com.joinforage.forage.android.core.ui.VaultWrapper
import com.joinforage.forage.android.core.ui.element.DynamicEnvElement
import com.joinforage.forage.android.core.ui.element.ForageConfig
import com.joinforage.forage.android.core.ui.element.ForageConfigManager
import com.joinforage.forage.android.core.ui.element.ForagePinElement
import com.joinforage.forage.android.core.ui.getLogoImageViewLayout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.joinforage.forage.android.core.env

import com.joinforage.forage.android.core.services.EnvConfig
import com.joinforage.forage.android.core.ui.element.ForageConfig
import com.joinforage.forage.android.core.services.ForageConfig
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.joinforage.forage.android.mock

import android.content.Context
import com.joinforage.forage.android.core.services.ForageConfig
import com.joinforage.forage.android.core.services.telemetry.Log
import com.joinforage.forage.android.core.ui.element.ForageConfig

internal class LogEntry(message: String, attributes: Map<String, Any?>) {
private var message = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.joinforage.forage.android.ui

import com.joinforage.forage.android.core.ui.element.ForageConfig
import com.joinforage.forage.android.core.services.ForageConfig
import com.joinforage.forage.android.core.ui.element.ForageConfigManager
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.joinforage.android.example.databinding.FragmentCatalogBinding
import com.joinforage.forage.android.core.ui.element.ForageConfig
import com.joinforage.forage.android.core.services.ForageConfig

class CatalogFragment : Fragment() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.joinforage.android.example.databinding.FragmentFlowBalanceBinding
import com.joinforage.android.example.ext.hideKeyboard
import com.joinforage.forage.android.core.ui.element.ForageConfig
import com.joinforage.forage.android.core.services.ForageConfig
import com.joinforage.forage.android.ecom.ui.element.ForagePINEditText
import dagger.hilt.android.AndroidEntryPoint

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.joinforage.android.example.R
import com.joinforage.android.example.databinding.FragmentFlowCapturePaymentBinding
import com.joinforage.android.example.ext.hideKeyboard
import com.joinforage.android.example.ui.base.BaseFragment
import com.joinforage.forage.android.core.ui.element.ForageConfig
import com.joinforage.forage.android.core.services.ForageConfig
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.joinforage.android.example.databinding.FragmentFlowTokenizeBinding
import com.joinforage.android.example.ext.hideKeyboard
import com.joinforage.forage.android.core.ui.element.ForageConfig
import com.joinforage.forage.android.core.services.ForageConfig
import com.joinforage.forage.android.ecom.ui.element.ForagePANEditText
import dagger.hilt.android.AndroidEntryPoint

Expand Down

0 comments on commit 7a0a4df

Please sign in to comment.