def send_reset_email(reset_token, email_address): TEMPLATE_FILE = 'password_reset_email.txt' template = get_email_template(TEMPLATE_FILE) body = template.render(host=current_app.config['APP_HOST'], reset_token=reset_token) add_after_request_executor_job( ses_email_handler, [email_address, 'Sempo Password Reset', body])
def send_bank_transfer_email(email_address, charge_info): TEXT_TEMPLATE_FILE = 'bank_transfer_email.txt' text_template = get_email_template(TEXT_TEMPLATE_FILE) bank = charge_info['wireDetails'] textbody = text_template.render(amount=charge_info['amount'], transfer_id=charge_info['id'], currency=charge_info['currency'], instructions=bank['instructions'], account_number=bank['accountNumber'], routing_number=bank['routingNumber'], swift_code=bank['swiftCode'], account_type=bank['accountType'], bank_address=bank['bankAddress'], beneficiary=bank['beneficiary']) HTML_TEMPLATE_FILE = 'bank_transfer_email.html' html_template = get_email_template(HTML_TEMPLATE_FILE) htmlbody = html_template.render(amount=charge_info['amount'], transfer_id=charge_info['id'], currency=charge_info['currency'], instructions=bank['instructions'], account_number=bank['accountNumber'], routing_number=bank['routingNumber'], swift_code=bank['swiftCode'], account_type=bank['accountType'], bank_address=bank['bankAddress'], beneficiary=bank['beneficiary']) add_after_request_executor_job( ses_email_handler, [email_address, 'Sempo: Fund your wallet', textbody, htmlbody])
def push_user_transfer_confirmation(receive_user, transfer_random_key): try: add_after_request_executor_job(async_pusher_trigger, ['private-user-{}-{}'.format(current_app.config['DEPLOYMENT_NAME'], receive_user.id),\ 'payment_confirmed',\ {'transfer_random_key': transfer_random_key}]) except Exception as e: print(e) sentry_sdk.capture_exception(e)
def send_export_email(file_url, email_address): TEMPLATE_FILE = 'export_email.txt' template = get_email_template(TEMPLATE_FILE) body = template.render(file_url=file_url, deployment=current_app.config['DEPLOYMENT_NAME']) add_after_request_executor_job( ses_email_handler, [email_address, 'Sempo: Your export is ready!', body])
def send_invite_email_to_existing_user(organisation, email_address): TEMPLATE_FILE = 'invite_existing_user_email.txt' template = get_email_template(TEMPLATE_FILE) body = template.render(host=current_app.config['APP_HOST'], organisation_name=organisation.name) add_after_request_executor_job( ses_email_handler, [email_address, 'Sempo: Added to new Organisation!', body])
def post(self): post_data = request.get_json() add_after_request_executor_job(generate_export, [post_data]) return { 'status': 'success', 'data': { 'message': 'Generating export. Please check your email shortly.', } }
def attempt_update_gps_location(self): from server.utils.location import async_set_user_gps_from_location if self._location is not None and self._location is not '': # Delay execution until after request to avoid race condition with db # We still need to flush to get user id though db.session.flush() add_after_request_executor_job( async_set_user_gps_from_location, kwargs={'user_id': self.id, 'location': self._location} )
def send_invite_email(invite, organisation): TEMPLATE_FILE = 'invite_email.txt' template = get_email_template(TEMPLATE_FILE) email = parse.quote(invite.email, safe='') body = template.render(host=current_app.config['APP_HOST'], organisation_name=organisation.name, referral_code=invite.referral_code, email=email) add_after_request_executor_job( ses_email_handler, [invite.email, 'Sempo: Invite to Join!', body])
def send_activation_email(activation_token, email_address): TEXT_TEMPLATE_FILE = 'account_activation_email.txt' text_template = get_email_template(TEXT_TEMPLATE_FILE) textbody = text_template.render(host=current_app.config['APP_HOST'], activation_token=activation_token) HTML_TEMPLATE_FILE = 'account_activation_email.html' html_template = get_email_template(HTML_TEMPLATE_FILE) htmlbody = html_template.render(host=current_app.config['APP_HOST'], activation_token=activation_token) add_after_request_executor_job( ses_email_handler, [email_address, 'Sempo: Activate your account', textbody, htmlbody])
def send_transfer_update_email(email_address, transfer_info, latest_status): TEXT_TEMPLATE_FILE = 'transfer_update_email.txt' text_template = get_email_template(TEXT_TEMPLATE_FILE) textbody = text_template.render( amount=transfer_info['sourceAmount'], transfer_id=transfer_info['id'], currency=transfer_info['sourceCurrency'], status=latest_status['statusDetail'], ) HTML_TEMPLATE_FILE = 'transfer_update_email.html' html_template = get_email_template(HTML_TEMPLATE_FILE) htmlbody = html_template.render( amount=transfer_info['sourceAmount'], transfer_id=transfer_info['id'], currency=transfer_info['sourceCurrency'], status=latest_status['statusDetail'], ) add_after_request_executor_job( ses_email_handler, [email_address, 'Sempo: Transfer Update', textbody, htmlbody])
def push_admin_credit_transfer(transfers): # If we only get one transfer, make it a list if not isinstance(transfers, list): transfers = [transfers] # Build prepared list of transfers we want to send pusher_batch_payload = [] for transfer in transfers: for org in transfer.organisations: pusher_transfer_payload = {} pusher_transfer_payload['data'] = {} pusher_transfer_payload['data']['credit_transfer'] = credit_transfer_schema.dump(transfer).data pusher_transfer_payload['name'] = 'credit_transfer' pusher_transfer_payload['channel'] = current_app.config['PUSHER_ENV_CHANNEL'] + '-' + str(org.id) pusher_batch_payload.append(pusher_transfer_payload) # Break the list of prepared transfers into MAX_BATCH_SIZE chunks and send each batch to the API for pusher_payload_chunk in misc.chunk_list(pusher_batch_payload, PUSHER_MAX_BATCH_SIZE): try: add_after_request_executor_job(async_pusher_trigger_batch, [pusher_payload_chunk]) except Exception as e: print(e) sentry_sdk.capture_exception(e)