У меня есть регистрационная форма, которая собирает данные кредитной карты. Рабочий процесс выглядит следующим образом:
Вот код отправки формы:
def register():
form = RegistrationForm()
if form.validate_on_submit():
user = User(
[...]
)
db.session.add(user)
#Charge
amount = 10000
customer = stripe.Customer.create(
email=job.company_email,
card=request.form['stripeToken']
)
try:
charge = stripe.Charge.create(
customer=customer.id,
amount=amount,
currency='usd',
description='Registration payment'
)
except StripeError as e:
***I want to raise a form validation error here if possible.***
db.session.commit()
return redirect(url_for('home'))
return render_template('register.html', form=form)