1. Go to this page and download the library: Download blackplatinum/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/ */
use BlackPlatinum\Zarinpal\Zarinpal;
/**
* This is for sending your request to the bank for your payment
*/
$paymentRequest = new Zarinpal(
'request',
[
'price' => 100, // Toman
'description' => 'درگاه پرداخت زرین پال',
'callbackUri' => 'your_uri', // Without '/'
'orderId' => 1 // Your order id
], true // Enables sandbox mode
);
$result = $paymentRequest->sendPaymentInfoToGateway();
if ($result->Status == 100) {
// The information that you have sent was out of mistakes and you are gonna
// redirect to zarinpal gateway
return redirect()->to($paymentRequest->linkToGateway($result->Authority));
}
// There is something wrong about your request and you are not qualify to redirect
// to zarinpal gateway
return redirect('your_failure_url_in_payment');
--------------------------------------------------------------------------------------------------
/**
* This is for receiving your response from the bank about your payment request in previous code
*/
$paymentResponse = new Zarinpal(
'response',
[
'price' => 100, // Toman
'authority' => $request->Authority
], true // Enables sandbox mode
);
$result = $paymentResponse->receivePaymentInfoFromGateway($request->Status);
if ($result) {
// Yor payment done successfully
$authority = $request->input('Authority');
$status = $request->input('Status');
$refId = $result->RefID;
// Do the rest...
}
else {
// Yor payment failed or you canceled payment
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.