@@ -228,6 +228,8 @@ $viberImage = new Vonage\Messages\Channel\Viber\ViberImage(
228
228
$client->messages()->send($viberImage);
229
229
```
230
230
231
+ ## Verify Examples (v1)
232
+
231
233
### Starting a Verification
232
234
233
235
Vonage's [ Verify API] [ doc_verify ] makes it easy to prove that a user has provided their own phone number during signup,
@@ -295,6 +297,93 @@ echo "Started verification with an id of: " . $response['request_id'];
295
297
296
298
Once the user inputs the pin code they received, call the ` /check ` endpoint with the request ID and the pin to confirm the pin is correct.
297
299
300
+ ## Verify Examples (v2)
301
+
302
+ ### Starting a Verification
303
+
304
+ Vonage's Verify v2 relies more on asynchronous workflows via. webhooks, and more customisable Verification
305
+ workflows to the developer. To start a verification, you'll need the API client, which is under the namespace
306
+ ` verify2 ` .
307
+
308
+ Making a Verify request needs a 'base' channel of communication to deliver the mode of verification. You can
309
+ customise these interactions by adding different 'workflows'. For each type of workflow, there is a Verify2 class
310
+ you can create that will handle the initial workflow for you. For example:
311
+
312
+ ``` php
313
+ $client = new Vonage\Client(
314
+ new Vonage\Client\Credentials\Basic(API_KEY, API_SECRET),
315
+ );
316
+
317
+ $smsRequest = new \Vonage\Verify2\Request\SMSRequest('TO_NUMBER');
318
+ $client->verify2()->startVerification($smsRequest);
319
+ ```
320
+
321
+ The ` SMSRequest ` object will resolve defaults for you, and will create a default ` workflow ` object to use SMS.
322
+ You can, however, add multiple workflows that operate with fall-back logic. For example, if you wanted to create
323
+ a Verification that tries to get a PIN code off the user via. SMS, but in case there is a problem with SMS delivery
324
+ you wish to add a Voice fallback: you can add it.
325
+
326
+ ``` php
327
+ $client = new Vonage\Client(
328
+ new Vonage\Client\Credentials\Basic(API_KEY, API_SECRET),
329
+ );
330
+
331
+ $smsRequest = new \Vonage\Verify2\Request\SMSRequest('TO_NUMBER', 'my-verification');
332
+ $voiceWorkflow = new \Vonage\Verify2\VerifyObjects\VerificationWorkflow(\Vonage\Verify2\VerifyObjects\VerificationWorkflow::WORKFLOW_VOICE, 'TO_NUMBER');
333
+ $smsRequest->addWorkflow($voiceWorkflow);
334
+ $client->verify2()->startVerification($smsRequest);
335
+ ```
336
+ This adds the voice workflow to the original SMS request. The verification request will try and resolve the process in
337
+ the order that it is given (starting with the default for the type of request).
338
+
339
+ The base request types are as follows:
340
+
341
+ * ` SMSRequest `
342
+ * ` WhatsAppRequest `
343
+ * ` WhatsAppInterativeRequest `
344
+ * ` EmailRequest `
345
+ * ` VoiceRequest `
346
+ * ` SilentAuthRequest `
347
+
348
+ For adding workflows, you can see the available valid workflows as constants within the ` VerificationWorkflow ` object.
349
+ For a better developer experience, you can't create an invalid workflow due to the validation that happens on the object.
350
+
351
+ ### Check a submitted code
352
+
353
+ To submit a code, you'll need to surround the method in a try/catch due to the nature of the API. If the code is correct,
354
+ the method will return a ` true ` boolean. If it fails, it will throw the relevant Exception from the API that will need to
355
+ be caught.
356
+
357
+ ``` php
358
+ $code = '1234';
359
+ try {
360
+ $client->verify2()->check($code);
361
+ } catch (\Exception $e) {
362
+ var_dump($e->getMessage())
363
+ }
364
+ ```
365
+
366
+ ### Webhooks
367
+
368
+ As events happen during a verification workflow, events and updates will fired as webhooks. Incoming server requests that conform to
369
+ PSR-7 standards can be hydrated into a webhook value object for nicer interactions. You can also hydrate
370
+ them from a raw array. If successful, you will receive a value object back for the type of event/update. Possible webhooks are:
371
+
372
+ * ` VerifyEvent `
373
+ * ` VerifyStatusUpdate `
374
+ * ` VerifySilentAuthUpdate `
375
+
376
+ ``` php
377
+ // From a request object
378
+ $verificationEvent = \Vonage\Verify2\Webhook\Factory::createFromRequest($request);
379
+ var_dump($verificationEvent->getStatus());
380
+ // From an array
381
+ $payload = $request->getBody()->getContents()
382
+ $verificationEvent = \Vonage\Verify2\Webhook\Factory::createFromArray($payload);
383
+ var_dump($verificationEvent->getStatus());
384
+ ```
385
+
386
+
298
387
### Making a Call
299
388
300
389
All ` $client->voice() ` methods require the client to be constructed with a ` Vonage\Client\Credentials\Keypair ` , or a
@@ -797,25 +886,26 @@ Check out the [documentation](https://developer.nexmo.com/number-insight/code-sn
797
886
798
887
## Supported APIs
799
888
800
- | API | API Release Status | Supported?
801
- | ----------| :---------:| :-------------:|
802
- | Account API | General Availability | ✅|
803
- | Alerts API | General Availability | ✅|
804
- | Application API | General Availability | ✅|
805
- | Audit API | Beta | ❌|
806
- | Conversation API | Beta | ❌|
807
- | Dispatch API | Beta | ❌|
808
- | External Accounts API | Beta | ❌|
809
- | Media API | Beta | ❌|
810
- | Messages API | General Availability | ✅|
811
- | Number Insight API | General Availability | ✅|
812
- | Number Management API | General Availability | ✅|
813
- | Pricing API | General Availability | ✅|
814
- | Redact API | General Availability | ✅|
815
- | Reports API | Beta | ❌|
816
- | SMS API | General Availability | ✅|
817
- | Verify API | General Availability | ✅|
818
- | Voice API | General Availability | ✅|
889
+ | API | API Release Status | Supported?
890
+ | ------------------------| :--------------------:| :-------------:|
891
+ | Account API | General Availability | ✅|
892
+ | Alerts API | General Availability | ✅|
893
+ | Application API | General Availability | ✅|
894
+ | Audit API | Beta | ❌|
895
+ | Conversation API | Beta | ❌|
896
+ | Dispatch API | Beta | ❌|
897
+ | External Accounts API | Beta | ❌|
898
+ | Media API | Beta | ❌|
899
+ | Messages API | General Availability | ✅|
900
+ | Number Insight API | General Availability | ✅|
901
+ | Number Management API | General Availability | ✅|
902
+ | Pricing API | General Availability | ✅|
903
+ | Redact API | General Availability | ✅|
904
+ | Reports API | Beta | ❌|
905
+ | SMS API | General Availability | ✅|
906
+ | Verify API | General Availability | ✅|
907
+ | Verify API (Version 2) | Beta | ❌|
908
+ | Voice API | General Availability | ✅|
819
909
820
910
## Troubleshooting
821
911
0 commit comments