-
Notifications
You must be signed in to change notification settings - Fork 2
/
payment_option.py
89 lines (66 loc) · 2.22 KB
/
payment_option.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'''
This module defines the class for Payment Option creation.
'''
import sqlite3
import os
class PaymentOption:
'''
Purpose:
This Class handles creation of a Payment Option.
Methods:
__init__(self, first_name, last_name, acct_number, exp_date, ccv, category)
Author:
@mccordgh
'''
def __init__(self, first_name, last_name, acct_number, exp_date, ccv, category, id_customer):
self.first_name = first_name
self.last_name = last_name
self.acct_number = acct_number
self.exp_date = exp_date
self.ccv = ccv
self.category = category
self.id_customer = id_customer
def save_to_db(self):
connection = sqlite3.connect('{}bangazon.db'.format(self.get_dir_fix()))
cursor = connection.cursor()
sql_command = """
INSERT OR IGNORE INTO Payments VALUES (null, "{}", "{}", "{}", "{}", "{}", "{}", "{}")
""".format(self.first_name, self.last_name, self.acct_number, self.exp_date, self.ccv, self.category, self.id_customer)
cursor.execute(sql_command)
connection.commit()
connection.close()
def get_first_name(self):
return self.first_name
def get_last_name(self):
return self.last_name
def get_acct_number(self):
return self.acct_number
def get_exp_date(self):
return self.exp_date
def get_ccv(self):
return self.ccv
def get_category(self):
return self.category
def get_id_customer(self):
return self.id_customer
def check_if_acct_exists(self):
connection = sqlite3.connect('{}bangazon.db'.format(self.get_dir_fix()))
cursor = connection.cursor()
sql_command = """
SELECT acct_number
FROM Payments
WHERE acct_number={}
""".format(self.acct_number)
try:
cursor.execute(sql_command)
except:
return False
acct_info = cursor.fetchall()
connection.commit()
connection.close()
return True
def get_dir_fix(self):
if os.path.basename(os.getcwd()) == 'tests' or os.path.basename(os.getcwd()) == 'scripts':
return '../'
else:
return ''