def main(args): """ メイン関数 """ if args[1] == "create": Base.metadata.create_all(bind=ENGINE) elif args[1] == "delete": Plan.__table__.drop(bind=ENGINE) elif args[1] == "maketestdata": """ [StripeプランID, Stripeプラン名, 金額] StripeプランIDは各自でつくったものを用意してください """ datas = [ ['plan_DmJAmdIJgDeQrl', 'ビギナープラン', 'beginner', 380], ['plan_DmJBmSkZsnm8z1', 'スタンダードプラン', 'standard', 1000], ['plan_DmJCkiLukDd4cY', 'プロフェッショナルプラン', 'professional', 2000], ] for data in datas: plan = Plan( stripe_plan_id=data[0], product_name='WEBプログラミングコース', name=data[1], namespace=data[2], amount=data[3], detail= 'テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト', ) session.add(plan) session.commit() session.close()
def create_user(form): user = User( email=form.getunicode('email'), password=_encrypt_password(form.getunicode('password1')), name=form.getunicode('name'), age=int(form.getunicode('age')) if form.getunicode('age') else None) session.add(user) session.commit() return user
def update_user(current_user, form): user = session.query(User).get(current_user.id) if form.getunicode('name'): user.name = form.getunicode('name') if form.getunicode('age'): user.age = int( form.getunicode('age')) if form.getunicode('age') else None if form.getunicode('email'): user.email = form.getunicode('email') session.commit()
def create_socials(user, data, provider): if provider == 'facebook': social = Social( user_id=user.id, provider=provider, provider_id=data['id'], ) # elif provider == 'twitter': session.add(social) session.commit()
def plans_charge(): subscription = stripe.Subscription.retrieve( current_user.stripe_subscription_id) subscription.delete() current_user.plan_id = None current_user.stripe_subscription_id = None session.commit() return template('templates/plans_delete', current_user=current_user, url=url)
def plans_charge(namespace): if current_user is None: redirect('/users/login') if current_user.stripe_id is None: redirect('/mypage') plan = session.query(Plan).filter(Plan.namespace == namespace).first() user = session.query(User).join( Plan, Plan.id == User.plan_id).filter(current_user.id == User.id).first() if plan is None: redirect('/plans') if current_user.plan_id is None: #新規 subscription = stripe.Subscription.create( customer=current_user.stripe_id, items=[{ 'plan': plan.stripe_plan_id, }]) current_user.plan_id = plan.id current_user.stripe_subscription_id = subscription.id session.commit() else: #既にサブスクリプションを購入しているので変更 if plan.id == current_user.plan_id: redirect('/plans') #同じプランには変更できない subscription = stripe.Subscription.retrieve( current_user.stripe_subscription_id) item_id = subscription['items']['data'][0].id stripe.Subscription.modify( current_user.stripe_subscription_id, cancel_at_period_end=False, items=[{ "id": item_id, "plan": plan.stripe_plan_id, }], ) current_user.plan_id = plan.id current_user.stripe_subscription_id = subscription.id session.commit() return template('templates/charge', url=url, current_user=current_user, plan=plan)
def create_facebook_user(data): user = User(name=data['name']) session.add(user) session.commit() return user
def update_password(current_user, form): user = session.query(User).get(current_user.id) if form.getunicode('password1'): user.password = _encrypt_password(form.getunicode('password1')) session.commit()
def set_stripe_id(user, stripe_id): user.stripe_id = stripe_id session.commit()