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())
|
||||
main_card = db.Column(db.BOOLEAN())
|
||||
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 Meta:
|
||||
model = Card_Card
|
||||
|
||||
@@ -11,6 +11,7 @@ class Customer_Customer(db.Model):
|
||||
primary_key=True,
|
||||
autoincrement=True,
|
||||
unique=False)
|
||||
auth_net_profile_id = db.Column(db.String, unique=True, index=True, nullable=True)
|
||||
account_number = db.Column(db.VARCHAR(25))
|
||||
customer_last_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) \
|
||||
.filter(Customer_Description.customer_id == get_delivery.customer_id) \
|
||||
.first()
|
||||
delivery_driver_id = request.json["driver_employee_id"]
|
||||
if delivery_driver_id is None:
|
||||
delivery_driver_id = 2
|
||||
if delivery_driver_id == 0:
|
||||
delivery_driver_id = 2
|
||||
|
||||
#TODO hardcode for now
|
||||
delivery_driver_id = 2
|
||||
|
||||
get_driver = (db.session
|
||||
.query(Employee_Employee)
|
||||
|
||||
@@ -144,19 +144,25 @@ def remove_user_card(card_id):
|
||||
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"])
|
||||
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
|
||||
.query(Customer_Customer)
|
||||
.filter(Customer_Customer.id == user_id)
|
||||
.first())
|
||||
|
||||
if not get_customer:
|
||||
return jsonify({"ok": False, "error": "Customer not found"}), 404
|
||||
|
||||
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") # <-- This now matches the frontend
|
||||
name_on_card = data.get("name_on_card")
|
||||
expiration_month = data.get("expiration_month")
|
||||
expiration_year = data.get("expiration_year")
|
||||
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)
|
||||
zip_code = data.get("zip_code")
|
||||
card_number = data.get("card_number")
|
||||
|
||||
# FIX: Correctly slice the last four digits
|
||||
last_four = card_number[-4:] if card_number else ""
|
||||
|
||||
create_new_card = Card_Card(
|
||||
user_id=get_customer.id,
|
||||
card_number=card_number,
|
||||
last_four_digits=last_four, # <-- Use the correctly sliced value
|
||||
name_on_card=name_on_card,
|
||||
expiration_month=expiration_month,
|
||||
expiration_year=expiration_year,
|
||||
type_of_card=type_of_card,
|
||||
security_number=security_number,
|
||||
accepted_or_declined=None,
|
||||
main_card=main_card,
|
||||
zip_code=zip_code
|
||||
)
|
||||
db.session.add(create_new_card)
|
||||
db.session.flush()
|
||||
try:
|
||||
create_new_card = Card_Card(
|
||||
user_id=get_customer.id,
|
||||
card_number=card_number,
|
||||
last_four_digits=last_four,
|
||||
name_on_card=name_on_card,
|
||||
expiration_month=expiration_month,
|
||||
expiration_year=expiration_year,
|
||||
type_of_card=type_of_card,
|
||||
security_number=security_number,
|
||||
accepted_or_declined=None, # This is correct, as we don't know the status yet
|
||||
main_card=main_card,
|
||||
zip_code=zip_code
|
||||
)
|
||||
db.session.add(create_new_card)
|
||||
db.session.flush()
|
||||
|
||||
if main_card:
|
||||
set_card_main(user_id=get_customer.id, card_id=create_new_card.id)
|
||||
if main_card:
|
||||
# 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
|
||||
|
||||
|
||||
@payment.route("/card/edit/<int:card_id>", methods=["PUT"])
|
||||
def update_user_card(card_id):
|
||||
"""
|
||||
@@ -225,8 +237,8 @@ def update_user_card(card_id):
|
||||
get_card.zip_code = zip_code
|
||||
|
||||
# FIX: Correctly slice the last four digits on edit
|
||||
if card_number:
|
||||
get_card.last_four_digits = card_number[-4:]
|
||||
if card_number and card_number[-4:].isdigit():
|
||||
get_card.last_four_digits = int(card_number[-4:])
|
||||
|
||||
if main_card:
|
||||
set_card_main(user_id=get_card.user_id, card_id=get_card.id)
|
||||
|
||||
Reference in New Issue
Block a user