Compare commits
1 Commits
feature/Fi
...
feature/Ge
| Author | SHA1 | Date | |
|---|---|---|---|
| c08d8eaf3b |
@@ -29,16 +29,6 @@ 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
|
public function files(User $user): JsonResponse
|
||||||
{
|
{
|
||||||
return $this->successResponse($user->load('documents'));
|
return $this->successResponse($user->load('documents'));
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ use Database\Factories\UserFactory;
|
|||||||
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
@@ -23,13 +22,9 @@ class User extends Authenticatable
|
|||||||
use HasFactory, Notifiable, HasApiTokens;
|
use HasFactory, Notifiable, HasApiTokens;
|
||||||
protected $guarded = ['id'];
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
public function documents(): MorphMany
|
public function documents(): MorphToMany
|
||||||
{
|
{
|
||||||
return $this->morphMany(Document::class, 'documentable');
|
return $this->morphToMany(Document::class, 'documentable');
|
||||||
}
|
|
||||||
public function gateway(): HasOne
|
|
||||||
{
|
|
||||||
return $this->hasOne(UserGateway::class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateForPassportPasswordGrant(string $password): bool
|
public function validateForPassportPasswordGrant(string $password): bool
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Database\Factories\UserGatewayFactory;
|
use Database\Factories\UserGatewayFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
class UserGateway extends Model
|
class UserGateway extends Model
|
||||||
{
|
{
|
||||||
@@ -12,4 +14,11 @@ class UserGateway extends Model
|
|||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $guarded = ['id'];
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
|
protected function logo(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: fn($value) => $value == null ? null : Storage::disk('public')->url($value)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,21 @@ class CancelPaymentService
|
|||||||
{
|
{
|
||||||
protected string $url;
|
protected string $url;
|
||||||
protected string $channelName;
|
protected string $channelName;
|
||||||
protected AuthorizationService $authorizationService;
|
protected string $accessToken;
|
||||||
|
protected array $headers;
|
||||||
|
|
||||||
public function __construct(AuthorizationService $authorizationService)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$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',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,26 +50,13 @@ class CancelPaymentService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ConnectionException
|
* @throws ConnectionException
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function sendRequest(): array
|
public function sendRequest(): array
|
||||||
{
|
{
|
||||||
return Http::withHeaders([
|
return Http::withHeaders($this->headers)
|
||||||
'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,13 +11,11 @@ class CheckPaymentStatusService
|
|||||||
{
|
{
|
||||||
protected string $url;
|
protected string $url;
|
||||||
protected string $channelName;
|
protected string $channelName;
|
||||||
protected AuthorizationService $authorizationService;
|
|
||||||
|
|
||||||
public function __construct(AuthorizationService $authorizationService)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->url = config('fib.checkPaymentStatus.url');
|
$this->url = config('fib.checkPaymentStatus.url');
|
||||||
$this->channelName = 'fib_status';
|
$this->channelName = '';
|
||||||
$this->authorizationService = $authorizationService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,26 +40,12 @@ class CheckPaymentStatusService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ConnectionException
|
* @throws ConnectionException
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function sendRequest(): array
|
public function sendRequest(): array
|
||||||
{
|
{
|
||||||
return Http::withHeaders([
|
return Http::throw()
|
||||||
'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,14 +11,27 @@ 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(AuthorizationService $authorizationService)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->url = config('fib.createPayment.url');
|
$this->url = config('fib.createPayment.url');
|
||||||
$this->channelName = 'fib_create_payment';
|
$this->channelName = '';
|
||||||
$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
|
||||||
@@ -48,26 +61,13 @@ class CreatePaymentService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ConnectionException
|
* @throws ConnectionException
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function sendRequest(): array
|
public function sendRequest(): array
|
||||||
{
|
{
|
||||||
return Http::withHeaders([
|
return Http::withHeaders($this->headers)
|
||||||
'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'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,21 @@ class RefundService
|
|||||||
{
|
{
|
||||||
protected string $url;
|
protected string $url;
|
||||||
protected string $channelName;
|
protected string $channelName;
|
||||||
protected AuthorizationService $authorizationService;
|
protected string $accessToken;
|
||||||
|
protected array $headers;
|
||||||
|
|
||||||
public function __construct(AuthorizationService $authorizationService)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->url = config('fib.refund.url');
|
$this->url = config('fib.refund.url');
|
||||||
$this->channelName = 'fib_refund';
|
$this->channelName = '';
|
||||||
$this->authorizationService = $authorizationService;
|
}
|
||||||
|
|
||||||
|
public function setHeaders(): void
|
||||||
|
{
|
||||||
|
$this->headers = [
|
||||||
|
'Authorization' => 'Bearer ' . $this->accessToken,
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,26 +50,13 @@ class RefundService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ConnectionException
|
* @throws ConnectionException
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function sendRequest(): array
|
public function sendRequest(): array
|
||||||
{
|
{
|
||||||
return Http::withHeaders([
|
return Http::withHeaders($this->headers)
|
||||||
'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'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\FIB\DTO;
|
namespace App\Services\Payments\DTO;
|
||||||
|
|
||||||
class FIBPaymentCreateDTO
|
class FIBPaymentCreateDTO
|
||||||
{
|
{
|
||||||
@@ -6,30 +6,22 @@ use App\Enums\PaymentStatusEnum;
|
|||||||
use App\Models\FibTransaction;
|
use App\Models\FibTransaction;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\Transaction;
|
use App\Models\Transaction;
|
||||||
use App\Services\FIB\CreatePaymentService;
|
use App\Services\FIB\FIBClient;
|
||||||
use App\Services\FIB\DTO\FIBPaymentCreateDTO;
|
use App\Services\Payments\DTO\FIBPaymentCreateDTO;
|
||||||
use App\Services\Payments\DTO\PaymentCreateDTO;
|
use App\Services\Payments\DTO\PaymentCreateDTO;
|
||||||
use Exception;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Throwable;
|
|
||||||
|
|
||||||
class PaymentService
|
class PaymentService
|
||||||
{
|
{
|
||||||
protected CreatePaymentService $create_payment_service;
|
public $fib_client;
|
||||||
|
|
||||||
public function __construct(CreatePaymentService $create_payment_service)
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->create_payment_service = $create_payment_service;
|
$this->fib_client = new FibClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
* @throws Throwable
|
|
||||||
*/
|
|
||||||
public function createPayment(PaymentCreateDTO $dto)
|
public function createPayment(PaymentCreateDTO $dto)
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($dto) {
|
try {
|
||||||
|
|
||||||
$payment = Payment::query()->create([
|
$payment = Payment::query()->create([
|
||||||
'user_id' => $dto->user_id,
|
'user_id' => $dto->user_id,
|
||||||
'username' => $dto->username,
|
'username' => $dto->username,
|
||||||
@@ -43,7 +35,7 @@ class PaymentService
|
|||||||
'user_gateway_id' => $dto->user_gateway_id,
|
'user_gateway_id' => $dto->user_gateway_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $this->create_payment_service->run();
|
$response = $this->fib_client->createPaymentService();
|
||||||
$fib_response_dto = FIBPaymentCreateDTO::fromResponse($response);
|
$fib_response_dto = FIBPaymentCreateDTO::fromResponse($response);
|
||||||
|
|
||||||
$transaction = Transaction::query()->create([
|
$transaction = Transaction::query()->create([
|
||||||
@@ -51,15 +43,15 @@ class PaymentService
|
|||||||
'amount' => $payment->amount,
|
'amount' => $payment->amount,
|
||||||
'currency' => $payment->currency,
|
'currency' => $payment->currency,
|
||||||
'callback_url' => $payment->callback_url,
|
'callback_url' => $payment->callback_url,
|
||||||
// 'description' => '',
|
// 'description' => '',
|
||||||
// 'expires_in' => '',
|
// 'expires_in' => '',
|
||||||
'payment_id' => $payment->id,
|
'payment_id' => $payment->id,
|
||||||
'payment_track_id' => $payment->track_id,
|
'payment_track_id' => $payment->track_id,
|
||||||
'user_gateway_id' => $payment->user_gateway_id,
|
'user_gateway_id' => $payment->user_gateway_id,
|
||||||
// 'status' => '',
|
// 'status' => '',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
FibTransaction::query()->create([
|
$fib_transactions = FibTransaction::query()->create([
|
||||||
'transaction_id' => $transaction->id,
|
'transaction_id' => $transaction->id,
|
||||||
'qrcode' => $fib_response_dto->qrCode,
|
'qrcode' => $fib_response_dto->qrCode,
|
||||||
'readable_code' => $fib_response_dto->readableCode,
|
'readable_code' => $fib_response_dto->readableCode,
|
||||||
@@ -72,8 +64,9 @@ class PaymentService
|
|||||||
'status_id' => PaymentStatusEnum::Unpaid->value,
|
'status_id' => PaymentStatusEnum::Unpaid->value,
|
||||||
'status_name' => PaymentStatusEnum::Unpaid->name,
|
'status_name' => PaymentStatusEnum::Unpaid->name,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $payment;
|
return $payment;
|
||||||
});
|
} catch (\Exception $exception) {
|
||||||
|
throw new \Exception($exception->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ 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')->user()->id),
|
UserGateway::query()->where('user_id', '=', Auth::guard('web')->id()),
|
||||||
$request,
|
$request,
|
||||||
allowedFilters: ['*'],
|
allowedFilters: ['*'],
|
||||||
allowedSortings: ['*'],
|
allowedSortings: ['*'],
|
||||||
@@ -40,13 +40,17 @@ class GatewayManagementController extends Controller
|
|||||||
$user = Auth::guard('web')->user();
|
$user = Auth::guard('web')->user();
|
||||||
|
|
||||||
$logo = $request->hasFile('logo')
|
$logo = $request->hasFile('logo')
|
||||||
? FileFacade::save($request->file('logo'), "{$user->id}")
|
? FileFacade::save($request->file('logo'), "user_gateway/{$user->id}")
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
$passportClient = DB::transaction(function () use ($user, $logo, $request) {
|
$passportClient = DB::transaction(function () use ($user, $logo, $request) {
|
||||||
|
|
||||||
$clientName = "Gateway {$request->name} - User {$user->id}";
|
$clientName = "Gateway {$request->name} - User {$user->id}";
|
||||||
$client = app(ClientRepository::class)->createPasswordGrantClient($clientName, 'users');
|
$client = app(ClientRepository::class)->createPasswordGrantClient($clientName, 'users', true);
|
||||||
|
$client->Fill([
|
||||||
|
'owner_type' => get_class($user),
|
||||||
|
'owner_id' => $user->id,
|
||||||
|
])->save();
|
||||||
|
|
||||||
UserGateway::query()->create([
|
UserGateway::query()->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ class StoreRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return Auth::guard('web')->user()->kyc_status;
|
return true; }
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the validation rules that apply to the request.
|
* Get the validation rules that apply to the request.
|
||||||
|
|||||||
@@ -133,24 +133,6 @@ 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',
|
|
||||||
],
|
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ Route::prefix('documents')
|
|||||||
->controller(DocumentationController::class)
|
->controller(DocumentationController::class)
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::get('/', 'index')->name('index');
|
Route::get('/', 'index')->name('index');
|
||||||
Route::get('/{user}', 'show')->name('show');
|
|
||||||
Route::post('confirm/{user}', 'confirm')->name('confirm');
|
Route::post('confirm/{user}', 'confirm')->name('confirm');
|
||||||
Route::post('reject/{user}', 'reject')->name('reject');
|
Route::post('reject/{user}', 'reject')->name('reject');
|
||||||
Route::get('files/{user}', 'files')->name('files');
|
Route::get('files/{user}', 'files')->name('files');
|
||||||
|
|||||||
Reference in New Issue
Block a user