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

Added WMTResultTexts to WMTUserOperation #160

Merged
merged 2 commits 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
4 changes: 4 additions & 0 deletions WultraMobileTokenSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
EA6DDF0F29F8036B0011E234 /* WMTPreApprovalScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA6DDF0E29F8036B0011E234 /* WMTPreApprovalScreen.swift */; };
EA6DDF1A29F804D60011E234 /* WMTPostApprovalScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA6DDF1929F804D60011E234 /* WMTPostApprovalScreen.swift */; };
EA6DDF1C29F807230011E234 /* OperationUIDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA6DDF1B29F807230011E234 /* OperationUIDataTests.swift */; };
EA74F7B32C2561BB004340B9 /* WMTResultTexts.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA74F7B22C2561BB004340B9 /* WMTResultTexts.swift */; };
EA7A6E582B0E639800C1D4F4 /* WMTOperationDetailRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7A6E572B0E639800C1D4F4 /* WMTOperationDetailRequest.swift */; };
EA9CE2BE2AEAA9FD00FE4E35 /* WMTProximityCheck.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9CE2BD2AEAA9FD00FE4E35 /* WMTProximityCheck.swift */; };
EA9CE2C22AEBDB0D00FE4E35 /* WMTPACUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9CE2C12AEBDB0D00FE4E35 /* WMTPACUtils.swift */; };
Expand Down Expand Up @@ -158,6 +159,7 @@
EA6DDF0E29F8036B0011E234 /* WMTPreApprovalScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WMTPreApprovalScreen.swift; sourceTree = "<group>"; };
EA6DDF1929F804D60011E234 /* WMTPostApprovalScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WMTPostApprovalScreen.swift; sourceTree = "<group>"; };
EA6DDF1B29F807230011E234 /* OperationUIDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperationUIDataTests.swift; sourceTree = "<group>"; };
EA74F7B22C2561BB004340B9 /* WMTResultTexts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WMTResultTexts.swift; sourceTree = "<group>"; };
EA7A6E572B0E639800C1D4F4 /* WMTOperationDetailRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WMTOperationDetailRequest.swift; sourceTree = "<group>"; };
EA9CE2BD2AEAA9FD00FE4E35 /* WMTProximityCheck.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WMTProximityCheck.swift; sourceTree = "<group>"; };
EA9CE2C12AEBDB0D00FE4E35 /* WMTPACUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WMTPACUtils.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -232,6 +234,7 @@
DCE5EAAF26BD81150061861A /* WMTOperationHistoryEntry.swift */,
EA294F3C29F6A07A00A0494E /* WMTOperationUIData.swift */,
EA9CE2BD2AEAA9FD00FE4E35 /* WMTProximityCheck.swift */,
EA74F7B22C2561BB004340B9 /* WMTResultTexts.swift */,
);
path = UserOperation;
sourceTree = "<group>";
Expand Down Expand Up @@ -612,6 +615,7 @@
DCC5CCD8244DBBBD004679AC /* WMTAuthorizationData.swift in Sources */,
DC488040292282FF00DB844B /* WMTInboxCount.swift in Sources */,
DCA43C6B29927C960059A163 /* WMTOperationAttributeAmountConversion.swift in Sources */,
EA74F7B32C2561BB004340B9 /* WMTResultTexts.swift in Sources */,
DC3D0B372480F3C7000DC4D9 /* WMTOperation.swift in Sources */,
BFEEB20B2937AD700047941D /* WMTCancellable.swift in Sources */,
DC81D1CD244F640600F80CD6 /* WMTPush.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class WMTOperationFormData: Codable {
/// Message for the user
public let message: String

/// Texts for the result of the operation
///
/// This includes messages for different outcomes of the operation such as success, rejection, and failure.
public let resultTexts: WMTResultTexts?

/// Other attributes.
///
/// Note that attributes can be presented with different classes (Starting with `WMTOperationAttribute*`) based on the attribute type.
Expand All @@ -39,6 +44,7 @@ public class WMTOperationFormData: Codable {
let c = try decoder.container(keyedBy: Keys.self)
title = try c.decode(String.self, forKey: .title)
message = try c.decode(String.self, forKey: .message)
resultTexts = try? c.decode(WMTResultTexts.self, forKey: .resultTexts)

var operationAttributes: [WMTOperationAttribute] = []
do {
Expand All @@ -59,14 +65,15 @@ public class WMTOperationFormData: Codable {
attributes = operationAttributes
}

public init(title: String, message: String, attributes: [WMTOperationAttribute]) {
public init(title: String, message: String, attributes: [WMTOperationAttribute], resultTexts: WMTResultTexts? = nil) {
self.title = title
self.message = message
self.attributes = attributes
self.resultTexts = resultTexts
}

private enum Keys: CodingKey {
case title, message, attributes
case title, message, attributes, resultTexts
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// 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.
//

import Foundation

/// Texts for the result of the operation.
///
/// This includes messages for different outcomes of the operation such as success, rejection, and failure.
public class WMTResultTexts: Codable {
Hopsaheysa marked this conversation as resolved.
Show resolved Hide resolved

/// Optional message to be displayed when the approval of the operation is successful.
public let success: String?

/// Optional message to be displayed when the operation approval or rejection fails.
public let failure: String?

/// Optional message to be displayed when the operation is rejected.
public let reject: String?

// MARK: - INTERNALS

private enum Keys: CodingKey {
case success, failure, reject
}

public required init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: Keys.self)
success = try? c.decode(String.self, forKey: .success)
failure = try? c.decode(String.self, forKey: .failure)
reject = try? c.decode(String.self, forKey: .reject)
}

public init(success: String?, failure: String?, reject: String?) {
self.success = success
self.failure = failure
self.reject = reject
}
}
33 changes: 33 additions & 0 deletions WultraMobileTokenSDKTests/NetworkingObjectsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,39 @@ class NetworkingObjectsTests: XCTestCase {
XCTAssertTrue(attributes.count == 1, "There should be one Conversion Attribute but the count is: \(attributes.count)")
XCTAssert(attributes.first is WMTOperationAttributeAmountConversion, "The First attribute should be a Conversion Attribute.")
}

func testResultTexts() {
let response = """
{"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"}, "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"}]}}, {"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"}]}}]}
"""

guard let result = try? jsonDecoder.decode(WPNResponseArray<WMTUserOperation>.self, from: response.data(using: .utf8)!) else {
XCTFail("Failed to parse JSON data")
return
}

XCTAssertNil(result.responseObject?[0].formData.resultTexts)

guard let resultTexts1 = result.responseObject?[1].formData.resultTexts else {
XCTFail("Failed to get resultTexts1")
return
}

XCTAssertEqual(resultTexts1.success, "Payment of was confirmed")
XCTAssertNil(resultTexts1.reject)
XCTAssertNil(resultTexts1.failure)

guard let resultTexts2 = result.responseObject?[2].formData.resultTexts else {
XCTFail("Failed to get resultTexts2")
return
}

let createdTexts = WMTResultTexts(success: "Payment of was confirmed", failure: "Payment approval failed", reject: "Payment was rejected")

XCTAssertEqual(resultTexts2.success, createdTexts.success)
XCTAssertEqual(resultTexts2.reject, createdTexts.reject)
XCTAssertEqual(resultTexts2.failure, createdTexts.failure)
}
}

extension WPNRequestBase {
Expand Down
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.11.0 (TBA)

- Added resultTexts to UserOperation [(#160)](https://github.com/wultra/mtoken-sdk-ios/pull/160)
- Extended PushParser to support parsing of inbox notifications [(#158)](https://github.com/wultra/mtoken-sdk-ios/pull/158)
- Added statusReason to UserOperation [(#156)](https://github.com/wultra/mtoken-sdk-ios/pull/156)

Expand Down
21 changes: 21 additions & 0 deletions docs/Using-Operations-Service.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,11 @@ public class WMTOperationFormData {

/// Message for the user
public let message: String

/// Texts for the result of the operation
///
/// This includes messages for different outcomes of the operation such as success, rejection, and failure.
public let resultTexts: WMTResultTexts?

/// Other attributes.
///
Expand All @@ -546,6 +551,22 @@ public class WMTOperationFormData {
}
```

Definition of `WMTResultTexts`:

```swift
public class WMTResultTexts: Codable {

/// Optional message to be displayed when the approval of the operation is successful.
public let success: String?

/// Optional message to be displayed when the operation approval fails.
public let failure: String?

/// Optional message to be displayed when the operation is rejected.
public let reject: String?
}
```

Attributes types:
- `AMOUNT` like "100.00 CZK"
- `KEY_VALUE` any key-value pair
Expand Down
Loading