Skip to content

Commit

Permalink
adding verify v2 to readme, adding verify2.cancel_verification
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed May 15, 2023
1 parent 31a4054 commit d1e19c8
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
72 changes: 70 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ need a Vonage account. Sign up [for free at vonage.com][signup].
- [Messages API](#messages-api)
- [Voice API](#voice-api)
- [NCCO Builder](#ncco-builder)
- [Verify API](#verify-api)
- [Verify V2 API](#verify-v1-api)
- [Verify V1 API](#verify-v1-api)
- [Number Insight API](#number-insight-api)
- [Account API](#account-api)
- [Number Management API](#number-management-api)
Expand Down Expand Up @@ -406,8 +407,75 @@ pprint(response)

When using the `connect` action, use the parameter `from_` to specify the recipient (as `from` is a reserved keyword in Python!)

## Verify V2 API

## Verify API
V2 of the Vonage Verify API lets you send verification codes via SMS, WhatsApp, Voice and Email

You can also verify a user by WhatsApp Interactive Message or by Silent Authentication on their mobile device.

### Send a verification code

```python
params = {
'brand': 'ACME, Inc',
'workflow': [{'channel': 'sms', 'to': '447700900000'}]
}
verify_request = verify2.new_request(params)
```

### Use silent authentication, with email as a fallback

```python
params = {
'brand': 'ACME, Inc',
'workflow': [
{'channel': 'silent_auth', 'to': '447700900000'},
{'channel': 'email', 'to': 'customer@example.com', 'from': 'business@example.com'}
]
}
verify_request = verify2.new_request(params)
```

### Send a verification code with custom options, including a custom code

```python
params = {
'locale': 'en-gb',
'channel_timeout': 120,
'client_ref': 'my client reference',
'code': 'asdf1234',
'brand': 'ACME, Inc',
'workflow': [{'channel': 'sms', 'to': '447700900000', 'app_hash': 'asdfghjklqw'}],
}
verify_request = verify2.new_request(params)
```

### Send a verification request to a blocked network

This feature is only enabled if you have requested for it to be added to your account.

```python
params = {
'brand': 'ACME, Inc',
'fraud_check': False,
'workflow': [{'channel': 'sms', 'to': '447700900000'}]
}
verify_request = verify2.new_request(params)
```

### Check a verification code

```python
verify2.check_code(REQUEST_ID, CODE)
```

### Cancel an ongoing verification

```python
verify2.cancel_verification(REQUEST_ID)
```

## Verify V1 API

### Search for a Verification request

Expand Down
10 changes: 10 additions & 0 deletions src/vonage/verify2.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ def check_code(self, request_id: str, code: str):
auth_type=self._auth_type,
)

def cancel_verification(self, request_id: str):
if not hasattr(self._client, '_application_id'):
self._auth_type = 'header'

return self._client.delete(
self._client.api_host(),
f'/v2/verify/{request_id}',
auth_type=self._auth_type,
)

class VerifyRequest(BaseModel):
brand: str
workflow: List[dict]
Expand Down
Empty file added tests/data/no_content.json
Empty file.
29 changes: 29 additions & 0 deletions tests/test_verify2.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,32 @@ def test_check_code_rate_limit():
str(err.value)
== "Rate Limit Hit: Please wait, then retry your request (https://www.developer.vonage.com/api-errors#throttled)"
)


@responses.activate
def test_cancel_verification():
stub(
responses.DELETE,
'https://api.nexmo.com/v2/verify/c11236f4-00bf-4b89-84ba-88b25df97315',
fixture_path='no_content.json',
status_code=204,
)

assert verify2.cancel_verification('c11236f4-00bf-4b89-84ba-88b25df97315') == None


@responses.activate
def test_cancel_verification_error_not_found():
stub(
responses.DELETE,
'https://api.nexmo.com/v2/verify/c11236f4-00bf-4b89-84ba-88b25df97315',
fixture_path='verify2/request_not_found.json',
status_code=404,
)

with raises(ClientError) as err:
verify2.cancel_verification('c11236f4-00bf-4b89-84ba-88b25df97315')
assert (
str(err.value)
== "Not Found: Request 'c11236f4-00bf-4b89-84ba-88b25df97315' was not found or it has been verified already. (https://developer.nexmo.com/api-errors#not-found)"
)

0 comments on commit d1e19c8

Please sign in to comment.