Add Stripe Connect account support and account.updated webhook handler

- Add stripeChargesEnabled and stripePayoutsEnabled fields to User entity + migration
- Handle account.updated webhook: sync charges_enabled and payouts_enabled from Stripe
- Add createAccountConnect() and createAccountLink() to StripeService
- Update organizer approved email with Stripe verification notice
- Tests: webhook account.updated with flags, unknown account, User stripe fields

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-19 20:46:55 +01:00
parent 65887fb3da
commit c5e5f81fe8
7 changed files with 194 additions and 3 deletions

View File

@@ -2,8 +2,11 @@
namespace App\Tests\Controller;
use App\Entity\User;
use App\Service\StripeService;
use Doctrine\ORM\EntityManagerInterface;
use Stripe\Event;
use Stripe\StripeObject;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class StripeWebhookControllerTest extends WebTestCase
@@ -38,4 +41,68 @@ class StripeWebhookControllerTest extends WebTestCase
self::assertResponseStatusCodeSame(400);
}
public function testWebhookAccountUpdatedSetsFlags(): void
{
$client = static::createClient();
$em = static::getContainer()->get(EntityManagerInterface::class);
$user = new User();
$user->setEmail('test-stripe-'.uniqid().'@example.com');
$user->setFirstName('Stripe');
$user->setLastName('Test');
$user->setPassword('$2y$13$hashed');
$user->setStripeAccountId('acct_test123');
$em->persist($user);
$em->flush();
$account = StripeObject::constructFrom([
'id' => 'acct_test123',
'charges_enabled' => true,
'payouts_enabled' => true,
]);
$event = new Event();
$event->type = 'account.updated';
$event->data = StripeObject::constructFrom(['object' => $account]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], [
'HTTP_STRIPE_SIGNATURE' => 'valid',
], '{}');
self::assertResponseIsSuccessful();
$em->refresh($user);
self::assertTrue($user->isStripeChargesEnabled());
self::assertTrue($user->isStripePayoutsEnabled());
}
public function testWebhookAccountUpdatedUnknownAccount(): void
{
$client = static::createClient();
$account = StripeObject::constructFrom([
'id' => 'acct_unknown',
'charges_enabled' => true,
'payouts_enabled' => true,
]);
$event = new Event();
$event->type = 'account.updated';
$event->data = StripeObject::constructFrom(['object' => $account]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], [
'HTTP_STRIPE_SIGNATURE' => 'valid',
], '{}');
self::assertResponseIsSuccessful();
}
}

View File

@@ -146,15 +146,22 @@ class UserTest extends TestCase
self::assertSame(1.5, $user->getCommissionRate());
}
public function testStripeAccountIdField(): void
public function testStripeFields(): void
{
$user = new User();
self::assertNull($user->getStripeAccountId());
self::assertFalse($user->isStripeChargesEnabled());
self::assertFalse($user->isStripePayoutsEnabled());
$result = $user->setStripeAccountId('acct_1234567890')
->setStripeChargesEnabled(true)
->setStripePayoutsEnabled(true);
$result = $user->setStripeAccountId('acct_1234567890');
self::assertSame($user, $result);
self::assertSame('acct_1234567890', $user->getStripeAccountId());
self::assertTrue($user->isStripeChargesEnabled());
self::assertTrue($user->isStripePayoutsEnabled());
}
public function testEmailVerificationFields(): void