Skip to content

Commit 2fd612b

Browse files
committed
Verify payout currency
1 parent 54ba87e commit 2fd612b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Message/PayoutRequest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Omnipay\WebMoney\Message;
44

5+
use Omnipay\Common\Exception\InvalidRequestException;
6+
57
/**
68
* WebMoney Payout Request
79
* http://wiki.wmtransfer.com/projects/webmoney/wiki/Interface_X2.
@@ -203,9 +205,14 @@ public function getData()
203205
'sslKey',
204206
'transactionId',
205207
'description',
208+
'currency',
206209
'amount'
207210
);
208211

212+
if ($this->getCurrencyByPurse($this->getMerchantPurse()) !== $this->getCurrency()) {
213+
throw new InvalidRequestException('Invalid currency for this merchant purse');
214+
}
215+
209216
$document = new \DOMDocument('1.0', 'utf-8');
210217
$document->formatOutput = false;
211218

tests/Message/PayoutRequestTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function setUp()
2323
$httpClient->addSubscriber($mockPlugin);
2424

2525
$this->request = new PayoutRequest($httpClient, $this->getHttpRequest());
26-
$this->request->initialize(array(
26+
$this->request->initialize([
2727
'webMoneyId' => '811333344777',
2828
'merchantPurse' => 'Z123428476799',
2929
'secretKey' => '226778888',
@@ -37,8 +37,20 @@ public function setUp()
3737
'invoiceId' => '12345678',
3838
'onlyAuth' => false,
3939
'description' => 'Payout',
40+
'currency' => 'USD',
4041
'amount' => '12.46'
41-
));
42+
]);
43+
}
44+
45+
public function testException()
46+
{
47+
$this->request->setCurrency('EUR');
48+
49+
try {
50+
$this->request->getData();
51+
} catch (\Exception $e) {
52+
$this->assertEquals('Omnipay\Common\Exception\InvalidRequestException', get_class($e));
53+
}
4254
}
4355

4456
public function testGetData()

0 commit comments

Comments
 (0)