This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
forked from Vonage/vonage-go-sdk
/
verify.go
142 lines (129 loc) · 5.02 KB
/
verify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package nexmo
import (
"fmt"
"net/http"
)
// StartVerificationRequest is the struct for initiating verification process for a phone number
type StartVerificationRequest struct {
Credentials
Number string `json:"number"`
Brand string `json:"brand"`
Country string `json:"country,omitempty"`
SenderID string `json:"sender_id,omitempty"`
CodeLength int8 `json:"code_length,omitempty"`
LG string `json:"lg,omitempty"`
RequireType string `json:"require_type,omitempty"`
PINExpiry int16 `json:"pin_expiry,omitempty"`
NextEventWait int16 `json:"next_event_wait,omitempty"`
WorkflowID int8 `json:"workflow_id,omitempty"`
PINCode string `json:"pin_code,omitempty"`
PoolID string `json:"pool-id,omitempty"`
}
// StartVerificationResponse is the struct for the response for the initiation of verification to a phone number
type StartVerificationResponse struct {
RequestID string `json:"request_id"`
Status string `json:"status"`
ErrorText string `json:"error_text"`
}
// Start is to begin the process of verifying a phone number, you probably want to capture the request_id
func (s *VerifyService) Start(request StartVerificationRequest) (*StartVerificationResponse, *http.Response, error) {
s.authSet.ApplyAPICredentials(&request)
response := new(StartVerificationResponse)
httpResponse, err := s.sling.New().
Post("json").
BodyJSON(request).
ReceiveSuccess(response)
return response, httpResponse, err
}
// CheckVerificationRequest verifies the phone number
type CheckVerificationRequest struct {
Credentials
RequestID string `json:"request_id"`
Code string `json:"code"`
IPAddress string `json:"ip_address,omitempty"`
}
// CheckVerificationResponse is the response to the verify phone number request
type CheckVerificationResponse struct {
RequestID string `json:"event_id"`
Status string `json:"status"`
Price string `json:"price"`
Currency string `json:"currency"`
ErrorText string `json:"error_text"`
}
// Check if the code the user supplied is correct for this request
func (s *VerifyService) Check(request CheckVerificationRequest) (*CheckVerificationResponse, *http.Response, error) {
s.authSet.ApplyAPICredentials(&request)
response := new(CheckVerificationResponse)
httpResponse, err := s.sling.New().
Post("check/json").
BodyJSON(request).
ReceiveSuccess(response)
return response, httpResponse, err
}
// SearchVerificationRequest is sent to search the status of a verification request
type SearchVerificationRequest struct {
Credentials
RequestIDs []string `json:"request_ids" url:"request_ids"`
}
// SearchVerificationResponse is the response to a search verification request
type SearchVerificationResponse struct {
Status string `json:"status"`
ErrorText string `json:"error_text"`
VerificationRequests []struct {
RequestID string `json:"request_id"`
AccountID string `json:"account_id"`
Number string `json:"number"`
SenderID string `json:"sender_id"`
DateSubmitted string `json:"date_submitted"`
DateFinalized string `json:"date_finalized"`
FirstEventDate string `json:"first_event_date"`
LastEventDate string `json:"last_event_date"`
Status string `json:"status"`
Price string `json:"price"`
Currency string `json:"currency"`
Checks []struct {
DateReceived string `json:"date_received"`
Code string `json:"code"`
Status string `json:"status"`
IPAddress string `json:"ip_address"`
} `json:"checks"`
} `json:"verification_requests"`
}
// Search for current or past verify requests, their costs and statuses
func (s *VerifyService) Search(request SearchVerificationRequest) (*SearchVerificationResponse, *http.Response, error) {
s.authSet.ApplyAPICredentials(&request)
response := new(SearchVerificationResponse)
httpResponse, err := s.sling.New().
Get("search/json").
QueryStruct(request).
ReceiveSuccess(response)
if response.Status != "" {
err = fmt.Errorf("%s: %s", response.Status, response.ErrorText)
}
return response, httpResponse, err
}
// ControlVerificationRequest is the request struct to send a control verification
type ControlVerificationRequest struct {
Credentials
RequestID string `json:"request_id"`
Command string `json:"cmd"`
}
// ControlVerificationResponse is the response to a control verification request
type ControlVerificationResponse struct {
Status string `json:"status"`
Command string `json:"command"`
ErrorText string `json:"error_text"`
}
// Control endpoint allows cancellation of a request or moving to the next verification stage
func (s *VerifyService) Control(request ControlVerificationRequest) (*ControlVerificationResponse, *http.Response, error) {
s.authSet.ApplyAPICredentials(&request)
response := new(ControlVerificationResponse)
httpResponse, err := s.sling.New().
Post("control/json").
BodyJSON(request).
ReceiveSuccess(response)
if response.Status != "" {
err = fmt.Errorf("%s: %s", response.Status, response.ErrorText)
}
return response, httpResponse, err
}