Skip to content

Commit 94aaf76

Browse files
authored
Prepare codebase for Vapor deployment (#351)
1 parent 3a43fb0 commit 94aaf76

File tree

50 files changed

+619
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+619
-123
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Deploy to Vapor Production
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- feat/vapor
8+
9+
jobs:
10+
vapor:
11+
name: Deploy to Vapor Production
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
# Step 1: Checkout the repository
16+
- uses: actions/checkout@v2
17+
18+
# Step 2: Setup PHP
19+
- name: Setup PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: 8.3
23+
tools: composer:v2
24+
coverage: none
25+
26+
# Step 3: Prepare Laravel Environment
27+
- name: Prepare Laravel Environment
28+
working-directory: ./backend
29+
run: |
30+
mkdir -p bootstrap/cache
31+
chmod -R 775 bootstrap/cache
32+
33+
# Step 4: Prepare HTMLPurifier Cache Directory
34+
- name: Prepare HTMLPurifier Cache Directory
35+
working-directory: ./backend
36+
run: |
37+
mkdir -p storage/app/htmlpurifier
38+
chmod -R 775 storage/app/htmlpurifier
39+
40+
# Step 5: Install Dependencies
41+
- name: Install Dependencies
42+
working-directory: ./backend
43+
run: composer install --no-dev --no-progress --no-scripts --optimize-autoloader
44+
45+
# Step 6: Install Vapor CLI
46+
- name: Install Vapor CLI
47+
run: composer global require laravel/vapor-cli
48+
49+
# Step 7: Log the branch being deployed (Optional enhancement)
50+
- name: Log Branch
51+
run: echo "Deploying branch ${{ github.ref_name }}"
52+
53+
# Step 8: Deploy to the Vapor Production Environment
54+
- name: Deploy to Production
55+
working-directory: ./backend
56+
run: vapor deploy production
57+
env:
58+
VAPOR_API_TOKEN: ${{ secrets.VAPOR_API_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
frontend/.env
77
backend/.env
88
todo.md
9+
10+
.vercel

backend/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ STRIPE_PUBLIC_KEY=
1616
STRIPE_SECRET_KEY=
1717
STRIPE_WEBHOOK_SECRET=
1818

19-
CORS_ALLOWED_ORIGINS=http://localhost:5173
19+
CORS_ALLOWED_ORIGINS=*
2020

2121
LOG_CHANNEL=stderr
2222
LOG_DEPRECATIONS_CHANNEL=null

backend/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
.env
99
.env.backup
1010
.env.production
11+
.env.staging
1112
.phpunit.result.cache
1213
Homestead.json
1314
Homestead.yaml

backend/app/Http/Actions/Common/Webhooks/StripeIncomingWebhookAction.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@
1212

1313
class StripeIncomingWebhookAction extends BaseAction
1414
{
15-
private IncomingWebhookHandler $webhookHandler;
16-
17-
public function __construct(IncomingWebhookHandler $webhookHandler)
18-
{
19-
$this->webhookHandler = $webhookHandler;
20-
}
21-
2215
public function __invoke(Request $request): Response
2316
{
2417
try {
25-
$this->webhookHandler->handle(new StripeWebhookDTO(
26-
headerSignature: $request->server('HTTP_STRIPE_SIGNATURE'),
27-
payload: $request->getContent(),
28-
));
18+
$headerSignature = $request->server('HTTP_STRIPE_SIGNATURE');
19+
$payload = $request->getContent();
20+
21+
dispatch(static function (IncomingWebhookHandler $handler) use ($headerSignature, $payload) {
22+
$handler->handle(new StripeWebhookDTO(
23+
headerSignature: $headerSignature,
24+
payload: $payload,
25+
));
26+
})->catch(function (Throwable $exception) use ($payload) {
27+
logger()->error(__('Failed to handle incoming Stripe webhook'), [
28+
'exception' => $exception,
29+
'payload' => $payload,
30+
]);
31+
});
32+
2933
} catch (Throwable $exception) {
3034
logger()?->error($exception->getMessage(), $exception->getTrace());
3135
return $this->noContentResponse(ResponseCodes::HTTP_BAD_REQUEST);

backend/app/Http/Actions/Orders/Public/CreateOrderActionPublic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function __invoke(CreateOrderRequest $request, int $eventId): JsonRespons
3838
$sessionId = $this->sessionIdentifierService->getSessionId();
3939

4040
$order = $this->orderHandler->handle(
41-
$eventId,
42-
CreateOrderPublicDTO::fromArray([
41+
eventId: $eventId,
42+
createOrderPublicDTO: CreateOrderPublicDTO::fromArray([
4343
'is_user_authenticated' => $this->isUserAuthenticated(),
4444
'promo_code' => $request->input('promo_code'),
4545
'products' => ProductOrderDetailsDTO::collectionFromArray($request->input('products')),

backend/app/Http/Actions/Products/GetProductAction.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
use HiEvents\DomainObjects\EventDomainObject;
88
use HiEvents\DomainObjects\Generated\ProductDomainObjectAbstract;
9-
use HiEvents\DomainObjects\TaxAndFeesDomainObject;
109
use HiEvents\DomainObjects\ProductPriceDomainObject;
10+
use HiEvents\DomainObjects\TaxAndFeesDomainObject;
1111
use HiEvents\Http\Actions\BaseAction;
1212
use HiEvents\Repository\Interfaces\ProductRepositoryInterface;
1313
use HiEvents\Resources\Product\ProductResource;
1414
use Illuminate\Http\JsonResponse;
15+
use Illuminate\Http\Response;
1516

1617
class GetProductAction extends BaseAction
1718
{
@@ -22,16 +23,22 @@ public function __construct(ProductRepositoryInterface $productRepository)
2223
$this->productRepository = $productRepository;
2324
}
2425

25-
public function __invoke(int $eventId, int $productId): JsonResponse
26+
public function __invoke(int $eventId, int $productId): JsonResponse|Response
2627
{
2728
$this->isActionAuthorized($eventId, EventDomainObject::class);
2829

29-
return $this->resourceResponse(ProductResource::class, $this->productRepository
30+
$product = $this->productRepository
3031
->loadRelation(TaxAndFeesDomainObject::class)
3132
->loadRelation(ProductPriceDomainObject::class)
3233
->findFirstWhere([
3334
ProductDomainObjectAbstract::EVENT_ID => $eventId,
3435
ProductDomainObjectAbstract::ID => $productId,
35-
]));
36+
]);
37+
38+
if ($product === null) {
39+
return $this->notFoundResponse();
40+
}
41+
42+
return $this->resourceResponse(ProductResource::class, $product);
3643
}
3744
}

backend/app/Services/Application/Handlers/Account/CreateAccountHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public function handle(CreateAccountDTO $accountData): AccountDomainObject
6060
// If the app is not running in SaaS mode, we can immediately verify the account.
6161
// Same goes for the email verification below.
6262
'account_verified_at' => $isSaasMode ? null : now()->toDateTimeString(),
63+
'configuration' => [
64+
'application_fee' => [
65+
'percentage' => config('app.saas_stripe_application_fee_percent'),
66+
'fixed' => config('app.saas_stripe_application_fee_fixed') ?? 0,
67+
],
68+
],
6369
]);
6470

6571
$user = $this->getExistingUser($accountData) ?? $this->userRepository->create([

backend/app/Services/Application/Handlers/Event/UpdateEventHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use HiEvents\Repository\Interfaces\EventRepositoryInterface;
1212
use HiEvents\Repository\Interfaces\OrderRepositoryInterface;
1313
use HiEvents\Services\Application\Handlers\Event\DTO\UpdateEventDTO;
14-
use HTMLPurifier;
14+
use HiEvents\Services\Infrastructure\HtmlPurifier\HtmlPurifierService;
1515
use Illuminate\Database\DatabaseManager;
1616
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
1717
use Throwable;
@@ -23,7 +23,7 @@ public function __construct(
2323
private Dispatcher $dispatcher,
2424
private DatabaseManager $databaseManager,
2525
private OrderRepositoryInterface $orderRepository,
26-
private HTMLPurifier $purifier,
26+
private HtmlPurifierService $purifier,
2727
)
2828
{
2929
}

backend/app/Services/Application/Handlers/EventSettings/UpdateEventSettingsHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
use HiEvents\DomainObjects\EventSettingDomainObject;
66
use HiEvents\Repository\Interfaces\EventSettingsRepositoryInterface;
77
use HiEvents\Services\Application\Handlers\EventSettings\DTO\UpdateEventSettingsDTO;
8-
use HTMLPurifier;
8+
use HiEvents\Services\Infrastructure\HtmlPurifier\HtmlPurifierService;
99
use Illuminate\Database\DatabaseManager;
1010
use Throwable;
1111

1212
readonly class UpdateEventSettingsHandler
1313
{
1414
public function __construct(
1515
private EventSettingsRepositoryInterface $eventSettingsRepository,
16-
private HTMLPurifier $purifier,
16+
private HtmlPurifierService $purifier,
1717
private DatabaseManager $databaseManager,
1818
)
1919
{

0 commit comments

Comments
 (0)