Esempio n. 1
0
def edit_address(aid):
    address = Address.query.filter_by(hashkey=aid).first()
    form = AddressForm(obj=address)
    if form.validate_on_submit():
        if address is None:
            address=Address()
            address.user = g.user
            db.session.add(address)
        form.populate_obj(address)
        db.session.commit()
        return redirect(url_for('confirm_payment'))
    return render_template('address.html.jinja2',
        user=g.user,
        addresses=Address.query.filter_by(user=g.user),
        form=form,
        title='Select Billing Address')
Esempio n. 2
0
def ebs_response():
    """
    Process response from EBS payment gateway.
    """
    data = b64decode(request.query_string[2:])
    decrypted = crypt(data, app.config['EBS_KEY'])
    response_split = {}
    status = 1
    for item in decrypted.split('&'):
        oneitem = item.split('=')
        response_split[oneitem[0]] = oneitem[1]

    #determine invoice from session
    workspace = Workspace.get(session['workspace'])
    invoice = Invoice.get_by_id(workspace, session['invoice'])
    address = Address.get_by_hashkey(session['address']).first()

    #pull out relevant info from response
    message = response_split['ResponseMessage']
    pg_transaction_id = response_split['TransactionID']
    status = response_split['ResponseCode']

    #create and save payment
    payment = Payment()
    db.session.add(payment)
    payment.invoice_id = invoice.id
    payment.response = json.dumps(response_split)
    db.session.commit()

    if status == '0':
        invoice.status = INVOICE_STATUS.PAID
    db.session.commit()

    # show transaction status
    return render_template('confirm.html.jinja2', status=status, invoice=invoice, address=address, workflow=invoice.workflow(), workspace=workspace, message=message, transaction_id=pg_transaction_id)
Esempio n. 3
0
def confirm_payment():
    """
    Confirm details and make a payment.
    """
    workspace = Workspace.get(session['workspace'])
    address = Address.get_by_hashkey(session['address']).first()
    invoice = Invoice.get_by_id(workspace, session['invoice'])
    return render_template('confirm.html.jinja2', invoice=invoice, address=address, workspace=workspace, workflow=invoice.workflow())
Esempio n. 4
0
def select_address(invoice, workspace):
    """
    Select an Address or enter a new one. Session must contain invoice id if it exists
    """
    form = AddressForm()
    if form.validate_on_submit():
        address = Address(user=g.user)
        db.session.add(address)
        form.populate_obj(address)
        db.session.commit()
        session['workspace'] = workspace.name
        session['address'] = getattr(address, 'hashkey', None)
        session['invoice'] = invoice.id
        print "SESSION WORKSPACE:", session['workspace']
        print "SESSION ADDRESS:", session['address']
        print "SESSION INVOICE:", session['invoice']
        return redirect(url_for('confirm_payment'))
    addresses = Address.get(g.user)
    return render_template('address.html',
        form=form, invoice=invoice, workspace=workspace, addresses=addresses)