承接 mnastalski/przelewy24-laravel 相关项目开发

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

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

mnastalski/przelewy24-laravel

Composer 安装命令:

composer require mnastalski/przelewy24-laravel

包简介

Przelewy24 Laravel library

README 文档

README

Laravel wrapper for mnastalski/przelewy24-php.

Requirements

  • PHP >=8.1
  • Laravel >=9.0

Installation

composer require mnastalski/przelewy24-laravel

Configuration

Add the following to your .env file:

PRZELEWY24_MERCHANT_ID=12345
PRZELEWY24_REPORTS_KEY=f0ae...
PRZELEWY24_CRC=aef0...
PRZELEWY24_IS_LIVE=false

Setting PRZELEWY24_IS_LIVE to false will use the sandbox environment. Set it to true to use production/live mode.

Pos ID may also be set if necessary:

PRZELEWY24_POS_ID=...

Usage

Here is a simple example of how the package can be used to create a transaction, listen for Przelewy24's webhook and verify the transaction. Dependency injection is used to get an instance of Przelewy24:

<?php

use App\Models\Order;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Przelewy24\Enums\Currency;
use Przelewy24\Enums\Language;
use Przelewy24\Exceptions\Przelewy24Exception;
use Przelewy24\Przelewy24;

class MyController
{
    public function __construct(
        private readonly Przelewy24 $przelewy24,
    ) {}

    public function pay(Order $order): RedirectResponse
    {
        // Create a new transaction
        $register = $this->przelewy24->transactions()->register(
            sessionId: $order->id,
            amount: $order->amount,
            description: "Order #{$order->id}",
            email: $order->email,
            urlReturn: route('orders.success'),
            urlStatus: route('orders.webhook'),
            // client: 'Mateusz Nastalski',
            // currency: Currency::EUR,
            // language: Language::ENGLISH,
            // ...
        );

        $order->payment_id = $register->token();
        $order->save();

        // Redirect to Przelewy24's payment gateway
        return redirect(
            $register->gatewayUrl()
        );
    }

    /**
     * Method for route "orders.success". 
     */
    public function paymentSuccessful(): Response
    {
        return response('Payment successful!');
    }

    /**
     * Method for route "orders.webhook".
     * Must be POST and excluded from CSRF protection.
     */
    public function webhook(Request $request): Response
    {
        // Handle Przelewy24's webhook
        $webhook = $this->przelewy24->handleWebhook(
            $request->post()
        );

        // Find related order using webhook's session ID
        $order = Order::find(
            $webhook->sessionId()
        );

        // If you would like to verify that the webhook and its
        // signature are legitimate, you may use the following method:
        $isSignValid = $webhook->isSignValid(
            sessionId: $order->id,
            amount: $order->amount,
            originAmount: $order->amount,
            orderId: $webhook->orderId(),
            methodId: $webhook->methodId(),
            statement: $webhook->statement(),
            // currency: Currency::EUR,
        );

        if (!$isSignValid) {
            // Handle error ...

            abort(Response::HTTP_BAD_REQUEST);
        }

        // Verify the transaction / claim the payment
        try {
            $this->przelewy24->transactions()->verify(
                $order->id,
                $webhook->orderId(),
                $order->amount,
            );

            $order->status = 'paid';
            $order->save();
        } catch (Przelewy24Exception) {
            // Handle error ...
        }

        return response()->noContent();
    }
}

As this package wraps the mnastalski/przelewy24-php package, all methods are the same. For a more in-depth documentation, check its README.

mnastalski/przelewy24-laravel 适用场景与选型建议

mnastalski/przelewy24-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.24k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2023 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 mnastalski/przelewy24-laravel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 20.24k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-06