[Flask] Saving Stripe JSON objects in Flask Database

Tom Vaughan thomas.david.vaughan at gmail.com
Sun Feb 26 08:27:52 EST 2017


On Sun, Feb 26, 2017 at 6:18 AM, Anonymous Coder
<anonymouscodar at gmail.com> wrote:
> Hi,
>
> I am having trouble saving Stripe json objects in Flask Database. Just need
> to save customer.id and expiry date from the view below:

I don't see an expiry date below. I don't see where you try to save
the customer id. What do you mean by "trouble"? Do you mean you've
encountered an error, or that you don't know how and you'd like us to
do the work for you? The former we can help with. The latter is
probably beyond the scope of this list.


>
> @app.route('/yearlychargedrec', methods=['GET', 'POST'])
> def yearly_charged_rec():
>     if not user_authorized():
>         return redirect('/')
>     if request.method == 'POST':
>         stripe_token = request.form['stripeToken']
>         email = request.form['stripeEmail']
>         customer = stripe.Customer.create(
>             email=email,
>             source=request.form['stripeToken']

See stripe_token variable above.

>         )
>         try:
>             subscription = stripe.Subscription.create(
>                 customer=customer.id,
>                 plan="yearlyrec",
>             )

subscription is unused.

>
>             package = Package(
>                 student_email=request.form['stripeEmail'],

See email variable above.

>                 is_active=True,
>                 package_type='yearlyrec'
>             )
>             dbase.session.add(package)
>             dbase.session.commit()
>         except stripe.error.CardError as e:
>             body = e.json_body
>             err = body['error']

body and err are unused. This error is ignored.

>
>     return render_template('/profile/charge/monthlycharge.html')

monthlycharge.html within a yearly charge handler?

>
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>


More information about the Flask mailing list