This commit is contained in:
2024-01-28 17:29:39 +05:00
parent 2dc812711e
commit 0a631aec80
18 changed files with 321 additions and 49 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Models\Payment;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ApiKeyHalkbank extends Model
{
use HasFactory;
/**
* Table name
*
* @var string
*/
protected $table = 'api_key_halkbank';
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'order_number',
'billing_username',
'billing_password',
];
/**
* Generate unique order number
*/
public static function generateOrderNumber($resource): int
{
$order_number = static::firstOrCreate([
'billing_username' => $resource->billing_username ?? 'asdasd',
'billing_password' => $resource->billing_password ?? 'asdasd',
], ['order_number' => '01122017270']);
$order_number->update([
'order_number' => $order_number->order_number + 1,
]);
return $order_number->order_number;
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Nova\Forms;
use Closure;
use Illuminate\Support\Str;
class NovaForm
{
/**
* Fill resource empty
*/
public static function fillEmpty(): Closure
{
return function ($request, $model, $attribute, $requestAttribute) {
};
}
/**
* Fill attribute
*/
public static function fillAttribute($key, $value): Closure
{
return function ($request, $model, $attribute, $requestAttribute) use ($key, $value) {
$model->{$key} = $request->input($value);
};
}
/**
* Fill schemaless
*/
public static function fillSchemalessField($schemalessAttribute = 'options'): Closure
{
return function ($request, $model, $attribute, $requestAttribute) use ($schemalessAttribute) {
$model->{$schemalessAttribute}->set($attribute, $request->input($attribute));
};
}
/**
* Save by capitalizing firrt letter
*/
public static function capitalize(): Closure
{
return function ($request, $model, $attribute, $requestAttribute) {
$model->{$attribute} = ucfirst($request->input($attribute));
};
}
/**
* Fill the slug field
*/
public static function fillSlug(string|array $from, ?string $resource): Closure
{
return function ($request, $model, $attribute, $requestAttribute) use ($from, $resource) {
$slugSource = is_array($from) ? data_get($request, implode('.', $from)) : data_get($request, $from);
$slug = Str::slug($slugSource);
$query = $resource ? $resource::where('slug', $slug) : $model::where('slug', $slug);
if ($query->exists()) {
$slug .= Str::random(6);
}
$model->{$attribute} = $slug;
};
}
/**
* Fill media file name
*/
public static function fillMediaFileName(): Closure
{
return fn ($originalFilename, $extension, $model) => sprintf('%s.%s', md5($originalFilename), $extension);
}
}

View File

@@ -6,12 +6,14 @@ use App\Models\Branch\Branch;
use App\Models\Order\Card\CardOrder as CardOrderModel;
use App\Nova\Filters\RegionFilter;
use App\Nova\Filters\StatusFilter;
use App\Nova\Forms\NovaForm;
use App\Nova\Resource;
use App\Nova\Resources\Order\Card\Concerns\CardOrderFieldsForDetail;
use App\Nova\Resources\Order\Card\Concerns\CardOrderFieldsForIndex;
use App\Repos\Order\Card\CardStateRepo;
use App\Repos\Order\Card\CardTypeRepo;
use App\Repos\Order\OrderRepo;
use App\Repos\Payment\OnlinePaymentRepo;
use App\Repos\System\Location\CountryRepo;
use App\Repos\System\Nova\NovaRepo;
use App\Repos\System\Settings\Legal\PassportRepo;
@@ -20,7 +22,6 @@ use App\Rules\DowranAgaAllowed;
use App\Rules\OnlyLetters;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\Hidden;
use Laravel\Nova\Fields\ID;
@@ -30,6 +31,7 @@ use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Panel;
use Laravel\Nova\URL;
use Nurmuhammet\NovaCustomHtml\NovaCustomHtml;
use Nurmuhammet\NovaInputmask\NovaInputmask;
@@ -123,6 +125,30 @@ class CardOrder extends Resource
return $query->where('user_id', $request->user()->id);
}
/**
* Return the location to redirect the user after creation.
*
* @param \Laravel\Nova\Resource $resource
*/
public static function redirectAfterCreate(NovaRequest $request, $resource): URL|string
{
return URL::remote((new OnlinePaymentRepo())->payCardOrder($resource));
}
/**
* Return the location to redirect the user after update.
*
* @param \Laravel\Nova\Resource $resource
* @return \Laravel\Nova\URL|string
*/
public static function redirectAfterUpdate(NovaRequest $request, $resource)
{
return URL::remote(
(new OnlinePaymentRepo())
->payCardOrder($resource),
);
}
/**
* Get the fields for index.
*/
@@ -306,11 +332,11 @@ class CardOrder extends Resource
->rules('max:2048', 'mimes:jpg,png,jpeg')
->creationRules('required')
->updateRules('nullable'),
NovaCustomHtml::make(__('Data'), 'ada')
->html(view('orders.cards.contract-agreement')->render()),
]),
NovaCustomHtml::make(__('Data'), 'ada')
->html(view('orders.cards.contract-agreement')->render())
->fillUsing(NovaForm::fillEmpty()),
]),
];
}

View File

@@ -152,18 +152,65 @@ class LoanOrder extends Resource
->default(auth()->id())
->hideWhenUpdating(),
Select::make(__('Status'), 'status')
->displayUsingLabels()
->searchable()
->options(OrderRepo::statusValues())
->default(OrderRepo::defaultStatus())
->fullWidth()
->rules('required')
->canSeeWhen('systemUser', $this),
new Panel(__('New :resource', ['resource' => $this->singularLabel()]), [
Select::make(__('Status'), 'status')
->displayUsingLabels()
->searchable()
->options(OrderRepo::statusValues())
->default(OrderRepo::defaultStatus())
->fullWidth()
->rules('required')
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
Text::make(__('Note'), 'notes')
->fullWidth()
->canSeeWhen('systemUser', $this),
]),
new Panel(__('Loan'), [
Select::make(__('Loan type'), 'loan_type')

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Repos\Payment;
use App\Models\Payment\ApiKeyHalkbank;
use Illuminate\Support\Facades\Http;
class OnlinePaymentRepo
{
public function payCardOrder($resource): string
{
$orderNumber = $this->generateOrderNumber($resource);
$response = Http::get('https://mpi.gov.tm/payment/rest/register.do', [
'orderNumber' => $orderNumber,
'amount' => $booking->total_price.'00',
'currency' => 934,
'language' => 'ru',
'userName' => 301161000067,
'password' => 'E3vb2SR3dgTPdff',
'returnUrl' => route('online-payment-store'),
'failUrl' => route('online-payment-store'),
'pageView' => 'DESKTOP',
'description' => 'Sargyt',
]);
return 'a';
}
/**
* Generate order number for payment
*/
public function generateOrderNumber($resource): int
{
return ApiKeyHalkbank::generateOrderNumber($resource);
}
}