From 783645893332cdff897fc53f294d8bd2191bf6e0 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Mon, 5 Sep 2016 18:15:36 +0300 Subject: [PATCH 01/13] =?UTF-8?q?MAGETWO-57923:=20=E2=80=9CNo=20Payment=20?= =?UTF-8?q?method=20available=E2=80=9D=20when=20customer=20tries=20to=20sh?= =?UTF-8?q?ip=20his=20items=20to=20billing=20restricted=20country?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added configuration option for billing address displays on payment step - Added validator pool for Braintree PayPal - Fixed vault payments comparator callback - Updated checkout layout processor for new configuration option --- app/code/Magento/Braintree/Helper/Country.php | 2 - app/code/Magento/Braintree/etc/di.xml | 19 +- .../Block/Checkout/LayoutProcessor.php | 222 +++++++++----- app/code/Magento/Checkout/Helper/Data.php | 14 + .../BillingAddressDisplayOptions.php | 39 +++ .../Checkout/Model/DefaultConfigProvider.php | 1 + .../Block/Checkout/LayoutProcessorTest.php | 276 ++++++++++++++++++ .../Magento/Checkout/etc/adminhtml/system.xml | 4 + .../frontend/web/js/view/billing-address.js | 37 ++- .../web/template/billing-address.html | 4 +- .../CanUseForCountry/CountryProvider.php | 4 +- .../CanUseForCountry/CountryProviderTest.php | 130 +++++++-- .../Vault/Model/Ui/TokensConfigProvider.php | 6 +- .../Model/Ui/TokensConfigProviderTest.php | 2 +- .../frontend/web/js/view/payment/vault.js | 3 +- .../Model/Ui/TokensConfigProviderTest.php | 2 +- 16 files changed, 637 insertions(+), 128 deletions(-) create mode 100644 app/code/Magento/Checkout/Model/Adminhtml/BillingAddressDisplayOptions.php create mode 100644 app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php diff --git a/app/code/Magento/Braintree/Helper/Country.php b/app/code/Magento/Braintree/Helper/Country.php index 3a3116b0d9ac0..3067c95d5e373 100644 --- a/app/code/Magento/Braintree/Helper/Country.php +++ b/app/code/Magento/Braintree/Helper/Country.php @@ -5,8 +5,6 @@ */ namespace Magento\Braintree\Helper; -use Magento\Directory\Model\ResourceModel\Country\CollectionFactory; - /** * Class Country */ diff --git a/app/code/Magento/Braintree/etc/di.xml b/app/code/Magento/Braintree/etc/di.xml index 849a3039fc361..d051ef78cfcd2 100644 --- a/app/code/Magento/Braintree/etc/di.xml +++ b/app/code/Magento/Braintree/etc/di.xml @@ -22,6 +22,7 @@ Magento\Braintree\Model\Ui\PayPal\ConfigProvider::PAYPAL_CODE BraintreePayPalInfo BraintreePayPalValueHandlerPool + BraintreePayPalValidatorPool BraintreePayPalCommandPool @@ -474,7 +475,7 @@ - + Magento\Braintree\Gateway\Config\Config @@ -487,6 +488,22 @@ + + + + + + Magento\Braintree\Gateway\Config\PayPal\Config + + + + + + BraintreePayPalCountryValidator + + + + diff --git a/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php b/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php index 646137310cb51..1b2c744419891 100644 --- a/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php +++ b/app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php @@ -5,6 +5,7 @@ */ namespace Magento\Checkout\Block\Checkout; +use Magento\Checkout\Helper\Data; use Magento\Framework\App\ObjectManager; class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcessorInterface @@ -29,6 +30,11 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso */ private $options; + /** + * @var Data + */ + private $checkoutDataHelper; + /** * @param \Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider * @param \Magento\Ui\Component\Form\AttributeMapper $attributeMapper @@ -133,23 +139,12 @@ public function process($jsLayout) if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] ['payment']['children'] )) { - if (!isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] - ['payment']['children']['payments-list']['children'])) { - $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] - ['payment']['children']['payments-list']['children'] = []; - } - $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] - ['payment']['children']['payments-list']['children'] = - array_merge_recursive( - $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] - ['payment']['children']['payments-list']['children'], - $this->processPaymentConfiguration( - $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] - ['payment']['children']['renders']['children'], - $elements - ) - ); + ['payment']['children'] = $this->processPaymentChildrenComponents( + $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children'] + ['payment']['children'], + $elements + ); } if (isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step'] @@ -168,6 +163,44 @@ public function process($jsLayout) return $jsLayout; } + /** + * Appends billing address form component to payment layout + * @param array $paymentLayout + * @param array $elements + * @return array + */ + private function processPaymentChildrenComponents(array $paymentLayout, array $elements) + { + if (!isset($paymentLayout['payments-list']['children'])) { + $paymentLayout['payments-list']['children'] = []; + } + + if (!isset($paymentLayout['afterMethods']['children'])) { + $paymentLayout['afterMethods']['children'] = []; + } + + // The if billing address should be displayed on Payment method or page + if ($this->getCheckoutDataHelper()->isDisplayBillingOnPaymentMethodAvailable()) { + $paymentLayout['payments-list']['children'] = + array_merge_recursive( + $paymentLayout['payments-list']['children'], + $this->processPaymentConfiguration( + $paymentLayout['renders']['children'], + $elements + ) + ); + } else { + $component['billing-address-form'] = $this->getBillingAddressComponent('shared', $elements); + $paymentLayout['afterMethods']['children'] = + array_merge_recursive( + $component, + $paymentLayout['afterMethods']['children'] + ); + } + + return $paymentLayout; + } + /** * Inject billing address component into every payment component * @@ -183,75 +216,102 @@ private function processPaymentConfiguration(array &$configuration, array $eleme if (empty($paymentComponent['isBillingAddressRequired'])) { continue; } - $output[$paymentCode . '-form'] = [ - 'component' => 'Magento_Checkout/js/view/billing-address', - 'displayArea' => 'billing-address-form-' . $paymentCode, - 'provider' => 'checkoutProvider', - 'deps' => 'checkoutProvider', - 'dataScopePrefix' => 'billingAddress' . $paymentCode, - 'sortOrder' => 1, - 'children' => [ - 'form-fields' => [ - 'component' => 'uiComponent', - 'displayArea' => 'additional-fieldsets', - 'children' => $this->merger->merge( - $elements, - 'checkoutProvider', - 'billingAddress' . $paymentCode, - [ - 'country_id' => [ - 'sortOrder' => 115, - ], - 'region' => [ - 'visible' => false, - ], - 'region_id' => [ - 'component' => 'Magento_Ui/js/form/element/region', - 'config' => [ - 'template' => 'ui/form/field', - 'elementTmpl' => 'ui/form/element/select', - 'customEntry' => 'billingAddress' . $paymentCode . '.region', - ], - 'validation' => [ - 'required-entry' => true, - ], - 'filterBy' => [ - 'target' => '${ $.provider }:${ $.parentScope }.country_id', - 'field' => 'country_id', - ], - ], - 'postcode' => [ - 'component' => 'Magento_Ui/js/form/element/post-code', - 'validation' => [ - 'required-entry' => true, - ], - ], - 'company' => [ - 'validation' => [ - 'min_text_length' => 0, - ], - ], - 'fax' => [ - 'validation' => [ - 'min_text_length' => 0, - ], - ], - 'telephone' => [ - 'config' => [ - 'tooltip' => [ - 'description' => __('For delivery questions.'), - ], - ], - ], - ] - ), - ], - ], - ]; + $output[$paymentCode . '-form'] = $this->getBillingAddressComponent($paymentCode, $elements); } unset($configuration[$paymentGroup]['methods']); } return $output; } + + /** + * Gets billing address component details + * + * @param string $paymentCode + * @param array $elements + * @return array + */ + private function getBillingAddressComponent($paymentCode, $elements) + { + return [ + 'component' => 'Magento_Checkout/js/view/billing-address', + 'displayArea' => 'billing-address-form-' . $paymentCode, + 'provider' => 'checkoutProvider', + 'deps' => 'checkoutProvider', + 'dataScopePrefix' => 'billingAddress' . $paymentCode, + 'sortOrder' => 1, + 'children' => [ + 'form-fields' => [ + 'component' => 'uiComponent', + 'displayArea' => 'additional-fieldsets', + 'children' => $this->merger->merge( + $elements, + 'checkoutProvider', + 'billingAddress' . $paymentCode, + [ + 'country_id' => [ + 'sortOrder' => 115, + ], + 'region' => [ + 'visible' => false, + ], + 'region_id' => [ + 'component' => 'Magento_Ui/js/form/element/region', + 'config' => [ + 'template' => 'ui/form/field', + 'elementTmpl' => 'ui/form/element/select', + 'customEntry' => 'billingAddress' . $paymentCode . '.region', + ], + 'validation' => [ + 'required-entry' => true, + ], + 'filterBy' => [ + 'target' => '${ $.provider }:${ $.parentScope }.country_id', + 'field' => 'country_id', + ], + ], + 'postcode' => [ + 'component' => 'Magento_Ui/js/form/element/post-code', + 'validation' => [ + 'required-entry' => true, + ], + ], + 'company' => [ + 'validation' => [ + 'min_text_length' => 0, + ], + ], + 'fax' => [ + 'validation' => [ + 'min_text_length' => 0, + ], + ], + 'telephone' => [ + 'config' => [ + 'tooltip' => [ + 'description' => __('For delivery questions.'), + ], + ], + ], + ] + ), + ], + ], + ]; + } + + /** + * Get checkout data helper instance + * + * @return Data + * @deprecated + */ + private function getCheckoutDataHelper() + { + if (!$this->checkoutDataHelper) { + $this->checkoutDataHelper = ObjectManager::getInstance()->get(Data::class); + } + + return $this->checkoutDataHelper; + } } diff --git a/app/code/Magento/Checkout/Helper/Data.php b/app/code/Magento/Checkout/Helper/Data.php index 2073ffe87d4d6..b54d3187949e4 100644 --- a/app/code/Magento/Checkout/Helper/Data.php +++ b/app/code/Magento/Checkout/Helper/Data.php @@ -8,6 +8,7 @@ use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Quote\Model\Quote\Item\AbstractItem; use Magento\Store\Model\Store; +use Magento\Store\Model\ScopeInterface; /** * Checkout default helper @@ -400,4 +401,17 @@ public function isCustomerMustBeLogged() \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } + + /** + * Checks if display billing address on payment method is available, otherwise + * billing address should be display on payment page + * @return bool + */ + public function isDisplayBillingOnPaymentMethodAvailable() + { + return (bool) !$this->scopeConfig->getValue( + 'checkout/options/display_billing_address_on', + ScopeInterface::SCOPE_STORE + ); + } } diff --git a/app/code/Magento/Checkout/Model/Adminhtml/BillingAddressDisplayOptions.php b/app/code/Magento/Checkout/Model/Adminhtml/BillingAddressDisplayOptions.php new file mode 100644 index 0000000000000..831d4b41ec904 --- /dev/null +++ b/app/code/Magento/Checkout/Model/Adminhtml/BillingAddressDisplayOptions.php @@ -0,0 +1,39 @@ + 'Payment Method', 'value' => 0], + * ['label' => 'Payment Page', 'value' => 1] + * ] + */ + public function toOptionArray() + { + return [ + [ + 'label' => __('Payment Method'), + 'value' => 0 + ], + [ + 'label' => __('Payment Page'), + 'value' => 1 + ] + ]; + } +} diff --git a/app/code/Magento/Checkout/Model/DefaultConfigProvider.php b/app/code/Magento/Checkout/Model/DefaultConfigProvider.php index 923e54aac9378..0544f3aae3912 100644 --- a/app/code/Magento/Checkout/Model/DefaultConfigProvider.php +++ b/app/code/Magento/Checkout/Model/DefaultConfigProvider.php @@ -296,6 +296,7 @@ public function getConfig() $output['originCountryCode'] = $this->getOriginCountryCode(); $output['paymentMethods'] = $this->getPaymentMethods(); $output['autocomplete'] = $this->isAutocompleteEnabled(); + $output['displayBillingOnPaymentMethod'] = $this->checkoutHelper->isDisplayBillingOnPaymentMethodAvailable(); return $output; } diff --git a/app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php b/app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php new file mode 100644 index 0000000000000..1351213f990b5 --- /dev/null +++ b/app/code/Magento/Checkout/Test/Unit/Block/Checkout/LayoutProcessorTest.php @@ -0,0 +1,276 @@ +attributeDataProvider = $this->getMockBuilder(AttributeMetadataDataProvider::class) + ->disableOriginalConstructor() + ->setMethods(['loadAttributesCollection']) + ->getMock(); + + $this->attributeMapper = $this->getMockBuilder(AttributeMapper::class) + ->disableOriginalConstructor() + ->setMethods(['map']) + ->getMock(); + + $this->attributeMerger = $this->getMockBuilder(AttributeMerger::class) + ->disableOriginalConstructor() + ->setMethods(['merge']) + ->getMock(); + + $this->dataHelper = $this->getMockBuilder(Data::class) + ->disableOriginalConstructor() + ->setMethods(['isDisplayBillingOnPaymentMethodAvailable']) + ->getMock(); + + $options = $this->getMockBuilder(Options::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->layoutProcessor = new LayoutProcessor( + $this->attributeDataProvider, + $this->attributeMapper, + $this->attributeMerger + ); + + $objectManager->setBackwardCompatibleProperty($this->layoutProcessor, 'checkoutDataHelper', $this->dataHelper); + $objectManager->setBackwardCompatibleProperty($this->layoutProcessor, 'options', $options); + } + + /** + * @covers \Magento\Checkout\Block\Checkout\LayoutProcessor::process + */ + public function testProcess() + { + $jsLayout = $this->getLayoutData(); + + $this->attributeDataProvider->expects(static::once()) + ->method('loadAttributesCollection') + ->willReturn([]); + + $this->dataHelper->expects(static::once()) + ->method('isDisplayBillingOnPaymentMethodAvailable') + ->willReturn(true); + + $this->attributeMerger->expects(static::exactly(2)) + ->method('merge') + ->willReturnMap([ + ['payment1_1' => $this->getBillingComponent('payment1_1')], + ['payment2_1' => $this->getBillingComponent('payment2_1')], + ]); + + $actual = $this->layoutProcessor->process($jsLayout); + + static::assertArrayHasKey( + 'payment1_1-form', + $actual['components']['checkout']['children']['steps']['children']['billing-step']['children'] + ['payment']['children']['payments-list']['children'] + ); + static::assertArrayHasKey( + 'payment2_1-form', + $actual['components']['checkout']['children']['steps']['children']['billing-step']['children'] + ['payment']['children']['payments-list']['children'] + ); + static::assertArrayNotHasKey( + 'payment2_2-form', + $actual['components']['checkout']['children']['steps']['children']['billing-step']['children'] + ['payment']['children']['payments-list']['children'] + ); + static::assertArrayHasKey( + 'afterMethods', + $actual['components']['checkout']['children']['steps']['children']['billing-step'] + ['children']['payment']['children'] + ); + static::assertEmpty( + $actual['components']['checkout']['children']['steps']['children']['billing-step'] + ['children']['payment']['children']['afterMethods']['children'] + ); + } + + /** + * @covers \Magento\Checkout\Block\Checkout\LayoutProcessor::process + */ + public function testProcessWithBillingAddressOnPaymentPage() + { + $jsLayout = $this->getLayoutData(); + + $this->attributeDataProvider->expects(static::once()) + ->method('loadAttributesCollection') + ->willReturn([]); + + $this->dataHelper->expects(static::once()) + ->method('isDisplayBillingOnPaymentMethodAvailable') + ->willReturn(false); + + $this->attributeMerger->expects(static::once()) + ->method('merge') + ->willReturn($this->getBillingComponent('shared')); + + $actual = $this->layoutProcessor->process($jsLayout); + + static::assertEmpty( + $actual['components']['checkout']['children']['steps']['children']['billing-step']['children'] + ['payment']['children']['payments-list']['children'] + ); + + static::assertNotEmpty( + $actual['components']['checkout']['children']['steps']['children']['billing-step']['children'] + ['payment']['children']['afterMethods']['children'] + ); + static::assertArrayHasKey( + 'billing-address-form', + $actual['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment'] + ['children']['afterMethods']['children'] + ); + } + + /** + * Get mock layout data for testing + * @return array + */ + private function getLayoutData() + { + return [ + 'components' => [ + 'checkout' => [ + 'children' => [ + 'steps' => [ + 'children' => [ + 'billing-step' => [ + 'children' => [ + 'payment' => [ + 'children' => [ + 'renders' => [ + 'children' => [ + 'payment1' => [ + 'methods' => [ + 'payment1_1' => [ + 'isBillingAddressRequired' => true + ] + ] + ], + 'payment2' => [ + 'methods' => [ + 'payment2_1' => [ + 'isBillingAddressRequired' => true + ], + 'payment2_2' => [ + 'isBillingAddressRequired' => false + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ] + ]; + } + + /** + * Get mock data for billing component + * @param string $paymentCode + * @return array + */ + private function getBillingComponent($paymentCode) + { + return [ + 'country_id' => [ + 'sortOrder' => 115, + ], + 'region' => [ + 'visible' => false, + ], + 'region_id' => [ + 'component' => 'Magento_Ui/js/form/element/region', + 'config' => [ + 'template' => 'ui/form/field', + 'elementTmpl' => 'ui/form/element/select', + 'customEntry' => 'billingAddress' . $paymentCode . '.region', + ], + 'validation' => [ + 'required-entry' => true, + ], + 'filterBy' => [ + 'target' => '${ $.provider }:${ $.parentScope }.country_id', + 'field' => 'country_id', + ], + ], + 'postcode' => [ + 'component' => 'Magento_Ui/js/form/element/post-code', + 'validation' => [ + 'required-entry' => true, + ], + ], + 'company' => [ + 'validation' => [ + 'min_text_length' => 0, + ], + ], + 'fax' => [ + 'validation' => [ + 'min_text_length' => 0, + ], + ], + 'telephone' => [ + 'config' => [ + 'tooltip' => [ + 'description' => __('For delivery questions.'), + ], + ], + ], + ]; + } +} diff --git a/app/code/Magento/Checkout/etc/adminhtml/system.xml b/app/code/Magento/Checkout/etc/adminhtml/system.xml index d4567a4382539..b3b3d11b568a3 100644 --- a/app/code/Magento/Checkout/etc/adminhtml/system.xml +++ b/app/code/Magento/Checkout/etc/adminhtml/system.xml @@ -21,6 +21,10 @@ Magento\Config\Model\Config\Source\Yesno + + + \Magento\Checkout\Model\Adminhtml\BillingAddressDisplayOptions + diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js b/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js index b9cf58b51b133..17dbf158d50be 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js @@ -17,6 +17,7 @@ define( 'Magento_Checkout/js/model/checkout-data-resolver', 'Magento_Customer/js/customer-data', 'Magento_Checkout/js/action/set-billing-address', + 'Magento_Checkout/js/action/set-shipping-information', 'Magento_Ui/js/model/messageList', 'mage/translate' ], @@ -32,6 +33,7 @@ define( checkoutDataResolver, customerData, setBillingAddressAction, + setShippingInformationAction, globalMessageList, $t ) { @@ -39,9 +41,13 @@ define( var lastSelectedBillingAddress = null, newAddressOption = { + /** + * Get new address label + * @returns {String} + */ getAddressInline: function () { - return $t('New Address'); - }, + return $t('New Address'); + }, customerAddressId: null }, countryData = customerData.get('directory-data'), @@ -121,6 +127,7 @@ define( useShippingAddress: function () { if (this.isAddressSameAsShipping()) { selectBillingAddress(quote.shippingAddress()); + if (window.checkoutConfig.reloadOnBillingAddress) { setBillingAddressAction(globalMessageList); } @@ -142,15 +149,18 @@ define( if (this.selectedAddress() && this.selectedAddress() != newAddressOption) { selectBillingAddress(this.selectedAddress()); checkoutData.setSelectedBillingAddress(this.selectedAddress().getKey()); + if (window.checkoutConfig.reloadOnBillingAddress) { setBillingAddressAction(globalMessageList); } + this.updateAddresses(); } else { this.source.set('params.invalid', false); this.source.trigger(this.dataScopePrefix + '.data.validate'); + if (this.source.get(this.dataScopePrefix + '.custom_attributes')) { this.source.trigger(this.dataScopePrefix + '.custom_attributes.data.validate'); - }; + } if (!this.source.get('params.invalid')) { var addressData = this.source.get(this.dataScopePrefix), @@ -159,7 +169,7 @@ define( if (customer.isLoggedIn() && !this.customerHasAddresses) { this.saveInAddressBook(1); } - addressData.save_in_address_book = this.saveInAddressBook() ? 1 : 0; + addressData['save_in_address_book'] = this.saveInAddressBook() ? 1 : 0; newBillingAddress = createBillingAddress(addressData); // New address must be selected as a billing address @@ -170,6 +180,7 @@ define( if (window.checkoutConfig.reloadOnBillingAddress) { setBillingAddressAction(globalMessageList); } + this.updateAddresses(); } } }, @@ -222,6 +233,24 @@ define( */ getCountryName: function (countryId) { return countryData()[countryId] != undefined ? countryData()[countryId].name : ''; + }, + + /** + * Trigger action to update shipping and billing addresses + */ + updateAddresses: function () { + if (!window.checkoutConfig.displayBillingOnPaymentMethod) { + setShippingInformationAction(); + } + }, + + /** + * Get code + * @param {Object} $parent + * @returns {String} + */ + getCode: function ($parent) { + return $parent.getCode === 'function' ? $parent.getCode() : 'shared'; } }); } diff --git a/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html b/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html index 377208aa1b8ee..dd1b3731b9dcb 100644 --- a/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html +++ b/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html @@ -5,8 +5,8 @@ */ -->
- - + +
diff --git a/app/code/Magento/Payment/Model/Checks/CanUseForCountry/CountryProvider.php b/app/code/Magento/Payment/Model/Checks/CanUseForCountry/CountryProvider.php index 8342b181d5e6f..cb7791cbc6d2d 100644 --- a/app/code/Magento/Payment/Model/Checks/CanUseForCountry/CountryProvider.php +++ b/app/code/Magento/Payment/Model/Checks/CanUseForCountry/CountryProvider.php @@ -31,8 +31,8 @@ public function __construct(DirectoryHelper $directoryHelper) */ public function getCountry(Quote $quote) { - $address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress(); - return $address + $address = $quote->getBillingAddress() ? : $quote->getShippingAddress(); + return (!empty($address) && !empty($address->getCountry())) ? $address->getCountry() : $this->directoryHelper->getDefaultCountry(); } diff --git a/app/code/Magento/Payment/Test/Unit/Model/Checks/CanUseForCountry/CountryProviderTest.php b/app/code/Magento/Payment/Test/Unit/Model/Checks/CanUseForCountry/CountryProviderTest.php index 5b14cc57a3035..02cfd0387c3e5 100644 --- a/app/code/Magento/Payment/Test/Unit/Model/Checks/CanUseForCountry/CountryProviderTest.php +++ b/app/code/Magento/Payment/Test/Unit/Model/Checks/CanUseForCountry/CountryProviderTest.php @@ -5,55 +5,123 @@ */ namespace Magento\Payment\Test\Unit\Model\Checks\CanUseForCountry; +use Magento\Directory\Helper\Data; +use Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider; +use Magento\Quote\Model\Quote; +use Magento\Quote\Model\Quote\Address; +use PHPUnit_Framework_MockObject_MockObject as MockObject; + +/** + * CountryProviderTest contains tests for CountryProvider class + */ class CountryProviderTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider + * @var CountryProvider */ - protected $model; + private $countryProvider; /** - * @var \PHPUnit_Framework_MockObject_MockObject + * @var Data|MockObject */ - protected $directoryMock; + private $directory; + + /** + * @var Quote|MockObject + */ + private $quote; protected function setUp() { - $this->directoryMock = $this->getMock(\Magento\Directory\Helper\Data::class, [], [], '', false, false); - $this->model = new \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider($this->directoryMock); + $this->directory = $this->getMockBuilder(Data::class) + ->disableOriginalConstructor() + ->setMethods(['getDefaultCountry']) + ->getMock(); + + $this->quote = $this->getMockBuilder(Quote::class) + ->disableOriginalConstructor() + ->setMethods(['getBillingAddress', 'getShippingAddress']) + ->getMock(); + + $this->countryProvider = new CountryProvider($this->directory); } - public function testGetCountryForNonVirtualQuote() + /** + * @covers \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider::getCountry + */ + public function testGetCountry() { - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false, false); - $quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); - $addressMock = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false, false); - $addressMock->expects($this->once())->method('getCountry')->will($this->returnValue(1)); - $quoteMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($addressMock)); - $this->assertEquals(1, $this->model->getCountry($quoteMock)); + $address = $this->getMockBuilder(Address::class) + ->disableOriginalConstructor() + ->setMethods(['getCountry']) + ->getMock(); + + $this->quote->expects(static::once()) + ->method('getBillingAddress') + ->willReturn($address); + + $this->quote->expects(static::never()) + ->method('getShippingAddress'); + + $address->expects(static::exactly(2)) + ->method('getCountry') + ->willReturn('UK'); + $this->directory->expects(static::never()) + ->method('getDefaultCountry'); + + static::assertEquals('UK', $this->countryProvider->getCountry($this->quote)); } - public function testGetCountryForVirtualQuoteWhenBillingAddressNotExist() + /** + * @covers \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider::getCountry + */ + public function testGetCountryForBillingAddressWithoutCountry() { - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false, false); - $quoteMock->expects($this->once())->method('isVirtual')->willReturn(true); - $addressMock = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false, false); - $addressMock->expects($this->never())->method('getCountry'); - $quoteMock->expects($this->never())->method('getShippingAddress'); - $quoteMock->expects($this->once())->method('getBillingAddress')->willReturn(null); - $this->directoryMock->expects($this->once())->method('getDefaultCountry')->willReturn(10); - $this->assertEquals(10, $this->model->getCountry($quoteMock)); + $address = $this->getMockBuilder(Address::class) + ->disableOriginalConstructor() + ->setMethods(['getCountry']) + ->getMock(); + + $this->quote->expects(static::never()) + ->method('getShippingAddress'); + $this->quote->expects(static::once()) + ->method('getBillingAddress') + ->willReturn($address); + + $address->expects(static::once()) + ->method('getCountry') + ->willReturn(null); + $this->directory->expects(static::once()) + ->method('getDefaultCountry') + ->willReturn('US'); + static::assertEquals('US', $this->countryProvider->getCountry($this->quote)); } - public function testGetCountryForVirtualQuoteWhenBillingAddressExist() + /** + * @covers \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider::getCountry + */ + public function testGetCountryShippingAddress() { - $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false, false); - $quoteMock->expects($this->once())->method('isVirtual')->willReturn(true); - $addressMock = $this->getMock(\Magento\Quote\Model\Quote\Address::class, [], [], '', false, false); - $addressMock->expects($this->once())->method('getCountry')->willReturn(10); - $quoteMock->expects($this->never())->method('getShippingAddress'); - $quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($addressMock); - $this->directoryMock->expects($this->never())->method('getDefaultCountry'); - $this->assertEquals(10, $this->model->getCountry($quoteMock)); + $address = $this->getMockBuilder(Address::class) + ->disableOriginalConstructor() + ->setMethods(['getCountry']) + ->getMock(); + + $this->quote->expects(static::once()) + ->method('getBillingAddress') + ->willReturn(null); + + $this->quote->expects(static::once()) + ->method('getShippingAddress') + ->willReturn($address); + + $address->expects(static::exactly(2)) + ->method('getCountry') + ->willReturn('CA'); + + $this->directory->expects(static::never()) + ->method('getDefaultCountry'); + + static::assertEquals('CA', $this->countryProvider->getCountry($this->quote)); } } diff --git a/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php b/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php index 434a5875b5bb1..f65f9a0c749d3 100644 --- a/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php +++ b/app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php @@ -84,8 +84,10 @@ public function getConfig() $componentProvider = $providers[$paymentCode]; $component = $componentProvider->getComponentForToken($token); - $vaultPayments[$paymentCode . '_item_' . $i] = [ - 'config' => $component->getConfig(), + $config = $component->getConfig(); + $vaultPaymentCode = !empty($config['code']) ? $config['code'] : $paymentCode; + $vaultPayments[$vaultPaymentCode . '_' . $i] = [ + 'config' => $config, 'component' => $component->getName() ]; } diff --git a/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php b/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php index e64fff27ff14c..cdc2004ec6a28 100644 --- a/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php +++ b/app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php @@ -81,7 +81,7 @@ public function testGetConfig() $expectedConfig = [ 'payment' => [ 'vault' => [ - $vaultProviderCode . '_item_' . '0' => [ + $vaultProviderCode . '_' . '0' => [ 'config' => ['token_code' => 'code'], 'component' => 'Vendor_Module/js/vault_component' ] diff --git a/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault.js b/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault.js index cba9256f2a563..c4e6c12834b09 100644 --- a/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault.js +++ b/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault.js @@ -31,7 +31,8 @@ define( * @return {Boolean} */ typeComparatorCallback: function (typeA, typeB) { - return typeA.indexOf(typeB) === 0; + // vaults items have the same name as vault payment without index + return typeA.substring(0, typeA.length - 2) === typeB; } } ); diff --git a/dev/tests/integration/testsuite/Magento/Braintree/Model/Ui/TokensConfigProviderTest.php b/dev/tests/integration/testsuite/Magento/Braintree/Model/Ui/TokensConfigProviderTest.php index b8550ae205429..440f7674f1227 100644 --- a/dev/tests/integration/testsuite/Magento/Braintree/Model/Ui/TokensConfigProviderTest.php +++ b/dev/tests/integration/testsuite/Magento/Braintree/Model/Ui/TokensConfigProviderTest.php @@ -72,7 +72,7 @@ public function testGetConfig() /** @var PaymentTokenManagement $tokenManagement */ $tokenManagement = $this->objectManager->get(PaymentTokenManagement::class); $paymentToken = $tokenManagement->getByGatewayToken($token, PayPalConfigProvider::PAYPAL_CODE, $customerId); - $item = PayPalConfigProvider::PAYPAL_CODE . '_item_' . $paymentToken->getEntityId(); + $item = PayPalConfigProvider::PAYPAL_VAULT_CODE . '_' . $paymentToken->getEntityId(); /** @var Session $session */ $session = $this->objectManager->get(Session::class); From 02a6c3757a298c8e699847a4ded93df8cf834048 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Tue, 6 Sep 2016 18:28:02 +0300 Subject: [PATCH 02/13] =?UTF-8?q?MAGETWO-57923:=20=E2=80=9CNo=20Payment=20?= =?UTF-8?q?method=20available=E2=80=9D=20when=20customer=20tries=20to=20sh?= =?UTF-8?q?ip=20his=20items=20to=20billing=20restricted=20country?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Used setBillingAddress action instead setShippingInformation - Fixed condition for Vault comparision callback - Fixed namespaces --- app/code/Magento/Braintree/Helper/Country.php | 17 ++++++------ .../frontend/web/js/view/billing-address.js | 27 +++++++------------ .../frontend/web/js/view/payment/vault.js | 4 +-- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/app/code/Magento/Braintree/Helper/Country.php b/app/code/Magento/Braintree/Helper/Country.php index 3067c95d5e373..e8660b8523b30 100644 --- a/app/code/Magento/Braintree/Helper/Country.php +++ b/app/code/Magento/Braintree/Helper/Country.php @@ -5,18 +5,21 @@ */ namespace Magento\Braintree\Helper; +use Magento\Directory\Model\ResourceModel\Country\CollectionFactory; +use Magento\Braintree\Model\Adminhtml\System\Config\Country as CountryConfig; + /** * Class Country */ class Country { /** - * @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory + * @var CollectionFactory */ private $collectionFactory; /** - * @var \Magento\Braintree\Model\Adminhtml\System\Config\Country + * @var CountryConfig */ private $countryConfig; @@ -26,13 +29,11 @@ class Country private $countries; /** - * @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $factory - * @param \Magento\Braintree\Model\Adminhtml\System\Config\Country $countryConfig + * @param CollectionFactory $factory + * @param CountryConfig $countryConfig */ - public function __construct( - \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $factory, - \Magento\Braintree\Model\Adminhtml\System\Config\Country $countryConfig - ) { + public function __construct(CollectionFactory $factory, CountryConfig $countryConfig) + { $this->collectionFactory = $factory; $this->countryConfig = $countryConfig; } diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js b/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js index 17dbf158d50be..517231cf888f2 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js @@ -7,6 +7,7 @@ define( [ 'ko', + 'underscore', 'Magento_Ui/js/form/form', 'Magento_Customer/js/model/customer', 'Magento_Customer/js/model/address-list', @@ -17,12 +18,12 @@ define( 'Magento_Checkout/js/model/checkout-data-resolver', 'Magento_Customer/js/customer-data', 'Magento_Checkout/js/action/set-billing-address', - 'Magento_Checkout/js/action/set-shipping-information', 'Magento_Ui/js/model/messageList', 'mage/translate' ], function ( ko, + _, Component, customer, addressList, @@ -33,7 +34,6 @@ define( checkoutDataResolver, customerData, setBillingAddressAction, - setShippingInformationAction, globalMessageList, $t ) { @@ -149,11 +149,6 @@ define( if (this.selectedAddress() && this.selectedAddress() != newAddressOption) { selectBillingAddress(this.selectedAddress()); checkoutData.setSelectedBillingAddress(this.selectedAddress().getKey()); - - if (window.checkoutConfig.reloadOnBillingAddress) { - setBillingAddressAction(globalMessageList); - } - this.updateAddresses(); } else { this.source.set('params.invalid', false); this.source.trigger(this.dataScopePrefix + '.data.validate'); @@ -176,13 +171,9 @@ define( selectBillingAddress(newBillingAddress); checkoutData.setSelectedBillingAddress(newBillingAddress.getKey()); checkoutData.setNewCustomerBillingAddress(addressData); - - if (window.checkoutConfig.reloadOnBillingAddress) { - setBillingAddressAction(globalMessageList); - } - this.updateAddresses(); } } + this.updateAddresses(); }, /** @@ -239,18 +230,20 @@ define( * Trigger action to update shipping and billing addresses */ updateAddresses: function () { - if (!window.checkoutConfig.displayBillingOnPaymentMethod) { - setShippingInformationAction(); + if (window.checkoutConfig.reloadOnBillingAddress || + !window.checkoutConfig.displayBillingOnPaymentMethod + ) { + setBillingAddressAction(globalMessageList); } }, /** * Get code - * @param {Object} $parent + * @param {Object} parent * @returns {String} */ - getCode: function ($parent) { - return $parent.getCode === 'function' ? $parent.getCode() : 'shared'; + getCode: function (parent) { + return _.isFunction(parent.getCode) ? parent.getCode() : 'shared'; } }); } diff --git a/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault.js b/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault.js index c4e6c12834b09..05d56e305f23e 100644 --- a/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault.js +++ b/app/code/Magento/Vault/view/frontend/web/js/view/payment/vault.js @@ -31,8 +31,8 @@ define( * @return {Boolean} */ typeComparatorCallback: function (typeA, typeB) { - // vaults items have the same name as vault payment without index - return typeA.substring(0, typeA.length - 2) === typeB; + // vault token items have the same name as vault payment without index + return typeA.substring(0, typeA.lastIndexOf('_')) === typeB; } } ); From 6bb07aacfefdf6a8d178fd6ef2e81c0c3085eeaa Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Thu, 8 Sep 2016 12:36:03 +0300 Subject: [PATCH 03/13] =?UTF-8?q?MAGETWO-57923:=20=E2=80=9CNo=20Payment=20?= =?UTF-8?q?method=20available=E2=80=9D=20when=20customer=20tries=20to=20sh?= =?UTF-8?q?ip=20his=20items=20to=20billing=20restricted=20country?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Removed conditional for virtual quote --- .../web/js/action/set-billing-address.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/action/set-billing-address.js b/app/code/Magento/Checkout/view/frontend/web/js/action/set-billing-address.js index 31d52e5dd1d76..36518a4d615e1 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/action/set-billing-address.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/action/set-billing-address.js @@ -10,7 +10,6 @@ define( 'mage/storage', 'Magento_Checkout/js/model/error-processor', 'Magento_Customer/js/model/customer', - 'Magento_Checkout/js/action/get-totals', 'Magento_Checkout/js/model/full-screen-loader', 'Magento_Checkout/js/action/get-payment-information' ], @@ -20,7 +19,6 @@ define( storage, errorProcessor, customer, - getTotalsAction, fullScreenLoader, getPaymentInformationAction ) { @@ -55,18 +53,12 @@ define( serviceUrl, JSON.stringify(payload) ).done( function () { - var deferred = null; + var deferred = $.Deferred(); - if (!quote.isVirtual()) { - getTotalsAction([]); + getPaymentInformationAction(deferred); + $.when(deferred).done(function () { fullScreenLoader.stopLoader(); - } else { - deferred = $.Deferred(); - getPaymentInformationAction(deferred); - $.when(deferred).done(function () { - fullScreenLoader.stopLoader(); - }); - } + }); } ).fail( function (response) { From e712bef4b59a537e7f31fdef20c6d3cdfd1578d4 Mon Sep 17 00:00:00 2001 From: Iurii Ivashchenko Date: Wed, 14 Sep 2016 11:19:09 +0300 Subject: [PATCH 04/13] =?UTF-8?q?MAGETWO-57923:=20=E2=80=9CNo=20Payment=20?= =?UTF-8?q?method=20available=E2=80=9D=20when=20customer=20tries=20to=20sh?= =?UTF-8?q?ip=20his=20items=20to=20billing=20restricted=20country?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - frontend issues fix --- .../web/template/billing-address.html | 42 +++++++++++-------- .../css/source/module/checkout/_payments.less | 22 ++++------ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html b/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html index dd1b3731b9dcb..23c02caa70b1a 100644 --- a/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html +++ b/app/code/Magento/Checkout/view/frontend/web/template/billing-address.html @@ -4,23 +4,29 @@ * See COPYING.txt for license details. */ --> -
- - -
+
- -
- - -
-
- - -
+
+ +
-
+ + +
+ + +
+
+ + +
+
+
+ +
\ No newline at end of file diff --git a/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/checkout/_payments.less b/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/checkout/_payments.less index 3c3ee77ed00e0..85b2e96e6ea4a 100644 --- a/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/checkout/_payments.less +++ b/app/design/frontend/Magento/luma/Magento_Checkout/web/css/source/module/checkout/_payments.less @@ -89,7 +89,7 @@ margin: 0 0 @indent__s; } - .payment-method-billing-address { + .checkout-billing-address { margin: 0 0 @indent__base; .primary { @@ -105,15 +105,11 @@ .billing-address-details { .lib-css(line-height, @checkout-billing-address-details__line-height); .lib-css(padding, @checkout-billing-address-details__padding); - - .action-edit-address { - &:extend(.abs-action-button-as-link all); - } } } .payment-method-note { - & + .payment-method-billing-address { + & + .checkout-billing-address { margin-top: @indent__base; } } @@ -160,7 +156,7 @@ .lib-css(padding, 0 @checkout-payment-method-title-mobile__padding @indent__base); } - .payment-method-billing-address { + .checkout-billing-address { .action-cancel { margin-top: @indent__s; } @@ -174,12 +170,10 @@ .media-width(@extremum, @break) when (@extremum = 'min') and (@break = @screen__m) { .checkout-payment-method { - .payment-methods { - .actions-toolbar { - .primary { - float: right; - margin: 0; - } + .actions-toolbar { + .primary { + float: right; + margin: 0; } } @@ -193,7 +187,7 @@ } } - .payment-method-billing-address { + .checkout-billing-address { .action-update { float: right; } From cd344f0c1e0546e7a7f4982d59e6a298e8fbf3bb Mon Sep 17 00:00:00 2001 From: Iurii Ivashchenko Date: Wed, 14 Sep 2016 17:07:58 +0300 Subject: [PATCH 05/13] MAGETWO-58330: ReorderUsingVaultTest fails on Bamboo --- app/code/Magento/Vault/Model/Method/Vault.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Vault/Model/Method/Vault.php b/app/code/Magento/Vault/Model/Method/Vault.php index 0e6689461e14b..3d3d4c9e59bc9 100644 --- a/app/code/Magento/Vault/Model/Method/Vault.php +++ b/app/code/Magento/Vault/Model/Method/Vault.php @@ -457,13 +457,13 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount) private function attachTokenExtensionAttribute(OrderPaymentInterface $orderPayment) { $additionalInformation = $orderPayment->getAdditionalInformation(); - if (empty($additionalInformation[PaymentTokenInterface::CUSTOMER_ID]) || - empty($additionalInformation[PaymentTokenInterface::PUBLIC_HASH]) - ) { - throw new \LogicException('Customer id and public hash should be defined'); + if (empty($additionalInformation[PaymentTokenInterface::PUBLIC_HASH])) { + throw new \LogicException('Customer public hash should be defined'); } - $customerId = $additionalInformation[PaymentTokenInterface::CUSTOMER_ID]; + $customerId = isset($additionalInformation[PaymentTokenInterface::CUSTOMER_ID]) ? + $additionalInformation[PaymentTokenInterface::CUSTOMER_ID] : null; + $publicHash = $additionalInformation[PaymentTokenInterface::PUBLIC_HASH]; $paymentToken = $this->tokenManagement->getByPublicHash($publicHash, $customerId); From 00e842e5bb78bd733cd99ce5b00fdcc43bf50641 Mon Sep 17 00:00:00 2001 From: Elena Marchenko Date: Wed, 14 Sep 2016 19:50:25 +0300 Subject: [PATCH 06/13] =?UTF-8?q?MAGETWO-57923:=20=E2=80=9CNo=20Payment=20?= =?UTF-8?q?method=20available=E2=80=9D=20when=20customer=20tries=20to=20sh?= =?UTF-8?q?ip=20his=20items=20to=20billing=20restricted=20country?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - functional tests fix --- .../SaveUseDeleteVaultForPaypalBraintreeTest.xml | 1 + .../Test/TestCase/UseVaultOnCheckoutTest.xml | 1 + .../UseVaultWith3dSecureOnCheckoutTest.xml | 1 + .../Test/TestCase/UseVaultOnCheckoutTest.xml | 1 + .../Test/TestStep/UseSavedPaymentMethodStep.php | 15 +++++++-------- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/SaveUseDeleteVaultForPaypalBraintreeTest.xml b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/SaveUseDeleteVaultForPaypalBraintreeTest.xml index 58612f7dee170..4948ce404c81a 100644 --- a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/SaveUseDeleteVaultForPaypalBraintreeTest.xml +++ b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/SaveUseDeleteVaultForPaypalBraintreeTest.xml @@ -19,6 +19,7 @@ 15.00 braintree_paypal + braintree_paypal_vault Yes braintree, braintree_paypal, braintree_paypal_use_vault Processing diff --git a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml index 4b061fb2664b8..e88ecae2cc276 100644 --- a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml +++ b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml @@ -16,6 +16,7 @@ Flat Rate Fixed braintree + braintree_cc_vault credit_card_braintree visa_braintree Yes diff --git a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultWith3dSecureOnCheckoutTest.xml b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultWith3dSecureOnCheckoutTest.xml index 1aaa684db5c66..e09437d821497 100644 --- a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultWith3dSecureOnCheckoutTest.xml +++ b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultWith3dSecureOnCheckoutTest.xml @@ -16,6 +16,7 @@ Flat Rate Fixed braintree + braintree_cc_vault credit_card_braintree visa_braintree_3dsecure diff --git a/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml b/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml index a71dd812b50f7..b93c0a9a111ff 100644 --- a/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml +++ b/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml @@ -15,6 +15,7 @@ Flat Rate Fixed payflowpro + payflowpro_cc_vault credit_card visa_default Yes diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedPaymentMethodStep.php b/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedPaymentMethodStep.php index b4b21670d2e0c..0f3e2af35896d 100644 --- a/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedPaymentMethodStep.php +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedPaymentMethodStep.php @@ -22,21 +22,21 @@ class UseSavedPaymentMethodStep implements TestStepInterface protected $checkoutOnepage; /** - * Payment information. + * Vault provider code. * - * @var array + * @var string */ - protected $payment; + protected $vaultCode; /** * @constructor * @param CheckoutOnepage $checkoutOnepage - * @param array $payment + * @param string $vaultCode */ - public function __construct (CheckoutOnepage $checkoutOnepage, array $payment) + public function __construct (CheckoutOnepage $checkoutOnepage, string $vaultCode) { $this->checkoutOnepage = $checkoutOnepage; - $this->payment = $payment; + $this->vaultCode = $vaultCode; } /** @@ -46,7 +46,6 @@ public function __construct (CheckoutOnepage $checkoutOnepage, array $payment) */ public function run() { - $this->payment['method'] .= '_item_'; - $this->checkoutOnepage->getPaymentBlock()->selectPaymentMethod($this->payment); + $this->checkoutOnepage->getPaymentBlock()->selectPaymentMethod($this->vaultCode); } } From 1ca768b9a3ff46f51b60fb64f4d10be61610b654 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Thu, 15 Sep 2016 09:14:11 +0300 Subject: [PATCH 07/13] =?UTF-8?q?MAGETWO-57923:=20=E2=80=9CNo=20Payment=20?= =?UTF-8?q?method=20available=E2=80=9D=20when=20customer=20tries=20to=20sh?= =?UTF-8?q?ip=20his=20items=20to=20billing=20restricted=20country?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added billing address converter --- .../js/view/payment/method-renderer/paypal.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js index 0145264e3cd3a..184260c39e954 100644 --- a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js +++ b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js @@ -12,8 +12,19 @@ define([ 'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/model/full-screen-loader', 'Magento_Checkout/js/model/payment/additional-validators', - 'Magento_Vault/js/view/payment/vault-enabler' -], function ($, _, Component, Braintree, quote, fullScreenLoader, additionalValidators, VaultEnabler) { + 'Magento_Vault/js/view/payment/vault-enabler', + 'Magento_Checkout/js/action/create-billing-address' +], function ( + $, + _, + Component, + Braintree, + quote, + fullScreenLoader, + additionalValidators, + VaultEnabler, + createBillingAddress +) { 'use strict'; return Component.extend({ @@ -172,14 +183,16 @@ define([ var billingAddress = { street: [address.streetAddress], city: address.locality, - regionCode: address.region, postcode: address.postalCode, countryId: address.countryCodeAlpha2, + email: customer.email, firstname: customer.firstName, lastname: customer.lastName, telephone: customer.phone }; + billingAddress['region_code'] = address.region; + billingAddress = createBillingAddress(billingAddress); quote.billingAddress(billingAddress); }, From 6aef2f9e9ac1617a84de73f471b4cbf563091c51 Mon Sep 17 00:00:00 2001 From: Iurii Ivashchenko Date: Thu, 15 Sep 2016 15:24:19 +0300 Subject: [PATCH 08/13] MAGETWO-58330: ReorderUsingVaultTest fails on Bamboo --- app/code/Magento/Vault/Model/Method/Vault.php | 2 +- app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Vault/Model/Method/Vault.php b/app/code/Magento/Vault/Model/Method/Vault.php index 3d3d4c9e59bc9..81e054742286f 100644 --- a/app/code/Magento/Vault/Model/Method/Vault.php +++ b/app/code/Magento/Vault/Model/Method/Vault.php @@ -458,7 +458,7 @@ private function attachTokenExtensionAttribute(OrderPaymentInterface $orderPayme { $additionalInformation = $orderPayment->getAdditionalInformation(); if (empty($additionalInformation[PaymentTokenInterface::PUBLIC_HASH])) { - throw new \LogicException('Customer public hash should be defined'); + throw new \LogicException('Public hash should be defined'); } $customerId = isset($additionalInformation[PaymentTokenInterface::CUSTOMER_ID]) ? diff --git a/app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php b/app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php index fc6f3e4d2390b..75086de262831 100644 --- a/app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php +++ b/app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php @@ -52,7 +52,7 @@ public function testAuthorizeNotOrderPayment() /** * @param array $additionalInfo * @expectedException \LogicException - * @expectedExceptionMessage Customer id and public hash should be defined + * @expectedExceptionMessage Public hash should be defined * @dataProvider additionalInfoDataProvider */ public function testAuthorizeNoTokenMetadata(array $additionalInfo) @@ -79,7 +79,7 @@ public function additionalInfoDataProvider() return [ ['additionalInfo' => []], ['additionalInfo' => ['customer_id' => 1]], - ['additionalInfo' => ['public_hash' => 'df768aak12uf']], + ['additionalInfo' => ['public_hash' => null]], ]; } From 92caa93a486cd5124c08af39fa11fa6d44085196 Mon Sep 17 00:00:00 2001 From: Elena Marchenko Date: Thu, 15 Sep 2016 16:00:05 +0300 Subject: [PATCH 09/13] =?UTF-8?q?MAGETWO-57923:=20=E2=80=9CNo=20Payment=20?= =?UTF-8?q?method=20available=E2=80=9D=20when=20customer=20tries=20to=20sh?= =?UTF-8?q?ip=20his=20items=20to=20billing=20restricted=20country?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - functional tests fix --- .../SaveUseDeleteVaultForPaypalBraintreeTest.xml | 2 +- .../Test/TestCase/UseVaultOnCheckoutTest.xml | 2 +- .../UseVaultWith3dSecureOnCheckoutTest.xml | 2 +- .../Test/TestCase/UseVaultOnCheckoutTest.xml | 2 +- .../Test/TestStep/UseSavedPaymentMethodStep.php | 14 +++++++------- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/SaveUseDeleteVaultForPaypalBraintreeTest.xml b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/SaveUseDeleteVaultForPaypalBraintreeTest.xml index 4948ce404c81a..6e214d4c205aa 100644 --- a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/SaveUseDeleteVaultForPaypalBraintreeTest.xml +++ b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/SaveUseDeleteVaultForPaypalBraintreeTest.xml @@ -19,7 +19,7 @@ 15.00 braintree_paypal - braintree_paypal_vault + braintree_paypal_vault Yes braintree, braintree_paypal, braintree_paypal_use_vault Processing diff --git a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml index e88ecae2cc276..00eb9c4802db6 100644 --- a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml +++ b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultOnCheckoutTest.xml @@ -16,7 +16,7 @@ Flat Rate Fixed braintree - braintree_cc_vault + braintree_cc_vault credit_card_braintree visa_braintree Yes diff --git a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultWith3dSecureOnCheckoutTest.xml b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultWith3dSecureOnCheckoutTest.xml index e09437d821497..0f00ff93612b8 100644 --- a/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultWith3dSecureOnCheckoutTest.xml +++ b/dev/tests/functional/tests/app/Magento/Braintree/Test/TestCase/UseVaultWith3dSecureOnCheckoutTest.xml @@ -16,7 +16,7 @@ Flat Rate Fixed braintree - braintree_cc_vault + braintree_cc_vault credit_card_braintree visa_braintree_3dsecure diff --git a/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml b/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml index b93c0a9a111ff..bde3837d71fda 100644 --- a/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml +++ b/dev/tests/functional/tests/app/Magento/Paypal/Test/TestCase/UseVaultOnCheckoutTest.xml @@ -15,7 +15,7 @@ Flat Rate Fixed payflowpro - payflowpro_cc_vault + payflowpro_cc_vault credit_card visa_default Yes diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedPaymentMethodStep.php b/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedPaymentMethodStep.php index 0f3e2af35896d..1470bde4f77e5 100644 --- a/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedPaymentMethodStep.php +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/TestStep/UseSavedPaymentMethodStep.php @@ -22,21 +22,21 @@ class UseSavedPaymentMethodStep implements TestStepInterface protected $checkoutOnepage; /** - * Vault provider code. + * Vault provider. * - * @var string + * @var array */ - protected $vaultCode; + protected $vault; /** * @constructor * @param CheckoutOnepage $checkoutOnepage - * @param string $vaultCode + * @param array $vault */ - public function __construct (CheckoutOnepage $checkoutOnepage, string $vaultCode) + public function __construct (CheckoutOnepage $checkoutOnepage, array $vault) { $this->checkoutOnepage = $checkoutOnepage; - $this->vaultCode = $vaultCode; + $this->vault = $vault; } /** @@ -46,6 +46,6 @@ public function __construct (CheckoutOnepage $checkoutOnepage, string $vaultCode */ public function run() { - $this->checkoutOnepage->getPaymentBlock()->selectPaymentMethod($this->vaultCode); + $this->checkoutOnepage->getPaymentBlock()->selectPaymentMethod($this->vault); } } From f1baac032543a8defb9eec4c35d14a7619db0181 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Fri, 16 Sep 2016 17:17:42 +0300 Subject: [PATCH 10/13] =?UTF-8?q?MAGETWO-57923:=20=E2=80=9CNo=20Payment=20?= =?UTF-8?q?method=20available=E2=80=9D=20when=20customer=20tries=20to=20sh?= =?UTF-8?q?ip=20his=20items=20to=20billing=20restricted=20country?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added billing address change action for useShippingAddress method --- .../Checkout/view/frontend/web/js/view/billing-address.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js b/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js index 517231cf888f2..0c2e7fb01c701 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js @@ -128,9 +128,7 @@ define( if (this.isAddressSameAsShipping()) { selectBillingAddress(quote.shippingAddress()); - if (window.checkoutConfig.reloadOnBillingAddress) { - setBillingAddressAction(globalMessageList); - } + this.updateAddresses(); this.isAddressDetailsVisible(true); } else { lastSelectedBillingAddress = quote.billingAddress(); From 439d91114a097f3d326cb5870163d1f799379586 Mon Sep 17 00:00:00 2001 From: Elena Marchenko Date: Mon, 19 Sep 2016 15:40:16 +0300 Subject: [PATCH 11/13] =?UTF-8?q?MAGETWO-57923:=20=E2=80=9CNo=20Payment=20?= =?UTF-8?q?method=20available=E2=80=9D=20when=20customer=20tries=20to=20sh?= =?UTF-8?q?ip=20his=20items=20to=20billing=20restricted=20country?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - functional tests fix --- .../Vault/Test/TestCase/DeleteSavedCreditCardTest.php | 4 ++-- .../Vault/Test/TestCase/DeleteSavedCreditCardTest.xml | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php index a90bd37f33047..17db35df1b44e 100644 --- a/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.php @@ -92,7 +92,7 @@ public function test( } $this->fillShippingMethod($shipping); if ($key >= 2) { // if this order will be placed via stored credit card - $this->useSavedCreditCard($payment); + $this->useSavedCreditCard($payment['vault']); } else { $this->selectPaymentMethod($payment, $payment['creditCardClass'], $payment['creditCard']); $this->saveCreditCard($payment, $creditCardSave); @@ -291,7 +291,7 @@ protected function useSavedCreditCard($payment) { $useSavedCreditCardStep = ObjectManager::getInstance()->create( \Magento\Vault\Test\TestStep\UseSavedPaymentMethodStep::class, - ['payment' => $payment] + ['vault' => $payment] ); $useSavedCreditCardStep->run(); } diff --git a/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.xml b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.xml index 5a2e2903e2c49..ae303b695277c 100644 --- a/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.xml +++ b/dev/tests/functional/tests/app/Magento/Vault/Test/TestCase/DeleteSavedCreditCardTest.xml @@ -35,6 +35,9 @@ visa_braintree + + braintree_cc_vault + payflowpro @@ -42,6 +45,9 @@ amex_default + + payflowpro_cc_vault + Yes From 112b53b378f7714d915eceda9b855739fea5c8ea Mon Sep 17 00:00:00 2001 From: Elena Marchenko Date: Tue, 20 Sep 2016 19:01:32 +0300 Subject: [PATCH 12/13] =?UTF-8?q?MAGETWO-57923:=20=E2=80=9CNo=20Payment=20?= =?UTF-8?q?method=20available=E2=80=9D=20when=20customer=20tries=20to=20sh?= =?UTF-8?q?ip=20his=20items=20to=20billing=20restricted=20country?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - functional tests fix --- .../Braintree/view/frontend/web/template/payment/form.html | 4 ++-- .../Braintree/view/frontend/web/template/payment/paypal.html | 4 ++-- .../view/frontend/web/template/payment/payflowpro-form.html | 4 ++-- .../Magento/Checkout/Test/Block/Onepage/Payment/Method.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Braintree/view/frontend/web/template/payment/form.html b/app/code/Magento/Braintree/view/frontend/web/template/payment/form.html index 50c252862d6aa..5aead9e823851 100644 --- a/app/code/Magento/Braintree/view/frontend/web/template/payment/form.html +++ b/app/code/Magento/Braintree/view/frontend/web/template/payment/form.html @@ -109,8 +109,8 @@ -