sber
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Branch\Branch;
|
||||
use App\Repos\Order\Loan\LoanOrderRepo;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
@@ -186,4 +187,31 @@ class SberPaymentOrder extends Model implements HasMedia
|
||||
|
||||
static::creating(LoanOrderRepo::creating());
|
||||
}
|
||||
|
||||
/**
|
||||
* Price for order
|
||||
*/
|
||||
public function priceAmount(): float
|
||||
{
|
||||
return 250;
|
||||
}
|
||||
|
||||
/**
|
||||
* Panel url
|
||||
*/
|
||||
public function panelUrl(string $type = 'index'): string
|
||||
{
|
||||
return match ($type) {
|
||||
'index' => sprintf('%s/resources/nova-sber-payment-orders', config('nova.path')),
|
||||
default => config('nova.path'),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment itmes
|
||||
*/
|
||||
public function paymentItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(SberPaymentOrderItem::class, 'sber_payment_order_id');
|
||||
}
|
||||
}
|
||||
|
||||
46
app/Modules/SberPaymentOrder/Models/SberPaymentOrderItem.php
Normal file
46
app/Modules/SberPaymentOrder/Models/SberPaymentOrderItem.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\SberPaymentOrder\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $sber_payment_order_id
|
||||
* @property int $online_payment_history_id
|
||||
* @property ?string $payer_name
|
||||
* @property ?string $payer_card
|
||||
* @property ?string $payment_order_number
|
||||
* @property string $tmt_payment_amount
|
||||
* @property string $usd_payment_amount
|
||||
* @property bool $paid
|
||||
* @property \Illuminate\Support\Carbon $created_at
|
||||
* @property \Illuminate\Support\Carbon $updated_at
|
||||
*/
|
||||
class SberPaymentOrderItem extends Model implements HasMedia
|
||||
{
|
||||
use InteractsWithMedia;
|
||||
|
||||
/**
|
||||
* Table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sber_payment_orders';
|
||||
|
||||
/**
|
||||
* Guarded attributes
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* Parent order
|
||||
*/
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SberPaymentOrder::class, 'sber_payment_order_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\SberPaymentOrder\Nova\Resources\Item;
|
||||
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
trait NovaSberPaymentOrderItemAuth
|
||||
{
|
||||
/** View button */
|
||||
public function authorizedToView(Request $request)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Create button */
|
||||
public static function authorizedToCreate(Request $request)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Create */
|
||||
public static function authorizeToCreate(Request $request)
|
||||
{
|
||||
throw_unless(auth()->user()->isMe(), AuthorizationException::class);
|
||||
}
|
||||
|
||||
/** Edit button */
|
||||
public function authorizedToUpdate(Request $request): bool
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->isMe()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Update */
|
||||
public function authorizeToUpdate(Request $request): void
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->isMe()) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new AuthorizationException;
|
||||
}
|
||||
|
||||
/** Delete button */
|
||||
public function authorizedToDelete(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->isMe()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Force delete */
|
||||
public function authorizedToForceDelete(Request $request)
|
||||
{
|
||||
return auth()->user()->isMe() ? true : false;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use App\Models\Branch\Branch;
|
||||
use App\Modules\SberPaymentOrder\Nova\Resources\Concerns\NovaSberPaymentOrderAuth;
|
||||
use App\Modules\SberPaymentOrder\Nova\Resources\Concerns\SberPaymentOrderFieldsForDetail;
|
||||
use App\Modules\SberPaymentOrder\Nova\Resources\Concerns\SberPaymentOrderFieldsForIndex;
|
||||
use App\Modules\VisaMasterPaymentOrder\Nova\Resources\NovaSberPaymentOrderItem;
|
||||
use App\Nova\Actions\MakeSberPaymentAction;
|
||||
use App\Nova\Resource;
|
||||
use App\Repos\Order\Card\CardOrderRepo;
|
||||
@@ -18,6 +19,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Nova\Fields\Badge;
|
||||
use Laravel\Nova\Fields\HasMany;
|
||||
use Laravel\Nova\Fields\Hidden;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Select;
|
||||
@@ -317,6 +319,8 @@ class NovaSberPaymentOrder extends Resource
|
||||
|
||||
Files::make('Ugradyjy we kabul ediji (talyp) 2015-nji ýyldan soňra Türkmenistanyň raýatynyň pasportyny ikinji gezek alandan soňra birinji gezek alan pasportynyň seriýasy baradaky maglumaty bilmeýän ,bolsa onda polisiýanyň degişli edaralaryndan birinji alan pasportynyň seriýasy baradaky güwänamasy', 'sender_passport_local_old_replacement'),
|
||||
]),
|
||||
|
||||
HasMany::make(__('Payment items'), 'paymentItems', NovaSberPaymentOrderItem::class),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\VisaMasterPaymentOrder\Nova\Resources;
|
||||
|
||||
use App\Models\Branch\Branch;
|
||||
use App\Models\Payment\OnlinePaymentHistory;
|
||||
use App\Modules\SberPaymentOrder\Nova\Resources\Item\NovaSberPaymentOrderItemAuth;
|
||||
use App\Nova\Actions\CheckOnlinePayment;
|
||||
use App\Nova\Resource;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Laravel\Nova\Actions\Action;
|
||||
use Laravel\Nova\Actions\ActionResponse;
|
||||
use Laravel\Nova\Fields\ActionFields;
|
||||
use Laravel\Nova\Fields\Boolean;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Laravel\Nova\Http\Requests\NovaRequest;
|
||||
|
||||
/**
|
||||
* @template TModel of \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem
|
||||
*/
|
||||
class NovaSberPaymentOrderItem extends Resource
|
||||
{
|
||||
use NovaSberPaymentOrderItemAuth;
|
||||
|
||||
/**
|
||||
* The model the resource corresponds to.
|
||||
*
|
||||
* @var class-string<\App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem>
|
||||
*/
|
||||
public static $model = \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem::class;
|
||||
|
||||
/**
|
||||
* The single value that should be used to represent the resource when being displayed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $title = 'id';
|
||||
|
||||
/**
|
||||
* The columns that should be searched.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public static $search = [
|
||||
'id',
|
||||
];
|
||||
|
||||
/**
|
||||
* The relationships that should be eager loaded on index queries.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
// public static $with = ['branch'];
|
||||
|
||||
/**
|
||||
* Indicates whether the resource should automatically poll for new resources.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $polling = true;
|
||||
|
||||
/**
|
||||
* The interval at which Nova should poll for new resources.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $pollingInterval = 30;
|
||||
|
||||
/**
|
||||
* Indicates whether to show the polling toggle button inside Nova.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $showPollingToggle = true;
|
||||
|
||||
/**
|
||||
* Get the displayable label of the resource.
|
||||
*/
|
||||
public static function label(): string
|
||||
{
|
||||
return __('Payments');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the displayable singular label of the resource.
|
||||
*/
|
||||
public static function singularLabel(): string
|
||||
{
|
||||
return __('Payment');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fields displayed by the resource.
|
||||
*
|
||||
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
|
||||
* @return array<int, \Laravel\Nova\Fields\FieldElement|\Laravel\Nova\Panel>
|
||||
*/
|
||||
public function fields(NovaRequest $request): array
|
||||
{
|
||||
return [
|
||||
ID::make(),
|
||||
|
||||
Text::make('Amaly geçiren raýatyň F.A.A.', 'payer_name'),
|
||||
|
||||
Text::make('Amaly geçiren raýatyň kart belgisi (mask)', 'payer_card'),
|
||||
|
||||
Text::make('Töleg ýyly', fn ($model) => $model->created_at->format('Y')),
|
||||
Text::make('Töleg aýy', fn ($model) => $model->created_at->translatedFormat('F')),
|
||||
|
||||
Text::make('Amalyň geçirilen wagty', fn ($model) => $model->created_at->format('H:i, d.m.Y')),
|
||||
|
||||
Text::make('Amalyň möçberi', fn ($model) => $model->usd_payment_amount.' USD'),
|
||||
|
||||
Text::make('Amalyň manat möçberi', fn ($model) => $model->tmt_payment_amount.' TMT'),
|
||||
|
||||
Text::make('Amalyň referensi', fn ($model) => $model->payment_order_number),
|
||||
|
||||
Boolean::make(__('Paid'), 'paid'),
|
||||
];
|
||||
}
|
||||
|
||||
public function actions(NovaRequest $request): array
|
||||
{
|
||||
return [
|
||||
Action::using('HALKBANK töleg barla', function (ActionFields $fields, Collection $models) {
|
||||
/** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrderItem $item */
|
||||
$item = $models->first();
|
||||
|
||||
$onlinePaymentResource = OnlinePaymentHistory::find($item->online_payment_history_id);
|
||||
|
||||
if (! $onlinePaymentResource) {
|
||||
return ActionResponse::danger('Online payment resource tapylmady');
|
||||
}
|
||||
|
||||
$relatedResource = (new $onlinePaymentResource->online_paymantable_type)
|
||||
->find(id: $onlinePaymentResource->online_paymantable_id);
|
||||
|
||||
if (! $relatedResource) {
|
||||
return ActionResponse::danger('Bu resource tapylmady');
|
||||
}
|
||||
|
||||
$username = $relatedResource->branch->billing_sber_username;
|
||||
$password = $relatedResource->branch->billing_sber_password;
|
||||
|
||||
if ($username == '') {
|
||||
return Action::modal('modal-response', [
|
||||
'title' => 'HALKBANK API',
|
||||
'body' => 'Ulanyjy ady bilen açar sözi gabat gelmedi',
|
||||
]);
|
||||
}
|
||||
|
||||
$response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [
|
||||
'language' => 'ru',
|
||||
'orderId' => $onlinePaymentResource->orderId,
|
||||
'userName' => $username,
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
return Action::modal('modal-response', [
|
||||
'title' => 'HALKBANK API',
|
||||
'html' => CheckOnlinePayment::resultHTML($response),
|
||||
]);
|
||||
})->icon('server')
|
||||
->sole()
|
||||
->withoutConfirmation(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user