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.nexmo.client.sms; 023 024 025import java.math.BigDecimal; 026 027/** 028 * Represents the result of the submission of a single sms message, 029 * or a single part of a long / multi-part message 030 * 031 * @author Paul Cook 032 */ 033public class SmsSubmissionResult implements java.io.Serializable { 034 035 private static final long serialVersionUID = 2580996244288340269L; 036 037 /** 038 * Message was successfully submitted to the Nexmo service 039 */ 040 public static final int STATUS_OK = 0; 041 042 /** 043 * Message was rejected due to exceeding the maximum throughput allowed for this account.<br> 044 * Message can be re-submitted after a short delay 045 */ 046 public static final int STATUS_THROTTLED = 1; 047 048 /** 049 * Message was rejected due to incomplete data in the submission request 050 */ 051 public static final int STATUS_MISSING_PARAMS = 2; 052 053 /** 054 * Message was rejected due to an illegal value in one or more elements of the submission request 055 */ 056 public static final int STATUS_INVALID_PARAMS = 3; 057 058 /** 059 * Message was rejected due to receiving invalid account api key and/or secret 060 */ 061 public static final int STATUS_INVALID_CREDENTIALS = 4; 062 063 /** 064 * Message was rejected due to a failure within the Nexmo systems.<br> 065 * Message can be re-submitted after a short delay 066 */ 067 public static final int STATUS_INTERNAL_ERROR = 5; 068 069 /** 070 * Message was rejected because the Nexmo service was unable to handle this request. eg, the destination was un-routable. 071 */ 072 public static final int STATUS_INVALID_MESSAGE = 6; 073 074 /** 075 * Message was rejected because the phone number you tried to submit to has been blacklisted. 076 */ 077 public static final int STATUS_NUMBER_BARRED = 7; 078 079 /** 080 * Message was rejected because your account has been barred, or has not yet been activated 081 */ 082 public static final int STATUS_PARTNER_ACCOUNT_BARRED = 8; 083 084 /** 085 * Message was rejected because your pre-paid balance does not contain enough credit to handle this request.<br> 086 * Please top up your balance before re-submitting this request or subsequent requests. 087 */ 088 public static final int STATUS_PARTNER_QUOTA_EXCEEDED = 9; 089 090 /** 091 * Message was rejected because already have the maximum number of concurrent connections allowed for your account. 092 */ 093 public static final int STATUS_TOO_MANY_BINDS = 10; 094 095 /** 096 * Message was rejected because your account is not provisioned for submitting via the REST interface. 097 */ 098 public static final int STATUS_ACCOUNT_NOT_HTTP = 11; 099 100 /** 101 * Message was rejected because it exceeds the allowable maximum length (140 octets for a binary message, or 3200 chars for a text message) 102 */ 103 public static final int STATUS_MESSAGE_TOO_LONG = 12; 104 105 /** 106 * Message was not submitted because there was a communications failure. 107 */ 108 public static final int STATUS_COMMS_FAILURE = 13; 109 110 /** 111 * Message was not submitted due to a verification failure in the submitted signature 112 */ 113 public static final int STATUS_INVALID_SIGNATURE = 14; 114 115 /** 116 * The 'from' address specified in the message submission was not permitted 117 */ 118 public static final int STATUS_INVALID_FROM_ADDRESS = 15; 119 120 /** 121 * invalid TTL -- The ttl parameter values, or combination of parameters is invalid 122 */ 123 public static final int STATUS_INVALID_TTL = 16; 124 125 /** 126 * This destination cannot be delivered to at this time (if reachable=true is specified) 127 */ 128 public static final int STATUS_NUMBER_UNREACHABKE = 17; 129 130 /** 131 * There are more than the maximum allowed number of destinations in this request 132 */ 133 public static final int STATUS_TOO_MANY_DESTINATIONS = 18; 134 135 /** 136 * Your request makes use of a facility that is not enabled on your account 137 */ 138 public static final int STATUS_FACILITY_NOT_ALLOWED = 19; 139 140 /** 141 * The message class value supplied was out of range (0 - 3) 142 */ 143 public static final int STATUS_INVALID_MESSAFE_CLASS = 20; 144 145 146 private final int status; 147 private final String destination; 148 private final String messageId; 149 private final String errorText; 150 private final String clientReference; 151 private final BigDecimal remainingBalance; 152 private final BigDecimal messagePrice; 153 private final boolean temporaryError; 154 private final SmsSubmissionReachabilityStatus smsSubmissionReachabilityStatus; 155 private final String network; 156 157 protected SmsSubmissionResult(final int status, 158 final String destination, 159 final String messageId, 160 final String errorText, 161 final String clientReference, 162 final BigDecimal remainingBalance, 163 final BigDecimal messagePrice, 164 final boolean temporaryError, 165 final SmsSubmissionReachabilityStatus smsSubmissionReachabilityStatus, 166 final String network) { 167 this.status = status; 168 this.destination = destination; 169 this.messageId = messageId; 170 this.errorText = errorText; 171 this.clientReference = clientReference; 172 this.remainingBalance = remainingBalance; 173 this.messagePrice = messagePrice; 174 this.temporaryError = temporaryError; 175 this.smsSubmissionReachabilityStatus = smsSubmissionReachabilityStatus; 176 this.network = network; 177 } 178 179 /** 180 * @return int status code representing either the success of the message submission or a reason for failure 181 */ 182 public int getStatus() { 183 return this.status; 184 } 185 186 /** 187 * @return String the destination phone number that the message was submitted to 188 */ 189 public String getDestination() { 190 return this.destination; 191 } 192 193 /** 194 * @return String a unique identifier associated with the submitted message. 195 * This value will be returned in any subsequent delivery notifications in order that they may be correlated with the appropriate message submission request. 196 */ 197 public String getMessageId() { 198 return this.messageId; 199 } 200 201 /** 202 * @return String a human readable error message giving further description of the value of {see #getStatus()} 203 */ 204 public String getErrorText() { 205 return this.errorText; 206 } 207 208 /** 209 * @return String the client-reference that was supplied as part of the original message submission 210 */ 211 public String getClientReference() { 212 return this.clientReference; 213 } 214 215 /** 216 * @return BigDecimal The account balance that remains after the submission of this message. 217 */ 218 public BigDecimal getRemainingBalance() { 219 return this.remainingBalance; 220 } 221 222 /** 223 * @return BigDecimal The amount that was debited from your account balance upon submission of this message 224 */ 225 public BigDecimal getMessagePrice() { 226 return this.messagePrice; 227 } 228 229 /** 230 * @return boolean Indicates if the failure was due to a temporary condition. If so, then the message submission may be re-attempted after a short delay 231 */ 232 public boolean getTemporaryError() { 233 return this.temporaryError; 234 } 235 236 /** 237 * @return SmsSubmissionReachabilityStatus the result of any reachability check that was performed on this message if one was requested 238 */ 239 public SmsSubmissionReachabilityStatus getSmsSubmissionReachabilityStatus() { 240 return this.smsSubmissionReachabilityStatus; 241 } 242 243 /** 244 * @return String the 'estimated' network that has been identified for this destination (Note, this can change during the processing of this message due to HLR lookups) 245 */ 246 public String getNetwork() { 247 return this.network; 248 } 249 250 @Override 251 public String toString() { 252 StringBuilder sb = new StringBuilder(); 253 sb.append("SMS-SUBMIT-RESULT -- STATUS:").append(this.status); 254 sb.append(" ERR:").append(this.errorText); 255 sb.append(" DEST:").append(this.destination); 256 sb.append(" MSG-ID:").append(this.messageId); 257 sb.append(" CLIENT-REF:").append(this.clientReference); 258 sb.append(" PRICE:").append(this.messagePrice == null ? "-" : this.messagePrice.toPlainString()); 259 sb.append(" BALANCE:").append(this.remainingBalance == null ? "-" : this.remainingBalance.toPlainString()); 260 sb.append(" TEMP-ERR?:").append(this.temporaryError); 261 if (this.smsSubmissionReachabilityStatus != null) 262 sb.append(" REACHABLE?:").append(this.smsSubmissionReachabilityStatus); 263 if (this.network != null) 264 sb.append("NETWORK:").append(this.network); 265 266 return sb.toString(); 267 } 268 269}