@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $txn = $has_object |
43 | 43 | ? $has_object |
44 | 44 | : new self($props_n_values, false, $timezone, $date_formats); |
45 | - if (! $has_object) { |
|
45 | + if ( ! $has_object) { |
|
46 | 46 | $txn->set_old_txn_status($txn->status_ID()); |
47 | 47 | } |
48 | 48 | return $txn; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | public function lock() |
75 | 75 | { |
76 | 76 | // attempt to set lock, but if that fails... |
77 | - if (! $this->add_extra_meta('lock', time(), true)) { |
|
77 | + if ( ! $this->add_extra_meta('lock', time(), true)) { |
|
78 | 78 | // then attempt to remove the lock in case it is expired |
79 | 79 | if ($this->_remove_expired_lock()) { |
80 | 80 | // if removal was successful, then try setting lock again |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | public function is_locked() |
123 | 123 | { |
124 | 124 | // if TXN is not locked, then return false immediately |
125 | - if (! $this->_get_lock()) { |
|
125 | + if ( ! $this->_get_lock()) { |
|
126 | 126 | return false; |
127 | 127 | } |
128 | 128 | // if not, then let's try and remove the lock in case it's expired... |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
528 | 528 | break; |
529 | 529 | } |
530 | - return $icon . $status[ $this->status_ID() ]; |
|
530 | + return $icon.$status[$this->status_ID()]; |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | public function invoice_url($type = 'html') |
632 | 632 | { |
633 | 633 | $REG = $this->primary_registration(); |
634 | - if (! $REG instanceof EE_Registration) { |
|
634 | + if ( ! $REG instanceof EE_Registration) { |
|
635 | 635 | return ''; |
636 | 636 | } |
637 | 637 | return $REG->invoice_url($type); |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | public function receipt_url($type = 'html') |
674 | 674 | { |
675 | 675 | $REG = $this->primary_registration(); |
676 | - if (! $REG instanceof EE_Registration) { |
|
676 | + if ( ! $REG instanceof EE_Registration) { |
|
677 | 677 | return ''; |
678 | 678 | } |
679 | 679 | return $REG->receipt_url($type); |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | public function total_line_item($create_if_not_found = true) |
819 | 819 | { |
820 | 820 | $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
821 | - if (! $item && $create_if_not_found) { |
|
821 | + if ( ! $item && $create_if_not_found) { |
|
822 | 822 | $item = EEH_Line_Item::create_total_line_item($this); |
823 | 823 | } |
824 | 824 | return $item; |
@@ -863,7 +863,7 @@ discard block |
||
863 | 863 | public function billing_info() |
864 | 864 | { |
865 | 865 | $payment_method = $this->payment_method(); |
866 | - if (! $payment_method) { |
|
866 | + if ( ! $payment_method) { |
|
867 | 867 | EE_Error::add_error( |
868 | 868 | __( |
869 | 869 | 'Could not find billing info for transaction because no gateway has been used for it yet', |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | return null; |
877 | 877 | } |
878 | 878 | $primary_reg = $this->primary_registration(); |
879 | - if (! $primary_reg) { |
|
879 | + if ( ! $primary_reg) { |
|
880 | 880 | EE_Error::add_error( |
881 | 881 | __( |
882 | 882 | 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
@@ -889,7 +889,7 @@ discard block |
||
889 | 889 | return null; |
890 | 890 | } |
891 | 891 | $attendee = $primary_reg->attendee(); |
892 | - if (! $attendee) { |
|
892 | + if ( ! $attendee) { |
|
893 | 893 | EE_Error::add_error( |
894 | 894 | __( |
895 | 895 | 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
@@ -1025,7 +1025,7 @@ discard block |
||
1025 | 1025 | public function update_based_on_payments() |
1026 | 1026 | { |
1027 | 1027 | EE_Error::doing_it_wrong( |
1028 | - __CLASS__ . '::' . __FUNCTION__, |
|
1028 | + __CLASS__.'::'.__FUNCTION__, |
|
1029 | 1029 | sprintf( |
1030 | 1030 | __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
1031 | 1031 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
@@ -1085,13 +1085,13 @@ discard block |
||
1085 | 1085 | private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
1086 | 1086 | { |
1087 | 1087 | $reg_steps = $this->reg_steps(); |
1088 | - if (! is_array($reg_steps) || empty($reg_steps)) { |
|
1088 | + if ( ! is_array($reg_steps) || empty($reg_steps)) { |
|
1089 | 1089 | return false; |
1090 | 1090 | } |
1091 | 1091 | // loop thru reg steps array) |
1092 | 1092 | foreach ($reg_steps as $slug => $reg_step_completed) { |
1093 | 1093 | // if NOT checking ALL steps (only checking one step) |
1094 | - if (! $check_all) { |
|
1094 | + if ( ! $check_all) { |
|
1095 | 1095 | // and this is the one |
1096 | 1096 | if ($slug === $reg_step_slug) { |
1097 | 1097 | return $reg_step_completed; |
@@ -1258,30 +1258,30 @@ discard block |
||
1258 | 1258 | // get reg steps array |
1259 | 1259 | $txn_reg_steps = $this->reg_steps(); |
1260 | 1260 | // if reg step does NOT exist |
1261 | - if (! isset($txn_reg_steps[ $reg_step_slug ])) { |
|
1261 | + if ( ! isset($txn_reg_steps[$reg_step_slug])) { |
|
1262 | 1262 | return false; |
1263 | 1263 | } |
1264 | 1264 | // if we're trying to complete a step that is already completed |
1265 | - if ($txn_reg_steps[ $reg_step_slug ] === true) { |
|
1265 | + if ($txn_reg_steps[$reg_step_slug] === true) { |
|
1266 | 1266 | return true; |
1267 | 1267 | } |
1268 | 1268 | // if we're trying to complete a step that hasn't even started |
1269 | - if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) { |
|
1269 | + if ($status === true && $txn_reg_steps[$reg_step_slug] === false) { |
|
1270 | 1270 | return false; |
1271 | 1271 | } |
1272 | 1272 | // if current status value matches the incoming value (no change) |
1273 | 1273 | // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
1274 | - if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) { |
|
1274 | + if ((int) $txn_reg_steps[$reg_step_slug] === (int) $status) { |
|
1275 | 1275 | // this will happen in cases where multiple AJAX requests occur during the same step |
1276 | 1276 | return true; |
1277 | 1277 | } |
1278 | 1278 | // if we're trying to set a start time, but it has already been set... |
1279 | - if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) { |
|
1279 | + if (is_numeric($status) && is_numeric($txn_reg_steps[$reg_step_slug])) { |
|
1280 | 1280 | // skip the update below, but don't return FALSE so that errors won't be displayed |
1281 | 1281 | return true; |
1282 | 1282 | } |
1283 | 1283 | // update completed status |
1284 | - $txn_reg_steps[ $reg_step_slug ] = $status; |
|
1284 | + $txn_reg_steps[$reg_step_slug] = $status; |
|
1285 | 1285 | $this->set_reg_steps($txn_reg_steps); |
1286 | 1286 | $this->save(); |
1287 | 1287 | return true; |
@@ -1301,7 +1301,7 @@ discard block |
||
1301 | 1301 | { |
1302 | 1302 | // get reg steps array |
1303 | 1303 | $txn_reg_steps = $this->reg_steps(); |
1304 | - unset($txn_reg_steps[ $reg_step_slug ]); |
|
1304 | + unset($txn_reg_steps[$reg_step_slug]); |
|
1305 | 1305 | $this->set_reg_steps($txn_reg_steps); |
1306 | 1306 | } |
1307 | 1307 | |
@@ -1374,12 +1374,12 @@ discard block |
||
1374 | 1374 | return; |
1375 | 1375 | } |
1376 | 1376 | $payments = $this->get_many_related('Payment'); |
1377 | - if (! empty($payments)) { |
|
1377 | + if ( ! empty($payments)) { |
|
1378 | 1378 | foreach ($payments as $payment) { |
1379 | 1379 | if ($payment instanceof EE_Payment) { |
1380 | 1380 | // kk this TXN should NOT be abandoned |
1381 | 1381 | $this->update_status_based_on_total_paid(); |
1382 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1382 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1383 | 1383 | EE_Error::add_attention( |
1384 | 1384 | sprintf( |
1385 | 1385 | esc_html__( |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | |
367 | 367 | |
368 | 368 | /** |
369 | - * @return mixed|null |
|
369 | + * @return EE_Cart|null |
|
370 | 370 | * @throws EE_Error |
371 | 371 | * @throws InvalidArgumentException |
372 | 372 | * @throws InvalidDataTypeException |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
509 | 509 | * function for getting attendees and how many registrations they each have for an event) |
510 | 510 | * |
511 | - * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
511 | + * @return EE_Base_Class[] EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
512 | 512 | * @throws EE_Error |
513 | 513 | * @throws InvalidArgumentException |
514 | 514 | * @throws InvalidDataTypeException |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | /** |
565 | 565 | * Gets all payments which have not been approved |
566 | 566 | * |
567 | - * @return EE_Base_Class[]|EEI_Payment[] |
|
567 | + * @return EE_Base_Class[] |
|
568 | 568 | * @throws EE_Error if a model is misconfigured somehow |
569 | 569 | * @throws InvalidArgumentException |
570 | 570 | * @throws InvalidDataTypeException |
@@ -13,1682 +13,1682 @@ |
||
13 | 13 | class EE_Transaction extends EE_Base_Class implements EEI_Transaction |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * The length of time in seconds that a lock is applied before being considered expired. |
|
18 | - * It is not long because a transaction should only be locked for the duration of the request that locked it |
|
19 | - */ |
|
20 | - const LOCK_EXPIRATION = 2; |
|
21 | - |
|
22 | - /** |
|
23 | - * txn status upon initial construction. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $_old_txn_status; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @param array $props_n_values incoming values |
|
32 | - * @param string $timezone incoming timezone |
|
33 | - * (if not set the timezone set for the website will be used.) |
|
34 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
35 | - * date_format and the second value is the time format |
|
36 | - * @return EE_Transaction |
|
37 | - * @throws EE_Error |
|
38 | - * @throws InvalidArgumentException |
|
39 | - * @throws InvalidDataTypeException |
|
40 | - * @throws InvalidInterfaceException |
|
41 | - * @throws ReflectionException |
|
42 | - */ |
|
43 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
44 | - { |
|
45 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
46 | - $txn = $has_object |
|
47 | - ? $has_object |
|
48 | - : new self($props_n_values, false, $timezone, $date_formats); |
|
49 | - if (! $has_object) { |
|
50 | - $txn->set_old_txn_status($txn->status_ID()); |
|
51 | - } |
|
52 | - return $txn; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @param array $props_n_values incoming values from the database |
|
58 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
59 | - * the website will be used. |
|
60 | - * @return EE_Transaction |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidArgumentException |
|
63 | - * @throws InvalidDataTypeException |
|
64 | - * @throws InvalidInterfaceException |
|
65 | - * @throws ReflectionException |
|
66 | - */ |
|
67 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
68 | - { |
|
69 | - $txn = new self($props_n_values, true, $timezone); |
|
70 | - $txn->set_old_txn_status($txn->status_ID()); |
|
71 | - return $txn; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Sets a meta field indicating that this TXN is locked and should not be updated in the db. |
|
77 | - * If a lock has already been set, then we will attempt to remove it in case it has expired. |
|
78 | - * If that also fails, then an exception is thrown. |
|
79 | - * |
|
80 | - * @throws EE_Error |
|
81 | - * @throws InvalidArgumentException |
|
82 | - * @throws InvalidDataTypeException |
|
83 | - * @throws InvalidInterfaceException |
|
84 | - * @throws ReflectionException |
|
85 | - */ |
|
86 | - public function lock() |
|
87 | - { |
|
88 | - // attempt to set lock, but if that fails... |
|
89 | - if (! $this->add_extra_meta('lock', time(), true)) { |
|
90 | - // then attempt to remove the lock in case it is expired |
|
91 | - if ($this->_remove_expired_lock()) { |
|
92 | - // if removal was successful, then try setting lock again |
|
93 | - $this->lock(); |
|
94 | - } else { |
|
95 | - // but if the lock can not be removed, then throw an exception |
|
96 | - throw new EE_Error( |
|
97 | - sprintf( |
|
98 | - __( |
|
99 | - 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', |
|
100 | - 'event_espresso' |
|
101 | - ), |
|
102 | - $this->ID() |
|
103 | - ) |
|
104 | - ); |
|
105 | - } |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * removes transaction lock applied in EE_Transaction::lock() |
|
112 | - * |
|
113 | - * @return int |
|
114 | - * @throws EE_Error |
|
115 | - * @throws InvalidArgumentException |
|
116 | - * @throws InvalidDataTypeException |
|
117 | - * @throws InvalidInterfaceException |
|
118 | - * @throws ReflectionException |
|
119 | - */ |
|
120 | - public function unlock() |
|
121 | - { |
|
122 | - return $this->delete_extra_meta('lock'); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Decides whether or not now is the right time to update the transaction. |
|
128 | - * This is useful because we don't always know if it is safe to update the transaction |
|
129 | - * and its related data. why? |
|
130 | - * because it's possible that the transaction is being used in another |
|
131 | - * request and could overwrite anything we save. |
|
132 | - * So we want to only update the txn once we know that won't happen. |
|
133 | - * We also check that the lock isn't expired, and remove it if it is |
|
134 | - * |
|
135 | - * @return boolean |
|
136 | - * @throws EE_Error |
|
137 | - * @throws InvalidArgumentException |
|
138 | - * @throws InvalidDataTypeException |
|
139 | - * @throws InvalidInterfaceException |
|
140 | - * @throws ReflectionException |
|
141 | - */ |
|
142 | - public function is_locked() |
|
143 | - { |
|
144 | - // if TXN is not locked, then return false immediately |
|
145 | - if (! $this->_get_lock()) { |
|
146 | - return false; |
|
147 | - } |
|
148 | - // if not, then let's try and remove the lock in case it's expired... |
|
149 | - // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false) |
|
150 | - // and a positive number if the lock was removed (ie: number of locks deleted), |
|
151 | - // so we need to return the opposite |
|
152 | - return ! $this->_remove_expired_lock() ? true : false; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Gets the meta field indicating that this TXN is locked |
|
158 | - * |
|
159 | - * @return int |
|
160 | - * @throws EE_Error |
|
161 | - * @throws InvalidArgumentException |
|
162 | - * @throws InvalidDataTypeException |
|
163 | - * @throws InvalidInterfaceException |
|
164 | - * @throws ReflectionException |
|
165 | - */ |
|
166 | - protected function _get_lock() |
|
167 | - { |
|
168 | - return (int) $this->get_extra_meta('lock', true, 0); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
|
174 | - * |
|
175 | - * @return int |
|
176 | - * @throws EE_Error |
|
177 | - * @throws InvalidArgumentException |
|
178 | - * @throws InvalidDataTypeException |
|
179 | - * @throws InvalidInterfaceException |
|
180 | - * @throws ReflectionException |
|
181 | - */ |
|
182 | - protected function _remove_expired_lock() |
|
183 | - { |
|
184 | - $locked = $this->_get_lock(); |
|
185 | - if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
186 | - return $this->unlock(); |
|
187 | - } |
|
188 | - return 0; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * Set transaction total |
|
194 | - * |
|
195 | - * @param float $total total value of transaction |
|
196 | - * @throws EE_Error |
|
197 | - * @throws InvalidArgumentException |
|
198 | - * @throws InvalidDataTypeException |
|
199 | - * @throws InvalidInterfaceException |
|
200 | - * @throws ReflectionException |
|
201 | - */ |
|
202 | - public function set_total($total = 0.00) |
|
203 | - { |
|
204 | - $this->set('TXN_total', (float) $total); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * Set Total Amount Paid to Date |
|
210 | - * |
|
211 | - * @param float $total_paid total amount paid to date (sum of all payments) |
|
212 | - * @throws EE_Error |
|
213 | - * @throws InvalidArgumentException |
|
214 | - * @throws InvalidDataTypeException |
|
215 | - * @throws InvalidInterfaceException |
|
216 | - * @throws ReflectionException |
|
217 | - */ |
|
218 | - public function set_paid($total_paid = 0.00) |
|
219 | - { |
|
220 | - $this->set('TXN_paid', (float) $total_paid); |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * Set transaction status |
|
226 | - * |
|
227 | - * @param string $status whether the transaction is open, declined, accepted, |
|
228 | - * or any number of custom values that can be set |
|
229 | - * @throws EE_Error |
|
230 | - * @throws InvalidArgumentException |
|
231 | - * @throws InvalidDataTypeException |
|
232 | - * @throws InvalidInterfaceException |
|
233 | - * @throws ReflectionException |
|
234 | - */ |
|
235 | - public function set_status($status = '') |
|
236 | - { |
|
237 | - $this->set('STS_ID', $status); |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * Set hash salt |
|
243 | - * |
|
244 | - * @param string $hash_salt required for some payment gateways |
|
245 | - * @throws EE_Error |
|
246 | - * @throws InvalidArgumentException |
|
247 | - * @throws InvalidDataTypeException |
|
248 | - * @throws InvalidInterfaceException |
|
249 | - * @throws ReflectionException |
|
250 | - */ |
|
251 | - public function set_hash_salt($hash_salt = '') |
|
252 | - { |
|
253 | - $this->set('TXN_hash_salt', $hash_salt); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * Sets TXN_reg_steps array |
|
259 | - * |
|
260 | - * @param array $txn_reg_steps |
|
261 | - * @throws EE_Error |
|
262 | - * @throws InvalidArgumentException |
|
263 | - * @throws InvalidDataTypeException |
|
264 | - * @throws InvalidInterfaceException |
|
265 | - * @throws ReflectionException |
|
266 | - */ |
|
267 | - public function set_reg_steps(array $txn_reg_steps) |
|
268 | - { |
|
269 | - $this->set('TXN_reg_steps', $txn_reg_steps); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Gets TXN_reg_steps |
|
275 | - * |
|
276 | - * @return array |
|
277 | - * @throws EE_Error |
|
278 | - * @throws InvalidArgumentException |
|
279 | - * @throws InvalidDataTypeException |
|
280 | - * @throws InvalidInterfaceException |
|
281 | - * @throws ReflectionException |
|
282 | - */ |
|
283 | - public function reg_steps() |
|
284 | - { |
|
285 | - $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
286 | - return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * @return string of transaction's total cost, with currency symbol and decimal |
|
292 | - * @throws EE_Error |
|
293 | - * @throws InvalidArgumentException |
|
294 | - * @throws InvalidDataTypeException |
|
295 | - * @throws InvalidInterfaceException |
|
296 | - * @throws ReflectionException |
|
297 | - */ |
|
298 | - public function pretty_total() |
|
299 | - { |
|
300 | - return $this->get_pretty('TXN_total'); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Gets the amount paid in a pretty string (formatted and with currency symbol) |
|
306 | - * |
|
307 | - * @return string |
|
308 | - * @throws EE_Error |
|
309 | - * @throws InvalidArgumentException |
|
310 | - * @throws InvalidDataTypeException |
|
311 | - * @throws InvalidInterfaceException |
|
312 | - * @throws ReflectionException |
|
313 | - */ |
|
314 | - public function pretty_paid() |
|
315 | - { |
|
316 | - return $this->get_pretty('TXN_paid'); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * calculate the amount remaining for this transaction and return; |
|
322 | - * |
|
323 | - * @return float amount remaining |
|
324 | - * @throws EE_Error |
|
325 | - * @throws InvalidArgumentException |
|
326 | - * @throws InvalidDataTypeException |
|
327 | - * @throws InvalidInterfaceException |
|
328 | - * @throws ReflectionException |
|
329 | - */ |
|
330 | - public function remaining() |
|
331 | - { |
|
332 | - return $this->total() - $this->paid(); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * get Transaction Total |
|
338 | - * |
|
339 | - * @return float |
|
340 | - * @throws EE_Error |
|
341 | - * @throws InvalidArgumentException |
|
342 | - * @throws InvalidDataTypeException |
|
343 | - * @throws InvalidInterfaceException |
|
344 | - * @throws ReflectionException |
|
345 | - */ |
|
346 | - public function total() |
|
347 | - { |
|
348 | - return (float) $this->get('TXN_total'); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * get Total Amount Paid to Date |
|
354 | - * |
|
355 | - * @return float |
|
356 | - * @throws EE_Error |
|
357 | - * @throws InvalidArgumentException |
|
358 | - * @throws InvalidDataTypeException |
|
359 | - * @throws InvalidInterfaceException |
|
360 | - * @throws ReflectionException |
|
361 | - */ |
|
362 | - public function paid() |
|
363 | - { |
|
364 | - return (float) $this->get('TXN_paid'); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * @return mixed|null |
|
370 | - * @throws EE_Error |
|
371 | - * @throws InvalidArgumentException |
|
372 | - * @throws InvalidDataTypeException |
|
373 | - * @throws InvalidInterfaceException |
|
374 | - * @throws ReflectionException |
|
375 | - */ |
|
376 | - public function get_cart_session() |
|
377 | - { |
|
378 | - $session_data = (array) $this->get('TXN_session_data'); |
|
379 | - return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
380 | - ? $session_data['cart'] |
|
381 | - : null; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * get Transaction session data |
|
387 | - * |
|
388 | - * @return array|mixed |
|
389 | - * @throws EE_Error |
|
390 | - * @throws InvalidArgumentException |
|
391 | - * @throws InvalidDataTypeException |
|
392 | - * @throws InvalidInterfaceException |
|
393 | - * @throws ReflectionException |
|
394 | - */ |
|
395 | - public function session_data() |
|
396 | - { |
|
397 | - $session_data = $this->get('TXN_session_data'); |
|
398 | - if (empty($session_data)) { |
|
399 | - $session_data = array( |
|
400 | - 'id' => null, |
|
401 | - 'user_id' => null, |
|
402 | - 'ip_address' => null, |
|
403 | - 'user_agent' => null, |
|
404 | - 'init_access' => null, |
|
405 | - 'last_access' => null, |
|
406 | - 'pages_visited' => array(), |
|
407 | - ); |
|
408 | - } |
|
409 | - return $session_data; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * Set session data within the TXN object |
|
415 | - * |
|
416 | - * @param EE_Session|array $session_data |
|
417 | - * @throws EE_Error |
|
418 | - * @throws InvalidArgumentException |
|
419 | - * @throws InvalidDataTypeException |
|
420 | - * @throws InvalidInterfaceException |
|
421 | - * @throws ReflectionException |
|
422 | - */ |
|
423 | - public function set_txn_session_data($session_data) |
|
424 | - { |
|
425 | - if ($session_data instanceof EE_Session) { |
|
426 | - $this->set('TXN_session_data', $session_data->get_session_data(null, true)); |
|
427 | - } else { |
|
428 | - $this->set('TXN_session_data', $session_data); |
|
429 | - } |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * get Transaction hash salt |
|
435 | - * |
|
436 | - * @return mixed |
|
437 | - * @throws EE_Error |
|
438 | - * @throws InvalidArgumentException |
|
439 | - * @throws InvalidDataTypeException |
|
440 | - * @throws InvalidInterfaceException |
|
441 | - * @throws ReflectionException |
|
442 | - */ |
|
443 | - public function hash_salt_() |
|
444 | - { |
|
445 | - return $this->get('TXN_hash_salt'); |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * Returns the transaction datetime as either: |
|
451 | - * - unix timestamp format ($format = false, $gmt = true) |
|
452 | - * - formatted date string including the UTC (timezone) offset ($format = true ($gmt |
|
453 | - * has no affect with this option)), this also may include a timezone abbreviation if the |
|
454 | - * set timezone in this class differs from what the timezone is on the blog. |
|
455 | - * - formatted date string including the UTC (timezone) offset (default). |
|
456 | - * |
|
457 | - * @param boolean $format - whether to return a unix timestamp (default) or formatted date string |
|
458 | - * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) |
|
459 | - * or no UTC offset applied |
|
460 | - * @return string | int |
|
461 | - * @throws EE_Error |
|
462 | - * @throws InvalidArgumentException |
|
463 | - * @throws InvalidDataTypeException |
|
464 | - * @throws InvalidInterfaceException |
|
465 | - * @throws ReflectionException |
|
466 | - */ |
|
467 | - public function datetime($format = false, $gmt = false) |
|
468 | - { |
|
469 | - if ($format) { |
|
470 | - return $this->get_pretty('TXN_timestamp'); |
|
471 | - } |
|
472 | - if ($gmt) { |
|
473 | - return $this->get_raw('TXN_timestamp'); |
|
474 | - } |
|
475 | - return $this->get('TXN_timestamp'); |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * Gets registrations on this transaction |
|
481 | - * |
|
482 | - * @param array $query_params array of query parameters |
|
483 | - * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
|
484 | - * @return EE_Base_Class[]|EE_Registration[] |
|
485 | - * @throws EE_Error |
|
486 | - * @throws InvalidArgumentException |
|
487 | - * @throws InvalidDataTypeException |
|
488 | - * @throws InvalidInterfaceException |
|
489 | - * @throws ReflectionException |
|
490 | - */ |
|
491 | - public function registrations($query_params = array(), $get_cached = false) |
|
492 | - { |
|
493 | - $query_params = (empty($query_params) || ! is_array($query_params)) |
|
494 | - ? array( |
|
495 | - 'order_by' => array( |
|
496 | - 'Event.EVT_name' => 'ASC', |
|
497 | - 'Attendee.ATT_lname' => 'ASC', |
|
498 | - 'Attendee.ATT_fname' => 'ASC', |
|
499 | - ), |
|
500 | - ) |
|
501 | - : $query_params; |
|
502 | - $query_params = $get_cached ? array() : $query_params; |
|
503 | - return $this->get_many_related('Registration', $query_params); |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
|
509 | - * function for getting attendees and how many registrations they each have for an event) |
|
510 | - * |
|
511 | - * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
512 | - * @throws EE_Error |
|
513 | - * @throws InvalidArgumentException |
|
514 | - * @throws InvalidDataTypeException |
|
515 | - * @throws InvalidInterfaceException |
|
516 | - * @throws ReflectionException |
|
517 | - */ |
|
518 | - public function attendees() |
|
519 | - { |
|
520 | - return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default |
|
526 | - * |
|
527 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
528 | - * @return EE_Base_Class[]|EE_Payment[] |
|
529 | - * @throws EE_Error |
|
530 | - * @throws InvalidArgumentException |
|
531 | - * @throws InvalidDataTypeException |
|
532 | - * @throws InvalidInterfaceException |
|
533 | - * @throws ReflectionException |
|
534 | - */ |
|
535 | - public function payments($query_params = array()) |
|
536 | - { |
|
537 | - return $this->get_many_related('Payment', $query_params); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * gets only approved payments for this transaction |
|
543 | - * |
|
544 | - * @return EE_Base_Class[]|EE_Payment[] |
|
545 | - * @throws EE_Error |
|
546 | - * @throws InvalidArgumentException |
|
547 | - * @throws ReflectionException |
|
548 | - * @throws InvalidDataTypeException |
|
549 | - * @throws InvalidInterfaceException |
|
550 | - */ |
|
551 | - public function approved_payments() |
|
552 | - { |
|
553 | - EE_Registry::instance()->load_model('Payment'); |
|
554 | - return $this->get_many_related( |
|
555 | - 'Payment', |
|
556 | - array( |
|
557 | - array('STS_ID' => EEM_Payment::status_id_approved), |
|
558 | - 'order_by' => array('PAY_timestamp' => 'DESC'), |
|
559 | - ) |
|
560 | - ); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * Gets all payments which have not been approved |
|
566 | - * |
|
567 | - * @return EE_Base_Class[]|EEI_Payment[] |
|
568 | - * @throws EE_Error if a model is misconfigured somehow |
|
569 | - * @throws InvalidArgumentException |
|
570 | - * @throws InvalidDataTypeException |
|
571 | - * @throws InvalidInterfaceException |
|
572 | - * @throws ReflectionException |
|
573 | - */ |
|
574 | - public function pending_payments() |
|
575 | - { |
|
576 | - return $this->get_many_related( |
|
577 | - 'Payment', |
|
578 | - array( |
|
579 | - array( |
|
580 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
581 | - ), |
|
582 | - 'order_by' => array( |
|
583 | - 'PAY_timestamp' => 'DESC', |
|
584 | - ), |
|
585 | - ) |
|
586 | - ); |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - /** |
|
591 | - * echoes $this->pretty_status() |
|
592 | - * |
|
593 | - * @param bool $show_icons |
|
594 | - * @throws EE_Error |
|
595 | - * @throws InvalidArgumentException |
|
596 | - * @throws InvalidDataTypeException |
|
597 | - * @throws InvalidInterfaceException |
|
598 | - * @throws ReflectionException |
|
599 | - */ |
|
600 | - public function e_pretty_status($show_icons = false) |
|
601 | - { |
|
602 | - echo $this->pretty_status($show_icons); |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - /** |
|
607 | - * returns a pretty version of the status, good for displaying to users |
|
608 | - * |
|
609 | - * @param bool $show_icons |
|
610 | - * @return string |
|
611 | - * @throws EE_Error |
|
612 | - * @throws InvalidArgumentException |
|
613 | - * @throws InvalidDataTypeException |
|
614 | - * @throws InvalidInterfaceException |
|
615 | - * @throws ReflectionException |
|
616 | - */ |
|
617 | - public function pretty_status($show_icons = false) |
|
618 | - { |
|
619 | - $status = EEM_Status::instance()->localized_status( |
|
620 | - array($this->status_ID() => __('unknown', 'event_espresso')), |
|
621 | - false, |
|
622 | - 'sentence' |
|
623 | - ); |
|
624 | - $icon = ''; |
|
625 | - switch ($this->status_ID()) { |
|
626 | - case EEM_Transaction::complete_status_code: |
|
627 | - $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
|
628 | - break; |
|
629 | - case EEM_Transaction::incomplete_status_code: |
|
630 | - $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>' |
|
631 | - : ''; |
|
632 | - break; |
|
633 | - case EEM_Transaction::abandoned_status_code: |
|
634 | - $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : ''; |
|
635 | - break; |
|
636 | - case EEM_Transaction::failed_status_code: |
|
637 | - $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
638 | - break; |
|
639 | - case EEM_Transaction::overpaid_status_code: |
|
640 | - $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
|
641 | - break; |
|
642 | - } |
|
643 | - return $icon . $status[ $this->status_ID() ]; |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - /** |
|
648 | - * get Transaction Status |
|
649 | - * |
|
650 | - * @return mixed |
|
651 | - * @throws EE_Error |
|
652 | - * @throws InvalidArgumentException |
|
653 | - * @throws InvalidDataTypeException |
|
654 | - * @throws InvalidInterfaceException |
|
655 | - * @throws ReflectionException |
|
656 | - */ |
|
657 | - public function status_ID() |
|
658 | - { |
|
659 | - return $this->get('STS_ID'); |
|
660 | - } |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * Returns TRUE or FALSE for whether or not this transaction cost any money |
|
665 | - * |
|
666 | - * @return boolean |
|
667 | - * @throws EE_Error |
|
668 | - * @throws InvalidArgumentException |
|
669 | - * @throws InvalidDataTypeException |
|
670 | - * @throws InvalidInterfaceException |
|
671 | - * @throws ReflectionException |
|
672 | - */ |
|
673 | - public function is_free() |
|
674 | - { |
|
675 | - return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * Returns whether this transaction is complete |
|
681 | - * Useful in templates and other logic for deciding if we should ask for another payment... |
|
682 | - * |
|
683 | - * @return boolean |
|
684 | - * @throws EE_Error |
|
685 | - * @throws InvalidArgumentException |
|
686 | - * @throws InvalidDataTypeException |
|
687 | - * @throws InvalidInterfaceException |
|
688 | - * @throws ReflectionException |
|
689 | - */ |
|
690 | - public function is_completed() |
|
691 | - { |
|
692 | - return $this->status_ID() === EEM_Transaction::complete_status_code; |
|
693 | - } |
|
694 | - |
|
695 | - |
|
696 | - /** |
|
697 | - * Returns whether this transaction is incomplete |
|
698 | - * Useful in templates and other logic for deciding if we should ask for another payment... |
|
699 | - * |
|
700 | - * @return boolean |
|
701 | - * @throws EE_Error |
|
702 | - * @throws InvalidArgumentException |
|
703 | - * @throws InvalidDataTypeException |
|
704 | - * @throws InvalidInterfaceException |
|
705 | - * @throws ReflectionException |
|
706 | - */ |
|
707 | - public function is_incomplete() |
|
708 | - { |
|
709 | - return $this->status_ID() === EEM_Transaction::incomplete_status_code; |
|
710 | - } |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * Returns whether this transaction is overpaid |
|
715 | - * Useful in templates and other logic for deciding if monies need to be refunded |
|
716 | - * |
|
717 | - * @return boolean |
|
718 | - * @throws EE_Error |
|
719 | - * @throws InvalidArgumentException |
|
720 | - * @throws InvalidDataTypeException |
|
721 | - * @throws InvalidInterfaceException |
|
722 | - * @throws ReflectionException |
|
723 | - */ |
|
724 | - public function is_overpaid() |
|
725 | - { |
|
726 | - return $this->status_ID() === EEM_Transaction::overpaid_status_code; |
|
727 | - } |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * Returns whether this transaction was abandoned |
|
732 | - * meaning that the transaction/registration process was somehow interrupted and never completed |
|
733 | - * but that contact information exists for at least one registrant |
|
734 | - * |
|
735 | - * @return boolean |
|
736 | - * @throws EE_Error |
|
737 | - * @throws InvalidArgumentException |
|
738 | - * @throws InvalidDataTypeException |
|
739 | - * @throws InvalidInterfaceException |
|
740 | - * @throws ReflectionException |
|
741 | - */ |
|
742 | - public function is_abandoned() |
|
743 | - { |
|
744 | - return $this->status_ID() === EEM_Transaction::abandoned_status_code; |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * Returns whether this transaction failed |
|
750 | - * meaning that the transaction/registration process was somehow interrupted and never completed |
|
751 | - * and that NO contact information exists for any registrants |
|
752 | - * |
|
753 | - * @return boolean |
|
754 | - * @throws EE_Error |
|
755 | - * @throws InvalidArgumentException |
|
756 | - * @throws InvalidDataTypeException |
|
757 | - * @throws InvalidInterfaceException |
|
758 | - * @throws ReflectionException |
|
759 | - */ |
|
760 | - public function failed() |
|
761 | - { |
|
762 | - return $this->status_ID() === EEM_Transaction::failed_status_code; |
|
763 | - } |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * This returns the url for the invoice of this transaction |
|
768 | - * |
|
769 | - * @param string $type 'html' or 'pdf' (default is pdf) |
|
770 | - * @return string |
|
771 | - * @throws EE_Error |
|
772 | - * @throws InvalidArgumentException |
|
773 | - * @throws InvalidDataTypeException |
|
774 | - * @throws InvalidInterfaceException |
|
775 | - * @throws ReflectionException |
|
776 | - */ |
|
777 | - public function invoice_url($type = 'html') |
|
778 | - { |
|
779 | - $REG = $this->primary_registration(); |
|
780 | - if (! $REG instanceof EE_Registration) { |
|
781 | - return ''; |
|
782 | - } |
|
783 | - return $REG->invoice_url($type); |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - /** |
|
788 | - * Gets the primary registration only |
|
789 | - * |
|
790 | - * @return EE_Base_Class|EE_Registration |
|
791 | - * @throws EE_Error |
|
792 | - * @throws InvalidArgumentException |
|
793 | - * @throws InvalidDataTypeException |
|
794 | - * @throws InvalidInterfaceException |
|
795 | - * @throws ReflectionException |
|
796 | - */ |
|
797 | - public function primary_registration() |
|
798 | - { |
|
799 | - $registrations = (array) $this->get_many_related( |
|
800 | - 'Registration', |
|
801 | - array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
802 | - ); |
|
803 | - foreach ($registrations as $registration) { |
|
804 | - // valid registration that is NOT cancelled or declined ? |
|
805 | - if ($registration instanceof EE_Registration |
|
806 | - && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
807 | - ) { |
|
808 | - return $registration; |
|
809 | - } |
|
810 | - } |
|
811 | - // nothing valid found, so just return first thing from array of results |
|
812 | - return reset($registrations); |
|
813 | - } |
|
814 | - |
|
815 | - |
|
816 | - /** |
|
817 | - * Gets the URL for viewing the receipt |
|
818 | - * |
|
819 | - * @param string $type 'pdf' or 'html' (default is 'html') |
|
820 | - * @return string |
|
821 | - * @throws EE_Error |
|
822 | - * @throws InvalidArgumentException |
|
823 | - * @throws InvalidDataTypeException |
|
824 | - * @throws InvalidInterfaceException |
|
825 | - * @throws ReflectionException |
|
826 | - */ |
|
827 | - public function receipt_url($type = 'html') |
|
828 | - { |
|
829 | - $REG = $this->primary_registration(); |
|
830 | - if (! $REG instanceof EE_Registration) { |
|
831 | - return ''; |
|
832 | - } |
|
833 | - return $REG->receipt_url($type); |
|
834 | - } |
|
835 | - |
|
836 | - |
|
837 | - /** |
|
838 | - * Gets the URL of the thank you page with this registration REG_url_link added as |
|
839 | - * a query parameter |
|
840 | - * |
|
841 | - * @return string |
|
842 | - * @throws EE_Error |
|
843 | - * @throws InvalidArgumentException |
|
844 | - * @throws InvalidDataTypeException |
|
845 | - * @throws InvalidInterfaceException |
|
846 | - * @throws ReflectionException |
|
847 | - */ |
|
848 | - public function payment_overview_url() |
|
849 | - { |
|
850 | - $primary_registration = $this->primary_registration(); |
|
851 | - return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false; |
|
852 | - } |
|
853 | - |
|
854 | - |
|
855 | - /** |
|
856 | - * @return string |
|
857 | - * @throws EE_Error |
|
858 | - * @throws InvalidArgumentException |
|
859 | - * @throws InvalidDataTypeException |
|
860 | - * @throws InvalidInterfaceException |
|
861 | - * @throws ReflectionException |
|
862 | - */ |
|
863 | - public function gateway_response_on_transaction() |
|
864 | - { |
|
865 | - $payment = $this->get_first_related('Payment'); |
|
866 | - return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
|
867 | - } |
|
868 | - |
|
869 | - |
|
870 | - /** |
|
871 | - * Get the status object of this object |
|
872 | - * |
|
873 | - * @return EE_Base_Class|EE_Status |
|
874 | - * @throws EE_Error |
|
875 | - * @throws InvalidArgumentException |
|
876 | - * @throws InvalidDataTypeException |
|
877 | - * @throws InvalidInterfaceException |
|
878 | - * @throws ReflectionException |
|
879 | - */ |
|
880 | - public function status_obj() |
|
881 | - { |
|
882 | - return $this->get_first_related('Status'); |
|
883 | - } |
|
884 | - |
|
885 | - |
|
886 | - /** |
|
887 | - * Gets all the extra meta info on this payment |
|
888 | - * |
|
889 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
890 | - * @return EE_Base_Class[]|EE_Extra_Meta |
|
891 | - * @throws EE_Error |
|
892 | - * @throws InvalidArgumentException |
|
893 | - * @throws InvalidDataTypeException |
|
894 | - * @throws InvalidInterfaceException |
|
895 | - * @throws ReflectionException |
|
896 | - */ |
|
897 | - public function extra_meta($query_params = array()) |
|
898 | - { |
|
899 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
900 | - } |
|
901 | - |
|
902 | - |
|
903 | - /** |
|
904 | - * Wrapper for _add_relation_to |
|
905 | - * |
|
906 | - * @param EE_Registration $registration |
|
907 | - * @return EE_Base_Class the relation was added to |
|
908 | - * @throws EE_Error |
|
909 | - * @throws InvalidArgumentException |
|
910 | - * @throws InvalidDataTypeException |
|
911 | - * @throws InvalidInterfaceException |
|
912 | - * @throws ReflectionException |
|
913 | - */ |
|
914 | - public function add_registration(EE_Registration $registration) |
|
915 | - { |
|
916 | - return $this->_add_relation_to($registration, 'Registration'); |
|
917 | - } |
|
918 | - |
|
919 | - |
|
920 | - /** |
|
921 | - * Removes the given registration from being related (even before saving this transaction). |
|
922 | - * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations |
|
923 | - * |
|
924 | - * @param int $registration_or_id |
|
925 | - * @return EE_Base_Class that was removed from being related |
|
926 | - * @throws EE_Error |
|
927 | - * @throws InvalidArgumentException |
|
928 | - * @throws InvalidDataTypeException |
|
929 | - * @throws InvalidInterfaceException |
|
930 | - * @throws ReflectionException |
|
931 | - */ |
|
932 | - public function remove_registration_with_id($registration_or_id) |
|
933 | - { |
|
934 | - return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
935 | - } |
|
936 | - |
|
937 | - |
|
938 | - /** |
|
939 | - * Gets all the line items which are for ACTUAL items |
|
940 | - * |
|
941 | - * @return EE_Line_Item[] |
|
942 | - * @throws EE_Error |
|
943 | - * @throws InvalidArgumentException |
|
944 | - * @throws InvalidDataTypeException |
|
945 | - * @throws InvalidInterfaceException |
|
946 | - * @throws ReflectionException |
|
947 | - */ |
|
948 | - public function items_purchased() |
|
949 | - { |
|
950 | - return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
951 | - } |
|
952 | - |
|
953 | - |
|
954 | - /** |
|
955 | - * Wrapper for _add_relation_to |
|
956 | - * |
|
957 | - * @param EE_Line_Item $line_item |
|
958 | - * @return EE_Base_Class the relation was added to |
|
959 | - * @throws EE_Error |
|
960 | - * @throws InvalidArgumentException |
|
961 | - * @throws InvalidDataTypeException |
|
962 | - * @throws InvalidInterfaceException |
|
963 | - * @throws ReflectionException |
|
964 | - */ |
|
965 | - public function add_line_item(EE_Line_Item $line_item) |
|
966 | - { |
|
967 | - return $this->_add_relation_to($line_item, 'Line_Item'); |
|
968 | - } |
|
969 | - |
|
970 | - |
|
971 | - /** |
|
972 | - * Gets ALL the line items related to this transaction (unstructured) |
|
973 | - * |
|
974 | - * @param array $query_params |
|
975 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
976 | - * @throws EE_Error |
|
977 | - * @throws InvalidArgumentException |
|
978 | - * @throws InvalidDataTypeException |
|
979 | - * @throws InvalidInterfaceException |
|
980 | - * @throws ReflectionException |
|
981 | - */ |
|
982 | - public function line_items($query_params = array()) |
|
983 | - { |
|
984 | - return $this->get_many_related('Line_Item', $query_params); |
|
985 | - } |
|
986 | - |
|
987 | - |
|
988 | - /** |
|
989 | - * Gets all the line items which are taxes on the total |
|
990 | - * |
|
991 | - * @return EE_Line_Item[] |
|
992 | - * @throws EE_Error |
|
993 | - * @throws InvalidArgumentException |
|
994 | - * @throws InvalidDataTypeException |
|
995 | - * @throws InvalidInterfaceException |
|
996 | - * @throws ReflectionException |
|
997 | - */ |
|
998 | - public function tax_items() |
|
999 | - { |
|
1000 | - return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
1001 | - } |
|
1002 | - |
|
1003 | - |
|
1004 | - /** |
|
1005 | - * Gets the total line item (which is a parent of all other related line items, |
|
1006 | - * meaning it takes them all into account on its total) |
|
1007 | - * |
|
1008 | - * @param bool $create_if_not_found |
|
1009 | - * @return \EE_Line_Item |
|
1010 | - * @throws EE_Error |
|
1011 | - * @throws InvalidArgumentException |
|
1012 | - * @throws InvalidDataTypeException |
|
1013 | - * @throws InvalidInterfaceException |
|
1014 | - * @throws ReflectionException |
|
1015 | - */ |
|
1016 | - public function total_line_item($create_if_not_found = true) |
|
1017 | - { |
|
1018 | - $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
1019 | - if (! $item && $create_if_not_found) { |
|
1020 | - $item = EEH_Line_Item::create_total_line_item($this); |
|
1021 | - } |
|
1022 | - return $item; |
|
1023 | - } |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * Returns the total amount of tax on this transaction |
|
1028 | - * (assumes there's only one tax subtotal line item) |
|
1029 | - * |
|
1030 | - * @return float |
|
1031 | - * @throws EE_Error |
|
1032 | - * @throws InvalidArgumentException |
|
1033 | - * @throws InvalidDataTypeException |
|
1034 | - * @throws InvalidInterfaceException |
|
1035 | - * @throws ReflectionException |
|
1036 | - */ |
|
1037 | - public function tax_total() |
|
1038 | - { |
|
1039 | - $tax_line_item = $this->tax_total_line_item(); |
|
1040 | - if ($tax_line_item) { |
|
1041 | - return (float) $tax_line_item->total(); |
|
1042 | - } |
|
1043 | - return (float) 0; |
|
1044 | - } |
|
1045 | - |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * Gets the tax subtotal line item (assumes there's only one) |
|
1049 | - * |
|
1050 | - * @return EE_Line_Item |
|
1051 | - * @throws EE_Error |
|
1052 | - * @throws InvalidArgumentException |
|
1053 | - * @throws InvalidDataTypeException |
|
1054 | - * @throws InvalidInterfaceException |
|
1055 | - * @throws ReflectionException |
|
1056 | - */ |
|
1057 | - public function tax_total_line_item() |
|
1058 | - { |
|
1059 | - return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
1060 | - } |
|
1061 | - |
|
1062 | - |
|
1063 | - /** |
|
1064 | - * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
|
1065 | - * |
|
1066 | - * @return EE_Form_Section_Proper |
|
1067 | - * @throws EE_Error |
|
1068 | - * @throws InvalidArgumentException |
|
1069 | - * @throws InvalidDataTypeException |
|
1070 | - * @throws InvalidInterfaceException |
|
1071 | - * @throws ReflectionException |
|
1072 | - */ |
|
1073 | - public function billing_info() |
|
1074 | - { |
|
1075 | - $payment_method = $this->payment_method(); |
|
1076 | - if (! $payment_method) { |
|
1077 | - EE_Error::add_error( |
|
1078 | - __( |
|
1079 | - 'Could not find billing info for transaction because no gateway has been used for it yet', |
|
1080 | - 'event_espresso' |
|
1081 | - ), |
|
1082 | - __FILE__, |
|
1083 | - __FUNCTION__, |
|
1084 | - __LINE__ |
|
1085 | - ); |
|
1086 | - return null; |
|
1087 | - } |
|
1088 | - $primary_reg = $this->primary_registration(); |
|
1089 | - if (! $primary_reg) { |
|
1090 | - EE_Error::add_error( |
|
1091 | - __( |
|
1092 | - 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
|
1093 | - 'event_espresso' |
|
1094 | - ), |
|
1095 | - __FILE__, |
|
1096 | - __FUNCTION__, |
|
1097 | - __LINE__ |
|
1098 | - ); |
|
1099 | - return null; |
|
1100 | - } |
|
1101 | - $attendee = $primary_reg->attendee(); |
|
1102 | - if (! $attendee) { |
|
1103 | - EE_Error::add_error( |
|
1104 | - __( |
|
1105 | - 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
|
1106 | - 'event_espresso' |
|
1107 | - ), |
|
1108 | - __FILE__, |
|
1109 | - __FUNCTION__, |
|
1110 | - __LINE__ |
|
1111 | - ); |
|
1112 | - return null; |
|
1113 | - } |
|
1114 | - return $attendee->billing_info_for_payment_method($payment_method); |
|
1115 | - } |
|
1116 | - |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * Gets PMD_ID |
|
1120 | - * |
|
1121 | - * @return int |
|
1122 | - * @throws EE_Error |
|
1123 | - * @throws InvalidArgumentException |
|
1124 | - * @throws InvalidDataTypeException |
|
1125 | - * @throws InvalidInterfaceException |
|
1126 | - * @throws ReflectionException |
|
1127 | - */ |
|
1128 | - public function payment_method_ID() |
|
1129 | - { |
|
1130 | - return $this->get('PMD_ID'); |
|
1131 | - } |
|
1132 | - |
|
1133 | - |
|
1134 | - /** |
|
1135 | - * Sets PMD_ID |
|
1136 | - * |
|
1137 | - * @param int $PMD_ID |
|
1138 | - * @throws EE_Error |
|
1139 | - * @throws InvalidArgumentException |
|
1140 | - * @throws InvalidDataTypeException |
|
1141 | - * @throws InvalidInterfaceException |
|
1142 | - * @throws ReflectionException |
|
1143 | - */ |
|
1144 | - public function set_payment_method_ID($PMD_ID) |
|
1145 | - { |
|
1146 | - $this->set('PMD_ID', $PMD_ID); |
|
1147 | - } |
|
1148 | - |
|
1149 | - |
|
1150 | - /** |
|
1151 | - * Gets the last-used payment method on this transaction |
|
1152 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
1153 | - * offline ones, dont' create payments) |
|
1154 | - * |
|
1155 | - * @return EE_Payment_Method |
|
1156 | - * @throws EE_Error |
|
1157 | - * @throws InvalidArgumentException |
|
1158 | - * @throws InvalidDataTypeException |
|
1159 | - * @throws InvalidInterfaceException |
|
1160 | - * @throws ReflectionException |
|
1161 | - */ |
|
1162 | - public function payment_method() |
|
1163 | - { |
|
1164 | - $pm = $this->get_first_related('Payment_Method'); |
|
1165 | - if ($pm instanceof EE_Payment_Method) { |
|
1166 | - return $pm; |
|
1167 | - } |
|
1168 | - $last_payment = $this->last_payment(); |
|
1169 | - if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
1170 | - return $last_payment->payment_method(); |
|
1171 | - } |
|
1172 | - return null; |
|
1173 | - } |
|
1174 | - |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * Gets the last payment made |
|
1178 | - * |
|
1179 | - * @return EE_Base_Class|EE_Payment |
|
1180 | - * @throws EE_Error |
|
1181 | - * @throws InvalidArgumentException |
|
1182 | - * @throws InvalidDataTypeException |
|
1183 | - * @throws InvalidInterfaceException |
|
1184 | - * @throws ReflectionException |
|
1185 | - */ |
|
1186 | - public function last_payment() |
|
1187 | - { |
|
1188 | - return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
1189 | - } |
|
1190 | - |
|
1191 | - |
|
1192 | - /** |
|
1193 | - * Gets all the line items which are unrelated to tickets on this transaction |
|
1194 | - * |
|
1195 | - * @return EE_Line_Item[] |
|
1196 | - * @throws EE_Error |
|
1197 | - * @throws InvalidArgumentException |
|
1198 | - * @throws InvalidDataTypeException |
|
1199 | - * @throws InvalidInterfaceException |
|
1200 | - * @throws ReflectionException |
|
1201 | - */ |
|
1202 | - public function non_ticket_line_items() |
|
1203 | - { |
|
1204 | - return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
1205 | - } |
|
1206 | - |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * possibly toggles TXN status |
|
1210 | - * |
|
1211 | - * @param boolean $update whether to save the TXN |
|
1212 | - * @return bool whether the TXN was saved |
|
1213 | - * @throws EE_Error |
|
1214 | - * @throws InvalidArgumentException |
|
1215 | - * @throws InvalidDataTypeException |
|
1216 | - * @throws InvalidInterfaceException |
|
1217 | - * @throws ReflectionException |
|
1218 | - * @throws RuntimeException |
|
1219 | - */ |
|
1220 | - public function update_status_based_on_total_paid($update = true) |
|
1221 | - { |
|
1222 | - // set transaction status based on comparison of TXN_paid vs TXN_total |
|
1223 | - if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) { |
|
1224 | - $new_txn_status = EEM_Transaction::overpaid_status_code; |
|
1225 | - } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) { |
|
1226 | - $new_txn_status = EEM_Transaction::complete_status_code; |
|
1227 | - } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) { |
|
1228 | - $new_txn_status = EEM_Transaction::incomplete_status_code; |
|
1229 | - } else { |
|
1230 | - throw new RuntimeException( |
|
1231 | - __('The total paid calculation for this transaction is inaccurate.', 'event_espresso') |
|
1232 | - ); |
|
1233 | - } |
|
1234 | - if ($new_txn_status !== $this->status_ID()) { |
|
1235 | - $this->set_status($new_txn_status); |
|
1236 | - if ($update) { |
|
1237 | - return $this->save() ? true : false; |
|
1238 | - } |
|
1239 | - } |
|
1240 | - return false; |
|
1241 | - } |
|
1242 | - |
|
1243 | - |
|
1244 | - /** |
|
1245 | - * Updates the transaction's status and total_paid based on all the payments |
|
1246 | - * that apply to it |
|
1247 | - * |
|
1248 | - * @deprecated |
|
1249 | - * @return array|bool |
|
1250 | - * @throws EE_Error |
|
1251 | - * @throws InvalidArgumentException |
|
1252 | - * @throws ReflectionException |
|
1253 | - * @throws InvalidDataTypeException |
|
1254 | - * @throws InvalidInterfaceException |
|
1255 | - */ |
|
1256 | - public function update_based_on_payments() |
|
1257 | - { |
|
1258 | - EE_Error::doing_it_wrong( |
|
1259 | - __CLASS__ . '::' . __FUNCTION__, |
|
1260 | - sprintf( |
|
1261 | - __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
1262 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
1263 | - ), |
|
1264 | - '4.6.0' |
|
1265 | - ); |
|
1266 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
1267 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
1268 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
1269 | - } |
|
1270 | - |
|
1271 | - |
|
1272 | - /** |
|
1273 | - * @return string |
|
1274 | - */ |
|
1275 | - public function old_txn_status() |
|
1276 | - { |
|
1277 | - return $this->_old_txn_status; |
|
1278 | - } |
|
1279 | - |
|
1280 | - |
|
1281 | - /** |
|
1282 | - * @param string $old_txn_status |
|
1283 | - */ |
|
1284 | - public function set_old_txn_status($old_txn_status) |
|
1285 | - { |
|
1286 | - // only set the first time |
|
1287 | - if ($this->_old_txn_status === null) { |
|
1288 | - $this->_old_txn_status = $old_txn_status; |
|
1289 | - } |
|
1290 | - } |
|
1291 | - |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * reg_status_updated |
|
1295 | - * |
|
1296 | - * @return bool |
|
1297 | - * @throws EE_Error |
|
1298 | - * @throws InvalidArgumentException |
|
1299 | - * @throws InvalidDataTypeException |
|
1300 | - * @throws InvalidInterfaceException |
|
1301 | - * @throws ReflectionException |
|
1302 | - */ |
|
1303 | - public function txn_status_updated() |
|
1304 | - { |
|
1305 | - return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null; |
|
1306 | - } |
|
1307 | - |
|
1308 | - |
|
1309 | - /** |
|
1310 | - * _reg_steps_completed |
|
1311 | - * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed, |
|
1312 | - * if a $reg_step_slug is provided, then this step will be skipped when testing for completion |
|
1313 | - * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion |
|
1314 | - * |
|
1315 | - * @param string $reg_step_slug |
|
1316 | - * @param bool $check_all |
|
1317 | - * @return bool|int |
|
1318 | - * @throws EE_Error |
|
1319 | - * @throws InvalidArgumentException |
|
1320 | - * @throws InvalidDataTypeException |
|
1321 | - * @throws InvalidInterfaceException |
|
1322 | - * @throws ReflectionException |
|
1323 | - */ |
|
1324 | - private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
|
1325 | - { |
|
1326 | - $reg_steps = $this->reg_steps(); |
|
1327 | - if (! is_array($reg_steps) || empty($reg_steps)) { |
|
1328 | - return false; |
|
1329 | - } |
|
1330 | - // loop thru reg steps array) |
|
1331 | - foreach ($reg_steps as $slug => $reg_step_completed) { |
|
1332 | - // if NOT checking ALL steps (only checking one step) |
|
1333 | - if (! $check_all) { |
|
1334 | - // and this is the one |
|
1335 | - if ($slug === $reg_step_slug) { |
|
1336 | - return $reg_step_completed; |
|
1337 | - } |
|
1338 | - // skip to next reg step in loop |
|
1339 | - continue; |
|
1340 | - } |
|
1341 | - // $check_all must be true, else we would never have gotten to this point |
|
1342 | - if ($slug === $reg_step_slug) { |
|
1343 | - // if we reach this point, then we are testing either: |
|
1344 | - // all_reg_steps_completed_except() or |
|
1345 | - // all_reg_steps_completed_except_final_step(), |
|
1346 | - // and since this is the reg step EXCEPTION being tested |
|
1347 | - // we want to return true (yes true) if this reg step is NOT completed |
|
1348 | - // ie: "is everything completed except the final step?" |
|
1349 | - // "that is correct... the final step is not completed, but all others are." |
|
1350 | - return $reg_step_completed !== true; |
|
1351 | - } |
|
1352 | - if ($reg_step_completed !== true) { |
|
1353 | - // if any reg step is NOT completed, then ALL steps are not completed |
|
1354 | - return false; |
|
1355 | - } |
|
1356 | - } |
|
1357 | - return true; |
|
1358 | - } |
|
1359 | - |
|
1360 | - |
|
1361 | - /** |
|
1362 | - * all_reg_steps_completed |
|
1363 | - * returns: |
|
1364 | - * true if ALL reg steps have been marked as completed |
|
1365 | - * or false if any step is not completed |
|
1366 | - * |
|
1367 | - * @return bool |
|
1368 | - * @throws EE_Error |
|
1369 | - * @throws InvalidArgumentException |
|
1370 | - * @throws InvalidDataTypeException |
|
1371 | - * @throws InvalidInterfaceException |
|
1372 | - * @throws ReflectionException |
|
1373 | - */ |
|
1374 | - public function all_reg_steps_completed() |
|
1375 | - { |
|
1376 | - return $this->_reg_steps_completed(); |
|
1377 | - } |
|
1378 | - |
|
1379 | - |
|
1380 | - /** |
|
1381 | - * all_reg_steps_completed_except |
|
1382 | - * returns: |
|
1383 | - * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
1384 | - * or false if any other step is not completed |
|
1385 | - * or false if ALL steps are completed including the exception you are testing !!! |
|
1386 | - * |
|
1387 | - * @param string $exception |
|
1388 | - * @return bool |
|
1389 | - * @throws EE_Error |
|
1390 | - * @throws InvalidArgumentException |
|
1391 | - * @throws InvalidDataTypeException |
|
1392 | - * @throws InvalidInterfaceException |
|
1393 | - * @throws ReflectionException |
|
1394 | - */ |
|
1395 | - public function all_reg_steps_completed_except($exception = '') |
|
1396 | - { |
|
1397 | - return $this->_reg_steps_completed($exception); |
|
1398 | - } |
|
1399 | - |
|
1400 | - |
|
1401 | - /** |
|
1402 | - * all_reg_steps_completed_except |
|
1403 | - * returns: |
|
1404 | - * true if ALL reg steps, except the final step, have been marked as completed |
|
1405 | - * or false if any step is not completed |
|
1406 | - * or false if ALL steps are completed including the final step !!! |
|
1407 | - * |
|
1408 | - * @return bool |
|
1409 | - * @throws EE_Error |
|
1410 | - * @throws InvalidArgumentException |
|
1411 | - * @throws InvalidDataTypeException |
|
1412 | - * @throws InvalidInterfaceException |
|
1413 | - * @throws ReflectionException |
|
1414 | - */ |
|
1415 | - public function all_reg_steps_completed_except_final_step() |
|
1416 | - { |
|
1417 | - return $this->_reg_steps_completed('finalize_registration'); |
|
1418 | - } |
|
1419 | - |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * reg_step_completed |
|
1423 | - * returns: |
|
1424 | - * true if a specific reg step has been marked as completed |
|
1425 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
1426 | - * or false if it has not yet been initialized |
|
1427 | - * |
|
1428 | - * @param string $reg_step_slug |
|
1429 | - * @return bool|int |
|
1430 | - * @throws EE_Error |
|
1431 | - * @throws InvalidArgumentException |
|
1432 | - * @throws InvalidDataTypeException |
|
1433 | - * @throws InvalidInterfaceException |
|
1434 | - * @throws ReflectionException |
|
1435 | - */ |
|
1436 | - public function reg_step_completed($reg_step_slug) |
|
1437 | - { |
|
1438 | - return $this->_reg_steps_completed($reg_step_slug, false); |
|
1439 | - } |
|
1440 | - |
|
1441 | - |
|
1442 | - /** |
|
1443 | - * completed_final_reg_step |
|
1444 | - * returns: |
|
1445 | - * true if the finalize_registration reg step has been marked as completed |
|
1446 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
1447 | - * or false if it has not yet been initialized |
|
1448 | - * |
|
1449 | - * @return bool|int |
|
1450 | - * @throws EE_Error |
|
1451 | - * @throws InvalidArgumentException |
|
1452 | - * @throws InvalidDataTypeException |
|
1453 | - * @throws InvalidInterfaceException |
|
1454 | - * @throws ReflectionException |
|
1455 | - */ |
|
1456 | - public function final_reg_step_completed() |
|
1457 | - { |
|
1458 | - return $this->_reg_steps_completed('finalize_registration', false); |
|
1459 | - } |
|
1460 | - |
|
1461 | - |
|
1462 | - /** |
|
1463 | - * set_reg_step_initiated |
|
1464 | - * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
1465 | - * |
|
1466 | - * @param string $reg_step_slug |
|
1467 | - * @return boolean |
|
1468 | - * @throws EE_Error |
|
1469 | - * @throws InvalidArgumentException |
|
1470 | - * @throws InvalidDataTypeException |
|
1471 | - * @throws InvalidInterfaceException |
|
1472 | - * @throws ReflectionException |
|
1473 | - */ |
|
1474 | - public function set_reg_step_initiated($reg_step_slug) |
|
1475 | - { |
|
1476 | - return $this->_set_reg_step_completed_status($reg_step_slug, time()); |
|
1477 | - } |
|
1478 | - |
|
1479 | - |
|
1480 | - /** |
|
1481 | - * set_reg_step_completed |
|
1482 | - * given a valid TXN_reg_step, this sets the step as completed |
|
1483 | - * |
|
1484 | - * @param string $reg_step_slug |
|
1485 | - * @return boolean |
|
1486 | - * @throws EE_Error |
|
1487 | - * @throws InvalidArgumentException |
|
1488 | - * @throws InvalidDataTypeException |
|
1489 | - * @throws InvalidInterfaceException |
|
1490 | - * @throws ReflectionException |
|
1491 | - */ |
|
1492 | - public function set_reg_step_completed($reg_step_slug) |
|
1493 | - { |
|
1494 | - return $this->_set_reg_step_completed_status($reg_step_slug, true); |
|
1495 | - } |
|
1496 | - |
|
1497 | - |
|
1498 | - /** |
|
1499 | - * set_reg_step_completed |
|
1500 | - * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
1501 | - * |
|
1502 | - * @param string $reg_step_slug |
|
1503 | - * @return boolean |
|
1504 | - * @throws EE_Error |
|
1505 | - * @throws InvalidArgumentException |
|
1506 | - * @throws InvalidDataTypeException |
|
1507 | - * @throws InvalidInterfaceException |
|
1508 | - * @throws ReflectionException |
|
1509 | - */ |
|
1510 | - public function set_reg_step_not_completed($reg_step_slug) |
|
1511 | - { |
|
1512 | - return $this->_set_reg_step_completed_status($reg_step_slug, false); |
|
1513 | - } |
|
1514 | - |
|
1515 | - |
|
1516 | - /** |
|
1517 | - * set_reg_step_completed |
|
1518 | - * given a valid reg step slug, this sets the TXN_reg_step completed status which is either: |
|
1519 | - * |
|
1520 | - * @param string $reg_step_slug |
|
1521 | - * @param boolean|int $status |
|
1522 | - * @return boolean |
|
1523 | - * @throws EE_Error |
|
1524 | - * @throws InvalidArgumentException |
|
1525 | - * @throws InvalidDataTypeException |
|
1526 | - * @throws InvalidInterfaceException |
|
1527 | - * @throws ReflectionException |
|
1528 | - */ |
|
1529 | - private function _set_reg_step_completed_status($reg_step_slug, $status) |
|
1530 | - { |
|
1531 | - // validate status |
|
1532 | - $status = is_bool($status) || is_int($status) ? $status : false; |
|
1533 | - // get reg steps array |
|
1534 | - $txn_reg_steps = $this->reg_steps(); |
|
1535 | - // if reg step does NOT exist |
|
1536 | - if (! isset($txn_reg_steps[ $reg_step_slug ])) { |
|
1537 | - return false; |
|
1538 | - } |
|
1539 | - // if we're trying to complete a step that is already completed |
|
1540 | - if ($txn_reg_steps[ $reg_step_slug ] === true) { |
|
1541 | - return true; |
|
1542 | - } |
|
1543 | - // if we're trying to complete a step that hasn't even started |
|
1544 | - if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) { |
|
1545 | - return false; |
|
1546 | - } |
|
1547 | - // if current status value matches the incoming value (no change) |
|
1548 | - // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
|
1549 | - if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) { |
|
1550 | - // this will happen in cases where multiple AJAX requests occur during the same step |
|
1551 | - return true; |
|
1552 | - } |
|
1553 | - // if we're trying to set a start time, but it has already been set... |
|
1554 | - if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) { |
|
1555 | - // skip the update below, but don't return FALSE so that errors won't be displayed |
|
1556 | - return true; |
|
1557 | - } |
|
1558 | - // update completed status |
|
1559 | - $txn_reg_steps[ $reg_step_slug ] = $status; |
|
1560 | - $this->set_reg_steps($txn_reg_steps); |
|
1561 | - $this->save(); |
|
1562 | - return true; |
|
1563 | - } |
|
1564 | - |
|
1565 | - |
|
1566 | - /** |
|
1567 | - * remove_reg_step |
|
1568 | - * given a valid TXN_reg_step slug, this will remove (unset) |
|
1569 | - * the reg step from the TXN reg step array |
|
1570 | - * |
|
1571 | - * @param string $reg_step_slug |
|
1572 | - * @return void |
|
1573 | - * @throws EE_Error |
|
1574 | - * @throws InvalidArgumentException |
|
1575 | - * @throws InvalidDataTypeException |
|
1576 | - * @throws InvalidInterfaceException |
|
1577 | - * @throws ReflectionException |
|
1578 | - */ |
|
1579 | - public function remove_reg_step($reg_step_slug) |
|
1580 | - { |
|
1581 | - // get reg steps array |
|
1582 | - $txn_reg_steps = $this->reg_steps(); |
|
1583 | - unset($txn_reg_steps[ $reg_step_slug ]); |
|
1584 | - $this->set_reg_steps($txn_reg_steps); |
|
1585 | - } |
|
1586 | - |
|
1587 | - |
|
1588 | - /** |
|
1589 | - * toggle_failed_transaction_status |
|
1590 | - * upgrades a TXNs status from failed to abandoned, |
|
1591 | - * meaning that contact information has been captured for at least one registrant |
|
1592 | - * |
|
1593 | - * @param bool $save |
|
1594 | - * @return bool |
|
1595 | - * @throws EE_Error |
|
1596 | - * @throws InvalidArgumentException |
|
1597 | - * @throws InvalidDataTypeException |
|
1598 | - * @throws InvalidInterfaceException |
|
1599 | - * @throws ReflectionException |
|
1600 | - */ |
|
1601 | - public function toggle_failed_transaction_status($save = true) |
|
1602 | - { |
|
1603 | - // if TXN status is still set as "failed"... |
|
1604 | - if ($this->status_ID() === EEM_Transaction::failed_status_code) { |
|
1605 | - $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1606 | - if ($save) { |
|
1607 | - $this->save(); |
|
1608 | - } |
|
1609 | - return true; |
|
1610 | - } |
|
1611 | - return false; |
|
1612 | - } |
|
1613 | - |
|
1614 | - |
|
1615 | - /** |
|
1616 | - * toggle_abandoned_transaction_status |
|
1617 | - * upgrades a TXNs status from failed or abandoned to incomplete |
|
1618 | - * |
|
1619 | - * @return bool |
|
1620 | - * @throws EE_Error |
|
1621 | - * @throws InvalidArgumentException |
|
1622 | - * @throws InvalidDataTypeException |
|
1623 | - * @throws InvalidInterfaceException |
|
1624 | - * @throws ReflectionException |
|
1625 | - */ |
|
1626 | - public function toggle_abandoned_transaction_status() |
|
1627 | - { |
|
1628 | - // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"... |
|
1629 | - $txn_status = $this->status_ID(); |
|
1630 | - if ($txn_status === EEM_Transaction::failed_status_code |
|
1631 | - || $txn_status === EEM_Transaction::abandoned_status_code |
|
1632 | - ) { |
|
1633 | - // if a contact record for the primary registrant has been created |
|
1634 | - if ($this->primary_registration() instanceof EE_Registration |
|
1635 | - && $this->primary_registration()->attendee() instanceof EE_Attendee |
|
1636 | - ) { |
|
1637 | - $this->set_status(EEM_Transaction::incomplete_status_code); |
|
1638 | - } else { |
|
1639 | - // no contact record? yer abandoned! |
|
1640 | - $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1641 | - } |
|
1642 | - return true; |
|
1643 | - } |
|
1644 | - return false; |
|
1645 | - } |
|
1646 | - |
|
1647 | - |
|
1648 | - /** |
|
1649 | - * checks if an Abandoned TXN has any related payments, and if so, |
|
1650 | - * updates the TXN status based on the amount paid |
|
1651 | - * |
|
1652 | - * @throws EE_Error |
|
1653 | - * @throws InvalidDataTypeException |
|
1654 | - * @throws InvalidInterfaceException |
|
1655 | - * @throws InvalidArgumentException |
|
1656 | - * @throws RuntimeException |
|
1657 | - * @throws ReflectionException |
|
1658 | - */ |
|
1659 | - public function verify_abandoned_transaction_status() |
|
1660 | - { |
|
1661 | - if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) { |
|
1662 | - return; |
|
1663 | - } |
|
1664 | - $payments = $this->get_many_related('Payment'); |
|
1665 | - if (! empty($payments)) { |
|
1666 | - foreach ($payments as $payment) { |
|
1667 | - if ($payment instanceof EE_Payment) { |
|
1668 | - // kk this TXN should NOT be abandoned |
|
1669 | - $this->update_status_based_on_total_paid(); |
|
1670 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1671 | - EE_Error::add_attention( |
|
1672 | - sprintf( |
|
1673 | - esc_html__( |
|
1674 | - 'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.', |
|
1675 | - 'event_espresso' |
|
1676 | - ), |
|
1677 | - $this->ID(), |
|
1678 | - $this->pretty_status() |
|
1679 | - ) |
|
1680 | - ); |
|
1681 | - } |
|
1682 | - // get final reg step status |
|
1683 | - $finalized = $this->final_reg_step_completed(); |
|
1684 | - // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
1685 | - // but has not yet been fully completed (TRUE) |
|
1686 | - if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
1687 | - $this->set_reg_step_completed('finalize_registration'); |
|
1688 | - $this->save(); |
|
1689 | - } |
|
1690 | - } |
|
1691 | - } |
|
1692 | - } |
|
1693 | - } |
|
16 | + /** |
|
17 | + * The length of time in seconds that a lock is applied before being considered expired. |
|
18 | + * It is not long because a transaction should only be locked for the duration of the request that locked it |
|
19 | + */ |
|
20 | + const LOCK_EXPIRATION = 2; |
|
21 | + |
|
22 | + /** |
|
23 | + * txn status upon initial construction. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $_old_txn_status; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @param array $props_n_values incoming values |
|
32 | + * @param string $timezone incoming timezone |
|
33 | + * (if not set the timezone set for the website will be used.) |
|
34 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
35 | + * date_format and the second value is the time format |
|
36 | + * @return EE_Transaction |
|
37 | + * @throws EE_Error |
|
38 | + * @throws InvalidArgumentException |
|
39 | + * @throws InvalidDataTypeException |
|
40 | + * @throws InvalidInterfaceException |
|
41 | + * @throws ReflectionException |
|
42 | + */ |
|
43 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
44 | + { |
|
45 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
46 | + $txn = $has_object |
|
47 | + ? $has_object |
|
48 | + : new self($props_n_values, false, $timezone, $date_formats); |
|
49 | + if (! $has_object) { |
|
50 | + $txn->set_old_txn_status($txn->status_ID()); |
|
51 | + } |
|
52 | + return $txn; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @param array $props_n_values incoming values from the database |
|
58 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
59 | + * the website will be used. |
|
60 | + * @return EE_Transaction |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidArgumentException |
|
63 | + * @throws InvalidDataTypeException |
|
64 | + * @throws InvalidInterfaceException |
|
65 | + * @throws ReflectionException |
|
66 | + */ |
|
67 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
68 | + { |
|
69 | + $txn = new self($props_n_values, true, $timezone); |
|
70 | + $txn->set_old_txn_status($txn->status_ID()); |
|
71 | + return $txn; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Sets a meta field indicating that this TXN is locked and should not be updated in the db. |
|
77 | + * If a lock has already been set, then we will attempt to remove it in case it has expired. |
|
78 | + * If that also fails, then an exception is thrown. |
|
79 | + * |
|
80 | + * @throws EE_Error |
|
81 | + * @throws InvalidArgumentException |
|
82 | + * @throws InvalidDataTypeException |
|
83 | + * @throws InvalidInterfaceException |
|
84 | + * @throws ReflectionException |
|
85 | + */ |
|
86 | + public function lock() |
|
87 | + { |
|
88 | + // attempt to set lock, but if that fails... |
|
89 | + if (! $this->add_extra_meta('lock', time(), true)) { |
|
90 | + // then attempt to remove the lock in case it is expired |
|
91 | + if ($this->_remove_expired_lock()) { |
|
92 | + // if removal was successful, then try setting lock again |
|
93 | + $this->lock(); |
|
94 | + } else { |
|
95 | + // but if the lock can not be removed, then throw an exception |
|
96 | + throw new EE_Error( |
|
97 | + sprintf( |
|
98 | + __( |
|
99 | + 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', |
|
100 | + 'event_espresso' |
|
101 | + ), |
|
102 | + $this->ID() |
|
103 | + ) |
|
104 | + ); |
|
105 | + } |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * removes transaction lock applied in EE_Transaction::lock() |
|
112 | + * |
|
113 | + * @return int |
|
114 | + * @throws EE_Error |
|
115 | + * @throws InvalidArgumentException |
|
116 | + * @throws InvalidDataTypeException |
|
117 | + * @throws InvalidInterfaceException |
|
118 | + * @throws ReflectionException |
|
119 | + */ |
|
120 | + public function unlock() |
|
121 | + { |
|
122 | + return $this->delete_extra_meta('lock'); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Decides whether or not now is the right time to update the transaction. |
|
128 | + * This is useful because we don't always know if it is safe to update the transaction |
|
129 | + * and its related data. why? |
|
130 | + * because it's possible that the transaction is being used in another |
|
131 | + * request and could overwrite anything we save. |
|
132 | + * So we want to only update the txn once we know that won't happen. |
|
133 | + * We also check that the lock isn't expired, and remove it if it is |
|
134 | + * |
|
135 | + * @return boolean |
|
136 | + * @throws EE_Error |
|
137 | + * @throws InvalidArgumentException |
|
138 | + * @throws InvalidDataTypeException |
|
139 | + * @throws InvalidInterfaceException |
|
140 | + * @throws ReflectionException |
|
141 | + */ |
|
142 | + public function is_locked() |
|
143 | + { |
|
144 | + // if TXN is not locked, then return false immediately |
|
145 | + if (! $this->_get_lock()) { |
|
146 | + return false; |
|
147 | + } |
|
148 | + // if not, then let's try and remove the lock in case it's expired... |
|
149 | + // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false) |
|
150 | + // and a positive number if the lock was removed (ie: number of locks deleted), |
|
151 | + // so we need to return the opposite |
|
152 | + return ! $this->_remove_expired_lock() ? true : false; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Gets the meta field indicating that this TXN is locked |
|
158 | + * |
|
159 | + * @return int |
|
160 | + * @throws EE_Error |
|
161 | + * @throws InvalidArgumentException |
|
162 | + * @throws InvalidDataTypeException |
|
163 | + * @throws InvalidInterfaceException |
|
164 | + * @throws ReflectionException |
|
165 | + */ |
|
166 | + protected function _get_lock() |
|
167 | + { |
|
168 | + return (int) $this->get_extra_meta('lock', true, 0); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
|
174 | + * |
|
175 | + * @return int |
|
176 | + * @throws EE_Error |
|
177 | + * @throws InvalidArgumentException |
|
178 | + * @throws InvalidDataTypeException |
|
179 | + * @throws InvalidInterfaceException |
|
180 | + * @throws ReflectionException |
|
181 | + */ |
|
182 | + protected function _remove_expired_lock() |
|
183 | + { |
|
184 | + $locked = $this->_get_lock(); |
|
185 | + if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
186 | + return $this->unlock(); |
|
187 | + } |
|
188 | + return 0; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * Set transaction total |
|
194 | + * |
|
195 | + * @param float $total total value of transaction |
|
196 | + * @throws EE_Error |
|
197 | + * @throws InvalidArgumentException |
|
198 | + * @throws InvalidDataTypeException |
|
199 | + * @throws InvalidInterfaceException |
|
200 | + * @throws ReflectionException |
|
201 | + */ |
|
202 | + public function set_total($total = 0.00) |
|
203 | + { |
|
204 | + $this->set('TXN_total', (float) $total); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * Set Total Amount Paid to Date |
|
210 | + * |
|
211 | + * @param float $total_paid total amount paid to date (sum of all payments) |
|
212 | + * @throws EE_Error |
|
213 | + * @throws InvalidArgumentException |
|
214 | + * @throws InvalidDataTypeException |
|
215 | + * @throws InvalidInterfaceException |
|
216 | + * @throws ReflectionException |
|
217 | + */ |
|
218 | + public function set_paid($total_paid = 0.00) |
|
219 | + { |
|
220 | + $this->set('TXN_paid', (float) $total_paid); |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * Set transaction status |
|
226 | + * |
|
227 | + * @param string $status whether the transaction is open, declined, accepted, |
|
228 | + * or any number of custom values that can be set |
|
229 | + * @throws EE_Error |
|
230 | + * @throws InvalidArgumentException |
|
231 | + * @throws InvalidDataTypeException |
|
232 | + * @throws InvalidInterfaceException |
|
233 | + * @throws ReflectionException |
|
234 | + */ |
|
235 | + public function set_status($status = '') |
|
236 | + { |
|
237 | + $this->set('STS_ID', $status); |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * Set hash salt |
|
243 | + * |
|
244 | + * @param string $hash_salt required for some payment gateways |
|
245 | + * @throws EE_Error |
|
246 | + * @throws InvalidArgumentException |
|
247 | + * @throws InvalidDataTypeException |
|
248 | + * @throws InvalidInterfaceException |
|
249 | + * @throws ReflectionException |
|
250 | + */ |
|
251 | + public function set_hash_salt($hash_salt = '') |
|
252 | + { |
|
253 | + $this->set('TXN_hash_salt', $hash_salt); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * Sets TXN_reg_steps array |
|
259 | + * |
|
260 | + * @param array $txn_reg_steps |
|
261 | + * @throws EE_Error |
|
262 | + * @throws InvalidArgumentException |
|
263 | + * @throws InvalidDataTypeException |
|
264 | + * @throws InvalidInterfaceException |
|
265 | + * @throws ReflectionException |
|
266 | + */ |
|
267 | + public function set_reg_steps(array $txn_reg_steps) |
|
268 | + { |
|
269 | + $this->set('TXN_reg_steps', $txn_reg_steps); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Gets TXN_reg_steps |
|
275 | + * |
|
276 | + * @return array |
|
277 | + * @throws EE_Error |
|
278 | + * @throws InvalidArgumentException |
|
279 | + * @throws InvalidDataTypeException |
|
280 | + * @throws InvalidInterfaceException |
|
281 | + * @throws ReflectionException |
|
282 | + */ |
|
283 | + public function reg_steps() |
|
284 | + { |
|
285 | + $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
286 | + return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * @return string of transaction's total cost, with currency symbol and decimal |
|
292 | + * @throws EE_Error |
|
293 | + * @throws InvalidArgumentException |
|
294 | + * @throws InvalidDataTypeException |
|
295 | + * @throws InvalidInterfaceException |
|
296 | + * @throws ReflectionException |
|
297 | + */ |
|
298 | + public function pretty_total() |
|
299 | + { |
|
300 | + return $this->get_pretty('TXN_total'); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Gets the amount paid in a pretty string (formatted and with currency symbol) |
|
306 | + * |
|
307 | + * @return string |
|
308 | + * @throws EE_Error |
|
309 | + * @throws InvalidArgumentException |
|
310 | + * @throws InvalidDataTypeException |
|
311 | + * @throws InvalidInterfaceException |
|
312 | + * @throws ReflectionException |
|
313 | + */ |
|
314 | + public function pretty_paid() |
|
315 | + { |
|
316 | + return $this->get_pretty('TXN_paid'); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * calculate the amount remaining for this transaction and return; |
|
322 | + * |
|
323 | + * @return float amount remaining |
|
324 | + * @throws EE_Error |
|
325 | + * @throws InvalidArgumentException |
|
326 | + * @throws InvalidDataTypeException |
|
327 | + * @throws InvalidInterfaceException |
|
328 | + * @throws ReflectionException |
|
329 | + */ |
|
330 | + public function remaining() |
|
331 | + { |
|
332 | + return $this->total() - $this->paid(); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * get Transaction Total |
|
338 | + * |
|
339 | + * @return float |
|
340 | + * @throws EE_Error |
|
341 | + * @throws InvalidArgumentException |
|
342 | + * @throws InvalidDataTypeException |
|
343 | + * @throws InvalidInterfaceException |
|
344 | + * @throws ReflectionException |
|
345 | + */ |
|
346 | + public function total() |
|
347 | + { |
|
348 | + return (float) $this->get('TXN_total'); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * get Total Amount Paid to Date |
|
354 | + * |
|
355 | + * @return float |
|
356 | + * @throws EE_Error |
|
357 | + * @throws InvalidArgumentException |
|
358 | + * @throws InvalidDataTypeException |
|
359 | + * @throws InvalidInterfaceException |
|
360 | + * @throws ReflectionException |
|
361 | + */ |
|
362 | + public function paid() |
|
363 | + { |
|
364 | + return (float) $this->get('TXN_paid'); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * @return mixed|null |
|
370 | + * @throws EE_Error |
|
371 | + * @throws InvalidArgumentException |
|
372 | + * @throws InvalidDataTypeException |
|
373 | + * @throws InvalidInterfaceException |
|
374 | + * @throws ReflectionException |
|
375 | + */ |
|
376 | + public function get_cart_session() |
|
377 | + { |
|
378 | + $session_data = (array) $this->get('TXN_session_data'); |
|
379 | + return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
380 | + ? $session_data['cart'] |
|
381 | + : null; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * get Transaction session data |
|
387 | + * |
|
388 | + * @return array|mixed |
|
389 | + * @throws EE_Error |
|
390 | + * @throws InvalidArgumentException |
|
391 | + * @throws InvalidDataTypeException |
|
392 | + * @throws InvalidInterfaceException |
|
393 | + * @throws ReflectionException |
|
394 | + */ |
|
395 | + public function session_data() |
|
396 | + { |
|
397 | + $session_data = $this->get('TXN_session_data'); |
|
398 | + if (empty($session_data)) { |
|
399 | + $session_data = array( |
|
400 | + 'id' => null, |
|
401 | + 'user_id' => null, |
|
402 | + 'ip_address' => null, |
|
403 | + 'user_agent' => null, |
|
404 | + 'init_access' => null, |
|
405 | + 'last_access' => null, |
|
406 | + 'pages_visited' => array(), |
|
407 | + ); |
|
408 | + } |
|
409 | + return $session_data; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * Set session data within the TXN object |
|
415 | + * |
|
416 | + * @param EE_Session|array $session_data |
|
417 | + * @throws EE_Error |
|
418 | + * @throws InvalidArgumentException |
|
419 | + * @throws InvalidDataTypeException |
|
420 | + * @throws InvalidInterfaceException |
|
421 | + * @throws ReflectionException |
|
422 | + */ |
|
423 | + public function set_txn_session_data($session_data) |
|
424 | + { |
|
425 | + if ($session_data instanceof EE_Session) { |
|
426 | + $this->set('TXN_session_data', $session_data->get_session_data(null, true)); |
|
427 | + } else { |
|
428 | + $this->set('TXN_session_data', $session_data); |
|
429 | + } |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * get Transaction hash salt |
|
435 | + * |
|
436 | + * @return mixed |
|
437 | + * @throws EE_Error |
|
438 | + * @throws InvalidArgumentException |
|
439 | + * @throws InvalidDataTypeException |
|
440 | + * @throws InvalidInterfaceException |
|
441 | + * @throws ReflectionException |
|
442 | + */ |
|
443 | + public function hash_salt_() |
|
444 | + { |
|
445 | + return $this->get('TXN_hash_salt'); |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * Returns the transaction datetime as either: |
|
451 | + * - unix timestamp format ($format = false, $gmt = true) |
|
452 | + * - formatted date string including the UTC (timezone) offset ($format = true ($gmt |
|
453 | + * has no affect with this option)), this also may include a timezone abbreviation if the |
|
454 | + * set timezone in this class differs from what the timezone is on the blog. |
|
455 | + * - formatted date string including the UTC (timezone) offset (default). |
|
456 | + * |
|
457 | + * @param boolean $format - whether to return a unix timestamp (default) or formatted date string |
|
458 | + * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) |
|
459 | + * or no UTC offset applied |
|
460 | + * @return string | int |
|
461 | + * @throws EE_Error |
|
462 | + * @throws InvalidArgumentException |
|
463 | + * @throws InvalidDataTypeException |
|
464 | + * @throws InvalidInterfaceException |
|
465 | + * @throws ReflectionException |
|
466 | + */ |
|
467 | + public function datetime($format = false, $gmt = false) |
|
468 | + { |
|
469 | + if ($format) { |
|
470 | + return $this->get_pretty('TXN_timestamp'); |
|
471 | + } |
|
472 | + if ($gmt) { |
|
473 | + return $this->get_raw('TXN_timestamp'); |
|
474 | + } |
|
475 | + return $this->get('TXN_timestamp'); |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * Gets registrations on this transaction |
|
481 | + * |
|
482 | + * @param array $query_params array of query parameters |
|
483 | + * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
|
484 | + * @return EE_Base_Class[]|EE_Registration[] |
|
485 | + * @throws EE_Error |
|
486 | + * @throws InvalidArgumentException |
|
487 | + * @throws InvalidDataTypeException |
|
488 | + * @throws InvalidInterfaceException |
|
489 | + * @throws ReflectionException |
|
490 | + */ |
|
491 | + public function registrations($query_params = array(), $get_cached = false) |
|
492 | + { |
|
493 | + $query_params = (empty($query_params) || ! is_array($query_params)) |
|
494 | + ? array( |
|
495 | + 'order_by' => array( |
|
496 | + 'Event.EVT_name' => 'ASC', |
|
497 | + 'Attendee.ATT_lname' => 'ASC', |
|
498 | + 'Attendee.ATT_fname' => 'ASC', |
|
499 | + ), |
|
500 | + ) |
|
501 | + : $query_params; |
|
502 | + $query_params = $get_cached ? array() : $query_params; |
|
503 | + return $this->get_many_related('Registration', $query_params); |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
|
509 | + * function for getting attendees and how many registrations they each have for an event) |
|
510 | + * |
|
511 | + * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
512 | + * @throws EE_Error |
|
513 | + * @throws InvalidArgumentException |
|
514 | + * @throws InvalidDataTypeException |
|
515 | + * @throws InvalidInterfaceException |
|
516 | + * @throws ReflectionException |
|
517 | + */ |
|
518 | + public function attendees() |
|
519 | + { |
|
520 | + return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default |
|
526 | + * |
|
527 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
528 | + * @return EE_Base_Class[]|EE_Payment[] |
|
529 | + * @throws EE_Error |
|
530 | + * @throws InvalidArgumentException |
|
531 | + * @throws InvalidDataTypeException |
|
532 | + * @throws InvalidInterfaceException |
|
533 | + * @throws ReflectionException |
|
534 | + */ |
|
535 | + public function payments($query_params = array()) |
|
536 | + { |
|
537 | + return $this->get_many_related('Payment', $query_params); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * gets only approved payments for this transaction |
|
543 | + * |
|
544 | + * @return EE_Base_Class[]|EE_Payment[] |
|
545 | + * @throws EE_Error |
|
546 | + * @throws InvalidArgumentException |
|
547 | + * @throws ReflectionException |
|
548 | + * @throws InvalidDataTypeException |
|
549 | + * @throws InvalidInterfaceException |
|
550 | + */ |
|
551 | + public function approved_payments() |
|
552 | + { |
|
553 | + EE_Registry::instance()->load_model('Payment'); |
|
554 | + return $this->get_many_related( |
|
555 | + 'Payment', |
|
556 | + array( |
|
557 | + array('STS_ID' => EEM_Payment::status_id_approved), |
|
558 | + 'order_by' => array('PAY_timestamp' => 'DESC'), |
|
559 | + ) |
|
560 | + ); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * Gets all payments which have not been approved |
|
566 | + * |
|
567 | + * @return EE_Base_Class[]|EEI_Payment[] |
|
568 | + * @throws EE_Error if a model is misconfigured somehow |
|
569 | + * @throws InvalidArgumentException |
|
570 | + * @throws InvalidDataTypeException |
|
571 | + * @throws InvalidInterfaceException |
|
572 | + * @throws ReflectionException |
|
573 | + */ |
|
574 | + public function pending_payments() |
|
575 | + { |
|
576 | + return $this->get_many_related( |
|
577 | + 'Payment', |
|
578 | + array( |
|
579 | + array( |
|
580 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
581 | + ), |
|
582 | + 'order_by' => array( |
|
583 | + 'PAY_timestamp' => 'DESC', |
|
584 | + ), |
|
585 | + ) |
|
586 | + ); |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + /** |
|
591 | + * echoes $this->pretty_status() |
|
592 | + * |
|
593 | + * @param bool $show_icons |
|
594 | + * @throws EE_Error |
|
595 | + * @throws InvalidArgumentException |
|
596 | + * @throws InvalidDataTypeException |
|
597 | + * @throws InvalidInterfaceException |
|
598 | + * @throws ReflectionException |
|
599 | + */ |
|
600 | + public function e_pretty_status($show_icons = false) |
|
601 | + { |
|
602 | + echo $this->pretty_status($show_icons); |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + /** |
|
607 | + * returns a pretty version of the status, good for displaying to users |
|
608 | + * |
|
609 | + * @param bool $show_icons |
|
610 | + * @return string |
|
611 | + * @throws EE_Error |
|
612 | + * @throws InvalidArgumentException |
|
613 | + * @throws InvalidDataTypeException |
|
614 | + * @throws InvalidInterfaceException |
|
615 | + * @throws ReflectionException |
|
616 | + */ |
|
617 | + public function pretty_status($show_icons = false) |
|
618 | + { |
|
619 | + $status = EEM_Status::instance()->localized_status( |
|
620 | + array($this->status_ID() => __('unknown', 'event_espresso')), |
|
621 | + false, |
|
622 | + 'sentence' |
|
623 | + ); |
|
624 | + $icon = ''; |
|
625 | + switch ($this->status_ID()) { |
|
626 | + case EEM_Transaction::complete_status_code: |
|
627 | + $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
|
628 | + break; |
|
629 | + case EEM_Transaction::incomplete_status_code: |
|
630 | + $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>' |
|
631 | + : ''; |
|
632 | + break; |
|
633 | + case EEM_Transaction::abandoned_status_code: |
|
634 | + $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : ''; |
|
635 | + break; |
|
636 | + case EEM_Transaction::failed_status_code: |
|
637 | + $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
638 | + break; |
|
639 | + case EEM_Transaction::overpaid_status_code: |
|
640 | + $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
|
641 | + break; |
|
642 | + } |
|
643 | + return $icon . $status[ $this->status_ID() ]; |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + /** |
|
648 | + * get Transaction Status |
|
649 | + * |
|
650 | + * @return mixed |
|
651 | + * @throws EE_Error |
|
652 | + * @throws InvalidArgumentException |
|
653 | + * @throws InvalidDataTypeException |
|
654 | + * @throws InvalidInterfaceException |
|
655 | + * @throws ReflectionException |
|
656 | + */ |
|
657 | + public function status_ID() |
|
658 | + { |
|
659 | + return $this->get('STS_ID'); |
|
660 | + } |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * Returns TRUE or FALSE for whether or not this transaction cost any money |
|
665 | + * |
|
666 | + * @return boolean |
|
667 | + * @throws EE_Error |
|
668 | + * @throws InvalidArgumentException |
|
669 | + * @throws InvalidDataTypeException |
|
670 | + * @throws InvalidInterfaceException |
|
671 | + * @throws ReflectionException |
|
672 | + */ |
|
673 | + public function is_free() |
|
674 | + { |
|
675 | + return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * Returns whether this transaction is complete |
|
681 | + * Useful in templates and other logic for deciding if we should ask for another payment... |
|
682 | + * |
|
683 | + * @return boolean |
|
684 | + * @throws EE_Error |
|
685 | + * @throws InvalidArgumentException |
|
686 | + * @throws InvalidDataTypeException |
|
687 | + * @throws InvalidInterfaceException |
|
688 | + * @throws ReflectionException |
|
689 | + */ |
|
690 | + public function is_completed() |
|
691 | + { |
|
692 | + return $this->status_ID() === EEM_Transaction::complete_status_code; |
|
693 | + } |
|
694 | + |
|
695 | + |
|
696 | + /** |
|
697 | + * Returns whether this transaction is incomplete |
|
698 | + * Useful in templates and other logic for deciding if we should ask for another payment... |
|
699 | + * |
|
700 | + * @return boolean |
|
701 | + * @throws EE_Error |
|
702 | + * @throws InvalidArgumentException |
|
703 | + * @throws InvalidDataTypeException |
|
704 | + * @throws InvalidInterfaceException |
|
705 | + * @throws ReflectionException |
|
706 | + */ |
|
707 | + public function is_incomplete() |
|
708 | + { |
|
709 | + return $this->status_ID() === EEM_Transaction::incomplete_status_code; |
|
710 | + } |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * Returns whether this transaction is overpaid |
|
715 | + * Useful in templates and other logic for deciding if monies need to be refunded |
|
716 | + * |
|
717 | + * @return boolean |
|
718 | + * @throws EE_Error |
|
719 | + * @throws InvalidArgumentException |
|
720 | + * @throws InvalidDataTypeException |
|
721 | + * @throws InvalidInterfaceException |
|
722 | + * @throws ReflectionException |
|
723 | + */ |
|
724 | + public function is_overpaid() |
|
725 | + { |
|
726 | + return $this->status_ID() === EEM_Transaction::overpaid_status_code; |
|
727 | + } |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * Returns whether this transaction was abandoned |
|
732 | + * meaning that the transaction/registration process was somehow interrupted and never completed |
|
733 | + * but that contact information exists for at least one registrant |
|
734 | + * |
|
735 | + * @return boolean |
|
736 | + * @throws EE_Error |
|
737 | + * @throws InvalidArgumentException |
|
738 | + * @throws InvalidDataTypeException |
|
739 | + * @throws InvalidInterfaceException |
|
740 | + * @throws ReflectionException |
|
741 | + */ |
|
742 | + public function is_abandoned() |
|
743 | + { |
|
744 | + return $this->status_ID() === EEM_Transaction::abandoned_status_code; |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * Returns whether this transaction failed |
|
750 | + * meaning that the transaction/registration process was somehow interrupted and never completed |
|
751 | + * and that NO contact information exists for any registrants |
|
752 | + * |
|
753 | + * @return boolean |
|
754 | + * @throws EE_Error |
|
755 | + * @throws InvalidArgumentException |
|
756 | + * @throws InvalidDataTypeException |
|
757 | + * @throws InvalidInterfaceException |
|
758 | + * @throws ReflectionException |
|
759 | + */ |
|
760 | + public function failed() |
|
761 | + { |
|
762 | + return $this->status_ID() === EEM_Transaction::failed_status_code; |
|
763 | + } |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * This returns the url for the invoice of this transaction |
|
768 | + * |
|
769 | + * @param string $type 'html' or 'pdf' (default is pdf) |
|
770 | + * @return string |
|
771 | + * @throws EE_Error |
|
772 | + * @throws InvalidArgumentException |
|
773 | + * @throws InvalidDataTypeException |
|
774 | + * @throws InvalidInterfaceException |
|
775 | + * @throws ReflectionException |
|
776 | + */ |
|
777 | + public function invoice_url($type = 'html') |
|
778 | + { |
|
779 | + $REG = $this->primary_registration(); |
|
780 | + if (! $REG instanceof EE_Registration) { |
|
781 | + return ''; |
|
782 | + } |
|
783 | + return $REG->invoice_url($type); |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + /** |
|
788 | + * Gets the primary registration only |
|
789 | + * |
|
790 | + * @return EE_Base_Class|EE_Registration |
|
791 | + * @throws EE_Error |
|
792 | + * @throws InvalidArgumentException |
|
793 | + * @throws InvalidDataTypeException |
|
794 | + * @throws InvalidInterfaceException |
|
795 | + * @throws ReflectionException |
|
796 | + */ |
|
797 | + public function primary_registration() |
|
798 | + { |
|
799 | + $registrations = (array) $this->get_many_related( |
|
800 | + 'Registration', |
|
801 | + array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
802 | + ); |
|
803 | + foreach ($registrations as $registration) { |
|
804 | + // valid registration that is NOT cancelled or declined ? |
|
805 | + if ($registration instanceof EE_Registration |
|
806 | + && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
807 | + ) { |
|
808 | + return $registration; |
|
809 | + } |
|
810 | + } |
|
811 | + // nothing valid found, so just return first thing from array of results |
|
812 | + return reset($registrations); |
|
813 | + } |
|
814 | + |
|
815 | + |
|
816 | + /** |
|
817 | + * Gets the URL for viewing the receipt |
|
818 | + * |
|
819 | + * @param string $type 'pdf' or 'html' (default is 'html') |
|
820 | + * @return string |
|
821 | + * @throws EE_Error |
|
822 | + * @throws InvalidArgumentException |
|
823 | + * @throws InvalidDataTypeException |
|
824 | + * @throws InvalidInterfaceException |
|
825 | + * @throws ReflectionException |
|
826 | + */ |
|
827 | + public function receipt_url($type = 'html') |
|
828 | + { |
|
829 | + $REG = $this->primary_registration(); |
|
830 | + if (! $REG instanceof EE_Registration) { |
|
831 | + return ''; |
|
832 | + } |
|
833 | + return $REG->receipt_url($type); |
|
834 | + } |
|
835 | + |
|
836 | + |
|
837 | + /** |
|
838 | + * Gets the URL of the thank you page with this registration REG_url_link added as |
|
839 | + * a query parameter |
|
840 | + * |
|
841 | + * @return string |
|
842 | + * @throws EE_Error |
|
843 | + * @throws InvalidArgumentException |
|
844 | + * @throws InvalidDataTypeException |
|
845 | + * @throws InvalidInterfaceException |
|
846 | + * @throws ReflectionException |
|
847 | + */ |
|
848 | + public function payment_overview_url() |
|
849 | + { |
|
850 | + $primary_registration = $this->primary_registration(); |
|
851 | + return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false; |
|
852 | + } |
|
853 | + |
|
854 | + |
|
855 | + /** |
|
856 | + * @return string |
|
857 | + * @throws EE_Error |
|
858 | + * @throws InvalidArgumentException |
|
859 | + * @throws InvalidDataTypeException |
|
860 | + * @throws InvalidInterfaceException |
|
861 | + * @throws ReflectionException |
|
862 | + */ |
|
863 | + public function gateway_response_on_transaction() |
|
864 | + { |
|
865 | + $payment = $this->get_first_related('Payment'); |
|
866 | + return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
|
867 | + } |
|
868 | + |
|
869 | + |
|
870 | + /** |
|
871 | + * Get the status object of this object |
|
872 | + * |
|
873 | + * @return EE_Base_Class|EE_Status |
|
874 | + * @throws EE_Error |
|
875 | + * @throws InvalidArgumentException |
|
876 | + * @throws InvalidDataTypeException |
|
877 | + * @throws InvalidInterfaceException |
|
878 | + * @throws ReflectionException |
|
879 | + */ |
|
880 | + public function status_obj() |
|
881 | + { |
|
882 | + return $this->get_first_related('Status'); |
|
883 | + } |
|
884 | + |
|
885 | + |
|
886 | + /** |
|
887 | + * Gets all the extra meta info on this payment |
|
888 | + * |
|
889 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
890 | + * @return EE_Base_Class[]|EE_Extra_Meta |
|
891 | + * @throws EE_Error |
|
892 | + * @throws InvalidArgumentException |
|
893 | + * @throws InvalidDataTypeException |
|
894 | + * @throws InvalidInterfaceException |
|
895 | + * @throws ReflectionException |
|
896 | + */ |
|
897 | + public function extra_meta($query_params = array()) |
|
898 | + { |
|
899 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
900 | + } |
|
901 | + |
|
902 | + |
|
903 | + /** |
|
904 | + * Wrapper for _add_relation_to |
|
905 | + * |
|
906 | + * @param EE_Registration $registration |
|
907 | + * @return EE_Base_Class the relation was added to |
|
908 | + * @throws EE_Error |
|
909 | + * @throws InvalidArgumentException |
|
910 | + * @throws InvalidDataTypeException |
|
911 | + * @throws InvalidInterfaceException |
|
912 | + * @throws ReflectionException |
|
913 | + */ |
|
914 | + public function add_registration(EE_Registration $registration) |
|
915 | + { |
|
916 | + return $this->_add_relation_to($registration, 'Registration'); |
|
917 | + } |
|
918 | + |
|
919 | + |
|
920 | + /** |
|
921 | + * Removes the given registration from being related (even before saving this transaction). |
|
922 | + * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations |
|
923 | + * |
|
924 | + * @param int $registration_or_id |
|
925 | + * @return EE_Base_Class that was removed from being related |
|
926 | + * @throws EE_Error |
|
927 | + * @throws InvalidArgumentException |
|
928 | + * @throws InvalidDataTypeException |
|
929 | + * @throws InvalidInterfaceException |
|
930 | + * @throws ReflectionException |
|
931 | + */ |
|
932 | + public function remove_registration_with_id($registration_or_id) |
|
933 | + { |
|
934 | + return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
935 | + } |
|
936 | + |
|
937 | + |
|
938 | + /** |
|
939 | + * Gets all the line items which are for ACTUAL items |
|
940 | + * |
|
941 | + * @return EE_Line_Item[] |
|
942 | + * @throws EE_Error |
|
943 | + * @throws InvalidArgumentException |
|
944 | + * @throws InvalidDataTypeException |
|
945 | + * @throws InvalidInterfaceException |
|
946 | + * @throws ReflectionException |
|
947 | + */ |
|
948 | + public function items_purchased() |
|
949 | + { |
|
950 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
951 | + } |
|
952 | + |
|
953 | + |
|
954 | + /** |
|
955 | + * Wrapper for _add_relation_to |
|
956 | + * |
|
957 | + * @param EE_Line_Item $line_item |
|
958 | + * @return EE_Base_Class the relation was added to |
|
959 | + * @throws EE_Error |
|
960 | + * @throws InvalidArgumentException |
|
961 | + * @throws InvalidDataTypeException |
|
962 | + * @throws InvalidInterfaceException |
|
963 | + * @throws ReflectionException |
|
964 | + */ |
|
965 | + public function add_line_item(EE_Line_Item $line_item) |
|
966 | + { |
|
967 | + return $this->_add_relation_to($line_item, 'Line_Item'); |
|
968 | + } |
|
969 | + |
|
970 | + |
|
971 | + /** |
|
972 | + * Gets ALL the line items related to this transaction (unstructured) |
|
973 | + * |
|
974 | + * @param array $query_params |
|
975 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
976 | + * @throws EE_Error |
|
977 | + * @throws InvalidArgumentException |
|
978 | + * @throws InvalidDataTypeException |
|
979 | + * @throws InvalidInterfaceException |
|
980 | + * @throws ReflectionException |
|
981 | + */ |
|
982 | + public function line_items($query_params = array()) |
|
983 | + { |
|
984 | + return $this->get_many_related('Line_Item', $query_params); |
|
985 | + } |
|
986 | + |
|
987 | + |
|
988 | + /** |
|
989 | + * Gets all the line items which are taxes on the total |
|
990 | + * |
|
991 | + * @return EE_Line_Item[] |
|
992 | + * @throws EE_Error |
|
993 | + * @throws InvalidArgumentException |
|
994 | + * @throws InvalidDataTypeException |
|
995 | + * @throws InvalidInterfaceException |
|
996 | + * @throws ReflectionException |
|
997 | + */ |
|
998 | + public function tax_items() |
|
999 | + { |
|
1000 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
1001 | + } |
|
1002 | + |
|
1003 | + |
|
1004 | + /** |
|
1005 | + * Gets the total line item (which is a parent of all other related line items, |
|
1006 | + * meaning it takes them all into account on its total) |
|
1007 | + * |
|
1008 | + * @param bool $create_if_not_found |
|
1009 | + * @return \EE_Line_Item |
|
1010 | + * @throws EE_Error |
|
1011 | + * @throws InvalidArgumentException |
|
1012 | + * @throws InvalidDataTypeException |
|
1013 | + * @throws InvalidInterfaceException |
|
1014 | + * @throws ReflectionException |
|
1015 | + */ |
|
1016 | + public function total_line_item($create_if_not_found = true) |
|
1017 | + { |
|
1018 | + $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
1019 | + if (! $item && $create_if_not_found) { |
|
1020 | + $item = EEH_Line_Item::create_total_line_item($this); |
|
1021 | + } |
|
1022 | + return $item; |
|
1023 | + } |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * Returns the total amount of tax on this transaction |
|
1028 | + * (assumes there's only one tax subtotal line item) |
|
1029 | + * |
|
1030 | + * @return float |
|
1031 | + * @throws EE_Error |
|
1032 | + * @throws InvalidArgumentException |
|
1033 | + * @throws InvalidDataTypeException |
|
1034 | + * @throws InvalidInterfaceException |
|
1035 | + * @throws ReflectionException |
|
1036 | + */ |
|
1037 | + public function tax_total() |
|
1038 | + { |
|
1039 | + $tax_line_item = $this->tax_total_line_item(); |
|
1040 | + if ($tax_line_item) { |
|
1041 | + return (float) $tax_line_item->total(); |
|
1042 | + } |
|
1043 | + return (float) 0; |
|
1044 | + } |
|
1045 | + |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * Gets the tax subtotal line item (assumes there's only one) |
|
1049 | + * |
|
1050 | + * @return EE_Line_Item |
|
1051 | + * @throws EE_Error |
|
1052 | + * @throws InvalidArgumentException |
|
1053 | + * @throws InvalidDataTypeException |
|
1054 | + * @throws InvalidInterfaceException |
|
1055 | + * @throws ReflectionException |
|
1056 | + */ |
|
1057 | + public function tax_total_line_item() |
|
1058 | + { |
|
1059 | + return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
1060 | + } |
|
1061 | + |
|
1062 | + |
|
1063 | + /** |
|
1064 | + * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
|
1065 | + * |
|
1066 | + * @return EE_Form_Section_Proper |
|
1067 | + * @throws EE_Error |
|
1068 | + * @throws InvalidArgumentException |
|
1069 | + * @throws InvalidDataTypeException |
|
1070 | + * @throws InvalidInterfaceException |
|
1071 | + * @throws ReflectionException |
|
1072 | + */ |
|
1073 | + public function billing_info() |
|
1074 | + { |
|
1075 | + $payment_method = $this->payment_method(); |
|
1076 | + if (! $payment_method) { |
|
1077 | + EE_Error::add_error( |
|
1078 | + __( |
|
1079 | + 'Could not find billing info for transaction because no gateway has been used for it yet', |
|
1080 | + 'event_espresso' |
|
1081 | + ), |
|
1082 | + __FILE__, |
|
1083 | + __FUNCTION__, |
|
1084 | + __LINE__ |
|
1085 | + ); |
|
1086 | + return null; |
|
1087 | + } |
|
1088 | + $primary_reg = $this->primary_registration(); |
|
1089 | + if (! $primary_reg) { |
|
1090 | + EE_Error::add_error( |
|
1091 | + __( |
|
1092 | + 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
|
1093 | + 'event_espresso' |
|
1094 | + ), |
|
1095 | + __FILE__, |
|
1096 | + __FUNCTION__, |
|
1097 | + __LINE__ |
|
1098 | + ); |
|
1099 | + return null; |
|
1100 | + } |
|
1101 | + $attendee = $primary_reg->attendee(); |
|
1102 | + if (! $attendee) { |
|
1103 | + EE_Error::add_error( |
|
1104 | + __( |
|
1105 | + 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
|
1106 | + 'event_espresso' |
|
1107 | + ), |
|
1108 | + __FILE__, |
|
1109 | + __FUNCTION__, |
|
1110 | + __LINE__ |
|
1111 | + ); |
|
1112 | + return null; |
|
1113 | + } |
|
1114 | + return $attendee->billing_info_for_payment_method($payment_method); |
|
1115 | + } |
|
1116 | + |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * Gets PMD_ID |
|
1120 | + * |
|
1121 | + * @return int |
|
1122 | + * @throws EE_Error |
|
1123 | + * @throws InvalidArgumentException |
|
1124 | + * @throws InvalidDataTypeException |
|
1125 | + * @throws InvalidInterfaceException |
|
1126 | + * @throws ReflectionException |
|
1127 | + */ |
|
1128 | + public function payment_method_ID() |
|
1129 | + { |
|
1130 | + return $this->get('PMD_ID'); |
|
1131 | + } |
|
1132 | + |
|
1133 | + |
|
1134 | + /** |
|
1135 | + * Sets PMD_ID |
|
1136 | + * |
|
1137 | + * @param int $PMD_ID |
|
1138 | + * @throws EE_Error |
|
1139 | + * @throws InvalidArgumentException |
|
1140 | + * @throws InvalidDataTypeException |
|
1141 | + * @throws InvalidInterfaceException |
|
1142 | + * @throws ReflectionException |
|
1143 | + */ |
|
1144 | + public function set_payment_method_ID($PMD_ID) |
|
1145 | + { |
|
1146 | + $this->set('PMD_ID', $PMD_ID); |
|
1147 | + } |
|
1148 | + |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * Gets the last-used payment method on this transaction |
|
1152 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
1153 | + * offline ones, dont' create payments) |
|
1154 | + * |
|
1155 | + * @return EE_Payment_Method |
|
1156 | + * @throws EE_Error |
|
1157 | + * @throws InvalidArgumentException |
|
1158 | + * @throws InvalidDataTypeException |
|
1159 | + * @throws InvalidInterfaceException |
|
1160 | + * @throws ReflectionException |
|
1161 | + */ |
|
1162 | + public function payment_method() |
|
1163 | + { |
|
1164 | + $pm = $this->get_first_related('Payment_Method'); |
|
1165 | + if ($pm instanceof EE_Payment_Method) { |
|
1166 | + return $pm; |
|
1167 | + } |
|
1168 | + $last_payment = $this->last_payment(); |
|
1169 | + if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
1170 | + return $last_payment->payment_method(); |
|
1171 | + } |
|
1172 | + return null; |
|
1173 | + } |
|
1174 | + |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * Gets the last payment made |
|
1178 | + * |
|
1179 | + * @return EE_Base_Class|EE_Payment |
|
1180 | + * @throws EE_Error |
|
1181 | + * @throws InvalidArgumentException |
|
1182 | + * @throws InvalidDataTypeException |
|
1183 | + * @throws InvalidInterfaceException |
|
1184 | + * @throws ReflectionException |
|
1185 | + */ |
|
1186 | + public function last_payment() |
|
1187 | + { |
|
1188 | + return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
1189 | + } |
|
1190 | + |
|
1191 | + |
|
1192 | + /** |
|
1193 | + * Gets all the line items which are unrelated to tickets on this transaction |
|
1194 | + * |
|
1195 | + * @return EE_Line_Item[] |
|
1196 | + * @throws EE_Error |
|
1197 | + * @throws InvalidArgumentException |
|
1198 | + * @throws InvalidDataTypeException |
|
1199 | + * @throws InvalidInterfaceException |
|
1200 | + * @throws ReflectionException |
|
1201 | + */ |
|
1202 | + public function non_ticket_line_items() |
|
1203 | + { |
|
1204 | + return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
1205 | + } |
|
1206 | + |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * possibly toggles TXN status |
|
1210 | + * |
|
1211 | + * @param boolean $update whether to save the TXN |
|
1212 | + * @return bool whether the TXN was saved |
|
1213 | + * @throws EE_Error |
|
1214 | + * @throws InvalidArgumentException |
|
1215 | + * @throws InvalidDataTypeException |
|
1216 | + * @throws InvalidInterfaceException |
|
1217 | + * @throws ReflectionException |
|
1218 | + * @throws RuntimeException |
|
1219 | + */ |
|
1220 | + public function update_status_based_on_total_paid($update = true) |
|
1221 | + { |
|
1222 | + // set transaction status based on comparison of TXN_paid vs TXN_total |
|
1223 | + if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) { |
|
1224 | + $new_txn_status = EEM_Transaction::overpaid_status_code; |
|
1225 | + } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) { |
|
1226 | + $new_txn_status = EEM_Transaction::complete_status_code; |
|
1227 | + } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) { |
|
1228 | + $new_txn_status = EEM_Transaction::incomplete_status_code; |
|
1229 | + } else { |
|
1230 | + throw new RuntimeException( |
|
1231 | + __('The total paid calculation for this transaction is inaccurate.', 'event_espresso') |
|
1232 | + ); |
|
1233 | + } |
|
1234 | + if ($new_txn_status !== $this->status_ID()) { |
|
1235 | + $this->set_status($new_txn_status); |
|
1236 | + if ($update) { |
|
1237 | + return $this->save() ? true : false; |
|
1238 | + } |
|
1239 | + } |
|
1240 | + return false; |
|
1241 | + } |
|
1242 | + |
|
1243 | + |
|
1244 | + /** |
|
1245 | + * Updates the transaction's status and total_paid based on all the payments |
|
1246 | + * that apply to it |
|
1247 | + * |
|
1248 | + * @deprecated |
|
1249 | + * @return array|bool |
|
1250 | + * @throws EE_Error |
|
1251 | + * @throws InvalidArgumentException |
|
1252 | + * @throws ReflectionException |
|
1253 | + * @throws InvalidDataTypeException |
|
1254 | + * @throws InvalidInterfaceException |
|
1255 | + */ |
|
1256 | + public function update_based_on_payments() |
|
1257 | + { |
|
1258 | + EE_Error::doing_it_wrong( |
|
1259 | + __CLASS__ . '::' . __FUNCTION__, |
|
1260 | + sprintf( |
|
1261 | + __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
1262 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
1263 | + ), |
|
1264 | + '4.6.0' |
|
1265 | + ); |
|
1266 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
1267 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
1268 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
1269 | + } |
|
1270 | + |
|
1271 | + |
|
1272 | + /** |
|
1273 | + * @return string |
|
1274 | + */ |
|
1275 | + public function old_txn_status() |
|
1276 | + { |
|
1277 | + return $this->_old_txn_status; |
|
1278 | + } |
|
1279 | + |
|
1280 | + |
|
1281 | + /** |
|
1282 | + * @param string $old_txn_status |
|
1283 | + */ |
|
1284 | + public function set_old_txn_status($old_txn_status) |
|
1285 | + { |
|
1286 | + // only set the first time |
|
1287 | + if ($this->_old_txn_status === null) { |
|
1288 | + $this->_old_txn_status = $old_txn_status; |
|
1289 | + } |
|
1290 | + } |
|
1291 | + |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * reg_status_updated |
|
1295 | + * |
|
1296 | + * @return bool |
|
1297 | + * @throws EE_Error |
|
1298 | + * @throws InvalidArgumentException |
|
1299 | + * @throws InvalidDataTypeException |
|
1300 | + * @throws InvalidInterfaceException |
|
1301 | + * @throws ReflectionException |
|
1302 | + */ |
|
1303 | + public function txn_status_updated() |
|
1304 | + { |
|
1305 | + return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null; |
|
1306 | + } |
|
1307 | + |
|
1308 | + |
|
1309 | + /** |
|
1310 | + * _reg_steps_completed |
|
1311 | + * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed, |
|
1312 | + * if a $reg_step_slug is provided, then this step will be skipped when testing for completion |
|
1313 | + * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion |
|
1314 | + * |
|
1315 | + * @param string $reg_step_slug |
|
1316 | + * @param bool $check_all |
|
1317 | + * @return bool|int |
|
1318 | + * @throws EE_Error |
|
1319 | + * @throws InvalidArgumentException |
|
1320 | + * @throws InvalidDataTypeException |
|
1321 | + * @throws InvalidInterfaceException |
|
1322 | + * @throws ReflectionException |
|
1323 | + */ |
|
1324 | + private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
|
1325 | + { |
|
1326 | + $reg_steps = $this->reg_steps(); |
|
1327 | + if (! is_array($reg_steps) || empty($reg_steps)) { |
|
1328 | + return false; |
|
1329 | + } |
|
1330 | + // loop thru reg steps array) |
|
1331 | + foreach ($reg_steps as $slug => $reg_step_completed) { |
|
1332 | + // if NOT checking ALL steps (only checking one step) |
|
1333 | + if (! $check_all) { |
|
1334 | + // and this is the one |
|
1335 | + if ($slug === $reg_step_slug) { |
|
1336 | + return $reg_step_completed; |
|
1337 | + } |
|
1338 | + // skip to next reg step in loop |
|
1339 | + continue; |
|
1340 | + } |
|
1341 | + // $check_all must be true, else we would never have gotten to this point |
|
1342 | + if ($slug === $reg_step_slug) { |
|
1343 | + // if we reach this point, then we are testing either: |
|
1344 | + // all_reg_steps_completed_except() or |
|
1345 | + // all_reg_steps_completed_except_final_step(), |
|
1346 | + // and since this is the reg step EXCEPTION being tested |
|
1347 | + // we want to return true (yes true) if this reg step is NOT completed |
|
1348 | + // ie: "is everything completed except the final step?" |
|
1349 | + // "that is correct... the final step is not completed, but all others are." |
|
1350 | + return $reg_step_completed !== true; |
|
1351 | + } |
|
1352 | + if ($reg_step_completed !== true) { |
|
1353 | + // if any reg step is NOT completed, then ALL steps are not completed |
|
1354 | + return false; |
|
1355 | + } |
|
1356 | + } |
|
1357 | + return true; |
|
1358 | + } |
|
1359 | + |
|
1360 | + |
|
1361 | + /** |
|
1362 | + * all_reg_steps_completed |
|
1363 | + * returns: |
|
1364 | + * true if ALL reg steps have been marked as completed |
|
1365 | + * or false if any step is not completed |
|
1366 | + * |
|
1367 | + * @return bool |
|
1368 | + * @throws EE_Error |
|
1369 | + * @throws InvalidArgumentException |
|
1370 | + * @throws InvalidDataTypeException |
|
1371 | + * @throws InvalidInterfaceException |
|
1372 | + * @throws ReflectionException |
|
1373 | + */ |
|
1374 | + public function all_reg_steps_completed() |
|
1375 | + { |
|
1376 | + return $this->_reg_steps_completed(); |
|
1377 | + } |
|
1378 | + |
|
1379 | + |
|
1380 | + /** |
|
1381 | + * all_reg_steps_completed_except |
|
1382 | + * returns: |
|
1383 | + * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
1384 | + * or false if any other step is not completed |
|
1385 | + * or false if ALL steps are completed including the exception you are testing !!! |
|
1386 | + * |
|
1387 | + * @param string $exception |
|
1388 | + * @return bool |
|
1389 | + * @throws EE_Error |
|
1390 | + * @throws InvalidArgumentException |
|
1391 | + * @throws InvalidDataTypeException |
|
1392 | + * @throws InvalidInterfaceException |
|
1393 | + * @throws ReflectionException |
|
1394 | + */ |
|
1395 | + public function all_reg_steps_completed_except($exception = '') |
|
1396 | + { |
|
1397 | + return $this->_reg_steps_completed($exception); |
|
1398 | + } |
|
1399 | + |
|
1400 | + |
|
1401 | + /** |
|
1402 | + * all_reg_steps_completed_except |
|
1403 | + * returns: |
|
1404 | + * true if ALL reg steps, except the final step, have been marked as completed |
|
1405 | + * or false if any step is not completed |
|
1406 | + * or false if ALL steps are completed including the final step !!! |
|
1407 | + * |
|
1408 | + * @return bool |
|
1409 | + * @throws EE_Error |
|
1410 | + * @throws InvalidArgumentException |
|
1411 | + * @throws InvalidDataTypeException |
|
1412 | + * @throws InvalidInterfaceException |
|
1413 | + * @throws ReflectionException |
|
1414 | + */ |
|
1415 | + public function all_reg_steps_completed_except_final_step() |
|
1416 | + { |
|
1417 | + return $this->_reg_steps_completed('finalize_registration'); |
|
1418 | + } |
|
1419 | + |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * reg_step_completed |
|
1423 | + * returns: |
|
1424 | + * true if a specific reg step has been marked as completed |
|
1425 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
1426 | + * or false if it has not yet been initialized |
|
1427 | + * |
|
1428 | + * @param string $reg_step_slug |
|
1429 | + * @return bool|int |
|
1430 | + * @throws EE_Error |
|
1431 | + * @throws InvalidArgumentException |
|
1432 | + * @throws InvalidDataTypeException |
|
1433 | + * @throws InvalidInterfaceException |
|
1434 | + * @throws ReflectionException |
|
1435 | + */ |
|
1436 | + public function reg_step_completed($reg_step_slug) |
|
1437 | + { |
|
1438 | + return $this->_reg_steps_completed($reg_step_slug, false); |
|
1439 | + } |
|
1440 | + |
|
1441 | + |
|
1442 | + /** |
|
1443 | + * completed_final_reg_step |
|
1444 | + * returns: |
|
1445 | + * true if the finalize_registration reg step has been marked as completed |
|
1446 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
1447 | + * or false if it has not yet been initialized |
|
1448 | + * |
|
1449 | + * @return bool|int |
|
1450 | + * @throws EE_Error |
|
1451 | + * @throws InvalidArgumentException |
|
1452 | + * @throws InvalidDataTypeException |
|
1453 | + * @throws InvalidInterfaceException |
|
1454 | + * @throws ReflectionException |
|
1455 | + */ |
|
1456 | + public function final_reg_step_completed() |
|
1457 | + { |
|
1458 | + return $this->_reg_steps_completed('finalize_registration', false); |
|
1459 | + } |
|
1460 | + |
|
1461 | + |
|
1462 | + /** |
|
1463 | + * set_reg_step_initiated |
|
1464 | + * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
1465 | + * |
|
1466 | + * @param string $reg_step_slug |
|
1467 | + * @return boolean |
|
1468 | + * @throws EE_Error |
|
1469 | + * @throws InvalidArgumentException |
|
1470 | + * @throws InvalidDataTypeException |
|
1471 | + * @throws InvalidInterfaceException |
|
1472 | + * @throws ReflectionException |
|
1473 | + */ |
|
1474 | + public function set_reg_step_initiated($reg_step_slug) |
|
1475 | + { |
|
1476 | + return $this->_set_reg_step_completed_status($reg_step_slug, time()); |
|
1477 | + } |
|
1478 | + |
|
1479 | + |
|
1480 | + /** |
|
1481 | + * set_reg_step_completed |
|
1482 | + * given a valid TXN_reg_step, this sets the step as completed |
|
1483 | + * |
|
1484 | + * @param string $reg_step_slug |
|
1485 | + * @return boolean |
|
1486 | + * @throws EE_Error |
|
1487 | + * @throws InvalidArgumentException |
|
1488 | + * @throws InvalidDataTypeException |
|
1489 | + * @throws InvalidInterfaceException |
|
1490 | + * @throws ReflectionException |
|
1491 | + */ |
|
1492 | + public function set_reg_step_completed($reg_step_slug) |
|
1493 | + { |
|
1494 | + return $this->_set_reg_step_completed_status($reg_step_slug, true); |
|
1495 | + } |
|
1496 | + |
|
1497 | + |
|
1498 | + /** |
|
1499 | + * set_reg_step_completed |
|
1500 | + * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
1501 | + * |
|
1502 | + * @param string $reg_step_slug |
|
1503 | + * @return boolean |
|
1504 | + * @throws EE_Error |
|
1505 | + * @throws InvalidArgumentException |
|
1506 | + * @throws InvalidDataTypeException |
|
1507 | + * @throws InvalidInterfaceException |
|
1508 | + * @throws ReflectionException |
|
1509 | + */ |
|
1510 | + public function set_reg_step_not_completed($reg_step_slug) |
|
1511 | + { |
|
1512 | + return $this->_set_reg_step_completed_status($reg_step_slug, false); |
|
1513 | + } |
|
1514 | + |
|
1515 | + |
|
1516 | + /** |
|
1517 | + * set_reg_step_completed |
|
1518 | + * given a valid reg step slug, this sets the TXN_reg_step completed status which is either: |
|
1519 | + * |
|
1520 | + * @param string $reg_step_slug |
|
1521 | + * @param boolean|int $status |
|
1522 | + * @return boolean |
|
1523 | + * @throws EE_Error |
|
1524 | + * @throws InvalidArgumentException |
|
1525 | + * @throws InvalidDataTypeException |
|
1526 | + * @throws InvalidInterfaceException |
|
1527 | + * @throws ReflectionException |
|
1528 | + */ |
|
1529 | + private function _set_reg_step_completed_status($reg_step_slug, $status) |
|
1530 | + { |
|
1531 | + // validate status |
|
1532 | + $status = is_bool($status) || is_int($status) ? $status : false; |
|
1533 | + // get reg steps array |
|
1534 | + $txn_reg_steps = $this->reg_steps(); |
|
1535 | + // if reg step does NOT exist |
|
1536 | + if (! isset($txn_reg_steps[ $reg_step_slug ])) { |
|
1537 | + return false; |
|
1538 | + } |
|
1539 | + // if we're trying to complete a step that is already completed |
|
1540 | + if ($txn_reg_steps[ $reg_step_slug ] === true) { |
|
1541 | + return true; |
|
1542 | + } |
|
1543 | + // if we're trying to complete a step that hasn't even started |
|
1544 | + if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) { |
|
1545 | + return false; |
|
1546 | + } |
|
1547 | + // if current status value matches the incoming value (no change) |
|
1548 | + // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
|
1549 | + if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) { |
|
1550 | + // this will happen in cases where multiple AJAX requests occur during the same step |
|
1551 | + return true; |
|
1552 | + } |
|
1553 | + // if we're trying to set a start time, but it has already been set... |
|
1554 | + if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) { |
|
1555 | + // skip the update below, but don't return FALSE so that errors won't be displayed |
|
1556 | + return true; |
|
1557 | + } |
|
1558 | + // update completed status |
|
1559 | + $txn_reg_steps[ $reg_step_slug ] = $status; |
|
1560 | + $this->set_reg_steps($txn_reg_steps); |
|
1561 | + $this->save(); |
|
1562 | + return true; |
|
1563 | + } |
|
1564 | + |
|
1565 | + |
|
1566 | + /** |
|
1567 | + * remove_reg_step |
|
1568 | + * given a valid TXN_reg_step slug, this will remove (unset) |
|
1569 | + * the reg step from the TXN reg step array |
|
1570 | + * |
|
1571 | + * @param string $reg_step_slug |
|
1572 | + * @return void |
|
1573 | + * @throws EE_Error |
|
1574 | + * @throws InvalidArgumentException |
|
1575 | + * @throws InvalidDataTypeException |
|
1576 | + * @throws InvalidInterfaceException |
|
1577 | + * @throws ReflectionException |
|
1578 | + */ |
|
1579 | + public function remove_reg_step($reg_step_slug) |
|
1580 | + { |
|
1581 | + // get reg steps array |
|
1582 | + $txn_reg_steps = $this->reg_steps(); |
|
1583 | + unset($txn_reg_steps[ $reg_step_slug ]); |
|
1584 | + $this->set_reg_steps($txn_reg_steps); |
|
1585 | + } |
|
1586 | + |
|
1587 | + |
|
1588 | + /** |
|
1589 | + * toggle_failed_transaction_status |
|
1590 | + * upgrades a TXNs status from failed to abandoned, |
|
1591 | + * meaning that contact information has been captured for at least one registrant |
|
1592 | + * |
|
1593 | + * @param bool $save |
|
1594 | + * @return bool |
|
1595 | + * @throws EE_Error |
|
1596 | + * @throws InvalidArgumentException |
|
1597 | + * @throws InvalidDataTypeException |
|
1598 | + * @throws InvalidInterfaceException |
|
1599 | + * @throws ReflectionException |
|
1600 | + */ |
|
1601 | + public function toggle_failed_transaction_status($save = true) |
|
1602 | + { |
|
1603 | + // if TXN status is still set as "failed"... |
|
1604 | + if ($this->status_ID() === EEM_Transaction::failed_status_code) { |
|
1605 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1606 | + if ($save) { |
|
1607 | + $this->save(); |
|
1608 | + } |
|
1609 | + return true; |
|
1610 | + } |
|
1611 | + return false; |
|
1612 | + } |
|
1613 | + |
|
1614 | + |
|
1615 | + /** |
|
1616 | + * toggle_abandoned_transaction_status |
|
1617 | + * upgrades a TXNs status from failed or abandoned to incomplete |
|
1618 | + * |
|
1619 | + * @return bool |
|
1620 | + * @throws EE_Error |
|
1621 | + * @throws InvalidArgumentException |
|
1622 | + * @throws InvalidDataTypeException |
|
1623 | + * @throws InvalidInterfaceException |
|
1624 | + * @throws ReflectionException |
|
1625 | + */ |
|
1626 | + public function toggle_abandoned_transaction_status() |
|
1627 | + { |
|
1628 | + // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"... |
|
1629 | + $txn_status = $this->status_ID(); |
|
1630 | + if ($txn_status === EEM_Transaction::failed_status_code |
|
1631 | + || $txn_status === EEM_Transaction::abandoned_status_code |
|
1632 | + ) { |
|
1633 | + // if a contact record for the primary registrant has been created |
|
1634 | + if ($this->primary_registration() instanceof EE_Registration |
|
1635 | + && $this->primary_registration()->attendee() instanceof EE_Attendee |
|
1636 | + ) { |
|
1637 | + $this->set_status(EEM_Transaction::incomplete_status_code); |
|
1638 | + } else { |
|
1639 | + // no contact record? yer abandoned! |
|
1640 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1641 | + } |
|
1642 | + return true; |
|
1643 | + } |
|
1644 | + return false; |
|
1645 | + } |
|
1646 | + |
|
1647 | + |
|
1648 | + /** |
|
1649 | + * checks if an Abandoned TXN has any related payments, and if so, |
|
1650 | + * updates the TXN status based on the amount paid |
|
1651 | + * |
|
1652 | + * @throws EE_Error |
|
1653 | + * @throws InvalidDataTypeException |
|
1654 | + * @throws InvalidInterfaceException |
|
1655 | + * @throws InvalidArgumentException |
|
1656 | + * @throws RuntimeException |
|
1657 | + * @throws ReflectionException |
|
1658 | + */ |
|
1659 | + public function verify_abandoned_transaction_status() |
|
1660 | + { |
|
1661 | + if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) { |
|
1662 | + return; |
|
1663 | + } |
|
1664 | + $payments = $this->get_many_related('Payment'); |
|
1665 | + if (! empty($payments)) { |
|
1666 | + foreach ($payments as $payment) { |
|
1667 | + if ($payment instanceof EE_Payment) { |
|
1668 | + // kk this TXN should NOT be abandoned |
|
1669 | + $this->update_status_based_on_total_paid(); |
|
1670 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1671 | + EE_Error::add_attention( |
|
1672 | + sprintf( |
|
1673 | + esc_html__( |
|
1674 | + 'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.', |
|
1675 | + 'event_espresso' |
|
1676 | + ), |
|
1677 | + $this->ID(), |
|
1678 | + $this->pretty_status() |
|
1679 | + ) |
|
1680 | + ); |
|
1681 | + } |
|
1682 | + // get final reg step status |
|
1683 | + $finalized = $this->final_reg_step_completed(); |
|
1684 | + // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
1685 | + // but has not yet been fully completed (TRUE) |
|
1686 | + if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
1687 | + $this->set_reg_step_completed('finalize_registration'); |
|
1688 | + $this->save(); |
|
1689 | + } |
|
1690 | + } |
|
1691 | + } |
|
1692 | + } |
|
1693 | + } |
|
1694 | 1694 | } |
@@ -11,86 +11,86 @@ |
||
11 | 11 | { |
12 | 12 | |
13 | 13 | |
14 | - /** |
|
15 | - * Used to reference when a registration has been checked out. |
|
16 | - * |
|
17 | - * @type int |
|
18 | - */ |
|
19 | - const status_checked_out = 0; |
|
20 | - |
|
21 | - /** |
|
22 | - * Used to reference when a registration has been checked in. |
|
23 | - * |
|
24 | - * @type int |
|
25 | - */ |
|
26 | - const status_checked_in = 1; |
|
27 | - |
|
28 | - /** |
|
29 | - * Used to reference when a registration has never been checked in. |
|
30 | - * |
|
31 | - * @type int |
|
32 | - */ |
|
33 | - const status_checked_never = 2; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * |
|
38 | - * @param array $props_n_values incoming values |
|
39 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be used.) |
|
40 | - * @param array $date_formats incoming date_formats in an array |
|
41 | - * where the first value is the date_format |
|
42 | - * and the second value is the time format |
|
43 | - * @return EE_Checkin |
|
44 | - * @throws EE_Error |
|
45 | - */ |
|
46 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
47 | - { |
|
48 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
49 | - return $has_object |
|
50 | - ? $has_object |
|
51 | - : new self($props_n_values, false, $timezone, $date_formats); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param array $props_n_values incoming values from the database |
|
57 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
58 | - * the website will be used. |
|
59 | - * @return EE_Checkin |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
63 | - { |
|
64 | - return new self($props_n_values, true, $timezone); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - public function ID() |
|
69 | - { |
|
70 | - return $this->get('CHK_ID'); |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - public function registration_id() |
|
75 | - { |
|
76 | - return $this->get('REG_ID'); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - public function datetime_id() |
|
81 | - { |
|
82 | - return $this->get('DTT_ID'); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - public function status() |
|
87 | - { |
|
88 | - return $this->get('CHK_in'); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - public function timestamp() |
|
93 | - { |
|
94 | - return $this->get('CHK_timestamp'); |
|
95 | - } |
|
14 | + /** |
|
15 | + * Used to reference when a registration has been checked out. |
|
16 | + * |
|
17 | + * @type int |
|
18 | + */ |
|
19 | + const status_checked_out = 0; |
|
20 | + |
|
21 | + /** |
|
22 | + * Used to reference when a registration has been checked in. |
|
23 | + * |
|
24 | + * @type int |
|
25 | + */ |
|
26 | + const status_checked_in = 1; |
|
27 | + |
|
28 | + /** |
|
29 | + * Used to reference when a registration has never been checked in. |
|
30 | + * |
|
31 | + * @type int |
|
32 | + */ |
|
33 | + const status_checked_never = 2; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * |
|
38 | + * @param array $props_n_values incoming values |
|
39 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be used.) |
|
40 | + * @param array $date_formats incoming date_formats in an array |
|
41 | + * where the first value is the date_format |
|
42 | + * and the second value is the time format |
|
43 | + * @return EE_Checkin |
|
44 | + * @throws EE_Error |
|
45 | + */ |
|
46 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
47 | + { |
|
48 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
49 | + return $has_object |
|
50 | + ? $has_object |
|
51 | + : new self($props_n_values, false, $timezone, $date_formats); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param array $props_n_values incoming values from the database |
|
57 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
58 | + * the website will be used. |
|
59 | + * @return EE_Checkin |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
63 | + { |
|
64 | + return new self($props_n_values, true, $timezone); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + public function ID() |
|
69 | + { |
|
70 | + return $this->get('CHK_ID'); |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + public function registration_id() |
|
75 | + { |
|
76 | + return $this->get('REG_ID'); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + public function datetime_id() |
|
81 | + { |
|
82 | + return $this->get('DTT_ID'); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + public function status() |
|
87 | + { |
|
88 | + return $this->get('CHK_in'); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + public function timestamp() |
|
93 | + { |
|
94 | + return $this->get('CHK_timestamp'); |
|
95 | + } |
|
96 | 96 | } |
@@ -11,578 +11,578 @@ |
||
11 | 11 | class EE_Payment_Method extends EE_Base_Class |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Payment Method type object, which has all the info about this type of payment method, |
|
16 | - * including functions for processing payments, to get settings forms, etc. |
|
17 | - * |
|
18 | - * @var EE_PMT_Base |
|
19 | - */ |
|
20 | - protected $_type_obj; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * @param array $props_n_values |
|
25 | - * @return EE_Payment_Method |
|
26 | - * @throws \EE_Error |
|
27 | - */ |
|
28 | - public static function new_instance($props_n_values = array()) |
|
29 | - { |
|
30 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
31 | - return $has_object ? $has_object : new self($props_n_values, false); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @param array $props_n_values |
|
37 | - * @return EE_Payment_Method |
|
38 | - * @throws \EE_Error |
|
39 | - */ |
|
40 | - public static function new_instance_from_db($props_n_values = array()) |
|
41 | - { |
|
42 | - return new self($props_n_values, true); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
49 | - * Otherwise returns a normal EE_Payment_Method |
|
50 | - * |
|
51 | - * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
52 | - * the classname minus 'EEPM_') |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - // private static function _payment_method_type($props_n_values) |
|
56 | - // { |
|
57 | - // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
58 | - // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
59 | - // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
60 | - // return 'EEPM_' . $type_string; |
|
61 | - // } else { |
|
62 | - // return __CLASS__; |
|
63 | - // } |
|
64 | - // } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
69 | - * |
|
70 | - * @return boolean |
|
71 | - */ |
|
72 | - public function active() |
|
73 | - { |
|
74 | - return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
80 | - * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
81 | - * |
|
82 | - * @throws \EE_Error |
|
83 | - */ |
|
84 | - public function set_active() |
|
85 | - { |
|
86 | - $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
87 | - if ($this->type_obj() && |
|
88 | - $this->type_obj()->payment_occurs() === EE_PMT_Base::offline) { |
|
89 | - $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
90 | - } |
|
91 | - $this->set_scope($default_scopes); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
97 | - */ |
|
98 | - public function deactivate() |
|
99 | - { |
|
100 | - $this->set_scope(array()); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Gets button_url |
|
106 | - * |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function button_url() |
|
110 | - { |
|
111 | - return $this->get('PMD_button_url'); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * Sets button_url |
|
117 | - * |
|
118 | - * @param string $button_url |
|
119 | - */ |
|
120 | - public function set_button_url($button_url) |
|
121 | - { |
|
122 | - $this->set('PMD_button_url', $button_url); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Gets debug_mode |
|
128 | - * |
|
129 | - * @return boolean |
|
130 | - */ |
|
131 | - public function debug_mode() |
|
132 | - { |
|
133 | - return $this->get('PMD_debug_mode'); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Sets debug_mode |
|
139 | - * |
|
140 | - * @param boolean $debug_mode |
|
141 | - */ |
|
142 | - public function set_debug_mode($debug_mode) |
|
143 | - { |
|
144 | - $this->set('PMD_debug_mode', $debug_mode); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Gets description |
|
150 | - * |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public function description() |
|
154 | - { |
|
155 | - return $this->get('PMD_desc'); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Sets description |
|
161 | - * |
|
162 | - * @param string $description |
|
163 | - */ |
|
164 | - public function set_description($description) |
|
165 | - { |
|
166 | - $this->set('PMD_desc', $description); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Gets name |
|
172 | - * |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function name() |
|
176 | - { |
|
177 | - return $this->get('PMD_name'); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * Sets name |
|
183 | - * |
|
184 | - * @param string $name |
|
185 | - */ |
|
186 | - public function set_name($name) |
|
187 | - { |
|
188 | - $this->set('PMD_name', $name); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * Gets open_by_default |
|
194 | - * |
|
195 | - * @return boolean |
|
196 | - */ |
|
197 | - public function open_by_default() |
|
198 | - { |
|
199 | - return $this->get('PMD_open_by_default'); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Sets open_by_default |
|
205 | - * |
|
206 | - * @param boolean $open_by_default |
|
207 | - */ |
|
208 | - public function set_open_by_default($open_by_default) |
|
209 | - { |
|
210 | - $this->set('PMD_open_by_default', $open_by_default); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Gets order |
|
216 | - * |
|
217 | - * @return int |
|
218 | - */ |
|
219 | - public function order() |
|
220 | - { |
|
221 | - return $this->get('PMD_order'); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * Sets order |
|
227 | - * |
|
228 | - * @param int $order |
|
229 | - */ |
|
230 | - public function set_order($order) |
|
231 | - { |
|
232 | - $this->set('PMD_order', $order); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Gets slug |
|
238 | - * |
|
239 | - * @return string |
|
240 | - */ |
|
241 | - public function slug() |
|
242 | - { |
|
243 | - return $this->get('PMD_slug'); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Sets slug |
|
249 | - * |
|
250 | - * @param string $slug |
|
251 | - */ |
|
252 | - public function set_slug($slug) |
|
253 | - { |
|
254 | - $this->set('PMD_slug', $slug); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Gets type |
|
260 | - * |
|
261 | - * @return string |
|
262 | - */ |
|
263 | - public function type() |
|
264 | - { |
|
265 | - return $this->get('PMD_type'); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * Sets type |
|
271 | - * |
|
272 | - * @param string $type |
|
273 | - */ |
|
274 | - public function set_type($type) |
|
275 | - { |
|
276 | - $this->set('PMD_type', $type); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Gets wp_user |
|
282 | - * |
|
283 | - * @return int |
|
284 | - */ |
|
285 | - public function wp_user() |
|
286 | - { |
|
287 | - return $this->get('PMD_wp_user'); |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Sets wp_user |
|
293 | - * |
|
294 | - * @param int $wp_user_id |
|
295 | - */ |
|
296 | - public function set_wp_user($wp_user_id) |
|
297 | - { |
|
298 | - $this->set('PMD_wp_user', $wp_user_id); |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
303 | - * |
|
304 | - * @param string $field_name |
|
305 | - * @param mixed $field_value |
|
306 | - * @param boolean $use_default |
|
307 | - */ |
|
308 | - public function set($field_name, $field_value, $use_default = false) |
|
309 | - { |
|
310 | - if ($field_name === 'PMD_type') { |
|
311 | - // the type has probably changed, so forget about its old type object |
|
312 | - $this->_type_obj = null; |
|
313 | - } |
|
314 | - parent::set($field_name, $field_value, $use_default); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Gets admin_name |
|
320 | - * |
|
321 | - * @return string |
|
322 | - */ |
|
323 | - public function admin_name() |
|
324 | - { |
|
325 | - return $this->get('PMD_admin_name'); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Sets admin_name |
|
331 | - * |
|
332 | - * @param string $admin_name |
|
333 | - */ |
|
334 | - public function set_admin_name($admin_name) |
|
335 | - { |
|
336 | - $this->set('PMD_admin_name', $admin_name); |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * Gets admin_desc |
|
342 | - * |
|
343 | - * @return string |
|
344 | - */ |
|
345 | - public function admin_desc() |
|
346 | - { |
|
347 | - return $this->get('PMD_admin_desc'); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * Sets admin_desc |
|
353 | - * |
|
354 | - * @param string $admin_desc |
|
355 | - */ |
|
356 | - public function set_admin_desc($admin_desc) |
|
357 | - { |
|
358 | - $this->set('PMD_admin_desc', $admin_desc); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * Gets scope |
|
364 | - * |
|
365 | - * @return array |
|
366 | - */ |
|
367 | - public function scope() |
|
368 | - { |
|
369 | - return $this->get('PMD_scope'); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * Sets scope |
|
375 | - * |
|
376 | - * @param array $scope |
|
377 | - */ |
|
378 | - public function set_scope($scope) |
|
379 | - { |
|
380 | - $this->set('PMD_scope', $scope); |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * Gets the payment method type for this payment method instance |
|
386 | - * |
|
387 | - * @return EE_PMT_Base |
|
388 | - * @throws EE_Error |
|
389 | - */ |
|
390 | - public function type_obj() |
|
391 | - { |
|
392 | - if (! $this->_type_obj) { |
|
393 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
394 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
395 | - $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
396 | - if (! class_exists($class_name)) { |
|
397 | - throw new EE_Error( |
|
398 | - sprintf( |
|
399 | - __( |
|
400 | - 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
401 | - 'event_espresso' |
|
402 | - ), |
|
403 | - $class_name, |
|
404 | - '<br />', |
|
405 | - '<a href="' . admin_url('plugins.php') . '">', |
|
406 | - '</a>' |
|
407 | - ) |
|
408 | - ); |
|
409 | - } |
|
410 | - $r = new ReflectionClass($class_name); |
|
411 | - $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
412 | - } else { |
|
413 | - throw new EE_Error( |
|
414 | - sprintf( |
|
415 | - __( |
|
416 | - 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
417 | - 'event_espresso' |
|
418 | - ), |
|
419 | - $this->type(), |
|
420 | - implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
421 | - ) |
|
422 | - ); |
|
423 | - } |
|
424 | - } |
|
425 | - return $this->_type_obj; |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
431 | - * and the extra meta. Mostly used for passing off ot gateways. * |
|
432 | - * |
|
433 | - * @return array |
|
434 | - */ |
|
435 | - public function settings_array() |
|
436 | - { |
|
437 | - $fields = $this->model_field_array(); |
|
438 | - $extra_meta = $this->all_extra_meta_array(); |
|
439 | - // remove the model's prefix from the fields |
|
440 | - $combined_settings_array = array(); |
|
441 | - foreach ($fields as $key => $value) { |
|
442 | - if (strpos($key, 'PMD_') === 0) { |
|
443 | - $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
444 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
445 | - } |
|
446 | - } |
|
447 | - $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
448 | - return $combined_settings_array; |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * Gets the HTML for displaying the payment method on a page. |
|
454 | - * |
|
455 | - * @param string $url |
|
456 | - * @param string $css_class |
|
457 | - * @return string of HTML for displaying the button |
|
458 | - * @throws \EE_Error |
|
459 | - */ |
|
460 | - public function button_html($url = '', $css_class = '') |
|
461 | - { |
|
462 | - $payment_occurs = $this->type_obj()->payment_occurs(); |
|
463 | - return ' |
|
14 | + /** |
|
15 | + * Payment Method type object, which has all the info about this type of payment method, |
|
16 | + * including functions for processing payments, to get settings forms, etc. |
|
17 | + * |
|
18 | + * @var EE_PMT_Base |
|
19 | + */ |
|
20 | + protected $_type_obj; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * @param array $props_n_values |
|
25 | + * @return EE_Payment_Method |
|
26 | + * @throws \EE_Error |
|
27 | + */ |
|
28 | + public static function new_instance($props_n_values = array()) |
|
29 | + { |
|
30 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
31 | + return $has_object ? $has_object : new self($props_n_values, false); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @param array $props_n_values |
|
37 | + * @return EE_Payment_Method |
|
38 | + * @throws \EE_Error |
|
39 | + */ |
|
40 | + public static function new_instance_from_db($props_n_values = array()) |
|
41 | + { |
|
42 | + return new self($props_n_values, true); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
49 | + * Otherwise returns a normal EE_Payment_Method |
|
50 | + * |
|
51 | + * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
52 | + * the classname minus 'EEPM_') |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + // private static function _payment_method_type($props_n_values) |
|
56 | + // { |
|
57 | + // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
58 | + // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
59 | + // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
60 | + // return 'EEPM_' . $type_string; |
|
61 | + // } else { |
|
62 | + // return __CLASS__; |
|
63 | + // } |
|
64 | + // } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
69 | + * |
|
70 | + * @return boolean |
|
71 | + */ |
|
72 | + public function active() |
|
73 | + { |
|
74 | + return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
80 | + * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
81 | + * |
|
82 | + * @throws \EE_Error |
|
83 | + */ |
|
84 | + public function set_active() |
|
85 | + { |
|
86 | + $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
87 | + if ($this->type_obj() && |
|
88 | + $this->type_obj()->payment_occurs() === EE_PMT_Base::offline) { |
|
89 | + $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
90 | + } |
|
91 | + $this->set_scope($default_scopes); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
97 | + */ |
|
98 | + public function deactivate() |
|
99 | + { |
|
100 | + $this->set_scope(array()); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Gets button_url |
|
106 | + * |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function button_url() |
|
110 | + { |
|
111 | + return $this->get('PMD_button_url'); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * Sets button_url |
|
117 | + * |
|
118 | + * @param string $button_url |
|
119 | + */ |
|
120 | + public function set_button_url($button_url) |
|
121 | + { |
|
122 | + $this->set('PMD_button_url', $button_url); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Gets debug_mode |
|
128 | + * |
|
129 | + * @return boolean |
|
130 | + */ |
|
131 | + public function debug_mode() |
|
132 | + { |
|
133 | + return $this->get('PMD_debug_mode'); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Sets debug_mode |
|
139 | + * |
|
140 | + * @param boolean $debug_mode |
|
141 | + */ |
|
142 | + public function set_debug_mode($debug_mode) |
|
143 | + { |
|
144 | + $this->set('PMD_debug_mode', $debug_mode); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Gets description |
|
150 | + * |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public function description() |
|
154 | + { |
|
155 | + return $this->get('PMD_desc'); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Sets description |
|
161 | + * |
|
162 | + * @param string $description |
|
163 | + */ |
|
164 | + public function set_description($description) |
|
165 | + { |
|
166 | + $this->set('PMD_desc', $description); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Gets name |
|
172 | + * |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function name() |
|
176 | + { |
|
177 | + return $this->get('PMD_name'); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * Sets name |
|
183 | + * |
|
184 | + * @param string $name |
|
185 | + */ |
|
186 | + public function set_name($name) |
|
187 | + { |
|
188 | + $this->set('PMD_name', $name); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * Gets open_by_default |
|
194 | + * |
|
195 | + * @return boolean |
|
196 | + */ |
|
197 | + public function open_by_default() |
|
198 | + { |
|
199 | + return $this->get('PMD_open_by_default'); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Sets open_by_default |
|
205 | + * |
|
206 | + * @param boolean $open_by_default |
|
207 | + */ |
|
208 | + public function set_open_by_default($open_by_default) |
|
209 | + { |
|
210 | + $this->set('PMD_open_by_default', $open_by_default); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Gets order |
|
216 | + * |
|
217 | + * @return int |
|
218 | + */ |
|
219 | + public function order() |
|
220 | + { |
|
221 | + return $this->get('PMD_order'); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * Sets order |
|
227 | + * |
|
228 | + * @param int $order |
|
229 | + */ |
|
230 | + public function set_order($order) |
|
231 | + { |
|
232 | + $this->set('PMD_order', $order); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Gets slug |
|
238 | + * |
|
239 | + * @return string |
|
240 | + */ |
|
241 | + public function slug() |
|
242 | + { |
|
243 | + return $this->get('PMD_slug'); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Sets slug |
|
249 | + * |
|
250 | + * @param string $slug |
|
251 | + */ |
|
252 | + public function set_slug($slug) |
|
253 | + { |
|
254 | + $this->set('PMD_slug', $slug); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Gets type |
|
260 | + * |
|
261 | + * @return string |
|
262 | + */ |
|
263 | + public function type() |
|
264 | + { |
|
265 | + return $this->get('PMD_type'); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * Sets type |
|
271 | + * |
|
272 | + * @param string $type |
|
273 | + */ |
|
274 | + public function set_type($type) |
|
275 | + { |
|
276 | + $this->set('PMD_type', $type); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Gets wp_user |
|
282 | + * |
|
283 | + * @return int |
|
284 | + */ |
|
285 | + public function wp_user() |
|
286 | + { |
|
287 | + return $this->get('PMD_wp_user'); |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Sets wp_user |
|
293 | + * |
|
294 | + * @param int $wp_user_id |
|
295 | + */ |
|
296 | + public function set_wp_user($wp_user_id) |
|
297 | + { |
|
298 | + $this->set('PMD_wp_user', $wp_user_id); |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
303 | + * |
|
304 | + * @param string $field_name |
|
305 | + * @param mixed $field_value |
|
306 | + * @param boolean $use_default |
|
307 | + */ |
|
308 | + public function set($field_name, $field_value, $use_default = false) |
|
309 | + { |
|
310 | + if ($field_name === 'PMD_type') { |
|
311 | + // the type has probably changed, so forget about its old type object |
|
312 | + $this->_type_obj = null; |
|
313 | + } |
|
314 | + parent::set($field_name, $field_value, $use_default); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Gets admin_name |
|
320 | + * |
|
321 | + * @return string |
|
322 | + */ |
|
323 | + public function admin_name() |
|
324 | + { |
|
325 | + return $this->get('PMD_admin_name'); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Sets admin_name |
|
331 | + * |
|
332 | + * @param string $admin_name |
|
333 | + */ |
|
334 | + public function set_admin_name($admin_name) |
|
335 | + { |
|
336 | + $this->set('PMD_admin_name', $admin_name); |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * Gets admin_desc |
|
342 | + * |
|
343 | + * @return string |
|
344 | + */ |
|
345 | + public function admin_desc() |
|
346 | + { |
|
347 | + return $this->get('PMD_admin_desc'); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * Sets admin_desc |
|
353 | + * |
|
354 | + * @param string $admin_desc |
|
355 | + */ |
|
356 | + public function set_admin_desc($admin_desc) |
|
357 | + { |
|
358 | + $this->set('PMD_admin_desc', $admin_desc); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * Gets scope |
|
364 | + * |
|
365 | + * @return array |
|
366 | + */ |
|
367 | + public function scope() |
|
368 | + { |
|
369 | + return $this->get('PMD_scope'); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * Sets scope |
|
375 | + * |
|
376 | + * @param array $scope |
|
377 | + */ |
|
378 | + public function set_scope($scope) |
|
379 | + { |
|
380 | + $this->set('PMD_scope', $scope); |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * Gets the payment method type for this payment method instance |
|
386 | + * |
|
387 | + * @return EE_PMT_Base |
|
388 | + * @throws EE_Error |
|
389 | + */ |
|
390 | + public function type_obj() |
|
391 | + { |
|
392 | + if (! $this->_type_obj) { |
|
393 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
394 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
395 | + $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
396 | + if (! class_exists($class_name)) { |
|
397 | + throw new EE_Error( |
|
398 | + sprintf( |
|
399 | + __( |
|
400 | + 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
401 | + 'event_espresso' |
|
402 | + ), |
|
403 | + $class_name, |
|
404 | + '<br />', |
|
405 | + '<a href="' . admin_url('plugins.php') . '">', |
|
406 | + '</a>' |
|
407 | + ) |
|
408 | + ); |
|
409 | + } |
|
410 | + $r = new ReflectionClass($class_name); |
|
411 | + $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
412 | + } else { |
|
413 | + throw new EE_Error( |
|
414 | + sprintf( |
|
415 | + __( |
|
416 | + 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
417 | + 'event_espresso' |
|
418 | + ), |
|
419 | + $this->type(), |
|
420 | + implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
421 | + ) |
|
422 | + ); |
|
423 | + } |
|
424 | + } |
|
425 | + return $this->_type_obj; |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
431 | + * and the extra meta. Mostly used for passing off ot gateways. * |
|
432 | + * |
|
433 | + * @return array |
|
434 | + */ |
|
435 | + public function settings_array() |
|
436 | + { |
|
437 | + $fields = $this->model_field_array(); |
|
438 | + $extra_meta = $this->all_extra_meta_array(); |
|
439 | + // remove the model's prefix from the fields |
|
440 | + $combined_settings_array = array(); |
|
441 | + foreach ($fields as $key => $value) { |
|
442 | + if (strpos($key, 'PMD_') === 0) { |
|
443 | + $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
444 | + $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
445 | + } |
|
446 | + } |
|
447 | + $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
448 | + return $combined_settings_array; |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * Gets the HTML for displaying the payment method on a page. |
|
454 | + * |
|
455 | + * @param string $url |
|
456 | + * @param string $css_class |
|
457 | + * @return string of HTML for displaying the button |
|
458 | + * @throws \EE_Error |
|
459 | + */ |
|
460 | + public function button_html($url = '', $css_class = '') |
|
461 | + { |
|
462 | + $payment_occurs = $this->type_obj()->payment_occurs(); |
|
463 | + return ' |
|
464 | 464 | <div id="' |
465 | - . $this->slug() |
|
466 | - . '-payment-option-dv" class="' |
|
467 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
465 | + . $this->slug() |
|
466 | + . '-payment-option-dv" class="' |
|
467 | + . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
468 | 468 | <a id="payment-gateway-button-' . $this->slug() |
469 | - . '" class="reg-page-payment-option-lnk" rel="' |
|
470 | - . $this->slug() . '" href="' . $url . '" > |
|
469 | + . '" class="reg-page-payment-option-lnk" rel="' |
|
470 | + . $this->slug() . '" href="' . $url . '" > |
|
471 | 471 | <img src="' . $this->button_url() . '" alt="' . sprintf( |
472 | - esc_attr__('Pay using %s', 'event_espresso'), |
|
473 | - $this->get_pretty('PMD_name', 'form_input') |
|
474 | - ) . '" /> |
|
472 | + esc_attr__('Pay using %s', 'event_espresso'), |
|
473 | + $this->get_pretty('PMD_name', 'form_input') |
|
474 | + ) . '" /> |
|
475 | 475 | </a> |
476 | 476 | </div> |
477 | 477 | '; |
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * Gets all the currencies which are an option for this payment method |
|
483 | - * (as defined by the gateway and the currently active currencies) |
|
484 | - * |
|
485 | - * @return EE_Currency[] |
|
486 | - * @throws \EE_Error |
|
487 | - */ |
|
488 | - public function get_all_usable_currencies() |
|
489 | - { |
|
490 | - return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * Reports whether or not this payment method can be used for this payment method |
|
496 | - * |
|
497 | - * @param string $currency_code currency ID (code) |
|
498 | - * @return boolean |
|
499 | - * @throws \EE_Error |
|
500 | - */ |
|
501 | - public function usable_for_currency($currency_code) |
|
502 | - { |
|
503 | - foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
504 | - if ($currency_obj->ID() === $currency_code) { |
|
505 | - return true; |
|
506 | - } |
|
507 | - } |
|
508 | - return false; |
|
509 | - } |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
514 | - * |
|
515 | - * @return bool |
|
516 | - * @throws \EE_Error |
|
517 | - */ |
|
518 | - public function is_on_site() |
|
519 | - { |
|
520 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
526 | - * |
|
527 | - * @return bool |
|
528 | - * @throws \EE_Error |
|
529 | - */ |
|
530 | - public function is_off_site() |
|
531 | - { |
|
532 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
533 | - } |
|
534 | - |
|
535 | - |
|
536 | - /** |
|
537 | - * Returns TRUE if this payment method does not utilize a gateway |
|
538 | - * |
|
539 | - * @return bool |
|
540 | - * @throws \EE_Error |
|
541 | - */ |
|
542 | - public function is_off_line() |
|
543 | - { |
|
544 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Overrides default __sleep so the object type is NOT cached. |
|
549 | - * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
550 | - * to load the required classes, and don't need them at the time of unserialization |
|
551 | - * |
|
552 | - * @return array |
|
553 | - */ |
|
554 | - public function __sleep() |
|
555 | - { |
|
556 | - $properties = get_object_vars($this); |
|
557 | - unset($properties['_type_obj']); |
|
558 | - return array_keys($properties); |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * Overrides parent to add some logging for when payment methods get deactivated |
|
564 | - * |
|
565 | - * @param array $set_cols_n_values |
|
566 | - * @return int @see EE_Base_Class::save() |
|
567 | - * @throws \EE_Error |
|
568 | - */ |
|
569 | - public function save($set_cols_n_values = array()) |
|
570 | - { |
|
571 | - $results = parent::save($set_cols_n_values); |
|
572 | - if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
573 | - EE_Log::instance()->log( |
|
574 | - __FILE__, |
|
575 | - __FUNCTION__, |
|
576 | - sprintf( |
|
577 | - __('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
578 | - $this->name(), |
|
579 | - serialize($this->get_original('PMD_scope')), |
|
580 | - serialize($this->get('PMD_scope')), |
|
581 | - EE_Registry::instance()->REQ->get_current_page_permalink() |
|
582 | - ), |
|
583 | - 'payment_method_change' |
|
584 | - ); |
|
585 | - } |
|
586 | - return $results; |
|
587 | - } |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * Gets all the currencies which are an option for this payment method |
|
483 | + * (as defined by the gateway and the currently active currencies) |
|
484 | + * |
|
485 | + * @return EE_Currency[] |
|
486 | + * @throws \EE_Error |
|
487 | + */ |
|
488 | + public function get_all_usable_currencies() |
|
489 | + { |
|
490 | + return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * Reports whether or not this payment method can be used for this payment method |
|
496 | + * |
|
497 | + * @param string $currency_code currency ID (code) |
|
498 | + * @return boolean |
|
499 | + * @throws \EE_Error |
|
500 | + */ |
|
501 | + public function usable_for_currency($currency_code) |
|
502 | + { |
|
503 | + foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
504 | + if ($currency_obj->ID() === $currency_code) { |
|
505 | + return true; |
|
506 | + } |
|
507 | + } |
|
508 | + return false; |
|
509 | + } |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
514 | + * |
|
515 | + * @return bool |
|
516 | + * @throws \EE_Error |
|
517 | + */ |
|
518 | + public function is_on_site() |
|
519 | + { |
|
520 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
526 | + * |
|
527 | + * @return bool |
|
528 | + * @throws \EE_Error |
|
529 | + */ |
|
530 | + public function is_off_site() |
|
531 | + { |
|
532 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
533 | + } |
|
534 | + |
|
535 | + |
|
536 | + /** |
|
537 | + * Returns TRUE if this payment method does not utilize a gateway |
|
538 | + * |
|
539 | + * @return bool |
|
540 | + * @throws \EE_Error |
|
541 | + */ |
|
542 | + public function is_off_line() |
|
543 | + { |
|
544 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Overrides default __sleep so the object type is NOT cached. |
|
549 | + * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
550 | + * to load the required classes, and don't need them at the time of unserialization |
|
551 | + * |
|
552 | + * @return array |
|
553 | + */ |
|
554 | + public function __sleep() |
|
555 | + { |
|
556 | + $properties = get_object_vars($this); |
|
557 | + unset($properties['_type_obj']); |
|
558 | + return array_keys($properties); |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * Overrides parent to add some logging for when payment methods get deactivated |
|
564 | + * |
|
565 | + * @param array $set_cols_n_values |
|
566 | + * @return int @see EE_Base_Class::save() |
|
567 | + * @throws \EE_Error |
|
568 | + */ |
|
569 | + public function save($set_cols_n_values = array()) |
|
570 | + { |
|
571 | + $results = parent::save($set_cols_n_values); |
|
572 | + if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
573 | + EE_Log::instance()->log( |
|
574 | + __FILE__, |
|
575 | + __FUNCTION__, |
|
576 | + sprintf( |
|
577 | + __('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
578 | + $this->name(), |
|
579 | + serialize($this->get_original('PMD_scope')), |
|
580 | + serialize($this->get('PMD_scope')), |
|
581 | + EE_Registry::instance()->REQ->get_current_page_permalink() |
|
582 | + ), |
|
583 | + 'payment_method_change' |
|
584 | + ); |
|
585 | + } |
|
586 | + return $results; |
|
587 | + } |
|
588 | 588 | } |
@@ -389,11 +389,11 @@ discard block |
||
389 | 389 | */ |
390 | 390 | public function type_obj() |
391 | 391 | { |
392 | - if (! $this->_type_obj) { |
|
392 | + if ( ! $this->_type_obj) { |
|
393 | 393 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
394 | 394 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
395 | 395 | $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
396 | - if (! class_exists($class_name)) { |
|
396 | + if ( ! class_exists($class_name)) { |
|
397 | 397 | throw new EE_Error( |
398 | 398 | sprintf( |
399 | 399 | __( |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | ), |
403 | 403 | $class_name, |
404 | 404 | '<br />', |
405 | - '<a href="' . admin_url('plugins.php') . '">', |
|
405 | + '<a href="'.admin_url('plugins.php').'">', |
|
406 | 406 | '</a>' |
407 | 407 | ) |
408 | 408 | ); |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | foreach ($fields as $key => $value) { |
442 | 442 | if (strpos($key, 'PMD_') === 0) { |
443 | 443 | $key_sans_model_prefix = str_replace('PMD_', '', $key); |
444 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
444 | + $combined_settings_array [$key_sans_model_prefix] = $value; |
|
445 | 445 | } |
446 | 446 | } |
447 | 447 | $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
@@ -464,14 +464,14 @@ discard block |
||
464 | 464 | <div id="' |
465 | 465 | . $this->slug() |
466 | 466 | . '-payment-option-dv" class="' |
467 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
467 | + . $payment_occurs.'-payment-gateway reg-page-payment-option-dv'.$css_class.'"> |
|
468 | 468 | <a id="payment-gateway-button-' . $this->slug() |
469 | 469 | . '" class="reg-page-payment-option-lnk" rel="' |
470 | - . $this->slug() . '" href="' . $url . '" > |
|
471 | - <img src="' . $this->button_url() . '" alt="' . sprintf( |
|
470 | + . $this->slug().'" href="'.$url.'" > |
|
471 | + <img src="' . $this->button_url().'" alt="'.sprintf( |
|
472 | 472 | esc_attr__('Pay using %s', 'event_espresso'), |
473 | 473 | $this->get_pretty('PMD_name', 'form_input') |
474 | - ) . '" /> |
|
474 | + ).'" /> |
|
475 | 475 | </a> |
476 | 476 | </div> |
477 | 477 | '; |
@@ -6,23 +6,23 @@ |
||
6 | 6 | class EE_Event_Venue extends EE_Base_Class |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @param array $props_n_values |
|
11 | - * @return EE_Event_Venue|mixed |
|
12 | - */ |
|
13 | - public static function new_instance($props_n_values = array()) |
|
14 | - { |
|
15 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
16 | - return $has_object ? $has_object : new self($props_n_values); |
|
17 | - } |
|
9 | + /** |
|
10 | + * @param array $props_n_values |
|
11 | + * @return EE_Event_Venue|mixed |
|
12 | + */ |
|
13 | + public static function new_instance($props_n_values = array()) |
|
14 | + { |
|
15 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
16 | + return $has_object ? $has_object : new self($props_n_values); |
|
17 | + } |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @param array $props_n_values |
|
22 | - * @return EE_Event_Venue |
|
23 | - */ |
|
24 | - public static function new_instance_from_db($props_n_values = array()) |
|
25 | - { |
|
26 | - return new self($props_n_values, true); |
|
27 | - } |
|
20 | + /** |
|
21 | + * @param array $props_n_values |
|
22 | + * @return EE_Event_Venue |
|
23 | + */ |
|
24 | + public static function new_instance_from_db($props_n_values = array()) |
|
25 | + { |
|
26 | + return new self($props_n_values, true); |
|
27 | + } |
|
28 | 28 | } |
@@ -12,53 +12,53 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * Overrides parent _delete() so that we do soft deletes. |
|
17 | - * |
|
18 | - * @return bool|int |
|
19 | - */ |
|
20 | - protected function _delete() |
|
21 | - { |
|
22 | - return $this->delete_or_restore(); |
|
23 | - } |
|
15 | + /** |
|
16 | + * Overrides parent _delete() so that we do soft deletes. |
|
17 | + * |
|
18 | + * @return bool|int |
|
19 | + */ |
|
20 | + protected function _delete() |
|
21 | + { |
|
22 | + return $this->delete_or_restore(); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Deletes or restores this object. |
|
28 | - * |
|
29 | - * @param bool $delete true=>delete, false=>restore |
|
30 | - * @return bool|int |
|
31 | - */ |
|
32 | - public function delete_or_restore($delete = true) |
|
33 | - { |
|
34 | - /** |
|
35 | - * Called just before trashing (soft delete) or restoring a trashed item. |
|
36 | - * |
|
37 | - * @param EE_Base_Class $model_object about to be trashed or restored |
|
38 | - * @param bool $delete true the item is being trashed, false the item is being restored. |
|
39 | - */ |
|
40 | - do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__before', $this, $delete); |
|
41 | - $model = $this->get_model(); |
|
42 | - $result = $model->delete_or_restore_by_ID($delete, $this->ID()); |
|
43 | - /** |
|
44 | - * Called just after trashing (soft delete) or restoring a trashed item. |
|
45 | - * |
|
46 | - * @param EE_Base_Class $model_object that was just trashed or restored. |
|
47 | - * @param bool $delete true the item is being trashed, false the item is being restored. |
|
48 | - * @param bool|int $result |
|
49 | - */ |
|
50 | - do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', $this, $delete, $result); |
|
51 | - return $result; |
|
52 | - } |
|
26 | + /** |
|
27 | + * Deletes or restores this object. |
|
28 | + * |
|
29 | + * @param bool $delete true=>delete, false=>restore |
|
30 | + * @return bool|int |
|
31 | + */ |
|
32 | + public function delete_or_restore($delete = true) |
|
33 | + { |
|
34 | + /** |
|
35 | + * Called just before trashing (soft delete) or restoring a trashed item. |
|
36 | + * |
|
37 | + * @param EE_Base_Class $model_object about to be trashed or restored |
|
38 | + * @param bool $delete true the item is being trashed, false the item is being restored. |
|
39 | + */ |
|
40 | + do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__before', $this, $delete); |
|
41 | + $model = $this->get_model(); |
|
42 | + $result = $model->delete_or_restore_by_ID($delete, $this->ID()); |
|
43 | + /** |
|
44 | + * Called just after trashing (soft delete) or restoring a trashed item. |
|
45 | + * |
|
46 | + * @param EE_Base_Class $model_object that was just trashed or restored. |
|
47 | + * @param bool $delete true the item is being trashed, false the item is being restored. |
|
48 | + * @param bool|int $result |
|
49 | + */ |
|
50 | + do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', $this, $delete, $result); |
|
51 | + return $result; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Performs a restoration (un-deletes) this object |
|
57 | - * |
|
58 | - * @return bool|int |
|
59 | - */ |
|
60 | - public function restore() |
|
61 | - { |
|
62 | - return $this->delete_or_restore(false); |
|
63 | - } |
|
55 | + /** |
|
56 | + * Performs a restoration (un-deletes) this object |
|
57 | + * |
|
58 | + * @return bool|int |
|
59 | + */ |
|
60 | + public function restore() |
|
61 | + { |
|
62 | + return $this->delete_or_restore(false); |
|
63 | + } |
|
64 | 64 | } |
@@ -6,23 +6,23 @@ |
||
6 | 6 | class EE_Event_Question_Group extends EE_Base_Class |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @param array $props_n_values |
|
11 | - * @return EE_Event_Question_Group|mixed |
|
12 | - */ |
|
13 | - public static function new_instance($props_n_values = array()) |
|
14 | - { |
|
15 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
16 | - return $has_object ? $has_object : new self($props_n_values); |
|
17 | - } |
|
9 | + /** |
|
10 | + * @param array $props_n_values |
|
11 | + * @return EE_Event_Question_Group|mixed |
|
12 | + */ |
|
13 | + public static function new_instance($props_n_values = array()) |
|
14 | + { |
|
15 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
16 | + return $has_object ? $has_object : new self($props_n_values); |
|
17 | + } |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @param array $props_n_values |
|
22 | - * @return EE_Event_Question_Group |
|
23 | - */ |
|
24 | - public static function new_instance_from_db($props_n_values = array()) |
|
25 | - { |
|
26 | - return new self($props_n_values, true); |
|
27 | - } |
|
20 | + /** |
|
21 | + * @param array $props_n_values |
|
22 | + * @return EE_Event_Question_Group |
|
23 | + */ |
|
24 | + public static function new_instance_from_db($props_n_values = array()) |
|
25 | + { |
|
26 | + return new self($props_n_values, true); |
|
27 | + } |
|
28 | 28 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | */ |
297 | 297 | public function timestamp($dt_frmt = '', $tm_frmt = '') |
298 | 298 | { |
299 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
299 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt.' '.$tm_frmt)); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | : ''; |
482 | 482 | break; |
483 | 483 | } |
484 | - return $icon . $status[ $this->STS_ID() ]; |
|
484 | + return $icon.$status[$this->STS_ID()]; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | public function redirect_form($inside_form_html = null) |
628 | 628 | { |
629 | 629 | $redirect_url = $this->redirect_url(); |
630 | - if (! empty($redirect_url)) { |
|
630 | + if ( ! empty($redirect_url)) { |
|
631 | 631 | // what ? no inner form content? |
632 | 632 | if ($inside_form_html === null) { |
633 | 633 | $inside_form_html = EEH_HTML::p( |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | $get_params = null; |
658 | 658 | parse_str($querystring, $get_params); |
659 | 659 | $inside_form_html .= $this->_args_as_inputs($get_params); |
660 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
660 | + $redirect_url = str_replace('?'.$querystring, '', $redirect_url); |
|
661 | 661 | } |
662 | 662 | $form = EEH_HTML::nl(1) |
663 | 663 | . '<form method="' |
@@ -665,9 +665,9 @@ discard block |
||
665 | 665 | . '" name="gateway_form" action="' |
666 | 666 | . $redirect_url |
667 | 667 | . '">'; |
668 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
668 | + $form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs(); |
|
669 | 669 | $form .= $inside_form_html; |
670 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
670 | + $form .= EEH_HTML::nl(-1).'</form>'.EEH_HTML::nl(-1); |
|
671 | 671 | return $form; |
672 | 672 | } else { |
673 | 673 | return null; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @param array $props_n_values incoming values |
14 | 14 | * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
15 | 15 | * used.) |
16 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
16 | + * @param string[] $date_formats incoming date_formats in an array where the first value is the |
|
17 | 17 | * date_format and the second value is the time format |
18 | 18 | * @return EE_Payment |
19 | 19 | * @throws \EE_Error |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | * Gets all the extra meta info on this payment |
589 | 589 | * |
590 | 590 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
591 | - * @return EE_Extra_Meta |
|
591 | + * @return EE_Base_Class[] |
|
592 | 592 | * @throws \EE_Error |
593 | 593 | */ |
594 | 594 | public function extra_meta($query_params = array()) |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | /** |
837 | 837 | * Returns the payment's transaction's primary registration |
838 | 838 | * |
839 | - * @return EE_Registration|null |
|
839 | + * @return EE_Base_Class|null |
|
840 | 840 | */ |
841 | 841 | public function get_primary_registration() |
842 | 842 | { |
@@ -9,855 +9,855 @@ |
||
9 | 9 | class EE_Payment extends EE_Base_Class implements EEI_Payment |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @param array $props_n_values incoming values |
|
14 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
15 | - * used.) |
|
16 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
17 | - * date_format and the second value is the time format |
|
18 | - * @return EE_Payment |
|
19 | - * @throws \EE_Error |
|
20 | - */ |
|
21 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
22 | - { |
|
23 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
24 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
25 | - } |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @param array $props_n_values incoming values from the database |
|
30 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
31 | - * the website will be used. |
|
32 | - * @return EE_Payment |
|
33 | - * @throws \EE_Error |
|
34 | - */ |
|
35 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
36 | - { |
|
37 | - return new self($props_n_values, true, $timezone); |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Set Transaction ID |
|
43 | - * |
|
44 | - * @access public |
|
45 | - * @param int $TXN_ID |
|
46 | - * @throws \EE_Error |
|
47 | - */ |
|
48 | - public function set_transaction_id($TXN_ID = 0) |
|
49 | - { |
|
50 | - $this->set('TXN_ID', $TXN_ID); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Gets the transaction related to this payment |
|
56 | - * |
|
57 | - * @return EE_Transaction |
|
58 | - * @throws \EE_Error |
|
59 | - */ |
|
60 | - public function transaction() |
|
61 | - { |
|
62 | - return $this->get_first_related('Transaction'); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Set Status |
|
68 | - * |
|
69 | - * @access public |
|
70 | - * @param string $STS_ID |
|
71 | - * @throws \EE_Error |
|
72 | - */ |
|
73 | - public function set_status($STS_ID = '') |
|
74 | - { |
|
75 | - $this->set('STS_ID', $STS_ID); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Set Payment Timestamp |
|
81 | - * |
|
82 | - * @access public |
|
83 | - * @param int $timestamp |
|
84 | - * @throws \EE_Error |
|
85 | - */ |
|
86 | - public function set_timestamp($timestamp = 0) |
|
87 | - { |
|
88 | - $this->set('PAY_timestamp', $timestamp); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Set Payment Method |
|
94 | - * |
|
95 | - * @access public |
|
96 | - * @param string $PAY_source |
|
97 | - * @throws \EE_Error |
|
98 | - */ |
|
99 | - public function set_source($PAY_source = '') |
|
100 | - { |
|
101 | - $this->set('PAY_source', $PAY_source); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * Set Payment Amount |
|
107 | - * |
|
108 | - * @access public |
|
109 | - * @param float $amount |
|
110 | - * @throws \EE_Error |
|
111 | - */ |
|
112 | - public function set_amount($amount = 0.00) |
|
113 | - { |
|
114 | - $this->set('PAY_amount', (float) $amount); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Set Payment Gateway Response |
|
120 | - * |
|
121 | - * @access public |
|
122 | - * @param string $gateway_response |
|
123 | - * @throws \EE_Error |
|
124 | - */ |
|
125 | - public function set_gateway_response($gateway_response = '') |
|
126 | - { |
|
127 | - $this->set('PAY_gateway_response', $gateway_response); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
133 | - * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
134 | - * used on it |
|
135 | - * |
|
136 | - * @deprecated |
|
137 | - * @return string |
|
138 | - * @throws \EE_Error |
|
139 | - */ |
|
140 | - public function gateway() |
|
141 | - { |
|
142 | - EE_Error::doing_it_wrong( |
|
143 | - 'EE_Payment::gateway', |
|
144 | - __( |
|
145 | - 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
146 | - 'event_espresso' |
|
147 | - ), |
|
148 | - '4.6.0' |
|
149 | - ); |
|
150 | - return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * Set Gateway Transaction ID |
|
156 | - * |
|
157 | - * @access public |
|
158 | - * @param string $txn_id_chq_nmbr |
|
159 | - * @throws \EE_Error |
|
160 | - */ |
|
161 | - public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
162 | - { |
|
163 | - $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Set Purchase Order Number |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @param string $po_number |
|
172 | - * @throws \EE_Error |
|
173 | - */ |
|
174 | - public function set_po_number($po_number = '') |
|
175 | - { |
|
176 | - $this->set('PAY_po_number', $po_number); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Set Extra Accounting Field |
|
182 | - * |
|
183 | - * @access public |
|
184 | - * @param string $extra_accntng |
|
185 | - * @throws \EE_Error |
|
186 | - */ |
|
187 | - public function set_extra_accntng($extra_accntng = '') |
|
188 | - { |
|
189 | - $this->set('PAY_extra_accntng', $extra_accntng); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * Set Payment made via admin flag |
|
195 | - * |
|
196 | - * @access public |
|
197 | - * @param bool $via_admin |
|
198 | - * @throws \EE_Error |
|
199 | - */ |
|
200 | - public function set_payment_made_via_admin($via_admin = false) |
|
201 | - { |
|
202 | - if ($via_admin) { |
|
203 | - $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
204 | - } else { |
|
205 | - $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Set Payment Details |
|
212 | - * |
|
213 | - * @access public |
|
214 | - * @param string|array $details |
|
215 | - * @throws \EE_Error |
|
216 | - */ |
|
217 | - public function set_details($details = '') |
|
218 | - { |
|
219 | - if (is_array($details)) { |
|
220 | - array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
221 | - } else { |
|
222 | - $details = wp_strip_all_tags($details); |
|
223 | - } |
|
224 | - $this->set('PAY_details', $details); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * Sets redirect_url |
|
230 | - * |
|
231 | - * @param string $redirect_url |
|
232 | - * @throws \EE_Error |
|
233 | - */ |
|
234 | - public function set_redirect_url($redirect_url) |
|
235 | - { |
|
236 | - $this->set('PAY_redirect_url', $redirect_url); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * Sets redirect_args |
|
242 | - * |
|
243 | - * @param array $redirect_args |
|
244 | - * @throws \EE_Error |
|
245 | - */ |
|
246 | - public function set_redirect_args($redirect_args) |
|
247 | - { |
|
248 | - $this->set('PAY_redirect_args', $redirect_args); |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * get Payment Transaction ID |
|
254 | - * |
|
255 | - * @access public |
|
256 | - * @throws \EE_Error |
|
257 | - */ |
|
258 | - public function TXN_ID() |
|
259 | - { |
|
260 | - return $this->get('TXN_ID'); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * get Payment Status |
|
266 | - * |
|
267 | - * @access public |
|
268 | - * @throws \EE_Error |
|
269 | - */ |
|
270 | - public function status() |
|
271 | - { |
|
272 | - return $this->get('STS_ID'); |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * get Payment Status |
|
278 | - * |
|
279 | - * @access public |
|
280 | - * @throws \EE_Error |
|
281 | - */ |
|
282 | - public function STS_ID() |
|
283 | - { |
|
284 | - return $this->get('STS_ID'); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * get Payment Timestamp |
|
290 | - * |
|
291 | - * @access public |
|
292 | - * @param string $dt_frmt |
|
293 | - * @param string $tm_frmt |
|
294 | - * @return string |
|
295 | - * @throws \EE_Error |
|
296 | - */ |
|
297 | - public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
298 | - { |
|
299 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * get Payment Source |
|
305 | - * |
|
306 | - * @access public |
|
307 | - * @throws \EE_Error |
|
308 | - */ |
|
309 | - public function source() |
|
310 | - { |
|
311 | - return $this->get('PAY_source'); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * get Payment Amount |
|
317 | - * |
|
318 | - * @access public |
|
319 | - * @return float |
|
320 | - * @throws \EE_Error |
|
321 | - */ |
|
322 | - public function amount() |
|
323 | - { |
|
324 | - return (float) $this->get('PAY_amount'); |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @return mixed |
|
330 | - * @throws \EE_Error |
|
331 | - */ |
|
332 | - public function amount_no_code() |
|
333 | - { |
|
334 | - return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * get Payment Gateway Response |
|
340 | - * |
|
341 | - * @access public |
|
342 | - * @throws \EE_Error |
|
343 | - */ |
|
344 | - public function gateway_response() |
|
345 | - { |
|
346 | - return $this->get('PAY_gateway_response'); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * get Payment Gateway Transaction ID |
|
352 | - * |
|
353 | - * @access public |
|
354 | - * @throws \EE_Error |
|
355 | - */ |
|
356 | - public function txn_id_chq_nmbr() |
|
357 | - { |
|
358 | - return $this->get('PAY_txn_id_chq_nmbr'); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * get Purchase Order Number |
|
364 | - * |
|
365 | - * @access public |
|
366 | - * @throws \EE_Error |
|
367 | - */ |
|
368 | - public function po_number() |
|
369 | - { |
|
370 | - return $this->get('PAY_po_number'); |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * get Extra Accounting Field |
|
376 | - * |
|
377 | - * @access public |
|
378 | - * @throws \EE_Error |
|
379 | - */ |
|
380 | - public function extra_accntng() |
|
381 | - { |
|
382 | - return $this->get('PAY_extra_accntng'); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * get Payment made via admin source |
|
388 | - * |
|
389 | - * @access public |
|
390 | - * @throws \EE_Error |
|
391 | - */ |
|
392 | - public function payment_made_via_admin() |
|
393 | - { |
|
394 | - return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * get Payment Details |
|
400 | - * |
|
401 | - * @access public |
|
402 | - * @throws \EE_Error |
|
403 | - */ |
|
404 | - public function details() |
|
405 | - { |
|
406 | - return $this->get('PAY_details'); |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * Gets redirect_url |
|
412 | - * |
|
413 | - * @return string |
|
414 | - * @throws \EE_Error |
|
415 | - */ |
|
416 | - public function redirect_url() |
|
417 | - { |
|
418 | - return $this->get('PAY_redirect_url'); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Gets redirect_args |
|
424 | - * |
|
425 | - * @return array |
|
426 | - * @throws \EE_Error |
|
427 | - */ |
|
428 | - public function redirect_args() |
|
429 | - { |
|
430 | - return $this->get('PAY_redirect_args'); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * echoes $this->pretty_status() |
|
436 | - * |
|
437 | - * @param bool $show_icons |
|
438 | - * @return void |
|
439 | - * @throws \EE_Error |
|
440 | - */ |
|
441 | - public function e_pretty_status($show_icons = false) |
|
442 | - { |
|
443 | - echo $this->pretty_status($show_icons); |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * returns a pretty version of the status, good for displaying to users |
|
449 | - * |
|
450 | - * @param bool $show_icons |
|
451 | - * @return string |
|
452 | - * @throws \EE_Error |
|
453 | - */ |
|
454 | - public function pretty_status($show_icons = false) |
|
455 | - { |
|
456 | - $status = EEM_Status::instance()->localized_status( |
|
457 | - array($this->STS_ID() => __('unknown', 'event_espresso')), |
|
458 | - false, |
|
459 | - 'sentence' |
|
460 | - ); |
|
461 | - $icon = ''; |
|
462 | - switch ($this->STS_ID()) { |
|
463 | - case EEM_Payment::status_id_approved: |
|
464 | - $icon = $show_icons |
|
465 | - ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
466 | - : ''; |
|
467 | - break; |
|
468 | - case EEM_Payment::status_id_pending: |
|
469 | - $icon = $show_icons |
|
470 | - ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
471 | - : ''; |
|
472 | - break; |
|
473 | - case EEM_Payment::status_id_cancelled: |
|
474 | - $icon = $show_icons |
|
475 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
476 | - : ''; |
|
477 | - break; |
|
478 | - case EEM_Payment::status_id_declined: |
|
479 | - $icon = $show_icons |
|
480 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
481 | - : ''; |
|
482 | - break; |
|
483 | - } |
|
484 | - return $icon . $status[ $this->STS_ID() ]; |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * For determining the status of the payment |
|
490 | - * |
|
491 | - * @return boolean whether the payment is approved or not |
|
492 | - * @throws \EE_Error |
|
493 | - */ |
|
494 | - public function is_approved() |
|
495 | - { |
|
496 | - return $this->status_is(EEM_Payment::status_id_approved); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * Generally determines if the status of this payment equals |
|
502 | - * the $STS_ID string |
|
503 | - * |
|
504 | - * @param string $STS_ID an ID from the esp_status table/ |
|
505 | - * one of the status_id_* on the EEM_Payment model |
|
506 | - * @return boolean whether the status of this payment equals the status id |
|
507 | - * @throws \EE_Error |
|
508 | - */ |
|
509 | - protected function status_is($STS_ID) |
|
510 | - { |
|
511 | - return $STS_ID === $this->STS_ID() ? true : false; |
|
512 | - } |
|
513 | - |
|
514 | - |
|
515 | - /** |
|
516 | - * For determining the status of the payment |
|
517 | - * |
|
518 | - * @return boolean whether the payment is pending or not |
|
519 | - * @throws \EE_Error |
|
520 | - */ |
|
521 | - public function is_pending() |
|
522 | - { |
|
523 | - return $this->status_is(EEM_Payment::status_id_pending); |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * For determining the status of the payment |
|
529 | - * |
|
530 | - * @return boolean |
|
531 | - * @throws \EE_Error |
|
532 | - */ |
|
533 | - public function is_cancelled() |
|
534 | - { |
|
535 | - return $this->status_is(EEM_Payment::status_id_cancelled); |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * For determining the status of the payment |
|
541 | - * |
|
542 | - * @return boolean |
|
543 | - * @throws \EE_Error |
|
544 | - */ |
|
545 | - public function is_declined() |
|
546 | - { |
|
547 | - return $this->status_is(EEM_Payment::status_id_declined); |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * For determining the status of the payment |
|
553 | - * |
|
554 | - * @return boolean |
|
555 | - * @throws \EE_Error |
|
556 | - */ |
|
557 | - public function is_failed() |
|
558 | - { |
|
559 | - return $this->status_is(EEM_Payment::status_id_failed); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
565 | - * |
|
566 | - * @return boolean |
|
567 | - * @throws \EE_Error |
|
568 | - */ |
|
569 | - public function is_a_refund() |
|
570 | - { |
|
571 | - return $this->amount() < 0 ? true : false; |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - /** |
|
576 | - * Get the status object of this object |
|
577 | - * |
|
578 | - * @return EE_Status |
|
579 | - * @throws \EE_Error |
|
580 | - */ |
|
581 | - public function status_obj() |
|
582 | - { |
|
583 | - return $this->get_first_related('Status'); |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * Gets all the extra meta info on this payment |
|
589 | - * |
|
590 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
591 | - * @return EE_Extra_Meta |
|
592 | - * @throws \EE_Error |
|
593 | - */ |
|
594 | - public function extra_meta($query_params = array()) |
|
595 | - { |
|
596 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * Gets the last-used payment method on this transaction |
|
602 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
603 | - * offline ones, dont' create payments) |
|
604 | - * |
|
605 | - * @return EE_Payment_Method |
|
606 | - * @throws \EE_Error |
|
607 | - */ |
|
608 | - public function payment_method() |
|
609 | - { |
|
610 | - return $this->get_first_related('Payment_Method'); |
|
611 | - } |
|
612 | - |
|
613 | - |
|
614 | - /** |
|
615 | - * Gets the HTML for redirecting the user to an offsite gateway |
|
616 | - * You can pass it special content to put inside the form, or use |
|
617 | - * the default inner content (or possibly generate this all yourself using |
|
618 | - * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
619 | - * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
620 | - * (and any querystring variables in the redirect_url are converted into html inputs |
|
621 | - * so browsers submit them properly) |
|
622 | - * |
|
623 | - * @param string $inside_form_html |
|
624 | - * @return string html |
|
625 | - * @throws \EE_Error |
|
626 | - */ |
|
627 | - public function redirect_form($inside_form_html = null) |
|
628 | - { |
|
629 | - $redirect_url = $this->redirect_url(); |
|
630 | - if (! empty($redirect_url)) { |
|
631 | - // what ? no inner form content? |
|
632 | - if ($inside_form_html === null) { |
|
633 | - $inside_form_html = EEH_HTML::p( |
|
634 | - sprintf( |
|
635 | - __( |
|
636 | - 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
637 | - 'event_espresso' |
|
638 | - ), |
|
639 | - EEH_HTML::br(2), |
|
640 | - '<input type="submit" value="', |
|
641 | - '">' |
|
642 | - ), |
|
643 | - '', |
|
644 | - '', |
|
645 | - 'text-align:center;' |
|
646 | - ); |
|
647 | - } |
|
648 | - $method = apply_filters( |
|
649 | - 'FHEE__EE_Payment__redirect_form__method', |
|
650 | - $this->redirect_args() ? 'POST' : 'GET', |
|
651 | - $this |
|
652 | - ); |
|
653 | - // if it's a GET request, we need to remove all the GET params in the querystring |
|
654 | - // and put them into the form instead |
|
655 | - if ($method === 'GET') { |
|
656 | - $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
657 | - $get_params = null; |
|
658 | - parse_str($querystring, $get_params); |
|
659 | - $inside_form_html .= $this->_args_as_inputs($get_params); |
|
660 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
661 | - } |
|
662 | - $form = EEH_HTML::nl(1) |
|
663 | - . '<form method="' |
|
664 | - . $method |
|
665 | - . '" name="gateway_form" action="' |
|
666 | - . $redirect_url |
|
667 | - . '">'; |
|
668 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
669 | - $form .= $inside_form_html; |
|
670 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
671 | - return $form; |
|
672 | - } else { |
|
673 | - return null; |
|
674 | - } |
|
675 | - } |
|
676 | - |
|
677 | - |
|
678 | - /** |
|
679 | - * Changes all the name-value pairs of the redirect args into html inputs |
|
680 | - * and returns the html as a string |
|
681 | - * |
|
682 | - * @return string |
|
683 | - * @throws \EE_Error |
|
684 | - */ |
|
685 | - public function redirect_args_as_inputs() |
|
686 | - { |
|
687 | - return $this->_args_as_inputs($this->redirect_args()); |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * Converts a 1d array of key-value pairs into html hidden inputs |
|
693 | - * and returns the string of html |
|
694 | - * |
|
695 | - * @param array $args key-value pairs |
|
696 | - * @return string |
|
697 | - */ |
|
698 | - protected function _args_as_inputs($args) |
|
699 | - { |
|
700 | - $html = ''; |
|
701 | - if ($args !== null && is_array($args)) { |
|
702 | - foreach ($args as $name => $value) { |
|
703 | - $html .= EEH_HTML::nl(0) |
|
704 | - . '<input type="hidden" name="' |
|
705 | - . $name |
|
706 | - . '" value="' |
|
707 | - . esc_attr($value) |
|
708 | - . '"/>'; |
|
709 | - } |
|
710 | - } |
|
711 | - return $html; |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * Returns the currency of the payment. |
|
717 | - * (At the time of writing, this will always be the currency in the configuration; |
|
718 | - * however in the future it is anticipated that this will be stored on the payment |
|
719 | - * object itself) |
|
720 | - * |
|
721 | - * @return string for the currency code |
|
722 | - */ |
|
723 | - public function currency_code() |
|
724 | - { |
|
725 | - return EE_Config::instance()->currency->code; |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - /** |
|
730 | - * apply wp_strip_all_tags to all elements within an array |
|
731 | - * |
|
732 | - * @access private |
|
733 | - * @param mixed $item |
|
734 | - */ |
|
735 | - private function _strip_all_tags_within_array(&$item) |
|
736 | - { |
|
737 | - if (is_object($item)) { |
|
738 | - $item = (array) $item; |
|
739 | - } |
|
740 | - if (is_array($item)) { |
|
741 | - array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
742 | - } else { |
|
743 | - $item = wp_strip_all_tags($item); |
|
744 | - } |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * Returns TRUE is this payment was set to approved during this request (or |
|
750 | - * is approved and was created during this request). False otherwise. |
|
751 | - * |
|
752 | - * @return boolean |
|
753 | - * @throws \EE_Error |
|
754 | - */ |
|
755 | - public function just_approved() |
|
756 | - { |
|
757 | - $original_status = EEH_Array::is_set( |
|
758 | - $this->_props_n_values_provided_in_constructor, |
|
759 | - 'STS_ID', |
|
760 | - $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
761 | - ); |
|
762 | - $current_status = $this->status(); |
|
763 | - if ($original_status !== EEM_Payment::status_id_approved |
|
764 | - && $current_status === EEM_Payment::status_id_approved |
|
765 | - ) { |
|
766 | - return true; |
|
767 | - } else { |
|
768 | - return false; |
|
769 | - } |
|
770 | - } |
|
771 | - |
|
772 | - |
|
773 | - /** |
|
774 | - * Overrides parents' get_pretty() function just for legacy reasons |
|
775 | - * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
776 | - * |
|
777 | - * @param string $field_name |
|
778 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
779 | - * (in cases where the same property may be used for different outputs |
|
780 | - * - i.e. datetime, money etc.) |
|
781 | - * @return mixed |
|
782 | - * @throws \EE_Error |
|
783 | - */ |
|
784 | - public function get_pretty($field_name, $extra_cache_ref = null) |
|
785 | - { |
|
786 | - if ($field_name === 'PAY_gateway') { |
|
787 | - return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
788 | - } |
|
789 | - return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
790 | - } |
|
791 | - |
|
792 | - |
|
793 | - /** |
|
794 | - * Gets details regarding which registrations this payment was applied to |
|
795 | - * |
|
796 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
797 | - * @return EE_Registration_Payment[] |
|
798 | - * @throws \EE_Error |
|
799 | - */ |
|
800 | - public function registration_payments($query_params = array()) |
|
801 | - { |
|
802 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
803 | - } |
|
804 | - |
|
805 | - |
|
806 | - /** |
|
807 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
808 | - * |
|
809 | - * @return EE_Event|null |
|
810 | - */ |
|
811 | - public function get_first_event() |
|
812 | - { |
|
813 | - $transaction = $this->transaction(); |
|
814 | - if ($transaction instanceof EE_Transaction) { |
|
815 | - $primary_registrant = $transaction->primary_registration(); |
|
816 | - if ($primary_registrant instanceof EE_Registration) { |
|
817 | - return $primary_registrant->event_obj(); |
|
818 | - } |
|
819 | - } |
|
820 | - return null; |
|
821 | - } |
|
822 | - |
|
823 | - |
|
824 | - /** |
|
825 | - * Gets the name of the first event for which is being paid |
|
826 | - * |
|
827 | - * @return string |
|
828 | - */ |
|
829 | - public function get_first_event_name() |
|
830 | - { |
|
831 | - $event = $this->get_first_event(); |
|
832 | - return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - /** |
|
837 | - * Returns the payment's transaction's primary registration |
|
838 | - * |
|
839 | - * @return EE_Registration|null |
|
840 | - */ |
|
841 | - public function get_primary_registration() |
|
842 | - { |
|
843 | - if ($this->transaction() instanceof EE_Transaction) { |
|
844 | - return $this->transaction()->primary_registration(); |
|
845 | - } |
|
846 | - return null; |
|
847 | - } |
|
848 | - |
|
849 | - |
|
850 | - /** |
|
851 | - * Gets the payment's transaction's primary registration's attendee, or null |
|
852 | - * |
|
853 | - * @return EE_Attendee|null |
|
854 | - */ |
|
855 | - public function get_primary_attendee() |
|
856 | - { |
|
857 | - $primary_reg = $this->get_primary_registration(); |
|
858 | - if ($primary_reg instanceof EE_Registration) { |
|
859 | - return $primary_reg->attendee(); |
|
860 | - } |
|
861 | - return null; |
|
862 | - } |
|
12 | + /** |
|
13 | + * @param array $props_n_values incoming values |
|
14 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
15 | + * used.) |
|
16 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
17 | + * date_format and the second value is the time format |
|
18 | + * @return EE_Payment |
|
19 | + * @throws \EE_Error |
|
20 | + */ |
|
21 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
22 | + { |
|
23 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
24 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
25 | + } |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @param array $props_n_values incoming values from the database |
|
30 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
31 | + * the website will be used. |
|
32 | + * @return EE_Payment |
|
33 | + * @throws \EE_Error |
|
34 | + */ |
|
35 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
36 | + { |
|
37 | + return new self($props_n_values, true, $timezone); |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Set Transaction ID |
|
43 | + * |
|
44 | + * @access public |
|
45 | + * @param int $TXN_ID |
|
46 | + * @throws \EE_Error |
|
47 | + */ |
|
48 | + public function set_transaction_id($TXN_ID = 0) |
|
49 | + { |
|
50 | + $this->set('TXN_ID', $TXN_ID); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Gets the transaction related to this payment |
|
56 | + * |
|
57 | + * @return EE_Transaction |
|
58 | + * @throws \EE_Error |
|
59 | + */ |
|
60 | + public function transaction() |
|
61 | + { |
|
62 | + return $this->get_first_related('Transaction'); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Set Status |
|
68 | + * |
|
69 | + * @access public |
|
70 | + * @param string $STS_ID |
|
71 | + * @throws \EE_Error |
|
72 | + */ |
|
73 | + public function set_status($STS_ID = '') |
|
74 | + { |
|
75 | + $this->set('STS_ID', $STS_ID); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Set Payment Timestamp |
|
81 | + * |
|
82 | + * @access public |
|
83 | + * @param int $timestamp |
|
84 | + * @throws \EE_Error |
|
85 | + */ |
|
86 | + public function set_timestamp($timestamp = 0) |
|
87 | + { |
|
88 | + $this->set('PAY_timestamp', $timestamp); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Set Payment Method |
|
94 | + * |
|
95 | + * @access public |
|
96 | + * @param string $PAY_source |
|
97 | + * @throws \EE_Error |
|
98 | + */ |
|
99 | + public function set_source($PAY_source = '') |
|
100 | + { |
|
101 | + $this->set('PAY_source', $PAY_source); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * Set Payment Amount |
|
107 | + * |
|
108 | + * @access public |
|
109 | + * @param float $amount |
|
110 | + * @throws \EE_Error |
|
111 | + */ |
|
112 | + public function set_amount($amount = 0.00) |
|
113 | + { |
|
114 | + $this->set('PAY_amount', (float) $amount); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Set Payment Gateway Response |
|
120 | + * |
|
121 | + * @access public |
|
122 | + * @param string $gateway_response |
|
123 | + * @throws \EE_Error |
|
124 | + */ |
|
125 | + public function set_gateway_response($gateway_response = '') |
|
126 | + { |
|
127 | + $this->set('PAY_gateway_response', $gateway_response); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
133 | + * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
134 | + * used on it |
|
135 | + * |
|
136 | + * @deprecated |
|
137 | + * @return string |
|
138 | + * @throws \EE_Error |
|
139 | + */ |
|
140 | + public function gateway() |
|
141 | + { |
|
142 | + EE_Error::doing_it_wrong( |
|
143 | + 'EE_Payment::gateway', |
|
144 | + __( |
|
145 | + 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
146 | + 'event_espresso' |
|
147 | + ), |
|
148 | + '4.6.0' |
|
149 | + ); |
|
150 | + return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * Set Gateway Transaction ID |
|
156 | + * |
|
157 | + * @access public |
|
158 | + * @param string $txn_id_chq_nmbr |
|
159 | + * @throws \EE_Error |
|
160 | + */ |
|
161 | + public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
162 | + { |
|
163 | + $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Set Purchase Order Number |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @param string $po_number |
|
172 | + * @throws \EE_Error |
|
173 | + */ |
|
174 | + public function set_po_number($po_number = '') |
|
175 | + { |
|
176 | + $this->set('PAY_po_number', $po_number); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Set Extra Accounting Field |
|
182 | + * |
|
183 | + * @access public |
|
184 | + * @param string $extra_accntng |
|
185 | + * @throws \EE_Error |
|
186 | + */ |
|
187 | + public function set_extra_accntng($extra_accntng = '') |
|
188 | + { |
|
189 | + $this->set('PAY_extra_accntng', $extra_accntng); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * Set Payment made via admin flag |
|
195 | + * |
|
196 | + * @access public |
|
197 | + * @param bool $via_admin |
|
198 | + * @throws \EE_Error |
|
199 | + */ |
|
200 | + public function set_payment_made_via_admin($via_admin = false) |
|
201 | + { |
|
202 | + if ($via_admin) { |
|
203 | + $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
204 | + } else { |
|
205 | + $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Set Payment Details |
|
212 | + * |
|
213 | + * @access public |
|
214 | + * @param string|array $details |
|
215 | + * @throws \EE_Error |
|
216 | + */ |
|
217 | + public function set_details($details = '') |
|
218 | + { |
|
219 | + if (is_array($details)) { |
|
220 | + array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
221 | + } else { |
|
222 | + $details = wp_strip_all_tags($details); |
|
223 | + } |
|
224 | + $this->set('PAY_details', $details); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * Sets redirect_url |
|
230 | + * |
|
231 | + * @param string $redirect_url |
|
232 | + * @throws \EE_Error |
|
233 | + */ |
|
234 | + public function set_redirect_url($redirect_url) |
|
235 | + { |
|
236 | + $this->set('PAY_redirect_url', $redirect_url); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * Sets redirect_args |
|
242 | + * |
|
243 | + * @param array $redirect_args |
|
244 | + * @throws \EE_Error |
|
245 | + */ |
|
246 | + public function set_redirect_args($redirect_args) |
|
247 | + { |
|
248 | + $this->set('PAY_redirect_args', $redirect_args); |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * get Payment Transaction ID |
|
254 | + * |
|
255 | + * @access public |
|
256 | + * @throws \EE_Error |
|
257 | + */ |
|
258 | + public function TXN_ID() |
|
259 | + { |
|
260 | + return $this->get('TXN_ID'); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * get Payment Status |
|
266 | + * |
|
267 | + * @access public |
|
268 | + * @throws \EE_Error |
|
269 | + */ |
|
270 | + public function status() |
|
271 | + { |
|
272 | + return $this->get('STS_ID'); |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * get Payment Status |
|
278 | + * |
|
279 | + * @access public |
|
280 | + * @throws \EE_Error |
|
281 | + */ |
|
282 | + public function STS_ID() |
|
283 | + { |
|
284 | + return $this->get('STS_ID'); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * get Payment Timestamp |
|
290 | + * |
|
291 | + * @access public |
|
292 | + * @param string $dt_frmt |
|
293 | + * @param string $tm_frmt |
|
294 | + * @return string |
|
295 | + * @throws \EE_Error |
|
296 | + */ |
|
297 | + public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
298 | + { |
|
299 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * get Payment Source |
|
305 | + * |
|
306 | + * @access public |
|
307 | + * @throws \EE_Error |
|
308 | + */ |
|
309 | + public function source() |
|
310 | + { |
|
311 | + return $this->get('PAY_source'); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * get Payment Amount |
|
317 | + * |
|
318 | + * @access public |
|
319 | + * @return float |
|
320 | + * @throws \EE_Error |
|
321 | + */ |
|
322 | + public function amount() |
|
323 | + { |
|
324 | + return (float) $this->get('PAY_amount'); |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @return mixed |
|
330 | + * @throws \EE_Error |
|
331 | + */ |
|
332 | + public function amount_no_code() |
|
333 | + { |
|
334 | + return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * get Payment Gateway Response |
|
340 | + * |
|
341 | + * @access public |
|
342 | + * @throws \EE_Error |
|
343 | + */ |
|
344 | + public function gateway_response() |
|
345 | + { |
|
346 | + return $this->get('PAY_gateway_response'); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * get Payment Gateway Transaction ID |
|
352 | + * |
|
353 | + * @access public |
|
354 | + * @throws \EE_Error |
|
355 | + */ |
|
356 | + public function txn_id_chq_nmbr() |
|
357 | + { |
|
358 | + return $this->get('PAY_txn_id_chq_nmbr'); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * get Purchase Order Number |
|
364 | + * |
|
365 | + * @access public |
|
366 | + * @throws \EE_Error |
|
367 | + */ |
|
368 | + public function po_number() |
|
369 | + { |
|
370 | + return $this->get('PAY_po_number'); |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * get Extra Accounting Field |
|
376 | + * |
|
377 | + * @access public |
|
378 | + * @throws \EE_Error |
|
379 | + */ |
|
380 | + public function extra_accntng() |
|
381 | + { |
|
382 | + return $this->get('PAY_extra_accntng'); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * get Payment made via admin source |
|
388 | + * |
|
389 | + * @access public |
|
390 | + * @throws \EE_Error |
|
391 | + */ |
|
392 | + public function payment_made_via_admin() |
|
393 | + { |
|
394 | + return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * get Payment Details |
|
400 | + * |
|
401 | + * @access public |
|
402 | + * @throws \EE_Error |
|
403 | + */ |
|
404 | + public function details() |
|
405 | + { |
|
406 | + return $this->get('PAY_details'); |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * Gets redirect_url |
|
412 | + * |
|
413 | + * @return string |
|
414 | + * @throws \EE_Error |
|
415 | + */ |
|
416 | + public function redirect_url() |
|
417 | + { |
|
418 | + return $this->get('PAY_redirect_url'); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Gets redirect_args |
|
424 | + * |
|
425 | + * @return array |
|
426 | + * @throws \EE_Error |
|
427 | + */ |
|
428 | + public function redirect_args() |
|
429 | + { |
|
430 | + return $this->get('PAY_redirect_args'); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * echoes $this->pretty_status() |
|
436 | + * |
|
437 | + * @param bool $show_icons |
|
438 | + * @return void |
|
439 | + * @throws \EE_Error |
|
440 | + */ |
|
441 | + public function e_pretty_status($show_icons = false) |
|
442 | + { |
|
443 | + echo $this->pretty_status($show_icons); |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * returns a pretty version of the status, good for displaying to users |
|
449 | + * |
|
450 | + * @param bool $show_icons |
|
451 | + * @return string |
|
452 | + * @throws \EE_Error |
|
453 | + */ |
|
454 | + public function pretty_status($show_icons = false) |
|
455 | + { |
|
456 | + $status = EEM_Status::instance()->localized_status( |
|
457 | + array($this->STS_ID() => __('unknown', 'event_espresso')), |
|
458 | + false, |
|
459 | + 'sentence' |
|
460 | + ); |
|
461 | + $icon = ''; |
|
462 | + switch ($this->STS_ID()) { |
|
463 | + case EEM_Payment::status_id_approved: |
|
464 | + $icon = $show_icons |
|
465 | + ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
466 | + : ''; |
|
467 | + break; |
|
468 | + case EEM_Payment::status_id_pending: |
|
469 | + $icon = $show_icons |
|
470 | + ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
471 | + : ''; |
|
472 | + break; |
|
473 | + case EEM_Payment::status_id_cancelled: |
|
474 | + $icon = $show_icons |
|
475 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
476 | + : ''; |
|
477 | + break; |
|
478 | + case EEM_Payment::status_id_declined: |
|
479 | + $icon = $show_icons |
|
480 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
481 | + : ''; |
|
482 | + break; |
|
483 | + } |
|
484 | + return $icon . $status[ $this->STS_ID() ]; |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * For determining the status of the payment |
|
490 | + * |
|
491 | + * @return boolean whether the payment is approved or not |
|
492 | + * @throws \EE_Error |
|
493 | + */ |
|
494 | + public function is_approved() |
|
495 | + { |
|
496 | + return $this->status_is(EEM_Payment::status_id_approved); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * Generally determines if the status of this payment equals |
|
502 | + * the $STS_ID string |
|
503 | + * |
|
504 | + * @param string $STS_ID an ID from the esp_status table/ |
|
505 | + * one of the status_id_* on the EEM_Payment model |
|
506 | + * @return boolean whether the status of this payment equals the status id |
|
507 | + * @throws \EE_Error |
|
508 | + */ |
|
509 | + protected function status_is($STS_ID) |
|
510 | + { |
|
511 | + return $STS_ID === $this->STS_ID() ? true : false; |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + /** |
|
516 | + * For determining the status of the payment |
|
517 | + * |
|
518 | + * @return boolean whether the payment is pending or not |
|
519 | + * @throws \EE_Error |
|
520 | + */ |
|
521 | + public function is_pending() |
|
522 | + { |
|
523 | + return $this->status_is(EEM_Payment::status_id_pending); |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * For determining the status of the payment |
|
529 | + * |
|
530 | + * @return boolean |
|
531 | + * @throws \EE_Error |
|
532 | + */ |
|
533 | + public function is_cancelled() |
|
534 | + { |
|
535 | + return $this->status_is(EEM_Payment::status_id_cancelled); |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * For determining the status of the payment |
|
541 | + * |
|
542 | + * @return boolean |
|
543 | + * @throws \EE_Error |
|
544 | + */ |
|
545 | + public function is_declined() |
|
546 | + { |
|
547 | + return $this->status_is(EEM_Payment::status_id_declined); |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * For determining the status of the payment |
|
553 | + * |
|
554 | + * @return boolean |
|
555 | + * @throws \EE_Error |
|
556 | + */ |
|
557 | + public function is_failed() |
|
558 | + { |
|
559 | + return $this->status_is(EEM_Payment::status_id_failed); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
565 | + * |
|
566 | + * @return boolean |
|
567 | + * @throws \EE_Error |
|
568 | + */ |
|
569 | + public function is_a_refund() |
|
570 | + { |
|
571 | + return $this->amount() < 0 ? true : false; |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + /** |
|
576 | + * Get the status object of this object |
|
577 | + * |
|
578 | + * @return EE_Status |
|
579 | + * @throws \EE_Error |
|
580 | + */ |
|
581 | + public function status_obj() |
|
582 | + { |
|
583 | + return $this->get_first_related('Status'); |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * Gets all the extra meta info on this payment |
|
589 | + * |
|
590 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
591 | + * @return EE_Extra_Meta |
|
592 | + * @throws \EE_Error |
|
593 | + */ |
|
594 | + public function extra_meta($query_params = array()) |
|
595 | + { |
|
596 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * Gets the last-used payment method on this transaction |
|
602 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
603 | + * offline ones, dont' create payments) |
|
604 | + * |
|
605 | + * @return EE_Payment_Method |
|
606 | + * @throws \EE_Error |
|
607 | + */ |
|
608 | + public function payment_method() |
|
609 | + { |
|
610 | + return $this->get_first_related('Payment_Method'); |
|
611 | + } |
|
612 | + |
|
613 | + |
|
614 | + /** |
|
615 | + * Gets the HTML for redirecting the user to an offsite gateway |
|
616 | + * You can pass it special content to put inside the form, or use |
|
617 | + * the default inner content (or possibly generate this all yourself using |
|
618 | + * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
619 | + * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
620 | + * (and any querystring variables in the redirect_url are converted into html inputs |
|
621 | + * so browsers submit them properly) |
|
622 | + * |
|
623 | + * @param string $inside_form_html |
|
624 | + * @return string html |
|
625 | + * @throws \EE_Error |
|
626 | + */ |
|
627 | + public function redirect_form($inside_form_html = null) |
|
628 | + { |
|
629 | + $redirect_url = $this->redirect_url(); |
|
630 | + if (! empty($redirect_url)) { |
|
631 | + // what ? no inner form content? |
|
632 | + if ($inside_form_html === null) { |
|
633 | + $inside_form_html = EEH_HTML::p( |
|
634 | + sprintf( |
|
635 | + __( |
|
636 | + 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
637 | + 'event_espresso' |
|
638 | + ), |
|
639 | + EEH_HTML::br(2), |
|
640 | + '<input type="submit" value="', |
|
641 | + '">' |
|
642 | + ), |
|
643 | + '', |
|
644 | + '', |
|
645 | + 'text-align:center;' |
|
646 | + ); |
|
647 | + } |
|
648 | + $method = apply_filters( |
|
649 | + 'FHEE__EE_Payment__redirect_form__method', |
|
650 | + $this->redirect_args() ? 'POST' : 'GET', |
|
651 | + $this |
|
652 | + ); |
|
653 | + // if it's a GET request, we need to remove all the GET params in the querystring |
|
654 | + // and put them into the form instead |
|
655 | + if ($method === 'GET') { |
|
656 | + $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
657 | + $get_params = null; |
|
658 | + parse_str($querystring, $get_params); |
|
659 | + $inside_form_html .= $this->_args_as_inputs($get_params); |
|
660 | + $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
661 | + } |
|
662 | + $form = EEH_HTML::nl(1) |
|
663 | + . '<form method="' |
|
664 | + . $method |
|
665 | + . '" name="gateway_form" action="' |
|
666 | + . $redirect_url |
|
667 | + . '">'; |
|
668 | + $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
669 | + $form .= $inside_form_html; |
|
670 | + $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
671 | + return $form; |
|
672 | + } else { |
|
673 | + return null; |
|
674 | + } |
|
675 | + } |
|
676 | + |
|
677 | + |
|
678 | + /** |
|
679 | + * Changes all the name-value pairs of the redirect args into html inputs |
|
680 | + * and returns the html as a string |
|
681 | + * |
|
682 | + * @return string |
|
683 | + * @throws \EE_Error |
|
684 | + */ |
|
685 | + public function redirect_args_as_inputs() |
|
686 | + { |
|
687 | + return $this->_args_as_inputs($this->redirect_args()); |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * Converts a 1d array of key-value pairs into html hidden inputs |
|
693 | + * and returns the string of html |
|
694 | + * |
|
695 | + * @param array $args key-value pairs |
|
696 | + * @return string |
|
697 | + */ |
|
698 | + protected function _args_as_inputs($args) |
|
699 | + { |
|
700 | + $html = ''; |
|
701 | + if ($args !== null && is_array($args)) { |
|
702 | + foreach ($args as $name => $value) { |
|
703 | + $html .= EEH_HTML::nl(0) |
|
704 | + . '<input type="hidden" name="' |
|
705 | + . $name |
|
706 | + . '" value="' |
|
707 | + . esc_attr($value) |
|
708 | + . '"/>'; |
|
709 | + } |
|
710 | + } |
|
711 | + return $html; |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * Returns the currency of the payment. |
|
717 | + * (At the time of writing, this will always be the currency in the configuration; |
|
718 | + * however in the future it is anticipated that this will be stored on the payment |
|
719 | + * object itself) |
|
720 | + * |
|
721 | + * @return string for the currency code |
|
722 | + */ |
|
723 | + public function currency_code() |
|
724 | + { |
|
725 | + return EE_Config::instance()->currency->code; |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + /** |
|
730 | + * apply wp_strip_all_tags to all elements within an array |
|
731 | + * |
|
732 | + * @access private |
|
733 | + * @param mixed $item |
|
734 | + */ |
|
735 | + private function _strip_all_tags_within_array(&$item) |
|
736 | + { |
|
737 | + if (is_object($item)) { |
|
738 | + $item = (array) $item; |
|
739 | + } |
|
740 | + if (is_array($item)) { |
|
741 | + array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
742 | + } else { |
|
743 | + $item = wp_strip_all_tags($item); |
|
744 | + } |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * Returns TRUE is this payment was set to approved during this request (or |
|
750 | + * is approved and was created during this request). False otherwise. |
|
751 | + * |
|
752 | + * @return boolean |
|
753 | + * @throws \EE_Error |
|
754 | + */ |
|
755 | + public function just_approved() |
|
756 | + { |
|
757 | + $original_status = EEH_Array::is_set( |
|
758 | + $this->_props_n_values_provided_in_constructor, |
|
759 | + 'STS_ID', |
|
760 | + $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
761 | + ); |
|
762 | + $current_status = $this->status(); |
|
763 | + if ($original_status !== EEM_Payment::status_id_approved |
|
764 | + && $current_status === EEM_Payment::status_id_approved |
|
765 | + ) { |
|
766 | + return true; |
|
767 | + } else { |
|
768 | + return false; |
|
769 | + } |
|
770 | + } |
|
771 | + |
|
772 | + |
|
773 | + /** |
|
774 | + * Overrides parents' get_pretty() function just for legacy reasons |
|
775 | + * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
776 | + * |
|
777 | + * @param string $field_name |
|
778 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
779 | + * (in cases where the same property may be used for different outputs |
|
780 | + * - i.e. datetime, money etc.) |
|
781 | + * @return mixed |
|
782 | + * @throws \EE_Error |
|
783 | + */ |
|
784 | + public function get_pretty($field_name, $extra_cache_ref = null) |
|
785 | + { |
|
786 | + if ($field_name === 'PAY_gateway') { |
|
787 | + return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
788 | + } |
|
789 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
790 | + } |
|
791 | + |
|
792 | + |
|
793 | + /** |
|
794 | + * Gets details regarding which registrations this payment was applied to |
|
795 | + * |
|
796 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
797 | + * @return EE_Registration_Payment[] |
|
798 | + * @throws \EE_Error |
|
799 | + */ |
|
800 | + public function registration_payments($query_params = array()) |
|
801 | + { |
|
802 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
803 | + } |
|
804 | + |
|
805 | + |
|
806 | + /** |
|
807 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
808 | + * |
|
809 | + * @return EE_Event|null |
|
810 | + */ |
|
811 | + public function get_first_event() |
|
812 | + { |
|
813 | + $transaction = $this->transaction(); |
|
814 | + if ($transaction instanceof EE_Transaction) { |
|
815 | + $primary_registrant = $transaction->primary_registration(); |
|
816 | + if ($primary_registrant instanceof EE_Registration) { |
|
817 | + return $primary_registrant->event_obj(); |
|
818 | + } |
|
819 | + } |
|
820 | + return null; |
|
821 | + } |
|
822 | + |
|
823 | + |
|
824 | + /** |
|
825 | + * Gets the name of the first event for which is being paid |
|
826 | + * |
|
827 | + * @return string |
|
828 | + */ |
|
829 | + public function get_first_event_name() |
|
830 | + { |
|
831 | + $event = $this->get_first_event(); |
|
832 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + /** |
|
837 | + * Returns the payment's transaction's primary registration |
|
838 | + * |
|
839 | + * @return EE_Registration|null |
|
840 | + */ |
|
841 | + public function get_primary_registration() |
|
842 | + { |
|
843 | + if ($this->transaction() instanceof EE_Transaction) { |
|
844 | + return $this->transaction()->primary_registration(); |
|
845 | + } |
|
846 | + return null; |
|
847 | + } |
|
848 | + |
|
849 | + |
|
850 | + /** |
|
851 | + * Gets the payment's transaction's primary registration's attendee, or null |
|
852 | + * |
|
853 | + * @return EE_Attendee|null |
|
854 | + */ |
|
855 | + public function get_primary_attendee() |
|
856 | + { |
|
857 | + $primary_reg = $this->get_primary_registration(); |
|
858 | + if ($primary_reg instanceof EE_Registration) { |
|
859 | + return $primary_reg->attendee(); |
|
860 | + } |
|
861 | + return null; |
|
862 | + } |
|
863 | 863 | } |
@@ -14,98 +14,98 @@ |
||
14 | 14 | class EE_Registration_Payment extends EE_Base_Class |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * |
|
19 | - * @param array $props_n_values |
|
20 | - * @param string $timezone |
|
21 | - * @return EE_Registration_Payment |
|
22 | - */ |
|
23 | - public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
24 | - { |
|
25 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
26 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
27 | - } |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @param array $props_n_values |
|
32 | - * @param string $timezone |
|
33 | - * @return EE_Registration_Payment |
|
34 | - */ |
|
35 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
36 | - { |
|
37 | - return new self($props_n_values, true, $timezone); |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * registration_ID |
|
43 | - * |
|
44 | - * @access public |
|
45 | - * @return int |
|
46 | - */ |
|
47 | - public function registration_ID() |
|
48 | - { |
|
49 | - return $this->get('REG_ID'); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * payment_ID |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @return int |
|
58 | - */ |
|
59 | - public function payment_ID() |
|
60 | - { |
|
61 | - return $this->get('PAY_ID'); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * amount |
|
67 | - * |
|
68 | - * @access public |
|
69 | - * @return float |
|
70 | - */ |
|
71 | - public function amount() |
|
72 | - { |
|
73 | - return $this->get('RPY_amount'); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * amount |
|
79 | - * |
|
80 | - * @access public |
|
81 | - * @param float $amount |
|
82 | - */ |
|
83 | - public function set_amount($amount = 0.000) |
|
84 | - { |
|
85 | - $this->set('RPY_amount', $amount); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * registration |
|
91 | - * |
|
92 | - * @access public |
|
93 | - * @return \EE_Registration |
|
94 | - */ |
|
95 | - public function registration() |
|
96 | - { |
|
97 | - return $this->get_first_related('Registration'); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * payment |
|
103 | - * |
|
104 | - * @access public |
|
105 | - * @return \EE_Payment |
|
106 | - */ |
|
107 | - public function payment() |
|
108 | - { |
|
109 | - return $this->get_first_related('Payment'); |
|
110 | - } |
|
17 | + /** |
|
18 | + * |
|
19 | + * @param array $props_n_values |
|
20 | + * @param string $timezone |
|
21 | + * @return EE_Registration_Payment |
|
22 | + */ |
|
23 | + public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
24 | + { |
|
25 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
26 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
27 | + } |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @param array $props_n_values |
|
32 | + * @param string $timezone |
|
33 | + * @return EE_Registration_Payment |
|
34 | + */ |
|
35 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
36 | + { |
|
37 | + return new self($props_n_values, true, $timezone); |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * registration_ID |
|
43 | + * |
|
44 | + * @access public |
|
45 | + * @return int |
|
46 | + */ |
|
47 | + public function registration_ID() |
|
48 | + { |
|
49 | + return $this->get('REG_ID'); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * payment_ID |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @return int |
|
58 | + */ |
|
59 | + public function payment_ID() |
|
60 | + { |
|
61 | + return $this->get('PAY_ID'); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * amount |
|
67 | + * |
|
68 | + * @access public |
|
69 | + * @return float |
|
70 | + */ |
|
71 | + public function amount() |
|
72 | + { |
|
73 | + return $this->get('RPY_amount'); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * amount |
|
79 | + * |
|
80 | + * @access public |
|
81 | + * @param float $amount |
|
82 | + */ |
|
83 | + public function set_amount($amount = 0.000) |
|
84 | + { |
|
85 | + $this->set('RPY_amount', $amount); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * registration |
|
91 | + * |
|
92 | + * @access public |
|
93 | + * @return \EE_Registration |
|
94 | + */ |
|
95 | + public function registration() |
|
96 | + { |
|
97 | + return $this->get_first_related('Registration'); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * payment |
|
103 | + * |
|
104 | + * @access public |
|
105 | + * @return \EE_Payment |
|
106 | + */ |
|
107 | + public function payment() |
|
108 | + { |
|
109 | + return $this->get_first_related('Payment'); |
|
110 | + } |
|
111 | 111 | } |
@@ -6,23 +6,23 @@ |
||
6 | 6 | class EE_Question_Group_Question extends EE_Base_Class |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @param array $props_n_values |
|
11 | - * @return EE_Question_Group_Question|mixed |
|
12 | - */ |
|
13 | - public static function new_instance($props_n_values = array()) |
|
14 | - { |
|
15 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
16 | - return $has_object ? $has_object : new self($props_n_values); |
|
17 | - } |
|
9 | + /** |
|
10 | + * @param array $props_n_values |
|
11 | + * @return EE_Question_Group_Question|mixed |
|
12 | + */ |
|
13 | + public static function new_instance($props_n_values = array()) |
|
14 | + { |
|
15 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
16 | + return $has_object ? $has_object : new self($props_n_values); |
|
17 | + } |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @param array $props_n_values |
|
22 | - * @return EE_Question_Group_Question |
|
23 | - */ |
|
24 | - public static function new_instance_from_db($props_n_values = array()) |
|
25 | - { |
|
26 | - return new self($props_n_values, true); |
|
27 | - } |
|
20 | + /** |
|
21 | + * @param array $props_n_values |
|
22 | + * @return EE_Question_Group_Question |
|
23 | + */ |
|
24 | + public static function new_instance_from_db($props_n_values = array()) |
|
25 | + { |
|
26 | + return new self($props_n_values, true); |
|
27 | + } |
|
28 | 28 | } |