@@ -17,105 +17,105 @@ |
||
17 | 17 | |
18 | 18 | trait StatelessResolver |
19 | 19 | { |
20 | - protected function resolveId(EE_Base_Class $source): string |
|
21 | - { |
|
22 | - if (method_exists($source, 'UUID') && is_callable([$source, 'UUID'])) { |
|
23 | - return $source->UUID(); |
|
24 | - } |
|
25 | - |
|
26 | - return Relay::toGlobalId($source->get_model()->item_name(), $source->ID()); |
|
27 | - } |
|
28 | - |
|
29 | - protected function resolveCacheId(EE_Base_Class $source): string |
|
30 | - { |
|
31 | - $item_name = $source->get_model()->item_name(); |
|
32 | - $id = $source->ID(); |
|
33 | - // Since cacheId does not need to be globally unique |
|
34 | - // $uniqid is sufficient, still adding the model name and ID |
|
35 | - // may be we need/use them in future. |
|
36 | - return uniqid("{$item_name}:{$id}:", true); |
|
37 | - } |
|
38 | - |
|
39 | - protected function resolveParent(EE_Base_Class $source): ?EE_Base_Class |
|
40 | - { |
|
41 | - return $source->get_model()->get_one_by_ID($source->parent()); |
|
42 | - } |
|
43 | - |
|
44 | - protected function resolveEvent(EE_Base_Class $source, AppContext $context): ?Deferred |
|
45 | - { |
|
46 | - switch (true) { |
|
47 | - case $source instanceof EE_Datetime: |
|
48 | - $event = $source->event(); |
|
49 | - break; |
|
50 | - case $source instanceof EE_Venue: |
|
51 | - case $source instanceof EE_Ticket: |
|
52 | - $event = $source->get_related_event(); |
|
53 | - break; |
|
54 | - default: |
|
55 | - $event = null; |
|
56 | - break; |
|
57 | - } |
|
58 | - |
|
59 | - if (! ($event instanceof EE_Event)) return null; |
|
60 | - |
|
61 | - return $context->get_loader('post')->load_deferred($event->ID()); |
|
62 | - } |
|
63 | - |
|
64 | - protected function resolveWpUser(EE_Base_Class $source, AppContext $context): ?Deferred |
|
65 | - { |
|
66 | - $user_id = $source->wp_user(); |
|
67 | - |
|
68 | - if (! $user_id) { |
|
69 | - return null; |
|
70 | - } |
|
71 | - |
|
72 | - return $context->get_loader('user')->load_deferred($user_id); |
|
73 | - } |
|
74 | - |
|
75 | - protected function resolveUserId($source): ?string |
|
76 | - { |
|
77 | - $user_id = $source->wp_user(); |
|
78 | - |
|
79 | - if (! $user_id) { |
|
80 | - return null; |
|
81 | - } |
|
82 | - |
|
83 | - return Relay::toGlobalId('user', $user_id); |
|
84 | - } |
|
85 | - |
|
86 | - protected function resolveState($source): ?EE_Base_Class |
|
87 | - { |
|
88 | - $state_id = null; |
|
89 | - |
|
90 | - if ($source instanceof EE_Attendee || $source instanceof EE_Venue) { |
|
91 | - $state_id = $source->state_ID(); |
|
92 | - } |
|
93 | - |
|
94 | - if (! $state_id) { |
|
95 | - return null; |
|
96 | - } |
|
97 | - |
|
98 | - return EEM_State::instance()->get_one_by_ID($state_id); |
|
99 | - } |
|
100 | - |
|
101 | - protected function resolveCountry(EE_Base_Class $source): ?EE_Base_Class |
|
102 | - { |
|
103 | - $country_iso = null; |
|
104 | - |
|
105 | - switch (true) { |
|
106 | - case $source instanceof EE_State: |
|
107 | - $country_iso = $source->country_iso(); |
|
108 | - break; |
|
109 | - case $source instanceof EE_Attendee: |
|
110 | - case $source instanceof EE_Venue: |
|
111 | - $country_iso = $source->country_ID(); |
|
112 | - break; |
|
113 | - } |
|
114 | - |
|
115 | - if (! $country_iso) { |
|
116 | - return null; |
|
117 | - } |
|
118 | - |
|
119 | - return EEM_Country::instance()->get_one_by_ID($country_iso); |
|
120 | - } |
|
20 | + protected function resolveId(EE_Base_Class $source): string |
|
21 | + { |
|
22 | + if (method_exists($source, 'UUID') && is_callable([$source, 'UUID'])) { |
|
23 | + return $source->UUID(); |
|
24 | + } |
|
25 | + |
|
26 | + return Relay::toGlobalId($source->get_model()->item_name(), $source->ID()); |
|
27 | + } |
|
28 | + |
|
29 | + protected function resolveCacheId(EE_Base_Class $source): string |
|
30 | + { |
|
31 | + $item_name = $source->get_model()->item_name(); |
|
32 | + $id = $source->ID(); |
|
33 | + // Since cacheId does not need to be globally unique |
|
34 | + // $uniqid is sufficient, still adding the model name and ID |
|
35 | + // may be we need/use them in future. |
|
36 | + return uniqid("{$item_name}:{$id}:", true); |
|
37 | + } |
|
38 | + |
|
39 | + protected function resolveParent(EE_Base_Class $source): ?EE_Base_Class |
|
40 | + { |
|
41 | + return $source->get_model()->get_one_by_ID($source->parent()); |
|
42 | + } |
|
43 | + |
|
44 | + protected function resolveEvent(EE_Base_Class $source, AppContext $context): ?Deferred |
|
45 | + { |
|
46 | + switch (true) { |
|
47 | + case $source instanceof EE_Datetime: |
|
48 | + $event = $source->event(); |
|
49 | + break; |
|
50 | + case $source instanceof EE_Venue: |
|
51 | + case $source instanceof EE_Ticket: |
|
52 | + $event = $source->get_related_event(); |
|
53 | + break; |
|
54 | + default: |
|
55 | + $event = null; |
|
56 | + break; |
|
57 | + } |
|
58 | + |
|
59 | + if (! ($event instanceof EE_Event)) return null; |
|
60 | + |
|
61 | + return $context->get_loader('post')->load_deferred($event->ID()); |
|
62 | + } |
|
63 | + |
|
64 | + protected function resolveWpUser(EE_Base_Class $source, AppContext $context): ?Deferred |
|
65 | + { |
|
66 | + $user_id = $source->wp_user(); |
|
67 | + |
|
68 | + if (! $user_id) { |
|
69 | + return null; |
|
70 | + } |
|
71 | + |
|
72 | + return $context->get_loader('user')->load_deferred($user_id); |
|
73 | + } |
|
74 | + |
|
75 | + protected function resolveUserId($source): ?string |
|
76 | + { |
|
77 | + $user_id = $source->wp_user(); |
|
78 | + |
|
79 | + if (! $user_id) { |
|
80 | + return null; |
|
81 | + } |
|
82 | + |
|
83 | + return Relay::toGlobalId('user', $user_id); |
|
84 | + } |
|
85 | + |
|
86 | + protected function resolveState($source): ?EE_Base_Class |
|
87 | + { |
|
88 | + $state_id = null; |
|
89 | + |
|
90 | + if ($source instanceof EE_Attendee || $source instanceof EE_Venue) { |
|
91 | + $state_id = $source->state_ID(); |
|
92 | + } |
|
93 | + |
|
94 | + if (! $state_id) { |
|
95 | + return null; |
|
96 | + } |
|
97 | + |
|
98 | + return EEM_State::instance()->get_one_by_ID($state_id); |
|
99 | + } |
|
100 | + |
|
101 | + protected function resolveCountry(EE_Base_Class $source): ?EE_Base_Class |
|
102 | + { |
|
103 | + $country_iso = null; |
|
104 | + |
|
105 | + switch (true) { |
|
106 | + case $source instanceof EE_State: |
|
107 | + $country_iso = $source->country_iso(); |
|
108 | + break; |
|
109 | + case $source instanceof EE_Attendee: |
|
110 | + case $source instanceof EE_Venue: |
|
111 | + $country_iso = $source->country_ID(); |
|
112 | + break; |
|
113 | + } |
|
114 | + |
|
115 | + if (! $country_iso) { |
|
116 | + return null; |
|
117 | + } |
|
118 | + |
|
119 | + return EEM_Country::instance()->get_one_by_ID($country_iso); |
|
120 | + } |
|
121 | 121 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | break; |
57 | 57 | } |
58 | 58 | |
59 | - if (! ($event instanceof EE_Event)) return null; |
|
59 | + if ( ! ($event instanceof EE_Event)) return null; |
|
60 | 60 | |
61 | 61 | return $context->get_loader('post')->load_deferred($event->ID()); |
62 | 62 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | { |
66 | 66 | $user_id = $source->wp_user(); |
67 | 67 | |
68 | - if (! $user_id) { |
|
68 | + if ( ! $user_id) { |
|
69 | 69 | return null; |
70 | 70 | } |
71 | 71 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | { |
77 | 77 | $user_id = $source->wp_user(); |
78 | 78 | |
79 | - if (! $user_id) { |
|
79 | + if ( ! $user_id) { |
|
80 | 80 | return null; |
81 | 81 | } |
82 | 82 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $state_id = $source->state_ID(); |
92 | 92 | } |
93 | 93 | |
94 | - if (! $state_id) { |
|
94 | + if ( ! $state_id) { |
|
95 | 95 | return null; |
96 | 96 | } |
97 | 97 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | break; |
113 | 113 | } |
114 | 114 | |
115 | - if (! $country_iso) { |
|
115 | + if ( ! $country_iso) { |
|
116 | 116 | return null; |
117 | 117 | } |
118 | 118 |
@@ -56,7 +56,9 @@ |
||
56 | 56 | break; |
57 | 57 | } |
58 | 58 | |
59 | - if (! ($event instanceof EE_Event)) return null; |
|
59 | + if (! ($event instanceof EE_Event)) { |
|
60 | + return null; |
|
61 | + } |
|
60 | 62 | |
61 | 63 | return $context->get_loader('post')->load_deferred($event->ID()); |
62 | 64 | } |
@@ -8,26 +8,26 @@ |
||
8 | 8 | |
9 | 9 | class GraphQLNode extends GraphQLInterface |
10 | 10 | { |
11 | - protected function getShortName(): string |
|
12 | - { |
|
13 | - return 'Node'; |
|
14 | - } |
|
11 | + protected function getShortName(): string |
|
12 | + { |
|
13 | + return 'Node'; |
|
14 | + } |
|
15 | 15 | |
16 | - protected function getArrayOfFields(): array |
|
17 | - { |
|
18 | - return [ |
|
19 | - new GraphQLOutputField( |
|
20 | - 'id', |
|
21 | - Type::nonNull(Type::string()), |
|
22 | - null, |
|
23 | - esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
24 | - ), |
|
25 | - new GraphQLOutputField( |
|
26 | - 'dbId', |
|
27 | - Type::nonNull(Type::string()), |
|
28 | - 'ID', |
|
29 | - esc_html__('Database table ID', 'event_espresso') |
|
30 | - ), |
|
31 | - ]; |
|
32 | - } |
|
16 | + protected function getArrayOfFields(): array |
|
17 | + { |
|
18 | + return [ |
|
19 | + new GraphQLOutputField( |
|
20 | + 'id', |
|
21 | + Type::nonNull(Type::string()), |
|
22 | + null, |
|
23 | + esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
24 | + ), |
|
25 | + new GraphQLOutputField( |
|
26 | + 'dbId', |
|
27 | + Type::nonNull(Type::string()), |
|
28 | + 'ID', |
|
29 | + esc_html__('Database table ID', 'event_espresso') |
|
30 | + ), |
|
31 | + ]; |
|
32 | + } |
|
33 | 33 | } |
@@ -29,126 +29,126 @@ |
||
29 | 29 | */ |
30 | 30 | class RestApiSpoofer |
31 | 31 | { |
32 | - protected EED_Core_Rest_Api $rest_module; |
|
32 | + protected EED_Core_Rest_Api $rest_module; |
|
33 | 33 | |
34 | - protected Read $rest_controller; |
|
34 | + protected Read $rest_controller; |
|
35 | 35 | |
36 | - protected WP_REST_Server $wp_rest_server; |
|
36 | + protected WP_REST_Server $wp_rest_server; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * RestApiSpoofer constructor. |
|
41 | - * |
|
42 | - * @param WP_REST_Server $wp_rest_server |
|
43 | - * @param EED_Core_Rest_Api $rest_module |
|
44 | - * @param Read $rest_api |
|
45 | - * @param string $api_version |
|
46 | - */ |
|
47 | - public function __construct( |
|
48 | - WP_REST_Server $wp_rest_server, |
|
49 | - EED_Core_Rest_Api $rest_module, |
|
50 | - Read $rest_api, |
|
51 | - string $api_version = '4.8.36' |
|
52 | - ) { |
|
53 | - $this->wp_rest_server = $wp_rest_server; |
|
54 | - $this->rest_module = $rest_module; |
|
55 | - $this->rest_controller = $rest_api; |
|
56 | - $this->rest_controller->setRequestedVersion($api_version); |
|
57 | - $this->setUpRestServer(); |
|
58 | - } |
|
39 | + /** |
|
40 | + * RestApiSpoofer constructor. |
|
41 | + * |
|
42 | + * @param WP_REST_Server $wp_rest_server |
|
43 | + * @param EED_Core_Rest_Api $rest_module |
|
44 | + * @param Read $rest_api |
|
45 | + * @param string $api_version |
|
46 | + */ |
|
47 | + public function __construct( |
|
48 | + WP_REST_Server $wp_rest_server, |
|
49 | + EED_Core_Rest_Api $rest_module, |
|
50 | + Read $rest_api, |
|
51 | + string $api_version = '4.8.36' |
|
52 | + ) { |
|
53 | + $this->wp_rest_server = $wp_rest_server; |
|
54 | + $this->rest_module = $rest_module; |
|
55 | + $this->rest_controller = $rest_api; |
|
56 | + $this->rest_controller->setRequestedVersion($api_version); |
|
57 | + $this->setUpRestServer(); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - private function setUpRestServer() |
|
62 | - { |
|
63 | - /* @var WP_REST_Server $wp_rest_server */ |
|
64 | - global $wp_rest_server; |
|
65 | - $wp_rest_server = $this->wp_rest_server; |
|
66 | - EED_Core_Rest_Api::set_hooks_both(); |
|
67 | - do_action('rest_api_init', $this->wp_rest_server); |
|
68 | - } |
|
61 | + private function setUpRestServer() |
|
62 | + { |
|
63 | + /* @var WP_REST_Server $wp_rest_server */ |
|
64 | + global $wp_rest_server; |
|
65 | + $wp_rest_server = $this->wp_rest_server; |
|
66 | + EED_Core_Rest_Api::set_hooks_both(); |
|
67 | + do_action('rest_api_init', $this->wp_rest_server); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @param EEM_Base $model |
|
73 | - * @param array $query_params |
|
74 | - * @param string $include |
|
75 | - * @return array |
|
76 | - * @throws EE_Error |
|
77 | - * @throws InvalidArgumentException |
|
78 | - * @throws InvalidDataTypeException |
|
79 | - * @throws InvalidInterfaceException |
|
80 | - * @throws ModelConfigurationException |
|
81 | - * @throws ReflectionException |
|
82 | - * @throws RestException |
|
83 | - * @throws RestPasswordIncorrectException |
|
84 | - * @throws RestPasswordRequiredException |
|
85 | - * @throws UnexpectedEntityException |
|
86 | - * @throws DomainException |
|
87 | - * @since 5.0.0.p |
|
88 | - */ |
|
89 | - public function getOneApiResult(EEM_Base $model, array $query_params, string $include = '') |
|
90 | - { |
|
91 | - if (! array_key_exists('limit', $query_params)) { |
|
92 | - $query_params['limit'] = 1; |
|
93 | - } |
|
94 | - $result = $this->getApiResults($model, $query_params, $include); |
|
95 | - return $result[0] ?? []; |
|
96 | - } |
|
71 | + /** |
|
72 | + * @param EEM_Base $model |
|
73 | + * @param array $query_params |
|
74 | + * @param string $include |
|
75 | + * @return array |
|
76 | + * @throws EE_Error |
|
77 | + * @throws InvalidArgumentException |
|
78 | + * @throws InvalidDataTypeException |
|
79 | + * @throws InvalidInterfaceException |
|
80 | + * @throws ModelConfigurationException |
|
81 | + * @throws ReflectionException |
|
82 | + * @throws RestException |
|
83 | + * @throws RestPasswordIncorrectException |
|
84 | + * @throws RestPasswordRequiredException |
|
85 | + * @throws UnexpectedEntityException |
|
86 | + * @throws DomainException |
|
87 | + * @since 5.0.0.p |
|
88 | + */ |
|
89 | + public function getOneApiResult(EEM_Base $model, array $query_params, string $include = '') |
|
90 | + { |
|
91 | + if (! array_key_exists('limit', $query_params)) { |
|
92 | + $query_params['limit'] = 1; |
|
93 | + } |
|
94 | + $result = $this->getApiResults($model, $query_params, $include); |
|
95 | + return $result[0] ?? []; |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * @param EEM_Base $model |
|
101 | - * @param array $query_params |
|
102 | - * @param string $include |
|
103 | - * @return array |
|
104 | - * @throws EE_Error |
|
105 | - * @throws InvalidArgumentException |
|
106 | - * @throws InvalidDataTypeException |
|
107 | - * @throws InvalidInterfaceException |
|
108 | - * @throws ModelConfigurationException |
|
109 | - * @throws ReflectionException |
|
110 | - * @throws RestException |
|
111 | - * @throws RestPasswordIncorrectException |
|
112 | - * @throws RestPasswordRequiredException |
|
113 | - * @throws UnexpectedEntityException |
|
114 | - * @throws DomainException |
|
115 | - * @since 5.0.0.p |
|
116 | - */ |
|
117 | - public function getApiResults(EEM_Base $model, array $query_params, string $include = ''): array |
|
118 | - { |
|
119 | - if (! array_key_exists('caps', $query_params)) { |
|
120 | - $query_params['caps'] = EEM_Base::caps_read_admin; |
|
121 | - } |
|
122 | - if (! array_key_exists('default_where_conditions', $query_params)) { |
|
123 | - $query_params['default_where_conditions'] = 'none'; |
|
124 | - } |
|
125 | - /** @type array $results */ |
|
126 | - $results = $model->get_all_wpdb_results($query_params); |
|
127 | - $rest_request = new WP_REST_Request(); |
|
128 | - $rest_request->set_param('include', $include); |
|
129 | - $rest_request->set_param('caps', 'edit'); |
|
130 | - $nice_results = []; |
|
131 | - foreach ($results as $result) { |
|
132 | - $nice_results[] = $this->rest_controller->createEntityFromWpdbResult( |
|
133 | - $model, |
|
134 | - $result, |
|
135 | - $rest_request |
|
136 | - ); |
|
137 | - } |
|
138 | - return $nice_results; |
|
139 | - } |
|
99 | + /** |
|
100 | + * @param EEM_Base $model |
|
101 | + * @param array $query_params |
|
102 | + * @param string $include |
|
103 | + * @return array |
|
104 | + * @throws EE_Error |
|
105 | + * @throws InvalidArgumentException |
|
106 | + * @throws InvalidDataTypeException |
|
107 | + * @throws InvalidInterfaceException |
|
108 | + * @throws ModelConfigurationException |
|
109 | + * @throws ReflectionException |
|
110 | + * @throws RestException |
|
111 | + * @throws RestPasswordIncorrectException |
|
112 | + * @throws RestPasswordRequiredException |
|
113 | + * @throws UnexpectedEntityException |
|
114 | + * @throws DomainException |
|
115 | + * @since 5.0.0.p |
|
116 | + */ |
|
117 | + public function getApiResults(EEM_Base $model, array $query_params, string $include = ''): array |
|
118 | + { |
|
119 | + if (! array_key_exists('caps', $query_params)) { |
|
120 | + $query_params['caps'] = EEM_Base::caps_read_admin; |
|
121 | + } |
|
122 | + if (! array_key_exists('default_where_conditions', $query_params)) { |
|
123 | + $query_params['default_where_conditions'] = 'none'; |
|
124 | + } |
|
125 | + /** @type array $results */ |
|
126 | + $results = $model->get_all_wpdb_results($query_params); |
|
127 | + $rest_request = new WP_REST_Request(); |
|
128 | + $rest_request->set_param('include', $include); |
|
129 | + $rest_request->set_param('caps', 'edit'); |
|
130 | + $nice_results = []; |
|
131 | + foreach ($results as $result) { |
|
132 | + $nice_results[] = $this->rest_controller->createEntityFromWpdbResult( |
|
133 | + $model, |
|
134 | + $result, |
|
135 | + $rest_request |
|
136 | + ); |
|
137 | + } |
|
138 | + return $nice_results; |
|
139 | + } |
|
140 | 140 | |
141 | 141 | |
142 | - /** |
|
143 | - * @param string $endpoint |
|
144 | - * @return array |
|
145 | - * @since 5.0.0.p |
|
146 | - */ |
|
147 | - public function getModelSchema(string $endpoint) |
|
148 | - { |
|
149 | - $response = $this->wp_rest_server->dispatch( |
|
150 | - new WP_REST_Request('OPTIONS', "/ee/v4.8.36/$endpoint") |
|
151 | - ); |
|
152 | - return $response->get_data(); |
|
153 | - } |
|
142 | + /** |
|
143 | + * @param string $endpoint |
|
144 | + * @return array |
|
145 | + * @since 5.0.0.p |
|
146 | + */ |
|
147 | + public function getModelSchema(string $endpoint) |
|
148 | + { |
|
149 | + $response = $this->wp_rest_server->dispatch( |
|
150 | + new WP_REST_Request('OPTIONS', "/ee/v4.8.36/$endpoint") |
|
151 | + ); |
|
152 | + return $response->get_data(); |
|
153 | + } |
|
154 | 154 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function getOneApiResult(EEM_Base $model, array $query_params, string $include = '') |
90 | 90 | { |
91 | - if (! array_key_exists('limit', $query_params)) { |
|
91 | + if ( ! array_key_exists('limit', $query_params)) { |
|
92 | 92 | $query_params['limit'] = 1; |
93 | 93 | } |
94 | 94 | $result = $this->getApiResults($model, $query_params, $include); |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function getApiResults(EEM_Base $model, array $query_params, string $include = ''): array |
118 | 118 | { |
119 | - if (! array_key_exists('caps', $query_params)) { |
|
119 | + if ( ! array_key_exists('caps', $query_params)) { |
|
120 | 120 | $query_params['caps'] = EEM_Base::caps_read_admin; |
121 | 121 | } |
122 | - if (! array_key_exists('default_where_conditions', $query_params)) { |
|
122 | + if ( ! array_key_exists('default_where_conditions', $query_params)) { |
|
123 | 123 | $query_params['default_where_conditions'] = 'none'; |
124 | 124 | } |
125 | 125 | /** @type array $results */ |
@@ -31,151 +31,151 @@ |
||
31 | 31 | */ |
32 | 32 | class RegularRequests extends PrimaryRoute |
33 | 33 | { |
34 | - /** |
|
35 | - * called just before matchesCurrentRequest() |
|
36 | - * and allows Route to perform any setup required such as calling setSpecification() |
|
37 | - * |
|
38 | - * @since 5.0.0.p |
|
39 | - */ |
|
40 | - public function initialize() |
|
41 | - { |
|
42 | - $basic_nodes = [ |
|
43 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api', |
|
44 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities', |
|
45 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale', |
|
46 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls', |
|
47 | - ]; |
|
48 | - foreach ($basic_nodes as $basic_node) { |
|
49 | - $this->dependency_map->registerDependencies( |
|
50 | - $basic_node, |
|
51 | - ['EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache] |
|
52 | - ); |
|
53 | - } |
|
54 | - $this->dependency_map->registerDependencies( |
|
55 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions', |
|
56 | - [ |
|
57 | - 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => EE_Dependency_Map::load_from_cache, |
|
58 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
59 | - ] |
|
60 | - ); |
|
61 | - $this->dependency_map->registerDependencies( |
|
62 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings', |
|
63 | - [ |
|
64 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
65 | - 'EventEspresso\core\services\converters\date_time_formats\PhpToUnicode' => EE_Dependency_Map::load_from_cache, |
|
66 | - ] |
|
67 | - ); |
|
68 | - $this->dependency_map->registerDependencies( |
|
69 | - 'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData', |
|
70 | - [ |
|
71 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api' => EE_Dependency_Map::load_from_cache, |
|
72 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config' => EE_Dependency_Map::load_from_cache, |
|
73 | - 'EventEspresso\core\services\assets\JedLocaleData' => EE_Dependency_Map::load_from_cache, |
|
74 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
75 | - ] |
|
76 | - ); |
|
77 | - $this->dependency_map->registerDependencies( |
|
78 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config', |
|
79 | - [ |
|
80 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
81 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain' => EE_Dependency_Map::load_from_cache, |
|
82 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings' => EE_Dependency_Map::load_from_cache, |
|
83 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale' => EE_Dependency_Map::load_from_cache, |
|
84 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency' => EE_Dependency_Map::load_from_cache, |
|
85 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions' => EE_Dependency_Map::load_from_cache, |
|
86 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls' => EE_Dependency_Map::load_from_cache, |
|
87 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
88 | - ] |
|
89 | - ); |
|
90 | - $this->dependency_map->registerDependencies( |
|
91 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser', |
|
92 | - [ |
|
93 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities' => EE_Dependency_Map::load_from_cache, |
|
94 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
95 | - ] |
|
96 | - ); |
|
97 | - $this->dependency_map->registerDependencies( |
|
98 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain', |
|
99 | - [ |
|
100 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
101 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
102 | - ] |
|
103 | - ); |
|
104 | - $this->dependency_map->registerDependencies( |
|
105 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency', |
|
106 | - [ |
|
107 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
108 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
109 | - ] |
|
110 | - ); |
|
111 | - $this->setDataNode( |
|
112 | - $this->loader->getShared('EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData') |
|
113 | - ); |
|
114 | - } |
|
34 | + /** |
|
35 | + * called just before matchesCurrentRequest() |
|
36 | + * and allows Route to perform any setup required such as calling setSpecification() |
|
37 | + * |
|
38 | + * @since 5.0.0.p |
|
39 | + */ |
|
40 | + public function initialize() |
|
41 | + { |
|
42 | + $basic_nodes = [ |
|
43 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api', |
|
44 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities', |
|
45 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale', |
|
46 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls', |
|
47 | + ]; |
|
48 | + foreach ($basic_nodes as $basic_node) { |
|
49 | + $this->dependency_map->registerDependencies( |
|
50 | + $basic_node, |
|
51 | + ['EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache] |
|
52 | + ); |
|
53 | + } |
|
54 | + $this->dependency_map->registerDependencies( |
|
55 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions', |
|
56 | + [ |
|
57 | + 'EventEspresso\core\domain\services\capabilities\FeatureFlags' => EE_Dependency_Map::load_from_cache, |
|
58 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
59 | + ] |
|
60 | + ); |
|
61 | + $this->dependency_map->registerDependencies( |
|
62 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings', |
|
63 | + [ |
|
64 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
65 | + 'EventEspresso\core\services\converters\date_time_formats\PhpToUnicode' => EE_Dependency_Map::load_from_cache, |
|
66 | + ] |
|
67 | + ); |
|
68 | + $this->dependency_map->registerDependencies( |
|
69 | + 'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData', |
|
70 | + [ |
|
71 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api' => EE_Dependency_Map::load_from_cache, |
|
72 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config' => EE_Dependency_Map::load_from_cache, |
|
73 | + 'EventEspresso\core\services\assets\JedLocaleData' => EE_Dependency_Map::load_from_cache, |
|
74 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
75 | + ] |
|
76 | + ); |
|
77 | + $this->dependency_map->registerDependencies( |
|
78 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config', |
|
79 | + [ |
|
80 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
81 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain' => EE_Dependency_Map::load_from_cache, |
|
82 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings' => EE_Dependency_Map::load_from_cache, |
|
83 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale' => EE_Dependency_Map::load_from_cache, |
|
84 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency' => EE_Dependency_Map::load_from_cache, |
|
85 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SitePermissions' => EE_Dependency_Map::load_from_cache, |
|
86 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls' => EE_Dependency_Map::load_from_cache, |
|
87 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
88 | + ] |
|
89 | + ); |
|
90 | + $this->dependency_map->registerDependencies( |
|
91 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser', |
|
92 | + [ |
|
93 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Capabilities' => EE_Dependency_Map::load_from_cache, |
|
94 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
95 | + ] |
|
96 | + ); |
|
97 | + $this->dependency_map->registerDependencies( |
|
98 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain', |
|
99 | + [ |
|
100 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
101 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
102 | + ] |
|
103 | + ); |
|
104 | + $this->dependency_map->registerDependencies( |
|
105 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency', |
|
106 | + [ |
|
107 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
108 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
109 | + ] |
|
110 | + ); |
|
111 | + $this->setDataNode( |
|
112 | + $this->loader->getShared('EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData') |
|
113 | + ); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | |
117 | - /** |
|
118 | - * returns true if the current request matches this route |
|
119 | - * |
|
120 | - * @return bool |
|
121 | - * @since 5.0.0.p |
|
122 | - */ |
|
123 | - public function matchesCurrentRequest(): bool |
|
124 | - { |
|
125 | - return ! $this->request->isActivation() || $this->request->isUnitTesting(); |
|
126 | - } |
|
117 | + /** |
|
118 | + * returns true if the current request matches this route |
|
119 | + * |
|
120 | + * @return bool |
|
121 | + * @since 5.0.0.p |
|
122 | + */ |
|
123 | + public function matchesCurrentRequest(): bool |
|
124 | + { |
|
125 | + return ! $this->request->isActivation() || $this->request->isUnitTesting(); |
|
126 | + } |
|
127 | 127 | |
128 | 128 | |
129 | - /** |
|
130 | - * @since 5.0.0.p |
|
131 | - */ |
|
132 | - protected function registerDependencies() |
|
133 | - { |
|
134 | - $public = ['EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache] + Route::getDefaultDependencies(); |
|
129 | + /** |
|
130 | + * @since 5.0.0.p |
|
131 | + */ |
|
132 | + protected function registerDependencies() |
|
133 | + { |
|
134 | + $public = ['EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache] + Route::getDefaultDependencies(); |
|
135 | 135 | |
136 | - $default_with_barista = [BaristaFactory::class => EE_Dependency_Map::load_from_cache] + |
|
137 | - Route::getDefaultDependencies(); |
|
138 | - $default_with_manifest = [AssetManifestFactory::class => EE_Dependency_Map::load_from_cache] + |
|
139 | - Route::getDefaultDependencies(); |
|
136 | + $default_with_barista = [BaristaFactory::class => EE_Dependency_Map::load_from_cache] + |
|
137 | + Route::getDefaultDependencies(); |
|
138 | + $default_with_manifest = [AssetManifestFactory::class => EE_Dependency_Map::load_from_cache] + |
|
139 | + Route::getDefaultDependencies(); |
|
140 | 140 | |
141 | - $default_routes = [ |
|
142 | - // default dependencies |
|
143 | - ShortcodeRequests::class => Route::getDefaultDependencies(), |
|
144 | - RestApiRequests::class => Route::getDefaultDependencies(), |
|
145 | - SessionRequests::class => Route::getDefaultDependencies(), |
|
146 | - WordPressHeartbeat::class => Route::getDefaultDependencies(), |
|
147 | - AssetRequests::class => $default_with_barista, |
|
148 | - GQLRequests::class => $default_with_manifest, |
|
149 | - // admin dependencies |
|
150 | - AdminRoute::class => AdminRoute::getDefaultDependencies(), |
|
151 | - EspressoBatchJob::class => AdminRoute::getDefaultDependencies(), |
|
152 | - EspressoEventsAdmin::class => AdminRoute::getDefaultDependencies(), |
|
153 | - EspressoEventEditor::class => AdminRoute::getDefaultDependencies(), |
|
154 | - EspressoLegacyAdmin::class => AdminRoute::getDefaultDependencies(), |
|
155 | - GutenbergEditor::class => AdminRoute::getDefaultDependencies(), |
|
156 | - NonEspressoAdminAjax::class => AdminRoute::getDefaultDependencies(), |
|
157 | - WordPressPluginsPage::class => AdminRoute::getDefaultDependencies(), |
|
158 | - WordPressPostsPage::class => AdminRoute::getDefaultDependencies(), |
|
159 | - WordPressProfilePage::class => AdminRoute::getDefaultDependencies(), |
|
160 | - // public dependencies |
|
161 | - PersonalDataRequests::class => $public, |
|
162 | - FrontendRequests::class => $public, |
|
163 | - ]; |
|
164 | - foreach ($default_routes as $route => $dependencies) { |
|
165 | - $this->dependency_map->registerDependencies($route, $dependencies); |
|
166 | - } |
|
167 | - } |
|
141 | + $default_routes = [ |
|
142 | + // default dependencies |
|
143 | + ShortcodeRequests::class => Route::getDefaultDependencies(), |
|
144 | + RestApiRequests::class => Route::getDefaultDependencies(), |
|
145 | + SessionRequests::class => Route::getDefaultDependencies(), |
|
146 | + WordPressHeartbeat::class => Route::getDefaultDependencies(), |
|
147 | + AssetRequests::class => $default_with_barista, |
|
148 | + GQLRequests::class => $default_with_manifest, |
|
149 | + // admin dependencies |
|
150 | + AdminRoute::class => AdminRoute::getDefaultDependencies(), |
|
151 | + EspressoBatchJob::class => AdminRoute::getDefaultDependencies(), |
|
152 | + EspressoEventsAdmin::class => AdminRoute::getDefaultDependencies(), |
|
153 | + EspressoEventEditor::class => AdminRoute::getDefaultDependencies(), |
|
154 | + EspressoLegacyAdmin::class => AdminRoute::getDefaultDependencies(), |
|
155 | + GutenbergEditor::class => AdminRoute::getDefaultDependencies(), |
|
156 | + NonEspressoAdminAjax::class => AdminRoute::getDefaultDependencies(), |
|
157 | + WordPressPluginsPage::class => AdminRoute::getDefaultDependencies(), |
|
158 | + WordPressPostsPage::class => AdminRoute::getDefaultDependencies(), |
|
159 | + WordPressProfilePage::class => AdminRoute::getDefaultDependencies(), |
|
160 | + // public dependencies |
|
161 | + PersonalDataRequests::class => $public, |
|
162 | + FrontendRequests::class => $public, |
|
163 | + ]; |
|
164 | + foreach ($default_routes as $route => $dependencies) { |
|
165 | + $this->dependency_map->registerDependencies($route, $dependencies); |
|
166 | + } |
|
167 | + } |
|
168 | 168 | |
169 | 169 | |
170 | - /** |
|
171 | - * implements logic required to run during request |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - * @since 5.0.0.p |
|
175 | - */ |
|
176 | - protected function requestHandler(): bool |
|
177 | - { |
|
178 | - $this->setRouteRequestType(PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR); |
|
179 | - return true; |
|
180 | - } |
|
170 | + /** |
|
171 | + * implements logic required to run during request |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + * @since 5.0.0.p |
|
175 | + */ |
|
176 | + protected function requestHandler(): bool |
|
177 | + { |
|
178 | + $this->setRouteRequestType(PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR); |
|
179 | + return true; |
|
180 | + } |
|
181 | 181 | } |
@@ -18,46 +18,46 @@ |
||
18 | 18 | class EspressoBatchJob extends AdminRoute |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * returns true if the current request matches this route |
|
23 | - * |
|
24 | - * @return bool |
|
25 | - * @since 5.0.0.p |
|
26 | - */ |
|
27 | - public function matchesCurrentRequest(): bool |
|
28 | - { |
|
29 | - global $pagenow; |
|
30 | - $page = $this->request->getRequestParam('page'); |
|
31 | - return ($pagenow === 'admin.php' || $pagenow === 'admin-ajax.php') |
|
32 | - && $page === 'espresso_batch' |
|
33 | - && parent::matchesCurrentRequest(); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @since 5.0.0.p |
|
39 | - */ |
|
40 | - protected function registerDependencies() |
|
41 | - { |
|
42 | - $this->dependency_map->registerDependencies( |
|
43 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder', |
|
44 | - [ |
|
45 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
46 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
47 | - null, |
|
48 | - ] |
|
49 | - ); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * implements logic required to run during request |
|
55 | - * |
|
56 | - * @return bool |
|
57 | - * @since 5.0.0.p |
|
58 | - */ |
|
59 | - protected function requestHandler(): bool |
|
60 | - { |
|
61 | - return true; |
|
62 | - } |
|
21 | + /** |
|
22 | + * returns true if the current request matches this route |
|
23 | + * |
|
24 | + * @return bool |
|
25 | + * @since 5.0.0.p |
|
26 | + */ |
|
27 | + public function matchesCurrentRequest(): bool |
|
28 | + { |
|
29 | + global $pagenow; |
|
30 | + $page = $this->request->getRequestParam('page'); |
|
31 | + return ($pagenow === 'admin.php' || $pagenow === 'admin-ajax.php') |
|
32 | + && $page === 'espresso_batch' |
|
33 | + && parent::matchesCurrentRequest(); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @since 5.0.0.p |
|
39 | + */ |
|
40 | + protected function registerDependencies() |
|
41 | + { |
|
42 | + $this->dependency_map->registerDependencies( |
|
43 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder', |
|
44 | + [ |
|
45 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
46 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
47 | + null, |
|
48 | + ] |
|
49 | + ); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * implements logic required to run during request |
|
55 | + * |
|
56 | + * @return bool |
|
57 | + * @since 5.0.0.p |
|
58 | + */ |
|
59 | + protected function requestHandler(): bool |
|
60 | + { |
|
61 | + return true; |
|
62 | + } |
|
63 | 63 | } |
@@ -22,677 +22,677 @@ |
||
22 | 22 | */ |
23 | 23 | class EE_Registration_Processor extends EE_Processor_Base |
24 | 24 | { |
25 | - private static ?EE_Registration_Processor $_instance = null; |
|
26 | - |
|
27 | - protected RequestInterface $request; |
|
28 | - |
|
29 | - /** |
|
30 | - * initial reg status at the beginning of this request. |
|
31 | - * indexed by registration ID |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected array $_old_reg_status = []; |
|
36 | - |
|
37 | - /** |
|
38 | - * reg status at the end of the request after all processing. |
|
39 | - * indexed by registration ID |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected array $_new_reg_status = []; |
|
44 | - |
|
45 | - /** |
|
46 | - * amounts paid at the end of the request after all processing. |
|
47 | - * indexed by registration ID |
|
48 | - * |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - protected static array $_amount_paid = []; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @singleton method used to instantiate class object |
|
56 | - * @param RequestInterface|null $request |
|
57 | - * @return EE_Registration_Processor instance |
|
58 | - * @throws InvalidArgumentException |
|
59 | - * @throws InvalidInterfaceException |
|
60 | - * @throws InvalidDataTypeException |
|
61 | - */ |
|
62 | - public static function instance(RequestInterface $request = null): EE_Registration_Processor |
|
63 | - { |
|
64 | - // check if class object is instantiated |
|
65 | - if (! self::$_instance instanceof EE_Registration_Processor) { |
|
66 | - if (! $request instanceof RequestInterface) { |
|
67 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
68 | - } |
|
69 | - self::$_instance = new self($request); |
|
70 | - } |
|
71 | - return self::$_instance; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * EE_Registration_Processor constructor. |
|
77 | - * |
|
78 | - * @param RequestInterface $request |
|
79 | - */ |
|
80 | - public function __construct(RequestInterface $request) |
|
81 | - { |
|
82 | - $this->request = $request; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param int $REG_ID |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function old_reg_status(int $REG_ID): ?string |
|
91 | - { |
|
92 | - return $this->_old_reg_status[ $REG_ID ] ?? null; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @param int $REG_ID |
|
98 | - * @param string $old_reg_status |
|
99 | - */ |
|
100 | - public function set_old_reg_status(int $REG_ID, string $old_reg_status) |
|
101 | - { |
|
102 | - // only set the first time |
|
103 | - if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
104 | - $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @param int $REG_ID |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function new_reg_status(int $REG_ID): ?string |
|
114 | - { |
|
115 | - return $this->_new_reg_status[ $REG_ID ] ?? null; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param int $REG_ID |
|
121 | - * @param string $new_reg_status |
|
122 | - */ |
|
123 | - public function set_new_reg_status(int $REG_ID, string $new_reg_status) |
|
124 | - { |
|
125 | - $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @param int $REG_ID |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - public function reg_status_updated(int $REG_ID): bool |
|
134 | - { |
|
135 | - return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param EE_Registration $registration |
|
141 | - * @throws EE_Error |
|
142 | - * @throws EntityNotFoundException |
|
143 | - * @throws InvalidArgumentException |
|
144 | - * @throws InvalidDataTypeException |
|
145 | - * @throws InvalidInterfaceException |
|
146 | - * @throws ReflectionException |
|
147 | - * @throws RuntimeException |
|
148 | - */ |
|
149 | - public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
150 | - { |
|
151 | - $this->toggle_incomplete_registration_status_to_default( |
|
152 | - $registration, |
|
153 | - false, |
|
154 | - new Context( |
|
155 | - __METHOD__, |
|
156 | - esc_html__( |
|
157 | - 'Executed when the registration status is updated during the registration process just prior to triggering notifications.', |
|
158 | - 'event_espresso' |
|
159 | - ) |
|
160 | - ) |
|
161 | - ); |
|
162 | - $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
163 | - $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
164 | - $registration->save(); |
|
165 | - // trigger notifications |
|
166 | - $this->trigger_registration_update_notifications($registration); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param EE_Registration $registration |
|
172 | - * @param string $new_reg_status |
|
173 | - * @param bool $save TRUE will save the registration if the status is updated, |
|
174 | - * FALSE will leave that up to client code |
|
175 | - * @return bool |
|
176 | - * @throws EE_Error |
|
177 | - * @throws EntityNotFoundException |
|
178 | - * @throws InvalidArgumentException |
|
179 | - * @throws InvalidDataTypeException |
|
180 | - * @throws InvalidInterfaceException |
|
181 | - * @throws ReflectionException |
|
182 | - * @throws RuntimeException |
|
183 | - */ |
|
184 | - public function manually_update_registration_status( |
|
185 | - EE_Registration $registration, |
|
186 | - string $new_reg_status = '', |
|
187 | - bool $save = true |
|
188 | - ): bool { |
|
189 | - // set initial REG_Status |
|
190 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
191 | - // set incoming REG_Status |
|
192 | - $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
193 | - // toggle reg status but only if it has changed and the user can do so |
|
194 | - if ( |
|
195 | - $this->reg_status_updated($registration->ID()) |
|
196 | - && ( |
|
197 | - (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
198 | - || EE_Registry::instance()->CAP->current_user_can( |
|
199 | - 'ee_edit_registration', |
|
200 | - 'toggle_registration_status', |
|
201 | - $registration->ID() |
|
202 | - ) |
|
203 | - ) |
|
204 | - ) { |
|
205 | - // change status to new value |
|
206 | - $updated = $registration->set_status( |
|
207 | - $this->new_reg_status($registration->ID()), |
|
208 | - false, |
|
209 | - new Context( |
|
210 | - __METHOD__, |
|
211 | - esc_html__( |
|
212 | - 'Executed when the registration status is manually updated during the reg process.', |
|
213 | - 'event_espresso' |
|
214 | - ) |
|
215 | - ) |
|
216 | - ); |
|
217 | - if ($updated && $save) { |
|
218 | - $registration->save(); |
|
219 | - } |
|
220 | - return true; |
|
221 | - } |
|
222 | - return false; |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * changes any incomplete registrations to either the event or global default registration status |
|
228 | - * |
|
229 | - * @param EE_Registration $registration |
|
230 | - * @param bool $save TRUE will save the registration if the status is updated, |
|
231 | - * FALSE will leave that up to client code |
|
232 | - * @param ContextInterface|null $context |
|
233 | - * @return void |
|
234 | - * @throws EE_Error |
|
235 | - * @throws InvalidArgumentException |
|
236 | - * @throws ReflectionException |
|
237 | - * @throws RuntimeException |
|
238 | - * @throws EntityNotFoundException |
|
239 | - * @throws InvalidDataTypeException |
|
240 | - * @throws InvalidInterfaceException |
|
241 | - */ |
|
242 | - public function toggle_incomplete_registration_status_to_default( |
|
243 | - EE_Registration $registration, |
|
244 | - bool $save = true, |
|
245 | - ?ContextInterface $context = null |
|
246 | - ) { |
|
247 | - $existing_reg_status = $registration->status_ID(); |
|
248 | - // set initial REG_Status |
|
249 | - $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
250 | - // is the registration currently incomplete ? |
|
251 | - if ($registration->status_ID() === RegStatus::INCOMPLETE) { |
|
252 | - // grab default reg status for the event, if set |
|
253 | - $event_default_registration_status = $registration->defaultRegistrationStatus(); |
|
254 | - // if no default reg status is set for the event, then use the global value |
|
255 | - $STS_ID = ! empty($event_default_registration_status) |
|
256 | - ? $event_default_registration_status |
|
257 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
258 | - // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
259 | - $STS_ID = $STS_ID === RegStatus::APPROVED |
|
260 | - ? RegStatus::PENDING_PAYMENT |
|
261 | - : $STS_ID; |
|
262 | - // set incoming REG_Status |
|
263 | - $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
264 | - $context = $context instanceof ContextInterface |
|
265 | - ? $context |
|
266 | - : new Context( |
|
267 | - __METHOD__, |
|
268 | - esc_html__( |
|
269 | - 'Executed when the registration status is updated to the default reg status during the registration process.', |
|
270 | - 'event_espresso' |
|
271 | - ) |
|
272 | - ); |
|
273 | - $registration->set_status($STS_ID, false, $context); |
|
274 | - if ($save) { |
|
275 | - $registration->save(); |
|
276 | - } |
|
277 | - // don't trigger notifications during IPNs because they will get triggered by |
|
278 | - // EventEspresso\core\services\payments\PostPaymentProcessor |
|
279 | - if (! EE_Processor_Base::$IPN) { |
|
280 | - // otherwise, send out notifications |
|
281 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
282 | - } |
|
283 | - // DEBUG LOG |
|
284 | - // $this->log( |
|
285 | - // __CLASS__, |
|
286 | - // __FUNCTION__, |
|
287 | - // __LINE__, |
|
288 | - // $registration->transaction(), |
|
289 | - // array( |
|
290 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
291 | - // 'deliver_notifications' => has_filter( |
|
292 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
293 | - // ), |
|
294 | - // ) |
|
295 | - // ); |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * @param EE_Registration $registration |
|
302 | - * @param bool $save TRUE will save the registration if the status is updated, |
|
303 | - * FALSE will leave that up to client code |
|
304 | - * @return bool |
|
305 | - * @throws EE_Error |
|
306 | - * @throws EntityNotFoundException |
|
307 | - * @throws InvalidArgumentException |
|
308 | - * @throws InvalidDataTypeException |
|
309 | - * @throws InvalidInterfaceException |
|
310 | - * @throws ReflectionException |
|
311 | - * @throws RuntimeException |
|
312 | - */ |
|
313 | - public function toggle_registration_status_for_default_approved_events( |
|
314 | - EE_Registration $registration, |
|
315 | - bool $save = true |
|
316 | - ): bool { |
|
317 | - $reg_status = $registration->status_ID(); |
|
318 | - // set initial REG_Status |
|
319 | - $this->set_old_reg_status($registration->ID(), $reg_status); |
|
320 | - // if not already, toggle reg status to approved IF the event default reg status is approved |
|
321 | - // ( as long as the registration wasn't cancelled or declined at some point ) |
|
322 | - if ( |
|
323 | - $reg_status !== RegStatus::CANCELLED |
|
324 | - && $reg_status !== RegStatus::DECLINED |
|
325 | - && $reg_status !== RegStatus::APPROVED |
|
326 | - && $registration->defaultRegistrationStatus() === RegStatus::APPROVED |
|
327 | - ) { |
|
328 | - // set incoming REG_Status |
|
329 | - $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
330 | - // toggle status to approved |
|
331 | - $registration->set_status( |
|
332 | - RegStatus::APPROVED, |
|
333 | - false, |
|
334 | - new Context( |
|
335 | - __METHOD__, |
|
336 | - esc_html__( |
|
337 | - 'Executed when the registration status is updated for events with a default reg status of RegStatus::APPROVED.', |
|
338 | - 'event_espresso' |
|
339 | - ) |
|
340 | - ) |
|
341 | - ); |
|
342 | - if ($save) { |
|
343 | - $registration->save(); |
|
344 | - } |
|
345 | - // don't trigger notifications during IPNs because they will get triggered by |
|
346 | - // EventEspresso\core\services\payments\PostPaymentProcessor |
|
347 | - if (! EE_Processor_Base::$IPN) { |
|
348 | - // otherwise, send out notifications |
|
349 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
350 | - } |
|
351 | - // DEBUG LOG |
|
352 | - // $this->log( |
|
353 | - // __CLASS__, |
|
354 | - // __FUNCTION__, |
|
355 | - // __LINE__, |
|
356 | - // $registration->transaction(), |
|
357 | - // array( |
|
358 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
359 | - // 'deliver_notifications' => has_filter( |
|
360 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
361 | - // ), |
|
362 | - // ) |
|
363 | - // ); |
|
364 | - return true; |
|
365 | - } |
|
366 | - return false; |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * toggle_registration_statuses_if_no_monies_owing |
|
372 | - * |
|
373 | - * @param EE_Registration $registration |
|
374 | - * @param bool $save TRUE will save the registration if the status is updated, |
|
375 | - * FALSE will leave that up to client code |
|
376 | - * @param array $additional_details |
|
377 | - * @return bool |
|
378 | - * @throws EE_Error |
|
379 | - * @throws EntityNotFoundException |
|
380 | - * @throws InvalidArgumentException |
|
381 | - * @throws InvalidDataTypeException |
|
382 | - * @throws InvalidInterfaceException |
|
383 | - * @throws ReflectionException |
|
384 | - * @throws RuntimeException |
|
385 | - */ |
|
386 | - public function toggle_registration_status_if_no_monies_owing( |
|
387 | - EE_Registration $registration, |
|
388 | - bool $save = true, |
|
389 | - array $additional_details = [] |
|
390 | - ): bool { |
|
391 | - // set initial REG_Status |
|
392 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
393 | - // was a payment just made ? |
|
394 | - $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
395 | - && $additional_details['payment_updates'] |
|
396 | - && $additional_details['last_payment'] instanceof EE_Payment |
|
397 | - ? $additional_details['last_payment'] |
|
398 | - : null; |
|
399 | - $total_paid = array_sum(self::$_amount_paid); |
|
400 | - // toggle reg status to approved IF |
|
401 | - if ( |
|
402 | - // REG status is pending payment |
|
403 | - $registration->status_ID() === RegStatus::PENDING_PAYMENT |
|
404 | - // AND no monies are owing |
|
405 | - && ( |
|
406 | - ( |
|
407 | - $registration->transaction()->is_completed() |
|
408 | - || $registration->transaction()->is_overpaid() |
|
409 | - || $registration->transaction()->is_free() |
|
410 | - || apply_filters( |
|
411 | - 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
412 | - false, |
|
413 | - $registration |
|
414 | - ) |
|
415 | - ) |
|
416 | - || ( |
|
417 | - $payment instanceof EE_Payment && $payment->is_approved() |
|
418 | - // this specific registration has not yet been paid for |
|
419 | - && ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
420 | - // payment amount, less what we have already attributed to other registrations, |
|
421 | - // is greater than this registration's final price |
|
422 | - && $payment->amount() - $total_paid >= $registration->final_price() |
|
423 | - ) |
|
424 | - ) |
|
425 | - ) { |
|
426 | - // mark as paid |
|
427 | - self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
428 | - // track new REG_Status |
|
429 | - $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
430 | - // toggle status to approved |
|
431 | - $registration->set_status( |
|
432 | - RegStatus::APPROVED, |
|
433 | - false, |
|
434 | - new Context( |
|
435 | - __METHOD__, |
|
436 | - esc_html__( |
|
437 | - 'Executed when the registration status is updated to RegStatus::APPROVED when no monies are owing.', |
|
438 | - 'event_espresso' |
|
439 | - ) |
|
440 | - ) |
|
441 | - ); |
|
442 | - if ($save) { |
|
443 | - $registration->save(); |
|
444 | - } |
|
445 | - // don't trigger notifications during IPNs because they will get triggered by |
|
446 | - // EventEspresso\core\services\payments\PostPaymentProcessor |
|
447 | - if (! EE_Processor_Base::$IPN) { |
|
448 | - // otherwise, send out notifications |
|
449 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
450 | - } |
|
451 | - // DEBUG LOG |
|
452 | - // $this->log( |
|
453 | - // __CLASS__, |
|
454 | - // __FUNCTION__, |
|
455 | - // __LINE__, |
|
456 | - // $registration->transaction(), |
|
457 | - // array( |
|
458 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
459 | - // 'deliver_notifications' => has_filter( |
|
460 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
461 | - // ), |
|
462 | - // ) |
|
463 | - // ); |
|
464 | - return true; |
|
465 | - } |
|
466 | - return false; |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * @param EE_Registration|null $registration |
|
472 | - * @param array $additional_details |
|
473 | - * @return void |
|
474 | - */ |
|
475 | - public function trigger_registration_update_notifications( |
|
476 | - ?EE_Registration $registration, |
|
477 | - array $additional_details = [] |
|
478 | - ) { |
|
479 | - try { |
|
480 | - if (! $registration instanceof EE_Registration) { |
|
481 | - throw new EE_Error( |
|
482 | - esc_html__('An invalid registration was received.', 'event_espresso') |
|
483 | - ); |
|
484 | - } |
|
485 | - // EE_Registry::instance()->load_helper('Debug_Tools'); |
|
486 | - // EEH_Debug_Tools::log( |
|
487 | - // __CLASS__, |
|
488 | - // __FUNCTION__, |
|
489 | - // __LINE__, |
|
490 | - // array($registration->transaction(), $additional_details), |
|
491 | - // false, |
|
492 | - // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
493 | - // ); |
|
494 | - if ( |
|
495 | - ! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int') |
|
496 | - && ! $registration->is_primary_registrant() |
|
497 | - ) { |
|
498 | - return; |
|
499 | - } |
|
500 | - do_action( |
|
501 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
502 | - $registration, |
|
503 | - $additional_details |
|
504 | - ); |
|
505 | - } catch (Exception $e) { |
|
506 | - EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
507 | - } |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
513 | - * |
|
514 | - * @param EE_Registration $registration |
|
515 | - * @param array $additional_details |
|
516 | - * @return bool |
|
517 | - * @throws EE_Error |
|
518 | - * @throws EntityNotFoundException |
|
519 | - * @throws InvalidArgumentException |
|
520 | - * @throws InvalidDataTypeException |
|
521 | - * @throws InvalidInterfaceException |
|
522 | - * @throws ReflectionException |
|
523 | - * @throws RuntimeException |
|
524 | - */ |
|
525 | - public function update_registration_after_checkout_or_payment( |
|
526 | - EE_Registration $registration, |
|
527 | - array $additional_details = [] |
|
528 | - ): bool { |
|
529 | - // set initial REG_Status |
|
530 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
531 | - // if the registration status gets updated, then save the registration |
|
532 | - if ( |
|
533 | - $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
534 | - || $this->toggle_registration_status_if_no_monies_owing( |
|
535 | - $registration, |
|
536 | - false, |
|
537 | - $additional_details |
|
538 | - ) |
|
539 | - ) { |
|
540 | - $registration->save(); |
|
541 | - } |
|
542 | - // set new REG_Status |
|
543 | - $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
544 | - return $this->reg_status_updated($registration->ID()) |
|
545 | - && $this->new_reg_status($registration->ID()) === RegStatus::APPROVED; |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * Updates the registration' final prices based on the current line item tree (taking into account |
|
551 | - * discounts, taxes, and other line items unrelated to tickets.) |
|
552 | - * |
|
553 | - * @param EE_Transaction $transaction |
|
554 | - * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
555 | - * @return void |
|
556 | - * @throws EE_Error |
|
557 | - * @throws InvalidArgumentException |
|
558 | - * @throws InvalidDataTypeException |
|
559 | - * @throws InvalidInterfaceException |
|
560 | - * @throws RuntimeException |
|
561 | - * @throws ReflectionException |
|
562 | - */ |
|
563 | - public function update_registration_final_prices(EE_Transaction $transaction, bool $save_regs = true) |
|
564 | - { |
|
565 | - $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
566 | - $transaction->total_line_item() |
|
567 | - ); |
|
568 | - foreach ($transaction->registrations() as $registration) { |
|
569 | - /** @var EE_Line_Item $line_item */ |
|
570 | - $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
571 | - if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
572 | - $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
573 | - if ($save_regs) { |
|
574 | - $registration->save(); |
|
575 | - } |
|
576 | - } |
|
577 | - } |
|
578 | - // and make sure there's no rounding problem |
|
579 | - $this->fix_reg_final_price_rounding_issue($transaction); |
|
580 | - } |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * Makes sure there is no rounding errors for the REG_final_prices. |
|
585 | - * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
586 | - * they will each be for $0.99333333, which gets rounded to $1 again. |
|
587 | - * So the transaction total will be $2.99, but each registration will be for $1, |
|
588 | - * so if each registrant paid individually they will have overpaid by $0.01. |
|
589 | - * So in order to overcome this, we check for any difference, and if there is a difference |
|
590 | - * we just grab one registrant at random and make them responsible for it. |
|
591 | - * This should be used after setting REG_final_prices (it's done automatically as part of |
|
592 | - * EE_Registration_Processor::update_registration_final_prices()) |
|
593 | - * |
|
594 | - * @param EE_Transaction $transaction |
|
595 | - * @return bool success verifying that there is NO difference after this method is done |
|
596 | - * @throws EE_Error |
|
597 | - * @throws InvalidArgumentException |
|
598 | - * @throws InvalidDataTypeException |
|
599 | - * @throws InvalidInterfaceException |
|
600 | - * @throws ReflectionException |
|
601 | - */ |
|
602 | - public function fix_reg_final_price_rounding_issue(EE_Transaction $transaction): bool |
|
603 | - { |
|
604 | - $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
605 | - [ |
|
606 | - [ |
|
607 | - 'TXN_ID' => $transaction->ID(), |
|
608 | - ], |
|
609 | - ], |
|
610 | - 'REG_final_price' |
|
611 | - ); |
|
612 | - $diff = $transaction->total() - $reg_final_price_sum; |
|
613 | - // ok then, just grab one of the registrations |
|
614 | - if ($diff !== 0.0) { |
|
615 | - $a_reg = EEM_Registration::instance()->get_one( |
|
616 | - [ |
|
617 | - [ |
|
618 | - 'TXN_ID' => $transaction->ID(), |
|
619 | - ], |
|
620 | - ] |
|
621 | - ); |
|
622 | - return $a_reg instanceof EE_Registration |
|
623 | - && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]); |
|
624 | - } |
|
625 | - return true; |
|
626 | - } |
|
627 | - |
|
628 | - |
|
629 | - /** |
|
630 | - * @param EE_Registration $registration |
|
631 | - * @param array $closed_reg_statuses |
|
632 | - * @param bool $update_reg |
|
633 | - * @return bool |
|
634 | - * @throws EE_Error |
|
635 | - * @throws RuntimeException |
|
636 | - * @throws ReflectionException |
|
637 | - */ |
|
638 | - public function update_registration_after_being_canceled_or_declined( |
|
639 | - EE_Registration $registration, |
|
640 | - array $closed_reg_statuses = [], |
|
641 | - bool $update_reg = true |
|
642 | - ): bool { |
|
643 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
644 | - $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
645 | - ? $closed_reg_statuses |
|
646 | - : EEM_Registration::closed_reg_statuses(); |
|
647 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
648 | - return false; |
|
649 | - } |
|
650 | - // release a reserved ticket by decrementing ticket and datetime reserved values |
|
651 | - $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
652 | - $registration->set_final_price(0); |
|
653 | - if ($update_reg) { |
|
654 | - $registration->save(); |
|
655 | - } |
|
656 | - return true; |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - /** |
|
661 | - * @param EE_Registration $registration |
|
662 | - * @param array $closed_reg_statuses |
|
663 | - * @param bool $update_reg |
|
664 | - * @return bool |
|
665 | - * @throws EE_Error |
|
666 | - * @throws RuntimeException |
|
667 | - * @throws ReflectionException |
|
668 | - */ |
|
669 | - public function update_canceled_or_declined_registration_after_being_reinstated( |
|
670 | - EE_Registration $registration, |
|
671 | - array $closed_reg_statuses = [], |
|
672 | - bool $update_reg = true |
|
673 | - ): bool { |
|
674 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
675 | - $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
676 | - : EEM_Registration::closed_reg_statuses(); |
|
677 | - if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
678 | - return false; |
|
679 | - } |
|
680 | - $ticket = $registration->ticket(); |
|
681 | - if (! $ticket instanceof EE_Ticket) { |
|
682 | - throw new EE_Error( |
|
683 | - sprintf( |
|
684 | - esc_html__( |
|
685 | - 'The Ticket for Registration %1$d was not found or is invalid.', |
|
686 | - 'event_espresso' |
|
687 | - ), |
|
688 | - $registration->ticket_ID() |
|
689 | - ) |
|
690 | - ); |
|
691 | - } |
|
692 | - $registration->set_final_price($ticket->price()); |
|
693 | - if ($update_reg) { |
|
694 | - $registration->save(); |
|
695 | - } |
|
696 | - return true; |
|
697 | - } |
|
25 | + private static ?EE_Registration_Processor $_instance = null; |
|
26 | + |
|
27 | + protected RequestInterface $request; |
|
28 | + |
|
29 | + /** |
|
30 | + * initial reg status at the beginning of this request. |
|
31 | + * indexed by registration ID |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected array $_old_reg_status = []; |
|
36 | + |
|
37 | + /** |
|
38 | + * reg status at the end of the request after all processing. |
|
39 | + * indexed by registration ID |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected array $_new_reg_status = []; |
|
44 | + |
|
45 | + /** |
|
46 | + * amounts paid at the end of the request after all processing. |
|
47 | + * indexed by registration ID |
|
48 | + * |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + protected static array $_amount_paid = []; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @singleton method used to instantiate class object |
|
56 | + * @param RequestInterface|null $request |
|
57 | + * @return EE_Registration_Processor instance |
|
58 | + * @throws InvalidArgumentException |
|
59 | + * @throws InvalidInterfaceException |
|
60 | + * @throws InvalidDataTypeException |
|
61 | + */ |
|
62 | + public static function instance(RequestInterface $request = null): EE_Registration_Processor |
|
63 | + { |
|
64 | + // check if class object is instantiated |
|
65 | + if (! self::$_instance instanceof EE_Registration_Processor) { |
|
66 | + if (! $request instanceof RequestInterface) { |
|
67 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
68 | + } |
|
69 | + self::$_instance = new self($request); |
|
70 | + } |
|
71 | + return self::$_instance; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * EE_Registration_Processor constructor. |
|
77 | + * |
|
78 | + * @param RequestInterface $request |
|
79 | + */ |
|
80 | + public function __construct(RequestInterface $request) |
|
81 | + { |
|
82 | + $this->request = $request; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param int $REG_ID |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function old_reg_status(int $REG_ID): ?string |
|
91 | + { |
|
92 | + return $this->_old_reg_status[ $REG_ID ] ?? null; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @param int $REG_ID |
|
98 | + * @param string $old_reg_status |
|
99 | + */ |
|
100 | + public function set_old_reg_status(int $REG_ID, string $old_reg_status) |
|
101 | + { |
|
102 | + // only set the first time |
|
103 | + if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
104 | + $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @param int $REG_ID |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function new_reg_status(int $REG_ID): ?string |
|
114 | + { |
|
115 | + return $this->_new_reg_status[ $REG_ID ] ?? null; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param int $REG_ID |
|
121 | + * @param string $new_reg_status |
|
122 | + */ |
|
123 | + public function set_new_reg_status(int $REG_ID, string $new_reg_status) |
|
124 | + { |
|
125 | + $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @param int $REG_ID |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + public function reg_status_updated(int $REG_ID): bool |
|
134 | + { |
|
135 | + return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param EE_Registration $registration |
|
141 | + * @throws EE_Error |
|
142 | + * @throws EntityNotFoundException |
|
143 | + * @throws InvalidArgumentException |
|
144 | + * @throws InvalidDataTypeException |
|
145 | + * @throws InvalidInterfaceException |
|
146 | + * @throws ReflectionException |
|
147 | + * @throws RuntimeException |
|
148 | + */ |
|
149 | + public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
150 | + { |
|
151 | + $this->toggle_incomplete_registration_status_to_default( |
|
152 | + $registration, |
|
153 | + false, |
|
154 | + new Context( |
|
155 | + __METHOD__, |
|
156 | + esc_html__( |
|
157 | + 'Executed when the registration status is updated during the registration process just prior to triggering notifications.', |
|
158 | + 'event_espresso' |
|
159 | + ) |
|
160 | + ) |
|
161 | + ); |
|
162 | + $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
163 | + $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
164 | + $registration->save(); |
|
165 | + // trigger notifications |
|
166 | + $this->trigger_registration_update_notifications($registration); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param EE_Registration $registration |
|
172 | + * @param string $new_reg_status |
|
173 | + * @param bool $save TRUE will save the registration if the status is updated, |
|
174 | + * FALSE will leave that up to client code |
|
175 | + * @return bool |
|
176 | + * @throws EE_Error |
|
177 | + * @throws EntityNotFoundException |
|
178 | + * @throws InvalidArgumentException |
|
179 | + * @throws InvalidDataTypeException |
|
180 | + * @throws InvalidInterfaceException |
|
181 | + * @throws ReflectionException |
|
182 | + * @throws RuntimeException |
|
183 | + */ |
|
184 | + public function manually_update_registration_status( |
|
185 | + EE_Registration $registration, |
|
186 | + string $new_reg_status = '', |
|
187 | + bool $save = true |
|
188 | + ): bool { |
|
189 | + // set initial REG_Status |
|
190 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
191 | + // set incoming REG_Status |
|
192 | + $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
193 | + // toggle reg status but only if it has changed and the user can do so |
|
194 | + if ( |
|
195 | + $this->reg_status_updated($registration->ID()) |
|
196 | + && ( |
|
197 | + (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
198 | + || EE_Registry::instance()->CAP->current_user_can( |
|
199 | + 'ee_edit_registration', |
|
200 | + 'toggle_registration_status', |
|
201 | + $registration->ID() |
|
202 | + ) |
|
203 | + ) |
|
204 | + ) { |
|
205 | + // change status to new value |
|
206 | + $updated = $registration->set_status( |
|
207 | + $this->new_reg_status($registration->ID()), |
|
208 | + false, |
|
209 | + new Context( |
|
210 | + __METHOD__, |
|
211 | + esc_html__( |
|
212 | + 'Executed when the registration status is manually updated during the reg process.', |
|
213 | + 'event_espresso' |
|
214 | + ) |
|
215 | + ) |
|
216 | + ); |
|
217 | + if ($updated && $save) { |
|
218 | + $registration->save(); |
|
219 | + } |
|
220 | + return true; |
|
221 | + } |
|
222 | + return false; |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * changes any incomplete registrations to either the event or global default registration status |
|
228 | + * |
|
229 | + * @param EE_Registration $registration |
|
230 | + * @param bool $save TRUE will save the registration if the status is updated, |
|
231 | + * FALSE will leave that up to client code |
|
232 | + * @param ContextInterface|null $context |
|
233 | + * @return void |
|
234 | + * @throws EE_Error |
|
235 | + * @throws InvalidArgumentException |
|
236 | + * @throws ReflectionException |
|
237 | + * @throws RuntimeException |
|
238 | + * @throws EntityNotFoundException |
|
239 | + * @throws InvalidDataTypeException |
|
240 | + * @throws InvalidInterfaceException |
|
241 | + */ |
|
242 | + public function toggle_incomplete_registration_status_to_default( |
|
243 | + EE_Registration $registration, |
|
244 | + bool $save = true, |
|
245 | + ?ContextInterface $context = null |
|
246 | + ) { |
|
247 | + $existing_reg_status = $registration->status_ID(); |
|
248 | + // set initial REG_Status |
|
249 | + $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
250 | + // is the registration currently incomplete ? |
|
251 | + if ($registration->status_ID() === RegStatus::INCOMPLETE) { |
|
252 | + // grab default reg status for the event, if set |
|
253 | + $event_default_registration_status = $registration->defaultRegistrationStatus(); |
|
254 | + // if no default reg status is set for the event, then use the global value |
|
255 | + $STS_ID = ! empty($event_default_registration_status) |
|
256 | + ? $event_default_registration_status |
|
257 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
258 | + // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
259 | + $STS_ID = $STS_ID === RegStatus::APPROVED |
|
260 | + ? RegStatus::PENDING_PAYMENT |
|
261 | + : $STS_ID; |
|
262 | + // set incoming REG_Status |
|
263 | + $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
264 | + $context = $context instanceof ContextInterface |
|
265 | + ? $context |
|
266 | + : new Context( |
|
267 | + __METHOD__, |
|
268 | + esc_html__( |
|
269 | + 'Executed when the registration status is updated to the default reg status during the registration process.', |
|
270 | + 'event_espresso' |
|
271 | + ) |
|
272 | + ); |
|
273 | + $registration->set_status($STS_ID, false, $context); |
|
274 | + if ($save) { |
|
275 | + $registration->save(); |
|
276 | + } |
|
277 | + // don't trigger notifications during IPNs because they will get triggered by |
|
278 | + // EventEspresso\core\services\payments\PostPaymentProcessor |
|
279 | + if (! EE_Processor_Base::$IPN) { |
|
280 | + // otherwise, send out notifications |
|
281 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
282 | + } |
|
283 | + // DEBUG LOG |
|
284 | + // $this->log( |
|
285 | + // __CLASS__, |
|
286 | + // __FUNCTION__, |
|
287 | + // __LINE__, |
|
288 | + // $registration->transaction(), |
|
289 | + // array( |
|
290 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
291 | + // 'deliver_notifications' => has_filter( |
|
292 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
293 | + // ), |
|
294 | + // ) |
|
295 | + // ); |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * @param EE_Registration $registration |
|
302 | + * @param bool $save TRUE will save the registration if the status is updated, |
|
303 | + * FALSE will leave that up to client code |
|
304 | + * @return bool |
|
305 | + * @throws EE_Error |
|
306 | + * @throws EntityNotFoundException |
|
307 | + * @throws InvalidArgumentException |
|
308 | + * @throws InvalidDataTypeException |
|
309 | + * @throws InvalidInterfaceException |
|
310 | + * @throws ReflectionException |
|
311 | + * @throws RuntimeException |
|
312 | + */ |
|
313 | + public function toggle_registration_status_for_default_approved_events( |
|
314 | + EE_Registration $registration, |
|
315 | + bool $save = true |
|
316 | + ): bool { |
|
317 | + $reg_status = $registration->status_ID(); |
|
318 | + // set initial REG_Status |
|
319 | + $this->set_old_reg_status($registration->ID(), $reg_status); |
|
320 | + // if not already, toggle reg status to approved IF the event default reg status is approved |
|
321 | + // ( as long as the registration wasn't cancelled or declined at some point ) |
|
322 | + if ( |
|
323 | + $reg_status !== RegStatus::CANCELLED |
|
324 | + && $reg_status !== RegStatus::DECLINED |
|
325 | + && $reg_status !== RegStatus::APPROVED |
|
326 | + && $registration->defaultRegistrationStatus() === RegStatus::APPROVED |
|
327 | + ) { |
|
328 | + // set incoming REG_Status |
|
329 | + $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
330 | + // toggle status to approved |
|
331 | + $registration->set_status( |
|
332 | + RegStatus::APPROVED, |
|
333 | + false, |
|
334 | + new Context( |
|
335 | + __METHOD__, |
|
336 | + esc_html__( |
|
337 | + 'Executed when the registration status is updated for events with a default reg status of RegStatus::APPROVED.', |
|
338 | + 'event_espresso' |
|
339 | + ) |
|
340 | + ) |
|
341 | + ); |
|
342 | + if ($save) { |
|
343 | + $registration->save(); |
|
344 | + } |
|
345 | + // don't trigger notifications during IPNs because they will get triggered by |
|
346 | + // EventEspresso\core\services\payments\PostPaymentProcessor |
|
347 | + if (! EE_Processor_Base::$IPN) { |
|
348 | + // otherwise, send out notifications |
|
349 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
350 | + } |
|
351 | + // DEBUG LOG |
|
352 | + // $this->log( |
|
353 | + // __CLASS__, |
|
354 | + // __FUNCTION__, |
|
355 | + // __LINE__, |
|
356 | + // $registration->transaction(), |
|
357 | + // array( |
|
358 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
359 | + // 'deliver_notifications' => has_filter( |
|
360 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
361 | + // ), |
|
362 | + // ) |
|
363 | + // ); |
|
364 | + return true; |
|
365 | + } |
|
366 | + return false; |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * toggle_registration_statuses_if_no_monies_owing |
|
372 | + * |
|
373 | + * @param EE_Registration $registration |
|
374 | + * @param bool $save TRUE will save the registration if the status is updated, |
|
375 | + * FALSE will leave that up to client code |
|
376 | + * @param array $additional_details |
|
377 | + * @return bool |
|
378 | + * @throws EE_Error |
|
379 | + * @throws EntityNotFoundException |
|
380 | + * @throws InvalidArgumentException |
|
381 | + * @throws InvalidDataTypeException |
|
382 | + * @throws InvalidInterfaceException |
|
383 | + * @throws ReflectionException |
|
384 | + * @throws RuntimeException |
|
385 | + */ |
|
386 | + public function toggle_registration_status_if_no_monies_owing( |
|
387 | + EE_Registration $registration, |
|
388 | + bool $save = true, |
|
389 | + array $additional_details = [] |
|
390 | + ): bool { |
|
391 | + // set initial REG_Status |
|
392 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
393 | + // was a payment just made ? |
|
394 | + $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
395 | + && $additional_details['payment_updates'] |
|
396 | + && $additional_details['last_payment'] instanceof EE_Payment |
|
397 | + ? $additional_details['last_payment'] |
|
398 | + : null; |
|
399 | + $total_paid = array_sum(self::$_amount_paid); |
|
400 | + // toggle reg status to approved IF |
|
401 | + if ( |
|
402 | + // REG status is pending payment |
|
403 | + $registration->status_ID() === RegStatus::PENDING_PAYMENT |
|
404 | + // AND no monies are owing |
|
405 | + && ( |
|
406 | + ( |
|
407 | + $registration->transaction()->is_completed() |
|
408 | + || $registration->transaction()->is_overpaid() |
|
409 | + || $registration->transaction()->is_free() |
|
410 | + || apply_filters( |
|
411 | + 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
412 | + false, |
|
413 | + $registration |
|
414 | + ) |
|
415 | + ) |
|
416 | + || ( |
|
417 | + $payment instanceof EE_Payment && $payment->is_approved() |
|
418 | + // this specific registration has not yet been paid for |
|
419 | + && ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
420 | + // payment amount, less what we have already attributed to other registrations, |
|
421 | + // is greater than this registration's final price |
|
422 | + && $payment->amount() - $total_paid >= $registration->final_price() |
|
423 | + ) |
|
424 | + ) |
|
425 | + ) { |
|
426 | + // mark as paid |
|
427 | + self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
428 | + // track new REG_Status |
|
429 | + $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
430 | + // toggle status to approved |
|
431 | + $registration->set_status( |
|
432 | + RegStatus::APPROVED, |
|
433 | + false, |
|
434 | + new Context( |
|
435 | + __METHOD__, |
|
436 | + esc_html__( |
|
437 | + 'Executed when the registration status is updated to RegStatus::APPROVED when no monies are owing.', |
|
438 | + 'event_espresso' |
|
439 | + ) |
|
440 | + ) |
|
441 | + ); |
|
442 | + if ($save) { |
|
443 | + $registration->save(); |
|
444 | + } |
|
445 | + // don't trigger notifications during IPNs because they will get triggered by |
|
446 | + // EventEspresso\core\services\payments\PostPaymentProcessor |
|
447 | + if (! EE_Processor_Base::$IPN) { |
|
448 | + // otherwise, send out notifications |
|
449 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
450 | + } |
|
451 | + // DEBUG LOG |
|
452 | + // $this->log( |
|
453 | + // __CLASS__, |
|
454 | + // __FUNCTION__, |
|
455 | + // __LINE__, |
|
456 | + // $registration->transaction(), |
|
457 | + // array( |
|
458 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
459 | + // 'deliver_notifications' => has_filter( |
|
460 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
461 | + // ), |
|
462 | + // ) |
|
463 | + // ); |
|
464 | + return true; |
|
465 | + } |
|
466 | + return false; |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * @param EE_Registration|null $registration |
|
472 | + * @param array $additional_details |
|
473 | + * @return void |
|
474 | + */ |
|
475 | + public function trigger_registration_update_notifications( |
|
476 | + ?EE_Registration $registration, |
|
477 | + array $additional_details = [] |
|
478 | + ) { |
|
479 | + try { |
|
480 | + if (! $registration instanceof EE_Registration) { |
|
481 | + throw new EE_Error( |
|
482 | + esc_html__('An invalid registration was received.', 'event_espresso') |
|
483 | + ); |
|
484 | + } |
|
485 | + // EE_Registry::instance()->load_helper('Debug_Tools'); |
|
486 | + // EEH_Debug_Tools::log( |
|
487 | + // __CLASS__, |
|
488 | + // __FUNCTION__, |
|
489 | + // __LINE__, |
|
490 | + // array($registration->transaction(), $additional_details), |
|
491 | + // false, |
|
492 | + // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
493 | + // ); |
|
494 | + if ( |
|
495 | + ! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int') |
|
496 | + && ! $registration->is_primary_registrant() |
|
497 | + ) { |
|
498 | + return; |
|
499 | + } |
|
500 | + do_action( |
|
501 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
502 | + $registration, |
|
503 | + $additional_details |
|
504 | + ); |
|
505 | + } catch (Exception $e) { |
|
506 | + EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
507 | + } |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
513 | + * |
|
514 | + * @param EE_Registration $registration |
|
515 | + * @param array $additional_details |
|
516 | + * @return bool |
|
517 | + * @throws EE_Error |
|
518 | + * @throws EntityNotFoundException |
|
519 | + * @throws InvalidArgumentException |
|
520 | + * @throws InvalidDataTypeException |
|
521 | + * @throws InvalidInterfaceException |
|
522 | + * @throws ReflectionException |
|
523 | + * @throws RuntimeException |
|
524 | + */ |
|
525 | + public function update_registration_after_checkout_or_payment( |
|
526 | + EE_Registration $registration, |
|
527 | + array $additional_details = [] |
|
528 | + ): bool { |
|
529 | + // set initial REG_Status |
|
530 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
531 | + // if the registration status gets updated, then save the registration |
|
532 | + if ( |
|
533 | + $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
534 | + || $this->toggle_registration_status_if_no_monies_owing( |
|
535 | + $registration, |
|
536 | + false, |
|
537 | + $additional_details |
|
538 | + ) |
|
539 | + ) { |
|
540 | + $registration->save(); |
|
541 | + } |
|
542 | + // set new REG_Status |
|
543 | + $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
544 | + return $this->reg_status_updated($registration->ID()) |
|
545 | + && $this->new_reg_status($registration->ID()) === RegStatus::APPROVED; |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * Updates the registration' final prices based on the current line item tree (taking into account |
|
551 | + * discounts, taxes, and other line items unrelated to tickets.) |
|
552 | + * |
|
553 | + * @param EE_Transaction $transaction |
|
554 | + * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
555 | + * @return void |
|
556 | + * @throws EE_Error |
|
557 | + * @throws InvalidArgumentException |
|
558 | + * @throws InvalidDataTypeException |
|
559 | + * @throws InvalidInterfaceException |
|
560 | + * @throws RuntimeException |
|
561 | + * @throws ReflectionException |
|
562 | + */ |
|
563 | + public function update_registration_final_prices(EE_Transaction $transaction, bool $save_regs = true) |
|
564 | + { |
|
565 | + $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
566 | + $transaction->total_line_item() |
|
567 | + ); |
|
568 | + foreach ($transaction->registrations() as $registration) { |
|
569 | + /** @var EE_Line_Item $line_item */ |
|
570 | + $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
571 | + if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
572 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
573 | + if ($save_regs) { |
|
574 | + $registration->save(); |
|
575 | + } |
|
576 | + } |
|
577 | + } |
|
578 | + // and make sure there's no rounding problem |
|
579 | + $this->fix_reg_final_price_rounding_issue($transaction); |
|
580 | + } |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * Makes sure there is no rounding errors for the REG_final_prices. |
|
585 | + * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
586 | + * they will each be for $0.99333333, which gets rounded to $1 again. |
|
587 | + * So the transaction total will be $2.99, but each registration will be for $1, |
|
588 | + * so if each registrant paid individually they will have overpaid by $0.01. |
|
589 | + * So in order to overcome this, we check for any difference, and if there is a difference |
|
590 | + * we just grab one registrant at random and make them responsible for it. |
|
591 | + * This should be used after setting REG_final_prices (it's done automatically as part of |
|
592 | + * EE_Registration_Processor::update_registration_final_prices()) |
|
593 | + * |
|
594 | + * @param EE_Transaction $transaction |
|
595 | + * @return bool success verifying that there is NO difference after this method is done |
|
596 | + * @throws EE_Error |
|
597 | + * @throws InvalidArgumentException |
|
598 | + * @throws InvalidDataTypeException |
|
599 | + * @throws InvalidInterfaceException |
|
600 | + * @throws ReflectionException |
|
601 | + */ |
|
602 | + public function fix_reg_final_price_rounding_issue(EE_Transaction $transaction): bool |
|
603 | + { |
|
604 | + $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
605 | + [ |
|
606 | + [ |
|
607 | + 'TXN_ID' => $transaction->ID(), |
|
608 | + ], |
|
609 | + ], |
|
610 | + 'REG_final_price' |
|
611 | + ); |
|
612 | + $diff = $transaction->total() - $reg_final_price_sum; |
|
613 | + // ok then, just grab one of the registrations |
|
614 | + if ($diff !== 0.0) { |
|
615 | + $a_reg = EEM_Registration::instance()->get_one( |
|
616 | + [ |
|
617 | + [ |
|
618 | + 'TXN_ID' => $transaction->ID(), |
|
619 | + ], |
|
620 | + ] |
|
621 | + ); |
|
622 | + return $a_reg instanceof EE_Registration |
|
623 | + && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]); |
|
624 | + } |
|
625 | + return true; |
|
626 | + } |
|
627 | + |
|
628 | + |
|
629 | + /** |
|
630 | + * @param EE_Registration $registration |
|
631 | + * @param array $closed_reg_statuses |
|
632 | + * @param bool $update_reg |
|
633 | + * @return bool |
|
634 | + * @throws EE_Error |
|
635 | + * @throws RuntimeException |
|
636 | + * @throws ReflectionException |
|
637 | + */ |
|
638 | + public function update_registration_after_being_canceled_or_declined( |
|
639 | + EE_Registration $registration, |
|
640 | + array $closed_reg_statuses = [], |
|
641 | + bool $update_reg = true |
|
642 | + ): bool { |
|
643 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
644 | + $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
645 | + ? $closed_reg_statuses |
|
646 | + : EEM_Registration::closed_reg_statuses(); |
|
647 | + if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
648 | + return false; |
|
649 | + } |
|
650 | + // release a reserved ticket by decrementing ticket and datetime reserved values |
|
651 | + $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
652 | + $registration->set_final_price(0); |
|
653 | + if ($update_reg) { |
|
654 | + $registration->save(); |
|
655 | + } |
|
656 | + return true; |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + /** |
|
661 | + * @param EE_Registration $registration |
|
662 | + * @param array $closed_reg_statuses |
|
663 | + * @param bool $update_reg |
|
664 | + * @return bool |
|
665 | + * @throws EE_Error |
|
666 | + * @throws RuntimeException |
|
667 | + * @throws ReflectionException |
|
668 | + */ |
|
669 | + public function update_canceled_or_declined_registration_after_being_reinstated( |
|
670 | + EE_Registration $registration, |
|
671 | + array $closed_reg_statuses = [], |
|
672 | + bool $update_reg = true |
|
673 | + ): bool { |
|
674 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
675 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
676 | + : EEM_Registration::closed_reg_statuses(); |
|
677 | + if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
678 | + return false; |
|
679 | + } |
|
680 | + $ticket = $registration->ticket(); |
|
681 | + if (! $ticket instanceof EE_Ticket) { |
|
682 | + throw new EE_Error( |
|
683 | + sprintf( |
|
684 | + esc_html__( |
|
685 | + 'The Ticket for Registration %1$d was not found or is invalid.', |
|
686 | + 'event_espresso' |
|
687 | + ), |
|
688 | + $registration->ticket_ID() |
|
689 | + ) |
|
690 | + ); |
|
691 | + } |
|
692 | + $registration->set_final_price($ticket->price()); |
|
693 | + if ($update_reg) { |
|
694 | + $registration->save(); |
|
695 | + } |
|
696 | + return true; |
|
697 | + } |
|
698 | 698 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | use EventEspresso\core\services\loaders\LoaderFactory; |
10 | 10 | use EventEspresso\core\services\request\RequestInterface; |
11 | 11 | |
12 | -require_once __DIR__ . '/EE_Processor_Base.class.php'; |
|
12 | +require_once __DIR__.'/EE_Processor_Base.class.php'; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * Class EE_Registration_Processor |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | public static function instance(RequestInterface $request = null): EE_Registration_Processor |
63 | 63 | { |
64 | 64 | // check if class object is instantiated |
65 | - if (! self::$_instance instanceof EE_Registration_Processor) { |
|
66 | - if (! $request instanceof RequestInterface) { |
|
65 | + if ( ! self::$_instance instanceof EE_Registration_Processor) { |
|
66 | + if ( ! $request instanceof RequestInterface) { |
|
67 | 67 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
68 | 68 | } |
69 | 69 | self::$_instance = new self($request); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function old_reg_status(int $REG_ID): ?string |
91 | 91 | { |
92 | - return $this->_old_reg_status[ $REG_ID ] ?? null; |
|
92 | + return $this->_old_reg_status[$REG_ID] ?? null; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | public function set_old_reg_status(int $REG_ID, string $old_reg_status) |
101 | 101 | { |
102 | 102 | // only set the first time |
103 | - if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
104 | - $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
103 | + if ( ! isset($this->_old_reg_status[$REG_ID])) { |
|
104 | + $this->_old_reg_status[$REG_ID] = $old_reg_status; |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function new_reg_status(int $REG_ID): ?string |
114 | 114 | { |
115 | - return $this->_new_reg_status[ $REG_ID ] ?? null; |
|
115 | + return $this->_new_reg_status[$REG_ID] ?? null; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function set_new_reg_status(int $REG_ID, string $new_reg_status) |
124 | 124 | { |
125 | - $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
125 | + $this->_new_reg_status[$REG_ID] = $new_reg_status; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | if ( |
195 | 195 | $this->reg_status_updated($registration->ID()) |
196 | 196 | && ( |
197 | - (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
197 | + ( ! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
198 | 198 | || EE_Registry::instance()->CAP->current_user_can( |
199 | 199 | 'ee_edit_registration', |
200 | 200 | 'toggle_registration_status', |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | } |
277 | 277 | // don't trigger notifications during IPNs because they will get triggered by |
278 | 278 | // EventEspresso\core\services\payments\PostPaymentProcessor |
279 | - if (! EE_Processor_Base::$IPN) { |
|
279 | + if ( ! EE_Processor_Base::$IPN) { |
|
280 | 280 | // otherwise, send out notifications |
281 | 281 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
282 | 282 | } |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | } |
345 | 345 | // don't trigger notifications during IPNs because they will get triggered by |
346 | 346 | // EventEspresso\core\services\payments\PostPaymentProcessor |
347 | - if (! EE_Processor_Base::$IPN) { |
|
347 | + if ( ! EE_Processor_Base::$IPN) { |
|
348 | 348 | // otherwise, send out notifications |
349 | 349 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
350 | 350 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | // set initial REG_Status |
392 | 392 | $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
393 | 393 | // was a payment just made ? |
394 | - $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
394 | + $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
395 | 395 | && $additional_details['payment_updates'] |
396 | 396 | && $additional_details['last_payment'] instanceof EE_Payment |
397 | 397 | ? $additional_details['last_payment'] |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | || ( |
417 | 417 | $payment instanceof EE_Payment && $payment->is_approved() |
418 | 418 | // this specific registration has not yet been paid for |
419 | - && ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
419 | + && ! isset(self::$_amount_paid[$registration->ID()]) |
|
420 | 420 | // payment amount, less what we have already attributed to other registrations, |
421 | 421 | // is greater than this registration's final price |
422 | 422 | && $payment->amount() - $total_paid >= $registration->final_price() |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | ) |
425 | 425 | ) { |
426 | 426 | // mark as paid |
427 | - self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
427 | + self::$_amount_paid[$registration->ID()] = $registration->final_price(); |
|
428 | 428 | // track new REG_Status |
429 | 429 | $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
430 | 430 | // toggle status to approved |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | } |
445 | 445 | // don't trigger notifications during IPNs because they will get triggered by |
446 | 446 | // EventEspresso\core\services\payments\PostPaymentProcessor |
447 | - if (! EE_Processor_Base::$IPN) { |
|
447 | + if ( ! EE_Processor_Base::$IPN) { |
|
448 | 448 | // otherwise, send out notifications |
449 | 449 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
450 | 450 | } |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | array $additional_details = [] |
478 | 478 | ) { |
479 | 479 | try { |
480 | - if (! $registration instanceof EE_Registration) { |
|
480 | + if ( ! $registration instanceof EE_Registration) { |
|
481 | 481 | throw new EE_Error( |
482 | 482 | esc_html__('An invalid registration was received.', 'event_espresso') |
483 | 483 | ); |
@@ -568,8 +568,8 @@ discard block |
||
568 | 568 | foreach ($transaction->registrations() as $registration) { |
569 | 569 | /** @var EE_Line_Item $line_item */ |
570 | 570 | $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
571 | - if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
572 | - $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
571 | + if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) { |
|
572 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]); |
|
573 | 573 | if ($save_regs) { |
574 | 574 | $registration->save(); |
575 | 575 | } |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | ], |
610 | 610 | 'REG_final_price' |
611 | 611 | ); |
612 | - $diff = $transaction->total() - $reg_final_price_sum; |
|
612 | + $diff = $transaction->total() - $reg_final_price_sum; |
|
613 | 613 | // ok then, just grab one of the registrations |
614 | 614 | if ($diff !== 0.0) { |
615 | 615 | $a_reg = EEM_Registration::instance()->get_one( |
@@ -644,11 +644,11 @@ discard block |
||
644 | 644 | $closed_reg_statuses = ! empty($closed_reg_statuses) |
645 | 645 | ? $closed_reg_statuses |
646 | 646 | : EEM_Registration::closed_reg_statuses(); |
647 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
647 | + if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
648 | 648 | return false; |
649 | 649 | } |
650 | 650 | // release a reserved ticket by decrementing ticket and datetime reserved values |
651 | - $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
651 | + $registration->release_reserved_ticket(true, 'RegProcessor:'.__LINE__); |
|
652 | 652 | $registration->set_final_price(0); |
653 | 653 | if ($update_reg) { |
654 | 654 | $registration->save(); |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | return false; |
679 | 679 | } |
680 | 680 | $ticket = $registration->ticket(); |
681 | - if (! $ticket instanceof EE_Ticket) { |
|
681 | + if ( ! $ticket instanceof EE_Ticket) { |
|
682 | 682 | throw new EE_Error( |
683 | 683 | sprintf( |
684 | 684 | esc_html__( |
@@ -14,250 +14,250 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Transaction_Payments |
16 | 16 | { |
17 | - private static ?EE_Transaction_Payments $_instance = null; |
|
17 | + private static ?EE_Transaction_Payments $_instance = null; |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @singleton method used to instantiate class object |
|
22 | - * @return EE_Transaction_Payments instance |
|
23 | - */ |
|
24 | - public static function instance(): EE_Transaction_Payments |
|
25 | - { |
|
26 | - // check if class object is instantiated |
|
27 | - if (! self::$_instance instanceof EE_Transaction_Payments) { |
|
28 | - self::$_instance = new self(); |
|
29 | - } |
|
30 | - return self::$_instance; |
|
31 | - } |
|
20 | + /** |
|
21 | + * @singleton method used to instantiate class object |
|
22 | + * @return EE_Transaction_Payments instance |
|
23 | + */ |
|
24 | + public static function instance(): EE_Transaction_Payments |
|
25 | + { |
|
26 | + // check if class object is instantiated |
|
27 | + if (! self::$_instance instanceof EE_Transaction_Payments) { |
|
28 | + self::$_instance = new self(); |
|
29 | + } |
|
30 | + return self::$_instance; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * @param EE_Transaction $transaction |
|
36 | - * @param bool $update_txn |
|
37 | - * @return bool true if TXN total was updated, false if not |
|
38 | - * @throws EE_Error |
|
39 | - * @throws ReflectionException |
|
40 | - */ |
|
41 | - public function recalculate_transaction_total(EE_Transaction $transaction, bool $update_txn = true): bool |
|
42 | - { |
|
43 | - $total_line_item = $transaction->total_line_item(); |
|
44 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
45 | - EE_Error::add_error( |
|
46 | - sprintf( |
|
47 | - esc_html__( |
|
48 | - 'The Total Line Item for Transaction %1$d\'s was not found or is invalid.', |
|
49 | - 'event_espresso' |
|
50 | - ), |
|
51 | - $transaction->ID() |
|
52 | - ), |
|
53 | - __FILE__, |
|
54 | - __FUNCTION__, |
|
55 | - __LINE__ |
|
56 | - ); |
|
57 | - return false; |
|
58 | - } |
|
59 | - $new_total = $total_line_item->recalculate_total_including_taxes(); |
|
60 | - $transaction->set_total($new_total); |
|
61 | - if ($update_txn) { |
|
62 | - return (bool) $transaction->save(); |
|
63 | - } |
|
64 | - return false; |
|
65 | - } |
|
34 | + /** |
|
35 | + * @param EE_Transaction $transaction |
|
36 | + * @param bool $update_txn |
|
37 | + * @return bool true if TXN total was updated, false if not |
|
38 | + * @throws EE_Error |
|
39 | + * @throws ReflectionException |
|
40 | + */ |
|
41 | + public function recalculate_transaction_total(EE_Transaction $transaction, bool $update_txn = true): bool |
|
42 | + { |
|
43 | + $total_line_item = $transaction->total_line_item(); |
|
44 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
45 | + EE_Error::add_error( |
|
46 | + sprintf( |
|
47 | + esc_html__( |
|
48 | + 'The Total Line Item for Transaction %1$d\'s was not found or is invalid.', |
|
49 | + 'event_espresso' |
|
50 | + ), |
|
51 | + $transaction->ID() |
|
52 | + ), |
|
53 | + __FILE__, |
|
54 | + __FUNCTION__, |
|
55 | + __LINE__ |
|
56 | + ); |
|
57 | + return false; |
|
58 | + } |
|
59 | + $new_total = $total_line_item->recalculate_total_including_taxes(); |
|
60 | + $transaction->set_total($new_total); |
|
61 | + if ($update_txn) { |
|
62 | + return (bool) $transaction->save(); |
|
63 | + } |
|
64 | + return false; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Updates the provided EE_Transaction with all the applicable payments |
|
70 | - * returns a boolean for whether the TXN was saved to the db |
|
71 | - * (meaning a status change occurred) |
|
72 | - * or not saved (which could **still** mean that |
|
73 | - * the TXN status changed, but just was not yet saved). |
|
74 | - * So if passing a value of false for the $update_txn param, |
|
75 | - * then client code needs to take responsibility for saving the TXN |
|
76 | - * regardless of what happens within EE_Transaction_Payments; |
|
77 | - * |
|
78 | - * @param EE_Transaction $transaction |
|
79 | - * @param boolean $update_txn whether to save the TXN |
|
80 | - * @return boolean whether the TXN was saved |
|
81 | - * @throws EE_Error |
|
82 | - * @throws ReflectionException |
|
83 | - */ |
|
84 | - public function calculate_total_payments_and_update_status( |
|
85 | - EE_Transaction $transaction, |
|
86 | - bool $update_txn = true |
|
87 | - ): bool { |
|
88 | - // calculate total paid |
|
89 | - $total_paid = $this->recalculate_total_payments_for_transaction($transaction); |
|
90 | - // if total paid has changed |
|
91 | - if (EEH_Money::compare_floats($total_paid, $transaction->paid(), '!==')) { |
|
92 | - $transaction->set_paid($total_paid); |
|
93 | - // maybe update status, and make sure to save transaction if not done already |
|
94 | - if (! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
95 | - if ($update_txn) { |
|
96 | - return (bool) $transaction->save(); |
|
97 | - } |
|
98 | - } else { |
|
99 | - // the status got updated and was saved by |
|
100 | - // update_transaction_status_based_on_total_paid() |
|
101 | - return true; |
|
102 | - } |
|
103 | - } |
|
104 | - return false; |
|
105 | - } |
|
68 | + /** |
|
69 | + * Updates the provided EE_Transaction with all the applicable payments |
|
70 | + * returns a boolean for whether the TXN was saved to the db |
|
71 | + * (meaning a status change occurred) |
|
72 | + * or not saved (which could **still** mean that |
|
73 | + * the TXN status changed, but just was not yet saved). |
|
74 | + * So if passing a value of false for the $update_txn param, |
|
75 | + * then client code needs to take responsibility for saving the TXN |
|
76 | + * regardless of what happens within EE_Transaction_Payments; |
|
77 | + * |
|
78 | + * @param EE_Transaction $transaction |
|
79 | + * @param boolean $update_txn whether to save the TXN |
|
80 | + * @return boolean whether the TXN was saved |
|
81 | + * @throws EE_Error |
|
82 | + * @throws ReflectionException |
|
83 | + */ |
|
84 | + public function calculate_total_payments_and_update_status( |
|
85 | + EE_Transaction $transaction, |
|
86 | + bool $update_txn = true |
|
87 | + ): bool { |
|
88 | + // calculate total paid |
|
89 | + $total_paid = $this->recalculate_total_payments_for_transaction($transaction); |
|
90 | + // if total paid has changed |
|
91 | + if (EEH_Money::compare_floats($total_paid, $transaction->paid(), '!==')) { |
|
92 | + $transaction->set_paid($total_paid); |
|
93 | + // maybe update status, and make sure to save transaction if not done already |
|
94 | + if (! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
95 | + if ($update_txn) { |
|
96 | + return (bool) $transaction->save(); |
|
97 | + } |
|
98 | + } else { |
|
99 | + // the status got updated and was saved by |
|
100 | + // update_transaction_status_based_on_total_paid() |
|
101 | + return true; |
|
102 | + } |
|
103 | + } |
|
104 | + return false; |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * @param EE_Transaction $transaction |
|
110 | - * @param string $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved). |
|
111 | - * By default, searches for approved payments |
|
112 | - * @return float |
|
113 | - * @throws EE_Error |
|
114 | - * @throws ReflectionException |
|
115 | - */ |
|
116 | - public function recalculate_total_payments_for_transaction( |
|
117 | - EE_Transaction $transaction, |
|
118 | - string $payment_status = EEM_Payment::status_id_approved |
|
119 | - ): float { |
|
120 | - // ensure Payment model is loaded |
|
121 | - EE_Registry::instance()->load_model('Payment'); |
|
122 | - // calls EEM_Base::sum() |
|
123 | - return EEM_Payment::instance()->sum( |
|
124 | - // query params |
|
125 | - [['TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status]], |
|
126 | - // field to sum |
|
127 | - 'PAY_amount' |
|
128 | - ); |
|
129 | - } |
|
108 | + /** |
|
109 | + * @param EE_Transaction $transaction |
|
110 | + * @param string $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved). |
|
111 | + * By default, searches for approved payments |
|
112 | + * @return float |
|
113 | + * @throws EE_Error |
|
114 | + * @throws ReflectionException |
|
115 | + */ |
|
116 | + public function recalculate_total_payments_for_transaction( |
|
117 | + EE_Transaction $transaction, |
|
118 | + string $payment_status = EEM_Payment::status_id_approved |
|
119 | + ): float { |
|
120 | + // ensure Payment model is loaded |
|
121 | + EE_Registry::instance()->load_model('Payment'); |
|
122 | + // calls EEM_Base::sum() |
|
123 | + return EEM_Payment::instance()->sum( |
|
124 | + // query params |
|
125 | + [['TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status]], |
|
126 | + // field to sum |
|
127 | + 'PAY_amount' |
|
128 | + ); |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * Before deleting the selected payment, we fetch its transaction, |
|
134 | - * then delete the payment, and update the transactions' amount paid. |
|
135 | - * |
|
136 | - * @param EE_Payment $payment |
|
137 | - * @return boolean |
|
138 | - * @throws EE_Error |
|
139 | - * @throws ReflectionException |
|
140 | - */ |
|
141 | - public function delete_payment_and_update_transaction(EE_Payment $payment): bool |
|
142 | - { |
|
143 | - if (! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
144 | - return false; |
|
145 | - } |
|
146 | - if (! $payment->delete()) { |
|
147 | - EE_Error::add_error( |
|
148 | - esc_html__('The payment could not be deleted.', 'event_espresso'), |
|
149 | - __FILE__, |
|
150 | - __FUNCTION__, |
|
151 | - __LINE__ |
|
152 | - ); |
|
153 | - return false; |
|
154 | - } |
|
132 | + /** |
|
133 | + * Before deleting the selected payment, we fetch its transaction, |
|
134 | + * then delete the payment, and update the transactions' amount paid. |
|
135 | + * |
|
136 | + * @param EE_Payment $payment |
|
137 | + * @return boolean |
|
138 | + * @throws EE_Error |
|
139 | + * @throws ReflectionException |
|
140 | + */ |
|
141 | + public function delete_payment_and_update_transaction(EE_Payment $payment): bool |
|
142 | + { |
|
143 | + if (! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
144 | + return false; |
|
145 | + } |
|
146 | + if (! $payment->delete()) { |
|
147 | + EE_Error::add_error( |
|
148 | + esc_html__('The payment could not be deleted.', 'event_espresso'), |
|
149 | + __FILE__, |
|
150 | + __FUNCTION__, |
|
151 | + __LINE__ |
|
152 | + ); |
|
153 | + return false; |
|
154 | + } |
|
155 | 155 | |
156 | - $transaction = $payment->transaction(); |
|
157 | - $TXN_status = $transaction->status_ID(); |
|
158 | - if ( |
|
159 | - $TXN_status === EEM_Transaction::abandoned_status_code |
|
160 | - || $TXN_status === EEM_Transaction::failed_status_code |
|
161 | - || $payment->amount() == 0.0 |
|
162 | - ) { |
|
163 | - EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso')); |
|
164 | - return true; |
|
165 | - } |
|
156 | + $transaction = $payment->transaction(); |
|
157 | + $TXN_status = $transaction->status_ID(); |
|
158 | + if ( |
|
159 | + $TXN_status === EEM_Transaction::abandoned_status_code |
|
160 | + || $TXN_status === EEM_Transaction::failed_status_code |
|
161 | + || $payment->amount() == 0.0 |
|
162 | + ) { |
|
163 | + EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso')); |
|
164 | + return true; |
|
165 | + } |
|
166 | 166 | |
167 | 167 | |
168 | - // if this fails, that just means that the transaction didn't get its status changed and/or updated. |
|
169 | - // however the payment was still deleted. |
|
170 | - if (! $this->calculate_total_payments_and_update_status($transaction)) { |
|
171 | - EE_Error::add_attention( |
|
172 | - esc_html__( |
|
173 | - 'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..', |
|
174 | - 'event_espresso' |
|
175 | - ), |
|
176 | - __FILE__, |
|
177 | - __FUNCTION__, |
|
178 | - __LINE__ |
|
179 | - ); |
|
180 | - return true; |
|
181 | - } |
|
168 | + // if this fails, that just means that the transaction didn't get its status changed and/or updated. |
|
169 | + // however the payment was still deleted. |
|
170 | + if (! $this->calculate_total_payments_and_update_status($transaction)) { |
|
171 | + EE_Error::add_attention( |
|
172 | + esc_html__( |
|
173 | + 'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..', |
|
174 | + 'event_espresso' |
|
175 | + ), |
|
176 | + __FILE__, |
|
177 | + __FUNCTION__, |
|
178 | + __LINE__ |
|
179 | + ); |
|
180 | + return true; |
|
181 | + } |
|
182 | 182 | |
183 | - EE_Error::add_success( |
|
184 | - esc_html__( |
|
185 | - 'The Payment was successfully deleted, and the Transaction has been updated accordingly.', |
|
186 | - 'event_espresso' |
|
187 | - ) |
|
188 | - ); |
|
189 | - return true; |
|
190 | - } |
|
183 | + EE_Error::add_success( |
|
184 | + esc_html__( |
|
185 | + 'The Payment was successfully deleted, and the Transaction has been updated accordingly.', |
|
186 | + 'event_espresso' |
|
187 | + ) |
|
188 | + ); |
|
189 | + return true; |
|
190 | + } |
|
191 | 191 | |
192 | 192 | |
193 | - /** |
|
194 | - * removes all registration payment records associated with a payment |
|
195 | - * and subtracts their amounts from the corresponding registrations REG_paid field |
|
196 | - * |
|
197 | - * @param EE_Payment $payment |
|
198 | - * @param array $reg_payment_query_params |
|
199 | - * @return bool |
|
200 | - * @throws EE_Error |
|
201 | - * @throws ReflectionException |
|
202 | - */ |
|
203 | - public function delete_registration_payments_and_update_registrations( |
|
204 | - EE_Payment $payment, |
|
205 | - array $reg_payment_query_params = [] |
|
206 | - ): bool { |
|
207 | - $save_payment = false; |
|
208 | - $reg_payment_query_params = ! empty($reg_payment_query_params) |
|
209 | - ? $reg_payment_query_params |
|
210 | - : [['PAY_ID' => $payment->ID()]]; |
|
211 | - $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params); |
|
212 | - if (! empty($registration_payments)) { |
|
213 | - foreach ($registration_payments as $registration_payment) { |
|
214 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
215 | - $amount_paid = $registration_payment->amount(); |
|
216 | - $registration = $registration_payment->registration(); |
|
217 | - if ($registration instanceof EE_Registration) { |
|
218 | - $registration->set_paid($registration->paid() - $amount_paid); |
|
219 | - if ($registration->save() !== false) { |
|
220 | - $registration_payment->delete_permanently(); |
|
221 | - $save_payment = true; |
|
222 | - } |
|
223 | - } else { |
|
224 | - EE_Error::add_error( |
|
225 | - sprintf( |
|
226 | - esc_html__( |
|
227 | - 'An invalid Registration object was associated with Registration Payment ID# %1$d.', |
|
228 | - 'event_espresso' |
|
229 | - ), |
|
230 | - $registration_payment->ID() |
|
231 | - ), |
|
232 | - __FILE__, |
|
233 | - __FUNCTION__, |
|
234 | - __LINE__ |
|
235 | - ); |
|
236 | - return false; |
|
237 | - } |
|
238 | - } else { |
|
239 | - EE_Error::add_error( |
|
240 | - sprintf( |
|
241 | - esc_html__( |
|
242 | - 'An invalid Registration Payment object was associated with payment ID# %1$d.', |
|
243 | - 'event_espresso' |
|
244 | - ), |
|
245 | - $payment->ID() |
|
246 | - ), |
|
247 | - __FILE__, |
|
248 | - __FUNCTION__, |
|
249 | - __LINE__ |
|
250 | - ); |
|
251 | - return false; |
|
252 | - } |
|
253 | - } |
|
254 | - } |
|
255 | - if ($save_payment) { |
|
256 | - $payment->save(); |
|
257 | - } |
|
258 | - return true; |
|
259 | - } |
|
193 | + /** |
|
194 | + * removes all registration payment records associated with a payment |
|
195 | + * and subtracts their amounts from the corresponding registrations REG_paid field |
|
196 | + * |
|
197 | + * @param EE_Payment $payment |
|
198 | + * @param array $reg_payment_query_params |
|
199 | + * @return bool |
|
200 | + * @throws EE_Error |
|
201 | + * @throws ReflectionException |
|
202 | + */ |
|
203 | + public function delete_registration_payments_and_update_registrations( |
|
204 | + EE_Payment $payment, |
|
205 | + array $reg_payment_query_params = [] |
|
206 | + ): bool { |
|
207 | + $save_payment = false; |
|
208 | + $reg_payment_query_params = ! empty($reg_payment_query_params) |
|
209 | + ? $reg_payment_query_params |
|
210 | + : [['PAY_ID' => $payment->ID()]]; |
|
211 | + $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params); |
|
212 | + if (! empty($registration_payments)) { |
|
213 | + foreach ($registration_payments as $registration_payment) { |
|
214 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
215 | + $amount_paid = $registration_payment->amount(); |
|
216 | + $registration = $registration_payment->registration(); |
|
217 | + if ($registration instanceof EE_Registration) { |
|
218 | + $registration->set_paid($registration->paid() - $amount_paid); |
|
219 | + if ($registration->save() !== false) { |
|
220 | + $registration_payment->delete_permanently(); |
|
221 | + $save_payment = true; |
|
222 | + } |
|
223 | + } else { |
|
224 | + EE_Error::add_error( |
|
225 | + sprintf( |
|
226 | + esc_html__( |
|
227 | + 'An invalid Registration object was associated with Registration Payment ID# %1$d.', |
|
228 | + 'event_espresso' |
|
229 | + ), |
|
230 | + $registration_payment->ID() |
|
231 | + ), |
|
232 | + __FILE__, |
|
233 | + __FUNCTION__, |
|
234 | + __LINE__ |
|
235 | + ); |
|
236 | + return false; |
|
237 | + } |
|
238 | + } else { |
|
239 | + EE_Error::add_error( |
|
240 | + sprintf( |
|
241 | + esc_html__( |
|
242 | + 'An invalid Registration Payment object was associated with payment ID# %1$d.', |
|
243 | + 'event_espresso' |
|
244 | + ), |
|
245 | + $payment->ID() |
|
246 | + ), |
|
247 | + __FILE__, |
|
248 | + __FUNCTION__, |
|
249 | + __LINE__ |
|
250 | + ); |
|
251 | + return false; |
|
252 | + } |
|
253 | + } |
|
254 | + } |
|
255 | + if ($save_payment) { |
|
256 | + $payment->save(); |
|
257 | + } |
|
258 | + return true; |
|
259 | + } |
|
260 | 260 | |
261 | 261 | |
262 | - /********************************** DEPRECATED METHODS **********************************/ |
|
262 | + /********************************** DEPRECATED METHODS **********************************/ |
|
263 | 263 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | public static function instance(): EE_Transaction_Payments |
25 | 25 | { |
26 | 26 | // check if class object is instantiated |
27 | - if (! self::$_instance instanceof EE_Transaction_Payments) { |
|
27 | + if ( ! self::$_instance instanceof EE_Transaction_Payments) { |
|
28 | 28 | self::$_instance = new self(); |
29 | 29 | } |
30 | 30 | return self::$_instance; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public function recalculate_transaction_total(EE_Transaction $transaction, bool $update_txn = true): bool |
42 | 42 | { |
43 | 43 | $total_line_item = $transaction->total_line_item(); |
44 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
44 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
45 | 45 | EE_Error::add_error( |
46 | 46 | sprintf( |
47 | 47 | esc_html__( |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | if (EEH_Money::compare_floats($total_paid, $transaction->paid(), '!==')) { |
92 | 92 | $transaction->set_paid($total_paid); |
93 | 93 | // maybe update status, and make sure to save transaction if not done already |
94 | - if (! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
94 | + if ( ! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
95 | 95 | if ($update_txn) { |
96 | 96 | return (bool) $transaction->save(); |
97 | 97 | } |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function delete_payment_and_update_transaction(EE_Payment $payment): bool |
142 | 142 | { |
143 | - if (! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
143 | + if ( ! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
144 | 144 | return false; |
145 | 145 | } |
146 | - if (! $payment->delete()) { |
|
146 | + if ( ! $payment->delete()) { |
|
147 | 147 | EE_Error::add_error( |
148 | 148 | esc_html__('The payment could not be deleted.', 'event_espresso'), |
149 | 149 | __FILE__, |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | |
168 | 168 | // if this fails, that just means that the transaction didn't get its status changed and/or updated. |
169 | 169 | // however the payment was still deleted. |
170 | - if (! $this->calculate_total_payments_and_update_status($transaction)) { |
|
170 | + if ( ! $this->calculate_total_payments_and_update_status($transaction)) { |
|
171 | 171 | EE_Error::add_attention( |
172 | 172 | esc_html__( |
173 | 173 | 'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..', |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | ? $reg_payment_query_params |
210 | 210 | : [['PAY_ID' => $payment->ID()]]; |
211 | 211 | $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params); |
212 | - if (! empty($registration_payments)) { |
|
212 | + if ( ! empty($registration_payments)) { |
|
213 | 213 | foreach ($registration_payments as $registration_payment) { |
214 | 214 | if ($registration_payment instanceof EE_Registration_Payment) { |
215 | 215 | $amount_paid = $registration_payment->amount(); |
@@ -16,590 +16,590 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Transaction_Processor extends EE_Processor_Base |
18 | 18 | { |
19 | - private static ?EE_Transaction_Processor $_instance = null; |
|
20 | - |
|
21 | - /** |
|
22 | - * array of query WHERE params to use when retrieving cached registrations from a transaction |
|
23 | - * |
|
24 | - * @var array $registration_query_params |
|
25 | - */ |
|
26 | - private array $_registration_query_params = []; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @singleton method used to instantiate class object |
|
31 | - * @param array $registration_query_params |
|
32 | - * @return EE_Transaction_Processor instance |
|
33 | - */ |
|
34 | - public static function instance(array $registration_query_params = []): EE_Transaction_Processor |
|
35 | - { |
|
36 | - // check if class object is instantiated |
|
37 | - if (! self::$_instance instanceof EE_Transaction_Processor) { |
|
38 | - self::$_instance = new self($registration_query_params); |
|
39 | - } |
|
40 | - return self::$_instance; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @param array $registration_query_params |
|
46 | - */ |
|
47 | - private function __construct(array $registration_query_params = []) |
|
48 | - { |
|
49 | - // make sure some query params are set for retrieving registrations |
|
50 | - $this->_set_registration_query_params($registration_query_params); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param array $registration_query_params |
|
56 | - */ |
|
57 | - private function _set_registration_query_params(array $registration_query_params) |
|
58 | - { |
|
59 | - $this->_registration_query_params = ! empty($registration_query_params) |
|
60 | - ? $registration_query_params |
|
61 | - : ['order_by' => ['REG_count' => 'ASC']]; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * manually_update_registration_statuses |
|
67 | - * |
|
68 | - * @param EE_Transaction $transaction |
|
69 | - * @param string $new_reg_status |
|
70 | - * @param array $registration_query_params array of query WHERE params to use |
|
71 | - * when retrieving cached registrations from a transaction |
|
72 | - * @return boolean |
|
73 | - * @throws EE_Error |
|
74 | - * @throws ReflectionException |
|
75 | - */ |
|
76 | - public function manually_update_registration_statuses( |
|
77 | - EE_Transaction $transaction, |
|
78 | - string $new_reg_status = '', |
|
79 | - array $registration_query_params = [] |
|
80 | - ): bool { |
|
81 | - $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
82 | - 'manually_update_registration_status', |
|
83 | - $transaction, |
|
84 | - $registration_query_params, |
|
85 | - $new_reg_status |
|
86 | - ); |
|
87 | - // send messages |
|
88 | - /** @type EE_Registration_Processor $registration_processor */ |
|
89 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
90 | - $registration_processor->trigger_registration_update_notifications( |
|
91 | - $transaction->primary_registration(), |
|
92 | - ['manually_updated' => true] |
|
93 | - ); |
|
94 | - do_action( |
|
95 | - 'AHEE__EE_Transaction_Processor__manually_update_registration_statuses', |
|
96 | - $transaction, |
|
97 | - $status_updates |
|
98 | - ); |
|
99 | - return $status_updates; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * update_transaction_and_registrations_after_checkout_or_payment |
|
105 | - * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each |
|
106 | - * |
|
107 | - * @param EE_Transaction $transaction |
|
108 | - * @param EE_Payment|null $payment |
|
109 | - * @param array $registration_query_params array of query WHERE params to use |
|
110 | - * when retrieving cached registrations from a transaction |
|
111 | - * @param bool $trigger_notifications whether to call EE_Registration_Processor::trigger_registration_update_notifications() |
|
112 | - * @return array |
|
113 | - * @throws EE_Error |
|
114 | - * @throws ReflectionException |
|
115 | - */ |
|
116 | - public function update_transaction_and_registrations_after_checkout_or_payment( |
|
117 | - EE_Transaction $transaction, |
|
118 | - ?EE_Payment $payment = null, |
|
119 | - array $registration_query_params = [], |
|
120 | - bool $trigger_notifications = true |
|
121 | - ): array { |
|
122 | - // make sure some query params are set for retrieving registrations |
|
123 | - $this->_set_registration_query_params($registration_query_params); |
|
124 | - // get final reg step status |
|
125 | - $finalized = $transaction->final_reg_step_completed(); |
|
126 | - // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
127 | - // but has not yet been fully completed (TRUE) |
|
128 | - if (is_int($finalized)) { |
|
129 | - $transaction->set_reg_step_completed('finalize_registration'); |
|
130 | - $finalized = true; |
|
131 | - } |
|
132 | - $transaction->save(); |
|
133 | - // array of details to aid in decision-making by systems |
|
134 | - $update_params = [ |
|
135 | - 'old_txn_status' => $transaction->old_txn_status(), |
|
136 | - 'new_txn_status' => $transaction->status_ID(), |
|
137 | - 'finalized' => $finalized, |
|
138 | - 'revisit' => $this->_revisit, |
|
139 | - 'payment_updates' => $payment instanceof EE_Payment, |
|
140 | - 'last_payment' => $payment, |
|
141 | - ]; |
|
142 | - // now update the registrations and add the results to our $update_params |
|
143 | - $update_params['status_updates'] = $this->_call_method_on_registrations_via_Registration_Processor( |
|
144 | - 'update_registration_after_checkout_or_payment', |
|
145 | - $transaction, |
|
146 | - $this->_registration_query_params, |
|
147 | - $update_params |
|
148 | - ); |
|
149 | - if ($trigger_notifications) { |
|
150 | - // send messages |
|
151 | - /** @type EE_Registration_Processor $registration_processor */ |
|
152 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
153 | - $registration_processor->trigger_registration_update_notifications( |
|
154 | - $transaction->primary_registration(), |
|
155 | - $update_params |
|
156 | - ); |
|
157 | - } |
|
158 | - do_action( |
|
159 | - 'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment', |
|
160 | - $transaction, |
|
161 | - $update_params |
|
162 | - ); |
|
163 | - return $update_params; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * update_transaction_after_registration_reopened |
|
169 | - * readjusts TXN and Line Item totals after a registration is changed from |
|
170 | - * cancelled or declined to another reg status such as pending payment or approved |
|
171 | - * |
|
172 | - * @param EE_Registration $registration |
|
173 | - * @param array $closed_reg_statuses |
|
174 | - * @param bool $update_txn |
|
175 | - * @return bool |
|
176 | - * @throws EE_Error |
|
177 | - * @throws ReflectionException |
|
178 | - */ |
|
179 | - public function update_transaction_after_reinstating_canceled_registration( |
|
180 | - EE_Registration $registration, |
|
181 | - array $closed_reg_statuses = [], |
|
182 | - bool $update_txn = true |
|
183 | - ): bool { |
|
184 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
185 | - $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
186 | - ? $closed_reg_statuses |
|
187 | - : EEM_Registration::closed_reg_statuses(); |
|
188 | - if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
189 | - return false; |
|
190 | - } |
|
191 | - try { |
|
192 | - $transaction = $registration->transaction(); |
|
193 | - $ticket_line_item = $this->getTicketLineItemForRegistration($registration); |
|
194 | - // un-cancel the ticket |
|
195 | - $success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item); |
|
196 | - } catch (EE_Error $e) { |
|
197 | - EE_Error::add_error( |
|
198 | - sprintf( |
|
199 | - esc_html__( |
|
200 | - 'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', |
|
201 | - 'event_espresso' |
|
202 | - ), |
|
203 | - $registration->ID(), |
|
204 | - '<br />', |
|
205 | - $e->getMessage() |
|
206 | - ), |
|
207 | - __FILE__, |
|
208 | - __FUNCTION__, |
|
209 | - __LINE__ |
|
210 | - ); |
|
211 | - return false; |
|
212 | - } |
|
213 | - if ($update_txn) { |
|
214 | - return $transaction->save() |
|
215 | - ? $success |
|
216 | - : false; |
|
217 | - } |
|
218 | - return $success; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * update_transaction_after_canceled_or_declined_registration |
|
224 | - * readjusts TXN and Line Item totals after a registration is cancelled or declined |
|
225 | - * |
|
226 | - * @param EE_Registration $registration |
|
227 | - * @param array $closed_reg_statuses |
|
228 | - * @param bool $update_txn |
|
229 | - * @return bool |
|
230 | - * @throws EE_Error |
|
231 | - * @throws ReflectionException |
|
232 | - */ |
|
233 | - public function update_transaction_after_canceled_or_declined_registration( |
|
234 | - EE_Registration $registration, |
|
235 | - array $closed_reg_statuses = [], |
|
236 | - bool $update_txn = true |
|
237 | - ): bool { |
|
238 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
239 | - $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
240 | - ? $closed_reg_statuses |
|
241 | - : EEM_Registration::closed_reg_statuses(); |
|
242 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
243 | - return false; |
|
244 | - } |
|
245 | - try { |
|
246 | - $transaction = $registration->transaction(); |
|
247 | - if ( |
|
248 | - apply_filters( |
|
249 | - 'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item', |
|
250 | - true, |
|
251 | - $registration, |
|
252 | - $transaction |
|
253 | - ) |
|
254 | - ) { |
|
255 | - $ticket_line_item = $this->getTicketLineItemForRegistration($registration); |
|
256 | - EEH_Line_Item::cancel_ticket_line_item($ticket_line_item); |
|
257 | - } |
|
258 | - } catch (EE_Error $e) { |
|
259 | - EE_Error::add_error( |
|
260 | - sprintf( |
|
261 | - esc_html__( |
|
262 | - 'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', |
|
263 | - 'event_espresso' |
|
264 | - ), |
|
265 | - $registration->ID(), |
|
266 | - '<br />', |
|
267 | - $e->getMessage() |
|
268 | - ), |
|
269 | - __FILE__, |
|
270 | - __FUNCTION__, |
|
271 | - __LINE__ |
|
272 | - ); |
|
273 | - return false; |
|
274 | - } |
|
275 | - return ! $update_txn || $transaction->save(); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * @param EE_Registration $registration |
|
281 | - * @return EE_Line_Item |
|
282 | - * @throws EE_Error |
|
283 | - * @throws ReflectionException |
|
284 | - */ |
|
285 | - public function getTicketLineItemForRegistration(EE_Registration $registration): EE_Line_Item |
|
286 | - { |
|
287 | - $ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction( |
|
288 | - $registration->transaction_ID(), |
|
289 | - $registration->ticket_ID() |
|
290 | - ); |
|
291 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
292 | - return $ticket_line_item; |
|
293 | - } |
|
294 | - throw new EE_Error( |
|
295 | - sprintf( |
|
296 | - esc_html__( |
|
297 | - 'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.', |
|
298 | - 'event_espresso' |
|
299 | - ), |
|
300 | - $registration->transaction_ID(), |
|
301 | - $registration->ticket_ID() |
|
302 | - ) |
|
303 | - ); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * cancel_transaction_if_all_registrations_canceled |
|
309 | - * cycles thru related registrations and checks their statuses |
|
310 | - * if ALL registrations are Cancelled or Declined, then this sets the TXN status to |
|
311 | - * |
|
312 | - * @param EE_Transaction $transaction |
|
313 | - * @param string $new_TXN_status |
|
314 | - * @param array $registration_query_params - array of query WHERE params to use when |
|
315 | - * retrieving cached registrations from a transaction |
|
316 | - * @param array $closed_reg_statuses |
|
317 | - * @param bool $update_txn |
|
318 | - * @return bool true if TXN status was updated, false if not |
|
319 | - * @throws EE_Error |
|
320 | - * @throws ReflectionException |
|
321 | - */ |
|
322 | - public function toggle_transaction_status_if_all_registrations_canceled_or_declined( |
|
323 | - EE_Transaction $transaction, |
|
324 | - string $new_TXN_status = '', |
|
325 | - array $registration_query_params = [], |
|
326 | - array $closed_reg_statuses = [], |
|
327 | - bool $update_txn = true |
|
328 | - ): bool { |
|
329 | - // make sure some query params are set for retrieving registrations |
|
330 | - $this->_set_registration_query_params($registration_query_params); |
|
331 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
332 | - $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
333 | - ? $closed_reg_statuses |
|
334 | - : EEM_Registration::closed_reg_statuses(); |
|
335 | - // loop through cached registrations |
|
336 | - foreach ($transaction->registrations($this->_registration_query_params) as $registration) { |
|
337 | - if ( |
|
338 | - $registration instanceof EE_Registration |
|
339 | - && ! in_array($registration->status_ID(), $closed_reg_statuses) |
|
340 | - ) { |
|
341 | - return false; |
|
342 | - } |
|
343 | - } |
|
344 | - if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) { |
|
345 | - $transaction->set_status($new_TXN_status); |
|
346 | - } |
|
347 | - if ($update_txn) { |
|
348 | - return (bool) $transaction->save(); |
|
349 | - } |
|
350 | - return true; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * _call_method_on_registrations_via_Registration_Processor |
|
356 | - * cycles thru related registrations and calls the requested method on each |
|
357 | - * |
|
358 | - * @param string $method_name |
|
359 | - * @param EE_Transaction $transaction |
|
360 | - * @param array $registration_query_params array of query WHERE params to use |
|
361 | - * when retrieving cached registrations from a transaction |
|
362 | - * @param array|string|null $additional_param |
|
363 | - * @return boolean |
|
364 | - * @throws EE_Error |
|
365 | - * @throws ReflectionException |
|
366 | - */ |
|
367 | - private function _call_method_on_registrations_via_Registration_Processor( |
|
368 | - string $method_name, |
|
369 | - EE_Transaction $transaction, |
|
370 | - array $registration_query_params = [], |
|
371 | - $additional_param = null |
|
372 | - ): bool { |
|
373 | - $response = false; |
|
374 | - /** @type EE_Registration_Processor $registration_processor */ |
|
375 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
376 | - // check that method exists |
|
377 | - if (! method_exists($registration_processor, $method_name)) { |
|
378 | - throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso')); |
|
379 | - } |
|
380 | - // make sure some query params are set for retrieving registrations |
|
381 | - $this->_set_registration_query_params($registration_query_params); |
|
382 | - // loop through cached registrations |
|
383 | - foreach ($transaction->registrations($this->_registration_query_params) as $registration) { |
|
384 | - if ($registration instanceof EE_Registration) { |
|
385 | - if ($additional_param) { |
|
386 | - $response = $registration_processor->{$method_name}($registration, $additional_param) |
|
387 | - ? true |
|
388 | - : $response; |
|
389 | - } else { |
|
390 | - $response = $registration_processor->{$method_name}($registration) |
|
391 | - ? true |
|
392 | - : $response; |
|
393 | - } |
|
394 | - } |
|
395 | - } |
|
396 | - return (bool) $response; |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * set_transaction_payment_method_based_on_registration_statuses |
|
402 | - * sets or unsets the PMD_ID field on the TXN based on the related REG statuses |
|
403 | - * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null, |
|
404 | - * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either: |
|
405 | - * the first "default" Payment Method |
|
406 | - * the first active Payment Method |
|
407 | - * whichever is found first. |
|
408 | - * |
|
409 | - * @param EE_Registration $edited_registration |
|
410 | - * @return void |
|
411 | - * @throws EE_Error |
|
412 | - * @throws ReflectionException |
|
413 | - */ |
|
414 | - public function set_transaction_payment_method_based_on_registration_statuses( |
|
415 | - EE_Registration $edited_registration |
|
416 | - ) { |
|
417 | - $transaction = $edited_registration->transaction(); |
|
418 | - $all_not_approved = true; |
|
419 | - foreach ($transaction->registrations() as $registration) { |
|
420 | - if ($registration instanceof EE_Registration) { |
|
421 | - // if any REG != "Not Approved" then toggle to false |
|
422 | - $all_not_approved = $registration->is_not_approved() |
|
423 | - ? $all_not_approved |
|
424 | - : false; |
|
425 | - } |
|
426 | - } |
|
427 | - // if ALL Registrations are "Not Approved" |
|
428 | - if ($all_not_approved) { |
|
429 | - $transaction->set_payment_method_ID(0); |
|
430 | - $transaction->save(); |
|
431 | - } else { |
|
432 | - $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
433 | - $transaction, |
|
434 | - EEM_Payment_Method::scope_cart |
|
435 | - ); |
|
436 | - if (! empty($available_payment_methods)) { |
|
437 | - $PMD_ID = 0; |
|
438 | - foreach ($available_payment_methods as $available_payment_method) { |
|
439 | - if ( |
|
440 | - $available_payment_method instanceof EE_Payment_Method |
|
441 | - && $available_payment_method->open_by_default() |
|
442 | - ) { |
|
443 | - $PMD_ID = $available_payment_method->ID(); |
|
444 | - break; |
|
445 | - } |
|
446 | - } |
|
447 | - if (! $PMD_ID) { |
|
448 | - $first_payment_method = reset($available_payment_methods); |
|
449 | - if ($first_payment_method instanceof EE_Payment_Method) { |
|
450 | - $PMD_ID = $first_payment_method->ID(); |
|
451 | - } else { |
|
452 | - EE_Error::add_error( |
|
453 | - esc_html__( |
|
454 | - 'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', |
|
455 | - 'event_espresso' |
|
456 | - ), |
|
457 | - __FILE__, |
|
458 | - __LINE__, |
|
459 | - __FUNCTION__ |
|
460 | - ); |
|
461 | - } |
|
462 | - } |
|
463 | - $transaction->set_payment_method_ID($PMD_ID); |
|
464 | - $transaction->save(); |
|
465 | - } else { |
|
466 | - EE_Error::add_error( |
|
467 | - esc_html__( |
|
468 | - 'Please activate at least one Payment Method in order for things to operate correctly.', |
|
469 | - 'event_espresso' |
|
470 | - ), |
|
471 | - __FILE__, |
|
472 | - __LINE__, |
|
473 | - __FUNCTION__ |
|
474 | - ); |
|
475 | - } |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /********************************** DEPRECATED METHODS **********************************/ |
|
482 | - |
|
483 | - |
|
484 | - /** |
|
485 | - * @param EE_Registration $registration |
|
486 | - * @return EE_Transaction |
|
487 | - * @throws EE_Error |
|
488 | - * @throws ReflectionException |
|
489 | - * @depecated 5.0.25.p |
|
490 | - */ |
|
491 | - public function get_transaction_for_registration(EE_Registration $registration): EE_Transaction |
|
492 | - { |
|
493 | - EE_Error::doing_it_wrong( |
|
494 | - __METHOD__, |
|
495 | - esc_html__( |
|
496 | - 'This logic is no longer necessary. Please just call EE_Registration::transaction() instead.', |
|
497 | - 'event_espresso' |
|
498 | - ), |
|
499 | - '5.0.25.p', |
|
500 | - '6.0.0' |
|
501 | - ); |
|
502 | - return $registration->transaction(); |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * @param EE_Transaction $transaction |
|
508 | - * @param EE_Registration $registration |
|
509 | - * @return EE_Line_Item |
|
510 | - * @throws EE_Error |
|
511 | - * @throws ReflectionException |
|
512 | - * @depecated 5.0.25.p |
|
513 | - */ |
|
514 | - public function get_ticket_line_item_for_transaction_registration( |
|
515 | - EE_Transaction $transaction, |
|
516 | - EE_Registration $registration |
|
517 | - ): EE_Line_Item { |
|
518 | - EE_Error::doing_it_wrong( |
|
519 | - __METHOD__, |
|
520 | - esc_html__( |
|
521 | - 'This logic been replaced by EE_Transaction_Processor::getTicketLineItemForRegistration(). Please use that method instead.', |
|
522 | - 'event_espresso' |
|
523 | - ), |
|
524 | - '5.0.25.p', |
|
525 | - '6.0.0' |
|
526 | - ); |
|
527 | - return $this->getTicketLineItemForRegistration($registration); |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - /** |
|
532 | - * toggle_registration_statuses_for_default_approved_events |
|
533 | - * |
|
534 | - * @param EE_Transaction $transaction |
|
535 | - * @param array $registration_query_params array of query WHERE params to use |
|
536 | - * when retrieving cached registrations from a transaction |
|
537 | - * @return boolean |
|
538 | - * @throws EE_Error |
|
539 | - * @throws ReflectionException |
|
540 | - * @depecated 5.0.25.p |
|
541 | - */ |
|
542 | - public function toggle_registration_statuses_for_default_approved_events( |
|
543 | - EE_Transaction $transaction, |
|
544 | - array $registration_query_params = [] |
|
545 | - ): bool { |
|
546 | - EE_Error::doing_it_wrong( |
|
547 | - __METHOD__, |
|
548 | - esc_html__( |
|
549 | - 'This logic been replaced by EE_Registration_Processor::toggle_registration_status_for_default_approved_events(). Please use that method instead.', |
|
550 | - 'event_espresso' |
|
551 | - ), |
|
552 | - '5.0.25.p', |
|
553 | - '6.0.0' |
|
554 | - ); |
|
555 | - $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
556 | - 'toggle_registration_status_for_default_approved_events', |
|
557 | - $transaction, |
|
558 | - $registration_query_params |
|
559 | - ); |
|
560 | - do_action( |
|
561 | - 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events', |
|
562 | - $transaction, |
|
563 | - $status_updates |
|
564 | - ); |
|
565 | - return $status_updates; |
|
566 | - } |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * toggle_registration_statuses_if_no_monies_owing |
|
571 | - * |
|
572 | - * @param EE_Transaction $transaction |
|
573 | - * @param array $registration_query_params array of query WHERE params to use |
|
574 | - * when retrieving cached registrations from a transaction |
|
575 | - * @return boolean |
|
576 | - * @throws EE_Error |
|
577 | - * @throws ReflectionException |
|
578 | - * @depecated 5.0.25.p |
|
579 | - */ |
|
580 | - public function toggle_registration_statuses_if_no_monies_owing( |
|
581 | - EE_Transaction $transaction, |
|
582 | - array $registration_query_params = [] |
|
583 | - ): bool { |
|
584 | - EE_Error::doing_it_wrong( |
|
585 | - __METHOD__, |
|
586 | - esc_html__( |
|
587 | - 'This logic been replaced by EE_Registration_Processor::toggle_registration_status_if_no_monies_owing(). Please use that method instead.', |
|
588 | - 'event_espresso' |
|
589 | - ), |
|
590 | - '5.0.25.p', |
|
591 | - '6.0.0' |
|
592 | - ); |
|
593 | - $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
594 | - 'toggle_registration_status_if_no_monies_owing', |
|
595 | - $transaction, |
|
596 | - $registration_query_params |
|
597 | - ); |
|
598 | - do_action( |
|
599 | - 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing', |
|
600 | - $transaction, |
|
601 | - $status_updates |
|
602 | - ); |
|
603 | - return $status_updates; |
|
604 | - } |
|
19 | + private static ?EE_Transaction_Processor $_instance = null; |
|
20 | + |
|
21 | + /** |
|
22 | + * array of query WHERE params to use when retrieving cached registrations from a transaction |
|
23 | + * |
|
24 | + * @var array $registration_query_params |
|
25 | + */ |
|
26 | + private array $_registration_query_params = []; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @singleton method used to instantiate class object |
|
31 | + * @param array $registration_query_params |
|
32 | + * @return EE_Transaction_Processor instance |
|
33 | + */ |
|
34 | + public static function instance(array $registration_query_params = []): EE_Transaction_Processor |
|
35 | + { |
|
36 | + // check if class object is instantiated |
|
37 | + if (! self::$_instance instanceof EE_Transaction_Processor) { |
|
38 | + self::$_instance = new self($registration_query_params); |
|
39 | + } |
|
40 | + return self::$_instance; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @param array $registration_query_params |
|
46 | + */ |
|
47 | + private function __construct(array $registration_query_params = []) |
|
48 | + { |
|
49 | + // make sure some query params are set for retrieving registrations |
|
50 | + $this->_set_registration_query_params($registration_query_params); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param array $registration_query_params |
|
56 | + */ |
|
57 | + private function _set_registration_query_params(array $registration_query_params) |
|
58 | + { |
|
59 | + $this->_registration_query_params = ! empty($registration_query_params) |
|
60 | + ? $registration_query_params |
|
61 | + : ['order_by' => ['REG_count' => 'ASC']]; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * manually_update_registration_statuses |
|
67 | + * |
|
68 | + * @param EE_Transaction $transaction |
|
69 | + * @param string $new_reg_status |
|
70 | + * @param array $registration_query_params array of query WHERE params to use |
|
71 | + * when retrieving cached registrations from a transaction |
|
72 | + * @return boolean |
|
73 | + * @throws EE_Error |
|
74 | + * @throws ReflectionException |
|
75 | + */ |
|
76 | + public function manually_update_registration_statuses( |
|
77 | + EE_Transaction $transaction, |
|
78 | + string $new_reg_status = '', |
|
79 | + array $registration_query_params = [] |
|
80 | + ): bool { |
|
81 | + $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
82 | + 'manually_update_registration_status', |
|
83 | + $transaction, |
|
84 | + $registration_query_params, |
|
85 | + $new_reg_status |
|
86 | + ); |
|
87 | + // send messages |
|
88 | + /** @type EE_Registration_Processor $registration_processor */ |
|
89 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
90 | + $registration_processor->trigger_registration_update_notifications( |
|
91 | + $transaction->primary_registration(), |
|
92 | + ['manually_updated' => true] |
|
93 | + ); |
|
94 | + do_action( |
|
95 | + 'AHEE__EE_Transaction_Processor__manually_update_registration_statuses', |
|
96 | + $transaction, |
|
97 | + $status_updates |
|
98 | + ); |
|
99 | + return $status_updates; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * update_transaction_and_registrations_after_checkout_or_payment |
|
105 | + * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each |
|
106 | + * |
|
107 | + * @param EE_Transaction $transaction |
|
108 | + * @param EE_Payment|null $payment |
|
109 | + * @param array $registration_query_params array of query WHERE params to use |
|
110 | + * when retrieving cached registrations from a transaction |
|
111 | + * @param bool $trigger_notifications whether to call EE_Registration_Processor::trigger_registration_update_notifications() |
|
112 | + * @return array |
|
113 | + * @throws EE_Error |
|
114 | + * @throws ReflectionException |
|
115 | + */ |
|
116 | + public function update_transaction_and_registrations_after_checkout_or_payment( |
|
117 | + EE_Transaction $transaction, |
|
118 | + ?EE_Payment $payment = null, |
|
119 | + array $registration_query_params = [], |
|
120 | + bool $trigger_notifications = true |
|
121 | + ): array { |
|
122 | + // make sure some query params are set for retrieving registrations |
|
123 | + $this->_set_registration_query_params($registration_query_params); |
|
124 | + // get final reg step status |
|
125 | + $finalized = $transaction->final_reg_step_completed(); |
|
126 | + // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
127 | + // but has not yet been fully completed (TRUE) |
|
128 | + if (is_int($finalized)) { |
|
129 | + $transaction->set_reg_step_completed('finalize_registration'); |
|
130 | + $finalized = true; |
|
131 | + } |
|
132 | + $transaction->save(); |
|
133 | + // array of details to aid in decision-making by systems |
|
134 | + $update_params = [ |
|
135 | + 'old_txn_status' => $transaction->old_txn_status(), |
|
136 | + 'new_txn_status' => $transaction->status_ID(), |
|
137 | + 'finalized' => $finalized, |
|
138 | + 'revisit' => $this->_revisit, |
|
139 | + 'payment_updates' => $payment instanceof EE_Payment, |
|
140 | + 'last_payment' => $payment, |
|
141 | + ]; |
|
142 | + // now update the registrations and add the results to our $update_params |
|
143 | + $update_params['status_updates'] = $this->_call_method_on_registrations_via_Registration_Processor( |
|
144 | + 'update_registration_after_checkout_or_payment', |
|
145 | + $transaction, |
|
146 | + $this->_registration_query_params, |
|
147 | + $update_params |
|
148 | + ); |
|
149 | + if ($trigger_notifications) { |
|
150 | + // send messages |
|
151 | + /** @type EE_Registration_Processor $registration_processor */ |
|
152 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
153 | + $registration_processor->trigger_registration_update_notifications( |
|
154 | + $transaction->primary_registration(), |
|
155 | + $update_params |
|
156 | + ); |
|
157 | + } |
|
158 | + do_action( |
|
159 | + 'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment', |
|
160 | + $transaction, |
|
161 | + $update_params |
|
162 | + ); |
|
163 | + return $update_params; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * update_transaction_after_registration_reopened |
|
169 | + * readjusts TXN and Line Item totals after a registration is changed from |
|
170 | + * cancelled or declined to another reg status such as pending payment or approved |
|
171 | + * |
|
172 | + * @param EE_Registration $registration |
|
173 | + * @param array $closed_reg_statuses |
|
174 | + * @param bool $update_txn |
|
175 | + * @return bool |
|
176 | + * @throws EE_Error |
|
177 | + * @throws ReflectionException |
|
178 | + */ |
|
179 | + public function update_transaction_after_reinstating_canceled_registration( |
|
180 | + EE_Registration $registration, |
|
181 | + array $closed_reg_statuses = [], |
|
182 | + bool $update_txn = true |
|
183 | + ): bool { |
|
184 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
185 | + $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
186 | + ? $closed_reg_statuses |
|
187 | + : EEM_Registration::closed_reg_statuses(); |
|
188 | + if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
189 | + return false; |
|
190 | + } |
|
191 | + try { |
|
192 | + $transaction = $registration->transaction(); |
|
193 | + $ticket_line_item = $this->getTicketLineItemForRegistration($registration); |
|
194 | + // un-cancel the ticket |
|
195 | + $success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item); |
|
196 | + } catch (EE_Error $e) { |
|
197 | + EE_Error::add_error( |
|
198 | + sprintf( |
|
199 | + esc_html__( |
|
200 | + 'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s', |
|
201 | + 'event_espresso' |
|
202 | + ), |
|
203 | + $registration->ID(), |
|
204 | + '<br />', |
|
205 | + $e->getMessage() |
|
206 | + ), |
|
207 | + __FILE__, |
|
208 | + __FUNCTION__, |
|
209 | + __LINE__ |
|
210 | + ); |
|
211 | + return false; |
|
212 | + } |
|
213 | + if ($update_txn) { |
|
214 | + return $transaction->save() |
|
215 | + ? $success |
|
216 | + : false; |
|
217 | + } |
|
218 | + return $success; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * update_transaction_after_canceled_or_declined_registration |
|
224 | + * readjusts TXN and Line Item totals after a registration is cancelled or declined |
|
225 | + * |
|
226 | + * @param EE_Registration $registration |
|
227 | + * @param array $closed_reg_statuses |
|
228 | + * @param bool $update_txn |
|
229 | + * @return bool |
|
230 | + * @throws EE_Error |
|
231 | + * @throws ReflectionException |
|
232 | + */ |
|
233 | + public function update_transaction_after_canceled_or_declined_registration( |
|
234 | + EE_Registration $registration, |
|
235 | + array $closed_reg_statuses = [], |
|
236 | + bool $update_txn = true |
|
237 | + ): bool { |
|
238 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
239 | + $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
240 | + ? $closed_reg_statuses |
|
241 | + : EEM_Registration::closed_reg_statuses(); |
|
242 | + if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
243 | + return false; |
|
244 | + } |
|
245 | + try { |
|
246 | + $transaction = $registration->transaction(); |
|
247 | + if ( |
|
248 | + apply_filters( |
|
249 | + 'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item', |
|
250 | + true, |
|
251 | + $registration, |
|
252 | + $transaction |
|
253 | + ) |
|
254 | + ) { |
|
255 | + $ticket_line_item = $this->getTicketLineItemForRegistration($registration); |
|
256 | + EEH_Line_Item::cancel_ticket_line_item($ticket_line_item); |
|
257 | + } |
|
258 | + } catch (EE_Error $e) { |
|
259 | + EE_Error::add_error( |
|
260 | + sprintf( |
|
261 | + esc_html__( |
|
262 | + 'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s', |
|
263 | + 'event_espresso' |
|
264 | + ), |
|
265 | + $registration->ID(), |
|
266 | + '<br />', |
|
267 | + $e->getMessage() |
|
268 | + ), |
|
269 | + __FILE__, |
|
270 | + __FUNCTION__, |
|
271 | + __LINE__ |
|
272 | + ); |
|
273 | + return false; |
|
274 | + } |
|
275 | + return ! $update_txn || $transaction->save(); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * @param EE_Registration $registration |
|
281 | + * @return EE_Line_Item |
|
282 | + * @throws EE_Error |
|
283 | + * @throws ReflectionException |
|
284 | + */ |
|
285 | + public function getTicketLineItemForRegistration(EE_Registration $registration): EE_Line_Item |
|
286 | + { |
|
287 | + $ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction( |
|
288 | + $registration->transaction_ID(), |
|
289 | + $registration->ticket_ID() |
|
290 | + ); |
|
291 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
292 | + return $ticket_line_item; |
|
293 | + } |
|
294 | + throw new EE_Error( |
|
295 | + sprintf( |
|
296 | + esc_html__( |
|
297 | + 'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.', |
|
298 | + 'event_espresso' |
|
299 | + ), |
|
300 | + $registration->transaction_ID(), |
|
301 | + $registration->ticket_ID() |
|
302 | + ) |
|
303 | + ); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * cancel_transaction_if_all_registrations_canceled |
|
309 | + * cycles thru related registrations and checks their statuses |
|
310 | + * if ALL registrations are Cancelled or Declined, then this sets the TXN status to |
|
311 | + * |
|
312 | + * @param EE_Transaction $transaction |
|
313 | + * @param string $new_TXN_status |
|
314 | + * @param array $registration_query_params - array of query WHERE params to use when |
|
315 | + * retrieving cached registrations from a transaction |
|
316 | + * @param array $closed_reg_statuses |
|
317 | + * @param bool $update_txn |
|
318 | + * @return bool true if TXN status was updated, false if not |
|
319 | + * @throws EE_Error |
|
320 | + * @throws ReflectionException |
|
321 | + */ |
|
322 | + public function toggle_transaction_status_if_all_registrations_canceled_or_declined( |
|
323 | + EE_Transaction $transaction, |
|
324 | + string $new_TXN_status = '', |
|
325 | + array $registration_query_params = [], |
|
326 | + array $closed_reg_statuses = [], |
|
327 | + bool $update_txn = true |
|
328 | + ): bool { |
|
329 | + // make sure some query params are set for retrieving registrations |
|
330 | + $this->_set_registration_query_params($registration_query_params); |
|
331 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
332 | + $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
333 | + ? $closed_reg_statuses |
|
334 | + : EEM_Registration::closed_reg_statuses(); |
|
335 | + // loop through cached registrations |
|
336 | + foreach ($transaction->registrations($this->_registration_query_params) as $registration) { |
|
337 | + if ( |
|
338 | + $registration instanceof EE_Registration |
|
339 | + && ! in_array($registration->status_ID(), $closed_reg_statuses) |
|
340 | + ) { |
|
341 | + return false; |
|
342 | + } |
|
343 | + } |
|
344 | + if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) { |
|
345 | + $transaction->set_status($new_TXN_status); |
|
346 | + } |
|
347 | + if ($update_txn) { |
|
348 | + return (bool) $transaction->save(); |
|
349 | + } |
|
350 | + return true; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * _call_method_on_registrations_via_Registration_Processor |
|
356 | + * cycles thru related registrations and calls the requested method on each |
|
357 | + * |
|
358 | + * @param string $method_name |
|
359 | + * @param EE_Transaction $transaction |
|
360 | + * @param array $registration_query_params array of query WHERE params to use |
|
361 | + * when retrieving cached registrations from a transaction |
|
362 | + * @param array|string|null $additional_param |
|
363 | + * @return boolean |
|
364 | + * @throws EE_Error |
|
365 | + * @throws ReflectionException |
|
366 | + */ |
|
367 | + private function _call_method_on_registrations_via_Registration_Processor( |
|
368 | + string $method_name, |
|
369 | + EE_Transaction $transaction, |
|
370 | + array $registration_query_params = [], |
|
371 | + $additional_param = null |
|
372 | + ): bool { |
|
373 | + $response = false; |
|
374 | + /** @type EE_Registration_Processor $registration_processor */ |
|
375 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
376 | + // check that method exists |
|
377 | + if (! method_exists($registration_processor, $method_name)) { |
|
378 | + throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso')); |
|
379 | + } |
|
380 | + // make sure some query params are set for retrieving registrations |
|
381 | + $this->_set_registration_query_params($registration_query_params); |
|
382 | + // loop through cached registrations |
|
383 | + foreach ($transaction->registrations($this->_registration_query_params) as $registration) { |
|
384 | + if ($registration instanceof EE_Registration) { |
|
385 | + if ($additional_param) { |
|
386 | + $response = $registration_processor->{$method_name}($registration, $additional_param) |
|
387 | + ? true |
|
388 | + : $response; |
|
389 | + } else { |
|
390 | + $response = $registration_processor->{$method_name}($registration) |
|
391 | + ? true |
|
392 | + : $response; |
|
393 | + } |
|
394 | + } |
|
395 | + } |
|
396 | + return (bool) $response; |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * set_transaction_payment_method_based_on_registration_statuses |
|
402 | + * sets or unsets the PMD_ID field on the TXN based on the related REG statuses |
|
403 | + * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null, |
|
404 | + * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either: |
|
405 | + * the first "default" Payment Method |
|
406 | + * the first active Payment Method |
|
407 | + * whichever is found first. |
|
408 | + * |
|
409 | + * @param EE_Registration $edited_registration |
|
410 | + * @return void |
|
411 | + * @throws EE_Error |
|
412 | + * @throws ReflectionException |
|
413 | + */ |
|
414 | + public function set_transaction_payment_method_based_on_registration_statuses( |
|
415 | + EE_Registration $edited_registration |
|
416 | + ) { |
|
417 | + $transaction = $edited_registration->transaction(); |
|
418 | + $all_not_approved = true; |
|
419 | + foreach ($transaction->registrations() as $registration) { |
|
420 | + if ($registration instanceof EE_Registration) { |
|
421 | + // if any REG != "Not Approved" then toggle to false |
|
422 | + $all_not_approved = $registration->is_not_approved() |
|
423 | + ? $all_not_approved |
|
424 | + : false; |
|
425 | + } |
|
426 | + } |
|
427 | + // if ALL Registrations are "Not Approved" |
|
428 | + if ($all_not_approved) { |
|
429 | + $transaction->set_payment_method_ID(0); |
|
430 | + $transaction->save(); |
|
431 | + } else { |
|
432 | + $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
433 | + $transaction, |
|
434 | + EEM_Payment_Method::scope_cart |
|
435 | + ); |
|
436 | + if (! empty($available_payment_methods)) { |
|
437 | + $PMD_ID = 0; |
|
438 | + foreach ($available_payment_methods as $available_payment_method) { |
|
439 | + if ( |
|
440 | + $available_payment_method instanceof EE_Payment_Method |
|
441 | + && $available_payment_method->open_by_default() |
|
442 | + ) { |
|
443 | + $PMD_ID = $available_payment_method->ID(); |
|
444 | + break; |
|
445 | + } |
|
446 | + } |
|
447 | + if (! $PMD_ID) { |
|
448 | + $first_payment_method = reset($available_payment_methods); |
|
449 | + if ($first_payment_method instanceof EE_Payment_Method) { |
|
450 | + $PMD_ID = $first_payment_method->ID(); |
|
451 | + } else { |
|
452 | + EE_Error::add_error( |
|
453 | + esc_html__( |
|
454 | + 'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', |
|
455 | + 'event_espresso' |
|
456 | + ), |
|
457 | + __FILE__, |
|
458 | + __LINE__, |
|
459 | + __FUNCTION__ |
|
460 | + ); |
|
461 | + } |
|
462 | + } |
|
463 | + $transaction->set_payment_method_ID($PMD_ID); |
|
464 | + $transaction->save(); |
|
465 | + } else { |
|
466 | + EE_Error::add_error( |
|
467 | + esc_html__( |
|
468 | + 'Please activate at least one Payment Method in order for things to operate correctly.', |
|
469 | + 'event_espresso' |
|
470 | + ), |
|
471 | + __FILE__, |
|
472 | + __LINE__, |
|
473 | + __FUNCTION__ |
|
474 | + ); |
|
475 | + } |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /********************************** DEPRECATED METHODS **********************************/ |
|
482 | + |
|
483 | + |
|
484 | + /** |
|
485 | + * @param EE_Registration $registration |
|
486 | + * @return EE_Transaction |
|
487 | + * @throws EE_Error |
|
488 | + * @throws ReflectionException |
|
489 | + * @depecated 5.0.25.p |
|
490 | + */ |
|
491 | + public function get_transaction_for_registration(EE_Registration $registration): EE_Transaction |
|
492 | + { |
|
493 | + EE_Error::doing_it_wrong( |
|
494 | + __METHOD__, |
|
495 | + esc_html__( |
|
496 | + 'This logic is no longer necessary. Please just call EE_Registration::transaction() instead.', |
|
497 | + 'event_espresso' |
|
498 | + ), |
|
499 | + '5.0.25.p', |
|
500 | + '6.0.0' |
|
501 | + ); |
|
502 | + return $registration->transaction(); |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * @param EE_Transaction $transaction |
|
508 | + * @param EE_Registration $registration |
|
509 | + * @return EE_Line_Item |
|
510 | + * @throws EE_Error |
|
511 | + * @throws ReflectionException |
|
512 | + * @depecated 5.0.25.p |
|
513 | + */ |
|
514 | + public function get_ticket_line_item_for_transaction_registration( |
|
515 | + EE_Transaction $transaction, |
|
516 | + EE_Registration $registration |
|
517 | + ): EE_Line_Item { |
|
518 | + EE_Error::doing_it_wrong( |
|
519 | + __METHOD__, |
|
520 | + esc_html__( |
|
521 | + 'This logic been replaced by EE_Transaction_Processor::getTicketLineItemForRegistration(). Please use that method instead.', |
|
522 | + 'event_espresso' |
|
523 | + ), |
|
524 | + '5.0.25.p', |
|
525 | + '6.0.0' |
|
526 | + ); |
|
527 | + return $this->getTicketLineItemForRegistration($registration); |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + /** |
|
532 | + * toggle_registration_statuses_for_default_approved_events |
|
533 | + * |
|
534 | + * @param EE_Transaction $transaction |
|
535 | + * @param array $registration_query_params array of query WHERE params to use |
|
536 | + * when retrieving cached registrations from a transaction |
|
537 | + * @return boolean |
|
538 | + * @throws EE_Error |
|
539 | + * @throws ReflectionException |
|
540 | + * @depecated 5.0.25.p |
|
541 | + */ |
|
542 | + public function toggle_registration_statuses_for_default_approved_events( |
|
543 | + EE_Transaction $transaction, |
|
544 | + array $registration_query_params = [] |
|
545 | + ): bool { |
|
546 | + EE_Error::doing_it_wrong( |
|
547 | + __METHOD__, |
|
548 | + esc_html__( |
|
549 | + 'This logic been replaced by EE_Registration_Processor::toggle_registration_status_for_default_approved_events(). Please use that method instead.', |
|
550 | + 'event_espresso' |
|
551 | + ), |
|
552 | + '5.0.25.p', |
|
553 | + '6.0.0' |
|
554 | + ); |
|
555 | + $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
556 | + 'toggle_registration_status_for_default_approved_events', |
|
557 | + $transaction, |
|
558 | + $registration_query_params |
|
559 | + ); |
|
560 | + do_action( |
|
561 | + 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events', |
|
562 | + $transaction, |
|
563 | + $status_updates |
|
564 | + ); |
|
565 | + return $status_updates; |
|
566 | + } |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * toggle_registration_statuses_if_no_monies_owing |
|
571 | + * |
|
572 | + * @param EE_Transaction $transaction |
|
573 | + * @param array $registration_query_params array of query WHERE params to use |
|
574 | + * when retrieving cached registrations from a transaction |
|
575 | + * @return boolean |
|
576 | + * @throws EE_Error |
|
577 | + * @throws ReflectionException |
|
578 | + * @depecated 5.0.25.p |
|
579 | + */ |
|
580 | + public function toggle_registration_statuses_if_no_monies_owing( |
|
581 | + EE_Transaction $transaction, |
|
582 | + array $registration_query_params = [] |
|
583 | + ): bool { |
|
584 | + EE_Error::doing_it_wrong( |
|
585 | + __METHOD__, |
|
586 | + esc_html__( |
|
587 | + 'This logic been replaced by EE_Registration_Processor::toggle_registration_status_if_no_monies_owing(). Please use that method instead.', |
|
588 | + 'event_espresso' |
|
589 | + ), |
|
590 | + '5.0.25.p', |
|
591 | + '6.0.0' |
|
592 | + ); |
|
593 | + $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( |
|
594 | + 'toggle_registration_status_if_no_monies_owing', |
|
595 | + $transaction, |
|
596 | + $registration_query_params |
|
597 | + ); |
|
598 | + do_action( |
|
599 | + 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing', |
|
600 | + $transaction, |
|
601 | + $status_updates |
|
602 | + ); |
|
603 | + return $status_updates; |
|
604 | + } |
|
605 | 605 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once __DIR__ . '/EE_Processor_Base.class.php'; |
|
3 | +require_once __DIR__.'/EE_Processor_Base.class.php'; |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * Class EE_Transaction_Processor |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public static function instance(array $registration_query_params = []): EE_Transaction_Processor |
35 | 35 | { |
36 | 36 | // check if class object is instantiated |
37 | - if (! self::$_instance instanceof EE_Transaction_Processor) { |
|
37 | + if ( ! self::$_instance instanceof EE_Transaction_Processor) { |
|
38 | 38 | self::$_instance = new self($registration_query_params); |
39 | 39 | } |
40 | 40 | return self::$_instance; |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | $closed_reg_statuses = ! empty($closed_reg_statuses) |
240 | 240 | ? $closed_reg_statuses |
241 | 241 | : EEM_Registration::closed_reg_statuses(); |
242 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
242 | + if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | try { |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | /** @type EE_Registration_Processor $registration_processor */ |
375 | 375 | $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
376 | 376 | // check that method exists |
377 | - if (! method_exists($registration_processor, $method_name)) { |
|
377 | + if ( ! method_exists($registration_processor, $method_name)) { |
|
378 | 378 | throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso')); |
379 | 379 | } |
380 | 380 | // make sure some query params are set for retrieving registrations |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | $transaction, |
434 | 434 | EEM_Payment_Method::scope_cart |
435 | 435 | ); |
436 | - if (! empty($available_payment_methods)) { |
|
436 | + if ( ! empty($available_payment_methods)) { |
|
437 | 437 | $PMD_ID = 0; |
438 | 438 | foreach ($available_payment_methods as $available_payment_method) { |
439 | 439 | if ( |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | break; |
445 | 445 | } |
446 | 446 | } |
447 | - if (! $PMD_ID) { |
|
447 | + if ( ! $PMD_ID) { |
|
448 | 448 | $first_payment_method = reset($available_payment_methods); |
449 | 449 | if ($first_payment_method instanceof EE_Payment_Method) { |
450 | 450 | $PMD_ID = $first_payment_method->ID(); |
@@ -10,71 +10,71 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Processor_Base |
12 | 12 | { |
13 | - /** |
|
14 | - * Used to indicate whether current request is for an IPN or not. |
|
15 | - * |
|
16 | - * @var bool |
|
17 | - */ |
|
18 | - protected static bool $IPN = false; |
|
13 | + /** |
|
14 | + * Used to indicate whether current request is for an IPN or not. |
|
15 | + * |
|
16 | + * @var bool |
|
17 | + */ |
|
18 | + protected static bool $IPN = false; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Used to indicate whether SPCO is being revisited by registrant or not. |
|
22 | - * |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected bool $_revisit = false; |
|
20 | + /** |
|
21 | + * Used to indicate whether SPCO is being revisited by registrant or not. |
|
22 | + * |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected bool $_revisit = false; |
|
26 | 26 | |
27 | - private static bool $debug = false; |
|
27 | + private static bool $debug = false; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @param bool|int|string $IPN truthy/falsey value |
|
32 | - */ |
|
33 | - public static function set_IPN($IPN) |
|
34 | - { |
|
35 | - self::$IPN = filter_var($IPN, FILTER_VALIDATE_BOOLEAN); |
|
36 | - } |
|
30 | + /** |
|
31 | + * @param bool|int|string $IPN truthy/falsey value |
|
32 | + */ |
|
33 | + public static function set_IPN($IPN) |
|
34 | + { |
|
35 | + self::$IPN = filter_var($IPN, FILTER_VALIDATE_BOOLEAN); |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * Allows external class (usually checkout) to set whether SPCO is being revisited by registrant or not. |
|
41 | - * |
|
42 | - * @param bool|int|string $revisit |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function set_revisit($revisit = false) |
|
46 | - { |
|
47 | - $this->_revisit = filter_var($revisit, FILTER_VALIDATE_BOOLEAN); |
|
48 | - } |
|
39 | + /** |
|
40 | + * Allows external class (usually checkout) to set whether SPCO is being revisited by registrant or not. |
|
41 | + * |
|
42 | + * @param bool|int|string $revisit |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function set_revisit($revisit = false) |
|
46 | + { |
|
47 | + $this->_revisit = filter_var($revisit, FILTER_VALIDATE_BOOLEAN); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * debug |
|
53 | - * |
|
54 | - * @param string $class |
|
55 | - * @param string $func |
|
56 | - * @param int|string $line |
|
57 | - * @param EE_Transaction|null $transaction |
|
58 | - * @param array $info |
|
59 | - * @param bool $display_request |
|
60 | - * @throws EE_Error |
|
61 | - * @throws ReflectionException |
|
62 | - */ |
|
63 | - protected function log( |
|
64 | - string $class = '', |
|
65 | - string $func = '', |
|
66 | - $line = '', |
|
67 | - ?EE_Transaction $transaction = null, |
|
68 | - array $info = [], |
|
69 | - bool $display_request = false |
|
70 | - ) { |
|
71 | - if (EE_Processor_Base::$debug && $transaction instanceof EE_Transaction && $transaction->ID()) { |
|
72 | - // don't serialize objects |
|
73 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
74 | - $info['TXN_status'] = $transaction->status_ID(); |
|
75 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
76 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
77 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
78 | - } |
|
79 | - } |
|
51 | + /** |
|
52 | + * debug |
|
53 | + * |
|
54 | + * @param string $class |
|
55 | + * @param string $func |
|
56 | + * @param int|string $line |
|
57 | + * @param EE_Transaction|null $transaction |
|
58 | + * @param array $info |
|
59 | + * @param bool $display_request |
|
60 | + * @throws EE_Error |
|
61 | + * @throws ReflectionException |
|
62 | + */ |
|
63 | + protected function log( |
|
64 | + string $class = '', |
|
65 | + string $func = '', |
|
66 | + $line = '', |
|
67 | + ?EE_Transaction $transaction = null, |
|
68 | + array $info = [], |
|
69 | + bool $display_request = false |
|
70 | + ) { |
|
71 | + if (EE_Processor_Base::$debug && $transaction instanceof EE_Transaction && $transaction->ID()) { |
|
72 | + // don't serialize objects |
|
73 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
74 | + $info['TXN_status'] = $transaction->status_ID(); |
|
75 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
76 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
77 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | } |
@@ -73,7 +73,7 @@ |
||
73 | 73 | $info = EEH_Debug_Tools::strip_objects($info); |
74 | 74 | $info['TXN_status'] = $transaction->status_ID(); |
75 | 75 | $info['TXN_reg_steps'] = $transaction->reg_steps(); |
76 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
76 | + $index = 'EE_Transaction: '.$transaction->ID(); |
|
77 | 77 | EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
78 | 78 | } |
79 | 79 | } |