Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

Feature: Store VAT rate (#944)

Dave Earleye33a196878bd
diff --git a/backend/app/DomainObjects/Generated/OrderPaymentPlatformFeeDomainObjectAbstract.php b/backend/app/DomainObjects/Generated/OrderPaymentPlatformFeeDomainObjectAbstract.php
index 1d8e2b2b1..d4d74b685 100644
--- a/backend/app/DomainObjects/Generated/OrderPaymentPlatformFeeDomainObjectAbstract.php
+++ b/backend/app/DomainObjects/Generated/OrderPaymentPlatformFeeDomainObjectAbstract.php
@@ -25,6 +25,7 @@ abstract class OrderPaymentPlatformFeeDomainObjectAbstract extends \HiEvents\Dom
final public const APPLICATION_FEE_NET_AMOUNT = 'application_fee_net_amount';
final public const APPLICATION_FEE_VAT_AMOUNT = 'application_fee_vat_amount';
final public const CHARGE_ID = 'charge_id';
+ final public const APPLICATION_FEE_VAT_RATE = 'application_fee_vat_rate';
protected int $id;
protected int $order_id;
@@ -41,6 +42,7 @@ abstract class OrderPaymentPlatformFeeDomainObjectAbstract extends \HiEvents\Dom
protected ?float $application_fee_net_amount = null;
protected ?float $application_fee_vat_amount = null;
protected ?string $charge_id = null;
+ protected ?float $application_fee_vat_rate = null;
public function toArray(): array
{
@@ -60,6 +62,7 @@ abstract class OrderPaymentPlatformFeeDomainObjectAbstract extends \HiEvents\Dom
'application_fee_net_amount' => $this->application_fee_net_amount ?? null,
'application_fee_vat_amount' => $this->application_fee_vat_amount ?? null,
'charge_id' => $this->charge_id ?? null,
+ 'application_fee_vat_rate' => $this->application_fee_vat_rate ?? null,
];
}
@@ -227,4 +230,15 @@ abstract class OrderPaymentPlatformFeeDomainObjectAbstract extends \HiEvents\Dom
{
return $this->charge_id;
}
+
+ public function setApplicationFeeVatRate(?float $application_fee_vat_rate): self
+ {
+ $this->application_fee_vat_rate = $application_fee_vat_rate;
+ return $this;
+ }
+
+ public function getApplicationFeeVatRate(): ?float
+ {
+ return $this->application_fee_vat_rate;
+ }
}
diff --git a/backend/app/DomainObjects/Generated/StripePaymentDomainObjectAbstract.php b/backend/app/DomainObjects/Generated/StripePaymentDomainObjectAbstract.php
index d02d15bc9..c53281049 100644
--- a/backend/app/DomainObjects/Generated/StripePaymentDomainObjectAbstract.php
+++ b/backend/app/DomainObjects/Generated/StripePaymentDomainObjectAbstract.php
@@ -32,6 +32,7 @@ abstract class StripePaymentDomainObjectAbstract extends \HiEvents\DomainObjects
final public const PAYOUT_CURRENCY = 'payout_currency';
final public const PAYOUT_EXCHANGE_RATE = 'payout_exchange_rate';
final public const BALANCE_TRANSACTION_ID = 'balance_transaction_id';
+ final public const APPLICATION_FEE_VAT_RATE = 'application_fee_vat_rate';
protected int $id;
protected int $order_id;
@@ -48,13 +49,14 @@ abstract class StripePaymentDomainObjectAbstract extends \HiEvents\DomainObjects
protected ?string $stripe_platform = null;
protected ?int $application_fee_net = null;
protected ?int $application_fee_vat = null;
- protected string $currency = 'USD';
+ protected ?string $currency = null;
protected ?string $payout_id = null;
protected ?int $payout_stripe_fee = null;
protected ?int $payout_net_amount = null;
protected ?string $payout_currency = null;
protected ?float $payout_exchange_rate = null;
protected ?string $balance_transaction_id = null;
+ protected ?float $application_fee_vat_rate = null;
public function toArray(): array
{
@@ -81,6 +83,7 @@ abstract class StripePaymentDomainObjectAbstract extends \HiEvents\DomainObjects
'payout_currency' => $this->payout_currency ?? null,
'payout_exchange_rate' => $this->payout_exchange_rate ?? null,
'balance_transaction_id' => $this->balance_transaction_id ?? null,
+ 'application_fee_vat_rate' => $this->application_fee_vat_rate ?? null,
];
}
@@ -249,13 +252,13 @@ abstract class StripePaymentDomainObjectAbstract extends \HiEvents\DomainObjects
return $this->application_fee_vat;
}
- public function setCurrency(string $currency): self
+ public function setCurrency(?string $currency): self
{
$this->currency = $currency;
return $this;
}
- public function getCurrency(): string
+ public function getCurrency(): ?string
{
return $this->currency;
}
@@ -325,4 +328,15 @@ abstract class StripePaymentDomainObjectAbstract extends \HiEvents\DomainObjects
{
return $this->balance_transaction_id;
}
+
+ public function setApplicationFeeVatRate(?float $application_fee_vat_rate): self
+ {
+ $this->application_fee_vat_rate = $application_fee_vat_rate;
+ return $this;
+ }
+
+ public function getApplicationFeeVatRate(): ?float
+ {
+ return $this->application_fee_vat_rate;
+ }
}
diff --git a/backend/app/Models/StripePayment.php b/backend/app/Models/StripePayment.php
index 6064d448f..4428e7033 100644
--- a/backend/app/Models/StripePayment.php
+++ b/backend/app/Models/StripePayment.php
@@ -19,7 +19,7 @@ class StripePayment extends BaseModel
return [
'last_error' => 'array',
'payout_exchange_rate' => 'float',
-
+ 'application_fee_vat_rate' => 'float',
];
}
diff --git a/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php b/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php
index 4247cb345..c4a6d2e63 100644
--- a/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php
+++ b/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php
@@ -131,6 +131,7 @@ readonly class CreatePaymentIntentHandler
StripePaymentDomainObjectAbstract::APPLICATION_FEE_GROSS => $applicationFeeData?->grossApplicationFee?->toMinorUnit() ?? 0,
StripePaymentDomainObjectAbstract::APPLICATION_FEE_NET => $applicationFeeData?->netApplicationFee?->toMinorUnit() ?? 0,
StripePaymentDomainObjectAbstract::APPLICATION_FEE_VAT => $applicationFeeData?->applicationFeeVatAmount?->toMinorUnit() ?? 0,
+ StripePaymentDomainObjectAbstract::APPLICATION_FEE_VAT_RATE => $applicationFeeData?->applicationFeeVatRate,
StripePaymentDomainObjectAbstract::CURRENCY => strtoupper($order->getCurrency()),
StripePaymentDomainObjectAbstract::STRIPE_PLATFORM => $stripePlatform?->value,
]);
diff --git a/backend/app/Services/Application/Handlers/Order/Payment/Stripe/IncomingWebhookHandler.php b/backend/app/Services/Application/Handlers/Order/Payment/Stripe/IncomingWebhookHandler.php
index 78b3792c6..39c02ecbf 100644
--- a/backend/app/Services/Application/Handlers/Order/Payment/Stripe/IncomingWebhookHandler.php
+++ b/backend/app/Services/Application/Handlers/Order/Payment/Stripe/IncomingWebhookHandler.php
@@ -75,7 +75,7 @@ class IncomingWebhookHandler
'data' => $event->data->object->toArray(),
]);
-// return;
+ return;
}
$this->logger->debug('Stripe event received: ' . $event->type, $event->data->object->toArray());
diff --git a/backend/app/Services/Domain/Order/OrderApplicationFeeCalculationService.php b/backend/app/Services/Domain/Order/OrderApplicationFeeCalculationService.php
index 31d7de5c4..ccfe9cb3e 100644
--- a/backend/app/Services/Domain/Order/OrderApplicationFeeCalculationService.php
+++ b/backend/app/Services/Domain/Order/OrderApplicationFeeCalculationService.php
@@ -109,6 +109,7 @@ class OrderApplicationFeeCalculationService
return new ApplicationFeeValuesDTO(
grossApplicationFee: $netApplicationFee,
netApplicationFee: $netApplicationFee,
+ applicationFeeVatRate: $vatRate,
);
}
diff --git a/backend/app/Services/Domain/Order/OrderPaymentPlatformFeeService.php b/backend/app/Services/Domain/Order/OrderPaymentPlatformFeeService.php
index 3539a7ec0..6343cdc8a 100644
--- a/backend/app/Services/Domain/Order/OrderPaymentPlatformFeeService.php
+++ b/backend/app/Services/Domain/Order/OrderPaymentPlatformFeeService.php
@@ -25,6 +25,7 @@ class OrderPaymentPlatformFeeService
?string $chargeId = null,
?int $applicationFeeNetAmountMinorUnit = null,
?int $applicationFeeVatAmountMinorUnit = null,
+ ?float $applicationFeeVatRate = null,
): void
{
$isZeroDecimalCurrency = Currency::isZeroDecimalCurrency($currency);
@@ -59,6 +60,7 @@ class OrderPaymentPlatformFeeService
OrderPaymentPlatformFeeDomainObjectAbstract::APPLICATION_FEE_GROSS_AMOUNT => $applicationFeeGrossAmount,
OrderPaymentPlatformFeeDomainObjectAbstract::APPLICATION_FEE_NET_AMOUNT => $applicationFeeNetAmount,
OrderPaymentPlatformFeeDomainObjectAbstract::APPLICATION_FEE_VAT_AMOUNT => $applicationFeeVatAmount,
+ OrderPaymentPlatformFeeDomainObjectAbstract::APPLICATION_FEE_VAT_RATE => $applicationFeeVatRate,
OrderPaymentPlatformFeeDomainObjectAbstract::CURRENCY => strtoupper($currency),
OrderPaymentPlatformFeeDomainObjectAbstract::TRANSACTION_ID => $transactionId,
OrderPaymentPlatformFeeDomainObjectAbstract::CHARGE_ID => $chargeId,
diff --git a/backend/app/Services/Domain/Payment/Stripe/NoStripeCountryCodeException.php b/backend/app/Services/Domain/Payment/Stripe/NoStripeCountryCodeException.php
new file mode 100644
index 000000000..a955f91af
--- /dev/null
+++ b/backend/app/Services/Domain/Payment/Stripe/NoStripeCountryCodeException.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace HiEvents\Services\Domain\Payment\Stripe;
+
+use Exception;
+
+class NoStripeCountryCodeException extends Exception
+{
+
+}
diff --git a/backend/app/Services/Domain/Payment/Stripe/StripeAccountSyncService.php b/backend/app/Services/Domain/Payment/Stripe/StripeAccountSyncService.php
index 6081fc19a..47c488170 100644
--- a/backend/app/Services/Domain/Payment/Stripe/StripeAccountSyncService.php
+++ b/backend/app/Services/Domain/Payment/Stripe/StripeAccountSyncService.php
@@ -3,6 +3,7 @@
namespace HiEvents\Services\Domain\Payment\Stripe;
use HiEvents\DomainObjects\AccountStripePlatformDomainObject;
+use HiEvents\DomainObjects\Enums\CountryCode;
use HiEvents\DomainObjects\Generated\AccountStripePlatformDomainObjectAbstract;
use HiEvents\DomainObjects\Generated\AccountVatSettingDomainObjectAbstract;
use HiEvents\Helper\Url;
@@ -60,6 +61,7 @@ class StripeAccountSyncService
/**
* Force update account status when we know it should be complete
* (e.g., from GetStripeConnectAccountsHandler when Stripe says complete but DB doesn't)
+ * @throws NoStripeCountryCodeException
*/
public function markAccountAsComplete(
AccountStripePlatformDomainObject $accountStripePlatform,
@@ -182,6 +184,9 @@ class StripeAccountSyncService
}
}
+ /**
+ * @throws NoStripeCountryCodeException
+ */
private function createVatSettingIfMissing(AccountStripePlatformDomainObject $accountStripePlatform): void
{
if ($this->config->get('app.tax.eu_vat_handling_enabled') !== true) {
@@ -192,6 +197,29 @@ class StripeAccountSyncService
return;
}
+ $countryCode = $accountStripePlatform->getStripeAccountDetails()['country'];
+
+ if ($countryCode === null) {
+ $this->logger->error('Stripe account country code is missing, cannot create VAT setting.', [
+ 'account_stripe_platform_id' => $accountStripePlatform->getId(),
+ 'account_id' => $accountStripePlatform->getAccountId(),
+ ]);
+
+ throw new NoStripeCountryCodeException('Stripe account country code is missing. cannot create VAT setting.',
+ accountStripePlatformId: $accountStripePlatform->getId(),
+ accountId: $accountStripePlatform->getAccountId()
+ );
+ }
+
+ if (!CountryCode::isEuCountry(CountryCode::from($countryCode))) {
+ $this->logger->info('Account is not in an EU country, skipping VAT setting creation.', [
+ 'account_stripe_platform_id' => $accountStripePlatform->getId(),
+ 'account_id' => $accountStripePlatform->getAccountId(),
+ 'country_code' => $countryCode,
+ ]);
+ return;
+ }
+
$existingVatSetting = $this->vatSettingRepository->findFirstWhere([
AccountVatSettingDomainObjectAbstract::ACCOUNT_ID => $accountStripePlatform->getAccountId(),
]);
@@ -200,8 +228,7 @@ class StripeAccountSyncService
$this->vatSettingRepository->create([
AccountVatSettingDomainObjectAbstract::ACCOUNT_ID => $accountStripePlatform->getAccountId(),
AccountVatSettingDomainObjectAbstract::VAT_VALIDATED => false,
- AccountVatSettingDomainObjectAbstract::VAT_COUNTRY_CODE => $accountStripePlatform
- ->getStripeAccountDetails()['country'] ?? null,
+ AccountVatSettingDomainObjectAbstract::VAT_COUNTRY_CODE => $countryCode,
]);
}
}
diff --git a/backend/app/Services/Domain/Payment/Stripe/StripePaymentPlatformFeeExtractionService.php b/backend/app/Services/Domain/Payment/Stripe/StripePaymentPlatformFeeExtractionService.php
index 3e3e085b6..af1add07d 100644
--- a/backend/app/Services/Domain/Payment/Stripe/StripePaymentPlatformFeeExtractionService.php
+++ b/backend/app/Services/Domain/Payment/Stripe/StripePaymentPlatformFeeExtractionService.php
@@ -111,6 +111,7 @@ class StripePaymentPlatformFeeExtractionService
chargeId: $charge->id ?? null,
applicationFeeNetAmountMinorUnit: $applicationFeeBreakdown['net'],
applicationFeeVatAmountMinorUnit: $applicationFeeBreakdown['vat'],
+ applicationFeeVatRate: $stripePayment->getApplicationFeeVatRate(),
);
$this->logger->info(__('Platform fee stored successfully'), [
diff --git a/backend/database/migrations/2025_11_07_153308_backfill_account_vat_settings.php b/backend/database/migrations/2025_11_07_153308_backfill_account_vat_settings.php
index 98b432f4e..94962130e 100644
--- a/backend/database/migrations/2025_11_07_153308_backfill_account_vat_settings.php
+++ b/backend/database/migrations/2025_11_07_153308_backfill_account_vat_settings.php
@@ -15,7 +15,7 @@ return new class extends Migration {
{
Model::preventLazyLoading(false);
- if (!config('app.is_hi_events')) {
+ if (!config('app.tax.eu_vat_handling_enabled')) {
return;
}
diff --git a/backend/database/migrations/2025_12_06_100000_add_application_fee_vat_rate_columns.php b/backend/database/migrations/2025_12_06_100000_add_application_fee_vat_rate_columns.php
new file mode 100644
index 000000000..30c783071
--- /dev/null
+++ b/backend/database/migrations/2025_12_06_100000_add_application_fee_vat_rate_columns.php
@@ -0,0 +1,36 @@
+<?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('stripe_payments', static function (Blueprint $table) {
+ $table->decimal('application_fee_vat_rate', 5, 4)->nullable();
+ });
+
+ Schema::table('order_payment_platform_fees', static function (Blueprint $table) {
+ $table->decimal('application_fee_vat_rate', 5, 4)->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('stripe_payments', static function (Blueprint $table) {
+ $table->dropColumn('application_fee_vat_rate');
+ });
+
+ Schema::table('order_payment_platform_fees', static function (Blueprint $table) {
+ $table->dropColumn('application_fee_vat_rate');
+ });
+ }
+};
diff --git a/backend/tests/Unit/Services/Domain/Payment/Stripe/StripePaymentPlatformFeeExtractionServiceTest.php b/backend/tests/Unit/Services/Domain/Payment/Stripe/StripePaymentPlatformFeeExtractionServiceTest.php
index b1c1d16f6..0609f1996 100644
--- a/backend/tests/Unit/Services/Domain/Payment/Stripe/StripePaymentPlatformFeeExtractionServiceTest.php
+++ b/backend/tests/Unit/Services/Domain/Payment/Stripe/StripePaymentPlatformFeeExtractionServiceTest.php
@@ -226,6 +226,7 @@ class StripePaymentPlatformFeeExtractionServiceTest extends TestCase
$stripePayment = m::mock(StripePaymentDomainObject::class);
$stripePayment->shouldReceive('getApplicationFeeNet')->andReturn(417);
$stripePayment->shouldReceive('getApplicationFeeVat')->andReturn(83);
+ $stripePayment->shouldReceive('getApplicationFeeVatRate')->andReturn(0.20);
$balanceTransaction = (object)[
'id' => 'txn_123',
@@ -285,7 +286,8 @@ class StripePaymentPlatformFeeExtractionServiceTest extends TestCase
$transactionId,
$chargeId,
$applicationFeeNetAmountMinorUnit,
- $applicationFeeVatAmountMinorUnit
+ $applicationFeeVatAmountMinorUnit,
+ $applicationFeeVatRate
) {
return $orderId === 123
&& $paymentPlatformFeeAmountMinorUnit === 500
@@ -293,6 +295,7 @@ class StripePaymentPlatformFeeExtractionServiceTest extends TestCase
&& $chargeId === 'ch_123'
&& $applicationFeeNetAmountMinorUnit === 488
&& $applicationFeeVatAmountMinorUnit === 97
+ && $applicationFeeVatRate === 0.20
&& $currency === 'eur';
});
@@ -316,6 +319,7 @@ class StripePaymentPlatformFeeExtractionServiceTest extends TestCase
$stripePayment = m::mock(StripePaymentDomainObject::class);
$stripePayment->shouldReceive('getApplicationFeeNet')->never();
$stripePayment->shouldReceive('getApplicationFeeVat')->never();
+ $stripePayment->shouldReceive('getApplicationFeeVatRate')->andReturn(null);
$balanceTransaction = (object)[
'id' => 'txn_123',
@@ -365,7 +369,8 @@ class StripePaymentPlatformFeeExtractionServiceTest extends TestCase
$transactionId,
$chargeId,
$applicationFeeNetAmountMinorUnit,
- $applicationFeeVatAmountMinorUnit
+ $applicationFeeVatAmountMinorUnit,
+ $applicationFeeVatRate
) {
return $orderId === 123
&& $paymentPlatformFeeAmountMinorUnit === 500
@@ -373,6 +378,7 @@ class StripePaymentPlatformFeeExtractionServiceTest extends TestCase
&& $chargeId === 'ch_123'
&& $applicationFeeNetAmountMinorUnit === null
&& $applicationFeeVatAmountMinorUnit === null
+ && $applicationFeeVatRate === null
&& $currency === 'eur';
});
diff --git a/frontend/src/components/routes/account/ManageAccount/sections/PaymentSettings/VatSettings/VatSettingsForm.tsx b/frontend/src/components/routes/account/ManageAccount/sections/PaymentSettings/VatSettings/VatSettingsForm.tsx
index 5322d6e03..483136e0e 100644
--- a/frontend/src/components/routes/account/ManageAccount/sections/PaymentSettings/VatSettings/VatSettingsForm.tsx
+++ b/frontend/src/components/routes/account/ManageAccount/sections/PaymentSettings/VatSettings/VatSettingsForm.tsx
@@ -112,8 +112,13 @@ export const VatSettingsForm = ({account, onSuccess, showCard = true}: VatSettin
const [vatNumber, setVatNumber] = useState('');
const [vatError, setVatError] = useState<string | undefined>();
+ const shouldPoll = vatNumber.trim().length > 0;
+
const vatSettingQuery = useGetAccountVatSetting(account.id, {
refetchInterval: (query) => {
+ if (!shouldPoll) {
+ return false;
+ }
const data = query.state.data;
if (data?.vat_validation_status === 'PENDING' || data?.vat_validation_status === 'VALIDATING') {
return 5000;