SimplePaymentTokenFormatter.php 1.1 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\InstantPurchase\PaymentMethodIntegration;

use Magento\Vault\Api\Data\PaymentTokenInterface;

/**
 * Payment token formatter that uses payment method title as token string representation.
 */
class SimplePaymentTokenFormatter implements PaymentTokenFormatterInterface
{
    /**
     * @var IntegrationsManager
     */
    private $integrationsManager;

    /**
     * SimplePaymentTokenFormatter constructor.
     * @param IntegrationsManager $integrationsManager
     */
    public function __construct(IntegrationsManager $integrationsManager)
    {
        $this->integrationsManager = $integrationsManager;
    }

    /**
     * @inheritdoc
     */
    public function formatPaymentToken(PaymentTokenInterface $paymentToken): string
    {
        $integration = $this->integrationsManager->getByTokenForCurrentStore($paymentToken);
        $paymentMethod = $integration->getPaymentMethod();
        $paymentMethodTitle = $paymentMethod->getTitle();
        return (string)$paymentMethodTitle;
    }
}