Skip to content

Commit 8fca683

Browse files
ENGCOM-3471: [Framework] New Link is not correctly shown as Current if contains default parts #19134
- Merge Pull Request #19134 from eduard13/magento2:2.3-develop-19099-issue - Merged commits: 1. 29640f1 2. fea9aaf 3. 508832b 4. 769e46d 5. 4241175 6. 3ee9190 7. 2f8314c 8. 64daebd 9. a912d27
2 parents a1dd861 + a912d27 commit 8fca683

File tree

69 files changed

+1729
-285
lines changed

Some content is hidden

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

69 files changed

+1729
-285
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+
declare(strict_types=1);
7+
8+
namespace Magento\Authorizenet\Block\Adminhtml\Order\View\Info;
9+
10+
use Magento\Framework\Phrase;
11+
use Magento\Payment\Block\ConfigurableInfo;
12+
13+
/**
14+
* Payment information block for Authorize.net payment method
15+
*/
16+
class PaymentDetails extends ConfigurableInfo
17+
{
18+
/**
19+
* Returns localized label for payment info block
20+
*
21+
* @param string $field
22+
* @return string | Phrase
23+
*/
24+
protected function getLabel($field)
25+
{
26+
return __($field);
27+
}
28+
}

app/code/Magento/Authorizenet/Model/Directpost.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Directpost extends \Magento\Authorizenet\Model\Authorizenet implements Tra
2727
/**
2828
* @var string
2929
*/
30-
protected $_infoBlockType = \Magento\Payment\Block\Info::class;
30+
protected $_infoBlockType = \Magento\Authorizenet\Block\Adminhtml\Order\View\Info\PaymentDetails::class;
3131

3232
/**
3333
* Payment Method feature
@@ -371,8 +371,7 @@ public function void(\Magento\Payment\Model\InfoInterface $payment)
371371
}
372372

373373
/**
374-
* Refund the amount
375-
* Need to decode last 4 digits for request.
374+
* Refund the amount need to decode last 4 digits for request.
376375
*
377376
* @param \Magento\Framework\DataObject|\Magento\Payment\Model\InfoInterface $payment
378377
* @param float $amount
@@ -626,6 +625,14 @@ protected function fillPaymentByResponse(\Magento\Framework\DataObject $payment)
626625
$payment->setIsTransactionPending(true)
627626
->setIsFraudDetected(true);
628627
}
628+
629+
$additionalInformationKeys = explode(',', $this->getValue('paymentInfoKeys'));
630+
foreach ($additionalInformationKeys as $paymentInfoKey) {
631+
$paymentInfoValue = $response->getDataByKey($paymentInfoKey);
632+
if ($paymentInfoValue !== null) {
633+
$payment->setAdditionalInformation($paymentInfoKey, $paymentInfoValue);
634+
}
635+
}
629636
}
630637

631638
/**
@@ -682,6 +689,7 @@ protected function matchAmount($amount)
682689

683690
/**
684691
* Operate with order using information from Authorize.net.
692+
*
685693
* Authorize order or authorize and capture it.
686694
*
687695
* @param \Magento\Sales\Model\Order $order
@@ -858,7 +866,7 @@ public function getConfigInterface()
858866
* Getter for specified value according to set payment method code
859867
*
860868
* @param mixed $key
861-
* @param null $storeId
869+
* @param int|string|null|\Magento\Store\Model\Store $storeId
862870
* @return mixed
863871
*/
864872
public function getValue($key, $storeId = null)
@@ -918,10 +926,12 @@ public function fetchTransactionInfo(\Magento\Payment\Model\InfoInterface $payme
918926
$payment->setIsTransactionDenied(true);
919927
}
920928
$this->addStatusCommentOnUpdate($payment, $response, $transactionId);
921-
return [];
929+
return $response->getData();
922930
}
923931

924932
/**
933+
* Add statuc comment on update.
934+
*
925935
* @param \Magento\Sales\Model\Order\Payment $payment
926936
* @param \Magento\Framework\DataObject $response
927937
* @param string $transactionId
@@ -996,8 +1006,9 @@ protected function getTransactionResponse($transactionId)
9961006
}
9971007

9981008
/**
999-
* @return \Psr\Log\LoggerInterface
1009+
* Get psr logger.
10001010
*
1011+
* @return \Psr\Log\LoggerInterface
10011012
* @deprecated 100.1.0
10021013
*/
10031014
private function getPsrLogger()
@@ -1038,7 +1049,9 @@ private function getOrderIncrementId(): string
10381049
}
10391050

10401051
/**
1041-
* Checks if filter action is Report Only. Transactions that trigger this filter are processed as normal,
1052+
* Checks if filter action is Report Only.
1053+
*
1054+
* Transactions that trigger this filter are processed as normal,
10421055
* but are also reported in the Merchant Interface as triggering this filter.
10431056
*
10441057
* @param string $fdsFilterAction

app/code/Magento/Authorizenet/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<cgi_url>https://secure.authorize.net/gateway/transact.dll</cgi_url>
3333
<cgi_url_td_test_mode>https://apitest.authorize.net/xml/v1/request.api</cgi_url_td_test_mode>
3434
<cgi_url_td>https://api2.authorize.net/xml/v1/request.api</cgi_url_td>
35+
<paymentInfoKeys>x_card_type,x_account_number,x_avs_code,x_auth_code,x_response_reason_text,x_cvv2_resp_code</paymentInfoKeys>
3536
</authorizenet_directpost>
3637
</payment>
3738
</default>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@
3535
</argument>
3636
</arguments>
3737
</type>
38+
<type name="Magento\Authorizenet\Block\Adminhtml\Order\View\Info\PaymentDetails">
39+
<arguments>
40+
<argument name="config" xsi:type="object">Magento\Authorizenet\Model\Directpost</argument>
41+
</arguments>
42+
</type>
3843
</config>

app/code/Magento/Authorizenet/i18n/en_US.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,9 @@ Debug,Debug
6767
"Minimum Order Total","Minimum Order Total"
6868
"Maximum Order Total","Maximum Order Total"
6969
"Sort Order","Sort Order"
70+
"x_card_type","Credit Card Type"
71+
"x_account_number", "Credit Card Number"
72+
"x_avs_code","AVS Response Code"
73+
"x_auth_code","Processor Authentication Code"
74+
"x_response_reason_text","Processor Response Text"
75+
"x_cvv2_resp_code","CVV2 Response Code"

app/code/Magento/Braintree/Controller/Paypal/PlaceOrder.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Braintree\Model\Paypal\Helper;
1010
use Magento\Checkout\Model\Session;
1111
use Magento\Framework\App\Action\Context;
12+
use Magento\Framework\App\Action\HttpPostActionInterface;
1213
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\Controller\ResultFactory;
1415
use Magento\Framework\Exception\LocalizedException;
@@ -17,7 +18,7 @@
1718
/**
1819
* Class PlaceOrder
1920
*/
20-
class PlaceOrder extends AbstractAction
21+
class PlaceOrder extends AbstractAction implements HttpPostActionInterface
2122
{
2223
/**
2324
* @var Helper\OrderPlace
@@ -54,6 +55,7 @@ public function __construct(
5455

5556
/**
5657
* @inheritdoc
58+
*
5759
* @throws LocalizedException
5860
*/
5961
public function execute()
@@ -71,7 +73,10 @@ public function execute()
7173
return $resultRedirect->setPath('checkout/onepage/success', ['_secure' => true]);
7274
} catch (\Exception $e) {
7375
$this->logger->critical($e);
74-
$this->messageManager->addExceptionMessage($e, $e->getMessage());
76+
$this->messageManager->addExceptionMessage(
77+
$e,
78+
'The order #' . $quote->getReservedOrderId() . ' cannot be processed.'
79+
);
7580
}
7681

7782
return $resultRedirect->setPath('checkout/cart', ['_secure' => true]);

app/code/Magento/Braintree/Model/Paypal/Helper/OrderPlace.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
namespace Magento\Braintree\Model\Paypal\Helper;
88

9-
use Magento\Quote\Model\Quote;
9+
use Magento\Braintree\Model\Paypal\OrderCancellationService;
10+
use Magento\Checkout\Api\AgreementsValidatorInterface;
1011
use Magento\Checkout\Helper\Data;
12+
use Magento\Checkout\Model\Type\Onepage;
1113
use Magento\Customer\Model\Group;
1214
use Magento\Customer\Model\Session;
13-
use Magento\Checkout\Model\Type\Onepage;
14-
use Magento\Quote\Api\CartManagementInterface;
1515
use Magento\Framework\Exception\LocalizedException;
16-
use Magento\Checkout\Api\AgreementsValidatorInterface;
16+
use Magento\Quote\Api\CartManagementInterface;
17+
use Magento\Quote\Model\Quote;
1718

1819
/**
1920
* Class OrderPlace
@@ -42,23 +43,29 @@ class OrderPlace extends AbstractHelper
4243
private $checkoutHelper;
4344

4445
/**
45-
* Constructor
46-
*
46+
* @var OrderCancellationService
47+
*/
48+
private $orderCancellationService;
49+
50+
/**
4751
* @param CartManagementInterface $cartManagement
4852
* @param AgreementsValidatorInterface $agreementsValidator
4953
* @param Session $customerSession
5054
* @param Data $checkoutHelper
55+
* @param OrderCancellationService $orderCancellationService
5156
*/
5257
public function __construct(
5358
CartManagementInterface $cartManagement,
5459
AgreementsValidatorInterface $agreementsValidator,
5560
Session $customerSession,
56-
Data $checkoutHelper
61+
Data $checkoutHelper,
62+
OrderCancellationService $orderCancellationService
5763
) {
5864
$this->cartManagement = $cartManagement;
5965
$this->agreementsValidator = $agreementsValidator;
6066
$this->customerSession = $customerSession;
6167
$this->checkoutHelper = $checkoutHelper;
68+
$this->orderCancellationService = $orderCancellationService;
6269
}
6370

6471
/**
@@ -67,7 +74,7 @@ public function __construct(
6774
* @param Quote $quote
6875
* @param array $agreement
6976
* @return void
70-
* @throws LocalizedException
77+
* @throws \Exception
7178
*/
7279
public function execute(Quote $quote, array $agreement)
7380
{
@@ -84,7 +91,12 @@ public function execute(Quote $quote, array $agreement)
8491
$this->disabledQuoteAddressValidation($quote);
8592

8693
$quote->collectTotals();
87-
$this->cartManagement->placeOrder($quote->getId());
94+
try {
95+
$this->cartManagement->placeOrder($quote->getId());
96+
} catch (\Exception $e) {
97+
$this->orderCancellationService->execute($quote->getReservedOrderId());
98+
throw $e;
99+
}
88100
}
89101

90102
/**
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Braintree\Model\Paypal;
9+
10+
use Magento\Framework\Api\SearchCriteriaBuilder;
11+
use Magento\Sales\Api\Data\OrderInterface;
12+
use Magento\Sales\Api\OrderRepositoryInterface;
13+
14+
/**
15+
* The service to cancel an order and void authorization transaction.
16+
*/
17+
class OrderCancellationService
18+
{
19+
/**
20+
* @var OrderRepositoryInterface
21+
*/
22+
private $orderRepository;
23+
24+
/**
25+
* @var SearchCriteriaBuilder
26+
*/
27+
private $searchCriteriaBuilder;
28+
29+
/**
30+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
31+
* @param OrderRepositoryInterface $orderRepository
32+
*/
33+
public function __construct(
34+
SearchCriteriaBuilder $searchCriteriaBuilder,
35+
OrderRepositoryInterface $orderRepository
36+
) {
37+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
38+
$this->orderRepository = $orderRepository;
39+
}
40+
41+
/**
42+
* Cancels an order and authorization transaction.
43+
*
44+
* @param string $incrementId
45+
* @return bool
46+
*/
47+
public function execute(string $incrementId): bool
48+
{
49+
$order = $this->getOrder($incrementId);
50+
if ($order === null) {
51+
return false;
52+
}
53+
54+
// `\Magento\Sales\Model\Service\OrderService::cancel` cannot be used for cancellation as the service uses
55+
// the order repository with outdated payment method instance (ex. contains Vault instead of Braintree)
56+
$order->cancel();
57+
$this->orderRepository->save($order);
58+
return true;
59+
}
60+
61+
/**
62+
* Gets order by increment ID.
63+
*
64+
* @param string $incrementId
65+
* @return OrderInterface|null
66+
*/
67+
private function getOrder(string $incrementId)
68+
{
69+
$searchCriteria = $this->searchCriteriaBuilder->addFilter(OrderInterface::INCREMENT_ID, $incrementId)
70+
->create();
71+
72+
$items = $this->orderRepository->getList($searchCriteria)
73+
->getItems();
74+
75+
return array_pop($items);
76+
}
77+
}

0 commit comments

Comments
 (0)