· 6 years ago · Mar 06, 2019, 02:20 PM
1stripe_keys = {'secret_key': "********************************", 'publishable_key': "pk_test_xSiQPqcyDe8xy2rsaB9EUZh3"}
2stripe.api_key = stripe_keys['secret_key']
3
4class Subscription(BaseView):
5 default_view = 'subscription_page'
6 @expose('/')
7 @has_access
8 def subscription_page(self):
9 return self.render_template( 'subscription.html', key=stripe_keys['publishable_key'])
10
11 @expose('/charge', methods=['GET', 'POST'])
12 @has_access
13 def charge(self):
14 amount = 500
15 customer = stripe.Customer.create(email = request.form['stripeEmail'], source=request.form['stripeToken'])
16 charge = stripe.Charge.create( customer=customer.id, amount=amount, currency='usd', description='Flask Charge')
17 return self.render_template('charge.html', amount=amount, charge_stripe = 1)
18
19 @expose('/charge/plan', methods=['GET', 'POST'])
20 @has_access
21 def subscription_charge(self):
22 amount = 2000
23 product = stripe.Product.create( name='Monthly Plan', type='service', )
24 plan = stripe.Plan.create( product=product.id, nickname='Monthly Plan', interval='month', currency='usd', amount=amount, )
25 customer = stripe.Customer.create(email = request.form['stripeEmail'], source=request.form['stripeToken'])
26 subscription = stripe.Subscription.create( customer.id, items=[{'plan': plan.id}])
27 return self.render_template('charge.html', amount=amount, subscription_stripe = 1)