Updated charge close to working
This commit is contained in:
21
app/classes/transactions.py
Normal file
21
app/classes/transactions.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from sqlalchemy import Column, Integer, String, Float, DateTime
|
||||||
|
from app import db
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
|
class Transaction(db.Model):
|
||||||
|
__tablename__ = "transactions"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
|
preauthorize_amount = Column(Float, nullable=True) # Amount preauthorized (for auth transactions)
|
||||||
|
charge_amount = Column(Float, nullable=True) # Final charge amount (for charge/capture transactions)
|
||||||
|
transaction_type = Column(Integer) # 0 = charge, 1 = auth, 3 = capture
|
||||||
|
status = Column(Integer) # 0 = approved, 1 = declined
|
||||||
|
auth_net_transaction_id = Column(String, unique=True, index=True, nullable=True)
|
||||||
|
customer_id = Column(Integer)
|
||||||
|
service_id = Column(Integer, nullable=True) # Reference to Service_Service.id
|
||||||
|
delivery_id = Column(Integer, nullable=True) # Reference to Delivery_Delivery.id
|
||||||
|
card_id = Column(Integer, nullable=True) # Reference to credit card used for payment
|
||||||
|
payment_gateway = Column(Integer, default=1) # 1 = Authorize.Net, 0 = Other
|
||||||
|
rejection_reason = Column(String, nullable=True) # Detailed error message when payment is declined
|
||||||
|
created_at = Column(DateTime, default=datetime.datetime.utcnow)
|
||||||
@@ -8,6 +8,7 @@ from app.classes.delivery import (Delivery_Delivery,
|
|||||||
)
|
)
|
||||||
from app.classes.service import Service_Service
|
from app.classes.service import Service_Service
|
||||||
from app.classes.auto import Auto_Delivery
|
from app.classes.auto import Auto_Delivery
|
||||||
|
from app.classes.transactions import Transaction
|
||||||
from datetime import date, timedelta, datetime
|
from datetime import date, timedelta, datetime
|
||||||
|
|
||||||
|
|
||||||
@@ -42,6 +43,8 @@ def get_sidebar_counts():
|
|||||||
Service_Service.scheduled_date < start_of_tomorrow
|
Service_Service.scheduled_date < start_of_tomorrow
|
||||||
).count()
|
).count()
|
||||||
|
|
||||||
|
transaction_count = db.session.query(Transaction).filter(Transaction.transaction_type == 0).count()
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"ok": True,
|
"ok": True,
|
||||||
"counts": {
|
"counts": {
|
||||||
@@ -52,6 +55,7 @@ def get_sidebar_counts():
|
|||||||
"automatic": automatic_count,
|
"automatic": automatic_count,
|
||||||
"upcoming_service": upcoming_service_count,
|
"upcoming_service": upcoming_service_count,
|
||||||
"today_service": today_service_count,
|
"today_service": today_service_count,
|
||||||
|
"transaction": transaction_count,
|
||||||
}
|
}
|
||||||
}), 200
|
}), 200
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from app.payment import payment
|
|||||||
from app import db
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -233,4 +234,46 @@ def update_user_card(card_id):
|
|||||||
db.session.add(get_card)
|
db.session.add(get_card)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return jsonify({"ok": True}), 200
|
return jsonify({"ok": True}), 200
|
||||||
|
|
||||||
|
|
||||||
|
@payment.route("/transactions/authorize/<int:page>", methods=["GET"])
|
||||||
|
def get_authorize_transactions(page):
|
||||||
|
"""
|
||||||
|
Gets transactions with transaction_type = 0 (charge), for the authorize page
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
.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
|
||||||
|
|||||||
@@ -288,6 +288,12 @@ def delete_service_plan(customer_id):
|
|||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
return jsonify({"error": str(e)}), 500
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
|
@service.route("/<int:id>", methods=["GET"])
|
||||||
|
def get_service_by_id(id):
|
||||||
|
service_record = Service_Service.query.get_or_404(id)
|
||||||
|
service_schema = Service_Service_schema()
|
||||||
|
return jsonify({"ok": True, "service": service_schema.dump(service_record)}), 200
|
||||||
|
|
||||||
@service.route("/delete/<int:id>", methods=["DELETE"])
|
@service.route("/delete/<int:id>", methods=["DELETE"])
|
||||||
def delete_service_call(id):
|
def delete_service_call(id):
|
||||||
service_record = Service_Service.query.get_or_404(id)
|
service_record = Service_Service.query.get_or_404(id)
|
||||||
|
|||||||
Reference in New Issue
Block a user