Working API CHARGING!

This commit is contained in:
2025-09-20 15:33:36 -04:00
parent cfbc12da3b
commit 2209145e74
3 changed files with 173 additions and 0 deletions

View File

@@ -154,6 +154,51 @@ def create_service_call():
db.session.commit()
return jsonify({ "ok": True, "id": new_service_call.id }), 201
@service.route("/update-cost/<int:id>", methods=["PUT"])
def update_service_cost(id):
"""
Dedicated endpoint to update only the service cost for a service call.
This is used after payment capture/charge to update the actual amount.
"""
try:
# Find the service
service_record = Service_Service.query.get_or_404(id)
# Get request data - only service_cost
data = request.get_json()
if not data:
return jsonify({"error": "No data provided"}), 400
# Extract and validate the service_cost
new_cost = data.get('service_cost')
if new_cost is None:
return jsonify({"error": "service_cost is required"}), 400
# Convert to float for validation
try:
new_cost_float = float(new_cost)
except (ValueError, TypeError):
return jsonify({"error": "service_cost must be a valid number"}), 400
# Update the service_cost
service_record.service_cost = new_cost_float
# Commit the transaction
db.session.commit()
# Return success response
return jsonify({
"ok": True,
"service_id": id,
"service_cost_updated": new_cost_float,
"message": f"Service {id} cost updated to ${new_cost_float}"
}), 200
except Exception as e:
db.session.rollback()
print(f"Error updating service cost for service {id}: {str(e)}")
return jsonify({"error": str(e)}), 500
@service.route("/update/<int:id>", methods=["PUT"])
def update_service_call(id):
service_record = Service_Service.query.get_or_404(id)
@@ -336,3 +381,22 @@ def update_service_parts(customer_id):
except Exception as e:
db.session.rollback()
return jsonify({"error": str(e)}), 500
@service.route("/payment/<int:service_id>/<int:payment_type>", methods=["PUT"])
def process_service_payment(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
# Set payment columns as specified
service.payment_type = payment_type # e.g., 1 for Tiger
service.payment_status = 2 # As specified
# payment_card_id retains the selected card's ID if set in the service record
try:
db.session.commit()
return jsonify({"ok": True}), 200
except Exception as e:
db.session.rollback()
return jsonify({"error": str(e)}), 500