Skip to content

Commit 94b5e59

Browse files
authored
Make Stripe Connect account type configurable (#359)
1 parent f1de1a8 commit 94b5e59

File tree

12 files changed

+107
-3
lines changed

12 files changed

+107
-3
lines changed

backend/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ APP_SAAS_MODE_ENABLED=false
1111
APP_SAAS_STRIPE_APPLICATION_FEE_PERCENT=1.5
1212
APP_HOMEPAGE_VIEWS_UPDATE_BATCH_SIZE=8
1313
APP_DISABLE_REGISTRATION=false
14+
APP_STRIPE_CONNECT_ACCOUNT_TYPE=express
1415

1516
STRIPE_PUBLIC_KEY=
1617
STRIPE_SECRET_KEY=
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace HiEvents\DomainObjects\Enums;
4+
5+
enum StripeConnectAccountType: string
6+
{
7+
use BaseEnum;
8+
9+
case STANDARD = 'standard';
10+
case EXPRESS = 'express';
11+
}

backend/app/DomainObjects/Generated/AccountDomainObjectAbstract.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ abstract class AccountDomainObjectAbstract extends \HiEvents\DomainObjects\Abstr
2323
final public const STRIPE_CONNECT_SETUP_COMPLETE = 'stripe_connect_setup_complete';
2424
final public const ACCOUNT_VERIFIED_AT = 'account_verified_at';
2525
final public const CONFIGURATION = 'configuration';
26+
final public const STRIPE_CONNECT_ACCOUNT_TYPE = 'stripe_connect_account_type';
2627

2728
protected int $id;
2829
protected string $currency_code = 'USD';
@@ -37,6 +38,7 @@ abstract class AccountDomainObjectAbstract extends \HiEvents\DomainObjects\Abstr
3738
protected ?bool $stripe_connect_setup_complete = false;
3839
protected ?string $account_verified_at = null;
3940
protected array|string|null $configuration = null;
41+
protected ?string $stripe_connect_account_type = null;
4042

4143
public function toArray(): array
4244
{
@@ -54,6 +56,7 @@ public function toArray(): array
5456
'stripe_connect_setup_complete' => $this->stripe_connect_setup_complete ?? null,
5557
'account_verified_at' => $this->account_verified_at ?? null,
5658
'configuration' => $this->configuration ?? null,
59+
'stripe_connect_account_type' => $this->stripe_connect_account_type ?? null,
5760
];
5861
}
5962

@@ -199,4 +202,15 @@ public function getConfiguration(): array|string|null
199202
{
200203
return $this->configuration;
201204
}
205+
206+
public function setStripeConnectAccountType(?string $stripe_connect_account_type): self
207+
{
208+
$this->stripe_connect_account_type = $stripe_connect_account_type;
209+
return $this;
210+
}
211+
212+
public function getStripeConnectAccountType(): ?string
213+
{
214+
return $this->stripe_connect_account_type;
215+
}
202216
}

backend/app/DomainObjects/Generated/StripeCustomerDomainObjectAbstract.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ abstract class StripeCustomerDomainObjectAbstract extends \HiEvents\DomainObject
1717
final public const CREATED_AT = 'created_at';
1818
final public const UPDATED_AT = 'updated_at';
1919
final public const DELETED_AT = 'deleted_at';
20+
final public const STRIPE_ACCOUNT_ID = 'stripe_account_id';
2021

2122
protected int $id;
2223
protected string $name;
@@ -25,6 +26,7 @@ abstract class StripeCustomerDomainObjectAbstract extends \HiEvents\DomainObject
2526
protected ?string $created_at = null;
2627
protected ?string $updated_at = null;
2728
protected ?string $deleted_at = null;
29+
protected ?string $stripe_account_id = null;
2830

2931
public function toArray(): array
3032
{
@@ -36,6 +38,7 @@ public function toArray(): array
3638
'created_at' => $this->created_at ?? null,
3739
'updated_at' => $this->updated_at ?? null,
3840
'deleted_at' => $this->deleted_at ?? null,
41+
'stripe_account_id' => $this->stripe_account_id ?? null,
3942
];
4043
}
4144

@@ -115,4 +118,15 @@ public function getDeletedAt(): ?string
115118
{
116119
return $this->deleted_at;
117120
}
121+
122+
public function setStripeAccountId(?string $stripe_account_id): self
123+
{
124+
$this->stripe_account_id = $stripe_account_id;
125+
return $this;
126+
}
127+
128+
public function getStripeAccountId(): ?string
129+
{
130+
return $this->stripe_account_id;
131+
}
118132
}

backend/app/Http/Actions/Accounts/Stripe/CreateStripeConnectAccountAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __invoke(int $accountId): JsonResponse
3232

3333
try {
3434
$accountResult = $this->createStripeConnectAccountHandler->handle(CreateStripeConnectAccountDTO::fromArray([
35-
'accountId' => $accountId,
35+
'accountId' => $this->getAuthenticatedAccountId(),
3636
]));
3737
} catch (CreateStripeConnectAccountLinksFailedException|CreateStripeConnectAccountFailedException $e) {
3838
return $this->errorResponse(

backend/app/Resources/Account/Stripe/StripeConnectAccountResponseResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class StripeConnectAccountResponseResource extends JsonResource
1414
public function toArray($request): array
1515
{
1616
return [
17+
'stripe_connect_account_type' => $this->stripeConnectAccountType,
1718
'stripe_account_id' => $this->stripeAccountId,
1819
'is_connect_setup_complete' => $this->isConnectSetupComplete,
1920
'connect_url' => $this->connectUrl,

backend/app/Services/Application/Handlers/Account/Payment/Stripe/CreateStripeConnectAccountHandler.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace HiEvents\Services\Application\Handlers\Account\Payment\Stripe;
44

55
use HiEvents\DomainObjects\AccountDomainObject;
6+
use HiEvents\DomainObjects\Enums\StripeConnectAccountType;
7+
use HiEvents\DomainObjects\Generated\AccountDomainObjectAbstract;
68
use HiEvents\Exceptions\CreateStripeConnectAccountFailedException;
79
use HiEvents\Exceptions\CreateStripeConnectAccountLinksFailedException;
810
use HiEvents\Exceptions\SaasModeEnabledException;
@@ -55,6 +57,7 @@ private function createOrGetStripeConnectAccount(CreateStripeConnectAccountDTO $
5557
);
5658

5759
$response = new CreateStripeConnectAccountResponse(
60+
stripeConnectAccountType: $stripeConnectAccount->type,
5861
stripeAccountId: $stripeConnectAccount->id,
5962
account: $account,
6063
isConnectSetupComplete: $this->isStripeAccountComplete($stripeConnectAccount),
@@ -80,7 +83,8 @@ private function getOrCreateStripeConnectAccount(AccountDomainObject $account):
8083
}
8184

8285
$stripeAccount = $this->stripe->accounts->create([
83-
'type' => 'express',
86+
'type' => $this->config->get('app.stripe_connect_account_type')
87+
?? StripeConnectAccountType::EXPRESS->value,
8488
]);
8589
} catch (Throwable $e) {
8690
$this->logger->error('Failed to create or fetch Stripe Connect Account: ' . $e->getMessage(), [
@@ -98,7 +102,8 @@ private function getOrCreateStripeConnectAccount(AccountDomainObject $account):
98102

99103
$this->accountRepository->updateWhere(
100104
attributes: [
101-
'stripe_account_id' => $stripeAccount->id,
105+
AccountDomainObjectAbstract::STRIPE_ACCOUNT_ID => $stripeAccount->id,
106+
AccountDomainObjectAbstract::STRIPE_CONNECT_ACCOUNT_TYPE => $stripeAccount->type,
102107
],
103108
where: [
104109
'id' => $account->getId(),

backend/app/Services/Application/Handlers/Account/Payment/Stripe/DTO/CreateStripeConnectAccountResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class CreateStripeConnectAccountResponse extends BaseDTO
99
{
1010
public function __construct(
11+
public string $stripeConnectAccountType,
1112
public string $stripeAccountId,
1213
public AccountDomainObject $account,
1314
public bool $isConnectSetupComplete,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ private function upsertStripeCustomer(CreatePaymentIntentRequestDTO $paymentInte
151151
{
152152
$customer = $this->stripeCustomerRepository->findFirstWhere([
153153
'email' => $paymentIntentDTO->order->getEmail(),
154+
'stripe_account_id' => $paymentIntentDTO->account->getStripeAccountId(),
154155
]);
155156

156157
if ($customer === null) {
@@ -166,6 +167,7 @@ private function upsertStripeCustomer(CreatePaymentIntentRequestDTO $paymentInte
166167
'name' => $stripeCustomer->name,
167168
'email' => $stripeCustomer->email,
168169
'stripe_customer_id' => $stripeCustomer->id,
170+
'stripe_account_id' => $paymentIntentDTO->account->getStripeAccountId(),
169171
]);
170172
}
171173

backend/config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'saas_stripe_application_fee_fixed' => env('APP_SAAS_STRIPE_APPLICATION_FEE_FIXED', 0),
1818
'disable_registration' => env('APP_DISABLE_REGISTRATION', false),
1919
'api_rate_limit_per_minute' => env('APP_API_RATE_LIMIT_PER_MINUTE', 180),
20+
'stripe_connect_account_type' => env('APP_STRIPE_CONNECT_ACCOUNT_TYPE', 'express'),
2021

2122
/**
2223
* The number of page views to batch before updating the database

0 commit comments

Comments
 (0)