Compare commits
1 Commits
1f8bd224a3
...
feature/Fo
| Author | SHA1 | Date | |
|---|---|---|---|
| 99d24c38c7 |
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Services\Auth\PasswordResetOtpService;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\RateLimiter;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class ForgotPasswordOtpController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly PasswordResetOtpService $otpService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function sendOtp(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'email' => ['required', 'email', 'exists:users,email'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$email = $validated['email'];
|
||||||
|
|
||||||
|
$key = 'user-forgot-password-otp:' . $email . ':' . $request->ip();
|
||||||
|
|
||||||
|
if (RateLimiter::tooManyAttempts($key, 3)) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'email' => ['Too many OTP requests. Please try again later.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
RateLimiter::hit($key, 600);
|
||||||
|
|
||||||
|
$user = User::query()->where('email', $email)->firstOrFail();
|
||||||
|
|
||||||
|
$this->otpService->sendOtp($user, 'user');
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'OTP sent to your email.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function verifyOtp(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'email' => ['required', 'email', 'exists:users,email'],
|
||||||
|
'otp' => ['required', 'digits:6'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->otpService->verifyOtp(
|
||||||
|
email: $validated['email'],
|
||||||
|
otp: $validated['otp'],
|
||||||
|
guard: 'user'
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'OTP verified successfully.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resetPassword(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'email' => ['required', 'email', 'exists:users,email'],
|
||||||
|
'password' => ['required', 'confirmed',],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$record = $this->otpService->ensureVerified(
|
||||||
|
email: $validated['email'],
|
||||||
|
guard: 'user'
|
||||||
|
);
|
||||||
|
|
||||||
|
$user = User::query()->where('email', $validated['email'])->firstOrFail();
|
||||||
|
|
||||||
|
$user->update([
|
||||||
|
'password' => Hash::make($validated['password']),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$record->delete();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'User password reset successfully.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Enums;
|
namespace App\Enums;
|
||||||
|
|
||||||
enum PaymentStatusEnum: int
|
enum PaymentStatusEnum:int
|
||||||
{
|
{
|
||||||
case Unpaid = 0;
|
case Unpaid = 0;
|
||||||
case Cancelled = 1;
|
case Cancelled = 1;
|
||||||
@@ -10,8 +10,6 @@ enum PaymentStatusEnum: int
|
|||||||
case Paid = 3;
|
case Paid = 3;
|
||||||
case Refunded = 4;
|
case Refunded = 4;
|
||||||
|
|
||||||
case PendingVerification = 5;
|
|
||||||
|
|
||||||
public function label(): string
|
public function label(): string
|
||||||
{
|
{
|
||||||
return match ($this) {
|
return match ($this) {
|
||||||
@@ -20,7 +18,6 @@ enum PaymentStatusEnum: int
|
|||||||
self::Expired => 'expired',
|
self::Expired => 'expired',
|
||||||
self::Paid => 'paid',
|
self::Paid => 'paid',
|
||||||
self::Refunded => 'refunded',
|
self::Refunded => 'refunded',
|
||||||
self::PendingVerification => 'pending_verification',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
backend/app/Models/PasswordResetOtp.php
Normal file
10
backend/app/Models/PasswordResetOtp.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class PasswordResetOtp extends Model
|
||||||
|
{
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ class User extends Authenticatable
|
|||||||
|
|
||||||
public function documents(): MorphToMany
|
public function documents(): MorphToMany
|
||||||
{
|
{
|
||||||
return $this->morphToMany(Document::class, 'documents');
|
return $this->morphToMany(Document::class, 'documentable');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateForPassportPasswordGrant(string $password): bool
|
public function validateForPassportPasswordGrant(string $password): bool
|
||||||
|
|||||||
32
backend/app/Notifications/ResetPasswordOtpNotification.php
Normal file
32
backend/app/Notifications/ResetPasswordOtpNotification.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
|
class ResetPasswordOtpNotification extends Notification
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly string $otp
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function via(object $notifiable): array
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toMail(object $notifiable): MailMessage
|
||||||
|
{
|
||||||
|
return (new MailMessage)
|
||||||
|
->subject('Reset Password OTP')
|
||||||
|
->greeting('Hello!')
|
||||||
|
->line('Your password reset code is:')
|
||||||
|
->line($this->otp)
|
||||||
|
->line('This code will expire in 10 minutes.')
|
||||||
|
->line('If you did not request password reset, ignore this email.');
|
||||||
|
}
|
||||||
|
}
|
||||||
103
backend/app/Services/Auth/PasswordResetOtpService.php
Normal file
103
backend/app/Services/Auth/PasswordResetOtpService.php
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Auth;
|
||||||
|
|
||||||
|
use App\Models\PasswordResetOtp;
|
||||||
|
use App\Notifications\ResetPasswordOtpNotification;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class PasswordResetOtpService
|
||||||
|
{
|
||||||
|
public function sendOtp(Model $user, string $guard = 'user'): void
|
||||||
|
{
|
||||||
|
$otp = (string) random_int(100000, 999999);
|
||||||
|
|
||||||
|
PasswordResetOtp::query()->where('email', $user->email)
|
||||||
|
->where('guard', $guard)
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
PasswordResetOtp::query()->create([
|
||||||
|
'email' => $user->email,
|
||||||
|
'guard' => $guard,
|
||||||
|
'otp' => Hash::make($otp),
|
||||||
|
'expires_at' => now()->addMinutes(10),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user->notify(new ResetPasswordOtpNotification($otp));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function verifyOtp(string $email, string $otp, string $guard = 'user'): void
|
||||||
|
{
|
||||||
|
$record = PasswordResetOtp::query()->where('email', $email)
|
||||||
|
->where('guard', $guard)
|
||||||
|
->latest()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $record) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'otp' => ['Invalid OTP.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($record->isExpired()) {
|
||||||
|
$record->delete();
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'otp' => ['OTP has expired.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($record->attempts >= 5) {
|
||||||
|
$record->delete();
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'otp' => ['Too many wrong attempts. Please request a new OTP.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! Hash::check($otp, $record->otp)) {
|
||||||
|
$record->increment('attempts');
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'otp' => ['Invalid OTP.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$record->update([
|
||||||
|
'verified_at' => now(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ensureVerified(string $email, string $guard = 'user'): PasswordResetOtp
|
||||||
|
{
|
||||||
|
$record = PasswordResetOtp::query()->where('email', $email)
|
||||||
|
->where('guard', $guard)
|
||||||
|
->latest()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $record || ! $record->isVerified()) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'otp' => ['Please verify OTP first.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($record->isExpired()) {
|
||||||
|
$record->delete();
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'otp' => ['OTP has expired.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteOtp(string $email, string $guard = 'user'): void
|
||||||
|
{
|
||||||
|
PasswordResetOtp::query()->where('email', $email)
|
||||||
|
->where('guard', $guard)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
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,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
|
||||||
{
|
{
|
||||||
@@ -26,13 +26,13 @@ class FIBPaymentCreateDTO
|
|||||||
public static function fromResponse($data): FIBPaymentCreateDTO
|
public static function fromResponse($data): FIBPaymentCreateDTO
|
||||||
{
|
{
|
||||||
return new self([
|
return new self([
|
||||||
'paymentId' => $data['paymentId'],
|
'paymentId' => $data->paymentId,
|
||||||
'readableCode' => $data['readableCode'],
|
'readableCode' => $data->readableCode,
|
||||||
'qrCode' => $data['qrCode'],
|
'qrCode' => $data->qrCode,
|
||||||
'validUntil' => $data['validUntil'],
|
'validUntil' => $data->validUntil,
|
||||||
'personalAppLink' => $data['personalAppLink'],
|
'personalAppLink' => $data->personalAppLink,
|
||||||
'businessAppLink' => $data['businessAppLink'],
|
'businessAppLink' => $data->businessAppLink,
|
||||||
'corporateAppLink' => $data['corporateAppLink'],
|
'corporateAppLink' => $data->corporateAppLink,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ class PaymentCreateDTO
|
|||||||
|
|
||||||
public string $username;
|
public string $username;
|
||||||
public int $user_id;
|
public int $user_id;
|
||||||
|
public string $track_id;
|
||||||
public string $amount;
|
public string $amount;
|
||||||
public string $currency;
|
public string $currency;
|
||||||
public string $callback_url;
|
public string $callback_url;
|
||||||
@@ -20,6 +21,7 @@ class PaymentCreateDTO
|
|||||||
{
|
{
|
||||||
$this->username = $data['username'];
|
$this->username = $data['username'];
|
||||||
$this->user_id = $data['user_id'];
|
$this->user_id = $data['user_id'];
|
||||||
|
$this->track_id = $data['track_id'];
|
||||||
$this->amount = $data['amount'];
|
$this->amount = $data['amount'];
|
||||||
$this->currency = $data['currency'];
|
$this->currency = $data['currency'];
|
||||||
$this->callback_url = $data['callback_url'];
|
$this->callback_url = $data['callback_url'];
|
||||||
@@ -33,6 +35,7 @@ class PaymentCreateDTO
|
|||||||
return new self([
|
return new self([
|
||||||
'username' => $request->username,
|
'username' => $request->username,
|
||||||
'user_id' => '2',
|
'user_id' => '2',
|
||||||
|
'track_id' => uuid_create(),
|
||||||
'amount' => $request->amount,
|
'amount' => $request->amount,
|
||||||
'currency' => $request->currency,
|
'currency' => $request->currency,
|
||||||
'callback_url' => $request->callback_url,
|
'callback_url' => $request->callback_url,
|
||||||
|
|||||||
@@ -6,66 +6,36 @@ 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\Models\UserGateway;
|
use App\Services\FIB\FIBClient;
|
||||||
use App\Services\FIB\CheckPaymentStatusService;
|
use App\Services\Payments\DTO\FIBPaymentCreateDTO;
|
||||||
use App\Services\FIB\CreatePaymentService;
|
|
||||||
use App\Services\FIB\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;
|
||||||
protected CheckPaymentStatusService $check_payment_status_service;
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
public function __construct(
|
|
||||||
CreatePaymentService $create_payment_service,
|
|
||||||
CheckPaymentStatusService $check_payment_status_service
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
$this->create_payment_service = $create_payment_service;
|
$this->fib_client = new FibClient();
|
||||||
$this->check_payment_status_service = $check_payment_status_service;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
* @throws Throwable
|
|
||||||
*/
|
|
||||||
public function createPayment(PaymentCreateDTO $dto)
|
public function createPayment(PaymentCreateDTO $dto)
|
||||||
{
|
{
|
||||||
$gateway = UserGateway::query()
|
try {
|
||||||
->where('id', $dto->user_gateway_id)
|
|
||||||
->where('user_id', $dto->user_id)
|
|
||||||
->firstOrFail();
|
|
||||||
|
|
||||||
return DB::transaction(function () use ($dto, $gateway) {
|
|
||||||
|
|
||||||
$payment = Payment::query()->create([
|
$payment = Payment::query()->create([
|
||||||
'user_id' => $dto->user_id,
|
'user_id' => $dto->user_id,
|
||||||
'username' => $dto->username,
|
'username' => $dto->username,
|
||||||
'track_id' => $this->generateTrackId(),
|
'track_id' => $dto->track_id,
|
||||||
'amount' => $dto->amount,
|
'amount' => $dto->amount,
|
||||||
'currency' => $dto->currency,
|
'currency' => $dto->currency,
|
||||||
'callback_url' => 'https://user_callback',
|
'callback_url' => $dto->callback_url,
|
||||||
'status_id' => PaymentStatusEnum::Unpaid->value,
|
'status_id' => PaymentStatusEnum::Unpaid->value,
|
||||||
'status_name' => PaymentStatusEnum::Unpaid->name,
|
'status_name' => PaymentStatusEnum::Unpaid->name,
|
||||||
'ip' => $dto->ip,
|
'ip' => $dto->ip,
|
||||||
'user_gateway_id' => $gateway->id,
|
'user_gateway_id' => $dto->user_gateway_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->create_payment_service->setInputParameters([
|
$response = $this->fib_client->createPaymentService();
|
||||||
'monetaryValue' => [
|
|
||||||
'amount' => $dto->amount,
|
|
||||||
'currency' => $dto->currency,
|
|
||||||
],
|
|
||||||
'statusCallbackUrl' => 'https://ipay/api/fib_callback',
|
|
||||||
'description' => $dto->description ?? "Payment #{$payment->track_id}",
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->create_payment_service->run();
|
|
||||||
$fib_response_dto = FIBPaymentCreateDTO::fromResponse($response);
|
$fib_response_dto = FIBPaymentCreateDTO::fromResponse($response);
|
||||||
|
|
||||||
$transaction = Transaction::query()->create([
|
$transaction = Transaction::query()->create([
|
||||||
@@ -73,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,
|
||||||
@@ -94,83 +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 [
|
} catch (\Exception $exception) {
|
||||||
'payment_id' => $payment->id,
|
throw new \Exception($exception->getMessage());
|
||||||
'track_id' => $payment->track_id,
|
}
|
||||||
'qr_code' => $fib_response_dto->qrCode,
|
|
||||||
'readable_code' => $fib_response_dto->readableCode,
|
|
||||||
'personal_app_link' => $fib_response_dto->personalAppLink,
|
|
||||||
'business_app_link' => $fib_response_dto->businessAppLink,
|
|
||||||
'corporate_app_link' => $fib_response_dto->corporateAppLink,
|
|
||||||
'valid_until' => $fib_response_dto->validUntil,
|
|
||||||
'status' => PaymentStatusEnum::Unpaid->name,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function generateTrackId(): string
|
|
||||||
{
|
|
||||||
do {
|
|
||||||
$id = uuid_create();
|
|
||||||
} while (Payment::query()->where('track_id', $id)->exists());
|
|
||||||
|
|
||||||
return $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkPaymentStatus($track_id)
|
|
||||||
{
|
|
||||||
$user_id = auth()->id();
|
|
||||||
return Payment::query()->where('track_id', $track_id)
|
|
||||||
->where('user_id', 2)
|
|
||||||
->firstOrFail();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function verifyPayment($track_id)
|
|
||||||
{
|
|
||||||
$user_id = auth()->id();
|
|
||||||
return DB::transaction(function () use ($track_id, $user_id) {
|
|
||||||
|
|
||||||
$payment = Payment::query()
|
|
||||||
->where('track_id', $track_id)
|
|
||||||
->where('user_id', $user_id)
|
|
||||||
->lockForUpdate()
|
|
||||||
->firstOrFail();
|
|
||||||
|
|
||||||
if ($payment->status_id === PaymentStatusEnum::Paid->value) {
|
|
||||||
return [
|
|
||||||
'status' => 'already_verified',
|
|
||||||
'paid' => true,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($payment->status_id !== PaymentStatusEnum::PendingVerification->value) {
|
|
||||||
return [
|
|
||||||
'status' => $payment->status_name,
|
|
||||||
'paid' => false,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$payment->update([
|
|
||||||
'status_id' => PaymentStatusEnum::Paid->value,
|
|
||||||
'status_name' => PaymentStatusEnum::Paid->name,
|
|
||||||
]);
|
|
||||||
|
|
||||||
Transaction::query()
|
|
||||||
->where('payment_id', $payment->id)
|
|
||||||
->update([
|
|
||||||
'status_id' => PaymentStatusEnum::Paid->value,
|
|
||||||
'status_name' => PaymentStatusEnum::Paid->name,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'status' => 'verified',
|
|
||||||
'paid' => true,
|
|
||||||
'track_id' => $payment->track_id,
|
|
||||||
'amount' => $payment->amount,
|
|
||||||
'currency' => $payment->currency,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
89
backend/app/User/Controllers/ForgotPasswordOtpController.php
Normal file
89
backend/app/User/Controllers/ForgotPasswordOtpController.php
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\User\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Expert;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Services\Auth\PasswordResetOtpService;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\RateLimiter;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class ForgotPasswordOtpController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly PasswordResetOtpService $otpService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function sendOtp(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'email' => ['required', 'email', 'exists:experts,email'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$email = $validated['email'];
|
||||||
|
|
||||||
|
$key = 'expert-forgot-password-otp:' . $email . ':' . $request->ip();
|
||||||
|
|
||||||
|
if (RateLimiter::tooManyAttempts($key, 3)) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'email' => ['Too many OTP requests. Please try again later.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
RateLimiter::hit($key, 600);
|
||||||
|
|
||||||
|
$expert = Expert::query()->where('email', $email)->firstOrFail();
|
||||||
|
|
||||||
|
$this->otpService->sendOtp($expert, 'expert');
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'OTP sent to your email.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function verifyOtp(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'email' => ['required', 'email', 'exists:experts,email'],
|
||||||
|
'otp' => ['required', 'digits:6'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->otpService->verifyOtp(
|
||||||
|
email: $validated['email'],
|
||||||
|
otp: $validated['otp'],
|
||||||
|
guard: 'expert'
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'OTP verified successfully.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resetPassword(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'email' => ['required', 'email', 'exists:experts,email'],
|
||||||
|
'password' => ['required', 'confirmed'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$record = $this->otpService->ensureVerified(
|
||||||
|
email: $validated['email'],
|
||||||
|
guard: 'expert'
|
||||||
|
);
|
||||||
|
|
||||||
|
$expert = Expert::query()->where('email', $validated['email'])->firstOrFail();
|
||||||
|
|
||||||
|
$expert->update([
|
||||||
|
'password' => Hash::make($validated['password']),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$record->delete();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Expert password reset successfully.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,6 @@ 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
|
||||||
@@ -24,11 +23,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')->user()->id),
|
UserGateway::query()->where('user_id', '=', Auth::guard('web')->id()),
|
||||||
$request,
|
$request,
|
||||||
allowedFilters: ['*'],
|
allowedFilters: ['*'],
|
||||||
allowedSortings: ['*'],
|
allowedSortings: ['*'],
|
||||||
allowedSelects: ['*'],
|
allowedSelects: ['id', 'name', 'domain', 'tax_id', 'bank_name', 'account_holder', 'iban', 'business_type_id', 'business_type_name'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,15 +38,9 @@ class GatewayManagementController extends Controller
|
|||||||
{
|
{
|
||||||
$user = Auth::guard('web')->user();
|
$user = Auth::guard('web')->user();
|
||||||
|
|
||||||
$logo = $request->hasFile('logo')
|
$logo = $request->has('logo') ? FileFacade::save($request->file('logo'), "{$user->id}") : null;
|
||||||
? 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,
|
||||||
@@ -60,20 +53,15 @@ 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([
|
|
||||||
'client_id' => $passportClient->id,
|
return $this->successResponse();
|
||||||
'client_secret' => $passportClient->secret,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show(UserGateway $gateway): JsonResponse
|
public function show(UserGateway $gateway): JsonResponse
|
||||||
{
|
{
|
||||||
return $this->successResponse($gateway);
|
return $this->successResponse($gateway);
|
||||||
|
|||||||
@@ -6,12 +6,9 @@ use App\Http\Controllers\Controller;
|
|||||||
use App\Services\Payments\DTO\PaymentCreateDTO;
|
use App\Services\Payments\DTO\PaymentCreateDTO;
|
||||||
use App\Services\Payments\PaymentService;
|
use App\Services\Payments\PaymentService;
|
||||||
use App\Traits\ApiResponse;
|
use App\Traits\ApiResponse;
|
||||||
use App\User\Requests\Payment\FIB\InquiryRequest;
|
|
||||||
use App\User\Requests\Payment\FIB\StoreRequest;
|
use App\User\Requests\Payment\FIB\StoreRequest;
|
||||||
use App\User\Resources\Payment\InquiryResource;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Js;
|
|
||||||
|
|
||||||
|
|
||||||
class PaymentController extends Controller
|
class PaymentController extends Controller
|
||||||
@@ -35,20 +32,4 @@ class PaymentController extends Controller
|
|||||||
throw $exception;
|
throw $exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkPaymentStatus(InquiryRequest $request): JsonResponse
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$result = $this->payment_service->checkPaymentStatus($request->track_id);
|
|
||||||
return $this->successResponse(new InquiryResource($result));
|
|
||||||
} catch (\Exception $exception) {
|
|
||||||
throw $exception;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function verify()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\User\Requests\Payment\FIB;
|
|
||||||
|
|
||||||
use Illuminate\Contracts\Validation\ValidationRule;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
|
|
||||||
class InquiryRequest extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*/
|
|
||||||
public function authorize(): bool
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, ValidationRule|array|string>
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'track_id' => ['required', 'uuid'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,12 +25,12 @@ class StoreRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'username' => ['required', 'string'],
|
'username' => ['required'],
|
||||||
|
'track_id' => ['required'],
|
||||||
'amount' => ['required'],
|
'amount' => ['required'],
|
||||||
'currency' => ['required', 'string'],
|
'currency' => ['required'],
|
||||||
'callback_url' => ['required'],
|
'callback_url' => ['required'],
|
||||||
'user_gateway_id' => ['required', 'integer', 'exists:user_gateways,id'],
|
'user_gateway_id' => ['required'],
|
||||||
'description' => ['nullable', 'string', 'max:500'],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\User\Resources\Payment;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
|
||||||
|
|
||||||
class InquiryResource extends JsonResource
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Transform the resource into an array.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
"track_id" => $this->track_id,
|
|
||||||
"amount" => $this->amount,
|
|
||||||
"currency" => $this->currency,
|
|
||||||
"status_id" => $this->status_id,
|
|
||||||
"status_name" => $this->status_name,
|
|
||||||
'payment_method' => $this->payment_method,
|
|
||||||
'paid_currency' => $this->paid_currency,
|
|
||||||
'paid_amount' => $this->paid_amount,
|
|
||||||
'paid_at' => $this->paid_at,
|
|
||||||
'verified_at' => $this->verified_at,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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',
|
|
||||||
],
|
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -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::create('password_reset_otps', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('email')->index();
|
||||||
|
$table->string('otp');
|
||||||
|
$table->string('guard_name');
|
||||||
|
$table->timestamp('expires_at');
|
||||||
|
$table->timestamp('verified_at')->nullable();
|
||||||
|
$table->unsignedTinyInteger('attempts')->default(0);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('password_reset_otps');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<?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']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<?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('payments', function (Blueprint $table) {
|
|
||||||
$table->string('payment_method')->nullable();
|
|
||||||
$table->string('paid_currency')->nullable();
|
|
||||||
$table->string('paid_amount')->nullable();
|
|
||||||
$table->timestamp('paid_at')->nullable();
|
|
||||||
$table->timestamp('verified_at')->nullable();
|
|
||||||
$table->timestamp('refunded_at')->nullable();
|
|
||||||
$table->string('refund_reason')->nullable();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('payments', function (Blueprint $table) {
|
|
||||||
$table->dropColumn(['payment_method', 'paid_currency', 'paid_amount',
|
|
||||||
'paid_at', 'verified_at', 'refunded_at', 'refund_reason',]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -14,8 +14,6 @@ Route::prefix('v1')->group(function () {
|
|||||||
// ->middleware('auth:api')
|
// ->middleware('auth:api')
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::post('/create_payment', [PaymentController::class, 'createPayment'])->name('create_payment');
|
Route::post('/create_payment', [PaymentController::class, 'createPayment'])->name('create_payment');
|
||||||
Route::post('/inquiry', [PaymentController::class, 'checkPaymentStatus'])->name('inquiry');
|
|
||||||
Route::post('/verify', [PaymentController::class, 'checkPaymentStatus'])->name('inquiry');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ Route::prefix('expert')
|
|||||||
|
|
||||||
Route::prefix('profile')
|
Route::prefix('profile')
|
||||||
->name('profile.')
|
->name('profile.')
|
||||||
->middleware('auth:expert')
|
->middleware('auth')
|
||||||
->controller(ProfileController::class)
|
->controller(ProfileController::class)
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::get('info', 'info')->name('info');
|
Route::get('info', 'info')->name('info');
|
||||||
|
|||||||
Reference in New Issue
Block a user