PHPackages                             dizatech/behpardakht\_ipg - 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. dizatech/behpardakht\_ipg

ActiveLibrary[Payment Processing](/categories/payments)

dizatech/behpardakht\_ipg
=========================

v1.0.1(4y ago)016GPL-3.0-or-laterPHP

Since Aug 8Pushed 4y ago1 watchersCompare

[ Source](https://github.com/dizatech/behpardakht_ipg)[ Packagist](https://packagist.org/packages/dizatech/behpardakht_ipg)[ RSS](/packages/dizatech-behpardakht-ipg/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (3)Used By (0)

Payment Cycle
-------------

[](#payment-cycle)

For a payment transaction we have to request a payment via web service. If our request is successful the IPG will return a token which we should use while redirecting customer to payment page. Customer will be redirected back to our desired URL(callback URL) from payment page via a POST request carrying data which may be used to check and verify customer's transaction using web service.

Request payment
---------------

[](#request-payment)

For a payment transaction we should send a payment request to IPG and acquire a token. This may be accomplished by calling `getToken` method.

### Instantiating an IPG object

[](#instantiating-an-ipg-object)

for instantiating an IPG object we should call `Dizatech\BehpardakhtIpg\BehpardakhtIpg` constructor passing it an array of required arguments containing:

- terminalId: your payment gateway terminal id
- userName: your payment gateway username
- userPassword: your payment gateway password

#### Code sample:

[](#code-sample)

```
$args = [
    'terminalId'    => '123',
    'userName'      => '456',
    'userPassword'  => '789'
]; //Replace arguments with your gateway actual values
$ipg = new BehpardakhtIpg($args);
```

### `getToken` method

[](#gettoken-method)

#### Arguments:

[](#arguments)

- order\_id: unique order id
- redirect\_address: URL to which customer may be redirected after payment
- mobile\_no(optional): Customer's mobile phone number in 989\*\*\*\*\*\*\*\*\* format

#### Returns:

[](#returns)

An object with the following properties:

- status: `success` or `error`
- token: in case of a successful request contains the generated token which may be used while redirecting customer to payment page
- message: contains error message when `status` is `error`

Redirecting customer to payment page
------------------------------------

[](#redirecting-customer-to-payment-page)

If `status` property of the result of calling `getToken` is `success` we can redirect customer to payment page URL which is currently `https://bpm.shaparak.ir/pgwchannel/startpay.mellat`. We have to redirect user to payment page via a POST request. So, it is necessary to inject an HTML form in page and submit it as done in the following example. The acquired token should be used as the value of RefId hidden input.

**It is neccessary to save the acquired token token for further use**

#### Code sample:

[](#code-sample-1)

```
$args = [
    'terminalId'    => '123',
    'userName'      => '456',
    'userPassword'  => '789'
]; //Replace arguments with your gateway actual values
$ipg = new BehpardakhtIpg($args);
$amount = 1000; //Replace with actual order amount in Rials
$order_id = 1; //Replace it with unique order id
$redirect_address = 'http://my.com/verify'; //Replace with your desired callback page URL
$result = $ipg->getToken($amount, $order_id, $redirect_address);
if( $result->status == 'success' ){
    ?>
