@@ -17,18 +17,18 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * Uses CollectionFilterCallbackIterator on a provided collection with provided Closure for filtering each object |
|
22 | - * in the collection. |
|
23 | - * The closure receives an instance of the object and should return false if it is not "valid" and true if it is. |
|
24 | - * |
|
25 | - * @param Collection $collection |
|
26 | - * @param Closure $acceptance_callback |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public static function getFilteredObjectsFromCollection(Collection $collection, Closure $acceptance_callback) |
|
30 | - { |
|
31 | - $collection_filter_iterator = new CollectionFilterCallbackIterator($collection, $acceptance_callback); |
|
32 | - return $collection_filter_iterator->getFiltered(); |
|
33 | - } |
|
20 | + /** |
|
21 | + * Uses CollectionFilterCallbackIterator on a provided collection with provided Closure for filtering each object |
|
22 | + * in the collection. |
|
23 | + * The closure receives an instance of the object and should return false if it is not "valid" and true if it is. |
|
24 | + * |
|
25 | + * @param Collection $collection |
|
26 | + * @param Closure $acceptance_callback |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public static function getFilteredObjectsFromCollection(Collection $collection, Closure $acceptance_callback) |
|
30 | + { |
|
31 | + $collection_filter_iterator = new CollectionFilterCallbackIterator($collection, $acceptance_callback); |
|
32 | + return $collection_filter_iterator->getFiltered(); |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -38,217 +38,217 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - function espresso_minimum_php_version_error() |
|
73 | - { |
|
74 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + function espresso_minimum_php_version_error() |
|
73 | + { |
|
74 | + ?> |
|
75 | 75 | <div class="error"> |
76 | 76 | <p> |
77 | 77 | <?php |
78 | - printf( |
|
79 | - esc_html__( |
|
80 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
81 | - 'event_espresso' |
|
82 | - ), |
|
83 | - EE_MIN_PHP_VER_REQUIRED, |
|
84 | - PHP_VERSION, |
|
85 | - '<br/>', |
|
86 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
87 | - ); |
|
88 | - ?> |
|
78 | + printf( |
|
79 | + esc_html__( |
|
80 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
81 | + 'event_espresso' |
|
82 | + ), |
|
83 | + EE_MIN_PHP_VER_REQUIRED, |
|
84 | + PHP_VERSION, |
|
85 | + '<br/>', |
|
86 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
87 | + ); |
|
88 | + ?> |
|
89 | 89 | </p> |
90 | 90 | </div> |
91 | 91 | <?php |
92 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
93 | - } |
|
92 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
93 | + } |
|
94 | 94 | |
95 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
96 | - } else { |
|
97 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
98 | - /** |
|
99 | - * espresso_version |
|
100 | - * Returns the plugin version |
|
101 | - * |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - function espresso_version() |
|
105 | - { |
|
106 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.54.rc.004'); |
|
107 | - } |
|
95 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
96 | + } else { |
|
97 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
98 | + /** |
|
99 | + * espresso_version |
|
100 | + * Returns the plugin version |
|
101 | + * |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + function espresso_version() |
|
105 | + { |
|
106 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.54.rc.004'); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * espresso_plugin_activation |
|
111 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
112 | - */ |
|
113 | - function espresso_plugin_activation() |
|
114 | - { |
|
115 | - update_option('ee_espresso_activation', true); |
|
116 | - } |
|
109 | + /** |
|
110 | + * espresso_plugin_activation |
|
111 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
112 | + */ |
|
113 | + function espresso_plugin_activation() |
|
114 | + { |
|
115 | + update_option('ee_espresso_activation', true); |
|
116 | + } |
|
117 | 117 | |
118 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
119 | - /** |
|
120 | - * espresso_load_error_handling |
|
121 | - * this function loads EE's class for handling exceptions and errors |
|
122 | - */ |
|
123 | - function espresso_load_error_handling() |
|
124 | - { |
|
125 | - static $error_handling_loaded = false; |
|
126 | - if ($error_handling_loaded) { |
|
127 | - return; |
|
128 | - } |
|
129 | - // load debugging tools |
|
130 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
131 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
132 | - \EEH_Debug_Tools::instance(); |
|
133 | - } |
|
134 | - // load error handling |
|
135 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
136 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
137 | - } else { |
|
138 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
139 | - } |
|
140 | - $error_handling_loaded = true; |
|
141 | - } |
|
118 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
119 | + /** |
|
120 | + * espresso_load_error_handling |
|
121 | + * this function loads EE's class for handling exceptions and errors |
|
122 | + */ |
|
123 | + function espresso_load_error_handling() |
|
124 | + { |
|
125 | + static $error_handling_loaded = false; |
|
126 | + if ($error_handling_loaded) { |
|
127 | + return; |
|
128 | + } |
|
129 | + // load debugging tools |
|
130 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
131 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
132 | + \EEH_Debug_Tools::instance(); |
|
133 | + } |
|
134 | + // load error handling |
|
135 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
136 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
137 | + } else { |
|
138 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
139 | + } |
|
140 | + $error_handling_loaded = true; |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * espresso_load_required |
|
145 | - * given a class name and path, this function will load that file or throw an exception |
|
146 | - * |
|
147 | - * @param string $classname |
|
148 | - * @param string $full_path_to_file |
|
149 | - * @throws EE_Error |
|
150 | - */ |
|
151 | - function espresso_load_required($classname, $full_path_to_file) |
|
152 | - { |
|
153 | - if (is_readable($full_path_to_file)) { |
|
154 | - require_once $full_path_to_file; |
|
155 | - } else { |
|
156 | - throw new \EE_Error ( |
|
157 | - sprintf( |
|
158 | - esc_html__( |
|
159 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
160 | - 'event_espresso' |
|
161 | - ), |
|
162 | - $classname |
|
163 | - ) |
|
164 | - ); |
|
165 | - } |
|
166 | - } |
|
143 | + /** |
|
144 | + * espresso_load_required |
|
145 | + * given a class name and path, this function will load that file or throw an exception |
|
146 | + * |
|
147 | + * @param string $classname |
|
148 | + * @param string $full_path_to_file |
|
149 | + * @throws EE_Error |
|
150 | + */ |
|
151 | + function espresso_load_required($classname, $full_path_to_file) |
|
152 | + { |
|
153 | + if (is_readable($full_path_to_file)) { |
|
154 | + require_once $full_path_to_file; |
|
155 | + } else { |
|
156 | + throw new \EE_Error ( |
|
157 | + sprintf( |
|
158 | + esc_html__( |
|
159 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
160 | + 'event_espresso' |
|
161 | + ), |
|
162 | + $classname |
|
163 | + ) |
|
164 | + ); |
|
165 | + } |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @since 4.9.27 |
|
170 | - * @throws \EE_Error |
|
171 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
172 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
173 | - * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
174 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
175 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
176 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
177 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
178 | - * @throws \OutOfBoundsException |
|
179 | - */ |
|
180 | - function bootstrap_espresso() |
|
181 | - { |
|
182 | - require_once __DIR__ . '/core/espresso_definitions.php'; |
|
183 | - try { |
|
184 | - espresso_load_error_handling(); |
|
185 | - espresso_load_required( |
|
186 | - 'EEH_Base', |
|
187 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
188 | - ); |
|
189 | - espresso_load_required( |
|
190 | - 'EEH_File', |
|
191 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
192 | - ); |
|
193 | - espresso_load_required( |
|
194 | - 'EEH_File', |
|
195 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
196 | - ); |
|
197 | - espresso_load_required( |
|
198 | - 'EEH_Array', |
|
199 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
200 | - ); |
|
201 | - // instantiate and configure PSR4 autoloader |
|
202 | - espresso_load_required( |
|
203 | - 'Psr4Autoloader', |
|
204 | - EE_CORE . 'Psr4Autoloader.php' |
|
205 | - ); |
|
206 | - espresso_load_required( |
|
207 | - 'EE_Psr4AutoloaderInit', |
|
208 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
209 | - ); |
|
210 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
211 | - $AutoloaderInit->initializeAutoloader(); |
|
212 | - espresso_load_required( |
|
213 | - 'EE_Request', |
|
214 | - EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
215 | - ); |
|
216 | - espresso_load_required( |
|
217 | - 'EE_Response', |
|
218 | - EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
219 | - ); |
|
220 | - espresso_load_required( |
|
221 | - 'EE_Bootstrap', |
|
222 | - EE_CORE . 'EE_Bootstrap.core.php' |
|
223 | - ); |
|
224 | - // bootstrap EE and the request stack |
|
225 | - new EE_Bootstrap( |
|
226 | - new EE_Request($_GET, $_POST, $_COOKIE), |
|
227 | - new EE_Response() |
|
228 | - ); |
|
229 | - } catch (Exception $e) { |
|
230 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
231 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
232 | - } |
|
233 | - } |
|
234 | - bootstrap_espresso(); |
|
235 | - } |
|
168 | + /** |
|
169 | + * @since 4.9.27 |
|
170 | + * @throws \EE_Error |
|
171 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
172 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
173 | + * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
174 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
175 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
176 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
177 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
178 | + * @throws \OutOfBoundsException |
|
179 | + */ |
|
180 | + function bootstrap_espresso() |
|
181 | + { |
|
182 | + require_once __DIR__ . '/core/espresso_definitions.php'; |
|
183 | + try { |
|
184 | + espresso_load_error_handling(); |
|
185 | + espresso_load_required( |
|
186 | + 'EEH_Base', |
|
187 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
188 | + ); |
|
189 | + espresso_load_required( |
|
190 | + 'EEH_File', |
|
191 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
192 | + ); |
|
193 | + espresso_load_required( |
|
194 | + 'EEH_File', |
|
195 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
196 | + ); |
|
197 | + espresso_load_required( |
|
198 | + 'EEH_Array', |
|
199 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
200 | + ); |
|
201 | + // instantiate and configure PSR4 autoloader |
|
202 | + espresso_load_required( |
|
203 | + 'Psr4Autoloader', |
|
204 | + EE_CORE . 'Psr4Autoloader.php' |
|
205 | + ); |
|
206 | + espresso_load_required( |
|
207 | + 'EE_Psr4AutoloaderInit', |
|
208 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
209 | + ); |
|
210 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
211 | + $AutoloaderInit->initializeAutoloader(); |
|
212 | + espresso_load_required( |
|
213 | + 'EE_Request', |
|
214 | + EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
215 | + ); |
|
216 | + espresso_load_required( |
|
217 | + 'EE_Response', |
|
218 | + EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
219 | + ); |
|
220 | + espresso_load_required( |
|
221 | + 'EE_Bootstrap', |
|
222 | + EE_CORE . 'EE_Bootstrap.core.php' |
|
223 | + ); |
|
224 | + // bootstrap EE and the request stack |
|
225 | + new EE_Bootstrap( |
|
226 | + new EE_Request($_GET, $_POST, $_COOKIE), |
|
227 | + new EE_Response() |
|
228 | + ); |
|
229 | + } catch (Exception $e) { |
|
230 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
231 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
232 | + } |
|
233 | + } |
|
234 | + bootstrap_espresso(); |
|
235 | + } |
|
236 | 236 | } |
237 | 237 | if (! function_exists('espresso_deactivate_plugin')) { |
238 | - /** |
|
239 | - * deactivate_plugin |
|
240 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
241 | - * |
|
242 | - * @access public |
|
243 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
244 | - * @return void |
|
245 | - */ |
|
246 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
247 | - { |
|
248 | - if (! function_exists('deactivate_plugins')) { |
|
249 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
250 | - } |
|
251 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
252 | - deactivate_plugins($plugin_basename); |
|
253 | - } |
|
238 | + /** |
|
239 | + * deactivate_plugin |
|
240 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
241 | + * |
|
242 | + * @access public |
|
243 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
244 | + * @return void |
|
245 | + */ |
|
246 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
247 | + { |
|
248 | + if (! function_exists('deactivate_plugins')) { |
|
249 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
250 | + } |
|
251 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
252 | + deactivate_plugins($plugin_basename); |
|
253 | + } |
|
254 | 254 | } |
@@ -362,7 +362,7 @@ |
||
362 | 362 | /** |
363 | 363 | * Posts the request to AuthorizeNet & returns response. |
364 | 364 | * |
365 | - * @param $payment |
|
365 | + * @param EEI_Payment $payment |
|
366 | 366 | * @return \EE_AuthorizeNetAIM_Response |
367 | 367 | */ |
368 | 368 | private function _sendRequest($payment) |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -29,424 +29,424 @@ discard block |
||
29 | 29 | class EEG_Aim extends EE_Onsite_Gateway |
30 | 30 | { |
31 | 31 | |
32 | - const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; //Authnet URL |
|
33 | - |
|
34 | - const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
35 | - |
|
36 | - protected $_login_id; |
|
37 | - |
|
38 | - protected $_transaction_key; |
|
39 | - |
|
40 | - protected $_server; |
|
41 | - |
|
42 | - protected $_currencies_supported = array( |
|
43 | - 'AUD', |
|
44 | - 'USD', |
|
45 | - 'CAD', |
|
46 | - 'EUR', |
|
47 | - 'GBP', |
|
48 | - 'NZD', |
|
49 | - ); |
|
50 | - |
|
51 | - /** |
|
52 | - * Whether to send test transactions (even to live site) |
|
53 | - * |
|
54 | - * @var boolean |
|
55 | - */ |
|
56 | - protected $_test_transactions; |
|
57 | - |
|
58 | - private $VERIFY_PEER = false; |
|
59 | - |
|
60 | - private $_x_post_fields = array( |
|
61 | - "version" => "3.1", |
|
62 | - "delim_char" => ",", |
|
63 | - "delim_data" => "TRUE", |
|
64 | - "relay_response" => "FALSE", |
|
65 | - "encap_char" => "|", |
|
66 | - ); |
|
67 | - |
|
68 | - private $_additional_line_items = array(); |
|
69 | - |
|
70 | - /** |
|
71 | - * A list of all fields in the AIM API. |
|
72 | - * Used to warn user if they try to set a field not offered in the API. |
|
73 | - */ |
|
74 | - private $_all_aim_fields = array( |
|
75 | - "address", |
|
76 | - "allow_partial_auth", |
|
77 | - "amount", |
|
78 | - "auth_code", |
|
79 | - "authentication_indicator", |
|
80 | - "bank_aba_code", |
|
81 | - "bank_acct_name", |
|
82 | - "bank_acct_num", |
|
83 | - "bank_acct_type", |
|
84 | - "bank_check_number", |
|
85 | - "bank_name", |
|
86 | - "card_code", |
|
87 | - "card_num", |
|
88 | - "cardholder_authentication_value", |
|
89 | - "city", |
|
90 | - "company", |
|
91 | - "country", |
|
92 | - "cust_id", |
|
93 | - "customer_ip", |
|
94 | - "delim_char", |
|
95 | - "delim_data", |
|
96 | - "description", |
|
97 | - "duplicate_window", |
|
98 | - "duty", |
|
99 | - "echeck_type", |
|
100 | - "email", |
|
101 | - "email_customer", |
|
102 | - "encap_char", |
|
103 | - "exp_date", |
|
104 | - "fax", |
|
105 | - "first_name", |
|
106 | - "footer_email_receipt", |
|
107 | - "freight", |
|
108 | - "header_email_receipt", |
|
109 | - "invoice_num", |
|
110 | - "last_name", |
|
111 | - "line_item", |
|
112 | - "login", |
|
113 | - "method", |
|
114 | - "phone", |
|
115 | - "po_num", |
|
116 | - "recurring_billing", |
|
117 | - "relay_response", |
|
118 | - "ship_to_address", |
|
119 | - "ship_to_city", |
|
120 | - "ship_to_company", |
|
121 | - "ship_to_country", |
|
122 | - "ship_to_first_name", |
|
123 | - "ship_to_last_name", |
|
124 | - "ship_to_state", |
|
125 | - "ship_to_zip", |
|
126 | - "split_tender_id", |
|
127 | - "state", |
|
128 | - "tax", |
|
129 | - "tax_exempt", |
|
130 | - "test_request", |
|
131 | - "tran_key", |
|
132 | - "trans_id", |
|
133 | - "type", |
|
134 | - "version", |
|
135 | - "zip", |
|
136 | - "solution_id" |
|
137 | - ); |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Gets the URL where the request should go. This is filterable |
|
142 | - * |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - protected function _get_server_url() |
|
146 | - { |
|
147 | - return apply_filters( |
|
148 | - 'FHEE__EEG_Aim___get_server_url', |
|
149 | - $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
150 | - $this |
|
151 | - ); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * TEMPORARY CALLBACK! Do not use |
|
157 | - * Callback which filters the server url. This is added so site admins can revert to using |
|
158 | - * the old AIM server in case Akamai service breaks their integration. |
|
159 | - * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net |
|
160 | - * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343) |
|
161 | - * Once that happens, this will be obsolete and WILL BE REMOVED. |
|
162 | - * |
|
163 | - * @param string $url |
|
164 | - * @param EEG_Aim $gateway_object |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) |
|
168 | - { |
|
169 | - if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) { |
|
170 | - return 'https://secure.authorize.net/gateway/transact.dll'; |
|
171 | - } else { |
|
172 | - return $url; |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
179 | - * usually send a request directly to the payment provider and update the payment's status based on that; |
|
180 | - * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
181 | - * for sending the request via http_remote_request() |
|
182 | - * |
|
183 | - * @param EEI_Payment $payment |
|
184 | - * @param array $billing_info { |
|
185 | - * @type $credit_card string |
|
186 | - * @type $cvv string |
|
187 | - * @type $exp_month string |
|
188 | - * @type $exp_year string |
|
189 | - * @see parent::do_direct_payment |
|
190 | - * } |
|
191 | - * @return EEI_Payment updated |
|
192 | - */ |
|
193 | - public function do_direct_payment($payment, $billing_info = null) |
|
194 | - { |
|
195 | - add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
196 | - // Enable test mode if needed |
|
197 | - //4007000000027 <-- test successful visa |
|
198 | - //4222222222222 <-- test failure card number |
|
199 | - |
|
200 | - $item_num = 1; |
|
201 | - $transaction = $payment->transaction(); |
|
202 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
203 | - $order_description = $gateway_formatter->formatOrderDescription($payment); |
|
204 | - $primary_registrant = $transaction->primary_registration(); |
|
205 | - //if we're are charging for the full amount, show the normal line items |
|
206 | - //and the itemized total adds up properly |
|
207 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
208 | - $total_line_item = $transaction->total_line_item(); |
|
209 | - foreach ($total_line_item->get_items() as $line_item) { |
|
210 | - if ($line_item->quantity() == 0) { |
|
211 | - continue; |
|
212 | - } |
|
213 | - $this->addLineItem( |
|
214 | - $item_num++, |
|
215 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
216 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
217 | - $line_item->quantity(), |
|
218 | - $line_item->unit_price(), |
|
219 | - 'N' |
|
220 | - ); |
|
221 | - $order_description .= $line_item->desc().', '; |
|
222 | - } |
|
223 | - foreach($total_line_item->tax_descendants() as $tax_line_item) { |
|
224 | - $this->addLineItem( |
|
225 | - $item_num++, |
|
226 | - $tax_line_item->name(), |
|
227 | - $tax_line_item->desc(), |
|
228 | - 1, |
|
229 | - $tax_line_item->total(), |
|
230 | - 'N' |
|
231 | - ); |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - //start transaction |
|
236 | - //if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
237 | - $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
238 | - $this->setField('solution_id', $partner_id); |
|
239 | - $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
240 | - $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
241 | - $this->_set_sensitive_billing_data($billing_info); |
|
242 | - $this->setField('first_name', $billing_info['first_name']); |
|
243 | - $this->setField('last_name', $billing_info['last_name']); |
|
244 | - $this->setField('email', $billing_info['email']); |
|
245 | - $this->setField('company', $billing_info['company']); |
|
246 | - $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
247 | - $this->setField('city', $billing_info['city']); |
|
248 | - $this->setField('state', $billing_info['state']); |
|
249 | - $this->setField('country', $billing_info['country']); |
|
250 | - $this->setField('zip', $billing_info['zip']); |
|
251 | - $this->setField('fax', $billing_info['fax']); |
|
252 | - $this->setField('cust_id', $primary_registrant->ID()); |
|
253 | - $this->setField('phone', $billing_info['phone']); |
|
254 | - //invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
255 | - //press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
256 | - //in which case, we need to generate teh invoice num per request right here... |
|
257 | - $this->setField('invoice_num', wp_generate_password(12, false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
258 | - //tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
259 | - $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
260 | - |
|
261 | - if ($this->_test_transactions) { |
|
262 | - $this->test_request = "true"; |
|
263 | - } |
|
264 | - |
|
265 | - //Capture response |
|
266 | - $this->type = "AUTH_CAPTURE"; |
|
267 | - $response = $this->_sendRequest($payment); |
|
268 | - if (! empty($response)) { |
|
269 | - if ($response->error_message) { |
|
270 | - $payment->set_status($this->_pay_model->failed_status()); |
|
271 | - $payment->set_gateway_response($response->error_message); |
|
272 | - } else { |
|
273 | - $payment_status = $response->approved |
|
274 | - ? $this->_pay_model->approved_status() |
|
275 | - : $this->_pay_model->declined_status(); |
|
276 | - $payment->set_status($payment_status); |
|
277 | - //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
278 | - $payment->set_amount((float) $response->amount); |
|
279 | - $payment->set_gateway_response( |
|
280 | - sprintf( |
|
281 | - esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
282 | - $response->response_reason_text, |
|
283 | - $response->response_reason_code |
|
284 | - ) |
|
285 | - ); |
|
286 | - if ($this->_debug_mode) { |
|
287 | - $txn_id = $response->invoice_number; |
|
288 | - } else { |
|
289 | - $txn_id = $response->transaction_id; |
|
290 | - } |
|
291 | - $payment->set_txn_id_chq_nmbr($txn_id); |
|
292 | - } |
|
293 | - $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
294 | - $payment->set_details(print_r($response, true)); |
|
295 | - } else { |
|
296 | - $payment->set_status($this->_pay_model->failed_status()); |
|
297 | - $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
298 | - $payment->set_details(print_r($response, true)); |
|
299 | - } |
|
300 | - return $payment; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
306 | - * also this method can be overridden by children classes to easily change |
|
307 | - * what billing data gets sent |
|
308 | - * |
|
309 | - * @param array $billing_info |
|
310 | - */ |
|
311 | - protected function _set_sensitive_billing_data($billing_info) |
|
312 | - { |
|
313 | - $this->setField('card_num', $billing_info['credit_card']); |
|
314 | - $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
315 | - $this->setField('card_code', $billing_info['cvv']); |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * Add a line item. |
|
321 | - * |
|
322 | - * @param string $item_id |
|
323 | - * @param string $item_name |
|
324 | - * @param string $item_description |
|
325 | - * @param string $item_quantity |
|
326 | - * @param string $item_unit_price |
|
327 | - * @param string $item_taxable |
|
328 | - */ |
|
329 | - public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
330 | - { |
|
331 | - $args = array( |
|
332 | - substr($item_id, 0, 31), |
|
333 | - substr($item_name, 0, 31), |
|
334 | - substr($item_description, 0, 255), |
|
335 | - number_format(abs($item_quantity), 2, '.', ''), |
|
336 | - number_format(abs($item_unit_price), 2, '.', ''), |
|
337 | - $item_taxable === 'N' ? 'N' : 'Y' |
|
338 | - ); |
|
339 | - $this->_additional_line_items[] = implode('<|>', $args); |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * Set an individual name/value pair. This will append x_ to the name |
|
345 | - * before posting. |
|
346 | - * |
|
347 | - * @param string $name |
|
348 | - * @param string $value |
|
349 | - * @throws AuthorizeNetException |
|
350 | - */ |
|
351 | - protected function setField($name, $value) |
|
352 | - { |
|
353 | - if (in_array($name, $this->_all_aim_fields)) { |
|
354 | - $this->_x_post_fields[$name] = $value; |
|
355 | - } else { |
|
356 | - throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
32 | + const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; //Authnet URL |
|
33 | + |
|
34 | + const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
35 | + |
|
36 | + protected $_login_id; |
|
37 | + |
|
38 | + protected $_transaction_key; |
|
39 | + |
|
40 | + protected $_server; |
|
41 | + |
|
42 | + protected $_currencies_supported = array( |
|
43 | + 'AUD', |
|
44 | + 'USD', |
|
45 | + 'CAD', |
|
46 | + 'EUR', |
|
47 | + 'GBP', |
|
48 | + 'NZD', |
|
49 | + ); |
|
50 | + |
|
51 | + /** |
|
52 | + * Whether to send test transactions (even to live site) |
|
53 | + * |
|
54 | + * @var boolean |
|
55 | + */ |
|
56 | + protected $_test_transactions; |
|
57 | + |
|
58 | + private $VERIFY_PEER = false; |
|
59 | + |
|
60 | + private $_x_post_fields = array( |
|
61 | + "version" => "3.1", |
|
62 | + "delim_char" => ",", |
|
63 | + "delim_data" => "TRUE", |
|
64 | + "relay_response" => "FALSE", |
|
65 | + "encap_char" => "|", |
|
66 | + ); |
|
67 | + |
|
68 | + private $_additional_line_items = array(); |
|
69 | + |
|
70 | + /** |
|
71 | + * A list of all fields in the AIM API. |
|
72 | + * Used to warn user if they try to set a field not offered in the API. |
|
73 | + */ |
|
74 | + private $_all_aim_fields = array( |
|
75 | + "address", |
|
76 | + "allow_partial_auth", |
|
77 | + "amount", |
|
78 | + "auth_code", |
|
79 | + "authentication_indicator", |
|
80 | + "bank_aba_code", |
|
81 | + "bank_acct_name", |
|
82 | + "bank_acct_num", |
|
83 | + "bank_acct_type", |
|
84 | + "bank_check_number", |
|
85 | + "bank_name", |
|
86 | + "card_code", |
|
87 | + "card_num", |
|
88 | + "cardholder_authentication_value", |
|
89 | + "city", |
|
90 | + "company", |
|
91 | + "country", |
|
92 | + "cust_id", |
|
93 | + "customer_ip", |
|
94 | + "delim_char", |
|
95 | + "delim_data", |
|
96 | + "description", |
|
97 | + "duplicate_window", |
|
98 | + "duty", |
|
99 | + "echeck_type", |
|
100 | + "email", |
|
101 | + "email_customer", |
|
102 | + "encap_char", |
|
103 | + "exp_date", |
|
104 | + "fax", |
|
105 | + "first_name", |
|
106 | + "footer_email_receipt", |
|
107 | + "freight", |
|
108 | + "header_email_receipt", |
|
109 | + "invoice_num", |
|
110 | + "last_name", |
|
111 | + "line_item", |
|
112 | + "login", |
|
113 | + "method", |
|
114 | + "phone", |
|
115 | + "po_num", |
|
116 | + "recurring_billing", |
|
117 | + "relay_response", |
|
118 | + "ship_to_address", |
|
119 | + "ship_to_city", |
|
120 | + "ship_to_company", |
|
121 | + "ship_to_country", |
|
122 | + "ship_to_first_name", |
|
123 | + "ship_to_last_name", |
|
124 | + "ship_to_state", |
|
125 | + "ship_to_zip", |
|
126 | + "split_tender_id", |
|
127 | + "state", |
|
128 | + "tax", |
|
129 | + "tax_exempt", |
|
130 | + "test_request", |
|
131 | + "tran_key", |
|
132 | + "trans_id", |
|
133 | + "type", |
|
134 | + "version", |
|
135 | + "zip", |
|
136 | + "solution_id" |
|
137 | + ); |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Gets the URL where the request should go. This is filterable |
|
142 | + * |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + protected function _get_server_url() |
|
146 | + { |
|
147 | + return apply_filters( |
|
148 | + 'FHEE__EEG_Aim___get_server_url', |
|
149 | + $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
150 | + $this |
|
151 | + ); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * TEMPORARY CALLBACK! Do not use |
|
157 | + * Callback which filters the server url. This is added so site admins can revert to using |
|
158 | + * the old AIM server in case Akamai service breaks their integration. |
|
159 | + * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net |
|
160 | + * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343) |
|
161 | + * Once that happens, this will be obsolete and WILL BE REMOVED. |
|
162 | + * |
|
163 | + * @param string $url |
|
164 | + * @param EEG_Aim $gateway_object |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) |
|
168 | + { |
|
169 | + if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) { |
|
170 | + return 'https://secure.authorize.net/gateway/transact.dll'; |
|
171 | + } else { |
|
172 | + return $url; |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
179 | + * usually send a request directly to the payment provider and update the payment's status based on that; |
|
180 | + * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
181 | + * for sending the request via http_remote_request() |
|
182 | + * |
|
183 | + * @param EEI_Payment $payment |
|
184 | + * @param array $billing_info { |
|
185 | + * @type $credit_card string |
|
186 | + * @type $cvv string |
|
187 | + * @type $exp_month string |
|
188 | + * @type $exp_year string |
|
189 | + * @see parent::do_direct_payment |
|
190 | + * } |
|
191 | + * @return EEI_Payment updated |
|
192 | + */ |
|
193 | + public function do_direct_payment($payment, $billing_info = null) |
|
194 | + { |
|
195 | + add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
196 | + // Enable test mode if needed |
|
197 | + //4007000000027 <-- test successful visa |
|
198 | + //4222222222222 <-- test failure card number |
|
199 | + |
|
200 | + $item_num = 1; |
|
201 | + $transaction = $payment->transaction(); |
|
202 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
203 | + $order_description = $gateway_formatter->formatOrderDescription($payment); |
|
204 | + $primary_registrant = $transaction->primary_registration(); |
|
205 | + //if we're are charging for the full amount, show the normal line items |
|
206 | + //and the itemized total adds up properly |
|
207 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
208 | + $total_line_item = $transaction->total_line_item(); |
|
209 | + foreach ($total_line_item->get_items() as $line_item) { |
|
210 | + if ($line_item->quantity() == 0) { |
|
211 | + continue; |
|
212 | + } |
|
213 | + $this->addLineItem( |
|
214 | + $item_num++, |
|
215 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
216 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
217 | + $line_item->quantity(), |
|
218 | + $line_item->unit_price(), |
|
219 | + 'N' |
|
220 | + ); |
|
221 | + $order_description .= $line_item->desc().', '; |
|
222 | + } |
|
223 | + foreach($total_line_item->tax_descendants() as $tax_line_item) { |
|
224 | + $this->addLineItem( |
|
225 | + $item_num++, |
|
226 | + $tax_line_item->name(), |
|
227 | + $tax_line_item->desc(), |
|
228 | + 1, |
|
229 | + $tax_line_item->total(), |
|
230 | + 'N' |
|
231 | + ); |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + //start transaction |
|
236 | + //if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
237 | + $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
238 | + $this->setField('solution_id', $partner_id); |
|
239 | + $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
240 | + $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
241 | + $this->_set_sensitive_billing_data($billing_info); |
|
242 | + $this->setField('first_name', $billing_info['first_name']); |
|
243 | + $this->setField('last_name', $billing_info['last_name']); |
|
244 | + $this->setField('email', $billing_info['email']); |
|
245 | + $this->setField('company', $billing_info['company']); |
|
246 | + $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
247 | + $this->setField('city', $billing_info['city']); |
|
248 | + $this->setField('state', $billing_info['state']); |
|
249 | + $this->setField('country', $billing_info['country']); |
|
250 | + $this->setField('zip', $billing_info['zip']); |
|
251 | + $this->setField('fax', $billing_info['fax']); |
|
252 | + $this->setField('cust_id', $primary_registrant->ID()); |
|
253 | + $this->setField('phone', $billing_info['phone']); |
|
254 | + //invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
255 | + //press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
256 | + //in which case, we need to generate teh invoice num per request right here... |
|
257 | + $this->setField('invoice_num', wp_generate_password(12, false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
258 | + //tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
259 | + $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
260 | + |
|
261 | + if ($this->_test_transactions) { |
|
262 | + $this->test_request = "true"; |
|
263 | + } |
|
264 | + |
|
265 | + //Capture response |
|
266 | + $this->type = "AUTH_CAPTURE"; |
|
267 | + $response = $this->_sendRequest($payment); |
|
268 | + if (! empty($response)) { |
|
269 | + if ($response->error_message) { |
|
270 | + $payment->set_status($this->_pay_model->failed_status()); |
|
271 | + $payment->set_gateway_response($response->error_message); |
|
272 | + } else { |
|
273 | + $payment_status = $response->approved |
|
274 | + ? $this->_pay_model->approved_status() |
|
275 | + : $this->_pay_model->declined_status(); |
|
276 | + $payment->set_status($payment_status); |
|
277 | + //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
278 | + $payment->set_amount((float) $response->amount); |
|
279 | + $payment->set_gateway_response( |
|
280 | + sprintf( |
|
281 | + esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
282 | + $response->response_reason_text, |
|
283 | + $response->response_reason_code |
|
284 | + ) |
|
285 | + ); |
|
286 | + if ($this->_debug_mode) { |
|
287 | + $txn_id = $response->invoice_number; |
|
288 | + } else { |
|
289 | + $txn_id = $response->transaction_id; |
|
290 | + } |
|
291 | + $payment->set_txn_id_chq_nmbr($txn_id); |
|
292 | + } |
|
293 | + $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
294 | + $payment->set_details(print_r($response, true)); |
|
295 | + } else { |
|
296 | + $payment->set_status($this->_pay_model->failed_status()); |
|
297 | + $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
298 | + $payment->set_details(print_r($response, true)); |
|
299 | + } |
|
300 | + return $payment; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
306 | + * also this method can be overridden by children classes to easily change |
|
307 | + * what billing data gets sent |
|
308 | + * |
|
309 | + * @param array $billing_info |
|
310 | + */ |
|
311 | + protected function _set_sensitive_billing_data($billing_info) |
|
312 | + { |
|
313 | + $this->setField('card_num', $billing_info['credit_card']); |
|
314 | + $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
315 | + $this->setField('card_code', $billing_info['cvv']); |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * Add a line item. |
|
321 | + * |
|
322 | + * @param string $item_id |
|
323 | + * @param string $item_name |
|
324 | + * @param string $item_description |
|
325 | + * @param string $item_quantity |
|
326 | + * @param string $item_unit_price |
|
327 | + * @param string $item_taxable |
|
328 | + */ |
|
329 | + public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
330 | + { |
|
331 | + $args = array( |
|
332 | + substr($item_id, 0, 31), |
|
333 | + substr($item_name, 0, 31), |
|
334 | + substr($item_description, 0, 255), |
|
335 | + number_format(abs($item_quantity), 2, '.', ''), |
|
336 | + number_format(abs($item_unit_price), 2, '.', ''), |
|
337 | + $item_taxable === 'N' ? 'N' : 'Y' |
|
338 | + ); |
|
339 | + $this->_additional_line_items[] = implode('<|>', $args); |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * Set an individual name/value pair. This will append x_ to the name |
|
345 | + * before posting. |
|
346 | + * |
|
347 | + * @param string $name |
|
348 | + * @param string $value |
|
349 | + * @throws AuthorizeNetException |
|
350 | + */ |
|
351 | + protected function setField($name, $value) |
|
352 | + { |
|
353 | + if (in_array($name, $this->_all_aim_fields)) { |
|
354 | + $this->_x_post_fields[$name] = $value; |
|
355 | + } else { |
|
356 | + throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
357 | 357 | To set a custom field use setCustomField('field','value') instead."); |
358 | - } |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * Posts the request to AuthorizeNet & returns response. |
|
364 | - * |
|
365 | - * @param $payment |
|
366 | - * @return \EE_AuthorizeNetAIM_Response |
|
367 | - */ |
|
368 | - private function _sendRequest($payment) |
|
369 | - { |
|
370 | - $this->_x_post_fields['login'] = $this->_login_id; |
|
371 | - $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
372 | - $x_keys = array(); |
|
373 | - foreach ($this->_x_post_fields as $key => $value) { |
|
374 | - $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
375 | - } |
|
376 | - // Add line items |
|
377 | - foreach ($this->_additional_line_items as $key => $value) { |
|
378 | - $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
379 | - } |
|
380 | - $this->_log_clean_request($x_keys, $payment); |
|
381 | - $post_url = $this->_get_server_url(); |
|
382 | - $curl_request = curl_init($post_url); |
|
383 | - $post_body = implode("&", $x_keys); |
|
384 | - curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
385 | - curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
386 | - curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
387 | - curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
388 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
389 | - if ($this->VERIFY_PEER) { |
|
390 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
391 | - } else { |
|
392 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
393 | - } |
|
394 | - |
|
395 | - if (preg_match('/xml/', $post_url)) { |
|
396 | - curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
|
397 | - } |
|
398 | - |
|
399 | - $response = curl_exec($curl_request); |
|
400 | - |
|
401 | - curl_close($curl_request); |
|
402 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
403 | - |
|
404 | - return $this->_log_and_clean_response($response_obj, $payment); |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Logs the clean data only |
|
410 | - * |
|
411 | - * @param array $request_array |
|
412 | - * @param EEI_Payment $payment |
|
413 | - */ |
|
414 | - protected function _log_clean_request($request_array, $payment) |
|
415 | - { |
|
416 | - $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
417 | - foreach ($request_array as $index => $keyvaltogether) { |
|
418 | - foreach ($keys_to_filter_out as $key) { |
|
419 | - if (strpos($keyvaltogether, $key) === 0) { |
|
420 | - //found it at the first character |
|
421 | - //so its one of them |
|
422 | - unset($request_array[$index]); |
|
423 | - } |
|
424 | - } |
|
425 | - } |
|
426 | - $this->log( |
|
427 | - array( |
|
428 | - 'AIM Request sent:' => $request_array, |
|
429 | - 'Server URL' => $this->_get_server_url() |
|
430 | - ), |
|
431 | - $payment |
|
432 | - ); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * Logs the response and cleans it |
|
439 | - * |
|
440 | - * @param EE_AuthorizeNetAIM_Response $response_obj |
|
441 | - * @param EE_Payment $payment |
|
442 | - * @return \EE_AuthorizeNetAIM_Response |
|
443 | - */ |
|
444 | - private function _log_and_clean_response($response_obj, $payment) |
|
445 | - { |
|
446 | - $response_obj->account_number = ''; |
|
447 | - $this->log(array('AIM Response received:' => (array)$response_obj), $payment); |
|
448 | - return $response_obj; |
|
449 | - } |
|
358 | + } |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * Posts the request to AuthorizeNet & returns response. |
|
364 | + * |
|
365 | + * @param $payment |
|
366 | + * @return \EE_AuthorizeNetAIM_Response |
|
367 | + */ |
|
368 | + private function _sendRequest($payment) |
|
369 | + { |
|
370 | + $this->_x_post_fields['login'] = $this->_login_id; |
|
371 | + $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
372 | + $x_keys = array(); |
|
373 | + foreach ($this->_x_post_fields as $key => $value) { |
|
374 | + $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
375 | + } |
|
376 | + // Add line items |
|
377 | + foreach ($this->_additional_line_items as $key => $value) { |
|
378 | + $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
379 | + } |
|
380 | + $this->_log_clean_request($x_keys, $payment); |
|
381 | + $post_url = $this->_get_server_url(); |
|
382 | + $curl_request = curl_init($post_url); |
|
383 | + $post_body = implode("&", $x_keys); |
|
384 | + curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
385 | + curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
386 | + curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
387 | + curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
388 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
389 | + if ($this->VERIFY_PEER) { |
|
390 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
391 | + } else { |
|
392 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
393 | + } |
|
394 | + |
|
395 | + if (preg_match('/xml/', $post_url)) { |
|
396 | + curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
|
397 | + } |
|
398 | + |
|
399 | + $response = curl_exec($curl_request); |
|
400 | + |
|
401 | + curl_close($curl_request); |
|
402 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
403 | + |
|
404 | + return $this->_log_and_clean_response($response_obj, $payment); |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Logs the clean data only |
|
410 | + * |
|
411 | + * @param array $request_array |
|
412 | + * @param EEI_Payment $payment |
|
413 | + */ |
|
414 | + protected function _log_clean_request($request_array, $payment) |
|
415 | + { |
|
416 | + $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
417 | + foreach ($request_array as $index => $keyvaltogether) { |
|
418 | + foreach ($keys_to_filter_out as $key) { |
|
419 | + if (strpos($keyvaltogether, $key) === 0) { |
|
420 | + //found it at the first character |
|
421 | + //so its one of them |
|
422 | + unset($request_array[$index]); |
|
423 | + } |
|
424 | + } |
|
425 | + } |
|
426 | + $this->log( |
|
427 | + array( |
|
428 | + 'AIM Request sent:' => $request_array, |
|
429 | + 'Server URL' => $this->_get_server_url() |
|
430 | + ), |
|
431 | + $payment |
|
432 | + ); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * Logs the response and cleans it |
|
439 | + * |
|
440 | + * @param EE_AuthorizeNetAIM_Response $response_obj |
|
441 | + * @param EE_Payment $payment |
|
442 | + * @return \EE_AuthorizeNetAIM_Response |
|
443 | + */ |
|
444 | + private function _log_and_clean_response($response_obj, $payment) |
|
445 | + { |
|
446 | + $response_obj->account_number = ''; |
|
447 | + $this->log(array('AIM Response received:' => (array)$response_obj), $payment); |
|
448 | + return $response_obj; |
|
449 | + } |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | |
@@ -462,193 +462,193 @@ discard block |
||
462 | 462 | class EE_AuthorizeNetAIM_Response |
463 | 463 | { |
464 | 464 | |
465 | - const APPROVED = '1'; |
|
466 | - const DECLINED = '2'; |
|
467 | - const ERROR = '3'; |
|
468 | - const HELD = '4'; |
|
469 | - |
|
470 | - protected $_x_post_fields = array( |
|
471 | - "version" => "3.1", |
|
472 | - "delim_char" => ",", |
|
473 | - "delim_data" => "TRUE", |
|
474 | - "relay_response" => "FALSE", |
|
475 | - "encap_char" => "|", |
|
476 | - ); |
|
477 | - public $approved; |
|
478 | - public $declined; |
|
479 | - public $error; |
|
480 | - public $held; |
|
481 | - public $response_code; |
|
482 | - public $response_subcode; |
|
483 | - public $response_reason_code; |
|
484 | - public $response_reason_text; |
|
485 | - public $authorization_code; |
|
486 | - public $avs_response; |
|
487 | - public $transaction_id; |
|
488 | - public $invoice_number; |
|
489 | - public $description; |
|
490 | - public $amount; |
|
491 | - public $method; |
|
492 | - public $transaction_type; |
|
493 | - public $customer_id; |
|
494 | - public $first_name; |
|
495 | - public $last_name; |
|
496 | - public $company; |
|
497 | - public $address; |
|
498 | - public $city; |
|
499 | - public $state; |
|
500 | - public $zip_code; |
|
501 | - public $country; |
|
502 | - public $phone; |
|
503 | - public $fax; |
|
504 | - public $email_address; |
|
505 | - public $ship_to_first_name; |
|
506 | - public $ship_to_last_name; |
|
507 | - public $ship_to_company; |
|
508 | - public $ship_to_address; |
|
509 | - public $ship_to_city; |
|
510 | - public $ship_to_state; |
|
511 | - public $ship_to_zip_code; |
|
512 | - public $ship_to_country; |
|
513 | - public $tax; |
|
514 | - public $duty; |
|
515 | - public $freight; |
|
516 | - public $tax_exempt; |
|
517 | - public $purchase_order_number; |
|
518 | - public $md5_hash; |
|
519 | - public $card_code_response; |
|
520 | - public $cavv_response; // cardholder_authentication_verification_response |
|
521 | - public $account_number; |
|
522 | - public $card_type; |
|
523 | - public $split_tender_id; |
|
524 | - public $requested_amount; |
|
525 | - public $balance_on_card; |
|
526 | - public $response; // The response string from AuthorizeNet. |
|
527 | - public $error_message; |
|
528 | - private $_response_array = array(); // An array with the split response. |
|
529 | - |
|
530 | - |
|
531 | - /** |
|
532 | - * Constructor. Parses the AuthorizeNet response string |
|
533 | - * |
|
534 | - * @param string $response The response from the AuthNet server. |
|
535 | - * @var string $delimiter The delimiter used (default is ",") |
|
536 | - * @var string $encap_char The encap_char used (default is "|") |
|
537 | - * @var array $custom_fields Any custom fields set in the request. |
|
538 | - */ |
|
539 | - |
|
540 | - public function __construct($response) |
|
541 | - { |
|
542 | - $encap_char = $this->_x_post_fields['encap_char']; |
|
543 | - $delimiter = $this->_x_post_fields['delim_char']; |
|
544 | - if ($response) { |
|
545 | - // Split Array |
|
546 | - $this->response = $response; |
|
547 | - if ($encap_char) { |
|
548 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
549 | - } else { |
|
550 | - $this->_response_array = explode($delimiter, $response); |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * If AuthorizeNet doesn't return a delimited response. |
|
555 | - */ |
|
556 | - if (count($this->_response_array) < 10) { |
|
557 | - $this->approved = false; |
|
558 | - $this->error = true; |
|
559 | - $this->error_message = sprintf( |
|
560 | - esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
561 | - esc_html($response) |
|
562 | - ); |
|
563 | - return; |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - |
|
568 | - // Set all fields |
|
569 | - $this->response_code = $this->_response_array[0]; |
|
570 | - $this->response_subcode = $this->_response_array[1]; |
|
571 | - $this->response_reason_code = $this->_response_array[2]; |
|
572 | - $this->response_reason_text = $this->_response_array[3]; |
|
573 | - $this->authorization_code = $this->_response_array[4]; |
|
574 | - $this->avs_response = $this->_response_array[5]; |
|
575 | - $this->transaction_id = $this->_response_array[6]; |
|
576 | - $this->invoice_number = $this->_response_array[7]; |
|
577 | - $this->description = $this->_response_array[8]; |
|
578 | - $this->amount = $this->_response_array[9]; |
|
579 | - $this->method = $this->_response_array[10]; |
|
580 | - $this->transaction_type = $this->_response_array[11]; |
|
581 | - $this->customer_id = $this->_response_array[12]; |
|
582 | - $this->first_name = $this->_response_array[13]; |
|
583 | - $this->last_name = $this->_response_array[14]; |
|
584 | - $this->company = $this->_response_array[15]; |
|
585 | - $this->address = $this->_response_array[16]; |
|
586 | - $this->city = $this->_response_array[17]; |
|
587 | - $this->state = $this->_response_array[18]; |
|
588 | - $this->zip_code = $this->_response_array[19]; |
|
589 | - $this->country = $this->_response_array[20]; |
|
590 | - $this->phone = $this->_response_array[21]; |
|
591 | - $this->fax = $this->_response_array[22]; |
|
592 | - $this->email_address = $this->_response_array[23]; |
|
593 | - $this->ship_to_first_name = $this->_response_array[24]; |
|
594 | - $this->ship_to_last_name = $this->_response_array[25]; |
|
595 | - $this->ship_to_company = $this->_response_array[26]; |
|
596 | - $this->ship_to_address = $this->_response_array[27]; |
|
597 | - $this->ship_to_city = $this->_response_array[28]; |
|
598 | - $this->ship_to_state = $this->_response_array[29]; |
|
599 | - $this->ship_to_zip_code = $this->_response_array[30]; |
|
600 | - $this->ship_to_country = $this->_response_array[31]; |
|
601 | - $this->tax = $this->_response_array[32]; |
|
602 | - $this->duty = $this->_response_array[33]; |
|
603 | - $this->freight = $this->_response_array[34]; |
|
604 | - $this->tax_exempt = $this->_response_array[35]; |
|
605 | - $this->purchase_order_number = $this->_response_array[36]; |
|
606 | - $this->md5_hash = $this->_response_array[37]; |
|
607 | - $this->card_code_response = $this->_response_array[38]; |
|
608 | - $this->cavv_response = $this->_response_array[39]; |
|
609 | - $this->account_number = $this->_response_array[50]; |
|
610 | - $this->card_type = $this->_response_array[51]; |
|
611 | - $this->split_tender_id = $this->_response_array[52]; |
|
612 | - $this->requested_amount = $this->_response_array[53]; |
|
613 | - $this->balance_on_card = $this->_response_array[54]; |
|
614 | - |
|
615 | - $this->approved = ($this->response_code === self::APPROVED); |
|
616 | - $this->declined = ($this->response_code === self::DECLINED); |
|
617 | - $this->error = ($this->response_code === self::ERROR); |
|
618 | - $this->held = ($this->response_code === self::HELD); |
|
619 | - } else { |
|
620 | - $this->approved = false; |
|
621 | - $this->error = true; |
|
622 | - $this->error_message = esc_html__( |
|
623 | - 'Error connecting to Authorize.net', |
|
624 | - 'event_espresso' |
|
625 | - ); |
|
626 | - } |
|
627 | - } |
|
465 | + const APPROVED = '1'; |
|
466 | + const DECLINED = '2'; |
|
467 | + const ERROR = '3'; |
|
468 | + const HELD = '4'; |
|
469 | + |
|
470 | + protected $_x_post_fields = array( |
|
471 | + "version" => "3.1", |
|
472 | + "delim_char" => ",", |
|
473 | + "delim_data" => "TRUE", |
|
474 | + "relay_response" => "FALSE", |
|
475 | + "encap_char" => "|", |
|
476 | + ); |
|
477 | + public $approved; |
|
478 | + public $declined; |
|
479 | + public $error; |
|
480 | + public $held; |
|
481 | + public $response_code; |
|
482 | + public $response_subcode; |
|
483 | + public $response_reason_code; |
|
484 | + public $response_reason_text; |
|
485 | + public $authorization_code; |
|
486 | + public $avs_response; |
|
487 | + public $transaction_id; |
|
488 | + public $invoice_number; |
|
489 | + public $description; |
|
490 | + public $amount; |
|
491 | + public $method; |
|
492 | + public $transaction_type; |
|
493 | + public $customer_id; |
|
494 | + public $first_name; |
|
495 | + public $last_name; |
|
496 | + public $company; |
|
497 | + public $address; |
|
498 | + public $city; |
|
499 | + public $state; |
|
500 | + public $zip_code; |
|
501 | + public $country; |
|
502 | + public $phone; |
|
503 | + public $fax; |
|
504 | + public $email_address; |
|
505 | + public $ship_to_first_name; |
|
506 | + public $ship_to_last_name; |
|
507 | + public $ship_to_company; |
|
508 | + public $ship_to_address; |
|
509 | + public $ship_to_city; |
|
510 | + public $ship_to_state; |
|
511 | + public $ship_to_zip_code; |
|
512 | + public $ship_to_country; |
|
513 | + public $tax; |
|
514 | + public $duty; |
|
515 | + public $freight; |
|
516 | + public $tax_exempt; |
|
517 | + public $purchase_order_number; |
|
518 | + public $md5_hash; |
|
519 | + public $card_code_response; |
|
520 | + public $cavv_response; // cardholder_authentication_verification_response |
|
521 | + public $account_number; |
|
522 | + public $card_type; |
|
523 | + public $split_tender_id; |
|
524 | + public $requested_amount; |
|
525 | + public $balance_on_card; |
|
526 | + public $response; // The response string from AuthorizeNet. |
|
527 | + public $error_message; |
|
528 | + private $_response_array = array(); // An array with the split response. |
|
529 | + |
|
530 | + |
|
531 | + /** |
|
532 | + * Constructor. Parses the AuthorizeNet response string |
|
533 | + * |
|
534 | + * @param string $response The response from the AuthNet server. |
|
535 | + * @var string $delimiter The delimiter used (default is ",") |
|
536 | + * @var string $encap_char The encap_char used (default is "|") |
|
537 | + * @var array $custom_fields Any custom fields set in the request. |
|
538 | + */ |
|
539 | + |
|
540 | + public function __construct($response) |
|
541 | + { |
|
542 | + $encap_char = $this->_x_post_fields['encap_char']; |
|
543 | + $delimiter = $this->_x_post_fields['delim_char']; |
|
544 | + if ($response) { |
|
545 | + // Split Array |
|
546 | + $this->response = $response; |
|
547 | + if ($encap_char) { |
|
548 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
549 | + } else { |
|
550 | + $this->_response_array = explode($delimiter, $response); |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * If AuthorizeNet doesn't return a delimited response. |
|
555 | + */ |
|
556 | + if (count($this->_response_array) < 10) { |
|
557 | + $this->approved = false; |
|
558 | + $this->error = true; |
|
559 | + $this->error_message = sprintf( |
|
560 | + esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
561 | + esc_html($response) |
|
562 | + ); |
|
563 | + return; |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + |
|
568 | + // Set all fields |
|
569 | + $this->response_code = $this->_response_array[0]; |
|
570 | + $this->response_subcode = $this->_response_array[1]; |
|
571 | + $this->response_reason_code = $this->_response_array[2]; |
|
572 | + $this->response_reason_text = $this->_response_array[3]; |
|
573 | + $this->authorization_code = $this->_response_array[4]; |
|
574 | + $this->avs_response = $this->_response_array[5]; |
|
575 | + $this->transaction_id = $this->_response_array[6]; |
|
576 | + $this->invoice_number = $this->_response_array[7]; |
|
577 | + $this->description = $this->_response_array[8]; |
|
578 | + $this->amount = $this->_response_array[9]; |
|
579 | + $this->method = $this->_response_array[10]; |
|
580 | + $this->transaction_type = $this->_response_array[11]; |
|
581 | + $this->customer_id = $this->_response_array[12]; |
|
582 | + $this->first_name = $this->_response_array[13]; |
|
583 | + $this->last_name = $this->_response_array[14]; |
|
584 | + $this->company = $this->_response_array[15]; |
|
585 | + $this->address = $this->_response_array[16]; |
|
586 | + $this->city = $this->_response_array[17]; |
|
587 | + $this->state = $this->_response_array[18]; |
|
588 | + $this->zip_code = $this->_response_array[19]; |
|
589 | + $this->country = $this->_response_array[20]; |
|
590 | + $this->phone = $this->_response_array[21]; |
|
591 | + $this->fax = $this->_response_array[22]; |
|
592 | + $this->email_address = $this->_response_array[23]; |
|
593 | + $this->ship_to_first_name = $this->_response_array[24]; |
|
594 | + $this->ship_to_last_name = $this->_response_array[25]; |
|
595 | + $this->ship_to_company = $this->_response_array[26]; |
|
596 | + $this->ship_to_address = $this->_response_array[27]; |
|
597 | + $this->ship_to_city = $this->_response_array[28]; |
|
598 | + $this->ship_to_state = $this->_response_array[29]; |
|
599 | + $this->ship_to_zip_code = $this->_response_array[30]; |
|
600 | + $this->ship_to_country = $this->_response_array[31]; |
|
601 | + $this->tax = $this->_response_array[32]; |
|
602 | + $this->duty = $this->_response_array[33]; |
|
603 | + $this->freight = $this->_response_array[34]; |
|
604 | + $this->tax_exempt = $this->_response_array[35]; |
|
605 | + $this->purchase_order_number = $this->_response_array[36]; |
|
606 | + $this->md5_hash = $this->_response_array[37]; |
|
607 | + $this->card_code_response = $this->_response_array[38]; |
|
608 | + $this->cavv_response = $this->_response_array[39]; |
|
609 | + $this->account_number = $this->_response_array[50]; |
|
610 | + $this->card_type = $this->_response_array[51]; |
|
611 | + $this->split_tender_id = $this->_response_array[52]; |
|
612 | + $this->requested_amount = $this->_response_array[53]; |
|
613 | + $this->balance_on_card = $this->_response_array[54]; |
|
614 | + |
|
615 | + $this->approved = ($this->response_code === self::APPROVED); |
|
616 | + $this->declined = ($this->response_code === self::DECLINED); |
|
617 | + $this->error = ($this->response_code === self::ERROR); |
|
618 | + $this->held = ($this->response_code === self::HELD); |
|
619 | + } else { |
|
620 | + $this->approved = false; |
|
621 | + $this->error = true; |
|
622 | + $this->error_message = esc_html__( |
|
623 | + 'Error connecting to Authorize.net', |
|
624 | + 'event_espresso' |
|
625 | + ); |
|
626 | + } |
|
627 | + } |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | if (! class_exists('AuthorizeNetException')) { |
631 | - /** |
|
632 | - * Class AuthorizeNetException |
|
633 | - * |
|
634 | - * @package AuthorizeNet |
|
635 | - */ |
|
636 | - class AuthorizeNetException extends Exception |
|
637 | - { |
|
638 | - |
|
639 | - /** |
|
640 | - * Construct the exception. Note: The message is NOT binary safe. |
|
641 | - * |
|
642 | - * @link http://php.net/manual/en/exception.construct.php |
|
643 | - * @param string $message [optional] The Exception message to throw. |
|
644 | - * @param int $code [optional] The Exception code. |
|
645 | - * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
646 | - * @since 5.1.0 |
|
647 | - */ |
|
648 | - public function __construct($message = "", $code = 0, Exception $previous = null) |
|
649 | - { |
|
650 | - parent::__construct($message, $code, $previous); |
|
651 | - } |
|
652 | - } |
|
631 | + /** |
|
632 | + * Class AuthorizeNetException |
|
633 | + * |
|
634 | + * @package AuthorizeNet |
|
635 | + */ |
|
636 | + class AuthorizeNetException extends Exception |
|
637 | + { |
|
638 | + |
|
639 | + /** |
|
640 | + * Construct the exception. Note: The message is NOT binary safe. |
|
641 | + * |
|
642 | + * @link http://php.net/manual/en/exception.construct.php |
|
643 | + * @param string $message [optional] The Exception message to throw. |
|
644 | + * @param int $code [optional] The Exception code. |
|
645 | + * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
646 | + * @since 5.1.0 |
|
647 | + */ |
|
648 | + public function __construct($message = "", $code = 0, Exception $previous = null) |
|
649 | + { |
|
650 | + parent::__construct($message, $code, $previous); |
|
651 | + } |
|
652 | + } |
|
653 | 653 | } |
654 | 654 | // End of file EEG_Aim.gateway.php |
655 | 655 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | ); |
221 | 221 | $order_description .= $line_item->desc().', '; |
222 | 222 | } |
223 | - foreach($total_line_item->tax_descendants() as $tax_line_item) { |
|
223 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
224 | 224 | $this->addLineItem( |
225 | 225 | $item_num++, |
226 | 226 | $tax_line_item->name(), |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | //invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
255 | 255 | //press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
256 | 256 | //in which case, we need to generate teh invoice num per request right here... |
257 | - $this->setField('invoice_num', wp_generate_password(12, false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
257 | + $this->setField('invoice_num', wp_generate_password(12, false)); //$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
258 | 258 | //tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
259 | 259 | $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
260 | 260 | |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | //Capture response |
266 | 266 | $this->type = "AUTH_CAPTURE"; |
267 | 267 | $response = $this->_sendRequest($payment); |
268 | - if (! empty($response)) { |
|
268 | + if ( ! empty($response)) { |
|
269 | 269 | if ($response->error_message) { |
270 | 270 | $payment->set_status($this->_pay_model->failed_status()); |
271 | 271 | $payment->set_gateway_response($response->error_message); |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | protected function _set_sensitive_billing_data($billing_info) |
312 | 312 | { |
313 | 313 | $this->setField('card_num', $billing_info['credit_card']); |
314 | - $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
314 | + $this->setField('exp_date', $billing_info['exp_month'].$billing_info['exp_year']); |
|
315 | 315 | $this->setField('card_code', $billing_info['cvv']); |
316 | 316 | } |
317 | 317 | |
@@ -371,11 +371,11 @@ discard block |
||
371 | 371 | $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
372 | 372 | $x_keys = array(); |
373 | 373 | foreach ($this->_x_post_fields as $key => $value) { |
374 | - $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
374 | + $x_keys[] = "x_$key=".urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
375 | 375 | } |
376 | 376 | // Add line items |
377 | 377 | foreach ($this->_additional_line_items as $key => $value) { |
378 | - $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
378 | + $x_keys[] = "x_line_item=".urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
379 | 379 | } |
380 | 380 | $this->_log_clean_request($x_keys, $payment); |
381 | 381 | $post_url = $this->_get_server_url(); |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
388 | 388 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
389 | 389 | if ($this->VERIFY_PEER) { |
390 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
390 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__).'/ssl/cert.pem'); |
|
391 | 391 | } else { |
392 | 392 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
393 | 393 | } |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | $response = curl_exec($curl_request); |
400 | 400 | |
401 | 401 | curl_close($curl_request); |
402 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
402 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
403 | 403 | |
404 | 404 | return $this->_log_and_clean_response($response_obj, $payment); |
405 | 405 | } |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | private function _log_and_clean_response($response_obj, $payment) |
445 | 445 | { |
446 | 446 | $response_obj->account_number = ''; |
447 | - $this->log(array('AIM Response received:' => (array)$response_obj), $payment); |
|
447 | + $this->log(array('AIM Response received:' => (array) $response_obj), $payment); |
|
448 | 448 | return $response_obj; |
449 | 449 | } |
450 | 450 | } |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | // Split Array |
546 | 546 | $this->response = $response; |
547 | 547 | if ($encap_char) { |
548 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
548 | + $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
549 | 549 | } else { |
550 | 550 | $this->_response_array = explode($delimiter, $response); |
551 | 551 | } |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | } |
628 | 628 | } |
629 | 629 | |
630 | -if (! class_exists('AuthorizeNetException')) { |
|
630 | +if ( ! class_exists('AuthorizeNetException')) { |
|
631 | 631 | /** |
632 | 632 | * Class AuthorizeNetException |
633 | 633 | * |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -16,290 +16,290 @@ discard block |
||
16 | 16 | class EEG_Mijireh extends EE_Offsite_Gateway |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Mijreh API access key. |
|
21 | - * |
|
22 | - * @var $_access_key string |
|
23 | - */ |
|
24 | - protected $_access_key; |
|
19 | + /** |
|
20 | + * Mijreh API access key. |
|
21 | + * |
|
22 | + * @var $_access_key string |
|
23 | + */ |
|
24 | + protected $_access_key; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Mijreh supported currencies. |
|
28 | - * |
|
29 | - * @var $_currencies_supported array |
|
30 | - */ |
|
31 | - protected $_currencies_supported = EE_Gateway::all_currencies_supported; |
|
26 | + /** |
|
27 | + * Mijreh supported currencies. |
|
28 | + * |
|
29 | + * @var $_currencies_supported array |
|
30 | + */ |
|
31 | + protected $_currencies_supported = EE_Gateway::all_currencies_supported; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Mijreh API order URL. |
|
35 | - * |
|
36 | - * @var $_mijireh_api_orders_url string |
|
37 | - */ |
|
38 | - protected $_mijireh_api_orders_url = 'https://secure.mijireh.com/api/1/orders'; |
|
33 | + /** |
|
34 | + * Mijreh API order URL. |
|
35 | + * |
|
36 | + * @var $_mijireh_api_orders_url string |
|
37 | + */ |
|
38 | + protected $_mijireh_api_orders_url = 'https://secure.mijireh.com/api/1/orders'; |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param EE_Payment $payment to process |
|
43 | - * @param array $billing_info but should be empty for this gateway |
|
44 | - * @param string $return_url URL to send the user to after a successful payment on the payment provider's website |
|
45 | - * @param string $notify_url URL to send the instant payment notification |
|
46 | - * @param string $cancel_url URL to send the user to after a cancelled payment attempt on teh payment provider's website |
|
47 | - * @throws \EE_Error |
|
48 | - * @return EE_Payment |
|
49 | - */ |
|
50 | - public function set_redirection_info( |
|
51 | - $payment, |
|
52 | - $billing_info = array(), |
|
53 | - $return_url = NULL, |
|
54 | - $notify_url = NULL, |
|
55 | - $cancel_url = NULL |
|
56 | - ) { |
|
57 | - /* @var $transaction EE_Transaction */ |
|
58 | - $transaction = $payment->transaction(); |
|
59 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
41 | + /** |
|
42 | + * @param EE_Payment $payment to process |
|
43 | + * @param array $billing_info but should be empty for this gateway |
|
44 | + * @param string $return_url URL to send the user to after a successful payment on the payment provider's website |
|
45 | + * @param string $notify_url URL to send the instant payment notification |
|
46 | + * @param string $cancel_url URL to send the user to after a cancelled payment attempt on teh payment provider's website |
|
47 | + * @throws \EE_Error |
|
48 | + * @return EE_Payment |
|
49 | + */ |
|
50 | + public function set_redirection_info( |
|
51 | + $payment, |
|
52 | + $billing_info = array(), |
|
53 | + $return_url = NULL, |
|
54 | + $notify_url = NULL, |
|
55 | + $cancel_url = NULL |
|
56 | + ) { |
|
57 | + /* @var $transaction EE_Transaction */ |
|
58 | + $transaction = $payment->transaction(); |
|
59 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
60 | 60 | |
61 | - //get any of the current registrations, |
|
62 | - $primary_registrant = $transaction->primary_registration(); |
|
61 | + //get any of the current registrations, |
|
62 | + $primary_registrant = $transaction->primary_registration(); |
|
63 | 63 | |
64 | - $primary_attendee = $primary_registrant->attendee(); |
|
65 | - $items = array(); |
|
66 | - //if we're are charging for the full amount, show the normal line items |
|
67 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
68 | - $total_line_item = $transaction->total_line_item(); |
|
69 | - $tax_total = $total_line_item->get_total_tax(); |
|
70 | - foreach ($total_line_item->get_items() as $line_item) { |
|
71 | - $items[] = array( |
|
72 | - 'name' => apply_filters( |
|
73 | - 'FHEE__EEG_Mijireh__set_redirection_info__full_amount_line_item_name', |
|
74 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
75 | - $line_item, |
|
76 | - $payment, |
|
77 | - $primary_registrant |
|
78 | - ), |
|
79 | - 'price' => $gateway_formatter->formatCurrency($line_item->unit_price()), |
|
80 | - 'sku' => $line_item->code(), |
|
81 | - 'quantity' => $line_item->quantity() |
|
82 | - ); |
|
83 | - } |
|
84 | - } else {//its a partial payment |
|
85 | - $tax_total = 0; |
|
86 | - //partial payment, so just add 1 item |
|
87 | - $items[] = array( |
|
88 | - 'name' => apply_filters( |
|
89 | - 'FHEE__EEG_Mijireh__set_redirection_info__partial_amount_line_item_name', |
|
90 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
91 | - $payment, |
|
92 | - $primary_registrant |
|
93 | - ), |
|
94 | - 'price' => $gateway_formatter->formatCurrency($payment->amount()), |
|
95 | - 'sku' => $primary_registrant->reg_code(), |
|
96 | - 'quantity' => 1 |
|
97 | - ); |
|
98 | - } |
|
99 | - $order = array( |
|
100 | - 'total' => $gateway_formatter->formatCurrency($payment->amount()), |
|
101 | - 'return_url' => $return_url, |
|
102 | - 'items' => $this->_prepare_for_mijireh($items), |
|
103 | - 'email' => $primary_attendee->email(), |
|
104 | - 'first_name' => $primary_attendee->fname(), |
|
105 | - 'last_name' => $primary_attendee->lname(), |
|
106 | - 'tax' => $gateway_formatter->formatCurrency($tax_total), |
|
107 | - 'partner_id' => 'ee' |
|
108 | - ); |
|
109 | - //setup address? |
|
110 | - if ($primary_attendee->address() |
|
111 | - && $primary_attendee->city() |
|
112 | - && $primary_attendee->state_ID() |
|
113 | - && $primary_attendee->country_ID() |
|
114 | - && $primary_attendee->zip() |
|
115 | - ) { |
|
116 | - $shipping_address = array( |
|
117 | - 'first_name' => $primary_attendee->fname(), |
|
118 | - 'last_name' => $primary_attendee->lname(), |
|
119 | - 'street' => $primary_attendee->address(), |
|
120 | - 'city' => $primary_attendee->city(), |
|
121 | - 'state_province' => $primary_attendee->state_name(), |
|
122 | - 'zip_code' => $primary_attendee->zip(), |
|
123 | - 'country' => $primary_attendee->country_ID() |
|
124 | - ); |
|
125 | - if ($primary_attendee->address2()) { |
|
126 | - $shipping_address['apt_suite'] = $primary_attendee->address2(); |
|
127 | - } |
|
128 | - if ($primary_attendee->phone()) { |
|
129 | - $shipping_address['phone'] = $primary_attendee->phone(); |
|
130 | - } |
|
131 | - $order['shipping_address'] = $shipping_address; |
|
132 | - } |
|
133 | - $order = apply_filters( |
|
134 | - 'FHEE__EEG_Mijireh__set_redirection_info__order_arguments', |
|
135 | - $order, |
|
136 | - $payment, |
|
137 | - $primary_registrant |
|
138 | - ); |
|
139 | - do_action('AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this))); |
|
140 | - $order = $this->_get_unsupported_character_remover()->formatArray($order); |
|
64 | + $primary_attendee = $primary_registrant->attendee(); |
|
65 | + $items = array(); |
|
66 | + //if we're are charging for the full amount, show the normal line items |
|
67 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
68 | + $total_line_item = $transaction->total_line_item(); |
|
69 | + $tax_total = $total_line_item->get_total_tax(); |
|
70 | + foreach ($total_line_item->get_items() as $line_item) { |
|
71 | + $items[] = array( |
|
72 | + 'name' => apply_filters( |
|
73 | + 'FHEE__EEG_Mijireh__set_redirection_info__full_amount_line_item_name', |
|
74 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
75 | + $line_item, |
|
76 | + $payment, |
|
77 | + $primary_registrant |
|
78 | + ), |
|
79 | + 'price' => $gateway_formatter->formatCurrency($line_item->unit_price()), |
|
80 | + 'sku' => $line_item->code(), |
|
81 | + 'quantity' => $line_item->quantity() |
|
82 | + ); |
|
83 | + } |
|
84 | + } else {//its a partial payment |
|
85 | + $tax_total = 0; |
|
86 | + //partial payment, so just add 1 item |
|
87 | + $items[] = array( |
|
88 | + 'name' => apply_filters( |
|
89 | + 'FHEE__EEG_Mijireh__set_redirection_info__partial_amount_line_item_name', |
|
90 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
91 | + $payment, |
|
92 | + $primary_registrant |
|
93 | + ), |
|
94 | + 'price' => $gateway_formatter->formatCurrency($payment->amount()), |
|
95 | + 'sku' => $primary_registrant->reg_code(), |
|
96 | + 'quantity' => 1 |
|
97 | + ); |
|
98 | + } |
|
99 | + $order = array( |
|
100 | + 'total' => $gateway_formatter->formatCurrency($payment->amount()), |
|
101 | + 'return_url' => $return_url, |
|
102 | + 'items' => $this->_prepare_for_mijireh($items), |
|
103 | + 'email' => $primary_attendee->email(), |
|
104 | + 'first_name' => $primary_attendee->fname(), |
|
105 | + 'last_name' => $primary_attendee->lname(), |
|
106 | + 'tax' => $gateway_formatter->formatCurrency($tax_total), |
|
107 | + 'partner_id' => 'ee' |
|
108 | + ); |
|
109 | + //setup address? |
|
110 | + if ($primary_attendee->address() |
|
111 | + && $primary_attendee->city() |
|
112 | + && $primary_attendee->state_ID() |
|
113 | + && $primary_attendee->country_ID() |
|
114 | + && $primary_attendee->zip() |
|
115 | + ) { |
|
116 | + $shipping_address = array( |
|
117 | + 'first_name' => $primary_attendee->fname(), |
|
118 | + 'last_name' => $primary_attendee->lname(), |
|
119 | + 'street' => $primary_attendee->address(), |
|
120 | + 'city' => $primary_attendee->city(), |
|
121 | + 'state_province' => $primary_attendee->state_name(), |
|
122 | + 'zip_code' => $primary_attendee->zip(), |
|
123 | + 'country' => $primary_attendee->country_ID() |
|
124 | + ); |
|
125 | + if ($primary_attendee->address2()) { |
|
126 | + $shipping_address['apt_suite'] = $primary_attendee->address2(); |
|
127 | + } |
|
128 | + if ($primary_attendee->phone()) { |
|
129 | + $shipping_address['phone'] = $primary_attendee->phone(); |
|
130 | + } |
|
131 | + $order['shipping_address'] = $shipping_address; |
|
132 | + } |
|
133 | + $order = apply_filters( |
|
134 | + 'FHEE__EEG_Mijireh__set_redirection_info__order_arguments', |
|
135 | + $order, |
|
136 | + $payment, |
|
137 | + $primary_registrant |
|
138 | + ); |
|
139 | + do_action('AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this))); |
|
140 | + $order = $this->_get_unsupported_character_remover()->formatArray($order); |
|
141 | 141 | |
142 | - $args = array( |
|
143 | - 'headers' => array( |
|
144 | - 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
145 | - 'Accept' => 'application/json' |
|
146 | - ), |
|
147 | - 'body' => wp_json_encode($order) |
|
148 | - ); |
|
149 | - $response = wp_remote_post($this->_mijireh_api_orders_url, $args); |
|
150 | - $problems_string = false; |
|
151 | - $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment); |
|
152 | - if (! $response instanceof WP_Error) { |
|
153 | - $response_body = json_decode($response['body']); |
|
154 | - if ($response_body && isset($response_body->checkout_url)) { |
|
155 | - $payment->set_redirect_url($response_body->checkout_url); |
|
156 | - $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
157 | - $payment->set_details($response['body']); |
|
158 | - } else { |
|
159 | - if (is_array($response_body) || is_object($response_body)) { |
|
160 | - $response_body_as_array = (array)$response_body; |
|
161 | - foreach ($response_body_as_array as $problem_parameter => $problems) { |
|
162 | - $problems_string .= sprintf( |
|
163 | - __('\nProblems with %s: %s', 'event_espresso'), |
|
164 | - $problem_parameter, |
|
165 | - implode(", ", $problems) |
|
166 | - ); |
|
167 | - } |
|
168 | - } else { |
|
169 | - $problems_string = $response['body']; |
|
170 | - } |
|
171 | - if (! $problems_string) { |
|
172 | - //no message to show? wack |
|
173 | - if (isset($response['headers']['status'])) { |
|
174 | - $problems_string = $response['headers']['status']; |
|
175 | - } else { |
|
176 | - $problems_string = __('No response from Mijireh', 'event_espresso'); |
|
177 | - } |
|
178 | - } |
|
179 | - } |
|
180 | - } else { |
|
181 | - $problems_string = implode(",", $response->get_error_messages()); |
|
182 | - } |
|
183 | - if ($problems_string) { |
|
184 | - $payment->set_gateway_response( |
|
185 | - sprintf( |
|
186 | - __('Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), |
|
187 | - $problems_string |
|
188 | - ) |
|
189 | - ); |
|
190 | - $payment->set_details($response); |
|
191 | - $payment->set_redirect_url(null); |
|
192 | - //even though the payment's status is failed at this point anyways, |
|
193 | - //let's be explicit about it. The fact that the redirect url is null |
|
194 | - //should be enough to client code that they can't redirect the user |
|
195 | - $payment->set_status($this->_pay_model->failed_status()); |
|
196 | - } |
|
197 | - return $payment; |
|
198 | - } |
|
142 | + $args = array( |
|
143 | + 'headers' => array( |
|
144 | + 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
145 | + 'Accept' => 'application/json' |
|
146 | + ), |
|
147 | + 'body' => wp_json_encode($order) |
|
148 | + ); |
|
149 | + $response = wp_remote_post($this->_mijireh_api_orders_url, $args); |
|
150 | + $problems_string = false; |
|
151 | + $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment); |
|
152 | + if (! $response instanceof WP_Error) { |
|
153 | + $response_body = json_decode($response['body']); |
|
154 | + if ($response_body && isset($response_body->checkout_url)) { |
|
155 | + $payment->set_redirect_url($response_body->checkout_url); |
|
156 | + $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
157 | + $payment->set_details($response['body']); |
|
158 | + } else { |
|
159 | + if (is_array($response_body) || is_object($response_body)) { |
|
160 | + $response_body_as_array = (array)$response_body; |
|
161 | + foreach ($response_body_as_array as $problem_parameter => $problems) { |
|
162 | + $problems_string .= sprintf( |
|
163 | + __('\nProblems with %s: %s', 'event_espresso'), |
|
164 | + $problem_parameter, |
|
165 | + implode(", ", $problems) |
|
166 | + ); |
|
167 | + } |
|
168 | + } else { |
|
169 | + $problems_string = $response['body']; |
|
170 | + } |
|
171 | + if (! $problems_string) { |
|
172 | + //no message to show? wack |
|
173 | + if (isset($response['headers']['status'])) { |
|
174 | + $problems_string = $response['headers']['status']; |
|
175 | + } else { |
|
176 | + $problems_string = __('No response from Mijireh', 'event_espresso'); |
|
177 | + } |
|
178 | + } |
|
179 | + } |
|
180 | + } else { |
|
181 | + $problems_string = implode(",", $response->get_error_messages()); |
|
182 | + } |
|
183 | + if ($problems_string) { |
|
184 | + $payment->set_gateway_response( |
|
185 | + sprintf( |
|
186 | + __('Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), |
|
187 | + $problems_string |
|
188 | + ) |
|
189 | + ); |
|
190 | + $payment->set_details($response); |
|
191 | + $payment->set_redirect_url(null); |
|
192 | + //even though the payment's status is failed at this point anyways, |
|
193 | + //let's be explicit about it. The fact that the redirect url is null |
|
194 | + //should be enough to client code that they can't redirect the user |
|
195 | + $payment->set_status($this->_pay_model->failed_status()); |
|
196 | + } |
|
197 | + return $payment; |
|
198 | + } |
|
199 | 199 | |
200 | 200 | |
201 | - /** |
|
202 | - * goes through $data and ensures there are no percent signs in it |
|
203 | - * (which, strangely, kill mijireh) |
|
204 | - * |
|
205 | - * @param mixed $data |
|
206 | - * @return mixed same type as $data |
|
207 | - */ |
|
208 | - private function _prepare_for_mijireh($data) |
|
209 | - { |
|
210 | - if (is_array($data)) { |
|
211 | - $prepared_data = array(); |
|
212 | - foreach($data as $key => $datum) { |
|
213 | - $prepared_data[$key] = $this->_prepare_for_mijireh($datum); |
|
214 | - } |
|
215 | - return $prepared_data; |
|
216 | - } elseif (is_string($data)) { |
|
217 | - return str_replace('%', 'percent', $data); |
|
218 | - } else { |
|
219 | - return $data; |
|
220 | - } |
|
221 | - } |
|
201 | + /** |
|
202 | + * goes through $data and ensures there are no percent signs in it |
|
203 | + * (which, strangely, kill mijireh) |
|
204 | + * |
|
205 | + * @param mixed $data |
|
206 | + * @return mixed same type as $data |
|
207 | + */ |
|
208 | + private function _prepare_for_mijireh($data) |
|
209 | + { |
|
210 | + if (is_array($data)) { |
|
211 | + $prepared_data = array(); |
|
212 | + foreach($data as $key => $datum) { |
|
213 | + $prepared_data[$key] = $this->_prepare_for_mijireh($datum); |
|
214 | + } |
|
215 | + return $prepared_data; |
|
216 | + } elseif (is_string($data)) { |
|
217 | + return str_replace('%', 'percent', $data); |
|
218 | + } else { |
|
219 | + return $data; |
|
220 | + } |
|
221 | + } |
|
222 | 222 | |
223 | 223 | |
224 | - /** |
|
225 | - * Handles the payment update (note: mijireh doesn't send an IPN in the usual sense, |
|
226 | - * instead they just redirect the user back to our website and then we need to query them |
|
227 | - * for the payment's status). Also note that the $update_info should be an array with the key |
|
228 | - * 'payment' containing the EEI_Payment to update |
|
229 | - * |
|
230 | - * @param array $update_info unused. We just use the $transaction |
|
231 | - * @param EEI_Transaction $transaction |
|
232 | - * @return \EEI_Payment |
|
233 | - * @throws EE_Error |
|
234 | - */ |
|
235 | - public function handle_payment_update($update_info, $transaction) |
|
236 | - { |
|
237 | - foreach($transaction->pending_payments() as $payment) { |
|
238 | - $payment = $this->check_payment_in_mijireh($payment); |
|
239 | - if ($payment->status() === $this->_pay_model->approved_status()) { |
|
240 | - return $payment; |
|
241 | - } |
|
242 | - } |
|
243 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
|
224 | + /** |
|
225 | + * Handles the payment update (note: mijireh doesn't send an IPN in the usual sense, |
|
226 | + * instead they just redirect the user back to our website and then we need to query them |
|
227 | + * for the payment's status). Also note that the $update_info should be an array with the key |
|
228 | + * 'payment' containing the EEI_Payment to update |
|
229 | + * |
|
230 | + * @param array $update_info unused. We just use the $transaction |
|
231 | + * @param EEI_Transaction $transaction |
|
232 | + * @return \EEI_Payment |
|
233 | + * @throws EE_Error |
|
234 | + */ |
|
235 | + public function handle_payment_update($update_info, $transaction) |
|
236 | + { |
|
237 | + foreach($transaction->pending_payments() as $payment) { |
|
238 | + $payment = $this->check_payment_in_mijireh($payment); |
|
239 | + if ($payment->status() === $this->_pay_model->approved_status()) { |
|
240 | + return $payment; |
|
241 | + } |
|
242 | + } |
|
243 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
|
244 | 244 | |
245 | - if (! $payment instanceof EEI_Payment) { |
|
246 | - throw new EE_Error( |
|
247 | - sprintf( |
|
248 | - __("Could not find Mijireh payment for transaction %s", 'event_espresso'), |
|
249 | - $transaction->ID() |
|
250 | - ) |
|
251 | - ); |
|
252 | - } |
|
253 | - return $payment; |
|
254 | - } |
|
245 | + if (! $payment instanceof EEI_Payment) { |
|
246 | + throw new EE_Error( |
|
247 | + sprintf( |
|
248 | + __("Could not find Mijireh payment for transaction %s", 'event_espresso'), |
|
249 | + $transaction->ID() |
|
250 | + ) |
|
251 | + ); |
|
252 | + } |
|
253 | + return $payment; |
|
254 | + } |
|
255 | 255 | |
256 | 256 | |
257 | - /** |
|
258 | - * Checks the payment's status in Mijireh for this specific payment |
|
259 | - * |
|
260 | - * @param \EEI_Payment $payment |
|
261 | - * @return \EEI_Payment |
|
262 | - */ |
|
263 | - public function check_payment_in_mijireh(EEI_Payment $payment) |
|
264 | - { |
|
265 | - $request_args = array( |
|
266 | - 'headers' => array( |
|
267 | - 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
268 | - 'Accept' => 'application/json' |
|
269 | - ) |
|
270 | - ); |
|
257 | + /** |
|
258 | + * Checks the payment's status in Mijireh for this specific payment |
|
259 | + * |
|
260 | + * @param \EEI_Payment $payment |
|
261 | + * @return \EEI_Payment |
|
262 | + */ |
|
263 | + public function check_payment_in_mijireh(EEI_Payment $payment) |
|
264 | + { |
|
265 | + $request_args = array( |
|
266 | + 'headers' => array( |
|
267 | + 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
268 | + 'Accept' => 'application/json' |
|
269 | + ) |
|
270 | + ); |
|
271 | 271 | |
272 | - $response = wp_remote_get( |
|
273 | - $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
274 | - $request_args |
|
275 | - ); |
|
272 | + $response = wp_remote_get( |
|
273 | + $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
274 | + $request_args |
|
275 | + ); |
|
276 | 276 | |
277 | - $this->log( |
|
278 | - array('get payment status request_args' => $request_args, 'response' => $response), |
|
279 | - $payment |
|
280 | - ); |
|
281 | - // validate response |
|
282 | - $response_body = isset($response['body']) ? json_decode($response['body']) : ''; |
|
283 | - if ($response && $response_body) { |
|
284 | - switch($response_body->status) { |
|
285 | - case 'paid': |
|
286 | - $payment->set_status($this->_pay_model->approved_status()); |
|
287 | - break; |
|
288 | - case 'pending': |
|
289 | - $payment->set_status($this->_pay_model->pending_status()); |
|
290 | - break; |
|
291 | - default: |
|
292 | - $payment->set_status($this->_pay_model->declined_status()); |
|
293 | - } |
|
294 | - } else { |
|
295 | - $payment->set_gateway_response(__('Response from Mijireh could not be understood.', 'event_espresso')); |
|
296 | - $payment->set_details($response); |
|
297 | - $payment->set_status($this->_pay_model->failed_status()); |
|
298 | - } |
|
299 | - // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
|
277 | + $this->log( |
|
278 | + array('get payment status request_args' => $request_args, 'response' => $response), |
|
279 | + $payment |
|
280 | + ); |
|
281 | + // validate response |
|
282 | + $response_body = isset($response['body']) ? json_decode($response['body']) : ''; |
|
283 | + if ($response && $response_body) { |
|
284 | + switch($response_body->status) { |
|
285 | + case 'paid': |
|
286 | + $payment->set_status($this->_pay_model->approved_status()); |
|
287 | + break; |
|
288 | + case 'pending': |
|
289 | + $payment->set_status($this->_pay_model->pending_status()); |
|
290 | + break; |
|
291 | + default: |
|
292 | + $payment->set_status($this->_pay_model->declined_status()); |
|
293 | + } |
|
294 | + } else { |
|
295 | + $payment->set_gateway_response(__('Response from Mijireh could not be understood.', 'event_espresso')); |
|
296 | + $payment->set_details($response); |
|
297 | + $payment->set_status($this->_pay_model->failed_status()); |
|
298 | + } |
|
299 | + // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
|
300 | 300 | // $payment->set_status( $this->_pay_model->pending_status() ); |
301 | - return $payment; |
|
302 | - } |
|
301 | + return $payment; |
|
302 | + } |
|
303 | 303 | |
304 | 304 | } |
305 | 305 | // End of file EEG_Mijireh.gateway.php |
306 | 306 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | $args = array( |
143 | 143 | 'headers' => array( |
144 | - 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
144 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
145 | 145 | 'Accept' => 'application/json' |
146 | 146 | ), |
147 | 147 | 'body' => wp_json_encode($order) |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $response = wp_remote_post($this->_mijireh_api_orders_url, $args); |
150 | 150 | $problems_string = false; |
151 | 151 | $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment); |
152 | - if (! $response instanceof WP_Error) { |
|
152 | + if ( ! $response instanceof WP_Error) { |
|
153 | 153 | $response_body = json_decode($response['body']); |
154 | 154 | if ($response_body && isset($response_body->checkout_url)) { |
155 | 155 | $payment->set_redirect_url($response_body->checkout_url); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $payment->set_details($response['body']); |
158 | 158 | } else { |
159 | 159 | if (is_array($response_body) || is_object($response_body)) { |
160 | - $response_body_as_array = (array)$response_body; |
|
160 | + $response_body_as_array = (array) $response_body; |
|
161 | 161 | foreach ($response_body_as_array as $problem_parameter => $problems) { |
162 | 162 | $problems_string .= sprintf( |
163 | 163 | __('\nProblems with %s: %s', 'event_espresso'), |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | } else { |
169 | 169 | $problems_string = $response['body']; |
170 | 170 | } |
171 | - if (! $problems_string) { |
|
171 | + if ( ! $problems_string) { |
|
172 | 172 | //no message to show? wack |
173 | 173 | if (isset($response['headers']['status'])) { |
174 | 174 | $problems_string = $response['headers']['status']; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | { |
210 | 210 | if (is_array($data)) { |
211 | 211 | $prepared_data = array(); |
212 | - foreach($data as $key => $datum) { |
|
212 | + foreach ($data as $key => $datum) { |
|
213 | 213 | $prepared_data[$key] = $this->_prepare_for_mijireh($datum); |
214 | 214 | } |
215 | 215 | return $prepared_data; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | */ |
235 | 235 | public function handle_payment_update($update_info, $transaction) |
236 | 236 | { |
237 | - foreach($transaction->pending_payments() as $payment) { |
|
237 | + foreach ($transaction->pending_payments() as $payment) { |
|
238 | 238 | $payment = $this->check_payment_in_mijireh($payment); |
239 | 239 | if ($payment->status() === $this->_pay_model->approved_status()) { |
240 | 240 | return $payment; |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | } |
243 | 243 | $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
244 | 244 | |
245 | - if (! $payment instanceof EEI_Payment) { |
|
245 | + if ( ! $payment instanceof EEI_Payment) { |
|
246 | 246 | throw new EE_Error( |
247 | 247 | sprintf( |
248 | 248 | __("Could not find Mijireh payment for transaction %s", 'event_espresso'), |
@@ -264,13 +264,13 @@ discard block |
||
264 | 264 | { |
265 | 265 | $request_args = array( |
266 | 266 | 'headers' => array( |
267 | - 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
267 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
268 | 268 | 'Accept' => 'application/json' |
269 | 269 | ) |
270 | 270 | ); |
271 | 271 | |
272 | 272 | $response = wp_remote_get( |
273 | - $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
273 | + $this->_mijireh_api_orders_url.'/'.$payment->txn_id_chq_nmbr(), |
|
274 | 274 | $request_args |
275 | 275 | ); |
276 | 276 | |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | // validate response |
282 | 282 | $response_body = isset($response['body']) ? json_decode($response['body']) : ''; |
283 | 283 | if ($response && $response_body) { |
284 | - switch($response_body->status) { |
|
284 | + switch ($response_body->status) { |
|
285 | 285 | case 'paid': |
286 | 286 | $payment->set_status($this->_pay_model->approved_status()); |
287 | 287 | break; |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\IpnException; |
4 | 4 | |
5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('NO direct script access allowed'); |
|
6 | + exit('NO direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | |
@@ -25,607 +25,607 @@ discard block |
||
25 | 25 | class EEG_Paypal_Standard extends EE_Offsite_Gateway |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Name for the wp option used to save the itemized payment |
|
30 | - */ |
|
31 | - const itemized_payment_option_name = '_itemized_payment'; |
|
32 | - |
|
33 | - protected $_paypal_id; |
|
34 | - |
|
35 | - protected $_image_url; |
|
36 | - |
|
37 | - protected $_shipping_details; |
|
38 | - |
|
39 | - protected $_paypal_shipping; |
|
40 | - |
|
41 | - protected $_paypal_taxes; |
|
42 | - |
|
43 | - protected $_gateway_url; |
|
44 | - |
|
45 | - protected $_currencies_supported = array( |
|
46 | - 'USD', |
|
47 | - 'GBP', |
|
48 | - 'CAD', |
|
49 | - 'AUD', |
|
50 | - 'BRL', |
|
51 | - 'CHF', |
|
52 | - 'CZK', |
|
53 | - 'DKK', |
|
54 | - 'EUR', |
|
55 | - 'HKD', |
|
56 | - 'HUF', |
|
57 | - 'ILS', |
|
58 | - 'JPY', |
|
59 | - 'MXN', |
|
60 | - 'MYR', |
|
61 | - 'NOK', |
|
62 | - 'NZD', |
|
63 | - 'PHP', |
|
64 | - 'PLN', |
|
65 | - 'SEK', |
|
66 | - 'SGD', |
|
67 | - 'THB', |
|
68 | - 'TRY', |
|
69 | - 'TWD', |
|
70 | - 'RUB' |
|
71 | - ); |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * EEG_Paypal_Standard constructor. |
|
76 | - * |
|
77 | - * @return EEG_Paypal_Standard |
|
78 | - */ |
|
79 | - public function __construct() |
|
80 | - { |
|
81 | - $this->set_uses_separate_IPN_request(true); |
|
82 | - parent::__construct(); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Also sets the gateway url class variable based on whether debug mode is enabled or not. |
|
88 | - * |
|
89 | - * @param array $settings_array |
|
90 | - */ |
|
91 | - public function set_settings($settings_array) |
|
92 | - { |
|
93 | - parent::set_settings($settings_array); |
|
94 | - $this->_gateway_url = $this->_debug_mode |
|
95 | - ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' |
|
96 | - : 'https://www.paypal.com/cgi-bin/webscr'; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @param EEI_Payment $payment the payment to process |
|
102 | - * @param array $billing_info but should be empty for this gateway |
|
103 | - * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
104 | - * @param string $notify_url URL to send the instant payment notification |
|
105 | - * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
106 | - * on the payment provider's website |
|
107 | - * @return EEI_Payment |
|
108 | - * @throws \EE_Error |
|
109 | - */ |
|
110 | - public function set_redirection_info( |
|
111 | - $payment, |
|
112 | - $billing_info = array(), |
|
113 | - $return_url = null, |
|
114 | - $notify_url = null, |
|
115 | - $cancel_url = null |
|
116 | - ) { |
|
117 | - $redirect_args = array(); |
|
118 | - $transaction = $payment->transaction(); |
|
119 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
120 | - $item_num = 1; |
|
121 | - /** @type EE_Line_Item $total_line_item */ |
|
122 | - $total_line_item = $transaction->total_line_item(); |
|
123 | - |
|
124 | - $total_discounts_to_cart_total = $transaction->paid(); |
|
125 | - //only itemize the order if we're paying for the rest of the order's amount |
|
126 | - if (EEH_Money::compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
127 | - $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
128 | - //this payment is for the remaining transaction amount, |
|
129 | - //keep track of exactly how much the itemized order amount equals |
|
130 | - $itemized_sum = 0; |
|
131 | - $shipping_previously_added = 0; |
|
132 | - //so let's show all the line items |
|
133 | - foreach ($total_line_item->get_items() as $line_item) { |
|
134 | - if ($line_item instanceof EE_Line_Item) { |
|
135 | - //it's some kind of discount |
|
136 | - if ($line_item->total() < 0) { |
|
137 | - $total_discounts_to_cart_total += abs($line_item->total()); |
|
138 | - $itemized_sum += $line_item->total(); |
|
139 | - continue; |
|
140 | - } |
|
141 | - //dont include shipping again. |
|
142 | - if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
143 | - $shipping_previously_added = $line_item->total(); |
|
144 | - continue; |
|
145 | - } |
|
146 | - $redirect_args['item_name_' . $item_num] = substr( |
|
147 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
148 | - 0, 127 |
|
149 | - ); |
|
150 | - $redirect_args['amount_' . $item_num] = $line_item->unit_price(); |
|
151 | - $redirect_args['quantity_' . $item_num] = $line_item->quantity(); |
|
152 | - //if we're not letting PayPal calculate shipping, tell them its 0 |
|
153 | - if (! $this->_paypal_shipping) { |
|
154 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
155 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
156 | - } |
|
157 | - $item_num++; |
|
158 | - $itemized_sum += $line_item->total(); |
|
159 | - } |
|
160 | - } |
|
161 | - $taxes_li = $this->_line_item->get_taxes_subtotal($total_line_item); |
|
162 | - //ideally itemized sum equals the transaction total. but if not (which is weird) |
|
163 | - //and the itemized sum is LESS than the transaction total |
|
164 | - //add another line item |
|
165 | - //if the itemized sum is MORE than the transaction total, |
|
166 | - //add the difference it to the discounts |
|
167 | - $itemized_sum_diff_from_txn_total = round( |
|
168 | - $transaction->total() - $itemized_sum - $taxes_li->total() - $shipping_previously_added, |
|
169 | - 2 |
|
170 | - ); |
|
171 | - if ($itemized_sum_diff_from_txn_total < 0) { |
|
172 | - //itemized sum is too big |
|
173 | - $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
|
174 | - } elseif ($itemized_sum_diff_from_txn_total > 0) { |
|
175 | - $redirect_args['item_name_' . $item_num] = substr( |
|
176 | - __('Other charges', 'event_espresso' ), 0, 127); |
|
177 | - $redirect_args['amount_' . $item_num] = $gateway_formatter->formatCurrency( |
|
178 | - $itemized_sum_diff_from_txn_total |
|
179 | - ); |
|
180 | - $redirect_args['quantity_' . $item_num] = 1; |
|
181 | - $item_num++; |
|
182 | - } |
|
183 | - if ($total_discounts_to_cart_total > 0) { |
|
184 | - $redirect_args['discount_amount_cart'] = $gateway_formatter->formatCurrency( |
|
185 | - $total_discounts_to_cart_total |
|
186 | - ); |
|
187 | - } |
|
188 | - //add our taxes to the order if we're NOT using PayPal's |
|
189 | - if (! $this->_paypal_taxes) { |
|
190 | - $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
|
191 | - } |
|
192 | - } else { |
|
193 | - $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
194 | - //partial payment that's not for the remaining amount, so we can't send an itemized list |
|
195 | - $redirect_args['item_name_' . $item_num] = substr( |
|
196 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
197 | - 0, |
|
198 | - 127 |
|
199 | - ); |
|
200 | - $redirect_args['amount_' . $item_num] = $payment->amount(); |
|
201 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
202 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
203 | - $redirect_args['tax_cart'] = '0'; |
|
204 | - $item_num++; |
|
205 | - } |
|
206 | - |
|
207 | - if ($this->_debug_mode) { |
|
208 | - $redirect_args['item_name_' . $item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | - $redirect_args['amount_' . $item_num] = 0; |
|
210 | - $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
|
211 | - $redirect_args['os0_' . $item_num] = $notify_url; |
|
212 | - $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
|
213 | - $redirect_args['os1_' . $item_num] = $return_url; |
|
28 | + /** |
|
29 | + * Name for the wp option used to save the itemized payment |
|
30 | + */ |
|
31 | + const itemized_payment_option_name = '_itemized_payment'; |
|
32 | + |
|
33 | + protected $_paypal_id; |
|
34 | + |
|
35 | + protected $_image_url; |
|
36 | + |
|
37 | + protected $_shipping_details; |
|
38 | + |
|
39 | + protected $_paypal_shipping; |
|
40 | + |
|
41 | + protected $_paypal_taxes; |
|
42 | + |
|
43 | + protected $_gateway_url; |
|
44 | + |
|
45 | + protected $_currencies_supported = array( |
|
46 | + 'USD', |
|
47 | + 'GBP', |
|
48 | + 'CAD', |
|
49 | + 'AUD', |
|
50 | + 'BRL', |
|
51 | + 'CHF', |
|
52 | + 'CZK', |
|
53 | + 'DKK', |
|
54 | + 'EUR', |
|
55 | + 'HKD', |
|
56 | + 'HUF', |
|
57 | + 'ILS', |
|
58 | + 'JPY', |
|
59 | + 'MXN', |
|
60 | + 'MYR', |
|
61 | + 'NOK', |
|
62 | + 'NZD', |
|
63 | + 'PHP', |
|
64 | + 'PLN', |
|
65 | + 'SEK', |
|
66 | + 'SGD', |
|
67 | + 'THB', |
|
68 | + 'TRY', |
|
69 | + 'TWD', |
|
70 | + 'RUB' |
|
71 | + ); |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * EEG_Paypal_Standard constructor. |
|
76 | + * |
|
77 | + * @return EEG_Paypal_Standard |
|
78 | + */ |
|
79 | + public function __construct() |
|
80 | + { |
|
81 | + $this->set_uses_separate_IPN_request(true); |
|
82 | + parent::__construct(); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Also sets the gateway url class variable based on whether debug mode is enabled or not. |
|
88 | + * |
|
89 | + * @param array $settings_array |
|
90 | + */ |
|
91 | + public function set_settings($settings_array) |
|
92 | + { |
|
93 | + parent::set_settings($settings_array); |
|
94 | + $this->_gateway_url = $this->_debug_mode |
|
95 | + ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' |
|
96 | + : 'https://www.paypal.com/cgi-bin/webscr'; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @param EEI_Payment $payment the payment to process |
|
102 | + * @param array $billing_info but should be empty for this gateway |
|
103 | + * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
104 | + * @param string $notify_url URL to send the instant payment notification |
|
105 | + * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
106 | + * on the payment provider's website |
|
107 | + * @return EEI_Payment |
|
108 | + * @throws \EE_Error |
|
109 | + */ |
|
110 | + public function set_redirection_info( |
|
111 | + $payment, |
|
112 | + $billing_info = array(), |
|
113 | + $return_url = null, |
|
114 | + $notify_url = null, |
|
115 | + $cancel_url = null |
|
116 | + ) { |
|
117 | + $redirect_args = array(); |
|
118 | + $transaction = $payment->transaction(); |
|
119 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
120 | + $item_num = 1; |
|
121 | + /** @type EE_Line_Item $total_line_item */ |
|
122 | + $total_line_item = $transaction->total_line_item(); |
|
123 | + |
|
124 | + $total_discounts_to_cart_total = $transaction->paid(); |
|
125 | + //only itemize the order if we're paying for the rest of the order's amount |
|
126 | + if (EEH_Money::compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
127 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
128 | + //this payment is for the remaining transaction amount, |
|
129 | + //keep track of exactly how much the itemized order amount equals |
|
130 | + $itemized_sum = 0; |
|
131 | + $shipping_previously_added = 0; |
|
132 | + //so let's show all the line items |
|
133 | + foreach ($total_line_item->get_items() as $line_item) { |
|
134 | + if ($line_item instanceof EE_Line_Item) { |
|
135 | + //it's some kind of discount |
|
136 | + if ($line_item->total() < 0) { |
|
137 | + $total_discounts_to_cart_total += abs($line_item->total()); |
|
138 | + $itemized_sum += $line_item->total(); |
|
139 | + continue; |
|
140 | + } |
|
141 | + //dont include shipping again. |
|
142 | + if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
143 | + $shipping_previously_added = $line_item->total(); |
|
144 | + continue; |
|
145 | + } |
|
146 | + $redirect_args['item_name_' . $item_num] = substr( |
|
147 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
148 | + 0, 127 |
|
149 | + ); |
|
150 | + $redirect_args['amount_' . $item_num] = $line_item->unit_price(); |
|
151 | + $redirect_args['quantity_' . $item_num] = $line_item->quantity(); |
|
152 | + //if we're not letting PayPal calculate shipping, tell them its 0 |
|
153 | + if (! $this->_paypal_shipping) { |
|
154 | + $redirect_args['shipping_' . $item_num] = '0'; |
|
155 | + $redirect_args['shipping2_' . $item_num] = '0'; |
|
156 | + } |
|
157 | + $item_num++; |
|
158 | + $itemized_sum += $line_item->total(); |
|
159 | + } |
|
160 | + } |
|
161 | + $taxes_li = $this->_line_item->get_taxes_subtotal($total_line_item); |
|
162 | + //ideally itemized sum equals the transaction total. but if not (which is weird) |
|
163 | + //and the itemized sum is LESS than the transaction total |
|
164 | + //add another line item |
|
165 | + //if the itemized sum is MORE than the transaction total, |
|
166 | + //add the difference it to the discounts |
|
167 | + $itemized_sum_diff_from_txn_total = round( |
|
168 | + $transaction->total() - $itemized_sum - $taxes_li->total() - $shipping_previously_added, |
|
169 | + 2 |
|
170 | + ); |
|
171 | + if ($itemized_sum_diff_from_txn_total < 0) { |
|
172 | + //itemized sum is too big |
|
173 | + $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
|
174 | + } elseif ($itemized_sum_diff_from_txn_total > 0) { |
|
175 | + $redirect_args['item_name_' . $item_num] = substr( |
|
176 | + __('Other charges', 'event_espresso' ), 0, 127); |
|
177 | + $redirect_args['amount_' . $item_num] = $gateway_formatter->formatCurrency( |
|
178 | + $itemized_sum_diff_from_txn_total |
|
179 | + ); |
|
180 | + $redirect_args['quantity_' . $item_num] = 1; |
|
181 | + $item_num++; |
|
182 | + } |
|
183 | + if ($total_discounts_to_cart_total > 0) { |
|
184 | + $redirect_args['discount_amount_cart'] = $gateway_formatter->formatCurrency( |
|
185 | + $total_discounts_to_cart_total |
|
186 | + ); |
|
187 | + } |
|
188 | + //add our taxes to the order if we're NOT using PayPal's |
|
189 | + if (! $this->_paypal_taxes) { |
|
190 | + $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
|
191 | + } |
|
192 | + } else { |
|
193 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
194 | + //partial payment that's not for the remaining amount, so we can't send an itemized list |
|
195 | + $redirect_args['item_name_' . $item_num] = substr( |
|
196 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
197 | + 0, |
|
198 | + 127 |
|
199 | + ); |
|
200 | + $redirect_args['amount_' . $item_num] = $payment->amount(); |
|
201 | + $redirect_args['shipping_' . $item_num] = '0'; |
|
202 | + $redirect_args['shipping2_' . $item_num] = '0'; |
|
203 | + $redirect_args['tax_cart'] = '0'; |
|
204 | + $item_num++; |
|
205 | + } |
|
206 | + |
|
207 | + if ($this->_debug_mode) { |
|
208 | + $redirect_args['item_name_' . $item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | + $redirect_args['amount_' . $item_num] = 0; |
|
210 | + $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
|
211 | + $redirect_args['os0_' . $item_num] = $notify_url; |
|
212 | + $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
|
213 | + $redirect_args['os1_' . $item_num] = $return_url; |
|
214 | 214 | // $redirect_args['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
215 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
216 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
217 | - } |
|
218 | - |
|
219 | - $redirect_args['business'] = $this->_paypal_id; |
|
220 | - $redirect_args['return'] = $return_url; |
|
221 | - $redirect_args['cancel_return'] = $cancel_url; |
|
222 | - $redirect_args['notify_url'] = $notify_url; |
|
223 | - $redirect_args['cmd'] = '_cart'; |
|
224 | - $redirect_args['upload'] = 1; |
|
225 | - $redirect_args['currency_code'] = $payment->currency_code(); |
|
226 | - $redirect_args['rm'] = 2;//makes the user return with method=POST |
|
227 | - if ($this->_image_url) { |
|
228 | - $redirect_args['image_url'] = $this->_image_url; |
|
229 | - } |
|
230 | - $redirect_args['no_shipping'] = $this->_shipping_details; |
|
231 | - $redirect_args['bn'] = 'EventEspresso_SP';//EE will blow up if you change this |
|
232 | - |
|
233 | - $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
|
234 | - |
|
235 | - $payment->set_redirect_url($this->_gateway_url); |
|
236 | - $payment->set_redirect_args($redirect_args); |
|
237 | - // log the results |
|
238 | - $this->log( |
|
239 | - array( |
|
240 | - 'message' => sprintf( |
|
241 | - __('PayPal payment request initiated.', 'event_espresso') |
|
242 | - ), |
|
243 | - 'transaction' => $transaction->model_field_array(), |
|
244 | - ), |
|
245 | - $payment |
|
246 | - ); |
|
247 | - return $payment; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Often used for IPNs. But applies the info in $update_info to the payment. |
|
253 | - * What is $update_info? Often the contents of $_REQUEST, but not necessarily. Whatever |
|
254 | - * the payment method passes in. |
|
255 | - * |
|
256 | - * @param array $update_info like $_POST |
|
257 | - * @param EEI_Transaction $transaction |
|
258 | - * @return \EEI_Payment updated |
|
259 | - * @throws \EE_Error, IpnException |
|
260 | - */ |
|
261 | - public function handle_payment_update($update_info, $transaction) |
|
262 | - { |
|
263 | - // verify there's payment data that's been sent |
|
264 | - if (empty($update_info['payment_status'] ) || empty($update_info['txn_id'])) { |
|
265 | - // log the results |
|
266 | - $this->log( |
|
267 | - array( |
|
268 | - 'message' => sprintf( |
|
269 | - // @codingStandardsIgnoreStart |
|
270 | - __('PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', 'event_espresso') |
|
271 | - // @codingStandardsIgnoreEnd |
|
272 | - ), |
|
273 | - 'update_info' => $update_info, |
|
274 | - ), |
|
275 | - $transaction |
|
276 | - ); |
|
277 | - // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
|
278 | - // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
|
279 | - if (isset($update_info['tx'])) { |
|
280 | - return $transaction->last_payment(); |
|
281 | - } else { |
|
282 | - return null; |
|
283 | - } |
|
284 | - } |
|
285 | - $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
286 | - if (! $payment instanceof EEI_Payment) { |
|
287 | - $payment = $transaction->last_payment(); |
|
288 | - } |
|
289 | - // ok, then validate the IPN. Even if we've already processed this payment, |
|
290 | - // let PayPal know we don't want to hear from them anymore! |
|
291 | - if (! $this->validate_ipn($update_info, $payment)) { |
|
292 | - return $payment; |
|
293 | - } |
|
294 | - // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
|
295 | - // registrations, ticket counts, etc) |
|
296 | - if ( |
|
297 | - ( |
|
298 | - $update_info['payment_status'] === 'Refunded' |
|
299 | - || $update_info['payment_status'] === 'Partially_Refunded' |
|
300 | - ) |
|
301 | - && apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true) |
|
302 | - ) { |
|
303 | - throw new EventEspresso\core\exceptions\IpnException( |
|
304 | - sprintf( |
|
305 | - esc_html__('Event Espresso does not yet support %1$s IPNs from PayPal', 'event_espresso'), |
|
306 | - $update_info['payment_status'] |
|
307 | - ), |
|
308 | - EventEspresso\core\exceptions\IpnException::UNSUPPORTED, |
|
309 | - null, |
|
310 | - $payment, |
|
311 | - $update_info |
|
312 | - ); |
|
313 | - } |
|
314 | - //ok, well let's process this payment then! |
|
315 | - switch ($update_info['payment_status']) { |
|
316 | - |
|
317 | - case 'Completed' : |
|
318 | - $status = $this->_pay_model->approved_status(); |
|
319 | - $gateway_response = esc_html__('The payment is approved.', 'event_espresso'); |
|
320 | - break; |
|
321 | - |
|
322 | - case 'Pending' : |
|
323 | - $status = $this->_pay_model->pending_status(); |
|
324 | - $gateway_response = esc_html__( |
|
325 | - 'The payment is in progress. Another message will be sent when payment is approved.', |
|
326 | - 'event_espresso' |
|
327 | - ); |
|
328 | - break; |
|
329 | - |
|
330 | - case 'Denied' : |
|
331 | - $status = $this->_pay_model->declined_status(); |
|
332 | - $gateway_response = esc_html__('The payment has been declined.', 'event_espresso'); |
|
333 | - break; |
|
334 | - |
|
335 | - case 'Expired' : |
|
336 | - case 'Failed' : |
|
337 | - $status = $this->_pay_model->failed_status(); |
|
338 | - $gateway_response = esc_html__('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
339 | - break; |
|
340 | - |
|
341 | - case 'Refunded' : |
|
342 | - case 'Partially_Refunded' : |
|
343 | - // even though it's a refund, we consider the payment as approved, it just has a negative value |
|
344 | - $status = $this->_pay_model->approved_status(); |
|
345 | - $gateway_response = esc_html__( |
|
346 | - 'The payment has been refunded. Please update registrations accordingly.', |
|
347 | - 'event_espresso' |
|
348 | - ); |
|
349 | - break; |
|
350 | - |
|
351 | - case 'Voided' : |
|
352 | - case 'Reversed' : |
|
353 | - case 'Canceled_Reversal' : |
|
354 | - default : |
|
355 | - $status = $this->_pay_model->cancelled_status(); |
|
356 | - $gateway_response = esc_html__( |
|
357 | - 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', |
|
358 | - 'event_espresso' |
|
359 | - ); |
|
360 | - break; |
|
361 | - |
|
362 | - } |
|
363 | - |
|
364 | - //check if we've already processed this payment |
|
365 | - if ($payment instanceof EEI_Payment) { |
|
366 | - //payment exists. if this has the exact same status and amount, don't bother updating. just return |
|
367 | - if ($payment->status() === $status && (float)$payment->amount() === (float)$update_info['mc_gross']) { |
|
368 | - // DUPLICATED IPN! don't bother updating transaction |
|
369 | - throw new IpnException( |
|
370 | - sprintf( |
|
371 | - esc_html__('It appears we have received a duplicate IPN from PayPal for payment %d', |
|
372 | - 'event_espresso' |
|
373 | - ), |
|
374 | - $payment->ID() |
|
375 | - ), |
|
376 | - IpnException::DUPLICATE, |
|
377 | - null, |
|
378 | - $payment, |
|
379 | - $update_info |
|
380 | - ); |
|
381 | - } else { |
|
382 | - // new payment yippee !!! |
|
383 | - $payment->set_status($status); |
|
384 | - $payment->set_amount((float)$update_info['mc_gross']); |
|
385 | - $payment->set_gateway_response($gateway_response); |
|
386 | - $payment->set_details($update_info); |
|
387 | - $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
388 | - $this->log( |
|
389 | - array( |
|
390 | - 'message' => esc_html__( |
|
391 | - 'Updated payment either from IPN or as part of POST from PayPal', |
|
392 | - 'event_espresso' |
|
393 | - ), |
|
394 | - 'url' => $this->_process_response_url(), |
|
395 | - 'payment' => $payment->model_field_array(), |
|
396 | - 'IPN_data' => $update_info |
|
397 | - ), |
|
398 | - $payment |
|
399 | - ); |
|
400 | - } |
|
401 | - |
|
402 | - } |
|
403 | - do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
404 | - return $payment; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Validate the IPN notification. |
|
410 | - * |
|
411 | - * @param array $update_info like $_REQUEST |
|
412 | - * @param EE_Payment|EEI_Payment $payment |
|
413 | - * @return boolean |
|
414 | - * @throws \EE_Error |
|
415 | - */ |
|
416 | - public function validate_ipn($update_info, $payment) |
|
417 | - { |
|
418 | - //allow us to skip validating IPNs with PayPal (useful for testing) |
|
419 | - if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
420 | - return true; |
|
421 | - } |
|
422 | - //...otherwise, we actually don't care what the $update_info is, we need to look |
|
423 | - //at the request directly because we can't use $update_info because it has issues with quotes |
|
424 | - // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
|
425 | - // Instead, read raw POST data from the input stream. |
|
426 | - // @see https://gist.github.com/xcommerce-gists/3440401 |
|
427 | - $raw_post_data = file_get_contents('php://input'); |
|
428 | - $raw_post_array = explode('&', $raw_post_data); |
|
429 | - $update_info = array(); |
|
430 | - foreach ($raw_post_array as $keyval) { |
|
431 | - $keyval = explode('=', $keyval); |
|
432 | - if (count($keyval) === 2) { |
|
433 | - $update_info[$keyval[0]] = urldecode($keyval[1]); |
|
434 | - } |
|
435 | - } |
|
436 | - // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
|
437 | - $req = 'cmd=_notify-validate'; |
|
438 | - $uses_get_magic_quotes = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1 |
|
439 | - ? true |
|
440 | - : false; |
|
441 | - foreach ($update_info as $key => $value) { |
|
442 | - $value = $uses_get_magic_quotes ? urlencode(stripslashes($value)) : urlencode($value); |
|
443 | - $req .= "&$key=$value"; |
|
444 | - } |
|
445 | - // HTTP POST the complete, unaltered IPN back to PayPal |
|
446 | - $response = wp_remote_post( |
|
447 | - $this->_gateway_url, |
|
448 | - array( |
|
449 | - 'body' => $req, |
|
450 | - 'sslverify' => false, |
|
451 | - 'timeout' => 60, |
|
452 | - // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
|
453 | - // plz see: https://github.com/websharks/s2member/issues/610 |
|
454 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
455 | - 'httpversion' => '1.1' |
|
456 | - ) |
|
457 | - ); |
|
458 | - // then check the response |
|
459 | - if ( |
|
460 | - array_key_exists('body', $response) |
|
461 | - && ! is_wp_error($response) |
|
462 | - && strcmp($response['body'], "VERIFIED") === 0 |
|
463 | - ) { |
|
464 | - return true; |
|
465 | - } |
|
466 | - // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
|
467 | - // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
|
468 | - if ($response instanceof WP_Error) { |
|
469 | - $error_msg = sprintf( |
|
470 | - esc_html__('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
471 | - $response->get_error_code(), |
|
472 | - $response->get_error_message(), |
|
473 | - print_r($response->get_error_data(), true) |
|
474 | - ); |
|
475 | - } elseif(is_array($response) && isset($response['body'])) { |
|
476 | - $error_msg = $response['body']; |
|
477 | - } else { |
|
478 | - $error_msg = print_r($response, true); |
|
479 | - } |
|
480 | - $payment->set_gateway_response( |
|
481 | - sprintf( |
|
482 | - esc_html__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), |
|
483 | - $error_msg |
|
484 | - ) |
|
485 | - ); |
|
486 | - $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
487 | - $payment->set_status(EEM_Payment::status_id_failed); |
|
488 | - // log the results |
|
489 | - $this->log( |
|
490 | - array( |
|
491 | - 'url' => $this->_process_response_url(), |
|
492 | - 'message' => $payment->gateway_response(), |
|
493 | - 'details' => $payment->details(), |
|
494 | - ), |
|
495 | - $payment |
|
496 | - ); |
|
497 | - return false; |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * _process_response_url |
|
503 | - * @return string |
|
504 | - */ |
|
505 | - protected function _process_response_url() |
|
506 | - { |
|
507 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
508 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
509 | - $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
510 | - $url .= EEH_URL::filter_input_server_url(); |
|
511 | - } else { |
|
512 | - $url = 'unknown'; |
|
513 | - } |
|
514 | - return $url; |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * Updates the transaction and line items based on the payment IPN data from PayPal, |
|
520 | - * like the taxes or shipping |
|
521 | - * |
|
522 | - * @param EEI_Payment $payment |
|
523 | - * @throws \EE_Error |
|
524 | - */ |
|
525 | - public function update_txn_based_on_payment($payment) |
|
526 | - { |
|
527 | - $update_info = $payment->details(); |
|
528 | - /** @var EE_Transaction $transaction */ |
|
529 | - $transaction = $payment->transaction(); |
|
530 | - $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
531 | - if (! $transaction) { |
|
532 | - $this->log( |
|
533 | - esc_html__( |
|
534 | - // @codingStandardsIgnoreStart |
|
535 | - 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', |
|
536 | - // @codingStandardsIgnoreEnd |
|
537 | - 'event_espresso' |
|
538 | - ), |
|
539 | - $payment |
|
540 | - ); |
|
541 | - return; |
|
542 | - } |
|
543 | - if ( |
|
544 | - ! is_array($update_info) |
|
545 | - || ! isset($update_info['mc_shipping']) |
|
546 | - || ! isset($update_info['tax']) |
|
547 | - ) { |
|
548 | - $this->log( |
|
549 | - array( |
|
550 | - 'message' => esc_html__( |
|
551 | - // @codingStandardsIgnoreStart |
|
552 | - 'Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', |
|
553 | - // @codingStandardsIgnoreEnd |
|
554 | - 'event_espresso' |
|
555 | - ), |
|
556 | - 'url' => $this->_process_response_url(), |
|
557 | - 'payment' => $payment->model_field_array() |
|
558 | - ), |
|
559 | - $payment |
|
560 | - ); |
|
561 | - return; |
|
562 | - } |
|
563 | - if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
564 | - $this->log( |
|
565 | - array( |
|
566 | - 'message' => esc_html__( |
|
567 | - 'We shouldn\'t update transactions taxes or shipping data from non-approved payments', |
|
568 | - 'event_espresso' |
|
569 | - ), |
|
570 | - 'url' => $this->_process_response_url(), |
|
571 | - 'payment' => $payment->model_field_array() |
|
572 | - ), |
|
573 | - $payment |
|
574 | - ); |
|
575 | - return; |
|
576 | - } |
|
577 | - $grand_total_needs_resaving = false; |
|
578 | - /** @var EE_Line_Item $transaction_total_line_item */ |
|
579 | - $transaction_total_line_item = $transaction->total_line_item(); |
|
580 | - |
|
581 | - //might paypal have changed the taxes? |
|
582 | - if ($this->_paypal_taxes && $payment_was_itemized) { |
|
583 | - // note that we're doing this BEFORE adding shipping; |
|
584 | - // we actually want PayPal's shipping to remain non-taxable |
|
585 | - $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
|
586 | - $this->_line_item->set_total_tax_to( |
|
587 | - $transaction_total_line_item, |
|
588 | - (float)$update_info['tax'], |
|
589 | - esc_html__('Taxes', 'event_espresso'), |
|
590 | - esc_html__('Calculated by Paypal', 'event_espresso'), |
|
591 | - 'paypal_tax' |
|
592 | - ); |
|
593 | - $grand_total_needs_resaving = TRUE; |
|
594 | - } |
|
595 | - |
|
596 | - $shipping_amount = (float)$update_info['mc_shipping']; |
|
597 | - //might paypal have added shipping? |
|
598 | - if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
599 | - $this->_line_item->add_unrelated_item( |
|
600 | - $transaction_total_line_item, |
|
601 | - sprintf(esc_html__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
602 | - $shipping_amount, |
|
603 | - esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
|
604 | - 1, |
|
605 | - false, |
|
606 | - 'paypal_shipping_' . $transaction->ID() |
|
607 | - ); |
|
608 | - $grand_total_needs_resaving = true; |
|
609 | - } |
|
610 | - |
|
611 | - if ($grand_total_needs_resaving) { |
|
612 | - $transaction_total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
613 | - /** @var EE_Registration_Processor $registration_processor */ |
|
614 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
615 | - $registration_processor->update_registration_final_prices($transaction); |
|
616 | - } |
|
617 | - $this->log( |
|
618 | - array( |
|
619 | - 'message' => esc_html__('Updated transaction related to payment', 'event_espresso'), |
|
620 | - 'url' => $this->_process_response_url(), |
|
621 | - 'transaction (updated)' => $transaction->model_field_array(), |
|
622 | - 'payment (updated)' => $payment->model_field_array(), |
|
623 | - 'use_paypal_shipping' => $this->_paypal_shipping, |
|
624 | - 'use_paypal_tax' => $this->_paypal_taxes, |
|
625 | - 'grand_total_needed_resaving' => $grand_total_needs_resaving, |
|
626 | - ), |
|
627 | - $payment |
|
628 | - ); |
|
629 | - } |
|
215 | + $redirect_args['shipping_' . $item_num] = '0'; |
|
216 | + $redirect_args['shipping2_' . $item_num] = '0'; |
|
217 | + } |
|
218 | + |
|
219 | + $redirect_args['business'] = $this->_paypal_id; |
|
220 | + $redirect_args['return'] = $return_url; |
|
221 | + $redirect_args['cancel_return'] = $cancel_url; |
|
222 | + $redirect_args['notify_url'] = $notify_url; |
|
223 | + $redirect_args['cmd'] = '_cart'; |
|
224 | + $redirect_args['upload'] = 1; |
|
225 | + $redirect_args['currency_code'] = $payment->currency_code(); |
|
226 | + $redirect_args['rm'] = 2;//makes the user return with method=POST |
|
227 | + if ($this->_image_url) { |
|
228 | + $redirect_args['image_url'] = $this->_image_url; |
|
229 | + } |
|
230 | + $redirect_args['no_shipping'] = $this->_shipping_details; |
|
231 | + $redirect_args['bn'] = 'EventEspresso_SP';//EE will blow up if you change this |
|
232 | + |
|
233 | + $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
|
234 | + |
|
235 | + $payment->set_redirect_url($this->_gateway_url); |
|
236 | + $payment->set_redirect_args($redirect_args); |
|
237 | + // log the results |
|
238 | + $this->log( |
|
239 | + array( |
|
240 | + 'message' => sprintf( |
|
241 | + __('PayPal payment request initiated.', 'event_espresso') |
|
242 | + ), |
|
243 | + 'transaction' => $transaction->model_field_array(), |
|
244 | + ), |
|
245 | + $payment |
|
246 | + ); |
|
247 | + return $payment; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Often used for IPNs. But applies the info in $update_info to the payment. |
|
253 | + * What is $update_info? Often the contents of $_REQUEST, but not necessarily. Whatever |
|
254 | + * the payment method passes in. |
|
255 | + * |
|
256 | + * @param array $update_info like $_POST |
|
257 | + * @param EEI_Transaction $transaction |
|
258 | + * @return \EEI_Payment updated |
|
259 | + * @throws \EE_Error, IpnException |
|
260 | + */ |
|
261 | + public function handle_payment_update($update_info, $transaction) |
|
262 | + { |
|
263 | + // verify there's payment data that's been sent |
|
264 | + if (empty($update_info['payment_status'] ) || empty($update_info['txn_id'])) { |
|
265 | + // log the results |
|
266 | + $this->log( |
|
267 | + array( |
|
268 | + 'message' => sprintf( |
|
269 | + // @codingStandardsIgnoreStart |
|
270 | + __('PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', 'event_espresso') |
|
271 | + // @codingStandardsIgnoreEnd |
|
272 | + ), |
|
273 | + 'update_info' => $update_info, |
|
274 | + ), |
|
275 | + $transaction |
|
276 | + ); |
|
277 | + // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
|
278 | + // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
|
279 | + if (isset($update_info['tx'])) { |
|
280 | + return $transaction->last_payment(); |
|
281 | + } else { |
|
282 | + return null; |
|
283 | + } |
|
284 | + } |
|
285 | + $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
286 | + if (! $payment instanceof EEI_Payment) { |
|
287 | + $payment = $transaction->last_payment(); |
|
288 | + } |
|
289 | + // ok, then validate the IPN. Even if we've already processed this payment, |
|
290 | + // let PayPal know we don't want to hear from them anymore! |
|
291 | + if (! $this->validate_ipn($update_info, $payment)) { |
|
292 | + return $payment; |
|
293 | + } |
|
294 | + // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
|
295 | + // registrations, ticket counts, etc) |
|
296 | + if ( |
|
297 | + ( |
|
298 | + $update_info['payment_status'] === 'Refunded' |
|
299 | + || $update_info['payment_status'] === 'Partially_Refunded' |
|
300 | + ) |
|
301 | + && apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true) |
|
302 | + ) { |
|
303 | + throw new EventEspresso\core\exceptions\IpnException( |
|
304 | + sprintf( |
|
305 | + esc_html__('Event Espresso does not yet support %1$s IPNs from PayPal', 'event_espresso'), |
|
306 | + $update_info['payment_status'] |
|
307 | + ), |
|
308 | + EventEspresso\core\exceptions\IpnException::UNSUPPORTED, |
|
309 | + null, |
|
310 | + $payment, |
|
311 | + $update_info |
|
312 | + ); |
|
313 | + } |
|
314 | + //ok, well let's process this payment then! |
|
315 | + switch ($update_info['payment_status']) { |
|
316 | + |
|
317 | + case 'Completed' : |
|
318 | + $status = $this->_pay_model->approved_status(); |
|
319 | + $gateway_response = esc_html__('The payment is approved.', 'event_espresso'); |
|
320 | + break; |
|
321 | + |
|
322 | + case 'Pending' : |
|
323 | + $status = $this->_pay_model->pending_status(); |
|
324 | + $gateway_response = esc_html__( |
|
325 | + 'The payment is in progress. Another message will be sent when payment is approved.', |
|
326 | + 'event_espresso' |
|
327 | + ); |
|
328 | + break; |
|
329 | + |
|
330 | + case 'Denied' : |
|
331 | + $status = $this->_pay_model->declined_status(); |
|
332 | + $gateway_response = esc_html__('The payment has been declined.', 'event_espresso'); |
|
333 | + break; |
|
334 | + |
|
335 | + case 'Expired' : |
|
336 | + case 'Failed' : |
|
337 | + $status = $this->_pay_model->failed_status(); |
|
338 | + $gateway_response = esc_html__('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
339 | + break; |
|
340 | + |
|
341 | + case 'Refunded' : |
|
342 | + case 'Partially_Refunded' : |
|
343 | + // even though it's a refund, we consider the payment as approved, it just has a negative value |
|
344 | + $status = $this->_pay_model->approved_status(); |
|
345 | + $gateway_response = esc_html__( |
|
346 | + 'The payment has been refunded. Please update registrations accordingly.', |
|
347 | + 'event_espresso' |
|
348 | + ); |
|
349 | + break; |
|
350 | + |
|
351 | + case 'Voided' : |
|
352 | + case 'Reversed' : |
|
353 | + case 'Canceled_Reversal' : |
|
354 | + default : |
|
355 | + $status = $this->_pay_model->cancelled_status(); |
|
356 | + $gateway_response = esc_html__( |
|
357 | + 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', |
|
358 | + 'event_espresso' |
|
359 | + ); |
|
360 | + break; |
|
361 | + |
|
362 | + } |
|
363 | + |
|
364 | + //check if we've already processed this payment |
|
365 | + if ($payment instanceof EEI_Payment) { |
|
366 | + //payment exists. if this has the exact same status and amount, don't bother updating. just return |
|
367 | + if ($payment->status() === $status && (float)$payment->amount() === (float)$update_info['mc_gross']) { |
|
368 | + // DUPLICATED IPN! don't bother updating transaction |
|
369 | + throw new IpnException( |
|
370 | + sprintf( |
|
371 | + esc_html__('It appears we have received a duplicate IPN from PayPal for payment %d', |
|
372 | + 'event_espresso' |
|
373 | + ), |
|
374 | + $payment->ID() |
|
375 | + ), |
|
376 | + IpnException::DUPLICATE, |
|
377 | + null, |
|
378 | + $payment, |
|
379 | + $update_info |
|
380 | + ); |
|
381 | + } else { |
|
382 | + // new payment yippee !!! |
|
383 | + $payment->set_status($status); |
|
384 | + $payment->set_amount((float)$update_info['mc_gross']); |
|
385 | + $payment->set_gateway_response($gateway_response); |
|
386 | + $payment->set_details($update_info); |
|
387 | + $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
388 | + $this->log( |
|
389 | + array( |
|
390 | + 'message' => esc_html__( |
|
391 | + 'Updated payment either from IPN or as part of POST from PayPal', |
|
392 | + 'event_espresso' |
|
393 | + ), |
|
394 | + 'url' => $this->_process_response_url(), |
|
395 | + 'payment' => $payment->model_field_array(), |
|
396 | + 'IPN_data' => $update_info |
|
397 | + ), |
|
398 | + $payment |
|
399 | + ); |
|
400 | + } |
|
401 | + |
|
402 | + } |
|
403 | + do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
404 | + return $payment; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Validate the IPN notification. |
|
410 | + * |
|
411 | + * @param array $update_info like $_REQUEST |
|
412 | + * @param EE_Payment|EEI_Payment $payment |
|
413 | + * @return boolean |
|
414 | + * @throws \EE_Error |
|
415 | + */ |
|
416 | + public function validate_ipn($update_info, $payment) |
|
417 | + { |
|
418 | + //allow us to skip validating IPNs with PayPal (useful for testing) |
|
419 | + if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
420 | + return true; |
|
421 | + } |
|
422 | + //...otherwise, we actually don't care what the $update_info is, we need to look |
|
423 | + //at the request directly because we can't use $update_info because it has issues with quotes |
|
424 | + // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
|
425 | + // Instead, read raw POST data from the input stream. |
|
426 | + // @see https://gist.github.com/xcommerce-gists/3440401 |
|
427 | + $raw_post_data = file_get_contents('php://input'); |
|
428 | + $raw_post_array = explode('&', $raw_post_data); |
|
429 | + $update_info = array(); |
|
430 | + foreach ($raw_post_array as $keyval) { |
|
431 | + $keyval = explode('=', $keyval); |
|
432 | + if (count($keyval) === 2) { |
|
433 | + $update_info[$keyval[0]] = urldecode($keyval[1]); |
|
434 | + } |
|
435 | + } |
|
436 | + // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
|
437 | + $req = 'cmd=_notify-validate'; |
|
438 | + $uses_get_magic_quotes = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1 |
|
439 | + ? true |
|
440 | + : false; |
|
441 | + foreach ($update_info as $key => $value) { |
|
442 | + $value = $uses_get_magic_quotes ? urlencode(stripslashes($value)) : urlencode($value); |
|
443 | + $req .= "&$key=$value"; |
|
444 | + } |
|
445 | + // HTTP POST the complete, unaltered IPN back to PayPal |
|
446 | + $response = wp_remote_post( |
|
447 | + $this->_gateway_url, |
|
448 | + array( |
|
449 | + 'body' => $req, |
|
450 | + 'sslverify' => false, |
|
451 | + 'timeout' => 60, |
|
452 | + // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
|
453 | + // plz see: https://github.com/websharks/s2member/issues/610 |
|
454 | + 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
455 | + 'httpversion' => '1.1' |
|
456 | + ) |
|
457 | + ); |
|
458 | + // then check the response |
|
459 | + if ( |
|
460 | + array_key_exists('body', $response) |
|
461 | + && ! is_wp_error($response) |
|
462 | + && strcmp($response['body'], "VERIFIED") === 0 |
|
463 | + ) { |
|
464 | + return true; |
|
465 | + } |
|
466 | + // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
|
467 | + // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
|
468 | + if ($response instanceof WP_Error) { |
|
469 | + $error_msg = sprintf( |
|
470 | + esc_html__('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
471 | + $response->get_error_code(), |
|
472 | + $response->get_error_message(), |
|
473 | + print_r($response->get_error_data(), true) |
|
474 | + ); |
|
475 | + } elseif(is_array($response) && isset($response['body'])) { |
|
476 | + $error_msg = $response['body']; |
|
477 | + } else { |
|
478 | + $error_msg = print_r($response, true); |
|
479 | + } |
|
480 | + $payment->set_gateway_response( |
|
481 | + sprintf( |
|
482 | + esc_html__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), |
|
483 | + $error_msg |
|
484 | + ) |
|
485 | + ); |
|
486 | + $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
487 | + $payment->set_status(EEM_Payment::status_id_failed); |
|
488 | + // log the results |
|
489 | + $this->log( |
|
490 | + array( |
|
491 | + 'url' => $this->_process_response_url(), |
|
492 | + 'message' => $payment->gateway_response(), |
|
493 | + 'details' => $payment->details(), |
|
494 | + ), |
|
495 | + $payment |
|
496 | + ); |
|
497 | + return false; |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * _process_response_url |
|
503 | + * @return string |
|
504 | + */ |
|
505 | + protected function _process_response_url() |
|
506 | + { |
|
507 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
508 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
509 | + $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
510 | + $url .= EEH_URL::filter_input_server_url(); |
|
511 | + } else { |
|
512 | + $url = 'unknown'; |
|
513 | + } |
|
514 | + return $url; |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * Updates the transaction and line items based on the payment IPN data from PayPal, |
|
520 | + * like the taxes or shipping |
|
521 | + * |
|
522 | + * @param EEI_Payment $payment |
|
523 | + * @throws \EE_Error |
|
524 | + */ |
|
525 | + public function update_txn_based_on_payment($payment) |
|
526 | + { |
|
527 | + $update_info = $payment->details(); |
|
528 | + /** @var EE_Transaction $transaction */ |
|
529 | + $transaction = $payment->transaction(); |
|
530 | + $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
531 | + if (! $transaction) { |
|
532 | + $this->log( |
|
533 | + esc_html__( |
|
534 | + // @codingStandardsIgnoreStart |
|
535 | + 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', |
|
536 | + // @codingStandardsIgnoreEnd |
|
537 | + 'event_espresso' |
|
538 | + ), |
|
539 | + $payment |
|
540 | + ); |
|
541 | + return; |
|
542 | + } |
|
543 | + if ( |
|
544 | + ! is_array($update_info) |
|
545 | + || ! isset($update_info['mc_shipping']) |
|
546 | + || ! isset($update_info['tax']) |
|
547 | + ) { |
|
548 | + $this->log( |
|
549 | + array( |
|
550 | + 'message' => esc_html__( |
|
551 | + // @codingStandardsIgnoreStart |
|
552 | + 'Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', |
|
553 | + // @codingStandardsIgnoreEnd |
|
554 | + 'event_espresso' |
|
555 | + ), |
|
556 | + 'url' => $this->_process_response_url(), |
|
557 | + 'payment' => $payment->model_field_array() |
|
558 | + ), |
|
559 | + $payment |
|
560 | + ); |
|
561 | + return; |
|
562 | + } |
|
563 | + if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
564 | + $this->log( |
|
565 | + array( |
|
566 | + 'message' => esc_html__( |
|
567 | + 'We shouldn\'t update transactions taxes or shipping data from non-approved payments', |
|
568 | + 'event_espresso' |
|
569 | + ), |
|
570 | + 'url' => $this->_process_response_url(), |
|
571 | + 'payment' => $payment->model_field_array() |
|
572 | + ), |
|
573 | + $payment |
|
574 | + ); |
|
575 | + return; |
|
576 | + } |
|
577 | + $grand_total_needs_resaving = false; |
|
578 | + /** @var EE_Line_Item $transaction_total_line_item */ |
|
579 | + $transaction_total_line_item = $transaction->total_line_item(); |
|
580 | + |
|
581 | + //might paypal have changed the taxes? |
|
582 | + if ($this->_paypal_taxes && $payment_was_itemized) { |
|
583 | + // note that we're doing this BEFORE adding shipping; |
|
584 | + // we actually want PayPal's shipping to remain non-taxable |
|
585 | + $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
|
586 | + $this->_line_item->set_total_tax_to( |
|
587 | + $transaction_total_line_item, |
|
588 | + (float)$update_info['tax'], |
|
589 | + esc_html__('Taxes', 'event_espresso'), |
|
590 | + esc_html__('Calculated by Paypal', 'event_espresso'), |
|
591 | + 'paypal_tax' |
|
592 | + ); |
|
593 | + $grand_total_needs_resaving = TRUE; |
|
594 | + } |
|
595 | + |
|
596 | + $shipping_amount = (float)$update_info['mc_shipping']; |
|
597 | + //might paypal have added shipping? |
|
598 | + if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
599 | + $this->_line_item->add_unrelated_item( |
|
600 | + $transaction_total_line_item, |
|
601 | + sprintf(esc_html__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
602 | + $shipping_amount, |
|
603 | + esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
|
604 | + 1, |
|
605 | + false, |
|
606 | + 'paypal_shipping_' . $transaction->ID() |
|
607 | + ); |
|
608 | + $grand_total_needs_resaving = true; |
|
609 | + } |
|
610 | + |
|
611 | + if ($grand_total_needs_resaving) { |
|
612 | + $transaction_total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
613 | + /** @var EE_Registration_Processor $registration_processor */ |
|
614 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
615 | + $registration_processor->update_registration_final_prices($transaction); |
|
616 | + } |
|
617 | + $this->log( |
|
618 | + array( |
|
619 | + 'message' => esc_html__('Updated transaction related to payment', 'event_espresso'), |
|
620 | + 'url' => $this->_process_response_url(), |
|
621 | + 'transaction (updated)' => $transaction->model_field_array(), |
|
622 | + 'payment (updated)' => $payment->model_field_array(), |
|
623 | + 'use_paypal_shipping' => $this->_paypal_shipping, |
|
624 | + 'use_paypal_tax' => $this->_paypal_taxes, |
|
625 | + 'grand_total_needed_resaving' => $grand_total_needs_resaving, |
|
626 | + ), |
|
627 | + $payment |
|
628 | + ); |
|
629 | + } |
|
630 | 630 | } |
631 | 631 | // End of file EEG_Paypal_Standard.gateway.php |
632 | 632 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | use EventEspresso\core\exceptions\IpnException; |
4 | 4 | |
5 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | 6 | exit('NO direct script access allowed'); |
7 | 7 | } |
8 | 8 | |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | $shipping_previously_added = $line_item->total(); |
144 | 144 | continue; |
145 | 145 | } |
146 | - $redirect_args['item_name_' . $item_num] = substr( |
|
146 | + $redirect_args['item_name_'.$item_num] = substr( |
|
147 | 147 | $gateway_formatter->formatLineItemName($line_item, $payment), |
148 | 148 | 0, 127 |
149 | 149 | ); |
150 | - $redirect_args['amount_' . $item_num] = $line_item->unit_price(); |
|
151 | - $redirect_args['quantity_' . $item_num] = $line_item->quantity(); |
|
150 | + $redirect_args['amount_'.$item_num] = $line_item->unit_price(); |
|
151 | + $redirect_args['quantity_'.$item_num] = $line_item->quantity(); |
|
152 | 152 | //if we're not letting PayPal calculate shipping, tell them its 0 |
153 | - if (! $this->_paypal_shipping) { |
|
154 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
155 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
153 | + if ( ! $this->_paypal_shipping) { |
|
154 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
155 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
156 | 156 | } |
157 | 157 | $item_num++; |
158 | 158 | $itemized_sum += $line_item->total(); |
@@ -172,12 +172,12 @@ discard block |
||
172 | 172 | //itemized sum is too big |
173 | 173 | $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
174 | 174 | } elseif ($itemized_sum_diff_from_txn_total > 0) { |
175 | - $redirect_args['item_name_' . $item_num] = substr( |
|
176 | - __('Other charges', 'event_espresso' ), 0, 127); |
|
177 | - $redirect_args['amount_' . $item_num] = $gateway_formatter->formatCurrency( |
|
175 | + $redirect_args['item_name_'.$item_num] = substr( |
|
176 | + __('Other charges', 'event_espresso'), 0, 127); |
|
177 | + $redirect_args['amount_'.$item_num] = $gateway_formatter->formatCurrency( |
|
178 | 178 | $itemized_sum_diff_from_txn_total |
179 | 179 | ); |
180 | - $redirect_args['quantity_' . $item_num] = 1; |
|
180 | + $redirect_args['quantity_'.$item_num] = 1; |
|
181 | 181 | $item_num++; |
182 | 182 | } |
183 | 183 | if ($total_discounts_to_cart_total > 0) { |
@@ -186,34 +186,34 @@ discard block |
||
186 | 186 | ); |
187 | 187 | } |
188 | 188 | //add our taxes to the order if we're NOT using PayPal's |
189 | - if (! $this->_paypal_taxes) { |
|
189 | + if ( ! $this->_paypal_taxes) { |
|
190 | 190 | $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
191 | 191 | } |
192 | 192 | } else { |
193 | 193 | $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
194 | 194 | //partial payment that's not for the remaining amount, so we can't send an itemized list |
195 | - $redirect_args['item_name_' . $item_num] = substr( |
|
195 | + $redirect_args['item_name_'.$item_num] = substr( |
|
196 | 196 | $gateway_formatter->formatPartialPaymentLineItemName($payment), |
197 | 197 | 0, |
198 | 198 | 127 |
199 | 199 | ); |
200 | - $redirect_args['amount_' . $item_num] = $payment->amount(); |
|
201 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
202 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
200 | + $redirect_args['amount_'.$item_num] = $payment->amount(); |
|
201 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
202 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
203 | 203 | $redirect_args['tax_cart'] = '0'; |
204 | 204 | $item_num++; |
205 | 205 | } |
206 | 206 | |
207 | 207 | if ($this->_debug_mode) { |
208 | - $redirect_args['item_name_' . $item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | - $redirect_args['amount_' . $item_num] = 0; |
|
208 | + $redirect_args['item_name_'.$item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | + $redirect_args['amount_'.$item_num] = 0; |
|
210 | 210 | $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
211 | - $redirect_args['os0_' . $item_num] = $notify_url; |
|
211 | + $redirect_args['os0_'.$item_num] = $notify_url; |
|
212 | 212 | $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
213 | - $redirect_args['os1_' . $item_num] = $return_url; |
|
213 | + $redirect_args['os1_'.$item_num] = $return_url; |
|
214 | 214 | // $redirect_args['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
215 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
216 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
215 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
216 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | $redirect_args['business'] = $this->_paypal_id; |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | $redirect_args['cmd'] = '_cart'; |
224 | 224 | $redirect_args['upload'] = 1; |
225 | 225 | $redirect_args['currency_code'] = $payment->currency_code(); |
226 | - $redirect_args['rm'] = 2;//makes the user return with method=POST |
|
226 | + $redirect_args['rm'] = 2; //makes the user return with method=POST |
|
227 | 227 | if ($this->_image_url) { |
228 | 228 | $redirect_args['image_url'] = $this->_image_url; |
229 | 229 | } |
230 | 230 | $redirect_args['no_shipping'] = $this->_shipping_details; |
231 | - $redirect_args['bn'] = 'EventEspresso_SP';//EE will blow up if you change this |
|
231 | + $redirect_args['bn'] = 'EventEspresso_SP'; //EE will blow up if you change this |
|
232 | 232 | |
233 | 233 | $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
234 | 234 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | public function handle_payment_update($update_info, $transaction) |
262 | 262 | { |
263 | 263 | // verify there's payment data that's been sent |
264 | - if (empty($update_info['payment_status'] ) || empty($update_info['txn_id'])) { |
|
264 | + if (empty($update_info['payment_status']) || empty($update_info['txn_id'])) { |
|
265 | 265 | // log the results |
266 | 266 | $this->log( |
267 | 267 | array( |
@@ -283,12 +283,12 @@ discard block |
||
283 | 283 | } |
284 | 284 | } |
285 | 285 | $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
286 | - if (! $payment instanceof EEI_Payment) { |
|
286 | + if ( ! $payment instanceof EEI_Payment) { |
|
287 | 287 | $payment = $transaction->last_payment(); |
288 | 288 | } |
289 | 289 | // ok, then validate the IPN. Even if we've already processed this payment, |
290 | 290 | // let PayPal know we don't want to hear from them anymore! |
291 | - if (! $this->validate_ipn($update_info, $payment)) { |
|
291 | + if ( ! $this->validate_ipn($update_info, $payment)) { |
|
292 | 292 | return $payment; |
293 | 293 | } |
294 | 294 | // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | //check if we've already processed this payment |
365 | 365 | if ($payment instanceof EEI_Payment) { |
366 | 366 | //payment exists. if this has the exact same status and amount, don't bother updating. just return |
367 | - if ($payment->status() === $status && (float)$payment->amount() === (float)$update_info['mc_gross']) { |
|
367 | + if ($payment->status() === $status && (float) $payment->amount() === (float) $update_info['mc_gross']) { |
|
368 | 368 | // DUPLICATED IPN! don't bother updating transaction |
369 | 369 | throw new IpnException( |
370 | 370 | sprintf( |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | } else { |
382 | 382 | // new payment yippee !!! |
383 | 383 | $payment->set_status($status); |
384 | - $payment->set_amount((float)$update_info['mc_gross']); |
|
384 | + $payment->set_amount((float) $update_info['mc_gross']); |
|
385 | 385 | $payment->set_gateway_response($gateway_response); |
386 | 386 | $payment->set_details($update_info); |
387 | 387 | $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | 'timeout' => 60, |
452 | 452 | // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
453 | 453 | // plz see: https://github.com/websharks/s2member/issues/610 |
454 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
454 | + 'user-agent' => 'Event Espresso v'.EVENT_ESPRESSO_VERSION.'; '.home_url(), |
|
455 | 455 | 'httpversion' => '1.1' |
456 | 456 | ) |
457 | 457 | ); |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | $response->get_error_message(), |
473 | 473 | print_r($response->get_error_data(), true) |
474 | 474 | ); |
475 | - } elseif(is_array($response) && isset($response['body'])) { |
|
475 | + } elseif (is_array($response) && isset($response['body'])) { |
|
476 | 476 | $error_msg = $response['body']; |
477 | 477 | } else { |
478 | 478 | $error_msg = print_r($response, true); |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | /** @var EE_Transaction $transaction */ |
529 | 529 | $transaction = $payment->transaction(); |
530 | 530 | $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
531 | - if (! $transaction) { |
|
531 | + if ( ! $transaction) { |
|
532 | 532 | $this->log( |
533 | 533 | esc_html__( |
534 | 534 | // @codingStandardsIgnoreStart |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
586 | 586 | $this->_line_item->set_total_tax_to( |
587 | 587 | $transaction_total_line_item, |
588 | - (float)$update_info['tax'], |
|
588 | + (float) $update_info['tax'], |
|
589 | 589 | esc_html__('Taxes', 'event_espresso'), |
590 | 590 | esc_html__('Calculated by Paypal', 'event_espresso'), |
591 | 591 | 'paypal_tax' |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | $grand_total_needs_resaving = TRUE; |
594 | 594 | } |
595 | 595 | |
596 | - $shipping_amount = (float)$update_info['mc_shipping']; |
|
596 | + $shipping_amount = (float) $update_info['mc_shipping']; |
|
597 | 597 | //might paypal have added shipping? |
598 | 598 | if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
599 | 599 | $this->_line_item->add_unrelated_item( |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
604 | 604 | 1, |
605 | 605 | false, |
606 | - 'paypal_shipping_' . $transaction->ID() |
|
606 | + 'paypal_shipping_'.$transaction->ID() |
|
607 | 607 | ); |
608 | 608 | $grand_total_needs_resaving = true; |
609 | 609 | } |