-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXverifyClientAPI.php
More file actions
183 lines (168 loc) · 6.04 KB
/
Copy pathXverifyClientAPI.php
File metadata and controls
183 lines (168 loc) · 6.04 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
class XverifyClientAPI {
var $api_host = 'http://www.xverify.com/services';
var $api_key;
var $services = array('phone','email','address','phoneconfirm','lead_scorecard','phoneconfirm_code');
var $response;
var $options;
function __construct($api_key, $options = array()) {
$this->api_key = $api_key;
if (empty($this->api_key)){
throw new InvalidArgumentException("api_key required");
}
$this->options = $options;
}
function verify($serviceName,$data) {
if (empty($serviceName) or !in_array($serviceName,$this->services)){
throw new InvalidArgumentException("Invalid service name");
}
$requests = array();
$requestUrl = $this->$serviceName($data);
$extraParameters = http_build_query($this->options);
if(trim($extraParameters) != '')
$requestUrl .= '&'.$extraParameters;
return $this->request($requestUrl);
}
public function getReponseAsObject()
{
$returnObj = new stdClass();
if ($this->response == null) return $returnObj;
$returnObj = json_decode($this->response);
foreach ($returnObj as $res) {
return $res;
}
return $returnObj;
}
private function request($requests) {
$curl_connection = curl_init();
curl_setopt($curl_connection,CURLOPT_URL,$requests);
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_HEADER, 0);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($curl_connection);
curl_close($curl_connection);
$this->response = $result;
return $result;
}
private function email($data) {
$url = $this->api_host . '/emails/verify/';
$value = '';
if(is_array($data) && isset($data['email']))
{
$value = $data['email'];
}
$params = array('email' => $value, 'apikey' => $this->api_key);
return $url . '?' . http_build_query($params);
}
private function phone($data) {
$url = $this->api_host . '/phone/verify/';
$value = '';
if(is_array($data) && isset($data['phone']))
{
$value = $data['phone'];
}
$params = array('phone' => $value, 'apikey' => $this->api_key);
return $url . '?' . http_build_query($params);
}
private function address($data) {
$url = $this->api_host . '/address/verify/';
$street = '';
$zip = '';
if(is_array($data))
{
if(isset($data['street'])) $street = $data['street'];
if(isset($data['zip'])) $zip = $data['zip'];
}
$params = array('street' => $street,'zip' => $zip, 'apikey' => $this->api_key);
return $url . '?' . http_build_query($params);
}
public function is_valid() {
if ($this->response == null) return null;
$responseObj = json_decode($this->response);
$valid = true;
foreach ($responseObj as $res) {
if (isset($res->status) && $res->status != 'valid') {
$valid = false;
}
}
return $valid;
}
public function status() {
if ($this->response == null) return null;
$responseObj = json_decode($this->response);
$status = 'unknown';
foreach ($responseObj as $res) {
if (isset($res->status)) {
$status = $res->status;
}
}
return $status;
}
private function phoneconfirm($data) {
$url = $this->api_host . '/phoneconfirm/placecall/';
$phone = '';
$country_code = 1;
$code = '';
$redial_count = 3;
$redial_interval = 10;
$call_place_time = 30;
if(is_array($data))
{
if(isset($data['phone'])) $phone = $data['phone'];
if(isset($data['country_code'])) $country_code = $data['country_code'];
if(isset($data['code'])) $code = $data['code'];
if(isset($data['redial_count'])) $redial_count = $data['redial_count'];
if(isset($data['call_place_time'])) $call_place_time = $data['call_place_time'];
if(isset($data['street'])) $street = $data['street'];
}
$params = array(
'apikey' => $this->api_key,'phone' => $phone,'country_code' => $country_code,
'code' => $code,'redial_count'=>$redial_count,'redial_interval'=>$redial_interval,'call_place_time'=>$call_place_time);
return $url . '?' . http_build_query($params);
}
private function phoneconfirm_code($data) {
$url = $this->api_host . '/phoneconfirm/verifycode/';
$transaction_number = '0';
$code = 0;
if(is_array($data))
{
if(isset($data['transaction_number'])) $phone = $data['transaction_number'];
if(isset($data['code'])) $street = $data['code'];
}
$params = array(
'apikey' => $this->api_key,'transaction_number' => $transaction_number,'code' => $code);
return $url . '?' . http_build_query($params);
}
private function lead_scorecard($data) {
$url = $this->api_host . '/scoring/verify/';
$phone = '';
$ip = '';
$firstname = '';
$lastname = '';
$address = '';
$city = '';
$state = '';
$zip = '';
$email = '';
$start_time = '';
if(is_array($data))
{
if(isset($data['phone'])) $phone = $data['phone'];
if(isset($data['ip'])) $ip = $data['ip'];
if(isset($data['firstname'])) $firstname = $data['firstname'];
if(isset($data['lastname'])) $lastname = $data['lastname'];
if(isset($data['address'])) $address = $data['address'];
if(isset($data['city'])) $city = $data['city'];
if(isset($data['state'])) $state = $data['state'];
if(isset($data['zip'])) $zip = $data['zip'];
if(isset($data['email'])) $email = $data['email'];
if(isset($data['start_time'])) $start_time = $data['start_time'];
}
$params = array(
'apikey' => $this->api_key,'phone' => $phone,'ip' => $ip,
'firstname' => $firstname,'lastname'=>$lastname,'address'=>$address,'city'=>$city,
'state' => $state,'zip'=>$zip,'email'=>$email,'start_time'=>$start_time);
return $url . '?' . http_build_query($params);
}
}