AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

StripeWebhookController.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Commerce\Checkout;
  4. use App\Commerce\Payments\PaymentException;
  5. use App\Commerce\Payments\PaymentGateway;
  6. use App\Models\Order;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Http\Response;
  9. /**
  10. * Stripe calls this address to tell us about payments.
  11. *
  12. * It is the safety net for shoppers who pay but close the browser before coming back to the store.
  13. * Every message is checked with the webhook signing secret before anything is done.
  14. */
  15. class StripeWebhookController extends Controller
  16. {
  17. public function __invoke(Request $request, PaymentGateway $gateway, Checkout $checkout): Response
  18. {
  19. try {
  20. $payment = $gateway->readWebhook($request->getContent(), (string) $request->header('Stripe-Signature'));
  21. } catch (PaymentException) {
  22. return response('Invalid webhook.', 400);
  23. }
  24. if ($payment !== null) {
  25. $order = Order::query()->where('payment_checkout_id', $payment->checkoutId)->first();
  26. if ($order !== null) {
  27. $checkout->markPaid($order, $payment);
  28. }
  29. }
  30. return response('OK');
  31. }
  32. }