Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.3-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - #13688: #13685 Upgrade jquery.mobile.custom.js to be compatible with jQuery 3.x (by @kirmorozov)
 - #13527: Removing deprecated dependencies from Braintree module (by @joni-jones)
 - #13655: [Port 2.3-develop] Update Store getConfig() to respect valid false return value (by @JeroenVanLeusden)


Fixed GitHub Issues:
 - #13685: Incompatibilies with jQuery 3 (reported by @kirmorozov) has been fixed in #13688 by @kirmorozov in 2.3-develop branch
   Related commits:
     1. c36fb76
     2. b21f2a6
  • Loading branch information
magento-engcom-team authored Mar 17, 2018
2 parents 2847ef2 + 7df4647 commit 3dda470
Show file tree
Hide file tree
Showing 10 changed files with 1,225 additions and 1,052 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
use Magento\Payment\Model\InfoInterface;
use Magento\Sales\Api\Data\OrderPaymentExtensionInterface;
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Api\Data\PaymentTokenInterfaceFactory;

/**
* Vault Details Handler
*/
class VaultDetailsHandler implements HandlerInterface
{
/**
* @var PaymentTokenInterfaceFactory
* @var PaymentTokenFactoryInterface
*/
private $paymentTokenFactory;

Expand All @@ -41,15 +41,13 @@ class VaultDetailsHandler implements HandlerInterface
private $dateTimeFactory;

/**
* Constructor
*
* @param PaymentTokenInterfaceFactory $paymentTokenFactory
* @param PaymentTokenFactoryInterface $paymentTokenFactory
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
* @param SubjectReader $subjectReader
* @param DateTimeFactory $dateTimeFactory
*/
public function __construct(
PaymentTokenInterfaceFactory $paymentTokenFactory,
PaymentTokenFactoryInterface $paymentTokenFactory,
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
SubjectReader $subjectReader,
DateTimeFactory $dateTimeFactory
Expand Down Expand Up @@ -92,7 +90,7 @@ private function getVaultPaymentToken(Transaction $transaction)
}

/** @var PaymentTokenInterface $paymentToken */
$paymentToken = $this->paymentTokenFactory->create();
$paymentToken = $this->paymentTokenFactory->create(PaymentTokenFactoryInterface::TOKEN_TYPE_ACCOUNT);
$paymentToken->setGatewayToken($token);
$paymentToken->setExpiresAt($this->getExpirationDate());
$details = json_encode([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
use Braintree\Transaction;
use Magento\Braintree\Gateway\Config\Config;
use Magento\Braintree\Gateway\Helper\SubjectReader;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Payment\Gateway\Response\HandlerInterface;
use Magento\Payment\Model\InfoInterface;
use Magento\Sales\Api\Data\OrderPaymentExtensionInterface;
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Api\Data\PaymentTokenInterfaceFactory;

/**
* Vault Details Handler
Expand All @@ -22,7 +24,7 @@
class VaultDetailsHandler implements HandlerInterface
{
/**
* @var PaymentTokenInterfaceFactory
* @var PaymentTokenFactoryInterface
*/
protected $paymentTokenFactory;

Expand All @@ -49,26 +51,26 @@ class VaultDetailsHandler implements HandlerInterface
/**
* VaultDetailsHandler constructor.
*
* @param PaymentTokenInterfaceFactory $paymentTokenFactory
* @param PaymentTokenFactoryInterface $paymentTokenFactory
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
* @param Config $config
* @param SubjectReader $subjectReader
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @param Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
PaymentTokenInterfaceFactory $paymentTokenFactory,
PaymentTokenFactoryInterface $paymentTokenFactory,
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
Config $config,
SubjectReader $subjectReader,
\Magento\Framework\Serialize\Serializer\Json $serializer = null
Json $serializer = null
) {
$this->paymentTokenFactory = $paymentTokenFactory;
$this->paymentExtensionFactory = $paymentExtensionFactory;
$this->config = $config;
$this->subjectReader = $subjectReader;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
$this->serializer = $serializer ?: ObjectManager::getInstance()
->get(Json::class);
}

/**
Expand Down Expand Up @@ -103,7 +105,7 @@ protected function getVaultPaymentToken(Transaction $transaction)
}

/** @var PaymentTokenInterface $paymentToken */
$paymentToken = $this->paymentTokenFactory->create();
$paymentToken = $this->paymentTokenFactory->create(PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD);
$paymentToken->setGatewayToken($token);
$paymentToken->setExpiresAt($this->getExpirationDate($transaction));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Magento\Braintree\Model\Adminhtml\Source;

use Magento\Framework\Option\ArrayInterface;
use Magento\Payment\Model\Method\AbstractMethod;
use Magento\Payment\Model\MethodInterface;

/**
* Class PaymentAction
Expand All @@ -22,11 +22,11 @@ public function toOptionArray()
{
return [
[
'value' => AbstractMethod::ACTION_AUTHORIZE,
'value' => MethodInterface::ACTION_AUTHORIZE,
'label' => __('Authorize'),
],
[
'value' => AbstractMethod::ACTION_AUTHORIZE_CAPTURE,
'value' => MethodInterface::ACTION_AUTHORIZE_CAPTURE,
'label' => __('Authorize and Capture'),
]
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Braintree\Test\Unit\Gateway\Response\PayPal;

use Braintree\Result\Successful;
use Braintree\Transaction;
use Braintree\Transaction\PayPalDetails;
use Magento\Braintree\Gateway\Helper\SubjectReader;
Expand All @@ -15,24 +16,23 @@
use Magento\Sales\Api\Data\OrderPaymentExtensionInterface;
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
use Magento\Sales\Model\Order\Payment;
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Api\Data\PaymentTokenInterfaceFactory;
use Magento\Vault\Model\AccountPaymentTokenFactory;
use Magento\Vault\Model\PaymentToken;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Class VaultDetailsHandlerTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class VaultDetailsHandlerTest extends \PHPUnit\Framework\TestCase
class VaultDetailsHandlerTest extends TestCase
{
private static $transactionId = '1n2suy';

/**
* @var SubjectReader|MockObject
*/
private $subjectReader;
private static $token = 'rc39al';

private static $payerEmail = '[email protected]';

/**
* @var PaymentDataObjectInterface|MockObject
Expand All @@ -45,7 +45,7 @@ class VaultDetailsHandlerTest extends \PHPUnit\Framework\TestCase
private $paymentInfo;

/**
* @var AccountPaymentTokenFactory|MockObject
* @var PaymentTokenFactoryInterface|MockObject
*/
private $paymentTokenFactory;

Expand Down Expand Up @@ -92,7 +92,7 @@ protected function setUp()

$this->paymentToken = $objectManager->getObject(PaymentToken::class);

$this->paymentTokenFactory = $this->getMockBuilder(AccountPaymentTokenFactory::class)
$this->paymentTokenFactory = $this->getMockBuilder(PaymentTokenFactoryInterface::class)
->setMethods(['create'])
->disableOriginalConstructor()
->getMock();
Expand All @@ -109,14 +109,6 @@ protected function setUp()
$this->subject = [
'payment' => $this->paymentDataObject,
];
$this->subjectReader = $this->getMockBuilder(SubjectReader::class)
->disableOriginalConstructor()
->setMethods(['readPayment', 'readTransaction'])
->getMock();
$this->subjectReader->expects(static::once())
->method('readPayment')
->with($this->subject)
->willReturn($this->paymentDataObject);

$this->dateTimeFactory = $this->getMockBuilder(DateTimeFactory::class)
->disableOriginalConstructor()
Expand All @@ -126,123 +118,102 @@ protected function setUp()
$this->handler = new VaultDetailsHandler(
$this->paymentTokenFactory,
$this->paymentExtensionFactory,
$this->subjectReader,
new SubjectReader(),
$this->dateTimeFactory
);
}

/**
* @covers \Magento\Braintree\Gateway\Response\PayPal\VaultDetailsHandler::handle
*/
public function testHandle()
{
/** @var Transaction $transaction */
$transaction = $this->getTransaction();
$response = [
'object' => $transaction
];

$this->paymentExtension->expects(static::once())
->method('setVaultPaymentToken')
$this->paymentExtension->method('setVaultPaymentToken')
->with($this->paymentToken);
$this->paymentExtension->expects(static::once())
->method('getVaultPaymentToken')
$this->paymentExtension->method('getVaultPaymentToken')
->willReturn($this->paymentToken);

$this->subjectReader->expects(static::once())
->method('readTransaction')
->with($response)
->willReturn($transaction);

$this->paymentDataObject->expects(static::once())
->method('getPayment')
$this->paymentDataObject->method('getPayment')
->willReturn($this->paymentInfo);

$this->paymentTokenFactory->expects(static::once())
->method('create')
$this->paymentTokenFactory->method('create')
->with(PaymentTokenFactoryInterface::TOKEN_TYPE_ACCOUNT)
->willReturn($this->paymentToken);

$this->paymentExtensionFactory->expects(static::once())
->method('create')
$this->paymentExtensionFactory->method('create')
->willReturn($this->paymentExtension);

$dateTime = new \DateTime('2016-07-05 00:00:00', new \DateTimeZone('UTC'));
$expirationDate = '2017-07-05 00:00:00';
$this->dateTimeFactory->expects(static::once())
->method('create')
$this->dateTimeFactory->method('create')
->willReturn($dateTime);

$this->handler->handle($this->subject, $response);

$extensionAttributes = $this->paymentInfo->getExtensionAttributes();
/** @var PaymentTokenInterface $paymentToken */
$paymentToken = $extensionAttributes->getVaultPaymentToken();
static::assertNotNull($paymentToken);
self::assertNotNull($paymentToken);

$tokenDetails = json_decode($paymentToken->getTokenDetails(), true);

static::assertSame($this->paymentToken, $paymentToken);
static::assertEquals($transaction->paypalDetails->token, $paymentToken->getGatewayToken());
static::assertEquals($transaction->paypalDetails->payerEmail, $tokenDetails['payerEmail']);
static::assertEquals($expirationDate, $paymentToken->getExpiresAt());
self::assertSame($this->paymentToken, $paymentToken);
self::assertEquals(self::$token, $paymentToken->getGatewayToken());
self::assertEquals(self::$payerEmail, $tokenDetails['payerEmail']);
self::assertEquals($expirationDate, $paymentToken->getExpiresAt());
}

/**
* @covers \Magento\Braintree\Gateway\Response\PayPal\VaultDetailsHandler::handle
*/
public function testHandleWithoutToken()
{
$transaction = $this->getTransaction();
$transaction->paypalDetails->token = null;
$transaction->transaction->paypalDetails->token = null;

$response = [
'object' => $transaction
];

$this->subjectReader->expects(static::once())
->method('readTransaction')
->with($response)
->willReturn($transaction);

$this->paymentDataObject->expects(static::once())
->method('getPayment')
$this->paymentDataObject->method('getPayment')
->willReturn($this->paymentInfo);

$this->paymentTokenFactory->expects(static::never())
$this->paymentTokenFactory->expects(self::never())
->method('create');

$this->dateTimeFactory->expects(static::never())
$this->dateTimeFactory->expects(self::never())
->method('create');

$this->handler->handle($this->subject, $response);
static::assertNull($this->paymentInfo->getExtensionAttributes());
self::assertNull($this->paymentInfo->getExtensionAttributes());
}

/**
* Create Braintree transaction
* @return Transaction
* Creates Braintree transaction.
*
* @return Successful
*/
private function getTransaction()
private function getTransaction(): Successful
{
$attributes = [
'id' => self::$transactionId,
'paypalDetails' => $this->getPayPalDetails()
];

$transaction = Transaction::factory($attributes);
$result = new Successful(['transaction' => $transaction]);

return $transaction;
return $result;
}

/**
* Get PayPal transaction details
* Gets PayPal transaction details.
*
* @return PayPalDetails
*/
private function getPayPalDetails()
private function getPayPalDetails(): PayPalDetails
{
$attributes = [
'token' => 'rc39al',
'payerEmail' => '[email protected]'
'token' => self::$token,
'payerEmail' => self::$payerEmail
];

$details = new PayPalDetails($attributes);
Expand Down
Loading

0 comments on commit 3dda470

Please sign in to comment.