Skip to content

Commit

Permalink
make PayuProvider.refund raise PayuApiError if an unexpected response…
Browse files Browse the repository at this point in the history
… is received
  • Loading branch information
radekholy24 committed Apr 7, 2024
1 parent 838e06c commit d2f4e90
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Unreleased
**********
* fix backward compatibility by making PayuProvider's get_refund_description argument optional
* make PayuProvider.refund fail if get_refund_description is not provided
* make PayuProvider.refund raise PayuApiError if an unexpected response is received
* deprecate the default value of get_refund_description; set it to a callable instead

1.3.1 (2024-03-19)
Expand Down
8 changes: 4 additions & 4 deletions payments_payu/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def refund(self, payment, amount=None):
response_status = dict(response["status"])
response_status_code = response_status["statusCode"]
except Exception:
raise ValueError(
raise PayuApiError(
f"invalid response to refund {refund_id or '???'} of payment {payment.id}: {response}"
)
if response_status_code != "SUCCESS":
Expand All @@ -669,7 +669,7 @@ def refund(self, payment, amount=None):
f"statusDesc={response_status.get('statusDesc', '???')}"
)
if refund_id is None:
raise ValueError(
raise PayuApiError(
f"invalid response to refund of payment {payment.id}: {response}"
)

Expand All @@ -679,7 +679,7 @@ def refund(self, payment, amount=None):
refund_currency = refund["currencyCode"]
refund_amount = dequantize_price(refund["amount"], refund_currency)
except Exception:
raise ValueError(
raise PayuApiError(
f"invalid response to refund {refund_id} of payment {payment.id}: {response}"
)
if refund_order_id != payment.transaction_id:
Expand All @@ -690,7 +690,7 @@ def refund(self, payment, amount=None):
if refund_status == "CANCELED":
raise ValueError(f"refund {refund_id} of payment {payment.id} canceled")
elif refund_status not in {"PENDING", "FINALIZED"}:
raise ValueError(
raise PayuApiError(
f"invalid status of refund {refund_id} of payment {payment.id}"
)
if refund_currency != payment.currency:
Expand Down

0 comments on commit d2f4e90

Please sign in to comment.