Updated claude big changes

This commit is contained in:
2026-01-29 08:43:56 -05:00
parent 2dbd3ea53f
commit eb4740c553
24 changed files with 388 additions and 429 deletions

View File

@@ -1,7 +1,8 @@
import logging
from flask import jsonify, request
from flask import request
from app.payment import payment
from app import db
from app.common.responses import error_response, success_response
from app.classes.customer import Customer_Customer
from app.classes.cards import Card_Card, Card_Card_schema
from app.classes.transactions import Transaction
@@ -68,7 +69,7 @@ def get_user_cards(user_id):
.all())
card_schema = Card_Card_schema(many=True)
return jsonify(card_schema.dump(get_u_cards))
return success_response({"cards": card_schema.dump(get_u_cards)})
@payment.route("/cards/onfile/<int:user_id>", methods=["GET"])
@@ -83,10 +84,7 @@ def get_user_cards_count(user_id):
.filter(Card_Card.user_id == user_id)
.count())
return jsonify({
"ok": True,
'cards': get_u_cards,
}), 200
return success_response({'cards': get_u_cards})
@payment.route("/card/<int:card_id>", methods=["GET"])
@@ -102,8 +100,7 @@ def get_user_specific_card(card_id):
.first())
card_schema = Card_Card_schema(many=False)
return jsonify(card_schema.dump(get_user_card))
return success_response({"card": card_schema.dump(get_user_card)})
@payment.route("/card/main/<int:card_id>/<int:user_id>", methods=["PUT"])
@@ -133,9 +130,7 @@ def set_main_card(user_id, card_id):
db.session.add(get_new_main_card)
db.session.commit()
return jsonify({"ok": True}), 200
return success_response()
@payment.route("/card/remove/<int:card_id>", methods=["DELETE"])
@@ -153,7 +148,7 @@ def remove_user_card(card_id):
db.session.delete(get_card)
db.session.commit()
return jsonify({"ok": True}), 200
return success_response()
# In your Flask payment routes file (e.g., app/routes/payment.py)
@@ -172,7 +167,7 @@ def create_user_card(user_id):
.first())
if not get_customer:
return jsonify({"ok": False, "error": "Customer not found"}), 404
return error_response("Customer not found", 404)
data = request.get_json()
name_on_card = data.get("name_on_card")
@@ -212,10 +207,10 @@ def create_user_card(user_id):
except Exception as e:
db.session.rollback()
logger.error(f"Database error saving card for user {user_id}: {e}")
return jsonify({"ok": False, "error": "Failed to save card information."}), 500
return error_response("Failed to save card information.", 500)
# Return a success response with the card_id
return jsonify({"ok": True, "card_id": create_new_card.id}), 200
return success_response({"card_id": create_new_card.id})
@payment.route("/card/update_payment_profile/<int:card_id>", methods=["PUT"])
@login_required
@@ -228,7 +223,7 @@ def update_card_payment_profile(card_id):
.filter(Card_Card.id == card_id)
.first())
if not get_card:
return jsonify({"ok": False, "error": "Card not found"}), 404
return error_response("Card not found", 404)
data = request.get_json()
auth_net_payment_profile_id = data.get("auth_net_payment_profile_id")
@@ -238,7 +233,7 @@ def update_card_payment_profile(card_id):
db.session.add(get_card)
db.session.commit()
return jsonify({"ok": True}), 200
return success_response()
@payment.route("/card/edit/<int:card_id>", methods=["PUT"])
@@ -252,7 +247,7 @@ def update_user_card(card_id):
.filter(Card_Card.id == card_id)
.first())
if not get_card:
return jsonify({"ok": False, "error": "Card not found"}), 404
return error_response("Card not found", 404)
data = request.get_json()
# FIX: Use .get() for safety and get the correct key 'name_on_card'
@@ -286,7 +281,7 @@ def update_user_card(card_id):
db.session.add(get_card)
db.session.commit()
return jsonify({"ok": True}), 200
return success_response()
@payment.route("/transactions/authorize/<int:page>", methods=["GET"])
@@ -327,10 +322,10 @@ def get_authorize_transactions(page):
"auto_id": transaction.auto_id,
})
return jsonify(transactions_data), 200
return success_response({"transactions": transactions_data})
except Exception as e:
return jsonify({"ok": False, "error": str(e)}), 500
return error_response(str(e), 500)
@payment.route("/authorize/cleanup/<int:customer_id>", methods=["POST"])
@@ -344,7 +339,7 @@ def cleanup_authorize_profile(customer_id):
# Get customer and set auth_net_profile_id to null
customer = db.session.query(Customer_Customer).filter(Customer_Customer.id == customer_id).first()
if not customer:
return jsonify({"ok": False, "error": "Customer not found"}), 404
return error_response("Customer not found", 404)
customer.auth_net_profile_id = None
@@ -356,11 +351,11 @@ def cleanup_authorize_profile(customer_id):
# Commit all changes
db.session.commit()
return jsonify({"ok": True, "message": f"Cleaned up Authorize.Net data for customer {customer_id}"}), 200
return success_response({"message": f"Cleaned up Authorize.Net data for customer {customer_id}"})
except Exception as e:
db.session.rollback()
return jsonify({"ok": False, "error": f"Failed to cleanup profile: {str(e)}"}), 500
return error_response(f"Failed to cleanup profile: {str(e)}", 500)
@payment.route("/authorize/<int:delivery_id>", methods=["PUT"])
@@ -375,14 +370,14 @@ def update_delivery_payment_authorize(delivery_id):
.first())
if not get_delivery:
return jsonify({"ok": False, "error": "Delivery not found"}), 404
return error_response("Delivery not found", 404)
get_delivery.payment_type = 11
db.session.add(get_delivery)
db.session.commit()
return jsonify({"ok": True}), 200
return success_response()
@payment.route("/transaction/delivery/<int:delivery_id>", methods=["GET"])
@@ -397,11 +392,10 @@ def get_transaction_by_delivery(delivery_id):
.first())
if not transaction:
return jsonify({"ok": False, "error": "Transaction not found"}), 404
return error_response("Transaction not found", 404)
# Convert to dict-like format for frontend
return jsonify({
"ok": True,
return success_response({
"transaction": {
"id": transaction.id,
"preauthorize_amount": float(transaction.preauthorize_amount or 0),
@@ -456,10 +450,10 @@ def get_customer_transactions(customer_id, page):
"auto_id": transaction.auto_id,
})
return jsonify(transactions_data), 200
return success_response({"transactions": transactions_data})
except Exception as e:
return jsonify({"ok": False, "error": str(e)}), 500
return error_response(str(e), 500)
@payment.route("/service/payment/<int:service_id>/<int:payment_type>", methods=["PUT"])
@@ -467,7 +461,7 @@ def get_customer_transactions(customer_id, page):
def process_service_payment_tiger(service_id, payment_type):
service = db.session.query(Service_Service).filter(Service_Service.id == service_id).first()
if not service:
return jsonify({"ok": False, "error": "Service not found"}), 404
return error_response("Service not found", 404)
# Set payment columns as specified
service.payment_type = payment_type # 1 for Tiger
@@ -476,10 +470,10 @@ def process_service_payment_tiger(service_id, payment_type):
try:
db.session.commit()
return jsonify({"ok": True}), 200
return success_response()
except Exception as e:
db.session.rollback()
return jsonify({"error": str(e)}), 500
return error_response(str(e), 500)
@payment.route("/authorize/service/<int:service_id>", methods=["PUT"])
@@ -487,7 +481,7 @@ def process_service_payment_tiger(service_id, payment_type):
def update_service_payment_authorize(service_id):
service = db.session.query(Service_Service).filter(Service_Service.id == service_id).first()
if not service:
return jsonify({"error": "Service not found"}), 404
return error_response("Service not found", 404)
data = request.get_json()
card_id = data.get('card_id')
@@ -500,10 +494,10 @@ def update_service_payment_authorize(service_id):
try:
db.session.commit()
return jsonify({"ok": True}), 200
return success_response()
except Exception as e:
db.session.rollback()
return jsonify({"error": str(e)}), 500
return error_response(str(e), 500)
@payment.route("/capture/service/<int:service_id>", methods=["PUT"])
@@ -511,7 +505,7 @@ def update_service_payment_authorize(service_id):
def update_service_payment_capture(service_id):
service = db.session.query(Service_Service).filter(Service_Service.id == service_id).first()
if not service:
return jsonify({"error": "Service not found"}), 404
return error_response("Service not found", 404)
data = request.get_json()
card_id = data.get('card_id')
@@ -525,10 +519,10 @@ def update_service_payment_capture(service_id):
try:
db.session.commit()
return jsonify({"ok": True}), 200
return success_response()
except Exception as e:
db.session.rollback()
return jsonify({"error": str(e)}), 500
return error_response(str(e), 500)
@payment.route("/transactions/service/<int:service_id>", methods=["GET"])
@@ -563,8 +557,8 @@ def get_service_transactions(service_id):
"card_id": transaction.card_id,
})
return jsonify(transactions_data), 200
return success_response({"transactions": transactions_data})
except Exception as e:
logger.error(f"Error fetching transactions for service {service_id}: {e}")
return jsonify({"ok": False, "error": str(e)}), 500
return error_response(str(e), 500)