PHP code example of mjm / zarinpal
1. Go to this page and download the library: Download mjm/zarinpal library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mjm / zarinpal example snippets
php composer.phar
.....
public function actionRequest()
{
/** @var Zarinpal $zarinpal */
$zarinpal = Yii::$app->zarinpal ;
// Change callback url (optional)
$zarinpal->callback_url = Url::to(['verify', 'id'=>123], true);
if($zarinpal->request(100,'Test Payment description')->getStatus() == '100'){
/*
* You can save your payment request data to the database in here before rediract user
* to get authority code you can use $zarinpal->getAuthority()
*/
return $this->redirect($zarinpal->getRedirectUrl());
}
echo "Error !";
}
public function actionVerify($Authority, $Status){
if($Status != "OK")
return ; //Payment canceled by user
/** @var Zarinpal $zarinpal */
$zarinpal = Yii::$app->zarinpal ;
if($zarinpal->verify($Authority, 100)->getStatus() == '100'){
//User payment successfully verified!
echo "payment successfully with referrer code: ".$zarinpal->getRefID();
}
elseif($zarinpal->getStatus() == '101') {
//User payment successfuly verified but user try to verified more than one
echo "duplicated verify payment";
}
else
echo "payment error !";
}
.....