AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

StripeConnectWebhookController.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 about payments made in merchants' own Stripe accounts ("Connected accounts" events).
  11. *
  12. * It is the safety net for shoppers who pay but close the browser before coming back to the store.
  13. * Messages are signed with their own secret (STRIPE_CONNECT_WEBHOOK_SECRET) and checked before anything is done.
  14. */
  15. class StripeConnectWebhookController 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'), fromMerchants: true);
  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. // The payment must be in the same merchant account the order's payment page was made in.
  27. if ($order !== null && $payment->account !== null && $payment->account === $order->payment_account) {
  28. $checkout->markPaid($order, $payment);
  29. }
  30. }
  31. return response('OK');
  32. }
  33. }