1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Gateway\Response;
use Magento\Payment\Gateway\Helper\ContextHelper;
use Magento\Braintree\Gateway\SubjectReader;
use Magento\Payment\Gateway\Response\HandlerInterface;
/**
* Class RiskDataHandler
*/
class RiskDataHandler implements HandlerInterface
{
/**
* Risk data id
*/
const RISK_DATA_ID = 'riskDataId';
/**
* The possible values of the risk decision are Not Evaluated, Approve, Review, and Decline
*/
const RISK_DATA_DECISION = 'riskDataDecision';
/**
* Risk data Review status
*/
private static $statusReview = 'Review';
/**
* @var SubjectReader
*/
private $subjectReader;
/**
* Constructor
*
* @param SubjectReader $subjectReader
*/
public function __construct(SubjectReader $subjectReader)
{
$this->subjectReader = $subjectReader;
}
/**
* Handles response
*
* @param array $handlingSubject
* @param array $response
* @return void
*/
public function handle(array $handlingSubject, array $response)
{
$paymentDO = $this->subjectReader->readPayment($handlingSubject);
/** @var \Braintree\Transaction $transaction */
$transaction = $this->subjectReader->readTransaction($response);
if (!isset($transaction->riskData)) {
return;
}
$payment = $paymentDO->getPayment();
ContextHelper::assertOrderPayment($payment);
$payment->setAdditionalInformation(self::RISK_DATA_ID, $transaction->riskData->id);
$payment->setAdditionalInformation(self::RISK_DATA_DECISION, $transaction->riskData->decision);
// mark payment as fraud
if ($transaction->riskData->decision === self::$statusReview) {
$payment->setIsFraudDetected(true);
}
}
}