Exemplo n.º 1
0
def dashboard():
    jamlaApp = Jamla()
    jamla = jamlaApp.load(src=app.config['JAMLA_PATH'])
    if jamlaApp.has_connected('gocardless'):
        gocardless_connected = True
    else:
        gocardless_connected = False
    if jamlaApp.has_connected('stripe'):
        stripe_connected = True
    else:
        stripe_connected = False
    return render_template('dashboard.html',
                           jamla=jamla,
                           gocardless_connected=gocardless_connected,
                           stripe_connected=stripe_connected)
Exemplo n.º 2
0
def connect_gocardless_manually():
    form = GocardlessConnectForm()
    jamlaApp = Jamla()
    jamla = jamlaApp.load(src=app.config['JAMLA_PATH'])
    if jamlaApp.has_connected('gocardless'):
        gocardless_connected = True
    else:
        gocardless_connected = False
    if form.validate_on_submit():
        access_token = form.data['access_token']
        jamla['payment_providers']['gocardless']['access_token'] = access_token
        # Check if live or test api key was given
        if "live" in access_token:
            jamla['payment_providers']['gocardless']['environment'] = 'live'
        else:
            jamla['payment_providers']['gocardless']['environment'] = 'sandbox'

        fp = open(app.config['JAMLA_PATH'], 'w')
        # Overwrite jamla file with gocardless access_token
        yaml.safe_dump(jamla, fp, default_flow_style=False)
        # Set users current session to store access_token for instant access
        flask_login.current_user.gocardless_access_token = access_token
        return redirect(url_for('dashboard'))
    else:
        return render_template('connect_gocardless_manually.html',
                               form=form,
                               jamla=jamla,
                               gocardless_connected=gocardless_connected)
Exemplo n.º 3
0
def connect_stripe_manually():
    form = StripeConnectForm()
    jamlaApp = Jamla()
    jamla = jamlaApp.load(src=app.config['JAMLA_PATH'])
    if jamlaApp.has_connected('stripe'):
        stripe_connected = True
    else:
        stripe_connected = False
    if form.validate_on_submit():
        publishable_key = form.data['publishable_key']
        secret_key = form.data['secret_key']
        jamla['payment_providers']['stripe'][
            'publishable_key'] = publishable_key
        jamla['payment_providers']['stripe']['secret_key'] = secret_key
        # Overwrite jamla file with gocardless access_token
        fp = open(app.config['JAMLA_PATH'], 'w')
        yaml.safe_dump(jamla, fp, default_flow_style=False)
        flask_login.current_user.stripe_publishable_key = publishable_key
        # Set stripe public key JS
        return redirect(url_for('dashboard'))
    else:
        return render_template('connect_stripe_manually.html',
                               form=form,
                               jamla=jamla,
                               stripe_connected=stripe_connected)
Exemplo n.º 4
0
def connect_stripe_manually():
    form = StripeConnectForm()
    jamla = get_jamla()
    jamlaApp = Jamla()
    jamlaApp.load(jamla=jamla)
    if jamlaApp.has_connected("stripe"):
        stripe_connected = True
    else:
        stripe_connected = False
    if form.validate_on_submit():
        publishable_key = form.data["publishable_key"].strip()
        secret_key = form.data["secret_key"].strip()
        jamla["payment_providers"]["stripe"][
            "publishable_key"] = publishable_key
        jamla["payment_providers"]["stripe"]["secret_key"] = secret_key
        # Overwrite jamla file with gocardless access_token
        fp = open(current_app.config["JAMLA_PATH"], "w")
        yaml.safe_dump(jamla, fp, default_flow_style=False)
        session["stripe_publishable_key"] = publishable_key
        # Set stripe public key JS
        return redirect(url_for("admin.dashboard"))
    else:
        return render_template(
            "admin/connect_stripe_manually.html",
            form=form,
            jamla=jamla,
            stripe_connected=stripe_connected,
        )
Exemplo n.º 5
0
def connect_gocardless_manually():
    form = GocardlessConnectForm()
    jamla = get_jamla()
    jamlaApp = Jamla()
    jamlaApp.load(jamla=jamla)
    if jamlaApp.has_connected("gocardless"):
        gocardless_connected = True
    else:
        gocardless_connected = False
    if form.validate_on_submit():
        access_token = form.data["access_token"]
        jamla["payment_providers"]["gocardless"]["access_token"] = access_token
        # Check if live or test api key was given
        if "live" in access_token:
            jamla["payment_providers"]["gocardless"]["environment"] = "live"
        else:
            jamla["payment_providers"]["gocardless"]["environment"] = "sandbox"

        fp = open(current_app.config["JAMLA_PATH"], "w")
        # Overwrite jamla file with gocardless access_token
        yaml.safe_dump(jamla, fp, default_flow_style=False)
        # Set users current session to store access_token for instant access
        session["gocardless_access_token"] = access_token
        return redirect(url_for("admin.dashboard"))
    else:
        return render_template(
            "admin/connect_gocardless_manually.html",
            form=form,
            jamla=jamla,
            gocardless_connected=gocardless_connected,
        )
Exemplo n.º 6
0
def customers():
    jamla = get_jamla()
    from SSOT import SSOT

    jamlaApp = Jamla()
    jamlaApp.load(jamla=jamla)

    target_gateways = ()

    if jamlaApp.has_connected("gocardless"):
        access_token = jamla["payment_providers"]["gocardless"]["access_token"]
        gc_environment = jamla["payment_providers"]["gocardless"][
            "environment"]
        target_gateways = target_gateways + ({
            "name": "GoCardless",
            "construct": {
                "access_token": access_token,
                "environment": gc_environment
            }
        }, )

    if jamlaApp.has_connected("stripe"):
        stripe_token = jamla["payment_providers"]["stripe"]["secret_key"]
        target_gateways = target_gateways + ({
            "name": "Stripe",
            "construct": stripe_token
        }, )

    try:
        SSOT = SSOT(target_gateways)
        partners = SSOT.partners
    except gocardless_pro.errors.InvalidApiUsageError as e:
        logging.error(e.type)
        logging.error(e.message)
        flash("Invalid GoCardless API token. Correct your GoCardless API key.")
        return redirect(url_for("admin.connect_gocardless_manually"))
    except ValueError as e:
        logging.error(e.message)
        if e.message == "No access_token provided":
            flash("You must connect your GoCardless account first.")
            return redirect(url_for("admin.connect_gocardless_manually"))
        else:
            raise
    return render_template("admin/customers.html",
                           jamla=jamla,
                           partners=partners)
Exemplo n.º 7
0
def establish_mandate():
    jamla = get_jamla()
    jamlaApp = Jamla()
    jamlaApp.load(jamla=jamla)

    if jamlaApp.has_connected("gocardless") is False:
        dashboard_url = url_for("admin.dashboard")
        return """<h1>Shop not set-up yet</h1>
            The shop owner first needs to login to their
            <a href="{}">dahboard</a>, and connect GoCardless to their shop.
            Once this has been completed, you will be able to order.
        """.format(dashboard_url)

    # lookup the customer with sid and get their relevant details
    sid = session["sid"]
    db = get_db()
    res = db.execute("SELECT * FROM person p WHERE p.sid = ?",
                     (sid, )).fetchone()

    logger.info("Person lookup: %s", res)
    # validate that hasInstantPaid is true for the customer
    gocclient = gocardless_pro.Client(
        access_token=jamlaApp.get_secret("gocardless", "access_token"),
        environment=jamla["payment_providers"]["gocardless"]["environment"],
    )

    description = " ".join([jamla["company"]["name"],
                            session["package"]])[0:100]
    redirect_flow = gocclient.redirect_flows.create(
        params={
            "description": description,
            "session_token": sid,
            "success_redirect_url": current_app.config["SUCCESS_REDIRECT_URL"],
            "prefilled_customer": {
                "given_name": res["given_name"],
                "family_name": res["family_name"],
                "address_line1": res["address_line1"],
                "city": res["city"],
                "postal_code": res["postal_code"],
                "email": res["email"],
            },
        })
    # Hold on to this ID - we'll need it when we
    # "confirm" the dedirect flow later
    print("ID: {} ".format(redirect_flow.id))
    print("URL: {} ".format(redirect_flow.redirect_url))

    # Check if we're inside an iframe, if yes redirect to pop-up
    # Issue https://github.com/Subscribie/subscribie/issues/128
    if request.args.get('inside_iframe', 'False') == "True":
        inside_iframe = True
        return render_template("iframe_new_window_redirect.html",
                               redirect_url=redirect_flow.redirect_url,
                               jamla=jamla)
        return '<a href="{}" target="_blank">Continue</a>'.format(
            redirect_flow.redirect_url)
    else:
        return redirect(redirect_flow.redirect_url)
Exemplo n.º 8
0
def dashboard():
    jamla = get_jamla()
    jamlaApp = Jamla()
    jamlaApp.load(jamla=jamla)

    if jamlaApp.has_connected("gocardless"):
        gocardless_connected = True
    else:
        gocardless_connected = False
    if jamlaApp.has_connected("stripe"):
        stripe_connected = True
    else:
        stripe_connected = False
    return render_template("admin/dashboard.html",
                           jamla=jamla,
                           gocardless_connected=gocardless_connected,
                           stripe_connected=stripe_connected,
                           loadedModules=getLoadedModules())