Updated charge close to working
This commit is contained in:
17
app/crud.py
17
app/crud.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user