承接 weishaypt/laravel-lava-ru 相关项目开发

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

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

weishaypt/laravel-lava-ru

最新稳定版本:v4.0.0

Composer 安装命令:

composer require weishaypt/laravel-lava-ru

包简介

lava.ru payments for Laravel

README 文档

README

Accept payments via LavaRu (lava.ru) using this Laravel framework package (Laravel).

  • receive payments, adding just the two callbacks

Laravel >= 11.*, PHP >= 8.2

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

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

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

Installation

Require this package with composer.

composer require weishaypt/laravel-lava-ru

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

Weishaypt\LavaRu\LavaRuServiceProvider::class,

Add the FreeKassa facade to your facades array:

'LavaRu' => Weishaypt\LavaRu\Facades\LavaRu::class,

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

php artisan vendor:publish --provider="Weishaypt\LavaRu\LavaRuServiceProvider"

Configuration

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

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

Usage

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

$url = LavaRu::getPayUrl($amount, $order_id);

$redirect = LavaRu::redirectToPayUrl($amount, $order_id);

You can add custom fields to your payment:

$rows = [
    'time' => Carbon::now(),
    'info' => 'Local payment'
];

$url = LavaRu::getPayUrl($amount, $order_id, $desc, $payment_methood, $rows);

$redirect = LavaRu::redirectToPayUrl($amount, $order_id, $desc, $payment_methood, $rows);

$desc and $payment_methood can be null.

  1. Process the request from LavaRu:
LavaRu::handle(Request $request)

Important

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

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

Example

The process scheme:

  1. The request comes from lava.ru GET / POST http://yourproject.com/LavaRu/result (with params).
  2. The functionLavaRuController@handlePayment runs the validation process (auto-validation request params).
  3. The method searchOrder will be called (see config/lavaru.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/lavaru.php paidOrder).

Add the route to routes/web.php:

 Route::get('/lavaru/result', 'LavaRuController@handlePayment');

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

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

class LavaRuController 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 LavaRu::handle($request);
    }
}

Security

If you discover any security related issues, please send me an email at ya@sanek.dev instead of using the issue tracker.

Credits

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固