1. Go to this page and download the library: Download pepco-api/php-rest-sdk 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/ */
pepco-api / php-rest-sdk example snippets
// Use pasargad package
use Pasargad\Pasargad;
use Pasargad\Classes\PaymentItem;
// Always use try catch for handling errors
try {
// Tip! Initialize this property in your payment service __constructor() method!
$pasargad = new Pasargad(
"YOUR_MERCHANT_CODE",
"YOUR_TERMINAL_ID",
"http://yoursite.com/redirect-url-here/",
"certificate_file_location");
//e.q:
// $pasargad = new Pasargad(123456,555555,"http://pep.co.ir/ipgtest","../cert/cert.xml");
// Set Amount
$pasargad->setAmount(100000);
// Set Invoice Number (it MUST BE UNIQUE)
$pasargad->setInvoiceNumber(4029);
// set Invoice Date with below format (Y/m/d H:i:s)
$pasargad->setInvoiceDate("2021/08/08 11:54:03");
// Optional Parameters
// ----------------------
// User's Mobile and Email:
$this->pasargad->setMobile("09121001234");
$this->pasargad->setEmail("[email protected]");
// IF YOU HAVE ACTIVATED "TAS-HIM" (تسهیم پرداخت), ADD SHABA AND PAYMENT SHARING PERCENTAGE/VALUE LIKE THIS:
// شروع تسهیم ---------------------------------------------
// فقط در صورتیکه قابلیت تسهیم شاپرکی را روی درگاه خود
// فعال کردهاید از متد addPaymentType استفاده کنید.
// تسهیم درصدی ۲۰ به ۸۰:
$this->pasargad->addPaymentType("IR300570023980000000000000",PaymentItem::BY_PERCENTAGE, 20);
$this->pasargad->addPaymentType("IR070570022080000000000001",PaymentItem::BY_PERCENTAGE, 80);
// تسهیم مبلغی:
$this->pasargad->addPaymentType("IR300570023980000000000000",PaymentItem::BY_VALUE, 20000);
$this->pasargad->addPaymentType("IR070570022080000000000001",PaymentItem::BY_VALUE, 80000);
// پایان تسهیم --------------------------------------------
// get the Generated RedirectUrl from Pasargad API:
$redirectUrl = $pasargad->redirect();
var_dump($redirectUrl);
// output example: https://pep.shaparak.ir/payment.aspx?n=bPo+Z8GLB4oh5W0KVNohihxCu1qBB3kziabGvO1xqg8Y=
// and redirect user to payment gateway:
return header("Location: $redirectUrl");
// ...or in Laravel/Symfony Controller (Controller extends Symfony\Component\HttpFoundation\Response):
return $this->redirect($redirectUrl);
} catch (\Exception $ex) {
var_dump($ex->getMessage());
die();
}
// Set Transaction refrence id received in
$pasargad->setTransactionReferenceId("636843820118990203");
// Set Unique Invoice Number that you want to check the result
$pasargad->setInvoiceNumber(4029);
// set Invoice Date of your Invoice
$pasargad->setInvoiceDate("2021/08/08 11:54:03");
// check Transaction result
var_dump($pasargad->checkTransaction());
// Set Transaction refrence id received in
$pasargad->setAmount(15000);
// Set Unique Invoice Number that you want to check the result
$pasargad->setInvoiceNumber(4029);
// set Invoice Date of your Invoice
$pasargad->setInvoiceDate("2021/08/08 11:54:03");
// verify payment:
return $pasargad->verifyPayment();
// Set Unique Invoice Number that you want to check the result
$pasargad->setInvoiceNumber(4029);
// set Invoice Date of your Invoice
$pasargad->setInvoiceDate("2021/08/08 11:54:03");
// check Transaction result
return $pasargad->refundPayment();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.