├── .gitignore ├── API.md ├── EmailSDK.md ├── LICENSE ├── README.md ├── WebSDK.md ├── composer.json └── src └── VerifyKit ├── Constant └── ValidationMethod.php ├── Entity ├── AccessToken.php ├── BlacklistAdd.php ├── BlacklistRemove.php ├── Countries.php ├── Country.php ├── EmailValidationStart.php ├── Localization.php ├── OTPCheck.php ├── OTPSend.php ├── Response.php ├── ValidationCheck.php ├── ValidationMethod.php ├── ValidationMethodList.php ├── ValidationStart.php └── WAMessageResponse.php ├── Exception ├── CountryCodeEmptyException.php ├── CurlException.php ├── OTPCodeEmptyException.php ├── PhoneNumberEmptyException.php ├── PhoneNumberListEmptyException.php ├── ReferenceEmptyException.php ├── ServerKeyEmptyException.php ├── SessionIdEmptyException.php ├── TextMessageEmptyException.php ├── ValidationMethodEmptyException.php └── ValidationMethodNotValidException.php ├── VerifyKit.php ├── WASessionMessage.php └── Web.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | composer.lock 4 | .project 5 | .metadata -------------------------------------------------------------------------------- /API.md: -------------------------------------------------------------------------------- 1 | API Implementation 2 | --- 3 | 4 | 5 | ### IMPORTANT NOTE 6 | 7 | For the security of your application, you should send the IP address of the end user in all requests. To do this, you need to add X-Vfk-Forwarded-For header parameter in all requests. 8 | 9 | #### Validation Method List 10 | 11 | There are verification methods and language variables that you can use while preparing your verification screens. Response also includes specific warning messages in cases of errors for developers to act upon. 12 | 13 | 14 | ##### Example curl request 15 | 16 | ```bash 17 | curl --request GET 'https://web-rest.verifykit.com/v1.0/init' \ 18 | --header 'X-Vfk-Server-Key: YOUR-SERVER-KEY' \ 19 | --header 'X-Vfk-Forwarded-For: END-USER-IP-ADDRESS' \ 20 | --header 'Content-Type: application/json' 21 | ``` 22 | 23 | ##### Example response body 24 | 25 | ```json 26 | { 27 | "meta": { 28 | "requestId": "REQUEST-ID", 29 | "httpStatusCode": 200 30 | }, 31 | "result": { 32 | "list": [ 33 | { 34 | "appPackage": "whatsapp", 35 | "name": "WhatsApp", 36 | "app": "whatsapp", 37 | "text": "Verify via WhatsApp", 38 | "textColour": "ffffff", 39 | "bgColour": "1bd741", 40 | "icon": "https://web-rest.verifykit.com/img/web/whatsapp@3x.png" 41 | }, 42 | { 43 | "appPackage": "telegram", 44 | "name": "Telegram", 45 | "app": "telegram", 46 | "text": "Verify via Telegram", 47 | "textColour": "ffffff", 48 | "bgColour": "61a8de", 49 | "icon": "https://web-rest.verifykit.com/img/web/telegram@3x.png" 50 | }, 51 | { 52 | "appPackage": "otp", 53 | "name": "Sms", 54 | "app": "otp", 55 | "text": "Click to verify via SMS", 56 | "textColour": "ffffff", 57 | "bgColour": "cbcbd0", 58 | "icon": "https://web-rest.verifykit.com/img/web/otp@3x.png" 59 | } 60 | ], 61 | "description": "Please tap on your preferred messaging app and send us the code appearing on the screen.", 62 | "localizationList": [ 63 | { 64 | "key": "validation.description", 65 | "value": "Please tap on your preferred messaging app and send us the code appearing on the screen." 66 | }, 67 | { 68 | "key": "validation.chooseAppText", 69 | "value": "Select a messaging app to verify your phone number." 70 | }, 71 | . 72 | . 73 | . 74 | ], 75 | "messages": [] 76 | } 77 | } 78 | 79 | ``` 80 | 81 | If your SMS view selection setting is set to 'alternative' in your application detail screen on VerifyKit dashboard, SMS validation method parameters will be given in the list parameter as in the code snippet above. However, if your sms view selection setting is set to 'recommended' option, SMS validation method parameters will be as follows. 82 | 83 | ```json 84 | { 85 | "alternativeValidation": "otp", 86 | "alternativeValidationDescription": "Don't use any of these apps?" 87 | } 88 | ``` 89 | 90 | 91 | 92 | #### Start Validation (WhatsApp or Telegram) 93 | 94 | When your users choose a validation method from the screen you prepare, you can start the validation process by sending the "app" parameter of selected validation method to this endpoint. 95 | ​ 96 | Three parameters are returned in the response. The first one is the "reference" code given to you in order to track the verification process on our end. The other two are the parameters you will use to verify your users. One of them is the qr code parameter which you can use if your users access your app through a browser. The other one is the deeplink to open the application in which your users will verify on their mobile devices. 97 | 98 | ##### Example curl request 99 | 100 | ```bash 101 | curl --request POST 'https://web-rest.verifykit.com/v1.0/start' \ 102 | --header 'X-Vfk-Server-Key: YOUR-SERVER-KEY' \ 103 | --header 'X-Vfk-Forwarded-For: END-USER-IP-ADDRESS' \ 104 | --header 'Content-Type: application/json' \ 105 | -d '{"app":"whatsapp"}' 106 | ``` 107 | 108 | 109 | Other parameters you can send at this request: 110 | ```bash 111 | -d '{"lang":"en"}' # Language of end user. Default value is 'en' (English). This parameter is not required. 112 | 113 | # We can give both deeplink and qrCode in response to the start request. If you send qrCode parameter as (bool)true, you can see that you have received a base64 qrCode. By showing this qrCode to users coming from desktop browsers, you can make it easier to verify. 114 | # We recommend that you do not send qrCode parameter as (bool)true for requests from mobile applications or mobile browsers. You should use deeplink for these platforms. 115 | # This two parameters cannot be (bool)true at the same time. If you send both (bool)true at the same time, we will only give the deeplink in the response. 116 | # Default value is true for deeplink, and false for qrCode. These parameters are not required. 117 | -d '{"deeplink":true}' 118 | -d '{"qrCode":false}' 119 | ``` 120 | 121 | ##### Example response body 122 | 123 | ```json 124 | { 125 | "meta": { 126 | "requestId": "REQUEST-ID", 127 | "httpStatusCode": 200 128 | }, 129 | "result": { 130 | "deeplink": "https://wa.me/905395744034?text=.....", 131 | "qrCode": "data:image/png;base64,iVBORw0KGgoAA......", 132 | "reference": "111111" 133 | } 134 | } 135 | ``` 136 | 137 | #### Check Validation (WhatsApp or Telegram) 138 | 139 | With the "reference" code you received in the previous response, you can check whether the validation has been completed by the user or not. 140 | 141 | If your user has completed the validation, you will receive a "session id" of this validation in the response. 142 | 143 | ##### Example curl request 144 | 145 | ```bash 146 | curl --request POST 'https://web-rest.verifykit.com/v1.0/check' \ 147 | --header 'X-Vfk-Server-Key: YOUR-SERVER-KEY' \ 148 | --header 'X-Vfk-Forwarded-For: END-USER-IP-ADDRESS' \ 149 | --header 'Content-Type: application/json' \ 150 | -d '{"reference":"REFERENCE-OF-VALIDATION"}' 151 | ``` 152 | 153 | ##### Example response body 154 | 155 | ```json 156 | { 157 | "meta": { 158 | "requestId": "REQUEST-ID", 159 | "httpStatusCode": 200 160 | }, 161 | "result": { 162 | "validationStatus": true, 163 | "sessionId": "QWERTY123456" 164 | } 165 | } 166 | ``` 167 | 168 | #### Start Validation (OTP) 169 | 170 | ##### Country List 171 | 172 | Firstly, prepare a screen where your user will enter their phone number and country code. While preparing this screen, you can get the list of country information such as country code and phone code by sending a request to the "/country" endpoint like the example below. 173 | 174 | ##### Example curl request 175 | ```bash 176 | curl --request POST 'https://web-rest.verifykit.com/v1.0/country' \ 177 | --header 'Content-Type: application/json' \ 178 | --header 'X-Vfk-Forwarded-For: END-USER-IP-ADDRESS' \ 179 | --header 'X-Vfk-Server-Key: YOUR-SERVER-KEY' 180 | ``` 181 | 182 | Other parameters you can send at this request: 183 | ```bash 184 | -d '{"countryCode":"TR"}' country code parameter for the request. We return the sent countryCode parameter at the top of the list in the response. If you want a specific country (user's country detected by ip on your side for example) to be the first response parameter, you can send countryCode with your request. Not required. 185 | ``` 186 | 187 | ##### Example response body 188 | 189 | ```json 190 | { 191 | "meta": { 192 | "requestId": "REQUEST-ID", 193 | "httpStatusCode": 200 194 | }, 195 | "result": { 196 | "list": [ 197 | { 198 | "phoneCode": "string", 199 | "countryCode": "string", 200 | "title": "string" 201 | }, 202 | . 203 | . 204 | . 205 | ] 206 | } 207 | } 208 | ``` 209 | 210 | 211 | ### Send Otp Request 212 | 213 | Then, you must post the country code and the phone number that your user entered. The response you receive includes the "reference" you will use for checking status and the validity period of this verification. During this period, a validation code will be sent to the phone number that was entered by your user. Proceed to the next step to continue verification with the user-entered code. 214 | 215 | 216 | ##### Example curl request 217 | ```bash 218 | curl --request POST 'https://web-rest.verifykit.com/v1.0/send-otp' \ 219 | --header 'X-Vfk-Server-Key: YOUR-SERVER-KEY' \ 220 | --header 'X-Vfk-Forwarded-For: END-USER-IP-ADDRESS' \ 221 | --header 'Content-Type: application/json' \ 222 | -d '{"phoneNumber":"PHONE_NUMBER","countryCode":"COUNTRY_CODE"}' 223 | ``` 224 | 225 | Other parameters you can send at this request: 226 | ```bash 227 | # For OTP verification to work best, you should send us the MCC and MNC code of the sim card in the user's device. 228 | -d '{"mcc":"999"}' # Mobile Country Code (MCC) of the sim card in the user's device. Default value is '999'. Not required. 229 | -d '{"mnc":"999"}' # Mobile Network Code (MNC) of the sim card in the user's device. Default value is '999'. Not required. 230 | 231 | -d '{"lang":"en"}' # Language of end user. Default value is 'en' (English). You can set the language of the sent message. This parameter is not required. 232 | ``` 233 | 234 | ##### Example response body 235 | ````json 236 | { 237 | "meta": { 238 | "requestId": "REQUEST-ID", 239 | "httpStatusCode": 201 240 | }, 241 | "result": { 242 | "reference": "123456", 243 | "timeout": 300 244 | } 245 | } 246 | ```` 247 | 248 | #### Check Validation (OTP) 249 | 250 | 251 | With the "reference" code you received in the previous response, you can check whether the validation has been completed by the user or not. 252 | 253 | If your user has completed the validation, you will receive a "session id" of this validation in the response which means the verification process sucessfully finished. 254 | 255 | 256 | 257 | ##### Example curl request 258 | ```bash 259 | curl --request POST 'https://web-rest.verifykit.com/v1.0/check-otp' \ 260 | --header 'X-Vfk-Server-Key: YOUR-SERVER-KEY' \ 261 | --header 'X-Vfk-Forwarded-For: END-USER-IP-ADDRESS' \ 262 | --header 'Content-Type: application/json' \ 263 | -d '{"phoneNumber":"PHONE_NUMBER","countryCode":"COUNTRY_CODE","reference":"REFERENCE-OF-VALIDATION","code":"USER-ENTERED-CODE"}' 264 | ``` 265 | 266 | ##### Example response body 267 | ```json 268 | { 269 | "meta": { 270 | "requestId": "REQUEST-ID", 271 | "httpStatusCode": 200 272 | }, 273 | "result": { 274 | "validationStatus": true, 275 | "sessionId": "QWERTY123456" 276 | } 277 | } 278 | ``` 279 | 280 | 281 | 282 | ### Last Step : Complete Validation 283 | 284 | This is where you will get your user's credentials such as phone number et cetera. You can complete the validation by sending the "session id" parameter of the validation here. 285 | 286 | ##### Example curl request 287 | 288 | ```bash 289 | curl --request POST 'https://api.verifykit.com/v1.0/result' \ 290 | --header 'X-Vfk-Server-Key: YOUR-SERVER-KEY' \ 291 | --header 'X-Vfk-Forwarded-For: END-USER-IP-ADDRESS' \ 292 | --header 'Content-Type: application/json' \ 293 | -d '{"sessionId":"SESSION-ID-OF-VALIDATION"}' 294 | ``` 295 | 296 | 297 | ##### Example response body 298 | 299 | ````json 300 | { 301 | "meta": { 302 | "requestId": "REQUEST-ID", 303 | "httpStatusCode": 200 304 | }, 305 | "result": { 306 | "validationType": "whatsapp", 307 | "validationDate": "Y-m-d H:i:s", 308 | "phoneNumber": "+9......", 309 | "countryCode": "TR" 310 | } 311 | } 312 | ```` 313 | 314 | ## Error Codes 315 | 316 | If there are any errors, the response scheme you get will be as follows. 317 | 318 | ```json 319 | { 320 | "meta": { 321 | "requestId": "REQUEST-ID", 322 | "httpStatusCode": "HTTP_STATUS_CODE", 323 | "errorMessage": "ERROR_MESSAGE", 324 | "errorCode": "ERROR_CODE" 325 | } 326 | } 327 | ``` 328 | 329 | The list of error messages is as follows 330 | 331 | | HTTP Status Code | Error Code | Description | 332 | |--- |--- |--- | 333 | | 400 | 400007 | Invalid phone number, please check the phone number. | 334 | | 403 | 403004 | You must send either qrCode or deeplink parameter as true in order to start verification. | 335 | | 403 | 403011 | Validation type is not active. | 336 | | 403 | 403012 | Phone number is banned. | 337 | | 403 | 403013 | OTP Validation not found. | 338 | | 403 | 403014 | OTP code is invalid. | 339 | | 403 | 403015 | You have reached the limit of sending OTP code. | 340 | | 403 | 403036 | Validation not found. | 341 | | 403 | 403037 | Validation has expired. | 342 | | 403 | 403038 | Undefined application. Please check your credential parameters. | 343 | | 403 | 403041 | You have reached the limit of package validation count. | 344 | | 403 | 403042 | Please check your account balance on VerifyKit Dashboard. | 345 | | 403 | 403043 | Please check your account balance on VerifyKit Dashboard. | 346 | | 403 | 403048 | Email is invalid. | 347 | | 403 | 403047 | OTP setting is not active. | 348 | | 403 | 403049 | OTP can only be used with test numbers. | 349 | | 429 | 429001 | Too many requests. please try again later. | 350 | | 500 | 500008 | Internal server error. | -------------------------------------------------------------------------------- /EmailSDK.md: -------------------------------------------------------------------------------- 1 | EmailSDK Implementation 2 | --- 3 | 4 | ### IMPORTANT NOTE 5 | 6 | For the security of your application, you should send the IP address of the end user in all requests. To do this, you need to add X-Vfk-Forwarded-For header parameter in all requests. 7 | 8 | ### Start email validation. 9 | Using this endpoint, you can start the email verification process. You can send the email address of the user you want to verify as the optional "email" parameter for an additional security measure. This optional parameter brings another variation to the /start-email request as additional content header is required to be sent alongside with the post parameter. In the response, you can get the reference and subject values of the verification for further status control purposes which will be explained later in this document. Example request and response values are given below. 10 | ##### Example curl request 11 | ```bash 12 | curl --request POST 'https://web-rest.verifykit.com/v1.0/start-email' \ 13 | --header 'X-Vfk-Server-Key: YOUR-SERVER-KEY' \ 14 | --header 'X-Vfk-Forwarded-For: END-USER-IP-ADDRESS' \ 15 | ``` 16 | ##### Example curl request with optional "email" parameter 17 | ```bash 18 | curl --request POST 'https://web-rest.verifykit.com/v1.0/start-email' \ 19 | --header 'X-Vfk-Server-Key: YOUR-SERVER-KEY' \ 20 | --header 'X-Vfk-Forwarded-For: END-USER-IP-ADDRESS' \ 21 | --header 'Content-Type: application/json' \ 22 | -d '{"email":"YOUR-CLIENT'S-EMAIL-ADDRESS"}' 23 | ``` 24 | ##### Example response body 25 | ```json 26 | { 27 | "meta": { 28 | "requestId": "REQUEST-ID", 29 | "httpStatusCode": 200 30 | }, 31 | "result": { 32 | "reference": "REFERENCE-FOR-VERIFICATION", 33 | "to": "YOUR-EMAIL-ADDRESS", 34 | "subject": "verify-abc123abc123", 35 | "body": "BODY-FOR-EMAIL", 36 | "mailto": "mailto:YOUR-EMAIL-ADDRESS?subject=verify-abc123abc123&body=BODY-FOR-EMAIL", 37 | } 38 | } 39 | ``` 40 | #### After starting the email verification process VerifyKit handles the verification process. You can check the process status or fetch the data of your user once the process completes successfully. 41 | ### Check if the validation is complete. 42 | With the "reference" and "subject" value you received in the previous response, you can check whether the verification has been completed by the user or not. In this request you should send reference value as "reference" parameter and subject value as the "code" parameter in order to check the status of the verification. 43 | If the verification is not completed yet, the response status code will be HTTP 403 with specific 403036 error code value which specifies the verification is still in progress. 44 | ##### Example curl request 45 | ```bash 46 | curl --request POST 'https://web-rest.verifykit.com/v1.0/check-email' \ 47 | --header 'X-Vfk-Server-Key: YOUR-SERVER-KEY' \ 48 | --header 'X-Vfk-Forwarded-For: END-USER-IP-ADDRESS' \ 49 | --header 'Content-Type: application/json' \ 50 | -d '{"reference":"REFERENCE-OF-VALIDATION", "code" : "SUBJECT VALUE OF START-EMAIL-REQUEST"}' 51 | ``` 52 | ##### Example response body 53 | ```json 54 | { 55 | "meta": { 56 | "requestId": "REQUEST-ID", 57 | "httpStatusCode": 200 58 | }, 59 | "result": { 60 | "emailVerify" : "boolean", 61 | "dkimVerify" : "boolean", 62 | "spfVerify": "boolean", 63 | "email" : "VALIDATION-EMAIL-ADDRESS", 64 | "validationType" : "VALIDATION-TYPE", 65 | "validationDate" : "VALIDATION-DATE", 66 | } 67 | } 68 | ``` 69 | ##### Also after we receive the user mail from your side, we forward the user verification details to the callback url you provide. Example data structure for the response you will receive on your callback url is given below. "reference" value of the response is the same value as both the "reference" value you receive in the response data of /start-email request and the "reference" parameter you use to send /check-email request. "reference" is the unique identification parameter for each verification which helps you match the user data we send with the ongoing verification on your side. 70 | ##### Example response body 71 | ```json 72 | { 73 | "emailVerify" : "boolean", 74 | "dkimVerify" : "boolean", 75 | "spfVerify" : "boolean", 76 | "email" : "VALIDATION-EMAIL-ADDRESS", 77 | "validationType" : "VALIDATION-TYPE", 78 | "validationDate" : "VALIDATION-DATE", 79 | "reference" : "REFERENCE-FOR-VERIFICATION", 80 | "sessionId" : "SESSION-ID-OF-SUCESSFUL-VERIFICATION" 81 | } 82 | ``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 verifykit 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VerifyKit 2 | ![Status](https://img.shields.io/badge/Status-Beta-yellowgreen) ![License](https://img.shields.io/badge/License-MIT-red.svg) 3 | 4 | VerifyKit is the next gen phone number validation system. Users can easily verify their phone numbers without the need of entering phone number or a pin code. 5 | 6 | *This SDK is a tool for you to use the [VerifyKit Rest API](https://github.com/verifykit/verifykit-sdk-php/blob/master/API.md) more easily.* 7 | 8 | ## Requirements 9 | 10 | - PHP >= 5.5 11 | - PHP-Curl 12 | - PHP-Json 13 | 14 | ## Installation 15 | 16 | You can install via composer 17 | 18 | ```bash 19 | composer require verifykit/verifykit-sdk-php 20 | ``` 21 | 22 | ## Usage 23 | 24 | ### IMPORTANT NOTE 25 | 26 | For the security of your application, you should send the IP address of the end user in all requests. To do this, you need to set $clientIp parameter in all class constructions. 27 | 28 | #### Validation Method List 29 | 30 | Firstly, get a list of validation methods. 31 | 32 | ```php 33 | $vfk = new \VerifyKit\Web($serverKey, $clientIp); 34 | 35 | /** @var \VerifyKit\Entity\ValidationMethodList $validationMethodList */ 36 | $validationMethodList = $vfk->getValidationMethodList(); 37 | 38 | /** @var \VerifyKit\Entity\ValidationMethod $validationMethod */ 39 | foreach ($validationMethodList->getList() as $validationMethod) { 40 | // $validationMethod-> getName, getApp, getText, getTextColour, getBgColour, getIcon... 41 | } 42 | 43 | // if you want to handle all localizations for validation steps, use this way. 44 | /** @var \VerifyKit\Entity\Localization $localization */ 45 | foreach ($validationMethodList->getLocalizationList() as $localization){ 46 | // getKey, getValue of localization. 47 | } 48 | ``` 49 | 50 | #### Start Validation (WhatsApp or Telegram) 51 | 52 | ```php 53 | $vfk = new \VerifyKit\Web($serverKey, $clientIp); 54 | 55 | $validationMethod = 'whatsapp'; // or telegram. Required. 56 | 57 | $lang = 'en'; // Language of end user. Default value is 'en' (English). This parameter is not required. 58 | 59 | // We can give both deeplink and qrCode in response to the start request. If you send qrCode parameter as (bool)true, you can see that you have received a base64 qrCode. By showing this qrCode to users coming from desktop browsers, you can make it easier to verify. 60 | // We recommend that you do not send qrCode parameter as (bool)true for requests from mobile applications or mobile browsers. You should use deeplink for these platforms. 61 | // This two parameters cannot be (bool)true at the same time. If you send both (bool)true at the same time, we will only give the deeplink in the response. 62 | // Default value is true for deeplink, and false for qrCode. These parameters are not required. 63 | $deeplink = true; 64 | $qrCode = false; 65 | 66 | /** @var \VerifyKit\Entity\ValidationStart $result */ 67 | $validationStart = $vfk->startValidation($validationMethod, $lang, $deeplink, $qrCode); 68 | 69 | // if you want to redirect your user for validation, get deeplink. 70 | echo $validationStart->getDeeplink(); 71 | 72 | // if you want to view a Qr code to your user for validation, get base64 png string and set it as an image source on web browsers. 73 | echo $validationStart->getQrCode(); 74 | 75 | // keep this reference code for next step. 76 | echo $validationStart->getReference(); 77 | ``` 78 | 79 | #### Check Validation (WhatsApp or Telegram) 80 | 81 | ```php 82 | $vfk = new \VerifyKit\Web($serverKey, $clientIp); 83 | 84 | $reference = "111111"; // reference from startValidation step. 85 | 86 | /** @var \VerifyKit\Entity\ValidationCheck $validation */ 87 | $validationCheck = $vfk->checkValidation($reference); 88 | if ($validationCheck->getValidationStatus()) { 89 | $sessionId = $validationCheck->getSessionId(); // session id for the validation result 90 | $appPlatform = $validationCheck->getAppPlatform(); // web, android or ios 91 | } 92 | ``` 93 | 94 | #### Start Validation (OTP) 95 | 96 | ##### Country List 97 | 98 | We recommend that users should choose their country before typing their numbers in order to avoid confusion about the country code. For this reason, it may be helpful to get the country list before OTP verifications. 99 | 100 | ```php 101 | $vfk = new \VerifyKit\Web($serverKey, $clientIp); 102 | 103 | $countryCode = "TR"; // country code parameter for the request. We return the sent countryCode parameter at the top of the list in the response. If you want a specific country (user's country detected by ip on your side for example) to be the first response parameter, you can send $countryCode with your request. Not required. 104 | 105 | $result = $vfk->getCountryList($countryCode); 106 | 107 | /** @var \VerifyKit\Entity\Country $country */ 108 | foreach ($result->getCountryList() as $country){ 109 | echo $country->getPhoneCode(); // phone code. 110 | echo $country->getCountryCode(); // country code 111 | echo $country->getTitle(); // country name 112 | } 113 | 114 | ``` 115 | 116 | Then, start an OTP validation 117 | 118 | ```php 119 | $vfk = new \VerifyKit\Web($serverKey, $clientIp); 120 | 121 | $phoneNumber = '+90........'; // End user phone number. Required. 122 | 123 | $countryCode = 'TR'; // Country code of the end user's phone number. This parameter should exist in the country list request's response array as only the listed countries could be used for OTP validations. Required. 124 | 125 | // For OTP verification to work best, you should send us the MCC and MNC code of the sim card in the user's device. 126 | $mcc = '999'; // Mobile Country Code (MCC) of the sim card in the user's device. Default value is '999'. Not required. 127 | $mnc = '999'; // Mobile Network Code (MNC) of the sim card in the user's device. Default value is '999'. Not required. 128 | 129 | $lang = 'en'; // Language of end user. Default value is 'en' (English). You can set the language of the sent message. This parameter is not required. 130 | 131 | 132 | /** @var \VerifyKit\Entity\OTPSend $result */ 133 | $result = $vfk->sendOTP($phoneNumber, $countryCode, $mcc, $mnc, $lang); 134 | 135 | $reference = $result->getReference(); // This parameter is required for a check OTP request. 136 | 137 | ``` 138 | 139 | #### Check Validation (OTP) 140 | 141 | $phoneNumber, $countryCode, $reference, $code 142 | 143 | ```php 144 | $vfk = new \VerifyKit\Web($serverKey, $clientIp); 145 | 146 | $phoneNumber = '+90........'; // End user phone number. Required. 147 | 148 | $countryCode = 'TR'; // Country code of the end user's phone number. This parameter should exist in the country list request's response array as only the listed countries could be used for OTP vadlidations. Required. 149 | 150 | $reference = "111111"; // reference from sendOtp step. Required. 151 | 152 | $code = "123456"; // The code to be entered by the user receiving the OTP. 153 | 154 | /** @var \VerifyKit\Entity\OtpCheck $validation */ 155 | $otpCheck = $vfk->checkOtp($phoneNumber, $countryCode, $reference, $code); 156 | if ($otpCheck->getValidationStatus()) { 157 | $sessionId = $otpCheck->getSessionId(); // session id for the OTP validation result 158 | } 159 | ``` 160 | 161 | #### Complete Validation 162 | 163 | Finally, get result by session id. 164 | 165 | ```php 166 | $vfk = new \VerifyKit\VerifyKit($serverKey, $clientIp); 167 | 168 | /** @var \VerifyKit\Entity\Response $result */ 169 | $result = $vfk->getResult($sessionId); 170 | 171 | if ($result->isSuccess()) { 172 | echo "Phone number : " . $result->getPhoneNumber() . 173 | ", Validation Type : " . $result->getValidationType() . 174 | ", Validation Date : " . $result->getValidationDate()->format('Y-m-d H:i:s') . PHP_EOL; 175 | } else { 176 | echo "Error message : " . $result->getErrorMessage() . ", error code : " . $result->getErrorCode() . PHP_EOL; 177 | } 178 | ``` 179 | 180 | 181 | #### WhatsApp Session Message 182 | 183 | If you want to send messages to your verified users within 24 hours with WhatsApp Session Message, you can use this way. 184 | 185 | ```php 186 | $waMessage = new \VerifyKit\WASessionMessage($serverKey, $clientIp); 187 | 188 | 189 | /** @var \VerifyKit\Entity\WAMessageResponse $result */ 190 | $result = $waMessage->sendMessage($phoneNumber, $textMessage); // Phone number that you received using the session id in the previous method. 191 | 192 | if ($result->isSuccess()) { 193 | echo "Phone number : " . $result->getPhoneNumber() . ", Message : " . $result->getMessage() . ", Status : " . $result->getStatus() . PHP_EOL; 194 | } else { 195 | echo "Error message : " . $result->getErrorMessage() . ", error code : " . $result->getErrorCode() . PHP_EOL; 196 | } 197 | ``` 198 | 199 | #### Web SDK 200 | If you want to use VerifyKit Web SDK, get an access token using unique id. For other details, [click here](https://github.com/verifykit/verifykit-sdk-php/blob/master/WebSDK.md). 201 | 202 | ```php 203 | $vfk = new \VerifyKit\VerifyKit($serverKey, $clientIp); 204 | 205 | /** @var \VerifyKit\Entity\AccessToken $result */ 206 | $result = $vfk->getWebAccessToken(); 207 | 208 | if ($result->isSuccess()) { 209 | echo "Access Token : " . $result->getAccessToken() . 210 | ", Timeout : " . $result->getTimeout()->format('Y-m-d H:i:s') . PHP_EOL; 211 | } else { 212 | echo "Error message : " . $result->getErrorMessage() . ", error code : " . $result->getErrorCode() . PHP_EOL; 213 | } 214 | ``` 215 | 216 | 217 | --- 218 | 219 | ## Author 220 | 221 | VerifyKit is owned and maintained by [VerifyKit DevTeam](mailto:sdk@verifykit.com). 222 | 223 | 224 | ## License 225 | 226 | The MIT License 227 | 228 | Copyright (c) 2019-2020 VerifyKit. [https://verifykit.com](https://verifykit.com) 229 | 230 | Permission is hereby granted, free of charge, to any person obtaining a copy 231 | of this software and associated documentation files (the "Software"), to deal 232 | in the Software without restriction, including without limitation the rights 233 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 234 | copies of the Software, and to permit persons to whom the Software is 235 | furnished to do so, subject to the following conditions: 236 | 237 | The above copyright notice and this permission notice shall be included in 238 | all copies or substantial portions of the Software. 239 | 240 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 241 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 242 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 243 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 244 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 245 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 246 | THE SOFTWARE. -------------------------------------------------------------------------------- /WebSDK.md: -------------------------------------------------------------------------------- 1 | Web Sdk Implementation 2 | --- 3 | Web SDK works with an iframe structure that handles user authentication and returns session identification number on successful verification. Before using the web-sdk, customers should whitelist their site's domain by creating a web app and registering their domain as a **"trusted domain"** on [VerifyKit Dashboard](https://dashboard.verifykit.com) 4 | * Before each authentication, developers should get a unique and one-time authentication token in order to initialize sdk script. (For details of this procedure please visit [here.](https://github.com/verifykit/verifykit-sdk-php#web-sdk)) 5 | After receiving the one-time token, javascript source and given div tag and should be inserted on the page where VerifyKit iframe is intended to appear. **lang** parameter determines the sdk screens' language (en, ru, tr, etc) and **token** parameter is needed for security and identification. 6 | ```html 7 |
8 | 9 | ``` 10 | * After inserting the code block above, a callback method **(cbMethod)** should be created on the parent page which should use the **sessionId** parameter that the identification value will be assigned when the verification successfully completes. This parameter should be stored and will be used to fetch client detail from backend to backend api request. 11 | * After including the given code and creating the callback method, **"initVerifyKit(cbMethod)"** method can be assigned to any login mechanism website owner prefers. initVerifyKit method will initialize the iframe and set the callback method to the listener of the verification process. 12 | 13 | ```javascript 14 | let cbMethod = function(){ 15 | console.log('Session id : ' + sessionId); 16 | } 17 | 18 | initVerifyKit(cbMethod); 19 | ``` 20 | 21 | * When user successfully authenticates with VerifyKit, user defined cbMethod will be triggered within the sdk scripts, running the intended business flow after the successful verification. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "verifykit/verifykit-sdk-php", 3 | "type": "library", 4 | "description": "VerifyKit is the next gen phone number validation system. Users can easily verify their phone numbers without the need of entering phone number or a pin code.", 5 | "keywords": [ 6 | "verifykit" 7 | ], 8 | "homepage": "https://verifykit.com", 9 | "license": "MIT", 10 | "require": { 11 | "php": ">=5.5.0", 12 | "ext-curl": "*", 13 | "ext-json": "*" 14 | }, 15 | "autoload": { 16 | "psr-4": { 17 | "VerifyKit\\": "src/VerifyKit" 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/VerifyKit/Constant/ValidationMethod.php: -------------------------------------------------------------------------------- 1 | requestId = isset($meta["requestId"]) ? $meta["requestId"] : null; 42 | $this->httpStatusCode = isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null; 43 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 44 | $this->errorCode = $meta["errorCode"]; 45 | $this->errorMessage = $meta["errorMessage"]; 46 | } elseif (isset($response["result"])) { 47 | $result = $response["result"]; 48 | $this->success = true; 49 | $this->accessToken = isset($result["accessToken"]) ? $result["accessToken"] : null; 50 | $this->timeout = isset($result["timeout"]) ? new \DateTime($result["timeout"]) : null; 51 | } 52 | } 53 | 54 | /** 55 | * @return string 56 | */ 57 | public function getRequestId() 58 | { 59 | return $this->requestId; 60 | } 61 | 62 | /** 63 | * @return int 64 | */ 65 | public function getHttpStatusCode() 66 | { 67 | return $this->httpStatusCode; 68 | } 69 | 70 | /** 71 | * @return string 72 | */ 73 | public function getAccessToken() 74 | { 75 | return $this->accessToken; 76 | } 77 | 78 | /** 79 | * @return \DateTime 80 | */ 81 | public function getTimeout() 82 | { 83 | return $this->timeout; 84 | } 85 | 86 | 87 | /** 88 | * @return string 89 | */ 90 | public function getErrorCode() 91 | { 92 | return $this->errorCode; 93 | } 94 | 95 | /** 96 | * @return string 97 | */ 98 | public function getErrorMessage() 99 | { 100 | return $this->errorMessage; 101 | } 102 | 103 | /** 104 | * @return bool 105 | */ 106 | public function isSuccess() 107 | { 108 | return $this->success; 109 | } 110 | 111 | 112 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/BlacklistAdd.php: -------------------------------------------------------------------------------- 1 | requestId = (isset($meta["requestId"]) ? $meta["requestId"] : null); 55 | $this->httpStatusCode = (isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null); 56 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 57 | $this->errorCode = $meta["errorCode"]; 58 | $this->errorMessage = $meta["errorMessage"]; 59 | } elseif (isset($response["result"])) { 60 | $result = $response["result"]; 61 | $this->success = true; 62 | $this->totalCount = $result["totalCount"]; 63 | $this->successCount = $result["successCount"]; 64 | $this->alreadyExistsCount = $result["alreadyExistsCount"]; 65 | $this->numberFormatCount = $result["numberFormatCount"]; 66 | $this->failCount = $result["failCount"]; 67 | $this->alreadyExistsList = $result["alreadyExistsList"]; 68 | $this->numberFormatList = $result["numberFormatList"]; 69 | $this->failList = $result["failList"]; 70 | } 71 | } 72 | 73 | /** 74 | * @return string 75 | */ 76 | public function getRequestId() 77 | { 78 | return $this->requestId; 79 | } 80 | 81 | /** 82 | * @return int 83 | */ 84 | public function getHttpStatusCode() 85 | { 86 | return $this->httpStatusCode; 87 | } 88 | 89 | /** 90 | * @return string 91 | */ 92 | public function getErrorCode() 93 | { 94 | return $this->errorCode; 95 | } 96 | 97 | /** 98 | * @return string 99 | */ 100 | public function getErrorMessage() 101 | { 102 | return $this->errorMessage; 103 | } 104 | 105 | /** 106 | * @return bool 107 | */ 108 | public function isSuccess() 109 | { 110 | return $this->success; 111 | } 112 | 113 | /** 114 | * @return int 115 | */ 116 | public function getTotalCount() 117 | { 118 | return $this->totalCount; 119 | } 120 | 121 | 122 | /** 123 | * @return int 124 | */ 125 | public function getSuccessCount() 126 | { 127 | return $this->successCount; 128 | } 129 | 130 | /** 131 | * @return int 132 | */ 133 | public function getAlreadyExistsCount() 134 | { 135 | return $this->alreadyExistsCount; 136 | } 137 | 138 | /** 139 | * @return int 140 | */ 141 | public function getNumberFormatCount() 142 | { 143 | return $this->numberFormatCount; 144 | } 145 | 146 | /** 147 | * @return int 148 | */ 149 | public function getFailCount() 150 | { 151 | return $this->failCount; 152 | } 153 | 154 | /** 155 | * @return array 156 | */ 157 | public function getAlreadyExistsList() 158 | { 159 | return $this->alreadyExistsList; 160 | } 161 | 162 | /** 163 | * @return array 164 | */ 165 | public function getNumberFormatList() 166 | { 167 | return $this->numberFormatList; 168 | } 169 | 170 | /** 171 | * @return array 172 | */ 173 | public function getFailList() 174 | { 175 | return $this->failList; 176 | } 177 | 178 | 179 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/BlacklistRemove.php: -------------------------------------------------------------------------------- 1 | requestId = (isset($meta["requestId"]) ? $meta["requestId"] : null); 55 | $this->httpStatusCode = (isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null); 56 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 57 | $this->errorCode = $meta["errorCode"]; 58 | $this->errorMessage = $meta["errorMessage"]; 59 | } elseif (isset($response["result"])) { 60 | $result = $response["result"]; 61 | $this->success = true; 62 | $this->totalCount = $result["totalCount"]; 63 | $this->successCount = $result["successCount"]; 64 | $this->notExistsCount = $result["notExistsCount"]; 65 | $this->numberFormatCount = $result["numberFormatCount"]; 66 | $this->failCount = $result["failCount"]; 67 | $this->notExistsList = $result["notExistsList"]; 68 | $this->numberFormatList = $result["numberFormatList"]; 69 | $this->failList = $result["failList"]; 70 | } 71 | } 72 | 73 | /** 74 | * @return string 75 | */ 76 | public function getRequestId() 77 | { 78 | return $this->requestId; 79 | } 80 | 81 | /** 82 | * @return int 83 | */ 84 | public function getHttpStatusCode() 85 | { 86 | return $this->httpStatusCode; 87 | } 88 | 89 | /** 90 | * @return string 91 | */ 92 | public function getErrorCode() 93 | { 94 | return $this->errorCode; 95 | } 96 | 97 | /** 98 | * @return string 99 | */ 100 | public function getErrorMessage() 101 | { 102 | return $this->errorMessage; 103 | } 104 | 105 | /** 106 | * @return bool 107 | */ 108 | public function isSuccess() 109 | { 110 | return $this->success; 111 | } 112 | 113 | /** 114 | * @return int 115 | */ 116 | public function getTotalCount() 117 | { 118 | return $this->totalCount; 119 | } 120 | 121 | 122 | /** 123 | * @return int 124 | */ 125 | public function getSuccessCount() 126 | { 127 | return $this->successCount; 128 | } 129 | 130 | /** 131 | * @return int 132 | */ 133 | public function getNotExistsCount() 134 | { 135 | return $this->notExistsCount; 136 | } 137 | 138 | 139 | /** 140 | * @return int 141 | */ 142 | public function getNumberFormatCount() 143 | { 144 | return $this->numberFormatCount; 145 | } 146 | 147 | /** 148 | * @return int 149 | */ 150 | public function getFailCount() 151 | { 152 | return $this->failCount; 153 | } 154 | 155 | /** 156 | * @return array 157 | */ 158 | public function getNotExistsList() 159 | { 160 | return $this->notExistsList; 161 | } 162 | 163 | 164 | /** 165 | * @return array 166 | */ 167 | public function getNumberFormatList() 168 | { 169 | return $this->numberFormatList; 170 | } 171 | 172 | /** 173 | * @return array 174 | */ 175 | public function getFailList() 176 | { 177 | return $this->failList; 178 | } 179 | 180 | 181 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/Countries.php: -------------------------------------------------------------------------------- 1 | requestId = (isset($meta["requestId"]) ? $meta["requestId"] : null); 39 | $this->httpStatusCode = (isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null); 40 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 41 | $this->errorCode = $meta["errorCode"]; 42 | $this->errorMessage = $meta["errorMessage"]; 43 | } elseif (isset($response["result"])) { 44 | $result = $response["result"]; 45 | $this->success = true; 46 | 47 | foreach ($result["list"] as $item) { 48 | $country = new Country(); 49 | $country->setPhoneCode($item["phoneCode"]); 50 | $country->setCountryCode($item["countryCode"]); 51 | $country->setTitle($item["title"]); 52 | 53 | $this->addListItem($country); 54 | } 55 | } 56 | } 57 | 58 | 59 | /** 60 | * @return string 61 | */ 62 | public function getRequestId() 63 | { 64 | return $this->requestId; 65 | } 66 | 67 | /** 68 | * @return int 69 | */ 70 | public function getHttpStatusCode() 71 | { 72 | return $this->httpStatusCode; 73 | } 74 | 75 | /** 76 | * @return string 77 | */ 78 | public function getErrorCode() 79 | { 80 | return $this->errorCode; 81 | } 82 | 83 | /** 84 | * @return string 85 | */ 86 | public function getErrorMessage() 87 | { 88 | return $this->errorMessage; 89 | } 90 | 91 | /** 92 | * @return bool 93 | */ 94 | public function isSuccess() 95 | { 96 | return $this->success; 97 | } 98 | 99 | /** 100 | * @return array 101 | */ 102 | public function getCountryList() 103 | { 104 | return $this->countryList; 105 | } 106 | 107 | /** 108 | * @param Country $country 109 | */ 110 | public function addListItem(Country $country) 111 | { 112 | $this->countryList[] = $country; 113 | } 114 | 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/VerifyKit/Entity/Country.php: -------------------------------------------------------------------------------- 1 | phoneCode; 28 | } 29 | 30 | /** 31 | * @param string $phoneCode 32 | */ 33 | public function setPhoneCode($phoneCode) 34 | { 35 | $this->phoneCode = $phoneCode; 36 | } 37 | 38 | /** 39 | * @return string 40 | */ 41 | public function getCountryCode() 42 | { 43 | return $this->countryCode; 44 | } 45 | 46 | /** 47 | * @param string $countryCode 48 | */ 49 | public function setCountryCode($countryCode) 50 | { 51 | $this->countryCode = $countryCode; 52 | } 53 | 54 | /** 55 | * @return string 56 | */ 57 | public function getTitle() 58 | { 59 | return $this->title; 60 | } 61 | 62 | /** 63 | * @param string $title 64 | */ 65 | public function setTitle($title) 66 | { 67 | $this->title = $title; 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/EmailValidationStart.php: -------------------------------------------------------------------------------- 1 | requestId = (isset($meta["requestId"]) ? $meta["requestId"] : null); 46 | $this->httpStatusCode = (isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null); 47 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 48 | $this->errorCode = $meta["errorCode"]; 49 | $this->errorMessage = $meta["errorMessage"]; 50 | } elseif (isset($response["result"])) { 51 | $result = $response["result"]; 52 | $this->success = true; 53 | $this->reference = $result["reference"]; 54 | $this->to = $result["to"]; 55 | $this->subject = $result["subject"]; 56 | $this->body = $result["body"]; 57 | $this->mailto = $result["mailto"]; 58 | } 59 | } 60 | 61 | /** 62 | * @return string 63 | */ 64 | public function getRequestId() 65 | { 66 | return $this->requestId; 67 | } 68 | 69 | 70 | /** 71 | * @return int 72 | */ 73 | public function getHttpStatusCode() 74 | { 75 | return $this->httpStatusCode; 76 | } 77 | 78 | /** 79 | * @return string 80 | */ 81 | public function getErrorCode() 82 | { 83 | return $this->errorCode; 84 | } 85 | 86 | /** 87 | * @return string 88 | */ 89 | public function getErrorMessage() 90 | { 91 | return $this->errorMessage; 92 | } 93 | 94 | /** 95 | * @return bool 96 | */ 97 | public function isSuccess() 98 | { 99 | return $this->success; 100 | } 101 | 102 | /** 103 | * @return string 104 | */ 105 | public function getReference() 106 | { 107 | return $this->reference; 108 | } 109 | 110 | /** 111 | * @return string 112 | */ 113 | public function getTo() 114 | { 115 | return $this->to; 116 | } 117 | 118 | /** 119 | * @return string 120 | */ 121 | public function getSubject() 122 | { 123 | return $this->subject; 124 | } 125 | 126 | /** 127 | * @return string 128 | */ 129 | public function getBody() 130 | { 131 | return $this->body; 132 | } 133 | 134 | /** 135 | * @return string 136 | */ 137 | public function getMailto() 138 | { 139 | return $this->mailto; 140 | } 141 | 142 | 143 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/Localization.php: -------------------------------------------------------------------------------- 1 | key; 23 | } 24 | 25 | /** 26 | * @param string $key 27 | */ 28 | public function setKey($key) 29 | { 30 | $this->key = $key; 31 | } 32 | 33 | /** 34 | * @return string 35 | */ 36 | public function getValue() 37 | { 38 | return $this->value; 39 | } 40 | 41 | /** 42 | * @param string $value 43 | */ 44 | public function setValue($value) 45 | { 46 | $this->value = $value; 47 | } 48 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/OTPCheck.php: -------------------------------------------------------------------------------- 1 | requestId = isset($meta["requestId"]) ? $meta["requestId"] : null; 38 | $this->httpStatusCode = isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null; 39 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 40 | $this->errorCode = $meta["errorCode"]; 41 | $this->errorMessage = $meta["errorMessage"]; 42 | } elseif (isset($response["result"])) { 43 | $result = $response["result"]; 44 | $this->success = true; 45 | $this->validationStatus = $result["validationStatus"]; 46 | $this->sessionId = $result["sessionId"]; 47 | } 48 | } 49 | 50 | /** 51 | * @return string 52 | */ 53 | public function getRequestId() 54 | { 55 | return $this->requestId; 56 | } 57 | 58 | /** 59 | * @return int 60 | */ 61 | public function getHttpStatusCode() 62 | { 63 | return $this->httpStatusCode; 64 | } 65 | 66 | /** 67 | * @return string 68 | */ 69 | public function getErrorCode() 70 | { 71 | return $this->errorCode; 72 | } 73 | 74 | /** 75 | * @return string 76 | */ 77 | public function getErrorMessage() 78 | { 79 | return $this->errorMessage; 80 | } 81 | 82 | /** 83 | * @return bool 84 | */ 85 | public function isSuccess() 86 | { 87 | return $this->success; 88 | } 89 | 90 | /** 91 | * @return bool 92 | */ 93 | public function getValidationStatus() 94 | { 95 | return $this->validationStatus; 96 | } 97 | 98 | /** 99 | * @return string 100 | */ 101 | public function getSessionId() 102 | { 103 | return $this->sessionId; 104 | } 105 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/OTPSend.php: -------------------------------------------------------------------------------- 1 | requestId = (isset($meta["requestId"]) ? $meta["requestId"] : null); 41 | $this->httpStatusCode = (isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null); 42 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 43 | $this->errorCode = $meta["errorCode"]; 44 | $this->errorMessage = $meta["errorMessage"]; 45 | } elseif (isset($response["result"])) { 46 | $result = $response["result"]; 47 | $this->success = true; 48 | $this->reference = $result["reference"]; 49 | $this->timeout = $result["timeout"]; 50 | $this->length = $result["length"]; 51 | } 52 | } 53 | 54 | /** 55 | * @return string 56 | */ 57 | public function getRequestId() 58 | { 59 | return $this->requestId; 60 | } 61 | 62 | 63 | /** 64 | * @return int 65 | */ 66 | public function getHttpStatusCode() 67 | { 68 | return $this->httpStatusCode; 69 | } 70 | 71 | /** 72 | * @return string 73 | */ 74 | public function getErrorCode() 75 | { 76 | return $this->errorCode; 77 | } 78 | 79 | /** 80 | * @return string 81 | */ 82 | public function getErrorMessage() 83 | { 84 | return $this->errorMessage; 85 | } 86 | 87 | /** 88 | * @return bool 89 | */ 90 | public function isSuccess() 91 | { 92 | return $this->success; 93 | } 94 | 95 | /** 96 | * @return string 97 | */ 98 | public function getReference() 99 | { 100 | return $this->reference; 101 | } 102 | 103 | /** 104 | * @return int 105 | */ 106 | public function getTimeout() 107 | { 108 | return $this->timeout; 109 | } 110 | 111 | /** 112 | * @return int 113 | */ 114 | public function getLength() 115 | { 116 | return $this->length; 117 | } 118 | 119 | 120 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/Response.php: -------------------------------------------------------------------------------- 1 | requestId = isset($meta["requestId"]) ? $meta["requestId"] : null; 51 | $this->httpStatusCode = isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null; 52 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 53 | $this->errorCode = $meta["errorCode"]; 54 | $this->errorMessage = $meta["errorMessage"]; 55 | } elseif (isset($response["result"])) { 56 | $result = $response["result"]; 57 | $this->success = true; 58 | $this->phoneNumber = isset($result["phoneNumber"]) ? $result["phoneNumber"] : null; 59 | $this->validationType = isset($result["validationType"]) ? $result["validationType"] : null; 60 | $this->validationDate = isset($result["validationDate"]) ? new \DateTime($result["validationDate"]) : null; 61 | $this->countryCode = isset($result["countryCode"]) ? $result["countryCode"] : null; 62 | $this->mobileNetwork = isset($result["mobileNetwork"]) ? $result["mobileNetwork"] : null; 63 | } 64 | } 65 | 66 | /** 67 | * @return string|null 68 | */ 69 | public function getRequestId() 70 | { 71 | return $this->requestId; 72 | } 73 | 74 | /** 75 | * @return int|null 76 | */ 77 | public function getHttpStatusCode() 78 | { 79 | return $this->httpStatusCode; 80 | } 81 | 82 | /** 83 | * @return string|null 84 | */ 85 | public function getValidationType() 86 | { 87 | return $this->validationType; 88 | } 89 | 90 | /** 91 | * @return \DateTime|null 92 | */ 93 | public function getValidationDate() 94 | { 95 | return $this->validationDate; 96 | } 97 | 98 | /** 99 | * @return string 100 | */ 101 | public function getCountryCode() 102 | { 103 | return $this->countryCode; 104 | } 105 | 106 | /** 107 | * @return string|null 108 | */ 109 | public function getPhoneNumber() 110 | { 111 | return $this->phoneNumber; 112 | } 113 | 114 | /** 115 | * @return array|null 116 | */ 117 | public function getMobileNetwork() 118 | { 119 | return $this->mobileNetwork; 120 | } 121 | 122 | /** 123 | * @return string|null 124 | */ 125 | public function getErrorCode() 126 | { 127 | return $this->errorCode; 128 | } 129 | 130 | 131 | /** 132 | * @return string|null 133 | */ 134 | public function getErrorMessage() 135 | { 136 | return $this->errorMessage; 137 | } 138 | 139 | /** 140 | * @return bool 141 | */ 142 | public function isSuccess() 143 | { 144 | return $this->success; 145 | } 146 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/ValidationCheck.php: -------------------------------------------------------------------------------- 1 | requestId = isset($meta["requestId"]) ? $meta["requestId"] : null; 40 | $this->httpStatusCode = isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null; 41 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 42 | $this->errorCode = $meta["errorCode"]; 43 | $this->errorMessage = $meta["errorMessage"]; 44 | } elseif (isset($response["result"])) { 45 | $result = $response["result"]; 46 | $this->success = true; 47 | $this->validationStatus = $result["validationStatus"]; 48 | $this->sessionId = $result["sessionId"]; 49 | $this->appPlatform = $result["appPlatform"]; 50 | } 51 | } 52 | 53 | /** 54 | * @return string 55 | */ 56 | public function getRequestId() 57 | { 58 | return $this->requestId; 59 | } 60 | 61 | /** 62 | * @return int 63 | */ 64 | public function getHttpStatusCode() 65 | { 66 | return $this->httpStatusCode; 67 | } 68 | 69 | /** 70 | * @return string 71 | */ 72 | public function getErrorCode() 73 | { 74 | return $this->errorCode; 75 | } 76 | 77 | /** 78 | * @return string 79 | */ 80 | public function getErrorMessage() 81 | { 82 | return $this->errorMessage; 83 | } 84 | 85 | /** 86 | * @return bool 87 | */ 88 | public function isSuccess() 89 | { 90 | return $this->success; 91 | } 92 | 93 | /** 94 | * @return bool 95 | */ 96 | public function getValidationStatus() 97 | { 98 | return $this->validationStatus; 99 | } 100 | 101 | /** 102 | * @return string 103 | */ 104 | public function getSessionId() 105 | { 106 | return $this->sessionId; 107 | } 108 | 109 | /** 110 | * @return string 111 | */ 112 | public function getAppPlatform() 113 | { 114 | return $this->appPlatform; 115 | } 116 | 117 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/ValidationMethod.php: -------------------------------------------------------------------------------- 1 | name; 35 | } 36 | 37 | /** 38 | * @param string $name 39 | */ 40 | public function setName($name) 41 | { 42 | $this->name = $name; 43 | } 44 | 45 | /** 46 | * @return string 47 | */ 48 | public function getApp() 49 | { 50 | return $this->app; 51 | } 52 | 53 | /** 54 | * @param string $app 55 | */ 56 | public function setApp($app) 57 | { 58 | $this->app = $app; 59 | } 60 | 61 | /** 62 | * @return string 63 | */ 64 | public function getText() 65 | { 66 | return $this->text; 67 | } 68 | 69 | /** 70 | * @param string $text 71 | */ 72 | public function setText($text) 73 | { 74 | $this->text = $text; 75 | } 76 | 77 | /** 78 | * @return string 79 | */ 80 | public function getTextColour() 81 | { 82 | return $this->textColour; 83 | } 84 | 85 | /** 86 | * @param string $textColour 87 | */ 88 | public function setTextColour($textColour) 89 | { 90 | $this->textColour = $textColour; 91 | } 92 | 93 | /** 94 | * @return string 95 | */ 96 | public function getBgColour() 97 | { 98 | return $this->bgColour; 99 | } 100 | 101 | /** 102 | * @param string $bgColour 103 | */ 104 | public function setBgColour($bgColour) 105 | { 106 | $this->bgColour = $bgColour; 107 | } 108 | 109 | /** 110 | * @return string 111 | */ 112 | public function getIconPath() 113 | { 114 | return $this->iconPath; 115 | } 116 | 117 | /** 118 | * @param string $iconPath 119 | */ 120 | public function setIconPath($iconPath) 121 | { 122 | $this->iconPath = $iconPath; 123 | } 124 | 125 | 126 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/ValidationMethodList.php: -------------------------------------------------------------------------------- 1 | requestId = (isset($meta["requestId"]) ? $meta["requestId"] : null); 44 | $this->httpStatusCode = (isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null); 45 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 46 | $this->errorCode = $meta["errorCode"]; 47 | $this->errorMessage = $meta["errorMessage"]; 48 | } elseif (isset($response["result"])) { 49 | $result = $response["result"]; 50 | $this->success = true; 51 | 52 | $this->description = $result["description"]; 53 | 54 | foreach ($result["list"] as $item) { 55 | $validationMethod = new ValidationMethod(); 56 | $validationMethod->setName($item["name"]); 57 | $validationMethod->setApp($item["app"]); 58 | $validationMethod->setText($item["text"]); 59 | $validationMethod->setTextColour($item["textColour"]); 60 | $validationMethod->setBgColour($item["bgColour"]); 61 | $validationMethod->setIconPath($item["icon"]); 62 | 63 | $this->addListItem($validationMethod); 64 | } 65 | 66 | foreach ($result["localizationList"] as $localizationItem) { 67 | $localization = new Localization(); 68 | $localization->setKey($localizationItem["key"]); 69 | $localization->setValue($localizationItem["value"]); 70 | 71 | $this->addLocalizationItem($localization); 72 | } 73 | } 74 | } 75 | 76 | 77 | /** 78 | * @return string 79 | */ 80 | public function getRequestId() 81 | { 82 | return $this->requestId; 83 | } 84 | 85 | /** 86 | * @return int 87 | */ 88 | public function getHttpStatusCode() 89 | { 90 | return $this->httpStatusCode; 91 | } 92 | 93 | /** 94 | * @return string 95 | */ 96 | public function getErrorCode() 97 | { 98 | return $this->errorCode; 99 | } 100 | 101 | 102 | /** 103 | * @return string 104 | */ 105 | public function getErrorMessage() 106 | { 107 | return $this->errorMessage; 108 | } 109 | 110 | /** 111 | * @return bool 112 | */ 113 | public function isSuccess() 114 | { 115 | return $this->success; 116 | } 117 | 118 | /** 119 | * @return array 120 | */ 121 | public function getList() 122 | { 123 | return $this->list; 124 | } 125 | 126 | /** 127 | * @param ValidationMethod $validationMethod 128 | */ 129 | public function addListItem(ValidationMethod $validationMethod) 130 | { 131 | $this->list[] = $validationMethod; 132 | } 133 | 134 | /** 135 | * @return string 136 | */ 137 | public function getDescription() 138 | { 139 | return $this->description; 140 | } 141 | 142 | /** 143 | * @return array 144 | */ 145 | public function getLocalizationList() 146 | { 147 | return $this->localizationList; 148 | } 149 | 150 | /** 151 | * @param Localization $localization 152 | */ 153 | public function addLocalizationItem(Localization $localization) 154 | { 155 | $this->localizationList[] = $localization; 156 | } 157 | 158 | 159 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/ValidationStart.php: -------------------------------------------------------------------------------- 1 | requestId = (isset($meta["requestId"]) ? $meta["requestId"] : null); 40 | $this->httpStatusCode = (isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null); 41 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 42 | $this->errorCode = $meta["errorCode"]; 43 | $this->errorMessage = $meta["errorMessage"]; 44 | } elseif (isset($response["result"])) { 45 | $result = $response["result"]; 46 | $this->success = true; 47 | $this->deeplink = $result["deeplink"]; 48 | $this->reference = $result["reference"]; 49 | $this->qrCode = $result["qrCode"]; 50 | } 51 | } 52 | 53 | /** 54 | * @return string 55 | */ 56 | public function getRequestId() 57 | { 58 | return $this->requestId; 59 | } 60 | 61 | 62 | /** 63 | * @return int 64 | */ 65 | public function getHttpStatusCode() 66 | { 67 | return $this->httpStatusCode; 68 | } 69 | 70 | /** 71 | * @return string 72 | */ 73 | public function getErrorCode() 74 | { 75 | return $this->errorCode; 76 | } 77 | 78 | /** 79 | * @return string 80 | */ 81 | public function getErrorMessage() 82 | { 83 | return $this->errorMessage; 84 | } 85 | 86 | /** 87 | * @return bool 88 | */ 89 | public function isSuccess() 90 | { 91 | return $this->success; 92 | } 93 | 94 | /** 95 | * @return string 96 | */ 97 | public function getDeeplink() 98 | { 99 | return $this->deeplink; 100 | } 101 | 102 | /** 103 | * @return string 104 | */ 105 | public function getReference() 106 | { 107 | return $this->reference; 108 | } 109 | 110 | /** 111 | * @return string 112 | */ 113 | public function getQrCode() 114 | { 115 | return $this->qrCode; 116 | } 117 | 118 | } -------------------------------------------------------------------------------- /src/VerifyKit/Entity/WAMessageResponse.php: -------------------------------------------------------------------------------- 1 | requestId = isset($meta["requestId"]) ? $meta["requestId"] : null; 45 | $this->httpStatusCode = isset($meta["httpStatusCode"]) ? $meta["httpStatusCode"] : null; 46 | if (isset($meta["errorMessage"]) && isset($meta["errorCode"])) { 47 | $this->errorCode = $meta["errorCode"]; 48 | $this->errorMessage = $meta["errorMessage"]; 49 | } elseif (isset($response["result"])) { 50 | $result = $response["result"]; 51 | $this->success = true; 52 | $this->phoneNumber = isset($result["phoneNumber"]) ? $result["phoneNumber"] : null; 53 | $this->message = isset($result["message"]) ? $result["message"] : null; 54 | $this->status = isset($result["status"]) ? $result["status"] : null; 55 | } 56 | } 57 | 58 | /** 59 | * @return string|null 60 | */ 61 | public function getRequestId() 62 | { 63 | return $this->requestId; 64 | } 65 | 66 | /** 67 | * @return int|null 68 | */ 69 | public function getHttpStatusCode() 70 | { 71 | return $this->httpStatusCode; 72 | } 73 | 74 | /** 75 | * @return string 76 | */ 77 | public function getMessage() 78 | { 79 | return $this->message; 80 | } 81 | 82 | /** 83 | * @return string 84 | */ 85 | public function getStatus() 86 | { 87 | return $this->status; 88 | } 89 | 90 | 91 | /** 92 | * @return string|null 93 | */ 94 | public function getPhoneNumber() 95 | { 96 | return $this->phoneNumber; 97 | } 98 | 99 | /** 100 | * @return string|null 101 | */ 102 | public function getErrorCode() 103 | { 104 | return $this->errorCode; 105 | } 106 | 107 | 108 | /** 109 | * @return string|null 110 | */ 111 | public function getErrorMessage() 112 | { 113 | return $this->errorMessage; 114 | } 115 | 116 | /** 117 | * @return bool 118 | */ 119 | public function isSuccess() 120 | { 121 | return $this->success; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/VerifyKit/Exception/CountryCodeEmptyException.php: -------------------------------------------------------------------------------- 1 | serverKey = $serverKey; 42 | 43 | if (!$clientIp) { 44 | $clientIp = $_SERVER["REMOTE_ADDR"]; 45 | } 46 | $this->clientIp = $clientIp; 47 | } 48 | 49 | /** 50 | * @param $sessionId 51 | * @return Response 52 | * @throws CurlException 53 | * @throws \Exception 54 | */ 55 | public function getResult($sessionId) 56 | { 57 | if (null === $sessionId || is_array($sessionId) || false == preg_match('/^[a-zA-Z0-9]+$/', $sessionId)) { 58 | throw new SessionIdEmptyException("Session id is empty or not formal: " . json_encode($sessionId), 835002); 59 | } 60 | 61 | $response = $this->makeRequest('/result', self::METHOD_POST, array("sessionId" => $sessionId)); 62 | 63 | return new Response($response); 64 | } 65 | 66 | /** 67 | * @return AccessToken 68 | * @throws CurlException 69 | * @throws \Exception 70 | */ 71 | public function getWebAccessToken() 72 | { 73 | $response = $this->makeRequest('/access-token', self::METHOD_GET); 74 | 75 | return new AccessToken($response); 76 | } 77 | 78 | /** 79 | * @param $endpoint 80 | * @param string $method 81 | * @param array $postFields 82 | * @return bool|string 83 | * @throws CurlException 84 | */ 85 | protected function makeRequest($endpoint, $method = 'POST', $postFields = array()) 86 | { 87 | $curl = curl_init(); 88 | 89 | curl_setopt($curl, CURLOPT_URL, $this->baseUrl . $endpoint); 90 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 91 | curl_setopt($curl, CURLOPT_MAXREDIRS, 10); 92 | curl_setopt($curl, CURLOPT_TIMEOUT, 30); 93 | curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 94 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 95 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 96 | 97 | $userAgent = 'VerifyKitWeb/1.0.0'; 98 | if (isset($_SERVER["HTTP_USER_AGENT"])) { 99 | $userAgent .= ' - ' . $_SERVER["HTTP_USER_AGENT"]; 100 | } 101 | curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); 102 | curl_setopt($curl, CURLOPT_HTTPHEADER, array( 103 | "X-Vfk-Server-Key: " . $this->serverKey, 104 | "Cache-Control: no-cache", 105 | "Content-Type: application/json;", 106 | "X-Vfk-Forwarded-For: " . $this->clientIp 107 | )); 108 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); 109 | if ($method == self::METHOD_POST) { 110 | curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postFields)); 111 | } 112 | 113 | $response = curl_exec($curl); 114 | 115 | 116 | if (curl_errno($curl)) { 117 | $error_msg = curl_error($curl); 118 | } 119 | curl_close($curl); 120 | 121 | if (isset($error_msg)) { 122 | throw new CurlException($error_msg); 123 | } 124 | 125 | return $response; 126 | } 127 | 128 | /** 129 | * @param string $baseUrl 130 | */ 131 | public function setBaseUrl($baseUrl) 132 | { 133 | $this->baseUrl = $baseUrl; 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/VerifyKit/WASessionMessage.php: -------------------------------------------------------------------------------- 1 | serverKey = $serverKey; 39 | 40 | if (!$clientIp) { 41 | $clientIp = $_SERVER["REMOTE_ADDR"]; 42 | } 43 | $this->clientIp = $clientIp; 44 | } 45 | 46 | /** 47 | * @param $phoneNumber 48 | * @param $textMessage 49 | * @return WAMessageResponse 50 | * @throws CurlException 51 | * @throws PhoneNumberEmptyException 52 | * @throws TextMessageEmptyException 53 | */ 54 | public function sendMessage($phoneNumber, $textMessage) 55 | { 56 | if (null === $phoneNumber || $phoneNumber == "") { 57 | throw new PhoneNumberEmptyException("Phone number cannot be empty.", 837002); 58 | } 59 | 60 | if (null === $textMessage || $textMessage == "" || strlen($textMessage) < 10) { 61 | throw new TextMessageEmptyException("Text message cannot be empty or less than 10 characters.", 837003); 62 | } 63 | 64 | $response = $this->makeRequest('/send-whatsapp-message', self::METHOD_POST, 65 | array("phoneNumber" => $phoneNumber, "message" => $textMessage) 66 | ); 67 | 68 | return new WAMessageResponse($response); 69 | } 70 | 71 | /** 72 | * @param $endpoint 73 | * @param string $method 74 | * @param array $postFields 75 | * @return bool|string 76 | * @throws CurlException 77 | */ 78 | protected function makeRequest($endpoint, $method = 'POST', $postFields = array()) 79 | { 80 | $curl = curl_init(); 81 | 82 | curl_setopt($curl, CURLOPT_URL, self::URL . $endpoint); 83 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 84 | curl_setopt($curl, CURLOPT_MAXREDIRS, 10); 85 | curl_setopt($curl, CURLOPT_TIMEOUT, 30); 86 | curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 87 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 88 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 89 | 90 | $userAgent = 'VerifyKitWAApiMessage/1.0.0'; 91 | if (isset($_SERVER["HTTP_USER_AGENT"])) { 92 | $userAgent .= ' - ' . $_SERVER["HTTP_USER_AGENT"]; 93 | } 94 | curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); 95 | curl_setopt($curl, CURLOPT_HTTPHEADER, array( 96 | "X-Vfk-Server-Key: " . $this->serverKey, 97 | "Cache-Control: no-cache", 98 | "Content-Type: application/json;", 99 | "X-Vfk-Forwarded-For: " . $this->clientIp 100 | )); 101 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); 102 | if ($method == self::METHOD_POST) { 103 | curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postFields)); 104 | } 105 | 106 | $response = curl_exec($curl); 107 | 108 | 109 | if (curl_errno($curl)) { 110 | $error_msg = curl_error($curl); 111 | } 112 | curl_close($curl); 113 | 114 | if (isset($error_msg)) { 115 | throw new CurlException($error_msg); 116 | } 117 | 118 | return $response; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/VerifyKit/Web.php: -------------------------------------------------------------------------------- 1 | serverKey = $serverKey; 54 | 55 | if (!$clientIp) { 56 | $clientIp = $_SERVER["REMOTE_ADDR"]; 57 | } 58 | $this->clientIp = $clientIp; 59 | 60 | } 61 | 62 | 63 | /** 64 | * @throws CurlException 65 | */ 66 | public function getValidationMethodList() 67 | { 68 | $response = $this->makeRequest('/init', self::METHOD_GET); 69 | 70 | return new ValidationMethodList($response); 71 | } 72 | 73 | 74 | /** 75 | * @param $validationMethod 76 | * @param string $lang 77 | * @param bool $deeplink 78 | * @param bool $qrCode 79 | * @return ValidationStart 80 | * @throws CurlException 81 | * @throws ValidationMethodEmptyException 82 | */ 83 | public function startValidation($validationMethod, $lang = 'en', $deeplink = true, $qrCode = false) 84 | { 85 | if (null === $validationMethod || $validationMethod == "") { 86 | throw new ValidationMethodEmptyException("Validation method cannot be empty.", 836002); 87 | } 88 | 89 | if (null === $lang) { 90 | $lang = 'en'; 91 | } 92 | 93 | if (null === $deeplink) { 94 | $deeplink = true; 95 | } 96 | 97 | if (null === $qrCode) { 98 | $qrCode = true; 99 | } 100 | 101 | if (($deeplink && $qrCode) || (false === $deeplink && false === $qrCode)) { 102 | $deeplink = true; 103 | $qrCode = false; 104 | } 105 | 106 | $response = $this->makeRequest('/start', self::METHOD_POST, 107 | array("app" => $validationMethod, "lang" => $lang, "deeplink" => $deeplink, "qrCode" => $qrCode) 108 | ); 109 | 110 | return new ValidationStart($response); 111 | } 112 | 113 | 114 | /** 115 | * @param string $countryCode 116 | * @param string $lang 117 | * @return Countries 118 | * @throws CurlException 119 | */ 120 | public function getCountryList($countryCode = 'TR', $lang = 'en') 121 | { 122 | $response = $this->makeRequest('/country', self::METHOD_POST, 123 | array("lang" => $lang, "countryCode" => $countryCode) 124 | ); 125 | 126 | return new Countries($response); 127 | } 128 | 129 | /** 130 | * @param $phoneNumber 131 | * @param $countryCode 132 | * @param int $mcc 133 | * @param int $mnc 134 | * @param string $lang 135 | * @return OTPSend 136 | * @throws CountryCodeEmptyException 137 | * @throws CurlException 138 | * @throws PhoneNumberEmptyException 139 | */ 140 | public function sendOTP($phoneNumber, $countryCode, $mcc = 999, $mnc = 999, $lang = 'en') 141 | { 142 | if (null === $phoneNumber || $phoneNumber == "") { 143 | throw new PhoneNumberEmptyException("Phone number cannot be empty.", 836004); 144 | } 145 | 146 | if (null === $countryCode || $countryCode == "") { 147 | throw new CountryCodeEmptyException("Country code cannot be empty.", 836005); 148 | } 149 | 150 | if (null === $lang || $lang == '') { 151 | $lang = 'en'; 152 | } 153 | 154 | $response = $this->makeRequest('/send-otp', self::METHOD_POST, 155 | array("phoneNumber" => $phoneNumber, "countryCode" => $countryCode, "mcc" => $mcc, "mnc" => $mnc, "lang" => $lang) 156 | ); 157 | 158 | return new OTPSend($response); 159 | } 160 | 161 | /** 162 | * @param null $email 163 | * @return EmailValidationStart 164 | * @throws CurlException 165 | */ 166 | public function startEmailValidation($email = null) 167 | { 168 | $postFields = array(); 169 | if (null !== $email) { 170 | $postFields = array("email" => $email); 171 | } 172 | 173 | $response = $this->makeRequest('/start-email', self::METHOD_POST, $postFields); 174 | 175 | return new EmailValidationStart($response); 176 | } 177 | 178 | /** 179 | * @param $reference 180 | * @return ValidationCheck 181 | * @throws CurlException 182 | * @throws ReferenceEmptyException 183 | */ 184 | public function checkValidation($reference) 185 | { 186 | if (null === $reference || $reference == "") { 187 | throw new ReferenceEmptyException("Reference cannot be empty.", 836003); 188 | } 189 | 190 | $response = $this->makeRequest('/check', self::METHOD_POST, array('reference' => $reference)); 191 | 192 | return new ValidationCheck($response); 193 | } 194 | 195 | 196 | /** 197 | * @param $phoneNumber 198 | * @param $countryCode 199 | * @param $reference 200 | * @param $code 201 | * @return OTPCheck 202 | * @throws CountryCodeEmptyException 203 | * @throws CurlException 204 | * @throws OTPCodeEmptyException 205 | * @throws PhoneNumberEmptyException 206 | * @throws ReferenceEmptyException 207 | */ 208 | public function checkOTP($phoneNumber, $countryCode, $reference, $code) 209 | { 210 | if (null === $phoneNumber || $phoneNumber == "") { 211 | throw new PhoneNumberEmptyException("Phone number cannot be empty.", 836004); 212 | } 213 | 214 | if (null === $countryCode || $countryCode == "") { 215 | throw new CountryCodeEmptyException("Country code cannot be empty.", 836005); 216 | } 217 | 218 | if (null === $reference || $reference == "") { 219 | throw new ReferenceEmptyException("Reference cannot be empty.", 836006); 220 | } 221 | 222 | if (null === $code || $code == "") { 223 | throw new OTPCodeEmptyException("OTP Code cannot be empty.", 836007); 224 | } 225 | 226 | $response = $this->makeRequest('/check-otp', self::METHOD_POST, 227 | array("phoneNumber" => $phoneNumber, "countryCode" => $countryCode, "reference" => $reference, "code" => $code) 228 | ); 229 | 230 | return new OTPCheck($response); 231 | } 232 | 233 | /** 234 | * @param $validationMethod 235 | * @param array $phoneNumberList 236 | * @return BlacklistAdd 237 | * @throws CurlException 238 | * @throws PhoneNumberListEmptyException 239 | * @throws ValidationMethodEmptyException 240 | * @throws ValidationMethodNotValidException 241 | */ 242 | public function addPhoneNumbersToBlacklist($validationMethod, array $phoneNumberList = array()) 243 | { 244 | if (null === $validationMethod || $validationMethod == "") { 245 | throw new ValidationMethodEmptyException("Validation method cannot be empty.", 836008); 246 | } 247 | 248 | if (false === in_array($validationMethod, Constant\ValidationMethod::getValidationMethods())) { 249 | throw new ValidationMethodNotValidException("Validation method is not valid.", 836012); 250 | } 251 | 252 | if (empty($phoneNumberList)) { 253 | throw new PhoneNumberListEmptyException("Validation method cannot be empty.", 836010); 254 | } 255 | 256 | $response = $this->makeRequest('/blacklist/add', self::METHOD_POST, 257 | array("type" => $validationMethod, "msisdn" => $phoneNumberList) 258 | ); 259 | 260 | return new BlacklistAdd($response); 261 | } 262 | 263 | /** 264 | * @param $validationMethod 265 | * @param array $phoneNumberList 266 | * @return BlacklistRemove 267 | * @throws CurlException 268 | * @throws PhoneNumberListEmptyException 269 | * @throws ValidationMethodEmptyException 270 | * @throws ValidationMethodNotValidException 271 | */ 272 | public function removePhoneNumbersFromBlacklist($validationMethod, array $phoneNumberList = array()) 273 | { 274 | if (null === $validationMethod || $validationMethod == "") { 275 | throw new ValidationMethodEmptyException("Validation method cannot be empty.", 836009); 276 | } 277 | 278 | if (false === in_array($validationMethod, Constant\ValidationMethod::getValidationMethods())) { 279 | throw new ValidationMethodNotValidException("Validation method is not valid.", 836013); 280 | } 281 | 282 | if (empty($phoneNumberList)) { 283 | throw new PhoneNumberListEmptyException("Validation method cannot be empty.", 836011); 284 | } 285 | 286 | $response = $this->makeRequest('/blacklist/remove', self::METHOD_POST, 287 | array("type" => $validationMethod, "msisdn" => $phoneNumberList) 288 | ); 289 | 290 | return new BlacklistRemove($response); 291 | } 292 | 293 | /** 294 | * @param $endpoint 295 | * @param string $method 296 | * @param array $postFields 297 | * @return bool|string 298 | * @throws CurlException 299 | */ 300 | protected function makeRequest($endpoint, $method = 'POST', $postFields = array()) 301 | { 302 | $curl = curl_init(); 303 | 304 | curl_setopt($curl, CURLOPT_URL, $this->baseUrl . $endpoint); 305 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 306 | curl_setopt($curl, CURLOPT_MAXREDIRS, 10); 307 | curl_setopt($curl, CURLOPT_TIMEOUT, 30); 308 | curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); 309 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 310 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 311 | 312 | $userAgent = 'VerifyKitWeb/1.0.0'; 313 | if (isset($_SERVER["HTTP_USER_AGENT"])) { 314 | $userAgent .= ' - ' . $_SERVER["HTTP_USER_AGENT"]; 315 | } 316 | curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); 317 | curl_setopt($curl, CURLOPT_HTTPHEADER, array( 318 | "X-Vfk-Server-Key: " . $this->serverKey, 319 | "Cache-Control: no-cache", 320 | "Content-Type: application/json;", 321 | "X-Vfk-Forwarded-For: " . $this->clientIp 322 | )); 323 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); 324 | if ($method == 'POST') { 325 | curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postFields)); 326 | } 327 | 328 | $response = curl_exec($curl); 329 | 330 | 331 | if (curl_errno($curl)) { 332 | $error_msg = curl_error($curl); 333 | } 334 | curl_close($curl); 335 | 336 | if (isset($error_msg)) { 337 | throw new CurlException($error_msg); 338 | } 339 | 340 | return $response; 341 | } 342 | 343 | /** 344 | * @param string $baseUrl 345 | */ 346 | public function setBaseUrl($baseUrl) 347 | { 348 | $this->baseUrl = $baseUrl; 349 | } 350 | 351 | } --------------------------------------------------------------------------------