diff --git a/app/code/Magento/Payment/Plugin/PaymentConfigurationProcess.php b/app/code/Magento/Payment/Plugin/PaymentConfigurationProcess.php index b1e36b7ae39f3..5b107b74295b3 100644 --- a/app/code/Magento/Payment/Plugin/PaymentConfigurationProcess.php +++ b/app/code/Magento/Payment/Plugin/PaymentConfigurationProcess.php @@ -59,10 +59,9 @@ public function beforeProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $ $activePaymentMethodCodes = array_map($getCodeFunc, $activePaymentMethodList); foreach ($configuration as $paymentGroup => $groupConfig) { - foreach (array_keys($groupConfig['methods']) as $paymentCode) { - if (!in_array($paymentCode, $activePaymentMethodCodes)) { - unset($configuration[$paymentGroup]['methods'][$paymentCode]); - } + $notActivePaymentMethodCodes = array_diff(array_keys($groupConfig['methods']), $activePaymentMethodCodes); + foreach ($notActivePaymentMethodCodes as $notActivePaymentMethodCode) { + unset($configuration[$paymentGroup]['methods'][$notActivePaymentMethodCode]); } if (empty($configuration[$paymentGroup]['methods'])) { unset($configuration[$paymentGroup]); diff --git a/app/code/Magento/Payment/Test/Unit/Plugin/PaymentConfigurationProcessTest.php b/app/code/Magento/Payment/Test/Unit/Plugin/PaymentConfigurationProcessTest.php index be5755440066e..3e49c8718e604 100644 --- a/app/code/Magento/Payment/Test/Unit/Plugin/PaymentConfigurationProcessTest.php +++ b/app/code/Magento/Payment/Test/Unit/Plugin/PaymentConfigurationProcessTest.php @@ -98,6 +98,23 @@ public function testBeforeProcess($jsLayout, $activePaymentList, $expectedResult public function beforeProcessDataProvider() { $jsLayout['components']['checkout']['children']['steps']['children']['billing-step'] + ['children']['payment']['children']['renders']['children'] = [ + 'braintree' => [ + 'methods' => [ + 'braintree_paypal' => [], + 'braintree' => [] + ] + ], + 'paypal-payments' => [ + 'methods' => [ + 'payflowpro' => [], + 'payflow_link' => [] + ] + ] + ]; + $result1['components']['checkout']['children']['steps']['children']['billing-step'] + ['children']['payment']['children']['renders']['children'] = []; + $result2['components']['checkout']['children']['steps']['children']['billing-step'] ['children']['payment']['children']['renders']['children'] = [ 'braintree' => [ 'methods' => [ @@ -106,8 +123,6 @@ public function beforeProcessDataProvider() ] ] ]; - $result['components']['checkout']['children']['steps']['children']['billing-step'] - ['children']['payment']['children']['renders']['children'] = []; $braintreePaymentMethod = $this ->getMockBuilder(\Magento\Payment\Api\Data\PaymentMethodInterface::class) @@ -124,8 +139,8 @@ public function beforeProcessDataProvider() $braintreePaypalPaymentMethod->expects($this->any())->method('getCode')->willReturn('braintree_paypal'); return [ - [$jsLayout, [], $result], - [$jsLayout, [$braintreePaymentMethod, $braintreePaypalPaymentMethod], $jsLayout] + [$jsLayout, [], $result1], + [$jsLayout, [$braintreePaymentMethod, $braintreePaypalPaymentMethod], $result2] ]; } } diff --git a/app/code/Magento/Vault/Plugin/PaymentVaultConfigurationProcess.php b/app/code/Magento/Vault/Plugin/PaymentVaultConfigurationProcess.php index 666e0b186309e..db38ccbed417a 100644 --- a/app/code/Magento/Vault/Plugin/PaymentVaultConfigurationProcess.php +++ b/app/code/Magento/Vault/Plugin/PaymentVaultConfigurationProcess.php @@ -69,21 +69,18 @@ public function beforeProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $ return $method->getProviderCode(); }; $activePaymentMethodCodes = array_map($getCodeFunc, $activePaymentMethodList); - $activeVaultCodes = array_map($getCodeFunc, $activeVaultList); $activeVaultProviderCodes = array_map($getProviderCodeFunc, $activeVaultList); $activePaymentMethodCodes = array_merge( $activePaymentMethodCodes, - $activeVaultCodes, $activeVaultProviderCodes ); foreach ($configuration as $paymentGroup => $groupConfig) { - foreach (array_keys($groupConfig['methods']) as $paymentCode) { - if (!in_array($paymentCode, $activePaymentMethodCodes)) { - unset($configuration[$paymentGroup]['methods'][$paymentCode]); - } + $notActivePaymentMethodCodes = array_diff(array_keys($groupConfig['methods']), $activePaymentMethodCodes); + foreach ($notActivePaymentMethodCodes as $notActivePaymentMethodCode) { + unset($configuration[$paymentGroup]['methods'][$notActivePaymentMethodCode]); } - if ($paymentGroup === 'vault' && !empty($activeVaultCodes)) { + if ($paymentGroup === 'vault' && !empty($activeVaultProviderCodes)) { continue; } if (empty($configuration[$paymentGroup]['methods'])) { diff --git a/app/code/Magento/Vault/Test/Unit/Plugin/PaymentVaultConfigurationProcessTest.php b/app/code/Magento/Vault/Test/Unit/Plugin/PaymentVaultConfigurationProcessTest.php index 0cf64c5424740..7e7a3fd0aebdf 100644 --- a/app/code/Magento/Vault/Test/Unit/Plugin/PaymentVaultConfigurationProcessTest.php +++ b/app/code/Magento/Vault/Test/Unit/Plugin/PaymentVaultConfigurationProcessTest.php @@ -112,9 +112,7 @@ public function beforeProcessDataProvider() $jsLayout['components']['checkout']['children']['steps']['children']['billing-step'] ['children']['payment']['children']['renders']['children'] = [ 'vault' => [ - 'methods' => [ - 'braintree_paypal_vault' => [] - ] + 'methods' => [] ], 'braintree' => [ 'methods' => [ @@ -134,9 +132,7 @@ public function beforeProcessDataProvider() $result2['components']['checkout']['children']['steps']['children']['billing-step'] ['children']['payment']['children']['renders']['children'] = [ 'vault' => [ - 'methods' => [ - 'braintree_paypal_vault' => [] - ] + 'methods' => [] ], 'braintree' => [ 'methods' => [ @@ -156,7 +152,7 @@ public function beforeProcessDataProvider() return [ [$jsLayout, [], [], $result1], - [$jsLayout, [$vaultPaymentMethod], [], $result2] + [$jsLayout, [$vaultPaymentMethod], [$vaultPaymentMethod], $result2] ]; } }