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

@@ -23,7 +23,8 @@ class Card_Card(db.Model):
accepted_or_declined = db.Column(db.INTEGER()) accepted_or_declined = db.Column(db.INTEGER())
main_card = db.Column(db.BOOLEAN()) main_card = db.Column(db.BOOLEAN())
zip_code = db.Column(db.VARCHAR(20)) zip_code = db.Column(db.VARCHAR(20))
auth_net_payment_profile_id = db.Column(db.String, unique=True, index=True, nullable=False) auth_net_payment_profile_id = db.Column(db.String, nullable=True)
class Card_Card_schema(ma.SQLAlchemyAutoSchema): class Card_Card_schema(ma.SQLAlchemyAutoSchema):
class Meta: class Meta:
model = Card_Card model = Card_Card

View File

@@ -337,10 +337,10 @@ def get_deliveries_tommorrow(page):
else: else:
offset_limit = (per_page_amount * page) - per_page_amount offset_limit = (per_page_amount * page) - per_page_amount
deliveries = (db.session deliveries = (db.session
.query(Delivery_Delivery) .query(Delivery_Delivery)
.filter(Delivery_Delivery.delivery_status == 3) .filter(Delivery_Delivery.delivery_status == 3)
.order_by(Delivery_Delivery.when_ordered.desc()) .order_by(Delivery_Delivery.id.desc())
.limit(per_page_amount).offset(offset_limit)) .limit(per_page_amount).offset(offset_limit))

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}") 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 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 return jsonify({"ok": True}), 200
@payment.route("/card/edit/<int:card_id>", methods=["PUT"]) @payment.route("/card/edit/<int:card_id>", methods=["PUT"])
def update_user_card(card_id): def update_user_card(card_id):
""" """
@@ -226,6 +249,7 @@ def update_user_card(card_id):
card_number = data.get("card_number") card_number = data.get("card_number")
main_card = data.get("main_card", False) main_card = data.get("main_card", False)
zip_code = data.get("zip_code") 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.card_number = card_number
get_card.name_on_card = name_on_card 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.security_number = security_number
get_card.main_card = main_card get_card.main_card = main_card
get_card.zip_code = zip_code 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 # FIX: Correctly slice the last four digits on edit
if card_number and card_number[-4:].isdigit(): if card_number and card_number[-4:].isdigit():
@@ -289,3 +314,46 @@ def get_authorize_transactions(page):
except Exception as e: except Exception as e:
return jsonify({"ok": False, "error": str(e)}), 500 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