added cleanup

This commit is contained in:
2025-09-19 19:08:25 -04:00
parent fd906a574b
commit cfbc12da3b

View File

@@ -317,6 +317,35 @@ def get_authorize_transactions(page):
return jsonify({"ok": False, "error": str(e)}), 500
@payment.route("/authorize/cleanup/<int:customer_id>", methods=["POST"])
def cleanup_authorize_profile(customer_id):
"""
Clean up Authorize.Net profile data in local database when API check fails.
Sets customer auth_net_profile_id to null and clears all card payment profile IDs.
"""
try:
# 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
customer.auth_net_profile_id = None
# Get all cards for this customer and set their auth_net_payment_profile_id to null
cards = db.session.query(Card_Card).filter(Card_Card.user_id == customer_id).all()
for card in cards:
card.auth_net_payment_profile_id = None
# Commit all changes
db.session.commit()
return jsonify({"ok": True, "message": f"Cleaned up Authorize.Net data for customer {customer_id}"}), 200
except Exception as e:
db.session.rollback()
return jsonify({"ok": False, "error": f"Failed to cleanup profile: {str(e)}"}), 500
@payment.route("/authorize/<int:delivery_id>", methods=["PUT"])
def update_delivery_payment_authorize(delivery_id):
"""