Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CVV2Match.php
Go to the documentation of this file.
1 <?php
7 
11 
15 class CVV2Match implements ValidatorInterface
16 {
20  const CVV2MATCH = 'cvv2match';
21 
26  const AMT = 'amt';
27 
31  const ERROR_MESSAGE = 'Card security code does not match.';
32 
34  const RESPONSE_YES = 'y';
35 
36  const RESPONSE_NO = 'n';
37 
42  const CONFIG_ON = 1;
43 
44  const CONFIG_OFF = 0;
45 
46  const CONFIG_NAME = 'avs_security_code';
56  public function validate(DataObject $response, Transparent $transparentModel)
57  {
58  if ($transparentModel->getConfig()->getValue(static::CONFIG_NAME) === static::CONFIG_OFF) {
59  return true;
60  }
61 
62  if ($this->isMatchCvv($response)) {
63  return true;
64  }
65 
66  if ($this->isNotMatchCvv($response)) {
67  $response->setRespmsg(static::ERROR_MESSAGE);
68  return false;
69  }
70 
71  if ($this->isCvvDoNotExists($response)) {
72  return true;
73  }
74 
75  $response->setRespmsg(static::ERROR_MESSAGE);
76  return false;
77  }
78 
85  protected function isMatchCvv(DataObject $response)
86  {
87  $cvvMatch = strtolower((string) $response->getData(static::CVV2MATCH));
88  return $cvvMatch === static::RESPONSE_YES || $cvvMatch === static::RESPONSE_NOT_SUPPORTED;
89  }
90 
97  protected function isNotMatchCvv(DataObject $response)
98  {
99  return strtolower((string) $response->getData(static::CVV2MATCH)) === static::RESPONSE_NO;
100  }
101 
109  {
110  return $response->getData(static::CVV2MATCH) == '';
111  }
112 }
$response
Definition: 404.php:11
validate(DataObject $response, Transparent $transparentModel)
Definition: CVV2Match.php:56