承接 wizcodepl/lunar-payu 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wizcodepl/lunar-payu

Composer 安装命令:

composer require wizcodepl/lunar-payu

包简介

PayU REST payment driver for Lunar PHP — authorize, redirect, HMAC-verified webhook capture.

README 文档

README

Lunar PayU

lunar-payu

PayU REST payment driver for Lunar PHP.

Features

  • PayU REST APIPOST /api/v2_1/orders with OAuth2 client_credentials and cached bearer tokens (auto-refresh on 401).
  • HMAC-SHA256 webhook signature verificationOpenPayU-Signature header parsed and validated against the merchant Second key. Legacy MD5 algorithm supported as a fallback for shops still on it.
  • payu_transactions audit table — append-only log of every authorize attempt and webhook event (PayU order id, status, amount, redirect URL, last raw event, last notification timestamp). Indexed by payu_order_id and status.
  • PayuTransactionStatus enumPending / CreateFailed / RedirectPending / Paid / Failed / Refunded / Cancelled cast on PayuTransaction.status.
  • Domain eventsPayuPaymentReceived, PayuPaymentFailed, PayuPaymentRefunded, PayuPaymentCancelled. Listeners can implement ShouldQueue to do slow work (mails, fulfilment) without starving the webhook.
  • Actions decomposition — webhook handling split into ResolveOrderFromNotification, UpdateOrderFromPayuStatus, RecordPayuWebhookEvent. Controller composes them; each is independently testable.
  • Queueable webhook job — controller acks PayU with 200 immediately and dispatches ProcessPayuNotification, so heavy listener work happens on a queue worker.
  • Idempotent webhook processing — repeat notifications for already-settled transactions don't double-fire domain events.
  • Amount sanity checkCOMPLETED notifications with a totalAmount that doesn't match the order total are downgraded to Failed and logged.

Requirements

  • PHP 8.2+
  • Lunar core ^1.3

Install

composer require wizcodepl/lunar-payu
php artisan vendor:publish --tag=lunar-payu-config
php artisan vendor:publish --tag=lunar-payu-migrations
php artisan migrate

The service provider auto-registers via Laravel package discovery.

Configure

Set the following in your .env:

PAYU_POS_ID="..."
PAYU_CLIENT_ID="..."
PAYU_CLIENT_SECRET="..."
PAYU_SECOND_KEY="..."

# Base URL — omit on production (defaults to https://secure.payu.com).
# For sandbox / staging:
PAYU_BASE_URL=https://secure.snd.payu.com

PAYU_RETURN_URL_SUCCESS="https://shop.example/order/thanks"
PAYU_RETURN_URL_ERROR="https://shop.example/checkout"

Register the driver in config/lunar.php:

'payments' => [
    'types' => [
        'payu' => ['driver' => 'payu'],
    ],
],

In the PayU merchant panel set the notification URL to:

https://shop.example/payu/notify

(The path is configurable via PAYU_WEBHOOK_PATH.)

Use

use Lunar\Facades\Payments;

$result = Payments::driver('payu')->order($order)->authorize();

if ($result?->success) {
    return redirect($result->message); // PayU's redirectUri lives in PaymentAuthorize.message
}

The customer pays on PayU's hosted page and is sent to PAYU_RETURN_URL_SUCCESS. The actual order status is updated by the webhook a few seconds later (asynchronously through ProcessPayuNotification), so don't trust the URL — read Order.status instead.

Listening to events

use WizcodePl\LunarPayu\Events\PayuPaymentReceived;

Event::listen(PayuPaymentReceived::class, function (PayuPaymentReceived $e) {
    // $e->order, $e->transaction
    Mail::to($e->order->billingAddress->contact_email)->queue(new PaymentConfirmation($e->order));
});

If your listener is slow, implement ShouldQueue — the event is already serializable.

Testing

composer install
composer test       # runs everything; e2e suites skip if PayU sandbox creds aren't set
composer format     # Pint
composer analyse    # PHPStan level 5 (Larastan)

E2E tests against the real PayU sandbox require:

export PAYU_POS_ID="..."
export PAYU_CLIENT_ID="..."
export PAYU_CLIENT_SECRET="..."
export PAYU_SECOND_KEY="..."
composer test

Refunds

Refunds are issued from the PayU merchant panel — this package does not expose a programmatic refund API. refund() on the driver returns PaymentRefund(false, …) by design.

What the package does handle on the refund side:

  • REFUNDED webhooks from PayU are received, verified, and update the Lunar Order status to refunded.
  • A PayuPaymentRefunded domain event fires so listeners can release stock, notify the customer, alert finance, etc.
  • The audit row in payu_transactions records the refund event.

So: trigger refunds in the panel, listen to the event in your app.

What's intentionally not in this package

  • Programmatic refund API — see above.
  • Recurring billing / saved cards — PayU supports them but they need their own DTO/event surface and a token storage strategy. Not in scope.
  • Partial captures — order is captured in full when PayU reports COMPLETED.
  • Filament admin UIOrder.meta.payu is the source of truth; surface it in your panel however you prefer.

License

MIT — see LICENSE.

wizcodepl/lunar-payu 适用场景与选型建议

wizcodepl/lunar-payu 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 102 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「ecommerce」 「payments」 「laravel」 「polish」 「payu」 「lunar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 wizcodepl/lunar-payu 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wizcodepl/lunar-payu 我们能提供哪些服务?
定制开发 / 二次开发

基于 wizcodepl/lunar-payu 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 102
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 47
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-05