1
+ package plivo
2
+
3
+ import (
4
+ "errors"
5
+ "os"
6
+ "path/filepath"
7
+ )
8
+
9
+ type AddressService struct {
10
+ client * Client
11
+ SalutationType addressSalutationRegistry
12
+ NumberType addressNumberTypeRegistry
13
+ ProofType addressProofTypeRegistry
14
+ FileType addressFileTypeRegistry
15
+ }
16
+
17
+ type AddressCreateParams struct {
18
+ PhoneNumberCountry string `json:"phone_number_country,omitempty" url:"phone_number_country,omitempty"`
19
+ NumberType string `json:"number_type,omitempty" url:"number_type,omitempty"`
20
+ Salutation string `json:"salutation,omitempty" url:"salutation,omitempty"`
21
+ FirstName string `json:"first_name,omitempty" url:"first_name,omitempty"`
22
+ LastName string `json:"last_name,omitempty" url:"last_name,omitempty"`
23
+ AddressLine1 string `json:"address_line1,omitempty" url:"address_line1,omitempty"`
24
+ AddressLine2 string `json:"address_line2,omitempty" url:"address_line2,omitempty"`
25
+ City string `json:"city,omitempty" url:"city,omitempty"`
26
+ Region string `json:"region,omitempty" url:"region,omitempty"`
27
+ PostalCode string `json:"postal_code,omitempty" url:"postal_code,omitempty"`
28
+ CountryIso string `json:"country_iso,omitempty" url:"country_iso,omitempty"`
29
+ CallBackUrl string `json:"callback_url,omitempty" url:"callback_url,omitempty"`
30
+ Alias string `json:"alias,omitempty" url:"alias,omitempty"`
31
+ File interface {} `json:"file,omitempty" url:"file,omitempty"`
32
+ AutoCorrectAddress string `json:"autoCorrectAddress,omitempty" url:"autoCorrectAddress,omitempty"`
33
+ AddressProofType string `json:"proof_type,omitempty" url:"proof_type,omitempty"`
34
+ IdNumber string `json:"id_number,omitempty" url:"id_number,omitempty"`
35
+ FiscalIdentificationCode string `json:"fiscal_identification_code,omitempty" url:"fiscal_identification_code,omitempty"`
36
+ StreetCode string `json:"street_code,omitempty" url:"street_code,omitempty"`
37
+ MunicipalCode string `json:"municipal_code,omitempty" url:"municipal_code,omitempty"`
38
+ }
39
+
40
+ type Address struct {
41
+ Account string `json:"account,omitempty" url:"account,omitempty"`
42
+ AddressLine1 string `json:"address_line1,omitempty" url:"address_line1,omitempty"`
43
+ AddressLine2 string `json:"address_line2,omitempty" url:"address_line2,omitempty"`
44
+ Alias string `json:"alias,omitempty" url:"alias,omitempty"`
45
+ StreetCode string `json:"street_code,omitempty" url:"street_code,omitempty"`
46
+ City string `json:"city,omitempty" url:"city,omitempty"`
47
+ CountryIso string `json:"country_iso,omitempty" url:"country_iso,omitempty"`
48
+ DocumentDetails map [string ]interface {} `json:"document_details,omitempty" url:"document_details,omitempty"`
49
+ FirstName string `json:"first_name,omitempty" url:"first_name,omitempty"`
50
+ LastName string `json:"last_name,omitempty" url:"last_name,omitempty"`
51
+ ID string `json:"id,omitempty" url:"id,omitempty"`
52
+ ApiID string `json:"api_id,omitempty" url:"api_id,omitempty"`
53
+ Region string `json:"region,omitempty" url:"region,omitempty"`
54
+ PostalCode string `json:"postal_code,omitempty" url:"postal_code,omitempty"`
55
+ Salutation string `json:"salutation,omitempty" url:"salutation,omitempty"`
56
+ FiscalIdentificationCode string `json:"fiscal_identification_code,omitempty" url:"fiscal_identification_code,omitempty"`
57
+ Url string `json:"url,omitempty" url:"url,omitempty"`
58
+ Subaccount string `json:"subaccount,omitempty" url:"subaccount,omitempty"`
59
+ MunicipalCode string `json:"municipal_code,omitempty" url:"municipal_code,omitempty"`
60
+ ValidationStatus string `json:"validation_status,omitempty" url:"validation_status,omitempty"`
61
+ AddressProofType string `json:"proof_type,omitempty" url:"proof_type,omitempty"`
62
+ VerificationStatus string `json:"verification_status,omitempty" url:"verification_status,omitempty"`
63
+ }
64
+
65
+ type AddressUpdateParams struct {
66
+
67
+ PhoneNumberCountry string `json:"phone_number_country,omitempty" url:"phone_number_country,omitempty"`
68
+ NumberType string `json:"number_type,omitempty" url:"number_type,omitempty"`
69
+ Salutation string `json:"salutation,omitempty" url:"salutation,omitempty"`
70
+ FirstName string `json:"first_name,omitempty" url:"first_name,omitempty"`
71
+ LastName string `json:"last_name,omitempty" url:"last_name,omitempty"`
72
+ AddressLine1 string `json:"address_line1,omitempty" url:"address_line1,omitempty"`
73
+ AddressLine2 string `json:"address_line2,omitempty" url:"address_line2,omitempty"`
74
+ City string `json:"city,omitempty" url:"city,omitempty"`
75
+ Region string `json:"region,omitempty" url:"region,omitempty"`
76
+ PostalCode string `json:"postal_code,omitempty" url:"postal_code,omitempty"`
77
+ CountryIso string `json:"country_iso,omitempty" url:"country_iso,omitempty"`
78
+ CallBackUrl string `json:"callback_url,omitempty" url:"callback_url,omitempty"`
79
+ Alias string `json:"alias,omitempty" url:"alias,omitempty"`
80
+ File interface {} `json:"file,omitempty" url:"file,omitempty"`
81
+ AutoCorrectAddress bool `json:"autoCorrectAddress,omitempty" url:"autoCorrectAddress,omitempty"`
82
+ AddressProofType string `json:"proof_type,omitempty" url:"proof_type,omitempty"`
83
+ FiscalIdentificationCode string `json:"fiscal_identification_code,omitempty" url:"fiscal_identification_code,omitempty"`
84
+ StreetCode string `json:"street_code,omitempty" url:"street_code,omitempty"`
85
+ MunicipalCode string `json:"municipal_code,omitempty" url:"municipal_code,omitempty"`
86
+
87
+ }
88
+
89
+ var AddressSalutationType = & addressSalutationRegistry {
90
+ MR : "Mr" ,
91
+ MRS : "Mrs" ,
92
+ }
93
+
94
+ var AddressNumberType = & addressNumberTypeRegistry {
95
+ LOCAL : "local" ,
96
+ NATIONAL : "national" ,
97
+ MOBILE : "mobile" ,
98
+ TOLLFREE : "tollfree" ,
99
+ }
100
+
101
+ var AddressProofType = & addressProofTypeRegistry {
102
+ NATIONALID : "national_id" ,
103
+ PASSPORT : "passport" ,
104
+ BUSINESSID : "business_id" ,
105
+ NIF : "NIF" ,
106
+ NIE :"NIE" ,
107
+ DNI :"DNI" ,
108
+ }
109
+
110
+ var AddressFileType = & addressFileTypeRegistry {
111
+ PNG : "png" ,
112
+ JPG : "jpg" ,
113
+ PDF : "pdf" ,
114
+ }
115
+
116
+ type addressSalutationRegistry struct {
117
+ MR string
118
+ MRS string
119
+ }
120
+
121
+ type addressNumberTypeRegistry struct {
122
+ LOCAL string
123
+ NATIONAL string
124
+ MOBILE string
125
+ TOLLFREE string
126
+ }
127
+
128
+ type addressProofTypeRegistry struct {
129
+ NATIONALID string
130
+ PASSPORT string
131
+ BUSINESSID string
132
+ NIF string
133
+ NIE string
134
+ DNI string
135
+ }
136
+
137
+ type addressFileTypeRegistry struct {
138
+ PNG string
139
+ JPG string
140
+ PDF string
141
+ }
142
+
143
+ type AddressListParams struct {
144
+ Limit int `url:"limit,omitempty"`
145
+ Offset int `url:"offset,omitempty"`
146
+ }
147
+
148
+
149
+ // Stores response for Create call
150
+ type AddressCreateResponseBody struct {
151
+ Message string `json:"message" url:"message"`
152
+ ApiID string `json:"api_id" url:"api_id"`
153
+ }
154
+
155
+ type AddressList struct {
156
+ BaseListResponse
157
+ Objects []Address `json:"objects" url:"objects"`
158
+ }
159
+ type AddressUpdateResponse BaseResponse
160
+
161
+ func addressCreateParamsNotNull (params AddressCreateParams ) bool {
162
+ if len (params .PhoneNumberCountry ) == 0 || len (params .NumberType ) == 0 || len (params .Salutation ) == 0 ||
163
+ len (params .FirstName ) == 0 || len (params .LastName ) == 0 || len (params .AddressLine1 ) == 0 ||
164
+ len (params .AddressLine2 ) == 0 || len (params .City ) == 0 || len (params .Region ) == 0 || len (params .PostalCode ) == 0 ||
165
+ len (params .CountryIso ) == 0 {
166
+ return false
167
+ }
168
+ return true
169
+ }
170
+
171
+
172
+
173
+ func (service * AddressService ) Create (params AddressCreateParams )(response * AddressCreateResponseBody , err error ){
174
+ if ! addressCreateParamsNotNull (params ) {
175
+ err = errors .New ("PhoneNumberCountry, numberType, salutation, firstName, lastName," +
176
+ "addressLine1, addressLine2, city, region, postalCode and countryIso must not be empty" )
177
+ return
178
+ }
179
+ err = IsValidCountryParams (params .CountryIso ,params .FiscalIdentificationCode ,params .StreetCode ,params .MunicipalCode )
180
+ if err != nil {
181
+ return
182
+ }
183
+ if (params .File != nil ){
184
+ err = IsValidFile (params .File .(string ))
185
+ if err != nil {
186
+ return
187
+ }
188
+ targetFilePath := filepath .Join (params .File .(string ), "./" )
189
+ file , _ := os .Stat (targetFilePath )
190
+ params .File = file
191
+ }
192
+ request , err := service .client .NewRequest ("POST" , params , "Verification/Address" )
193
+ if err != nil {
194
+ return
195
+ }
196
+ response = & AddressCreateResponseBody {}
197
+ err = service .client .ExecuteRequest (request , response )
198
+ return
199
+ }
200
+
201
+ func (service * AddressService ) List (params AddressListParams ) (response * AddressList , err error ) {
202
+ request , err := service .client .NewRequest ("GET" , params , "Verification/Address/" )
203
+ if err != nil {
204
+ return
205
+ }
206
+ response = & AddressList {}
207
+ err = service .client .ExecuteRequest (request , response )
208
+ return
209
+ }
210
+
211
+
212
+ func (service * AddressService ) Get (documentID string ) (response * Address , err error ) {
213
+ request , err := service .client .NewRequest ("GET" , nil , "Verification/Address/%s" ,documentID )
214
+ if err != nil {
215
+ return
216
+ }
217
+ response = & Address {}
218
+ err = service .client .ExecuteRequest (request , response )
219
+ return
220
+ }
221
+
222
+
223
+ func (service * AddressService ) Delete (documentID string ) (err error ) {
224
+ request , err := service .client .NewRequest ("DELETE" , nil , "Verification/Address/%s" ,documentID )
225
+ if err != nil {
226
+ return
227
+ }
228
+ err = service .client .ExecuteRequest (request , nil )
229
+ return
230
+ }
231
+
232
+ func (service * AddressService ) Update (documentID string , params AddressUpdateParams ) (response * AddressUpdateResponse , err error ) {
233
+ err = IsValidCountryParams (params .CountryIso ,params .FiscalIdentificationCode ,params .StreetCode ,params .MunicipalCode )
234
+ if err != nil {
235
+ return
236
+ }
237
+ if (params .File != nil ){
238
+ err = IsValidFile (params .File .(string ))
239
+ if err != nil {
240
+ return
241
+ }
242
+ targetFilePath := filepath .Join (params .File .(string ), "./" )
243
+ file , _ := os .Stat (targetFilePath )
244
+ params .File = file
245
+ }
246
+ request , err := service .client .NewRequest ("POST" , params , "Verification/Address/%s" ,documentID )
247
+ if err != nil {
248
+ return
249
+ }
250
+ response = & AddressUpdateResponse {}
251
+ err = service .client .ExecuteRequest (request , response )
252
+ return
253
+ }
0 commit comments