HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/integrations/seven_hundred_credit.py
import os
import logging
import xml.etree.ElementTree as ET
from flask import current_app as app
import requests
import xml.etree.ElementTree as ET
import xmltodict
import json

log = logging.getLogger(__name__)


class SevenHundredCreditException(Exception):
    pass


class SevenHundredCredit(object):
    if app.config['DEBUG']:
        API_ROOT = os.environ.get(
            'SEVEN_HUNDRED_CREDIT_API_ROOT', 'https://www.700CreditSolution.com/XCRS/Service.aspx'
        )
        API__COMPLIANCE_ROOT = os.environ.get(
            'SEVEN_HUNDRED_CREDIT_COMPLIANCE_ROOT', 'https://www.700creditsolution.com/ComplianceDBIFrame.aspx'
        )
    else:
        API_ROOT = os.environ.get(
            'SEVEN_HUNDRED_CREDIT_API_ROOT', 'https://www.700Dealer.com/XCRS/Service.aspx'
        )
        API__COMPLIANCE_ROOT = os.environ.get(
            'SEVEN_HUNDRED_CREDIT_COMPLIANCE_ROOT', 'https://www.700dealer.com/ComplianceDBIFrame.aspx'
        )

    def __init__(self, username, password, product, api_root=API_ROOT, api_com_root=API__COMPLIANCE_ROOT):
        self.username = username
        self.password = password
        self.product = product
        self.api_root = api_root
        self.api_com_root = api_com_root
        self.url_root = '{}'.format(self.api_root)
        self.url_com_root = '{}'.format(self.api_com_root)

    @property
    def credit_report(self):
        return CreditReport(self)

    def post(self, url, data, headers):

        # start creating request-log
        from buyercall.blueprints.sysadmin.utilities.request_log_task_call import LogRequestTaskTrigger
        from flask import request

        # LogRequestTaskTrigger().log_request_task_trigger(
        #                     request, "seven-hundred-credit")
        # end creating request-log
        from buyercall.blueprints.sysadmin.models import RequestLog
        request_id = request.environ.get('HTTP_X_REQUEST_ID')
        r = requests.post(url, data=data, headers=headers)
        log.info('The response returns: {}'.format(r.content.decode()))
        xml_content = xmltodict.parse(r.content.decode())
        json_xml_content = json.dumps(xml_content)
        return_xml_json = json.loads(json_xml_content)
        is_error = 'Creditsystem_Error'
        if is_error in return_xml_json['Results']:
            log.info('The order post error: {}'.format(return_xml_json))
            error_code = return_xml_json['Results']['Creditsystem_Error']['@id']
            error_message = return_xml_json['Results']['Creditsystem_Error']['@message']
            # LogRequestTaskTrigger().log_request_task_trigger(
            #                 request, "seven-hundred-credit")
            RequestLog().update_record(
            request_id, {"error":error_message})
            raise Exception('ERROR_CODE: {} - MESSAGE: {}'.format(error_code, error_message))
        else:
            return return_xml_json


class CreditReport(object):
    def __init__(self, client):
        self.client = client
        self.base_url = self.client.url_root
        self.base_com_url = self.client.url_com_root
        self.account = self.client.username
        self.password = self.client.password
        self.product_type = self.client.product
        self.child_class = None

    def get_full_credit_report(self, buruea, name, ssn, address, city, state, zip_code, a_username, a_user_id):
        url = '{}'.format(self.base_url)
        data = {'ACCOUNT': self.account, 'PASSWD': self.password, 'PRODUCT': self.product_type, 'BUREAU': buruea,
                'PASS': '2', 'PROCESS': 'PCCREDIT', 'NAME': name, 'ADDRESS': address, 'CITY': city,
                'STATE': state, 'ZIP': zip_code, 'SSN': ssn, 'A_USER_NAME': a_username, 'A_USER_ID': a_user_id}
        headers = {'Content-Type': 'application/xml; charset=UTF-8'}
        return self.client.post(url, data, headers)

    def get_prequalify_credit_report(self, buruea, name, address, city, state, zip_code, ssn, a_username, a_user_id):
        url = '{}'.format(self.base_url)
        data = {'ACCOUNT': self.account, 'PASSWD': self.password, 'PRODUCT': self.product_type, 'BUREAU': buruea,
                'PASS': '2', 'PROCESS': 'PCCREDIT', 'NAME': name, 'ADDRESS': address,
                'CITY': city, 'STATE': state, 'ZIP': zip_code, 'SSN': ssn, 'A_USER_NAME': a_username, 'A_USER_ID': a_user_id}
        headers = {'Content-Type': 'application/xml; charset=UTF-8'}
        return self.client.post(url, data, headers)

    def get_compliance_dashboard(self):
        url = '{}'.format(self.base_com_url)
        data = '?ACCOUNT=' + self.account + '&PASSWD=' + self.password
        return url + data