예제 #1
0
파일: app.py 프로젝트: ligthyear/at-su-g2
def start_payment():
    order = Order.query.get(request.form["order_id"])
    if not order or order.state not in ("to_confirm", "in_payment"):
        raise ValueError()

    order.state = "in_payment"
    db_session.add(order)
    db_session.commit()

    callback_url = url_for(".payment_callback",
                           payment_id=order.id, _external=True)
    return redirect(config.PAYMENT_URL.format(callback_url))
예제 #2
0
def get_user_from_browserid(user_data):
    if not user_data["status"] == "okay":
        raise ValueError(user_data)

    user = db_session.query(User
                            ).filter_by(email=user_data["email"]
                                        ).first()
    if not user:
        user = User(email=user_data["email"])
        db_session.add(user)
        db_session.commit()

    return user
예제 #3
0
파일: app.py 프로젝트: ligthyear/at-su-g2
def confirm():
    order = Order(user_id=current_user.id, state="to_confirm")

    if request.form.get("bill-selector") == "vat":
        valid, info = get_vat_info(request.form.get("vat-nr"))
        if not valid:
            return redirect(url_for(".checkout"))

        order.address = "{0}\n{1}".format(info.name, info.address)
        order.vat_addr = "{0}{1}".format(info.countryCode, info.vatNumber)

    elif request.form.get("address"):
        order.address = request.form.get("address")
    else:
        # FIXME: give good user message
        return redirect(url_for(".checkout"))

    if check_domain_available(request.form.get("domain")):
        order.domain = request.form.get("domain")
    else:
        # FIXME: give good user message
        return redirect(url_for(".checkout"))

    ctx = session["checkout_context"]

    sum_total = _total_price(ctx)
    order.currency = ctx["currency"]["label"]
    if order.vat_addr:
        order.total = sum_total
    else:
        order.total_vat = math.ceil(sum_total * 19) / 100.0
        order.total = sum_total + order.total_vat

    order.details = json.dumps(ctx)
    db_session.add(order)
    db_session.commit()

    return render_template("confirm.html", order=order,
                           upgrade_names=_upgrade_names(), **ctx)
예제 #4
0
파일: app.py 프로젝트: ligthyear/at-su-g2
def payment_callback(payment_id):
    # FIXME: needs to check against the third-party
    order = Order.query.get(payment_id)
    if not order or order.state != "in_payment":
        raise ValueError()

    order.state = "paid"
    db_session.add(order)
    db_session.commit()

    paid_callback = config.airtime["APIs"]["paid_callback"]
    details = json.loads(order.details)
    if paid_callback:
        for key in ("created", "updated", "domain", "state", "address",
                    "vat_addr", "currency", "total", "total_vat"):
            details[key] = getattr(details, key)

        req = urllib2.Request(paid_callback, json.dumps(details),
                              {'Content-Type': 'application/json'})
        urllib2.urlopen(req).read()

    return render_template("end_confirm.html", upgrade_names=_upgrade_names(), order=order, **details)