Skip to content

Commit c8aeffd

Browse files
committed
Validation refactoring and code formatting
1 parent 25fe560 commit c8aeffd

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $payment = new \Idma\Robokassa\Payment(
4141
'john_doe', 'password1', 'password2', true
4242
);
4343

44-
if ($payment->validate($_GET) {
44+
if ($payment->validateResult($_GET) {
4545
$order = Orders::find($payment->getInvoiceId());
4646

4747
if ($payment->getSum() == $order->sum) {
@@ -54,14 +54,15 @@ if ($payment->validate($_GET) {
5454
...
5555
```
5656

57-
Check payment on Success page:
57+
Check payment on Success or Fail page:
5858
```php
5959
...
6060
$payment = new \Idma\Robokassa\Payment(
6161
'john_doe', 'password1', 'password2', true
6262
);
6363

64-
if ($payment->validate($_GET, "payment") {
64+
// if ($payment->validateFail($_GET) {
65+
if ($payment->validateSuccess($_GET) {
6566
$order = Orders::find($payment->getInvoiceId());
6667

6768
if ($payment->getSum() == $order->sum) {

src/Payment.php

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ class Payment {
4040
/**
4141
* Class constructor.
4242
*
43-
* @param string $login login of Merchant
44-
* @param string $paymentPassword password #1
45-
* @param string $validationPassword password #2
46-
* @param bool $testMode use test server
43+
* @param string $login login of Merchant
44+
* @param string $paymentPassword password #1
45+
* @param string $validationPassword password #2
46+
* @param bool $testMode use test server
4747
*/
4848
public function __construct($login, $paymentPassword, $validationPassword, $testMode = false)
4949
{
@@ -113,18 +113,56 @@ public function getPaymentUrl()
113113
return $this->baseUrl . $data . ($custom ? '&' . $custom : '');
114114
}
115115

116+
/**
117+
* Validates on ResultURL.
118+
*
119+
* @param string $data query data
120+
*
121+
* @return bool
122+
*/
123+
public function validateResult($data)
124+
{
125+
return $this->validate($data);
126+
}
127+
128+
/**
129+
* Validates on SuccessURL.
130+
*
131+
* @param string $data query data
132+
*
133+
* @return bool
134+
*/
135+
public function validateSuccess($data)
136+
{
137+
return $this->validate($data, 'payment');
138+
}
139+
140+
/**
141+
* Validates on FailURL.
142+
*
143+
* @param string $data query data
144+
*
145+
* @return bool
146+
*/
147+
public function validateFail($data)
148+
{
149+
return $this->validate($data, 'payment');
150+
}
151+
116152
/**
117153
* Validates the Robokassa query.
118154
*
119-
* @param string $data query data
120-
* @param string $passwordType type of password, "validation" or "payment"
155+
* @param string $data query data
156+
* @param string $passwordType type of password, 'validation' or 'payment'
121157
*
122158
* @return bool
123159
*/
124-
public function validate($data, $passwordType = "validation")
160+
private function validate($data, $passwordType = 'validation')
125161
{
126162
$this->data = $data;
127-
$password = $this->{"{$passwordType}Password"};
163+
164+
$password = $this->{$passwordType . 'Password'};
165+
128166
$signature = vsprintf('%s:%u:%s%s', [
129167
// '$OutSum:$InvId:$password[:$params]'
130168
$data['OutSum'],
@@ -223,7 +261,7 @@ public function getSum()
223261
}
224262

225263
/**
226-
* @param $summ
264+
* @param mixed $summ
227265
*
228266
* @throws InvalidSumException
229267
*
@@ -251,7 +289,7 @@ public function getDescription()
251289
}
252290

253291
/**
254-
* @param $description
292+
* @param string $description
255293
*
256294
* @return Payment
257295
*/

0 commit comments

Comments
 (0)