Compare commits

...

4 Commits

11 changed files with 132 additions and 65 deletions

View File

@@ -29,6 +29,16 @@ class DocumentationController extends Controller
);
}
public function show(User $user): JsonResponse
{
$data=User::query()
->with([
'gateway:id,user_id,domain,tax_id,bank_name,account_holder,logo',
'documents:id,documentable_id,documentable_type,title,url',
])->find($user);
return $this->successResponse($data);
}
public function files(User $user): JsonResponse
{
return $this->successResponse($user->load('documents'));

View File

@@ -7,7 +7,8 @@ use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Guarded;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
@@ -22,9 +23,13 @@ class User extends Authenticatable
use HasFactory, Notifiable, HasApiTokens;
protected $guarded = ['id'];
public function documents(): MorphToMany
public function documents(): MorphMany
{
return $this->morphToMany(Document::class, 'documentable');
return $this->morphMany(Document::class, 'documentable');
}
public function gateway(): HasOne
{
return $this->hasOne(UserGateway::class);
}
public function validateForPassportPasswordGrant(string $password): bool

View File

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

@@ -11,11 +11,13 @@ class CheckPaymentStatusService
{
protected string $url;
protected string $channelName;
protected AuthorizationService $authorizationService;
public function __construct()
public function __construct(AuthorizationService $authorizationService)
{
$this->url = config('fib.checkPaymentStatus.url');
$this->channelName = '';
$this->channelName = 'fib_status';
$this->authorizationService = $authorizationService;
}
/**
@@ -40,12 +42,26 @@ class CheckPaymentStatusService
/**
* @throws ConnectionException
* @throws Exception
*/
public function sendRequest(): array
{
return Http::throw()
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

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

@@ -1,6 +1,6 @@
<?php
namespace App\Services\Payments\DTO;
namespace App\Services\FIB\DTO;
class FIBPaymentCreateDTO
{

View File

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

@@ -6,22 +6,30 @@ use App\Enums\PaymentStatusEnum;
use App\Models\FibTransaction;
use App\Models\Payment;
use App\Models\Transaction;
use App\Services\FIB\FIBClient;
use App\Services\Payments\DTO\FIBPaymentCreateDTO;
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
{
public $fib_client;
protected CreatePaymentService $create_payment_service;
public function __construct()
public function __construct(CreatePaymentService $create_payment_service)
{
$this->fib_client = new FibClient();
$this->create_payment_service = $create_payment_service;
}
/**
* @throws Exception
* @throws Throwable
*/
public function createPayment(PaymentCreateDTO $dto)
{
try {
return DB::transaction(function () use ($dto) {
$payment = Payment::query()->create([
'user_id' => $dto->user_id,
'username' => $dto->username,
@@ -35,7 +43,7 @@ class PaymentService
'user_gateway_id' => $dto->user_gateway_id,
]);
$response = $this->fib_client->createPaymentService();
$response = $this->create_payment_service->run();
$fib_response_dto = FIBPaymentCreateDTO::fromResponse($response);
$transaction = Transaction::query()->create([
@@ -51,7 +59,7 @@ class PaymentService
// 'status' => '',
]);
$fib_transactions = FibTransaction::query()->create([
FibTransaction::query()->create([
'transaction_id' => $transaction->id,
'qrcode' => $fib_response_dto->qrCode,
'readable_code' => $fib_response_dto->readableCode,
@@ -64,9 +72,8 @@ class PaymentService
'status_id' => PaymentStatusEnum::Unpaid->value,
'status_name' => PaymentStatusEnum::Unpaid->name,
]);
return $payment;
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
}
});
}
}

View File

@@ -24,7 +24,7 @@ class GatewayManagementController extends Controller
public function index(Request $request)
{
return DataTableFacade::run(
UserGateway::query()->where('user_id', '=', Auth::guard('web')->id()),
UserGateway::query()->where('user_id', '=', Auth::guard('web')->user()->id),
$request,
allowedFilters: ['*'],
allowedSortings: ['*'],

View File

@@ -133,6 +133,24 @@ return [
'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',
],
],
];

View File

@@ -22,6 +22,7 @@ Route::prefix('documents')
->controller(DocumentationController::class)
->group(function () {
Route::get('/', 'index')->name('index');
Route::get('/{user}', 'show')->name('show');
Route::post('confirm/{user}', 'confirm')->name('confirm');
Route::post('reject/{user}', 'reject')->name('reject');
Route::get('files/{user}', 'files')->name('files');