001/*
002 *   Copyright 2020 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.JsonCreator;
019import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
020import com.fasterxml.jackson.annotation.JsonProperty;
021import com.fasterxml.jackson.databind.JsonMappingException;
022import com.fasterxml.jackson.databind.ObjectMapper;
023import com.vonage.client.VonageResponseParseException;
024import com.vonage.client.VonageUnexpectedException;
025
026import java.io.IOException;
027import java.math.BigDecimal;
028
029@JsonIgnoreProperties(ignoreUnknown = true)
030public class CheckResponse {
031    private String requestId;
032    private String eventId;
033    private VerifyStatus status;
034    private BigDecimal price;
035    private String currency;
036    private String errorText;
037
038    @JsonCreator
039    public CheckResponse(@JsonProperty(value = "status", required = true) VerifyStatus status) {
040        this.status = status;
041    }
042
043    @JsonProperty("request_id")
044    public String getRequestId() {
045        return this.requestId;
046    }
047
048    @JsonProperty("event_id")
049    public String getEventId() {
050        return this.eventId;
051    }
052
053    public VerifyStatus getStatus() {
054        return this.status;
055    }
056
057    public BigDecimal getPrice() {
058        return this.price;
059    }
060
061    public String getCurrency() {
062        return this.currency;
063    }
064
065    @JsonProperty("error_text")
066    public String getErrorText() {
067        return this.errorText;
068    }
069
070    public static CheckResponse fromJson(String json) {
071        try {
072            ObjectMapper mapper = new ObjectMapper();
073            return mapper.readValue(json, CheckResponse.class);
074        } catch (JsonMappingException jme) {
075            throw new VonageResponseParseException("Failed to produce CheckResponse from json.", jme);
076        } catch (IOException jpe) {
077            throw new VonageUnexpectedException("Failed to produce CheckResponse from json.", jpe);
078        }
079    }
080}