Exemplo n.º 1
0
    def post(self, corp_num):
        try:
            authenticated, token = get_client_credentials(
                SBC_SVC_AUTH_URL, SBC_SVC_AUTH_CLIENT_ID,
                SBC_SVC_CLIENT_SECRET)
            if not authenticated:
                raise ColinServiceException(
                    message=MSG_CLIENT_CREDENTIALS_REQ_FAILED)

            # Get the profile
            print('\nCalling COLIN API using [corp_num: {corp_num}]'.format(
                corp_num=corp_num))
            colin_url = COLIN_SVC_URL.format(corp_num=corp_num)
            headers = {
                # 'x-api-key': COLIN_SVC_API_KEY,
                # 'Accept': 'application/xml'
                'Authorization': 'Bearer ' + token
            }

            print(colin_url)
            print(repr(headers))
            response = requests.get(colin_url, headers=headers)

            content = json.loads(response.text)
            if response.status_code != 200:
                return jsonify(content.get('message')), response.status_code
            return jsonify(content), response.status_code
        except ColinServiceException as err:
            return handle_exception(err, err.message, err.status_code)
        except Exception as err:
            return handle_exception(err, 'Internal Server Error', 500)
Exemplo n.º 2
0
def get_invoices(payment_identifier):
    # Create an instance of the API class
    api_instance = openapi_client.InvoicesApi()

    authenticated, token = get_client_credentials(PAYMENT_SVC_AUTH_URL, PAYMENT_SVC_AUTH_CLIENT_ID, PAYMENT_SVC_CLIENT_SECRET)
    if not authenticated:
        raise SBCPaymentException(message=MSG_CLIENT_CREDENTIALS_REQ_FAILED)
    set_api_client_auth_header(api_instance, token)

    # Set API host URI
    set_api_client_request_host(api_instance, PAYMENT_SVC_URL)

    try:
        # Get Invoices
        api_response = api_instance.get_invoices(payment_identifier)

        pprint(api_response)
        return api_response

    except ApiException as err:
        print("Exception when calling InvoicesApi->get_invoices: %s\n" % err)
        err_response = json.loads(err.body)
        message = ''
        if err_response.get('detail'):
            message = err_response.get('detail')
        elif err_response.get('message'):
            message = err_response.get('message')
        raise SBCPaymentException(err, message=message)

    except Exception as err:
        print("Exception when calling InvoicesApi->get_invoices: %s\n" % err)
        raise SBCPaymentException(err)
Exemplo n.º 3
0
def get_receipt(payment_identifier, model):
    # Create an instance of the API class
    api_instance = openapi_client.ReceiptsApi()

    authenticated, token = get_client_credentials(PAYMENT_SVC_AUTH_URL, PAYMENT_SVC_AUTH_CLIENT_ID, PAYMENT_SVC_CLIENT_SECRET)
    if not authenticated:
        raise SBCPaymentException(message=MSG_CLIENT_CREDENTIALS_REQ_FAILED)
    set_api_client_auth_header(api_instance, token)

    # Set API host URI
    set_api_client_request_host(api_instance, PAYMENT_SVC_URL)

    try:
        # Get receipt for the payment
        api_response = api_instance.get_receipt(payment_identifier, model)

        pprint(api_response)
        return api_response

    except ApiException as err:
        print("Exception when calling ReceiptsApi->get_receipt: %s\n" % err)
        err_response = json.loads(err.body)
        title = err_response.get('detail')
        details = ', '.join(err_response.get('invalidParams', []))
        message = ''
        if title and not details:
            message = '{title}'.format(title=title)
        elif title and details:
            message = '{title} - {details}'.format(title=title, details=details)
        raise SBCPaymentException(err, message=message)

    except Exception as err:
        print("Exception when calling ReceiptsApi->get_receipt: %s\n" % err)
        raise SBCPaymentException(err)
Exemplo n.º 4
0
def delete_api_v1_payment_requests_payment_identifier(req, callback):
    # Create an instance of the API class
    api_instance = openapi_client.DefaultApi()

    authenticated, token = get_client_credentials(PAYMENT_SVC_AUTH_URL,
                                                  PAYMENT_SVC_AUTH_CLIENT_ID,
                                                  PAYMENT_SVC_CLIENT_SECRET)
    if not authenticated:
        raise SBCPaymentException(message=MSG_CLIENT_CREDENTIALS_REQ_FAILED)
    set_api_client_auth_header(api_instance, token)

    try:
        api_instance.delete_api_v1_payment_requests_payment_identifier(
            req.payment_identifier)

    except Exception as e:
        print(
            "Exception when calling DefaultApi->delete_api_v1_payment_requests_payment_identifier: %s\n"
            % e)
Exemplo n.º 5
0
def calculate_fees(req):
    # Create an instance of the API class
    api_instance = openapi_client.FeesApi()

    authenticated, token = get_client_credentials(PAYMENT_SVC_AUTH_URL,
                                                  PAYMENT_SVC_AUTH_CLIENT_ID,
                                                  PAYMENT_SVC_CLIENT_SECRET)
    if not authenticated:
        raise SBCPaymentException(message=MSG_CLIENT_CREDENTIALS_REQ_FAILED)
    set_api_client_auth_header(api_instance, token)

    # Set API host URI
    set_api_client_request_host(api_instance, PAYMENT_SVC_URL)

    try:
        # Calculate Fees
        api_response = api_instance.calculate_fees(
            req.corp_type,
            req.filing_type_code,
            jurisdiction=req.jurisdiction,
            date=req.date,
            priority=req.priority)

        pprint(api_response)
        return api_response

    except ApiException as err:
        print("Exception when calling FeesApi->calculate_fees: %s\n" % err)
        err_response = json.loads(err.body)
        message = ''
        if err_response.get('detail'):
            message = err_response.get('detail')
        elif err_response.get('message'):
            message = err_response.get('message')
        raise SBCPaymentException(err, message=message)

    except Exception as err:
        print("Exception when calling FeesApi->calculate_fees: %s\n" % err)
        raise SBCPaymentException(err)