Skip to content

Commit

Permalink
Add try/except around transaction_id block
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie committed May 29, 2024
1 parent 5af57ed commit 844e17f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions paypal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,16 @@ def capture_paypal_order(
# Get transaction ID from PayPal response
# paypal_response.purchase_units[0].payments.captures[0].id
# but make sure to get it safely since there may be null or undefined values
transaction_id = (
paypal_response.get("purchase_units", [{}])[0]
.get("payments", {})
.get("captures", [{}])[0]
.get("id", "")
)

try:
transaction_id = (
paypal_response.get("purchase_units", [{}])[0]
.get("payments", {})
.get("captures", [{}])[0]
.get("id", "")
)
except (IndexError, KeyError, TypeError):
transaction_id = ""

# Finally, update the order in our database
# with the PayPal payment ID and mark it as paid
Expand Down

0 comments on commit 844e17f

Please sign in to comment.