001/* 002 * Copyright 2024 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.verify; 017 018import com.fasterxml.jackson.annotation.JsonProperty; 019import com.vonage.client.Jsonable; 020import com.vonage.client.JsonableBaseObject; 021import com.vonage.client.VonageResponseParseException; 022import java.math.BigDecimal; 023 024public class CheckResponse extends JsonableBaseObject { 025 private VerifyStatus status; 026 private String requestId, eventId, currency, errorText; 027 private BigDecimal price, estimatedPriceMessagesSent; 028 029 private CheckResponse() { 030 } 031 032 public CheckResponse(VerifyStatus status) { 033 this.status = status; 034 } 035 036 /** 037 * @return The {@code request_id} that you received in the response to the Verify request 038 * and used in the Verify check request. 039 */ 040 @JsonProperty("request_id") 041 public String getRequestId() { 042 return requestId; 043 } 044 045 /** 046 * @return The ID of the verification event, such as an SMS or TTS call. 047 */ 048 @JsonProperty("event_id") 049 public String getEventId() { 050 return eventId; 051 } 052 053 /** 054 * @return A value of {@link VerifyStatus#OK} indicates that your user entered the correct code. 055 * Otherwise, check {@link #getErrorText()}. 056 */ 057 @JsonProperty("status") 058 public VerifyStatus getStatus() { 059 return status; 060 } 061 062 /** 063 * @return The cost incurred for this request. 064 */ 065 @JsonProperty("price") 066 public BigDecimal getPrice() { 067 return price; 068 } 069 070 /** 071 * @return The currency code. 072 */ 073 @JsonProperty("currency") 074 public String getCurrency() { 075 return currency; 076 } 077 078 /** 079 * @return If the status is non-zero, this explains the error encountered. 080 */ 081 @JsonProperty("error_text") 082 public String getErrorText() { 083 return errorText; 084 } 085 086 /** 087 * @return This field may not be present, depending on your pricing model. 088 * The value indicates the cost (in EUR) of the calls made and messages sent for the verification process. 089 * This value may be updated during and shortly after the request completes because user input events can 090 * overlap with message/call events. When this field is present, the total cost of the verification is the 091 * sum of this field and the {@code price} field. 092 * 093 * @since 7.1.0 094 */ 095 @JsonProperty("estimated_price_messages_sent") 096 public BigDecimal getEstimatedPriceMessagesSent() { 097 return estimatedPriceMessagesSent; 098 } 099 100 @Override 101 public void updateFromJson(String json) { 102 super.updateFromJson(json); 103 if (status == null) { 104 throw new VonageResponseParseException("Response status is missing."); 105 } 106 } 107 108 /** 109 * Constructs a CheckResponse with the fields populated from the JSON payload. 110 * 111 * @param json The JSON string. 112 * 113 * @return A new instance of this class. 114 */ 115 public static CheckResponse fromJson(String json) { 116 return Jsonable.fromJson(json); 117 } 118}