# -*- coding: utf-8 -*-
from model import StartPaymentData
from paymentrouter._PaymentRouter import PaymentError

from ._CommonProcessor import _CommonProcessor


class StartPaymentProcessor(_CommonProcessor):
    def parse_data(self, data, event_type):
        return StartPaymentData(*data.split(';'))

    def call_business(self, obj):
        # type: (StartPaymentData) -> str
        try:
            processor = self.payment_router.get_payment_processor(obj.electronic_type)
            add_payment_response = processor.add_payment(obj)
            return add_payment_response.to_xml()
        except PaymentError as ex:
            self.payment_router._logger.exception("exception: {}".format(ex.message))
