def start(override=None):
    """
    Bootstrap the application.

    :return {Flask}: Returns the configuration Flask applciation object.
    """
    env = utils.environment()

    app = Flask(
        __name__,
        template_folder="/mystripeapp/mystripeapp/ui",
        static_folder="/mystripeapp/mystripeapp/ui/static",
    )

    configuration = dict(
        {
            "SERVER_NAME":
            "{name}:{port}".format(name=env["app"]["name"],
                                   port=env["app"]["port"]),
            "WTF_CSRF_SECRET_KEY":
            env["app"]["secret"],
            "WTF_CSRF_ENABLED":
            True,
            "WTF_CSRF_METHODS": ["GET", "POST", "PUT", "DELETE"],
            "SQLALCHEMY_TRACK_MODIFICATIONS":
            False,
            "SQLALCHEMY_DATABASE_URI":
            "{provider}://{user}:{password}@{host}:{port}/{db}".format(
                provider=env["database"]["provider"],
                user=env["database"]["username"],
                password=env["database"]["password"],
                host=env["database"]["host"],
                port=env["database"]["port"],
                db=env["database"]["database"],
            ),
        }, **override or {})

    # Apply default configuration values...
    for configuration_value in configuration:
        app.config[configuration_value] = configuration[configuration_value]

    # Enable the login manager library...
    app.login_manager = LoginManager(app)
    app.secret_key = env["app"]["secret"]

    # Setup the logging handlers and formatters...
    handler = logging.StreamHandler(stream=sys.stdout)
    handler.setFormatter(Formatter("%(asctime)s %(levelname)s: %(message)s"))
    handler.setLevel(logging.INFO)
    app.logger.handlers = [handler]
    app.logger.setLevel(logging.INFO)

    return app
示例#2
0
def delete_account():
    env = utils.environment()

    stripe.api_key = env["billing"]["stripe"]["token"]
    for subscription in stripe.Subscription.list(
            customer=current_user.stripe_customer_id):
        if subscription.customer == current_user.stripe_customer_id:
            subscription.delete()

    db.session.delete(current_user)
    db.session.commit()

    logout_user()
    return redirect("/")
    def register_to_stripe(self, user):
        """
        Registers a user to stripe.

        :param user {models.User}: The user to register to stripe.
        :return {tuple}: Returns the customer and the subscription created.
        """
        env = utils.environment()
        stripe.api_key = env["billing"]["stripe"]["token"]

        customer = stripe.Customer.create(
            description=self.name.data,
            source=self.stripeToken.data,
            metadata={"customer_code": user.id},
        )

        subscription = stripe.Subscription.create(
            customer=customer.id,
            items=[{
                "plan": env["billing"]["stripe"]["product"]
            }])

        return customer, subscription