Skip to content

Commit 7fd1efd

Browse files
author
lestare
committed
MAGETWO-55612: “No Payment method available” when customer tries to ship his items to billing restricted country for 2.1.x
1 parent 2347bc6 commit 7fd1efd

File tree

16 files changed

+722
-213
lines changed

16 files changed

+722
-213
lines changed

app/code/Magento/Braintree/Helper/Country.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Braintree\Helper;
77

8+
use Magento\Braintree\Model\Adminhtml\System\Config\Country as CountryConfig;
89
use Magento\Directory\Model\ResourceModel\Country\CollectionFactory;
910

1011
/**
@@ -13,12 +14,12 @@
1314
class Country
1415
{
1516
/**
16-
* @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory
17+
* @var CollectionFactory
1718
*/
1819
private $collectionFactory;
1920

2021
/**
21-
* @var \Magento\Braintree\Model\Adminhtml\System\Config\Country
22+
* @var CountryConfig
2223
*/
2324
private $countryConfig;
2425

@@ -28,13 +29,11 @@ class Country
2829
private $countries;
2930

3031
/**
31-
* @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $factory
32-
* @param \Magento\Braintree\Model\Adminhtml\System\Config\Country $countryConfig
32+
* @param CollectionFactory $factory
33+
* @param CountryConfig $countryConfig
3334
*/
34-
public function __construct(
35-
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $factory,
36-
\Magento\Braintree\Model\Adminhtml\System\Config\Country $countryConfig
37-
) {
35+
public function __construct(CollectionFactory $factory, CountryConfig $countryConfig)
36+
{
3837
$this->collectionFactory = $factory;
3938
$this->countryConfig = $countryConfig;
4039
}
@@ -52,6 +51,7 @@ public function getCountries()
5251
->loadData()
5352
->toOptionArray(false);
5453
}
54+
5555
return $this->countries;
5656
}
5757
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<argument name="code" xsi:type="const">Magento\Braintree\Model\Ui\ConfigProvider::PAYPAL_CODE</argument>
2323
<argument name="infoBlockType" xsi:type="string">BraintreePayPalInfo</argument>
2424
<argument name="valueHandlerPool" xsi:type="object">BraintreePayPalValueHandlerPool</argument>
25+
<argument name="validatorPool" xsi:type="object">BraintreePayPalValidatorPool</argument>
2526
<argument name="commandPool" xsi:type="object">BraintreePayPalCommandPool</argument>
2627
</arguments>
2728
</virtualType>
@@ -379,7 +380,7 @@
379380
</arguments>
380381
</virtualType>
381382

382-
<!-- Value validators infrastructure -->
383+
<!-- Braintree validators infrastructure -->
383384
<virtualType name="BraintreeCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
384385
<arguments>
385386
<argument name="config" xsi:type="object">Magento\Braintree\Gateway\Config\Config</argument>
@@ -392,6 +393,22 @@
392393
</argument>
393394
</arguments>
394395
</virtualType>
396+
<!-- Braintree validators infrastructure -->
397+
398+
<!-- Braintree PayPal validators -->
399+
<virtualType name="BraintreePayPalCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
400+
<arguments>
401+
<argument name="config" xsi:type="object">Magento\Braintree\Gateway\Config\PayPal\Config</argument>
402+
</arguments>
403+
</virtualType>
404+
<virtualType name="BraintreePayPalValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
405+
<arguments>
406+
<argument name="validators" xsi:type="array">
407+
<item name="country" xsi:type="string">BraintreePayPalCountryValidator</item>
408+
</argument>
409+
</arguments>
410+
</virtualType>
411+
<!-- END Braintree PayPal validators -->
395412

396413
<type name="Magento\Braintree\Block\Info">
397414
<arguments>

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ define([
1111
'Magento_Braintree/js/view/payment/adapter',
1212
'Magento_Checkout/js/model/quote',
1313
'Magento_Checkout/js/model/full-screen-loader',
14-
'Magento_Checkout/js/model/payment/additional-validators'
15-
], function ($, _, Component, Braintree, quote, fullScreenLoader, additionalValidators) {
14+
'Magento_Checkout/js/model/payment/additional-validators',
15+
'Magento_Checkout/js/action/create-billing-address'
16+
], function (
17+
$,
18+
_,
19+
Component,
20+
Braintree,
21+
quote,
22+
fullScreenLoader,
23+
additionalValidators,
24+
createBillingAddress
25+
) {
1626
'use strict';
1727

1828
return Component.extend({
@@ -152,14 +162,16 @@ define([
152162
var billingAddress = {
153163
street: [address.streetAddress],
154164
city: address.locality,
155-
regionCode: address.region,
156165
postcode: address.postalCode,
157166
countryId: address.countryCodeAlpha2,
167+
email: customer.email,
158168
firstname: customer.firstName,
159169
lastname: customer.lastName,
160170
telephone: customer.phone
161171
};
162172

173+
billingAddress['region_code'] = address.region;
174+
billingAddress = createBillingAddress(billingAddress);
163175
quote.billingAddress(billingAddress);
164176
},
165177

0 commit comments

Comments
 (0)