Skip to content

Commit

Permalink
Merge branch 'develop' into issues/161-templates
Browse files Browse the repository at this point in the history
# Conflicts:
#	WultraMobileTokenSDK.xcodeproj/project.pbxproj
#	docs/Changelog.md
  • Loading branch information
Hopsaheysa committed Jun 27, 2024
2 parents 17b190c + 466f443 commit 68d843d
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 2 deletions.
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 */; };
EA9795132C2C18450073E861 /* WMTTemplates.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9795122C2C18450073E861 /* WMTTemplates.swift */; };
EA9CE2BE2AEAA9FD00FE4E35 /* WMTProximityCheck.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9CE2BD2AEAA9FD00FE4E35 /* WMTProximityCheck.swift */; };
Expand Down Expand Up @@ -159,6 +160,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>"; };
EA9795122C2C18450073E861 /* WMTTemplates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WMTTemplates.swift; sourceTree = "<group>"; };
EA9CE2BD2AEAA9FD00FE4E35 /* WMTProximityCheck.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WMTProximityCheck.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -234,6 +236,7 @@
DCE5EAAF26BD81150061861A /* WMTOperationHistoryEntry.swift */,
EA294F3C29F6A07A00A0494E /* WMTOperationUIData.swift */,
EA9CE2BD2AEAA9FD00FE4E35 /* WMTProximityCheck.swift */,
EA74F7B22C2561BB004340B9 /* WMTResultTexts.swift */,
EA9795122C2C18450073E861 /* WMTTemplates.swift */,
);
path = UserOperation;
Expand Down Expand Up @@ -615,6 +618,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 {

/// 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 @@ -3,6 +3,7 @@
## 1.11.0 (TBA)

- Added WMTTemplates to WMTOperationUIData [(#162)](https://github.com/wultra/mtoken-sdk-ios/pull/162)
- 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

0 comments on commit 68d843d

Please sign in to comment.