1. Go to this page and download the library: Download javad/ir-kish 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/ */
use MJSeydi\iranKish\Exceptions\IranKishException;
use MJSeydi\iranKish\Facades\IranKish;
public function pay(Order $order)
{
try {
// the second argument is sent as "requestId" and comes back to your callback
$token = IranKish::requestToken($order->amount, (string) $order->id);
} catch (IranKishException $e) {
return back()->withErrors($e->getMessage()); // $e->getResponseCode() holds the gateway code
}
$order->update(['token' => $token]);
return IranKish::redirect($token); // auto-submitting form to the gateway
}
IranKish::requestToken($amount, $requestId, [
'callback' => route('payment.callback'), // override the configured revert url
'payment_id' => '...', // Iranian standard payment identifier (شناسه پرداخت)
'cms_preservation_id' => '989121234567', // payer mobile, if enabled for your terminal
'additional_parameters' => ['nationalId' => '...'],
]);
public function callback(Request $request)
{
$callback = IranKish::callback($request); // token, responseCode, requestId, retrievalReferenceNumber, ...
$order = Order::findOrFail($callback['requestId']);
// the posted fields come through the customer's browser: make sure the token is the one you issued
abort_unless($callback['token'] === $order->token, 403);
try {
// checks the callback code and amount, then confirms the purchase
$result = IranKish::verifyCallback($request, $order->amount);
} catch (IranKishException $e) {
return view('payment.failed', ['message' => $e->getMessage()]);
}
$order->update([
'paid' => true,
'reference' => $result['retrievalReferenceNumber'],
'trace' => $result['systemTraceAuditNumber'],
]);
return view('payment.success');
}