Exemple #1
0
def get_transaction_data():
    # Get POST data
    try:
        data = json.loads(request.data)
    except JSONDecodeError:
        return abort(403)

    if 'api_secret' not in data or config_file['API_SECRET'] != data[
            'api_secret']:
        return abort(403)

    # Initilialize webpay
    configure_webpay()

    # ACK the transaction
    try:
        response = Transaction.commit(token=data['token'])
    except TransactionCommitError:
        # On error, return the status of the token
        try:
            response = Transaction.status(token=data['token'])
        except TransactionStatusError as e:
            # Invalid token
            return {"response_code": -1, "reason": e.message}

    return json.dumps(response, default=lambda x: x.__dict__)
Exemple #2
0
def webpay_plus_commit(request):
    token = request.POST.get("token_ws")
    print("commit for token_ws: {}".format(token))

    response = Transaction.commit(token=token)
    print("response: {}".format(response))

    data = {'token': token, 'response': response}
    return render(request, 'Webpay/commit.html', data)
Exemple #3
0
def webpay_plus_commit():
    token = request.form.get("token_ws")
    print("commit for token_ws: {}".format(token))

    response = Transaction.commit(token=token)
    print("response: {}".format(response))

    return render_template('webpay/plus/commit.html',
                           token=token,
                           response=response)
Exemple #4
0
def webpay_plus_refund():
    token = request.form.get("token_ws")
    amount = request.form.get("amount")
    print("refund for token_ws: {} by amount: {}".format(token, amount))

    try:
        response = Transaction.refund(token, amount)
        print("response: {}".format(response))

        return render_template("webpay/plus/refund.html",
                               token=token,
                               amount=amount,
                               response=response)
    except TransbankError as e:
        print(e.message)
Exemple #5
0
def cart(request):
    total = 0
    FprecioC = 0
    buy_order = str(1)
    session_id = str(1)
    return_url = 'http://127.0.0.1:8000/terminal.html'
    for key, value in request.session['cart'].items():
            total = total + (float(value['price']) * value['quantity'])
            # FprecioC=(f'{total:.3f}')
            FprecioC= int(total)
    amount = FprecioC
    try:
        response = Transaction().create(buy_order, session_id, amount, return_url)
        print(amount)
        return render(request, 'core/cart.html', {"response":response})
    except TransbankError as e:
        print(e.message)
        return render(request, 'core/cart.html', {})
Exemple #6
0
def process_payment():
    # Get POST data
    try:
        basket = json.loads(request.data)
    except JSONDecodeError as e:
        return abort(403)

    if 'api_secret' not in basket or config_file['API_SECRET'] != basket[
            'api_secret']:
        return abort(403)

    # Initilialize webpay
    configure_webpay()

    result = Transaction.create(buy_order=basket['order_number'],
                                session_id=basket['order_number'],
                                amount=float(basket['total_incl_tax']),
                                return_url=basket['notify_url'])

    return {"token": result.token, "url": result.url}
Exemple #7
0
def webpay_plus_create():
    print("Webpay Plus Transaction.create")
    buy_order = str(random.randrange(1000000, 99999999))
    session_id = str(random.randrange(1000000, 99999999))
    amount = random.randrange(10000, 1000000)
    return_url = request.url_root + 'webpay-plus/commit'

    create_request = {
        "buy_order": buy_order,
        "session_id": session_id,
        "amount": amount,
        "return_url": return_url
    }

    response = Transaction.create(buy_order, session_id, amount, return_url)

    print(response)

    return render_template('webpay/plus/create.html',
                           request=create_request,
                           response=response)
Exemple #8
0
def webpay_plus_commit(request):
    token = request.POST.get("token_ws")
    response = Transaction.commit(token)
    return render(request, 'core/terminal.html', {"response":response,"token":token})
Exemple #9
0
 def status(cls,
            token: str,
            options: Options = None) -> TransactionStatusResponse:
     return T.status(token, cls.build_options(options))
Exemple #10
0
 def commit(cls,
            token: str,
            options: Options = None) -> TransactionCommitResponse:
     return T.commit(token, cls.build_options(options))