Saman-Payment Yii Extension
Saman-Payment is a Online Payment Component used for online shoping or donate.
Requirements ¶
requirements of using this extension (e.g. Yii 1.1 or above)...
Installation ¶
- Extract the release file under protected/extensions
- After place this code within your configuration file (main.php) inside the 'components' section
'Payment' => array(
'class'=> 'ext.SamanPayment.RezvanPayment',
'MerchantID' => 'your_merchent_id',
'Password' => 'your_password',
),
Usage ¶
See the following code example:
On your controller action:
$order_Id = rand(); // This variables must be uniquely
$result = Yii::app()->Payment->RequestToken( $order_Id , 'your_amount');
if(!$result['error']){
$this->render('_redirect',array(
'token'=>$result['response'],
'callback'=> 'callback_page',
));
}
else
Yii::app()->user->setFlash('error', $result['response']);
And redirect page: ~~~ [html]
function postRefId (refIdValue, callback) {
var form = document.createElement("form");
form.setAttribute("method", "POST");
form.setAttribute("action", "https://sep.shaparak.ir/Payment.aspx");
form.setAttribute("target", "_self");
var hiddenField = document.createElement("input");
hiddenField.setAttribute("name", "Token");
hiddenField.setAttribute("value", refIdValue);
form.appendChild(hiddenField);
var hiddenField = document.createElement("input");
hiddenField.setAttribute("name", "RedirectURL");
hiddenField.setAttribute("value", callback);
form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
}
postRefId('<?php echo $token; ?>', '<?php echo $callback; ?>');
~~~
Users are directed to the website of the bank for payment. After payment by user, bank returns the user to the previously announced CallBack Address. return address, which is an action in the controller.
In this action you can with parameters that come from the bank, send verifying deposit to bank.
CallBack action:
$model=$this->loadModelByReference($_POST['RefId']);
if($_POST['RefNum'] != NULL && $_POST['State'] == 'OK')
{
$result = Yii::app()->Payment->verifyTransaction($_POST['RefNum']);
if(!$result['error'])
{
// process insert into database
// First, Compare the amount of returning with Paid amount by user
// If confirmed amount then recorded and stored in the database and display the results of the transaction and the tracking code
// $model->save(false)
echo "SuccessFully Pay : " . $result['response'];
}
else
echo "Do not pay for the following reason : </br>" . (is_array($result['response']) ? $result['response']['faultstring'] : $result['response']);
}
else
echo "Do not pay for the following reason : </br>" . $_POST['State'];
And other function:
- Reverse Transaction:
Using this method, to return the amount to the Payer's account. The return value of "1" means request is successful else "-1" unsuccessfull.
# **Reverse Transaction:**
Yii::app()->Payment->reverseTransaction('RefNum');
Donate ¶
Want to say thanks for the time and efforts put on this project?
Donate
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.