Skip to content

Payment Gateways

The internet_payment_gateways adapter provides integration with internet payment gateways. Currently supports Parsian Shaparak, an Iranian payment gateway.

Parsian Shaparak

Adapters

Concrete Parsian Shaparak payment gateway adapter implementing payment initiation, verification, and reversal.

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.logger module-attribute

logger = getLogger(__name__)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentRequestDTO

Bases: BaseDTO

DTO for initiating a payment request.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
class PaymentRequestDTO(BaseDTO):
    """DTO for initiating a payment request."""

    amount: int = Field(..., gt=0, description="Transaction amount in IRR")
    order_id: int = Field(..., gt=0, description="Unique order identifier")
    callback_url: HttpUrl = Field(..., description="URL to redirect after payment")
    additional_data: str | None = Field(None, description="Additional transaction data")
    originator: str | None = Field(None, description="Transaction originator")

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentRequestDTO.amount class-attribute instance-attribute

amount: int = Field(
    ..., gt=0, description="Transaction amount in IRR"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentRequestDTO.order_id class-attribute instance-attribute

order_id: int = Field(
    ..., gt=0, description="Unique order identifier"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentRequestDTO.callback_url class-attribute instance-attribute

callback_url: HttpUrl = Field(
    ..., description="URL to redirect after payment"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentRequestDTO.additional_data class-attribute instance-attribute

additional_data: str | None = Field(
    None, description="Additional transaction data"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentRequestDTO.originator class-attribute instance-attribute

originator: str | None = Field(
    None, description="Transaction originator"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentRequestDTO.model_config class-attribute instance-attribute

model_config = ConfigDict(
    extra="ignore",
    validate_default=True,
    from_attributes=True,
    frozen=True,
    str_strip_whitespace=True,
    arbitrary_types_allowed=True,
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentResponseDTO

Bases: BaseDTO

DTO for payment response.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
class PaymentResponseDTO(BaseDTO):
    """DTO for payment response."""

    token: int | None = Field(None, description="Transaction token")
    status: int | None = Field(None, description="Transaction status code")
    message: str | None = Field(None, description="Status message or error description")

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentResponseDTO.token class-attribute instance-attribute

token: int | None = Field(
    None, description="Transaction token"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentResponseDTO.status class-attribute instance-attribute

status: int | None = Field(
    None, description="Transaction status code"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentResponseDTO.message class-attribute instance-attribute

message: str | None = Field(
    None, description="Status message or error description"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.PaymentResponseDTO.model_config class-attribute instance-attribute

model_config = ConfigDict(
    extra="ignore",
    validate_default=True,
    from_attributes=True,
    frozen=True,
    str_strip_whitespace=True,
    arbitrary_types_allowed=True,
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmRequestDTO

Bases: BaseDTO

DTO for confirming a payment.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
class ConfirmRequestDTO(BaseDTO):
    """DTO for confirming a payment."""

    token: int = Field(..., gt=0, description="Transaction token")

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmRequestDTO.token class-attribute instance-attribute

token: int = Field(
    ..., gt=0, description="Transaction token"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmRequestDTO.model_config class-attribute instance-attribute

model_config = ConfigDict(
    extra="ignore",
    validate_default=True,
    from_attributes=True,
    frozen=True,
    str_strip_whitespace=True,
    arbitrary_types_allowed=True,
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmResponseDTO

Bases: BaseDTO

DTO for confirm payment response.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
class ConfirmResponseDTO(BaseDTO):
    """DTO for confirm payment response."""

    status: int | None = Field(None, description="Transaction status code")
    rrn: int | None = Field(None, description="Retrieval Reference Number")
    card_number_masked: str | None = Field(None, description="Masked card number")
    token: int | None = Field(None, description="Transaction token")

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmResponseDTO.status class-attribute instance-attribute

status: int | None = Field(
    None, description="Transaction status code"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmResponseDTO.rrn class-attribute instance-attribute

rrn: int | None = Field(
    None, description="Retrieval Reference Number"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmResponseDTO.card_number_masked class-attribute instance-attribute

card_number_masked: str | None = Field(
    None, description="Masked card number"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmResponseDTO.token class-attribute instance-attribute

token: int | None = Field(
    None, description="Transaction token"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmResponseDTO.model_config class-attribute instance-attribute

model_config = ConfigDict(
    extra="ignore",
    validate_default=True,
    from_attributes=True,
    frozen=True,
    str_strip_whitespace=True,
    arbitrary_types_allowed=True,
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmWithAmountRequestDTO

Bases: BaseDTO

DTO for confirming a payment with amount and order verification.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
class ConfirmWithAmountRequestDTO(BaseDTO):
    """DTO for confirming a payment with amount and order verification."""

    token: int = Field(..., gt=0, description="Transaction token")
    order_id: int = Field(..., gt=0, description="Unique order identifier")
    amount: int = Field(..., gt=0, description="Transaction amount in IRR")

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmWithAmountRequestDTO.token class-attribute instance-attribute

token: int = Field(
    ..., gt=0, description="Transaction token"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmWithAmountRequestDTO.order_id class-attribute instance-attribute

order_id: int = Field(
    ..., gt=0, description="Unique order identifier"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmWithAmountRequestDTO.amount class-attribute instance-attribute

amount: int = Field(
    ..., gt=0, description="Transaction amount in IRR"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmWithAmountRequestDTO.model_config class-attribute instance-attribute

model_config = ConfigDict(
    extra="ignore",
    validate_default=True,
    from_attributes=True,
    frozen=True,
    str_strip_whitespace=True,
    arbitrary_types_allowed=True,
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmWithAmountResponseDTO

Bases: BaseDTO

DTO for confirm payment with amount response.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
class ConfirmWithAmountResponseDTO(BaseDTO):
    """DTO for confirm payment with amount response."""

    status: int | None = Field(None, description="Transaction status code")
    rrn: int | None = Field(None, description="Retrieval Reference Number")
    card_number_masked: str | None = Field(None, description="Masked card number")
    token: int | None = Field(None, description="Transaction token")

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmWithAmountResponseDTO.status class-attribute instance-attribute

status: int | None = Field(
    None, description="Transaction status code"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmWithAmountResponseDTO.rrn class-attribute instance-attribute

rrn: int | None = Field(
    None, description="Retrieval Reference Number"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmWithAmountResponseDTO.card_number_masked class-attribute instance-attribute

card_number_masked: str | None = Field(
    None, description="Masked card number"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmWithAmountResponseDTO.token class-attribute instance-attribute

token: int | None = Field(
    None, description="Transaction token"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ConfirmWithAmountResponseDTO.model_config class-attribute instance-attribute

model_config = ConfigDict(
    extra="ignore",
    validate_default=True,
    from_attributes=True,
    frozen=True,
    str_strip_whitespace=True,
    arbitrary_types_allowed=True,
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ReverseRequestDTO

Bases: BaseDTO

DTO for reversing a payment.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
class ReverseRequestDTO(BaseDTO):
    """DTO for reversing a payment."""

    token: int = Field(..., gt=0, description="Transaction token")

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ReverseRequestDTO.token class-attribute instance-attribute

token: int = Field(
    ..., gt=0, description="Transaction token"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ReverseRequestDTO.model_config class-attribute instance-attribute

model_config = ConfigDict(
    extra="ignore",
    validate_default=True,
    from_attributes=True,
    frozen=True,
    str_strip_whitespace=True,
    arbitrary_types_allowed=True,
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ReverseResponseDTO

Bases: BaseDTO

DTO for reverse payment response.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
class ReverseResponseDTO(BaseDTO):
    """DTO for reverse payment response."""

    status: int | None = Field(None, description="Transaction status code")
    message: str | None = Field(None, description="Status message or error description")
    token: int | None = Field(None, description="Transaction token")

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ReverseResponseDTO.status class-attribute instance-attribute

status: int | None = Field(
    None, description="Transaction status code"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ReverseResponseDTO.message class-attribute instance-attribute

message: str | None = Field(
    None, description="Status message or error description"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ReverseResponseDTO.token class-attribute instance-attribute

token: int | None = Field(
    None, description="Transaction token"
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ReverseResponseDTO.model_config class-attribute instance-attribute

model_config = ConfigDict(
    extra="ignore",
    validate_default=True,
    from_attributes=True,
    frozen=True,
    str_strip_whitespace=True,
    arbitrary_types_allowed=True,
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ParsianShaparakPaymentAdapter

Adapter for interacting with Parsian Shaparak payment gateway services.

Provides methods for initiating payments, confirming transactions, and reversing payments through the Parsian Shaparak payment gateway SOAP services. Supports proxy configuration for environments where direct connections are not possible.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
class ParsianShaparakPaymentAdapter:
    """Adapter for interacting with Parsian Shaparak payment gateway services.

    Provides methods for initiating payments, confirming transactions, and reversing
    payments through the Parsian Shaparak payment gateway SOAP services. Supports
    proxy configuration for environments where direct connections are not possible.
    """

    def __init__(self, config: ParsianShaparakConfig | None = None) -> None:
        """Initialize the adapter with Parsian Shaparak configuration.

        Args:
            config (ParsianShaparakConfig | None): Configuration for Parsian Shaparak services.
                If None, uses global config. Includes optional proxy configuration via
                the PROXIES field.

        Raises:
            ValueError: If LOGIN_ACCOUNT is not a valid string.
        """
        configs = BaseConfig.global_config().PARSIAN_SHAPARAK if config is None else config
        if not configs.LOGIN_ACCOUNT or not isinstance(configs.LOGIN_ACCOUNT, str):
            raise ValueError("LOGIN_ACCOUNT must be a non-empty string")

        self.login_account = configs.LOGIN_ACCOUNT
        transport = None
        if configs.PROXIES:
            session = requests.Session()
            session.proxies = configs.PROXIES
            transport = Transport(session=session)

        # Initialize SOAP clients
        self.sale_client = zeep.Client(wsdl=configs.PAYMENT_WSDL_URL, transport=transport)
        self.confirm_client = zeep.Client(wsdl=configs.CONFIRM_WSDL_URL, transport=transport)
        self.reversal_client = zeep.Client(wsdl=configs.REVERSAL_WSDL_URL, transport=transport)

    def initiate_payment(self, request: PaymentRequestDTO) -> PaymentResponseDTO:
        """Initiate a payment request.

        Args:
            request (PaymentRequestDTO): Payment request data.

        Returns:
            PaymentResponseDTO: Response containing token, status, and message.

        Raises:
            UnavailableError: If a SOAP fault occurs during the request.
            InternalError: If an unexpected error occurs during the request.
        """
        try:
            request_data = {
                "LoginAccount": self.login_account,
                "Amount": request.amount,
                "OrderId": request.order_id,
                "CallBackUrl": str(request.callback_url),
                "AdditionalData": request.additional_data,
                "Originator": request.originator,
            }

            logger.debug(f"Initiating payment: {request_data}")
            response = self.sale_client.service.SalePaymentRequest(requestData=request_data)
            result = PaymentResponseDTO(
                token=response.Token,
                status=response.Status,
                message=response.Message,
            )
            logger.debug(f"Payment response: {result}")
        except Fault as exception:
            raise UnavailableError(resource_type="Parsian Shaparak Sale Service") from exception
        except Exception as exception:
            raise InternalError() from exception
        else:
            return result

    def confirm_payment(self, request: ConfirmRequestDTO) -> ConfirmResponseDTO:
        """Confirm a payment transaction.

        Args:
            request (ConfirmRequestDTO): Confirm request data.

        Returns:
            ConfirmResponseDTO: Response containing status, RRN, card number, and token.

        Raises:
            UnavailableError: If a SOAP fault occurs during the request.
            InternalError: If an unexpected error occurs during the request.
        """
        try:
            request_data = {"LoginAccount": self.login_account, "Token": request.token}

            logger.debug(f"Confirming payment: {request_data}")
            response = self.confirm_client.service.ConfirmPayment(requestData=request_data)
            result = ConfirmResponseDTO(
                status=response.Status,
                rrn=response.RRN,
                card_number_masked=response.CardNumberMasked,
                token=response.Token,
            )
            logger.debug(f"Confirm response: {result}")
        except Fault as exception:
            raise UnavailableError(resource_type="Parsian Shaparak Confirm Service") from exception
        except Exception as exception:
            raise InternalError() from exception
        else:
            return result

    def confirm_payment_with_amount(self, request: ConfirmWithAmountRequestDTO) -> ConfirmWithAmountResponseDTO:
        """Confirm a payment transaction with amount and order verification.

        Args:
            request (ConfirmWithAmountRequestDTO): Confirm with amount request data.

        Returns:
            ConfirmWithAmountResponseDTO: Response containing status, RRN, card number, and token.

        Raises:
            UnavailableError: If a SOAP fault occurs during the request.
            InternalError: If an unexpected error occurs during the request.
        """
        try:
            request_data = {
                "LoginAccount": self.login_account,
                "Token": request.token,
                "OrderId": request.order_id,
                "Amount": request.amount,
            }

            logger.debug(f"Confirming payment with amount: {request_data}")
            response = self.confirm_client.service.ConfirmPaymentWithAmount(requestData=request_data)
            result = ConfirmWithAmountResponseDTO(
                status=response.Status,
                rrn=response.RRN,
                card_number_masked=response.CardNumberMasked,
                token=response.Token,
            )
            logger.debug(f"Confirm with amount response: {result}")
        except Fault as exception:
            raise UnavailableError(resource_type="Parsian Shaparak Confirm Service") from exception
        except Exception as exception:
            raise InternalError() from exception
        else:
            return result

    def reverse_payment(self, request: ReverseRequestDTO) -> ReverseResponseDTO:
        """Request a reversal of a confirmed transaction.

        Args:
            request (ReverseRequestDTO): Reverse request data.

        Returns:
            ReverseResponseDTO: Response containing status, message, and token.

        Raises:
            UnavailableError: If a SOAP fault occurs during the request.
            InternalError: If an unexpected error occurs during the request.
        """
        try:
            request_data = {"LoginAccount": self.login_account, "Token": request.token}

            logger.debug(f"Reversing payment: {request_data}")
            response = self.reversal_client.service.ReversalRequest(requestData=request_data)
            result = ReverseResponseDTO(
                status=response.Status,
                message=response.Message,
                token=response.Token,
            )
            logger.debug(f"Reversal response: {result}")
        except Fault as exception:
            raise UnavailableError(resource_type="Parsian Shaparak Reversal Service") from exception
        except Exception as exception:
            raise InternalError() from exception
        else:
            return result

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ParsianShaparakPaymentAdapter.login_account instance-attribute

login_account = LOGIN_ACCOUNT

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ParsianShaparakPaymentAdapter.sale_client instance-attribute

sale_client = Client(
    wsdl=PAYMENT_WSDL_URL, transport=transport
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ParsianShaparakPaymentAdapter.confirm_client instance-attribute

confirm_client = Client(
    wsdl=CONFIRM_WSDL_URL, transport=transport
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ParsianShaparakPaymentAdapter.reversal_client instance-attribute

reversal_client = Client(
    wsdl=REVERSAL_WSDL_URL, transport=transport
)

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ParsianShaparakPaymentAdapter.initiate_payment

initiate_payment(
    request: PaymentRequestDTO,
) -> PaymentResponseDTO

Initiate a payment request.

Parameters:

Name Type Description Default
request PaymentRequestDTO

Payment request data.

required

Returns:

Name Type Description
PaymentResponseDTO PaymentResponseDTO

Response containing token, status, and message.

Raises:

Type Description
UnavailableError

If a SOAP fault occurs during the request.

InternalError

If an unexpected error occurs during the request.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
def initiate_payment(self, request: PaymentRequestDTO) -> PaymentResponseDTO:
    """Initiate a payment request.

    Args:
        request (PaymentRequestDTO): Payment request data.

    Returns:
        PaymentResponseDTO: Response containing token, status, and message.

    Raises:
        UnavailableError: If a SOAP fault occurs during the request.
        InternalError: If an unexpected error occurs during the request.
    """
    try:
        request_data = {
            "LoginAccount": self.login_account,
            "Amount": request.amount,
            "OrderId": request.order_id,
            "CallBackUrl": str(request.callback_url),
            "AdditionalData": request.additional_data,
            "Originator": request.originator,
        }

        logger.debug(f"Initiating payment: {request_data}")
        response = self.sale_client.service.SalePaymentRequest(requestData=request_data)
        result = PaymentResponseDTO(
            token=response.Token,
            status=response.Status,
            message=response.Message,
        )
        logger.debug(f"Payment response: {result}")
    except Fault as exception:
        raise UnavailableError(resource_type="Parsian Shaparak Sale Service") from exception
    except Exception as exception:
        raise InternalError() from exception
    else:
        return result

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ParsianShaparakPaymentAdapter.confirm_payment

confirm_payment(
    request: ConfirmRequestDTO,
) -> ConfirmResponseDTO

Confirm a payment transaction.

Parameters:

Name Type Description Default
request ConfirmRequestDTO

Confirm request data.

required

Returns:

Name Type Description
ConfirmResponseDTO ConfirmResponseDTO

Response containing status, RRN, card number, and token.

Raises:

Type Description
UnavailableError

If a SOAP fault occurs during the request.

InternalError

If an unexpected error occurs during the request.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
def confirm_payment(self, request: ConfirmRequestDTO) -> ConfirmResponseDTO:
    """Confirm a payment transaction.

    Args:
        request (ConfirmRequestDTO): Confirm request data.

    Returns:
        ConfirmResponseDTO: Response containing status, RRN, card number, and token.

    Raises:
        UnavailableError: If a SOAP fault occurs during the request.
        InternalError: If an unexpected error occurs during the request.
    """
    try:
        request_data = {"LoginAccount": self.login_account, "Token": request.token}

        logger.debug(f"Confirming payment: {request_data}")
        response = self.confirm_client.service.ConfirmPayment(requestData=request_data)
        result = ConfirmResponseDTO(
            status=response.Status,
            rrn=response.RRN,
            card_number_masked=response.CardNumberMasked,
            token=response.Token,
        )
        logger.debug(f"Confirm response: {result}")
    except Fault as exception:
        raise UnavailableError(resource_type="Parsian Shaparak Confirm Service") from exception
    except Exception as exception:
        raise InternalError() from exception
    else:
        return result

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ParsianShaparakPaymentAdapter.confirm_payment_with_amount

confirm_payment_with_amount(
    request: ConfirmWithAmountRequestDTO,
) -> ConfirmWithAmountResponseDTO

Confirm a payment transaction with amount and order verification.

Parameters:

Name Type Description Default
request ConfirmWithAmountRequestDTO

Confirm with amount request data.

required

Returns:

Name Type Description
ConfirmWithAmountResponseDTO ConfirmWithAmountResponseDTO

Response containing status, RRN, card number, and token.

Raises:

Type Description
UnavailableError

If a SOAP fault occurs during the request.

InternalError

If an unexpected error occurs during the request.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
def confirm_payment_with_amount(self, request: ConfirmWithAmountRequestDTO) -> ConfirmWithAmountResponseDTO:
    """Confirm a payment transaction with amount and order verification.

    Args:
        request (ConfirmWithAmountRequestDTO): Confirm with amount request data.

    Returns:
        ConfirmWithAmountResponseDTO: Response containing status, RRN, card number, and token.

    Raises:
        UnavailableError: If a SOAP fault occurs during the request.
        InternalError: If an unexpected error occurs during the request.
    """
    try:
        request_data = {
            "LoginAccount": self.login_account,
            "Token": request.token,
            "OrderId": request.order_id,
            "Amount": request.amount,
        }

        logger.debug(f"Confirming payment with amount: {request_data}")
        response = self.confirm_client.service.ConfirmPaymentWithAmount(requestData=request_data)
        result = ConfirmWithAmountResponseDTO(
            status=response.Status,
            rrn=response.RRN,
            card_number_masked=response.CardNumberMasked,
            token=response.Token,
        )
        logger.debug(f"Confirm with amount response: {result}")
    except Fault as exception:
        raise UnavailableError(resource_type="Parsian Shaparak Confirm Service") from exception
    except Exception as exception:
        raise InternalError() from exception
    else:
        return result

archipy.adapters.internet_payment_gateways.ir.parsian.adapters.ParsianShaparakPaymentAdapter.reverse_payment

reverse_payment(
    request: ReverseRequestDTO,
) -> ReverseResponseDTO

Request a reversal of a confirmed transaction.

Parameters:

Name Type Description Default
request ReverseRequestDTO

Reverse request data.

required

Returns:

Name Type Description
ReverseResponseDTO ReverseResponseDTO

Response containing status, message, and token.

Raises:

Type Description
UnavailableError

If a SOAP fault occurs during the request.

InternalError

If an unexpected error occurs during the request.

Source code in archipy/adapters/internet_payment_gateways/ir/parsian/adapters.py
def reverse_payment(self, request: ReverseRequestDTO) -> ReverseResponseDTO:
    """Request a reversal of a confirmed transaction.

    Args:
        request (ReverseRequestDTO): Reverse request data.

    Returns:
        ReverseResponseDTO: Response containing status, message, and token.

    Raises:
        UnavailableError: If a SOAP fault occurs during the request.
        InternalError: If an unexpected error occurs during the request.
    """
    try:
        request_data = {"LoginAccount": self.login_account, "Token": request.token}

        logger.debug(f"Reversing payment: {request_data}")
        response = self.reversal_client.service.ReversalRequest(requestData=request_data)
        result = ReverseResponseDTO(
            status=response.Status,
            message=response.Message,
            token=response.Token,
        )
        logger.debug(f"Reversal response: {result}")
    except Fault as exception:
        raise UnavailableError(resource_type="Parsian Shaparak Reversal Service") from exception
    except Exception as exception:
        raise InternalError() from exception
    else:
        return result

options: show_root_toc_entry: false heading_level: 3