tecsin / yii2-voguepay
为 Yii2 框架的 VoguePay 扩展
2.0.0
2018-05-25 01:01 UTC
Requires
- yiisoft/yii2: >=2.0.8
- yiisoft/yii2-httpclient: ~2.0.0
This package is auto-updated.
Last update: 2024-09-05 02:24:55 UTC
README
Pay2
VoguePay 支付处理器扩展程序,用于 Yii2 框架(命令 API 处于测试阶段)。Pay2 是 VoguePay 支付处理器移动/服务器到服务器和命令 API 的 Yii2 封装。移动/服务器到服务器 API 允许您通过发送您的商户 ID 和其他必要参数来获取支付链接令牌。
命令 API 允许您直接在您的应用程序中执行多个操作(获取交易详情、向用户付款、将资金提取到银行账户、创建新用户)。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令:
composer require --prefer-dist tecsin/yii2-voguepay "~2.0.0"
或将其添加到您的 composer.json
文件的 require 部分:
"tecsin/yii2-voguepay": "~2.0.0"
使用方法
首先,通过运行迁移代码来设置数据库:
php yii migrate --migrationPath="@vendor/tecsin/yii2-voguepay/migrations"
之后,您应该在应用程序组件的模块部分添加 pay2,如下所示
'components' => [ //... 'modules' => [ //... 'pay2' => [ 'class' => 'tecsin\pay2\Module', 'userModelClass' => 'app\models\User', 'controllerMap' => [ 'manage' => [ 'class' => 'yii2mod\comments\controllers\ManageController', 'layout' => '@app/modules/admin/views/layouts/main', 'accessControlConfig' => [ 'class' => 'yii\filters\AccessControl', 'rules' => [ [ 'allow' => true, 'roles' => ['admin', 'manager'], ], ], ], ], ], ], ], ],
并通过项目.com/pay2 设置您的 VoguePay 详细信息。
通知和立即付款按钮
从 VoguePay 获取通知并在将用户发送到 VoguePay 之前将数据保存到数据库中。
<?php namespace app\controllers; class SiteController extends \yii\web\Controller { //... public function actions() { return [ //... 'voguepay-notification' => [ 'class' => 'tecsin\pay2\actions\Pay2NotificationAction', // see this class if you will change anything for better explanations 'modelClass' => 'tecsin\pay2\models\NotificationExample'//this is the default model to run for every notification 'method' => 'voguepay'//the method to be called in modelClass, and must have a parameter which should be an array of transaction from voguepay ], 'set-data' => [ 'class' => 'tecsin\pay2\actions\InitSaleAction', //redirects user to voguepay payment page after saving the pay now form data to db //this is mandatory if you use the PayButton widget ], ]; } }
显示立即付款按钮
<?= tecsin\pay2\widgets\PayButton::widget() ?>
移动/服务器到服务器
您可以直接将用户发送到 VoguePay 付款页面(这是默认操作)
$MsModel = new \tecsin\pay2\models\VoguepayMs(['aaaMerchantId' => '11111', 'mmmMemo' => 'one sparklyn yellow wedding dress', 'tttTotalCost' => '200310', 'rrrMerchantRef' => time().mt_rand(0,999999999)]); if($MsModel->validate()){ return $MsModel->setRequest()->sendRequest()->sendResponse(); }
或者向用户显示一个付款按钮(将 showPayButton 属性设置为 true)
$MsModel = new \tecsin\pay2\models\VoguepayMs(['aaaMerchantId' => '11111', 'mmmMemo' => 'one sparklyn yellow wedding dress', 'tttTotalCost' => '200310', 'rrrMerchantRef' => time().mt_rand(0,999999999), 'showPayButton' => true]); if($MsModel->validate()){ $response = $MsModel->setRequest()->sendRequest()->sendResponse(); return $response;//response is json {status: "success|error", success|error : { message: "https://www.voguepay.com/payment-url|errorMesssge"}} }
命令 API
使用命令 API,您可以获取交易记录,向 VoguePay 商户付款,将资金提取到各种银行账户,并在 VoguePay 上创建新用户。
请参阅 tecsin\pay2\models\Money 以获取提取示例
阅读更多。
请参阅 VoguePay 开发者页面
贡献
欢迎以任何形式做出贡献