Skip to content
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

Add ResultTexts to UserOperation #152

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
22 changes: 22 additions & 0 deletions docs/Using-Operations-Service.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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?
)
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
27 changes: 27 additions & 0 deletions library/src/test/java/OperationJsonDeserializationTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Loading