extreme-bg/borica-emv-3ds
Composer 安装命令:
composer require extreme-bg/borica-emv-3ds
包简介
Client library for Borica EMV 3DS
README 文档
README
Borica EMV 3DS is PHP library providing an easier way to integrate newly released Borica protocol called EMV 3DS.
The library supports the new MAC_GENERAL signage algorithm and will work after the 1 August 2023 changes.
0. Requirements
TBD
- PHP 7.1 or newer
- Properly configured
default_charsetphp.ini directive
1. Installation
1.1. Using Composer
Installation is recommended to be done via composer by running:
composer require extreme-bg/borica-emv-3ds "1.*"
Alternatively you can add the following to the require section in your composer.json manually:
"extreme-bg/borica-emv-3ds": "1.*"
2. Usage
2.1. Initialize
Create and configure Borica using your private key and certificate. The private key needs to be generated by yourself (see Cryptography section for more details). The certificate (public key) is provided by Borica.
$borica = new Borica(); $borica->setPrivateKey('/var/www/certificates/borica.pem') // Absolute file path ->setPrivateKeyPassword('<Private Key Password>') ->setCertificate('/var/www/certificates/borica.cer') // Absolute file path ->setSandboxMode(true) ->setSigningAlgorithm(SigningAlgorithm::MAC_GENERAL);
2.2. Create and send Sale Request (TRTYPE=1)
At the moment it works only with Bulgarian lev (BGN). Borica works on Euro (EUR) support.
To make a sale request (most commonly used one in e-commerce), create and configure SaleRequest. Both <МИД> and <ТИД> are obtained from Borica. For all properties check the library source code.
Don't forget to use sanitized data instead of raw $_POST data.
require_once __DIR__ . '/vendor/autoload.php'; use BogdanKovachev\Borica\Borica; use BogdanKovachev\Borica\SigningAlgorithm; use BogdanKovachev\Borica\TransactionType; use BogdanKovachev\Borica\Request\SaleRequest; $request = new SaleRequest(); $request->setTransactionType(TransactionType::SALE) ->setAddendum('AD,TD') ->setAmount(100.0) ->setCountry('bg') ->setCurrency('BGN') ->setDescription('Order via 1337.bg') ->setEmail('extreme@1337.bg') ->setMerchant('<МИД>') ->setMerchantName('1337.bg') ->setMerchantTimezone('+02') ->setMerchantUrl('https://1337.bg') ->setNonce(strtoupper(bin2hex(openssl_random_pseudo_bytes(16)))) ->setOrder(9001) ->setOrderIdentifier($request->getOrder() . ' Website') ->setTerminal('<ТИД>') ->setTimestamp(time()) ->sign($borica);
Optionally you can validate that all the properties are correct with:
if (!$request->validate()) { // List all errors var_dump($request->getErrors()); }
After you create the request, you need to generate an HTML form and redirect user to Borica payment page. See example implementation below:
<div> <p> Ще бъдете прехвърлени към страницата за онлайн плащания на БОРИКА през защитена (SSL) връзка. </p> <p> За нареденото от вас плащане, няма да ви бъдат удържани банкови такси. </p> </div> <div style="display: none;"> <?= $request->renderForm($borica) ?> </div> <script type="text/javascript"> window.onload = function () { window.setTimeout(function () { document.getElementById('boricaForm').submit(); }, 3000); }; </script>
2.3. Handle response
After a user pays on the Borica payment page, they will be redirected to the backUrl defined for the terminal in APGW database (check with the bank that this URL is correctly set for the terminal). Note that this is not guaranteed, because the user can close their browser or disable JavaScript used for redirecting. In this case see 2.4. Create Status Check Request.
require_once __DIR__ . '/vendor/autoload.php'; use BogdanKovachev\Borica\Borica; use BogdanKovachev\Borica\SigningAlgorithm; use BogdanKovachev\Borica\TransactionType; use BogdanKovachev\Borica\Response\Response; $borica = new Borica(); $borica->setPrivateKey('/var/www/certificates/borica.pem') // Absolute file path ->setPrivateKeyPassword('<Private Key Password>') ->setCertificate('/var/www/certificates/borica.cer') // Absolute file path ->setSandboxMode(true) ->setSigningAlgorithm(SigningAlgorithm::MAC_GENERAL); $response = Response::withPost($_POST)->verify($borica); if (!$response->signatureIsVerified) { ... } if ($response->isSuccessful()) { echo '<h1>Плащането е успешно</h1>'; ... } else { echo '<h1>Възникна грешка при плащане</h1>'; echo '<p>Отговор на сървъра: ' . $response->responseCode . ' - ' . $response->responseCodeDescription() . '</p>'; }
2.4. Create Status Check Request (TRTYPE=90)
If you want to check the status of an already sent request, create and configure StatusCheckRequest. <ТИД> is obtained from Borica.
require_once __DIR__ . '/vendor/autoload.php'; use BogdanKovachev\Borica\Borica; use BogdanKovachev\Borica\Request\StatusCheckRequest; use BogdanKovachev\Borica\Response\Response; use BogdanKovachev\Borica\SigningAlgorithm; use BogdanKovachev\Borica\TransactionType; $request = new StatusCheckRequest(); $request->setTransactionType(TransactionType::STATUS_CHECK) ->setNonce(strtoupper(bin2hex(openssl_random_pseudo_bytes(16)))) ->setOrder(9001) ->setOriginalTransactionType(TransactionType::SALE) ->setTerminal('<ТИД>') ->sign($borica);
2.5. Create Reversal Request (TRTYPE=24)
To reverse successful SaleRequest (TRTYPE=1) or completed deferred authorization (TRTYPE=24), create and configure ReversalRequest.
<RRN> and <INT_REF> are returned in response of SaleRequest and are unique for every transaction. Both <МИД> and <ТИД> are obtained from Borica. For all properties check the library source code.
require_once __DIR__ . '/vendor/autoload.php'; use BogdanKovachev\Borica\Borica; use BogdanKovachev\Borica\Request\ReversalRequest; use BogdanKovachev\Borica\Response\Response; use BogdanKovachev\Borica\SigningAlgorithm; use BogdanKovachev\Borica\TransactionType; $request = new ReversalRequest(); $request->setTransactionType(TransactionType::REVERSAL) ->setAddendum('AD,TD') ->setAmount(100.0) ->setCurrency('BGN') ->setDescription('Отмяна на плащане през bulmint.com') ->setInternalReference('<INT_REF>') ->setMerchant('<МИД>') ->setMerchantName('Мебели Дизма') ->setNonce(strtoupper(bin2hex(openssl_random_pseudo_bytes(16)))) ->setOrder(9001) ->setOrderIdentifier($request->getOrder() . ' Website') ->setRetrievalReferenceNumber('<RRN>') ->setTerminal('<ТИД>') ->setTimestamp(time()) ->sign($borica);
3. Cryptography
- Generate a private key with secure password:
$ openssl genrsa -out borica.key -aes256 2048
- Generate a code signing request (CSR) using your company information:
$ openssl req -new -key borica.key -out borica.csr Country Name (2 letter code) []:BG State or Province Name (full name) []:Plovdiv Locality Name (eg, city) []:Plovdiv Organization Name (eg, company) []:1337 LTD Organizational Unit Name (eg, section) []:V0000000 Common Name (eg, fully qualified host name) []:1337.bg Email Address []:extreme@1337.bg A challenge password []: <empty>
-
Rename
borica.csrto match file patternTID_YYYYMMDD.csrand send it to Borica. Use yourТИДandcurrent date(i.e.V0000000_20201105.csr). -
In response you'll receive a signed certificate (
borica.cer) and a public key (borica.pub) from Borica.
4. Contributing
TBD
5. License
Borica EMV 3DS is licensed under the MIT License.
extreme-bg/borica-emv-3ds 适用场景与选型建议
extreme-bg/borica-emv-3ds 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 408 次下载、GitHub Stars 达 13, 最近一次更新时间为 2020 年 11 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「borica」 「борика」 「borika」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 extreme-bg/borica-emv-3ds 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 extreme-bg/borica-emv-3ds 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 extreme-bg/borica-emv-3ds 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Borica integration from Sylius
The Payum extension. Rapid extensino development
Client library for Borica EMV 3DS
Client library for Borica EMV 3DS
Borica payment package
统计信息
- 总下载量: 408
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-05