Skip to content

Commit

Permalink
Merge branch 'master' into fix_get_statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Sodiqmirzo authored Jan 30, 2025
2 parents 42ee3fd + 80970ec commit e32480b
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 44 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
- [Paynet](http://paynet.uz) - Merchant
- [Stripe](https://stripe.com/) - Merchant(Subscribe)

*По умолчанию для оплаты установлен "накопительный режим". Чтобы производить оплату в "Одноразовом режиме", вам необходимо изменить параметр в config/payuz.php ``'multi_transaction' => false``*

**Planned**
------
- Upay
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "goodoneuz/pay-uz",
"description": "Payment: Click, Payme, Uzcard, Visa",
"keywords": [
"goodoneuz",
"blaze",
"pay-uz"
],
"homepage": "https://github.com/goodoneuz/pay-uz",
"homepage": "https://github.com/shaxzodbek-uzb/pay-uz",
"license": "MIT",
"type": "library",
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion publishable/Payments/key_model.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
return \App\User::find($key);
return \App\Models\User::find($key);

42 changes: 29 additions & 13 deletions src/Http/Classes/Payme/Payme.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,27 @@ private function CheckPerformTransaction()
'Invalid amount for this object.'
);
}
$active_transactions = $this->getModelTransactions($model, true);

if ((count($active_transactions) > 0) && !config('payuz')['multi_transaction']) {
$active_transactions = $this->getActiveTransactions($model);
if ((count($active_transactions) > 0)) {
$this->response->error(
Response::ERROR_INVALID_TRANSACTION,
'There is other active/completed transaction for this object.'
'There is other active transaction for this object.'
);
}

$completed_transactions = $this->getComplatedTransactions($model);
if ((count($completed_transactions) > 0) && !config('payuz')['multi_transaction']) {
$this->response->error(
Response::ERROR_INVALID_TRANSACTION,
'There is other completed transaction for this object.'
);
}

PaymentService::payListener($model, null, 'before-pay');

$response = [
'allow' => false,
'allow' => true,
];

$response = PaymentService::beforeResponse("Payme@CheckPerformTransaction", $this->request->params, $response);
Expand All @@ -124,15 +133,22 @@ public function validateParams(array $params)
return true;
}

public function getModelTransactions($model, $active = false)
public function getActiveTransactions($model)
{
$transactions = Transaction::where('payment_system', PaymentSystem::PAYME)
return Transaction::where('payment_system', PaymentSystem::PAYME)
->where('transactionable_type', get_class($model))
->where('transactionable_id', $model->id);
if ($active) {
$transactions = $transactions->where('state', Transaction::STATE_CREATED);
}
return $transactions->get();
->where('transactionable_id', $model->id)
->where('state', Transaction::STATE_CREATED)
->get();
}

public function getComplatedTransactions($model)
{
return Transaction::where('payment_system', PaymentSystem::PAYME)
->where('transactionable_type', get_class($model))
->where('transactionable_id', $model->id)
->where('state', Transaction::STATE_COMPLETED)
->get();
}

private function CheckTransaction()
Expand Down Expand Up @@ -211,7 +227,7 @@ private function CreateTransaction()
'create_time' => $create_time,
'perform_time' => null,
'cancel_time' => null,
'system_time_datetime' => DataFormat::timestamp2datetime($this->request->params['time'])
'system_time_datetime' => $this->request->params['time']
);

$transaction = Transaction::create([
Expand Down Expand Up @@ -463,7 +479,7 @@ public function getRedirectParams($model, $amount, $currency, $url)
$params = [
'merchant' => $this->config['merchant_id'],
'amount' => $amount * 100,
'account[key]' => PaymentService::convertModelToKey($model),
'account[' . $this->config['key'] . ']' => PaymentService::convertModelToKey($model),
'lang' => 'ru',
'currency' => $currency,
'callback' => $url,
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Classes/Paynet/Paynet.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function run()
$body = Response::makeResponse($this->GetInformation());
break;
default:
$this->response->response($this->request, 'Method not found.', PaynetException::ERROR_METHOD_NOT_FOUND);
$this->response->response($this->request, 'Method not found.', Response::ERROR_METHOD_NOT_FOUND);
}
$this->response->response($this->request, $body, Response::SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Goodoneuz\PayUz\Http\Controllers;

use Illuminate\Http\Request;
use Goodoneuz\PayUz\Models\Project;
use Goodoneuz\PayUz\Models\PaymentProject;
use App\Http\Controllers\Controller;

class ProjectController extends Controller
class PaymentProjectController extends Controller
{

/**
Expand All @@ -16,7 +16,7 @@ class ProjectController extends Controller
*/
public function index()
{
$projects = Project::latest()->get();
$projects = PaymentProject::latest()->get();
return view('pay-uz::projects.index',compact('projects'));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Project.php → src/Models/PaymentProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Project extends Model
class PaymentProject extends Model
{
use SoftDeletes;

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function cancel($reason)

public function isExpired()
{
return $this->state == self::STATE_CREATED && DataFormat::datetime2timestamp($this->updated_time) - time() > self::TIMEOUT;
return ($this->state == self::STATE_CREATED) && ($this->updated_at < now()->subHours(12));
}

public function transactionable(): MorphTo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProjectsTable extends Migration
class CreatePaymentProjectsTable extends Migration
{
/**
* Run the migrations.
Expand All @@ -13,7 +13,7 @@ class CreateProjectsTable extends Migration
*/
public function up()
{
Schema::create('projects', function (Blueprint $table) {
Schema::create('payment_projects', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('status');
Expand All @@ -30,6 +30,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('projects');
Schema::dropIfExists('payment_projects');
}
}
19 changes: 2 additions & 17 deletions src/resources/views/components/main_nav.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@
<a class="nav-link" href="{{ route('payment.dashboard') }}">
<i class="fa fa-fw fa-dashboard"></i>
<span class="nav-link-text">
Asosiy bo'lim</span>
</a>
</li>
<li class="nav-item @if($current_route == 'payment.projects.index') active @endif" data-toggle="tooltip" data-placement="right" title="Payment Systems">
<a class="nav-link" href="{{ route('payment.projects.index') }}">
<i class="fa fa-fw fa-list"></i>
<span class="nav-link-text">
Loyihalar</span>
Dashboard</span>
</a>
</li>
<li class="nav-item @if($current_route == 'payment.payment_systems.index') active @endif" data-toggle="tooltip" data-placement="right" title="Payment Systems">
<a class="nav-link" href="{{ route('payment.payment_systems.index') }}">
<i class="fa fa-fw fa-list"></i>
<span class="nav-link-text">
To'lov tizimlari</span>
Payment systems</span>
</a>
</li>
<li class="nav-item @if($current_route == 'payment.transactions.index') active @endif" data-toggle="tooltip" data-placement="right" title="Transactions">
Expand All @@ -34,14 +27,6 @@
Transactions</span>
</a>
</li>
<li class="nav-item @if($current_route == 'payment.settings.index') active @endif" data-toggle="tooltip" data-placement="right" title="Settings">
<a class="nav-link" href="{{ route('payment.settings') }}">
<i class="fa fa-fw fa-cog"></i>
<span class="nav-link-text">
Settings
</span>
</a>
</li>
<li class="nav-item @if($current_route == 'payment.editors.index') active @endif" data-toggle="tooltip" data-placement="right" title="Editors">
<a class="nav-link" href="{{ route('payment.editors') }}">
<i class="fa fa-fw fa-edit"></i>
Expand Down
2 changes: 1 addition & 1 deletion src/resources/views/projects/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<td class="text-center">
<a href="#" data-project-id="{{ $project->id }}" class="deleteBtn"><span class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="O'chirish"></span></a> &nbsp;
<a href="{{ route('payment.projects.edit',['project' => $project->id]) }}"><span class="fa fa-cog" data-toggle="tooltip" data-placement="top" title="Sozlash"></span></a> &nbsp;
<a href="{{ route('payment.projects.edit_status',['project' => $project->id]) }}"><span class="fa @if($project->status == \Goodoneuz\PayUz\Models\Project::NOT_ACTIVE) fa-lock @else fa-unlock-alt @endif " data-toggle="tooltip" data-placement="top" title="Bloklash"></span></a>
<a href="{{ route('payment.projects.edit_status',['project' => $project->id]) }}"><span class="fa @if($project->status == \Goodoneuz\PayUz\Models\PaymentProject::NOT_ACTIVE) fa-lock @else fa-unlock-alt @endif " data-toggle="tooltip" data-placement="top" title="Bloklash"></span></a>
</td>
</tr>
@endforeach
Expand Down
2 changes: 1 addition & 1 deletion src/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// end --editable functions

Route::resource('transactions', 'TransactionController');
Route::resource('projects', 'ProjectController');
Route::resource('payment-projects', 'PaymentProjectController');
Route::resource('payment_systems', 'PaymentSystemController');
Route::resource('transactions', 'TransactionController');
});

0 comments on commit e32480b

Please sign in to comment.