parameters:
    oro_payment.entity.payment_term.class: Oro\Bundle\PaymentBundle\Entity\PaymentTerm
    oro_payment.entity.payment_transaction.class: Oro\Bundle\PaymentBundle\Entity\PaymentTransaction

services:
    oro_payment.payment_term.manager.api:
        class: 'Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager'
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - '%oro_payment.entity.payment_term.class%'
            - "@doctrine.orm.entity_manager"

    oro_payment.form.autocomplete.payment_term.search_handler:
        public: false
        parent: oro_form.autocomplete.search_handler
        arguments:
            - '%oro_payment.entity.payment_term.class%'
            - ["label"]
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: oro_payment_term, acl_resource: oro_payment_term_view }

    oro_payment.payment_term.delete_message_generator:
        class: 'Oro\Bundle\PaymentBundle\Twig\DeleteMessageTextGenerator'
        public: false
        arguments:
            - "@router"
            - "@twig"
            - "@doctrine"

    oro_payment.twig.delete_message_text_extension:
        class: 'Oro\Bundle\PaymentBundle\Twig\DeleteMessageTextExtension'
        public: false
        arguments:
            - "@oro_payment.payment_term.delete_message_generator"
        tags:
            - { name: twig.extension }

    oro_payment.formatter.payment_method_label:
        class: 'Oro\Bundle\PaymentBundle\Formatter\PaymentMethodLabelFormatter'
        arguments:
            - "@oro_payment.payment_method.view.registry"
            - "@translator"

    oro_payment.twig.payment_method_extension:
        class: 'Oro\Bundle\PaymentBundle\Twig\PaymentMethodExtension'
        public: false
        arguments:
            - "@oro_payment.provider.payment_transaction"
            - "@oro_payment.formatter.payment_method_label"
        tags:
            - { name: twig.extension }

    oro_payment.event_listener.form_view:
        class: 'Oro\Bundle\PaymentBundle\EventListener\FormViewListener'
        arguments:
            - "@request_stack"
            - "@translator"
            - "@oro_entity.doctrine_helper"
            - '%oro_payment.entity.payment_term.class%'
        tags:
            - { name: kernel.event_listener, event: oro_ui.scroll_data.before.account-view, method: onAccountView }
            - { name: kernel.event_listener, event: oro_ui.scroll_data.before.account-edit, method: onEntityEdit }
            - { name: kernel.event_listener, event: oro_ui.scroll_data.before.account-group-view, method: onAccountGroupView }
            - { name: kernel.event_listener, event: oro_ui.scroll_data.before.account-group-edit, method: onEntityEdit }

    oro_payment.event_listener.datagrid:
        class: 'Oro\Bundle\PaymentBundle\EventListener\DatagridListener'
        calls:
            - [setPaymentTermClass, ['%oro_payment.entity.payment_term.class%']]
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.before.account-accounts-grid, method: onBuildBeforeAccounts }
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.before.account-groups-grid, method: onBuildBeforeAccountGroups }
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.before.quotes-grid, method: onBuildBeforeQuotes }

    oro_payment.extension.action.type.payment_delete:
        class: 'Oro\Bundle\PaymentBundle\Extension\Action\Actions\PaymentDeleteAction'
        scope: prototype
        tags:
            - { name: oro_datagrid.extension.action.type, type: payment-delete }

    oro_payment.provider.surcharge:
        class: 'Oro\Bundle\PaymentBundle\Provider\SurchargeProvider'
        public: false
        arguments:
            - '@event_dispatcher'

    oro_payment.provider.payment_term:
        class: 'Oro\Bundle\PaymentBundle\Provider\PaymentTermProvider'
        public: false
        arguments:
            - '@doctrine'
            - '@security.token_storage'
            - '@event_dispatcher'
            - '%oro_payment.entity.payment_term.class%'

    oro_payment.provider.methods_provider:
        class: 'Oro\Bundle\PaymentBundle\Layout\DataProvider\PaymentMethodsProvider'
        arguments:
            - '@oro_payment.payment_method.view.registry'
            - '@oro_payment.provider.payment_context'
            - '@oro_payment.payment_method.registry'
            - '@oro_payment.provider.payment_transaction'
        tags:
            - { name: layout.data_provider, alias: oro_payment_methods_provider }

    oro_payment.provider.method_widget_provider:
        class: 'Oro\Bundle\PaymentBundle\Layout\DataProvider\PaymentMethodWidgetProvider'
        tags:
            - { name: layout.data_provider, alias: oro_payment_method_widget_provider }

    oro_payment.event.callback_handler:
        class: 'Oro\Bundle\PaymentBundle\Event\CallbackHandler'
        lazy: true
        arguments:
            - '@event_dispatcher'
            - '@oro_payment.provider.payment_transaction'

    oro_payment.provider.payment_transaction:
        class: 'Oro\Bundle\PaymentBundle\Provider\PaymentTransactionProvider'
        arguments:
            - '@oro_api.doctrine_helper'
            - '@security.token_storage'
            - '@event_dispatcher'
            - '%oro_payment.entity.payment_transaction.class%'
        calls:
            - ['setLogger', ['@logger']]

    oro_payment.provider.payment_status:
        class: 'Oro\Bundle\PaymentBundle\Provider\PaymentStatusProvider'
        arguments:
            - '@oro_payment.provider.payment_transaction'
            - '@oro_pricing.subtotal_processor.total_processor_provider'

    oro_payment.action.payment_method_action.abstract:
        abstract: true
        arguments:
            - '@oro_action.context_accessor'
            - '@oro_payment.payment_method.registry'
            - '@oro_payment.provider.payment_transaction'
            - '@router'
        calls:
            - ['setLogger', ['@logger']]

    oro_payment.action.capture:
        class: 'Oro\Bundle\PaymentBundle\Action\CaptureAction'
        parent: oro_payment.action.payment_method_action.abstract
        tags:
            - { name: oro_workflow.action, alias: payment_capture }
            - { name: oro_action.action, alias: payment_capture }

    oro_payment.action.purchase:
        class: 'Oro\Bundle\PaymentBundle\Action\PurchaseAction'
        parent: oro_payment.action.payment_method_action.abstract
        tags:
            - { name: oro_workflow.action, alias: payment_purchase }
            - { name: oro_action.action, alias: payment_purchase }

    oro_payment.action.validate:
        class: 'Oro\Bundle\PaymentBundle\Action\ValidateAction'
        parent: oro_payment.action.payment_method_action.abstract
        tags:
            - { name: oro_workflow.action, alias: payment_validate }
            - { name: oro_action.action, alias: payment_validate }

    oro_payment.event_listener.callback.redirect:
        class: 'Oro\Bundle\PaymentBundle\EventListener\Callback\RedirectListener'
        lazy: true
        arguments:
            - '@session'
        tags:
            - { name: kernel.event_listener, event: oro_payment.callback.return, method: onReturn, priority: 10 }
            - { name: kernel.event_listener, event: oro_payment.callback.error, method: onError, priority: 10 }

    oro_payment.condition.payment_method_enabled:
        class: 'Oro\Bundle\PaymentBundle\Condition\PaymentMethodEnabled'
        arguments:
            - '@oro_payment.payment_method.registry'
        tags:
            - { name: oro_workflow.condition, alias: 'payment_method_enabled' }
            - { name: oro_action.condition, alias: 'payment_method_enabled' }

    oro_payment.condition.payment_method_applicable:
        class: 'Oro\Bundle\PaymentBundle\Condition\PaymentMethodApplicable'
        arguments:
            - '@oro_payment.payment_method.registry'
            - '@oro_payment.provider.payment_context'
        tags:
            - { name: oro_workflow.condition, alias: 'payment_method_applicable' }
            - { name: oro_action.condition, alias: 'payment_method_applicable' }

    oro_payment.condition.has_applicable_payment_methods:
        class: 'Oro\Bundle\PaymentBundle\Condition\HasApplicablePaymentMethods'
        arguments:
            - '@oro_payment.payment_method.registry'
            - '@oro_payment.provider.payment_context'
        tags:
            - { name: oro_workflow.condition, alias: 'has_applicable_payment_methods' }
            - { name: oro_action.condition, alias: 'has_applicable_payment_methods' }

    oro_payment.provider.address_extractor:
        class: 'Oro\Bundle\PaymentBundle\Provider\AddressExtractor'
        public: false
        arguments:
            - '@property_accessor'

    oro_payment.provider.payment_context:
        class: 'Oro\Bundle\PaymentBundle\Provider\PaymentContextProvider'
        public: false
        arguments:
            - '@oro_payment.provider.address_extractor'
            - '@oro_pricing.user_currency_manager'

    oro_payment.condition.payment_method_supports:
        class: 'Oro\Bundle\PaymentBundle\Condition\PaymentMethodSupports'
        arguments:
            - '@oro_payment.payment_method.registry'
        tags:
            - { name: oro_workflow.condition, alias: 'payment_method_supports' }
            - { name: oro_action.condition, alias: 'payment_method_supports' }

    oro_payment.listener.payment_transaction_listener:
        class: 'Oro\Bundle\PaymentBundle\EventListener\PaymentTransactionListener'
        arguments:
            - '@oro_payment.manager.payment_status'
        tags:
            - { name: kernel.event_listener, event: oro_payment.event.transaction_complete, method: onTransactionComplete }

    oro_payment.manager.payment_status:
        class: 'Oro\Bundle\PaymentBundle\Manager\PaymentStatusManager'
        arguments:
            - '@oro_payment.provider.payment_status'
            - '@oro_entity.doctrine_helper'
            - '@oro_payment.provider.payment_transaction'

    oro_payment.formatter.payment_status_label:
        class: 'Oro\Bundle\PaymentBundle\Formatter\PaymentStatusLabelFormatter'
        arguments:
            - "@translator"

    oro_payment.twig.payment_status_extension:
        class: 'Oro\Bundle\PaymentBundle\Twig\PaymentStatusExtension'
        public: false
        arguments:
            - "@oro_payment.formatter.payment_status_label"
        tags:
            - { name: twig.extension }

    oro_payment.condition.require_payment_redirect:
        class: 'Oro\Bundle\PaymentBundle\Condition\RequirePaymentRedirect'
        arguments:
            - '@oro_payment.payment_method.registry'
            - '@event_dispatcher'
        tags:
            - { name: oro_workflow.condition, alias: 'require_payment_redirect' }
            - { name: oro_action.condition, alias: 'require_payment_redirect' }
