Esempio n. 1
0
def charge_up_front():
    jamla = get_jamla()
    jamlaApp = Jamla()
    jamlaApp.load(jamla=jamla)
    charge = {}
    charge["amount"] = session["upfront_cost"]
    charge["currency"] = "GBP"

    sid = session["sid"]

    db = get_db()
    res = db.execute("SELECT * FROM person p WHERE p.sid = ?",
                     (sid, )).fetchone()
    try:
        stripe.api_key = jamla["payment_providers"]["stripe"]["secret_key"]
        customer = stripe.Customer.create(email=res["email"],
                                          source=request.form["stripeToken"])

        charge = stripe.Charge.create(
            customer=customer.id,
            amount=charge["amount"],
            currency=charge["currency"],
            description="Subscribie",
        )
    except stripe.error.AuthenticationError as e:
        return str(e)
    if jamlaApp.requires_subscription(session["package"]):
        return redirect(url_for("views.establish_mandate"))
    else:
        return redirect(
            url_for("views.thankyou", _scheme="https", _external=True))
Esempio n. 2
0
def charge_up_front():
    jamlaApp = Jamla()
    jamla = jamlaApp.load(src=app.config['JAMLA_PATH'])
    charge = {}
    charge['amount'] = session['upfront_cost']
    charge['currency'] = "GBP"

    sid = session['sid']
    con = sqlite3.connect(app.config["DB_FULL_PATH"])
    cur = con.cursor()
    cur.execute("SELECT * FROM person p WHERE p.sid = ?", (sid, ))
    res = cur.fetchone()
    con.close()

    try:
        stripe.api_key = jamla['payment_providers']['stripe']['secret_key']
        customer = stripe.Customer.create(email=res[7],
                                          source=request.form['stripeToken'])

        charge = stripe.Charge.create(customer=customer.id,
                                      amount=charge['amount'],
                                      currency=charge['currency'],
                                      description='Subscribie')
    except stripe.error.AuthenticationError as e:
        return str(e)
    if jamlaApp.requires_subscription(session['package']):
        return redirect(url_for('establish_mandate'))
    else:
        return redirect(url_for('thankyou', _scheme='https', _external=True))
Esempio n. 3
0
def store_customer():
    form = CustomerForm()
    if form.validate():
        given_name = form.data['given_name']
        family_name = form.data['family_name']
        address_line_one = form.data['address_line_one']
        city = form.data['city']
        postcode = form.data['postcode']
        email = form.data['email']
        mobile = form.data['mobile']
        now = datetime.datetime.now()
        # Store customer in session
        sid = session['sid']
        # Store email in session
        session['email'] = email

        # Store plan in session
        jamlaApp = Jamla()
        jamla = jamlaApp.load(src=app.config['JAMLA_PATH'])
        if jamlaApp.sku_exists(request.args.get('plan')):
            wants = request.args.get('plan')
            session['plan'] = wants
        print "##################"
        con = sqlite3.connect(app.config["DB_FULL_PATH"])
        cur = con.cursor()
        cur.execute(
            "INSERT INTO person VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
            (sid, now, given_name, family_name, address_line_one, city,
             postcode, email, mobile, wants, 'null', 'null', False))
        con.commit()
        con.close()

        if jamlaApp.requires_instantpayment(session['package']):
            return redirect(
                url_for('up_front',
                        _scheme='https',
                        _external=True,
                        sid=sid,
                        package=wants,
                        fname=given_name))
        if jamlaApp.requires_subscription(session['package']):
            return redirect(url_for('establish_mandate'))
        return redirect(url_for('thankyou', _scheme='https', _external=True))
    else:
        return "Oops, there was an error processing that form, please go back and try again."
Esempio n. 4
0
def store_customer():
    form = CustomerForm()
    if form.validate():
        given_name = form.data["given_name"]
        family_name = form.data["family_name"]
        address_line_one = form.data["address_line_one"]
        city = form.data["city"]
        postcode = form.data["postcode"]
        email = form.data["email"]
        mobile = form.data["mobile"]
        now = datetime.datetime.now()
        # Store customer in session
        sid = session["sid"]
        # Store email in session
        session["email"] = email

        # Store plan in session
        jamlaApp = Jamla()
        jamla = get_jamla()
        jamlaApp.load(jamla=jamla)
        if jamlaApp.sku_exists(request.args.get("plan")):
            wants = request.args.get("plan")
            session["plan"] = wants
        db = get_db()
        db.execute(
            "INSERT INTO person VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
            (
                sid,
                now,
                given_name,
                family_name,
                address_line_one,
                city,
                postcode,
                email,
                mobile,
                wants,
                "null",
                "null",
                False,
            ),
        )
        db.commit()
        # Store note to seller in session if there is one
        note_to_seller = form.data["note_to_seller"]
        session["note_to_seller"] = note_to_seller
        if jamlaApp.requires_instantpayment(session["package"]):
            return redirect(
                url_for(
                    "views.up_front",
                    _scheme="https",
                    _external=True,
                    sid=sid,
                    package=wants,
                    fname=given_name,
                ))
        if jamlaApp.requires_subscription(session["package"]):
            # Check if in iframe
            if form.data["is_iframe"] == "True":
                insideIframe = True
            else:
                insideIframe = False
            return redirect(
                url_for("views.establish_mandate", inside_iframe=insideIframe))
        return redirect(
            url_for("views.thankyou", _scheme="https", _external=True))
    else:
        return "Oops, there was an error processing that form, please go back and try again."