Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Form.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Braintree\Gateway\Config\Config as GatewayConfig;
17 
21 class Form extends Cc
22 {
26  protected $sessionQuote;
27 
31  protected $gatewayConfig;
32 
36  protected $ccType;
37 
41  private $paymentDataHelper;
42 
52  public function __construct(
53  Context $context,
54  Config $paymentConfig,
56  GatewayConfig $gatewayConfig,
58  Data $paymentDataHelper,
59  array $data = []
60  ) {
61  parent::__construct($context, $paymentConfig, $data);
62  $this->sessionQuote = $sessionQuote;
63  $this->gatewayConfig = $gatewayConfig;
64  $this->ccType = $ccType;
65  $this->paymentDataHelper = $paymentDataHelper;
66  }
67 
72  public function getCcAvailableTypes()
73  {
74  $configuredCardTypes = $this->getConfiguredCardTypes();
75  $countryId = $this->sessionQuote->getQuote()->getBillingAddress()->getCountryId();
76  return $this->filterCardTypesForCountry($configuredCardTypes, $countryId);
77  }
78 
83  public function useCvv()
84  {
85  return $this->gatewayConfig->isCvvEnabled($this->sessionQuote->getStoreId());
86  }
87 
92  public function isVaultEnabled()
93  {
94  $vaultPayment = $this->getVaultPayment();
95  return $vaultPayment->isActive($this->sessionQuote->getStoreId());
96  }
97 
102  private function getConfiguredCardTypes()
103  {
104  $types = $this->ccType->getCcTypeLabelMap();
105  $configCardTypes = array_fill_keys(
106  $this->gatewayConfig->getAvailableCardTypes($this->sessionQuote->getStoreId()),
107  ''
108  );
109 
110  return array_intersect_key($types, $configCardTypes);
111  }
112 
119  private function filterCardTypesForCountry(array $configCardTypes, $countryId)
120  {
121  $filtered = $configCardTypes;
122  $countryCardTypes = $this->gatewayConfig->getCountryAvailableCardTypes(
123  $countryId,
124  $this->sessionQuote->getStoreId()
125  );
126 
127  // filter card types only if specific card types are set for country
128  if (!empty($countryCardTypes)) {
129  $availableTypes = array_fill_keys($countryCardTypes, '');
130  $filtered = array_intersect_key($filtered, $availableTypes);
131  }
132  return $filtered;
133  }
134 
139  private function getVaultPayment()
140  {
141  return $this->paymentDataHelper->getMethodInstance(ConfigProvider::CC_VAULT_CODE);
142  }
143 }
__construct(Context $context, Config $paymentConfig, Quote $sessionQuote, GatewayConfig $gatewayConfig, CcType $ccType, Data $paymentDataHelper, array $data=[])
Definition: Form.php:52