"""visaacceptancemergedspec.

This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
"""

# ruff: noqa: D410, E501, E101, D206
from apimatic_core.authentication.multiple.and_auth_group import (
    And,
)
from apimatic_core.authentication.multiple.single_auth import (
    Single,
)
from apimatic_core.request_builder import RequestBuilder
from apimatic_core.response_handler import ResponseHandler
from apimatic_core.types.parameter import Parameter

from visaacceptancemergedspec.api_helper import (
    APIHelper,
)
from visaacceptancemergedspec.apis.base_api import (
    BaseApi,
)
from visaacceptancemergedspec.configuration import (
    Server,
)
from visaacceptancemergedspec.exceptions.api_exception import (
    ApiException,
)
from visaacceptancemergedspec.exceptions.pts_v_2_incremental_authorization_patch_400_response_1_exception import (  # noqa: E501
    PtsV2IncrementalAuthorizationPatch400Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_incremental_authorization_patch_502_response_1_exception import (  # noqa: E501
    PtsV2IncrementalAuthorizationPatch502Response1Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_payments_post_400_response_11_exception import (  # noqa: E501
    PtsV2PaymentsPost400Response11Exception,
)
from visaacceptancemergedspec.exceptions.pts_v_2_payments_post_502_response_11_exception import (  # noqa: E501
    PtsV2PaymentsPost502Response11Exception,
)
from visaacceptancemergedspec.http.http_method_enum import (
    HttpMethodEnum,
)
from visaacceptancemergedspec.models.pts_v_2_incremental_authorization_patch_201_response import (  # noqa: E501
    PtsV2IncrementalAuthorizationPatch201Response,
)
from visaacceptancemergedspec.models.pts_v_2_payments_order_post_201_response import (
    PtsV2PaymentsOrderPost201Response,
)
from visaacceptancemergedspec.models.pts_v_2_payments_post_201_response_1 import (
    PtsV2PaymentsPost201Response1,
)
from visaacceptancemergedspec.models.pts_v_2_payments_post_201_response_2 import (
    PtsV2PaymentsPost201Response2,
)


class PaymentsApi(BaseApi):
    """A Controller to access Endpoints in the visaacceptancemergedspec API."""

    def __init__(self, config):
        """Initialize PaymentsApi object."""
        super(PaymentsApi, self).__init__(config)

    def create_payment(self,
                       body):
        """Perform a POST request to /pts/v2/payments.

        A payment authorizes the amount for the transaction. There are a number of
        supported payment features, such as E-commerce and Card Present - Credit
        Card/Debit Card, Echeck, e-Wallets, Level II/III Data, etc..
        A payment response includes the status of the request. It also includes
        processor-specific information when the request is successful and errors if
        unsuccessful. See the [Payments Developer Guides Page](
        Authorization can be requested with Capture, Decision Manager, Payer
        Authentication(3ds), and Token Creation.

        Args:
            body (CreatePaymentRequest): The request body parameter.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Successful response.

        Raises:
            ApiException: When an error occurs while fetching the data from the
                remote API. This exception includes the HTTP Response code, an error
                message, and the HTTP body that was received in the request.

        """
        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path("/pts/v2/payments")
            .http_method(HttpMethodEnum.POST)
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json;charset=utf-8"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .is_api_response(True)
            .local_error("400", "Invalid request.", ApiException)
            .local_error("502",
                "Unexpected system error or system timeout.",
                ApiException),
        ).execute()

    def increment_auth(self,
                       id,
                       body):
        """Perform a PATCH request to /pts/v2/payments/{id}.

        Use this service to authorize additional charges in a lodging or autorental
        transaction. Include the ID returned from the original authorization in the
        PATCH request to add additional charges to that authorization.

        Args:
            id (str): The ID returned from the original authorization request.
            body (IncrementAuthRequest): The request body parameter.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Successful response.

        Raises:
            ApiException: When an error occurs while fetching the data from the
                remote API. This exception includes the HTTP Response code, an error
                message, and the HTTP body that was received in the request.

        """
        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path("/pts/v2/payments/{id}")
            .http_method(HttpMethodEnum.PATCH)
            .template_param(Parameter()
                .key("id")
                .value(id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PtsV2IncrementalAuthorizationPatch201Response.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2IncrementalAuthorizationPatch400Response1Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2IncrementalAuthorizationPatch502Response1Exception),
        ).execute()

    def refresh_payment_status(self,
                               id,
                               body):
        """Perform a POST request to /pts/v2/refresh-payment-status/{id}.

        Checks and updates the payment status

        Args:
            id (str): The payment id whose status needs to be checked and updated.
            body (RefreshPaymentStatusRequest): The request body parameter.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Successful response.

        Raises:
            ApiException: When an error occurs while fetching the data from the
                remote API. This exception includes the HTTP Response code, an error
                message, and the HTTP body that was received in the request.

        """
        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path("/pts/v2/refresh-payment-status/{id}")
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                .key("id")
                .value(id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PtsV2PaymentsPost201Response1.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2PaymentsPost400Response11Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2PaymentsPost502Response11Exception),
        ).execute()

    def create_order_request(self,
                             id,
                             body):
        """Perform a POST request to /pts/v2/payment-references/{id}/intents.

        Create a Payment Order Request

        Args:
            id (str): Request identifier number for the order request.
            body (OrderPaymentRequest): The request body parameter.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Successful response.

        Raises:
            ApiException: When an error occurs while fetching the data from the
                remote API. This exception includes the HTTP Response code, an error
                message, and the HTTP body that was received in the request.

        """
        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path("/pts/v2/payment-references/{id}/intents")
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                .key("id")
                .value(id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PtsV2PaymentsOrderPost201Response.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2PaymentsPost400Response11Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2PaymentsPost502Response11Exception),
        ).execute()

    def create_session_request(self,
                               body):
        """Perform a POST request to /pts/v2/payment-references.

        Create Alternative Payments Sessions Request

        Args:
            body (CreateSessionReq): The request body parameter.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Successful response.

        Raises:
            ApiException: When an error occurs while fetching the data from the
                remote API. This exception includes the HTTP Response code, an error
                message, and the HTTP body that was received in the request.

        """
        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path("/pts/v2/payment-references")
            .http_method(HttpMethodEnum.POST)
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PtsV2PaymentsPost201Response2.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2PaymentsPost400Response11Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2PaymentsPost502Response11Exception),
        ).execute()

    def update_session_req(self,
                           id,
                           body):
        """Perform a PATCH request to /pts/v2/payment-references/{id}.

        Update Alternative Payments Sessions Request

        Args:
            id (str): The payment ID. This ID is returned from a previous payment
                request.
            body (CreateSessionRequest): The request body parameter.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Successful response.

        Raises:
            ApiException: When an error occurs while fetching the data from the
                remote API. This exception includes the HTTP Response code, an error
                message, and the HTTP body that was received in the request.

        """
        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path("/pts/v2/payment-references/{id}")
            .http_method(HttpMethodEnum.PATCH)
            .template_param(Parameter()
                .key("id")
                .value(id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .body_serializer(APIHelper.json_serialize)
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(PtsV2PaymentsPost201Response2.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Invalid request.",
                PtsV2PaymentsPost400Response11Exception)
            .local_error("502",
                "Unexpected system error or system timeout.",
                PtsV2PaymentsPost502Response11Exception),
        ).execute()
