import logging

from sysactions import (
    mbcontext,
    action,
)
from bustoken import TK_ELECTRONIC_PAYMENT_CANCEL_PAYMENT
from util_eft import get_electronic_payment_component_name

logger = logging.getLogger("EftActions")


@action
def abort_current_payment(
    pos_id,     # type: str
):
    # type: (...) -> None

    logger.info("Start abort current payment. PosId: {}".format(pos_id))

    payment_service = get_electronic_payment_component_name(pos_id=pos_id)
    if not payment_service:
        logger.info("PaymentService not found. PosId: {}".format(pos_id))
        return

    logger.info("Calling electronic payment. PosId: {} - PaymentService: {}".format(pos_id, payment_service))
    mbcontext.MB_EasySendMessage(
        dest_name=payment_service,
        token=TK_ELECTRONIC_PAYMENT_CANCEL_PAYMENT,
        data=pos_id,
    )
    logger.info("Abort current payment finished. PosId: {}".format(pos_id))
