Skip to content

Commit b90e0fe

Browse files
author
Sergey Shvets
committed
MAGETWO-68811: [Backport] - Payflow Pro zero amount transaction in wrong currency - for 2.1
1 parent ff253a7 commit b90e0fe

File tree

2 files changed

+87
-19
lines changed

2 files changed

+87
-19
lines changed

app/code/Magento/Paypal/Model/Payflow/Service/Request/SecureToken.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Paypal\Model\Payflow\Service\Request;
78

89
use Magento\Framework\Math\Random;
@@ -11,7 +12,6 @@
1112
use Magento\Paypal\Model\Payflow\Transparent;
1213
use Magento\Paypal\Model\Payflowpro;
1314
use Magento\Quote\Model\Quote;
14-
use Magento\Sales\Model\Order\Payment;
1515

1616
/**
1717
* Class SecureToken
@@ -64,6 +64,7 @@ public function requestToken(Quote $quote)
6464
$request->setTrxtype(Payflowpro::TRXTYPE_AUTH_ONLY);
6565
$request->setVerbosity('HIGH');
6666
$request->setAmt(0);
67+
$request->setCurrency($quote->getBaseCurrencyCode());
6768
$request->setCreatesecuretoken('Y');
6869
$request->setSecuretokenid($this->mathRandom->getUniqueHash());
6970
$request->setReturnurl($this->url->getUrl('paypal/transparent/response'));

app/code/Magento/Paypal/Test/Unit/Model/Payflow/Service/Request/SecureTokenTest.php

Lines changed: 85 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Paypal\Test\Unit\Model\Payflow\Service\Request;
78

89
use Magento\Framework\Math\Random;
910
use Magento\Framework\DataObject;
1011
use Magento\Framework\UrlInterface;
1112
use Magento\Paypal\Model\Payflow\Service\Request\SecureToken;
1213
use Magento\Paypal\Model\Payflow\Transparent;
14+
use Magento\Paypal\Model\PayflowConfig;
15+
use Magento\Quote\Model\Quote;
1316

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

42+
/** @var DataObject */
43+
private $request;
44+
3945
protected function setUp()
4046
{
41-
$this->url = $this->getMock('Magento\Framework\UrlInterface', [], [], '', false);
42-
$this->mathRandom = $this->getMock('Magento\Framework\Math\Random', [], [], '', false);
43-
$this->transparent = $this->getMock('Magento\Paypal\Model\Payflow\Transparent', [], [], '', false);
47+
$this->url = $this->buildMock(UrlInterface::class);
48+
$this->mathRandom = $this->buildMock(Random::class);
49+
$this->request = new DataObject();
50+
51+
$this->transparent = $this->buildPaymentService($this->request);
4452

4553
$this->model = new SecureToken(
4654
$this->url,
@@ -49,34 +57,93 @@ protected function setUp()
4957
);
5058
}
5159

60+
/**
61+
* Test Request Token
62+
*/
5263
public function testRequestToken()
5364
{
54-
$request = new DataObject();
5565
$secureTokenID = 'Sdj46hDokds09c8k2klaGJdKLl032ekR';
5666

57-
$this->transparent->expects($this->once())
58-
->method('buildBasicRequest')
59-
->willReturn($request);
60-
$this->transparent->expects($this->once())
61-
->method('fillCustomerContacts');
62-
$this->transparent->expects($this->once())
63-
->method('getConfig')
64-
->willReturn($this->getMock('Magento\Paypal\Model\PayflowConfig', [], [], '', false));
65-
$this->transparent->expects($this->once())
66-
->method('postRequest')
67-
->willReturn(new DataObject());
68-
6967
$this->mathRandom->expects($this->once())
7068
->method('getUniqueHash')
7169
->willReturn($secureTokenID);
7270

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

76-
$quote = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false);
74+
/** @var Quote | \PHPUnit_Framework_MockObject_MockObject $quote */
75+
$quote = $this->buildMock(Quote::class);
76+
77+
$this->model->requestToken($quote);
78+
79+
$this->assertEquals($secureTokenID, $this->request->getSecuretokenid());
80+
}
81+
82+
/**
83+
* Test request currency
84+
*
85+
* @dataProvider currencyProvider
86+
* @param $currency
87+
*/
88+
public function testCurrency($currency)
89+
{
90+
/** @var Quote | \PHPUnit_Framework_MockObject_MockObject $quote */
91+
$quote = $this->buildMock(Quote::class, ['getBaseCurrencyCode']);
92+
$quote->expects(self::atLeastOnce())
93+
->method('getBaseCurrencyCode')
94+
->willReturn($currency);
7795

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

80-
$this->assertEquals($secureTokenID, $request->getSecuretokenid());
98+
$this->assertEquals($currency, $this->request->getCurrency());
99+
}
100+
101+
/**
102+
* Builds default mock object
103+
*
104+
* @param string $class className
105+
* @param array|null $methods
106+
* @return \PHPUnit_Framework_MockObject_MockObject
107+
*/
108+
private function buildMock($class, array $methods = [])
109+
{
110+
return $this->getMockBuilder($class)
111+
->disableOriginalConstructor()
112+
->setMethods($methods)
113+
->getMock();
114+
}
115+
116+
/**
117+
* Creates payment method service
118+
*
119+
* @param DataObject $request
120+
* @return Transparent | \PHPUnit_Framework_MockObject_MockObject
121+
*/
122+
private function buildPaymentService(DataObject $request)
123+
{
124+
$service = $this->buildMock(Transparent::class);
125+
$service->expects($this->once())
126+
->method('buildBasicRequest')
127+
->willReturn($request);
128+
$service->expects($this->once())
129+
->method('fillCustomerContacts');
130+
$service->expects($this->once())
131+
->method('getConfig')
132+
->willReturn($this->buildMock(PayflowConfig::class));
133+
$service->expects($this->once())
134+
->method('postRequest')
135+
->willReturn(new DataObject());
136+
137+
return $service;
138+
}
139+
140+
/**
141+
* DataProvider for testing currency
142+
*
143+
* @return array
144+
*/
145+
public function currencyProvider()
146+
{
147+
return [['GBP'], [null], ['USD']];
81148
}
82149
}

0 commit comments

Comments
 (0)