33namespace HiEvents \DomainObjects ;
44
55use HiEvents \DomainObjects \DTO \AccountApplicationFeeDTO ;
6+ use HiEvents \DomainObjects \Enums \StripePlatform ;
7+ use Illuminate \Support \Collection ;
68
79class AccountDomainObject extends Generated \AccountDomainObjectAbstract
810{
911 private ?AccountConfigurationDomainObject $ configuration = null ;
1012
13+ /** @var Collection<int, AccountStripePlatformDomainObject>|null */
14+ private ?Collection $ stripePlatforms = null ;
15+
1116 public function getApplicationFee (): AccountApplicationFeeDTO
1217 {
1318 /** @var AccountConfigurationDomainObject $applicationFee */
@@ -28,4 +33,68 @@ public function setConfiguration(AccountConfigurationDomainObject $configuration
2833 {
2934 $ this ->configuration = $ configuration ;
3035 }
36+
37+ public function getAccountStripePlatforms (): ?Collection
38+ {
39+ return $ this ->stripePlatforms ;
40+ }
41+
42+ public function setAccountStripePlatforms (Collection $ stripePlatforms ): void
43+ {
44+ $ this ->stripePlatforms = $ stripePlatforms ;
45+ }
46+
47+ /**
48+ * Get the primary active Stripe platform for this account
49+ * Returns the platform with setup completed, preferring the most recent
50+ */
51+ public function getPrimaryStripePlatform (): ?AccountStripePlatformDomainObject
52+ {
53+ if (!$ this ->stripePlatforms || $ this ->stripePlatforms ->isEmpty ()) {
54+ return null ;
55+ }
56+
57+ return $ this ->stripePlatforms
58+ ->filter (fn ($ platform ) => $ platform ->getStripeSetupCompletedAt () !== null )
59+ ->sortByDesc (fn ($ platform ) => $ platform ->getCreatedAt ())
60+ ->first ();
61+ }
62+
63+ /**
64+ * Get the Stripe platform for a specific platform type
65+ * Handles null platform for open-source installations
66+ */
67+ public function getStripePlatformByType (?StripePlatform $ platformType ): ?AccountStripePlatformDomainObject
68+ {
69+ if (!$ this ->stripePlatforms || $ this ->stripePlatforms ->isEmpty ()) {
70+ return null ;
71+ }
72+
73+ return $ this ->stripePlatforms
74+ ->filter (fn ($ platform ) => $ platform ->getStripeConnectPlatform () === $ platformType ?->value)
75+ ->first ();
76+ }
77+
78+ public function getActiveStripeAccountId (): ?string
79+ {
80+ return $ this ->getPrimaryStripePlatform ()?->getStripeAccountId();
81+ }
82+
83+ public function getActiveStripePlatform (): ?StripePlatform
84+ {
85+ $ primaryPlatform = $ this ->getPrimaryStripePlatform ();
86+ if (!$ primaryPlatform || !$ primaryPlatform ->getStripeConnectPlatform ()) {
87+ return null ;
88+ }
89+
90+ return StripePlatform::fromString ($ primaryPlatform ->getStripeConnectPlatform ());
91+ }
92+
93+ /**
94+ * Check if Stripe is set up and ready for payments
95+ */
96+ public function isStripeSetupComplete (): bool
97+ {
98+ return $ this ->getPrimaryStripePlatform () !== null ;
99+ }
31100}
0 commit comments