示例#1
0
def credit_register(item_id):
    """クレジットカード登録"""
    form = CreditRegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        user_id = current_user.get_id()
        credit = Credit(
            # ユーザーID
            User_id=user_id,
            # クレジット名義人
            credit_name=form.credit_name.data,
            # クレジットカード番号
            credit_num=form.credit_num.data,
            # クレジット有効期限 Date型のため、日付はすべて1に設定するとする。
            expire=datetime.date(form.expiration_date02.data,
                                 form.expiration_date01.data, 1))
        credit.security_code = str(form.security_code.data)
        # データベース処理
        with db.session.begin(subtransactions=True):
            credit.create_new_credit()
        db.session.commit()
        # デフォルトに設定する場合
        if form.is_default.data:
            with db.session.begin(subtransactions=True):
                current_user.default_pay_way = 2
                current_user.default_Credit_id = credit.Credit_id
            db.session.commit()
        session['pay_way'] = 2
        session['Credit_id'] = credit.Credit_id
        flash('登録しました')
        return redirect(url_for('buy.pay_way', item_id=item_id))
    return render_template('buy/credit_register.html',
                           item_id=item_id,
                           form=form)
示例#2
0
def pay_way_delete():
    """支払い方法削除処理"""
    form = HiddenPayWayDeleteForm(request.form)
    if request.method == 'POST':
        with db.session.begin(subtransactions=True):
            # デフォルトで設定されているdefault_Credit_idが
            # 削除するdefault_Credit_idと一致していればNull値に更新し
            # default_pay_wayを1(代金引換)に更新する
            if current_user.default_Credit_id == int(form.Credit_id.data):
                current_user.default_pay_way = 1
                current_user.default_Credit_id = None
            Credit.delete_credit(int(form.Credit_id.data))
        db.session.commit()
        flash('削除しました')
    return redirect(url_for('mypage.pay_way'))
示例#3
0
def pay_way():
    """支払い方法選択処理"""
    if current_user.default_pay_way == 1:
        default_pay_way = 0
    elif current_user.default_pay_way == 2:
        default_pay_way = current_user.default_Credit_id
    form = PayWayForm(request.form, pay_way=default_pay_way)
    delete_form = HiddenPayWayDeleteForm(request.form)
    credits = Credit.select_credits_by_user_id()
    if credits:
        form.pay_way.choices += [(credit.Credit_id, 'クレジットカード')
                                 for credit in credits]
    if request.method == 'POST' and form.validate():
        # 代金引き換えのvalue:0に設定済み(1だとCredit_idと重複し判断できないため)
        if form.pay_way.data == 0:
            # デフォルト設定を代金引き換えに更新
            with db.session.begin(subtransactions=True):
                current_user.default_pay_way = 1
                # デフォルト設定ですでにdefault_Credit_idが設定されていればNull値に更新
                if current_user.default_Credit_id:
                    current_user.default_Credit_id = None
            db.session.commit()
        else:
            # デフォルト設定をクレジットに更新
            with db.session.begin(subtransactions=True):
                current_user.default_pay_way = 2
                current_user.default_Credit_id = int(form.pay_way.data)
            db.session.commit()
        flash('支払い方法を選択しました。')
    return render_template('mypage/pay_way.html',
                           form=form,
                           credits=credits,
                           delete_form=delete_form)
示例#4
0
def buy(item_id):
    """購入処理"""
    form = HiddenBuyForm(request.form)
    item = Sell.select_sell_by_sell_id(item_id)
    if request.method == 'POST' and form.validate():
        user_id = current_user.get_id()
        s_address = ShippingAddress.search_shippingaddress(
            form.ShippingAddress_id.data)
        if form.pay_way.data == '2':
            credit = Credit.search_credit(form.Credit_id.data)
            buycredit = BuyCredit(credit_name=credit.credit_name,
                                  credit_num=credit.credit_num,
                                  expire=credit.expire,
                                  security_code_hash=credit.security_code_hash)
            with db.session.begin(subtransactions=True):
                buycredit.create_new_buycredit()
            db.session.commit()
        buyshippingaddress = BuyShippingAddress(
            last_name=s_address.last_name,
            first_name=s_address.first_name,
            last_name_kana=s_address.last_name_kana,
            first_name_kana=s_address.first_name_kana,
            zip_code=s_address.zip_code,
            prefecture=s_address.prefecture,
            address1=s_address.address1,
            address2=s_address.address2,
            address3=s_address.address3)
        with db.session.begin(subtransactions=True):
            buyshippingaddress.create_new_buyshippingaddress()
        db.session.commit()
        creditid = ""
        if form.pay_way.data == '2':
            creditid = buycredit.BuyCredit_id
        buy = Buy(User_id=user_id,
                  Sell_id=item_id,
                  pay_way=form.pay_way.data,
                  Credit_id=creditid,
                  ShippingAddress_id=buyshippingaddress.BuyShippingAddress_id)
        with db.session.begin(subtransactions=True):
            buy.create_new_buy()
            item.deal_status = Deal_status['取引中']
            item.update_at = datetime.datetime.now()
        db.session.commit()
        # セッションの破棄
        session.pop('pay_way', None)
        session.pop('Credit_id', None)
        session.pop('ShippingAddress_id', None)
        return redirect(url_for('buy.buy_complete', item_id=item_id))
    return render_template('buy/buy.html', item=item, form=form)
示例#5
0
 def search_credit(Credit_id):
     """クレジット情報レコードを返す"""
     credit = Credit.search_credit(Credit_id)
     return credit