AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PaymentGateways.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Commerce\Payments;
  3. use App\Commerce\Payments\HitPay\HitPayGateway;
  4. use App\Models\Order;
  5. use App\Models\Store;
  6. /**
  7. * The ways a store can be paid. Stripe (cards, FPX, GrabPay) comes first; HitPay (DuitNow QR and e-wallets) is a
  8. * second choice when the merchant connected it. The shopper picks one at checkout.
  9. */
  10. class PaymentGateways
  11. {
  12. public function __construct(
  13. private readonly PaymentGateway $main,
  14. private readonly HitPayGateway $hitpay,
  15. ) {}
  16. /**
  17. * The ways shoppers can pay this store now, by name, in the order shown.
  18. *
  19. * @return array<string, PaymentGateway>
  20. */
  21. public function available(Store $store): array
  22. {
  23. $ways = [];
  24. foreach ([$this->main, $this->hitpay] as $gateway) {
  25. if ($gateway->canTakePayments($store)) {
  26. $ways[$gateway->name()] = $gateway;
  27. }
  28. }
  29. return $ways;
  30. }
  31. /**
  32. * The provider an order was sent to. Orders from before HitPay were all Stripe's.
  33. */
  34. public function for(Order $order): PaymentGateway
  35. {
  36. return $order->payment_provider === $this->hitpay->name() ? $this->hitpay : $this->main;
  37. }
  38. }