<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- Extension Attributes -->
    <preference for="StripeIntegration\Payments\Api\Data\CouponInterface" type="StripeIntegration\Payments\Model\Coupon" />
    <preference for="StripeIntegration\Payments\Api\Data\SubscriptionOptionsInterface" type="StripeIntegration\Payments\Model\SubscriptionOptions" />

    <type name="Magento\SalesRule\Model\Rule\DataProvider">
        <plugin name="StripeIntegration_Payments::Form_Data_Provider" type="StripeIntegration\Payments\Plugin\SalesRule\Model\DataProviderPlugin"/>
    </type>

    <!-- Payment Method Facade configuration -->
    <virtualType name="StripePaymentsFacade" type="StripeIntegration\Payments\Model\PaymentMethod">
        <arguments>
            <argument name="eventManager" xsi:type="object">\Magento\Framework\Event\ManagerInterface</argument>
            <argument name="valueHandlerPool" xsi:type="object">StripePaymentsValueHandlerPool</argument>
            <argument name="paymentDataObjectFactory" xsi:type="object">Magento\Payment\Gateway\Data\PaymentDataObjectFactory</argument>
            <argument name="code" xsi:type="string">stripe_payments</argument>
            <argument name="formBlockType" xsi:type="string">Magento\Payment\Block\Form</argument>
            <argument name="infoBlockType" xsi:type="string">StripeIntegration\Payments\Block\PaymentInfo\Element</argument>
            <argument name="checkoutHelper" xsi:type="object">\Magento\Checkout\Helper\Data</argument>
            <argument name="cache" xsi:type="object">\Magento\Framework\App\CacheInterface</argument>
            <argument name="logger" xsi:type="object">Psr\Log\LoggerInterface</argument>
            <!-- <argument name="commandPool" xsi:type="object">\Magento\Payment\Gateway\Command\CommandPoolInterface</argument> -->
            <argument name="validatorPool" xsi:type="object">StripePaymentsValidatorPool</argument>
        </arguments>
    </virtualType>
    <virtualType name="StripePaymentsInvoiceFacade" type="StripeIntegration\Payments\Model\Method\Invoice">
        <arguments>
            <argument name="eventManager" xsi:type="object">\Magento\Framework\Event\ManagerInterface</argument>
            <argument name="valueHandlerPool" xsi:type="object">StripePaymentsInvoiceValueHandlerPool</argument>
            <argument name="paymentDataObjectFactory" xsi:type="object">Magento\Payment\Gateway\Data\PaymentDataObjectFactory</argument>
            <argument name="code" xsi:type="string">stripe_payments_invoice</argument>
            <argument name="formBlockType" xsi:type="string">StripeIntegration\Payments\Block\Method\Invoice</argument>
            <argument name="infoBlockType" xsi:type="string">StripeIntegration\Payments\Block\PaymentInfo\Invoice</argument>
            <argument name="cache" xsi:type="object">\Magento\Framework\App\CacheInterface</argument>
            <argument name="commandPool" xsi:type="object">StripePaymentsInvoiceCommandPool</argument>
            <argument name="validatorPool" xsi:type="object">StripePaymentsValidatorPool</argument>
        </arguments>
    </virtualType>

    <virtualType name="StripeSubscriptionsFacade" type="StripeIntegration\Payments\Model\Method\Subscriptions">
        <arguments>
            <argument name="code" xsi:type="string">stripe_payments_subscriptions</argument>
            <argument name="formBlockType" xsi:type="string">Magento\Payment\Block\Form</argument>
            <argument name="infoBlockType" xsi:type="string">StripeIntegration\Payments\Block\Info</argument>
            <argument name="config" xsi:type="object">StripeIntegration\Payments\Model\Config</argument>
            <argument name="logger" xsi:type="object">Psr\Log\LoggerInterface</argument>
            <argument name="valueHandlerPool" xsi:type="object">StripePaymentsInvoiceValueHandlerPool</argument>
            <argument name="validatorPool" xsi:type="object">StripePaymentsValidatorPool</argument>
        </arguments>
    </virtualType>

    <virtualType name="StripeExpressFacade" type="StripeIntegration\Payments\Model\Method\Express">
        <arguments>
            <argument name="code" xsi:type="string">stripe_payments_express</argument>
            <argument name="valueHandlerPool" xsi:type="object">StripePaymentsExpressValueHandlerPool</argument>
            <argument name="formBlockType" xsi:type="string">Magento\Payment\Block\Form</argument>
            <argument name="infoBlockType" xsi:type="string">StripeIntegration\Payments\Block\PaymentInfo\Element</argument>
        </arguments>
    </virtualType>

    <!-- Configuration reader -->
    <virtualType name="StripePaymentsConfig" type="Magento\Payment\Gateway\Config\Config">
        <arguments>
            <argument name="methodCode" xsi:type="string">stripe_payments</argument>
        </arguments>
    </virtualType>
    <virtualType name="StripePaymentsExpressConfig" type="Magento\Payment\Gateway\Config\Config">
        <arguments>
            <argument name="methodCode" xsi:type="string">stripe_payments_express</argument>
        </arguments>
    </virtualType>
    <virtualType name="StripePaymentsInvoiceConfig" type="Magento\Payment\Gateway\Config\Config">
        <arguments>
            <argument name="methodCode" xsi:type="string">stripe_payments_invoice</argument>
        </arguments>
    </virtualType>

    <!-- Logger, initialized with StripePaymentsConfig -->
    <virtualType name="StripePaymentsLogger" type="Magento\Payment\Model\Method\Logger">
        <arguments>
            <argument name="config" xsi:type="object">StripePaymentsConfig</argument>
        </arguments>
    </virtualType>

    <type name="StripeIntegration\Payments\Gateway\Http\Client\ClientMock">
        <arguments>
            <argument name="logger" xsi:type="object">StripePaymentsLogger</argument>
        </arguments>
    </type>

    <!-- Validators -->
    <virtualType name="StripePaymentsCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
        <arguments>
            <argument name="config" xsi:type="object">StripePaymentsConfig</argument>
        </arguments>
    </virtualType>
    <virtualType name="StripePaymentsValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
        <arguments>
            <argument name="validators" xsi:type="array">
                <item name="country" xsi:type="string">StripePaymentsCountryValidator</item>
            </argument>
        </arguments>
    </virtualType>

    <!-- Value handlers infrastructure -->
    <virtualType name="StripePaymentsValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
        <arguments>
            <argument name="handlers" xsi:type="array">
                <item name="default" xsi:type="string">StripePaymentsConfigValueHandler</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="StripePaymentsExpressValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
        <arguments>
            <argument name="handlers" xsi:type="array">
                <item name="default" xsi:type="string">StripePaymentsExpressConfigValueHandler</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="StripePaymentsConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
        <arguments>
            <argument name="configInterface" xsi:type="object">StripePaymentsConfig</argument>
        </arguments>
    </virtualType>
    <virtualType name="StripePaymentsExpressConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
        <arguments>
            <argument name="configInterface" xsi:type="object">StripePaymentsExpressConfig</argument>
        </arguments>
    </virtualType>
    <virtualType name="StripePaymentsInvoiceValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
        <arguments>
            <argument name="handlers" xsi:type="array">
                <item name="default" xsi:type="string">StripePaymentsInvoiceConfigValueHandler</item>
                <item name="can_void" xsi:type="string">StripeIntegration\Payments\Gateway\Config\Invoice\CanVoidValueHandler</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="StripePaymentsInvoiceConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
        <arguments>
            <argument name="configInterface" xsi:type="object">StripePaymentsInvoiceConfig</argument>
        </arguments>
    </virtualType>

    <!--  Command pool structure  -->
    <virtualType name="StripePaymentsInvoiceCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="cancel" xsi:type="string">StripePaymentsInvoiceCancelCommand</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="StripePaymentsInvoiceCancelCommand" type="StripeIntegration\Payments\Gateway\Command\Invoice\CancelCommand" />

    <type name="StripeIntegration\Payments\Block\Info">
        <arguments>
            <argument name="config" xsi:type="object">StripePaymentsConfig</argument>
        </arguments>
    </type>

    <type name="StripeIntegration\Payments\Model\Ui\ConfigProvider">
        <arguments>
            <argument name="ccConfig" xsi:type="string">Magento\Checkout\Model\ConfigProviderInterface\CcConfig</argument>
            <argument name="assetSource" xsi:type="string">Magento\Framework\View\Asset\Source</argument>
        </arguments>
    </type>

    <type name="StripeIntegration\Payments\Controller\Customer\Subscriptions">
        <arguments>
            <argument name="session" xsi:type="object">Magento\Customer\Model\Session</argument>
            <argument name="helper" xsi:type="object">StripeIntegration\Payments\Helper\Generic</argument>
            <argument name="order" xsi:type="object">Magento\Sales\Model\Order</argument>
        </arguments>
    </type>

    <!-- Webhooks Logger -->
    <type name="StripeIntegration\Payments\Logger\Handler">
        <arguments>
            <argument name="filesystem" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
            <argument name="dir" xsi:type="object">Magento\Framework\App\Filesystem\DirectoryList</argument>
        </arguments>
    </type>

    <type name="StripeIntegration\Payments\Logger\WebhooksLogger">
        <arguments>
            <argument name="name" xsi:type="string">webhooks</argument>
            <argument name="handlers"  xsi:type="array">
                <item name="system" xsi:type="object">StripeIntegration\Payments\Logger\Handler</item>
            </argument>
        </arguments>
    </type>

    <!-- Checkout crashes logger -->
    <type name="StripeIntegration\Payments\Logger\CheckoutCrash\Logger">
        <arguments>
            <argument name="name" xsi:type="string">stripe_checkout_crashes</argument>
            <argument name="handlers" xsi:type="array">
                <item name="0" xsi:type="object">StripeIntegration\Payments\Logger\CheckoutCrash\Handler</item>
            </argument>
        </arguments>
    </type>

    <!-- Warnings logger -->
    <type name="StripeIntegration\Payments\Logger\Warnings\Logger">
        <arguments>
            <argument name="name" xsi:type="string">stripe_warnings</argument>
            <argument name="handlers" xsi:type="array">
                <item name="0" xsi:type="object">StripeIntegration\Payments\Logger\Warnings\Handler</item>
            </argument>
        </arguments>
    </type>

    <type name="Magento\Quote\Model\QuoteManagement">
        <plugin name="stripe_payments_quote_management" type="StripeIntegration\Payments\Plugin\Quote\QuoteManagement" />
    </type>

    <type name="Magento\Quote\Model\Quote\Address\Total\Shipping">
        <plugin name="stripe_payments_trial_subscription_shipping_total" type="StripeIntegration\Payments\Plugin\Quote\AddressShippingTotal" />
    </type>

    <type name="Magento\Payment\Model\Checks\ZeroTotal">
        <plugin name="stripe_payments_zero_total_check" type="StripeIntegration\Payments\Plugin\Validations\ZeroTotalCheck" />
    </type>

    <type name="Magento\Sales\Block\Adminhtml\Order\View">
        <plugin name="stripe_dispute_review_order_buttons" type="StripeIntegration\Payments\Plugin\Sales\Block\Adminhtml\Order\ViewPlugin" sortOrder="100"/>
    </type>

    <type name="Magento\Sales\Model\Order\Creditmemo">
        <plugin name="creditmemoPlugin" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Creditmemo"/>
    </type>

    <type name="Magento\Sales\Model\Service\CreditmemoService">
        <plugin name="stripe_creditmemo_service" type="StripeIntegration\Payments\Plugin\Sales\Model\Service\CreditmemoService"/>
    </type>

    <type name="Magento\Sales\Api\RefundInvoiceInterface">
        <plugin name="stripe_refund_invoice" type="StripeIntegration\Payments\Plugin\Sales\Model\RefundInvoice"/>
    </type>

    <type name="Magento\Sales\Model\ResourceModel\Order\Handler\State">
        <plugin name="stripe_order_state_resolver" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\StateResolver"/>
    </type>

    <preference for="StripeIntegration\Payments\Api\ServiceInterface" type="StripeIntegration\Payments\Api\Service" />

    <!-- Console Commands -->
    <type name="Magento\Framework\Console\CommandList">
        <arguments>
            <argument name="commands" xsi:type="array">
                <!-- Orders -->
                <item name="OrdersMigratePaymentMethod" xsi:type="object">StripeIntegration\Payments\Commands\Orders\MigratePaymentMethodCommand</item>

                <!-- Subscriptions -->
                <item name="SubscriptionsMigrateSubscriptionPrice" xsi:type="object">StripeIntegration\Payments\Commands\Subscriptions\MigrateSubscriptionPriceCommand</item>
                <item name="SubscriptionsCreateFromOrderCommand" xsi:type="object">StripeIntegration\Payments\Commands\Subscriptions\CreateFromOrderCommand</item>

                <!-- Webhooks -->
                <item name="WebhooksConfigure" xsi:type="object">StripeIntegration\Payments\Commands\Webhooks\ConfigureCommand</item>
                <item name="WebhooksOriginCheck" xsi:type="object">StripeIntegration\Payments\Commands\Webhooks\OriginCheckCommand</item>
                <item name="WebhooksProcessEvent" xsi:type="object">StripeIntegration\Payments\Commands\Webhooks\ProcessEventCommand</item>
                <item name="WebhooksProcessEventsRange" xsi:type="object">StripeIntegration\Payments\Commands\Webhooks\ProcessEventsRangeCommand</item>
                <item name="WebhooksProcessEventsDateRange" xsi:type="object">StripeIntegration\Payments\Commands\Webhooks\ProcessEventsDateRangeCommand</item>

                <!-- Cron -->
                <item name="CronCancelAbandonedPayments" xsi:type="object">StripeIntegration\Payments\Commands\Cron\CancelAbandonedPaymentsCommand</item>
                <item name="CronRetryEvents" xsi:type="object">StripeIntegration\Payments\Commands\Cron\RetryEventsCommand</item>
                <item name="CleanupDBTables" xsi:type="object">StripeIntegration\Payments\Commands\Cron\CleanupDBTables</item>

                <!-- MFTF seed data -->
                <item name="MftfConfigureSubscriptionProduct" xsi:type="object">StripeIntegration\Payments\Commands\Mftf\ConfigureSubscriptionProductCommand</item>
            </argument>
        </arguments>
    </type>

    <type name="StripeIntegration\Payments\Setup\Migrate\ProductConfigurationCommand">
        <arguments>
            <argument name="session" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\CollectionFactory</argument>
        </arguments>
    </type>

    <!-- Initial Fee -->
    <type name="Magento\Quote\Model\Quote\Address\ToOrder">
        <plugin name="addInitialFeeToOrder" type="StripeIntegration\Payments\Plugin\Quote\InitialFeeToOrder" sortOrder="30"/>
    </type>
    <type name="Magento\Sales\Block\Order\Totals">
        <plugin name="addInitialFeeTotal" type="StripeIntegration\Payments\Plugin\Order\AddInitialFeeToTotalsBlock" sortOrder="30"/>
    </type>
    <type name="Magento\Sales\Model\Order">
        <plugin name="setInitialFeeExtensionAfterLoad" type="StripeIntegration\Payments\Plugin\Order\LoadInitialFee" sortOrder="30"/>
        <plugin name="stripe_magento_sales_model_order" type="StripeIntegration\Payments\Plugin\Sales\Model\Order" sortOrder="30"/>
        <plugin name="stripe_payments_filter_deregistered_invoice" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\FilterRelatedObjects" sortOrder="30"/>
    </type>
    <type name="Magento\Sales\Model\OrderRepository">
        <plugin name="getInitialFeeExtensionBeforeSave" type="StripeIntegration\Payments\Plugin\Order\SaveInitialFee" sortOrder="30"/>
    </type>
    <type name="Magento\Sales\Model\ResourceModel\Order\Collection">
        <plugin name="setInitialFeeExtensionAfterLoad" type="StripeIntegration\Payments\Plugin\Order\LoadInitialFeeOnCollection" sortOrder="30"/>
    </type>
    <type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
        <plugin name="addInitalFeeToOrderItem" type="StripeIntegration\Payments\Plugin\Quote\QuoteItemToOrderItem" sortOrder="30"/>
    </type>

    <!-- Disable manual invoice capturing -->
    <type name="Magento\Sales\Model\Order\Invoice">
        <plugin name="invoicePlugin" type="StripeIntegration\Payments\Plugin\Sales\Model\Invoice" sortOrder="30"/>
    </type>

    <!-- Around order placement -->
    <type name="Magento\Sales\Model\Service\OrderService">
        <plugin name="stripePaymentsOrderService"
                type="StripeIntegration\Payments\Plugin\Sales\Model\Service\OrderService"
                sortOrder="1"
                disabled="false"/>
    </type>

    <!-- Subscriptions -->
    <type name="Magento\Tax\Model\Config">
        <plugin name="stripeSubscriptionsTaxCalculation" type="StripeIntegration\Payments\Plugin\Tax\Config" sortOrder="30" />
    </type>
    <type name="Magento\Sales\Model\ResourceModel\Collection\ExpiredQuotesCollection">
        <plugin name="stripeSubscriptionsExpiredQuoted" type="StripeIntegration\Payments\Plugin\Quote\ExpiredQuotesCollection" sortOrder="30" />
    </type>
    <type name="Magento\SalesRule\Model\Utility">
        <plugin name="stripeRuleValidator" type="StripeIntegration\Payments\Plugin\SalesRule\Model\Utility" sortOrder="30" />
    </type>

    <!-- Set the initial order state -->
    <type name="Magento\Sales\Model\Order\Payment\State\OrderCommand">
        <plugin name="stripe_order_payment_order_command" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Payment\State\OrderCommand" sortOrder="10" />
    </type>
    <type name="Magento\Sales\Model\Order\Payment\State\AuthorizeCommand">
        <plugin name="stripe_order_payment_authorize_command" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Payment\State\AuthorizeCaptureCommand" sortOrder="10" />
    </type>
    <type name="Magento\Sales\Model\Order\Payment\State\CaptureCommand">
        <plugin name="stripe_order_payment_capture_command" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Payment\State\AuthorizeCaptureCommand" sortOrder="10" />
    </type>

    <!-- Pending Payment Order Lifetime -->
    <type name="Magento\Sales\Model\CronJob\CleanExpiredOrders">
        <plugin name="stripe_pending_payment_order_lifetime" type="StripeIntegration\Payments\Plugin\Sales\Model\CronJob\CleanExpiredOrders" sortOrder="10" />
    </type>

    <type name="Magento\Config\Model\Config\TypePool">
        <arguments>
            <argument name="sensitive" xsi:type="array">
                <item name="payment/stripe_payments_basic/stripe_test_sk" xsi:type="string">1</item>
                <item name="payment/stripe_payments_basic/stripe_live_sk" xsi:type="string">1</item>
            </argument>
        </arguments>
    </type>

    <!-- GraphQL -->
    <type name="Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart">
        <plugin name="stripe_payments_set_payment_method_on_cart" type="StripeIntegration\Payments\Plugin\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart"/>
    </type>
    <type name="Magento\QuoteGraphQl\Model\Resolver\PlaceOrder">
        <plugin name="stripe_payments_place_order" type="StripeIntegration\Payments\Plugin\QuoteGraphQl\Model\Resolver\PlaceOrder"/>
    </type>

    <!-- Multishipping -->
    <type name="Magento\Multishipping\Model\Checkout\Type\Multishipping">
        <arguments>
            <argument name="paymentSpecification" xsi:type="object">multishippingPaymentSpecification</argument>
            <argument name="logger" xsi:type="object">Psr\Log\LoggerInterface</argument>
        </arguments>
        <plugin name="stripe_payments_require_payment_token" type="StripeIntegration\Payments\Plugin\Multishipping\Checkout"/>
    </type>
    <virtualType name="multishippingPaymentSpecification" type="Magento\Payment\Model\Method\Specification\Composite">
        <arguments>
            <argument name="specifications" xsi:type="array">
                <item name="enabled" xsi:type="string">Magento\Multishipping\Model\Payment\Method\Specification\Enabled</item>
            </argument>
        </arguments>
    </virtualType>
    <type name="Magento\Multishipping\Helper\Data">
        <plugin name="disableMultishippingSubscriptions" type="StripeIntegration\Payments\Plugin\Multishipping\Helper" sortOrder="7"/>
    </type>

    <!-- Before add to cart validations -->
    <type name="Magento\Quote\Model\Quote">
        <plugin name="stripeBeforeAddToCartValidations" type="StripeIntegration\Payments\Plugin\Cart\BeforeAddToCart" sortOrder="7"/>
        <plugin name="stripeBeforeQuoteSave" type="StripeIntegration\Payments\Plugin\Quote\BeforeSave" sortOrder="7"/>
    </type>
    <type name="Magento\Quote\Api\CartRepositoryInterface">
        <plugin name="stripeBeforeCartRepositorySave" type="StripeIntegration\Payments\Plugin\CartRepository\BeforeSave" sortOrder="7"/>
    </type>

    <type name="Magento\Checkout\Controller\Cart\Add">
        <plugin name="stripeBeforeAddToCartSubscriptionValidations" type="StripeIntegration\Payments\Plugin\Checkout\Controller\Cart\Add"/>
    </type>

    <!-- Gift cards, store credit and reward points -->
    <type name="Magento\GiftCardAccount\Model\Service\GiftCardAccountManagement">
        <plugin name="stripeFutureSubscriptionsGiftCards" type="StripeIntegration\Payments\Plugin\Cart\FutureSubscriptionsGiftcards" sortOrder="10" />
    </type>
    <type name="Magento\Reward\Model\RewardManagement">
        <plugin name="stripeFutureSubscriptionsRewards" type="StripeIntegration\Payments\Plugin\Cart\FutureSubscriptionsRewards" sortOrder="10" />
    </type>
    <type name="Magento\CustomerBalance\Model\BalanceManagement">
        <plugin name="stripeFutureSubscriptionsStoreCredit" type="StripeIntegration\Payments\Plugin\Cart\FutureSubscriptionsStoreCredit" sortOrder="10" />
    </type>

    <!-- Event Config: suppress sales_order_invoice_register for deregistered invoices -->
    <type name="Magento\Framework\Event\ConfigInterface">
        <plugin name="stripe_payments_event_config" type="StripeIntegration\Payments\Plugin\Framework\Event\Config" sortOrder="10"/>
    </type>

    <!-- Handlers -->
    <type name="Magento\Framework\EntityManager\Operation\ExtensionPool">
        <arguments>
            <argument name="extensionActions" xsi:type="array">
                <item name="Magento\SalesRule\Api\Data\RuleInterface" xsi:type="array">
                    <item name="create" xsi:type="array">
                        <item name="create_stripe_rule" xsi:type="string">StripeIntegration\Payments\Model\SalesRule\SaveHandler</item>
                    </item>
                    <item name="update" xsi:type="array">
                        <item name="create_stripe_rule" xsi:type="string">StripeIntegration\Payments\Model\SalesRule\SaveHandler</item>
                    </item>
                    <item name="read" xsi:type="array">
                        <item name="read_stripe_rule" xsi:type="string">StripeIntegration\Payments\Model\SalesRule\ReadHandler</item>
                    </item>
                </item>
                <item name="Magento\Catalog\Api\Data\ProductInterface" xsi:type="array">
                    <item name="create" xsi:type="array">
                        <item name="create_subscription_options" xsi:type="string">StripeIntegration\Payments\Model\SubscriptionOptions\SaveHandler</item>
                    </item>
                    <item name="update" xsi:type="array">
                        <item name="update_subscription_options" xsi:type="string">StripeIntegration\Payments\Model\SubscriptionOptions\SaveHandler</item>
                    </item>
                    <item name="read" xsi:type="array">
                        <item name="read_subscription_options" xsi:type="string">StripeIntegration\Payments\Model\SubscriptionOptions\ReadHandler</item>
                    </item>
                </item>
            </argument>
        </arguments>
    </type>

    <virtualType name="Magento\Sales\Model\ResourceModel\Order\Grid">
        <arguments>
            <argument name="columns" xsi:type="array">
                <item name="stripe_radar_risk_score" xsi:type="string">sales_order.stripe_radar_risk_score</item>
                <item name="stripe_radar_risk_level" xsi:type="string">sales_order.stripe_radar_risk_level</item>
                <item name="stripe_payment_method_type" xsi:type="string">sales_order.stripe_payment_method_type</item>
            </argument>
        </arguments>
    </virtualType>

    <!-- Bank transfers -->
    <virtualType name="StripeBankTransfersFacade" type="StripeIntegration\Payments\Model\Method\BankTransfers">
        <arguments>
            <argument name="code" xsi:type="string">stripe_payments_bank_transfers</argument>
            <argument name="formBlockType" xsi:type="string">Magento\Payment\Block\Form</argument>
            <argument name="infoBlockType" xsi:type="string">StripeIntegration\Payments\Block\PaymentInfo\BankTransfers</argument>
            <argument name="valueHandlerPool" xsi:type="object">StripeBankTransfersValueHandlerPool</argument>
            <argument name="validatorPool" xsi:type="object">StripeBankTransfersValidatorPool</argument>
            <argument name="commandPool" xsi:type="object">StripeBankTransfersCommandPool</argument>
        </arguments>
    </virtualType>
    <virtualType name="StripeBankTransfersValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
        <arguments>
            <argument name="handlers" xsi:type="array">
                <item name="default" xsi:type="string">StripeBankTransfersConfigValueHandler</item>
                <item name="can_void" xsi:type="string">StripeIntegration\Payments\Gateway\Config\BankTransfers\CanVoidValueHandler</item>
<!--                <item name="can_cancel" xsi:type="string">StripeBankTransfersCanCancelValueHandler</item> -->
<!--                <item name="can_refund" xsi:type="string">StripeBankTransfersCanRefundValueHandler</item> -->
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="StripeBankTransfersConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
        <arguments>
            <argument name="configInterface" xsi:type="object">StripeBankTransfersConfig</argument>
        </arguments>
    </virtualType>
    <virtualType name="StripeBankTransfersValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
        <arguments>
            <argument name="validators" xsi:type="array">
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="StripeBankTransfersConfig" type="Magento\Payment\Gateway\Config\Config">
        <arguments>
            <argument name="methodCode" xsi:type="string">stripe_payments_bank_transfers</argument>
        </arguments>
    </virtualType>
    <virtualType name="StripeBankTransfersCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="order" xsi:type="string">StripeBankTransfersOrderCommand</item>
                <item name="refund" xsi:type="string">StripeBankTransfersRefundCommand</item>
                <item name="cancel" xsi:type="string">StripeBankTransfersCancelCommand</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="StripeBankTransfersOrderCommand" type="StripeIntegration\Payments\Gateway\Command\BankTransfers\OrderCommand"></virtualType>
    <virtualType name="StripeBankTransfersRefundCommand" type="StripeIntegration\Payments\Gateway\Command\BankTransfers\RefundCommand"></virtualType>
    <virtualType name="StripeBankTransfersCancelCommand" type="StripeIntegration\Payments\Gateway\Command\BankTransfers\CancelCommand"></virtualType>

    <!-- Redirect Flow (Stripe Checkout) -->
    <virtualType name="RedirectFlowFacade" type="StripeIntegration\Payments\Model\Method\Checkout">
        <arguments>
            <argument name="code" xsi:type="string">stripe_payments_checkout</argument>
            <argument name="formBlockType" xsi:type="string">Magento\Payment\Block\Form</argument>
            <argument name="infoBlockType" xsi:type="string">StripeIntegration\Payments\Block\PaymentInfo\Checkout</argument>
            <argument name="valueHandlerPool" xsi:type="object">RedirectFlowValueHandlerPool</argument>
            <argument name="validatorPool" xsi:type="object">RedirectFlowValidatorPool</argument>
            <argument name="commandPool" xsi:type="object">RedirectFlowCommandPool</argument>
        </arguments>
    </virtualType>
    <virtualType name="RedirectFlowValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
        <arguments>
            <argument name="handlers" xsi:type="array">
                <item name="default" xsi:type="string">RedirectFlowConfigValueHandler</item>
                <item name="can_order" xsi:type="string">StripeIntegration\Payments\Gateway\Config\RedirectFlow\CanOrderValueHandler</item>
                <item name="can_authorize" xsi:type="string">StripeIntegration\Payments\Gateway\Config\RedirectFlow\CanAuthorizeValueHandler</item>
                <item name="can_capture" xsi:type="string">StripeIntegration\Payments\Gateway\Config\RedirectFlow\CanCaptureValueHandler</item>
                <item name="sort_order" xsi:type="string">StripeIntegration\Payments\Gateway\Config\RedirectFlow\SortOrderValueHandler</item>
                <!-- <item name="can_void" xsi:type="string">RedirectFlowCanVoidValueHandler</item>
                <item name="can_cancel" xsi:type="string">RedirectFlowCanCancelValueHandler</item>
                <item name="can_refund" xsi:type="string">RedirectFlowCanRefundValueHandler</item> -->
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="RedirectFlowConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
        <arguments>
            <argument name="configInterface" xsi:type="object">RedirectFlowConfig</argument>
        </arguments>
    </virtualType>
    <virtualType name="RedirectFlowValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
        <arguments>
            <argument name="validators" xsi:type="array">
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="RedirectFlowConfig" type="Magento\Payment\Gateway\Config\Config">
        <arguments>
            <argument name="methodCode" xsi:type="string">stripe_payments_checkout</argument>
        </arguments>
    </virtualType>
    <virtualType name="RedirectFlowCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="order" xsi:type="string">RedirectFlowOrderCommand</item>
                <item name="void" xsi:type="string">RedirectFlowRefundCommand</item>
                <item name="cancel" xsi:type="string">RedirectFlowRefundCommand</item>
                <item name="refund" xsi:type="string">RedirectFlowRefundCommand</item>
                <item name="capture" xsi:type="string">RedirectFlowCaptureCommand</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="RedirectFlowOrderCommand" type="StripeIntegration\Payments\Gateway\Command\RedirectFlow\OrderCommand"></virtualType>
    <virtualType name="RedirectFlowRefundCommand" type="StripeIntegration\Payments\Gateway\Command\RedirectFlow\RefundCommand"></virtualType>
    <virtualType name="RedirectFlowCaptureCommand" type="StripeIntegration\Payments\Gateway\Command\RedirectFlow\CaptureCommand"></virtualType>

    <type name="Magento\Sales\Model\Order\Item">
        <plugin name="stripe_order_item" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Item" sortOrder="10"/>
    </type>

    <!--  Payment method messaging element plugins  -->
    <type name="Magento\Checkout\CustomerData\Cart">
        <plugin name="vendor_module_add_cart_data" type="StripeIntegration\Payments\Plugin\Checkout\CustomerData\Cart" />
    </type>
    <type name="Magento\Checkout\Block\Cart\Totals">
        <plugin name="stripe_pmme_cart" type="StripeIntegration\Payments\Plugin\Checkout\Block\Cart\Totals" />
    </type>
    <type name="Magento\Checkout\Block\Cart\Sidebar">
        <plugin name="stripe_pmme_minicart" type="StripeIntegration\Payments\Plugin\Checkout\Block\Cart\Sidebar" />
    </type>

    <type name="Magento\Sales\Model\Order\Payment\Transaction\ManagerInterface">
        <plugin name="stripe_payment_transaction_manager" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Payment\Transaction\Manager" />
    </type>

    <type name="Magento\Sales\Api\Data\OrderPaymentInterface">
        <plugin name="stripe_order_payment" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Payment" />
    </type>

    <!--  Subscription emails  -->
    <type name="Magento\Sales\Model\Order\Email\Container\OrderIdentity">
        <plugin name="stripe_subscription_order_email_identity" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Email\Container\OrderIdentity" />
    </type>
    <type name="Magento\Sales\Model\Order\Email\Sender\OrderSender">
        <plugin name="stripe_subscription_order_email_sender" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Email\Sender\OrderSender" />
    </type>
    <type name="Magento\Sales\Model\Order\Email\Container\InvoiceIdentity">
        <plugin name="stripe_subscription_invoice_email_identity" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Email\Container\InvoiceIdentity" />
    </type>
    <type name="Magento\Sales\Model\Order\Email\Sender\InvoiceSender">
        <plugin name="stripe_subscription_invoice_email_sender" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Email\Sender\InvoiceSender" />
    </type>
    <type name="Magento\Sales\Model\Order\Email\Container\CreditmemoIdentity">
        <plugin name="stripe_subscription_creditmemo_email_identity" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Email\Container\CreditmemoIdentity" />
    </type>
    <type name="Magento\Sales\Model\Order\Email\Sender\CreditmemoSender">
        <plugin name="stripe_subscription_creditmemo_email_sender" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Email\Sender\CreditmemoSender" />
    </type>
    <type name="Magento\Sales\Model\Order\Email\Container\ShipmentIdentity">
        <plugin name="stripe_subscription_shipment_email_identity" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Email\Container\ShipmentIdentity" />
    </type>
    <type name="Magento\Sales\Model\Order\Email\Sender\ShipmentSender">
        <plugin name="stripe_subscription_shipment_email_sender" type="StripeIntegration\Payments\Plugin\Sales\Model\Order\Email\Sender\ShipmentSender" />
    </type>
    <!-- Restore the WCS pending order's quote before the checkout/cart page renders, so that a
         customer returning from a redirect-based payment method's authorization page (back button)
         is not redirected to an empty cart. -->
    <type name="Magento\Checkout\Controller\Index\Index">
        <plugin name="stripe_payments_checkout_index_restore" type="StripeIntegration\Payments\Plugin\Checkout\IndexController" />
    </type>
    <type name="Magento\Checkout\Controller\Cart\Index">
        <plugin name="stripe_payments_cart_index_restore" type="StripeIntegration\Payments\Plugin\Checkout\IndexController" />
    </type>

    <!--
        OneStepCheckout / custom checkout modules serve the checkout page from their OWN controller,
        so the native Magento\Checkout\Controller\Index\Index plugin above does not fire for them.
        To restore the abandoned pending order's cart on such pages, register the SAME plugin class
        (StripeIntegration\Payments\Plugin\Checkout\IndexController) on the OSC module's checkout
        controller. The plugin's beforeExecute() is typed against \Magento\Framework\App\Action\Action,
        so any controller extending it works.

        Find the controller class in the installed OSC module (class names vary by version), then
        uncomment/adjust the matching example below:

        Aheadworks One Step Checkout  (route: onestepcheckout):
        <type name="Aheadworks\OneStepCheckout\Controller\Index\Index">
            <plugin name="stripe_payments_osc_restore" type="StripeIntegration\Payments\Plugin\Checkout\IndexController" />
        </type>

        Mageplaza One Step Checkout  (route: onestepcheckout):
        <type name="Mageplaza\Osc\Controller\Index\Index">
            <plugin name="stripe_payments_osc_restore" type="StripeIntegration\Payments\Plugin\Checkout\IndexController" />
        </type>

        Amasty One Step Checkout  (route: onestepcheckout):
        <type name="Amasty\CheckoutCore\Controller\Index\Index">
            <plugin name="stripe_payments_osc_restore" type="StripeIntegration\Payments\Plugin\Checkout\IndexController" />
        </type>

        IWD One Page Checkout  (route: onepage):
        <type name="IWD\Opc\Controller\Index\Index">
            <plugin name="stripe_payments_osc_restore" type="StripeIntegration\Payments\Plugin\Checkout\IndexController" />
        </type>
    -->
</config>
