Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IntegrationsManager.php
Go to the documentation of this file.
1 <?php
7 
13 
20 {
24  private $paymentMethodList;
25 
29  private $integrationFactory;
30 
34  private $storeManager;
35 
39  private $integrations;
40 
47  public function __construct(
48  PaymentMethodList $paymentMethodList,
49  IntegrationFactory $integrationFactory,
50  StoreManagerInterface $storeManager
51  ) {
52  $this->paymentMethodList = $paymentMethodList;
53  $this->integrationFactory = $integrationFactory;
54  $this->storeManager = $storeManager;
55  $this->integrations = [];
56  }
57 
64  public function getList(int $storeId): array
65  {
66  if (!isset($this->integrations[$storeId])) {
67  $this->integrations[$storeId] = $this->findIntegrations($storeId);
68  }
69  return $this->integrations[$storeId];
70  }
71 
81  {
82  foreach ($this->getList($storeId) as $integration) {
83  if ($integration->getVaultProviderCode() === $paymentToken->getPaymentMethodCode()) {
84  return $integration;
85  }
86  }
87  throw new LocalizedException(__('Instant purchase integration not available for token.'));
88  }
89 
96  public function getListForCurrentStore(): array
97  {
98  return $this->getList($this->storeManager->getStore()->getId());
99  }
100 
110  {
111  return $this->getByToken($paymentToken, $this->storeManager->getStore()->getId());
112  }
113 
120  private function findIntegrations(int $storeId): array
121  {
122  $integrations = [];
123  foreach ($this->paymentMethodList->getActiveList($storeId) as $paymentMethod) {
124  if ($this->isIntegrationAvailable($paymentMethod, $storeId)) {
125  $integrations[] = $this->integrationFactory->create($paymentMethod, $storeId);
126  }
127  }
128  return $integrations;
129  }
130 
152  private function isIntegrationAvailable(VaultPaymentInterface $paymentMethod, $storeId): bool
153  {
154  $data = $paymentMethod->getConfigData('instant_purchase', $storeId);
155  if (!is_array($data)) {
156  return false;
157  }
158  if (isset($data['supported']) && $data['supported'] !== '1') {
159  return false;
160  }
161  return true;
162  }
163 }
getByToken(PaymentTokenInterface $paymentToken, int $storeId)
$storeManager
__()
Definition: __.php:13
__construct(PaymentMethodList $paymentMethodList, IntegrationFactory $integrationFactory, StoreManagerInterface $storeManager)