001/* 002 * Copyright (c) 2011-2017 Nexmo Inc 003 * 004 * Permission is hereby granted, free of charge, to any person obtaining a copy 005 * of this software and associated documentation files (the "Software"), to deal 006 * in the Software without restriction, including without limitation the rights 007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 008 * copies of the Software, and to permit persons to whom the Software is 009 * furnished to do so, subject to the following conditions: 010 * 011 * The above copyright notice and this permission notice shall be included in 012 * all copies or substantial portions of the Software. 013 * 014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 020 * THE SOFTWARE. 021 */ 022package com.vonage.client.verify; 023 024import java.util.Locale; 025 026/** 027 * Base request class for {@link VerifyRequest} and {@link Psd2Request} 028 * @since 5.5.0 029 */ 030public class BaseRequest { 031 032 private final String number; 033 private Integer length; 034 private Locale locale; 035 private String country; 036 private Integer pinExpiry; 037 private Integer nextEventWait; 038 039 public BaseRequest(String number, Integer length, Locale locale) { 040 this.number = number; 041 this.length = length; 042 this.locale = locale; 043 country = null; 044 pinExpiry = null; 045 nextEventWait = null; 046 } 047 048 protected BaseRequest(String number, Integer length, Locale locale, String country, Integer pinExpiry, Integer nextEventWait) { 049 this.number = number; 050 this.length = length; 051 this.locale = locale; 052 this.country = country; 053 this.pinExpiry = pinExpiry; 054 this.nextEventWait = nextEventWait; 055 } 056 057 /** 058 * @return the recipient's phone number provided in the constructor, in 059 * <a href="https://en.wikipedia.org/wiki/E.164">E.164</a> format. 060 */ 061 public String getNumber() { 062 return number; 063 } 064 065 /** 066 * @return the length of the verification code to be sent to the user, specified in some {@link VerifyRequest} 067 * constructors. {@code -1} indicates the default length will be used. 068 */ 069 public Integer getLength() { 070 return length; 071 } 072 073 /** 074 * 075 * @param length the length of the verification code to be sent to the user. Options are either 4 or 6. 076 * @deprecated since 5.5.0 use {@link VerifyRequest.Builder} to create a 2FA verification request or 077 * {@link Psd2Request.Builder} to create a PSD2 verification request 078 */ 079 @Deprecated 080 public void setLength(Integer length) { 081 this.length = length; 082 } 083 084 /** 085 * @return the default locale used for verification. If this value is {@code null}, the locale will be determined 086 * from the country code included in {@code number} 087 */ 088 public Locale getLocale() { 089 return locale; 090 } 091 092 093 /** 094 * 095 * @param locale Override the default locale used for verification. By default the locale is determined 096 * from the country code included in {@code number} 097 * @deprecated since 5.5.0 use {@link VerifyRequest.Builder} to create a 2FA verification request or 098 * {@link Psd2Request.Builder} to create a PSD2 verification request 099 */ 100 public void setLocale(Locale locale) { 101 this.locale = locale; 102 } 103 104 /** 105 * @return the default locale used for verification in snake case. 106 * Ex: {@code en-gb} 107 * If this value is {@code null}, the locale will be determined 108 * from the country code included in {@code number} 109 */ 110 public String getDashedLocale(){ 111 if(locale != null){ 112 return locale.toLanguageTag().toLowerCase(); 113 } 114 else return null; 115 } 116 117 /** 118 * The country for the destination phone number. 119 * 120 * @return a String containing a 2-character country code 121 */ 122 public String getCountry() { 123 return country; 124 } 125 126 /** 127 * The country for the destination phone number. 128 * <p> 129 * If you wish to used localised number formats or you are not sure if number is correctly formatted, set this to a 130 * two-character country code. For example, GB, US. Verify will work out the international phone number for you. 131 * </p> 132 * 133 * @param country a String containing a 2-character country code 134 * @deprecated since 5.5.0 use {@link VerifyRequest.Builder} to create a 2FA verification request or 135 * {@link Psd2Request.Builder} to create a PSD2 verification request 136 */ 137 public void setCountry(String country) { 138 this.country = country; 139 } 140 141 /** 142 * @return PIN expiry time in seconds 143 */ 144 public Integer getPinExpiry() { 145 return pinExpiry; 146 } 147 148 /** 149 * @param pinExpiry PIN expiry time in seconds. 150 * @deprecated since 5.5.0 use {@link VerifyRequest.Builder} to create a 2FA verification request or 151 * {@link Psd2Request.Builder} to create a PSD2 verification request 152 */ 153 public void setPinExpiry(Integer pinExpiry) { 154 this.pinExpiry = pinExpiry; 155 } 156 157 /** 158 * @return the wait time between attempts to deliver the PIN. An Integer between 600-900, or null. 159 */ 160 public Integer getNextEventWait() { 161 return nextEventWait; 162 } 163 164 /** 165 * Set the wait time between attempts to deliver the PIN. 166 * 167 * @param nextEventWait An Integer value between 60 and 900 seconds, or null to use the default duration. 168 * @deprecated since 5.5.0 use {@link VerifyRequest.Builder} to create a 2FA verification request or 169 * {@link Psd2Request.Builder} to create a PSD2 verification request 170 */ 171 public void setNextEventWait(Integer nextEventWait) { 172 this.nextEventWait = nextEventWait; 173 } 174 175 @Override 176 public String toString() { 177 return "number='" + number + '\'' + 178 ", length=" + length + 179 ", locale=" + locale + 180 ", country='" + country + '\'' + 181 ", pinExpiry=" + pinExpiry + 182 ", nextEventWait=" + nextEventWait; 183 } 184}