1. Go to this page and download the library: Download alnazer/knet-payment 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/ */
alnazer / knet-payment example snippets
use Alnazer\KnetPayment\Knet;
$config = [
"tranportal_id"=>"",
"password"=>"",
"resource_key"=>"",
"response_url" => "https://yourdomain.com/result.php",
"error_url" => "https://yourdomain.com/error.php",
"amount"=> 1,
"udf1"=> "",
"udf2"=> "",
"udf3"=> "",
"udf4"=> "",
"udf5"=> "",
];
$knet = new Knet($config);
// ************** request from knet *************//
$request = $knet->request();
if($request["status"] == 1)
{
// redirect to knet payment page using $request["data"]["url"];
}
else
{
// display errors print_r($request["errors"]);
}
// ************** back from knet *************//
$resutl = $knet->responce();
if($resutl["status"] == "success"){
// get reult and update your database
}
else
{
// print error $resutl["ErrorText"]
}
$is_redirection_mode = true;
//$redirect_url the link will redirect (your order page or confiremed payment)
//$payment_id : payment id return from KNET
print_redirect($redirect_url,$payment_id);
// ************** back from knet *************//
$resutl = $knet->responce();
if($resutl["status"] == "success"){
// get reult and update your database
echo $knet->print_redirect("The page url will redirect to it",$resutl["paymentid"]);
}
else
{
// get reult and update your database
echo $knet->print_redirect("The error page url will redirect to it",$resutl["paymentid"]);
}
$tranportal_id;
$password;
$resource_key;
$is_test = true;
$response_url; // url bank will return after payment operation success
$error_url;// url bank will return if faveing error in payment operation
$this->request()
$this->responce()
$this->validate();
$this->addError("index_name","message");
public function beforeValidate()
{
parent::beforeValidate();
//code here ....
return true;
}
public function afterValidate()
{
parent::afterValidate();
//code here ....
return true;
}
public function beforeRequest()
{
parent::beforeRequest();
//code here ....
return true;
}
public function afterRequest($trackid, $pay_url)
{
parent::afterRequest($trackid, $pay_url);
//code here ....
return true;
}
public function beforeResponce()
{
parent::beforeResponce();
//code here ....
return true;
}
public function afterResponce($payment_id, $trackid, $result)
{
parent::afterResponce($payment_id, $trackid, $result);
//code here ....
return true;
}
[
"status" => "success",
"paymentid" => "2423sdfsd723482582",
"trackid" => "3424234234",
"tranid" => "4234234234234",
"ref" => "3523235252",
"result" => "CAPTURED", //knet result CAPTURED,NOT CAPTURED,CANCELED ... ect
"postdate" => "3234234",
"auth" => "44445",
"avr" => "4566",
"amount" => "1.000",
"udf1" => "", // you set this data in request function
"udf2" => "",// you set this data in request function
"udf3" => "",// you set this data in request function
"udf4" => "",// you set this data in request function
"udf5" => "",// you set this data in request function
"data" => "", // all $_REQUEST data
"ErrorText" => "",
"Error" => "",
]
[
"status" => "error",
"paymentid" => "2423sdfsd723482582",
"trackid" => "3424234234",
"tranid" => "4234234234234",
"ref" => "3523235252",
"result" => "error",
"postdate" => "3234234",
"auth" => "44445",
"avr" => "4566",
"amount" => "1.000",
"udf1" => "", // you set this data in request function
"udf2" => "",// you set this data in request function
"udf3" => "",// you set this data in request function
"udf4" => "",// you set this data in request function
"udf5" => "",// you set this data in request function
"ErrorText" => "get from knet responce",
"Error" => "get from knet responce",
]
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.