Skip to content

Commit

Permalink
Merge pull request #1284 from magento-east/pr-218
Browse files Browse the repository at this point in the history
[East] Bugfix for 2.1.8
  • Loading branch information
Volodymyr Klymenko authored Jul 6, 2017
2 parents 0ad9891 + ca1c4bd commit ca53c80
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Paypal\Model\Payflow\Service\Request;

use Magento\Framework\Math\Random;
Expand All @@ -11,7 +12,6 @@
use Magento\Paypal\Model\Payflow\Transparent;
use Magento\Paypal\Model\Payflowpro;
use Magento\Quote\Model\Quote;
use Magento\Sales\Model\Order\Payment;

/**
* Class SecureToken
Expand Down Expand Up @@ -64,6 +64,7 @@ public function requestToken(Quote $quote)
$request->setTrxtype(Payflowpro::TRXTYPE_AUTH_ONLY);
$request->setVerbosity('HIGH');
$request->setAmt(0);
$request->setCurrency($quote->getBaseCurrencyCode());
$request->setCreatesecuretoken('Y');
$request->setSecuretokenid($this->mathRandom->getUniqueHash());
$request->setReturnurl($this->url->getUrl('paypal/transparent/response'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Paypal\Test\Unit\Model\Payflow\Service\Request;

use Magento\Framework\Math\Random;
use Magento\Framework\DataObject;
use Magento\Framework\UrlInterface;
use Magento\Paypal\Model\Payflow\Service\Request\SecureToken;
use Magento\Paypal\Model\Payflow\Transparent;
use Magento\Paypal\Model\PayflowConfig;
use Magento\Quote\Model\Quote;

/**
* Test class for \Magento\Paypal\Model\Payflow\Service\Request\SecureToken
Expand All @@ -36,11 +39,16 @@ class SecureTokenTest extends \PHPUnit_Framework_TestCase
*/
protected $url;

/** @var DataObject */
private $request;

protected function setUp()
{
$this->url = $this->getMock('Magento\Framework\UrlInterface', [], [], '', false);
$this->mathRandom = $this->getMock('Magento\Framework\Math\Random', [], [], '', false);
$this->transparent = $this->getMock('Magento\Paypal\Model\Payflow\Transparent', [], [], '', false);
$this->url = $this->buildMock(UrlInterface::class);
$this->mathRandom = $this->buildMock(Random::class);
$this->request = new DataObject();

$this->transparent = $this->buildPaymentService($this->request);

$this->model = new SecureToken(
$this->url,
Expand All @@ -49,34 +57,93 @@ protected function setUp()
);
}

/**
* Test Request Token
*/
public function testRequestToken()
{
$request = new DataObject();
$secureTokenID = 'Sdj46hDokds09c8k2klaGJdKLl032ekR';

$this->transparent->expects($this->once())
->method('buildBasicRequest')
->willReturn($request);
$this->transparent->expects($this->once())
->method('fillCustomerContacts');
$this->transparent->expects($this->once())
->method('getConfig')
->willReturn($this->getMock('Magento\Paypal\Model\PayflowConfig', [], [], '', false));
$this->transparent->expects($this->once())
->method('postRequest')
->willReturn(new DataObject());

$this->mathRandom->expects($this->once())
->method('getUniqueHash')
->willReturn($secureTokenID);

$this->url->expects($this->exactly(3))
->method('getUrl');

$quote = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false);
/** @var Quote | \PHPUnit_Framework_MockObject_MockObject $quote */
$quote = $this->buildMock(Quote::class);

$this->model->requestToken($quote);

$this->assertEquals($secureTokenID, $this->request->getSecuretokenid());
}

/**
* Test request currency
*
* @dataProvider currencyProvider
* @param $currency
*/
public function testCurrency($currency)
{
/** @var Quote | \PHPUnit_Framework_MockObject_MockObject $quote */
$quote = $this->buildMock(Quote::class, ['getBaseCurrencyCode']);
$quote->expects(self::atLeastOnce())
->method('getBaseCurrencyCode')
->willReturn($currency);

$this->model->requestToken($quote);

$this->assertEquals($secureTokenID, $request->getSecuretokenid());
$this->assertEquals($currency, $this->request->getCurrency());
}

/**
* Builds default mock object
*
* @param string $class className
* @param array|null $methods
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function buildMock($class, array $methods = [])
{
return $this->getMockBuilder($class)
->disableOriginalConstructor()
->setMethods($methods)
->getMock();
}

/**
* Creates payment method service
*
* @param DataObject $request
* @return Transparent | \PHPUnit_Framework_MockObject_MockObject
*/
private function buildPaymentService(DataObject $request)
{
$service = $this->buildMock(Transparent::class);
$service->expects($this->once())
->method('buildBasicRequest')
->willReturn($request);
$service->expects($this->once())
->method('fillCustomerContacts');
$service->expects($this->once())
->method('getConfig')
->willReturn($this->buildMock(PayflowConfig::class));
$service->expects($this->once())
->method('postRequest')
->willReturn(new DataObject());

return $service;
}

/**
* DataProvider for testing currency
*
* @return array
*/
public function currencyProvider()
{
return [['GBP'], [null], ['USD']];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<data name="shipping/shipping_method" xsi:type="string">Express easy</data>
<data name="cart/data/shipping_method" xsi:type="string">Express easy</data>
<data name="payment/method" xsi:type="string">checkmo</data>
<data name="configData" xsi:type="string">checkmo, dhl_eu, shipping_origin_CH, config_base_currency_ch</data>
<data name="configData" xsi:type="string">checkmo, dhl_eu, shipping_origin_GB, config_base_currency_gb</data>
<data name="tag" xsi:type="string">test_type:3rd_party_test</data>
<constraint name="Magento\Checkout\Test\Constraint\AssertOrderSuccessPlacedMessage" />
<constraint name="Magento\Checkout\Test\Constraint\AssertMinicartEmpty" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,31 @@
<item name="value" xsi:type="string">Weinbergstrasse 4</item>
</field>
</dataset>
<dataset name="shipping_origin_GB">
<field name="shipping/origin/country_id" xsi:type="array">
<item name="scope" xsi:type="string">carriers</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string">United Kingdom</item>
<item name="value" xsi:type="string">GB</item>
</field>
<field name="shipping/origin/postcode" xsi:type="array">
<item name="scope" xsi:type="string">shipping</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string"/>
<item name="value" xsi:type="string">SW1W 8JA</item>
</field>
<field name="shipping/origin/city" xsi:type="array">
<item name="scope" xsi:type="string">shipping</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string"/>
<item name="value" xsi:type="string">London</item>
</field>
<field name="shipping/origin/street_line1" xsi:type="array">
<item name="scope" xsi:type="string">shipping</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string"/>
<item name="value" xsi:type="string">Bourne St</item>
</field>
</dataset>
</repository>
</config>

0 comments on commit ca53c80

Please sign in to comment.