Handle payment_intent.succeeded webhook: generate tickets and send email
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\BilletBuyer;
|
||||
use App\Entity\Payout;
|
||||
use App\Entity\User;
|
||||
use App\Service\BilletOrderService;
|
||||
use App\Service\MailerService;
|
||||
use App\Service\PayoutPdfService;
|
||||
use App\Service\StripeService;
|
||||
@@ -16,7 +18,7 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
class StripeWebhookController extends AbstractController
|
||||
{
|
||||
#[Route('/stripe/webhook', name: 'app_stripe_webhook', methods: ['POST'])]
|
||||
public function webhook(Request $request, StripeService $stripeService, EntityManagerInterface $em, MailerService $mailerService, PayoutPdfService $pdfService): Response
|
||||
public function webhook(Request $request, StripeService $stripeService, EntityManagerInterface $em, MailerService $mailerService, PayoutPdfService $pdfService, BilletOrderService $billetOrderService): Response
|
||||
{
|
||||
$payload = $request->getContent();
|
||||
$signature = $request->headers->get('Stripe-Signature', '');
|
||||
@@ -31,6 +33,7 @@ class StripeWebhookController extends AbstractController
|
||||
|
||||
match ($type) {
|
||||
'payout.created', 'payout.updated', 'payout.paid', 'payout.failed', 'payout.canceled' => $this->handlePayout($event, $em, $mailerService, $pdfService),
|
||||
'payment_intent.succeeded' => $this->handlePaymentIntentSucceeded($event, $em, $billetOrderService),
|
||||
default => null,
|
||||
};
|
||||
|
||||
@@ -118,6 +121,24 @@ class StripeWebhookController extends AbstractController
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
private function handlePaymentIntentSucceeded(\Stripe\Event $event, EntityManagerInterface $em, BilletOrderService $billetOrderService): void
|
||||
{
|
||||
$paymentIntent = $event->data->object;
|
||||
$orderId = $paymentIntent->metadata->order_id ?? null;
|
||||
|
||||
if (!$orderId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$order = $em->getRepository(BilletBuyer::class)->find((int) $orderId);
|
||||
if (!$order || BilletBuyer::STATUS_PENDING !== $order->getStatus()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$billetOrderService->generateOrderTickets($order);
|
||||
$billetOrderService->generateAndSendTickets($order);
|
||||
}
|
||||
|
||||
private function handlePayout(\Stripe\Event $event, EntityManagerInterface $em, MailerService $mailerService, PayoutPdfService $pdfService): void
|
||||
{
|
||||
$payoutData = $event->data->object;
|
||||
|
||||
Reference in New Issue
Block a user