Ejemplo n.º 1
0
def create_mollie_transaction(result_id):

    # Find the form_result we are trying to pay.
    form_result = CustomFormResult.query.get_or_404(result_id)

    # Search open transactions that are still waiting to be paid.
    transaction = Transaction.query.join(TransactionActivity)\
        .filter(TransactionActivity.custom_form_result_id == form_result.id)\
        .filter(Transaction.status == 'open').first()

    # If no such payment exist, create a new one.
    if not transaction or not transaction.mollie_id:
        callback = TransactionActivity()
        callback.custom_form_result_id = result_id
        db.session.add(callback)
        db.session.commit()

        description = form_result.form.transaction_description
        description = "VIA Activity: " + description

        payment_url, msg = mollie.create_transaction(
            amount=form_result.form.price,
            description=form_result.form.transaction_description,
            user=form_result.owner,
            callbacks=[callback]
        )

        return redirect(payment_url) if payment_url else \
            render_template('mollie/success.htm', message=msg)
    else:
        payment, msg = mollie.check_transaction(transaction)
        if payment.is_open():
            return redirect(payment.get_payment_url())
        else:
            render_template('mollie/success.htm', message=msg)
Ejemplo n.º 2
0
def check(mollie_id=None, transaction_id=None):

    if transaction_id:
        transaction = Transaction.query.filter(
            Transaction.id == transaction_id).first() or abort(404)
    elif mollie_id:
        transaction = Transaction.query.filter(
            Transaction.mollie_id == mollie_id).first() or abort(404)
    else:
        abort(404)

    (success, msg) = check_transaction(transaction)
    flash(msg, 'success') if success else flash(msg, 'danger')
    return redirect(url_for('mollie.list'))
Ejemplo n.º 3
0
def callback(transaction_id=None):
    transaction = Transaction.query.get_or_404(transaction_id)
    (_, message) = check_transaction(transaction)
    return render_template('mollie/success.htm', message=message)