"""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.delete_payment_instrument_exception_1_exception import (  # noqa: E501
    DeletePaymentInstrumentException1Exception,
)
from visaacceptancemergedspec.exceptions.delete_payment_instrument_exception_21_exception import (  # noqa: E501
    DeletePaymentInstrumentException21Exception,
)
from visaacceptancemergedspec.exceptions.delete_payment_instrument_exception_31_exception import (  # noqa: E501
    DeletePaymentInstrumentException31Exception,
)
from visaacceptancemergedspec.exceptions.delete_payment_instrument_exception_51_exception import (  # noqa: E501
    DeletePaymentInstrumentException51Exception,
)
from visaacceptancemergedspec.exceptions.get_payment_instrument_exception_1_exception import (  # noqa: E501
    GetPaymentInstrumentException1Exception,
)
from visaacceptancemergedspec.exceptions.get_payment_instrument_exception_21_exception import (  # noqa: E501
    GetPaymentInstrumentException21Exception,
)
from visaacceptancemergedspec.exceptions.get_payment_instrument_exception_31_exception import (  # noqa: E501
    GetPaymentInstrumentException31Exception,
)
from visaacceptancemergedspec.exceptions.get_payment_instrument_exception_41_exception import (  # noqa: E501
    GetPaymentInstrumentException41Exception,
)
from visaacceptancemergedspec.exceptions.get_payment_instrument_exception_61_exception import (  # noqa: E501
    GetPaymentInstrumentException61Exception,
)
from visaacceptancemergedspec.exceptions.patch_payment_instrument_exception_1_exception import (  # noqa: E501
    PatchPaymentInstrumentException1Exception,
)
from visaacceptancemergedspec.exceptions.patch_payment_instrument_exception_21_exception import (  # noqa: E501
    PatchPaymentInstrumentException21Exception,
)
from visaacceptancemergedspec.exceptions.patch_payment_instrument_exception_31_exception import (  # noqa: E501
    PatchPaymentInstrumentException31Exception,
)
from visaacceptancemergedspec.exceptions.patch_payment_instrument_exception_41_exception import (  # noqa: E501
    PatchPaymentInstrumentException41Exception,
)
from visaacceptancemergedspec.exceptions.patch_payment_instrument_exception_51_exception import (  # noqa: E501
    PatchPaymentInstrumentException51Exception,
)
from visaacceptancemergedspec.exceptions.patch_payment_instrument_exception_71_exception import (  # noqa: E501
    PatchPaymentInstrumentException71Exception,
)
from visaacceptancemergedspec.exceptions.post_payment_instrument_exception_1_exception import (  # noqa: E501
    PostPaymentInstrumentException1Exception,
)
from visaacceptancemergedspec.exceptions.post_payment_instrument_exception_21_exception import (  # noqa: E501
    PostPaymentInstrumentException21Exception,
)
from visaacceptancemergedspec.exceptions.post_payment_instrument_exception_31_exception import (  # noqa: E501
    PostPaymentInstrumentException31Exception,
)
from visaacceptancemergedspec.exceptions.post_payment_instrument_exception_41_exception import (  # noqa: E501
    PostPaymentInstrumentException41Exception,
)
from visaacceptancemergedspec.exceptions.post_payment_instrument_exception_51_exception import (  # noqa: E501
    PostPaymentInstrumentException51Exception,
)
from visaacceptancemergedspec.http.http_method_enum import (
    HttpMethodEnum,
)
from visaacceptancemergedspec.models.get_payment_instrument_response import (
    GetPaymentInstrumentResponse,
)
from visaacceptancemergedspec.models.patch_payment_instrument_response import (
    PatchPaymentInstrumentResponse,
)
from visaacceptancemergedspec.models.post_payment_instrument_response import (
    PostPaymentInstrumentResponse,
)


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

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

    def post_payment_instrument(self,
                                body,
                                profile_id=None,
                                retrieve_bin_details=None):
        """Perform a POST request to /tms/v1/paymentinstruments.

        |  |  |  |
        | --- | --- | --- |
        |**Standalone Payment Instruments**<br>A Payment Instrument represents
        tokenized payment information such as expiration date, billing address & card
        type.<br>A Payment Instrument token does not store the card number. A Payment
        Instrument is associated with an [Instrument
        Identifier](#token-management_instrument-identifier_create-an-instrument-ident
        ifier) that represents either a payment card number, or in the case of an ACH
        bank account, the routing and account number.<br>**Standalone Payment
        Instruments do not belong to a
        [Customer](#token-management_customer_create-a-customer).**<br><br>**Creating
        a Payment Instrument**<br>It is recommended you [create a Payment Instrument
        via a Payment
        Authorization](#payments_payments_process-a-payment_samplerequests-dropdown_au
        thorization-with-token-create_authorization-with-customer-token-creation_livec
        onsole-tab-request-body), this can be for a zero amount.<br>In Europe: You
        should perform Payer Authentication alongside the
        Authorization.|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|**Payment Network
        Tokens**<br>Network tokens perform better than regular card numbers and they
        are not necessarily invalidated when a cardholder loses their card, or it
        expires.<br>A Payment Network Token will be automatically created and used in
        future payments if you are enabled for the service.<br>A Payment Network
        Token can also be [provisioned for an existing Instrument
        Identifier](#token-management_instrument-identifier_enroll-an-instrument-ident
        ifier-for-payment-network-token).<br>For more information about Payment
        Network Tokens see the Developer Guide.<br><br>**Payments with Payment
        Instruments**<br>To perform a payment with a particular Payment Instrument
        specify the [Payment Instrument in the payment
        request](#payments_payments_process-a-payment_samplerequests-dropdown_authoriz
        ation-using-tokens_authorization-with-customer-payment-instrument-and-shipping
        -address-token-id_liveconsole-tab-request-body).

        Args:
            body (PostPaymentInstrumentRequest): The request body parameter.
            profile_id (str, optional): The Id of a profile containing user specific
                TMS configuration.
            retrieve_bin_details (bool, optional): Retrieve the Bin Details of PAN or
                network token

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Returns an existing
                Payment Instrument associated with the supplied Id.

        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("/tms/v1/paymentinstruments")
            .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("profile-id")
                .value(profile_id))
            .query_param(Parameter()
                .key("retrieveBinDetails")
                .value(retrieve_bin_details))
            .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(PostPaymentInstrumentResponse.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Bad Request: e.g. A required header value could be missing.",
                PostPaymentInstrumentException1Exception)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                PostPaymentInstrumentException21Exception)
            .local_error("409",
                "Conflict. The token is linked to a Payment Instrument.",
                PostPaymentInstrumentException31Exception)
            .local_error("424",
                "Failed Dependency: e.g. The profile represented by the profile-id ma"
                "y not exist or the profile-id was entered incorrectly.",
                PostPaymentInstrumentException41Exception)
            .local_error("500",
                "Unexpected error.",
                PostPaymentInstrumentException51Exception),
        ).execute()

    def get_payment_instrument(self,
                               payment_instrument_id,
                               profile_id=None,
                               retrieve_bin_details=None):
        """Perform a GET request to
        /tms/v1/paymentinstruments/{paymentInstrumentId}.

        |  |  |  |
        | --- | --- | --- |
        |**Standalone Payment Instruments**<br>A Payment Instrument represents
        tokenized payment information such as expiration date, billing address & card
        type.<br>A Payment Instrument token does not store the card number. A Payment
        Instrument is associated with an [Instrument
        Identifier](#token-management_instrument-identifier_create-an-instrument-ident
        ifier) that represents either a payment card number, or in the case of an ACH
        bank account, the routing and account number.<br>**Standalone Payment
        Instruments do not belong to a
        [Customer](#token-management_customer_create-a-customer).**|&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;|**Retrieving a Payment Instrument**<br>Your system can use
        this API to retrieve an existing Payment Instrument.<br>To perform a payment
        with a particular Payment Instrument simply specify the [Payment Instrument
        Id in the payments
        request](#payments_payments_process-a-payment_samplerequests-dropdown_authoriz
        ation-using-tokens_authorization-with-customer-payment-instrument-and-shipping
        -address-token-id_liveconsole-tab-request-body).

        Args:
            payment_instrument_id (str): The Id of a payment instrument.
            profile_id (str, optional): The Id of a profile containing user specific
                TMS configuration.
            retrieve_bin_details (bool, optional): Retrieve the Bin Details of PAN or
                network token

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Returns an existing
                Payment Instrument associated with the supplied Id.

        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("/tms/v1/paymentinstruments/{paymentInstrumentId}")
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                .key("paymentInstrumentId")
                .value(payment_instrument_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("profile-id")
                .value(profile_id))
            .query_param(Parameter()
                .key("retrieveBinDetails")
                .value(retrieve_bin_details))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(GetPaymentInstrumentResponse.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Bad Request: e.g. A required header value could be missing.",
                GetPaymentInstrumentException1Exception)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                GetPaymentInstrumentException21Exception)
            .local_error("404",
                "Token Not Found. The Id may not exist or was entered incorrectly.",
                GetPaymentInstrumentException31Exception)
            .local_error("410",
                "Token Not Available. The token has been deleted.",
                GetPaymentInstrumentException41Exception)
            .local_error("424",
                "Failed Dependency: e.g. The profile represented by the profile-id ma"
                "y not exist or the profile-id was entered incorrectly.",
                GetPaymentInstrumentException31Exception)
            .local_error("500",
                "Unexpected error.",
                GetPaymentInstrumentException61Exception),
        ).execute()

    def patch_payment_instrument(self,
                                 payment_instrument_id,
                                 body,
                                 profile_id=None,
                                 retrieve_bin_details=None,
                                 if_match=None):
        """Perform a PATCH request to
        /tms/v1/paymentinstruments/{paymentInstrumentId}.

        |  |  |  |
        | --- | --- | --- |
        |**Standalone Payment Instruments**<br>A Payment Instrument represents
        tokenized payment information such as expiration date, billing address & card
        type.<br>A Payment Instrument token does not store the card number. A Payment
        Instrument is associated with an [Instrument
        Identifier](#token-management_instrument-identifier_create-an-instrument-ident
        ifier) that represents either a payment card number, or in the case of an ACH
        bank account, the routing and account number.<br>**Standalone Payment
        Instruments do not belong to a
        [Customer](#token-management_customer_create-a-customer).**|&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;|**Updating a Payment Instrument**<br>Your system can use
        this API to update an existing Payment Instrument.

        Args:
            payment_instrument_id (str): The Id of a payment instrument.
            body (PatchPaymentInstrumentRequest): The request body parameter.
            profile_id (str, optional): The Id of a profile containing user specific
                TMS configuration.
            retrieve_bin_details (bool, optional): Retrieve the Bin Details of PAN or
                network token
            if_match (str, optional): Contains an ETag value from a GET request to
                make the request conditional.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. Returns an existing
                Payment Instrument associated with the supplied Id.

        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("/tms/v1/paymentinstruments/{paymentInstrumentId}")
            .http_method(HttpMethodEnum.PATCH)
            .template_param(Parameter()
                .key("paymentInstrumentId")
                .value(payment_instrument_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("Content-Type")
                .value("application/json;charset=utf-8"))
            .body_param(Parameter()
                .value(body)
                .is_required(True))
            .header_param(Parameter()
                .key("profile-id")
                .value(profile_id))
            .query_param(Parameter()
                .key("retrieveBinDetails")
                .value(retrieve_bin_details))
            .header_param(Parameter()
                .key("if-match")
                .value(if_match))
            .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(PatchPaymentInstrumentResponse.from_dictionary)
            .is_api_response(True)
            .local_error("400",
                "Bad Request: e.g. A required header value could be missing.",
                PatchPaymentInstrumentException1Exception)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                PatchPaymentInstrumentException21Exception)
            .local_error("404",
                "Token Not Found. The Id may not exist or was entered incorrectly.",
                PatchPaymentInstrumentException31Exception)
            .local_error("410",
                "Token Not Available. The token has been deleted.",
                PatchPaymentInstrumentException41Exception)
            .local_error("412",
                "Precondition Failed: The If-Match request header value does not matc"
                "h the current resources ETag",
                PatchPaymentInstrumentException51Exception)
            .local_error("424",
                "Failed Dependency: e.g. The profile represented by the profile-id ma"
                "y not exist or the profile-id was entered incorrectly.",
                PatchPaymentInstrumentException31Exception)
            .local_error("500",
                "Unexpected error.",
                PatchPaymentInstrumentException71Exception),
        ).execute()

    def delete_payment_instrument(self,
                                  payment_instrument_id,
                                  profile_id=None):
        """Perform a DELETE request to
        /tms/v1/paymentinstruments/{paymentInstrumentId}.

        |  |  |  |
        | --- | --- | --- |
        |**Standalone Payment Instruments**<br>A Payment Instrument represents
        tokenized payment information such as expiration date, billing address & card
        type.<br>A Payment Instrument token does not store the card number. A Payment
        Instrument is associated with an [Instrument
        Identifier](#token-management_instrument-identifier_create-an-instrument-ident
        ifier) that represents either a payment card number, or in the case of an ACH
        bank account, the routing and account number.<br>**Standalone Payment
        Instruments do not belong to a
        [Customer](#token-management_customer_create-a-customer).**|&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;|**Deleting a Payment Instrument**<br>Your system can use
        this API to delete an existing Payment Instrument.<br>Any Instrument
        Identifiers representing the card number will also be deleted if they are not
        associated with any other Payment Instruments.

        Args:
            payment_instrument_id (str): The Id of a payment instrument.
            profile_id (str, optional): The Id of a profile containing user specific
                TMS configuration.

        Returns:
            ApiResponse: An object with the response value as well as other useful
                information such as status codes and headers. The request is
                fulfilled but does not need to return a body

        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("/tms/v1/paymentinstruments/{paymentInstrumentId}")
            .http_method(HttpMethodEnum.DELETE)
            .template_param(Parameter()
                .key("paymentInstrumentId")
                .value(payment_instrument_id)
                .is_required(True)
                .should_encode(True))
            .header_param(Parameter()
                .key("profile-id")
                .value(profile_id))
            .header_param(Parameter()
                .key("accept")
                .value("application/json"))
            .auth(And(Single("BearerAuth"), Single("Accept"))),
        ).response(
            ResponseHandler()
            .is_api_response(True)
            .local_error("403",
                "Forbidden: e.g. The profile might not have permission to perform the"
                " operation.",
                DeletePaymentInstrumentException1Exception)
            .local_error("404",
                "Token Not Found. The Id may not exist or was entered incorrectly.",
                DeletePaymentInstrumentException21Exception)
            .local_error("410",
                "Token Not Available. The token has been deleted.",
                DeletePaymentInstrumentException31Exception)
            .local_error("424",
                "Failed Dependency: e.g. The profile represented by the profile-id ma"
                "y not exist or the profile-id was entered incorrectly.",
                DeletePaymentInstrumentException21Exception)
            .local_error("500",
                "Unexpected error.",
                DeletePaymentInstrumentException51Exception),
        ).execute()
