|
| 1 | +import requests |
| 2 | +from docusign_esign import ExtensionData, ConnectionInstance |
| 3 | +from docusign.ds_config import SMARTY_EXTENSION_ID, PHONE_EXTENSION_ID, SSN_EXTENSION_ID, CONNECTED_FIELDS_BASE_HOST |
| 4 | + |
| 5 | +class Extensions: |
| 6 | + @staticmethod |
| 7 | + def get_extension_apps(session): |
| 8 | + headers = { |
| 9 | + "Authorization": "Bearer " + session['access_token'], |
| 10 | + "Accept": "application/json", |
| 11 | + "Content-Type": "application/json" |
| 12 | + } |
| 13 | + |
| 14 | + url = f"{CONNECTED_FIELDS_BASE_HOST}/v1/accounts/{session['account_id']}/connected-fields/tab-groups" |
| 15 | + response = requests.get(url, headers=headers) |
| 16 | + |
| 17 | + return response.json() |
| 18 | + |
| 19 | + def get_extension_app(session, appId): |
| 20 | + headers = { |
| 21 | + "Authorization": "Bearer " + session['access_token'], |
| 22 | + "Accept": "application/json", |
| 23 | + "Content-Type": "application/json" |
| 24 | + } |
| 25 | + |
| 26 | + url = f"{CONNECTED_FIELDS_BASE_HOST}/v1/accounts/{session['account_id']}/connected-fields/tab-groups?appId={appId}" |
| 27 | + response = requests.get(url, headers=headers) |
| 28 | + |
| 29 | + return response.json() |
| 30 | + |
| 31 | + @staticmethod |
| 32 | + def get_address_extension_id(): |
| 33 | + return SMARTY_EXTENSION_ID |
| 34 | + |
| 35 | + @staticmethod |
| 36 | + def get_phone_extension_id(): |
| 37 | + return PHONE_EXTENSION_ID |
| 38 | + |
| 39 | + @staticmethod |
| 40 | + def get_ssn_extension_id(): |
| 41 | + return SSN_EXTENSION_ID |
| 42 | + |
| 43 | + @staticmethod |
| 44 | + def get_extension_by_app_id(objects, app_id): |
| 45 | + return next((obj for obj in objects if obj["appId"] == app_id), None) |
| 46 | + |
| 47 | + @staticmethod |
| 48 | + def extract_verification_data(selected_app_id, tab): |
| 49 | + extension_data = tab["extensionData"] |
| 50 | + |
| 51 | + return { |
| 52 | + "app_id": selected_app_id, |
| 53 | + "extension_group_id": extension_data["extensionGroupId"] if "extensionGroupId" in extension_data else "", |
| 54 | + "publisher_name": extension_data["publisherName"] if "publisherName" in extension_data else "", |
| 55 | + "application_name": extension_data["applicationName"] if "applicationName" in extension_data else "", |
| 56 | + "action_name": extension_data["actionName"] if "actionName" in extension_data else "", |
| 57 | + "action_input_key": extension_data["actionInputKey"] if "actionInputKey" in extension_data else "", |
| 58 | + "action_contract": extension_data["actionContract"] if "actionContract" in extension_data else "", |
| 59 | + "extension_name": extension_data["extensionName"] if "extensionName" in extension_data else "", |
| 60 | + "extension_contract": extension_data["extensionContract"] if "extensionContract" in extension_data else "", |
| 61 | + "required_for_extension": extension_data["requiredForExtension"] if "requiredForExtension" in extension_data else "", |
| 62 | + "tab_label": tab["tabLabel"], |
| 63 | + "connection_key": ( |
| 64 | + extension_data["connectionInstances"][0]["connectionKey"] |
| 65 | + if "connectionInstances" in extension_data and extension_data["connectionInstances"] |
| 66 | + else "" |
| 67 | + ), |
| 68 | + "connection_value": ( |
| 69 | + extension_data["connectionInstances"][0]["connectionValue"] |
| 70 | + if "connectionInstances" in extension_data and extension_data["connectionInstances"] |
| 71 | + else "" |
| 72 | + ) |
| 73 | + } |
| 74 | + |
| 75 | + @staticmethod |
| 76 | + def get_extension_data(verification_data): |
| 77 | + return ExtensionData( |
| 78 | + extension_group_id = verification_data["extension_group_id"], |
| 79 | + publisher_name = verification_data["publisher_name"], |
| 80 | + application_id = verification_data["app_id"], |
| 81 | + application_name = verification_data["application_name"], |
| 82 | + action_name = verification_data["action_name"], |
| 83 | + action_contract = verification_data["action_contract"], |
| 84 | + extension_name = verification_data["extension_name"], |
| 85 | + extension_contract = verification_data["extension_contract"], |
| 86 | + required_for_extension = verification_data["required_for_extension"], |
| 87 | + action_input_key = verification_data["action_input_key"], |
| 88 | + extension_policy = 'MustVerifyToSign', |
| 89 | + connection_instances = [ConnectionInstance( |
| 90 | + connection_key = verification_data["connection_key"], |
| 91 | + connection_value = verification_data["connection_value"], |
| 92 | + )] |
| 93 | + ) |
0 commit comments