承接 dmitriidigital/laravel-unitpay 相关项目开发

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

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

dmitriidigital/laravel-unitpay

Composer 安装命令:

composer require dmitriidigital/laravel-unitpay

包简介

UnitPay payments for Laravel

README 文档

README

Latest Stable Version Build Status StyleCI CodeFactor Total Downloads License

Accept payments via UnitPay (unitpay.ru) using this Laravel framework package (Laravel).

  • receive payments, adding just the two callbacks

Laravel >= 8.*, PHP >= 7.3

To use the package for Laravel 7.* use the 3.x branch

To use the package for Laravel 6.* use the 2.x branch

To use the package for Laravel 5.* use the 1.x branch

Installation

Require this package with composer.

composer require "dmitriidigital/laravel-unitpay"

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php

Dmitriidigital\UnitPay\UnitPayServiceProvider::class,

Add the UnitPay facade to your facades array:

'UnitPay' => Dmitriidigital\UnitPay\Facades\UnitPay::class,

Copy the package config to your local config with the publish command:

php artisan vendor:publish --provider="Dmitriidigital\UnitPay\UnitPayServiceProvider"

Configuration

Once you have published the configuration files, please edit the config file in config/unitpay.php.

  • Create an account on unitpay.ru
  • Add your project, copy the public_key, secret_key params and paste into config/unitpay.php
  • After the configuration has been published, edit config/unitpay.php
  • Set the callback static function for searchOrder and paidOrder
  • Create route to your controller, and call UnitPay::handle method

Usage

  1. Generate a payment url or get redirect:
$amount = 100; // Payment`s amount

$email = "example@gmail.com"; // Your customer`s email

$description = "Test payment";

//

$url = UnitPay::getPayUrl($amount, $order_id, $email, $description, $currency);

$redirect = UnitPay::redirectToPayUrl($amount, $order_id, $email, $description, $currency);
  1. Process the request from UnitPay:
UnitPay::handle(Request $request)

Important

You must define callbacks in config/unitpay.php to search the order and save the paid order.

'searchOrder' => null  // UnitPayController@searchOrder(Request $request)
'paidOrder' => null  // UnitPayController@paidOrder(Request $request, $order)

Example

The process scheme:

  1. The request comes from unitpay.ru GET http://yourproject.com/unitpay/result (with params).
  2. The functionUnitPayController@handlePayment runs the validation process (auto-validation request params).
  3. The method searchOrder will be called (see config/unitpay.php searchOrder) to search the order by the unique id.
  4. If the current order status is NOT paid in your database, the method paidOrder will be called (see config/unitpay.php paidOrder).

Add the route to routes/web.php:

 Route::get('/unitpay/result', 'UnitPayController@handlePayment');

Note: don't forget to save your full route url (e.g. http://example.com/unitpay/result ) for your project on unitpay.ru.

Create the following controller: /app/Http/Controllers/UnitPayController.php:

class UnitPayController extends Controller
{
    /**
     * Search the order in your database and return that order
     * to paidOrder, if status of your order is 'paid'
     *
     * @param Request $request
     * @param $order_id
     * @return bool|mixed
     */
    public function searchOrder(Request $request, $order_id)
    {
        $order = Order::where('id', $order_id)->first();

        if($order) {
            $order['_orderSum'] = $order->sum;

            // If your field can be `paid` you can set them like string
            $order['_orderStatus'] = $order['status'];

            // Else your field doesn` has value like 'paid', you can change this value
            $order['_orderStatus'] = ('1' == $order['status']) ? 'paid' : false;

            return $order;
        }

        return false;
    }

    /**
     * When paymnet is check, you can paid your order
     *
     * @param Request $request
     * @param $order
     * @return bool
     */
    public function paidOrder(Request $request, $order)
    {
        $order->status = 'paid';
        $order->save();

        //

        return true;
    }

    /**
     * Start handle process from route
     *
     * @param Request $request
     * @return mixed
     */
    public function handlePayment(Request $request)
    {
        return UnitPay::handle($request);
    }
}

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please send me an email at dmitriidigital@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

dmitriidigital/laravel-unitpay 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-09