[Flask] Saving Stripe JSON objects in Flask Database
Anonymous Coder
anonymouscodar at gmail.com
Sun Feb 26 22:41:56 EST 2017
I have a Package model where I am trying to update fields below but for
expiry and due date I don't know how to implement. Objective is to retrieve
due date and expiry dates from stripe subscriptions.
class Package(db.Model):
__tablename__ = 'package'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
student_id = db.Column(db.Integer, ForeignKey('student_profile.id'))
stripe_id = db.Column(db.String(45))
student_email = db.Column(db.String(20))
subscription_date = db.Column(db.DateTime, default=today)
expiry_date = db.Column(db.DateTime, default=deadline)
expiry_date = db.Column(db.DateTime, default=deadline)
is_active = db.Column(db.Boolean, default=True)
package_type = db.Column(db.String(45), default='NOPACKAGE')
package_price = db.Column(db.Integer)
coupon = db.Column(db.String(12))
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
On Sun, Feb 26, 2017 at 1:27 PM, Tom Vaughan <thomas.david.vaughan at gmail.com
> wrote:
> 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
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20170227/605be0b8/attachment.html>
More information about the Flask
mailing list