Skip to content

Commit 3577bed

Browse files
committed
Add account configuration
1 parent eb723cb commit 3577bed

File tree

15 files changed

+210
-24
lines changed

15 files changed

+210
-24
lines changed

backend/app/DomainObjects/AccountDomainObject.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
namespace HiEvents\DomainObjects;
44

5+
use HiEvents\DomainObjects\DTO\AccountApplicationFeeDTO;
6+
57
class AccountDomainObject extends Generated\AccountDomainObjectAbstract
68
{
9+
public function getApplicationFee(): AccountApplicationFeeDTO
10+
{
11+
$applicationFee = $this->getConfiguration()['application_fee'];
12+
13+
return new AccountApplicationFeeDTO(
14+
$applicationFee['percentage'],
15+
$applicationFee['fixed']
16+
);
17+
}
718
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace HiEvents\DomainObjects\DTO;
4+
5+
class AccountApplicationFeeDTO
6+
{
7+
public function __construct(
8+
public readonly float $percentageFee,
9+
public readonly float $fixedFee,
10+
)
11+
{
12+
}
13+
}

backend/app/DomainObjects/Generated/AccountDomainObjectAbstract.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ abstract class AccountDomainObjectAbstract extends \HiEvents\DomainObjects\Abstr
2222
final public const SHORT_ID = 'short_id';
2323
final public const STRIPE_CONNECT_SETUP_COMPLETE = 'stripe_connect_setup_complete';
2424
final public const ACCOUNT_VERIFIED_AT = 'account_verified_at';
25+
final public const CONFIGURATION = 'configuration';
2526

2627
protected int $id;
2728
protected string $currency_code = 'USD';
@@ -35,6 +36,7 @@ abstract class AccountDomainObjectAbstract extends \HiEvents\DomainObjects\Abstr
3536
protected string $short_id;
3637
protected ?bool $stripe_connect_setup_complete = false;
3738
protected ?string $account_verified_at = null;
39+
protected array|string|null $configuration = null;
3840

3941
public function toArray(): array
4042
{
@@ -51,6 +53,7 @@ public function toArray(): array
5153
'short_id' => $this->short_id ?? null,
5254
'stripe_connect_setup_complete' => $this->stripe_connect_setup_complete ?? null,
5355
'account_verified_at' => $this->account_verified_at ?? null,
56+
'configuration' => $this->configuration ?? null,
5457
];
5558
}
5659

@@ -185,4 +188,15 @@ public function getAccountVerifiedAt(): ?string
185188
{
186189
return $this->account_verified_at;
187190
}
191+
192+
public function setConfiguration(array|string|null $configuration): self
193+
{
194+
$this->configuration = $configuration;
195+
return $this;
196+
}
197+
198+
public function getConfiguration(): array|string|null
199+
{
200+
return $this->configuration;
201+
}
188202
}

backend/app/Models/Account.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class Account extends BaseModel
1111
{
1212
protected function getCastMap(): array
1313
{
14-
return [];
14+
return [
15+
'configuration' => 'array',
16+
];
1517
}
1618

1719
protected function getFillableFields(): array

backend/app/Resources/Event/EventResourcePublic.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public function toArray(Request $request): array
4444
),
4545
'settings' => $this->when(
4646
condition: !is_null($this->getEventSettings()),
47-
value: fn() => new EventSettingsResourcePublic($this->getEventSettings(), $this->includePostCheckoutData),
47+
value: fn() => new EventSettingsResourcePublic(
48+
$this->getEventSettings(),
49+
$this->includePostCheckoutData
50+
),
4851
),
4952
// @TODO - public question resource
5053
'questions' => $this->when(

backend/app/Resources/Event/EventSettingsResourcePublic.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public function toArray($request): array
2323
return [
2424
'pre_checkout_message' => $this->getPreCheckoutMessage(),
2525

26+
// We only show post checkout data if the order is completed. So this data is only returned when this
27+
// resource is returned within the context of an order that is completed.
28+
// i.e. order->event->event_settings and not event->event_settings
2629
$this->mergeWhen($this->includePostCheckoutData, [
2730
'post_checkout_message' => $this->getPostCheckoutMessage(),
2831
'online_event_connection_details' => $this->getOnlineEventConnectionDetails(),

backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ private function getApplicationFee(CreatePaymentIntentRequestDTO $paymentIntentD
112112
return 0;
113113
}
114114

115-
return ceil($paymentIntentDTO->amount * $this->config->get('app.saas_stripe_application_fee_percent') / 100);
115+
$fixedFee = $paymentIntentDTO->account->getApplicationFee()->fixedFee;
116+
$percentageFee = $paymentIntentDTO->account->getApplicationFee()->percentageFee;
117+
118+
return ceil(($fixedFee * 100) + ($paymentIntentDTO->amount * $percentageFee / 100));
116119
}
117120

118121
/**

backend/config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'default_currency_code' => 'USD',
1515
'saas_mode_enabled' => env('APP_SAAS_MODE_ENABLED', false),
1616
'saas_stripe_application_fee_percent' => env('APP_SAAS_STRIPE_APPLICATION_FEE_PERCENT', 1.5),
17+
'saas_stripe_application_fee_fixed' => env('APP_SAAS_STRIPE_APPLICATION_FEE_FIXED', 0),
1718
'disable_registration' => env('APP_DISABLE_REGISTRATION', false),
1819
'api_rate_limit_per_minute' => env('APP_API_RATE_LIMIT_PER_MINUTE', 180),
1920

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
7+
8+
return new class extends Migration {
9+
public function up(): void
10+
{
11+
Schema::table('accounts', static function (Blueprint $table) {
12+
$table->json('configuration')->nullable();
13+
});
14+
15+
DB::table('accounts')->update(['configuration' => [
16+
'application_fee' => [
17+
'percentage' => config('app.saas_stripe_application_fee_percent'),
18+
'fixed' => 0,
19+
]
20+
]]);
21+
}
22+
23+
public function down(): void
24+
{
25+
Schema::table('accounts', static function (Blueprint $table) {
26+
$table->dropColumn('configuration');
27+
});
28+
}
29+
};

frontend/src/components/common/Editor/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface EditorProps {
1616
onChange: (value: string) => void;
1717
value: string;
1818
label?: React.ReactNode;
19-
description?: string;
19+
description?: React.ReactNode;
2020
required?: boolean;
2121
className?: string;
2222
error?: string;

0 commit comments

Comments
 (0)