def _get_report(self): if self._report_key == 'correction': self._report_key = self._filing.filing_json['filing'][ 'correction']['correctedFilingType'] elif self._report_key == 'alteration': self._report_key = 'alterationNotice' if self._filing.business_id: self._business = Business.find_by_internal_id( self._filing.business_id) Report._populate_business_info_to_filing(self._filing, self._business) headers = { 'Authorization': 'Bearer {}'.format(jwt.get_token_auth_header()), 'Content-Type': 'application/json' } data = { 'reportName': self._get_report_filename(), 'template': "'" + base64.b64encode(bytes(self._get_template(), 'utf-8')).decode() + "'", 'templateVars': self._get_template_data() } response = requests.post(url=current_app.config.get('REPORT_SVC_URL'), headers=headers, data=json.dumps(data)) if response.status_code != HTTPStatus.OK: return jsonify(message=str(response.content)), response.status_code return response.content, response.status_code
def get_pdf(self): """Render a pdf for the report.""" headers = { 'Authorization': 'Bearer {}'.format(jwt.get_token_auth_header()), 'Content-Type': 'application/json' } data = { 'reportName': self._get_report_filename(), 'template': "'" + base64.b64encode(bytes(self._get_template(), 'utf-8')).decode() + "'", 'templateVars': self._get_template_data() } response = requests.post(url=current_app.config.get('REPORT_SVC_URL'), headers=headers, data=json.dumps(data)) if response.status_code != HTTPStatus.OK: return jsonify(message=str(response.content)), response.status_code return response.content, response.status_code
def patch(identifier, filing_id=None): """Cancel the payment and resets the filing status to DRAFT.""" if not filing_id: return ({'message': _('No filing id provided for:') + identifier}, HTTPStatus.BAD_REQUEST) # check authorization if not authorized(identifier, jwt, action=['edit']): return jsonify({'message': _('You are not authorized to delete a filing for:') + identifier}), \ HTTPStatus.UNAUTHORIZED filing = Business.get_filing_by_id(identifier, filing_id) if not filing: return jsonify({'message': ('Filing Not Found.')}), \ HTTPStatus.NOT_FOUND try: payment_svc_url = '{}/{}'.format(current_app.config.get('PAYMENT_SVC_URL'), filing.payment_token) token = jwt.get_token_auth_header() headers = {'Authorization': 'Bearer ' + token} rv = requests.delete(url=payment_svc_url, headers=headers, timeout=20.0) if rv.status_code == HTTPStatus.OK or rv.status_code == HTTPStatus.ACCEPTED: filing.reset_filing_to_draft() except (exceptions.ConnectionError, exceptions.Timeout) as err: current_app.logger.error(f'Payment connection failure for {identifier}: filing:{filing.id}', err) return {'message': 'Unable to cancel payment for the filing.'}, HTTPStatus.INTERNAL_SERVER_ERROR except BusinessException as err: return {'message': err.error}, err.status_code return jsonify(filing.json), HTTPStatus.ACCEPTED
{'identifier': identifier })), HTTPStatus.NOT_FOUND if not (filing := Filing.get(identifier, filing_id)): return jsonify(message=get_error_message( ErrorCode.FILING_NOT_FOUND, **{ 'filing_id': filing_id, 'identifier': identifier })), HTTPStatus.NOT_FOUND if not legal_filing_name: return _get_document_list(business, filing) if legal_filing_name and ('application/pdf' in request.accept_mimetypes): if legal_filing_name.lower().startswith('receipt'): return _get_receipt(business, filing, jwt.get_token_auth_header()) return get_pdf(filing.storage, legal_filing_name) return {}, HTTPStatus.NOT_FOUND def _get_document_list(business, filing): """Get list of document outputs.""" if not (document_list := Filing.get_document_list(business, filing, request)): return {}, HTTPStatus.NOT_FOUND return jsonify(document_list), HTTPStatus.OK