PluginProbe
The Innovative Form Builder – IvyForms / trunk
The Innovative Form Builder – IvyForms vtrunk
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Services / Payment / PaymentGatewayRegistry.php

PaymentGatewayRegistry.php in The Innovative Form Builder – IvyForms trunk, at backend/src/Services/Payment/PaymentGatewayRegistry.php

50 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Services\Payment;
4
5 use IvyForms\Common\Exceptions\InvalidArgumentException;
6 use IvyForms\Services\Translations\BackendStrings;
7
8 /**
9 * Registry of payment gateways available during form submission.
10 */
11 class PaymentGatewayRegistry
12 {
13 /**
14 * @var array<string, PaymentGatewayInterface>
15 */
16 private array $gateways = [];
17
18 public function register(PaymentGatewayInterface $gateway): void
19 {
20 $this->gateways[$gateway->getId()] = $gateway;
21 }
22
23 public function has(string $id): bool
24 {
25 return isset($this->gateways[$id]);
26 }
27
28 /**
29 * @throws InvalidArgumentException
30 */
31 public function get(string $id): PaymentGatewayInterface
32 {
33 if (!isset($this->gateways[$id])) {
34 throw new InvalidArgumentException(
35 BackendStrings::getPaymentStrings()['payment_gateway_unavailable']
36 );
37 }
38
39 return $this->gateways[$id];
40 }
41
42 /**
43 * @return array<string, PaymentGatewayInterface>
44 */
45 public function all(): array
46 {
47 return $this->gateways;
48 }
49 }
50