Skip to content

Commit

Permalink
Validation refactoring and code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaoda committed Apr 10, 2015
1 parent 25fe560 commit c8aeffd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $payment = new \Idma\Robokassa\Payment(
'john_doe', 'password1', 'password2', true
);

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

if ($payment->getSum() == $order->sum) {
Expand All @@ -54,14 +54,15 @@ if ($payment->validate($_GET) {
...
```

Check payment on Success page:
Check payment on Success or Fail page:
```php
...
$payment = new \Idma\Robokassa\Payment(
'john_doe', 'password1', 'password2', true
);

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

if ($payment->getSum() == $order->sum) {
Expand Down
58 changes: 48 additions & 10 deletions src/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class Payment {
/**
* Class constructor.
*
* @param string $login login of Merchant
* @param string $paymentPassword password #1
* @param string $validationPassword password #2
* @param bool $testMode use test server
* @param string $login login of Merchant
* @param string $paymentPassword password #1
* @param string $validationPassword password #2
* @param bool $testMode use test server
*/
public function __construct($login, $paymentPassword, $validationPassword, $testMode = false)
{
Expand Down Expand Up @@ -113,18 +113,56 @@ public function getPaymentUrl()
return $this->baseUrl . $data . ($custom ? '&' . $custom : '');
}

/**
* Validates on ResultURL.
*
* @param string $data query data
*
* @return bool
*/
public function validateResult($data)
{
return $this->validate($data);
}

/**
* Validates on SuccessURL.
*
* @param string $data query data
*
* @return bool
*/
public function validateSuccess($data)
{
return $this->validate($data, 'payment');
}

/**
* Validates on FailURL.
*
* @param string $data query data
*
* @return bool
*/
public function validateFail($data)
{
return $this->validate($data, 'payment');
}

/**
* Validates the Robokassa query.
*
* @param string $data query data
* @param string $passwordType type of password, "validation" or "payment"
* @param string $data query data
* @param string $passwordType type of password, 'validation' or 'payment'
*
* @return bool
*/
public function validate($data, $passwordType = "validation")
private function validate($data, $passwordType = 'validation')
{
$this->data = $data;
$password = $this->{"{$passwordType}Password"};

$password = $this->{$passwordType . 'Password'};

$signature = vsprintf('%s:%u:%s%s', [
// '$OutSum:$InvId:$password[:$params]'
$data['OutSum'],
Expand Down Expand Up @@ -223,7 +261,7 @@ public function getSum()
}

/**
* @param $summ
* @param mixed $summ
*
* @throws InvalidSumException
*
Expand Down Expand Up @@ -251,7 +289,7 @@ public function getDescription()
}

/**
* @param $description
* @param string $description
*
* @return Payment
*/
Expand Down

0 comments on commit c8aeffd

Please sign in to comment.