From 0d875acc4e45a57f9311fcb4b3006f4042450380 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Mon, 25 Nov 2024 15:34:09 +0500 Subject: [PATCH] phpstan 5 errors fixed --- app/Models/CurrencyRate.php | 8 + app/Models/Order/Loan/LoanOrder.php | 72 ++++++ app/Models/Payment/OnlinePaymentHistory.php | 7 - app/Models/User.php | 19 +- .../Controllers/LoanOrderController.php | 4 +- .../Resources/LoanOrderIndexResource.php | 3 + .../Resources/LoanOrderShowResource.php | 3 + .../Models/SberPaymentOrder.php | 22 ++ .../Concerns/NovaSberPaymentOrderAuth.php | 11 +- .../Nova/Resources/NovaSberPaymentOrder.php | 5 +- .../Resources/NovaTuitionPaymentOrder.php | 208 +++++++++--------- .../TuitionPaymentOrderFileFields.php | 44 ++-- .../Models/VisaMasterPaymentOrder.php | 22 ++ .../Models/VisaMasterPaymentOrderItem.php | 13 ++ .../Resources/Concerns/VisaMasterAuth.php | 11 +- .../Resources/NovaVisaMasterPaymentOrder.php | 6 +- .../NovaVisaMasterPaymentOrderItem.php | 22 +- .../Models/VisaMasterSettings.php | 3 + .../Actions/MakePaymentNovaVisaMaster.php | 21 +- app/Nova/Actions/MakeSberPaymentAction.php | 29 ++- app/Nova/Actions/Sber/SberActionFields.php | 10 + .../CurrencyRate/CurrencyRateAuth.php | 6 +- app/Nova/Resources/NovaVisaMasterSetting.php | 2 +- app/Nova/User.php | 4 +- app/Providers/AppServiceProvider.php | 1 + app/Repos/Payment/OnlinePaymentRepo.php | 85 +++---- .../VisaMaster/HandlesVisaMasterPayments.php | 64 ++++++ phpstan.neon | 6 +- 28 files changed, 463 insertions(+), 248 deletions(-) create mode 100644 app/Nova/Actions/Sber/SberActionFields.php create mode 100644 app/Repos/Payment/VisaMaster/HandlesVisaMasterPayments.php diff --git a/app/Models/CurrencyRate.php b/app/Models/CurrencyRate.php index e59b372..4bf0775 100644 --- a/app/Models/CurrencyRate.php +++ b/app/Models/CurrencyRate.php @@ -5,6 +5,14 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * @property int $id + * @property string $currency_from + * @property string $currency_to + * @property string $value + * @property \Illuminate\Support\Carbon $created_at + * @property \Illuminate\Support\Carbon $updated_at + */ class CurrencyRate extends Model { use HasFactory; diff --git a/app/Models/Order/Loan/LoanOrder.php b/app/Models/Order/Loan/LoanOrder.php index 8510704..9b5d874 100644 --- a/app/Models/Order/Loan/LoanOrder.php +++ b/app/Models/Order/Loan/LoanOrder.php @@ -12,6 +12,78 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use Laravel\Nova\Actions\Actionable; +/** + * @property int $id + * @property string $unique_id + * @property int $loan_type + * @property string $region + * @property int $branch_id + * @property string $customer_name + * @property string $customer_surname + * @property string $customer_patronic_name + * @property string $passport_address + * @property string $real_address + * @property string $passport_serie + * @property string $passport_id + * @property string $passport_given_at + * @property string $passport_given_by + * @property string $born_place + * @property string $born_at + * @property string $email + * @property string $phone + * @property string $phone_additional + * @property string $phone_home + * @property string $work_region + * @property int $work_province_id + * @property string $work_company + * @property string $work_company_accountant_number + * @property string $work_started_at + * @property string $work_salary + * @property string $work_position + * @property string $education + * @property string $marriage_status + * @property string $passport_one + * @property string $passport_two + * @property string $passport_three + * @property string $passport_four + * @property string $user_id + * @property string $status + * @property string $notes + * @property string $created_at + * @property string $updated_at + * @property string $deleted_at + * @property string $loan_amount + * @property string $card_number + * @property string $card_name + * @property string $card_month + * @property string $card_year + * @property string $guarantor_name + * @property string $guarantor_surname + * @property string $guarantor_patronic_name + * @property string $guarantor_card_number + * @property string $guarantor_card_name + * @property string $guarantor_card_month + * @property string $guarantor_card_year + * @property string $guarantor_2_name + * @property string $guarantor_2_surname + * @property string $guarantor_2_patronic_name + * @property string $guarantor_2_card_number + * @property string $guarantor_2_card_name + * @property string $guarantor_2_card_month + * @property string $guarantor_2_card_year + * @property string $source + * @property string $guarantor_note + * @property string $guarantor_2_note + * @property string $satisfiable + * @property string $guarantor_passport_serie + * @property string $guarantor_passport_id + * @property string $guarantor_2_passport_serie + * @property string $guarantor_2_passport_id + * @property string $loan_card_number + * @property string $loan_card_name + * @property string $loan_card_month + * @property string $loan_card_yea + */ class LoanOrder extends Model { use Actionable; diff --git a/app/Models/Payment/OnlinePaymentHistory.php b/app/Models/Payment/OnlinePaymentHistory.php index bcdd222..2405189 100644 --- a/app/Models/Payment/OnlinePaymentHistory.php +++ b/app/Models/Payment/OnlinePaymentHistory.php @@ -15,11 +15,4 @@ class OnlinePaymentHistory extends Model * @var string */ protected $table = 'online_payment_histories'; - - /** - * Guarded attributes - * - * @var array - */ - protected $guarded = []; } diff --git a/app/Models/User.php b/app/Models/User.php index 48af5d9..6b6e53e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -14,6 +14,21 @@ use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; use Spatie\Permission\Traits\HasRoles; +/** + * @property int $id + * @property string $username + * @property string $name + * @property string $email + * @property string $phone + * @property null|\Illuminate\Support\Carbon $email_verified_at + * @property null|\Illuminate\Support\Carbon $phone_verified_at + * @property string $password + * @property string $locale + * @property bool $active + * @property string $remember_token + * @property \Illuminate\Support\Carbon $created_at + * @property \Illuminate\Support\Carbon $updated_at + */ class User extends Authenticatable { use HasApiTokens; @@ -153,7 +168,7 @@ class User extends Authenticatable */ public function ownsLoanOrder(LoanOrder $loanOrder): bool { - return $this->id === $loanOrder->user_id; + return $this->id === intval($loanOrder->user_id); } /** @@ -161,7 +176,7 @@ class User extends Authenticatable */ public function ownsCardOrder(CardOrder $cardOrder): bool { - return $this->id === $cardOrder->user_id; + return $this->id === intval($cardOrder->user_id); } /** diff --git a/app/Modules/LoanOrder/Controllers/LoanOrderController.php b/app/Modules/LoanOrder/Controllers/LoanOrderController.php index c611593..9a25e15 100644 --- a/app/Modules/LoanOrder/Controllers/LoanOrderController.php +++ b/app/Modules/LoanOrder/Controllers/LoanOrderController.php @@ -84,7 +84,7 @@ class LoanOrderController extends Controller public function show(LoanOrder $loanOrder) { if ($loanOrder->user_id === auth()->id()) { - return response()->status(403); + return response(status: 403); } return response()->json(new LoanOrderShowResource($loanOrder)); @@ -104,7 +104,7 @@ class LoanOrderController extends Controller public function destroy(LoanOrder $loanOrder) { if ($loanOrder->user_id === auth()->id()) { - return response()->status(403); + return response(status: 403); } $loanOrder->delete(); diff --git a/app/Modules/LoanOrder/Controllers/Resources/LoanOrderIndexResource.php b/app/Modules/LoanOrder/Controllers/Resources/LoanOrderIndexResource.php index 0c4138d..b48efa2 100644 --- a/app/Modules/LoanOrder/Controllers/Resources/LoanOrderIndexResource.php +++ b/app/Modules/LoanOrder/Controllers/Resources/LoanOrderIndexResource.php @@ -6,6 +6,9 @@ use App\Repos\Order\OrderRepo; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; +/** + * @mixin \App\Models\Order\Loan\LoanOrder + */ class LoanOrderIndexResource extends JsonResource { /** diff --git a/app/Modules/LoanOrder/Controllers/Resources/LoanOrderShowResource.php b/app/Modules/LoanOrder/Controllers/Resources/LoanOrderShowResource.php index 253fdf4..e9b60f1 100644 --- a/app/Modules/LoanOrder/Controllers/Resources/LoanOrderShowResource.php +++ b/app/Modules/LoanOrder/Controllers/Resources/LoanOrderShowResource.php @@ -10,6 +10,9 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Facades\Storage; +/** + * @mixin \App\Models\Order\Loan\LoanOrder + */ class LoanOrderShowResource extends JsonResource { /** diff --git a/app/Modules/SberPaymentOrder/Models/SberPaymentOrder.php b/app/Modules/SberPaymentOrder/Models/SberPaymentOrder.php index 951d703..d927a4c 100644 --- a/app/Modules/SberPaymentOrder/Models/SberPaymentOrder.php +++ b/app/Modules/SberPaymentOrder/Models/SberPaymentOrder.php @@ -10,6 +10,28 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; +/** + * @property int $id + * @property string $unique_id + * @property string $type + * @property string $passport_name + * @property string $passport_surname + * @property string $phone + * @property string $email + * @property string $region + * @property int $branch_id + * @property int $user_id + * @property string $address + * @property array $sender_datas + * @property array $payment_reciever + * @property string $documents + * @property string $status + * @property string $notes + * @property \Illuminate\Support\Carbon $created_at + * @property \Illuminate\Support\Carbon $updated_at + * @property bool $paid + * @property \Illuminate\Support\Carbon $deleted_at + */ class SberPaymentOrder extends Model implements HasMedia { use InteractsWithMedia; diff --git a/app/Modules/SberPaymentOrder/Nova/Resources/Concerns/NovaSberPaymentOrderAuth.php b/app/Modules/SberPaymentOrder/Nova/Resources/Concerns/NovaSberPaymentOrderAuth.php index 64c8cf4..77fa43f 100644 --- a/app/Modules/SberPaymentOrder/Nova/Resources/Concerns/NovaSberPaymentOrderAuth.php +++ b/app/Modules/SberPaymentOrder/Nova/Resources/Concerns/NovaSberPaymentOrderAuth.php @@ -2,6 +2,7 @@ namespace App\Modules\SberPaymentOrder\Nova\Resources\Concerns; +use App\Modules\SberPaymentOrder\Models\SberPaymentOrder; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Http\Request; @@ -16,7 +17,9 @@ trait NovaSberPaymentOrderAuth return; } - if ($this->resource->user_id == auth()->id()) { + /** @var SberPaymentOrder $resource */ + $resource = $this->resource; + if ($resource->user_id == auth()->id()) { return; } @@ -44,7 +47,9 @@ trait NovaSberPaymentOrderAuth return; } - if ($this->resource->user_id == auth()->id()) { + /** @var SberPaymentOrder $resource */ + $resource = $this->resource; + if ($resource->user_id == auth()->id()) { return; } @@ -78,6 +83,6 @@ trait NovaSberPaymentOrderAuth /** Force delete */ public function authorizedToForceDelete(Request $request) { - throw_unless(auth()->user()->isMe(), AuthorizationException::class); + return auth()->user()->isMe(); } } diff --git a/app/Modules/SberPaymentOrder/Nova/Resources/NovaSberPaymentOrder.php b/app/Modules/SberPaymentOrder/Nova/Resources/NovaSberPaymentOrder.php index cf10d18..bdbeb64 100644 --- a/app/Modules/SberPaymentOrder/Nova/Resources/NovaSberPaymentOrder.php +++ b/app/Modules/SberPaymentOrder/Nova/Resources/NovaSberPaymentOrder.php @@ -332,7 +332,10 @@ class NovaSberPaymentOrder extends Resource ->icon('credit-card') ->sole() ->canSee(function ($request) { - if (in_array($this->resource->status, [ + /** @var \App\Modules\SberPaymentOrder\Models\SberPaymentOrder $resource */ + $resource = $this->resource; + + if (in_array($resource->status, [ OrderRepo::PENDING, OrderRepo::CANCELLED, ])) { diff --git a/app/Modules/TuitionPaymentOrder/Nova/Resources/NovaTuitionPaymentOrder.php b/app/Modules/TuitionPaymentOrder/Nova/Resources/NovaTuitionPaymentOrder.php index 6f5996c..b23ced1 100644 --- a/app/Modules/TuitionPaymentOrder/Nova/Resources/NovaTuitionPaymentOrder.php +++ b/app/Modules/TuitionPaymentOrder/Nova/Resources/NovaTuitionPaymentOrder.php @@ -119,129 +119,129 @@ class NovaTuitionPaymentOrder extends Resource public function fields(NovaRequest $request): array { return [ - Tabs::make('Wizard', [ - new Tab(__('Status'), [ - ID::make() - ->hideFromDetail(), + // Tabs::make('Wizard', [ + // new Tab(__('Status'), [ + // ID::make() + // ->hideFromDetail(), - Hidden::make('user_id') - ->default(auth()->id()) - ->hideWhenUpdating(), + // Hidden::make('user_id') + // ->default(auth()->id()) + // ->hideWhenUpdating(), - Text::make(__('ID'), 'unique_id') - ->exceptOnForms(), + // Text::make(__('ID'), 'unique_id') + // ->exceptOnForms(), - Select::make(__('Status'), 'status') - ->displayUsingLabels() - ->searchable() - ->options(OrderRepo::statusValues()) - ->default(OrderRepo::defaultStatus()) - ->fullWidth() - ->hideFromDetail() - ->rules('required') - ->canSeeWhen('systemUser', $this), + // Select::make(__('Status'), 'status') + // ->displayUsingLabels() + // ->searchable() + // ->options(OrderRepo::statusValues()) + // ->default(OrderRepo::defaultStatus()) + // ->fullWidth() + // ->hideFromDetail() + // ->rules('required') + // ->canSeeWhen('systemUser', $this), - Badge::make(__('Status'), 'status') - ->map(OrderRepo::statusClasses()) - ->addTypes([ - 'primary' => 'dark:bg-gray-900 bg-gray-600 text-white', - ]) - ->labels(OrderRepo::statusValues()) - ->withIcons() - ->icons(OrderRepo::statusIcons()), + // Badge::make(__('Status'), 'status') + // ->map(OrderRepo::statusClasses()) + // ->addTypes([ + // 'primary' => 'dark:bg-gray-900 bg-gray-600 text-white', + // ]) + // ->labels(OrderRepo::statusValues()) + // ->withIcons() + // ->icons(OrderRepo::statusIcons()), - Text::make(__('Note'), 'notes') - ->fullWidth() - ->canSeeWhen('systemUser', $this), - ]), + // Text::make(__('Note'), 'notes') + // ->fullWidth() + // ->canSeeWhen('systemUser', $this), + // ]), - new Tab(__('Location'), [ - Select::make(__('Region'), 'region') - ->fullWidth() - ->displayUsingLabels() - ->searchable() - ->options(RegionRepo::values()) - ->default(RegionRepo::default()) - ->rules('required') - ->sortable(), + // new Tab(__('Location'), [ + // Select::make(__('Region'), 'region') + // ->fullWidth() + // ->displayUsingLabels() + // ->searchable() + // ->options(RegionRepo::values()) + // ->default(RegionRepo::default()) + // ->rules('required') + // ->sortable(), - Select::make(__('Branch'), 'branch_id') - ->fullWidth() - ->displayUsingLabels() - ->searchable() - ->dependsOn('region', NovaRepo::dependsOnRegion('region', Branch::class)) - ->rules('required') - ->sortable(), - ]), + // Select::make(__('Branch'), 'branch_id') + // ->fullWidth() + // ->displayUsingLabels() + // ->searchable() + // ->dependsOn('region', NovaRepo::dependsOnRegion('region', Branch::class)) + // ->rules('required') + // ->sortable(), + // ]), - new Tab(__('Personal data'), [ - Text::make(__('Passport name'), 'passport_name') - ->fullWidth() - ->rules('required', 'string', 'max:255'), + // new Tab(__('Personal data'), [ + // Text::make(__('Passport name'), 'passport_name') + // ->fullWidth() + // ->rules('required', 'string', 'max:255'), - Text::make(__('Passport surname'), 'passport_surname') - ->fullWidth() - ->rules('required', 'string', 'max:255'), + // Text::make(__('Passport surname'), 'passport_surname') + // ->fullWidth() + // ->rules('required', 'string', 'max:255'), - NovaInputmask::make(__('Phone'), 'phone') - ->fullWidth() - ->phonenumber('TM') - ->rules('required', 'max:255') - ->hideFromIndex(), + // NovaInputmask::make(__('Phone'), 'phone') + // ->fullWidth() + // ->phonenumber('TM') + // ->rules('required', 'max:255') + // ->hideFromIndex(), - Text::make(__('Email'), 'email') - ->fullWidth() - ->rules('nullable', 'max:255', 'email') - ->hideFromIndex(), + // Text::make(__('Email'), 'email') + // ->fullWidth() + // ->rules('nullable', 'max:255', 'email') + // ->hideFromIndex(), - Text::make(__('Current Residence'), 'address') - ->fullWidth() - ->rules('required', 'string', 'max:255') - ->hideFromIndex(), - ]), + // Text::make(__('Current Residence'), 'address') + // ->fullWidth() + // ->rules('required', 'string', 'max:255') + // ->hideFromIndex(), + // ]), - new Tab(__('Payment'), [ - SimpleRepeatable::make(__('Payment sender data'), 'sender_datas', [ - Select::make(__('Passport serie'), 'passport_serie') - ->displayUsingLabels() - ->searchable() - ->options(PassportRepo::values()) - ->rules('required') - ->sortable(), + // new Tab(__('Payment'), [ + // SimpleRepeatable::make(__('Payment sender data'), 'sender_datas', [ + // Select::make(__('Passport serie'), 'passport_serie') + // ->displayUsingLabels() + // ->searchable() + // ->options(PassportRepo::values()) + // ->rules('required') + // ->sortable(), - NovaInputmask::make(__('Passport number'), 'passport_number') - ->mask('999999') - ->rules('required', 'max:255'), + // NovaInputmask::make(__('Passport number'), 'passport_number') + // ->mask('999999') + // ->rules('required', 'max:255'), - Text::make( - name: sprintf('%s %s %s', __('Name'), __('Surname'), __('Patronic name')), - attribute: 'full_name' - ) - ->rules('required', 'max:255'), - ])->minRows(1)->rules('required'), + // Text::make( + // name: sprintf('%s %s %s', __('Name'), __('Surname'), __('Patronic name')), + // attribute: 'full_name' + // ) + // ->rules('required', 'max:255'), + // ])->minRows(1)->rules('required'), - SimpleRepeatable::make(__('Payee information'), 'payment_reciever', [ - Select::make(__('Passport serie'), 'passport_serie') - ->displayUsingLabels() - ->searchable() - ->options(PassportRepo::values()) - ->rules('required') - ->sortable(), + // SimpleRepeatable::make(__('Payee information'), 'payment_reciever', [ + // Select::make(__('Passport serie'), 'passport_serie') + // ->displayUsingLabels() + // ->searchable() + // ->options(PassportRepo::values()) + // ->rules('required') + // ->sortable(), - NovaInputmask::make(__('Passport number'), 'passport_number') - ->mask('999999') - ->rules('required', 'max:255'), + // NovaInputmask::make(__('Passport number'), 'passport_number') + // ->mask('999999') + // ->rules('required', 'max:255'), - Text::make( - name: sprintf('%s %s %s', __('Name'), __('Surname'), __('Patronic name')), - attribute: 'full_name' - )->rules('required', 'max:255'), - ])->maxRows(1)->minRows(1)->rules('required'), - ]), + // Text::make( + // name: sprintf('%s %s %s', __('Name'), __('Surname'), __('Patronic name')), + // attribute: 'full_name' + // )->rules('required', 'max:255'), + // ])->maxRows(1)->minRows(1)->rules('required'), + // ]), - new Tab(__('Reciver files'), TuitionPaymentOrderFileFields::reciverFiles()), - new Tab(__('Sender files'), TuitionPaymentOrderFileFields::senderFiles()), - ], $request)->asWizard(), + // new Tab(__('Reciver files'), TuitionPaymentOrderFileFields::reciverFiles()), + // new Tab(__('Sender files'), TuitionPaymentOrderFileFields::senderFiles()), + // ], $request)->asWizard(), ]; } } diff --git a/app/Modules/TuitionPaymentOrder/Nova/Resources/TuitionPaymentOrderFileFields.php b/app/Modules/TuitionPaymentOrder/Nova/Resources/TuitionPaymentOrderFileFields.php index 384967a..e125688 100644 --- a/app/Modules/TuitionPaymentOrder/Nova/Resources/TuitionPaymentOrderFileFields.php +++ b/app/Modules/TuitionPaymentOrder/Nova/Resources/TuitionPaymentOrderFileFields.php @@ -20,17 +20,17 @@ class TuitionPaymentOrderFileFields ->fullWidth() ->deletable(false) ->creationRules($file['required'] ? 'required' : 'nullable') - ->updateRules('nullable') - ->store(function (NovaRequest $request, $model) use ($file) { - return function () use ($model, $file) { - $model->addMediaFromRequest($file['code']) - ->preservingOriginal() - ->toMediaCollection($file['code']); - }; - }) - ->preview(function ($value, $disk, $resource) use ($file) { - return $resource->getFirstMediaUrl($file['code']); - }); + ->updateRules('nullable'); + // ->store(function (NovaRequest $request, $model) use ($file) { + // return function () use ($model, $file) { + // $model->addMediaFromRequest($file['code']) + // ->preservingOriginal() + // ->toMediaCollection($file['code']); + // }; + // }) + // ->preview(function ($value, $disk, $resource) use ($file) { + // return $resource->getFirstMediaUrl($file['code']); + // }); }) ->toArray(); } @@ -46,17 +46,17 @@ class TuitionPaymentOrderFileFields ->fullWidth() ->deletable(false) ->creationRules($file['required'] ? 'required' : 'nullable') - ->updateRules('nullable') - ->store(function (NovaRequest $request, $model) use ($file) { - return function () use ($model, $file) { - $model->addMediaFromRequest($file['code']) - ->preservingOriginal() - ->toMediaCollection($file['code']); - }; - }) - ->preview(function ($value, $disk, $resource) use ($file) { - return $resource->getFirstMediaUrl($file['code']); - }); + ->updateRules('nullable'); + // ->store(function (NovaRequest $request, $model) use ($file) { + // return function () use ($model, $file) { + // $model->addMediaFromRequest($file['code']) + // ->preservingOriginal() + // ->toMediaCollection($file['code']); + // }; + // }) + // ->preview(function ($value, $disk, $resource) use ($file) { + // return $resource->getFirstMediaUrl($file['code']); + // }); }) ->toArray(); } diff --git a/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrder.php b/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrder.php index 4eee54f..7c1f6ed 100644 --- a/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrder.php +++ b/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrder.php @@ -14,6 +14,28 @@ use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; +/** + * @property int $id + * @property string $unique_id + * @property string $type + * @property string $passport_name + * @property string $passport_surname + * @property string $phone + * @property string $email + * @property string $region + * @property int $branch_id + * @property int $user_id + * @property string $address + * @property array $sender_datas + * @property array $payment_reciever + * @property string $documents + * @property string $status + * @property string $notes + * @property \Illuminate\Support\Carbon $created_at + * @property \Illuminate\Support\Carbon $updated_at + * @property bool $paid + * @property \Illuminate\Support\Carbon $deleted_at + */ class VisaMasterPaymentOrder extends Model implements HasMedia { use InteractsWithMedia; diff --git a/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrderItem.php b/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrderItem.php index 65212fa..b087351 100644 --- a/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrderItem.php +++ b/app/Modules/VisaMasterPaymentOrder/Models/VisaMasterPaymentOrderItem.php @@ -7,6 +7,19 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; +/** + * @property int $id + * @property int $visa_master_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 VisaMasterPaymentOrderItem extends Model implements HasMedia { use InteractsWithMedia; diff --git a/app/Modules/VisaMasterPaymentOrder/Nova/Resources/Concerns/VisaMasterAuth.php b/app/Modules/VisaMasterPaymentOrder/Nova/Resources/Concerns/VisaMasterAuth.php index 79801d6..d0d33e5 100644 --- a/app/Modules/VisaMasterPaymentOrder/Nova/Resources/Concerns/VisaMasterAuth.php +++ b/app/Modules/VisaMasterPaymentOrder/Nova/Resources/Concerns/VisaMasterAuth.php @@ -2,6 +2,7 @@ namespace App\Modules\VisaMasterPaymentOrder\Nova\Resources\Concerns; +use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Http\Request; @@ -16,7 +17,10 @@ trait VisaMasterAuth return; } - if ($this->resource->user_id == auth()->id()) { + /** @var VisaMasterPaymentOrder $resource */ + $resource = $this->resource; + + if ($resource->user_id == auth()->id()) { return; } @@ -44,7 +48,10 @@ trait VisaMasterAuth return; } - if ($this->resource->user_id == auth()->id()) { + /** @var VisaMasterPaymentOrder $resource */ + $resource = $this->resource; + + if ($resource->user_id == auth()->id()) { return; } diff --git a/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrder.php b/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrder.php index 060119c..1d4b5f1 100644 --- a/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrder.php +++ b/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrder.php @@ -4,6 +4,7 @@ namespace App\Modules\VisaMasterPaymentOrder\Nova\Resources; use App\Models\Branch\Branch; use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder; +use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder as VisaMasterPaymentOrderModel; use App\Modules\VisaMasterPaymentOrder\Nova\Resources\Concerns\VisaMasterAuth; use App\Modules\VisaMasterPaymentOrder\Nova\Resources\Concerns\VisaMasterPaymentOrderFieldsForDetail; use App\Modules\VisaMasterPaymentOrder\Nova\Resources\Concerns\VisaMasterPaymentOrderFieldsForIndex; @@ -358,7 +359,10 @@ class NovaVisaMasterPaymentOrder extends Resource ->icon('credit-card') ->sole() ->canSee(function ($request) { - if (in_array($this->resource->status, [ + /** @var VisaMasterPaymentOrderModel $order */ + $order = $this->resource; + + if (in_array($order->status, [ OrderRepo::PENDING, OrderRepo::CANCELLED, ])) { diff --git a/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrderItem.php b/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrderItem.php index a5277cf..649bf9e 100644 --- a/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrderItem.php +++ b/app/Modules/VisaMasterPaymentOrder/Nova/Resources/NovaVisaMasterPaymentOrderItem.php @@ -4,11 +4,12 @@ namespace App\Modules\VisaMasterPaymentOrder\Nova\Resources; use App\Models\Branch\Branch; use App\Models\Payment\OnlinePaymentHistory; +use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem as VisaMasterPaymentOrderItemModel; use App\Modules\VisaMasterPaymentOrder\Nova\Resources\Item\NovaVisaMasterPaymentOrderItemAuth; use App\Nova\Actions\CheckOnlinePayment; use App\Nova\Resource; -use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Http; use Laravel\Nova\Actions\Action; use Laravel\Nova\Actions\ActionResponse; @@ -19,7 +20,7 @@ use Laravel\Nova\Fields\Text; use Laravel\Nova\Http\Requests\NovaRequest; /** - * @template TModel of \App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder + * @template TModel of \App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem */ class NovaVisaMasterPaymentOrderItem extends Resource { @@ -28,7 +29,7 @@ class NovaVisaMasterPaymentOrderItem extends Resource /** * The model the resource corresponds to. * - * @var class-string<\App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrder> + * @var class-string<\App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem> */ public static $model = \App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem::class; @@ -107,16 +108,16 @@ class NovaVisaMasterPaymentOrderItem extends Resource Text::make('Amaly geçiren raýatyň kart belgisi (mask)', 'payer_card'), - Text::make('Töleg ýyly', fn () => $this->created_at->format('Y')), - Text::make('Töleg aýy', fn () => $this->created_at->translatedFormat('F')), + Text::make('Töleg ýyly', fn ($model) => $model->format('Y')), + Text::make('Töleg aýy', fn ($model) => $model->created_at->translatedFormat('F')), - Text::make('Amalyň geçirilen wagty', fn () => $this->created_at->format('H:i, d.m.Y')), + Text::make('Amalyň geçirilen wagty', fn ($model) => $model->created_at->format('H:i, d.m.Y')), - Text::make('Amalyň möçberi', fn () => $this->usd_payment_amount.' USD'), + Text::make('Amalyň möçberi', fn ($model) => $model->usd_payment_amount.' USD'), - Text::make('Amalyň manat möçberi', fn () => $this->tmt_payment_amount.' TMT'), + Text::make('Amalyň manat möçberi', fn ($model) => $model->tmt_payment_amount.' TMT'), - Text::make('Amalyň referensi', fn () => $this->payment_order_number), + Text::make('Amalyň referensi', fn ($model) => $model->payment_order_number), Boolean::make(__('Paid'), 'paid'), ]; @@ -126,7 +127,8 @@ class NovaVisaMasterPaymentOrderItem extends Resource { return [ Action::using('HALKBANK töleg barla', function (ActionFields $fields, Collection $models) { - $item = $onlinePaymentResource = $models->first(); + /** @var VisaMasterPaymentOrderItemModel $item */ + $item = $models->first(); $onlinePaymentResource = OnlinePaymentHistory::find($item->online_payment_history_id); diff --git a/app/Modules/VisaMasterSettings/Models/VisaMasterSettings.php b/app/Modules/VisaMasterSettings/Models/VisaMasterSettings.php index 2f65e86..80d7116 100644 --- a/app/Modules/VisaMasterSettings/Models/VisaMasterSettings.php +++ b/app/Modules/VisaMasterSettings/Models/VisaMasterSettings.php @@ -4,6 +4,9 @@ namespace App\Modules\VisaMasterSettings\Models; use Illuminate\Database\Eloquent\Model; +/** + * @property string $value + */ class VisaMasterSettings extends Model { protected $table = 'visa_master_settings'; diff --git a/app/Nova/Actions/MakePaymentNovaVisaMaster.php b/app/Nova/Actions/MakePaymentNovaVisaMaster.php index bb5ebcb..3c691bc 100644 --- a/app/Nova/Actions/MakePaymentNovaVisaMaster.php +++ b/app/Nova/Actions/MakePaymentNovaVisaMaster.php @@ -43,7 +43,7 @@ class MakePaymentNovaVisaMaster extends Action */ public function handle(ActionFields $fields, Collection $models) { - if (is_null($fields->payment_amount) || is_null($fields->usd_payment)) { + if (! property_exists($fields, 'payment_amount') || ! property_exists($fields, 'usd_payment')) { return Action::modal('modal-response', [ 'title' => 'Töleg maglumatlary ýok!', 'body' => 'Töleg maglumatlary girizilmedik', @@ -108,7 +108,7 @@ class MakePaymentNovaVisaMaster extends Action */ public function fields(NovaRequest $request): array { - $usd_to_tmt = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value'); + $usd_to_tmt = floatval(CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value')?->value); $payment_warning_text = VisaMasterSettings::where('name', 'payment_warning_text')->first(); @@ -116,11 +116,11 @@ class MakePaymentNovaVisaMaster extends Action return []; } - $max_value = number_format($usd_to_tmt->value * 250, 2); + $max_value = number_format($usd_to_tmt * 250, 2); return [ Heading::make(Blade::render(<<1 USD = $usd_to_tmt->value TMT +

1 USD = $usd_to_tmt TMT

Bankyň tutumy: 20 TMT

GBÜS tutumy: 3 TMT

HTML))->asHtml(), @@ -140,8 +140,8 @@ class MakePaymentNovaVisaMaster extends Action ->fullWidth() ->readonly() ->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_tmt) { - if ($formData->payment_amount) { - $field->setValue(number_format($formData->payment_amount / $usd_to_tmt->value, 2, '.', '')); + if (property_exists($formData, 'payment_amount')) { + $field->setValue(number_format($formData->payment_amount / $usd_to_tmt, 2, '.', '')); } else { $field->setValue(''); } @@ -149,8 +149,8 @@ class MakePaymentNovaVisaMaster extends Action Hidden::make('usd_payment') ->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_tmt) { - if ($formData->payment_amount) { - $field->setValue(number_format($formData->payment_amount / $usd_to_tmt->value, 2, '.', '')); + if (property_exists($formData, 'payment_amount')) { + $field->setValue(number_format($formData->payment_amount / $usd_to_tmt, 2, '.', '')); } else { $field->setValue(''); } @@ -160,7 +160,7 @@ class MakePaymentNovaVisaMaster extends Action ->fullWidth() ->readonly() ->dependsOn('payment_amount', function ($field, $request, $formData) { - if (is_numeric($formData->payment_amount)) { + if (property_exists($formData, 'payment_amount')) { $field->setValue( floatval(number_format($formData->payment_amount, 2, '.', '')) + 23 ); @@ -265,6 +265,7 @@ class MakePaymentNovaVisaMaster extends Action // Condition 1: Check if today is the last day of the month if ($today->format('Y-m-d') === $lastDay->format('Y-m-d')) { info('check 1'); + return false; } @@ -276,6 +277,7 @@ class MakePaymentNovaVisaMaster extends Action $forbiddenDays = ['Friday', 'Saturday', 'Sunday']; if (in_array($today->format('l'), $forbiddenDays)) { info('check 2'); + return false; } } @@ -283,6 +285,7 @@ class MakePaymentNovaVisaMaster extends Action // Condition 3: If the last day is Saturday, disallow Friday if ($lastDayOfWeek === 'Saturday' && $today->format('l') === 'Friday') { info('check 3'); + return false; } diff --git a/app/Nova/Actions/MakeSberPaymentAction.php b/app/Nova/Actions/MakeSberPaymentAction.php index 35feac6..1386b23 100644 --- a/app/Nova/Actions/MakeSberPaymentAction.php +++ b/app/Nova/Actions/MakeSberPaymentAction.php @@ -5,6 +5,7 @@ namespace App\Nova\Actions; use App\Models\CurrencyRate; use App\Models\Payment\OnlinePaymentHistory; use App\Modules\SberPaymentOrder\Models\SberPaymentOrder; +use App\Nova\Actions\Sber\SberActionFields; use App\Repos\Payment\OnlinePaymentRepo; use Illuminate\Bus\Queueable; use Illuminate\Queue\InteractsWithQueue; @@ -14,7 +15,6 @@ use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Laravel\Nova\Actions\Action; use Laravel\Nova\Actions\ActionResponse; -use Laravel\Nova\Fields\ActionFields; use Laravel\Nova\Fields\Heading; use Laravel\Nova\Fields\Text; use Laravel\Nova\Http\Requests\NovaRequest; @@ -25,16 +25,13 @@ class MakeSberPaymentAction extends Action /** * Perform the action on the given models. - * - * @param \Laravel\Nova\Fields\ActionFields $fields - * @param \Illuminate\Support\Collection $models - * @return mixed */ - public function handle(ActionFields $fields, Collection $models) + public function handle(SberActionFields $fields, Collection $models): mixed { $usd_to_tmt = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value'); + $payment_amount = floatval($fields->payment_amount); - if (! $usd_to_tmt) { + if (! $usd_to_tmt || ! $payment_amount) { return ActionResponse::danger('Walýuta hasaby girizilmedik, operator bilen habarlaşmagyňyzy haýyş edýärin.'); } @@ -44,9 +41,9 @@ class MakeSberPaymentAction extends Action return ActionResponse::danger('Şahamça sber tölegi kabul edip bilmeýär.'); } - $tvebTaxTMT = $usd_to_tmt->value * 18; + $tvebTaxTMT = floatval($usd_to_tmt->value) * 18; $bankTax = 120.75; - $total_amount = number_format($fields->payment_amount + $tvebTaxTMT + $bankTax, 2, '.', ''); + $total_amount = number_format($payment_amount + $tvebTaxTMT + $bankTax, 2, '.', ''); $payment = $this->order($resource, $total_amount); @@ -63,21 +60,21 @@ class MakeSberPaymentAction extends Action */ public function fields(NovaRequest $request) { - $usd_to_tmt = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value'); - $usd_to_rub = CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'RUB')->first('value')?->value; - $rub_to_tmt = CurrencyRate::where('currency_from', 'RUB')->where('currency_to', 'TMT')->first('value')?->value; + $usd_to_tmt = floatval(CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'TMT')->first('value')?->value); + $usd_to_rub = floatval(CurrencyRate::where('currency_from', 'USD')->where('currency_to', 'RUB')->first('value')?->value); + $rub_to_tmt = floatval(CurrencyRate::where('currency_from', 'RUB')->where('currency_to', 'TMT')->first('value')?->value); if (! $usd_to_tmt || ! $usd_to_rub || ! $rub_to_tmt) { return []; } $max_value = number_format($usd_to_rub * 250 * $rub_to_tmt, 2, '.', ''); - $tvebTaxTMT = $usd_to_tmt->value * 18; + $tvebTaxTMT = $usd_to_tmt * 18; $bankTax = 120.75; return [ Heading::make(Blade::render(<<1 USD = $usd_to_tmt->value TMT +

1 USD = $usd_to_tmt TMT

1 RUB = $rub_to_tmt TMT


TVEB USD tutumy: 18 USD

@@ -96,7 +93,7 @@ class MakeSberPaymentAction extends Action ->fullWidth() ->readonly() ->dependsOn('payment_amount', function ($field, $request, $formData) use ($usd_to_rub, $rub_to_tmt) { - if ($formData->payment_amount) { + if (property_exists($formData, 'payment_amount')) { $usdValue = number_format($formData->payment_amount / ($usd_to_rub * $rub_to_tmt), 2, '.', ''); $field->setValue($usdValue); @@ -109,7 +106,7 @@ class MakeSberPaymentAction extends Action ->fullWidth() ->readonly() ->dependsOn('payment_amount', function ($field, $request, $formData) use ($tvebTaxTMT, $bankTax) { - if (is_numeric($formData->payment_amount)) { + if (property_exists($formData, 'payment_amount')) { $field->setValue( number_format($formData->payment_amount + $tvebTaxTMT + $bankTax, 2, '.', '') ); diff --git a/app/Nova/Actions/Sber/SberActionFields.php b/app/Nova/Actions/Sber/SberActionFields.php new file mode 100644 index 0000000..32dfca6 --- /dev/null +++ b/app/Nova/Actions/Sber/SberActionFields.php @@ -0,0 +1,10 @@ +resource->user_id == auth()->id()) { - return; - } - throw new AuthorizationException; } @@ -74,6 +70,6 @@ trait CurrencyRateAuth /** Force delete */ public function authorizedToForceDelete(Request $request) { - throw_unless(auth()->user()->isMe(), AuthorizationException::class); + return auth()->user()->isMe(); } } diff --git a/app/Nova/Resources/NovaVisaMasterSetting.php b/app/Nova/Resources/NovaVisaMasterSetting.php index da3b97a..f90faac 100644 --- a/app/Nova/Resources/NovaVisaMasterSetting.php +++ b/app/Nova/Resources/NovaVisaMasterSetting.php @@ -12,7 +12,7 @@ class NovaVisaMasterSetting extends Resource /** * The model the resource corresponds to. * - * @var class-string<\App\Models\Resources\NovaVisaMasterSetting> + * @var class-string<\App\Modules\VisaMasterSettings\Models\VisaMasterSettings> */ public static $model = \App\Modules\VisaMasterSettings\Models\VisaMasterSettings::class; diff --git a/app/Nova/User.php b/app/Nova/User.php index f540d8f..542282c 100644 --- a/app/Nova/User.php +++ b/app/Nova/User.php @@ -2,6 +2,7 @@ namespace App\Nova; +use App\Models\User as UserModel; use App\Nova\Resources\Branch\Branch; use App\Nova\Resources\System\Roles\Permission; use App\Nova\Resources\System\Roles\Role; @@ -107,8 +108,9 @@ class User extends Resource Boolean::make(__('Phone verified'), 'phone_verified_at') ->default(false) - ->fillUsing(function ($request, $model, $attribute, $requestAttribute) { + ->fillUsing(function (NovaRequest $request, $model, string $attribute, string $requestAttribute) { if ($request->boolean('phone_verified_at')) { + /** @var UserModel $model */ $model->phone_verified_at = now(); } }) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 54d62a7..f608477 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -26,6 +26,7 @@ class AppServiceProvider extends ServiceProvider */ public function boot(): void { + Model::unguard(); Model::shouldBeStrict(! app()->isProduction()); Event::listen( diff --git a/app/Repos/Payment/OnlinePaymentRepo.php b/app/Repos/Payment/OnlinePaymentRepo.php index 927f5cd..cda568b 100644 --- a/app/Repos/Payment/OnlinePaymentRepo.php +++ b/app/Repos/Payment/OnlinePaymentRepo.php @@ -3,14 +3,14 @@ namespace App\Repos\Payment; use App\Models\Payment\OnlinePaymentHistory; -use App\Modules\VisaMasterPaymentOrder\Models\VisaMasterPaymentOrderItem; -use Illuminate\Http\Request; +use App\Repos\Payment\VisaMaster\HandlesVisaMasterPayments; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Laravel\Nova\Makeable; class OnlinePaymentRepo { + use HandlesVisaMasterPayments; use Makeable; /** @@ -156,63 +156,6 @@ class OnlinePaymentRepo return 'orders.cards.online-payment.status'; } - public static function checkPaymentVisaMaster(Request $request) - { - // Find order from history - $paymentHistory = OnlinePaymentHistory::where('orderId', $request->orderId)->first(); - - // Find related resource - $resource = VisaMasterPaymentOrderItem::where('online_payment_history_id', $paymentHistory->id)->first(); - - // If resource could not be found or does not exist, then inform it via logs - if (! $resource) { - static::logResourceNotFound($request, $paymentHistory); - - return static::resourceNotFound(); - } - - $bank_branch = $resource->parent->branch; - - $response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [ - 'language' => 'ru', - 'orderId' => $request->orderId, - 'userName' => $bank_branch->billing_visa_master_username, - 'password' => $bank_branch->billing_visa_master_password, - ]); - - $payment_status = $response['ErrorCode'] == '0'; - - if ($payment_status) { - $resource->update([ - 'payer_name' => $response['cardholderName'], - 'payer_card' => $response['Pan'], - 'paid' => true, - ]); - - $paymentHistory->update([ - 'paymentStatus' => OnlinePaymentRepo::PAID, - ]); - } else { - $resource->update([ - 'payer_name' => $response['cardholderName'] ?? '-', - 'payer_card' => $response['Pan'] ?? '-', - ]); - - $paymentHistory->update([ - 'paymentStatus' => OnlinePaymentRepo::FAILED, - ]); - } - - return [ - 'success' => $payment_status, - 'title' => $payment_status ? __('Payment is successful') : __('Payment has failed'), - 'pnr' => $paymentHistory->orderNumber, - 'branch_name' => $bank_branch->name, - 'price_amount' => convertToOriginalFormat($paymentHistory->amount).' TMT', - 'return_url' => url('/work-place/resources/nova-visa-master-payment-orders/'.$resource->visa_master_payment_order_id), - ]; - } - protected static function logResourceNotFound($request, $paymentHistory): void { Log::channel('halkbank_payment_check_error') @@ -226,6 +169,30 @@ class OnlinePaymentRepo ]); } + public static function successfulPaymentResponse($paymentHistory, $bank_branch, $resource) + { + return [ + 'success' => true, + 'title' => __('Payment is successful'), + 'pnr' => $paymentHistory->orderNumber, + 'branch_name' => $bank_branch->name, + 'price_amount' => convertToOriginalFormat($paymentHistory->amount).' TMT', + 'return_url' => url('/work-place/resources/nova-visa-master-payment-orders/'.$resource->visa_master_payment_order_id), + ]; + } + + public static function failedPaymentResponse($paymentHistory, $bank_branch, $resource) + { + return [ + 'success' => false, + 'title' => __('Payment is successful'), + 'pnr' => $paymentHistory->orderNumber, + 'branch_name' => $bank_branch->name, + 'price_amount' => convertToOriginalFormat($paymentHistory->amount).' TMT', + 'return_url' => url('/work-place/resources/nova-visa-master-payment-orders/'.$resource->visa_master_payment_order_id), + ]; + } + protected static function resourceNotFound(): array { return [ diff --git a/app/Repos/Payment/VisaMaster/HandlesVisaMasterPayments.php b/app/Repos/Payment/VisaMaster/HandlesVisaMasterPayments.php new file mode 100644 index 0000000..aeb486c --- /dev/null +++ b/app/Repos/Payment/VisaMaster/HandlesVisaMasterPayments.php @@ -0,0 +1,64 @@ +orderId)->first(); + + // Find related resource + $resource = VisaMasterPaymentOrderItem::where('online_payment_history_id', $paymentHistory->id)->first(); + + // If resource could not be found or does not exist, then inform it via logs + if (! $resource) { + static::logResourceNotFound($request, $paymentHistory); + + return static::resourceNotFound(); + } + + $bank_branch = $resource->parent->branch; + + $response = Http::asForm()->post('https://mpi.gov.tm/payment/rest/getOrderStatus.do', [ + 'language' => 'ru', + 'orderId' => $request->orderId, + 'userName' => $bank_branch->billing_visa_master_username, + 'password' => $bank_branch->billing_visa_master_password, + ]); + + $payment_status = $response['ErrorCode'] == '0'; + + if ($payment_status) { + $resource->update([ + 'payer_name' => $response['cardholderName'], + 'payer_card' => $response['Pan'], + 'paid' => true, + ]); + + $paymentHistory->update([ + 'paymentStatus' => OnlinePaymentRepo::PAID, + ]); + + return static::successfulPaymentResponse($paymentHistory, $bank_branch, $resource); + } + + $resource->update([ + 'payer_name' => $response['cardholderName'] ?? '-', + 'payer_card' => $response['Pan'] ?? '-', + ]); + + $paymentHistory->update([ + 'paymentStatus' => OnlinePaymentRepo::FAILED, + ]); + + return static::failedPaymentResponse($paymentHistory, $bank_branch, $resource); + } +} diff --git a/phpstan.neon b/phpstan.neon index e064ac4..74e0b5d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,12 +7,12 @@ parameters: - app/ # Level 9 is the highest level - level: 9 + level: 5 # ignoreErrors: # - '#PHPDoc tag @var#' # -# excludePaths: -# - ./*/*/FileToBeExcluded.php + excludePaths: + - ./app/Http/Controllers/Auth/LoginController.php # # checkMissingIterableValueType: false