Compare commits

...

7 Commits

35 changed files with 1714 additions and 100 deletions

View File

@@ -1,28 +1,36 @@
FROM docker.arvancloud.ir/dunglas/frankenphp:1.11.2-php8.5-trixie
FROM php:8.5.3-fpm-alpine3.23
RUN apt-get update \
&& apt-get install -y --no-install-recommends libpq-dev \
# Install common PHP extension dependencies
RUN apk update && apk add --no-cache \
bash \
curl \
libpng \
libpng-dev \
libjpeg-turbo-dev \
freetype-dev \
libwebp-dev \
libxml2-dev \
unzip \
zip \
&& install-php-extensions pdo_pgsql pgsql \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
libzip-dev \
libpq-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
&& docker-php-ext-install pdo_pgsql gd zip
# Set the working directory
WORKDIR /var/www/payment
#ENV SERVER_NAME=your-domain-name.example.com
# Copy Laravel application
COPY . .
# Give permissions to storage and bootstrap/cache
RUN chmod -R 777 storage bootstrap/cache
RUN chmod -R 775 /var/www/payment/storage /var/www/payment/bootstrap/cache
# Install Composer
COPY --from=docker.arvancloud.ir/composer:latest /usr/bin/composer /usr/bin/composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER=1
CMD composer install;\
php artisan key:generate;\
php artisan migrate;\
php artisan db:seed;\
frankenphp php-server -r public/
# Default command
CMD composer install ;\
composer dump-autoload --optimize --classmap-authoritative ;\
php artisan key:generate ;\
php artisan migrate ;\
php artisan db:seed ;\
php-fpm

View File

@@ -14,19 +14,28 @@ COPY . .
RUN composer dump-autoload --optimize --classmap-authoritative
FROM docker.arvancloud.ir/dunglas/frankenphp:1.11.2-php8.5-trixie AS application
FROM php:8.5.3-fpm-alpine3.23 AS application
RUN apt-get update \
&& apt-get install -y --no-install-recommends libpq-dev unzip zip \
&& install-php-extensions pdo_pgsql pgsql \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN apk update && apk add --no-cache \
bash \
curl \
libpng \
libpng-dev \
libjpeg-turbo-dev \
freetype-dev \
libwebp-dev \
libxml2-dev \
unzip \
libzip-dev \
libpq-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
&& docker-php-ext-install pdo_pgsql gd zip
WORKDIR /var/www/payment
COPY --from=builder /app /var/www/payment
RUN chown -R www-data:www-data /var/www/payment \
&& chmod -R 775 storage bootstrap/cache
&& chmod -R 665 storage bootstrap/cache
CMD ["frankenphp", "php-server", "-r", "public/"]
CMD ["php-fpm"]

View File

@@ -9,13 +9,14 @@ use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
#[Fillable(['name', 'email', 'password'])]
#[Hidden(['password', 'remember_token'])]
class User extends Authenticatable
{
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable;
use HasFactory, Notifiable, HasApiTokens;
/**
* Get the attributes that should be cast.

View File

@@ -3,6 +3,7 @@
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Laravel\Passport\Passport;
class AppServiceProvider extends ServiceProvider
{
@@ -19,6 +20,6 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot(): void
{
//
Passport::enablePasswordGrant();
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace App\User\Services\FIB;
use Exception;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class AuthorizationService
{
protected string $url;
protected string $channelName;
protected array $inputParameters;
public function __construct()
{
$this->url = config('fib.authorization.url');
$this->channelName = '';
}
public function setInputParameters(): void
{
$this->inputParameters = [
'client_id' => config('fib.authorization.client_id'),
'client_secret' => config('fib.authorization.client_secret'),
'grant_type' => 'client_credentials',
];
}
/**
* @throws Exception
*/
public function run(): array
{
try {
return $this->sendRequest();
}
catch (Exception $e) {
Log::channel($this->channelName)
->error(get_class($this),
[
'message' => $e->getMessage(),
]
);
throw $e;
}
}
/**
* @throws ConnectionException
*/
public function sendRequest(): array
{
return Http::withHeaders(['Content-Type' => 'application/json'])
->throw()
->withoutVerifying()
->post($this->url, $this->inputParameters)
->json();
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace App\User\Services\FIB;
use Exception;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class CancelPaymentService
{
protected string $url;
protected string $channelName;
protected string $accessToken;
protected array $headers;
public function __construct()
{
$this->url = config('fib.cancelPayment.url');
$this->channelName = '';
}
public function setHeaders(): void
{
$this->headers = [
'Authorization' => 'Bearer ' . $this->accessToken,
'Content-Type' => 'application/json',
];
}
/**
* @throws Exception
*/
public function run(): array
{
try {
return $this->sendRequest();
}
catch (Exception $e) {
Log::channel($this->channelName)
->error(get_class($this),
[
'message' => $e->getMessage(),
]
);
throw $e;
}
}
/**
* @throws ConnectionException
*/
public function sendRequest(): array
{
return Http::withHeaders($this->headers)
->throw()
->withoutVerifying()
->post($this->url)
->json();
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace App\User\Services\FIB;
use Exception;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class CheckPaymentStatusService
{
protected string $url;
protected string $channelName;
public function __construct()
{
$this->url = config('fib.checkPaymentStatus.url');
$this->channelName = '';
}
/**
* @throws Exception
*/
public function run(): array
{
try {
return $this->sendRequest();
}
catch (Exception $e) {
Log::channel($this->channelName)
->error(get_class($this),
[
'message' => $e->getMessage(),
]
);
throw $e;
}
}
/**
* @throws ConnectionException
*/
public function sendRequest(): array
{
return Http::throw()
->withoutVerifying()
->post($this->url)
->json();
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace App\User\Services\FIB;
use Exception;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class CreatePaymentService
{
protected string $url;
protected string $channelName;
protected string $accessToken;
protected array $headers;
protected array $inputParameters;
public function __construct()
{
$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',
];
}
public function setInputParameters(array $inputParameters): void
{
$this->inputParameters = $inputParameters;
}
/**
* @throws Exception
*/
public function run(): array
{
try {
return $this->sendRequest();
}
catch (Exception $e) {
Log::channel($this->channelName)
->error(get_class($this),
[
'message' => $e->getMessage(),
]
);
throw $e;
}
}
/**
* @throws ConnectionException
*/
public function sendRequest(): array
{
return Http::withHeaders($this->headers)
->throw()
->withoutVerifying()
->post($this->url, $this->inputParameters)
->json();
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace App\User\Services\FIB;
use Exception;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class RefundService
{
protected string $url;
protected string $channelName;
protected string $accessToken;
protected array $headers;
public function __construct()
{
$this->url = config('fib.refund.url');
$this->channelName = '';
}
public function setHeaders(): void
{
$this->headers = [
'Authorization' => 'Bearer ' . $this->accessToken,
'Content-Type' => 'application/json',
];
}
/**
* @throws Exception
*/
public function run(): array
{
try {
return $this->sendRequest();
}
catch (Exception $e) {
Log::channel($this->channelName)
->error(get_class($this),
[
'message' => $e->getMessage(),
]
);
throw $e;
}
}
/**
* @throws ConnectionException
*/
public function sendRequest(): array
{
return Http::withHeaders($this->headers)
->throw()
->withoutVerifying()
->post($this->url)
->json();
}
}

View File

@@ -7,6 +7,7 @@ use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)

0
backend/bootstrap/cache/.gitignore vendored Normal file → Executable file
View File

View File

@@ -11,6 +11,7 @@
"require": {
"php": "^8.3",
"laravel/framework": "^13.0",
"laravel/passport": "^13.0",
"laravel/tinker": "^3.0"
},
"require-dev": {
@@ -86,4 +87,4 @@
},
"minimum-stability": "stable",
"prefer-stable": true
}
}

1010
backend/composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -42,6 +42,10 @@ return [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
/*

25
backend/config/fib.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
return [
'authorization' => [
'url' => env('FIB_AUTHORIZATION_URL'),
'client_id' => env('FIB_CLIENT_ID'),
'client_secret' => env('FIB_CLIENT_SECRET'),
],
'createPayment' => [
'url' => env('FIB_CREATE_PAYMENT_URL'),
],
'checkPaymentStatus' => [
'url' => env('FIB_CHECK_PAYMENT_STATUS_URL'),
],
'cancelPayment' => [
'url' => env('FIB_CANCEL_PAYMENT_URL'),
],
'refund' => [
'url' => env('FIB_REFUND_URL'),
],
];

View File

@@ -0,0 +1,48 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Passport Guard
|--------------------------------------------------------------------------
|
| Here you may specify which authentication guard Passport will use when
| authenticating users. This value should correspond with one of your
| guards that is already present in your "auth" configuration file.
|
*/
'guard' => 'web',
'middleware' => [],
/*
|--------------------------------------------------------------------------
| Encryption Keys
|--------------------------------------------------------------------------
|
| Passport uses encryption keys while generating secure access tokens for
| your application. By default, the keys are stored as local files but
| can be set via environment variables when that is more convenient.
|
*/
'private_key' => env('PASSPORT_PRIVATE_KEY'),
'public_key' => env('PASSPORT_PUBLIC_KEY'),
/*
|--------------------------------------------------------------------------
| Passport Database Connection
|--------------------------------------------------------------------------
|
| By default, Passport's models will utilize your application's default
| database connection. If you wish to use a different connection you
| may specify the configured name of the database connection here.
|
*/
'connection' => env('PASSPORT_CONNECTION'),
];

View File

@@ -0,0 +1,39 @@
<?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('oauth_auth_codes', function (Blueprint $table) {
$table->char('id', 80)->primary();
$table->foreignId('user_id')->index();
$table->foreignUuid('client_id');
$table->text('scopes')->nullable();
$table->boolean('revoked');
$table->dateTime('expires_at')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('oauth_auth_codes');
}
/**
* Get the migration connection name.
*/
public function getConnection(): ?string
{
return $this->connection ?? config('passport.connection');
}
};

View File

@@ -0,0 +1,41 @@
<?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('oauth_access_tokens', function (Blueprint $table) {
$table->char('id', 80)->primary();
$table->foreignId('user_id')->nullable()->index();
$table->foreignUuid('client_id');
$table->string('name')->nullable();
$table->text('scopes')->nullable();
$table->boolean('revoked');
$table->timestamps();
$table->dateTime('expires_at')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('oauth_access_tokens');
}
/**
* Get the migration connection name.
*/
public function getConnection(): ?string
{
return $this->connection ?? config('passport.connection');
}
};

View File

@@ -0,0 +1,37 @@
<?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('oauth_refresh_tokens', function (Blueprint $table) {
$table->char('id', 80)->primary();
$table->char('access_token_id', 80)->index();
$table->boolean('revoked');
$table->dateTime('expires_at')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('oauth_refresh_tokens');
}
/**
* Get the migration connection name.
*/
public function getConnection(): ?string
{
return $this->connection ?? config('passport.connection');
}
};

View File

@@ -0,0 +1,42 @@
<?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('oauth_clients', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->nullableMorphs('owner');
$table->string('name');
$table->string('secret')->nullable();
$table->string('provider')->nullable();
$table->text('redirect_uris');
$table->text('grant_types');
$table->boolean('revoked');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('oauth_clients');
}
/**
* Get the migration connection name.
*/
public function getConnection(): ?string
{
return $this->connection ?? config('passport.connection');
}
};

View File

@@ -0,0 +1,42 @@
<?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('oauth_device_codes', function (Blueprint $table) {
$table->char('id', 80)->primary();
$table->foreignId('user_id')->nullable()->index();
$table->foreignUuid('client_id')->index();
$table->char('user_code', 8)->unique();
$table->text('scopes');
$table->boolean('revoked');
$table->dateTime('user_approved_at')->nullable();
$table->dateTime('last_polled_at')->nullable();
$table->dateTime('expires_at')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('oauth_device_codes');
}
/**
* Get the migration connection name.
*/
public function getConnection(): ?string
{
return $this->connection ?? config('passport.connection');
}
};

8
backend/routes/api.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::get('/user', function (Request $request) {
return $request->user();
})->middleware('auth:api');

0
backend/storage/app/.gitignore vendored Normal file → Executable file
View File

0
backend/storage/app/private/.gitignore vendored Normal file → Executable file
View File

0
backend/storage/app/public/.gitignore vendored Normal file → Executable file
View File

0
backend/storage/framework/.gitignore vendored Normal file → Executable file
View File

0
backend/storage/framework/cache/.gitignore vendored Normal file → Executable file
View File

0
backend/storage/framework/cache/data/.gitignore vendored Normal file → Executable file
View File

0
backend/storage/framework/sessions/.gitignore vendored Normal file → Executable file
View File

0
backend/storage/framework/testing/.gitignore vendored Normal file → Executable file
View File

0
backend/storage/framework/views/.gitignore vendored Normal file → Executable file
View File

0
backend/storage/logs/.gitignore vendored Normal file → Executable file
View File

View File

@@ -1,60 +0,0 @@
services:
postgres:
image: docker.arvancloud.ir/postgres:17.8-alpine3.23
container_name: pgsql
restart: unless-stopped
ports:
- "8091:5432"
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- payment-db:/var/lib/postgresql/data
networks:
- payment
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 30s
timeout: 10s
retries: 3
backend:
build:
context: ${BACKEND_PATH}
dockerfile: Dockerfile.production
container_name: laravel
tty: true
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:80"]
interval: 30s
timeout: 10s
retries: 3
ports:
- "8003:80"
- "443:443"
- "443:443/udp"
volumes:
- ${BACKEND_PATH}:/var/www/${PROJECT_NAME}
depends_on:
- postgres
networks:
- payment
logging:
driver: "syslog"
options:
syslog-address: "tcp://host.docker.internal:514"
tag: "laravel-backend"
syslog-facility: "daemon"
max-size: "10m"
mem_limit: 512M
cpus: 1
volumes:
payment-db:
driver: local
networks:
payment:
driver: bridge

View File

@@ -1,14 +1,39 @@
services:
postgres:
image: docker.arvancloud.ir/postgres:17.8-alpine3.23
container_name: pgsql
nginx:
image: nginx:stable-alpine3.23-perl
container_name: nginx
restart: unless-stopped
ports:
- "8091:5432"
- "8000:80"
volumes:
- ./nginx/payment.conf:/etc/nginx/conf.d/default.conf
- ${BACKEND_PATH}:/var/www/${PROJECT_NAME}
networks:
- payment
redis:
image: redis:8.6.0-alpine3.23
container_name: redis
restart: unless-stopped
tty: true
networks:
- payment
postgres:
image: postgres:18.2-alpine3.23
container_name: payment-db
restart: unless-stopped
ports:
- "8092:5432"
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}" ]
interval: 30s
timeout: 10s
retries: 3
volumes:
- payment-db:/var/lib/postgresql/data
networks:
@@ -22,17 +47,22 @@ services:
tty: true
restart: unless-stopped
ports:
- "8003:80"
- "443:443"
- "443:443/udp"
- "9000:9000"
volumes:
- ${BACKEND_PATH}:/var/www/${PROJECT_NAME}
# - caddy_data:/data
# - caddy_config:/config
depends_on:
- postgres
networks:
- payment
# logging:
# driver: "syslog"
# options:
# syslog-address: "tcp://host.docker.internal:514"
# tag: "laravel-backend"
# syslog-facility: "daemon"
# max-size: "10m"
# mem_limit: 512M
# cpus: 1
volumes:
payment-db:

21
nginx/payment.conf Normal file
View File

@@ -0,0 +1,21 @@
server {
listen 80;
listen [::]:80;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/index\.php(/|$) {
include fastcgi_params;
fastcgi_pass laravel:9000;
fastcgi_index index.php;
fastcgi_hide_header X-Powered-By;
fastcgi_param SCRIPT_FILENAME /var/www/payment/public/index.php;
}
location ~ /\.(?!well-known).* {
deny all;
}
}