Skip to content

Commit 32a9110

Browse files
committed
MAGETWO-90310: [Magento Cloud] - PayPal pop up does not work with virtual product (gift card)
1 parent f658498 commit 32a9110

File tree

5 files changed

+263
-56
lines changed

5 files changed

+263
-56
lines changed

app/code/Magento/Payment/Model/Method/AbstractMethod.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
namespace Magento\Payment\Model\Method;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\DataObject;
1011
use Magento\Payment\Model\InfoInterface;
1112
use Magento\Payment\Model\MethodInterface;
1213
use Magento\Payment\Observer\AbstractDataAssignObserver;
1314
use Magento\Quote\Api\Data\PaymentMethodInterface;
1415
use Magento\Sales\Model\Order\Payment;
16+
use Magento\Directory\Helper\Data as DirectoryHelper;
1517

1618
/**
1719
* Payment method abstract model
@@ -194,6 +196,11 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl
194196
*/
195197
protected $logger;
196198

199+
/**
200+
* @var DirectoryHelper
201+
*/
202+
private $directory;
203+
197204
/**
198205
* @param \Magento\Framework\Model\Context $context
199206
* @param \Magento\Framework\Registry $registry
@@ -205,6 +212,7 @@ abstract class AbstractMethod extends \Magento\Framework\Model\AbstractExtensibl
205212
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
206213
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
207214
* @param array $data
215+
* @param DirectoryHelper $directory
208216
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
209217
*/
210218
public function __construct(
@@ -217,7 +225,8 @@ public function __construct(
217225
\Magento\Payment\Model\Method\Logger $logger,
218226
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
219227
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
220-
array $data = []
228+
array $data = [],
229+
DirectoryHelper $directory = null
221230
) {
222231
parent::__construct(
223232
$context,
@@ -231,6 +240,7 @@ public function __construct(
231240
$this->_paymentData = $paymentData;
232241
$this->_scopeConfig = $scopeConfig;
233242
$this->logger = $logger;
243+
$this->directory = $directory ?: ObjectManager::getInstance()->get(DirectoryHelper::class);
234244
$this->initializeData($data);
235245
}
236246

@@ -584,11 +594,14 @@ public function validate()
584594
} else {
585595
$billingCountry = $paymentInfo->getQuote()->getBillingAddress()->getCountryId();
586596
}
597+
$billingCountry = $billingCountry ?: $this->directory->getDefaultCountry();
598+
587599
if (!$this->canUseForCountry($billingCountry)) {
588600
throw new \Magento\Framework\Exception\LocalizedException(
589601
__('You can\'t use the payment type you selected to make payments to the billing country.')
590602
);
591603
}
604+
592605
return $this;
593606
}
594607

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Paypal\Controller\Express\AbstractExpress;
99

10+
use Magento\Framework\Exception\LocalizedException;
1011
use Magento\Paypal\Model\Api\ProcessableException as ApiProcessableException;
1112

1213
/**
@@ -118,15 +119,27 @@ public function execute()
118119
return;
119120
} catch (ApiProcessableException $e) {
120121
$this->_processPaypalApiError($e);
122+
} catch (LocalizedException $e) {
123+
$this->processException($e, $e->getRawMessage());
121124
} catch (\Exception $e) {
122-
$this->messageManager->addExceptionMessage(
123-
$e,
124-
__('We can\'t place the order.')
125-
);
126-
$this->_redirect('*/*/review');
125+
$this->processException($e, 'We can\'t place the order.');
127126
}
128127
}
129128

129+
/**
130+
* Process exception.
131+
*
132+
* @param \Exception $exception
133+
* @param string $message
134+
*
135+
* @return void
136+
*/
137+
private function processException(\Exception $exception, string $message): void
138+
{
139+
$this->messageManager->addExceptionMessage($exception, __($message));
140+
$this->_redirect('*/*/review');
141+
}
142+
130143
/**
131144
* Process PayPal API's processable errors
132145
*

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,12 @@ protected function _setExportedAddressData($address, $exportedAddress)
897897
{
898898
// Exported data is more priority if we came from Express Checkout button
899899
$isButton = (bool)$this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON);
900-
if (!$isButton) {
900+
901+
// Since country is required field for billing and shipping address,
902+
// we consider the address information to be empty if country is empty.
903+
$isEmptyAddress = ($address->getCountryId() === null);
904+
905+
if (!$isButton && !$isEmptyAddress) {
901906
return;
902907
}
903908

0 commit comments

Comments
 (0)