Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FraudHandler.php
Go to the documentation of this file.
1 <?php
7 
14 
19 {
23  const RESPONSE_MESSAGE = 'respmsg';
24 
28  const FRAUD_RULES_XML = 'fps_prexmldata';
29 
33  private $paypalInfoManager;
34 
40  private $xmlSecurity;
41 
48  public function __construct(Info $paypalInfoManager, Security $xmlSecurity)
49  {
50  $this->paypalInfoManager = $paypalInfoManager;
51  $this->xmlSecurity = $xmlSecurity;
52  }
53 
58  {
59  if (!in_array(
60  $response->getData('result'),
61  [
64  ]
65  )) {
66  return;
67  }
68 
69  $fraudMessages = ['RESPMSG' => $response->getData(self::RESPONSE_MESSAGE)];
70  if ($response->getData(self::FRAUD_RULES_XML)) {
71  $fraudMessages = array_merge(
72  $fraudMessages,
73  $this->getFraudRulesDictionary($response->getData(self::FRAUD_RULES_XML))
74  );
75  }
76 
77  $this->paypalInfoManager->importToPayment(
78  [
79  Info::FRAUD_FILTERS => array_merge(
80  $fraudMessages,
81  (array)$payment->getAdditionalInformation(Info::FRAUD_FILTERS)
82  )
83  ],
84  $payment
85  );
86  }
87 
95  private function getFraudRulesDictionary($rulesString)
96  {
97  $rules = [];
98 
99  if (!$this->xmlSecurity->scan($rulesString)) {
100  return $rules;
101  }
102 
103  try {
104  $rulesXml = new \SimpleXMLElement($rulesString);
105  foreach ($rulesXml->{'rule'} as $rule) {
106  $rules[(string)$rule->{'ruleDescription'}] = (string)$rule->{'triggeredMessage'};
107  }
108  } catch (\Exception $e) {
109  } finally {
110  libxml_use_internal_errors(false);
111  }
112 
113  return $rules;
114  }
115 }
$response
Definition: 404.php:11
__construct(Info $paypalInfoManager, Security $xmlSecurity)
$payment
Definition: order.php:17
handle(InfoInterface $payment, DataObject $response)