-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 17f3f38
Showing
27 changed files
with
1,824 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/vendor | ||
/.idea | ||
composer.phar | ||
composer.lock | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
preset: laravel | ||
|
||
linting: true | ||
|
||
disabled: | ||
- single_class_element_per_statement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
language: php | ||
|
||
env: | ||
global: | ||
- setup=basic | ||
|
||
matrix: | ||
fast_finish: true | ||
include: | ||
- php: 5.6 | ||
env: setup=lowest FRAMEWORK_VERSION=5.3.10 testbench_VERSION=3.3.3 | ||
- php: 5.6 | ||
env: setup=stable FRAMEWORK_VERSION=5.3.* testbench_VERSION=3.3.3 | ||
- php: 5.6 | ||
env: setup=stable FRAMEWORK_VERSION=5.4.* testbench_VERSION=3.4.* | ||
- php: 7.0 | ||
env: setup=lowest FRAMEWORK_VERSION=5.3.10 testbench_VERSION=3.3.3 | ||
- php: 7.0 | ||
env: setup=stable FRAMEWORK_VERSION=5.3.* testbench_VERSION=3.3.3 | ||
- php: 7.0 | ||
env: setup=stable FRAMEWORK_VERSION=5.4.* testbench_VERSION=3.4.* | ||
- php: 7.1 | ||
env: setup=lowest FRAMEWORK_VERSION=5.3.10 testbench_VERSION=3.3.3 | ||
- php: 7.1 | ||
env: setup=stable FRAMEWORK_VERSION=5.3.* testbench_VERSION=3.3.3 | ||
- php: 7.1 | ||
env: setup=stable FRAMEWORK_VERSION=5.4.* testbench_VERSION=3.4.* | ||
|
||
sudo: false | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
|
||
services: | ||
- memcached | ||
- redis-server | ||
|
||
before_install: | ||
- if [[ $TRAVIS_PHP_VERSION != 7.1 ]] ; then phpenv config-rm xdebug.ini; fi | ||
- echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini | ||
- echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini | ||
- composer require "laravel/framework:${FRAMEWORK_VERSION}" --no-update | ||
- composer require "orchestra/testbench:${testbench_VERSION}" --no-update | ||
- travis_retry composer self-update | ||
|
||
install: | ||
- if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-dist --no-suggest; fi | ||
- if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; fi | ||
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable --no-suggest; fi | ||
|
||
script: vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Changelog | ||
|
||
All notable changes to `laravel-unitpay` will be documented in this file | ||
|
||
## 1.0.6 - 2017-07-11 | ||
|
||
- Add support for automatic package discovery. | ||
|
||
## 1.0.5 - 2017-02-25 | ||
|
||
- stable release | ||
|
||
## 1.0.0 - 2017-02-21 | ||
|
||
- initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Contributing | ||
|
||
Contributions are **welcome** and will be fully **credited**. | ||
|
||
Please read and understand the contribution guide before creating an issue or pull request. | ||
|
||
## Etiquette | ||
|
||
This project is open source, and as such, the maintainers give their free time to build and maintain the source code | ||
held within. They make the code freely available in the hope that it will be of use to other developers. It would be | ||
extremely unfair for them to suffer abuse or anger for their hard work. | ||
|
||
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the | ||
world that developers are civilized and selfless people. | ||
|
||
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient | ||
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. | ||
|
||
## Viability | ||
|
||
When requesting or submitting new features, first consider whether it might be useful to others. Open | ||
source projects are used by many developers, who may have entirely different needs to your own. Think about | ||
whether or not your feature is likely to be used by other users of the project. | ||
|
||
## Procedure | ||
|
||
Before filing an issue: | ||
|
||
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. | ||
- Check to make sure your feature suggestion isn't already present within the project. | ||
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress. | ||
- Check the pull requests tab to ensure that the feature isn't already in progress. | ||
|
||
Before submitting a pull request: | ||
|
||
- Check the codebase to ensure that your feature doesn't already exist. | ||
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix. | ||
|
||
## Requirements | ||
|
||
If the project maintainer has any additional requirements, you will find them listed here. | ||
|
||
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). | ||
|
||
- **Add tests!** - Your patch won't be accepted if it doesn't have tests. | ||
|
||
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. | ||
|
||
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. | ||
|
||
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. | ||
|
||
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. | ||
|
||
**Happy coding**! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) ActionM <[email protected]> | ||
|
||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
> in the Software without restriction, including without limitation the rights | ||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
> copies of the Software, and to permit persons to whom the Software is | ||
> furnished to do so, subject to the following conditions: | ||
> | ||
> The above copyright notice and this permission notice shall be included in | ||
> all copies or substantial portions of the Software. | ||
> | ||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
> THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
# Laravel payment processor package for UnitPay gateway | ||
|
||
[![Latest Stable Version](https://poser.pugx.org/actionm/laravel-unitpay/v/stable)](https://packagist.org/packages/actionm/laravel-unitpay) | ||
[![Build Status](https://img.shields.io/travis/actionm/laravel-unitpay/master.svg?style=flat-square)](https://travis-ci.org/actionm/laravel-unitpay) | ||
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/91033cd8-7b31-4001-8a18-331336c7dcd3/mini.png)](https://insight.sensiolabs.com/projects/91033cd8-7b31-4001-8a18-331336c7dcd3) | ||
[![Quality Score](https://img.shields.io/scrutinizer/g/actionm/laravel-unitpay.svg?style=flat-square)](https://scrutinizer-ci.com/g/actionm/laravel-unitpay) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/actionm/laravel-unitpay.svg?style=flat-square)](https://packagist.org/packages/actionm/laravel-unitpay) | ||
[![License](https://poser.pugx.org/actionm/laravel-unitpay/license)](https://packagist.org/packages/actionm/laravel-unitpay) | ||
|
||
Accept payments via UnitPay ([unitpay.money](http://unitpay.money) or [unitpay.ru](http://unitpay.ru)) using this Laravel framework package ([Laravel](https://laravel.com)). | ||
|
||
- receive payments, adding just the two callbacks | ||
- receive payment notifications via your email or Slack | ||
|
||
You can accept payments with Unitpay via Yandex.Money, QIWI, WebMoney, PayPal, credit cards etc. | ||
|
||
#### Laravel 5.3, 5.4, PHP >= 5.6.4 | ||
|
||
## Installation | ||
|
||
You can install the package through Composer: | ||
|
||
``` bash | ||
composer require actionm/laravel-unitpay | ||
``` | ||
|
||
|
||
Add the service provider to the `providers` array in `config/app.php`: | ||
|
||
```php | ||
'providers' => [ | ||
|
||
ActionM\UnitPay\UnitPayServiceProvider::class, | ||
|
||
] | ||
``` | ||
|
||
Add the `UnitPay` facade to your facades array: | ||
|
||
```php | ||
'UnitPay' => ActionM\UnitPay\Facades\UnitPay::class, | ||
``` | ||
|
||
Publish the configuration file and views | ||
``` bash | ||
php artisan vendor:publish --provider="ActionM\UnitPay\UnitPayServiceProvider" | ||
``` | ||
|
||
Publish only the configuration file | ||
``` bash | ||
php artisan vendor:publish --provider="ActionM\UnitPay\UnitPayServiceProvider" --tag=config | ||
``` | ||
|
||
Publish only the views | ||
``` bash | ||
php artisan vendor:publish --provider="ActionM\UnitPay\UnitPayServiceProvider" --tag=views | ||
``` | ||
|
||
## Configuration | ||
|
||
Once you have published the configuration files, please edit the config file in `config/unitpay.php`. | ||
|
||
- Create an account on [unitpay.money](http://unitpay.money) or [unitpay.ru](http://unitpay.ru) | ||
- Add your project, copy the `PUBLIC KEY` and `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 `searchOrderFilter` and `paidOrderFilter` | ||
- Set notification channels (email and/or Slack) and Slack `webhook_url` | ||
|
||
## Usage | ||
|
||
1) Generate an HTML payment form with enabled payment methods: | ||
|
||
``` php | ||
$payment_amount = Order amount | ||
|
||
$payment_no = Unique order ID in your project | ||
|
||
$user_email = User email | ||
|
||
$item_name = Name of your order item | ||
|
||
$currency = 'RUB' or 'UAH','BYR','EUR','USD' | ||
``` | ||
|
||
``` php | ||
UnitPay::generatePaymentForm($payment_amount, $payment_no, $user_email, $item_name, $currency); | ||
``` | ||
|
||
Customize the HTML payment form in the published view: | ||
|
||
`app/resources/views/vendor/unitpay/payment_form.blade.php` | ||
|
||
2) Process the request from UnitPay: | ||
``` php | ||
UnitPay::payOrderFromGate(Request $request) | ||
``` | ||
## Important | ||
|
||
You must define callbacks in `config/unitpay.php` to search the order and save the paid order. | ||
|
||
|
||
``` php | ||
'searchOrderFilter' => null // ExampleController:searchOrderFilter($request) | ||
``` | ||
|
||
``` php | ||
'paidOrderFilter' => null // ExampleController::paidOrderFilter($request,$order) | ||
``` | ||
|
||
## Example | ||
|
||
The process scheme: | ||
|
||
1. The request comes from `unitpay.money` or `unitpay.ru` `GET` `http://yourproject.com/unitpay/result` (with params). | ||
2. The function`ExampleController@payOrderFromGate` runs the validation process (auto-validation request params). | ||
3. The static function `searchOrderFilter` will be called (see `config/unitpay.php` `searchOrderFilter`) to search the order by the unique id. | ||
4. If the current order status is NOT `paid` in your database, the static function `paidOrderFilter` will be called (see `config/unitpay.php` `paidOrderFilter`). | ||
|
||
Add the route to `routes/web.php`: | ||
``` php | ||
Route::get('/unitpay/result', 'ExampleController@payOrderFromGate'); | ||
``` | ||
|
||
> **Note:** | ||
don't forget to save your full route url (e.g. http://example.com/unitpay/result ) for your project on [unitpay.money](unitpay.money) or [unitpay.ru](unitpay.ru). | ||
|
||
Create the following controller: `/app/Http/Controllers/ExampleController.php`: | ||
|
||
``` php | ||
class ExampleController extends Controller | ||
{ | ||
|
||
/** | ||
* Search the order if the request from unitpay is received. | ||
* Return the order with required details for the unitpay request verification. | ||
* | ||
* @param Request $request | ||
* @param $order_id | ||
* @return mixed | ||
*/ | ||
public static function searchOrderFilter(Request $request, $order_id) { | ||
|
||
// If the order with the unique order ID exists in the database | ||
$order = Order::where('unique_id', $order_id)->first(); | ||
|
||
if ($order) { | ||
$order['UNITPAY_orderSum'] = $order->amount; // from your database | ||
$order['UNITPAY_orderCurrency'] = 'RUB'; // from your database | ||
|
||
// if the current_order is already paid in your database, return strict "paid"; | ||
// if not, return something else | ||
$order['UNITPAY_orderStatus'] = $order->order_status; // from your database | ||
return $order; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* When the payment of the order is received from unitpay, you can process the paid order. | ||
* !Important: don't forget to set the order status as "paid" in your database. | ||
* | ||
* @param Request $request | ||
* @param $order | ||
* @return bool | ||
*/ | ||
public static function paidOrderFilter(Request $request, $order) | ||
{ | ||
// Your code should be here: | ||
YourOrderController::saveOrderAsPaid($order); | ||
|
||
// Return TRUE if the order is saved as "paid" in the database or FALSE if some error occurs. | ||
// If you return FALSE, then you can repeat the failed paid requests on the unitpay website manually. | ||
return true; | ||
} | ||
|
||
/** | ||
* Process the request from the UnitPay route. | ||
* searchOrderFilter is called to search the order. | ||
* If the order is paid for the first time, paidOrderFilter is called to set the order status. | ||
* If searchOrderFilter returns the "paid" order status, then paidOrderFilter will not be called. | ||
* | ||
* @param Request $request | ||
* @return mixed | ||
*/ | ||
public function payOrderFromGate(Request $request) | ||
{ | ||
return UnitPay::payOrderFromGate($request); | ||
} | ||
``` | ||
|
||
|
||
## Changelog | ||
|
||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. | ||
|
||
## Testing | ||
|
||
``` bash | ||
$ composer test | ||
``` | ||
|
||
## Contributing | ||
|
||
Please see [CONTRIBUTING](CONTRIBUTING.md) 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 | ||
|
||
- [ActionM](https://github.com/actionm) | ||
- [All Contributors](../../contributors) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
Oops, something went wrong.