macklus / yii2-redsys-tpv
管理 RedSys TPV 支付表单生成器
dev-master
2017-04-04 13:42 UTC
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-15 03:39:32 UTC
README
管理 Redsys TPV 支付表单生成器
安装
安装此扩展的首选方法是通过 composer。
运行以下命令之一
php composer.phar require --prefer-dist macklus/yii2-redsys-tpv "*"
或
"macklus/yii2-redsys-tpv": "*"
将以下内容添加到您的 composer.json
文件的 require 部分。
配置
使用以下方法配置 tpv 组件
'redsys' => [ 'class' => 'macklus\RedsysTpv\Tpv', 'mode' => 'prod', 'debug' => [ 'Merchant' => '0XXXXXXXX', 'Terminal' => '0000000X', 'Key' => 'XXXXXXXX', 'URL_OK' => '', 'URL_NOK' => '', 'Version' => '', ], 'prod' => [ 'Merchant' => '0XXXXXXXX', 'Terminal' => '0000000X', 'Key' => 'XXXXXXXX', 'URL_OK' => '', 'URL_NOK' => '', 'Version' => '', ], ],
mode 变量定义使用模式,目前有
- prod: 生产模式
- debug: 调试模式
生成支付表单
您可以使用以下代码在视图中生成支付表单
<?php use Yii; ?> <?= Yii::$app->redsys->generateForm($Num_operacion, $Importe, $TipoMoneda = 978, $idioma = 1, $showButton = true) ?>
- Num_operation: 识别此订单的字母数字代码
- Importe: 支付的总金额
- TipoMoneda: 货币
- Idioma: 语言
- showButton: 如果为 true,则表单包含提交按钮。如果为 false,您应通过 JavaScript 提交它。请记住,表单的 id 总是 ceca-tpv-form
处理 TPV 响应
一旦付款,TPV 应该 POST 支付信息(如果您已配置)。为了处理,您应该在您的操作中使用
<?php class PaymentsController extends Controller { public function init() { if (isset($_POST)) { /* Turn off CSRF */ Yii::$app->request->enableCsrfValidation = false; } } public function actionTpv() { $logfile = Yii::getAlias('@runtime/tpv.log'); if (isset($_POST)) { file_put_contents($logfile, print_R($_POST, true), FILE_APPEND); } $response = Yii::$app->tpv->getTPVResponse(); if ($response && $response->isValid()) { // do some stuff on your database or app if( myStuffWorkFine ) { $response->returnOkToServer(); } else { $response->returnErrorToServer(); } } Yii::$app->request->enableCsrfValidation = true; } }