- Create StripeService: webhook sync, signature verification, save secret to .env.local - Create StripeWebhookController with signature verification (400 on invalid) - Create stripe:sync command to auto-create webhook endpoint via Stripe API - Webhook listens to all events (configurable later) - Save webhook secret automatically to .env.local on creation - Add stripeAccountId field to User entity for Stripe Connect + migration - Tests: StripeServiceTest (5), StripeWebhookControllerTest (2), StripeSyncCommandTest (1), UserTest updated Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Controller;
|
|
|
|
use App\Service\StripeService;
|
|
use Stripe\Event;
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
class StripeWebhookControllerTest extends WebTestCase
|
|
{
|
|
public function testWebhookWithValidSignature(): void
|
|
{
|
|
$client = static::createClient();
|
|
|
|
$stripeService = $this->createMock(StripeService::class);
|
|
$stripeService->method('verifyWebhookSignature')->willReturn(new Event());
|
|
static::getContainer()->set(StripeService::class, $stripeService);
|
|
|
|
$client->request('POST', '/stripe/webhook', [], [], [
|
|
'HTTP_STRIPE_SIGNATURE' => 'valid',
|
|
], '{}');
|
|
|
|
self::assertResponseIsSuccessful();
|
|
self::assertSame('OK', $client->getResponse()->getContent());
|
|
}
|
|
|
|
public function testWebhookWithInvalidSignature(): void
|
|
{
|
|
$client = static::createClient();
|
|
|
|
$stripeService = $this->createMock(StripeService::class);
|
|
$stripeService->method('verifyWebhookSignature')->willReturn(null);
|
|
static::getContainer()->set(StripeService::class, $stripeService);
|
|
|
|
$client->request('POST', '/stripe/webhook', [], [], [
|
|
'HTTP_STRIPE_SIGNATURE' => 'invalid',
|
|
], '{}');
|
|
|
|
self::assertResponseStatusCodeSame(400);
|
|
}
|
|
}
|