PHPackages                             pepco-api/php-rest-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. pepco-api/php-rest-sdk

ActiveLibrary[Payment Processing](/categories/payments)

pepco-api/php-rest-sdk
======================

PHP package to connect your application to Pasargad Internet Payment Gateway through RESTful API

0.4.0(4y ago)116.2k6[3 issues](https://github.com/pepco-api/php-rest-sdk/issues)Apache-2.0PHPPHP &gt;=5.6.0

Since Aug 8Pushed 4y ago1 watchersCompare

[ Source](https://github.com/pepco-api/php-rest-sdk)[ Packagist](https://packagist.org/packages/pepco-api/php-rest-sdk)[ Docs](https://github.com/pepco-api/php-rest-sdk)[ RSS](/packages/pepco-api-php-rest-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (8)Used By (0)

Pasargad php-rest-sdk
=====================

[](#pasargad-php-rest-sdk)

PHP package to connect your application to Pasargad Internet Payment Gateway through RESTful API

Installation
============

[](#installation)

For installation, use `composer` package:

```
$ composer require pepco-api/php-rest-sdk
```

Usage
=====

[](#usage)

- To Read API Documentation, [Click Here! (دانلود مستندات کامل درگاه پرداخت)](https://www.pep.co.ir/wp-content/uploads/2019/06/1-__PEP_IPG_REST-13971020.Ver3_.00.pdf)
- Save your private key into an `.xml` file inside your project directory.

Redirect User to Payment Gateway
--------------------------------

[](#redirect-user-to-payment-gateway)

```
// 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("user@email.com");

    // 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();
}
```

Checking and Verifying Transaction
----------------------------------

[](#checking-and-verifying-transaction)

After Payment Process, User is going to be returned to your redirect\_url.

payment gateway is going to answer the payment result with sending below parameters to your redirectURL (as `QueryString` parameters):

- InvoiceNumber (IN field)
- InvoiceDate (ID field)
- TransactionReferenceID (tref field)

Store this information in a proper data storage and let's check transaction result by sending a check api request to the Bank:

```
// 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());
```

Successful result is a PHP array:

```
$result = [
  "TraceNumber" => 908768
  "ReferenceNumber" => 141113323710
  "TransactionDate" => "2021/09/16 12:08:28"
  "Action" => "1003"
  "TransactionReferenceID" => "637673907761796375"
  "InvoiceNumber" => "40209"
  "InvoiceDate" => "2021/09/16 11:54:03"
  "MerchantCode" => 4532980
  "TerminalCode" => 1718577
  "Amount" => 15000.0
  "TrxHashedCardNumber" => "9EB09984BF3F0FDA07D6055997A32F363276D4BD029AE0C870E60DCFC37ED02C"
  "TrxMaskedCardNumber" => "5022-29**-****-0682"
  "IsSuccess" => true
  "Message" => "عمليات به اتمام رسيد"
]
```

If you got `IsSuccess` with `true` value, so everything is O.K! otherwise, you will get an Exception.

Now, for your successful transaction, you should call `verifyPayment()` method to keep the money and Bank makes sure the checking process was done properly:

```
// 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();
```

...and the successful response, is an array:

```
$result = [
  "MaskedCardNumber" => "5022-29**-****-0682"
  "HashedCardNumber" => "2DDB1E270C598677AE328AA37C2970E3075E1DB6665C5AAFD131C59F7FAD99F23680536B07C140D24AAD8355EA9725A5493AC48E0F48E39D50B54DB906958182"
  "ShaparakRefNumber" => "141113323710"
  "IsSuccess" => true
  "Message" => "عمليات با موفقيت انجام شد"
]
```

Payment Refund
--------------

[](#payment-refund)

If for any reason, you decided to cancel an order in early hours after taking the order (maximum 2 hours later), you can refund the client payment to his/her bank card.

for this, use `refundPayment()` method:

```
// 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();
```

Support
=======

[](#support)

Please use your credentials to login into [Support Panel](https://my.pep.co.ir)

Contact Author/Maintainer: [Reza Seyf](https://twitter.com/seyfcode)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Recently: every ~19 days

Total

7

Last Release

1660d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c5af244a846991103db8c4a92568a3aa0f6ce37e6fc5b9eae2dbab9a88eba6a9?d=identicon)[rseyf](/maintainers/rseyf)

---

Top Contributors

[![rseyf](https://avatars.githubusercontent.com/u/6011555?v=4)](https://github.com/rseyf "rseyf (35 commits)")

---

Tags

api-wrapperpasargadpasargad-bankpaymentphp

### Embed Badge

![Health badge](/badges/pepco-api-php-rest-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/pepco-api-php-rest-sdk/health.svg)](https://phpackages.com/packages/pepco-api-php-rest-sdk)
```

###  Alternatives

[omnipay/paypal

PayPal gateway for Omnipay payment processing library

3156.8M53](/packages/omnipay-paypal)[tbbc/money-bundle

This is a Symfony bundle that integrates moneyphp/money library (Fowler pattern): https://github.com/moneyphp/money.

1961.9M](/packages/tbbc-money-bundle)[2checkout/2checkout-php

2Checkout PHP Library

83740.3k2](/packages/2checkout-2checkout-php)[smhg/sepa-qr-data

Generate QR code data for SEPA payments

61717.2k5](/packages/smhg-sepa-qr-data)[dnetix/redirection

Library to connect with PlacetoPay Checkout service

17123.3k2](/packages/dnetix-redirection)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
