diff --git a/CHANGELOG.md b/CHANGELOG.md index 461bfd17a..534fbfa3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). # [8.9.2] - 2024-07-12 - Refactoring to accommodate using v2.0.0 of Vonage JWT library - Made `timestamp` optional in Conversion API +- Added response object to `Verify2Client.checkVerificationCode` - Fixed `SpeechSettings.Language.NEPALI` (de)serialisation - `fromRandomNumber` true if `from` is not specified in `Call.Builder` - Fixed `com.vonage.client.voice.EventWebhook` deserialisation issue diff --git a/src/main/java/com/vonage/client/verify2/Verify2Client.java b/src/main/java/com/vonage/client/verify2/Verify2Client.java index e1d23e3ef..90d7b16b2 100644 --- a/src/main/java/com/vonage/client/verify2/Verify2Client.java +++ b/src/main/java/com/vonage/client/verify2/Verify2Client.java @@ -28,7 +28,7 @@ public class Verify2Client { final boolean hasJwtAuthMethod; final RestEndpoint verifyUser; - final RestEndpoint verifyRequest; + final RestEndpoint verifyRequest; final RestEndpoint cancel, nextWorkflow; /** @@ -115,10 +115,12 @@ public VerificationResponse sendVerification(VerificationRequest request) { * @param requestId ID of the verify request, obtained from {@link VerificationResponse#getRequestId()}. * @param code The code supplied by the user. * + * @return Details of the verification request (if the code matched). + * * @throws VerifyResponseException If the code was invalid, or any other error. */ - public void checkVerificationCode(UUID requestId, String code) { - verifyRequest.execute(new VerifyCodeRequestWrapper( + public VerifyCodeResponse checkVerificationCode(UUID requestId, String code) { + return verifyRequest.execute(new VerifyCodeRequestWrapper( validateRequestId(requestId).toString(), Objects.requireNonNull(code, "Code is required.") )); diff --git a/src/main/java/com/vonage/client/verify2/VerifyCodeResponse.java b/src/main/java/com/vonage/client/verify2/VerifyCodeResponse.java new file mode 100644 index 000000000..a4c0a4f66 --- /dev/null +++ b/src/main/java/com/vonage/client/verify2/VerifyCodeResponse.java @@ -0,0 +1,52 @@ +/* + * Copyright 2024 Vonage + * + * 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.vonage.client.verify2; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.vonage.client.JsonableBaseObject; +import java.util.UUID; + +/** + * Represents the response from {@link Verify2Client#checkVerificationCode(UUID, String)}. + * + * @since 8.9.2 + */ +public final class VerifyCodeResponse extends JsonableBaseObject { + private UUID requestId; + private VerificationStatus status; + + private VerifyCodeResponse() {} + + /** + * ID of the verify request. + * + * @return The verify request ID. + */ + @JsonProperty("request_id") + public UUID getRequestId() { + return requestId; + } + + /** + * Status of the verification workflow. + * + * @return The status as an enum. + */ + @JsonProperty("status") + public VerificationStatus getStatus() { + return status; + } +} diff --git a/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java b/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java index 8839af3ec..4f957fcfd 100644 --- a/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java +++ b/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java @@ -18,6 +18,7 @@ import com.vonage.client.AbstractClientTest; import com.vonage.client.HttpWrapper; import com.vonage.client.RestEndpoint; +import com.vonage.client.TestUtils; import com.vonage.client.common.HttpMethod; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.*; @@ -28,7 +29,7 @@ import java.util.UUID; public class Verify2ClientTest extends AbstractClientTest { - static final UUID REQUEST_ID = UUID.randomUUID(); + static final UUID REQUEST_ID = UUID.fromString("90596ac8-e1f1-46a9-a80f-ebd55e2296ae"); static final String CODE = "1234"; static final String VERIFICATION_RESPONSE = "{\"request_id\": \""+REQUEST_ID+"\"}"; @@ -192,10 +193,19 @@ void testParseResponseFailureAllParams() throws Exception { } @Test - public void testVerifyCodeSuccess() throws Exception { + public void testVerifyCodeSuccessNoResponse() throws Exception { stubResponseAndRun(204, () -> client.checkVerificationCode(REQUEST_ID, CODE)); } + @Test + public void testVerifyCodeSuccess() throws Exception { + stubResponse(200, VERIFICATION_RESPONSE.replace("}", ",\"status\":\"completed\"}")); + VerifyCodeResponse parsed = client.checkVerificationCode(REQUEST_ID, CODE); + TestUtils.testJsonableBaseObject(parsed); + assertEquals(REQUEST_ID, parsed.getRequestId()); + assertEquals(VerificationStatus.COMPLETED, parsed.getStatus()); + } + @Test public void testVerifyCodeFailure() throws Exception { assert429ResponseException(() -> client.checkVerificationCode(REQUEST_ID, CODE)); @@ -212,10 +222,10 @@ public void testVerifyCodeFailure() throws Exception { @Test public void testVerifyCodeEndpoint() throws Exception { - new Verify2EndpointTestSpec() { + new Verify2EndpointTestSpec() { @Override - protected RestEndpoint endpoint() { + protected RestEndpoint endpoint() { return client.verifyRequest; }