def action(self, resource, context, form): payments_module = get_payments(resource) devise = resource.get_property('devise') payment = payments_module.make_payment( resource, form['mode'], form['amount'], context.user, devise, order=resource) goto = '%s/;payment_form' % context.get_link(payment) return context.come_back(self.return_message, goto=goto)
def confirm_payments(): error = None access_token = request.cookies.get('access_token') try: payment_id = request.form['payment_id'] payment = confirm_payment(access_token, payment_id) payments = get_payments(access_token) accounts = list_accounts(access_token) except Exception as e: error = e if error: return render_template('payments.html', error=error) else: return redirect(url_for('payments'))
def payment_ways(self): context = get_context() namespace = [] payments = get_payments(context.resource) for brain in payments.get_payment_ways(enabled=True): payment_way = context.root.get_resource(brain.abspath) # XXX Does we have to set price in get_payment_way_description ? description = payment_way.get_payment_way_description(context, None) namespace.append({ 'name': payment_way.name, 'value': payment_way.get_title(), 'description': description, 'selected': False, 'logo': payment_way.get_logo(context)}) # Select the only possible choice if only one way enabled if len(namespace) == 1: namespace[0]['selected'] = True return namespace
def payments(): error = None access_token = request.cookies.get('access_token') if request.method == 'GET': try: payments = get_payments(access_token) accounts = list_accounts(access_token) except Exception as e: error = e if error: return render_template('payments.html', error=error) else: return render_template('payments.html', payments=payments, accounts=accounts) elif request.method == 'POST': amount = request.form['amount'] account_id = request.form['account_id'] beneficiary = request.form['beneficiary'] name = request.form['name'] message = request.form['message'] if None in [amount, account_id, beneficiary, name, message]: error = 'Form data missing!' if error: return render_template('payments.html', error=error) # Geenrate the payload payload = { "amount": amount, "creditor": { "account": { "_type": "IBAN", "value": beneficiary }, "message": message, "name": name, "reference": { "_type": "RF", "value": "RF18539007547034" } }, "currency": "EUR", "debtor": { "_accountId": account_id } } try: payment = initiate_payment(access_token, payload) accounts = list_accounts(access_token) payments = get_payments(access_token) except Exception as e: error = e if error: return render_template('payments.html', error=error) else: return render_template('payments.html', payments=payments, payment=payment, accounts=accounts)