Compare commits
17 Commits
feature/Ge
...
feature/Fi
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d2e575d12 | |||
| 42d783da5c | |||
| 08b0cd4cca | |||
| 6db74f557b | |||
| 4eec548b83 | |||
| 675d2bdbad | |||
| 69ffe322ce | |||
| a1466d8f57 | |||
| 392fca8635 | |||
| 9a01a83370 | |||
| 8438655f8c | |||
| 5040299efc | |||
| 26a0f79a6d | |||
| 1b5d339a53 | |||
| c73d50d096 | |||
| 738b21e182 | |||
| 77a4e98058 |
@@ -16,19 +16,6 @@ class AuthController extends Controller
|
|||||||
{
|
{
|
||||||
use ApiResponse;
|
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
|
public function login(LoginRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$credentials = ['password' => $request->password];
|
$credentials = ['password' => $request->password];
|
||||||
@@ -39,8 +26,7 @@ class AuthController extends Controller
|
|||||||
$credentials['username'] = $request->login;
|
$credentials['username'] = $request->login;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Auth::attempt($credentials))
|
if (Auth::guard('expert')->attempt($credentials)) {
|
||||||
{
|
|
||||||
$request->session()->regenerate();
|
$request->session()->regenerate();
|
||||||
|
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class DocumentationController extends Controller
|
|||||||
public function index(Request $request): array
|
public function index(Request $request): array
|
||||||
{
|
{
|
||||||
return DataTableFacade::run(
|
return DataTableFacade::run(
|
||||||
User::query(),
|
User::query()->where('kyc_status','!=',0),
|
||||||
$request,
|
$request,
|
||||||
allowedFilters: ['*'],
|
allowedFilters: ['*'],
|
||||||
allowedSortings: ['*'],
|
allowedSortings: ['*'],
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ enum BusinessTypeEnum: int
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public function name($id): string
|
public static function name($id): string
|
||||||
{
|
{
|
||||||
$mapArray = [
|
$mapArray = [
|
||||||
1 => 'medical',
|
1 => 'medical',
|
||||||
|
|||||||
@@ -5,17 +5,19 @@ namespace App\Models;
|
|||||||
use Database\Factories\ExpertFactory;
|
use Database\Factories\ExpertFactory;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Spatie\Permission\Traits\HasRoles;
|
use Spatie\Permission\Traits\HasRoles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method roles()
|
* @method roles()
|
||||||
* @method permissions()
|
* @method permissions()
|
||||||
*/
|
*/
|
||||||
class Expert extends Model
|
class Expert extends Authenticatable
|
||||||
{
|
{
|
||||||
/** @use HasFactory<ExpertFactory> */
|
/** @use HasFactory<ExpertFactory> */
|
||||||
use HasFactory;
|
|
||||||
use HasRoles;
|
use Notifiable,HasFactory,HasRoles;
|
||||||
|
|
||||||
protected $guarded = ['id'];
|
protected $guarded = ['id'];
|
||||||
protected string $guard_name = 'web';
|
protected string $guard_name = 'web';
|
||||||
|
|||||||
@@ -9,4 +9,6 @@ class FibTransaction extends Model
|
|||||||
{
|
{
|
||||||
/** @use HasFactory<\Database\Factories\FibTransactionFactory> */
|
/** @use HasFactory<\Database\Factories\FibTransactionFactory> */
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = ['id'];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,21 +11,13 @@ class CancelPaymentService
|
|||||||
{
|
{
|
||||||
protected string $url;
|
protected string $url;
|
||||||
protected string $channelName;
|
protected string $channelName;
|
||||||
protected string $accessToken;
|
protected AuthorizationService $authorizationService;
|
||||||
protected array $headers;
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct(AuthorizationService $authorizationService)
|
||||||
{
|
{
|
||||||
$this->url = config('fib.cancelPayment.url');
|
$this->url = config('fib.cancelPayment.url');
|
||||||
$this->channelName = '';
|
$this->channelName = '';
|
||||||
}
|
$this->authorizationService = $authorizationService;
|
||||||
|
|
||||||
public function setHeaders(): void
|
|
||||||
{
|
|
||||||
$this->headers = [
|
|
||||||
'Authorization' => 'Bearer ' . $this->accessToken,
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,13 +42,26 @@ class CancelPaymentService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ConnectionException
|
* @throws ConnectionException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendRequest(): array
|
public function sendRequest(): array
|
||||||
{
|
{
|
||||||
return Http::withHeaders($this->headers)
|
return Http::withHeaders([
|
||||||
|
'Authorization' => 'Bearer ' . $this->getToken(),
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
])
|
||||||
->throw()
|
->throw()
|
||||||
->withoutVerifying()
|
->withoutVerifying()
|
||||||
->post($this->url)
|
->post($this->url)
|
||||||
->json();
|
->json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function getToken(): string
|
||||||
|
{
|
||||||
|
$data = $this->authorizationService->run();
|
||||||
|
return $data['access_token'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,13 @@ class CheckPaymentStatusService
|
|||||||
{
|
{
|
||||||
protected string $url;
|
protected string $url;
|
||||||
protected string $channelName;
|
protected string $channelName;
|
||||||
|
protected AuthorizationService $authorizationService;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct(AuthorizationService $authorizationService)
|
||||||
{
|
{
|
||||||
$this->url = config('fib.checkPaymentStatus.url');
|
$this->url = config('fib.checkPaymentStatus.url');
|
||||||
$this->channelName = '';
|
$this->channelName = 'fib_status';
|
||||||
|
$this->authorizationService = $authorizationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,12 +42,26 @@ class CheckPaymentStatusService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ConnectionException
|
* @throws ConnectionException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendRequest(): array
|
public function sendRequest(): array
|
||||||
{
|
{
|
||||||
return Http::throw()
|
return Http::withHeaders([
|
||||||
|
'Authorization' => 'Bearer ' . $this->getToken(),
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
])
|
||||||
|
->throw()
|
||||||
->withoutVerifying()
|
->withoutVerifying()
|
||||||
->post($this->url)
|
->post($this->url)
|
||||||
->json();
|
->json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function getToken(): string
|
||||||
|
{
|
||||||
|
$data = $this->authorizationService->run();
|
||||||
|
return $data['access_token'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,27 +11,14 @@ class CreatePaymentService
|
|||||||
{
|
{
|
||||||
protected string $url;
|
protected string $url;
|
||||||
protected string $channelName;
|
protected string $channelName;
|
||||||
protected string $accessToken;
|
|
||||||
protected array $headers;
|
|
||||||
protected array $inputParameters;
|
protected array $inputParameters;
|
||||||
|
protected AuthorizationService $authorizationService;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct(AuthorizationService $authorizationService)
|
||||||
{
|
{
|
||||||
$this->url = config('fib.createPayment.url');
|
$this->url = config('fib.createPayment.url');
|
||||||
$this->channelName = '';
|
$this->channelName = 'fib_create_payment';
|
||||||
}
|
$this->authorizationService = $authorizationService;
|
||||||
|
|
||||||
public function setAccessToken(string $accessToken): void
|
|
||||||
{
|
|
||||||
$this->accessToken = $accessToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setHeaders(): void
|
|
||||||
{
|
|
||||||
$this->headers = [
|
|
||||||
'Authorization' => 'Bearer ' . $this->accessToken,
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setInputParameters(array $inputParameters): void
|
public function setInputParameters(array $inputParameters): void
|
||||||
@@ -61,13 +48,26 @@ class CreatePaymentService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ConnectionException
|
* @throws ConnectionException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendRequest(): array
|
public function sendRequest(): array
|
||||||
{
|
{
|
||||||
return Http::withHeaders($this->headers)
|
return Http::withHeaders([
|
||||||
|
'Authorization' => 'Bearer ' . $this->getToken(),
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
])
|
||||||
->throw()
|
->throw()
|
||||||
->withoutVerifying()
|
->withoutVerifying()
|
||||||
->post($this->url, $this->inputParameters)
|
->post($this->url, $this->inputParameters)
|
||||||
->json();
|
->json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function getToken(): string
|
||||||
|
{
|
||||||
|
$data = $this->authorizationService->run();
|
||||||
|
return $data['access_token'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
backend/app/Services/FIB/DTO/FIBPaymentCreateDTO.php
Normal file
38
backend/app/Services/FIB/DTO/FIBPaymentCreateDTO.php
Normal 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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
86
backend/app/Services/FIB/FIBClient.php
Executable file
86
backend/app/Services/FIB/FIBClient.php
Executable file
@@ -0,0 +1,86 @@
|
|||||||
|
<?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()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if ($this->isNotProduction()) {
|
||||||
|
return json_decode(
|
||||||
|
file_get_contents(storage_path('app/mock/fib/token.json'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createPaymentService()
|
||||||
|
{
|
||||||
|
if ($this->isNotProduction()) {
|
||||||
|
return json_decode(
|
||||||
|
file_get_contents(storage_path('app/mock/fib/payment_create_success.json'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$response = $this->client()->post("https://fib-stage.fib.iq/protected/v1/payments");
|
||||||
|
if ($response->failed()) {
|
||||||
|
throw new \Exception(
|
||||||
|
'Unable to authenticate with FIB: ' .
|
||||||
|
$response->body()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $response->json();
|
||||||
|
if (!isset($data['paymentId'])) {
|
||||||
|
throw new \Exception('FIB paymentId missing in response');
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isNotProduction()
|
||||||
|
{
|
||||||
|
return env('APP_ENV') === 'local';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,21 +11,13 @@ class RefundService
|
|||||||
{
|
{
|
||||||
protected string $url;
|
protected string $url;
|
||||||
protected string $channelName;
|
protected string $channelName;
|
||||||
protected string $accessToken;
|
protected AuthorizationService $authorizationService;
|
||||||
protected array $headers;
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct(AuthorizationService $authorizationService)
|
||||||
{
|
{
|
||||||
$this->url = config('fib.refund.url');
|
$this->url = config('fib.refund.url');
|
||||||
$this->channelName = '';
|
$this->channelName = 'fib_refund';
|
||||||
}
|
$this->authorizationService = $authorizationService;
|
||||||
|
|
||||||
public function setHeaders(): void
|
|
||||||
{
|
|
||||||
$this->headers = [
|
|
||||||
'Authorization' => 'Bearer ' . $this->accessToken,
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,13 +42,26 @@ class RefundService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ConnectionException
|
* @throws ConnectionException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function sendRequest(): array
|
public function sendRequest(): array
|
||||||
{
|
{
|
||||||
return Http::withHeaders($this->headers)
|
return Http::withHeaders([
|
||||||
|
'Authorization' => 'Bearer ' . $this->getToken(),
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
])
|
||||||
->throw()
|
->throw()
|
||||||
->withoutVerifying()
|
->withoutVerifying()
|
||||||
->post($this->url)
|
->post($this->url)
|
||||||
->json();
|
->json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function getToken(): string
|
||||||
|
{
|
||||||
|
$data = $this->authorizationService->run();
|
||||||
|
return $data['access_token'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
46
backend/app/Services/Payments/DTO/PaymentCreateDTO.php
Normal file
46
backend/app/Services/Payments/DTO/PaymentCreateDTO.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Payments\DTO;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class PaymentCreateDTO
|
||||||
|
{
|
||||||
|
|
||||||
|
public string $username;
|
||||||
|
public int $user_id;
|
||||||
|
public string $track_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->track_id = $data['track_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',
|
||||||
|
'track_id' => uuid_create(),
|
||||||
|
'amount' => $request->amount,
|
||||||
|
'currency' => $request->currency,
|
||||||
|
'callback_url' => $request->callback_url,
|
||||||
|
'ip' => $request->getClientIp(),
|
||||||
|
'user_gateway_id' => $request->user_gateway_id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
backend/app/Services/Payments/FibAdapter.php
Normal file
37
backend/app/Services/Payments/FibAdapter.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
79
backend/app/Services/Payments/PaymentService.php
Normal file
79
backend/app/Services/Payments/PaymentService.php
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<?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\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;
|
||||||
|
|
||||||
|
public function __construct(CreatePaymentService $create_payment_service)
|
||||||
|
{
|
||||||
|
$this->create_payment_service = $create_payment_service;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
public function createPayment(PaymentCreateDTO $dto)
|
||||||
|
{
|
||||||
|
return DB::transaction(function () use ($dto) {
|
||||||
|
|
||||||
|
$payment = 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,
|
||||||
|
'status_id' => PaymentStatusEnum::Unpaid->value,
|
||||||
|
'status_name' => PaymentStatusEnum::Unpaid->name,
|
||||||
|
'ip' => $dto->ip,
|
||||||
|
'user_gateway_id' => $dto->user_gateway_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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ use Illuminate\Http\JsonResponse;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Laravel\Passport\ClientRepository;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class GatewayManagementController extends Controller
|
class GatewayManagementController extends Controller
|
||||||
@@ -23,11 +24,11 @@ class GatewayManagementController extends Controller
|
|||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
return DataTableFacade::run(
|
return DataTableFacade::run(
|
||||||
UserGateway::query()->where('user_id', '=', Auth::guard('web')->id()),
|
UserGateway::query()->where('user_id', '=', Auth::guard('web')->user()->id),
|
||||||
$request,
|
$request,
|
||||||
allowedFilters: ['*'],
|
allowedFilters: ['*'],
|
||||||
allowedSortings: ['*'],
|
allowedSortings: ['*'],
|
||||||
allowedSelects: ['id', 'name', 'domain', 'tax_id', 'bank_name', 'account_holder', 'iban', 'business_type_id', 'business_type_name'],
|
allowedSelects: ['*'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,9 +39,15 @@ class GatewayManagementController extends Controller
|
|||||||
{
|
{
|
||||||
$user = Auth::guard('web')->user();
|
$user = Auth::guard('web')->user();
|
||||||
|
|
||||||
$logo = $request->has('logo') ? FileFacade::save($request->file('logo'), "{$user->id}") : null;
|
$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');
|
||||||
|
|
||||||
DB::transaction(function () use ($user, $logo, $request) {
|
|
||||||
UserGateway::query()->create([
|
UserGateway::query()->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'username' => $user->username,
|
'username' => $user->username,
|
||||||
@@ -53,15 +60,20 @@ class GatewayManagementController extends Controller
|
|||||||
'business_type_id' => $request->business_type_id,
|
'business_type_id' => $request->business_type_id,
|
||||||
'business_type_name' => BusinessTypeEnum::name($request->business_type_id),
|
'business_type_name' => BusinessTypeEnum::name($request->business_type_id),
|
||||||
'logo' => $logo,
|
'logo' => $logo,
|
||||||
|
'client_id' => $client->id,
|
||||||
|
'client_secret' => $client->secret,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user->update(['authority_level' => 1]);
|
$user->update(['authority_level' => 1]);
|
||||||
|
|
||||||
|
return $client;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return $this->successResponse([
|
||||||
return $this->successResponse();
|
'client_id' => $passportClient->id,
|
||||||
|
'client_secret' => $passportClient->secret,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show(UserGateway $gateway): JsonResponse
|
public function show(UserGateway $gateway): JsonResponse
|
||||||
{
|
{
|
||||||
return $this->successResponse($gateway);
|
return $this->successResponse($gateway);
|
||||||
|
|||||||
35
backend/app/User/Controllers/Payment/PaymentController.php
Normal file
35
backend/app/User/Controllers/Payment/PaymentController.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?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\StoreRequest;
|
||||||
|
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(StoreRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$dto = PaymentCreateDTO::fromRequest($request);
|
||||||
|
$result = $this->payment_service->createPayment($dto);
|
||||||
|
return $this->successResponse($result);
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,7 +46,7 @@ class ProfileController extends Controller
|
|||||||
$user->update([
|
$user->update([
|
||||||
'first_name' => $request->first_name,
|
'first_name' => $request->first_name,
|
||||||
'last_name' => $request->last_name,
|
'last_name' => $request->last_name,
|
||||||
'national_id' => $request->national_id,
|
'national_id' => $user->kyc_status == 0 ? $request->national_id : $user->national_id,
|
||||||
'address' => $request->address,
|
'address' => $request->address,
|
||||||
'postal_code' => $request->postal_code,
|
'postal_code' => $request->postal_code,
|
||||||
'phone_number' => $request->phone_number,
|
'phone_number' => $request->phone_number,
|
||||||
|
|||||||
36
backend/app/User/Requests/Payment/FIB/StoreRequest.php
Normal file
36
backend/app/User/Requests/Payment/FIB/StoreRequest.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Requests\Payment\FIB;
|
||||||
|
|
||||||
|
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 true;
|
||||||
|
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 [
|
||||||
|
'username' => ['required'],
|
||||||
|
'track_id' => ['required'],
|
||||||
|
'amount' => ['required'],
|
||||||
|
'currency' => ['required'],
|
||||||
|
'callback_url' => ['required'],
|
||||||
|
'user_gateway_id' => ['required'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,12 +24,13 @@ class UserResource extends JsonResource
|
|||||||
'address' => $this->address,
|
'address' => $this->address,
|
||||||
'postal_code' => $this->postal_code,
|
'postal_code' => $this->postal_code,
|
||||||
'phone_number' => $this->phone_number,
|
'phone_number' => $this->phone_number,
|
||||||
'province_id' => $this->provonce_id,
|
'province_id' => $this->province_id,
|
||||||
'province_name' => $this->province_name,
|
'province_name' => $this->province_name,
|
||||||
'city_id' => $this->city_id,
|
'city_id' => $this->city_id,
|
||||||
'city_name' => $this->city_name,
|
'city_name' => $this->city_name,
|
||||||
'birth_date' => $this->birth_date,
|
'birth_date' => $this->birth_date,
|
||||||
'kyc_status' => $this->kyc_status,
|
'kyc_status' => $this->kyc_status,
|
||||||
|
'authority_level' => $this->authority_level,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Expert;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -133,6 +133,24 @@ return [
|
|||||||
'level' => 'error',
|
'level' => 'error',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'fib_create_payment' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/fib/createPayment.log'),
|
||||||
|
'level' => 'error',
|
||||||
|
],
|
||||||
|
|
||||||
|
'fib_status' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/fib/status.log'),
|
||||||
|
'level' => 'error',
|
||||||
|
],
|
||||||
|
|
||||||
|
'fib_refund' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/fib/refund.log'),
|
||||||
|
'level' => 'error',
|
||||||
|
],
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
||||||
@@ -14,15 +13,15 @@ return new class extends Migration
|
|||||||
Schema::create('transactions', function (Blueprint $table) {
|
Schema::create('transactions', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('user_id')->constrained('users');
|
$table->foreignId('user_id')->constrained('users');
|
||||||
$table->string('amount');
|
$table->string('amount')->nullable();
|
||||||
$table->string('currency');
|
$table->string('currency')->nullable();
|
||||||
$table->string('callback_url');
|
$table->string('callback_url')->nullable();
|
||||||
$table->string('description');
|
$table->string('description')->nullable();
|
||||||
$table->dateTime('expires_in');
|
$table->dateTime('expires_in')->nullable();
|
||||||
$table->foreignId('payment_id')->constrained('payments');
|
$table->foreignId('payment_id')->constrained('payments');
|
||||||
$table->string('payment_track_id');
|
$table->string('payment_track_id')->nullable();
|
||||||
$table->foreignId('user_gateway_id')->constrained('user_gateways');
|
$table->foreignId('user_gateway_id')->constrained('user_gateways');
|
||||||
$table->integer('status');
|
$table->integer('status')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration;
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*/
|
*/
|
||||||
@@ -14,23 +13,23 @@ return new class extends Migration
|
|||||||
Schema::create('fib_transactions', function (Blueprint $table) {
|
Schema::create('fib_transactions', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignId('transaction_id')->constrained('transactions');
|
$table->foreignId('transaction_id')->constrained('transactions');
|
||||||
$table->text('qrcode');
|
$table->text('qrcode')->nullable();
|
||||||
$table->string('readable_code');
|
$table->string('readable_code')->nullable();
|
||||||
$table->string('personalAppLink');
|
$table->string('personalAppLink')->nullable();
|
||||||
$table->string('businessAppLink');
|
$table->string('businessAppLink')->nullable();
|
||||||
$table->string('corporateAppLink');
|
$table->string('corporateAppLink')->nullable();
|
||||||
$table->string('paymentId');
|
$table->string('paymentId')->nullable();
|
||||||
$table->string('paymentMethod');
|
$table->string('paymentMethod')->nullable();
|
||||||
$table->timestamp('validUntil');
|
$table->timestamp('validUntil')->nullable();
|
||||||
$table->foreignId('status_id')->constrained('fib_transaction_statuses');
|
$table->foreignId('status_id')->constrained('fib_transaction_statuses');
|
||||||
$table->string('status_name');
|
$table->string('status_name')->nullable();
|
||||||
$table->timestamp('paidAt');
|
$table->timestamp('paidAt')->nullable();
|
||||||
$table->string('paidAmount');
|
$table->string('paidAmount')->nullable();
|
||||||
$table->string('paidCurrency');
|
$table->string('paidCurrency')->nullable();
|
||||||
$table->string('decliningReason');
|
$table->string('decliningReason')->nullable();
|
||||||
$table->timestamp('declinedAt');
|
$table->timestamp('declinedAt')->nullable();
|
||||||
$table->string('paidByName');
|
$table->string('paidByName')->nullable();
|
||||||
$table->string('paidByIban');
|
$table->string('paidByIban')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('user_gateways', function (Blueprint $table) {
|
||||||
|
$table->string('client_id')->nullable();
|
||||||
|
$table->string('client_secret')->nullable();
|
||||||
|
$table->integer('status')->default(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('user_gateways', function (Blueprint $table) {
|
||||||
|
$table->dropColumn(['client_id', 'client_secret','status']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -4,6 +4,7 @@ namespace Database\Seeders;
|
|||||||
|
|
||||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class FibTransactionStatusSeeder extends Seeder
|
class FibTransactionStatusSeeder extends Seeder
|
||||||
{
|
{
|
||||||
@@ -12,6 +13,12 @@ class FibTransactionStatusSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
//
|
DB::table('fib_transaction_statuses')->insert([
|
||||||
|
['id' => 0, 'name' => 'unpaid', 'created_at' => now(), 'updated_at' => now(),],
|
||||||
|
['id' => 1, 'name' => 'cancelled', 'created_at' => now(), 'updated_at' => now(),],
|
||||||
|
['id' => 2, 'name' => 'expired', 'created_at' => now(), 'updated_at' => now(),],
|
||||||
|
['id' => 3, 'name' => 'paid', 'created_at' => now(), 'updated_at' => now(),],
|
||||||
|
['id' => 4, 'name' => 'refunded', 'created_at' => now(), 'updated_at' => now(),],
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use \App\User\Controllers\Payment\PaymentController;
|
||||||
|
|
||||||
Route::get('/user', function (Request $request) {
|
Route::get('/user', function (Request $request) {
|
||||||
return $request->user();
|
return $request->user();
|
||||||
})->middleware('auth:api');
|
})->middleware('auth:api');
|
||||||
|
|
||||||
|
Route::prefix('v1')->group(function () {
|
||||||
|
Route::prefix('payment')
|
||||||
|
// ->middleware('auth:api')
|
||||||
|
->group(function () {
|
||||||
|
Route::post('/create_payment', [PaymentController::class, 'createPayment'])->name('create_payment');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ Route::prefix('auth')
|
|||||||
->name('auth.')
|
->name('auth.')
|
||||||
->controller(AuthController::class)
|
->controller(AuthController::class)
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::post('register', 'register')->name('register');
|
|
||||||
Route::post('login', 'login')->name('login');
|
Route::post('login', 'login')->name('login');
|
||||||
Route::post('logout', 'logout')->name('logout');
|
Route::post('logout', 'logout')->name('logout');
|
||||||
});
|
});
|
||||||
@@ -78,7 +77,7 @@ Route::prefix('expert')
|
|||||||
|
|
||||||
Route::prefix('profile')
|
Route::prefix('profile')
|
||||||
->name('profile.')
|
->name('profile.')
|
||||||
->middleware('auth')
|
->middleware('auth:expert')
|
||||||
->controller(ProfileController::class)
|
->controller(ProfileController::class)
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::get('info', 'info')->name('info');
|
Route::get('info', 'info')->name('info');
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ services:
|
|||||||
- payment
|
- payment
|
||||||
|
|
||||||
backend:
|
backend:
|
||||||
build:
|
image: payment-backend:latest
|
||||||
context: ${BACKEND_PATH}
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
container_name: laravel
|
container_name: laravel
|
||||||
tty: true
|
tty: true
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -54,6 +52,8 @@ services:
|
|||||||
- postgres
|
- postgres
|
||||||
networks:
|
networks:
|
||||||
- payment
|
- payment
|
||||||
|
command: ["php", "artisan", "serve", "--host=0.0.0.0", "--port=9000"]
|
||||||
|
# Prints "Overridden command!"
|
||||||
# logging:
|
# logging:
|
||||||
# driver: "syslog"
|
# driver: "syslog"
|
||||||
# options:
|
# options:
|
||||||
|
|||||||
Reference in New Issue
Block a user