Skip to content

Queries

components.payment_gateway.subcomponents.cards.business_logic.queries.card_holder_queries

CardHolderQueries

This class contains all the queries related to card holders.

get_card_holder

get_card_holder(session, /, id)

Get a card holder entity from its ID.

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_holder_queries.py
def get_card_holder(
    self,
    session: Session,
    /,
    id: CardHolderId,
) -> CardHolder:
    """
    Get a card holder entity from its ID.
    """

    with raise_if_card_holder_not_found(id):
        card_holder = CardHolderModelBroker.get_card_holder(session, id=id)

    raise_on_terminated_card_holder(card_holder)

    return CardHolder(
        id=CardHolderId(card_holder.id),
        provider=card_holder.provider,
        external_id=card_holder.external_id,
        first_name=card_holder.first_name,
        last_name=card_holder.last_name,
        display_name=card_holder.display_name,
        short_name=card_holder.short_name,
    )

components.payment_gateway.subcomponents.cards.business_logic.queries.card_order_queries

CardOrderQueries

This class contains all the queries related to card orders.

get_card_order

get_card_order(session, /, card_id)

Get the card order info for a card.

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_order_queries.py
def get_card_order(
    self,
    session: Session,
    /,
    card_id: CardId,
) -> CardOrder:
    """
    Get the card order info for a card.
    """

    with raise_if_card_order_not_found_for_card_id(card_id):
        card_order = CardOrderModelBroker.get_card_order_for_card(
            session, card_id=card_id
        )

    return CardOrder(
        card_id=CardId(card_order.card_id),
        delivery_status=card_order.delivery_status,
        shipping_method=card_order.shipping_method,
        tracking_number=card_order.tracking_number,
    )

components.payment_gateway.subcomponents.cards.business_logic.queries.card_provisioning_queries

CardProvisioningQueries

This class contains all the queries related to card provisioning.

get_all_card_provisioning

get_all_card_provisioning(session, /, card_id)
Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_provisioning_queries.py
def get_all_card_provisioning(
    self,
    session: Session,
    /,
    card_id: CardId,
) -> list[CardProvisioning]:
    return [
        _to_dataclass(card_provisioning=card_provisioning)
        for card_provisioning in CardProvisioningModelBroker.list_card_provisionings_for_card(
            session, card_id=card_id
        )
    ]

components.payment_gateway.subcomponents.cards.business_logic.queries.card_queries

CardQueries

This class contains all the queries related to cards.

get_card

get_card(session, /, id)

Get a card entity from its ID.

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_queries.py
def get_card(
    self,
    session: Session,
    /,
    id: CardId,
) -> Card:
    """
    Get a card entity from its ID.
    """

    with raise_if_card_not_found(id):
        card = CardModelBroker.get_card(session, id=id)

    raise_on_terminated_card(card)

    return _to_card(card)

get_card_ids_for_account

get_card_ids_for_account(session, /, account_id)

Get all the card IDs for an account.

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_queries.py
def get_card_ids_for_account(
    self,
    session: Session,
    /,
    account_id: AccountId,
) -> list[CardId]:
    """
    Get all the card IDs for an account.
    """

    return [
        CardId(card_id)
        for card_id in CardModelBroker.list_card_ids_for_account(
            session, account_id=account_id
        )
    ]

get_card_ids_for_card_holder

get_card_ids_for_card_holder(session, /, card_holder_id)

Get all the card IDs for a card holder.

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_queries.py
def get_card_ids_for_card_holder(
    self,
    session: Session,
    /,
    card_holder_id: CardHolderId,
) -> list[CardId]:
    """
    Get all the card IDs for a card holder.
    """

    return [
        CardId(card_id)
        for card_id in CardModelBroker.list_card_ids_for_card_holder(
            session, card_holder_id=card_holder_id
        )
    ]

get_cards_for_account

get_cards_for_account(session, /, account_id)

Get all the cards for an account.

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_queries.py
def get_cards_for_account(
    self,
    session: Session,
    /,
    account_id: AccountId,
) -> list[Card]:
    """
    Get all the cards for an account.
    """

    return [
        _to_card(card)
        for card in CardModelBroker.list_cards_for_account(
            session, account_id=account_id
        )
    ]

get_cards_for_card_holder

get_cards_for_card_holder(session, /, card_holder_id)

Get all the cards for a card holder.

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_queries.py
def get_cards_for_card_holder(
    self,
    session: Session,
    /,
    card_holder_id: CardHolderId,
) -> list[Card]:
    """
    Get all the cards for a card holder.
    """

    return [
        _to_card(card)
        for card in CardModelBroker.list_cards_for_card_holder(
            session, card_holder_id=card_holder_id
        )
    ]

components.payment_gateway.subcomponents.cards.business_logic.queries.card_reveal_queries

CARD_PASSWORD_SALT_CONFIG_KEY module-attribute

CARD_PASSWORD_SALT_CONFIG_KEY = (
    "ADYEN_CARD_PASSWORD_SALT_SECRET_NAME"
)

CARD_PASSWORD_SALT_DEFAULT_KEY module-attribute

CARD_PASSWORD_SALT_DEFAULT_KEY = 'ADYEN_CARD_PASSWORD_SALT'

CardRevealQueries

CardRevealQueries(adyen_client, password_salt)

This class contains all the queries related to card PIN/PAN reveals.

Implements the following Nullable patterns: - Nullables: https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks#nullables ⧉ - Parameterless instantiation: https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks#instantiation ⧉

Tags
Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_reveal_queries.py
def __init__(
    self,
    adyen_client: "AdyenPaymentInstrumentRevealApiClient | None",
    password_salt: str | None,
) -> None:
    self._adyen_client = adyen_client
    self.password_salt = password_salt

adyen_client property

adyen_client

Ensures the Adyen client is available when accessing it.

create classmethod

create()

Normal factory

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_reveal_queries.py
@classmethod
def create(cls) -> "CardRevealQueries":
    """Normal factory"""
    from shared.services.adyen.clients.adyen_payment_instrument_reveal_api_client import (
        AdyenPaymentInstrumentRevealApiClient,
    )
    from shared.services.adyen.clients.exceptions import (
        AdyenClientMissingCredentialsException,
    )

    try:
        adyen_client = AdyenPaymentInstrumentRevealApiClient.create()
    except AdyenClientMissingCredentialsException:
        adyen_client = None

    password_salt = raw_secret_from_config(
        config_key=CARD_PASSWORD_SALT_CONFIG_KEY,
        default_secret_value=current_config.get(CARD_PASSWORD_SALT_DEFAULT_KEY),
    )

    return cls(
        adyen_client=adyen_client,
        password_salt=password_salt,
    )

create_null classmethod

create_null(track_adyen_requests=None)

Null factory

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_reveal_queries.py
@classmethod
def create_null(
    cls,
    track_adyen_requests: list[tuple[str, dict, dict]] | None = None,  # type: ignore[type-arg]
) -> "CardRevealQueries":
    """Null factory"""
    from shared.services.adyen.clients.adyen_payment_instrument_reveal_api_client import (
        AdyenPaymentInstrumentRevealApiClient,
    )

    password_salt = "dummy_password_salt"  # gitleaks:allow

    return cls(
        adyen_client=AdyenPaymentInstrumentRevealApiClient.create_null(
            track_requests=track_adyen_requests,
        ),
        password_salt=password_salt,
    )

get_card_pan_reveal_public_key

get_card_pan_reveal_public_key()

Get the base-64 public key used for client-side encryption of card PAN reveal requests.

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_reveal_queries.py
def get_card_pan_reveal_public_key(self) -> str:
    """
    Get the base-64 public key used for client-side encryption of card PAN reveal requests.
    """

    response = self.adyen_client.get_pan_reveal_public_key()
    return response.publicKey

get_card_pin_reveal_public_key

get_card_pin_reveal_public_key()

Get the base-64 public key used for client-side encryption of card PIN reveal requests.

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_reveal_queries.py
def get_card_pin_reveal_public_key(self) -> str:
    """
    Get the base-64 public key used for client-side encryption of card PIN reveal requests.
    """

    response = self.adyen_client.get_pin_reveal_public_key()
    return response.publicKey

password_salt instance-attribute

password_salt = password_salt

reveal_card_default_password

reveal_card_default_password(id)

Reveal the default password of a card.

Very scrappy way of enabling 3DS payments at creation date. See below for full context: https://github.com/alan-eu/Topics/discussions/24840?sort=old ⧉

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_reveal_queries.py
def reveal_card_default_password(
    self,
    id: CardId,
) -> str:
    """
    Reveal the default password of a card.

    Very scrappy way of enabling 3DS payments at creation date. See below for full context:
    https://github.com/alan-eu/Topics/discussions/24840?sort=old
    """
    from components.payment_gateway.subcomponents.cards.adapters.adyen.helpers import (
        generate_card_password,
    )

    if self.password_salt is None:
        raise MissingCardPasswordSaltException()

    return generate_card_password(id, self.password_salt)

reveal_card_pan

reveal_card_pan(session, /, id, encrypted_aes_key)

Reveal the PAN of a card.

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_reveal_queries.py
def reveal_card_pan(
    self,
    session: Session,
    /,
    id: CardId,
    encrypted_aes_key: str,
) -> CardRevealPANData:
    """
    Reveal the PAN of a card.
    """
    from shared.services.adyen.raw_apis.payment_instrument_reveal_api import (
        PaymentInstrumentRevealPanRequest,
    )

    with raise_if_card_not_found(id):
        card = CardModelBroker.get_card(session, id=id)

    raise_on_terminated_card(card)

    response = self.adyen_client.reveal_pan_of_payment_instrument(
        PaymentInstrumentRevealPanRequest(
            paymentInstrumentId=card.external_id,
            encryptedKey=encrypted_aes_key,
        ),
    )
    return CardRevealPANData(
        encrypted_data=response.encryptedData,
    )

reveal_card_pin

reveal_card_pin(session, /, id, encrypted_aes_key)

Reveal the PAN of a card.

Source code in components/payment_gateway/subcomponents/cards/business_logic/queries/card_reveal_queries.py
def reveal_card_pin(
    self,
    session: Session,
    /,
    id: CardId,
    encrypted_aes_key: str,
) -> CardRevealPINData:
    """
    Reveal the PAN of a card.
    """
    from shared.services.adyen.raw_apis.payment_instrument_reveal_api import (
        PaymentInstrumentRevealPinRequest,
    )

    with raise_if_card_not_found(id):
        card = CardModelBroker.get_card(session, id=id)

    raise_on_terminated_card(card)

    response = self.adyen_client.reveal_pin_of_payment_instrument(
        PaymentInstrumentRevealPinRequest(
            paymentInstrumentId=card.external_id,
            encryptedKey=encrypted_aes_key,
        ),
    )
    return CardRevealPINData(
        encrypted_pin_block=response.encryptedPinBlock,
        token=response.token,
    )