Skip to content

Cannot access Verifications with this SDK #33

@audiovention

Description

@audiovention

The SDK doesn't expose the verifications endpoint which is critical for my application. Furthermore, I debugged a long time to get it working, I don't know if it's possible to even make it work with the requests library, due to signature generation and parameter handling. I'm posting an example here that you guys can extend, based on urlli

`from trolley.exceptions.invalidFieldException import InvalidFieldException
import trolley.configuration
import urllib.request
import urllib.error
import time
import json

class UserVerificationGateway(object):

def __init__(self, config):
    self.config = config

def is_user_verified_individual(self, recipient_id) -> bool:
    if recipient_id is None:
        raise InvalidFieldException("Recipient id cannot be None.")
    endpoint = f'/v1/verifications?' + f'verificationType=individual&recipientId[]={recipient_id}&status[]=approved'
    client = trolley.configuration.Configuration.client(self.config)
    full_url = client.config.enviroment + endpoint
    timestamp = int(time.time())
    authorization = client.generate_authorization(timestamp, 'GET', endpoint, client.config)

    headers = {'Content-Type': 'application/json',
                'Authorization': authorization,
                'X-PR-Timestamp': str(timestamp),
                'Trolley-Source': 'python-sdk_1.0.1'
                }
    
    req = urllib.request.Request(full_url, headers=headers, method='GET')

    try:
        response = urllib.request.urlopen(req)
        response_data = response.read()
        encoding = response.info().get_content_charset('utf-8')
        resp_json = json.loads(response_data.decode(encoding))
    except urllib.error.HTTPError as e:
        return False

    if resp_json and resp_json['ok'] and len(resp_json['verifications']) > 0:
        return True
    return False`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions