Good progression
This commit is contained in:
@@ -9,7 +9,7 @@ class Transaction(db.Model):
|
|||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
preauthorize_amount = Column(Numeric(10, 2), nullable=True) # Amount preauthorized (for auth transactions)
|
preauthorize_amount = Column(Numeric(10, 2), nullable=True) # Amount preauthorized (for auth transactions)
|
||||||
charge_amount = Column(Numeric(10, 2), nullable=True) # Final charge amount (for charge/capture transactions)
|
charge_amount = Column(Numeric(10, 2), nullable=True) # Final charge amount (for charge/capture transactions)
|
||||||
transaction_type = Column(Integer) # 0 = charge, 1 = auth, 3 = capture
|
transaction_type = Column(Integer) # 0 = charge, 1 = auth, 2 = capture
|
||||||
status = Column(Integer) # 0 = approved, 1 = declined
|
status = Column(Integer) # 0 = approved, 1 = declined
|
||||||
auth_net_transaction_id = Column(String, unique=True, index=True, nullable=True)
|
auth_net_transaction_id = Column(String, unique=True, index=True, nullable=True)
|
||||||
customer_id = Column(Integer)
|
customer_id = Column(Integer)
|
||||||
|
|||||||
@@ -617,16 +617,18 @@ def create_a_delivery(user_id):
|
|||||||
|
|
||||||
|
|
||||||
# 0 = cash only
|
# 0 = cash only
|
||||||
# 1 = credit only
|
# 1 = CC - Tiger (Physical)
|
||||||
|
# 11 = CC - Authorize (API)
|
||||||
# 2 = credit /cash
|
# 2 = credit /cash
|
||||||
# 3 = check
|
# 3 = check
|
||||||
# 4 = other
|
# 4 = other
|
||||||
# 5 = unknown
|
|
||||||
|
|
||||||
if cash_payment is True:
|
if cash_payment is True:
|
||||||
delivery_payment_method = 0
|
delivery_payment_method = 0
|
||||||
if card_payment is True:
|
if card_payment is True:
|
||||||
delivery_payment_method = 1
|
# Check if Authorize.net API should be used (type 11) vs physical (type 1)
|
||||||
|
# This logic can be enhanced to check user preferences or other criteria
|
||||||
|
delivery_payment_method = 1 # Default to Tiger physical machine
|
||||||
if check_payment is True:
|
if check_payment is True:
|
||||||
delivery_payment_method = 3
|
delivery_payment_method = 3
|
||||||
if other_payment is True:
|
if other_payment is True:
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from app import db
|
|||||||
from app.classes.customer import Customer_Customer
|
from app.classes.customer import Customer_Customer
|
||||||
from app.classes.cards import Card_Card, Card_Card_schema
|
from app.classes.cards import Card_Card, Card_Card_schema
|
||||||
from app.classes.transactions import Transaction
|
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
|
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"])
|
@payment.route("/transactions/customer/<int:customer_id>/<int:page>", methods=["GET"])
|
||||||
def get_customer_transactions(customer_id, page):
|
def get_customer_transactions(customer_id, page):
|
||||||
"""
|
"""
|
||||||
@@ -327,8 +381,7 @@ def get_customer_transactions(customer_id, page):
|
|||||||
|
|
||||||
query = (
|
query = (
|
||||||
db.session
|
db.session
|
||||||
.query(Transaction, Customer_Customer)
|
.query(Transaction)
|
||||||
.join(Customer_Customer, Transaction.customer_id == Customer_Customer.id)
|
|
||||||
.filter(Transaction.customer_id == customer_id)
|
.filter(Transaction.customer_id == customer_id)
|
||||||
.order_by(Transaction.created_at.desc())
|
.order_by(Transaction.created_at.desc())
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
@@ -338,14 +391,13 @@ def get_customer_transactions(customer_id, page):
|
|||||||
results = query.all()
|
results = query.all()
|
||||||
|
|
||||||
transactions_data = []
|
transactions_data = []
|
||||||
for transaction, customer in results:
|
for transaction in results:
|
||||||
transactions_data.append({
|
transactions_data.append({
|
||||||
"id": transaction.id,
|
"id": transaction.id,
|
||||||
"preauthorize_amount": transaction.preauthorize_amount,
|
"preauthorize_amount": transaction.preauthorize_amount,
|
||||||
"charge_amount": transaction.charge_amount,
|
"charge_amount": transaction.charge_amount,
|
||||||
"transaction_type": transaction.transaction_type,
|
"transaction_type": transaction.transaction_type,
|
||||||
"status": transaction.status,
|
"status": transaction.status,
|
||||||
"customer_name": f"{customer.customer_first_name} {customer.customer_last_name}",
|
|
||||||
"created_at": transaction.created_at.isoformat(),
|
"created_at": transaction.created_at.isoformat(),
|
||||||
"auth_net_transaction_id": transaction.auth_net_transaction_id,
|
"auth_net_transaction_id": transaction.auth_net_transaction_id,
|
||||||
"rejection_reason": transaction.rejection_reason,
|
"rejection_reason": transaction.rejection_reason,
|
||||||
|
|||||||
1
info_authorize_transactiopn_type.txt
Normal file
1
info_authorize_transactiopn_type.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# 0 = charge, 1 = auth, 3 = capture
|
||||||
@@ -2,4 +2,12 @@
|
|||||||
1: CC
|
1: CC
|
||||||
2: Cash/CC
|
2: Cash/CC
|
||||||
3: Check
|
3: Check
|
||||||
|
4: Other
|
||||||
|
|
||||||
|
|
||||||
|
0: Cash
|
||||||
|
1: CC - Tiger
|
||||||
|
11: CC - Authorize
|
||||||
|
2: Cash/CC
|
||||||
|
3: Check
|
||||||
4: Other
|
4: Other
|
||||||
Reference in New Issue
Block a user