Split Stripe webhooks into 2 endpoints: insta (payments) and leger (Connect)

- /stripe/webhook → /webhooks/stripe/insta (paiements, payouts, disputes, subscriptions)
- /stripe/webhook/connect → /webhooks/stripe/leger (gestion comptes Connect)
- Rename env vars: STRIPE_WEBHOOK_SECRET → STRIPE_WEBHOOK_SECRET_INSTA,
  STRIPE_WEBHOOK_SECRET_CONNECT → STRIPE_WEBHOOK_SECRET_LEGER
- Update StripeService, CsrfProtectionSubscriber, vault, env files and all tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-04-01 14:07:49 +02:00
parent 1c559263a8
commit 381acd603e
10 changed files with 236 additions and 236 deletions

View File

@@ -25,10 +25,10 @@ class StripeWebhookControllerTest extends WebTestCase
$client = static::createClient();
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn(new Event());
$stripeService->method('verifyWebhookSignatureInsta')->willReturn(new Event());
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], [
$client->request('POST', '/webhooks/stripe/insta', [], [], [
'HTTP_STRIPE_SIGNATURE' => 'valid',
], '{}');
@@ -41,10 +41,10 @@ class StripeWebhookControllerTest extends WebTestCase
$client = static::createClient();
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn(null);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn(null);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], [
$client->request('POST', '/webhooks/stripe/insta', [], [], [
'HTTP_STRIPE_SIGNATURE' => 'invalid',
], '{}');
@@ -64,7 +64,7 @@ class StripeWebhookControllerTest extends WebTestCase
$this->mockStripe($client, $event);
$payload = json_encode(['related_object' => ['id' => 'acct_created']]);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
self::assertResponseIsSuccessful();
@@ -89,7 +89,7 @@ class StripeWebhookControllerTest extends WebTestCase
$this->mockStripe($client, $event);
$payload = json_encode(['related_object' => ['id' => 'acct_closed']]);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
self::assertResponseIsSuccessful();
@@ -113,7 +113,7 @@ class StripeWebhookControllerTest extends WebTestCase
$this->mockStripe($client, $event);
$payload = json_encode(['related_object' => ['id' => 'acct_upd']]);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
self::assertResponseIsSuccessful();
@@ -132,7 +132,7 @@ class StripeWebhookControllerTest extends WebTestCase
$this->mockStripe($client, $event);
$payload = json_encode(['related_object' => ['id' => 'acct_nonexistent']]);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
self::assertResponseIsSuccessful();
}
@@ -146,7 +146,7 @@ class StripeWebhookControllerTest extends WebTestCase
$this->mockStripe($client, $event);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
}
@@ -171,7 +171,7 @@ class StripeWebhookControllerTest extends WebTestCase
]],
]]],
]);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
self::assertResponseIsSuccessful();
@@ -200,7 +200,7 @@ class StripeWebhookControllerTest extends WebTestCase
]],
]]],
]);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
self::assertResponseIsSuccessful();
@@ -231,7 +231,7 @@ class StripeWebhookControllerTest extends WebTestCase
]],
]]],
]);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
self::assertResponseIsSuccessful();
@@ -253,7 +253,7 @@ class StripeWebhookControllerTest extends WebTestCase
'related_object' => ['id' => 'acct_ghost'],
'changes' => ['after' => ['configuration' => []]],
]);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], $payload);
self::assertResponseIsSuccessful();
}
@@ -278,14 +278,14 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$mailer = $this->createMock(MailerService::class);
$mailer->expects(self::once())->method('sendEmail');
static::getContainer()->set(MailerService::class, $mailer);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
}
@@ -312,7 +312,7 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$mailer = $this->createMock(MailerService::class);
@@ -323,7 +323,7 @@ class StripeWebhookControllerTest extends WebTestCase
$pdfService->expects(self::once())->method('generateToFile')->willReturn('/tmp/fake.pdf');
static::getContainer()->set(PayoutPdfService::class, $pdfService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
@@ -364,14 +364,14 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$mailer = $this->createMock(MailerService::class);
$mailer->expects(self::once())->method('sendEmail');
static::getContainer()->set(MailerService::class, $mailer);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
@@ -390,10 +390,10 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
}
@@ -414,10 +414,10 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
}
@@ -441,7 +441,7 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$mailer = $this->createMock(MailerService::class);
@@ -452,7 +452,7 @@ class StripeWebhookControllerTest extends WebTestCase
$audit->expects(self::once())->method('log')->with('payment_failed', 'BilletBuyer', $order->getId(), $this->anything());
static::getContainer()->set(AuditService::class, $audit);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
$freshEm = static::getContainer()->get(EntityManagerInterface::class);
@@ -470,10 +470,10 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
}
@@ -489,10 +489,10 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
}
@@ -514,10 +514,10 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
$freshEm = static::getContainer()->get(EntityManagerInterface::class);
@@ -541,7 +541,7 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$mailer = $this->createMock(MailerService::class);
@@ -557,7 +557,7 @@ class StripeWebhookControllerTest extends WebTestCase
);
static::getContainer()->set(AuditService::class, $audit);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
}
@@ -579,7 +579,7 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$mailer = $this->createMock(MailerService::class);
@@ -589,7 +589,7 @@ class StripeWebhookControllerTest extends WebTestCase
$audit = $this->createMock(AuditService::class);
static::getContainer()->set(AuditService::class, $audit);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
}
@@ -614,7 +614,7 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$mailer = $this->createMock(MailerService::class);
@@ -629,7 +629,7 @@ class StripeWebhookControllerTest extends WebTestCase
$billetOrderService->expects(self::once())->method('notifyOrganizerCancelled')->with($this->anything(), 'remboursee');
static::getContainer()->set(BilletOrderService::class, $billetOrderService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
$freshEm = static::getContainer()->get(EntityManagerInterface::class);
@@ -662,7 +662,7 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$mailer = $this->createMock(MailerService::class);
@@ -674,7 +674,7 @@ class StripeWebhookControllerTest extends WebTestCase
$billetOrderService = $this->createMock(BilletOrderService::class);
static::getContainer()->set(BilletOrderService::class, $billetOrderService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
$freshEm = static::getContainer()->get(EntityManagerInterface::class);
@@ -692,10 +692,10 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
}
@@ -709,10 +709,10 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
}
@@ -734,10 +734,10 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
$freshEm = static::getContainer()->get(EntityManagerInterface::class);
@@ -764,7 +764,7 @@ class StripeWebhookControllerTest extends WebTestCase
]);
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
$mailer = $this->createMock(MailerService::class);
@@ -777,7 +777,7 @@ class StripeWebhookControllerTest extends WebTestCase
$billetOrderService = $this->createMock(BilletOrderService::class);
static::getContainer()->set(BilletOrderService::class, $billetOrderService);
$client->request('POST', '/stripe/webhook', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
$client->request('POST', '/webhooks/stripe/insta', [], [], ['HTTP_STRIPE_SIGNATURE' => 'v'], '{}');
self::assertResponseIsSuccessful();
}
@@ -845,7 +845,7 @@ class StripeWebhookControllerTest extends WebTestCase
private function mockStripe(\Symfony\Bundle\FrameworkBundle\KernelBrowser $client, Event $event): void
{
$stripeService = $this->createMock(StripeService::class);
$stripeService->method('verifyWebhookSignature')->willReturn($event);
$stripeService->method('verifyWebhookSignatureInsta')->willReturn($event);
static::getContainer()->set(StripeService::class, $stripeService);
}
}

View File

@@ -48,8 +48,8 @@ class CsrfProtectionSubscriberTest extends TestCase
{
$subscriber = $this->createSubscriber();
$request = Request::create('/stripe/webhook', 'POST');
$request->attributes->set('_route', 'app_stripe_webhook');
$request = Request::create('/webhooks/stripe/insta', 'POST');
$request->attributes->set('_route', 'app_stripe_webhook_insta');
$kernel = $this->createMock(HttpKernelInterface::class);
$event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST);

View File

@@ -9,16 +9,16 @@ class StripeServiceTest extends TestCase
{
private function createService(): StripeService
{
return new StripeService('sk_test', 'whsec_test', 'whsec_connect_test', 'https://example.com');
return new StripeService('sk_test', 'whsec_test_insta', 'whsec_test_leger', 'https://example.com');
}
public function testVerifyWebhookSignatureReturnsNullOnInvalid(): void
public function testVerifyWebhookSignatureInstaReturnsNullOnInvalid(): void
{
self::assertNull($this->createService()->verifyWebhookSignature('{}', 'invalid'));
self::assertNull($this->createService()->verifyWebhookSignatureInsta('{}', 'invalid'));
}
public function testVerifyConnectWebhookSignatureReturnsNullOnInvalid(): void
public function testVerifyWebhookSignatureLegerReturnsNullOnInvalid(): void
{
self::assertNull($this->createService()->verifyConnectWebhookSignature('{}', 'invalid'));
self::assertNull($this->createService()->verifyWebhookSignatureLeger('{}', 'invalid'));
}
}