Source code for worldline.connect.sdk.v1.declined_refund_exception
#
# This class was auto-generated from the API references found at
# https://apireference.connect.worldline-solutions.com/
#
from typing import Optional
from .declined_transaction_exception import DeclinedTransactionException
from worldline.connect.sdk.v1.domain.refund_error_response import RefundErrorResponse
from worldline.connect.sdk.v1.domain.refund_result import RefundResult
[docs]
class DeclinedRefundException(DeclinedTransactionException):
"""
Represents an error response from a refund call.
"""
def __init__(self, status_code: int, response_body: str, response: Optional[RefundErrorResponse]):
if response is not None:
super(DeclinedRefundException, self).__init__(status_code, response_body, response.error_id, response.errors,
DeclinedRefundException.__create_message(response))
else:
super(DeclinedRefundException, self).__init__(status_code, response_body, None, None,
DeclinedRefundException.__create_message(response))
self.__response = response
@staticmethod
def __create_message(response: Optional[RefundErrorResponse]) -> str:
if response is not None:
refund_result = response.refund_result
else:
refund_result = None
if refund_result is not None:
return "declined refund '%s' with status '%s'" % (refund_result.id, refund_result.status)
else:
return "the Worldline Global Collect platform returned a declined refund response"
@property
def refund_result(self) -> Optional[RefundResult]:
"""
:return: The result of creating a refund if available, otherwise None.
"""
if self.__response is None:
return None
else:
return self.__response.refund_result