Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentTokens.php
Go to the documentation of this file.
1 <?php
7 
12 
16 abstract class PaymentTokens extends Template
17 {
21  private $customerTokens;
22 
26  private $customerTokenManagement;
27 
34  public function __construct(
35  Template\Context $context,
36  CustomerTokenManagement $customerTokenManagement,
37  array $data = []
38  ) {
39  parent::__construct($context, $data);
40  $this->customerTokenManagement = $customerTokenManagement;
41  }
42 
47  abstract public function getType();
48 
52  public function getPaymentTokens()
53  {
54  $tokens = [];
56  foreach ($this->getCustomerTokens() as $token) {
57  if ($token->getType() === $this->getType()) {
58  $tokens[] = $token;
59  }
60  }
61  return $tokens;
62  }
63 
69  {
70  foreach ($this->getChildNames() as $childName) {
71  $childBlock = $this->getChildBlock($childName);
72  if ($childBlock instanceof TokenRendererInterface && $childBlock->canRender($token)) {
73  return $childBlock->render($token);
74  }
75  }
76 
77  return '';
78  }
79 
84  public function isExistsCustomerTokens()
85  {
86  return !empty($this->getCustomerTokens());
87  }
88 
93  private function getCustomerTokens()
94  {
95  if (empty($this->customerTokens)) {
96  $this->customerTokens = $this->customerTokenManagement->getCustomerSessionTokens();
97  }
98  return $this->customerTokens;
99  }
100 }
__construct(Template\Context $context, CustomerTokenManagement $customerTokenManagement, array $data=[])
canRender(PaymentTokenInterface $token)
renderTokenHtml(PaymentTokenInterface $token)
$tokens
Definition: cards_list.phtml:9