stage things

This commit is contained in:
2026-05-22 16:28:10 +03:30
parent 01bae8474b
commit 77a4e98058
7 changed files with 232 additions and 3 deletions

View File

@@ -0,0 +1,54 @@
<?php
namespace App\Services\FIB;
use Illuminate\Support\Facades\Http;
class FIBClient
{
public $auth_service;
public $create_payment_service;
public function __construct()
{
}
public function client()
{
return Http::acceptJson()
->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();
}
}
}

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,37 @@
<?php
namespace App\Services\Payments;
use App\Models\Payment;
use App\Services\FIB\FIBClient;
use App\User\Controllers\Payment\DTO\PaymentCreateDTO;
class PaymentService
{
public $fib_client;
public function __construct()
{
$this->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();
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\User\Controllers\Payment\DTO;
use Illuminate\Http\Request;
class PaymentCreateDTO
{
public ?string $username;
public ?int $user_id;
public ?int $track_id;
public ?string $amount;
public ?string $currency;
public ?string $callback_url;
public ?string $expires_at;
public ?int $status_id;
public ?string $status_name;
public ?string $ip;
public ?int $user_gateway_id;
public ?string $created_at;
public ?string $updated_at;
public function __construct(array $data)
{
$this->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,
]);
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\User\Controllers\Payment;
use App\Http\Controllers\Controller;
use App\Services\Payments\PaymentService;
use App\Traits\ApiResponse;
use App\User\Controllers\Payment\DTO\PaymentCreateDTO;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class PaymentController extends Controller
{
use ApiResponse;
public $payment_service;
public function __construct(PaymentService $payment_service)
{
$this->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;
}
}
}

View File

@@ -1,8 +1,17 @@
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use \App\User\Controllers\Payment\PaymentController;
Route::get('/user', function (Request $request) {
return $request->user();
})->middleware('auth:api');
Route::prefix('v1')->group(function () {
Route::prefix('payment')->group(function () {
Route::get('/create_payment', [PaymentController::class, 'createPayment']);
});
});

View File

@@ -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: