Good progression
This commit is contained in:
@@ -4,6 +4,7 @@ from app import db
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -316,6 +317,59 @@ def get_authorize_transactions(page):
|
||||
return jsonify({"ok": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@payment.route("/authorize/<int:delivery_id>", methods=["PUT"])
|
||||
def update_delivery_payment_authorize(delivery_id):
|
||||
"""
|
||||
Update a delivery's payment_type to 11 (CC - Authorize API) after successful preauthorization
|
||||
"""
|
||||
get_delivery = (db.session
|
||||
.query(Delivery_Delivery)
|
||||
.filter(Delivery_Delivery.id == delivery_id)
|
||||
.first())
|
||||
|
||||
if not get_delivery:
|
||||
return jsonify({"ok": False, "error": "Delivery not found"}), 404
|
||||
|
||||
get_delivery.payment_type = 11
|
||||
|
||||
db.session.add(get_delivery)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({"ok": True}), 200
|
||||
|
||||
|
||||
@payment.route("/transaction/delivery/<int:delivery_id>", methods=["GET"])
|
||||
def get_transaction_by_delivery(delivery_id):
|
||||
"""
|
||||
Get a single transaction by delivery_id for Authorize.net payments
|
||||
"""
|
||||
transaction = (db.session
|
||||
.query(Transaction)
|
||||
.filter(Transaction.delivery_id == delivery_id)
|
||||
.first())
|
||||
|
||||
if not transaction:
|
||||
return jsonify({"ok": False, "error": "Transaction not found"}), 404
|
||||
|
||||
# Convert to dict-like format for frontend
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
"transaction": {
|
||||
"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,
|
||||
"auth_net_transaction_id": transaction.auth_net_transaction_id,
|
||||
"delivery_id": transaction.delivery_id,
|
||||
"customer_id": transaction.customer_id,
|
||||
"service_id": transaction.service_id,
|
||||
"card_id": transaction.card_id,
|
||||
"created_at": transaction.created_at.isoformat() if transaction.created_at else None
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@payment.route("/transactions/customer/<int:customer_id>/<int:page>", methods=["GET"])
|
||||
def get_customer_transactions(customer_id, page):
|
||||
"""
|
||||
@@ -327,8 +381,7 @@ def get_customer_transactions(customer_id, page):
|
||||
|
||||
query = (
|
||||
db.session
|
||||
.query(Transaction, Customer_Customer)
|
||||
.join(Customer_Customer, Transaction.customer_id == Customer_Customer.id)
|
||||
.query(Transaction)
|
||||
.filter(Transaction.customer_id == customer_id)
|
||||
.order_by(Transaction.created_at.desc())
|
||||
.offset(offset)
|
||||
@@ -338,14 +391,13 @@ def get_customer_transactions(customer_id, page):
|
||||
results = query.all()
|
||||
|
||||
transactions_data = []
|
||||
for transaction, customer in results:
|
||||
for transaction 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,
|
||||
|
||||
Reference in New Issue
Block a user