PaymentTokenFormatter.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\InstantPurchase\Model\Ui;
  7. use Magento\InstantPurchase\PaymentMethodIntegration\IntegrationsManager;
  8. use Magento\Vault\Api\Data\PaymentTokenInterface;
  9. /**
  10. * Payment token string presentation.
  11. *
  12. * @api May be used for pluginization.
  13. * @since 100.2.0
  14. */
  15. class PaymentTokenFormatter
  16. {
  17. /**
  18. * @var IntegrationsManager
  19. */
  20. private $integrationsManager;
  21. /**
  22. * PaymentTokenFormatter constructor.
  23. * @param IntegrationsManager $integrationsManager
  24. */
  25. public function __construct(IntegrationsManager $integrationsManager)
  26. {
  27. $this->integrationsManager = $integrationsManager;
  28. }
  29. /**
  30. * Formats payment token to string.
  31. *
  32. * @param PaymentTokenInterface $paymentToken
  33. * @return string
  34. * @since 100.2.0
  35. */
  36. public function format(PaymentTokenInterface $paymentToken): string
  37. {
  38. $integration = $this->integrationsManager->getByTokenForCurrentStore($paymentToken);
  39. $formatted = $integration->formatPaymentToken($paymentToken);
  40. return $formatted;
  41. }
  42. }