承接 amirasaran/zarinpal 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

amirasaran/zarinpal

最新稳定版本:2.0.2

Composer 安装命令:

composer require amirasaran/zarinpal

包简介

Online Zarinpal Payment Extension For Yii2

README 文档

README

Online Zarinpal Payment Extension For Yii2

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require amirasaran/zarinpal:"*"

or add

"amirasaran/zarinpal": "*"

to the require section of your composer.json file.

How to config payment component

Add the following code to your common/config/main.php components

    'components' => [
         ....
        'zarinpal' => [
            'class' => 'amirasaran\zarinpal\Zarinpal',
            'merchant_id' => 'XXXXXXX-XXX-XXXX-XXXXXXXXXXXX',
            'callback_url' => 'http://site.com/payment/verify',
            'testing' => true, // if you are testing zarinpal set it true, else set to false
        ],
        .... 
    ]
        

How to use this component

For example, imagine that you have a controller called this PaymentController at first you need 2 actions, one of them is for request payment and another is verify payment.

you need to use an storage to save your payments and payments status.

PaymentController.php

..... 

public function actionRequest()
{
    /** @var Zarinpal $zarinpal */
    $zarinpal = Yii::$app->zarinpal ;
    /*
    * if you whant, you can pass $callbackParams as array to request method for additional params send to your callback url
    */
    if($zarinpal->request(100,'Test Payment description',null,null,['parameter'=>'value','parameter2'=>'value2'])->getStatus() == '100'){
        /*
        * You can save your payment request data to the database in here before rediract user
        * to get authority code you can use $zarinpal->getAuthority()
        */
        return $this->redirect($zarinpal->getRedirectUrl());
    }
    echo "Error !";
}

/*
* $parameter and $parameter2 are optional parameter that set in request method $callbackParams
*/
public function actionVerify($Authority, $Status , $parameter , $parameter2){

    if($Status != "OK")
        return ; //Payment canceled by user 

    /** @var Zarinpal $zarinpal */
    $zarinpal = Yii::$app->zarinpal ;
    
    if($zarinpal->verify($Authority, 100)->getStatus() == '100'){
        //User payment successfully verified!
        echo "payment successfully";
    }
    elseif($zarinpal->getStatus() == '101') {
        //User payment successfuly verified but user try to verified more than one 
        echo  "duplicated verify payment";
    } 
    else
        echo "payment error !";
}

.....

统计信息

  • 总下载量: 1.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2015-08-09