Skip to content

Commit

Permalink
Deprecated RejectionReason enum in rejectOperation method (#130)
Browse files Browse the repository at this point in the history
* Deprecate `RejectionReason` enum  in rejectOperation method

* Fix klint

* Implement RejectionData - wrapper class which can extend RejectionReason with custom string

* Implement remarks
  • Loading branch information
Hopsaheysa authored Jan 24, 2024
1 parent bdafca8 commit 84b65e2
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/Using-Operations-Service.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ To reject an operation use `IOperationsService.rejectOperation`. Operation rejec

```kotlin
// Reject operation with some reason
fun reject(operation: IOperation, reason: RejectionReason) {
fun reject(operation: IOperation, reason: RejectionData) {
this.operationsService.rejectOperation(operation, reason) {
it.onSuccess {
// show success UI
Expand Down Expand Up @@ -390,7 +390,7 @@ All available methods and attributes of `IOperationsService` API are:
- `operation` - An operation to approve, retrieved from `getOperations` call or [created locally](#creating-a-custom-operation).
- `authentication` - PowerAuth authentication object for operation signing.
- `callback` - Called when authorization request finishes.
- `rejectOperation(operation: IOperation, reason: RejectionReason, callback: (result: Result<Unit>) -> Unit)` - Reject provided operation.
- `rejectOperation(operation: IOperation, reason: RejectionData, callback: (result: Result<Unit>) -> Unit)` - Reject provided operation.
- `operation` - An operation to reject, retrieved from `getOperations` call or [created locally](#creating-a-custom-operation).
- `reason` - Rejection reason.
- `callback` - Called when rejection request finishes.
Expand Down
5 changes: 2 additions & 3 deletions library/src/androidTest/java/IntegrationTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import com.wultra.android.mtokensdk.api.operation.model.ProximityCheckType
import com.wultra.android.mtokensdk.api.operation.model.QROperationParser
import com.wultra.android.mtokensdk.api.operation.model.UserOperation
import com.wultra.android.mtokensdk.operation.*
import com.wultra.android.mtokensdk.operation.RejectionData
import com.wultra.android.powerauth.networking.error.ApiError
import io.getlime.security.powerauth.sdk.PowerAuthAuthentication
import io.getlime.security.powerauth.sdk.PowerAuthSDK
import org.junit.*
import org.threeten.bp.ZonedDateTime
import java.lang.Exception
import java.lang.Math.abs
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -204,7 +203,7 @@ class IntegrationTests {
return
}
val opFuture = CompletableFuture<Any?>()
ops.rejectOperation(opFromList, RejectionReason.UNEXPECTED_OPERATION) { result ->
ops.rejectOperation(opFromList, RejectionData("UNEXPECTED_OPERATION")) { result ->
result.onSuccess { opFuture.complete(null) }
.onFailure { opFuture.completeExceptionally(it) }
}
Expand Down
1 change: 1 addition & 0 deletions library/src/androidTest/java/IntegrationTestsDeprecated.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.wultra.android.mtokensdk.api.operation.model.OperationHistoryEntrySta
import com.wultra.android.mtokensdk.api.operation.model.QROperationParser
import com.wultra.android.mtokensdk.api.operation.model.UserOperation
import com.wultra.android.mtokensdk.operation.*
import com.wultra.android.mtokensdk.operation.RejectionReason
import com.wultra.android.powerauth.networking.error.ApiError
import io.getlime.security.powerauth.networking.response.IActivationRemoveListener
import io.getlime.security.powerauth.sdk.PowerAuthAuthentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,10 @@ fun IOperationsService.rejectOperation(operation: IOperation, reason: RejectionR
}
}
}

@Deprecated("Enum RejectionReason is deprecated. Use RejectionData wrapper object instead") // 1.8.3
fun IOperationsService.rejectOperation(operation: IOperation, reason: RejectionReason, callback: (result: Result<Unit>) -> Unit) {
rejectOperation(operation, RejectionData(reason)) { result ->
callback(result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ interface IOperationsService {
* @param reason Rejection reason
* @param callback Callback with result.
*/
fun rejectOperation(operation: IOperation, reason: RejectionReason, callback: (result: Result<Unit>) -> Unit)
fun rejectOperation(operation: IOperation, reason: RejectionData, callback: (result: Result<Unit>) -> Unit)

/**
* Sign offline QR operation with provided authentication.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ class OperationsService: IOperationsService {
)
}

override fun rejectOperation(operation: IOperation, reason: RejectionReason, callback: (result: Result<Unit>) -> Unit) {
val rejectRequest = RejectRequest(RejectRequestObject(operation.id, reason.reason))
override fun rejectOperation(operation: IOperation, reason: RejectionData, callback: (result: Result<Unit>) -> Unit) {
val rejectRequest = RejectRequest(RejectRequestObject(operation.id, reason.serialized))
operationApi.reject(
rejectRequest,
object : IApiCallResponseListener<StatusResponse> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.operation

/**
* Wrapper class for operation rejection reason
* RejectionReason enum or custom String reason can be used
*
* @property serialized The rejection reason.
*/
class RejectionData {

/**
* The reason of the rejection.
*/
val serialized: String

/**
* Constructs a [RejectionData] with the specified reason.
*
* Represents a custom reason for rejection, allowing for flexibility in specifying rejection reasons.
* @param reason The reason for rejection as a [String], e.g., `POSSIBLE_FRAUD`.
*/
constructor(reason: String) {
this.serialized = reason
}

/**
* Constructs a [RejectionData] with the specified [RejectionReason].
*
* @param reason The [RejectionReason] for rejection.
*/
constructor(reason: RejectionReason) {
this.serialized = reason.reason
}
}

0 comments on commit 84b65e2

Please sign in to comment.