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 _move_investment_agreement_pdf_to_gcs(investment_agreement_key): investment_agreement = get_investment_agreement_details( investment_agreement_key.id()) if not investment_agreement.see_document: return original_url = investment_agreement.see_document.versions[0].link _move_pdf(InvestmentAgreement.filename(investment_agreement.id), original_url)
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_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