Adding authnet not tested
This commit is contained in:
@@ -23,7 +23,7 @@ class Card_Card(db.Model):
|
|||||||
accepted_or_declined = db.Column(db.INTEGER())
|
accepted_or_declined = db.Column(db.INTEGER())
|
||||||
main_card = db.Column(db.BOOLEAN())
|
main_card = db.Column(db.BOOLEAN())
|
||||||
zip_code = db.Column(db.VARCHAR(20))
|
zip_code = db.Column(db.VARCHAR(20))
|
||||||
|
auth_net_payment_profile_id = db.Column(db.String, unique=True, index=True, nullable=False)
|
||||||
class Card_Card_schema(ma.SQLAlchemyAutoSchema):
|
class Card_Card_schema(ma.SQLAlchemyAutoSchema):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Card_Card
|
model = Card_Card
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class Customer_Customer(db.Model):
|
|||||||
primary_key=True,
|
primary_key=True,
|
||||||
autoincrement=True,
|
autoincrement=True,
|
||||||
unique=False)
|
unique=False)
|
||||||
|
auth_net_profile_id = db.Column(db.String, unique=True, index=True, nullable=True)
|
||||||
account_number = db.Column(db.VARCHAR(25))
|
account_number = db.Column(db.VARCHAR(25))
|
||||||
customer_last_name = db.Column(db.VARCHAR(250))
|
customer_last_name = db.Column(db.VARCHAR(250))
|
||||||
customer_first_name = db.Column(db.VARCHAR(250))
|
customer_first_name = db.Column(db.VARCHAR(250))
|
||||||
|
|||||||
@@ -49,11 +49,9 @@ def office_finalize_delivery(delivery_id):
|
|||||||
.query(Customer_Description) \
|
.query(Customer_Description) \
|
||||||
.filter(Customer_Description.customer_id == get_delivery.customer_id) \
|
.filter(Customer_Description.customer_id == get_delivery.customer_id) \
|
||||||
.first()
|
.first()
|
||||||
delivery_driver_id = request.json["driver_employee_id"]
|
|
||||||
if delivery_driver_id is None:
|
#TODO hardcode for now
|
||||||
delivery_driver_id = 2
|
delivery_driver_id = 2
|
||||||
if delivery_driver_id == 0:
|
|
||||||
delivery_driver_id = 2
|
|
||||||
|
|
||||||
get_driver = (db.session
|
get_driver = (db.session
|
||||||
.query(Employee_Employee)
|
.query(Employee_Employee)
|
||||||
|
|||||||
@@ -54,9 +54,9 @@ def get_user_cards(user_id):
|
|||||||
"""
|
"""
|
||||||
gets all cards of a user
|
gets all cards of a user
|
||||||
"""
|
"""
|
||||||
get_u_cards = (db.session
|
get_u_cards = (db.session
|
||||||
.query(Card_Card)
|
.query(Card_Card)
|
||||||
.filter(Card_Card.user_id == user_id)
|
.filter(Card_Card.user_id == user_id)
|
||||||
.all())
|
.all())
|
||||||
|
|
||||||
card_schema = Card_Card_schema(many=True)
|
card_schema = Card_Card_schema(many=True)
|
||||||
@@ -144,19 +144,25 @@ def remove_user_card(card_id):
|
|||||||
return jsonify({"ok": True}), 200
|
return jsonify({"ok": True}), 200
|
||||||
|
|
||||||
|
|
||||||
|
# In your Flask payment routes file (e.g., app/routes/payment.py)
|
||||||
|
|
||||||
|
# ... (your existing imports: jsonify, request, db, Customer_Customer, Card_Card) ...
|
||||||
|
|
||||||
@payment.route("/card/create/<int:user_id>", methods=["POST"])
|
@payment.route("/card/create/<int:user_id>", methods=["POST"])
|
||||||
def create_user_card(user_id):
|
def create_user_card(user_id):
|
||||||
"""
|
"""
|
||||||
adds a card of a user
|
Adds a card for a user to the local database. This is its only job.
|
||||||
"""
|
"""
|
||||||
get_customer = (db.session
|
get_customer = (db.session
|
||||||
.query(Customer_Customer)
|
.query(Customer_Customer)
|
||||||
.filter(Customer_Customer.id == user_id)
|
.filter(Customer_Customer.id == user_id)
|
||||||
.first())
|
.first())
|
||||||
|
|
||||||
|
if not get_customer:
|
||||||
|
return jsonify({"ok": False, "error": "Customer not found"}), 404
|
||||||
|
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
# FIX: Use .get() for safety and get the correct key 'name_on_card'
|
name_on_card = data.get("name_on_card")
|
||||||
name_on_card = data.get("name_on_card") # <-- This now matches the frontend
|
|
||||||
expiration_month = data.get("expiration_month")
|
expiration_month = data.get("expiration_month")
|
||||||
expiration_year = data.get("expiration_year")
|
expiration_year = data.get("expiration_year")
|
||||||
type_of_card = data.get("type_of_card")
|
type_of_card = data.get("type_of_card")
|
||||||
@@ -164,34 +170,40 @@ def create_user_card(user_id):
|
|||||||
main_card = data.get("main_card", False)
|
main_card = data.get("main_card", False)
|
||||||
zip_code = data.get("zip_code")
|
zip_code = data.get("zip_code")
|
||||||
card_number = data.get("card_number")
|
card_number = data.get("card_number")
|
||||||
|
|
||||||
# FIX: Correctly slice the last four digits
|
|
||||||
last_four = card_number[-4:] if card_number else ""
|
last_four = card_number[-4:] if card_number else ""
|
||||||
|
|
||||||
create_new_card = Card_Card(
|
try:
|
||||||
user_id=get_customer.id,
|
create_new_card = Card_Card(
|
||||||
card_number=card_number,
|
user_id=get_customer.id,
|
||||||
last_four_digits=last_four, # <-- Use the correctly sliced value
|
card_number=card_number,
|
||||||
name_on_card=name_on_card,
|
last_four_digits=last_four,
|
||||||
expiration_month=expiration_month,
|
name_on_card=name_on_card,
|
||||||
expiration_year=expiration_year,
|
expiration_month=expiration_month,
|
||||||
type_of_card=type_of_card,
|
expiration_year=expiration_year,
|
||||||
security_number=security_number,
|
type_of_card=type_of_card,
|
||||||
accepted_or_declined=None,
|
security_number=security_number,
|
||||||
main_card=main_card,
|
accepted_or_declined=None, # This is correct, as we don't know the status yet
|
||||||
zip_code=zip_code
|
main_card=main_card,
|
||||||
)
|
zip_code=zip_code
|
||||||
db.session.add(create_new_card)
|
)
|
||||||
db.session.flush()
|
db.session.add(create_new_card)
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
if main_card:
|
if main_card:
|
||||||
set_card_main(user_id=get_customer.id, card_id=create_new_card.id)
|
# Assuming set_card_main is another function you have
|
||||||
|
set_card_main(user_id=get_customer.id, card_id=create_new_card.id)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
print(f"SUCCESS: Card saved locally for user {user_id} with new ID {create_new_card.id}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
db.session.rollback()
|
||||||
|
print(f"DATABASE ERROR: Could not save card for user {user_id}. Error: {e}")
|
||||||
|
return jsonify({"ok": False, "error": "Failed to save card information."}), 500
|
||||||
|
|
||||||
|
# Return a success response because the primary goal was achieved.
|
||||||
return jsonify({"ok": True}), 200
|
return jsonify({"ok": True}), 200
|
||||||
|
|
||||||
|
|
||||||
@payment.route("/card/edit/<int:card_id>", methods=["PUT"])
|
@payment.route("/card/edit/<int:card_id>", methods=["PUT"])
|
||||||
def update_user_card(card_id):
|
def update_user_card(card_id):
|
||||||
"""
|
"""
|
||||||
@@ -225,8 +237,8 @@ def update_user_card(card_id):
|
|||||||
get_card.zip_code = zip_code
|
get_card.zip_code = zip_code
|
||||||
|
|
||||||
# FIX: Correctly slice the last four digits on edit
|
# FIX: Correctly slice the last four digits on edit
|
||||||
if card_number:
|
if card_number and card_number[-4:].isdigit():
|
||||||
get_card.last_four_digits = card_number[-4:]
|
get_card.last_four_digits = int(card_number[-4:])
|
||||||
|
|
||||||
if main_card:
|
if main_card:
|
||||||
set_card_main(user_id=get_card.user_id, card_id=get_card.id)
|
set_card_main(user_id=get_card.user_id, card_id=get_card.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user