add laravel 13 support
This commit is contained in:
15
.editorconfig
Normal file
15
.editorconfig
Normal file
@@ -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
|
||||
17
.gitattributes
vendored
Normal file
17
.gitattributes
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
||||
61
.gitignore
vendored
Normal file
61
.gitignore
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# =========================
|
||||
# Operating System Files
|
||||
# =========================
|
||||
|
||||
# OSX
|
||||
# =========================
|
||||
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# PhpStorm project's cache
|
||||
.idea
|
||||
|
||||
# VSCode project's cache
|
||||
.vscode
|
||||
|
||||
# Vendor directory
|
||||
vendor/
|
||||
|
||||
# Composer.lock file
|
||||
composer.lock
|
||||
|
||||
.phpunit.result.cache
|
||||
1
.styleci.yml
Normal file
1
.styleci.yml
Normal file
@@ -0,0 +1 @@
|
||||
preset: psr2
|
||||
8
.travis.yml
Normal file
8
.travis.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
language: php
|
||||
php:
|
||||
- '8.0'
|
||||
- '8.1'
|
||||
- '8.2'
|
||||
- '8.3'
|
||||
- '8.4'
|
||||
before_script: composer install
|
||||
25
CHANGELOG.md
Normal file
25
CHANGELOG.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Changelog
|
||||
|
||||
All Notable changes to `payment` will be documented in this file.
|
||||
|
||||
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
|
||||
|
||||
## Date - 2019-01-09
|
||||
|
||||
### Fixed
|
||||
- Nothing
|
||||
|
||||
### Added
|
||||
- Nothing
|
||||
|
||||
### Deprecated
|
||||
- Nothing
|
||||
|
||||
### Fixed
|
||||
- Nothing
|
||||
|
||||
### Removed
|
||||
- Nothing
|
||||
|
||||
### Security
|
||||
- Nothing
|
||||
74
CONDUCT.md
Normal file
74
CONDUCT.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# Contributor Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at `khanzadimahdi@gmail.com`. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
24
CONTRIBUTING.md
Normal file
24
CONTRIBUTING.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Contributing
|
||||
|
||||
Contributions are **welcome** and will be fully **credited**.
|
||||
|
||||
We accept contributions via Pull Requests on [Github](https://github.com/shetabit/payment).
|
||||
|
||||
## Pull Requests
|
||||
|
||||
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - Check the code style with ``$ composer check-style`` and fix it with ``$ composer fix-style``.
|
||||
|
||||
- **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.
|
||||
|
||||
- **Create feature branches** - Don't ask us to pull from your master branch.
|
||||
|
||||
- **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**!
|
||||
27
ISSUE_TEMPLATE.md
Normal file
27
ISSUE_TEMPLATE.md
Normal file
@@ -0,0 +1,27 @@
|
||||
<!-- Provide a general summary of the issue in the Title above -->
|
||||
|
||||
## Detailed description
|
||||
|
||||
Provide a detailed description of the change or addition you are proposing.
|
||||
|
||||
Make it clear if the issue is a bug, an enhancement or just a question.
|
||||
|
||||
## Context
|
||||
|
||||
Why is this change important to you? How would you use it?
|
||||
|
||||
How can it benefit other users?
|
||||
|
||||
## Possible implementation
|
||||
|
||||
Not obligatory, but suggest an idea for implementing addition or change.
|
||||
|
||||
## Your environment
|
||||
|
||||
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
|
||||
|
||||
* Version used (e.g. PHP 7.2, HHVM 3):
|
||||
* Operating system and version (e.g. Ubuntu 19.04, Windows 10):
|
||||
* Link to your project:
|
||||
* ...
|
||||
* ...
|
||||
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Mahdi Khanzadi <khanzadimahdi@gmail.com>
|
||||
|
||||
> 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.
|
||||
43
PULL_REQUEST_TEMPLATE.md
Normal file
43
PULL_REQUEST_TEMPLATE.md
Normal file
@@ -0,0 +1,43 @@
|
||||
<!--- Provide a general summary of your changes in the Title above -->
|
||||
|
||||
## Description
|
||||
|
||||
Describe your changes in detail.
|
||||
|
||||
## Motivation and context
|
||||
|
||||
Why is this change required? What problem does it solve?
|
||||
|
||||
If it fixes an open issue, please link to the issue here (if you write `fixes #num`
|
||||
or `closes #num`, the issue will be automatically closed when the pull is accepted.)
|
||||
|
||||
## How has this been tested?
|
||||
|
||||
Please describe in detail how you tested your changes.
|
||||
|
||||
Include details of your testing environment, and the tests you ran to
|
||||
see how your change affects other areas of the code, etc.
|
||||
|
||||
## Screenshots (if appropriate)
|
||||
|
||||
## Types of changes
|
||||
|
||||
What types of changes does your code introduce? Put an `x` in all the boxes that apply:
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
|
||||
|
||||
## Checklist:
|
||||
|
||||
Go over all the following points, and put an `x` in all the boxes that apply.
|
||||
|
||||
Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our [continuous integration](http://www.phptherightway.com/#continuous-integration) server to make sure your [tests and code style pass](https://help.github.com/articles/about-required-status-checks/).
|
||||
|
||||
- [ ] I have read the **[CONTRIBUTING](CONTRIBUTING.md)** document.
|
||||
- [ ] My pull request addresses exactly one patch/feature.
|
||||
- [ ] I have created a branch for this patch/feature.
|
||||
- [ ] Each individual commit in the pull request is meaningful.
|
||||
- [ ] I have added tests to cover my changes.
|
||||
- [ ] If my change requires a change to the documentation, I have updated it accordingly.
|
||||
|
||||
If you're unsure about any of these, don't hesitate to ask. We're here to help!
|
||||
553
README-FA.md
Normal file
553
README-FA.md
Normal file
@@ -0,0 +1,553 @@
|
||||
<p align="center"><img src="resources/images/payment.png?raw=true"></p>
|
||||
|
||||
<div dir=rtl>
|
||||
|
||||
# پکیج درگاه پرداخت برای لاراول
|
||||
|
||||
|
||||
[![Software License][ico-license]](LICENSE.md)
|
||||
[![Latest Version on Packagist][ico-version]][link-packagist]
|
||||
[![Total Downloads on Packagist][ico-download]][link-packagist]
|
||||
[](https://github.styleci.io/repos/169948762)
|
||||
[](https://codeclimate.com/github/shetabit/payment/maintainability)
|
||||
[![Quality Score][ico-code-quality]][link-code-quality]
|
||||
|
||||
این پکیج برای پرداخت آنلاین توسط درگاههای مختلف در لاراول ایجاد شده است.
|
||||
|
||||
|
||||
> این پکیج با درگاههای پرداخت مختلفی کار میکنه. در صورتی که درگاه مورد نظرتون رو در لیست درایورهای موجود پیدا نکردید میتونید برای درگاهی که استفاده میکنید درایور مورد نظرتون رو بسازید.
|
||||
|
||||
درصورتی که از PHP استفاده میکنید میتونید از پکیج [shetabit/multipay](https://github.com/shetabit/multipay) استفاده کنید.
|
||||
|
||||
- [داکیومنت فارسی][link-fa]
|
||||
- [english documents][link-en]
|
||||
- [中文文档][link-zh]
|
||||
|
||||
|
||||
در صورتی که از این پکیج خوشتون آمده و ازش استفاده میکنید میتونید با پرداخت مبلغ اندکی من رو حمایت کنید تا این پکیج رو بیشتر توسعه بدم و درگاههای جدیدتری بهش اضافه کنم.
|
||||
|
||||
[به منظور کمک مالی کلیک کنید](https://zarinp.al/@mahdikhanzadi) :sunglasses: :bowtie:
|
||||
|
||||
|
||||
در صورتی که نیاز به آموزش دارید میتونید یه نگاهی به لینک زیر بندازید
|
||||
|
||||
- [آموزش ویدیویی پرداخت و خرید در لاراول](https://ditty.ir/videos/laravel-online-payment-installation/nM4Y5)
|
||||
|
||||
# لیست محتوا
|
||||
|
||||
- [درایور های موجود](#درایورهای-موجود)
|
||||
- [نصب](#نصب)
|
||||
- [تنظیمات](#تنظیمات)
|
||||
- [طریقه استفاده](#طریقه-استفاده)
|
||||
- [کار با صورتحساب ها](#کار-با-صورتحساب-ها)
|
||||
- [ثبت درخواست برای پرداخت صورتحساب](#ثبت-درخواست-برای-پرداخت-صورتحساب)
|
||||
- [پرداخت صورتحساب](#پرداخت-صورتحساب)
|
||||
- [اعتبار سنجی پرداخت](#اعتبار-سنجی-پرداخت)
|
||||
- [ایجاد درایور دلخواه](#ایجاد-درایور-دلخواه)
|
||||
- [متدهای سودمند](#متدهای-سودمند)
|
||||
- [تغییرات](#تغییرات)
|
||||
- [مشارکت کننده ها](#مشارکت-کننده-ها)
|
||||
- [امنیت](#امنیت)
|
||||
- [توسعه دهندگان](#توسعه-دهندگان)
|
||||
- [لایسنس](#لایسنس)
|
||||
|
||||
# درایورهای موجود
|
||||
|
||||
- [آتیپی](https://www.atipay.net/) :heavy_check_mark:
|
||||
- [آقای پرداخت](https://aqayepardakht.ir/) :heavy_check_mark:
|
||||
- [ازکیوام (پرداخت اقساطی)](https://www.azkivam.com/) :heavy_check_mark:
|
||||
- [آسانپرداخت](https://asanpardakht.ir/) :heavy_check_mark:
|
||||
- [اعتبارینو (پرداخت اقساطی)](https://etebarino.com/) :heavy_check_mark:
|
||||
- [امیدپی](https://omidpayment.ir/) :heavy_check_mark:
|
||||
- [آیدیپی](https://idpay.ir/) :heavy_check_mark:
|
||||
- [ایرانکیش](http://irankish.com/) :heavy_check_mark:
|
||||
- [بهپرداخت (ملت)](http://www.behpardakht.com/) :heavy_check_mark:
|
||||
- [بیتپی](https://bitpay.ir/) :heavy_check_mark:
|
||||
- [دیجیپی](https://www.mydigipay.com/) :heavy_check_mark:
|
||||
- [فنآواکارت](https://www.fanava.com/) :heavy_check_mark:
|
||||
- [لوکال](#local-driver) :heavy_check_mark:
|
||||
- [جیبیت](https://jibit.ir/) :heavy_check_mark:
|
||||
- [نکستپی](https://nextpay.ir/) :heavy_check_mark:
|
||||
- [پارسیان](https://www.pec.ir/) :heavy_check_mark:
|
||||
- [پاسارگاد](https://bpi.ir/) :heavy_check_mark:
|
||||
- [پیآیآر](https://pay.ir/) :heavy_check_mark:
|
||||
- [پیفا](https://payfa.com/) :heavy_check_mark:
|
||||
- [پیپال](http://www.paypal.com/) (به زودی در ورژن بعدی اضافه میشود)
|
||||
- [پیپینگ](https://www.payping.ir/) :heavy_check_mark:
|
||||
- [پیاستار](http://paystar.ir/) :heavy_check_mark:
|
||||
- [پولام](https://poolam.ir/) :heavy_check_mark:
|
||||
- [رایانپی](https://rayanpay.com/) :heavy_check_mark:
|
||||
- [سداد (ملی)](https://sadadpsp.ir/) :heavy_check_mark:
|
||||
- [سامان](https://www.sep.ir) :heavy_check_mark:
|
||||
- [سپ (درگاه الکترونیک سامان) کشاورزی و صادرات](https://www.sep.ir) :heavy_check_mark:
|
||||
- [سپهر (صادرات)](https://www.sepehrpay.com/) :heavy_check_mark:
|
||||
- [سپرده](https://sepordeh.com/) :heavy_check_mark:
|
||||
- [سیزپی](https://www.sizpay.ir/) :heavy_check_mark:
|
||||
- [تومن](https://tomanpay.net/) :heavy_check_mark:
|
||||
- [وندار](https://vandar.io/) :heavy_check_mark:
|
||||
- [والتا](https://walleta.ir/) :heavy_check_mark:
|
||||
- [یکپی](https://yekpay.com/) :heavy_check_mark:
|
||||
- [زرینپال](https://www.zarinpal.com/) :heavy_check_mark:
|
||||
- [زیبال](https://www.zibal.ir/) :heavy_check_mark:
|
||||
|
||||
- درایورهای دیگر ساخته خواهند شد یا اینکه بسازید و درخواست `merge` بدید.
|
||||
|
||||
> در صورتی که درایور مورد نظرتون موجود نیست, میتونید برای درگاه پرداخت موردنظرتون درایور بسازید.
|
||||
|
||||
## نصب
|
||||
|
||||
نصب با استفاده از کامپوزر
|
||||
|
||||
</div>
|
||||
|
||||
``` bash
|
||||
composer require shetabit/payment
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
## تنظیمات
|
||||
|
||||
درصورتی که از `Laravel 5.5` یا ورژن های بالاتر استفاده میکنید نیازی به انجام تنظیمات `providers` و `alias` نخواهید داشت.
|
||||
|
||||
درون فایل `config/app.php` دستورات زیر را وارد کنید
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
// In your providers array.
|
||||
'providers' => [
|
||||
...
|
||||
Shetabit\Payment\Provider\PaymentServiceProvider::class,
|
||||
],
|
||||
|
||||
// In your aliases array.
|
||||
'aliases' => [
|
||||
...
|
||||
'Payment' => Shetabit\Payment\Facade\Payment::class,
|
||||
],
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
سپس دستور `php artisan vendor:publish` را اجرا کنید تا فایل `config/payment.php` درون دایرکتوری تنظیمات لاراول قرار بگیرد.
|
||||
|
||||
درون فایل تنظیمات در قسمت `default driver` میتوانید درایوری که قصد استفاده از ان را دارید قرار دهید تا تمامی پرداخت ها از آن طریق انجام شود.
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
// Eg. if you want to use zarinpal.
|
||||
'default' => 'zarinpal',
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
سپس تنظیمات مرتبط با درایوری که قصد استفاده از ان را دارید انجام دهید
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
'drivers' => [
|
||||
'zarinpal' => [
|
||||
// Fill all the credentials here.
|
||||
'apiPurchaseUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentRequest.json',
|
||||
'apiPaymentUrl' => 'https://www.zarinpal.com/pg/StartPay/',
|
||||
'apiVerificationUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentVerification.json',
|
||||
'merchantId' => '',
|
||||
'callbackUrl' => 'http://yoursite.com/path/to',
|
||||
'description' => 'payment in '.config('app.name'),
|
||||
],
|
||||
...
|
||||
]
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
## طریقه استفاده
|
||||
|
||||
در تمامی پرداخت ها اطلاعات پرداخت درون صورتحساب شما نگهداری میشود. برای استفاده از پکیج ابتدا نحوه ی استفاده از کلاس `Invoice` به منظور کار با صورتحساب ها را توضیح میدهیم.
|
||||
|
||||
#### کار با صورتحساب ها
|
||||
|
||||
قبل از انجام هرکاری نیاز به ایجاد یک صورتحساب دارید. برای ایجاد صورتحساب میتوانید از کلاس `Invoice` استفاده کنید.
|
||||
|
||||
درون کد خودتون به شکل زیر عمل کنید:
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
...
|
||||
|
||||
// Create new invoice.
|
||||
$invoice = new Invoice;
|
||||
|
||||
// Set invoice amount.
|
||||
$invoice->amount(1000);
|
||||
|
||||
// Add invoice details: There are 4 syntax available for this.
|
||||
// 1
|
||||
$invoice->detail(['detailName' => 'your detail goes here']);
|
||||
// 2
|
||||
$invoice->detail('detailName','your detail goes here');
|
||||
// 3
|
||||
$invoice->detail(['name1' => 'detail1','name2' => 'detail2']);
|
||||
// 4
|
||||
$invoice->detail('detailName1','your detail1 goes here')
|
||||
->detail('detailName2','your detail2 goes here');
|
||||
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
متدهای موجود برای کار با صورتحساب ها:
|
||||
|
||||
- `uuid`: یک ایدی یونیک برای صورتحساب تنظیم میکند
|
||||
- `getUuid`: ایدی یونیک صورتحساب را برمیگرداند
|
||||
- `detail`: توضیحات یا مواردی که مرتبط به صورتحساب است را به صورتحساب اضافه میکند
|
||||
- `getDetails`: تمامی موارد مرتبطی که به صورتحساب افزوده شده است را برمیگرداند
|
||||
- `amount`: مقدار هزینهای که باید پرداخت شود را مشخص میکند
|
||||
- `getAmount`: هزینهی صورتحساب را برمیگرداند
|
||||
- `transactionId`: شماره تراکنش صورتحساب را مشخص میکند
|
||||
- `getTransactionId`: شماره تراکنش صورتحساب را برمیگرداند
|
||||
- `via`: درایوری که قصد پرداخت صورتحساب با آن را داریم مشخص میکند
|
||||
- `getDriver`: درایور انتخاب شده را برمیگرداند
|
||||
|
||||
#### ثبت درخواست برای پرداخت صورتحساب
|
||||
به منظور پرداخت تمامی صورتحساب ها به یک شماره تراکنش بانکی یا `transactionId` نیاز خواهیم داشت.
|
||||
با ثبت درخواست به منظور پرداخت میتوان شماره تراکنش بانکی را دریافت کرد:
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
...
|
||||
|
||||
// Create new invoice.
|
||||
$invoice = (new Invoice)->amount(1000);
|
||||
|
||||
// Purchase the given invoice.
|
||||
Payment::purchase($invoice,function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
});
|
||||
|
||||
// Purchase method accepts a callback function.
|
||||
Payment::purchase($invoice, function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
});
|
||||
|
||||
// You can specify callbackUrl
|
||||
Payment::callbackUrl('http://yoursite.com/verify')->purchase(
|
||||
$invoice,
|
||||
function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
#### پرداخت صورتحساب
|
||||
|
||||
با استفاده از شماره تراکنش یا `transactionId` میتوانیم کاربر را به صفحه ی پرداخت بانک هدایت کنیم:
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
...
|
||||
|
||||
// Create new invoice.
|
||||
$invoice = (new Invoice)->amount(1000);
|
||||
// Purchase and pay the given invoice.
|
||||
// You should use return statement to redirect user to the bank page.
|
||||
return Payment::purchase($invoice, function($driver, $transactionId) {
|
||||
// Store transactionId in database as we need it to verify payment in the future.
|
||||
})->pay()->render();
|
||||
|
||||
// Do all things together in a single line.
|
||||
return Payment::purchase(
|
||||
(new Invoice)->amount(1000),
|
||||
function($driver, $transactionId) {
|
||||
// Store transactionId in database.
|
||||
// We need the transactionId to verify payment in the future.
|
||||
}
|
||||
)->pay()->render();
|
||||
|
||||
// Retrieve json format of Redirection (in this case you can handle redirection to bank gateway)
|
||||
return Payment::purchase(
|
||||
(new Invoice)->amount(1000),
|
||||
function($driver, $transactionId) {
|
||||
// Store transactionId in database.
|
||||
// We need the transactionId to verify payment in the future.
|
||||
}
|
||||
)->pay()->toJson();
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
|
||||
#### اعتبار سنجی پرداخت
|
||||
|
||||
بعد از پرداخت شدن صورتحساب توسط کاربر, بانک کاربر را به یکی از صفحات سایت ما برمیگردونه و ما با اعتبار سنجی میتونیم متوجه بشیم کاربر پرداخت رو انجام داده یا نه!
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
use Shetabit\Multipay\Exceptions\InvalidPaymentException;
|
||||
...
|
||||
|
||||
// You need to verify the payment to ensure the invoice has been paid successfully.
|
||||
// We use transaction id to verify payments
|
||||
// It is a good practice to add invoice amount as well.
|
||||
try {
|
||||
$receipt = Payment::amount(1000)->transactionId($transaction_id)->verify();
|
||||
|
||||
// You can show payment referenceId to the user.
|
||||
echo $receipt->getReferenceId();
|
||||
|
||||
...
|
||||
} catch (InvalidPaymentException $exception) {
|
||||
/**
|
||||
when payment is not verified, it will throw an exception.
|
||||
We can catch the exception to handle invalid payments.
|
||||
getMessage method, returns a suitable message that can be used in user interface.
|
||||
**/
|
||||
echo $exception->getMessage();
|
||||
}
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
|
||||
در صورتی که پرداخت توسط کاربر به درستی انجام نشده باشه یک استثنا از نوع `InvalidPaymentException` ایجاد میشود که حاوی پیام متناسب با پرداخت انجام شده است.
|
||||
|
||||
#### ایجاد درایور دلخواه:
|
||||
|
||||
برای ایجاد درایور جدید ابتدا نام (اسم) درایوری که قراره بسازید رو به لیست درایور ها اضافه کنید و لیست تنظیات مورد نیاز را نیز مشخص کنید.
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
'drivers' => [
|
||||
'zarinpal' => [...],
|
||||
'my_driver' => [
|
||||
... // Your Config Params here.
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
|
||||
کلاس درایوری که قصد ساختنش رو دارید باید کلاس `Shetabit\Payment\Abstracts\Driver` رو به ارث ببره.
|
||||
|
||||
به عنوان مثال:
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
namespace App\Packages\PaymentDriver;
|
||||
|
||||
use Shetabit\Multipay\Abstracts\Driver;
|
||||
use Shetabit\Multipay\Exceptions\InvalidPaymentException;
|
||||
use Shetabit\Multipay\{Contracts\ReceiptInterface, Invoice, Receipt};
|
||||
|
||||
class MyDriver extends Driver
|
||||
{
|
||||
protected $invoice; // Invoice.
|
||||
|
||||
protected $settings; // Driver settings.
|
||||
|
||||
public function __construct(Invoice $invoice, $settings)
|
||||
{
|
||||
$this->invoice($invoice); // Set the invoice.
|
||||
$this->settings = (object) $settings; // Set settings.
|
||||
}
|
||||
|
||||
// Purchase the invoice, save its transactionId and finaly return it.
|
||||
public function purchase() {
|
||||
// Request for a payment transaction id.
|
||||
...
|
||||
|
||||
$this->invoice->transactionId($transId);
|
||||
|
||||
return $transId;
|
||||
}
|
||||
|
||||
// Redirect into bank using transactionId, to complete the payment.
|
||||
public function pay() {
|
||||
// It is better to set bankApiUrl in config/payment.php and retrieve it here:
|
||||
$bankUrl = $this->settings->bankApiUrl; // bankApiUrl is the config name.
|
||||
|
||||
// Prepare payment url.
|
||||
$payUrl = $bankUrl.$this->invoice->getTransactionId();
|
||||
|
||||
// Redirect to the bank.
|
||||
return redirect()->to($payUrl);
|
||||
}
|
||||
|
||||
// Verify the payment (we must verify to ensure that user has paid the invoice).
|
||||
public function verify(): ReceiptInterface {
|
||||
$verifyPayment = $this->settings->verifyApiUrl;
|
||||
|
||||
$verifyUrl = $verifyPayment.$this->invoice->getTransactionId();
|
||||
|
||||
...
|
||||
|
||||
/**
|
||||
Then we send a request to $verifyUrl and if payment is not valid we throw an InvalidPaymentException with a suitable message.
|
||||
**/
|
||||
throw new InvalidPaymentException('a suitable message');
|
||||
|
||||
/**
|
||||
We create a receipt for this payment if everything goes normally.
|
||||
**/
|
||||
return new Receipt('driverName', 'payment_receipt_number');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
|
||||
بعد از اینکه کلاس درایور خودتون رو ایجاد کردید به فایل `Config/payment.php` برید و درایور خودتون رو در قسمت `map` اضافه کنید.
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
'map' => [
|
||||
...
|
||||
'my_driver' => App\Packages\PaymentDriver\MyDriver::class,
|
||||
]
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
|
||||
**نکته:** دقت کنید کلیدی که قسمت `map` قرار میدهید باید همنام با نامی باشد که در قسمت `drivers` قرار داده اید.
|
||||
|
||||
#### متدهای سودمند
|
||||
|
||||
- `callbackUrl`: با استفاده از این متد به صورت داینامیک میتوانید ادرس صفحه ای که بعد از پرداخت آنلاین کاربر به ان هدایت میشود را مشخص کنید
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
...
|
||||
|
||||
// Create new invoice.
|
||||
$invoice = (new Invoice)->amount(1000);
|
||||
|
||||
// Purchase the given invoice.
|
||||
Payment::callbackUrl($url)->purchase(
|
||||
$invoice,
|
||||
function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
- `amount`: به کمک این متد میتوانید به صورت مستقیم هزینه صورتحساب را مشخص کنید
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
...
|
||||
|
||||
// Purchase (we set invoice to null).
|
||||
Payment::callbackUrl($url)->amount(1000)->purchase(
|
||||
null,
|
||||
function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
- `via`: به منظور تغییر درایور در هنگام اجرای برنامه مورد استفاده قرار میگیرد
|
||||
|
||||
</div>
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
...
|
||||
|
||||
// Create new invoice.
|
||||
$invoice = (new Invoice)->amount(1000);
|
||||
|
||||
// Purchase the given invoice.
|
||||
Payment::via('driverName')->purchase(
|
||||
$invoice,
|
||||
function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
<div dir="rtl">
|
||||
|
||||
|
||||
#### رویدادها
|
||||
|
||||
شما میتوانید درون برنامه خود دو رویداد را ثبت و ضبط کنید
|
||||
|
||||
- **InvoicePurchasedEvent**: هنگامی که یک پرداخت به درستی ثبت شود این رویداد اتفاق میافتد.
|
||||
- **InvoiceVerifiedEvent**: هنگامی که یک پرداخت به درستی وریفای شود این رویداد اتفاق میافتد
|
||||
|
||||
|
||||
## تغییرات
|
||||
|
||||
برای مشاهده آخرین تغییرات انجام شده در پکیج [قسمت تغییرات](CHANGELOG.md) را بررسی کنید.
|
||||
|
||||
## مشارکت کننده ها
|
||||
|
||||
برای مشاهده لیست مشارکت کننده ها [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) را بررسی کنید.
|
||||
|
||||
## امنیت
|
||||
|
||||
در صورتی که مشکل امنیتی در پکیج پیدا کردید به منظور رفع مشکل با ایمیل khanzadimahdi@gmail.com در ارتباط باشید.
|
||||
|
||||
## توسعه دهندگان
|
||||
|
||||
- [Mahdi khanzadi][link-author]
|
||||
- [All Contributors][link-contributors]
|
||||
|
||||
## لایسنس
|
||||
|
||||
توسعه و تولید تحت لایسنس MIT است. برای اطلاعات بیشتر [فایل لایسنس](LICENSE.md) را مطالعه کنید.
|
||||
|
||||
</div>
|
||||
|
||||
[ico-version]: https://img.shields.io/packagist/v/shetabit/payment.svg?style=flat-square
|
||||
[ico-download]: https://img.shields.io/packagist/dt/shetabit/payment.svg?color=%23F18&style=flat-square
|
||||
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
|
||||
[ico-code-quality]: https://img.shields.io/scrutinizer/g/shetabit/payment.svg?label=Code%20Quality&style=flat-square
|
||||
|
||||
[link-fa]: README-FA.md
|
||||
[link-en]: README.md
|
||||
[link-zh]: README-ZH.md
|
||||
[link-packagist]: https://packagist.org/packages/shetabit/payment
|
||||
[link-code-quality]: https://scrutinizer-ci.com/g/shetabit/payment
|
||||
[link-author]: https://github.com/khanzadimahdi
|
||||
[link-contributors]: ../../contributors
|
||||
525
README-ZH.md
Normal file
525
README-ZH.md
Normal file
@@ -0,0 +1,525 @@
|
||||
<p align="center"><img src="resources/images/payment.png?raw=true"></p>
|
||||
|
||||
|
||||
|
||||
# Laravel 支付网关
|
||||
|
||||
|
||||
|
||||
[![Software License][ico-license]](LICENSE.md)
|
||||
[![Latest Version on Packagist][ico-version]][link-packagist]
|
||||
[![Total Downloads on Packagist][ico-download]][link-packagist]
|
||||
[](https://github.styleci.io/repos/169948762)
|
||||
[](https://codeclimate.com/github/shetabit/payment/maintainability)
|
||||
[![Quality Score][ico-code-quality]][link-code-quality]
|
||||
|
||||
这是一个用于整合支付网关的Laravel包。这个包依赖 `Laravel 5.8+`.
|
||||
|
||||
[捐赠我](https://yekpay.me/mahdikhanzadi) 如果你喜欢这个包:sunglasses: :bowtie:
|
||||
|
||||
For PHP integration you can use [shetabit/multipay](https://github.com/shetabit/multipay) package.
|
||||
|
||||
> 此软件包可用于多个驱动程序,如果在[当前驱动程序列表](#list-of-available-drivers)中找不到驱动程序,则可以创建它们
|
||||
|
||||
- [داکیومنت فارسی][link-fa]
|
||||
- [English documents][link-en]
|
||||
- [中文文档][link-zh]
|
||||
|
||||
# 目录
|
||||
|
||||
- [Laravel 支付网关](#laravel-%e6%94%af%e4%bb%98%e7%bd%91%e5%85%b3)
|
||||
- [目录](#%e7%9b%ae%e5%bd%95)
|
||||
- [可用驱动列表](#%e5%8f%af%e7%94%a8%e9%a9%b1%e5%8a%a8%e5%88%97%e8%a1%a8)
|
||||
- [安装](#%e5%ae%89%e8%a3%85)
|
||||
- [配置](#%e9%85%8d%e7%bd%ae)
|
||||
- [如何使用](#%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8)
|
||||
- [使用费用清单进行工作](#%e4%bd%bf%e7%94%a8%e8%b4%b9%e7%94%a8%e6%b8%85%e5%8d%95%e8%bf%9b%e8%a1%8c%e5%b7%a5%e4%bd%9c)
|
||||
- [获取支付清单](#%e8%8e%b7%e5%8f%96%e6%94%af%e4%bb%98%e6%b8%85%e5%8d%95)
|
||||
- [支付](#%e6%94%af%e4%bb%98)
|
||||
- [验证付款](#%e9%aa%8c%e8%af%81%e4%bb%98%e6%ac%be)
|
||||
- [有用的方法](#%e6%9c%89%e7%94%a8%e7%9a%84%e6%96%b9%e6%b3%95)
|
||||
- [创建自定义驱动:](#%e5%88%9b%e5%bb%ba%e8%87%aa%e5%ae%9a%e4%b9%89%e9%a9%b1%e5%8a%a8)
|
||||
- [事件](#%e4%ba%8b%e4%bb%b6)
|
||||
- [Change log](#change-log)
|
||||
- [贡献](#%e8%b4%a1%e7%8c%ae)
|
||||
- [安全](#%e5%ae%89%e5%85%a8)
|
||||
- [信誉](#%e4%bf%a1%e8%aa%89)
|
||||
- [License](#license)
|
||||
|
||||
# 可用驱动列表
|
||||
|
||||
- [asanpardakht](https://asanpardakht.ir/) :heavy_check_mark:
|
||||
- [aqayepardakht](https://aqayepardakht.ir/) :heavy_check_mark:
|
||||
- [atipay](https://www.atipay.net/) :heavy_check_mark:
|
||||
- [azkiVam (Installment payment)](https://www.azkivam.com/) :heavy_check_mark:
|
||||
- [behpardakht (mellat)](http://www.behpardakht.com/) :heavy_check_mark:
|
||||
- [bitpay](https://bitpay.ir/) :heavy_check_mark:
|
||||
- [digipay](https://www.mydigipay.com/) :heavy_check_mark:
|
||||
- [etebarino (Installment payment)](https://etebarino.com/) :heavy_check_mark:
|
||||
- [fanavacard](https://www.fanava.com/) :heavy_check_mark:
|
||||
- [idpay](https://idpay.ir/) :heavy_check_mark:
|
||||
- [irankish](http://irankish.com/) :heavy_check_mark:
|
||||
- [local](#local-driver) :heavy_check_mark:
|
||||
- [jibit](https://jibit.ir/) :heavy_check_mark:
|
||||
- [nextpay](https://nextpay.ir/) :heavy_check_mark:
|
||||
- [omidpay](https://omidpayment.ir/) :heavy_check_mark:
|
||||
- [parsian](https://www.pec.ir/) :heavy_check_mark:
|
||||
- [pasargad](https://bpi.ir/) :heavy_check_mark:
|
||||
- [payir](https://pay.ir/) :heavy_check_mark:
|
||||
- [payfa](https://payfa.com/) :heavy_check_mark:
|
||||
- [paypal](http://www.paypal.com/) (在下一个版本中很快就支持了)
|
||||
- [payping](https://www.payping.ir/) :heavy_check_mark:
|
||||
- [paystar](http://paystar.ir/) :heavy_check_mark:
|
||||
- [poolam](https://poolam.ir/) :heavy_check_mark:
|
||||
- [rayanpay](https://rayanpay.com/) :heavy_check_mark:
|
||||
- [sadad (melli)](https://sadadpsp.ir/) :heavy_check_mark:
|
||||
- [saman](https://www.sep.ir) :heavy_check_mark:
|
||||
- [sep (saman electronic payment) Keshavarzi & Saderat](https://www.sep.ir) :heavy_check_mark:
|
||||
- [sepehr (saderat)](https://www.sepehrpay.com/) :heavy_check_mark:
|
||||
- [sepordeh](https://sepordeh.com/) :heavy_check_mark:
|
||||
- [sizpay](https://www.sizpay.ir/) :heavy_check_mark:
|
||||
- [toman](https://tomanpay.net/) :heavy_check_mark:
|
||||
- [vandar](https://vandar.io/) :heavy_check_mark:
|
||||
- [walleta (Installment payment)](https://walleta.ir/) :heavy_check_mark:
|
||||
- [yekpay](https://yekpay.com/) :heavy_check_mark:
|
||||
- [zarinpal](https://www.zarinpal.com/) :heavy_check_mark:
|
||||
- [zibal](https://www.zibal.ir/) :heavy_check_mark:
|
||||
- 其他正在进行中
|
||||
|
||||
**您可以通过`pull requests` 帮助我创建更多的网关**
|
||||
|
||||
- stripe
|
||||
- authorize
|
||||
- 2checkout
|
||||
- braintree
|
||||
- skrill
|
||||
- payU
|
||||
- amazon payments
|
||||
- wepay
|
||||
- payoneer
|
||||
- paysimple
|
||||
|
||||
> 如果找不到你需要的,您可以创建你自己的驱动,阅读`创建自定义驱动`部分,可以了解更多
|
||||
|
||||
## 安装
|
||||
|
||||
通过 Composer
|
||||
|
||||
``` bash
|
||||
composer require shetabit/payment
|
||||
```
|
||||
|
||||
## 配置
|
||||
|
||||
如果你使用`Laravel 5.5`或更高版本,你不需要手动设置 `provider` 和 `alias`,可以直接看b步骤
|
||||
|
||||
a. 在你的 `config/app.php` 文件中,添加如下两行
|
||||
|
||||
```php
|
||||
// In your providers array.
|
||||
'providers' => [
|
||||
...
|
||||
Shetabit\Payment\Provider\PaymentServiceProvider::class,
|
||||
],
|
||||
|
||||
// In your aliases array.
|
||||
'aliases' => [
|
||||
...
|
||||
'Payment' => Shetabit\Payment\Facade\Payment::class,
|
||||
],
|
||||
```
|
||||
|
||||
b. 然后运行 `php artisan vendor:publish` 来发布 `config/payment.php` 文件到你的项目中
|
||||
|
||||
在配置文件中,您可以将 `default`设置项设置为你希望的付款方式。但也可以在运行时更改驱动。
|
||||
|
||||
选择要在应用程序中使用的网关。然后将其设为默认驱动程序,这样就不必在任何地方都指定它。但是,您也可以在一个项目中使用多个网关。
|
||||
|
||||
|
||||
```php
|
||||
// Eg. if you want to use zarinpal.
|
||||
'default' => 'zarinpal',
|
||||
```
|
||||
|
||||
然后在驱动数组中填充该网关的凭据。
|
||||
|
||||
```php
|
||||
'drivers' => [
|
||||
'zarinpal' => [
|
||||
// Fill in the credentials here.
|
||||
'apiPurchaseUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentRequest.json',
|
||||
'apiPaymentUrl' => 'https://www.zarinpal.com/pg/StartPay/',
|
||||
'apiVerificationUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentVerification.json',
|
||||
'merchantId' => '',
|
||||
'callbackUrl' => 'http://yoursite.com/path/to',
|
||||
'description' => 'payment in '.config('app.name'),
|
||||
],
|
||||
...
|
||||
]
|
||||
```
|
||||
|
||||
## 如何使用
|
||||
|
||||
您的 `Invoice` 包含您的付款详细信息,因此我们首先将讨论 `Invoice` 类。
|
||||
|
||||
|
||||
#### 使用费用清单进行工作
|
||||
|
||||
在做任何事情之前,您需要使用 `Invoice` 类来创建费用清单。
|
||||
|
||||
像下面这样,在你的代码中使用费用清单:
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
...
|
||||
|
||||
// Create new invoice.
|
||||
$invoice = new Invoice;
|
||||
|
||||
// 设置清单金额.
|
||||
$invoice->amount(1000);
|
||||
|
||||
// 给清单添加详情: 这里展示了四种语法.
|
||||
// 1
|
||||
$invoice->detail(['detailName' => 'your detail goes here']);
|
||||
// 2
|
||||
$invoice->detail('detailName','your detail goes here');
|
||||
// 3
|
||||
$invoice->detail(['name1' => 'detail1','name2' => 'detail2']);
|
||||
// 4
|
||||
$invoice->detail('detailName1','your detail1 goes here')
|
||||
->detail('detailName2','your detail2 goes here');
|
||||
|
||||
```
|
||||
可用方法:
|
||||
|
||||
- `uuid`: 设置一个清单的唯一id
|
||||
- `getUuid`: 获取清单的当前唯一id
|
||||
- `detail`: 给清单添加自定义信息
|
||||
- `getDetails`: 获取所有的详细信息
|
||||
- `amount`: 设置一个清单金额
|
||||
- `getAmount`: 获取清单金额
|
||||
- `transactionId`: 设置支付交易单号
|
||||
- `getTransactionId`: 获取支付交易单号
|
||||
- `via`: 设置我们用来支付清单的驱动
|
||||
- `getDriver`: 获取驱动
|
||||
|
||||
#### 获取支付清单
|
||||
|
||||
为了支付清单,我们需要付款交易ID:
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
...
|
||||
|
||||
// Create new invoice.
|
||||
$invoice = (new Invoice)->amount(1000);
|
||||
|
||||
// Purchase the given invoice.
|
||||
Payment::purchase($invoice,function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
});
|
||||
|
||||
// Purchase method accepts a callback function.
|
||||
Payment::purchase($invoice, function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
});
|
||||
|
||||
// You can specify callbackUrl
|
||||
Payment::callbackUrl('http://yoursite.com/verify')->purchase(
|
||||
$invoice,
|
||||
function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
#### 支付
|
||||
|
||||
在获取支付单后,我们可以跳转到第三方支付机构的页面
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
...
|
||||
|
||||
// Create new invoice.
|
||||
$invoice = (new Invoice)->amount(1000);
|
||||
// Purchase and pay the given invoice.
|
||||
// You should use return statement to redirect user to the bank page.
|
||||
return Payment::purchase($invoice, function($driver, $transactionId) {
|
||||
// Store transactionId in database as we need it to verify payment in the future.
|
||||
})->pay()->render();
|
||||
|
||||
// Do all things together in a single line.
|
||||
return Payment::purchase(
|
||||
(new Invoice)->amount(1000),
|
||||
function($driver, $transactionId) {
|
||||
// 把交易ID保存到数据库.
|
||||
// 在接下来的付款中,我们需要验证交易ID
|
||||
}
|
||||
)->pay()->render();
|
||||
|
||||
// Retrieve json format of Redirection (in this case you can handle redirection to bank gateway)
|
||||
return Payment::purchase(
|
||||
(new Invoice)->amount(1000),
|
||||
function($driver, $transactionId) {
|
||||
// 把交易ID保存到数据库.
|
||||
// 在接下来的付款中,我们需要验证交易ID
|
||||
}
|
||||
)->pay()->toJson();
|
||||
```
|
||||
|
||||
#### 验证付款
|
||||
|
||||
当用户完成付款后,支付机构会将其重定向到您的网站,然后您需要**验证您的付款**,以确保**清单**已**支付**。
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
use Shetabit\Multipay\Exceptions\InvalidPaymentException;
|
||||
...
|
||||
|
||||
// 您需要验证支付机构的回传数据,以确保付款成功
|
||||
// 我们需要使用交易ID来验证
|
||||
// 使用交易金额来验证,也是一个很好的方法
|
||||
try {
|
||||
$receipt = Payment::amount(1000)->transactionId($transaction_id)->verify();
|
||||
|
||||
// You can show payment referenceId to the user.
|
||||
echo $receipt->getReferenceId();
|
||||
|
||||
...
|
||||
} catch (InvalidPaymentException $exception) {
|
||||
/**
|
||||
如果未验证付款,则会引发异常。
|
||||
|
||||
我们可以抓住异常处理无效付款。
|
||||
|
||||
getMessage方法,返回可在用户界面中使用的适当消息。
|
||||
**/
|
||||
echo $exception->getMessage();
|
||||
}
|
||||
```
|
||||
|
||||
#### 有用的方法
|
||||
|
||||
- ###### `callbackUrl`: 使用它可以在运行时改变回调地址.
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
...
|
||||
|
||||
// Create new invoice.
|
||||
$invoice = (new Invoice)->amount(1000);
|
||||
|
||||
// Purchase the given invoice.
|
||||
Payment::callbackUrl($url)->purchase(
|
||||
$invoice,
|
||||
function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
- ###### `amount`: 你可以设置一个清单的金额
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
...
|
||||
|
||||
// Purchase (we set invoice to null).
|
||||
Payment::callbackUrl($url)->amount(1000)->purchase(
|
||||
null,
|
||||
function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
- ###### `via`: 在运行中更改支付方式
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
...
|
||||
|
||||
// Create new invoice.
|
||||
$invoice = (new Invoice)->amount(1000);
|
||||
|
||||
// Purchase the given invoice.
|
||||
Payment::via('driverName')->purchase(
|
||||
$invoice,
|
||||
function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
- ###### `config`: 在运行中更改驱动的配置信息
|
||||
|
||||
```php
|
||||
// At the top of the file.
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Payment\Facade\Payment;
|
||||
...
|
||||
|
||||
// Create new invoice.
|
||||
$invoice = (new Invoice)->amount(1000);
|
||||
|
||||
// Purchase the given invoice with custom driver configs.
|
||||
Payment::config('mechandId', 'your mechand id')->purchase(
|
||||
$invoice,
|
||||
function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
}
|
||||
);
|
||||
|
||||
// Also we can change multiple configs at the same time.
|
||||
Payment::config(['key1' => 'value1', 'key2' => 'value2'])->purchase(
|
||||
$invoice,
|
||||
function($driver, $transactionId) {
|
||||
// We can store $transactionId in database.
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
#### 创建自定义驱动:
|
||||
|
||||
首先必须在`drivers`数组中添加驱动程序的名称,还可以指定所需的任何配置参数。
|
||||
|
||||
```php
|
||||
'drivers' => [
|
||||
'zarinpal' => [...],
|
||||
'my_driver' => [
|
||||
... // Your Config Params here.
|
||||
]
|
||||
]
|
||||
```
|
||||
|
||||
现在您必须创建一个将用于支付清单的驱动程序映射类。
|
||||
在你的驱动中,你必须继承 `Shetabit\Payment\Abstracts\Driver`.这个类
|
||||
|
||||
例如,你创建了这样一个类: `App\Packages\PaymentDriver\MyDriver`。
|
||||
|
||||
```php
|
||||
namespace App\Packages\PaymentDriver;
|
||||
|
||||
use Shetabit\Multipay\Abstracts\Driver;
|
||||
use Shetabit\Multipay\Exceptions\InvalidPaymentException;
|
||||
use Shetabit\Multipay\{Contracts\ReceiptInterface, Invoice, Receipt};
|
||||
|
||||
class MyDriver extends Driver
|
||||
{
|
||||
protected $invoice; // Invoice.
|
||||
|
||||
protected $settings; // Driver settings.
|
||||
|
||||
public function __construct(Invoice $invoice, $settings)
|
||||
{
|
||||
$this->invoice($invoice); // Set the invoice.
|
||||
$this->settings = (object) $settings; // Set settings.
|
||||
}
|
||||
|
||||
// Purchase the invoice, save its transactionId and finaly return it.
|
||||
public function purchase() {
|
||||
// Request for a payment transaction id.
|
||||
...
|
||||
|
||||
$this->invoice->transactionId($transId);
|
||||
|
||||
return $transId;
|
||||
}
|
||||
|
||||
// Redirect into bank using transactionId, to complete the payment.
|
||||
public function pay() {
|
||||
// It is better to set bankApiUrl in config/payment.php and retrieve it here:
|
||||
$bankUrl = $this->settings->bankApiUrl; // bankApiUrl is the config name.
|
||||
|
||||
// Prepare payment url.
|
||||
$payUrl = $bankUrl.$this->invoice->getTransactionId();
|
||||
|
||||
// Redirect to the bank.
|
||||
return redirect()->to($payUrl);
|
||||
}
|
||||
|
||||
// Verify the payment (we must verify to ensure that user has paid the invoice).
|
||||
public function verify(): ReceiptInterface {
|
||||
$verifyPayment = $this->settings->verifyApiUrl;
|
||||
|
||||
$verifyUrl = $verifyPayment.$this->invoice->getTransactionId();
|
||||
|
||||
...
|
||||
|
||||
/**
|
||||
Then we send a request to $verifyUrl and if payment is not valid we throw an InvalidPaymentException with a suitable message.
|
||||
**/
|
||||
throw new InvalidPaymentException('a suitable message');
|
||||
|
||||
/**
|
||||
We create a receipt for this payment if everything goes normally.
|
||||
**/
|
||||
return new Receipt('driverName', 'payment_receipt_number');
|
||||
}
|
||||
}
|
||||
```
|
||||
创建该类后,必须在 `payment.php` 配置文件的 `map` 部分中指定它。
|
||||
|
||||
```php
|
||||
'map' => [
|
||||
...
|
||||
'my_driver' => App\Packages\PaymentDriver\MyDriver::class,
|
||||
]
|
||||
```
|
||||
|
||||
**Note:-** 必须确保 `map` 数组的键与 `drivers` 数组的键相同。
|
||||
|
||||
#### 事件
|
||||
|
||||
你可以监听两个事件
|
||||
|
||||
- **InvoicePurchasedEvent**: 在获取清单后执行
|
||||
- **InvoiceVerifiedEvent**: 在验证交易成功后执行
|
||||
|
||||
## Change log
|
||||
|
||||
请查看 [CHANGELOG](CHANGELOG.md) 来获取更多关于版本更新的信息
|
||||
|
||||
## 贡献
|
||||
|
||||
请查看 [CONTRIBUTING](CONTRIBUTING.md) 和 [CONDUCT](CONDUCT.md) 获取更多详细信息
|
||||
|
||||
## 安全
|
||||
|
||||
如果您发现任何与安全相关的问题,请发送电子邮件至`khanzadimahdi@gmail.com`,而不要使用issue。
|
||||
|
||||
## 信誉
|
||||
|
||||
- [Mahdi khanzadi][link-author]
|
||||
- [All Contributors][link-contributors]
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
|
||||
|
||||
[ico-version]: https://img.shields.io/packagist/v/shetabit/payment.svg?style=flat-square
|
||||
[ico-download]: https://img.shields.io/packagist/dt/shetabit/payment.svg?color=%23F18&style=flat-square
|
||||
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
|
||||
[ico-code-quality]: https://img.shields.io/scrutinizer/g/shetabit/payment.svg?label=Code%20Quality&style=flat-square
|
||||
|
||||
[link-fa]: README-FA.md
|
||||
[link-en]: README.md
|
||||
[link-zh]: README-ZH.md
|
||||
[link-packagist]: https://packagist.org/packages/shetabit/payment
|
||||
[link-code-quality]: https://scrutinizer-ci.com/g/shetabit/payment
|
||||
[link-author]: https://github.com/khanzadimahdi
|
||||
[link-contributors]: ../../contributors
|
||||
16
phpunit.xml
Normal file
16
phpunit.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage>
|
||||
<include>
|
||||
<directory>./src/</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Test Suite">
|
||||
<directory suffix="Test.php">./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<env name="APP_ENV" value="testing"/>
|
||||
</php>
|
||||
</phpunit>
|
||||
BIN
resources/images/payment.png
Normal file
BIN
resources/images/payment.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
102
resources/views/redirectForm.blade.php
Normal file
102
resources/views/redirectForm.blade.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Forwarding to secure payment provider</title>
|
||||
<style>
|
||||
.text-center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.mt-2 {
|
||||
margin-top: 2em;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
margin: 100px auto 0;
|
||||
width: 70px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.spinner > div {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
background-color: #333;
|
||||
border-radius: 100%;
|
||||
display: inline-block;
|
||||
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
|
||||
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
|
||||
}
|
||||
|
||||
.spinner .bounce1 {
|
||||
-webkit-animation-delay: -0.32s;
|
||||
animation-delay: -0.32s;
|
||||
}
|
||||
|
||||
.spinner .bounce2 {
|
||||
-webkit-animation-delay: -0.16s;
|
||||
animation-delay: -0.16s;
|
||||
}
|
||||
|
||||
@-webkit-keyframes sk-bouncedelay {
|
||||
0%, 80%, 100% { -webkit-transform: scale(0) }
|
||||
40% { -webkit-transform: scale(1.0) }
|
||||
}
|
||||
|
||||
@keyframes sk-bouncedelay {
|
||||
0%, 80%, 100% {
|
||||
-webkit-transform: scale(0);
|
||||
transform: scale(0);
|
||||
} 40% {
|
||||
-webkit-transform: scale(1.0);
|
||||
transform: scale(1.0);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="submitForm();">
|
||||
<div class="spinner">
|
||||
<div class="bounce1"></div>
|
||||
<div class="bounce2"></div>
|
||||
<div class="bounce3"></div>
|
||||
</div>
|
||||
<form class="text-center mt-2" method="{{ $method }}" action="{{ $action }}">
|
||||
<p>Forwarding to secure payment provider.</p>
|
||||
<p>
|
||||
If you are not automatically redirected to the payment website with in
|
||||
<span id="countdown">10</span>
|
||||
seconds...
|
||||
</p>
|
||||
|
||||
@foreach($inputs as $name => $value)
|
||||
<input type="hidden" name="{{ $name }}" value="{{ $value }}">
|
||||
@endforeach
|
||||
|
||||
<button type="submit">Click here</button>
|
||||
</form>
|
||||
<script>
|
||||
// Total seconds to wait
|
||||
var seconds = 10;
|
||||
|
||||
function submitForm() {
|
||||
document.forms[0].submit();
|
||||
}
|
||||
|
||||
function countdown() {
|
||||
seconds = seconds - 1;
|
||||
if (seconds <= 0) {
|
||||
// submit the form
|
||||
submitForm();
|
||||
} else {
|
||||
// Update remaining seconds
|
||||
document.getElementById("countdown").innerHTML = seconds;
|
||||
// Count down using javascript
|
||||
window.setTimeout("countdown()", 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// Run countdown function
|
||||
countdown();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
29
src/Events/InvoicePurchasedEvent.php
Normal file
29
src/Events/InvoicePurchasedEvent.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Shetabit\Payment\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Shetabit\Multipay\Contracts\DriverInterface;
|
||||
use Shetabit\Multipay\Invoice;
|
||||
|
||||
class InvoicePurchasedEvent
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $driver;
|
||||
public $invoice;
|
||||
|
||||
/**
|
||||
* InvoicePurchasedEvent constructor.
|
||||
*
|
||||
* @param DriverInterface $driver
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(DriverInterface $driver, Invoice $invoice)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
}
|
||||
33
src/Events/InvoiceVerifiedEvent.php
Normal file
33
src/Events/InvoiceVerifiedEvent.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Shetabit\Payment\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Shetabit\Multipay\Contracts\DriverInterface;
|
||||
use Shetabit\Multipay\Contracts\ReceiptInterface;
|
||||
use Shetabit\Multipay\Invoice;
|
||||
|
||||
class InvoiceVerifiedEvent
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $receipt;
|
||||
public $driver;
|
||||
public $invoice;
|
||||
|
||||
/**
|
||||
* InvoiceVerifiedEvent constructor.
|
||||
*
|
||||
* @param ReceiptInterface $receipt
|
||||
* @param DriverInterface $driver
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(ReceiptInterface $receipt, DriverInterface $driver, Invoice $invoice)
|
||||
{
|
||||
$this->receipt = $receipt;
|
||||
$this->driver = $driver;
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
}
|
||||
38
src/Facade/Payment.php
Normal file
38
src/Facade/Payment.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Shetabit\Payment\Facade;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Multipay\Contracts\ReceiptInterface;
|
||||
use Shetabit\Multipay\Payment as MultipayPayment;
|
||||
|
||||
/**
|
||||
* Class Payment
|
||||
*
|
||||
* @method static MultipayPayment config($key, $value = null)
|
||||
* @method static MultipayPayment callbackUrl($url = null)
|
||||
* @method static MultipayPayment resetCallbackUrl()
|
||||
* @method static MultipayPayment amount($amount)
|
||||
* @method static MultipayPayment detail($key, $value = null)
|
||||
* @method static MultipayPayment transactionId($id)
|
||||
* @method static MultipayPayment via($driver)
|
||||
* @method static MultipayPayment purchase(Invoice $invoice = null, $finalizeCallback = null)
|
||||
* @method static mixed pay($initializeCallback = null)
|
||||
* @method static ReceiptInterface verify($finalizeCallback = null)
|
||||
*
|
||||
* @package Shetabit\Payment\Facade
|
||||
* @see \Shetabit\Multipay\Payment
|
||||
*/
|
||||
class Payment extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getFacadeAccessor()
|
||||
{
|
||||
return 'shetabit-payment';
|
||||
}
|
||||
}
|
||||
130
src/Provider/PaymentServiceProvider.php
Normal file
130
src/Provider/PaymentServiceProvider.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace Shetabit\Payment\Provider;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\View\View;
|
||||
use Shetabit\Multipay\Payment;
|
||||
use Shetabit\Multipay\Request;
|
||||
use Shetabit\Payment\Events\InvoicePurchasedEvent;
|
||||
use Shetabit\Payment\Events\InvoiceVerifiedEvent;
|
||||
|
||||
class PaymentServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Perform post-registration booting of services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'shetabitPayment');
|
||||
|
||||
/**
|
||||
* Configurations that needs to be done by user.
|
||||
*/
|
||||
$this->publishes(
|
||||
[
|
||||
Payment::getDefaultConfigPath() => config_path('payment.php'),
|
||||
],
|
||||
'payment-config'
|
||||
);
|
||||
|
||||
/**
|
||||
* Views that needs to be modified by user.
|
||||
*/
|
||||
$this->publishes(
|
||||
[
|
||||
__DIR__ . '/../../resources/views' => resource_path('views/vendor/shetabitPayment'),
|
||||
],
|
||||
'payment-views'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any package services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Merge default config with user's config
|
||||
$this->mergeConfigFrom(Payment::getDefaultConfigPath(), 'payment');
|
||||
|
||||
Request::overwrite('input', function ($key) {
|
||||
return \request($key);
|
||||
});
|
||||
|
||||
/**
|
||||
* Bind to service container.
|
||||
*/
|
||||
$this->app->bind('shetabit-payment', function () {
|
||||
$config = config('payment') ?? [];
|
||||
|
||||
return new Payment($config);
|
||||
});
|
||||
|
||||
$this->registerEvents();
|
||||
|
||||
// use blade to render redirection form
|
||||
Payment::setRedirectionFormViewRenderer(function ($view, $action, $inputs, $method) {
|
||||
if ($this->existCustomRedirectFormView()) {
|
||||
return $this->loadNormalRedirectForm($action, $inputs, $method);
|
||||
}
|
||||
return Blade::render(
|
||||
str_replace('</form>', '@csrf</form>', file_get_contents($view)),
|
||||
[
|
||||
'action' => $action,
|
||||
'inputs' => $inputs,
|
||||
'method' => $method,
|
||||
]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Laravel events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerEvents()
|
||||
{
|
||||
Payment::addPurchaseListener(function ($driver, $invoice) {
|
||||
event(new InvoicePurchasedEvent($driver, $invoice));
|
||||
});
|
||||
|
||||
Payment::addVerifyListener(function ($reciept, $driver, $invoice) {
|
||||
event(new InvoiceVerifiedEvent($reciept, $driver, $invoice));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the user has customized the view file called `redirectForm.blade.php` or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function existCustomRedirectFormView()
|
||||
{
|
||||
return file_exists(resource_path('views/vendor/shetabitPayment') . '/redirectForm.blade.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $action
|
||||
* @param $inputs
|
||||
* @param $method
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
private function loadNormalRedirectForm($action, $inputs, $method)
|
||||
{
|
||||
return view('shetabitPayment::redirectForm')->with(
|
||||
[
|
||||
'action' => $action,
|
||||
'inputs' => $inputs,
|
||||
'method' => $method,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
30
tests/TestCase.php
Normal file
30
tests/TestCase.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Shetabit\Payment\Tests;
|
||||
|
||||
use Orchestra\Testbench\TestCase as BaseTestCase;
|
||||
use Shetabit\Multipay\Tests\Drivers\BarDriver;
|
||||
|
||||
class TestCase extends BaseTestCase
|
||||
{
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return ['Shetabit\Payment\Provider\PaymentServiceProvider'];
|
||||
}
|
||||
|
||||
protected function getPackageAliases($app)
|
||||
{
|
||||
return [
|
||||
'Payment' => 'Shetabit\Payment\Facade\Payment',
|
||||
];
|
||||
}
|
||||
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
$settings = require __DIR__.'/../src/Config/payment.php';
|
||||
$settings['drivers']['bar'] = ['key' => 'foo'];
|
||||
$settings['map']['bar'] = BarDriver::class;
|
||||
|
||||
$app['config']->set('payment', $settings);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user