shahinsoft/irbanks

伊朗银行支付网关接口

v3.2 2023-07-25 13:03 UTC

This package is auto-updated.

Last update: 2024-09-25 15:29:35 UTC


README

伊朗银行支付网关接口

简介

此库提供了一个简单且易于使用的方法,使用PHP接受伊朗银行的支付。

安装

简单使用composer安装IRbanks

composer require shahinsoft/irbanks

如何使用?

每个银行都有自己的支付流程、端点和参数。首先,你需要了解你银行的流程。然后参考此文档中的银行部分。

Mellat

Mellat支付有3个主要步骤;获取支付令牌、验证支付和结算支付。

1. 获取支付令牌

try{
    $mellat = new \IRbanks\Mellat($terminalId, $userName, $userPassword);
    $response = $mellat->request($amount);
}catch(\Throwable $e){
    echo "error: ".$e->getMessage();
}

2. 将用户重定向到支付页面

//use $response info like token($response->token) and orderId($response->order_id) to create a HTML form with POST method
//or automatically do it using redirectToMellat() function
    $response->redirectToMellat();

//This function generates a JS script which creates a hidden HTML form with POST method to redirect the end-user to the Mellat payment page.

3. 验证支付

try{
    $mellat = new \IRbanks\Mellat($terminalId, $userName, $userPassword);
    $response = $mellat->verify();
    update_your_payment_with($response->reference_id,$response->order_id,$response->card_number);
    echo "successful payment";
}catch(\Throwable $e){
    //payment was unsuccessful or verification failed
    echo "error: ".$e->getMessage();
}

Parsian

Parsian支付有3个主要步骤;获取支付令牌、将用户重定向到支付页面和验证支付。还有撤销交易的可能性。(最后测试:2023年7月25日)

1. 获取支付令牌

<?php 
use IRbanks\Parsian;

try{
    $parsian = new Parsian($pin);
    $response = $parsian->request($amount, $callbackUrl, $orderId, $additionalData);
}catch (\Throwable $exception){
    echo $exception->getMessage();
}

2. 将用户重定向到支付页面

//use payment URL ($parsian->paymentUrl()) to redirect user to the payment page with your project standards
//or call redirect function ($parsian->redirect()) for automatic redirect using header location

//manual approach
$payment_url = $parsian->paymentUrl();
return redirect($payment_url);

//automatic approach
$parsian->redirect();

3. 验证支付

<?php
use IRbanks\Parsian;

try{
    $parsian = new Parsian($pin);
    $response = $parsian->verify();
    update_your_payment_with($response->token,$response->order_id,$response->RNN,$response->hash_card_number);
    echo "Successful payment";
}catch (\Throwable $exception){
    //payment was unsuccessful or verification failed
    echo $exception->getMessage();
}

4. 撤销交易

如果你没有验证交易,你可以撤销它。

<?php
use IRbanks\Parsian;

try{
    $parsian = new Parsian($pin);
    $parsian->reverse($token);
    echo "Transaction reversed successfully";
}catch (\Throwable $exception){
    echo $exception->getMessage();
}

Asan Pardakht

Asan Pardakht支付有3个主要步骤;获取支付令牌、验证支付和结算支付。

1. 获取支付令牌

try{
    $AP = new \IRbanks\Asanpardakht($merchantId, $username, $password, $aesKey, $aesIV);
    $response = $AP->request($amount, $callback_url, $order_id);
}catch(\Throwable $e){
    echo "error: ".$e->getMessage();
}

2. 将用户重定向到支付页面

//use $response info like token($response->token) and refId($response->refID) to create a HTML form with POST method
//or automatically do it using redirectToAsanpardakht() function.
    $response->redirectToAsanpardakht();

//This function generates a JS script which creates a hidden HTML form with POST method to redirect the end-user to the Asanpardakht payment page.

3. 验证支付

try{
    $AP = new \IRbanks\Asanpardakht($merchantId, $username, $password, $aesKey, $aesIV);
    $optional_REQUEST_parameter = Request::input('ReturningParams'); //This is an optional parameter, if not set, the $_POST will be used
    $response = $AP->verify($optional_REQUEST_parameter);

    // OR
    $response = $AP->verify();

    update_your_payment_with($response->reference_id,$response->order_id,$response->card_number,$response->asanpardakht_transaction_id);
    echo "successful payment";
}catch(\Throwable $e){
    //payment was unsuccessful or verification failed
    echo "error: ".$e->getMessage();
}

Sadad(伊朗国家银行)

Sadad支付有3个主要步骤;获取支付令牌、将用户重定向到支付页面和验证支付。

1. 获取支付令牌

注意:您的回调URL应包含order_id,因为Sadad不会将其返回到回调URL。

try{
    $Sadad = new \IRbanks\Sadad($terminalId, $merchant, $transactionKey);
    $response = $Sadad->request($amount, $callback_url, $order_id);
}catch(\Throwable $e){
    echo "error: ".$e->getMessage();
}

2. 将用户重定向到支付页面

//use $response info like token($response->token) and refId($response->refID) to create a HTML form with POST method
//or automatically do it using redirectToAsanpardakht() function.
    $response->redirectToAsanpardakht();

//This function generates a JS script which creates a hidden HTML form with POST method to redirect the end-user to the Asanpardakht payment page.

3. 验证支付

try{
    $AP = new \IRbanks\Asanpardakht($merchantId, $username, $password, $aesKey, $aesIV);
    $optional_REQUEST_parameter = Request::input('ReturningParams'); //This is an optional parameter, if not set, the $_POST will be used
    $response = $AP->verify($optional_REQUEST_parameter);

    // OR
    $response = $AP->verify();
    
    update_your_payment_with($response->reference_id,$response->order_id,$response->card_number,$response->asanpardakht_transaction_id);
    echo "successful payment";
}catch(\Throwable $e){
    //payment was unsuccessful or verification failed
    echo "error: ".$e->getMessage();
}