Skip to content

Commit 871c571

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into MC-18467
2 parents 158236c + f087565 commit 871c571

File tree

84 files changed

+3365
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+3365
-87
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AuthorizenetAcceptjs\Gateway\Request;
10+
11+
use Magento\Payment\Gateway\Request\BuilderInterface;
12+
13+
/**
14+
* Stub data builder.
15+
*
16+
* Since the order of params is matters for Authorize.net request,
17+
* this builder is used to reserve a place in builders sequence.
18+
*/
19+
class StubDataBuilder implements BuilderInterface
20+
{
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function build(array $buildSubject): array
25+
{
26+
return [];
27+
}
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\AuthorizenetAcceptjs\Plugin;
7+
8+
use Magento\Framework\View\Asset\Minification;
9+
10+
/**
11+
* Plugin for Magento\Framework\View\Asset\Minification.
12+
*/
13+
class ExcludeFilesFromMinification
14+
{
15+
/**
16+
* Add Accept.js to exclude from minification
17+
*
18+
* @param Minification $subject
19+
* @param array $result
20+
* @param $contentType
21+
*
22+
* @return array
23+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
24+
*/
25+
public function afterGetExcludes(Minification $subject, array $result, $contentType)
26+
{
27+
if ($contentType == 'js') {
28+
$result[] = '/v1/Accept';
29+
}
30+
return $result;
31+
}
32+
}

app/code/Magento/AuthorizenetAcceptjs/etc/adminhtml/di.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,29 @@
1111
<argument name="config" xsi:type="object">Magento\AuthorizenetAcceptjs\Model\Ui\ConfigProvider</argument>
1212
</arguments>
1313
</type>
14+
<virtualType name="AuthorizenetAcceptjsAuthorizeRequest" type="Magento\Payment\Gateway\Request\BuilderComposite">
15+
<arguments>
16+
<argument name="builders" xsi:type="array">
17+
<item name="request_type" xsi:type="string">AuthorizenetAcceptjsTransactionRequestTypeBuilder</item>
18+
<item name="store" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\StoreConfigBuilder</item>
19+
<item name="merchant_account" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\AuthenticationDataBuilder</item>
20+
<item name="transaction_type" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\AuthorizeDataBuilder</item>
21+
<item name="amount" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\AmountDataBuilder</item>
22+
<item name="payment" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\PaymentDataBuilder</item>
23+
<item name="shipping" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\ShippingDataBuilder</item>
24+
<item name="solution" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\SolutionDataBuilder</item>
25+
<item name="order" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\OrderDataBuilder</item>
26+
<item name="po" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\PoDataBuilder</item>
27+
<item name="customer" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\CustomerDataBuilder</item>
28+
<item name="address" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\AddressDataBuilder</item>
29+
<item name="custom_settings" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\CustomSettingsBuilder</item>
30+
<item name="passthrough_data" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\PassthroughDataBuilder</item>
31+
</argument>
32+
</arguments>
33+
</virtualType>
34+
<virtualType name="AuthorizenetAcceptjsAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
35+
<arguments>
36+
<argument name="validator" xsi:type="object">AuthorizenetAcceptjsTransactionValidator</argument>
37+
</arguments>
38+
</virtualType>
1439
</config>

app/code/Magento/AuthorizenetAcceptjs/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
<arguments>
135135
<argument name="requestBuilder" xsi:type="object">AuthorizenetAcceptjsRefundRequest</argument>
136136
<argument name="handler" xsi:type="object">AuthorizenetAcceptjsRefundSettledHandler</argument>
137+
<argument name="validator" xsi:type="object">AuthorizenetAcceptjsTransactionValidator</argument>
137138
</arguments>
138139
</virtualType>
139140
<virtualType name="AuthorizenetAcceptjsCaptureCommand" type="Magento\AuthorizenetAcceptjs\Gateway\Command\CaptureStrategyCommand">
@@ -145,6 +146,7 @@
145146
<arguments>
146147
<argument name="requestBuilder" xsi:type="object">AuthorizenetAcceptjsCaptureRequest</argument>
147148
<argument name="handler" xsi:type="object">AuthorizenetAcceptjsCaptureTransactionHandler</argument>
149+
<argument name="validator" xsi:type="object">AuthorizenetAcceptjsTransactionValidator</argument>
148150
</arguments>
149151
</virtualType>
150152
<virtualType name="AuthorizenetAcceptjsVoidCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
@@ -258,6 +260,7 @@
258260
<item name="po" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\PoDataBuilder</item>
259261
<item name="customer" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\CustomerDataBuilder</item>
260262
<item name="address" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\AddressDataBuilder</item>
263+
<item name="3d_secure" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\StubDataBuilder</item>
261264
<item name="custom_settings" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\CustomSettingsBuilder</item>
262265
<item name="passthrough_data" xsi:type="string">Magento\AuthorizenetAcceptjs\Gateway\Request\PassthroughDataBuilder</item>
263266
</argument>
@@ -425,4 +428,8 @@
425428
<argument name="config" xsi:type="object">Magento\AuthorizenetAcceptjs\Gateway\Config</argument>
426429
</arguments>
427430
</virtualType>
431+
432+
<type name="Magento\Framework\View\Asset\Minification">
433+
<plugin name="excludeAcceptJsFromMin" type="Magento\AuthorizenetAcceptjs\Plugin\ExcludeFilesFromMinification" />
434+
</type>
428435
</config>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AuthorizenetCardinal\Gateway\Request;
10+
11+
use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
12+
use Magento\AuthorizenetCardinal\Model\Config;
13+
use Magento\CardinalCommerce\Model\Response\JwtParserInterface;
14+
use Magento\Payment\Gateway\Request\BuilderInterface;
15+
use Magento\Sales\Model\Order\Payment;
16+
17+
/**
18+
* Adds the cardholder authentication information to the request
19+
*/
20+
class Authorize3DSecureBuilder implements BuilderInterface
21+
{
22+
/**
23+
* @var SubjectReader
24+
*/
25+
private $subjectReader;
26+
27+
/**
28+
* @var Config
29+
*/
30+
private $config;
31+
32+
/**
33+
* @var JwtParserInterface
34+
*/
35+
private $jwtParser;
36+
37+
/**
38+
* @param SubjectReader $subjectReader
39+
* @param Config $config
40+
* @param JwtParserInterface $jwtParser
41+
*/
42+
public function __construct(
43+
SubjectReader $subjectReader,
44+
Config $config,
45+
JwtParserInterface $jwtParser
46+
) {
47+
$this->subjectReader = $subjectReader;
48+
$this->config = $config;
49+
$this->jwtParser = $jwtParser;
50+
}
51+
52+
/**
53+
* @inheritdoc
54+
*/
55+
public function build(array $buildSubject): array
56+
{
57+
if ($this->config->isActive() === false) {
58+
return [];
59+
}
60+
61+
$paymentDO = $this->subjectReader->readPayment($buildSubject);
62+
$payment = $paymentDO->getPayment();
63+
$data = [];
64+
65+
if ($payment instanceof Payment) {
66+
$cardinalJwt = (string)$payment->getAdditionalInformation('cardinalJWT');
67+
$jwtPayload = $this->jwtParser->execute($cardinalJwt);
68+
$eciFlag = $jwtPayload['Payload']['Payment']['ExtendedData']['ECIFlag'] ?? '';
69+
$cavv = $jwtPayload['Payload']['Payment']['ExtendedData']['CAVV'] ?? '';
70+
$data = [
71+
'transactionRequest' => [
72+
'cardholderAuthentication' => [
73+
'authenticationIndicator' => $eciFlag,
74+
'cardholderAuthenticationValue' => $cavv
75+
],
76+
]
77+
];
78+
}
79+
80+
return $data;
81+
}
82+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AuthorizenetCardinal\Gateway\Validator;
10+
11+
use Magento\AuthorizenetAcceptjs\Gateway\SubjectReader;
12+
use Magento\AuthorizenetCardinal\Model\Config;
13+
use Magento\Payment\Gateway\Validator\AbstractValidator;
14+
use Magento\Payment\Gateway\Validator\ResultInterface;
15+
use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
16+
17+
/**
18+
* Validates cardholder authentication verification response code.
19+
*/
20+
class CavvResponseValidator extends AbstractValidator
21+
{
22+
/**
23+
* The result code that authorize.net returns if CAVV passed validation.
24+
*/
25+
const RESULT_CODE_SUCCESS = '2';
26+
27+
/**
28+
* @var SubjectReader
29+
*/
30+
private $subjectReader;
31+
32+
/**
33+
* @var ResultInterfaceFactory
34+
*/
35+
private $resultFactory;
36+
37+
/**
38+
* @var Config
39+
*/
40+
private $config;
41+
42+
/**
43+
* @param ResultInterfaceFactory $resultFactory
44+
* @param SubjectReader $subjectReader
45+
* @param Config $config
46+
*/
47+
public function __construct(
48+
ResultInterfaceFactory $resultFactory,
49+
SubjectReader $subjectReader,
50+
Config $config
51+
) {
52+
parent::__construct($resultFactory);
53+
54+
$this->resultFactory = $resultFactory;
55+
$this->subjectReader = $subjectReader;
56+
$this->config = $config;
57+
}
58+
59+
/**
60+
* @inheritdoc
61+
*/
62+
public function validate(array $validationSubject): ResultInterface
63+
{
64+
if ($this->config->isActive() === false) {
65+
return $this->createResult(true);
66+
}
67+
68+
$response = $this->subjectReader->readResponse($validationSubject);
69+
$transactionResponse = $response['transactionResponse'];
70+
71+
$cavvResultCode = $transactionResponse['cavvResultCode'] ?? '';
72+
$isValid = $cavvResultCode === self::RESULT_CODE_SUCCESS;
73+
$errorCodes = [];
74+
$errorMessages = [];
75+
76+
if (!$isValid) {
77+
$errorCodes[] = $transactionResponse['cavvResultCode'];
78+
$errorMessages[] = 'CAVV failed validation';
79+
}
80+
81+
return $this->createResult($isValid, $errorMessages);
82+
}
83+
}

0 commit comments

Comments
 (0)