1: <?php
2: /*
3: * This file was automatically generated.
4: */
5: namespace Worldline\Acquiring\Sdk\Authentication;
6:
7: /**
8: * Class OAuth2Scopes
9: *
10: * @package Worldline\Acquiring\Sdk\Authentication
11: */
12: class OAuth2Scopes
13: {
14: /**
15: * @var array|null
16: */
17: private static ?array $scopesByOperation = null;
18:
19: /**
20: * @var array|null
21: */
22: private static ?array $allScopes = null;
23:
24: private function __construct()
25: {
26: }
27:
28: private static function initializeScopesByOperationIfNeeded(): void
29: {
30: if (is_null(OAuth2Scopes::$scopesByOperation)) {
31: OAuth2Scopes::$scopesByOperation = [
32: "v1" => [
33: "processPayment" => ["processing_payment"],
34: "getPaymentStatus" => ["processing_payment"],
35: "simpleCaptureOfPayment" => ["processing_payment"],
36: "reverseAuthorization" => ["processing_payment"],
37: "incrementPayment" => ["processing_payment"],
38: "createRefund" => ["processing_refund"],
39: "processStandaloneRefund" => ["processing_refund"],
40: "getRefund" => ["processing_refund"],
41: "captureRefund" => ["processing_refund"],
42: "reverseRefundAuthorization" => ["processing_refund"],
43: "processAccountVerification" => ["processing_accountverification"],
44: "processBalanceInquiry" => ["processing_balanceinquiry"],
45: "technicalReversal" => ["processing_operation_reverse"],
46: "requestDccRate" => ["processing_dcc_rate"],
47: "ping" => ["services_ping"],
48: ],
49: ];
50: OAuth2Scopes::$allScopes = [];
51: foreach (OAuth2Scopes::$scopesByOperation as $operations) {
52: foreach ($operations as $scopes) {
53: OAuth2Scopes::$allScopes = array_merge(OAuth2Scopes::$allScopes, array_values($scopes));
54: }
55: }
56: OAuth2Scopes::$allScopes = array_unique(OAuth2Scopes::$allScopes);
57: }
58: }
59:
60: /**
61: * @return array all available scopes.
62: */
63: public static function all(): array
64: {
65: OAuth2Scopes::initializeScopesByOperationIfNeeded();
66: return OAuth2Scopes::$allScopes;
67: }
68:
69: /**
70: * @param string $apiVersion
71: *
72: * @return array all scopes needed for all operations of the given API version.
73: */
74: public static function forApiVersion(string $apiVersion): array
75: {
76: OAuth2Scopes::initializeScopesByOperationIfNeeded();
77: $operations = OAuth2Scopes::$scopesByOperation[$apiVersion] ?? [];
78: $result = [];
79: foreach ($operations as $scopes) {
80: $result = array_merge($result, $scopes);
81: }
82: return array_unique($result);
83: }
84:
85: /**
86: * @param string $apiVersion
87: * @param string $operationId
88: *
89: * @return array all scopes needed for the given operation of the given API version.
90: */
91: public static function forOperation(string $apiVersion, string $operationId): array
92: {
93: OAuth2Scopes::initializeScopesByOperationIfNeeded();
94: $operations = OAuth2Scopes::$scopesByOperation[$apiVersion] ?? [];
95: return $operations[$operationId] ?? [];
96: }
97:
98: /**
99: * @param string $apiVersion
100: * @param string ...$operationIds
101: *
102: * @return array all scopes needed for the given operations of the given API version.
103: */
104: public static function forOperations(string $apiVersion, string ...$operationIds): array
105: {
106: OAuth2Scopes::initializeScopesByOperationIfNeeded();
107: $operations = OAuth2Scopes::$scopesByOperation[$apiVersion] ?? [];
108: if (count($operationIds) === 1) {
109: return $operations[$operationIds[0]] ?? [];
110: }
111: $result = [];
112: foreach ($operationIds as $operationId) {
113: $scopes = $operations[$operationId] ?? [];
114: $result = array_merge($result, $scopes);
115: }
116: return array_unique($result);
117: }
118:
119: /**
120: * @param callable $filter The filter to apply.
121: * The first argument is the API version, the second is the operation id,
122: * the return value should be true to include the scopes for the API version and operation id,
123: * or false otherwise.
124: * @return array all scopes needed for the operations that pass the given filter.
125: */
126: public static function forFilteredOperations(callable $filter): array
127: {
128: OAuth2Scopes::initializeScopesByOperationIfNeeded();
129: $result = [];
130: foreach (OAuth2Scopes::$scopesByOperation as $apiVersion => $operations) {
131: foreach ($operations as $operationId => $scopes) {
132: if (call_user_func($filter, $apiVersion, $operationId)) {
133: $result = array_merge($result, $scopes);
134: }
135: }
136: }
137: return array_unique($result);
138: }
139: }
140: