@@ -13,124 +13,124 @@ |
||
13 | 13 | |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * format - output formatted EE object address information |
|
18 | - * |
|
19 | - * @access public |
|
20 | - * @param object EEI_Address $obj_with_address |
|
21 | - * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
22 | - * @param boolean $use_schema whether to apply schema.org formatting to the address |
|
23 | - * @param bool $add_wrapper |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public static function format( |
|
27 | - $obj_with_address = null, |
|
28 | - $type = 'multiline', |
|
29 | - $use_schema = true, |
|
30 | - $add_wrapper = true |
|
31 | - ) { |
|
32 | - // check that incoming object implements the EEI_Address interface |
|
33 | - if (! $obj_with_address instanceof EEI_Address) { |
|
34 | - $msg = __('The address could not be formatted.', 'event_espresso'); |
|
35 | - $dev_msg = __( |
|
36 | - 'The Address Formatter requires passed objects to implement the EEI_Address interface.', |
|
37 | - 'event_espresso' |
|
38 | - ); |
|
39 | - EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
40 | - return null; |
|
41 | - } |
|
42 | - // obtain an address formatter |
|
43 | - $formatter = EEH_Address::_get_formatter($type); |
|
44 | - // apply schema.org formatting ? |
|
45 | - $use_schema = ! is_admin() ? $use_schema : false; |
|
46 | - $formatted_address = $use_schema |
|
47 | - ? EEH_Address::_schema_formatting($formatter, $obj_with_address) |
|
48 | - : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper); |
|
49 | - $formatted_address = $add_wrapper && ! $use_schema |
|
50 | - ? '<div class="espresso-address-dv">' . $formatted_address . '</div>' |
|
51 | - : $formatted_address; |
|
52 | - // return the formatted address |
|
53 | - return $formatted_address; |
|
54 | - } |
|
16 | + /** |
|
17 | + * format - output formatted EE object address information |
|
18 | + * |
|
19 | + * @access public |
|
20 | + * @param object EEI_Address $obj_with_address |
|
21 | + * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
22 | + * @param boolean $use_schema whether to apply schema.org formatting to the address |
|
23 | + * @param bool $add_wrapper |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public static function format( |
|
27 | + $obj_with_address = null, |
|
28 | + $type = 'multiline', |
|
29 | + $use_schema = true, |
|
30 | + $add_wrapper = true |
|
31 | + ) { |
|
32 | + // check that incoming object implements the EEI_Address interface |
|
33 | + if (! $obj_with_address instanceof EEI_Address) { |
|
34 | + $msg = __('The address could not be formatted.', 'event_espresso'); |
|
35 | + $dev_msg = __( |
|
36 | + 'The Address Formatter requires passed objects to implement the EEI_Address interface.', |
|
37 | + 'event_espresso' |
|
38 | + ); |
|
39 | + EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
40 | + return null; |
|
41 | + } |
|
42 | + // obtain an address formatter |
|
43 | + $formatter = EEH_Address::_get_formatter($type); |
|
44 | + // apply schema.org formatting ? |
|
45 | + $use_schema = ! is_admin() ? $use_schema : false; |
|
46 | + $formatted_address = $use_schema |
|
47 | + ? EEH_Address::_schema_formatting($formatter, $obj_with_address) |
|
48 | + : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper); |
|
49 | + $formatted_address = $add_wrapper && ! $use_schema |
|
50 | + ? '<div class="espresso-address-dv">' . $formatted_address . '</div>' |
|
51 | + : $formatted_address; |
|
52 | + // return the formatted address |
|
53 | + return $formatted_address; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * _get_formatter - obtain the requester formatter class |
|
60 | - * |
|
61 | - * @access private |
|
62 | - * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
63 | - * @return EEI_Address_Formatter |
|
64 | - */ |
|
65 | - private static function _get_formatter($type) |
|
66 | - { |
|
67 | - switch ($type) { |
|
68 | - case 'multiline': |
|
69 | - return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter(); |
|
70 | - case 'inline': |
|
71 | - return new EventEspresso\core\services\address\formatters\InlineAddressFormatter(); |
|
72 | - default: |
|
73 | - return new EventEspresso\core\services\address\formatters\NullAddressFormatter(); |
|
74 | - } |
|
75 | - } |
|
58 | + /** |
|
59 | + * _get_formatter - obtain the requester formatter class |
|
60 | + * |
|
61 | + * @access private |
|
62 | + * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
63 | + * @return EEI_Address_Formatter |
|
64 | + */ |
|
65 | + private static function _get_formatter($type) |
|
66 | + { |
|
67 | + switch ($type) { |
|
68 | + case 'multiline': |
|
69 | + return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter(); |
|
70 | + case 'inline': |
|
71 | + return new EventEspresso\core\services\address\formatters\InlineAddressFormatter(); |
|
72 | + default: |
|
73 | + return new EventEspresso\core\services\address\formatters\NullAddressFormatter(); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * _regular_formatting |
|
81 | - * adds formatting to an address |
|
82 | - * |
|
83 | - * @access private |
|
84 | - * @param object EEI_Address_Formatter $formatter |
|
85 | - * @param object EEI_Address $obj_with_address |
|
86 | - * @param bool $add_wrapper |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - private static function _regular_formatting( |
|
90 | - EEI_Address_Formatter $formatter, |
|
91 | - EEI_Address $obj_with_address, |
|
92 | - $add_wrapper = true |
|
93 | - ) { |
|
94 | - $formatted_address = $add_wrapper ? '<div>' : ''; |
|
95 | - $formatted_address .= $formatter->format( |
|
96 | - $obj_with_address->address(), |
|
97 | - $obj_with_address->address2(), |
|
98 | - $obj_with_address->city(), |
|
99 | - $obj_with_address->state_name(), |
|
100 | - $obj_with_address->zip(), |
|
101 | - $obj_with_address->country_name(), |
|
102 | - $obj_with_address->country_ID() |
|
103 | - ); |
|
104 | - $formatted_address .= $add_wrapper ? '</div>' : ''; |
|
105 | - // return the formatted address |
|
106 | - return $formatted_address; |
|
107 | - } |
|
79 | + /** |
|
80 | + * _regular_formatting |
|
81 | + * adds formatting to an address |
|
82 | + * |
|
83 | + * @access private |
|
84 | + * @param object EEI_Address_Formatter $formatter |
|
85 | + * @param object EEI_Address $obj_with_address |
|
86 | + * @param bool $add_wrapper |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + private static function _regular_formatting( |
|
90 | + EEI_Address_Formatter $formatter, |
|
91 | + EEI_Address $obj_with_address, |
|
92 | + $add_wrapper = true |
|
93 | + ) { |
|
94 | + $formatted_address = $add_wrapper ? '<div>' : ''; |
|
95 | + $formatted_address .= $formatter->format( |
|
96 | + $obj_with_address->address(), |
|
97 | + $obj_with_address->address2(), |
|
98 | + $obj_with_address->city(), |
|
99 | + $obj_with_address->state_name(), |
|
100 | + $obj_with_address->zip(), |
|
101 | + $obj_with_address->country_name(), |
|
102 | + $obj_with_address->country_ID() |
|
103 | + ); |
|
104 | + $formatted_address .= $add_wrapper ? '</div>' : ''; |
|
105 | + // return the formatted address |
|
106 | + return $formatted_address; |
|
107 | + } |
|
108 | 108 | |
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * _schema_formatting |
|
113 | - * adds schema.org formatting to an address |
|
114 | - * |
|
115 | - * @access private |
|
116 | - * @param object EEI_Address_Formatter $formatter |
|
117 | - * @param object EEI_Address $obj_with_address |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - private static function _schema_formatting(EEI_Address_Formatter $formatter, EEI_Address $obj_with_address) |
|
121 | - { |
|
122 | - $formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">'; |
|
123 | - $formatted_address .= $formatter->format( |
|
124 | - EEH_Schema::streetAddress($obj_with_address), |
|
125 | - EEH_Schema::postOfficeBoxNumber($obj_with_address), |
|
126 | - EEH_Schema::addressLocality($obj_with_address), |
|
127 | - EEH_Schema::addressRegion($obj_with_address), |
|
128 | - EEH_Schema::postalCode($obj_with_address), |
|
129 | - EEH_Schema::addressCountry($obj_with_address), |
|
130 | - $obj_with_address->country_ID() |
|
131 | - ); |
|
132 | - $formatted_address .= '</div>'; |
|
133 | - // return the formatted address |
|
134 | - return $formatted_address; |
|
135 | - } |
|
111 | + /** |
|
112 | + * _schema_formatting |
|
113 | + * adds schema.org formatting to an address |
|
114 | + * |
|
115 | + * @access private |
|
116 | + * @param object EEI_Address_Formatter $formatter |
|
117 | + * @param object EEI_Address $obj_with_address |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + private static function _schema_formatting(EEI_Address_Formatter $formatter, EEI_Address $obj_with_address) |
|
121 | + { |
|
122 | + $formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">'; |
|
123 | + $formatted_address .= $formatter->format( |
|
124 | + EEH_Schema::streetAddress($obj_with_address), |
|
125 | + EEH_Schema::postOfficeBoxNumber($obj_with_address), |
|
126 | + EEH_Schema::addressLocality($obj_with_address), |
|
127 | + EEH_Schema::addressRegion($obj_with_address), |
|
128 | + EEH_Schema::postalCode($obj_with_address), |
|
129 | + EEH_Schema::addressCountry($obj_with_address), |
|
130 | + $obj_with_address->country_ID() |
|
131 | + ); |
|
132 | + $formatted_address .= '</div>'; |
|
133 | + // return the formatted address |
|
134 | + return $formatted_address; |
|
135 | + } |
|
136 | 136 | } |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | $add_wrapper = true |
31 | 31 | ) { |
32 | 32 | // check that incoming object implements the EEI_Address interface |
33 | - if (! $obj_with_address instanceof EEI_Address) { |
|
33 | + if ( ! $obj_with_address instanceof EEI_Address) { |
|
34 | 34 | $msg = __('The address could not be formatted.', 'event_espresso'); |
35 | 35 | $dev_msg = __( |
36 | 36 | 'The Address Formatter requires passed objects to implement the EEI_Address interface.', |
37 | 37 | 'event_espresso' |
38 | 38 | ); |
39 | - EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
39 | + EE_Error::add_error($msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
40 | 40 | return null; |
41 | 41 | } |
42 | 42 | // obtain an address formatter |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | ? EEH_Address::_schema_formatting($formatter, $obj_with_address) |
48 | 48 | : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper); |
49 | 49 | $formatted_address = $add_wrapper && ! $use_schema |
50 | - ? '<div class="espresso-address-dv">' . $formatted_address . '</div>' |
|
50 | + ? '<div class="espresso-address-dv">'.$formatted_address.'</div>' |
|
51 | 51 | : $formatted_address; |
52 | 52 | // return the formatted address |
53 | 53 | return $formatted_address; |
@@ -12,108 +12,108 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * _admin_format_content |
|
17 | - * Text formatting function for wp_editor. |
|
18 | - * This should fix all of the formatting issues of text output from the database. |
|
19 | - * |
|
20 | - * @static |
|
21 | - * @access public |
|
22 | - * @param string $content content to format |
|
23 | - * @return string formatted content |
|
24 | - */ |
|
25 | - public static function admin_format_content($content = '') |
|
26 | - { |
|
27 | - return wpautop(stripslashes_deep(html_entity_decode($content, ENT_QUOTES, "UTF-8"))); |
|
28 | - } |
|
15 | + /** |
|
16 | + * _admin_format_content |
|
17 | + * Text formatting function for wp_editor. |
|
18 | + * This should fix all of the formatting issues of text output from the database. |
|
19 | + * |
|
20 | + * @static |
|
21 | + * @access public |
|
22 | + * @param string $content content to format |
|
23 | + * @return string formatted content |
|
24 | + */ |
|
25 | + public static function admin_format_content($content = '') |
|
26 | + { |
|
27 | + return wpautop(stripslashes_deep(html_entity_decode($content, ENT_QUOTES, "UTF-8"))); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * ee_tep_output_string |
|
34 | - * todo: we need a description for this. |
|
35 | - * |
|
36 | - * @static |
|
37 | - * @access public |
|
38 | - * @param string $string string to handle |
|
39 | - * @param boolean $translate //todo what is this for? |
|
40 | - * @param boolean $protected true then we run htmlspecialchars and return |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public static function ee_tep_output_string($string, $translate = false, $protected = false) |
|
44 | - { |
|
45 | - if ($protected === true) { |
|
46 | - return htmlspecialchars($string); |
|
47 | - } else { |
|
48 | - if ($translate === false) { |
|
49 | - return self::ee_tep_parse_input_field_data($string, array( '"' => '"' )); |
|
50 | - } else { |
|
51 | - return self::ee_tep_parse_input_field_data($string, $translate); |
|
52 | - } |
|
53 | - } |
|
54 | - } |
|
32 | + /** |
|
33 | + * ee_tep_output_string |
|
34 | + * todo: we need a description for this. |
|
35 | + * |
|
36 | + * @static |
|
37 | + * @access public |
|
38 | + * @param string $string string to handle |
|
39 | + * @param boolean $translate //todo what is this for? |
|
40 | + * @param boolean $protected true then we run htmlspecialchars and return |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public static function ee_tep_output_string($string, $translate = false, $protected = false) |
|
44 | + { |
|
45 | + if ($protected === true) { |
|
46 | + return htmlspecialchars($string); |
|
47 | + } else { |
|
48 | + if ($translate === false) { |
|
49 | + return self::ee_tep_parse_input_field_data($string, array( '"' => '"' )); |
|
50 | + } else { |
|
51 | + return self::ee_tep_parse_input_field_data($string, $translate); |
|
52 | + } |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * ee_tep_parse_input_field_data |
|
60 | - * |
|
61 | - * @param string $data string to be "translated" |
|
62 | - * @param array ] $parse array in the form array( 'from' => 'to', ... ) |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public static function ee_tep_parse_input_field_data($data, $parse) |
|
66 | - { |
|
67 | - return strtr(trim($data), $parse); |
|
68 | - } |
|
58 | + /** |
|
59 | + * ee_tep_parse_input_field_data |
|
60 | + * |
|
61 | + * @param string $data string to be "translated" |
|
62 | + * @param array ] $parse array in the form array( 'from' => 'to', ... ) |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public static function ee_tep_parse_input_field_data($data, $parse) |
|
66 | + { |
|
67 | + return strtr(trim($data), $parse); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * [ee_tep_not_null description] |
|
74 | - * |
|
75 | - * @param string | array $value [description] |
|
76 | - * @return bool [description] |
|
77 | - */ |
|
78 | - public static function ee_tep_not_null($value) |
|
79 | - { |
|
80 | - if (is_array($value)) { |
|
81 | - if (count($value) > 0) { |
|
82 | - return true; |
|
83 | - } else { |
|
84 | - return false; |
|
85 | - } |
|
86 | - } else { |
|
87 | - if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) { |
|
88 | - return true; |
|
89 | - } else { |
|
90 | - return false; |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
72 | + /** |
|
73 | + * [ee_tep_not_null description] |
|
74 | + * |
|
75 | + * @param string | array $value [description] |
|
76 | + * @return bool [description] |
|
77 | + */ |
|
78 | + public static function ee_tep_not_null($value) |
|
79 | + { |
|
80 | + if (is_array($value)) { |
|
81 | + if (count($value) > 0) { |
|
82 | + return true; |
|
83 | + } else { |
|
84 | + return false; |
|
85 | + } |
|
86 | + } else { |
|
87 | + if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) { |
|
88 | + return true; |
|
89 | + } else { |
|
90 | + return false; |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * Formats a date |
|
99 | - * |
|
100 | - * @param string $date |
|
101 | - * @param string $format - format for the date |
|
102 | - * @deprecated 4.6.12 Note, a search revealed this was not used anywhere in core or in our |
|
103 | - * addons at time of writing this. So just deprecated in case of third party use. |
|
104 | - * @return string |
|
105 | - * @deprecated v4.6.21 |
|
106 | - */ |
|
107 | - public static function event_date_display($date, $format = '') |
|
108 | - { |
|
109 | - EE_Error::doing_it_wrong( |
|
110 | - __METHOD__, |
|
111 | - __( |
|
112 | - 'This method is deprecated as of EE 4.6.12. Currently it does not reformat as with prior behaviour but just returns the incoming string. Please use the EE_Datetime helpers for Datetime on the event to display as desired.', |
|
113 | - 'event_espresso' |
|
114 | - ), |
|
115 | - '4.6.21' |
|
116 | - ); |
|
117 | - return $date; |
|
118 | - } |
|
97 | + /** |
|
98 | + * Formats a date |
|
99 | + * |
|
100 | + * @param string $date |
|
101 | + * @param string $format - format for the date |
|
102 | + * @deprecated 4.6.12 Note, a search revealed this was not used anywhere in core or in our |
|
103 | + * addons at time of writing this. So just deprecated in case of third party use. |
|
104 | + * @return string |
|
105 | + * @deprecated v4.6.21 |
|
106 | + */ |
|
107 | + public static function event_date_display($date, $format = '') |
|
108 | + { |
|
109 | + EE_Error::doing_it_wrong( |
|
110 | + __METHOD__, |
|
111 | + __( |
|
112 | + 'This method is deprecated as of EE 4.6.12. Currently it does not reformat as with prior behaviour but just returns the incoming string. Please use the EE_Datetime helpers for Datetime on the event to display as desired.', |
|
113 | + 'event_espresso' |
|
114 | + ), |
|
115 | + '4.6.21' |
|
116 | + ); |
|
117 | + return $date; |
|
118 | + } |
|
119 | 119 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | return htmlspecialchars($string); |
47 | 47 | } else { |
48 | 48 | if ($translate === false) { |
49 | - return self::ee_tep_parse_input_field_data($string, array( '"' => '"' )); |
|
49 | + return self::ee_tep_parse_input_field_data($string, array('"' => '"')); |
|
50 | 50 | } else { |
51 | 51 | return self::ee_tep_parse_input_field_data($string, $translate); |
52 | 52 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | return false; |
85 | 85 | } |
86 | 86 | } else { |
87 | - if (( $value !== '' ) && ( strtolower($value) !== 'null' ) && ( strlen(trim($value)) > 0 )) { |
|
87 | + if (($value !== '') && (strtolower($value) !== 'null') && (strlen(trim($value)) > 0)) { |
|
88 | 88 | return true; |
89 | 89 | } else { |
90 | 90 | return false; |
@@ -11,42 +11,42 @@ |
||
11 | 11 | class EEH_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @var array $uri_segment_array URL segments |
|
16 | - * @access private |
|
17 | - */ |
|
14 | + /** |
|
15 | + * @var array $uri_segment_array URL segments |
|
16 | + * @access private |
|
17 | + */ |
|
18 | 18 | // final private function __construct() {} |
19 | 19 | |
20 | - /** |
|
21 | - * @ override magic methods |
|
22 | - * @ return void |
|
23 | - */ |
|
24 | - public function __set($a, $b) |
|
25 | - { |
|
26 | - return false; |
|
27 | - } |
|
28 | - public function __get($a) |
|
29 | - { |
|
30 | - return false; |
|
31 | - } |
|
32 | - public function __isset($a) |
|
33 | - { |
|
34 | - return false; |
|
35 | - } |
|
36 | - public function __unset($a) |
|
37 | - { |
|
38 | - return false; |
|
39 | - } |
|
40 | - public function __clone() |
|
41 | - { |
|
42 | - return false; |
|
43 | - } |
|
44 | - public function __wakeup() |
|
45 | - { |
|
46 | - return false; |
|
47 | - } |
|
48 | - public function __destruct() |
|
49 | - { |
|
50 | - return false; |
|
51 | - } |
|
20 | + /** |
|
21 | + * @ override magic methods |
|
22 | + * @ return void |
|
23 | + */ |
|
24 | + public function __set($a, $b) |
|
25 | + { |
|
26 | + return false; |
|
27 | + } |
|
28 | + public function __get($a) |
|
29 | + { |
|
30 | + return false; |
|
31 | + } |
|
32 | + public function __isset($a) |
|
33 | + { |
|
34 | + return false; |
|
35 | + } |
|
36 | + public function __unset($a) |
|
37 | + { |
|
38 | + return false; |
|
39 | + } |
|
40 | + public function __clone() |
|
41 | + { |
|
42 | + return false; |
|
43 | + } |
|
44 | + public function __wakeup() |
|
45 | + { |
|
46 | + return false; |
|
47 | + } |
|
48 | + public function __destruct() |
|
49 | + { |
|
50 | + return false; |
|
51 | + } |
|
52 | 52 | } |
@@ -13,203 +13,203 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays |
|
18 | - * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects |
|
19 | - * |
|
20 | - * @uses array_udiff core php function for setting up our own array comparison |
|
21 | - * @uses self::_compare_objects as the custom method for array_udiff |
|
22 | - * @param array $array1 an array of objects |
|
23 | - * @param array $array2 an array of objects |
|
24 | - * @return array an array of objects found in array 1 that aren't found in array 2. |
|
25 | - */ |
|
26 | - public static function object_array_diff($array1, $array2) |
|
27 | - { |
|
28 | - return array_udiff($array1, $array2, array('self', '_compare_objects')); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed |
|
33 | - * |
|
34 | - * @param array $array |
|
35 | - * @return boolean |
|
36 | - */ |
|
37 | - public static function is_associative_array(array $array) |
|
38 | - { |
|
39 | - return array_keys($array) !== range(0, count($array) - 1); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Gets an item from the array and leave the array intact. Use in place of end() |
|
44 | - * when you don't want to change the array |
|
45 | - * |
|
46 | - * @param array $arr |
|
47 | - * @return mixed what ever is in the array |
|
48 | - */ |
|
49 | - public static function get_one_item_from_array($arr) |
|
50 | - { |
|
51 | - $item = end($arr); |
|
52 | - reset($arr); |
|
53 | - return $item; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Detects if this is a multi-dimensional array (meaning that the top-level |
|
58 | - * values are themselves array. Eg array(array(...),...) |
|
59 | - * |
|
60 | - * @param mixed $arr |
|
61 | - * @return boolean |
|
62 | - */ |
|
63 | - public static function is_multi_dimensional_array($arr) |
|
64 | - { |
|
65 | - if (is_array($arr)) { |
|
66 | - $first_item = reset($arr); |
|
67 | - if (is_array($first_item)) { |
|
68 | - return true;// yep, there's at least 2 levels to this array |
|
69 | - } else { |
|
70 | - return false;// nope, only 1 level |
|
71 | - } |
|
72 | - } else { |
|
73 | - return false;// its not an array at all! |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default |
|
79 | - * |
|
80 | - * @param array $arr |
|
81 | - * @param mixed $index |
|
82 | - * @param mixed $default |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - public static function is_set($arr, $index, $default) |
|
86 | - { |
|
87 | - return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118 |
|
92 | - * |
|
93 | - * @param mixed $value usually a string, but could be an array or object |
|
94 | - * @return mixed the UN-serialized data |
|
95 | - */ |
|
96 | - public static function maybe_unserialize($value) |
|
97 | - { |
|
98 | - $data = maybe_unserialize($value); |
|
99 | - // it's possible that this still has serialized data if its the session. WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesnt' unserialize this automatically. |
|
100 | - $token = 'C'; |
|
101 | - $data = is_string($data) ? trim($data) : $data; |
|
102 | - if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) { |
|
103 | - return unserialize($data); |
|
104 | - } else { |
|
105 | - return $data; |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * insert_into_array |
|
112 | - * |
|
113 | - * @param array $target_array the array to insert new data into |
|
114 | - * @param array $array_to_insert the new data to be inserted |
|
115 | - * @param int | string $offset a known key within $target_array where new data will be inserted |
|
116 | - * @param bool $add_before whether to add new data before or after the offset key |
|
117 | - * @param bool $preserve_keys whether or not to reset numerically indexed arrays |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public static function insert_into_array( |
|
121 | - $target_array = array(), |
|
122 | - $array_to_insert = array(), |
|
123 | - $offset = null, |
|
124 | - $add_before = true, |
|
125 | - $preserve_keys = true |
|
126 | - ) { |
|
127 | - // ensure incoming arrays are actually arrays |
|
128 | - $target_array = (array) $target_array; |
|
129 | - $array_to_insert = (array) $array_to_insert; |
|
130 | - // if no offset key was supplied |
|
131 | - if (empty($offset)) { |
|
132 | - // use start or end of $target_array based on whether we are adding before or not |
|
133 | - $offset = $add_before ? 0 : count($target_array); |
|
134 | - } |
|
135 | - // if offset key is a string, then find the corresponding numeric location for that element |
|
136 | - $offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array)); |
|
137 | - // add one to the offset if adding after |
|
138 | - $offset = $add_before ? $offset : $offset + 1; |
|
139 | - // but ensure offset does not exceed the length of the array |
|
140 | - $offset = $offset > count($target_array) ? count($target_array) : $offset; |
|
141 | - // reindex array ??? |
|
142 | - if ($preserve_keys) { |
|
143 | - // take a slice of the target array from the beginning till the offset, |
|
144 | - // then add the new data |
|
145 | - // then add another slice that starts at the offset and goes till the end |
|
146 | - return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice( |
|
147 | - $target_array, |
|
148 | - $offset, |
|
149 | - null, |
|
150 | - true |
|
151 | - ); |
|
152 | - } else { |
|
153 | - // since we don't want to preserve keys, we can use array_splice |
|
154 | - array_splice($target_array, $offset, 0, $array_to_insert); |
|
155 | - return $target_array; |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * array_merge() is slow and should never be used while looping over data |
|
162 | - * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster |
|
163 | - * so really this acts more like array_replace( $array1, $array2 ) |
|
164 | - * or a union with the arrays flipped ( $array2 + $array1 ) |
|
165 | - * this saves a few lines of code and improves readability |
|
166 | - * |
|
167 | - * @param array $array1 |
|
168 | - * @param array $array2 |
|
169 | - * @return array |
|
170 | - */ |
|
171 | - public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
|
172 | - { |
|
173 | - foreach ($array2 as $key => $value) { |
|
174 | - $array1[ $key ] = $value; |
|
175 | - } |
|
176 | - return $array1; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * given a flat array like $array = array('A', 'B', 'C') |
|
182 | - * will convert into a multidimensional array like $array[A][B][C] |
|
183 | - * if $final_value is provided and is anything other than null, |
|
184 | - * then that will be set as the value for the innermost array key |
|
185 | - * like so: $array[A][B][C] = $final_value |
|
186 | - * |
|
187 | - * @param array $flat_array |
|
188 | - * @param mixed $final_value |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - public static function convert_array_values_to_keys(array $flat_array, $final_value = null) |
|
192 | - { |
|
193 | - $multidimensional = array(); |
|
194 | - $reference = &$multidimensional; |
|
195 | - foreach ($flat_array as $key) { |
|
196 | - $reference[ $key ] = array(); |
|
197 | - $reference = &$reference[ $key ]; |
|
198 | - } |
|
199 | - if ($final_value !== null) { |
|
200 | - $reference = $final_value; |
|
201 | - } |
|
202 | - return $multidimensional; |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
208 | - * @param array $array |
|
209 | - * @return bool |
|
210 | - */ |
|
211 | - public static function is_array_numerically_and_sequentially_indexed(array $array) |
|
212 | - { |
|
213 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
214 | - } |
|
16 | + /** |
|
17 | + * This method basically works the same as the PHP core function array_diff except it allows you to compare arrays |
|
18 | + * of EE_Base_Class objects NOTE: This will ONLY work on an array of EE_Base_Class objects |
|
19 | + * |
|
20 | + * @uses array_udiff core php function for setting up our own array comparison |
|
21 | + * @uses self::_compare_objects as the custom method for array_udiff |
|
22 | + * @param array $array1 an array of objects |
|
23 | + * @param array $array2 an array of objects |
|
24 | + * @return array an array of objects found in array 1 that aren't found in array 2. |
|
25 | + */ |
|
26 | + public static function object_array_diff($array1, $array2) |
|
27 | + { |
|
28 | + return array_udiff($array1, $array2, array('self', '_compare_objects')); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Given that $arr is an array, determines if it's associative or numerically AND sequentially indexed |
|
33 | + * |
|
34 | + * @param array $array |
|
35 | + * @return boolean |
|
36 | + */ |
|
37 | + public static function is_associative_array(array $array) |
|
38 | + { |
|
39 | + return array_keys($array) !== range(0, count($array) - 1); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Gets an item from the array and leave the array intact. Use in place of end() |
|
44 | + * when you don't want to change the array |
|
45 | + * |
|
46 | + * @param array $arr |
|
47 | + * @return mixed what ever is in the array |
|
48 | + */ |
|
49 | + public static function get_one_item_from_array($arr) |
|
50 | + { |
|
51 | + $item = end($arr); |
|
52 | + reset($arr); |
|
53 | + return $item; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Detects if this is a multi-dimensional array (meaning that the top-level |
|
58 | + * values are themselves array. Eg array(array(...),...) |
|
59 | + * |
|
60 | + * @param mixed $arr |
|
61 | + * @return boolean |
|
62 | + */ |
|
63 | + public static function is_multi_dimensional_array($arr) |
|
64 | + { |
|
65 | + if (is_array($arr)) { |
|
66 | + $first_item = reset($arr); |
|
67 | + if (is_array($first_item)) { |
|
68 | + return true;// yep, there's at least 2 levels to this array |
|
69 | + } else { |
|
70 | + return false;// nope, only 1 level |
|
71 | + } |
|
72 | + } else { |
|
73 | + return false;// its not an array at all! |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Shorthand for isset( $arr[ $index ] ) ? $arr[ $index ] : $default |
|
79 | + * |
|
80 | + * @param array $arr |
|
81 | + * @param mixed $index |
|
82 | + * @param mixed $default |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + public static function is_set($arr, $index, $default) |
|
86 | + { |
|
87 | + return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Exactly like `maybe_unserialize`, but also accounts for a WP bug: http://core.trac.wordpress.org/ticket/26118 |
|
92 | + * |
|
93 | + * @param mixed $value usually a string, but could be an array or object |
|
94 | + * @return mixed the UN-serialized data |
|
95 | + */ |
|
96 | + public static function maybe_unserialize($value) |
|
97 | + { |
|
98 | + $data = maybe_unserialize($value); |
|
99 | + // it's possible that this still has serialized data if its the session. WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesnt' unserialize this automatically. |
|
100 | + $token = 'C'; |
|
101 | + $data = is_string($data) ? trim($data) : $data; |
|
102 | + if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) { |
|
103 | + return unserialize($data); |
|
104 | + } else { |
|
105 | + return $data; |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * insert_into_array |
|
112 | + * |
|
113 | + * @param array $target_array the array to insert new data into |
|
114 | + * @param array $array_to_insert the new data to be inserted |
|
115 | + * @param int | string $offset a known key within $target_array where new data will be inserted |
|
116 | + * @param bool $add_before whether to add new data before or after the offset key |
|
117 | + * @param bool $preserve_keys whether or not to reset numerically indexed arrays |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public static function insert_into_array( |
|
121 | + $target_array = array(), |
|
122 | + $array_to_insert = array(), |
|
123 | + $offset = null, |
|
124 | + $add_before = true, |
|
125 | + $preserve_keys = true |
|
126 | + ) { |
|
127 | + // ensure incoming arrays are actually arrays |
|
128 | + $target_array = (array) $target_array; |
|
129 | + $array_to_insert = (array) $array_to_insert; |
|
130 | + // if no offset key was supplied |
|
131 | + if (empty($offset)) { |
|
132 | + // use start or end of $target_array based on whether we are adding before or not |
|
133 | + $offset = $add_before ? 0 : count($target_array); |
|
134 | + } |
|
135 | + // if offset key is a string, then find the corresponding numeric location for that element |
|
136 | + $offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array)); |
|
137 | + // add one to the offset if adding after |
|
138 | + $offset = $add_before ? $offset : $offset + 1; |
|
139 | + // but ensure offset does not exceed the length of the array |
|
140 | + $offset = $offset > count($target_array) ? count($target_array) : $offset; |
|
141 | + // reindex array ??? |
|
142 | + if ($preserve_keys) { |
|
143 | + // take a slice of the target array from the beginning till the offset, |
|
144 | + // then add the new data |
|
145 | + // then add another slice that starts at the offset and goes till the end |
|
146 | + return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice( |
|
147 | + $target_array, |
|
148 | + $offset, |
|
149 | + null, |
|
150 | + true |
|
151 | + ); |
|
152 | + } else { |
|
153 | + // since we don't want to preserve keys, we can use array_splice |
|
154 | + array_splice($target_array, $offset, 0, $array_to_insert); |
|
155 | + return $target_array; |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * array_merge() is slow and should never be used while looping over data |
|
162 | + * if you don't need to preserve keys from all arrays, then using a foreach loop is much faster |
|
163 | + * so really this acts more like array_replace( $array1, $array2 ) |
|
164 | + * or a union with the arrays flipped ( $array2 + $array1 ) |
|
165 | + * this saves a few lines of code and improves readability |
|
166 | + * |
|
167 | + * @param array $array1 |
|
168 | + * @param array $array2 |
|
169 | + * @return array |
|
170 | + */ |
|
171 | + public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
|
172 | + { |
|
173 | + foreach ($array2 as $key => $value) { |
|
174 | + $array1[ $key ] = $value; |
|
175 | + } |
|
176 | + return $array1; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * given a flat array like $array = array('A', 'B', 'C') |
|
182 | + * will convert into a multidimensional array like $array[A][B][C] |
|
183 | + * if $final_value is provided and is anything other than null, |
|
184 | + * then that will be set as the value for the innermost array key |
|
185 | + * like so: $array[A][B][C] = $final_value |
|
186 | + * |
|
187 | + * @param array $flat_array |
|
188 | + * @param mixed $final_value |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + public static function convert_array_values_to_keys(array $flat_array, $final_value = null) |
|
192 | + { |
|
193 | + $multidimensional = array(); |
|
194 | + $reference = &$multidimensional; |
|
195 | + foreach ($flat_array as $key) { |
|
196 | + $reference[ $key ] = array(); |
|
197 | + $reference = &$reference[ $key ]; |
|
198 | + } |
|
199 | + if ($final_value !== null) { |
|
200 | + $reference = $final_value; |
|
201 | + } |
|
202 | + return $multidimensional; |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
208 | + * @param array $array |
|
209 | + * @return bool |
|
210 | + */ |
|
211 | + public static function is_array_numerically_and_sequentially_indexed(array $array) |
|
212 | + { |
|
213 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
214 | + } |
|
215 | 215 | } |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | if (is_array($arr)) { |
66 | 66 | $first_item = reset($arr); |
67 | 67 | if (is_array($first_item)) { |
68 | - return true;// yep, there's at least 2 levels to this array |
|
68 | + return true; // yep, there's at least 2 levels to this array |
|
69 | 69 | } else { |
70 | - return false;// nope, only 1 level |
|
70 | + return false; // nope, only 1 level |
|
71 | 71 | } |
72 | 72 | } else { |
73 | - return false;// its not an array at all! |
|
73 | + return false; // its not an array at all! |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public static function is_set($arr, $index, $default) |
86 | 86 | { |
87 | - return isset($arr[ $index ]) ? $arr[ $index ] : $default; |
|
87 | + return isset($arr[$index]) ? $arr[$index] : $default; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) |
172 | 172 | { |
173 | 173 | foreach ($array2 as $key => $value) { |
174 | - $array1[ $key ] = $value; |
|
174 | + $array1[$key] = $value; |
|
175 | 175 | } |
176 | 176 | return $array1; |
177 | 177 | } |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | $multidimensional = array(); |
194 | 194 | $reference = &$multidimensional; |
195 | 195 | foreach ($flat_array as $key) { |
196 | - $reference[ $key ] = array(); |
|
197 | - $reference = &$reference[ $key ]; |
|
196 | + $reference[$key] = array(); |
|
197 | + $reference = &$reference[$key]; |
|
198 | 198 | } |
199 | 199 | if ($final_value !== null) { |
200 | 200 | $reference = $final_value; |
@@ -13,70 +13,70 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * $CPT - the current page, if it utilizes CPTs |
|
18 | - * |
|
19 | - * @var object |
|
20 | - * @access protected |
|
21 | - */ |
|
22 | - protected $CPT = null; |
|
16 | + /** |
|
17 | + * $CPT - the current page, if it utilizes CPTs |
|
18 | + * |
|
19 | + * @var object |
|
20 | + * @access protected |
|
21 | + */ |
|
22 | + protected $CPT = null; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * class constructor |
|
27 | - * |
|
28 | - * @access private |
|
29 | - * @param array $arguments |
|
30 | - * @return \EE_CPT_Default_Strategy |
|
31 | - */ |
|
32 | - public function __construct($arguments = array()) |
|
33 | - { |
|
34 | - $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null; |
|
35 | - } |
|
25 | + /** |
|
26 | + * class constructor |
|
27 | + * |
|
28 | + * @access private |
|
29 | + * @param array $arguments |
|
30 | + * @return \EE_CPT_Default_Strategy |
|
31 | + */ |
|
32 | + public function __construct($arguments = array()) |
|
33 | + { |
|
34 | + $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * pre_get_posts |
|
40 | - * |
|
41 | - * @access public |
|
42 | - * @param \WP_Query $WP_Query |
|
43 | - * @return \WP_Query |
|
44 | - */ |
|
45 | - public function pre_get_posts(WP_Query $WP_Query) |
|
46 | - { |
|
47 | - if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) { |
|
48 | - return $WP_Query; |
|
49 | - } |
|
50 | - return $WP_Query; |
|
51 | - } |
|
38 | + /** |
|
39 | + * pre_get_posts |
|
40 | + * |
|
41 | + * @access public |
|
42 | + * @param \WP_Query $WP_Query |
|
43 | + * @return \WP_Query |
|
44 | + */ |
|
45 | + public function pre_get_posts(WP_Query $WP_Query) |
|
46 | + { |
|
47 | + if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) { |
|
48 | + return $WP_Query; |
|
49 | + } |
|
50 | + return $WP_Query; |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * wp |
|
56 | - * |
|
57 | - * @access public |
|
58 | - * @param \WP_Post[] $posts |
|
59 | - * @param \WP_Query $WP_Query |
|
60 | - * @return \WP_Post[] |
|
61 | - */ |
|
62 | - public function the_posts($posts, WP_Query $WP_Query) |
|
63 | - { |
|
64 | - return $posts; |
|
65 | - } |
|
54 | + /** |
|
55 | + * wp |
|
56 | + * |
|
57 | + * @access public |
|
58 | + * @param \WP_Post[] $posts |
|
59 | + * @param \WP_Query $WP_Query |
|
60 | + * @return \WP_Post[] |
|
61 | + */ |
|
62 | + public function the_posts($posts, WP_Query $WP_Query) |
|
63 | + { |
|
64 | + return $posts; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * get_EE_post_type_metadata |
|
70 | - * |
|
71 | - * @access public |
|
72 | - * @param mixed $meta_value |
|
73 | - * @param int $post_id |
|
74 | - * @param string $meta_key |
|
75 | - * @param string $single |
|
76 | - * @return mixed |
|
77 | - */ |
|
78 | - public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single) |
|
79 | - { |
|
80 | - return $meta_value; |
|
81 | - } |
|
68 | + /** |
|
69 | + * get_EE_post_type_metadata |
|
70 | + * |
|
71 | + * @access public |
|
72 | + * @param mixed $meta_value |
|
73 | + * @param int $post_id |
|
74 | + * @param string $meta_key |
|
75 | + * @param string $single |
|
76 | + * @return mixed |
|
77 | + */ |
|
78 | + public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single) |
|
79 | + { |
|
80 | + return $meta_value; |
|
81 | + } |
|
82 | 82 | } |
@@ -44,7 +44,7 @@ |
||
44 | 44 | */ |
45 | 45 | public function pre_get_posts(WP_Query $WP_Query) |
46 | 46 | { |
47 | - if (! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) { |
|
47 | + if ( ! $WP_Query->is_main_query() && ! $WP_Query->is_archive()) { |
|
48 | 48 | return $WP_Query; |
49 | 49 | } |
50 | 50 | return $WP_Query; |
@@ -24,39 +24,39 @@ |
||
24 | 24 | class EE_CPT_Attendee_Strategy |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * $CPT - the current page, if it utilizes CPTs |
|
29 | - * |
|
30 | - * @var array |
|
31 | - * @access protected |
|
32 | - */ |
|
33 | - protected $CPT = null; |
|
27 | + /** |
|
28 | + * $CPT - the current page, if it utilizes CPTs |
|
29 | + * |
|
30 | + * @var array |
|
31 | + * @access protected |
|
32 | + */ |
|
33 | + protected $CPT = null; |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * class constructor |
|
38 | - * |
|
39 | - * @access public |
|
40 | - * @param array $arguments |
|
41 | - * @return \EE_CPT_Attendee_Strategy |
|
42 | - */ |
|
43 | - public function __construct($arguments = array()) |
|
44 | - { |
|
45 | - $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null; |
|
46 | - $WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null; |
|
47 | - } |
|
36 | + /** |
|
37 | + * class constructor |
|
38 | + * |
|
39 | + * @access public |
|
40 | + * @param array $arguments |
|
41 | + * @return \EE_CPT_Attendee_Strategy |
|
42 | + */ |
|
43 | + public function __construct($arguments = array()) |
|
44 | + { |
|
45 | + $this->CPT = isset($arguments['CPT']) ? $arguments['CPT'] : null; |
|
46 | + $WP_Query = isset($arguments['WP_Query']) ? $arguments['WP_Query'] : null; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * the_posts |
|
52 | - * |
|
53 | - * @access public |
|
54 | - * @param $posts |
|
55 | - * @param WP_Query $wp_query |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function the_posts($posts, WP_Query $wp_query) |
|
59 | - { |
|
60 | - return $posts; |
|
61 | - } |
|
50 | + /** |
|
51 | + * the_posts |
|
52 | + * |
|
53 | + * @access public |
|
54 | + * @param $posts |
|
55 | + * @param WP_Query $wp_query |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function the_posts($posts, WP_Query $wp_query) |
|
59 | + { |
|
60 | + return $posts; |
|
61 | + } |
|
62 | 62 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public static function instance() |
34 | 34 | { |
35 | 35 | // check if class object is instantiated |
36 | - if (! self::$_instance instanceof EE_Payment_Processor) { |
|
36 | + if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
37 | 37 | self::$_instance = new self(); |
38 | 38 | } |
39 | 39 | return self::$_instance; |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | /** @type \EE_Transaction $transaction */ |
171 | 171 | $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
172 | 172 | $primary_reg = $transaction->primary_registration(); |
173 | - if (! $primary_reg instanceof EE_Registration) { |
|
173 | + if ( ! $primary_reg instanceof EE_Registration) { |
|
174 | 174 | throw new EE_Error( |
175 | 175 | sprintf( |
176 | 176 | __( |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | EEM_Change_Log::instance()->log( |
266 | 266 | EEM_Change_Log::type_gateway, |
267 | 267 | array( |
268 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
268 | + 'message' => 'IPN Exception: '.$e->getMessage(), |
|
269 | 269 | 'current_url' => EEH_URL::current_url(), |
270 | 270 | 'payment' => $e->getPaymentProperties(), |
271 | 271 | 'IPN_data' => $e->getIpnData(), |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | EEM_Change_Log::instance()->log( |
310 | 310 | EEM_Change_Log::type_gateway, |
311 | 311 | array( |
312 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
312 | + 'message' => 'IPN Exception: '.$e->getMessage(), |
|
313 | 313 | 'current_url' => EEH_URL::current_url(), |
314 | 314 | 'payment' => $e->getPaymentProperties(), |
315 | 315 | 'IPN_data' => $e->getIpnData(), |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | { |
381 | 381 | $return_data = array(); |
382 | 382 | foreach ($request_data as $key => $value) { |
383 | - $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters( |
|
383 | + $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters( |
|
384 | 384 | $value |
385 | 385 | ); |
386 | 386 | } |
@@ -18,846 +18,846 @@ |
||
18 | 18 | class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Payment_Processor $_instance |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - private static $_instance; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @singleton method used to instantiate class object |
|
30 | - * @access public |
|
31 | - * @return EE_Payment_Processor instance |
|
32 | - */ |
|
33 | - public static function instance() |
|
34 | - { |
|
35 | - // check if class object is instantiated |
|
36 | - if (! self::$_instance instanceof EE_Payment_Processor) { |
|
37 | - self::$_instance = new self(); |
|
38 | - } |
|
39 | - return self::$_instance; |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @return EE_Payment_Processor |
|
45 | - */ |
|
46 | - public static function reset() |
|
47 | - { |
|
48 | - self::$_instance = null; |
|
49 | - return self::instance(); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - *private constructor to prevent direct creation |
|
55 | - * |
|
56 | - * @Constructor |
|
57 | - * @access private |
|
58 | - */ |
|
59 | - private function __construct() |
|
60 | - { |
|
61 | - do_action('AHEE__EE_Payment_Processor__construct'); |
|
62 | - add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
68 | - * appropriately. Saves the payment that is generated |
|
69 | - * |
|
70 | - * @param EE_Payment_Method $payment_method |
|
71 | - * @param EE_Transaction $transaction |
|
72 | - * @param float $amount if only part of the transaction is to be paid for, how much. |
|
73 | - * Leave null if payment is for the full amount owing |
|
74 | - * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
75 | - * Receive_form_submission() should have |
|
76 | - * already been called on the billing form |
|
77 | - * (ie, its inputs should have their normalized values set). |
|
78 | - * @param string $return_url string used mostly by offsite gateways to specify |
|
79 | - * where to go AFTER the offsite gateway |
|
80 | - * @param string $method like 'CART', indicates who the client who called this was |
|
81 | - * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
82 | - * @param boolean $update_txn whether or not to call |
|
83 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
84 | - * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
85 | - * @return EE_Payment |
|
86 | - * @throws EE_Error |
|
87 | - * @throws InvalidArgumentException |
|
88 | - * @throws ReflectionException |
|
89 | - * @throws RuntimeException |
|
90 | - * @throws InvalidDataTypeException |
|
91 | - * @throws InvalidInterfaceException |
|
92 | - */ |
|
93 | - public function process_payment( |
|
94 | - EE_Payment_Method $payment_method, |
|
95 | - EE_Transaction $transaction, |
|
96 | - $amount = null, |
|
97 | - $billing_form = null, |
|
98 | - $return_url = null, |
|
99 | - $method = 'CART', |
|
100 | - $by_admin = false, |
|
101 | - $update_txn = true, |
|
102 | - $cancel_url = '' |
|
103 | - ) { |
|
104 | - if ((float) $amount < 0) { |
|
105 | - throw new EE_Error( |
|
106 | - sprintf( |
|
107 | - __( |
|
108 | - 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
109 | - 'event_espresso' |
|
110 | - ), |
|
111 | - $amount, |
|
112 | - $transaction->ID() |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
116 | - // verify payment method |
|
117 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
118 | - $payment_method, |
|
119 | - true |
|
120 | - ); |
|
121 | - // verify transaction |
|
122 | - EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
123 | - $transaction->set_payment_method_ID($payment_method->ID()); |
|
124 | - // verify payment method type |
|
125 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
126 | - $payment = $payment_method->type_obj()->process_payment( |
|
127 | - $transaction, |
|
128 | - min($amount, $transaction->remaining()), // make sure we don't overcharge |
|
129 | - $billing_form, |
|
130 | - $return_url, |
|
131 | - add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
132 | - $method, |
|
133 | - $by_admin |
|
134 | - ); |
|
135 | - // check if payment method uses an off-site gateway |
|
136 | - if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
137 | - // don't process payments for off-site gateways yet because no payment has occurred yet |
|
138 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
139 | - } |
|
140 | - return $payment; |
|
141 | - } |
|
142 | - EE_Error::add_error( |
|
143 | - sprintf( |
|
144 | - __( |
|
145 | - 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
146 | - 'event_espresso' |
|
147 | - ), |
|
148 | - '<br/>', |
|
149 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
150 | - ), |
|
151 | - __FILE__, |
|
152 | - __FUNCTION__, |
|
153 | - __LINE__ |
|
154 | - ); |
|
155 | - return null; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @param EE_Transaction|int $transaction |
|
161 | - * @param EE_Payment_Method $payment_method |
|
162 | - * @return string |
|
163 | - * @throws EE_Error |
|
164 | - * @throws InvalidArgumentException |
|
165 | - * @throws InvalidDataTypeException |
|
166 | - * @throws InvalidInterfaceException |
|
167 | - */ |
|
168 | - public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
169 | - { |
|
170 | - /** @type \EE_Transaction $transaction */ |
|
171 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
172 | - $primary_reg = $transaction->primary_registration(); |
|
173 | - if (! $primary_reg instanceof EE_Registration) { |
|
174 | - throw new EE_Error( |
|
175 | - sprintf( |
|
176 | - __( |
|
177 | - 'Cannot get IPN URL for transaction with ID %d because it has no primary registration', |
|
178 | - 'event_espresso' |
|
179 | - ), |
|
180 | - $transaction->ID() |
|
181 | - ) |
|
182 | - ); |
|
183 | - } |
|
184 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
185 | - $payment_method, |
|
186 | - true |
|
187 | - ); |
|
188 | - $url = add_query_arg( |
|
189 | - array( |
|
190 | - 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
191 | - 'ee_payment_method' => $payment_method->slug(), |
|
192 | - ), |
|
193 | - EE_Registry::instance()->CFG->core->txn_page_url() |
|
194 | - ); |
|
195 | - return $url; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
201 | - * we can easily find what registration the IPN is for and what payment method. |
|
202 | - * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
203 | - * If a payment is found for the IPN info, it is saved. |
|
204 | - * |
|
205 | - * @param array $_req_data eg $_REQUEST |
|
206 | - * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
207 | - * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
208 | - * @param boolean $update_txn whether or not to call |
|
209 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
210 | - * @param bool $separate_IPN_request whether the IPN uses a separate request (true, like PayPal) |
|
211 | - * or is processed manually (false, like Authorize.net) |
|
212 | - * @throws EE_Error |
|
213 | - * @throws Exception |
|
214 | - * @return EE_Payment |
|
215 | - * @throws \RuntimeException |
|
216 | - * @throws \ReflectionException |
|
217 | - * @throws \InvalidArgumentException |
|
218 | - * @throws InvalidInterfaceException |
|
219 | - * @throws InvalidDataTypeException |
|
220 | - */ |
|
221 | - public function process_ipn( |
|
222 | - $_req_data, |
|
223 | - $transaction = null, |
|
224 | - $payment_method = null, |
|
225 | - $update_txn = true, |
|
226 | - $separate_IPN_request = true |
|
227 | - ) { |
|
228 | - EE_Registry::instance()->load_model('Change_Log'); |
|
229 | - $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data); |
|
230 | - EE_Processor_Base::set_IPN($separate_IPN_request); |
|
231 | - $obj_for_log = null; |
|
232 | - if ($transaction instanceof EE_Transaction) { |
|
233 | - $obj_for_log = $transaction; |
|
234 | - if ($payment_method instanceof EE_Payment_Method) { |
|
235 | - $obj_for_log = EEM_Payment::instance()->get_one( |
|
236 | - array( |
|
237 | - array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
238 | - 'order_by' => array('PAY_timestamp' => 'desc'), |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - } elseif ($payment_method instanceof EE_Payment) { |
|
243 | - $obj_for_log = $payment_method; |
|
244 | - } |
|
245 | - $log = EEM_Change_Log::instance()->log( |
|
246 | - EEM_Change_Log::type_gateway, |
|
247 | - array('IPN data received' => $_req_data), |
|
248 | - $obj_for_log |
|
249 | - ); |
|
250 | - try { |
|
251 | - /** |
|
252 | - * @var EE_Payment $payment |
|
253 | - */ |
|
254 | - $payment = null; |
|
255 | - if ($transaction && $payment_method) { |
|
256 | - /** @type EE_Transaction $transaction */ |
|
257 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
258 | - /** @type EE_Payment_Method $payment_method */ |
|
259 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
260 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
261 | - try { |
|
262 | - $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
263 | - $log->set_object($payment); |
|
264 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
265 | - EEM_Change_Log::instance()->log( |
|
266 | - EEM_Change_Log::type_gateway, |
|
267 | - array( |
|
268 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
269 | - 'current_url' => EEH_URL::current_url(), |
|
270 | - 'payment' => $e->getPaymentProperties(), |
|
271 | - 'IPN_data' => $e->getIpnData(), |
|
272 | - ), |
|
273 | - $obj_for_log |
|
274 | - ); |
|
275 | - return $e->getPayment(); |
|
276 | - } |
|
277 | - } else { |
|
278 | - // not a payment |
|
279 | - EE_Error::add_error( |
|
280 | - sprintf( |
|
281 | - __( |
|
282 | - 'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', |
|
283 | - 'event_espresso' |
|
284 | - ), |
|
285 | - '<br/>', |
|
286 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
287 | - ), |
|
288 | - __FILE__, |
|
289 | - __FUNCTION__, |
|
290 | - __LINE__ |
|
291 | - ); |
|
292 | - } |
|
293 | - } else { |
|
294 | - // that's actually pretty ok. The IPN just wasn't able |
|
295 | - // to identify which transaction or payment method this was for |
|
296 | - // give all active payment methods a chance to claim it |
|
297 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
298 | - foreach ($active_payment_methods as $active_payment_method) { |
|
299 | - try { |
|
300 | - $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
301 | - $payment_method = $active_payment_method; |
|
302 | - EEM_Change_Log::instance()->log( |
|
303 | - EEM_Change_Log::type_gateway, |
|
304 | - array('IPN data' => $_req_data), |
|
305 | - $payment |
|
306 | - ); |
|
307 | - break; |
|
308 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
309 | - EEM_Change_Log::instance()->log( |
|
310 | - EEM_Change_Log::type_gateway, |
|
311 | - array( |
|
312 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
313 | - 'current_url' => EEH_URL::current_url(), |
|
314 | - 'payment' => $e->getPaymentProperties(), |
|
315 | - 'IPN_data' => $e->getIpnData(), |
|
316 | - ), |
|
317 | - $obj_for_log |
|
318 | - ); |
|
319 | - return $e->getPayment(); |
|
320 | - } catch (EE_Error $e) { |
|
321 | - // that's fine- it apparently couldn't handle the IPN |
|
322 | - } |
|
323 | - } |
|
324 | - } |
|
325 | - // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
326 | - if ($payment instanceof EE_Payment) { |
|
327 | - $payment->save(); |
|
328 | - // update the TXN |
|
329 | - $this->update_txn_based_on_payment( |
|
330 | - $transaction, |
|
331 | - $payment, |
|
332 | - $update_txn, |
|
333 | - $separate_IPN_request |
|
334 | - ); |
|
335 | - } else { |
|
336 | - // we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
337 | - if ($payment_method) { |
|
338 | - EEM_Change_Log::instance()->log( |
|
339 | - EEM_Change_Log::type_gateway, |
|
340 | - array('IPN data' => $_req_data), |
|
341 | - $payment_method |
|
342 | - ); |
|
343 | - } elseif ($transaction) { |
|
344 | - EEM_Change_Log::instance()->log( |
|
345 | - EEM_Change_Log::type_gateway, |
|
346 | - array('IPN data' => $_req_data), |
|
347 | - $transaction |
|
348 | - ); |
|
349 | - } |
|
350 | - } |
|
351 | - return $payment; |
|
352 | - } catch (EE_Error $e) { |
|
353 | - do_action( |
|
354 | - 'AHEE__log', |
|
355 | - __FILE__, |
|
356 | - __FUNCTION__, |
|
357 | - sprintf( |
|
358 | - __( |
|
359 | - 'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', |
|
360 | - 'event_espresso' |
|
361 | - ), |
|
362 | - print_r($transaction, true), |
|
363 | - print_r($_req_data, true), |
|
364 | - $e->getMessage() |
|
365 | - ) |
|
366 | - ); |
|
367 | - throw $e; |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Removes any non-printable illegal characters from the input, |
|
374 | - * which might cause a raucous when trying to insert into the database |
|
375 | - * |
|
376 | - * @param array $request_data |
|
377 | - * @return array |
|
378 | - */ |
|
379 | - protected function _remove_unusable_characters_from_array(array $request_data) |
|
380 | - { |
|
381 | - $return_data = array(); |
|
382 | - foreach ($request_data as $key => $value) { |
|
383 | - $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters( |
|
384 | - $value |
|
385 | - ); |
|
386 | - } |
|
387 | - return $return_data; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * Removes any non-printable illegal characters from the input, |
|
393 | - * which might cause a raucous when trying to insert into the database |
|
394 | - * |
|
395 | - * @param string $request_data |
|
396 | - * @return string |
|
397 | - */ |
|
398 | - protected function _remove_unusable_characters($request_data) |
|
399 | - { |
|
400 | - return preg_replace('/[^[:print:]]/', '', $request_data); |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * Should be called just before displaying the payment attempt results to the user, |
|
406 | - * when the payment attempt has finished. Some payment methods may have special |
|
407 | - * logic to perform here. For example, if process_payment() happens on a special request |
|
408 | - * and then the user is redirected to a page that displays the payment's status, this |
|
409 | - * should be called while loading the page that displays the payment's status. If the user is |
|
410 | - * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
411 | - * provider. |
|
412 | - * |
|
413 | - * @param EE_Transaction|int $transaction |
|
414 | - * @param bool $update_txn whether or not to call |
|
415 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
416 | - * @return EE_Payment |
|
417 | - * @throws EE_Error |
|
418 | - * @throws InvalidArgumentException |
|
419 | - * @throws ReflectionException |
|
420 | - * @throws RuntimeException |
|
421 | - * @throws InvalidDataTypeException |
|
422 | - * @throws InvalidInterfaceException |
|
423 | - * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
424 | - * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
425 | - */ |
|
426 | - public function finalize_payment_for($transaction, $update_txn = true) |
|
427 | - { |
|
428 | - /** @var $transaction EE_Transaction */ |
|
429 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
430 | - $last_payment_method = $transaction->payment_method(); |
|
431 | - if ($last_payment_method instanceof EE_Payment_Method) { |
|
432 | - $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
433 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
434 | - return $payment; |
|
435 | - } |
|
436 | - return null; |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
442 | - * |
|
443 | - * @param EE_Payment_Method $payment_method |
|
444 | - * @param EE_Payment $payment_to_refund |
|
445 | - * @param array $refund_info |
|
446 | - * @return EE_Payment |
|
447 | - * @throws EE_Error |
|
448 | - * @throws InvalidArgumentException |
|
449 | - * @throws ReflectionException |
|
450 | - * @throws RuntimeException |
|
451 | - * @throws InvalidDataTypeException |
|
452 | - * @throws InvalidInterfaceException |
|
453 | - */ |
|
454 | - public function process_refund( |
|
455 | - EE_Payment_Method $payment_method, |
|
456 | - EE_Payment $payment_to_refund, |
|
457 | - array $refund_info = array() |
|
458 | - ) { |
|
459 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
460 | - $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
461 | - $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
462 | - } |
|
463 | - return $payment_to_refund; |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * This should be called each time there may have been an update to a |
|
469 | - * payment on a transaction (ie, we asked for a payment to process a |
|
470 | - * payment for a transaction, or we told a payment method about an IPN, or |
|
471 | - * we told a payment method to |
|
472 | - * "finalize_payment_for" (a transaction), or we told a payment method to |
|
473 | - * process a refund. This should handle firing the correct hooks to |
|
474 | - * indicate |
|
475 | - * what exactly happened and updating the transaction appropriately). This |
|
476 | - * could be integrated directly into EE_Transaction upon save, but we want |
|
477 | - * this logic to be separate from 'normal' plain-jane saving and updating |
|
478 | - * of transactions and payments, and to be tied to payment processing. |
|
479 | - * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
480 | - * of previous code to decide whether or not to save (because the payment passed into |
|
481 | - * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
482 | - * in which case we only want that payment object for some temporary usage during this request, |
|
483 | - * but we don't want it to be saved). |
|
484 | - * |
|
485 | - * @param EE_Transaction|int $transaction |
|
486 | - * @param EE_Payment $payment |
|
487 | - * @param boolean $update_txn |
|
488 | - * whether or not to call |
|
489 | - * EE_Transaction_Processor:: |
|
490 | - * update_transaction_and_registrations_after_checkout_or_payment() |
|
491 | - * (you can save 1 DB query if you know you're going |
|
492 | - * to save it later instead) |
|
493 | - * @param bool $IPN |
|
494 | - * if processing IPNs or other similar payment |
|
495 | - * related activities that occur in alternate |
|
496 | - * requests than the main one that is processing the |
|
497 | - * TXN, then set this to true to check whether the |
|
498 | - * TXN is locked before updating |
|
499 | - * @throws EE_Error |
|
500 | - * @throws InvalidArgumentException |
|
501 | - * @throws ReflectionException |
|
502 | - * @throws RuntimeException |
|
503 | - * @throws InvalidDataTypeException |
|
504 | - * @throws InvalidInterfaceException |
|
505 | - */ |
|
506 | - public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
507 | - { |
|
508 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
509 | - /** @type EE_Transaction $transaction */ |
|
510 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
511 | - // can we freely update the TXN at this moment? |
|
512 | - if ($IPN && $transaction->is_locked()) { |
|
513 | - // don't update the transaction at this exact moment |
|
514 | - // because the TXN is active in another request |
|
515 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
516 | - time(), |
|
517 | - $transaction->ID(), |
|
518 | - $payment->ID() |
|
519 | - ); |
|
520 | - } else { |
|
521 | - // verify payment and that it has been saved |
|
522 | - if ($payment instanceof EE_Payment && $payment->ID()) { |
|
523 | - if ( |
|
524 | - $payment->payment_method() instanceof EE_Payment_Method |
|
525 | - && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
526 | - ) { |
|
527 | - $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
528 | - // update TXN registrations with payment info |
|
529 | - $this->process_registration_payments($transaction, $payment); |
|
530 | - } |
|
531 | - $do_action = $payment->just_approved() |
|
532 | - ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
533 | - : $do_action; |
|
534 | - } else { |
|
535 | - // send out notifications |
|
536 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
537 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
538 | - } |
|
539 | - if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
540 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
541 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
542 | - // set new value for total paid |
|
543 | - $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
544 | - // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
545 | - if ($update_txn) { |
|
546 | - $this->_post_payment_processing($transaction, $payment, $IPN); |
|
547 | - } |
|
548 | - } |
|
549 | - // granular hook for others to use. |
|
550 | - do_action($do_action, $transaction, $payment); |
|
551 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
552 | - // global hook for others to use. |
|
553 | - do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
554 | - } |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * update registrations REG_paid field after successful payment and link registrations with payment |
|
560 | - * |
|
561 | - * @param EE_Transaction $transaction |
|
562 | - * @param EE_Payment $payment |
|
563 | - * @param EE_Registration[] $registrations |
|
564 | - * @throws EE_Error |
|
565 | - * @throws InvalidArgumentException |
|
566 | - * @throws RuntimeException |
|
567 | - * @throws InvalidDataTypeException |
|
568 | - * @throws InvalidInterfaceException |
|
569 | - */ |
|
570 | - public function process_registration_payments( |
|
571 | - EE_Transaction $transaction, |
|
572 | - EE_Payment $payment, |
|
573 | - array $registrations = array() |
|
574 | - ) { |
|
575 | - // only process if payment was successful |
|
576 | - if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
577 | - return; |
|
578 | - } |
|
579 | - // EEM_Registration::instance()->show_next_x_db_queries(); |
|
580 | - if (empty($registrations)) { |
|
581 | - // find registrations with monies owing that can receive a payment |
|
582 | - $registrations = $transaction->registrations( |
|
583 | - array( |
|
584 | - array( |
|
585 | - // only these reg statuses can receive payments |
|
586 | - 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
587 | - 'REG_final_price' => array('!=', 0), |
|
588 | - 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
589 | - ), |
|
590 | - ) |
|
591 | - ); |
|
592 | - } |
|
593 | - // still nothing ??!?? |
|
594 | - if (empty($registrations)) { |
|
595 | - return; |
|
596 | - } |
|
597 | - // todo: break out the following logic into a separate strategy class |
|
598 | - // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
599 | - // todo: which would apply payments using the capitalist "first come first paid" approach |
|
600 | - // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
601 | - // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
602 | - // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
603 | - $refund = $payment->is_a_refund(); |
|
604 | - // how much is available to apply to registrations? |
|
605 | - $available_payment_amount = abs($payment->amount()); |
|
606 | - foreach ($registrations as $registration) { |
|
607 | - if ($registration instanceof EE_Registration) { |
|
608 | - // nothing left? |
|
609 | - if ($available_payment_amount <= 0) { |
|
610 | - break; |
|
611 | - } |
|
612 | - if ($refund) { |
|
613 | - $available_payment_amount = $this->process_registration_refund( |
|
614 | - $registration, |
|
615 | - $payment, |
|
616 | - $available_payment_amount |
|
617 | - ); |
|
618 | - } else { |
|
619 | - $available_payment_amount = $this->process_registration_payment( |
|
620 | - $registration, |
|
621 | - $payment, |
|
622 | - $available_payment_amount |
|
623 | - ); |
|
624 | - } |
|
625 | - } |
|
626 | - } |
|
627 | - if ( |
|
628 | - $available_payment_amount > 0 |
|
629 | - && apply_filters( |
|
630 | - 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', |
|
631 | - false |
|
632 | - ) |
|
633 | - ) { |
|
634 | - EE_Error::add_attention( |
|
635 | - sprintf( |
|
636 | - __( |
|
637 | - 'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
638 | - 'event_espresso' |
|
639 | - ), |
|
640 | - EEH_Template::format_currency($available_payment_amount), |
|
641 | - implode(', ', array_keys($registrations)), |
|
642 | - '<br/>', |
|
643 | - EEH_Template::format_currency($payment->amount()) |
|
644 | - ), |
|
645 | - __FILE__, |
|
646 | - __FUNCTION__, |
|
647 | - __LINE__ |
|
648 | - ); |
|
649 | - } |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * update registration REG_paid field after successful payment and link registration with payment |
|
655 | - * |
|
656 | - * @param EE_Registration $registration |
|
657 | - * @param EE_Payment $payment |
|
658 | - * @param float $available_payment_amount |
|
659 | - * @return float |
|
660 | - * @throws EE_Error |
|
661 | - * @throws InvalidArgumentException |
|
662 | - * @throws RuntimeException |
|
663 | - * @throws InvalidDataTypeException |
|
664 | - * @throws InvalidInterfaceException |
|
665 | - */ |
|
666 | - public function process_registration_payment( |
|
667 | - EE_Registration $registration, |
|
668 | - EE_Payment $payment, |
|
669 | - $available_payment_amount = 0.00 |
|
670 | - ) { |
|
671 | - $owing = $registration->final_price() - $registration->paid(); |
|
672 | - if ($owing > 0) { |
|
673 | - // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
674 | - $payment_amount = min($available_payment_amount, $owing); |
|
675 | - // update $available_payment_amount |
|
676 | - $available_payment_amount -= $payment_amount; |
|
677 | - // calculate and set new REG_paid |
|
678 | - $registration->set_paid($registration->paid() + $payment_amount); |
|
679 | - // now save it |
|
680 | - $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
681 | - } |
|
682 | - return $available_payment_amount; |
|
683 | - } |
|
684 | - |
|
685 | - |
|
686 | - /** |
|
687 | - * update registration REG_paid field after successful payment and link registration with payment |
|
688 | - * |
|
689 | - * @param EE_Registration $registration |
|
690 | - * @param EE_Payment $payment |
|
691 | - * @param float $payment_amount |
|
692 | - * @return void |
|
693 | - * @throws EE_Error |
|
694 | - * @throws InvalidArgumentException |
|
695 | - * @throws InvalidDataTypeException |
|
696 | - * @throws InvalidInterfaceException |
|
697 | - */ |
|
698 | - protected function _apply_registration_payment( |
|
699 | - EE_Registration $registration, |
|
700 | - EE_Payment $payment, |
|
701 | - $payment_amount = 0.00 |
|
702 | - ) { |
|
703 | - // find any existing reg payment records for this registration and payment |
|
704 | - $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
705 | - array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
706 | - ); |
|
707 | - // if existing registration payment exists |
|
708 | - if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
709 | - // then update that record |
|
710 | - $existing_reg_payment->set_amount($payment_amount); |
|
711 | - $existing_reg_payment->save(); |
|
712 | - } else { |
|
713 | - // or add new relation between registration and payment and set amount |
|
714 | - $registration->_add_relation_to( |
|
715 | - $payment, |
|
716 | - 'Payment', |
|
717 | - array('RPY_amount' => $payment_amount) |
|
718 | - ); |
|
719 | - // make it stick |
|
720 | - $registration->save(); |
|
721 | - } |
|
722 | - } |
|
723 | - |
|
724 | - |
|
725 | - /** |
|
726 | - * update registration REG_paid field after refund and link registration with payment |
|
727 | - * |
|
728 | - * @param EE_Registration $registration |
|
729 | - * @param EE_Payment $payment |
|
730 | - * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
731 | - * @return float |
|
732 | - * @throws EE_Error |
|
733 | - * @throws InvalidArgumentException |
|
734 | - * @throws RuntimeException |
|
735 | - * @throws InvalidDataTypeException |
|
736 | - * @throws InvalidInterfaceException |
|
737 | - */ |
|
738 | - public function process_registration_refund( |
|
739 | - EE_Registration $registration, |
|
740 | - EE_Payment $payment, |
|
741 | - $available_refund_amount = 0.00 |
|
742 | - ) { |
|
743 | - // EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
744 | - if ($registration->paid() > 0) { |
|
745 | - // ensure $available_refund_amount is NOT negative |
|
746 | - $available_refund_amount = (float) abs($available_refund_amount); |
|
747 | - // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
748 | - $refund_amount = min($available_refund_amount, (float) $registration->paid()); |
|
749 | - // update $available_payment_amount |
|
750 | - $available_refund_amount -= $refund_amount; |
|
751 | - // calculate and set new REG_paid |
|
752 | - $registration->set_paid($registration->paid() - $refund_amount); |
|
753 | - // convert payment amount back to a negative value for storage in the db |
|
754 | - $refund_amount = (float) abs($refund_amount) * -1; |
|
755 | - // now save it |
|
756 | - $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
757 | - } |
|
758 | - return $available_refund_amount; |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * Process payments and transaction after payment process completed. |
|
764 | - * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
765 | - * if this request happens to be processing an IPN, |
|
766 | - * then we will also set the Payment Options Reg Step to completed, |
|
767 | - * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
768 | - * |
|
769 | - * @param EE_Transaction $transaction |
|
770 | - * @param EE_Payment $payment |
|
771 | - * @param bool $IPN |
|
772 | - * @throws EE_Error |
|
773 | - * @throws InvalidArgumentException |
|
774 | - * @throws ReflectionException |
|
775 | - * @throws RuntimeException |
|
776 | - * @throws InvalidDataTypeException |
|
777 | - * @throws InvalidInterfaceException |
|
778 | - */ |
|
779 | - protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
780 | - { |
|
781 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
782 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
783 | - // is the Payment Options Reg Step completed ? |
|
784 | - $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
785 | - // if the Payment Options Reg Step is completed... |
|
786 | - $revisit = $payment_options_step_completed === true; |
|
787 | - // then this is kinda sorta a revisit with regards to payments at least |
|
788 | - $transaction_processor->set_revisit($revisit); |
|
789 | - // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
790 | - if ( |
|
791 | - $IPN |
|
792 | - && $payment_options_step_completed !== true |
|
793 | - && ($payment->is_approved() || $payment->is_pending()) |
|
794 | - ) { |
|
795 | - $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
796 | - 'payment_options' |
|
797 | - ); |
|
798 | - } |
|
799 | - // maybe update status, but don't save transaction just yet |
|
800 | - $transaction->update_status_based_on_total_paid(false); |
|
801 | - // check if 'finalize_registration' step has been completed... |
|
802 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
803 | - // if this is an IPN and the final step has not been initiated |
|
804 | - if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
805 | - // and if it hasn't already been set as being started... |
|
806 | - $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
807 | - } |
|
808 | - $transaction->save(); |
|
809 | - // because the above will return false if the final step was not fully completed, we need to check again... |
|
810 | - if ($IPN && $finalized !== false) { |
|
811 | - // and if we are all good to go, then send out notifications |
|
812 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
813 | - // ok, now process the transaction according to the payment |
|
814 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
815 | - $transaction, |
|
816 | - $payment |
|
817 | - ); |
|
818 | - } |
|
819 | - // DEBUG LOG |
|
820 | - $payment_method = $payment->payment_method(); |
|
821 | - if ($payment_method instanceof EE_Payment_Method) { |
|
822 | - $payment_method_type_obj = $payment_method->type_obj(); |
|
823 | - if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
824 | - $gateway = $payment_method_type_obj->get_gateway(); |
|
825 | - if ($gateway instanceof EE_Gateway) { |
|
826 | - $gateway->log( |
|
827 | - array( |
|
828 | - 'message' => (string) __('Post Payment Transaction Details', 'event_espresso'), |
|
829 | - 'transaction' => $transaction->model_field_array(), |
|
830 | - 'finalized' => $finalized, |
|
831 | - 'IPN' => $IPN, |
|
832 | - 'deliver_notifications' => has_filter( |
|
833 | - 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
834 | - ), |
|
835 | - ), |
|
836 | - $payment |
|
837 | - ); |
|
838 | - } |
|
839 | - } |
|
840 | - } |
|
841 | - } |
|
842 | - |
|
843 | - |
|
844 | - /** |
|
845 | - * Force posts to PayPal to use TLS v1.2. See: |
|
846 | - * https://core.trac.wordpress.org/ticket/36320 |
|
847 | - * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
848 | - * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
849 | - * This will affect PayPal standard, pro, express, and Payflow. |
|
850 | - * |
|
851 | - * @param $handle |
|
852 | - * @param $r |
|
853 | - * @param $url |
|
854 | - */ |
|
855 | - public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
856 | - { |
|
857 | - if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) { |
|
858 | - // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
859 | - // instead of the constant because it might not be defined |
|
860 | - curl_setopt($handle, CURLOPT_SSLVERSION, 6); |
|
861 | - } |
|
862 | - } |
|
21 | + /** |
|
22 | + * @var EE_Payment_Processor $_instance |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + private static $_instance; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @singleton method used to instantiate class object |
|
30 | + * @access public |
|
31 | + * @return EE_Payment_Processor instance |
|
32 | + */ |
|
33 | + public static function instance() |
|
34 | + { |
|
35 | + // check if class object is instantiated |
|
36 | + if (! self::$_instance instanceof EE_Payment_Processor) { |
|
37 | + self::$_instance = new self(); |
|
38 | + } |
|
39 | + return self::$_instance; |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @return EE_Payment_Processor |
|
45 | + */ |
|
46 | + public static function reset() |
|
47 | + { |
|
48 | + self::$_instance = null; |
|
49 | + return self::instance(); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + *private constructor to prevent direct creation |
|
55 | + * |
|
56 | + * @Constructor |
|
57 | + * @access private |
|
58 | + */ |
|
59 | + private function __construct() |
|
60 | + { |
|
61 | + do_action('AHEE__EE_Payment_Processor__construct'); |
|
62 | + add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
68 | + * appropriately. Saves the payment that is generated |
|
69 | + * |
|
70 | + * @param EE_Payment_Method $payment_method |
|
71 | + * @param EE_Transaction $transaction |
|
72 | + * @param float $amount if only part of the transaction is to be paid for, how much. |
|
73 | + * Leave null if payment is for the full amount owing |
|
74 | + * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
75 | + * Receive_form_submission() should have |
|
76 | + * already been called on the billing form |
|
77 | + * (ie, its inputs should have their normalized values set). |
|
78 | + * @param string $return_url string used mostly by offsite gateways to specify |
|
79 | + * where to go AFTER the offsite gateway |
|
80 | + * @param string $method like 'CART', indicates who the client who called this was |
|
81 | + * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
82 | + * @param boolean $update_txn whether or not to call |
|
83 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
84 | + * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
85 | + * @return EE_Payment |
|
86 | + * @throws EE_Error |
|
87 | + * @throws InvalidArgumentException |
|
88 | + * @throws ReflectionException |
|
89 | + * @throws RuntimeException |
|
90 | + * @throws InvalidDataTypeException |
|
91 | + * @throws InvalidInterfaceException |
|
92 | + */ |
|
93 | + public function process_payment( |
|
94 | + EE_Payment_Method $payment_method, |
|
95 | + EE_Transaction $transaction, |
|
96 | + $amount = null, |
|
97 | + $billing_form = null, |
|
98 | + $return_url = null, |
|
99 | + $method = 'CART', |
|
100 | + $by_admin = false, |
|
101 | + $update_txn = true, |
|
102 | + $cancel_url = '' |
|
103 | + ) { |
|
104 | + if ((float) $amount < 0) { |
|
105 | + throw new EE_Error( |
|
106 | + sprintf( |
|
107 | + __( |
|
108 | + 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
109 | + 'event_espresso' |
|
110 | + ), |
|
111 | + $amount, |
|
112 | + $transaction->ID() |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + // verify payment method |
|
117 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
118 | + $payment_method, |
|
119 | + true |
|
120 | + ); |
|
121 | + // verify transaction |
|
122 | + EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
123 | + $transaction->set_payment_method_ID($payment_method->ID()); |
|
124 | + // verify payment method type |
|
125 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
126 | + $payment = $payment_method->type_obj()->process_payment( |
|
127 | + $transaction, |
|
128 | + min($amount, $transaction->remaining()), // make sure we don't overcharge |
|
129 | + $billing_form, |
|
130 | + $return_url, |
|
131 | + add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
132 | + $method, |
|
133 | + $by_admin |
|
134 | + ); |
|
135 | + // check if payment method uses an off-site gateway |
|
136 | + if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
137 | + // don't process payments for off-site gateways yet because no payment has occurred yet |
|
138 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
139 | + } |
|
140 | + return $payment; |
|
141 | + } |
|
142 | + EE_Error::add_error( |
|
143 | + sprintf( |
|
144 | + __( |
|
145 | + 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
146 | + 'event_espresso' |
|
147 | + ), |
|
148 | + '<br/>', |
|
149 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
150 | + ), |
|
151 | + __FILE__, |
|
152 | + __FUNCTION__, |
|
153 | + __LINE__ |
|
154 | + ); |
|
155 | + return null; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @param EE_Transaction|int $transaction |
|
161 | + * @param EE_Payment_Method $payment_method |
|
162 | + * @return string |
|
163 | + * @throws EE_Error |
|
164 | + * @throws InvalidArgumentException |
|
165 | + * @throws InvalidDataTypeException |
|
166 | + * @throws InvalidInterfaceException |
|
167 | + */ |
|
168 | + public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
169 | + { |
|
170 | + /** @type \EE_Transaction $transaction */ |
|
171 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
172 | + $primary_reg = $transaction->primary_registration(); |
|
173 | + if (! $primary_reg instanceof EE_Registration) { |
|
174 | + throw new EE_Error( |
|
175 | + sprintf( |
|
176 | + __( |
|
177 | + 'Cannot get IPN URL for transaction with ID %d because it has no primary registration', |
|
178 | + 'event_espresso' |
|
179 | + ), |
|
180 | + $transaction->ID() |
|
181 | + ) |
|
182 | + ); |
|
183 | + } |
|
184 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
185 | + $payment_method, |
|
186 | + true |
|
187 | + ); |
|
188 | + $url = add_query_arg( |
|
189 | + array( |
|
190 | + 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
191 | + 'ee_payment_method' => $payment_method->slug(), |
|
192 | + ), |
|
193 | + EE_Registry::instance()->CFG->core->txn_page_url() |
|
194 | + ); |
|
195 | + return $url; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
201 | + * we can easily find what registration the IPN is for and what payment method. |
|
202 | + * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
203 | + * If a payment is found for the IPN info, it is saved. |
|
204 | + * |
|
205 | + * @param array $_req_data eg $_REQUEST |
|
206 | + * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
207 | + * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
208 | + * @param boolean $update_txn whether or not to call |
|
209 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
210 | + * @param bool $separate_IPN_request whether the IPN uses a separate request (true, like PayPal) |
|
211 | + * or is processed manually (false, like Authorize.net) |
|
212 | + * @throws EE_Error |
|
213 | + * @throws Exception |
|
214 | + * @return EE_Payment |
|
215 | + * @throws \RuntimeException |
|
216 | + * @throws \ReflectionException |
|
217 | + * @throws \InvalidArgumentException |
|
218 | + * @throws InvalidInterfaceException |
|
219 | + * @throws InvalidDataTypeException |
|
220 | + */ |
|
221 | + public function process_ipn( |
|
222 | + $_req_data, |
|
223 | + $transaction = null, |
|
224 | + $payment_method = null, |
|
225 | + $update_txn = true, |
|
226 | + $separate_IPN_request = true |
|
227 | + ) { |
|
228 | + EE_Registry::instance()->load_model('Change_Log'); |
|
229 | + $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data); |
|
230 | + EE_Processor_Base::set_IPN($separate_IPN_request); |
|
231 | + $obj_for_log = null; |
|
232 | + if ($transaction instanceof EE_Transaction) { |
|
233 | + $obj_for_log = $transaction; |
|
234 | + if ($payment_method instanceof EE_Payment_Method) { |
|
235 | + $obj_for_log = EEM_Payment::instance()->get_one( |
|
236 | + array( |
|
237 | + array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
238 | + 'order_by' => array('PAY_timestamp' => 'desc'), |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + } elseif ($payment_method instanceof EE_Payment) { |
|
243 | + $obj_for_log = $payment_method; |
|
244 | + } |
|
245 | + $log = EEM_Change_Log::instance()->log( |
|
246 | + EEM_Change_Log::type_gateway, |
|
247 | + array('IPN data received' => $_req_data), |
|
248 | + $obj_for_log |
|
249 | + ); |
|
250 | + try { |
|
251 | + /** |
|
252 | + * @var EE_Payment $payment |
|
253 | + */ |
|
254 | + $payment = null; |
|
255 | + if ($transaction && $payment_method) { |
|
256 | + /** @type EE_Transaction $transaction */ |
|
257 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
258 | + /** @type EE_Payment_Method $payment_method */ |
|
259 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
260 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
261 | + try { |
|
262 | + $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
263 | + $log->set_object($payment); |
|
264 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
265 | + EEM_Change_Log::instance()->log( |
|
266 | + EEM_Change_Log::type_gateway, |
|
267 | + array( |
|
268 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
269 | + 'current_url' => EEH_URL::current_url(), |
|
270 | + 'payment' => $e->getPaymentProperties(), |
|
271 | + 'IPN_data' => $e->getIpnData(), |
|
272 | + ), |
|
273 | + $obj_for_log |
|
274 | + ); |
|
275 | + return $e->getPayment(); |
|
276 | + } |
|
277 | + } else { |
|
278 | + // not a payment |
|
279 | + EE_Error::add_error( |
|
280 | + sprintf( |
|
281 | + __( |
|
282 | + 'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', |
|
283 | + 'event_espresso' |
|
284 | + ), |
|
285 | + '<br/>', |
|
286 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
287 | + ), |
|
288 | + __FILE__, |
|
289 | + __FUNCTION__, |
|
290 | + __LINE__ |
|
291 | + ); |
|
292 | + } |
|
293 | + } else { |
|
294 | + // that's actually pretty ok. The IPN just wasn't able |
|
295 | + // to identify which transaction or payment method this was for |
|
296 | + // give all active payment methods a chance to claim it |
|
297 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
298 | + foreach ($active_payment_methods as $active_payment_method) { |
|
299 | + try { |
|
300 | + $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
301 | + $payment_method = $active_payment_method; |
|
302 | + EEM_Change_Log::instance()->log( |
|
303 | + EEM_Change_Log::type_gateway, |
|
304 | + array('IPN data' => $_req_data), |
|
305 | + $payment |
|
306 | + ); |
|
307 | + break; |
|
308 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
309 | + EEM_Change_Log::instance()->log( |
|
310 | + EEM_Change_Log::type_gateway, |
|
311 | + array( |
|
312 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
313 | + 'current_url' => EEH_URL::current_url(), |
|
314 | + 'payment' => $e->getPaymentProperties(), |
|
315 | + 'IPN_data' => $e->getIpnData(), |
|
316 | + ), |
|
317 | + $obj_for_log |
|
318 | + ); |
|
319 | + return $e->getPayment(); |
|
320 | + } catch (EE_Error $e) { |
|
321 | + // that's fine- it apparently couldn't handle the IPN |
|
322 | + } |
|
323 | + } |
|
324 | + } |
|
325 | + // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
326 | + if ($payment instanceof EE_Payment) { |
|
327 | + $payment->save(); |
|
328 | + // update the TXN |
|
329 | + $this->update_txn_based_on_payment( |
|
330 | + $transaction, |
|
331 | + $payment, |
|
332 | + $update_txn, |
|
333 | + $separate_IPN_request |
|
334 | + ); |
|
335 | + } else { |
|
336 | + // we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
337 | + if ($payment_method) { |
|
338 | + EEM_Change_Log::instance()->log( |
|
339 | + EEM_Change_Log::type_gateway, |
|
340 | + array('IPN data' => $_req_data), |
|
341 | + $payment_method |
|
342 | + ); |
|
343 | + } elseif ($transaction) { |
|
344 | + EEM_Change_Log::instance()->log( |
|
345 | + EEM_Change_Log::type_gateway, |
|
346 | + array('IPN data' => $_req_data), |
|
347 | + $transaction |
|
348 | + ); |
|
349 | + } |
|
350 | + } |
|
351 | + return $payment; |
|
352 | + } catch (EE_Error $e) { |
|
353 | + do_action( |
|
354 | + 'AHEE__log', |
|
355 | + __FILE__, |
|
356 | + __FUNCTION__, |
|
357 | + sprintf( |
|
358 | + __( |
|
359 | + 'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', |
|
360 | + 'event_espresso' |
|
361 | + ), |
|
362 | + print_r($transaction, true), |
|
363 | + print_r($_req_data, true), |
|
364 | + $e->getMessage() |
|
365 | + ) |
|
366 | + ); |
|
367 | + throw $e; |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Removes any non-printable illegal characters from the input, |
|
374 | + * which might cause a raucous when trying to insert into the database |
|
375 | + * |
|
376 | + * @param array $request_data |
|
377 | + * @return array |
|
378 | + */ |
|
379 | + protected function _remove_unusable_characters_from_array(array $request_data) |
|
380 | + { |
|
381 | + $return_data = array(); |
|
382 | + foreach ($request_data as $key => $value) { |
|
383 | + $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters( |
|
384 | + $value |
|
385 | + ); |
|
386 | + } |
|
387 | + return $return_data; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * Removes any non-printable illegal characters from the input, |
|
393 | + * which might cause a raucous when trying to insert into the database |
|
394 | + * |
|
395 | + * @param string $request_data |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + protected function _remove_unusable_characters($request_data) |
|
399 | + { |
|
400 | + return preg_replace('/[^[:print:]]/', '', $request_data); |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * Should be called just before displaying the payment attempt results to the user, |
|
406 | + * when the payment attempt has finished. Some payment methods may have special |
|
407 | + * logic to perform here. For example, if process_payment() happens on a special request |
|
408 | + * and then the user is redirected to a page that displays the payment's status, this |
|
409 | + * should be called while loading the page that displays the payment's status. If the user is |
|
410 | + * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
411 | + * provider. |
|
412 | + * |
|
413 | + * @param EE_Transaction|int $transaction |
|
414 | + * @param bool $update_txn whether or not to call |
|
415 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
416 | + * @return EE_Payment |
|
417 | + * @throws EE_Error |
|
418 | + * @throws InvalidArgumentException |
|
419 | + * @throws ReflectionException |
|
420 | + * @throws RuntimeException |
|
421 | + * @throws InvalidDataTypeException |
|
422 | + * @throws InvalidInterfaceException |
|
423 | + * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
424 | + * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
425 | + */ |
|
426 | + public function finalize_payment_for($transaction, $update_txn = true) |
|
427 | + { |
|
428 | + /** @var $transaction EE_Transaction */ |
|
429 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
430 | + $last_payment_method = $transaction->payment_method(); |
|
431 | + if ($last_payment_method instanceof EE_Payment_Method) { |
|
432 | + $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
433 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
434 | + return $payment; |
|
435 | + } |
|
436 | + return null; |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
442 | + * |
|
443 | + * @param EE_Payment_Method $payment_method |
|
444 | + * @param EE_Payment $payment_to_refund |
|
445 | + * @param array $refund_info |
|
446 | + * @return EE_Payment |
|
447 | + * @throws EE_Error |
|
448 | + * @throws InvalidArgumentException |
|
449 | + * @throws ReflectionException |
|
450 | + * @throws RuntimeException |
|
451 | + * @throws InvalidDataTypeException |
|
452 | + * @throws InvalidInterfaceException |
|
453 | + */ |
|
454 | + public function process_refund( |
|
455 | + EE_Payment_Method $payment_method, |
|
456 | + EE_Payment $payment_to_refund, |
|
457 | + array $refund_info = array() |
|
458 | + ) { |
|
459 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
460 | + $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
461 | + $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
462 | + } |
|
463 | + return $payment_to_refund; |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * This should be called each time there may have been an update to a |
|
469 | + * payment on a transaction (ie, we asked for a payment to process a |
|
470 | + * payment for a transaction, or we told a payment method about an IPN, or |
|
471 | + * we told a payment method to |
|
472 | + * "finalize_payment_for" (a transaction), or we told a payment method to |
|
473 | + * process a refund. This should handle firing the correct hooks to |
|
474 | + * indicate |
|
475 | + * what exactly happened and updating the transaction appropriately). This |
|
476 | + * could be integrated directly into EE_Transaction upon save, but we want |
|
477 | + * this logic to be separate from 'normal' plain-jane saving and updating |
|
478 | + * of transactions and payments, and to be tied to payment processing. |
|
479 | + * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
480 | + * of previous code to decide whether or not to save (because the payment passed into |
|
481 | + * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
482 | + * in which case we only want that payment object for some temporary usage during this request, |
|
483 | + * but we don't want it to be saved). |
|
484 | + * |
|
485 | + * @param EE_Transaction|int $transaction |
|
486 | + * @param EE_Payment $payment |
|
487 | + * @param boolean $update_txn |
|
488 | + * whether or not to call |
|
489 | + * EE_Transaction_Processor:: |
|
490 | + * update_transaction_and_registrations_after_checkout_or_payment() |
|
491 | + * (you can save 1 DB query if you know you're going |
|
492 | + * to save it later instead) |
|
493 | + * @param bool $IPN |
|
494 | + * if processing IPNs or other similar payment |
|
495 | + * related activities that occur in alternate |
|
496 | + * requests than the main one that is processing the |
|
497 | + * TXN, then set this to true to check whether the |
|
498 | + * TXN is locked before updating |
|
499 | + * @throws EE_Error |
|
500 | + * @throws InvalidArgumentException |
|
501 | + * @throws ReflectionException |
|
502 | + * @throws RuntimeException |
|
503 | + * @throws InvalidDataTypeException |
|
504 | + * @throws InvalidInterfaceException |
|
505 | + */ |
|
506 | + public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
507 | + { |
|
508 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
509 | + /** @type EE_Transaction $transaction */ |
|
510 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
511 | + // can we freely update the TXN at this moment? |
|
512 | + if ($IPN && $transaction->is_locked()) { |
|
513 | + // don't update the transaction at this exact moment |
|
514 | + // because the TXN is active in another request |
|
515 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
516 | + time(), |
|
517 | + $transaction->ID(), |
|
518 | + $payment->ID() |
|
519 | + ); |
|
520 | + } else { |
|
521 | + // verify payment and that it has been saved |
|
522 | + if ($payment instanceof EE_Payment && $payment->ID()) { |
|
523 | + if ( |
|
524 | + $payment->payment_method() instanceof EE_Payment_Method |
|
525 | + && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
526 | + ) { |
|
527 | + $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
528 | + // update TXN registrations with payment info |
|
529 | + $this->process_registration_payments($transaction, $payment); |
|
530 | + } |
|
531 | + $do_action = $payment->just_approved() |
|
532 | + ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
533 | + : $do_action; |
|
534 | + } else { |
|
535 | + // send out notifications |
|
536 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
537 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
538 | + } |
|
539 | + if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
540 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
541 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
542 | + // set new value for total paid |
|
543 | + $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
544 | + // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
545 | + if ($update_txn) { |
|
546 | + $this->_post_payment_processing($transaction, $payment, $IPN); |
|
547 | + } |
|
548 | + } |
|
549 | + // granular hook for others to use. |
|
550 | + do_action($do_action, $transaction, $payment); |
|
551 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
552 | + // global hook for others to use. |
|
553 | + do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
554 | + } |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * update registrations REG_paid field after successful payment and link registrations with payment |
|
560 | + * |
|
561 | + * @param EE_Transaction $transaction |
|
562 | + * @param EE_Payment $payment |
|
563 | + * @param EE_Registration[] $registrations |
|
564 | + * @throws EE_Error |
|
565 | + * @throws InvalidArgumentException |
|
566 | + * @throws RuntimeException |
|
567 | + * @throws InvalidDataTypeException |
|
568 | + * @throws InvalidInterfaceException |
|
569 | + */ |
|
570 | + public function process_registration_payments( |
|
571 | + EE_Transaction $transaction, |
|
572 | + EE_Payment $payment, |
|
573 | + array $registrations = array() |
|
574 | + ) { |
|
575 | + // only process if payment was successful |
|
576 | + if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
577 | + return; |
|
578 | + } |
|
579 | + // EEM_Registration::instance()->show_next_x_db_queries(); |
|
580 | + if (empty($registrations)) { |
|
581 | + // find registrations with monies owing that can receive a payment |
|
582 | + $registrations = $transaction->registrations( |
|
583 | + array( |
|
584 | + array( |
|
585 | + // only these reg statuses can receive payments |
|
586 | + 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
587 | + 'REG_final_price' => array('!=', 0), |
|
588 | + 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
589 | + ), |
|
590 | + ) |
|
591 | + ); |
|
592 | + } |
|
593 | + // still nothing ??!?? |
|
594 | + if (empty($registrations)) { |
|
595 | + return; |
|
596 | + } |
|
597 | + // todo: break out the following logic into a separate strategy class |
|
598 | + // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
599 | + // todo: which would apply payments using the capitalist "first come first paid" approach |
|
600 | + // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
601 | + // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
602 | + // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
603 | + $refund = $payment->is_a_refund(); |
|
604 | + // how much is available to apply to registrations? |
|
605 | + $available_payment_amount = abs($payment->amount()); |
|
606 | + foreach ($registrations as $registration) { |
|
607 | + if ($registration instanceof EE_Registration) { |
|
608 | + // nothing left? |
|
609 | + if ($available_payment_amount <= 0) { |
|
610 | + break; |
|
611 | + } |
|
612 | + if ($refund) { |
|
613 | + $available_payment_amount = $this->process_registration_refund( |
|
614 | + $registration, |
|
615 | + $payment, |
|
616 | + $available_payment_amount |
|
617 | + ); |
|
618 | + } else { |
|
619 | + $available_payment_amount = $this->process_registration_payment( |
|
620 | + $registration, |
|
621 | + $payment, |
|
622 | + $available_payment_amount |
|
623 | + ); |
|
624 | + } |
|
625 | + } |
|
626 | + } |
|
627 | + if ( |
|
628 | + $available_payment_amount > 0 |
|
629 | + && apply_filters( |
|
630 | + 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', |
|
631 | + false |
|
632 | + ) |
|
633 | + ) { |
|
634 | + EE_Error::add_attention( |
|
635 | + sprintf( |
|
636 | + __( |
|
637 | + 'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
638 | + 'event_espresso' |
|
639 | + ), |
|
640 | + EEH_Template::format_currency($available_payment_amount), |
|
641 | + implode(', ', array_keys($registrations)), |
|
642 | + '<br/>', |
|
643 | + EEH_Template::format_currency($payment->amount()) |
|
644 | + ), |
|
645 | + __FILE__, |
|
646 | + __FUNCTION__, |
|
647 | + __LINE__ |
|
648 | + ); |
|
649 | + } |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * update registration REG_paid field after successful payment and link registration with payment |
|
655 | + * |
|
656 | + * @param EE_Registration $registration |
|
657 | + * @param EE_Payment $payment |
|
658 | + * @param float $available_payment_amount |
|
659 | + * @return float |
|
660 | + * @throws EE_Error |
|
661 | + * @throws InvalidArgumentException |
|
662 | + * @throws RuntimeException |
|
663 | + * @throws InvalidDataTypeException |
|
664 | + * @throws InvalidInterfaceException |
|
665 | + */ |
|
666 | + public function process_registration_payment( |
|
667 | + EE_Registration $registration, |
|
668 | + EE_Payment $payment, |
|
669 | + $available_payment_amount = 0.00 |
|
670 | + ) { |
|
671 | + $owing = $registration->final_price() - $registration->paid(); |
|
672 | + if ($owing > 0) { |
|
673 | + // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
674 | + $payment_amount = min($available_payment_amount, $owing); |
|
675 | + // update $available_payment_amount |
|
676 | + $available_payment_amount -= $payment_amount; |
|
677 | + // calculate and set new REG_paid |
|
678 | + $registration->set_paid($registration->paid() + $payment_amount); |
|
679 | + // now save it |
|
680 | + $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
681 | + } |
|
682 | + return $available_payment_amount; |
|
683 | + } |
|
684 | + |
|
685 | + |
|
686 | + /** |
|
687 | + * update registration REG_paid field after successful payment and link registration with payment |
|
688 | + * |
|
689 | + * @param EE_Registration $registration |
|
690 | + * @param EE_Payment $payment |
|
691 | + * @param float $payment_amount |
|
692 | + * @return void |
|
693 | + * @throws EE_Error |
|
694 | + * @throws InvalidArgumentException |
|
695 | + * @throws InvalidDataTypeException |
|
696 | + * @throws InvalidInterfaceException |
|
697 | + */ |
|
698 | + protected function _apply_registration_payment( |
|
699 | + EE_Registration $registration, |
|
700 | + EE_Payment $payment, |
|
701 | + $payment_amount = 0.00 |
|
702 | + ) { |
|
703 | + // find any existing reg payment records for this registration and payment |
|
704 | + $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
705 | + array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
706 | + ); |
|
707 | + // if existing registration payment exists |
|
708 | + if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
709 | + // then update that record |
|
710 | + $existing_reg_payment->set_amount($payment_amount); |
|
711 | + $existing_reg_payment->save(); |
|
712 | + } else { |
|
713 | + // or add new relation between registration and payment and set amount |
|
714 | + $registration->_add_relation_to( |
|
715 | + $payment, |
|
716 | + 'Payment', |
|
717 | + array('RPY_amount' => $payment_amount) |
|
718 | + ); |
|
719 | + // make it stick |
|
720 | + $registration->save(); |
|
721 | + } |
|
722 | + } |
|
723 | + |
|
724 | + |
|
725 | + /** |
|
726 | + * update registration REG_paid field after refund and link registration with payment |
|
727 | + * |
|
728 | + * @param EE_Registration $registration |
|
729 | + * @param EE_Payment $payment |
|
730 | + * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
731 | + * @return float |
|
732 | + * @throws EE_Error |
|
733 | + * @throws InvalidArgumentException |
|
734 | + * @throws RuntimeException |
|
735 | + * @throws InvalidDataTypeException |
|
736 | + * @throws InvalidInterfaceException |
|
737 | + */ |
|
738 | + public function process_registration_refund( |
|
739 | + EE_Registration $registration, |
|
740 | + EE_Payment $payment, |
|
741 | + $available_refund_amount = 0.00 |
|
742 | + ) { |
|
743 | + // EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
744 | + if ($registration->paid() > 0) { |
|
745 | + // ensure $available_refund_amount is NOT negative |
|
746 | + $available_refund_amount = (float) abs($available_refund_amount); |
|
747 | + // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
748 | + $refund_amount = min($available_refund_amount, (float) $registration->paid()); |
|
749 | + // update $available_payment_amount |
|
750 | + $available_refund_amount -= $refund_amount; |
|
751 | + // calculate and set new REG_paid |
|
752 | + $registration->set_paid($registration->paid() - $refund_amount); |
|
753 | + // convert payment amount back to a negative value for storage in the db |
|
754 | + $refund_amount = (float) abs($refund_amount) * -1; |
|
755 | + // now save it |
|
756 | + $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
757 | + } |
|
758 | + return $available_refund_amount; |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * Process payments and transaction after payment process completed. |
|
764 | + * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
765 | + * if this request happens to be processing an IPN, |
|
766 | + * then we will also set the Payment Options Reg Step to completed, |
|
767 | + * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
768 | + * |
|
769 | + * @param EE_Transaction $transaction |
|
770 | + * @param EE_Payment $payment |
|
771 | + * @param bool $IPN |
|
772 | + * @throws EE_Error |
|
773 | + * @throws InvalidArgumentException |
|
774 | + * @throws ReflectionException |
|
775 | + * @throws RuntimeException |
|
776 | + * @throws InvalidDataTypeException |
|
777 | + * @throws InvalidInterfaceException |
|
778 | + */ |
|
779 | + protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
780 | + { |
|
781 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
782 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
783 | + // is the Payment Options Reg Step completed ? |
|
784 | + $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
785 | + // if the Payment Options Reg Step is completed... |
|
786 | + $revisit = $payment_options_step_completed === true; |
|
787 | + // then this is kinda sorta a revisit with regards to payments at least |
|
788 | + $transaction_processor->set_revisit($revisit); |
|
789 | + // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
790 | + if ( |
|
791 | + $IPN |
|
792 | + && $payment_options_step_completed !== true |
|
793 | + && ($payment->is_approved() || $payment->is_pending()) |
|
794 | + ) { |
|
795 | + $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
796 | + 'payment_options' |
|
797 | + ); |
|
798 | + } |
|
799 | + // maybe update status, but don't save transaction just yet |
|
800 | + $transaction->update_status_based_on_total_paid(false); |
|
801 | + // check if 'finalize_registration' step has been completed... |
|
802 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
803 | + // if this is an IPN and the final step has not been initiated |
|
804 | + if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
805 | + // and if it hasn't already been set as being started... |
|
806 | + $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
807 | + } |
|
808 | + $transaction->save(); |
|
809 | + // because the above will return false if the final step was not fully completed, we need to check again... |
|
810 | + if ($IPN && $finalized !== false) { |
|
811 | + // and if we are all good to go, then send out notifications |
|
812 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
813 | + // ok, now process the transaction according to the payment |
|
814 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
815 | + $transaction, |
|
816 | + $payment |
|
817 | + ); |
|
818 | + } |
|
819 | + // DEBUG LOG |
|
820 | + $payment_method = $payment->payment_method(); |
|
821 | + if ($payment_method instanceof EE_Payment_Method) { |
|
822 | + $payment_method_type_obj = $payment_method->type_obj(); |
|
823 | + if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
824 | + $gateway = $payment_method_type_obj->get_gateway(); |
|
825 | + if ($gateway instanceof EE_Gateway) { |
|
826 | + $gateway->log( |
|
827 | + array( |
|
828 | + 'message' => (string) __('Post Payment Transaction Details', 'event_espresso'), |
|
829 | + 'transaction' => $transaction->model_field_array(), |
|
830 | + 'finalized' => $finalized, |
|
831 | + 'IPN' => $IPN, |
|
832 | + 'deliver_notifications' => has_filter( |
|
833 | + 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
834 | + ), |
|
835 | + ), |
|
836 | + $payment |
|
837 | + ); |
|
838 | + } |
|
839 | + } |
|
840 | + } |
|
841 | + } |
|
842 | + |
|
843 | + |
|
844 | + /** |
|
845 | + * Force posts to PayPal to use TLS v1.2. See: |
|
846 | + * https://core.trac.wordpress.org/ticket/36320 |
|
847 | + * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
848 | + * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
849 | + * This will affect PayPal standard, pro, express, and Payflow. |
|
850 | + * |
|
851 | + * @param $handle |
|
852 | + * @param $r |
|
853 | + * @param $url |
|
854 | + */ |
|
855 | + public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
856 | + { |
|
857 | + if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) { |
|
858 | + // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
859 | + // instead of the constant because it might not be defined |
|
860 | + curl_setopt($handle, CURLOPT_SSLVERSION, 6); |
|
861 | + } |
|
862 | + } |
|
863 | 863 | } |
@@ -13,82 +13,82 @@ |
||
13 | 13 | class EED_Invalid_Checkout_Access extends EED_Module |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var InvalidCheckoutAccess $invalid_checkout_access_form |
|
18 | - */ |
|
19 | - private static $invalid_checkout_access_form; |
|
16 | + /** |
|
17 | + * @var InvalidCheckoutAccess $invalid_checkout_access_form |
|
18 | + */ |
|
19 | + private static $invalid_checkout_access_form; |
|
20 | 20 | |
21 | - /** |
|
22 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
23 | - */ |
|
24 | - public static function set_hooks() |
|
25 | - { |
|
26 | - } |
|
21 | + /** |
|
22 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
23 | + */ |
|
24 | + public static function set_hooks() |
|
25 | + { |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
31 | - */ |
|
32 | - public static function set_hooks_admin() |
|
33 | - { |
|
34 | - add_action( |
|
35 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
36 | - array('EED_Invalid_Checkout_Access', 'display_invalid_checkout_access_form'), |
|
37 | - 15 |
|
38 | - ); |
|
39 | - add_filter( |
|
40 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
41 | - array('EED_Invalid_Checkout_Access', 'process_invalid_checkout_access_form') |
|
42 | - ); |
|
43 | - } |
|
29 | + /** |
|
30 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
31 | + */ |
|
32 | + public static function set_hooks_admin() |
|
33 | + { |
|
34 | + add_action( |
|
35 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
36 | + array('EED_Invalid_Checkout_Access', 'display_invalid_checkout_access_form'), |
|
37 | + 15 |
|
38 | + ); |
|
39 | + add_filter( |
|
40 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
41 | + array('EED_Invalid_Checkout_Access', 'process_invalid_checkout_access_form') |
|
42 | + ); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * run - initial module setup |
|
48 | - * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
49 | - * |
|
50 | - * @var WP $WP |
|
51 | - */ |
|
52 | - public function run($WP) |
|
53 | - { |
|
54 | - // TODO: Implement run() method. |
|
55 | - } |
|
46 | + /** |
|
47 | + * run - initial module setup |
|
48 | + * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
49 | + * |
|
50 | + * @var WP $WP |
|
51 | + */ |
|
52 | + public function run($WP) |
|
53 | + { |
|
54 | + // TODO: Implement run() method. |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * @return InvalidCheckoutAccess |
|
60 | - */ |
|
61 | - public static function getInvalidCheckoutAccess() |
|
62 | - { |
|
63 | - if (! self::$invalid_checkout_access_form instanceof InvalidCheckoutAccess) { |
|
64 | - self::$invalid_checkout_access_form = new InvalidCheckoutAccess(); |
|
65 | - } |
|
66 | - return self::$invalid_checkout_access_form; |
|
67 | - } |
|
58 | + /** |
|
59 | + * @return InvalidCheckoutAccess |
|
60 | + */ |
|
61 | + public static function getInvalidCheckoutAccess() |
|
62 | + { |
|
63 | + if (! self::$invalid_checkout_access_form instanceof InvalidCheckoutAccess) { |
|
64 | + self::$invalid_checkout_access_form = new InvalidCheckoutAccess(); |
|
65 | + } |
|
66 | + return self::$invalid_checkout_access_form; |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * email_validation_settings_form |
|
72 | - * |
|
73 | - * @return void |
|
74 | - * @throws \EE_Error |
|
75 | - */ |
|
76 | - public static function display_invalid_checkout_access_form() |
|
77 | - { |
|
78 | - $invalid_checkout_access_form = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
79 | - echo $invalid_checkout_access_form->getForm()->get_html(); |
|
80 | - } |
|
70 | + /** |
|
71 | + * email_validation_settings_form |
|
72 | + * |
|
73 | + * @return void |
|
74 | + * @throws \EE_Error |
|
75 | + */ |
|
76 | + public static function display_invalid_checkout_access_form() |
|
77 | + { |
|
78 | + $invalid_checkout_access_form = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
79 | + echo $invalid_checkout_access_form->getForm()->get_html(); |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * email_validation_settings_form |
|
85 | - * |
|
86 | - * @param \EE_Registration_Config $EE_Registration_Config |
|
87 | - * @return \EE_Registration_Config |
|
88 | - */ |
|
89 | - public static function process_invalid_checkout_access_form(\EE_Registration_Config $EE_Registration_Config) |
|
90 | - { |
|
91 | - $invalid_checkout_access_form = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
92 | - return $invalid_checkout_access_form->processForm($EE_Registration_Config); |
|
93 | - } |
|
83 | + /** |
|
84 | + * email_validation_settings_form |
|
85 | + * |
|
86 | + * @param \EE_Registration_Config $EE_Registration_Config |
|
87 | + * @return \EE_Registration_Config |
|
88 | + */ |
|
89 | + public static function process_invalid_checkout_access_form(\EE_Registration_Config $EE_Registration_Config) |
|
90 | + { |
|
91 | + $invalid_checkout_access_form = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
92 | + return $invalid_checkout_access_form->processForm($EE_Registration_Config); |
|
93 | + } |
|
94 | 94 | } |
@@ -60,7 +60,7 @@ |
||
60 | 60 | */ |
61 | 61 | public static function getInvalidCheckoutAccess() |
62 | 62 | { |
63 | - if (! self::$invalid_checkout_access_form instanceof InvalidCheckoutAccess) { |
|
63 | + if ( ! self::$invalid_checkout_access_form instanceof InvalidCheckoutAccess) { |
|
64 | 64 | self::$invalid_checkout_access_form = new InvalidCheckoutAccess(); |
65 | 65 | } |
66 | 66 | return self::$invalid_checkout_access_form; |
@@ -12,69 +12,69 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * @return EED_Csv |
|
17 | - */ |
|
18 | - public static function instance() |
|
19 | - { |
|
20 | - return parent::get_instance(__CLASS__); |
|
21 | - } |
|
15 | + /** |
|
16 | + * @return EED_Csv |
|
17 | + */ |
|
18 | + public static function instance() |
|
19 | + { |
|
20 | + return parent::get_instance(__CLASS__); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
26 | - * |
|
27 | - * @access public |
|
28 | - * @return void |
|
29 | - */ |
|
30 | - public static function set_hooks() |
|
31 | - { |
|
32 | - } |
|
24 | + /** |
|
25 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
26 | + * |
|
27 | + * @access public |
|
28 | + * @return void |
|
29 | + */ |
|
30 | + public static function set_hooks() |
|
31 | + { |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
36 | - * |
|
37 | - * @access public |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public static function set_hooks_admin() |
|
41 | - { |
|
42 | - } |
|
34 | + /** |
|
35 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
36 | + * |
|
37 | + * @access public |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public static function set_hooks_admin() |
|
41 | + { |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * run - initial module setup |
|
47 | - * |
|
48 | - * @access public |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function run($WP) |
|
52 | - { |
|
53 | - } |
|
45 | + /** |
|
46 | + * run - initial module setup |
|
47 | + * |
|
48 | + * @access public |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function run($WP) |
|
52 | + { |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * export |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public function export() |
|
63 | - { |
|
64 | - $Export = EE_Registry::instance()->load_class('Export'); |
|
65 | - $Export->export(); |
|
66 | - } |
|
56 | + /** |
|
57 | + * export |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public function export() |
|
63 | + { |
|
64 | + $Export = EE_Registry::instance()->load_class('Export'); |
|
65 | + $Export->export(); |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * import |
|
71 | - * |
|
72 | - * @access public |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function import() |
|
76 | - { |
|
77 | - $Import = EE_Registry::instance()->load_class('Import'); |
|
78 | - $Import->import(); |
|
79 | - } |
|
69 | + /** |
|
70 | + * import |
|
71 | + * |
|
72 | + * @access public |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function import() |
|
76 | + { |
|
77 | + $Import = EE_Registry::instance()->load_class('Import'); |
|
78 | + $Import->import(); |
|
79 | + } |
|
80 | 80 | } |