2017 © Pedro Peláez
 

library gateways

To use all Iranian gateways and maybe international gateways using one package

image

hos69shah/gateways

To use all Iranian gateways and maybe international gateways using one package

  • Monday, August 7, 2017
  • by hos69shah
  • Repository
  • 1 Watchers
  • 2 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 86 % Grown

The README.md

See Documentation With Better UX Here

Composer Plugin To Support Following Gateways

  • Mellat (Behpardakht)

Also other gateways will be implemented soon, or feel free to do it on your own and merge it, (*1)


Package Installation

  1. Downloading Package:
    php composer.phar require hos69shah/gateways, (*2)

  2. Require Package In Project
    If you already require global vendor/autoload.php step this part, otherwise:
    require_once 'path/to/vendor/autoload.php';, (*3)

  3. Using Namespace
    Then you must use my namespace to access classes simply:
    use Hossein\Gateway as HG;, (*4)

Mellat Documentation

See Live Usage Here, (*5)

When you done with above steps, you can simply use package to connect to Mellat gateway using your credential info supplied by Behpardakht., (*6)

Starting Payment

First of all create an instantiate of Mellat class:
$mellat = new HG\Mellat();, (*7)

Then you should supply some variables and credentials to start payment as below:, (*8)

$mellat->terminal = 'Your Terminal ID';
$mellat->username = 'Your Username';
$mellat->password = 'Your Password';
$mellat->order_id = mt_rand(0, 1000); //Unique number, Should be store somewhere to use it in callback
$mellat->amount = 1000; //Rials means 100 Toman
$mellat->callback = 'http://your-domain.com?specific_data_to_distinguish_request';

All variables are set now. Remember if any of these variables didn't set, you'll encounter an exception before starting payment., (*9)

Now all you need to do is starting payment:, (*10)

try{
    $mellat->start_payment();

}catch(HG\AllException $ae){
    echo '<b>Result Code: </b>' . $mellat->result_code . '<br />';
    echo HG\Language::get($ae->getMessage());

}

Note 1
You should use try-catch block for this plugin as it will through an exception in case of failure., (*11)

Note 2
You should catch all exception through AllException type., (*12)

Note 3
We can use Language class to translate exception messages as we see above.
You can use it's static function get($index) to get human readable message.
To get more information just look at src/Language.php and it's lang_fa() function to see indexes and messages. Also feel free to change message as you want or try to add extra language to it., (*13)

Starting Callback

When payment done or failed in bank side, user will redirect to address you provided before through $mellat->callback., (*14)

Now assume that here is a page we consider as callback. First of all we should provide and set some credential limiter than previous:, (*15)

$mellat = new HG\Mellat();
$mellat->terminal = 'Your Terminal ID';
$mellat->username = 'Your Username';
$mellat->password = 'Your Password';
$mellat->order_id = 'Order ID'; //This is an order ID you supplied starting payment, you stored it and you can fetch it according to your callback parameters

After these you should call request handler and wait for its response:, (*16)

try {
    $mellat->handle_payment();

    echo '<h1 style="color:green">Payment Was Successful</h1>';

    echo '<b>Sale Reference ID: </b>' . $mellat->sale_reference_id . '<br />';
    echo '<b>Sale Order ID: </b>' . $mellat->sale_order_id . '<br />';
    echo '<b>Card Holder Info: </b>' . $mellat->card_holder_info . '<br />';
    echo '<b>Card Holder Pan: </b>' . $mellat->card_holder_pan . '<br />';

} catch (HG\AllException $ae) {

    echo '<h1 style="color:red">Payment Was Unsuccessful</h1>';
    $mellat->refund_payment();
    echo '<b>Result Code: </b>' . $mellat->result_code . '<br />';
    echo HG\Language::get($ae->getMessage());

}

Note 4
Same as note 1 to 3, read them carefully., (*17)

Note 5
If anything failed you can call $mellat->refund_payment() to return fee to use bank account if his/her balance decreased. Also this is optional and bank will do it automatically after some minutes., (*18)

Properties

All variables are accessible but not necessarily settable, (*19)

$mode
Settable/Accessible When everything is ok to redirect to bank page you have a few option to handle situation:
+ direct-immediate:(default), Immediately redirect user to bank page.
+ direct-delay: Transfer user to bank page after $direct_delay second.
+ indirect: Get a string as start_payment() result contains javascript function to create and submit form to post reference id to bank.
+ information: Get an array contains index_name, index_value and traget, you should redirect user to target through posting target_value with name index_name to target., (*20)

$direct_delay
Settable/Accessible
Number of second when you are in direct-delay mode. (default: 3), (*21)

$terminal
Settable/Accessible
Terminal ID provided by Behpardakht, (*22)

$username
Settable/Accessible
Username provided by Behpardakht, (*23)

Password
Settable/Accessible
Password provided by Behpardakht, (*24)

$order_id
Settable/Accessible
Unique ID for each transaction. You should generate and store this value in your database to use it during handling callback., (*25)

$amount
Settable/Accessible
Amount of transaction fee that should be set in Rials and more than 0., (*26)

$callback
Settable/Accessible
A link that user will be redirected from bank. you should set it as you can get user information from it and fetch transaction order ID from., (*27)

$reference_id
Just Accessible
A string that will be generated on payment start for specific transaction, (*28)

$result_code
Just Accessible
A code that returned by bank after each step. Almost always 0 means success., (*29)

$sale_order_id
Just Accessible
Long integer returned by bank contains an ID that should be store for further consistency., (*30)

$sale_reference_id
Just Accessible
Long integer returned by bank contains an ID that should be store for further consistency., (*31)

$card_holder_info
Just Accessible
..., (*32)

$card_holder_pan
Just Accessible
Contains first 6 digit and last 4 digit of card number that user use to pay transaction., (*33)

Methods

init($terminal, $username, $password, $order, $amount, $callback, $additional)
All are optional.
Use this function to set all variables at one instead of individually., (*34)

start_payment()
To begin transaction and redirect user to bank. Use it after initializing variables and credentials.
+ Will echo form and post it automatically.
+ Will return javascript function that will create and submit a form.
+ Will return an array to transfer user manually
+ Will throw an AllException in case of failure See $mode description for more information., (*35)

handle_payment
To handle payment after returning from bank. Use it on callback page and call it after initializing variables and credentials.
+ Will set bank variables + Will throw an AllException in case of failure, (*36)

refund_payment
To return fee to user account sooner. Use this function is optional and it should be used on catch block only., (*37)

The Versions

07/08 2017

dev-master

9999999-dev

To use all Iranian gateways and maybe international gateways using one package

  Sources   Download

MIT

The Requires

 

07/08 2017

v1.0.2

1.0.2.0

To use all Iranian gateways and maybe international gateways using one package

  Sources   Download

MIT

The Requires

 

07/08 2017

v1.0.1

1.0.1.0

To use all Iranian gateways and maybe international gateways using one package

  Sources   Download

MIT

The Requires

 

13/06 2017

v1.0.0

1.0.0.0

To use all Iranian gateways and maybe international gateways using one package

  Sources   Download

MIT

The Requires

 

12/06 2017

dev-test

dev-test

To use all Iranian gateways and maybe international gateways using one package

  Sources   Download

MIT

The Requires