vguerrerobosch/redsys-php
Composer 安装命令:
composer require vguerrerobosch/redsys-php
包简介
Unofficial yet better PHP library for the Redsys API.
README 文档
README
This unofficial Redsys PHP library provides convenient access to the Redsys API from applications written in the PHP language.
Requirements
PHP 5.6.0 and later.
Composer
You can install the library via Composer. Run the following command:
composer require vguerrerobosch/redsys-php
Manual Installation
If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the init.php file.
require_once('/path/to/redsys-php/init.php');
Getting Started
Payment Requests
You can create a payment request
use Vguerrerobosch\Redsys\Redsys; use Vguerrerobosch\Redsys\PaymentRequest; Redsys::setApiKey('sq7HjrUOBfKmC576ILgskD5srU870gJ7'); $payment_request = PaymentRequest::create([ 'amount' => 2000, 'order' => time(), 'merchant_code' => 999008881, 'merchant_url' => 'https://941a2b9e.ngrok.io/webhook', 'url_ok' => 'http://redsys-php.test/ok', 'url_ko' => 'http://redsys-php.test/ko', ]);
then you can build the form like:
$sumbit_onload = false; // default true $payment_request->form($submit_onload);
or you may access the properties directly:
$payment_request->url; // the Redsys endpoint $payment_request->params; // the encoded parameters $payment_request->signature; // the calculated signature $payment_request->signature_version // currently HMAC_SHA256_V1
Handling webhooks
The very first thing should be verifing the signature of the request:
use Vguerrerobosch\Redsys\Webhook as Webhook; use Vguerrerobosch\Redsys\Exception\SignatureVerificationException; $content_type = $_SERVER['CONTENT_TYPE']; Webhook::setContentType($content_type); // defaults to application/x-www-form-urlencoded $payload = $content_type == 'application/x-www-form-urlencoded' ? $_POST : @file_get_contents('php://input'); $secret_key = 'sq7HjrUOBfKmC576ILgskD5srU870gJ7'; try { Webhook::verifySignature($payload, $secret_key); } catch (SignatureVerificationException $exception) { http_response_code(403); die; }
then get the data from the response payload and update the order status on your database or whatever needs to be done.
$data = Webhook::getData($payload);
and finally return the response (required for SOAP)
echo Webhook::response($order_id, $secret_key); die;
Testing
Test card numbers
Genuine card information cannot be used in test mode. Instead, use the following test card numbers, a valid expiration date in the future, and any random CVC number, to create a successful payment.
| Card number | Description |
|---|---|
4548 8120 4940 0004 |
Visa charge succeeded. |
5576 4400 2278 8500 |
MasterCard charge is declined with 9551 response code. |
vguerrerobosch/redsys-php 适用场景与选型建议
vguerrerobosch/redsys-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.87k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 vguerrerobosch/redsys-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vguerrerobosch/redsys-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.87k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2019-09-27