コード例 #1
0
ファイル: app.py プロジェクト: shabanovanton/vipps-developers
def order_page(order_id):
    """
    Page for managing a initiated order. No authentication performed. This page shows a mix of what should be
    accessible to the merchant and costumer.

    :param order_id: The ID for the order that are to be managed.
    :return: A render of the manage order page.
    """
    form = OrderPage(request.form)
    access_token = token_request()["access_token"]
    if request.method == 'POST':
        if form.cancel_order.data:
            cancel_order(order_id, access_token, "User canceled order")
        elif form.capture_order.data:
            capture_payment(order_id, access_token)
        elif form.refund_order.data:
            refund_payment(order_id, access_token)
    if session.get("order_id") == order_id:
        payment_url = session["payment_url"]
    else:
        payment_url = ""
    order_status_string = str(order_status(order_id, access_token))
    history = order_details(order_id, access_token)["transactionLogHistory"]
    return render_template("order_page.html",
                           form=form,
                           payment_url=payment_url,
                           order_status=order_status_string,
                           order_id=order_id,
                           order_history=history)
コード例 #2
0
ファイル: app.py プロジェクト: shabanovanton/vipps-developers
def initiate_payment():
    """
    Page for initiating payment. Validates that all fields are filled, before making a create_payment call.

    :return: A redirect to the Vipps confirm payment page.
    """
    form = Transaction(request.form)
    if form.validate():
        customer_number = int(form.customer_number.data)
        transaction_amount = form.transaction_amount.data
        transaction_text = form.transaction_text.data
        access_token = token_request()["access_token"]
        order_id = generate_random_order_id()
        payment = create_payment(order_id,
                                 access_token,
                                 transaction_amount,
                                 transaction_text,
                                 customer_number,
                                 express_checkout=form.express_checkout.data,
                                 is_app=form.is_app.data)
        if "url" in payment:
            payment_url = payment["url"]
        else:
            return jsonify(payment)
        session['payment_url'] = payment_url
        session['order_id'] = order_id
        return redirect(url_for('order_page', order_id=order_id))
    else:
        return redirect(url_for('index'))
コード例 #3
0
ファイル: app.py プロジェクト: alfmags/vipps-developers
def callback_route(order_id):
    """
    Endpoint for Vipps to provide transaction updates.

    :param order_id: The ID for the order there is updated information about.
    :return: Vipps requires no return for callback.
    """
    response = request.get_json()
    if response["transactionInfo"]["status"] == "Reserved":
        access_token = token_request()["access_token"]
        capture_payment(order_id, access_token)
コード例 #4
0
def callback_route(order_id):
    """
    Endpoint for Vipps to provide transaction updates.

    :param order_id: The ID for the order there is updated information about.
    :return: Vipps requires no return for callback.
    """
    callback_msg = request.get_json()
    log_callback(__name__ + ".callback_route", callback_msg=callback_msg, path_var=order_id)
    if callback_msg["transactionInfo"]["status"] == "RESERVE":
        access_token = token_request()["access_token"]
        capture_payment(order_id, access_token)
    return ""