Skip to content

Commit

Permalink
Merge pull request #460 from magento-mpi/MPI-PR-bugfixes
Browse files Browse the repository at this point in the history
Fixed Issues:

- MAGETWO-58670 Unable to go to PayPal side from first attempt after applying discount on checkout
- MAGETWO-58997 Copy past detector fails in Vault module
- MAGETWO-59033 [Github] Authorize.net doesn't allow to use JCB and Diners Club credit cards
- MAGETWO-59187 Magento\Checkout\Test\TestCase\OnePageCheckoutTest fails on variation OnePageCheckoutUspsTestVariation2
  • Loading branch information
sdwright authored Oct 4, 2016
2 parents 36b07c7 + 18895de commit ad37944
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 218 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Authorizenet/Model/Source/Cctype.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class Cctype extends PaymentCctype
*/
public function getAllowedTypes()
{
return ['VI', 'MC', 'AE', 'DI'];
return ['VI', 'MC', 'AE', 'DI', 'JCB', 'DN'];
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Authorizenet/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<payment>
<authorizenet_directpost>
<active>0</active>
<cctypes>AE,VI,MC,DI</cctypes>
<cctypes>AE,VI,MC,DI,JCB,DN</cctypes>
<debug>0</debug>
<email_customer>0</email_customer>
<login backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ define(
) {
'use strict';

// State of PayPal module initialization
var clientInit = false;

return Component.extend({

defaults: {
Expand Down Expand Up @@ -93,15 +96,26 @@ define(
* @returns {Object}
*/
initClient: function () {
var selector = '#' + this.getButtonId();

_.each(this.clientConfig, function (fn, name) {
if (typeof fn === 'function') {
this.clientConfig[name] = fn.bind(this);
}
}, this);

domObserver.get('#' + this.getButtonId(), function () {
paypalExpressCheckout.checkout.setup(this.merchantId, this.clientConfig);
}.bind(this));
if (!clientInit) {
domObserver.get(selector, function () {
paypalExpressCheckout.checkout.setup(this.merchantId, this.clientConfig);
clientInit = true;
domObserver.off(selector);
}.bind(this));
} else {
domObserver.get(selector, function () {
$(selector).on('click', this.clientConfig.click);
domObserver.off(selector);
}.bind(this));
}

return this;
},
Expand Down
30 changes: 30 additions & 0 deletions app/code/Magento/Vault/Api/PaymentMethodListInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Vault\Api;

use Magento\Vault\Model\VaultPaymentInterface;

/**
* Contains methods to retrieve vault payment methods
* This interface is consistent with \Magento\Payment\Api\PaymentMethodListInterface
* @api
*/
interface PaymentMethodListInterface
{
/**
* Get list of available vault payments
* @param int $storeId
* @return VaultPaymentInterface[]
*/
public function getList($storeId);

/**
* Get list of enabled in the configuration vault payments
* @param int $storeId
* @return VaultPaymentInterface[]
*/
public function getActiveList($storeId);
}
78 changes: 78 additions & 0 deletions app/code/Magento/Vault/Model/PaymentMethodList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Vault\Model;

use Magento\Payment\Api\Data\PaymentMethodInterface;
use Magento\Payment\Api\PaymentMethodListInterface;
use Magento\Payment\Model\Method\InstanceFactory;
use Magento\Payment\Model\MethodInterface;
use Magento\Vault\Api\PaymentMethodListInterface as VaultPaymentMethodListInterface;

/**
* Contains methods to retrieve configured vault payments
*/
class PaymentMethodList implements VaultPaymentMethodListInterface
{
/**
* @var InstanceFactory
*/
private $instanceFactory;

/**
* @var PaymentMethodListInterface
*/
private $paymentMethodList;

/**
* PaymentMethodList constructor.
* @param PaymentMethodListInterface $paymentMethodList
* @param InstanceFactory $instanceFactory
*/
public function __construct(PaymentMethodListInterface $paymentMethodList, InstanceFactory $instanceFactory)
{
$this->instanceFactory = $instanceFactory;
$this->paymentMethodList = $paymentMethodList;
}

/**
* @inheritdoc
*/
public function getList($storeId)
{
return $this->filterList($this->paymentMethodList->getList($storeId));
}

/**
* @inheritdoc
*/
public function getActiveList($storeId)
{
return $this->filterList($this->paymentMethodList->getActiveList($storeId));
}

/**
* Filter vault methods from payments
* @param PaymentMethodInterface[] $list
* @return VaultPaymentInterface[]
*/
private function filterList(array $list)
{
$paymentMethods = array_map(
function (PaymentMethodInterface $paymentMethod) {
return $this->instanceFactory->create($paymentMethod);
},
$list
);

$availableMethods = array_filter(
$paymentMethods,
function (MethodInterface $methodInstance) {
return $methodInstance instanceof VaultPaymentInterface;
}
);
return array_values($availableMethods);
}
}
72 changes: 11 additions & 61 deletions app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Payment\Api\Data\PaymentMethodInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Vault\Api\PaymentMethodListInterface;
use Magento\Vault\Model\CustomerTokenManagement;
use Magento\Vault\Model\VaultPaymentInterface;

/**
* Class ConfigProvider
Expand Down Expand Up @@ -39,14 +38,9 @@ final class TokensConfigProvider implements ConfigProviderInterface
private $customerTokenManagement;

/**
* @var \Magento\Payment\Api\PaymentMethodListInterface
* @var PaymentMethodListInterface
*/
private $paymentMethodList;

/**
* @var \Magento\Payment\Model\Method\InstanceFactory
*/
private $paymentMethodInstanceFactory;
private $vaultPaymentList;

/**
* Constructor
Expand Down Expand Up @@ -112,7 +106,8 @@ public function getConfig()
private function getComponentProviders()
{
$providers = [];
$vaultPaymentMethods = $this->getVaultPaymentMethodList();
$storeId = $this->storeManager->getStore()->getId();
$vaultPaymentMethods = $this->getVaultPaymentList()->getActiveList($storeId);

foreach ($vaultPaymentMethods as $method) {
$providerCode = $method->getProviderCode();
Expand Down Expand Up @@ -141,60 +136,15 @@ private function getComponentProvider($vaultProviderCode)
}

/**
* Get list of active Vault payment methods.
*
* @return VaultPaymentInterface[]
*/
private function getVaultPaymentMethodList()
{
$storeId = $this->storeManager->getStore()->getId();

$paymentMethods = array_map(
function (PaymentMethodInterface $paymentMethod) {
return $this->getPaymentMethodInstanceFactory()->create($paymentMethod);
},
$this->getPaymentMethodList()->getActiveList($storeId)
);

$availableMethods = array_filter(
$paymentMethods,
function (\Magento\Payment\Model\MethodInterface $methodInstance) {
return $methodInstance instanceof VaultPaymentInterface;
}
);

return $availableMethods;
}

/**
* Get payment method list.
*
* @return \Magento\Payment\Api\PaymentMethodListInterface
* @deprecated
*/
private function getPaymentMethodList()
{
if ($this->paymentMethodList === null) {
$this->paymentMethodList = ObjectManager::getInstance()->get(
\Magento\Payment\Api\PaymentMethodListInterface::class
);
}
return $this->paymentMethodList;
}

/**
* Get payment method instance factory.
*
* @return \Magento\Payment\Model\Method\InstanceFactory
* Get instance of vault payment list instance
* @return PaymentMethodListInterface
* @deprecated
*/
private function getPaymentMethodInstanceFactory()
private function getVaultPaymentList()
{
if ($this->paymentMethodInstanceFactory === null) {
$this->paymentMethodInstanceFactory = ObjectManager::getInstance()->get(
\Magento\Payment\Model\Method\InstanceFactory::class
);
if ($this->vaultPaymentList === null) {
$this->vaultPaymentList = ObjectManager::getInstance()->get(PaymentMethodListInterface::class);
}
return $this->paymentMethodInstanceFactory;
return $this->vaultPaymentList;
}
}
73 changes: 11 additions & 62 deletions app/code/Magento/Vault/Model/Ui/VaultConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Payment\Api\Data\PaymentMethodInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Vault\Model\VaultPaymentInterface;
use Magento\Vault\Api\PaymentMethodListInterface;

class VaultConfigProvider implements ConfigProviderInterface
{
Expand All @@ -32,14 +31,9 @@ class VaultConfigProvider implements ConfigProviderInterface
private $session;

/**
* @var \Magento\Payment\Api\PaymentMethodListInterface
* @var PaymentMethodListInterface
*/
private $paymentMethodList;

/**
* @var \Magento\Payment\Model\Method\InstanceFactory
*/
private $paymentMethodInstanceFactory;
private $vaultPaymentList;

/**
* VaultConfigProvider constructor.
Expand All @@ -62,9 +56,9 @@ public function __construct(
public function getConfig()
{
$availableMethods = [];
$vaultPayments = $this->getVaultPaymentMethodList();
$customerId = $this->session->getCustomerId();
$storeId = $this->storeManager->getStore()->getId();
$vaultPayments = $this->getVaultPaymentList()->getActiveList($storeId);
$customerId = $this->session->getCustomerId();

foreach ($vaultPayments as $method) {
$availableMethods[$method->getCode()] = [
Expand All @@ -78,60 +72,15 @@ public function getConfig()
}

/**
* Get list of active Vault payment methods.
*
* @return VaultPaymentInterface[]
*/
private function getVaultPaymentMethodList()
{
$storeId = $this->storeManager->getStore()->getId();

$paymentMethods = array_map(
function (PaymentMethodInterface $paymentMethod) {
return $this->getPaymentMethodInstanceFactory()->create($paymentMethod);
},
$this->getPaymentMethodList()->getActiveList($storeId)
);

$availableMethods = array_filter(
$paymentMethods,
function (\Magento\Payment\Model\MethodInterface $methodInstance) {
return $methodInstance instanceof VaultPaymentInterface;
}
);

return $availableMethods;
}

/**
* Get payment method list.
*
* @return \Magento\Payment\Api\PaymentMethodListInterface
* @deprecated
*/
private function getPaymentMethodList()
{
if ($this->paymentMethodList === null) {
$this->paymentMethodList = ObjectManager::getInstance()->get(
\Magento\Payment\Api\PaymentMethodListInterface::class
);
}
return $this->paymentMethodList;
}

/**
* Get payment method instance factory.
*
* @return \Magento\Payment\Model\Method\InstanceFactory
* Get vault payment list instance
* @return PaymentMethodListInterface
* @deprecated
*/
private function getPaymentMethodInstanceFactory()
private function getVaultPaymentList()
{
if ($this->paymentMethodInstanceFactory === null) {
$this->paymentMethodInstanceFactory = ObjectManager::getInstance()->get(
\Magento\Payment\Model\Method\InstanceFactory::class
);
if ($this->vaultPaymentList === null) {
$this->vaultPaymentList = ObjectManager::getInstance()->get(PaymentMethodListInterface::class);
}
return $this->paymentMethodInstanceFactory;
return $this->vaultPaymentList;
}
}
Loading

0 comments on commit ad37944

Please sign in to comment.