Code Monkey home page Code Monkey logo

laravel-unitpay's Introduction

Laravel payment processor package for UnitPay gateway

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 "maksa988/laravel-unitpay"

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

Maksa988\UnitPay\UnitPayServiceProvider::class,

Add the UnitPay facade to your facades array:

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

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

php artisan vendor:publish --provider="Maksa988\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 = "[email protected]"; // 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 [email protected] instead of using the issue tracker.

Credits

License

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

laravel-unitpay's People

Contributors

maksa988 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-unitpay's Issues

error with guzzlehttp/guzzle

Hi,

I have an error for Laravel 8 in composer
Problem 1
- Installation request for maksa988/laravel-unitpay 2.* -> satisfiable by maksa988/laravel-unitpay[2.x-dev, v2.0.0].
- Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.2.0].
- Can only install one of: guzzlehttp/guzzle[7.2.0, 6.5.x-dev].
- Can only install one of: guzzlehttp/guzzle[6.5.x-dev, 7.2.0].
- Conclusion: install guzzlehttp/guzzle 6.5.x-dev
- Installation request for guzzlehttp/guzzle (locked at 7.2.0, required as ^7.0.1) -> satisfiable by guzzlehttp/guzzle[7.2.0].

Laravel 6 and 7 support

Hi, I`ve tried to use this package with Laravel 6.18.0 and got an error:

Problem 1
    - Conclusion: remove laravel/framework v6.18.0
    - Conclusion: don't install laravel/framework v6.18.0
    - maksa988/laravel-unitpay v1.0.2 requires laravel/framework ^5.5 -> satisfiable by laravel/framework[5.5.x-dev, 5.6.x-dev, 5.7.x-dev, 5.8.x-dev].
    - maksa988/laravel-unitpay v1.0.0 requires laravel/framework ^5.3.10 -> satisfiable by laravel/framework[5.3.x-dev, 5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.x-dev, 5.8.x-dev].
    - maksa988/laravel-unitpay v1.0.1 requires laravel/framework ^5.3.10 -> satisfiable by laravel/framework[5.3.x-dev, 5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.x-dev, 5.8.x-dev].
    - Can only install one of: laravel/framework[5.5.x-dev, v6.18.0].
    - Can only install one of: laravel/framework[5.6.x-dev, v6.18.0].
    - Can only install one of: laravel/framework[5.7.x-dev, v6.18.0].
    - Can only install one of: laravel/framework[5.8.x-dev, v6.18.0].
    - Can only install one of: laravel/framework[5.3.x-dev, v6.18.0].
    - Can only install one of: laravel/framework[5.4.x-dev, v6.18.0].
    - Installation request for laravel/framework (locked at v6.18.0, required as ^6.2) -> satisfiable by laravel/framework[v6.18.0].
    - Installation request for maksa988/laravel-unitpay ^1.0 -> satisfiable by maksa988/laravel-unitpay[v1.0.0, v1.0.1, v1.0.2].

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.