diff --git a/README.md b/README.md index a41e241..1c0a8fc 100644 --- a/README.md +++ b/README.md @@ -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) { @@ -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) { diff --git a/src/Payment.php b/src/Payment.php index 46d467a..dece2e0 100644 --- a/src/Payment.php +++ b/src/Payment.php @@ -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) { @@ -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'], @@ -223,7 +261,7 @@ public function getSum() } /** - * @param $summ + * @param mixed $summ * * @throws InvalidSumException * @@ -251,7 +289,7 @@ public function getDescription() } /** - * @param $description + * @param string $description * * @return Payment */