webgriffe / lib-quipago
3.0.0
2024-07-08 09:04 UTC
Requires
- php: ^8.0
- ext-ctype: *
- ext-dom: *
- ext-json: *
- ext-simplexml: *
- guzzlehttp/guzzle: ^6.5 || ^7.5
- psr/log: ^2.0
- respect/validation: ^2.2
Requires (Dev)
- phpspec/phpspec: ^7.3
- phpstan/phpstan: ^1.11
- squizlabs/php_codesniffer: ^3.7
README
一个用于 Nexi/QuiPago (密钥客户端/CartaSì) 支付网关的 PHP 库。
使用方法
您可以使用 UrlGenerator
生成支付初始化 URL。
$urlGenerator = new Webgriffe\LibQuiPago\PaymentInit\UrlGenerator();
$url = $urlGenerator->generate(
'https://ecommerce.nexi.it/ecomm/ecomm/DispatcherServlet',
'merchant_alias',
'secret_key',
'sha1',
50.50,
'1200123',
'http-cancel-url', // The URL where the user is redirected on failed payment
'customer@mail.com',
'http-succes-url', // The URL where the user is redirected on successful payment
'SESSID123',
'ITA',
'http-post-url' // The URL for the server-to-server notification
);
// Returned $url is https://ecommerce.nexi.it/ecomm/ecomm/DispatcherServlet?alias=merchant_alias&importo=5050&divisa=EUR&codTrans=1200123&url_back=http-cancel-url&mail=customer%40mail.com&url=http-succes-url&session_id=SESSID123&languageId=ITA&urlpost=http-post-url&mac=0fa0ca05a13c6b5d0bd1466461319658f7f990bf
您还可以通过通知 Handler
处理 QuiPago 的服务器到服务器通知。
// These request params array comes from the QuiPago's HTTP notification request
$requestParams = array(
'codTrans' => '1200123',
'esito' => 'OK',
'importo' => '5050',
'divisa' => 'EUR',
'data' => '20160221',
'orario' => '181854',
'codAut' => '123abc',
'mac' => 'c83cee2a5422189cab2b54ef685b29dc428741dc',
'alias' => 'merchant_123',
'session_id' => '123123',
'$BRAND' => 'Visa',
'nome' => 'John',
'cognome' => 'Doe',
'mail' => 'jd@mail.com',
);
$handler = new Webgriffe\LibQuiPago\Notification\Handler();
$handler->handle('secret_key', 'sha1', $requestParams)
// You'll get all parameters mapped
$handler->getTransactionCode(); // '1200123'
$handler->getAmount(); // 50.50
$handler->getCurrency(); //'EUR'
$handler->getTransactionDate(); // \DateTime('21/02/2016 18:18:54')
$handler->getAuthCode(); // '123abc'
$handler->getMacFromRequest(); // 'c83cee2a5422189cab2b54ef685b29dc428741dc'
$handler->getMerchantAlias(); // 'merchant_123'
$handler->getSessionId(); // '123123'
$handler->getCardBrand(); // 'Visa'
$handler->getFirstName(); // 'John'
$handler->getLastName(); // 'Doe'
$handler->getEmail(); // 'jd@mail.com'
// And you know if the transaction has been authorized or not by calling
$handler->isTransactionResultPositive(); // true
您可以将 Psr\Log\LoggerInterface
日志记录器注入到 Webgriffe\LibQuiPago\PaymentInit\UrlGenerator
和 Webgriffe\LibQuiPago\Notification\Handler
中,以启用内部操作的日志记录。
ECREQ/ECRES API
您还可以通过 API Client
发送 ECREQ 消息并接收 ECRES 响应消息。支持捕获和作废方法。
require 'vendor/autoload.php';
$client = new Webgriffe\LibQuiPago\Api\Client(
new GuzzleHttp\Client(),
'payment_3444153',
'TLGHTOWIZXQPTIZRALWKG',
'Manu'
);
/** @var Webgriffe\LibQuiPago\Api\EcResponse $response */
$response = $client->capture(
'000000123', // Transaction Code
Webgriffe\LibQuiPago\Api\EcRequest::REQUEST_TYPE_FIRST_ATTEMPT,
'000000123', // Operation Id
105, // Original Amount
'978', // Currency ISO code
'TESTOK', // Auth Code
105, // Operation Amount
true // Is test request?
);
/** @var Webgriffe\LibQuiPago\Api\EcResponse $response */
$response = $client->void(
'000000123', // Transaction Code
Webgriffe\LibQuiPago\Api\EcRequest::REQUEST_TYPE_FIRST_ATTEMPT,
'000000123', // Operation Id
105, // Original Amount
'978', // Currency ISO code
'TESTOK', // Auth Code
105, // Operation Amount
true // Is test request?
);
查看 Webgriffe\LibQuiPago\Api\EcResponse
类,以了解可以从该对象检索哪些数据。
贡献
- 克隆此仓库
- composer install
- 进行您的更改
- vendor/bin/phpspec run
- vendor/bin/phpcs --standard=PSR2 src/
- 提交拉取请求
许可证
此库位于 MIT 许可证之下。请参阅 LICENSE 文件中的完整许可证。
致谢
由 Webgriffe® 开发。