Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ abstract class AccountConfigurationDomainObjectAbstract extends \HiEvents\Domain
final public const CREATED_AT = 'created_at';
final public const UPDATED_AT = 'updated_at';
final public const DELETED_AT = 'deleted_at';
final public const BYPASS_APPLICATION_FEES = 'bypass_application_fees';

protected int $id;
protected string $name;
Expand All @@ -25,6 +26,7 @@ abstract class AccountConfigurationDomainObjectAbstract extends \HiEvents\Domain
protected ?string $created_at = null;
protected ?string $updated_at = null;
protected ?string $deleted_at = null;
protected bool $bypass_application_fees = false;

public function toArray(): array
{
Expand All @@ -36,6 +38,7 @@ public function toArray(): array
'created_at' => $this->created_at ?? null,
'updated_at' => $this->updated_at ?? null,
'deleted_at' => $this->deleted_at ?? null,
'bypass_application_fees' => $this->bypass_application_fees ?? null,
];
}

Expand Down Expand Up @@ -115,4 +118,15 @@ public function getDeletedAt(): ?string
{
return $this->deleted_at;
}

public function setBypassApplicationFees(bool $bypass_application_fees): self
{
$this->bypass_application_fees = $bypass_application_fees;
return $this;
}

public function getBypassApplicationFees(): bool
{
return $this->bypass_application_fees;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public function __invoke(Request $request): JsonResponse
'application_fees' => 'required|array',
'application_fees.fixed' => 'required|numeric|min:0',
'application_fees.percentage' => 'required|numeric|min:0|max:100',
'bypass_application_fees' => 'sometimes|boolean',
]);

$configuration = $this->repository->create([
'name' => $validated['name'],
'is_system_default' => false,
'application_fees' => $validated['application_fees'],
'bypass_application_fees' => $validated['bypass_application_fees'] ?? false,
]);

return $this->jsonResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ public function __invoke(Request $request, int $configurationId): JsonResponse
'application_fees' => 'required|array',
'application_fees.fixed' => 'required|numeric|min:0',
'application_fees.percentage' => 'required|numeric|min:0|max:100',
'bypass_application_fees' => 'sometimes|boolean',
]);

$configuration = $this->repository->updateFromArray(
id: $configurationId,
attributes: [
'name' => $validated['name'],
'application_fees' => $validated['application_fees'],
'bypass_application_fees' => $validated['bypass_application_fees'] ?? false,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function toArray($request): array
'percentage' => $this->getPercentageApplicationFee(),
'fixed' => $this->getFixedApplicationFee(),
],
'bypass_application_fees' => $this->getBypassApplicationFees(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ public function createPaymentIntentWithClient(
try {
$this->databaseManager->beginTransaction();

$accountConfiguration = $paymentIntentDTO->account->getConfiguration();
$bypassApplicationFees = $accountConfiguration?->getBypassApplicationFees() ?? false;

$applicationFee = $this->orderApplicationFeeCalculationService->calculateApplicationFee(
accountConfiguration: $paymentIntentDTO->account->getConfiguration(),
accountConfiguration: $accountConfiguration,
order: $paymentIntentDTO->order,
vatSettings: $paymentIntentDTO->vatSettings,
);
Expand All @@ -80,7 +83,7 @@ public function createPaymentIntentWithClient(
'automatic_payment_methods' => [
'enabled' => true,
],
...($applicationFee ? ['application_fee_amount' => $applicationFee->grossApplicationFee->toMinorUnit()] : []),
...($applicationFee && !$bypassApplicationFees ? ['application_fee_amount' => $applicationFee->grossApplicationFee->toMinorUnit()] : []),
], $this->getStripeAccountData($paymentIntentDTO));

$this->logger->debug('Stripe payment intent created', [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up(): void
{
Schema::table('account_configuration', function (Blueprint $table) {
$table->boolean('bypass_application_fees')->default(false)->after('application_fees');
});
}

public function down(): void
{
Schema::table('account_configuration', function (Blueprint $table) {
$table->dropColumn('bypass_application_fees');
});
}
};
3 changes: 3 additions & 0 deletions frontend/src/api/admin.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface AccountConfiguration {
fixed: number;
percentage: number;
};
bypass_application_fees: boolean;
}

export interface CreateConfigurationData {
Expand All @@ -60,6 +61,7 @@ export interface CreateConfigurationData {
fixed: number;
percentage: number;
};
bypass_application_fees?: boolean;
}

export interface UpdateConfigurationData {
Expand All @@ -68,6 +70,7 @@ export interface UpdateConfigurationData {
fixed: number;
percentage: number;
};
bypass_application_fees?: boolean;
}

export interface AssignConfigurationData {
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/components/routes/admin/Configurations/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Container, Title, Stack, Card, Text, Group, Button, Badge, ActionIcon, Alert, NumberInput, TextInput, Skeleton} from "@mantine/core";
import {Container, Title, Stack, Card, Text, Group, Button, Badge, ActionIcon, Alert, NumberInput, TextInput, Skeleton, Switch} from "@mantine/core";
import {t} from "@lingui/macro";
import {useGetAllConfigurations} from "../../../../queries/useGetAllConfigurations";
import {useCreateConfiguration} from "../../../../mutations/useCreateConfiguration";
Expand All @@ -16,6 +16,7 @@ interface ConfigurationFormValues {
name: string;
fixed_fee: number;
percentage_fee: number;
bypass_application_fees: boolean;
}

const Configurations = () => {
Expand Down Expand Up @@ -80,6 +81,9 @@ const Configurations = () => {
{config.is_system_default && (
<Badge color="blue" size="sm">{t`System Default`}</Badge>
)}
{config.bypass_application_fees && (
<Badge color="orange" size="sm">{t`Fees Bypassed`}</Badge>
)}
</Group>
<Group gap="xl">
<div>
Expand Down Expand Up @@ -150,6 +154,7 @@ const ConfigurationModal = ({configuration, onClose}: ConfigurationModalProps) =
name: configuration?.name || '',
fixed_fee: configuration?.application_fees?.fixed || 0,
percentage_fee: configuration?.application_fees?.percentage || 0,
bypass_application_fees: configuration?.bypass_application_fees || false,
},
validate: {
name: (value) => {
Expand All @@ -172,6 +177,7 @@ const ConfigurationModal = ({configuration, onClose}: ConfigurationModalProps) =
fixed: values.fixed_fee,
percentage: values.percentage_fee,
},
bypass_application_fees: values.bypass_application_fees,
};

const mutation = isEditing ? updateMutation : createMutation;
Expand Down Expand Up @@ -232,6 +238,12 @@ const ConfigurationModal = ({configuration, onClose}: ConfigurationModalProps) =
{...form.getInputProps('percentage_fee')}
/>

<Switch
label={t`Bypass Application Fees`}
description={t`When enabled, no application fees will be charged on Stripe Connect transactions. Use this for countries where application fees are not supported.`}
{...form.getInputProps('bypass_application_fees', { type: 'checkbox' })}
/>

<Button
fullWidth
loading={createMutation.isPending || updateMutation.isPending}
Expand Down
Loading