def _move_pdf(filename, original_url): if 'gateway.ipfs' in original_url: response = urlfetch.fetch(original_url, deadline=30) if response.status_code != 200: raise Exception('Invalid response from %s: %s\n%s', response.status_code, response.content) pdf_content = response.content upload_to_gcs(filename, pdf_content, 'application/pdf')
def create_investment_agreement(agreement): # type: (CreateInvestmentAgreementTO) -> InvestmentAgreement app_user = users.User(agreement.app_user) username = get_iyo_username(app_user) token_count_float = get_token_count(agreement.currency, agreement.amount) agreement_model = _create_investment_agreement( agreement.amount, agreement.currency, agreement.token, token_count_float, username, 'manually_created', app_user, status=agreement.status, paid_time=agreement.paid_time, sign_time=agreement.sign_time) prefix, doc_content_base64 = agreement.document.split(',') content_type = prefix.split(';')[0].replace('data:', '') doc_content = base64.b64decode(doc_content_base64) agreement_model.put() pdf_name = InvestmentAgreement.filename(agreement_model.id) pdf_url = upload_to_gcs(pdf_name, doc_content, content_type) deferred.defer(_create_investment_agreement_iyo_see_doc, agreement_model.key, app_user, pdf_url, content_type, send_sign_message=False) return agreement_model
def _create_node_order_pdf(node_order_id): node_order = get_node_order(node_order_id) user_email, app_id = get_app_user_tuple(node_order.app_user) logging.debug('Creating Hosting agreement') pdf_name = NodeOrder.filename(node_order_id) pdf_contents = create_hosting_agreement_pdf(node_order.billing_info.name, node_order.billing_info.address) pdf_url = upload_to_gcs(pdf_name, pdf_contents, 'application/pdf') deferred.defer(_order_node_iyo_see, node_order.app_user, node_order_id, pdf_url) deferred.defer(update_hoster_progress, user_email.email(), app_id, HosterSteps.FLOW_ADDRESS)
def create_node_order(data): # type: (CreateNodeOrderTO) -> NodeOrder if data.status not in (NodeOrderStatus.SIGNED, NodeOrderStatus.SENT, NodeOrderStatus.ARRIVED, NodeOrderStatus.PAID): data.sign_time = MISSING if data.status not in (NodeOrderStatus.SENT, NodeOrderStatus.ARRIVED): data.send_time = MISSING app_user = users.User(data.app_user) order_count = NodeOrder.list_by_so(data.odoo_sale_order_id).count() if order_count > 0: raise OrderAlreadyExistsException(data.odoo_sale_order_id) try: nodes = get_nodes_from_odoo(data.odoo_sale_order_id) except (IndexError, TypeError): logging.warn('Could not get nodes from odoo for order id %s' % data.odoo_sale_order_id, exc_info=True) raise HttpBadRequestException('cannot_find_so_x', {'id': data.odoo_sale_order_id}) if not nodes: raise HttpBadRequestException('no_serial_number_configured_yet', {'sale_order': data.odoo_sale_order_id}) prefix, doc_content_base64 = data.document.split(',') content_type = prefix.split(';')[0].replace('data:', '') if content_type != 'application/pdf': raise InvalidContentTypeException(content_type, ['application/pdf']) doc_content = base64.b64decode(doc_content_base64) order_key = NodeOrder.create_key() pdf_name = NodeOrder.filename(order_key.id()) pdf_url = upload_to_gcs(pdf_name, doc_content, content_type) order = NodeOrder(key=order_key, app_user=app_user, **data.to_dict(exclude=['document', 'app_user'])) order.put() iyo_username = get_iyo_username(app_user) email, app_id = get_app_user_tuple(app_user) deferred.defer(add_nodes_to_profile, iyo_username, nodes) deferred.defer(set_hoster_status_in_user_data, order.app_user, False) deferred.defer(add_user_to_role, UserDetailsTO(email=email.email(), app_id=app_id), RogerthatRoles.HOSTERS) deferred.defer(tag_intercom_users, IntercomTags.HOSTER, [iyo_username]) deferred.defer(_order_node_iyo_see, order.app_user, order.id, pdf_url, len(doc_content), create_quotation=False) return order
def save_utility_bill(url, profile_key): from plugins.tff_backend.bizz.user import store_kyc_in_user_data result = urlfetch.fetch(url) # type: urlfetch._URLFetchResult if result.status_code != 200: raise Exception('Invalid status %s %s' % (result.status_code, result.content)) profile = profile_key.get() # type: TffProfile content_type = result.headers.get('Content-Type', 'image/jpeg') filename = 'users/%s/utility_bill.jpeg' % profile.username profile.kyc.utility_bill_url = upload_to_gcs(filename, result.content, content_type) profile.put() deferred.defer(store_kyc_in_user_data, profile.app_user, _transactional=ndb.in_transaction())
def _invest(agreement_key, email, app_id, retry_count): # type: (ndb.Key, unicode, unicode, long, list[int]) -> None from plugins.tff_backend.bizz.agreements import create_token_agreement_pdf app_user = create_app_user_by_email(email, app_id) logging.debug('Creating Token agreement') agreement = get_investment_agreement(agreement_key.id()) _set_token_count(agreement) agreement.put() currency_full = _get_currency_name(agreement.currency) pdf_name = InvestmentAgreement.filename(agreement_key.id()) username = get_iyo_username(app_user) has_verified_utility_bill = get_tff_profile(username).kyc.utility_bill_verified pdf_contents = create_token_agreement_pdf(agreement.name, agreement.address, agreement.amount, currency_full, agreement.currency, agreement.token, agreement.payment_info, has_verified_utility_bill) pdf_url = upload_to_gcs(pdf_name, pdf_contents, 'application/pdf') logging.debug('Storing Investment Agreement in the datastore') pdf_size = len(pdf_contents) deferred.defer(_create_investment_agreement_iyo_see_doc, agreement_key, app_user, pdf_url, pdf_size=pdf_size) deferred.defer(update_investor_progress, email, app_id, INVESTMENT_TODO_MAPPING[agreement.status])
def create_token_value_agreement(username): logging.info('Creating token value agreement for user %s', username) document_id = Document.allocate_ids(1)[0] pdf_name = Document.create_filename(DocumentType.TOKEN_VALUE_ADDENDUM.value, document_id) pdf_contents = create_itft_amendment_1_pdf(get_app_user_from_iyo_username(username)) content_type = u'application/pdf' pdf_url = upload_to_gcs(pdf_name, pdf_contents, content_type) pdf_size = len(pdf_contents) iyo_see_doc_id = u'Amendment %s' % document_id doc_category = u'Amendment to purchase agreement' description = doc_category create_see_document(iyo_see_doc_id, doc_category, description, username, pdf_url, content_type) document = Document(key=Document.create_key(document_id), iyo_see_id=iyo_see_doc_id, username=username, type=DocumentType.TOKEN_VALUE_ADDENDUM.value) document.put() attachment_name = iyo_see_doc_id push_message = 'Please read through and sign the amendment to receive 100x more tokens in your wallet for your' \ ' purchased value.' deferred.defer(send_document_sign_message, document.key, username, pdf_url, attachment_name, pdf_size, SIGN_TOKEN_VALUE_ADDENDUM_TAG, FLOW_SIGN_TOKEN_VALUE_ADDENDUM, push_message)
def create_investment_agreement(agreement): # type: (CreateInvestmentAgreementTO) -> InvestmentAgreement app_user = users.User(agreement.app_user) username = get_iyo_username(app_user) tff_profile = get_tff_profile(username) if tff_profile.kyc.status != KYCStatus.VERIFIED: raise HttpBadRequestException('cannot_invest_not_kyc_verified') token_count_float = get_token_count(agreement.currency, agreement.amount) agreement_model = _create_investment_agreement(agreement.amount, agreement.currency, agreement.token, token_count_float, username, 'manually_created', app_user, status=agreement.status, paid_time=agreement.paid_time, sign_time=agreement.sign_time) prefix, doc_content_base64 = agreement.document.split(',') content_type = prefix.split(';')[0].replace('data:', '') doc_content = base64.b64decode(doc_content_base64) agreement_model.put() pdf_name = InvestmentAgreement.filename(agreement_model.id) pdf_url = upload_to_gcs(pdf_name, doc_content, content_type) deferred.defer(_create_investment_agreement_iyo_see_doc, agreement_model.key, app_user, pdf_url, content_type, send_sign_message=False, pdf_size=len(doc_content)) return agreement_model