italiamultimedia/xpay
Composer 安装命令:
composer require italiamultimedia/xpay
包简介
A PHP component/library.
关键字:
README 文档
README
An XPay (Nexi) implementation.
Currently implemented functionality:
Pagamento semplice
Extend class AbstractSimplePaymentService
- implement
SimplePaymentServiceInterface:createCancelUrl;createNotificationUrl;createReturnUrl;
final class SimplePaymentService extends AbstractSimplePaymentService implements SimplePaymentServiceInterface { protected function createCancelUrl(string $orderId): string { ... } protected function createNotificationUrl(string $orderId): string { ... } protected function createReturnUrl(string $orderId): string { ... } }
Extend class AbstractRequestInputService
- optionally implement your own validation rules;
final class RequestInputService extends AbstractRequestInputService implements RequestInputServiceInterface { public const KEY_LANGUAGE = 'lang'; public const KEY_ORDER_ID = 'orderId'; protected function getValidationRule(string $key): string { return match ($key) { self::KEY_ORDER_ID => '/^[a-f0-9]{42}$/', default => parent::getValidationRule($key), }; } protected function validateInput(string $key, string $value): bool { if ($key === self::KEY_LANGUAGE) { return $this->validateLanguageCode($value); } return parent::validateInput($key, $value); } private function validateLanguageCode(string $value): bool { if (!in_array($value, ['en', 'it'], true)) { throw new UnexpectedValueException('Invalid data.'); } return true; } }
Payment request
<!doctype html>
<html>
<head>
...
</head>
<body>
<form id="payment_form" method="POST" action="<?=$paymentService->getSimplePaymentStartUrl()?>">
<?php
foreach (
$paymentService->createPaymentRequestParameters(
$languageCode,
$orderId,
$orderInformation->total,
) as $key => $value
) { ?>
<input type="hidden" name="<?=$key?>" value="<?=$value?>" />
<?php } ?>
<button type="submit" class="btn btn-primary">
<?=$languageCode === 'it' ? 'Acquista ora' : 'Buy now'?>
</button>
</form>
<script>
document.getElementById('payment_form').submit();
</script>
</body>
</html>
Return page
// Validate order (get info from storage) ... /** * Special situation: "mac" can be missing from the request. * Eg. try to pay already paid transaction. * In that situation we don't want to have a transaction error, however we also can not trust the request. * Simply do not process transaction. */ $processTransaction = true; try { // Try to get mac $requestInputService->getValidatedString(RequestInput::MAC); } catch (OutOfBoundsException) { $processTransaction = false; } if ($processTransaction) { // Validate transaction. Uses input data (_GET or _POST). $requestInputService->validateInputMac(); // Store transaction result. ... } // Redirect back to website. ...
Pagamento ricorrente
Extend class AbstractRecurringPaymentService
- implement
RecurringPaymentServiceInterface:createCancelUrl;createNotificationUrl;createReturnUrl;
final class RecurringPaymentService extends AbstractRecurringPaymentService implements RecurringPaymentServiceInterface { protected function createCancelUrl(string $orderId): string { ... } protected function createNotificationUrl(string $orderId): string { ... } protected function createReturnUrl(string $orderId): string { ... } }
Extend class AbstractRequestInputService
- optionally implement your own validation rules;
- see the same section in "Pagamento semplice"
First payment: Payment request
<!doctype html>
<html>
<head>
...
</head>
<body>
<form id="payment_form" method="POST" action="<?=$paymentService->getRecurringPaymentInitialUrl()?>">
<?php
foreach (
$paymentService->createInitialPaymentRequestParameters(
$languageCode,
$numContratto,
$orderInformation->total,
) as $key => $value
) { ?>
<input type="hidden" name="<?=$key?>" value="<?=$value?>" />
<?php } ?>
<button type="submit" class="btn btn-primary">
<?=$languageCode === 'it' ? 'Acquista ora' : 'Buy now'?>
</button>
</form>
<script>
document.getElementById('payment_form').submit();
</script>
</body>
</html>
First payment: Return page
- see the same section in "Pagamento semplice"
Subsequent payments
-
Use
SubsequentPaymentService, methodexecuteSubsequentPayment(string $numeroContratto, float $orderTotal, string $scadenza): AbstractResponseData. -
Can also use
SubsequentPaymentService.getResponse, returnsPsr\Http\Message\ResponseInterfaceif run afterexecuteSubsequentPayment, null otherwise. -
Check if the result is
PositiveResponseDataorNegativeResponseDataand act accordingly.
Development
# Lint composer check:lint && \ # Code style composer check:phpcs && \ # PHPStan composer check:phpstan && \ # Phan composer check:phan && \ # PHPMD composer check:phpmd && \ # Psalm composer check:psalm
italiamultimedia/xpay 适用场景与选型建议
italiamultimedia/xpay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 169 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nexi」 「italiamultimedia」 「xpay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 italiamultimedia/xpay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 italiamultimedia/xpay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 italiamultimedia/xpay 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nexi Checkout
An unofficial SDK for the Nexi XPay Web payment gateway (Intesa Sanpaolo bank)
An unofficial SDK for the Nexi XPay payment gateway (not for Intesa Sanpaolo bank customers)
Unofficial PHP library for the Nexi XPay payment gateway: HPP, Pay-by-Link, recurring contracts, operations and webhooks
A postal code validator
Nets Easy driver for the Omnipay PHP payment processing library
统计信息
- 总下载量: 169
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-21