tuutti / php-tupas
此包已被弃用且不再维护。未建议替换包。
最新版本(1.0.0)的此包没有提供许可证信息。
1.0.0
2019-11-04 16:23 UTC
Requires
- paragonie/random_compat: ^1.0|^2.0|^9.99.99
- webmozart/assert: ~1.2
Requires (Dev)
- phpunit/phpunit: ^4.8 || ^5.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2022-01-04 21:44:07 UTC
README
安装
composer require tuutti/php-tupas
测试
使用phpunit运行测试。
./vendor/bin/phpunit
使用
构建 tupas 按钮/表单
创建一个新类,该类实现了 \Tupas\Entity\BankInterface。
<?php class YourBankClass implements \Tupas\Entity\BankInterface { // Add required getters and populate required values. } ... /** @var \Tupas\Entity\BankInterface $bank */ $bank = new YourBankClass(); ... $form = new \Tupas\Form\TupasForm($bank); $form->setCancelUrl('http://example.com/tupas/cancel') ->setRejectedUrl('http://example.com/tupas/rejected') ->setReturnUrl('http://example.com/tupas/return') ->setLanguage('FI');
在跨多个请求持续存在的存储中生成并存储交易ID,例如
<?php $_SESSION['transaction_id'] = $form->getTransactionId();
注意:这不是必需的,但强烈推荐,否则用户可以多次重用他们有效的认证URL。
构建你的表单
<?php foreach ($form->build() as $key => $value) { // Your form logic should generate a hidden input field: // <input type="hidden" name="$key", value="$value"> }
设置表单操作
<form method="..." action="$bank->getActionUrl();">
验证回头客
<?php ... // You should always use the bank number (three first // characters of B02K_TIMESTMP) to validate the bank. // Something like: $bank_number = substr($_GET['B02K_TIMESTMP'], 0, 3); ... $tupas = new \Tupas\Tupas($bank, $_GET); // Compare transaction id stored in a persistent storage against // the one returned by the Tupas service. if (!$tupas->isValidTransaction($_SESSION['transaction_id'])) { // Transaction id validation failed. } try { $tupas->validate(); } catch (\Tupas\Exception\TupasGenericException $e) { // Validation failed due to missing parameters. } catch (\Tupas\Exception\HashMatchException $e) { // Validation failed due to hash mismatch. }
在成功认证后无效化交易ID
<?php unset($_SESSION['transaction_id']);