Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentConfigurationProcess.php
Go to the documentation of this file.
1 <?php
7 
14 {
18  private $paymentMethodList;
19 
23  private $storeManager;
24 
29  public function __construct(
30  \Magento\Payment\Api\PaymentMethodListInterface $paymentMethodList,
31  \Magento\Store\Model\StoreManagerInterface $storeManager
32  ) {
33  $this->paymentMethodList = $paymentMethodList;
34  $this->storeManager = $storeManager;
35  }
36 
45  public function beforeProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $processor, $jsLayout)
46  {
47  $configuration = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
48  ['children']['payment']['children']['renders']['children'];
49 
50  if (!isset($configuration)) {
51  return [$jsLayout];
52  }
53 
54  $storeId = $this->storeManager->getStore()->getId();
55  $activePaymentMethodList = $this->paymentMethodList->getActiveList($storeId);
56  $getCodeFunc = function ($method) {
57  return $method->getCode();
58  };
59  $activePaymentMethodCodes = array_map($getCodeFunc, $activePaymentMethodList);
60 
61  foreach ($configuration as $paymentGroup => $groupConfig) {
62  $notActivePaymentMethodCodes = array_diff(array_keys($groupConfig['methods']), $activePaymentMethodCodes);
63  foreach ($notActivePaymentMethodCodes as $notActivePaymentMethodCode) {
64  unset($configuration[$paymentGroup]['methods'][$notActivePaymentMethodCode]);
65  }
66  if (empty($configuration[$paymentGroup]['methods'])) {
67  unset($configuration[$paymentGroup]);
68  }
69  }
70 
71  return [$jsLayout];
72  }
73 }
beforeProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $processor, $jsLayout)
__construct(\Magento\Payment\Api\PaymentMethodListInterface $paymentMethodList, \Magento\Store\Model\StoreManagerInterface $storeManager)
$configuration
Definition: index.php:33
$processor
Definition: 404.php:10
$storeManager
$method
Definition: info.phtml:13