Compare commits

..

44 Commits

Author SHA1 Message Date
98b9d5cbca add trancactions report 2026-07-06 14:02:27 +03:30
8002679ca2 check status | sync status 2026-07-04 15:52:01 +03:30
1f8bd224a3 stage 2026-06-07 21:36:06 +03:30
08b0cd4cca Merge pull request 'add authorization to all fib services' (#31) from feature/FibDTO into develop
Reviewed-on: #31
2026-06-02 10:34:11 +00:00
6db74f557b add authorization to all fib services 2026-06-02 14:03:58 +03:30
4eec548b83 Merge pull request 'add three column in user_gateways and use them in controller' (#30) from feature/GetClient into develop
Reviewed-on: #30
2026-06-01 13:06:13 +00:00
675d2bdbad fix clied password nd fix rote for expert 2026-06-01 16:36:02 +03:30
69ffe322ce fix migration 2026-06-01 15:34:54 +03:30
a1466d8f57 fix migration 2026-06-01 15:33:06 +03:30
392fca8635 add three column in user_gateways and use them in controller 2026-06-01 15:26:09 +03:30
9a01a83370 Merge pull request 'feature/payment_creation_phase_1' (#28) from feature/payment_creation_phase_1 into develop
Reviewed-on: #28
2026-05-28 13:30:34 +00:00
8438655f8c Merge pull request 'feature/FixLogin' (#27) from feature/FixLogin into develop
Reviewed-on: #27
2026-05-25 12:48:50 +00:00
5040299efc fix user resource and profil 2026-05-25 16:18:08 +03:30
26a0f79a6d fix enum for gateway managment 2026-05-25 16:12:14 +03:30
1b5d339a53 fix login code in3 point 2026-05-25 15:00:44 +03:30
c73d50d096 Merge pull request 'change show province' (#26) from feature/GetCity into develop
Reviewed-on: #26
2026-05-23 13:08:23 +00:00
8be89d350f change show province 2026-05-23 16:36:40 +03:30
d31c641216 Merge pull request 'create seeder for city and province' (#25) from feature/ProvinceAndCitySeeder into develop
Reviewed-on: #25
2026-05-23 11:54:56 +00:00
aa363d1695 Merge pull request 'feature/CreateSeedrStatus' (#24) from feature/CreateSeedrStatus into develop
Reviewed-on: #24
2026-05-23 11:51:20 +00:00
ca2ec66fb5 resolve the conflicts 2026-05-23 15:21:15 +03:30
5c757e1823 create seeder for city and province 2026-05-23 15:13:12 +03:30
d9f895c382 create seeder for city and province 2026-05-23 14:55:00 +03:30
9ad3d6cea0 create show for city and province 2026-05-23 14:03:10 +03:30
8554f4cc55 create list for city and province 2026-05-23 13:49:09 +03:30
5e48777e1c create list for city and province 2026-05-23 13:45:05 +03:30
738b21e182 just shape sth stage1 2026-05-22 19:18:11 +03:30
77a4e98058 stage things 2026-05-22 16:28:10 +03:30
01bae8474b Merge pull request 'add id card to profile' (#23) from feature/TransactionServices into develop
Reviewed-on: #23
2026-05-20 11:52:39 +00:00
463ca3f006 add id card to profile 2026-05-20 15:22:13 +03:30
1ba141e715 Merge pull request 'change edit method' (#22) from feature/EditUserProfile into develop
Reviewed-on: #22
2026-05-20 06:23:34 +00:00
76e6ab4e0c change edit method 2026-05-20 09:53:05 +03:30
fb35ed58b1 Merge pull request 'feature/EditProfile' (#18) from feature/EditProfile into develop
Reviewed-on: #18
2026-05-20 05:50:25 +00:00
ffb4179e0d Merge pull request 'create user gateway controller' (#21) from feature/GatewayManagement into develop
Reviewed-on: #21
2026-05-20 05:44:09 +00:00
a7fa1097b7 create user gateway controller 2026-05-20 09:14:06 +03:30
f2f9d38907 Merge pull request 'create Enum and seeder for BusinessType and payment_statuses' (#20) from feature/CreateSeedrStatus into develop
Reviewed-on: #20
2026-05-19 10:49:50 +00:00
5b79cefe28 create Enum and seeder for BusinessType and payment_statuses 2026-05-18 16:28:58 +03:30
41b7ead69e Merge pull request 'separate any gateways' (#19) from feature/PaymentModel into develop
Reviewed-on: #19
2026-05-18 11:10:23 +00:00
5ea986db40 separate any gateways 2026-05-18 14:34:28 +03:30
d04637b1ef fix code 2026-05-18 14:10:45 +03:30
3c61e279ec create profile for expert 2026-05-18 13:59:05 +03:30
e9f6ee71fa create profile for expert 2026-05-18 13:58:20 +03:30
60129f5abb create profile for expert 2026-05-18 13:57:03 +03:30
2d8f2dbcc5 create profile for expert 2026-05-18 13:50:37 +03:30
86e353749a create profile for expert 2026-05-18 13:49:33 +03:30
197 changed files with 1936 additions and 283 deletions

0
backend/.dockerignore Normal file → Executable file
View File

0
backend/.editorconfig Normal file → Executable file
View File

0
backend/.env.example Normal file → Executable file
View File

0
backend/.gitattributes vendored Normal file → Executable file
View File

0
backend/.gitignore vendored Normal file → Executable file
View File

0
backend/.npmrc Normal file → Executable file
View File

0
backend/Dockerfile Normal file → Executable file
View File

0
backend/Dockerfile.production Normal file → Executable file
View File

0
backend/README.md Normal file → Executable file
View File

16
backend/app/Admin/Controllers/AuthController.php Normal file → Executable file
View File

@@ -16,19 +16,6 @@ class AuthController extends Controller
{
use ApiResponse;
public function register(RegisterRequest $request): JsonResponse
{
Expert::query()->create([
'username' => $request->username,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
$request->session()->regenerate();
return $this->successResponse();
}
public function login(LoginRequest $request): JsonResponse
{
$credentials = ['password' => $request->password];
@@ -39,8 +26,7 @@ class AuthController extends Controller
$credentials['username'] = $request->login;
}
if (Auth::attempt($credentials))
{
if (Auth::guard('expert')->attempt($credentials)) {
$request->session()->regenerate();
return $this->successResponse();

View File

View File

@@ -4,7 +4,6 @@ namespace App\Admin\Controllers;
use App\Admin\Requests\ExpertManagement\StoreRequest;
use App\Admin\Requests\ExpertManagement\UpdateRequest;
use App\Admin\Resources\ExpertManagementResource;
use App\Facades\DataTable\DataTableFacade;
use App\Http\Controllers\Controller;
use App\Models\City;

View File

1
backend/app/Admin/Controllers/ProfileController.php Normal file → Executable file
View File

@@ -53,5 +53,4 @@ class ProfileController extends Controller
return $this->successResponse();
}
}

View File

0
backend/app/Admin/Requests/Auth/LoginRequest.php Normal file → Executable file
View File

0
backend/app/Admin/Requests/Auth/RegisterRequest.php Normal file → Executable file
View File

View File

View File

View File

View File

View File

View File

8
backend/app/Admin/Requests/Profile/EditRequest.php Normal file → Executable file
View File

@@ -4,6 +4,8 @@ namespace App\Admin\Requests\Profile;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
class EditRequest extends FormRequest
{
@@ -24,10 +26,10 @@ class EditRequest extends FormRequest
{
return [
'username' => 'string|max:255',
'first_name' => 'string',
'last_name' => 'string',
'first_name' => 'required|string',
'last_name' => 'required|string',
'national_id' => 'required',
'email' => 'string|email|max:255',
'national_id' => 'string',
'phone_number' => 'string',
'province_id' => 'string',
'city_id' => 'string',

View File

View File

View File

View File

0
backend/app/Admin/Resources/ExpertResource.php Normal file → Executable file
View File

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Enums;
enum BusinessTypeEnum: int
{
case MEDICAL = 1;
case LEGAL = 2;
case ENGINEERING = 3;
case EDUCATION = 4;
case CONSULTING = 5;
case BEAUTY = 6;
case TECHNICAL_SERVICES = 7;
case FINANCIAL = 8;
case REAL_ESTATE = 9;
case RESTAURANT = 10;
case SHOP = 11;
case TRANSPORTATION = 12;
case ART = 13;
case SPORT = 14;
case OTHER = 15;
public function label(): string
{
return match ($this) {
self::MEDICAL => 'medical',
self::LEGAL => 'legal',
self::ENGINEERING => 'engineering',
self::EDUCATION => 'education',
self::CONSULTING => 'consulting',
self::BEAUTY => 'beauty',
self::TECHNICAL_SERVICES => 'technical_services',
self::FINANCIAL => 'financial',
self::REAL_ESTATE => 'real_estate',
self::RESTAURANT => 'restaurant',
self::SHOP => 'shop',
self::TRANSPORTATION => 'transportation',
self::ART => 'art',
self::SPORT => 'sport',
self::OTHER => 'other',
};
}
public static function name($id): string
{
$mapArray = [
1 => 'medical',
2 => 'legal',
3 => 'engineering',
4 => 'education',
5 => 'consulting',
6 => 'beauty',
7 => 'technical_services',
8 => 'financial',
9 => 'real_estate',
10 => 'restaurant',
11 => 'shop',
12 => 'transportation',
13 => 'art',
14 => 'sport',
15 => 'other',
];
return $mapArray[$id];
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Enums;
enum PaymentStatusEnum: int
{
case UNPAID = 0;
case Cancelled = 1;
case Expired = 2;
case PAID = 3;
case REFUNDED = 4;
case PendingVerification = 5;
case REFUND_REQUESTED = 6;
public function label(): string
{
return match ($this) {
self::UNPAID => 'UNPAID',
self::Cancelled => 'CANCELLED',
self::Expired => 'EXPIRED',
self::PAID => 'PAID',
self::REFUNDED => 'REFUNDED',
self::REFUND_REQUESTED => 'REFUND_REQUESTED',
self::PendingVerification => 'PENDING_VERIFICATION',
};
}
}

0
backend/app/Facades/DataTable/DataTable.php Normal file → Executable file
View File

0
backend/app/Facades/DataTable/DataTableFacade.php Normal file → Executable file
View File

0
backend/app/Facades/File/File.php Normal file → Executable file
View File

0
backend/app/Facades/File/FileFacade.php Normal file → Executable file
View File

0
backend/app/Http/Controllers/Controller.php Normal file → Executable file
View File

0
backend/app/Mail/LoginNotificationMail.php Normal file → Executable file
View File

View File

@@ -2,13 +2,13 @@
namespace App\Models;
use Database\Factories\GatewayCategoryFactory;
use Database\Factories\BusinessTypeFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class GatewayCategory extends Model
class BusinessType extends Model
{
/** @use HasFactory<GatewayCategoryFactory> */
/** @use HasFactory<BusinessTypeFactory> */
use HasFactory;
protected $guarded = ['id'];

0
backend/app/Models/City.php Normal file → Executable file
View File

0
backend/app/Models/Document.php Normal file → Executable file
View File

8
backend/app/Models/Expert.php Normal file → Executable file
View File

@@ -5,17 +5,19 @@ namespace App\Models;
use Database\Factories\ExpertFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
/**
* @method roles()
* @method permissions()
*/
class Expert extends Model
class Expert extends Authenticatable
{
/** @use HasFactory<ExpertFactory> */
use HasFactory;
use HasRoles;
use Notifiable,HasFactory,HasRoles;
protected $guarded = ['id'];
protected string $guard_name = 'web';

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class FibTransaction extends Model
{
/** @use HasFactory<\Database\Factories\FibTransactionFactory> */
use HasFactory;
protected $guarded = ['id'];
public function transaction(): BelongsTo
{
return $this->belongsTo(Transaction::class);
}
public function payment(): BelongsTo
{
return $this->belongsTo(Payment::class);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class FibTransactionStatus extends Model
{
/** @use HasFactory<\Database\Factories\FibTransactionStatusFactory> */
use HasFactory;
}

0
backend/app/Models/Province.php Normal file → Executable file
View File

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Database\Factories\TransactionFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Transaction extends Model
{
/** @use HasFactory<TransactionFactory> */
use HasFactory;
protected $guarded = ['id'];
public function payment(): BelongsTo
{
return $this->belongsTo(Payment::class);
}
}

View File

@@ -10,6 +10,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Laravel\Passport\Bridge\Client;
use Laravel\Passport\HasApiTokens;
#[Guarded(['id'])]
@@ -22,6 +24,16 @@ class User extends Authenticatable
public function documents(): MorphToMany
{
return $this->morphToMany(Document::class, 'documentable');
return $this->morphToMany(Document::class, 'documents');
}
public function validateForPassportPasswordGrant(string $password): bool
{
return Hash::check($password, $this->password);
}
public function findForPassport(string $username, Client $client): User
{
return $this->where('username', $username)->first();
}
}

View File

@@ -2,13 +2,13 @@
namespace App\Models;
use Database\Factories\GatewayFactory;
use Database\Factories\UserGatewayFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Gateway extends Model
class UserGateway extends Model
{
/** @use HasFactory<GatewayFactory> */
/** @use HasFactory<UserGatewayFactory> */
use HasFactory;
protected $guarded = ['id'];

View File

@@ -22,6 +22,8 @@ class AppServiceProvider extends ServiceProvider
public function boot(): void
{
Passport::enablePasswordGrant();
Passport::tokensExpireIn(CarbonInterval::minutes(1));
Passport::refreshTokensExpireIn(CarbonInterval::minutes(5));
Passport::personalAccessTokensExpireIn(CarbonInterval::minutes(1));
}
}

0
backend/app/Providers/DataTableServiceProvider.php Normal file → Executable file
View File

0
backend/app/Providers/FileServiceProvider.php Normal file → Executable file
View File

0
backend/app/Services/DataTable/DataTableInput.php Normal file → Executable file
View File

0
backend/app/Services/DataTable/DataTableService.php Normal file → Executable file
View File

0
backend/app/Services/DataTable/Enums/DataType.php Normal file → Executable file
View File

0
backend/app/Services/DataTable/Enums/SearchType.php Normal file → Executable file
View File

View File

View File

View File

0
backend/app/Services/DataTable/Filter/ApplyFilter.php Normal file → Executable file
View File

0
backend/app/Services/DataTable/Filter/Filter.php Normal file → Executable file
View File

View File

View File

0
backend/app/Services/DataTable/Sort/ApplySort.php Normal file → Executable file
View File

0
backend/app/Services/DataTable/Sort/Sort.php Normal file → Executable file
View File

View File

View File

View File

View File

@@ -1,6 +1,6 @@
<?php
namespace App\User\Services\FIB;
namespace App\Services\FIB;
use Exception;
use Illuminate\Http\Client\ConnectionException;
@@ -16,7 +16,7 @@ class AuthorizationService
public function __construct()
{
$this->url = config('fib.authorization.url');
$this->channelName = '';
$this->channelName = 'fib_authorization';
$this->inputParameters = [
'client_id' => config('fib.authorization.client_id'),
'client_secret' => config('fib.authorization.client_secret'),
@@ -51,7 +51,6 @@ class AuthorizationService
{
return Http::asForm()
->throw()
->withoutVerifying()
->post($this->url, $this->inputParameters)
->json();
}

View File

@@ -1,6 +1,6 @@
<?php
namespace App\User\Services\FIB;
namespace App\Services\FIB;
use Exception;
use Illuminate\Http\Client\ConnectionException;
@@ -11,21 +11,13 @@ class CancelPaymentService
{
protected string $url;
protected string $channelName;
protected string $accessToken;
protected array $headers;
protected AuthorizationService $authorizationService;
public function __construct()
public function __construct(AuthorizationService $authorizationService)
{
$this->url = config('fib.cancelPayment.url');
$this->channelName = '';
}
public function setHeaders(): void
{
$this->headers = [
'Authorization' => 'Bearer ' . $this->accessToken,
'Content-Type' => 'application/json',
];
$this->authorizationService = $authorizationService;
}
/**
@@ -50,13 +42,26 @@ class CancelPaymentService
/**
* @throws ConnectionException
* @throws Exception
*/
public function sendRequest(): array
{
return Http::withHeaders($this->headers)
return Http::withHeaders([
'Authorization' => 'Bearer ' . $this->getToken(),
'Content-Type' => 'application/json',
])
->throw()
->withoutVerifying()
->post($this->url)
->json();
}
/**
* @throws Exception
*/
public function getToken(): string
{
$data = $this->authorizationService->run();
return $data['access_token'];
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Services\FIB;
use Exception;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class CheckPaymentStatusService
{
protected string $url;
protected string $channelName;
protected AuthorizationService $authorization_service;
public function __construct(AuthorizationService $authorization_service)
{
$this->url = 'https://fib-stage.fib.iq/protected/v1/payments/';
$this->channelName = 'fib_status';
$this->authorization_service = $authorization_service;
}
/**
* @throws Exception
*/
public function run(string $fib_payment_id): array
{
try {
return $this->sendRequest($fib_payment_id);
} catch (Exception $e) {
Log::channel($this->channelName)
->error(get_class($this),
[
'message' => $e->getMessage(),
]
);
throw $e;
}
}
/**
* @throws ConnectionException
* @throws Exception
*/
public function sendRequest(string $fib_payment_id): array
{
$url = rtrim($this->url, '/') . "/{$fib_payment_id}/status";
return Http::withHeaders([
'Authorization' => 'Bearer ' . $this->getToken(),
'Accept' => 'application/json',
])
->throw()
->withoutVerifying()
->get($url)
->json();
}
/**
* @throws Exception
*/
public function getToken(): string
{
$data = $this->authorization_service->run();
return $data['access_token'];
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace App\User\Services\FIB;
namespace App\Services\FIB;
use Exception;
use Illuminate\Http\Client\ConnectionException;
@@ -11,27 +11,14 @@ class CreatePaymentService
{
protected string $url;
protected string $channelName;
protected string $accessToken;
protected array $headers;
protected array $inputParameters;
protected AuthorizationService $authorizationService;
public function __construct()
public function __construct(AuthorizationService $authorizationService)
{
$this->url = config('fib.createPayment.url');
$this->channelName = '';
}
public function setAccessToken(string $accessToken): void
{
$this->accessToken = $accessToken;
}
public function setHeaders(): void
{
$this->headers = [
'Authorization' => 'Bearer ' . $this->accessToken,
'Content-Type' => 'application/json',
];
$this->channelName = 'fib_create_payment';
$this->authorizationService = $authorizationService;
}
public function setInputParameters(array $inputParameters): void
@@ -61,13 +48,26 @@ class CreatePaymentService
/**
* @throws ConnectionException
* @throws Exception
*/
public function sendRequest(): array
{
return Http::withHeaders($this->headers)
return Http::withHeaders([
'Authorization' => 'Bearer ' . $this->getToken(),
'Content-Type' => 'application/json',
])
->throw()
->withoutVerifying()
->post($this->url, $this->inputParameters)
->json();
}
/**
* @throws Exception
*/
public function getToken(): string
{
$data = $this->authorizationService->run();
return $data['access_token'];
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Services\FIB\DTO;
class FIBPaymentCreateDTO
{
public string $paymentId;
public string $readableCode;
public string $qrCode;
public string $validUntil;
public string $personalAppLink;
public string $businessAppLink;
public string $corporateAppLink;
public function __construct(array $data)
{
$this->paymentId = $data['paymentId'];
$this->readableCode = $data['readableCode'];
$this->qrCode = $data['qrCode'];
$this->validUntil = $data['validUntil'];
$this->personalAppLink = $data['personalAppLink'];
$this->businessAppLink = $data['businessAppLink'];
$this->corporateAppLink = $data['corporateAppLink'];
}
public static function fromResponse($data): FIBPaymentCreateDTO
{
return new self([
'paymentId' => $data['paymentId'],
'readableCode' => $data['readableCode'],
'qrCode' => $data['qrCode'],
'validUntil' => $data['validUntil'],
'personalAppLink' => $data['personalAppLink'],
'businessAppLink' => $data['businessAppLink'],
'corporateAppLink' => $data['corporateAppLink'],
]);
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace App\User\Services\FIB;
namespace App\Services\FIB;
use Exception;
use Illuminate\Http\Client\ConnectionException;
@@ -11,21 +11,13 @@ class RefundService
{
protected string $url;
protected string $channelName;
protected string $accessToken;
protected array $headers;
protected AuthorizationService $authorizationService;
public function __construct()
public function __construct(AuthorizationService $authorizationService)
{
$this->url = config('fib.refund.url');
$this->channelName = '';
}
public function setHeaders(): void
{
$this->headers = [
'Authorization' => 'Bearer ' . $this->accessToken,
'Content-Type' => 'application/json',
];
$this->channelName = 'fib_refund';
$this->authorizationService = $authorizationService;
}
/**
@@ -50,13 +42,26 @@ class RefundService
/**
* @throws ConnectionException
* @throws Exception
*/
public function sendRequest(): array
{
return Http::withHeaders($this->headers)
return Http::withHeaders([
'Authorization' => 'Bearer ' . $this->getToken(),
'Content-Type' => 'application/json',
])
->throw()
->withoutVerifying()
->post($this->url)
->json();
}
/**
* @throws Exception
*/
public function getToken(): string
{
$data = $this->authorizationService->run();
return $data['access_token'];
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Services\Payments\Commands;
use App\Models\FibTransaction;
use App\Services\Payments\SyncFibPaymentStatusService;
use Illuminate\Console\Command;
class SyncFibPaymentStatuses extends Command
{
protected $signature = 'payments:sync-fib-statuses';
protected $description = 'Poll FIB for status updates on all pending payments';
public function handle(SyncFibPaymentStatusService $service)
{
$this->info('Syncing FIB payment statuses...');
$service->run();
$this->info('Done.');
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Services\Payments\Controllers;
use App\Http\Controllers\Controller;
use App\Services\FIB\CheckPaymentStatusService;
use App\Services\Payments\DTO\PaymentCreateDTO;
use App\Services\Payments\PaymentService;
use App\Traits\ApiResponse;
use App\User\Requests\Payment\FIB\InquiryRequest;
use App\User\Requests\Payment\FIB\StoreRequest;
use App\User\Resources\Payment\InquiryResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Js;
class FIBTempController extends Controller
{
use ApiResponse;
public $check_status_service;
public function __construct(CheckPaymentStatusService $check_status_service)
{
$this->check_status_service = $check_status_service;
}
public function checkStatus(Request $request): JsonResponse
{
try {
$result = $this->check_status_service->run('8a6e8f4d-b9fb-44f4-b086-12450939bf5c');
return $this->successResponse($result);
} catch (\Exception $exception) {
throw $exception;
}
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Services\Payments\DTO;
use Illuminate\Http\Request;
class PaymentCreateDTO
{
public string $username;
public int $user_id;
public string $amount;
public string $currency;
public string $callback_url;
public string $ip;
public int $user_gateway_id;
public function __construct(array $data)
{
$this->username = $data['username'];
$this->user_id = $data['user_id'];
$this->amount = $data['amount'];
$this->currency = $data['currency'];
$this->callback_url = $data['callback_url'];
$this->ip = $data['ip'];
$this->user_gateway_id = $data['user_gateway_id'];
}
public static function fromRequest(Request $request): PaymentCreateDTO
{
return new self([
'username' => $request->username,
'user_id' => '2',
'amount' => $request->amount,
'currency' => $request->currency,
'callback_url' => $request->callback_url,
'ip' => $request->getClientIp(),
'user_gateway_id' => $request->user_gateway_id,
]);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Services\Payments;
use App\Models\Payment;
use App\Services\FIB\CreatePaymentService;
use App\Services\FIB\FIBClient;
class FibAdapter
{
public function __construct(
private CreatePaymentService $create_payment_service,
private FIBClient $fib_client
)
{
}
public function createPayment(array $data)
{
Payment::query()->create([
'user_id' => auth()->id(),
'username' => $data['username'],
'track_id' => $data['track_id'],
'amount' => $data['amount'],
'currency' => $data['currency'],
'callback_url' => $data['callback_url'],
'expires_at' => $data['expires_at'],
'status_id' => $data['status_id'],
'status_name' => $data['status_name'],
'ip' => $data['ip'],
'user_gateway_id' => $data['user_gateway_id'],
'created_at' => $data['created_at'],
'updated_at' => $data['updated_at'],
]);
$this->fib_client->client();
}
}

View File

@@ -0,0 +1,176 @@
<?php
namespace App\Services\Payments;
use App\Enums\PaymentStatusEnum;
use App\Models\FibTransaction;
use App\Models\Payment;
use App\Models\Transaction;
use App\Models\UserGateway;
use App\Services\FIB\CheckPaymentStatusService;
use App\Services\FIB\CreatePaymentService;
use App\Services\FIB\DTO\FIBPaymentCreateDTO;
use App\Services\Payments\DTO\PaymentCreateDTO;
use Exception;
use Illuminate\Support\Facades\DB;
use Throwable;
class PaymentService
{
protected CreatePaymentService $create_payment_service;
protected CheckPaymentStatusService $check_payment_status_service;
public function __construct(
CreatePaymentService $create_payment_service,
CheckPaymentStatusService $check_payment_status_service
)
{
$this->create_payment_service = $create_payment_service;
$this->check_payment_status_service = $check_payment_status_service;
}
/**
* @throws Exception
* @throws Throwable
*/
public function createPayment(PaymentCreateDTO $dto)
{
$gateway = UserGateway::query()
->where('id', $dto->user_gateway_id)
->where('user_id', $dto->user_id)
->firstOrFail();
return DB::transaction(function () use ($dto, $gateway) {
$payment = Payment::query()->create([
'user_id' => $dto->user_id,
'username' => $dto->username,
'track_id' => $this->generateTrackId(),
'amount' => $dto->amount,
'currency' => $dto->currency,
'callback_url' => 'https://user_callback',
'status_id' => PaymentStatusEnum::UNPAID->value,
'status_name' => PaymentStatusEnum::UNPAID->name,
'ip' => $dto->ip,
'user_gateway_id' => $gateway->id,
]);
$this->create_payment_service->setInputParameters([
'monetaryValue' => [
'amount' => $dto->amount,
'currency' => $dto->currency,
],
'statusCallbackUrl' => 'https://ipay/api/fib_callback',
'description' => $dto->description ?? "Payment #{$payment->track_id}",
]);
$response = $this->create_payment_service->run();
$fib_response_dto = FIBPaymentCreateDTO::fromResponse($response);
$transaction = Transaction::query()->create([
'user_id' => $payment->user_id,
'amount' => $payment->amount,
'currency' => $payment->currency,
'callback_url' => $payment->callback_url,
// 'description' => '',
// 'expires_in' => '',
'payment_id' => $payment->id,
'payment_track_id' => $payment->track_id,
'user_gateway_id' => $payment->user_gateway_id,
// 'status' => '',
]);
FibTransaction::query()->create([
'transaction_id' => $transaction->id,
'qrcode' => $fib_response_dto->qrCode,
'readable_code' => $fib_response_dto->readableCode,
'personalAppLink' => $fib_response_dto->personalAppLink,
'businessAppLink' => $fib_response_dto->businessAppLink,
'corporateAppLink' => $fib_response_dto->corporateAppLink,
'paymentId' => $fib_response_dto->paymentId,
'paymentMethod' => 'fib',
'validUntil' => $fib_response_dto->validUntil,
'status_id' => PaymentStatusEnum::UNPAID->value,
'status_name' => PaymentStatusEnum::UNPAID->name,
]);
return [
'payment_id' => $payment->id,
'track_id' => $payment->track_id,
'qr_code' => $fib_response_dto->qrCode,
'readable_code' => $fib_response_dto->readableCode,
'personal_app_link' => $fib_response_dto->personalAppLink,
'business_app_link' => $fib_response_dto->businessAppLink,
'corporate_app_link' => $fib_response_dto->corporateAppLink,
'valid_until' => $fib_response_dto->validUntil,
'status' => PaymentStatusEnum::UNPAID->name,
];
});
}
private function generateTrackId(): string
{
do {
$id = uuid_create();
} while (Payment::query()->where('track_id', $id)->exists());
return $id;
}
public function checkPaymentStatus($track_id)
{
$user_id = auth()->id() ?? 2;
return Payment::query()->where('track_id', $track_id)
->where('user_id', $user_id)
->firstOrFail();
}
public function verifyPayment($track_id)
{
$user_id = auth()->id();
return DB::transaction(function () use ($track_id, $user_id) {
$payment = Payment::query()
->where('track_id', $track_id)
->where('user_id', $user_id)
->lockForUpdate()
->firstOrFail();
if ($payment->status_id == PaymentStatusEnum::PAID->value) {
return [
'status' => 'already_verified',
'paid' => true,
];
}
if ($payment->status_id !== PaymentStatusEnum::PendingVerification->value) {
return [
'status' => $payment->status_name,
'paid' => false,
];
}
$payment->update([
'status_id' => PaymentStatusEnum::PAID->value,
'status_name' => PaymentStatusEnum::PAID->name,
]);
Transaction::query()
->where('payment_id', $payment->id)
->update([
'status_id' => PaymentStatusEnum::PAID->value,
'status_name' => PaymentStatusEnum::PAID->name,
]);
return [
'status' => 'verified',
'paid' => true,
'track_id' => $payment->track_id,
'amount' => $payment->amount,
'currency' => $payment->currency,
];
});
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace App\Services\Payments;
use App\Enums\PaymentStatusEnum;
use App\Models\FibTransaction;
use App\Models\Payment;
use App\Models\Transaction;
use App\Services\FIB\CheckPaymentStatusService;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class SyncFibPaymentStatusService
{
public function __construct(
protected CheckPaymentStatusService $checkPaymentStatusService
)
{
}
public function run(): void
{
$fib_transactions = FibTransaction::query()
->whereIn('status_id', [
PaymentStatusEnum::UNPAID->value,
])
->with('transaction.payment')
->get();
foreach ($fib_transactions as $fib_transaction) {
try {
$this->syncOne($fib_transaction);
} catch (\Exception $e) {
Log::channel('fib_status')->error('Failed to sync fib transaction', [
'fib_transaction_id' => $fib_transaction->id,
'fib_payment_id' => $fib_transaction->paymentId,
'error' => $e->getMessage(),
]);
}
}
}
public function syncOne(FibTransaction $fib_transaction)
{
$fib_status_response = $this->checkPaymentStatusService->run($fib_transaction->paymentId);
if (!$fib_status_response['status']) {
Log::error('No status feild in fib ', []);
return false;
}
$mapped_status = $this->mapFibStatus($fib_status_response['status']);
// if ($mapped_status->value == $fib_transaction->status) {
// return;
// }
return DB::transaction(function () use ($fib_transaction, $fib_status_response, $mapped_status) {
$transaction = $fib_transaction->transaction;
$payment = $transaction->payment;
$fib_transaction->update([
'status_id' => $mapped_status->value,
'status_name' => $fib_transaction->status,
'paidAt' => $fib_status_response['paidAt'] ?? null,
'paidAmount' => $fib_status_response['amount']['amount'] ?? null,
'paidCurrency' => $fib_status_response['amount']['currency'] ?? null,
'decliningReason' => $fib_status_response['decliningReason'] ?? null,
'declinedAt' => $fib_status_response['declinedAt'] ?? null,
'paidByName' => $fib_status_response['paidBy']['name'] ?? null,
'paidByIban' => $fib_status_response['paidBy']['iban'] ?? null,
]);
$transaction->update([
'status_id' => $mapped_status->value,
'status_name' => $mapped_status->label(),
]);
if ($mapped_status === PaymentStatusEnum::PAID) {
$payment->update([
'status_id' => PaymentStatusEnum::PendingVerification->value,
'status_name' => PaymentStatusEnum::PendingVerification->label(),
'payment_method' => 'FIB',
'paid_currency' => $fib_transaction->paidCurrency,
'paid_amount' => $fib_transaction->paidAmount,
'paid_at' => $fib_transaction->paidAt,
]);
#------ has to implement ------
// $this->notifyMerchant($payment);
} else {
$payment->update([
'status_id' => $mapped_status->value,
'status_name' => $mapped_status->label(),
'paid_currency' => $fib_transaction->paidCurrency,
'paid_amount' => $fib_transaction->paidAmount,
'paid_at' => $fib_transaction->paidAt,
]);
}
return $payment;
});
}
protected function mapFibStatus(string $fib_status_response): PaymentStatusEnum
{
return match (strtoupper($fib_status_response)) {
'PAID' => PaymentStatusEnum::PAID,
'UNPAID' => PaymentStatusEnum::UNPAID,
'DECLINED' => PaymentStatusEnum::Cancelled,
'EXPIRED' => PaymentStatusEnum::Expired,
'REFUNDED' => PaymentStatusEnum::REFUNDED,
'REFUND_REQUESTED' => PaymentStatusEnum::REFUND_REQUESTED,
default => PaymentStatusEnum::UNPAID,
};
}
}

0
backend/app/User/Controllers/AuthController.php Normal file → Executable file
View File

View File

@@ -0,0 +1,24 @@
<?php
namespace App\User\Controllers;
use App\Http\Controllers\Controller;
use App\Models\City;
use App\Models\Province;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CityController extends Controller
{
use ApiResponse;
public function list(Request $request): JsonResponse
{
$cities = City::query()
->where('province_id', '=', $request->query('province_id'))
->get(['id', 'name']);
return $this->successResponse($cities);
}
}

View File

@@ -1,14 +0,0 @@
<?php
namespace App\User\Controllers\Dashboard;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ConfirmController extends Controller
{
public function index()
{
//
}
}

View File

@@ -1,24 +0,0 @@
<?php
namespace App\User\Controller\Dashboard;
use App\Http\Controllers\Controller;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class DocumentationController extends Controller
{
use ApiResponse;
public function store(StoreRequest $request): jsonResponse
{
//
}
public function update(UpdateRequest $request): JsonResponse
{
//
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace App\User\Controllers;
use App\Enums\BusinessTypeEnum;
use App\Facades\DataTable\DataTableFacade;
use App\Facades\File\FileFacade;
use App\Http\Controllers\Controller;
use App\Models\UserGateway;
use App\Traits\ApiResponse;
use App\User\Requests\Gateway\StoreRequest;
use App\User\Requests\Gateway\UpdateRequest;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Laravel\Passport\ClientRepository;
use Throwable;
class GatewayManagementController extends Controller
{
use ApiResponse;
public function index(Request $request)
{
return DataTableFacade::run(
UserGateway::query()->where('user_id', '=', Auth::guard('web')->user()->id),
$request,
allowedFilters: ['*'],
allowedSortings: ['*'],
allowedSelects: ['*'],
);
}
/**
* @throws Throwable
*/
public function store(StoreRequest $request): JsonResponse
{
$user = Auth::guard('web')->user();
$logo = $request->hasFile('logo')
? FileFacade::save($request->file('logo'), "{$user->id}")
: null;
$passportClient = DB::transaction(function () use ($user, $logo, $request) {
$clientName = "Gateway {$request->name} - User {$user->id}";
$client = app(ClientRepository::class)->createPasswordGrantClient($clientName, 'users');
UserGateway::query()->create([
'user_id' => $user->id,
'username' => $user->username,
'name' => $request->name,
'domain' => $request->domain,
'tax_id' => $request->tax_id,
'bank_name' => $request->bank_name,
'account_holder' => $request->account_holder,
'iban' => $request->iban,
'business_type_id' => $request->business_type_id,
'business_type_name' => BusinessTypeEnum::name($request->business_type_id),
'logo' => $logo,
'client_id' => $client->id,
'client_secret' => $client->secret,
]);
$user->update(['authority_level' => 1]);
return $client;
});
return $this->successResponse([
'client_id' => $passportClient->id,
'client_secret' => $passportClient->secret,
]);
}
public function show(UserGateway $gateway): JsonResponse
{
return $this->successResponse($gateway);
}
public function update(UpdateRequest $request, UserGateway $gateway): JsonResponse
{
$logo = null;
$user = Auth::guard('web')->user();
if ($request->has('logo'))
{
FileFacade::delete($gateway->logo, true);
$logo = FileFacade::save(request()->file('logo'), "{$user->id}");
}
$gateway->update([
'name' => $request->name,
'domain' => $request->domain,
'business_type_id' => $request->business_type_id,
'business_type_name' => BusinessTypeEnum::name($request->business_type_id),
'logo' => $logo,
]);
return $this->successResponse();
}
public function destroy(UserGateway $gateway): JsonResponse
{
$gateway->delete();
return $this->successResponse();
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace App\User\Controllers\Payment;
use App\Http\Controllers\Controller;
use App\Services\Payments\DTO\PaymentCreateDTO;
use App\Services\Payments\PaymentService;
use App\Traits\ApiResponse;
use App\User\Requests\Payment\FIB\InquiryRequest;
use App\User\Requests\Payment\FIB\StoreRequest;
use App\User\Resources\Payment\InquiryResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Js;
class PaymentController extends Controller
{
use ApiResponse;
public $payment_service;
public function __construct(PaymentService $payment_service)
{
$this->payment_service = $payment_service;
}
public function createPayment(StoreRequest $request): JsonResponse
{
try {
$dto = PaymentCreateDTO::fromRequest($request);
$result = $this->payment_service->createPayment($dto);
return $this->successResponse($result);
} catch (\Exception $exception) {
throw $exception;
}
}
public function InquiryTransaction(InquiryRequest $request): JsonResponse
{
try {
$result = $this->payment_service->checkPaymentStatus($request->track_id);
return $this->successResponse(new InquiryResource($result));
} catch (\Exception $exception) {
throw $exception;
}
}
public function verify()
{
}
}

46
backend/app/User/Controllers/ProfileController.php Normal file → Executable file
View File

@@ -2,14 +2,19 @@
namespace App\User\Controllers;
use App\Facades\File\FileFacade;
use App\Http\Controllers\Controller;
use App\Models\City;
use App\Models\Province;
use App\Traits\ApiResponse;
use App\User\Requests\Profile\ChangePasswordRequest;
use App\User\Requests\Profile\EditRequest;
use App\User\Resources\UserResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Throwable;
class ProfileController extends Controller
{
@@ -20,21 +25,40 @@ class ProfileController extends Controller
return $this->successResponse(new UserResource(Auth::user()));
}
/**
* @throws Throwable
*/
public function edit(EditRequest $request): JsonResponse
{
$user = Auth::user();
$province = Province::query()->find($request->province_id);
$city = City::query()->find($request->city_id);
$user->update([
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'national_id' => $request->national_id,
'address' => $request->address,
'postal_code' => $request->postal_code,
'phone_number' => $request->phone_number,
'province_id' => $request->province_id,
'city_id' => $request->city_id,
'status' => 1
]);
DB::transaction(function () use ($user, $province, $city, $request) {
if ($user->kyc_status == 0)
{
$user->documents()->create([
'title' => 'id_card',
'url' => FileFacade::save($request->file('id_card'), "{$user->id}/"),
]);
}
$user->update([
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'national_id' => $user->kyc_status == 0 ? $request->national_id : $user->national_id,
'address' => $request->address,
'postal_code' => $request->postal_code,
'phone_number' => $request->phone_number,
'province_id' => $province->id,
'province_name' => $province->name,
'city_id' => $city->id,
'city_name' => $city->name,
'birth_date' => $request->birth_date,
'email' => $request->email,
'kyc_status' => 1,
]);
});
return $this->successResponse();
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\User\Controllers;
use App\Http\Controllers\Controller;
use App\Models\Province;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
class ProvinceController extends Controller
{
use ApiResponse;
public function list(): JsonResponse
{
return $this->successResponse(Province::all(['id', 'name']));
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace App\User\Controllers\Transactions;
use App\Enums\PaymentStatusEnum;
use App\Facades\DataTable\DataTableFacade;
use App\Http\Controllers\Controller;
use App\Models\Payment;
use App\Models\Transaction;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class MerchantTransactionController extends Controller
{
use ApiResponse;
public function index(Request $request)
{
$merchantId = Auth::id();
$query = Transaction::query()
->select([
'transactions.id',
'transactions.amount',
'transactions.currency',
'transactions.status_id',
'transactions.created_at',
'payments.id',
'payments.payment_method',
'payments.paid_amount',
'payments.paid_currency',
'payments.paid_at',
'payments.status_name as payment_status',
'payments.status_id as payment_status_id',
'payments.verified_at',
'payments.refunded_at',
'payments.refund_reason',
'payments.track_id',
'user_gateways.name',
])
->join(
'payments',
'payments.id',
'=',
'transactions.payment_id'
)
->leftJoin(
'user_gateways',
'user_gateways.id',
'=',
'transactions.user_gateway_id'
)
->where('transactions.user_id', $merchantId);
return DataTableFacade::run(
$query,
$request,
allowedFilters: ['*'],
allowedSortings: ['*'],
allowedSelects: ['payments.id as payment_id', 'payments.track_id', 'payments.status_id as payment_status_id',
'payments.status_name as payment_status',
'payment_method', 'paid_amount', 'paid_currency', 'paid_at', 'payment_track_id',
'transactions.amount',
'transactions.currency',
'user_gateways.name as gateway_name',
'payments.verified_at',
'payments.refunded_at',
'payments.refund_reason',
]
);
}
public function stats(): JsonResponse
{
$merchantId = Auth::id();
$data = [
'total_transactions' => Payment::query()->where(
'user_id',
$merchantId
)->count(),
'successful_transactions' => Payment::query()->where(
'user_id',
$merchantId
)
->where('status_id', PaymentStatusEnum::PAID->value)
->count(),
'failed_transactions' => Payment::query()->where(
'user_id',
$merchantId
)
->whereIn('status_id', [
PaymentStatusEnum::Cancelled->value,
PaymentStatusEnum::Expired->value
])
->count(),
'total_paid_amount' => Payment::query()
->where('user_id', $merchantId)
->where(
'status_id',
PaymentStatusEnum::PendingVerification->value
)
->selectRaw('SUM(CAST(paid_amount AS DECIMAL(20,2))) as total')
->value('total'),
];
return $this->successResponse($data);
}
}

0
backend/app/User/Requests/Auth/LoginRequest.php Normal file → Executable file
View File

0
backend/app/User/Requests/Auth/RegisterRequest.php Normal file → Executable file
View File

View File

@@ -0,0 +1,37 @@
<?php
namespace App\User\Requests\Gateway;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
class StoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return Auth::guard('web')->user()->kyc_status;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array|string>
*/
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'domain' => 'required|string|max:255',
'tax_id' => 'required|string',
'bank_name' => 'required|string|max:255',
'account_holder' => 'required|string',
'iban' => 'required|string|max:255',
'logo' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
'business_type_id' => 'required|string|exists:business_types,id',
];
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\User\Requests\Gateway;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
class UpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return Auth::guard('web')->user()->kyc_status;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array|string>
*/
public function rules(): array
{
return [
'name' => 'required|string|max:255',
'domain' => 'required|string|max:255',
'business_type_id' => 'required|string|exists:business_types,id',
'logo' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\User\Requests\Payment\FIB;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
class InquiryRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array|string>
*/
public function rules(): array
{
return [
'track_id' => ['required', 'uuid'],
];
}
}

Some files were not shown because too many files have changed in this diff Show More