-
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 b896173
Showing
19 changed files
with
974 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,3 @@ | ||
.idea | ||
vendor | ||
composer.lock |
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Elbek Khamdullaev | ||
|
||
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,61 @@ | ||
# Usage | ||
|
||
## Installation | ||
|
||
```bash | ||
composer require khamdullaevuz/laravel-payme | ||
``` | ||
|
||
## Configuration | ||
|
||
```bash | ||
php artisan vendor:publish --tag=payme-config | ||
``` | ||
|
||
## Add your configs to `config/payme.php` | ||
```php | ||
|
||
return [ | ||
'min_amount' => env('PAYME_MIN_AMOUNT', 1_000_00), | ||
'max_amount' => env('PAYME_MAX_AMOUNT', 100_000_000_00), | ||
'identity' => env('PAYME_IDENTITY', 'id'), | ||
'login' => env('PAYME_LOGIN', 'TestUser'), | ||
'key' => env('PAYME_KEY', 'TestKey'), | ||
'merchant_id' => env('PAYME_MERCHANT_ID', '123456789'), | ||
'allowed_ips' => [ | ||
'185.178.51.131', '185.178.51.132', '195.158.31.134', '195.158.31.10', '195.158.28.124', '195.158.5.82', '127.0.0.1' | ||
] | ||
]; | ||
``` | ||
|
||
## Add service provider to `config/app.php` | ||
|
||
```php | ||
'providers' => [ | ||
// Other Service Providers | ||
Khamdullaevuz\Payme\PaymeServiceProvider::class, | ||
], | ||
``` | ||
|
||
## Add facade to globally aliases in `config/app.php` | ||
|
||
```php | ||
'aliases' => [ | ||
// Other Aliases | ||
'Payme' => Khamdullaevuz\Payme\Facades\Payme::class, | ||
], | ||
``` | ||
|
||
## Usage in route | ||
|
||
```php | ||
use Khamdullaevuz\Payme\Facades\Payme; | ||
use Khamdullaevuz\Payme\Http\Middleware\PaymeCheck; | ||
use Illuminate\Http\Request; | ||
|
||
// Other Routes | ||
|
||
Route::any('/payme', function (Request $request) { | ||
return Payme::handle($request); | ||
})->middleware(PaymeCheck::class); | ||
``` |
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,30 @@ | ||
{ | ||
"name": "khamdullaevuz/laravel-payme", | ||
"description": "Laravel Payme", | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "Elbek Khamdullaev", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.1", | ||
"illuminate/support": "^10.0|^9.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Khamdullaevuz\\Payme\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Khamdullaevuz\\Payme\\PaymeServiceProvider" | ||
], | ||
"aliases": { | ||
"Payme": "Khamdullaevuz\\Payme\\Facades\\Payme" | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
database/migrations/2023_07_04_092809_create_payme_transactions_table.php
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,37 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('payme_transactions', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('transaction')->nullable(); | ||
$table->string('code')->nullable(); | ||
$table->string('state')->nullable(); | ||
$table->string('owner_id')->nullable(); | ||
$table->bigInteger('amount')->nullable(); | ||
$table->string('reason')->nullable(); | ||
$table->string('payme_time')->nullable(); | ||
$table->string('cancel_time')->nullable(); | ||
$table->string('create_time')->nullable(); | ||
$table->string('perform_time')->nullable(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('payme_transactions'); | ||
} | ||
}; |
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,14 @@ | ||
<?php | ||
|
||
namespace Khamdullaevuz\Payme\Enums; | ||
|
||
enum PaymeMethods: string | ||
{ | ||
case CheckPerformTransaction = 'CheckPerformTransaction'; | ||
case CreateTransaction = 'CreateTransaction'; | ||
case PerformTransaction = 'PerformTransaction'; | ||
case CancelTransaction = 'CancelTransaction'; | ||
case CheckTransaction = 'CheckTransaction'; | ||
case GetStatement = 'GetStatement'; | ||
case SetFiscalData = 'SetFiscalData'; | ||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace Khamdullaevuz\Payme\Enums; | ||
|
||
enum PaymeState: int | ||
{ | ||
case Pending = 1; | ||
case Done = 2; | ||
case Cancelled = -1; | ||
case Cancelled_After_Success = -2; | ||
} |
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,171 @@ | ||
<?php | ||
|
||
namespace Khamdullaevuz\Payme\Exceptions; | ||
|
||
use Exception; | ||
|
||
class PaymeException extends Exception | ||
{ | ||
public array $error; | ||
|
||
/** | ||
* Системная (внутренняя ошибка). | ||
*/ | ||
const SYSTEM_ERROR = -32400; | ||
|
||
|
||
/** | ||
* Auth error | ||
*/ | ||
const AUTH_ERROR = -32504; | ||
|
||
|
||
/** | ||
* Неверная сумма. | ||
*/ | ||
const WRONG_AMOUNT = -31001; | ||
|
||
|
||
/** | ||
* Ошибки связанные с неверным пользовательским вводом "account". | ||
* Например: введенный логин не найден | ||
*/ | ||
const USER_NOT_FOUND = -31050; | ||
|
||
|
||
/** | ||
* Передан неправильный JSON-RPC объект. | ||
*/ | ||
const JSON_RPC_ERROR = -32600; | ||
|
||
|
||
/** | ||
* Транзакция не найдена. | ||
*/ | ||
const TRANS_NOT_FOUND = -31003; | ||
|
||
|
||
/** | ||
* Запрашиваемый метод не найден. | ||
* Поле data содержит запрашиваемый метод. | ||
*/ | ||
const METHOD_NOT_FOUND = -32601; | ||
|
||
|
||
/** | ||
* Ошибка Парсинга JSON. | ||
* Запрос является не валидным JSON объектом | ||
*/ | ||
const JSON_PARSING_ERROR = -32700; | ||
|
||
|
||
/** | ||
* Невозможно выполнить данную операцию. | ||
*/ | ||
const CANT_PERFORM_TRANS = -31008; | ||
|
||
|
||
/** | ||
* Невозможно отменить транзакцию. | ||
* Товар или услуга предоставлена Потребителю в полном объеме. | ||
*/ | ||
const CANT_CANCEL_TRANSACTION = -31007; | ||
|
||
|
||
/** | ||
* В ожидании оплаты | ||
*/ | ||
const PENDING_PAYMENT = -31099; | ||
|
||
const INVALID_HTTP_METHOD = -32300; | ||
|
||
public function __construct($error, $customMessage = null) | ||
{ | ||
$this->error = [ | ||
'code' => $error, | ||
'message' => $customMessage ?? $this->getErrorMessage($error) | ||
]; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
public function getErrorMessage($code): array | ||
{ | ||
$messages = [ | ||
|
||
self::INVALID_HTTP_METHOD => [ | ||
"uz" => "Xato so'rov", | ||
"ru" => "Ошибка запроса", | ||
"en" => "Error request" | ||
], | ||
|
||
self::SYSTEM_ERROR => [ | ||
"uz" => "Ichki sestema hatoligi", | ||
"ru" => "Внутренняя ошибка сервера", | ||
"en" => "Internal server error" | ||
], | ||
|
||
self::WRONG_AMOUNT => [ | ||
"uz" => "Notug'ri summa.", | ||
"ru" => "Неверная сумма.", | ||
"en" => "Wrong amount.", | ||
], | ||
|
||
self::USER_NOT_FOUND => [ | ||
"uz" => "Foydalanuvchi topilmadi", | ||
"ru" => "Пользователь не найден", | ||
"en" => "User not found", | ||
], | ||
|
||
self::JSON_RPC_ERROR => [ | ||
"uz" => "Notog`ri JSON-RPC obyekt yuborilgan.", | ||
"ru" => "Передан неправильный JSON-RPC объект.", | ||
"en" => "Handed the wrong JSON-RPC object." | ||
], | ||
|
||
self::TRANS_NOT_FOUND => [ | ||
"uz" => "Transaction not found", | ||
"ru" => "Трансакция не найдена", | ||
"en" => "Transaksiya topilmadi" | ||
], | ||
|
||
self::METHOD_NOT_FOUND => [ | ||
"uz" => "Metod topilmadi", | ||
"ru" => "Запрашиваемый метод не найден.", | ||
"en" => "Method not found" | ||
], | ||
|
||
self::JSON_PARSING_ERROR => [ | ||
"uz" => "Json pars qilganda hatolik yuz berdi", | ||
"ru" => "Ошибка при парсинге JSON", | ||
"en" => "Error while parsing json" | ||
], | ||
|
||
self::CANT_PERFORM_TRANS => [ | ||
"uz" => "Bu operatsiyani bajarish mumkin emas", | ||
"ru" => "Невозможно выполнить данную операцию.", | ||
"en" => "Can't perform transaction", | ||
], | ||
|
||
self::CANT_CANCEL_TRANSACTION => [ | ||
"uz" => "Transaksiyani qayyarib bolmaydi", | ||
"ru" => "Невозможно отменить транзакцию", | ||
"en" => "You can not cancel the transaction" | ||
], | ||
|
||
self::PENDING_PAYMENT => [ | ||
"uz" => "To'lov kutilmoqda", | ||
"ru" => "В ожидании оплаты", | ||
"en" => "Pending payment" | ||
], | ||
|
||
self::AUTH_ERROR => [ | ||
"uz" => "Avtorizatsiyadan otishda xatolik", | ||
"ru" => "Ошибка аутентификации", | ||
"en" => "Auth error" | ||
] | ||
]; | ||
|
||
return $messages[$code] ?? []; | ||
} | ||
} |
Oops, something went wrong.