Working flow authorize

This commit is contained in:
2025-09-16 12:45:32 -04:00
parent 8d9ecf6935
commit 908100514f
3 changed files with 74 additions and 5 deletions

View File

@@ -201,9 +201,32 @@ def create_user_card(user_id):
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 a success response with the card_id
return jsonify({"ok": True, "card_id": create_new_card.id}), 200
@payment.route("/card/update_payment_profile/<int:card_id>", methods=["PUT"])
def update_card_payment_profile(card_id):
"""
Updates the auth_net_payment_profile_id for a card
"""
get_card = (db.session
.query(Card_Card)
.filter(Card_Card.id == card_id)
.first())
if not get_card:
return jsonify({"ok": False, "error": "Card not found"}), 404
data = request.get_json()
auth_net_payment_profile_id = data.get("auth_net_payment_profile_id")
get_card.auth_net_payment_profile_id = auth_net_payment_profile_id
db.session.add(get_card)
db.session.commit()
return jsonify({"ok": True}), 200
@payment.route("/card/edit/<int:card_id>", methods=["PUT"])
def update_user_card(card_id):
"""
@@ -226,6 +249,7 @@ def update_user_card(card_id):
card_number = data.get("card_number")
main_card = data.get("main_card", False)
zip_code = data.get("zip_code")
auth_net_payment_profile_id = data.get("auth_net_payment_profile_id")
get_card.card_number = card_number
get_card.name_on_card = name_on_card
@@ -235,6 +259,7 @@ def update_user_card(card_id):
get_card.security_number = security_number
get_card.main_card = main_card
get_card.zip_code = zip_code
get_card.auth_net_payment_profile_id = auth_net_payment_profile_id
# FIX: Correctly slice the last four digits on edit
if card_number and card_number[-4:].isdigit():
@@ -289,3 +314,46 @@ def get_authorize_transactions(page):
except Exception as e:
return jsonify({"ok": False, "error": str(e)}), 500
@payment.route("/transactions/customer/<int:customer_id>/<int:page>", methods=["GET"])
def get_customer_transactions(customer_id, page):
"""
Gets transactions for a specific customer
"""
try:
per_page = 50
offset = (page - 1) * per_page
query = (
db.session
.query(Transaction, Customer_Customer)
.join(Customer_Customer, Transaction.customer_id == Customer_Customer.id)
.filter(Transaction.customer_id == customer_id)
.order_by(Transaction.created_at.desc())
.offset(offset)
.limit(per_page)
)
results = query.all()
transactions_data = []
for transaction, customer in results:
transactions_data.append({
"id": transaction.id,
"preauthorize_amount": transaction.preauthorize_amount,
"charge_amount": transaction.charge_amount,
"transaction_type": transaction.transaction_type,
"status": transaction.status,
"customer_name": f"{customer.customer_first_name} {customer.customer_last_name}",
"created_at": transaction.created_at.isoformat(),
"auth_net_transaction_id": transaction.auth_net_transaction_id,
"rejection_reason": transaction.rejection_reason,
"delivery_id": transaction.delivery_id,
"service_id": transaction.service_id,
})
return jsonify(transactions_data), 200
except Exception as e:
return jsonify({"ok": False, "error": str(e)}), 500