From 77a4e980583e600ca265670d08e5049d7e6b9655 Mon Sep 17 00:00:00 2001 From: hasanzaki Date: Fri, 22 May 2026 16:28:10 +0330 Subject: [PATCH] stage things --- backend/app/Services/FIB/FIBClient.php | 54 +++++++++++++++++ backend/app/Services/Payments/FibAdapter.php | 37 ++++++++++++ .../app/Services/Payments/PaymentService.php | 37 ++++++++++++ .../Payment/DTO/PaymentCreateDTO.php | 58 +++++++++++++++++++ .../Controllers/Payment/PaymentController.php | 34 +++++++++++ backend/routes/api.php | 9 +++ docker-compose.yml | 6 +- 7 files changed, 232 insertions(+), 3 deletions(-) create mode 100755 backend/app/Services/FIB/FIBClient.php create mode 100644 backend/app/Services/Payments/FibAdapter.php create mode 100644 backend/app/Services/Payments/PaymentService.php create mode 100644 backend/app/User/Controllers/Payment/DTO/PaymentCreateDTO.php create mode 100644 backend/app/User/Controllers/Payment/PaymentController.php diff --git a/backend/app/Services/FIB/FIBClient.php b/backend/app/Services/FIB/FIBClient.php new file mode 100755 index 00000000..e96a7e9b --- /dev/null +++ b/backend/app/Services/FIB/FIBClient.php @@ -0,0 +1,54 @@ +contentType('application/json') + ->withToken($this->getAccessToken()) + ->timeout(30); + } + + public function getAccessToken(): string + { + try { + $response = Http::withOptions([ + 'proxy' => 'http://host.docker.internal:10808', + ])->asForm()->post('https://fib-stage.fib.iq/auth/realms/fib-online-shop/protocol/openid-connect/token', [ + 'grant_type' => 'client_credentials', + 'client_id' => 'ipay-test-payment', + 'client_secret' => '8dae3180-f39c-448e-8b45-a01c8f4c8c15', + ]); + + if ($response->failed()) { + throw new \Exception( + 'Unable to authenticate with FIB: ' . + $response->body() + ); + } + + $data = $response->json(); + + if (!isset($data['access_token'])) { + throw new \Exception('FIB token missing in response'); + } + + return $data['access_token']; + } catch (\Exception $exception) { + return $exception->getMessage(); + } + } +} diff --git a/backend/app/Services/Payments/FibAdapter.php b/backend/app/Services/Payments/FibAdapter.php new file mode 100644 index 00000000..0e6adb2b --- /dev/null +++ b/backend/app/Services/Payments/FibAdapter.php @@ -0,0 +1,37 @@ +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(); + } +} diff --git a/backend/app/Services/Payments/PaymentService.php b/backend/app/Services/Payments/PaymentService.php new file mode 100644 index 00000000..e5dd86fa --- /dev/null +++ b/backend/app/Services/Payments/PaymentService.php @@ -0,0 +1,37 @@ +fib_client = new FibClient(); + } + + public function createPayment(PaymentCreateDTO $dto) + { +// Payment::query()->create([ +// 'user_id' => $dto->user_id, +// 'username' => $dto->username, +// 'track_id' => $dto->track_id, +// 'amount' => $dto->amount, +// 'currency' => $dto->currency, +// 'callback_url' => $dto->callback_url, +// 'expires_at' => $dto->expires_at, +// 'status_id' => $dto->status_id, +// 'status_name' => $dto->status_name, +// 'ip' => $dto->ip, +// 'user_gateway_id' => $dto->user_gateway_id, +// 'created_at' => $dto->created_at, +// 'updated_at' => $dto->updated_at, +// ]); + return $this->fib_client->getAccessToken(); + } +} diff --git a/backend/app/User/Controllers/Payment/DTO/PaymentCreateDTO.php b/backend/app/User/Controllers/Payment/DTO/PaymentCreateDTO.php new file mode 100644 index 00000000..30725e34 --- /dev/null +++ b/backend/app/User/Controllers/Payment/DTO/PaymentCreateDTO.php @@ -0,0 +1,58 @@ +username = $data['username'] ?? null; + $this->user_id = $data['user_id'] ?? null; + $this->track_id = $data['track_id'] ?? null; + $this->amount = $data['amount'] ?? null; + $this->currency = $data['currency'] ?? null; + $this->callback_url = $data['callback_url'] ?? null; + $this->expires_at = $data['expires_at'] ?? null; + $this->status_id = $data['status_id'] ?? null; + $this->status_name = $data['status_name'] ?? null; + $this->ip = $data['ip'] ?? null; + $this->user_gateway_id = $data['user_gateway_id'] ?? null; + $this->created_at = $data['created_at'] ?? null; + $this->updated_at = $data['updated_at'] ?? null; + } + + public static function fromRequest(Request $request): PaymentCreateDTO + { + return new self([ + 'username' => $request->username ?? null, + 'track_id' => $request->track_id ?? null, + 'amount' => $request->amount ?? null, + 'currency' => $request->currency ?? null, + 'callback_url' => $request->callback_url ?? null, + 'expires_at' => $request->expires_at ?? null, + 'status_id' => $request->status_id ?? null, + 'status_name' => $request->status_name ?? null, + 'ip' => $request->ip ?? null, + 'user_gateway_id' => $request->user_gateway_id ?? null, + 'created_at' => $request->created_at ?? null, + 'updated_at' => $request->updated_at ?? null, + ]); + } +} diff --git a/backend/app/User/Controllers/Payment/PaymentController.php b/backend/app/User/Controllers/Payment/PaymentController.php new file mode 100644 index 00000000..4ec9251b --- /dev/null +++ b/backend/app/User/Controllers/Payment/PaymentController.php @@ -0,0 +1,34 @@ +payment_service = $payment_service; + } + + public function createPayment(Request $request): JsonResponse + { + try { + $dto = PaymentCreateDTO::fromRequest($request); + $result = $this->payment_service->createPayment($dto); + return $this->successResponse($result); + } catch (\Exception $exception) { + throw $exception; + } + } +} diff --git a/backend/routes/api.php b/backend/routes/api.php index f35f6f84..a511350e 100755 --- a/backend/routes/api.php +++ b/backend/routes/api.php @@ -1,8 +1,17 @@ user(); })->middleware('auth:api'); + +Route::prefix('v1')->group(function () { + Route::prefix('payment')->group(function () { + Route::get('/create_payment', [PaymentController::class, 'createPayment']); + }); + +}); diff --git a/docker-compose.yml b/docker-compose.yml index d21e5ef4..a93a5001 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,9 +40,7 @@ services: - payment backend: - build: - context: ${BACKEND_PATH} - dockerfile: Dockerfile + image: payment-backend:latest container_name: laravel tty: true restart: unless-stopped @@ -54,6 +52,8 @@ services: - postgres networks: - payment + command: ["php", "artisan", "serve", "--host=0.0.0.0", "--port=9000"] + # Prints "Overridden command!" # logging: # driver: "syslog" # options: