Api
1 day ago
Container
2 years ago
Deprecated
2 years ago
Divi
1 year ago
Elementor
7 months ago
Email
3 years ago
Email 2
2 years ago
Mioweb
1 year ago
Model
1 year ago
Repository
3 weeks ago
Service
1 day ago
Templates
2 years ago
Utils
1 day ago
Utils 2
2 years ago
services 2
2 years ago
styles 2
2 years ago
Bootstrap.php
1 day ago
EmailTemplatesProvider.php
3 years ago
FapiApi.php
2 years ago
FapiClients.php
2 years ago
FapiLevels.php
2 years ago
FapiMemberPlugin.php
1 year ago
FapiMemberTools.php
2 years ago
FapiMembership.php
2 years ago
FapiMembershipLoader.php
2 years ago
FapiSanitization.php
2 years ago
FapiTermEnvelope.php
4 years ago
FapiUserUtils.php
3 years ago
FapiClients.php
115 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FapiMember; |
| 4 | |
| 5 | use function json_encode; |
| 6 | |
| 7 | |
| 8 | final class FapiClients { |
| 9 | |
| 10 | |
| 11 | /** |
| 12 | * @var array<FapiApi>&FapiApi[] |
| 13 | */ |
| 14 | private $fapiApis; |
| 15 | |
| 16 | /** |
| 17 | * @param array<FapiApi> &FapiApi[] $fapiApis |
| 18 | */ |
| 19 | public function __construct( $fapiApis ) { |
| 20 | $this->fapiApis = $fapiApis; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @return array<FapiApi> |
| 25 | */ |
| 26 | public function getFapiApis() { |
| 27 | return $this->fapiApis; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @param int $id |
| 32 | * @return false|array<mixed> |
| 33 | */ |
| 34 | public function getInvoice( $id ) { |
| 35 | foreach ( $this->fapiApis as $fapiApi ) { |
| 36 | $response = $fapiApi->getInvoice( $id ); |
| 37 | |
| 38 | if ( is_array( $response ) && ! isset( $response['error'] ) ) { |
| 39 | return $response; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | /** |
| 48 | * @param int $id |
| 49 | * @return false|array<mixed> |
| 50 | */ |
| 51 | public function getVoucher( $id ) { |
| 52 | foreach ( $this->fapiApis as $fapiApi ) { |
| 53 | $response = $fapiApi->getVoucher( $id ); |
| 54 | |
| 55 | if ( is_array( $response ) && ! isset( $response['error'] ) ) { |
| 56 | return $response; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @param string $code |
| 65 | * @return false|array<mixed> |
| 66 | */ |
| 67 | public function getItemTemplate( $code ) { |
| 68 | foreach ( $this->fapiApis as $fapiApi ) { |
| 69 | $response = $fapiApi->getItemTemplate( $code ); |
| 70 | |
| 71 | if ( is_array( $response ) && ! isset( $response['error'] ) ) { |
| 72 | return $response; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @return bool |
| 81 | */ |
| 82 | public function checkCredentials() { |
| 83 | $credentialsOk = true; |
| 84 | |
| 85 | if ( empty( $this->fapiApis ) ) { |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | foreach ( $this->fapiApis as $fapiApi ) { |
| 90 | $credentialsOk = $credentialsOk && $fapiApi->checkCredentials(); |
| 91 | } |
| 92 | |
| 93 | return $credentialsOk; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @return array<string> |
| 98 | */ |
| 99 | public function getLastErrors() { |
| 100 | $out = array(); |
| 101 | |
| 102 | foreach ( $this->fapiApis as $fapiApi ) { |
| 103 | |
| 104 | $lastError = $fapiApi->lastError; |
| 105 | |
| 106 | if ( $lastError !== null ) { |
| 107 | $out[ $fapiApi->getApiUser() ][] = $lastError; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return $out; |
| 112 | } |
| 113 | |
| 114 | } |
| 115 |