diff --git a/HISTORY.rst b/HISTORY.rst index ab57d08..27862e8 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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) diff --git a/payments_payu/provider.py b/payments_payu/provider.py index e5b19ee..ed7db84 100644 --- a/payments_payu/provider.py +++ b/payments_payu/provider.py @@ -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": @@ -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}" ) @@ -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: @@ -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: