Skip to content

Commit 21ce591

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-96138' into 2.3-develop
2 parents c7af28a + cfcb773 commit 21ce591

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

app/code/Magento/Paypal/Controller/Express/AbstractExpress/ShippingOptionsCallback.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
*/
77
namespace Magento\Paypal\Controller\Express\AbstractExpress;
88

9-
class ShippingOptionsCallback extends \Magento\Paypal\Controller\Express\AbstractExpress
9+
use Magento\Framework\App\CsrfAwareActionInterface;
10+
use Magento\Paypal\Controller\Express\AbstractExpress;
11+
use Magento\Framework\App\Request\InvalidRequestException;
12+
use Magento\Framework\App\RequestInterface;
13+
14+
/**
15+
* Returns shipping rates by server-to-server request from PayPal.
16+
*
17+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
*/
19+
class ShippingOptionsCallback extends AbstractExpress implements CsrfAwareActionInterface
1020
{
1121
/**
1222
* @var \Magento\Quote\Api\CartRepositoryInterface
@@ -65,4 +75,21 @@ public function execute()
6575
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
6676
}
6777
}
78+
79+
/**
80+
* @inheritDoc
81+
*/
82+
public function createCsrfValidationException(
83+
RequestInterface $request
84+
): ?InvalidRequestException {
85+
return null;
86+
}
87+
88+
/**
89+
* @inheritDoc
90+
*/
91+
public function validateForCsrf(RequestInterface $request): ?bool
92+
{
93+
return true;
94+
}
6895
}

app/code/Magento/Paypal/Model/Express/Checkout.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ protected static function cmpShippingOptions(DataObject $option1, DataObject $op
10761076
*/
10771077
protected function _matchShippingMethodCode(Address $address, $selectedCode)
10781078
{
1079+
$address->collectShippingRates();
10791080
$options = $this->_prepareShippingOptions($address, false);
10801081
foreach ($options as $option) {
10811082
if ($selectedCode === $option['code'] // the proper case as outlined in documentation

dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function setUp()
7272

7373
$this->api = $this->getMockBuilder(Nvp::class)
7474
->disableOriginalConstructor()
75-
->setMethods(['call', 'getExportedShippingAddress', 'getExportedBillingAddress'])
75+
->setMethods(['call', 'getExportedShippingAddress', 'getExportedBillingAddress', 'getShippingRateCode'])
7676
->getMock();
7777

7878
$this->api->expects($this->any())
@@ -302,6 +302,8 @@ public function testReturnFromPaypal()
302302
public function testReturnFromPaypalButton()
303303
{
304304
$quote = $this->getFixtureQuote();
305+
$quote->getShippingAddress()->setShippingMethod('');
306+
305307
$this->prepareCheckoutModel($quote);
306308
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 1);
307309

@@ -317,6 +319,8 @@ public function testReturnFromPaypalButton()
317319
$this->assertEquals($exportedShippingData['telephone'], $shippingAddress->getTelephone());
318320
$this->assertEquals($exportedShippingData['email'], $shippingAddress->getEmail());
319321

322+
$this->assertEquals('flatrate_flatrate', $shippingAddress->getShippingMethod());
323+
320324
$this->assertEquals([$exportedShippingData['street']], $billingAddress->getStreet());
321325
$this->assertEquals($exportedShippingData['firstname'], $billingAddress->getFirstname());
322326
$this->assertEquals($exportedShippingData['city'], $billingAddress->getCity());
@@ -551,6 +555,9 @@ private function prepareCheckoutModel(Quote $quote, $prefix = '')
551555
$this->api->method('getExportedShippingAddress')
552556
->willReturn($exportedShippingAddress);
553557

558+
$this->api->method('getShippingRateCode')
559+
->willReturn('flatrate_flatrate Flat Rate - Fixed');
560+
554561
$this->paypalInfo->method('importToPayment')
555562
->with($this->api, $quote->getPayment());
556563
}
@@ -573,7 +580,7 @@ private function getExportedData(): array
573580
'city' => 'Denver',
574581
'street' => '66 Pearl St',
575582
'postcode' => '80203',
576-
'telephone' => '555-555-555'
583+
'telephone' => '555-555-555',
577584
],
578585
'billing' => [
579586
'email' => 'customer@example.com',

0 commit comments

Comments
 (0)