Esempio n. 1
0
def account():
    user = User.load_current_user()
    stripe.api_key = STRIPE_SECRET
    try:
        customer = stripe.Customer.retrieve(user.stripe_customer_id)
    except:
        customer = False
    mail = MailingAddress.get_by_username(user.username)
    return render_template('account.html', customer=customer, mail=mail)
Esempio n. 2
0
def subscribe():
    form = StripeSubscriptionForm(request.form)
    if request.method == 'POST':
        stripe.api_key = STRIPE_SECRET

        user = User.load_current_user()
        customer = stripe.Customer.create(
            card=form.stripeToken.data,
            plan="regular",
            email=user.username
        )
        user.stripe_customer_id = customer.id
        user.put()
        m = MailingAddress(username=user.username, name=form.name.data, address1 = form.address1.data,\
            address2=form.address2.data, zipcode=form.zipcode.data, city=form.city.data, state=form.state.data, country=form.country.data)
        m.put()
        return redirect(url_for('account'))
    return render_template('subscribe.html', form=form, pub_key=STRIPE_PUB_KEY)
Esempio n. 3
0
def update_address():
    user = User.load_current_user()    
    form = AddressForm(request.form)
    m = MailingAddress.get_by_username(user.username)
    m.name = form.name.data
    m.address1 = form.address1.data
    m.address2 = form.address2.data
    m.zipcode = form.zipcode.data
    m.city = form.city.data
    m.state = form.state.data 
    m.country = form.country.data
    m.put()
    return redirect(url_for('account'))
Esempio n. 4
0
def subscribe():
    form = StripeSubscriptionForm(request.form)
    if request.method == 'POST':
        stripe.api_key = STRIPE_SECRET

        user = User.load_current_user()
        customer = stripe.Customer.create(
            card=form.stripeToken.data,
            plan="regular",
            email=user.username
        )
        user.stripe_customer_id = customer.id
        user.put()
        m = MailingAddress(username=user.username, name=form.name.data, address1 = form.address1.data,\
            address2=form.address2.data, zipcode=form.zipcode.data, city=form.city.data, state=form.state.data, country=form.country.data)
        m.put()
        context = dict()
        bodytext = render_template_string('emails/confirmation.txt', context=context)
        bodyhtml = render_template('emails/confirmation.html', context=context)
        mail.send_mail(sender="<*****@*****.**>", to=user.username,
                           subject="Welcome to the Club", body=bodytext, html=bodyhtml)
        return redirect(url_for('account'))
    return render_template('subscribe.html', form=form, pub_key=STRIPE_PUB_KEY)
Esempio n. 5
0
def edit_address():
    user = User.load_current_user()
    mail = MailingAddress.get_by_username(user.username)
    form = AddressForm(obj=mail)
    return render_template('address_edit.html', form=form)