Skip to content

Commit 2bf3b78

Browse files
authored
Merge pull request #8 from saphaljha/2.2-develop-PR-port-19634
[Backport] Fixed - Lifetime update syntax error magento#13309
2 parents f7407a4 + fb3115d commit 2bf3b78

File tree

325 files changed

+8163
-822
lines changed

Some content is hidden

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

325 files changed

+8163
-822
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: 21 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,13 @@ public function fetchTransactionInfo(\Magento\Payment\Model\InfoInterface $payme
918926
$payment->setIsTransactionDenied(true);
919927
}
920928
$this->addStatusCommentOnUpdate($payment, $response, $transactionId);
921-
return [];
929+
930+
return $response->getData();
922931
}
923932

924933
/**
934+
* Add statuc comment on update.
935+
*
925936
* @param \Magento\Sales\Model\Order\Payment $payment
926937
* @param \Magento\Framework\DataObject $response
927938
* @param string $transactionId
@@ -996,8 +1007,9 @@ protected function getTransactionResponse($transactionId)
9961007
}
9971008

9981009
/**
999-
* @return \Psr\Log\LoggerInterface
1010+
* Get psr logger.
10001011
*
1012+
* @return \Psr\Log\LoggerInterface
10011013
* @deprecated 100.1.0
10021014
*/
10031015
private function getPsrLogger()
@@ -1038,7 +1050,9 @@ private function getOrderIncrementId(): string
10381050
}
10391051

10401052
/**
1041-
* Checks if filter action is Report Only. Transactions that trigger this filter are processed as normal,
1053+
* Checks if filter action is Report Only.
1054+
*
1055+
* Transactions that trigger this filter are processed as normal,
10421056
* but are also reported in the Merchant Interface as triggering this filter.
10431057
*
10441058
* @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/Authorizenet/view/adminhtml/templates/order/view/info/fraud_details.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ $fraudDetails = $payment->getAdditionalInformation('fraud_details');
4444
<?php endif; ?>
4545

4646
<?php if(!empty($fraudDetails['fraud_filters'])): ?>
47-
<b><?= $block->escapeHtml(__('Fraud Filters')) ?>:
48-
</b></br>
47+
<strong><?= $block->escapeHtml(__('Fraud Filters')) ?>:
48+
</strong></br>
4949
<?php foreach($fraudDetails['fraud_filters'] as $filter): ?>
5050
<?= $block->escapeHtml($filter['name']) ?>:
5151
<?= $block->escapeHtml($filter['action']) ?>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="AdminSlideOutDialogSection">
12+
<element name="closeButton" type="button" selector=".modal-slide._show [data-role='closeBtn']" timeout="30"/>
13+
<element name="cancelButton" type="button" selector="//*[contains(@class, 'modal-slide') and contains(@class, '_show')]//*[contains(@class, 'page-actions')]//button[normalize-space(.)='Cancel']" timeout="30"/>
14+
<element name="doneButton" type="button" selector="//*[contains(@class, 'modal-slide') and contains(@class, '_show')]//*[contains(@class, 'page-actions')]//button[normalize-space(.)='Done']" timeout="30"/>
15+
<element name="saveButton" type="button" selector="//*[contains(@class, 'modal-slide') and contains(@class, '_show')]//*[contains(@class, 'page-actions')]//button[normalize-space(.)='Save']" timeout="30"/>
16+
</section>
17+
</sections>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function __construct(
5454

5555
/**
5656
* @inheritdoc
57+
*
5758
* @throws LocalizedException
5859
*/
5960
public function execute()
@@ -71,7 +72,10 @@ public function execute()
7172
return $resultRedirect->setPath('checkout/onepage/success', ['_secure' => true]);
7273
} catch (\Exception $e) {
7374
$this->logger->critical($e);
74-
$this->messageManager->addExceptionMessage($e, $e->getMessage());
75+
$this->messageManager->addExceptionMessage(
76+
$e,
77+
'The order #' . $quote->getReservedOrderId() . ' cannot be processed.'
78+
);
7579
}
7680

7781
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
@@ -5,14 +5,15 @@
55
*/
66
namespace Magento\Braintree\Model\Paypal\Helper;
77

8-
use Magento\Quote\Model\Quote;
8+
use Magento\Braintree\Model\Paypal\OrderCancellationService;
9+
use Magento\Checkout\Api\AgreementsValidatorInterface;
910
use Magento\Checkout\Helper\Data;
11+
use Magento\Checkout\Model\Type\Onepage;
1012
use Magento\Customer\Model\Group;
1113
use Magento\Customer\Model\Session;
12-
use Magento\Checkout\Model\Type\Onepage;
13-
use Magento\Quote\Api\CartManagementInterface;
1414
use Magento\Framework\Exception\LocalizedException;
15-
use Magento\Checkout\Api\AgreementsValidatorInterface;
15+
use Magento\Quote\Api\CartManagementInterface;
16+
use Magento\Quote\Model\Quote;
1617

1718
/**
1819
* Class OrderPlace
@@ -41,23 +42,29 @@ class OrderPlace extends AbstractHelper
4142
private $checkoutHelper;
4243

4344
/**
44-
* Constructor
45-
*
45+
* @var OrderCancellationService
46+
*/
47+
private $orderCancellationService;
48+
49+
/**
4650
* @param CartManagementInterface $cartManagement
4751
* @param AgreementsValidatorInterface $agreementsValidator
4852
* @param Session $customerSession
4953
* @param Data $checkoutHelper
54+
* @param OrderCancellationService $orderCancellationService
5055
*/
5156
public function __construct(
5257
CartManagementInterface $cartManagement,
5358
AgreementsValidatorInterface $agreementsValidator,
5459
Session $customerSession,
55-
Data $checkoutHelper
60+
Data $checkoutHelper,
61+
OrderCancellationService $orderCancellationService
5662
) {
5763
$this->cartManagement = $cartManagement;
5864
$this->agreementsValidator = $agreementsValidator;
5965
$this->customerSession = $customerSession;
6066
$this->checkoutHelper = $checkoutHelper;
67+
$this->orderCancellationService = $orderCancellationService;
6168
}
6269

6370
/**
@@ -66,7 +73,7 @@ public function __construct(
6673
* @param Quote $quote
6774
* @param array $agreement
6875
* @return void
69-
* @throws LocalizedException
76+
* @throws \Exception
7077
*/
7178
public function execute(Quote $quote, array $agreement)
7279
{
@@ -81,7 +88,12 @@ public function execute(Quote $quote, array $agreement)
8188
$this->disabledQuoteAddressValidation($quote);
8289

8390
$quote->collectTotals();
84-
$this->cartManagement->placeOrder($quote->getId());
91+
try {
92+
$this->cartManagement->placeOrder($quote->getId());
93+
} catch (\Exception $e) {
94+
$this->orderCancellationService->execute($quote->getReservedOrderId());
95+
throw $e;
96+
}
8597
}
8698

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

0 commit comments

Comments
 (0)