From d6d8e9dc078f96d53c615b41b7d54a8934f01f8e Mon Sep 17 00:00:00 2001 From: Marek Stransky Date: Mon, 24 Jun 2024 10:00:00 +0200 Subject: [PATCH] Add Result texts to UserOpertation --- docs/Changelog.md | 2 + docs/Using-Operations-Service.md | 22 +++++++++++ .../api/operation/model/ResultTexts.kt | 38 +++++++++++++++++++ .../api/operation/model/UserOperation.kt | 8 ++++ .../java/OperationJsonDeserializationTests.kt | 27 +++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/ResultTexts.kt diff --git a/docs/Changelog.md b/docs/Changelog.md index 4a6192f..cca8137 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,6 +1,8 @@ # Changelog ## 1.12.0 (TBA) + +- Added resultTexts to UserOperation [(#152)](https://github.com/wultra/mtoken-sdk-ios/pull/152) - Extended PushParser to support parsing of inbox notifications [(#150)](https://github.com/wultra/mtoken-sdk-android/pull/150) - Added statusReason to UserOperation [(#148)](https://github.com/wultra/mtoken-sdk-android/pull/148) diff --git a/docs/Using-Operations-Service.md b/docs/Using-Operations-Service.md index 199188d..3aee587 100644 --- a/docs/Using-Operations-Service.md +++ b/docs/Using-Operations-Service.md @@ -491,6 +491,13 @@ class FormData { /** Message for the user */ val message: String + + /** + * Texts for the result of the operation + * + * This includes messages for different outcomes of the operation such as success, rejection, and failure. + */ + val resultTexts: ResultTexts? /** * Other attributes. @@ -502,6 +509,21 @@ class FormData { } ``` +Definition of `ResultTexts`: + +```kotlin +class ResultTexts( + /** Optional message to be displayed when the approval of the operation is successful. */ + val success: String?, + + /** Optional message to be displayed when the operation approval or rejection fails. */ + val failure: String?, + + /** Optional message to be displayed when the operation is rejected. */ + val reject: String? +) +``` + Attributes types: - `AMOUNT` like "100.00 CZK" - `KEY_VALUE` any key-value pair diff --git a/library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/ResultTexts.kt b/library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/ResultTexts.kt new file mode 100644 index 0000000..dcb3410 --- /dev/null +++ b/library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/ResultTexts.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2024 Wultra s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions + * and limitations under the License. + */ + +package com.wultra.android.mtokensdk.api.operation.model + +import com.google.gson.annotations.SerializedName + +/** + * Texts for the result of the operation. + * + * This includes messages for different outcomes of the operation such as success, rejection, and failure. + */ +data class ResultTexts( + /** Optional message to be displayed when the approval of the operation is successful. */ + @SerializedName("success") + val success: String?, + + /** Optional message to be displayed when the operation approval or rejection fails. */ + @SerializedName("failure") + val failure: String?, + + /** Optional message to be displayed when the operation is rejected. */ + @SerializedName("reject") + val reject: String? +) diff --git a/library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/UserOperation.kt b/library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/UserOperation.kt index c0eaf95..b85837f 100644 --- a/library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/UserOperation.kt +++ b/library/src/main/java/com/wultra/android/mtokensdk/api/operation/model/UserOperation.kt @@ -156,6 +156,14 @@ data class FormData( @SerializedName("message") val message: String, + /** + * Texts for the result of the operation + * + * This includes messages for different outcomes of the operation such as success, rejection, and failure. + */ + @SerializedName("resultTexts") + val resultTexts: ResultTexts?, + /** * Other attributes. * diff --git a/library/src/test/java/OperationJsonDeserializationTests.kt b/library/src/test/java/OperationJsonDeserializationTests.kt index 892274b..0484acb 100644 --- a/library/src/test/java/OperationJsonDeserializationTests.kt +++ b/library/src/test/java/OperationJsonDeserializationTests.kt @@ -367,4 +367,31 @@ class OperationJsonDeserializationTests { assert(resp.responseObject.find { it.status == status } != null) } } + + @Test + fun `test result texts`() { + + val json = """ + {"status":"OK", "currentTimestamp":"2023-02-10T12:30:42+0000", "responseObject":[{"id":"930febe7-f350-419a-8bc0-c8883e7f71e3", "name":"authorize_payment", "data":"A1*A100CZK*Q238400856/0300**D20170629*NUtility Bill Payment - 05/2017", "operationCreated":"2018-08-08T12:30:42+0000", "operationExpires":"2018-08-08T12:35:43+0000", "allowedSignatureType": {"type":"2FA", "variants": ["possession_knowledge", "possession_biometry"]}, "formData": {"title":"Potvrzení platby", "message":"Dobrý den,prosíme o potvrzení následující platby:", "attributes": [{"type":"AMOUNT", "id":"operation.amount", "label":"Částka", "currency":"CZK"}, { "type": "AMOUNT_CONVERSION", "id": "operation.conversion", "label": "Conversion", "dynamic": true, "sourceAmount": 1.26, "sourceCurrency": "ETC", "targetAmount": 1710.98, "targetCurrency": "USD"}]}}, {"id":"930febe7-f350-419a-8bc0-c8883e7f71e3", "name":"authorize_payment", "data":"A1*A100CZK*Q238400856/0300**D20170629*NUtility Bill Payment - 05/2017", "operationCreated":"2018-08-08T12:30:42+0000", "operationExpires":"2018-08-08T12:35:43+0000", "allowedSignatureType": {"type":"2FA", "variants": ["possession_knowledge", "possession_biometry"]}, "formData": {"title":"Potvrzení platby", "message":"Dobrý den,prosíme o potvrzení následující platby:", "resultTexts": {"success": "Payment of was confirmed"}, "attributes": [{"type":"AMOUNT", "id":"operation.amount", "label":"Částka", "currency":"CZK"}, { "type": "AMOUNT_CONVERSION", "id": "operation.conversion", "label": "Conversion", "dynamic": true, "sourceAmount": 1.26, "sourceCurrency": "ETC", "targetAmount": 1710.98, "targetCurrency": "USD"}]}}, {"id":"930febe7-f350-419a-8bc0-c8883e7f71e3", "name":"authorize_payment", "data":"A1*A100CZK*Q238400856/0300**D20170629*NUtility Bill Payment - 05/2017", "operationCreated":"2018-08-08T12:30:42+0000", "operationExpires":"2018-08-08T12:35:43+0000", "allowedSignatureType": {"type":"2FA", "variants": ["possession_knowledge", "possession_biometry"]}, "formData": {"title":"Potvrzení platby", "message":"Dobrý den,prosíme o potvrzení následující platby:", "resultTexts": {"success": "Payment of was confirmed", "reject": "Payment was rejected", "failure": "Payment approval failed"},"attributes": [{"type":"AMOUNT", "id":"operation.amount", "label":"Částka", "currency":"CZK"}, { "type": "AMOUNT_CONVERSION", "id": "operation.conversion", "label": "Conversion", "dynamic": true, "sourceAmount": 1.26, "sourceCurrency": "ETC", "targetAmount": 1710.98, "targetCurrency": "USD"}]}}]} + """ + val response = typeAdapter.fromJson(json) + Assert.assertNotNull("Failed to parse JSON data", response) + + val responseObject = response?.responseObject + Assert.assertNotNull("Response object is null", responseObject) + + Assert.assertNull(responseObject?.get(0)?.formData?.resultTexts) + + val resultTexts1 = responseObject?.get(1)?.formData?.resultTexts + Assert.assertNotNull("Failed to get resultTexts1", resultTexts1) + Assert.assertEquals("Payment of was confirmed", resultTexts1?.success) + Assert.assertNull(resultTexts1?.reject) + Assert.assertNull(resultTexts1?.failure) + + val resultTexts2 = responseObject?.get(2)?.formData?.resultTexts + Assert.assertNotNull("Failed to get resultTexts2", resultTexts2) + Assert.assertEquals("Payment of was confirmed", resultTexts2?.success) + Assert.assertEquals("Payment was rejected", resultTexts2?.reject) + Assert.assertEquals("Payment approval failed", resultTexts2?.failure) + } }