コード例 #1
0
ファイル: app.py プロジェクト: zap-me/zapm_server
def add_merchant_codes():
    with app.app_context():
        for user in User.all(db.session):
            if not user.merchant_code:
                user.merchant_code = generate_key(4)
                db.session.add(user)
        db.session.commit()
コード例 #2
0
def email_invoices_timer_callback():
    logger.info("email_invoices_timer_callback()..")
    with app.app_context():
        invoices = Invoice.all_with_email_and_not_terminated(db.session)
        for invoice in invoices:
            order = bronze_order_status(invoice)
            if order:
                if invoice.status != order["status"]:
                    invoice_url = url_for("invoice", token=invoice.token)
                    hostname = urllib.parse.urlparse(invoice_url).hostname
                    sender = "no-reply@" + hostname
                    formatted_amount = '{0:0.2f}'.format(invoice.amount /
                                                         100.0)
                    # send email
                    msg = Message('ZAP bill payment status updated',
                                  sender=sender,
                                  recipients=[invoice.email])
                    msg.html = 'Invoice <a href="{}">{}</a> has updated the {} invoice with the amount of ${} to status "{}"'.format(
                        invoice_url, invoice.token, invoice.utility_name,
                        formatted_amount, order["status"])
                    msg.body = 'Invoice {} has updated the {} invoice with the amount of ${} to status {}'.format(
                        invoice_url, invoice.utility_name, formatted_amount,
                        order["status"])
                    mail.send(msg)
                    # update invoice object
                    invoice.status = order["status"]
                    db.session.commit()
コード例 #3
0
ファイル: app.py プロジェクト: zap-me/zapm_server
def add_user(email, password):
    with app.app_context():
        user = User.from_email(db.session, email)
        if user:
            #logger.error("user already exists")
            #return
            user.password = encrypt_password(password)
        else:
            user = user_datastore.create_user(
                email=email, password=encrypt_password(password))
        db.session.commit()
コード例 #4
0
ファイル: app.py プロジェクト: zap-me/zapm_server
def add_role(email, role_name):
    with app.app_context():
        user = User.from_email(db.session, email)
        if not user:
            logger.error("user does not exist")
            return
        role = create_role(role_name, None)
        if role not in user.roles:
            user.roles.append(role)
        else:
            logger.info("user already has role")
        db.session.commit()
コード例 #5
0
def process_email_alerts():
    with app.app_context():
        data = dashboard_data_paydb()
        ### OPERATIONS WALLET THRESHOLD
        if data["premio_stage_balance"] < int(app.config["OPERATIONS_ACCOUNT_MIN_BALANCE_CENTS"]):
            subject = 'Operations wallet balance too low.'
            msg = 'Please issue more tokens to the Operations wallet.'
            utils.email_notification_alert(logger, subject, msg, app.config["OPERATIONS_ACCOUNT"])
        ### OPERATIONS WALLET THRESHOLD < CLAIMABLE REWARDS
        if data["premio_stage_balance"] < data["claimable_rewards"]:
            subject = 'Amount claimable is higher than the amount in Operations wallet.'
            msg = 'Please issue new tokens so all claimable rewards can be claimed.'
            utils.email_notification_alert(logger, subject, msg, app.config["OPERATIONS_ACCOUNT"])
コード例 #6
0
def process_proposals():
    with app.app_context():
        # set expired
        expired = 0
        now = datetime.datetime.now()
        proposals = Proposal.in_status(db.session, Proposal.STATE_AUTHORIZED)
        for proposal in proposals:
            if proposal.date_expiry < now:
                proposal.status = Proposal.STATE_EXPIRED
                expired += 1
                db.session.add(proposal)
        db.session.commit()
        # process authorized
        emails = 0
        sms_messages = 0
        proposals = Proposal.in_status(db.session, Proposal.STATE_AUTHORIZED)
        # pylint: disable=too-many-nested-blocks
        for proposal in proposals:
            for payment in proposal.payments:
                if payment.status == payment.STATE_CREATED:
                    if payment.email:
                        utils.email_payment_claim(logger,
                                                  app.config["ASSET_NAME"],
                                                  payment,
                                                  proposal.HOURS_EXPIRY)
                        payment.status = payment.STATE_SENT_CLAIM_LINK
                        db.session.add(payment)
                        logger.info("Sent payment claim url to %s",
                                    payment.email)
                        emails += 1
                    elif payment.mobile:
                        utils.sms_payment_claim(logger,
                                                app.config["ASSET_NAME"],
                                                payment, proposal.HOURS_EXPIRY)
                        payment.status = payment.STATE_SENT_CLAIM_LINK
                        db.session.add(payment)
                        logger.info("Sent payment claim url to %s",
                                    payment.mobile)
                        sms_messages += 1
                    elif payment.recipient:
                        ##TODO: set status and commit before sending so we cannot send twice
                        raise Exception("not yet implemented")
        db.session.commit()
        #logger.info(f"payment statuses commited")
        return f"done (expired {expired}, emails {emails}, SMS messages {sms_messages})"