aboutsummaryrefslogtreecommitdiff
path: root/merchant-terminal
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-07-20 16:37:46 -0300
committerTorsten Grote <t@grobox.de>2020-07-20 16:37:46 -0300
commitc9fb036798fc533a07b4b75386b51151b31f8be0 (patch)
tree383b60c8a1f6acbba5e01c8634e45682ce50ddcf /merchant-terminal
parentde69768ac75e1608601751bd0a187e6a687dbdd2 (diff)
downloadtaler-android-c9fb036798fc533a07b4b75386b51151b31f8be0.tar.gz
taler-android-c9fb036798fc533a07b4b75386b51151b31f8be0.tar.bz2
taler-android-c9fb036798fc533a07b4b75386b51151b31f8be0.zip
[pos] create merchant-lib and move first v1 API endpoint there
Diffstat (limited to 'merchant-terminal')
-rw-r--r--merchant-terminal/build.gradle8
-rw-r--r--merchant-terminal/src/main/java/net/taler/merchantpos/MainViewModel.kt4
-rw-r--r--merchant-terminal/src/main/java/net/taler/merchantpos/config/ConfigManager.kt31
-rw-r--r--merchant-terminal/src/main/res/values/strings.xml1
4 files changed, 30 insertions, 14 deletions
diff --git a/merchant-terminal/build.gradle b/merchant-terminal/build.gradle
index 8a7eac7..2ba1a66 100644
--- a/merchant-terminal/build.gradle
+++ b/merchant-terminal/build.gradle
@@ -46,10 +46,16 @@ android {
// https://github.com/material-components/material-components-android/issues/504
ignore "WrongConstant"
}
+
+ packagingOptions {
+ exclude 'META-INF/common.kotlin_module'
+ exclude 'META-INF/*.kotlin_module'
+ }
}
dependencies {
implementation project(":taler-kotlin-common")
+ implementation project(":merchant-lib")
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
@@ -63,7 +69,7 @@ dependencies {
// HTTP Requests
implementation 'com.android.volley:volley:1.1.1'
- implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
+ implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
// JSON parsing and serialization
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.10.2"
diff --git a/merchant-terminal/src/main/java/net/taler/merchantpos/MainViewModel.kt b/merchant-terminal/src/main/java/net/taler/merchantpos/MainViewModel.kt
index 3fe472d..2dd2c24 100644
--- a/merchant-terminal/src/main/java/net/taler/merchantpos/MainViewModel.kt
+++ b/merchant-terminal/src/main/java/net/taler/merchantpos/MainViewModel.kt
@@ -23,6 +23,7 @@ import com.android.volley.toolbox.Volley
import com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
+import net.taler.merchantlib.MerchantApi
import net.taler.merchantpos.config.ConfigManager
import net.taler.merchantpos.history.HistoryManager
import net.taler.merchantpos.history.RefundManager
@@ -31,13 +32,14 @@ import net.taler.merchantpos.payment.PaymentManager
class MainViewModel(app: Application) : AndroidViewModel(app) {
+ private val api = MerchantApi()
private val mapper = ObjectMapper()
.registerModule(KotlinModule())
.configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
private val queue = Volley.newRequestQueue(app)
val orderManager = OrderManager(app, mapper)
- val configManager = ConfigManager(app, viewModelScope, mapper, queue).apply {
+ val configManager = ConfigManager(app, viewModelScope, api, mapper, queue).apply {
addConfigurationReceiver(orderManager)
}
val paymentManager = PaymentManager(configManager, queue, mapper)
diff --git a/merchant-terminal/src/main/java/net/taler/merchantpos/config/ConfigManager.kt b/merchant-terminal/src/main/java/net/taler/merchantpos/config/ConfigManager.kt
index 171cf28..eee7905 100644
--- a/merchant-terminal/src/main/java/net/taler/merchantpos/config/ConfigManager.kt
+++ b/merchant-terminal/src/main/java/net/taler/merchantpos/config/ConfigManager.kt
@@ -34,10 +34,14 @@ import com.fasterxml.jackson.module.kotlin.readValue
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
+import net.taler.merchantlib.ConfigResponse
+import net.taler.merchantlib.MerchantApi
import net.taler.merchantpos.LogErrorListener
import net.taler.merchantpos.R
import org.json.JSONObject
+private const val VERSION = "0:0:0"
+
private const val SETTINGS_NAME = "taler-merchant-terminal"
private const val SETTINGS_CONFIG_URL = "configUrl"
@@ -60,6 +64,7 @@ interface ConfigurationReceiver {
class ConfigManager(
private val context: Context,
private val scope: CoroutineScope,
+ private val api: MerchantApi,
private val mapper: ObjectMapper,
private val queue: RequestQueue
) {
@@ -114,25 +119,27 @@ class ConfigManager(
return
}
- val params = mapOf("instance" to merchantConfig.instance)
- val req = MerchantRequest(GET, merchantConfig, "config", params, null,
- Listener { onMerchantConfigReceived(config, json, merchantConfig, it) },
- LogErrorListener { onNetworkError(it) }
- )
- queue.add(req)
+ scope.launch(Dispatchers.IO) {
+ val configResponse = api.getConfig(merchantConfig.baseUrl, merchantConfig.apiKey)
+ onMerchantConfigReceived(config, json, merchantConfig, configResponse)
+ }
}
private fun onMerchantConfigReceived(
newConfig: Config?,
configJson: JSONObject,
merchantConfig: MerchantConfig,
- json: JSONObject
+ configResponse: ConfigResponse
) = scope.launch(Dispatchers.Default) {
- val currency = json.getString("currency")
-
+ // TODO do real matching
+ if (VERSION != configResponse.version) {
+ val str = context.getString(R.string.config_error_version)
+ mConfigUpdateResult.postValue(ConfigUpdateResult.Error(str))
+ return@launch
+ }
for (receiver in configurationReceivers) {
val result = try {
- receiver.onConfigurationReceived(configJson, currency)
+ receiver.onConfigurationReceived(configJson, configResponse.currency)
} catch (e: Exception) {
Log.e(TAG, "Error handling configuration by ${receiver::class.java.simpleName}", e)
context.getString(R.string.config_error_unknown)
@@ -146,8 +153,8 @@ class ConfigManager(
config = it
saveConfig(it)
}
- this@ConfigManager.merchantConfig = merchantConfig.copy(currency = currency)
- mConfigUpdateResult.postValue(ConfigUpdateResult.Success(currency))
+ this@ConfigManager.merchantConfig = merchantConfig.copy(currency = configResponse.currency)
+ mConfigUpdateResult.postValue(ConfigUpdateResult.Success(configResponse.currency))
}
fun forgetPassword() {
diff --git a/merchant-terminal/src/main/res/values/strings.xml b/merchant-terminal/src/main/res/values/strings.xml
index b3dcd8d..931f31c 100644
--- a/merchant-terminal/src/main/res/values/strings.xml
+++ b/merchant-terminal/src/main/res/values/strings.xml
@@ -22,6 +22,7 @@
<string name="config_password">Password</string>
<string name="config_ok">Fetch configuration</string>
<string name="config_auth_error">Error: Invalid username or password</string>
+ <string name="config_error_version">Error: Incompatible backend version</string>
<string name="config_error_network">Error: Could not connect to configuration server</string>
<string name="config_error_category">Error: No valid product category found</string>
<string name="config_error_malformed">Error: The configuration JSON is malformed</string>