Working API CHARGING!
This commit is contained in:
@@ -5,6 +5,7 @@ from app.classes.customer import Customer_Customer
|
||||
from app.classes.cards import Card_Card, Card_Card_schema
|
||||
from app.classes.transactions import Transaction
|
||||
from app.classes.delivery import Delivery_Delivery
|
||||
from app.classes.service import Service_Service, Service_Service_schema
|
||||
|
||||
|
||||
|
||||
@@ -438,3 +439,107 @@ def get_customer_transactions(customer_id, page):
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"ok": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@payment.route("/service/payment/<int:service_id>/<int:payment_type>", methods=["PUT"])
|
||||
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
|
||||
|
||||
# Set payment columns as specified
|
||||
service.payment_type = payment_type # 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
|
||||
|
||||
|
||||
@payment.route("/authorize/service/<int:service_id>", methods=["PUT"])
|
||||
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
|
||||
|
||||
data = request.get_json()
|
||||
card_id = data.get('card_id')
|
||||
status = data.get('status', 0)
|
||||
|
||||
service.payment_type = 11 # CC - Authorize
|
||||
service.payment_status = status
|
||||
if card_id:
|
||||
service.payment_card_id = card_id
|
||||
|
||||
try:
|
||||
db.session.commit()
|
||||
return jsonify({"ok": True}), 200
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
@payment.route("/capture/service/<int:service_id>", methods=["PUT"])
|
||||
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
|
||||
|
||||
data = request.get_json()
|
||||
card_id = data.get('card_id')
|
||||
status = data.get('status', 3) # Default to 3 for capture
|
||||
|
||||
if service.payment_type is None or service.payment_type != 11:
|
||||
service.payment_type = 11 # CC - Authorize
|
||||
service.payment_status = status # 3 for capture
|
||||
if card_id:
|
||||
service.payment_card_id = card_id
|
||||
|
||||
try:
|
||||
db.session.commit()
|
||||
return jsonify({"ok": True}), 200
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
@payment.route("/transactions/service/<int:service_id>", methods=["GET"])
|
||||
def get_service_transactions(service_id):
|
||||
"""
|
||||
Gets all transactions for a specific service ID
|
||||
"""
|
||||
try:
|
||||
query = (
|
||||
db.session
|
||||
.query(Transaction)
|
||||
.filter(Transaction.service_id == service_id)
|
||||
.order_by(Transaction.created_at.desc())
|
||||
)
|
||||
|
||||
transactions = query.all()
|
||||
|
||||
transactions_data = []
|
||||
for transaction in transactions:
|
||||
transactions_data.append({
|
||||
"id": transaction.id,
|
||||
"preauthorize_amount": float(transaction.preauthorize_amount or 0),
|
||||
"charge_amount": float(transaction.charge_amount or 0),
|
||||
"transaction_type": transaction.transaction_type,
|
||||
"status": transaction.status,
|
||||
"created_at": transaction.created_at.isoformat() if transaction.created_at else None,
|
||||
"auth_net_transaction_id": transaction.auth_net_transaction_id,
|
||||
"rejection_reason": transaction.rejection_reason,
|
||||
"delivery_id": transaction.delivery_id,
|
||||
"service_id": transaction.service_id,
|
||||
"card_id": transaction.card_id,
|
||||
})
|
||||
|
||||
return jsonify(transactions_data), 200
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error fetching transactions for service {service_id}: {str(e)}")
|
||||
return jsonify({"ok": False, "error": str(e)}), 500
|
||||
|
||||
Reference in New Issue
Block a user