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

Deprecated reject method with Reject enum and replace it with String #143

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class WMTRejectionData: Codable {
let id: String

/// Rejection reason
let reason: WMTRejectionReason
let reason: String

init(operationId: String, reason: WMTRejectionReason) {
self.id = operationId
self.reason = reason
self.reason = reason.serialized
}
}
21 changes: 16 additions & 5 deletions WultraMobileTokenSDK/Operations/Model/WMTRejectionReason.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@
import Foundation

/// Reason why the operation will be rejected
public enum WMTRejectionReason: String, Codable {
/// User don't want to provide the reason.
case unknown = "UNKNOWN"
public enum WMTRejectionReason {
/// User doesn't want to provide the reason.
case unknown
/// Operation data does not match (for example when user found a typo or other mistake)
case incorrectData = "INCORRECT_DATA"
case incorrectData
/// User didn't started this operation
case unexpectedOperation = "UNEXPECTED_OPERATION"
case unexpectedOperation // = "UNEXPECTED_OPERATION"
Hopsaheysa marked this conversation as resolved.
Show resolved Hide resolved
/// Custom reason of rejection
Hopsaheysa marked this conversation as resolved.
Show resolved Hide resolved
case custom(_ reason: String)

var serialized: String {
return switch self {
case .unknown: "UNKNOWN"
case .incorrectData: "INCORRECT_DATA"
case .unexpectedOperation: "UNEXPECTED_OPERATION"
case .custom(let reason): reason
}
}
}
4 changes: 2 additions & 2 deletions WultraMobileTokenSDKTests/NetworkingObjectsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ class NetworkingObjectsTests: XCTestCase {
func testOperationRejectionRequest() {

let expectation = """
{"requestObject":{"id":"95e51995-fa60-4018-bd87-43a58f098570","reason":"UNEXPECTED_OPERATION"}}
{"requestObject":{"id":"95e51995-fa60-4018-bd87-43a58f098570","reason":"COMPLETELLY_CUSTOM_REJECT_REASON"}}
"""

let request = WMTOperationEndpoints.Reject.EndpointType.RequestData(.init(operationId: "95e51995-fa60-4018-bd87-43a58f098570", reason: .unexpectedOperation))
let request = WMTOperationEndpoints.Reject.EndpointType.RequestData(.init(operationId: "95e51995-fa60-4018-bd87-43a58f098570", reason: .custom("COMPLETELLY_CUSTOM_REJECT_REASON")))
request.testSerialization(expectation: expectation)
}

Expand Down
4 changes: 2 additions & 2 deletions docs/Using-Operations-Service.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ func approveWithBiometry(operation: WMTOperation) {

## Reject an Operation

To reject an operation use `WMTOperations.reject`. Operation rejection is confirmed by possession factor so there is no need for creating `PowerAuthAuthentication` object. You can simply use it with the following example.
To reject an operation use `WMTOperations.reject`. Operation rejection is confirmed by a possession factor, so there is no need for creating a `PowerAuthAuthentication` object. You can simply use it with the following example.

```swift
import WultraMobileTokenSDK
import PowerAuth2

// Reject operation with some reason
func reject(operation: WMTOperation, reason: WMTRejectionReason) {
func reject(operation: WMTOperation, reason: String) {
Hopsaheysa marked this conversation as resolved.
Show resolved Hide resolved
operationService.reject(operation: operation, reason: reason) { error in
if let error = error {
// show error UI
Expand Down
Loading