Updated charge close to working

This commit is contained in:
2025-09-09 18:28:41 -04:00
parent 8c37b6aeab
commit 8d134f691b
15 changed files with 40 additions and 113 deletions

View File

@@ -12,17 +12,17 @@ def get_customers(db: Session, skip: int = 0, limit: int = 100):
def create_transaction(db: Session, transaction: schemas.TransactionBase, customer_id: int, status: int, auth_net_transaction_id: str = None):
db_transaction = models.Transaction(
preauthorize_amount=transaction.preauthorize_amount,
charge_amount=transaction.charge_amount,
preauthorize_amount=transaction.preauthorize_amount if status == 0 else 0, # Only save pre-auth amount if approved
charge_amount=transaction.charge_amount if transaction.transaction_type != 0 or status == 0 else 0, # Only save charge amount for charges if approved
transaction_type=transaction.transaction_type,
customer_id=customer_id,
status=status,
auth_net_transaction_id=auth_net_transaction_id,
service_id=transaction.service_id,
delivery_id=transaction.delivery_id,
card_id=transaction.card_id,
service_id=transaction.service_id,
delivery_id=transaction.delivery_id,
card_id=transaction.card_id,
payment_gateway=transaction.payment_gateway,
rejection_reason=transaction.rejection_reason
rejection_reason=transaction.rejection_reason
)
db.add(db_transaction)
db.commit()
@@ -50,7 +50,8 @@ def update_transaction_for_capture(db: Session, auth_net_transaction_id: str, ch
if not transaction:
return None
transaction.charge_amount = charge_amount
# Set charge_amount only if approved (status == 0), otherwise set to 0
transaction.charge_amount = charge_amount if status == 0 else 0
transaction.transaction_type = 3 # capture
transaction.status = status
if rejection_reason:
@@ -58,4 +59,4 @@ def update_transaction_for_capture(db: Session, auth_net_transaction_id: str, ch
db.commit()
db.refresh(transaction)
return transaction
return transaction