Exemple #1
0
def create(image_id):
    amount = request.form['amount']
    nonce_from_the_client = request.form['payment_method_nonce']
    result = gateway.transaction.sale({
        'amount': amount,
        'payment_method_nonce': nonce_from_the_client,
        'options': {
            "submit_for_settlement": True
        }
    })

    image_owner_id = Image.get_by_id(image_id)

    if result.is_success:
        new_donation = Donation.create(sender_id=current_user.id,
                                       receiver_id=image_owner_id,
                                       image=image_id,
                                       amount=amount)
        # need to link to user not image
        new_donation.save()
        flash('Donation received successfully', 'success')
        return redirect(url_for('users.show', username=current_user.name))
    else:
        flash(result.transaction.status)
        # flash(f'{result.transaction.processor_response_code}': {result.transaction.processor_response_code})
        return redirect(url_for('users.show', username=current_user.name))
def checkout():
    print(request.form.get('paymentMethodNonce'))
    donation_amount = request.form.get('donation_amount')
    Donation.create(user=current_user.id, amount=donation_amount)
    print(donation_amount)
    result = gateway.transaction.sale({
        "amount":
        donation_amount,
        "payment_method_nonce":
        request.form.get('paymentMethodNonce'),
        "options": {
            "submit_for_settlement": True
        }
    })

    print(result)
    print(request.form)
    send_message()
    return redirect(url_for('users.show', username=current_user.name))