Created
July 28, 2011 06:47
-
-
Save kirs/1111108 to your computer and use it in GitHub Desktop.
PayController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class PayController extends Controller | |
{ | |
public function actionIndex() | |
{ | |
$this->render('about',array()); | |
} | |
public function actionForm() | |
{ | |
$model = new RoboPayForm; | |
if(isset($_POST['RoboPayForm'])) | |
{ | |
$model->attributes=$_POST['RoboPayForm']; | |
if($model->validate()) | |
{ | |
$command = Yii::app()->db->createCommand(); | |
$command->insert('{{robopays}}', array( | |
'name' => $model->fio, | |
'created_at' => mktime(), | |
)); | |
$invId = Yii::app()->db->getLastInsertID(); | |
$mrhLogin = "vasya"; // your login here | |
$mrhPass1 = "qwerty"; // merchant pass1 here | |
$invDesc = "Оплата занятий"; | |
$outSum = intval($model->summ) > 1 ? intval($model->summ) : 1; // invoice summ | |
// build CRC value | |
$crc = md5("$mrhLogin:$outSum:$invId:$mrhPass1"); | |
// build URL | |
$roboUrl = "https://merchant.roboxchange.com/Index.aspx?MrchLogin=" . $mrhLogin. "&OutSum=" . $outSum . "&InvId=" . $invId . "&Desc=" . $invDesc . "&SignatureValue=" . $crc; | |
Yii::app()->request->redirect($roboUrl); // redirect to the gate | |
} | |
} | |
$this->render('form',array( | |
'model'=>$model, | |
)); | |
} | |
public function actionProcess() { | |
// your registration data | |
$mrhPass1 = "qwerty"; // merchant pass1 here | |
// HTTP parameters: | |
$outSum = $_REQUEST["OutSum"]; | |
$invId = $_REQUEST["InvId"]; | |
$crc = $_REQUEST["SignatureValue"]; | |
$crc = strtoupper($crc); // force uppercase | |
// build own CRC | |
$my_crc = strtoupper(md5("$outSum:$invId:$mrhPass1")); | |
if (strtoupper($my_crc) != strtoupper($crc)) { | |
// rendering bad page | |
$this->render('declined'); | |
} | |
else { | |
$command = Yii::app()->db->createCommand(); | |
$command->update('{{robopays}}', array( | |
'summ'=>$outSum, | |
), 'id=:id', array(':id' => $invId)); | |
// rendering success page | |
$this->render('accepted',array('outSum' => $outSum)); | |
} | |
} | |
public function actionCancel(){ | |
// if user cancelled | |
$this->render('canceled'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class RoboPayForm extends CFormModel | |
{ | |
public $fio; | |
public $summ; | |
public $acceptOferta; | |
/** | |
* Declares the validation rules. | |
*/ | |
public function rules() | |
{ | |
return array( | |
// name, email, subject and body are required | |
array('fio, summ', 'required', 'message'=> 'Поле {attribute} не может быть пустым.'), | |
// email has to be a valid email address | |
array('summ', 'numerical'), | |
array('summ', 'compare', 'operator'=>'>=', 'compareValue'=>5, 'message'=>'Минимальная сумма для оплаты – 100 рублей.'), | |
array('acceptOferta', 'compare', 'operator'=>'==','compareValue'=>1, 'message' => 'Необходимо принять условия Договора-оферты.'), | |
); | |
} | |
/** | |
* Declares customized attribute labels. | |
* If not declared here, an attribute would have a label that is | |
* the same as its name with the first letter in upper case. | |
*/ | |
public function attributeLabels() | |
{ | |
return array( | |
'fio' => 'ФИО', | |
'summ' => 'Сумма платежа', | |
'acceptOferta' => 'Согласен с офертой', | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment