@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @since 1.0 |
10 | 10 | */ |
11 | 11 | |
12 | -if ( ! defined( 'ABSPATH' ) ) { |
|
12 | +if ( ! defined('ABSPATH')) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @access private |
22 | 22 | * @since 1.0 |
23 | 23 | */ |
24 | -add_action( 'give_paypal_cc_form', '__return_false' ); |
|
24 | +add_action('give_paypal_cc_form', '__return_false'); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Process PayPal Purchase. |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return void |
34 | 34 | */ |
35 | -function give_process_paypal_purchase( $purchase_data ) { |
|
35 | +function give_process_paypal_purchase($purchase_data) { |
|
36 | 36 | |
37 | - if ( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'give-gateway' ) ) { |
|
38 | - wp_die( esc_html__( 'Nonce verification has failed.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
37 | + if ( ! wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) { |
|
38 | + wp_die(esc_html__('Nonce verification has failed.', 'give'), esc_html__('Error', 'give'), array('response' => 403)); |
|
39 | 39 | } |
40 | 40 | |
41 | - $form_id = intval( $purchase_data['post_data']['give-form-id'] ); |
|
42 | - $price_id = isset( $purchase_data['post_data']['give-price-id'] ) ? $purchase_data['post_data']['give-price-id'] : ''; |
|
41 | + $form_id = intval($purchase_data['post_data']['give-form-id']); |
|
42 | + $price_id = isset($purchase_data['post_data']['give-price-id']) ? $purchase_data['post_data']['give-price-id'] : ''; |
|
43 | 43 | |
44 | 44 | // Collect payment data. |
45 | 45 | $payment_data = array( |
@@ -57,69 +57,69 @@ discard block |
||
57 | 57 | ); |
58 | 58 | |
59 | 59 | // Record the pending payment. |
60 | - $payment = give_insert_payment( $payment_data ); |
|
60 | + $payment = give_insert_payment($payment_data); |
|
61 | 61 | |
62 | 62 | // Check payment. |
63 | - if ( ! $payment ) { |
|
63 | + if ( ! $payment) { |
|
64 | 64 | // Record the error. |
65 | 65 | give_record_gateway_error( |
66 | - esc_html__( 'Payment Error', 'give' ), |
|
66 | + esc_html__('Payment Error', 'give'), |
|
67 | 67 | sprintf( |
68 | 68 | /* translators: %s: payment data */ |
69 | - esc_html__( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give' ), |
|
70 | - json_encode( $payment_data ) |
|
69 | + esc_html__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give'), |
|
70 | + json_encode($payment_data) |
|
71 | 71 | ), |
72 | 72 | $payment |
73 | 73 | ); |
74 | 74 | // Problems? Send back. |
75 | - give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] ); |
|
75 | + give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']); |
|
76 | 76 | |
77 | 77 | } else { |
78 | 78 | |
79 | 79 | // Only send to PayPal if the pending payment is created successfully. |
80 | - $listener_url = add_query_arg( 'give-listener', 'IPN', home_url( 'index.php' ) ); |
|
80 | + $listener_url = add_query_arg('give-listener', 'IPN', home_url('index.php')); |
|
81 | 81 | |
82 | 82 | // Get the success url |
83 | - $return_url = add_query_arg( array( |
|
83 | + $return_url = add_query_arg(array( |
|
84 | 84 | 'payment-confirmation' => 'paypal', |
85 | 85 | 'payment-id' => $payment |
86 | 86 | |
87 | - ), get_permalink( give_get_option( 'success_page' ) ) ); |
|
87 | + ), get_permalink(give_get_option('success_page'))); |
|
88 | 88 | |
89 | 89 | // Get the PayPal redirect uri |
90 | - $paypal_redirect = trailingslashit( give_get_paypal_redirect() ) . '?'; |
|
90 | + $paypal_redirect = trailingslashit(give_get_paypal_redirect()).'?'; |
|
91 | 91 | |
92 | 92 | //Item name - pass level name if variable priced |
93 | 93 | $item_name = $purchase_data['post_data']['give-form-title']; |
94 | 94 | |
95 | 95 | //Verify has variable prices |
96 | - if ( give_has_variable_prices( $form_id ) && isset( $purchase_data['post_data']['give-price-id'] ) ) { |
|
96 | + if (give_has_variable_prices($form_id) && isset($purchase_data['post_data']['give-price-id'])) { |
|
97 | 97 | |
98 | - $item_price_level_text = give_get_price_option_name( $form_id, $purchase_data['post_data']['give-price-id'] ); |
|
98 | + $item_price_level_text = give_get_price_option_name($form_id, $purchase_data['post_data']['give-price-id']); |
|
99 | 99 | |
100 | - $price_level_amount = give_get_price_option_amount( $form_id, $purchase_data['post_data']['give-price-id'] ); |
|
100 | + $price_level_amount = give_get_price_option_amount($form_id, $purchase_data['post_data']['give-price-id']); |
|
101 | 101 | |
102 | 102 | //Donation given doesn't match selected level (must be a custom amount) |
103 | - if ( $price_level_amount != give_sanitize_amount( $purchase_data['price'] ) ) { |
|
104 | - $custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
|
103 | + if ($price_level_amount != give_sanitize_amount($purchase_data['price'])) { |
|
104 | + $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true); |
|
105 | 105 | //user custom amount text if any, fallback to default if not |
106 | - $item_name .= ' - ' . ( ! empty( $custom_amount_text ) ? $custom_amount_text : esc_html__( 'Custom Amount', 'give' ) ); |
|
106 | + $item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : esc_html__('Custom Amount', 'give')); |
|
107 | 107 | |
108 | 108 | } //Is there any donation level text? |
109 | - elseif ( ! empty( $item_price_level_text ) ) { |
|
110 | - $item_name .= ' - ' . $item_price_level_text; |
|
109 | + elseif ( ! empty($item_price_level_text)) { |
|
110 | + $item_name .= ' - '.$item_price_level_text; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | } //Single donation: Custom Amount |
114 | - elseif ( give_get_form_price( $form_id ) !== give_sanitize_amount( $purchase_data['price'] ) ) { |
|
115 | - $custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true ); |
|
114 | + elseif (give_get_form_price($form_id) !== give_sanitize_amount($purchase_data['price'])) { |
|
115 | + $custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true); |
|
116 | 116 | //user custom amount text if any, fallback to default if not |
117 | - $item_name .= ' - ' . ( ! empty( $custom_amount_text ) ? $custom_amount_text : esc_html__( 'Custom Amount', 'give' ) ); |
|
117 | + $item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : esc_html__('Custom Amount', 'give')); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | // Setup PayPal arguments |
121 | 121 | $paypal_args = array( |
122 | - 'business' => give_get_option( 'paypal_email', false ), |
|
122 | + 'business' => give_get_option('paypal_email', false), |
|
123 | 123 | 'email' => $purchase_data['user_email'], |
124 | 124 | 'invoice' => $purchase_data['purchase_key'], |
125 | 125 | 'amount' => $purchase_data['price'], |
@@ -130,25 +130,25 @@ discard block |
||
130 | 130 | 'shipping' => '0', |
131 | 131 | 'no_note' => '1', |
132 | 132 | 'currency_code' => give_get_currency(), |
133 | - 'charset' => get_bloginfo( 'charset' ), |
|
133 | + 'charset' => get_bloginfo('charset'), |
|
134 | 134 | 'custom' => $payment, |
135 | 135 | 'rm' => '2', |
136 | 136 | 'return' => $return_url, |
137 | - 'cancel_return' => give_get_failed_transaction_uri( '?payment-id=' . $payment ), |
|
137 | + 'cancel_return' => give_get_failed_transaction_uri('?payment-id='.$payment), |
|
138 | 138 | 'notify_url' => $listener_url, |
139 | 139 | 'page_style' => give_get_paypal_page_style(), |
140 | - 'cbt' => get_bloginfo( 'name' ), |
|
140 | + 'cbt' => get_bloginfo('name'), |
|
141 | 141 | 'bn' => 'givewp_SP' |
142 | 142 | ); |
143 | 143 | |
144 | - if ( ! empty( $purchase_data['user_info']['address'] ) ) { |
|
144 | + if ( ! empty($purchase_data['user_info']['address'])) { |
|
145 | 145 | $paypal_args['address1'] = $purchase_data['user_info']['address']['line1']; |
146 | 146 | $paypal_args['address2'] = $purchase_data['user_info']['address']['line2']; |
147 | 147 | $paypal_args['city'] = $purchase_data['user_info']['address']['city']; |
148 | 148 | $paypal_args['country'] = $purchase_data['user_info']['address']['country']; |
149 | 149 | } |
150 | 150 | |
151 | - if ( give_get_option( 'paypal_button_type' ) === 'standard' ) { |
|
151 | + if (give_get_option('paypal_button_type') === 'standard') { |
|
152 | 152 | $paypal_extra_args = array( |
153 | 153 | 'cmd' => '_xclick', |
154 | 154 | ); |
@@ -158,23 +158,23 @@ discard block |
||
158 | 158 | ); |
159 | 159 | } |
160 | 160 | |
161 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
162 | - $paypal_args = apply_filters( 'give_paypal_redirect_args', $paypal_args, $purchase_data ); |
|
161 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
162 | + $paypal_args = apply_filters('give_paypal_redirect_args', $paypal_args, $purchase_data); |
|
163 | 163 | |
164 | 164 | // Build query |
165 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
165 | + $paypal_redirect .= http_build_query($paypal_args); |
|
166 | 166 | |
167 | 167 | // Fix for some sites that encode the entities |
168 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
168 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
169 | 169 | |
170 | 170 | // Redirect to PayPal |
171 | - wp_redirect( $paypal_redirect ); |
|
171 | + wp_redirect($paypal_redirect); |
|
172 | 172 | exit; |
173 | 173 | } |
174 | 174 | |
175 | 175 | } |
176 | 176 | |
177 | -add_action( 'give_gateway_paypal', 'give_process_paypal_purchase' ); |
|
177 | +add_action('give_gateway_paypal', 'give_process_paypal_purchase'); |
|
178 | 178 | |
179 | 179 | /** |
180 | 180 | * Listens for a PayPal IPN requests and then sends to the processing function |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | */ |
185 | 185 | function give_listen_for_paypal_ipn() { |
186 | 186 | // Regular PayPal IPN |
187 | - if ( isset( $_GET['give-listener'] ) && $_GET['give-listener'] == 'IPN' ) { |
|
188 | - do_action( 'give_verify_paypal_ipn' ); |
|
187 | + if (isset($_GET['give-listener']) && $_GET['give-listener'] == 'IPN') { |
|
188 | + do_action('give_verify_paypal_ipn'); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
192 | -add_action( 'init', 'give_listen_for_paypal_ipn' ); |
|
192 | +add_action('init', 'give_listen_for_paypal_ipn'); |
|
193 | 193 | |
194 | 194 | /** |
195 | 195 | * Process PayPal IPN |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | function give_process_paypal_ipn() { |
201 | 201 | |
202 | 202 | // Check the request method is POST |
203 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
203 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
204 | 204 | return; |
205 | 205 | } |
206 | 206 | |
@@ -208,11 +208,11 @@ discard block |
||
208 | 208 | $post_data = ''; |
209 | 209 | |
210 | 210 | // Fallback just in case post_max_size is lower than needed |
211 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
212 | - $post_data = file_get_contents( 'php://input' ); |
|
211 | + if (ini_get('allow_url_fopen')) { |
|
212 | + $post_data = file_get_contents('php://input'); |
|
213 | 213 | } else { |
214 | 214 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
215 | - ini_set( 'post_max_size', '12M' ); |
|
215 | + ini_set('post_max_size', '12M'); |
|
216 | 216 | } |
217 | 217 | // Start the encoded data collection with notification command |
218 | 218 | $encoded_data = 'cmd=_notify-validate'; |
@@ -221,40 +221,40 @@ discard block |
||
221 | 221 | $arg_separator = give_get_php_arg_separator_output(); |
222 | 222 | |
223 | 223 | // Verify there is a post_data |
224 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
224 | + if ($post_data || strlen($post_data) > 0) { |
|
225 | 225 | // Append the data |
226 | - $encoded_data .= $arg_separator . $post_data; |
|
226 | + $encoded_data .= $arg_separator.$post_data; |
|
227 | 227 | } else { |
228 | 228 | // Check if POST is empty |
229 | - if ( empty( $_POST ) ) { |
|
229 | + if (empty($_POST)) { |
|
230 | 230 | // Nothing to do |
231 | 231 | return; |
232 | 232 | } else { |
233 | 233 | // Loop through each POST |
234 | - foreach ( $_POST as $key => $value ) { |
|
234 | + foreach ($_POST as $key => $value) { |
|
235 | 235 | // Encode the value and append the data |
236 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
236 | + $encoded_data .= $arg_separator."$key=".urlencode($value); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | 241 | // Convert collected post data to an array |
242 | - parse_str( $encoded_data, $encoded_data_array ); |
|
242 | + parse_str($encoded_data, $encoded_data_array); |
|
243 | 243 | |
244 | - foreach ( $encoded_data_array as $key => $value ) { |
|
244 | + foreach ($encoded_data_array as $key => $value) { |
|
245 | 245 | |
246 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
247 | - $new_key = str_replace( '&', '&', $key ); |
|
248 | - $new_key = str_replace( 'amp;', '&', $new_key ); |
|
246 | + if (false !== strpos($key, 'amp;')) { |
|
247 | + $new_key = str_replace('&', '&', $key); |
|
248 | + $new_key = str_replace('amp;', '&', $new_key); |
|
249 | 249 | |
250 | - unset( $encoded_data_array[ $key ] ); |
|
251 | - $encoded_data_array[ $new_key ] = $value; |
|
250 | + unset($encoded_data_array[$key]); |
|
251 | + $encoded_data_array[$new_key] = $value; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | } |
255 | 255 | |
256 | 256 | //Validate IPN request w/ PayPal if user hasn't disabled this security measure |
257 | - if ( ! give_get_option( 'disable_paypal_verification' ) ) { |
|
257 | + if ( ! give_get_option('disable_paypal_verification')) { |
|
258 | 258 | |
259 | 259 | $remote_post_vars = array( |
260 | 260 | 'method' => 'POST', |
@@ -274,28 +274,28 @@ discard block |
||
274 | 274 | ); |
275 | 275 | |
276 | 276 | // Validate the IPN |
277 | - $api_response = wp_remote_post( give_get_paypal_redirect(), $remote_post_vars ); |
|
277 | + $api_response = wp_remote_post(give_get_paypal_redirect(), $remote_post_vars); |
|
278 | 278 | |
279 | - if ( is_wp_error( $api_response ) ) { |
|
279 | + if (is_wp_error($api_response)) { |
|
280 | 280 | give_record_gateway_error( |
281 | - esc_html__( 'IPN Error', 'give' ), |
|
281 | + esc_html__('IPN Error', 'give'), |
|
282 | 282 | sprintf( |
283 | 283 | /* translators: %s: Paypal IPN response */ |
284 | - esc_html__( 'Invalid IPN verification response. IPN data: %s', 'give' ), |
|
285 | - json_encode( $api_response ) |
|
284 | + esc_html__('Invalid IPN verification response. IPN data: %s', 'give'), |
|
285 | + json_encode($api_response) |
|
286 | 286 | ) |
287 | 287 | ); |
288 | 288 | |
289 | 289 | return; // Something went wrong |
290 | 290 | } |
291 | 291 | |
292 | - if ( $api_response['body'] !== 'VERIFIED' && give_get_option( 'disable_paypal_verification', false ) ) { |
|
292 | + if ($api_response['body'] !== 'VERIFIED' && give_get_option('disable_paypal_verification', false)) { |
|
293 | 293 | give_record_gateway_error( |
294 | - esc_html__( 'IPN Error', 'give' ), |
|
294 | + esc_html__('IPN Error', 'give'), |
|
295 | 295 | sprintf( |
296 | 296 | /* translators: %s: Paypal IPN response */ |
297 | - esc_html__( 'Invalid IPN verification response. IPN data: %s', 'give' ), |
|
298 | - json_encode( $api_response ) |
|
297 | + esc_html__('Invalid IPN verification response. IPN data: %s', 'give'), |
|
298 | + json_encode($api_response) |
|
299 | 299 | ) |
300 | 300 | ); |
301 | 301 | |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | } |
306 | 306 | |
307 | 307 | // Check if $post_data_array has been populated |
308 | - if ( ! is_array( $encoded_data_array ) && ! empty( $encoded_data_array ) ) { |
|
308 | + if ( ! is_array($encoded_data_array) && ! empty($encoded_data_array)) { |
|
309 | 309 | return; |
310 | 310 | } |
311 | 311 | |
@@ -314,21 +314,21 @@ discard block |
||
314 | 314 | 'payment_status' => '' |
315 | 315 | ); |
316 | 316 | |
317 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
317 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
318 | 318 | |
319 | - $payment_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
319 | + $payment_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
320 | 320 | |
321 | - if ( has_action( 'give_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
321 | + if (has_action('give_paypal_'.$encoded_data_array['txn_type'])) { |
|
322 | 322 | // Allow PayPal IPN types to be processed separately |
323 | - do_action( 'give_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $payment_id ); |
|
323 | + do_action('give_paypal_'.$encoded_data_array['txn_type'], $encoded_data_array, $payment_id); |
|
324 | 324 | } else { |
325 | 325 | // Fallback to web accept just in case the txn_type isn't present |
326 | - do_action( 'give_paypal_web_accept', $encoded_data_array, $payment_id ); |
|
326 | + do_action('give_paypal_web_accept', $encoded_data_array, $payment_id); |
|
327 | 327 | } |
328 | 328 | exit; |
329 | 329 | } |
330 | 330 | |
331 | -add_action( 'give_verify_paypal_ipn', 'give_process_paypal_ipn' ); |
|
331 | +add_action('give_verify_paypal_ipn', 'give_process_paypal_ipn'); |
|
332 | 332 | |
333 | 333 | /** |
334 | 334 | * Process web accept (one time) payment IPNs |
@@ -339,224 +339,224 @@ discard block |
||
339 | 339 | * |
340 | 340 | * @return void |
341 | 341 | */ |
342 | -function give_process_paypal_web_accept_and_cart( $data, $payment_id ) { |
|
342 | +function give_process_paypal_web_accept_and_cart($data, $payment_id) { |
|
343 | 343 | |
344 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
344 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
345 | 345 | return; |
346 | 346 | } |
347 | 347 | |
348 | - if ( empty( $payment_id ) ) { |
|
348 | + if (empty($payment_id)) { |
|
349 | 349 | return; |
350 | 350 | } |
351 | 351 | |
352 | 352 | // Collect payment details |
353 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
353 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
354 | 354 | $paypal_amount = $data['mc_gross']; |
355 | - $payment_status = strtolower( $data['payment_status'] ); |
|
356 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
357 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
358 | - $payment_meta = give_get_payment_meta( $payment_id ); |
|
355 | + $payment_status = strtolower($data['payment_status']); |
|
356 | + $currency_code = strtolower($data['mc_currency']); |
|
357 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
358 | + $payment_meta = give_get_payment_meta($payment_id); |
|
359 | 359 | |
360 | 360 | |
361 | - if ( give_get_payment_gateway( $payment_id ) != 'paypal' ) { |
|
361 | + if (give_get_payment_gateway($payment_id) != 'paypal') { |
|
362 | 362 | return; // this isn't a PayPal standard IPN |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Verify payment recipient |
366 | - if ( strcasecmp( $business_email, trim( give_get_option( 'paypal_email' ) ) ) != 0 ) { |
|
366 | + if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) != 0) { |
|
367 | 367 | |
368 | 368 | give_record_gateway_error( |
369 | - esc_html__( 'IPN Error', 'give' ), |
|
369 | + esc_html__('IPN Error', 'give'), |
|
370 | 370 | sprintf( |
371 | 371 | /* translators: %s: Paypal IPN response */ |
372 | - esc_html__( 'Invalid business email in IPN response. IPN data: %s', 'give' ), |
|
373 | - json_encode( $data ) |
|
372 | + esc_html__('Invalid business email in IPN response. IPN data: %s', 'give'), |
|
373 | + json_encode($data) |
|
374 | 374 | ), |
375 | 375 | $payment_id |
376 | 376 | ); |
377 | - give_update_payment_status( $payment_id, 'failed' ); |
|
378 | - give_insert_payment_note( $payment_id, esc_html__( 'Payment failed due to invalid PayPal business email.', 'give' ) ); |
|
377 | + give_update_payment_status($payment_id, 'failed'); |
|
378 | + give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid PayPal business email.', 'give')); |
|
379 | 379 | |
380 | 380 | return; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // Verify payment currency |
384 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
384 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
385 | 385 | |
386 | 386 | give_record_gateway_error( |
387 | - esc_html__( 'IPN Error', 'give' ), |
|
387 | + esc_html__('IPN Error', 'give'), |
|
388 | 388 | sprintf( |
389 | 389 | /* translators: %s: Paypal IPN response */ |
390 | - esc_html__( 'Invalid currency in IPN response. IPN data: %s', 'give' ), |
|
391 | - json_encode( $data ) |
|
390 | + esc_html__('Invalid currency in IPN response. IPN data: %s', 'give'), |
|
391 | + json_encode($data) |
|
392 | 392 | ), |
393 | 393 | $payment_id |
394 | 394 | ); |
395 | - give_update_payment_status( $payment_id, 'failed' ); |
|
396 | - give_insert_payment_note( $payment_id, esc_html__( 'Payment failed due to invalid currency in PayPal IPN.', 'give' ) ); |
|
395 | + give_update_payment_status($payment_id, 'failed'); |
|
396 | + give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid currency in PayPal IPN.', 'give')); |
|
397 | 397 | |
398 | 398 | return; |
399 | 399 | } |
400 | 400 | |
401 | - if ( ! give_get_payment_user_email( $payment_id ) ) { |
|
401 | + if ( ! give_get_payment_user_email($payment_id)) { |
|
402 | 402 | |
403 | 403 | // No email associated with purchase, so store from PayPal |
404 | - give_update_payment_meta( $payment_id, '_give_payment_user_email', $data['payer_email'] ); |
|
404 | + give_update_payment_meta($payment_id, '_give_payment_user_email', $data['payer_email']); |
|
405 | 405 | |
406 | 406 | // Setup and store the donors's details |
407 | 407 | $address = array(); |
408 | - $address['line1'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
409 | - $address['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
410 | - $address['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
411 | - $address['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
412 | - $address['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
408 | + $address['line1'] = ! empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
409 | + $address['city'] = ! empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
410 | + $address['state'] = ! empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
411 | + $address['country'] = ! empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
412 | + $address['zip'] = ! empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
413 | 413 | |
414 | 414 | $user_info = array( |
415 | 415 | 'id' => '-1', |
416 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
417 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
418 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
416 | + 'email' => sanitize_text_field($data['payer_email']), |
|
417 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
418 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
419 | 419 | 'discount' => '', |
420 | 420 | 'address' => $address |
421 | 421 | ); |
422 | 422 | |
423 | 423 | $payment_meta['user_info'] = $user_info; |
424 | - give_update_payment_meta( $payment_id, '_give_payment_meta', $payment_meta ); |
|
424 | + give_update_payment_meta($payment_id, '_give_payment_meta', $payment_meta); |
|
425 | 425 | } |
426 | 426 | |
427 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
427 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
428 | 428 | |
429 | 429 | // Process a refund |
430 | - give_process_paypal_refund( $data, $payment_id ); |
|
430 | + give_process_paypal_refund($data, $payment_id); |
|
431 | 431 | |
432 | 432 | } else { |
433 | 433 | |
434 | - if ( get_post_status( $payment_id ) == 'publish' ) { |
|
434 | + if (get_post_status($payment_id) == 'publish') { |
|
435 | 435 | return; // Only complete payments once |
436 | 436 | } |
437 | 437 | |
438 | 438 | // Retrieve the total purchase amount (before PayPal) |
439 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
439 | + $payment_amount = give_get_payment_amount($payment_id); |
|
440 | 440 | |
441 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
441 | + if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
442 | 442 | // The prices don't match |
443 | 443 | give_record_gateway_error( |
444 | - esc_html__( 'IPN Error', 'give' ), |
|
444 | + esc_html__('IPN Error', 'give'), |
|
445 | 445 | sprintf( |
446 | 446 | /* translators: %s: Paypal IPN response */ |
447 | - esc_html__( 'Invalid payment amount in IPN response. IPN data: %s', 'give' ), |
|
448 | - json_encode( $data ) |
|
447 | + esc_html__('Invalid payment amount in IPN response. IPN data: %s', 'give'), |
|
448 | + json_encode($data) |
|
449 | 449 | ), |
450 | 450 | $payment_id |
451 | 451 | ); |
452 | - give_update_payment_status( $payment_id, 'failed' ); |
|
453 | - give_insert_payment_note( $payment_id, esc_html__( 'Payment failed due to invalid amount in PayPal IPN.', 'give' ) ); |
|
452 | + give_update_payment_status($payment_id, 'failed'); |
|
453 | + give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid amount in PayPal IPN.', 'give')); |
|
454 | 454 | |
455 | 455 | return; |
456 | 456 | } |
457 | - if ( $purchase_key != give_get_payment_key( $payment_id ) ) { |
|
457 | + if ($purchase_key != give_get_payment_key($payment_id)) { |
|
458 | 458 | // Purchase keys don't match |
459 | 459 | give_record_gateway_error( |
460 | - esc_html__( 'IPN Error', 'give' ), |
|
460 | + esc_html__('IPN Error', 'give'), |
|
461 | 461 | sprintf( |
462 | 462 | /* translators: %s: Paypal IPN response */ |
463 | - esc_html__( 'Invalid purchase key in IPN response. IPN data: %s', 'give' ), |
|
464 | - json_encode( $data ) |
|
463 | + esc_html__('Invalid purchase key in IPN response. IPN data: %s', 'give'), |
|
464 | + json_encode($data) |
|
465 | 465 | ), |
466 | 466 | $payment_id |
467 | 467 | ); |
468 | - give_update_payment_status( $payment_id, 'failed' ); |
|
469 | - give_insert_payment_note( $payment_id, esc_html__( 'Payment failed due to invalid purchase key in PayPal IPN.', 'give' ) ); |
|
468 | + give_update_payment_status($payment_id, 'failed'); |
|
469 | + give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid purchase key in PayPal IPN.', 'give')); |
|
470 | 470 | |
471 | 471 | return; |
472 | 472 | } |
473 | 473 | |
474 | - if ( $payment_status == 'completed' || give_is_test_mode() ) { |
|
474 | + if ($payment_status == 'completed' || give_is_test_mode()) { |
|
475 | 475 | give_insert_payment_note( |
476 | 476 | $payment_id, |
477 | 477 | sprintf( |
478 | 478 | /* translators: %s: Paypal transaction ID */ |
479 | - esc_html__( 'PayPal Transaction ID: %s', 'give' ), |
|
479 | + esc_html__('PayPal Transaction ID: %s', 'give'), |
|
480 | 480 | $data['txn_id'] |
481 | 481 | ) |
482 | 482 | ); |
483 | - give_set_payment_transaction_id( $payment_id, $data['txn_id'] ); |
|
484 | - give_update_payment_status( $payment_id, 'publish' ); |
|
485 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
483 | + give_set_payment_transaction_id($payment_id, $data['txn_id']); |
|
484 | + give_update_payment_status($payment_id, 'publish'); |
|
485 | + } else if ('pending' == $payment_status && isset($data['pending_reason'])) { |
|
486 | 486 | |
487 | 487 | // Look for possible pending reasons, such as an echeck |
488 | 488 | |
489 | 489 | $note = ''; |
490 | 490 | |
491 | - switch ( strtolower( $data['pending_reason'] ) ) { |
|
491 | + switch (strtolower($data['pending_reason'])) { |
|
492 | 492 | |
493 | 493 | case 'echeck' : |
494 | 494 | |
495 | - $note = esc_html__( 'Payment made via eCheck and will clear automatically in 5-8 days.', 'give' ); |
|
495 | + $note = esc_html__('Payment made via eCheck and will clear automatically in 5-8 days.', 'give'); |
|
496 | 496 | |
497 | 497 | break; |
498 | 498 | |
499 | 499 | case 'address' : |
500 | 500 | |
501 | - $note = esc_html__( 'Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give' ); |
|
501 | + $note = esc_html__('Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give'); |
|
502 | 502 | |
503 | 503 | break; |
504 | 504 | |
505 | 505 | case 'intl' : |
506 | 506 | |
507 | - $note = esc_html__( 'Payment must be accepted manually through PayPal due to international account regulations.', 'give' ); |
|
507 | + $note = esc_html__('Payment must be accepted manually through PayPal due to international account regulations.', 'give'); |
|
508 | 508 | |
509 | 509 | break; |
510 | 510 | |
511 | 511 | case 'multi-currency' : |
512 | 512 | |
513 | - $note = esc_html__( 'Payment received in non-shop currency and must be accepted manually through PayPal.', 'give' ); |
|
513 | + $note = esc_html__('Payment received in non-shop currency and must be accepted manually through PayPal.', 'give'); |
|
514 | 514 | |
515 | 515 | break; |
516 | 516 | |
517 | 517 | case 'paymentreview' : |
518 | 518 | case 'regulatory_review' : |
519 | 519 | |
520 | - $note = esc_html__( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give' ); |
|
520 | + $note = esc_html__('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give'); |
|
521 | 521 | |
522 | 522 | break; |
523 | 523 | |
524 | 524 | case 'unilateral' : |
525 | 525 | |
526 | - $note = esc_html__( 'Payment was sent to non-confirmed or non-registered email address.', 'give' ); |
|
526 | + $note = esc_html__('Payment was sent to non-confirmed or non-registered email address.', 'give'); |
|
527 | 527 | |
528 | 528 | break; |
529 | 529 | |
530 | 530 | case 'upgrade' : |
531 | 531 | |
532 | - $note = esc_html__( 'PayPal account must be upgraded before this payment can be accepted.', 'give' ); |
|
532 | + $note = esc_html__('PayPal account must be upgraded before this payment can be accepted.', 'give'); |
|
533 | 533 | |
534 | 534 | break; |
535 | 535 | |
536 | 536 | case 'verify' : |
537 | 537 | |
538 | - $note = esc_html__( 'PayPal account is not verified. Verify account in order to accept this payment.', 'give' ); |
|
538 | + $note = esc_html__('PayPal account is not verified. Verify account in order to accept this payment.', 'give'); |
|
539 | 539 | |
540 | 540 | break; |
541 | 541 | |
542 | 542 | case 'other' : |
543 | 543 | |
544 | - $note = esc_html__( 'Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give' ); |
|
544 | + $note = esc_html__('Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give'); |
|
545 | 545 | |
546 | 546 | break; |
547 | 547 | |
548 | 548 | } |
549 | 549 | |
550 | - if ( ! empty( $note ) ) { |
|
550 | + if ( ! empty($note)) { |
|
551 | 551 | |
552 | - give_insert_payment_note( $payment_id, $note ); |
|
552 | + give_insert_payment_note($payment_id, $note); |
|
553 | 553 | |
554 | 554 | } |
555 | 555 | } |
556 | 556 | } |
557 | 557 | } |
558 | 558 | |
559 | -add_action( 'give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2 ); |
|
559 | +add_action('give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2); |
|
560 | 560 | |
561 | 561 | /** |
562 | 562 | * Process PayPal IPN Refunds |
@@ -567,28 +567,28 @@ discard block |
||
567 | 567 | * |
568 | 568 | * @return void |
569 | 569 | */ |
570 | -function give_process_paypal_refund( $data, $payment_id = 0 ) { |
|
570 | +function give_process_paypal_refund($data, $payment_id = 0) { |
|
571 | 571 | |
572 | 572 | // Collect payment details |
573 | 573 | |
574 | - if ( empty( $payment_id ) ) { |
|
574 | + if (empty($payment_id)) { |
|
575 | 575 | return; |
576 | 576 | } |
577 | 577 | |
578 | - if ( get_post_status( $payment_id ) == 'refunded' ) { |
|
578 | + if (get_post_status($payment_id) == 'refunded') { |
|
579 | 579 | return; // Only refund payments once |
580 | 580 | } |
581 | 581 | |
582 | - $payment_amount = give_get_payment_amount( $payment_id ); |
|
582 | + $payment_amount = give_get_payment_amount($payment_id); |
|
583 | 583 | $refund_amount = $data['payment_gross'] * - 1; |
584 | 584 | |
585 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
585 | + if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) { |
|
586 | 586 | |
587 | 587 | give_insert_payment_note( |
588 | 588 | $payment_id, |
589 | 589 | sprintf( |
590 | 590 | /* translators: %s: Paypal parent transaction ID */ |
591 | - esc_html__( 'Partial PayPal refund processed: %s', 'give' ), |
|
591 | + esc_html__('Partial PayPal refund processed: %s', 'give'), |
|
592 | 592 | $data['parent_txn_id'] |
593 | 593 | ) |
594 | 594 | ); |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | $payment_id, |
602 | 602 | sprintf( |
603 | 603 | /* translators: %s: Paypal parent transaction ID */ |
604 | - esc_html__( 'PayPal Payment #%s Refunded for reason: %s', 'give' ), |
|
604 | + esc_html__('PayPal Payment #%s Refunded for reason: %s', 'give'), |
|
605 | 605 | $data['parent_txn_id'], $data['reason_code'] |
606 | 606 | ) |
607 | 607 | ); |
@@ -609,11 +609,11 @@ discard block |
||
609 | 609 | $payment_id, |
610 | 610 | sprintf( |
611 | 611 | /* translators: %s: Paypal transaction ID */ |
612 | - esc_html__( 'PayPal Refund Transaction ID: %s', 'give' ), |
|
612 | + esc_html__('PayPal Refund Transaction ID: %s', 'give'), |
|
613 | 613 | $data['txn_id'] |
614 | 614 | ) |
615 | 615 | ); |
616 | - give_update_payment_status( $payment_id, 'refunded' ); |
|
616 | + give_update_payment_status($payment_id, 'refunded'); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
@@ -625,24 +625,24 @@ discard block |
||
625 | 625 | * |
626 | 626 | * @return string |
627 | 627 | */ |
628 | -function give_get_paypal_redirect( $ssl_check = false ) { |
|
628 | +function give_get_paypal_redirect($ssl_check = false) { |
|
629 | 629 | |
630 | - if ( is_ssl() || ! $ssl_check ) { |
|
630 | + if (is_ssl() || ! $ssl_check) { |
|
631 | 631 | $protocal = 'https://'; |
632 | 632 | } else { |
633 | 633 | $protocal = 'http://'; |
634 | 634 | } |
635 | 635 | |
636 | 636 | // Check the current payment mode |
637 | - if ( give_is_test_mode() ) { |
|
637 | + if (give_is_test_mode()) { |
|
638 | 638 | // Test mode |
639 | - $paypal_uri = $protocal . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
|
639 | + $paypal_uri = $protocal.'www.sandbox.paypal.com/cgi-bin/webscr'; |
|
640 | 640 | } else { |
641 | 641 | // Live mode |
642 | - $paypal_uri = $protocal . 'www.paypal.com/cgi-bin/webscr'; |
|
642 | + $paypal_uri = $protocal.'www.paypal.com/cgi-bin/webscr'; |
|
643 | 643 | } |
644 | 644 | |
645 | - return apply_filters( 'give_paypal_uri', $paypal_uri ); |
|
645 | + return apply_filters('give_paypal_uri', $paypal_uri); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | /** |
@@ -652,9 +652,9 @@ discard block |
||
652 | 652 | * @return string |
653 | 653 | */ |
654 | 654 | function give_get_paypal_page_style() { |
655 | - $page_style = trim( give_get_option( 'paypal_page_style', 'PayPal' ) ); |
|
655 | + $page_style = trim(give_get_option('paypal_page_style', 'PayPal')); |
|
656 | 656 | |
657 | - return apply_filters( 'give_paypal_page_style', $page_style ); |
|
657 | + return apply_filters('give_paypal_page_style', $page_style); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -669,27 +669,27 @@ discard block |
||
669 | 669 | * @return string |
670 | 670 | * |
671 | 671 | */ |
672 | -function give_paypal_success_page_content( $content ) { |
|
672 | +function give_paypal_success_page_content($content) { |
|
673 | 673 | |
674 | - if ( ! isset( $_GET['payment-id'] ) && ! give_get_purchase_session() ) { |
|
674 | + if ( ! isset($_GET['payment-id']) && ! give_get_purchase_session()) { |
|
675 | 675 | return $content; |
676 | 676 | } |
677 | 677 | |
678 | - $payment_id = isset( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : false; |
|
678 | + $payment_id = isset($_GET['payment-id']) ? absint($_GET['payment-id']) : false; |
|
679 | 679 | |
680 | - if ( ! $payment_id ) { |
|
680 | + if ( ! $payment_id) { |
|
681 | 681 | $session = give_get_purchase_session(); |
682 | - $payment_id = give_get_purchase_id_by_key( $session['purchase_key'] ); |
|
682 | + $payment_id = give_get_purchase_id_by_key($session['purchase_key']); |
|
683 | 683 | } |
684 | 684 | |
685 | - $payment = get_post( $payment_id ); |
|
685 | + $payment = get_post($payment_id); |
|
686 | 686 | |
687 | - if ( $payment && 'pending' == $payment->post_status ) { |
|
687 | + if ($payment && 'pending' == $payment->post_status) { |
|
688 | 688 | |
689 | 689 | // Payment is still pending so show processing indicator to fix the Race Condition |
690 | 690 | ob_start(); |
691 | 691 | |
692 | - give_get_template_part( 'payment', 'processing' ); |
|
692 | + give_get_template_part('payment', 'processing'); |
|
693 | 693 | |
694 | 694 | $content = ob_get_clean(); |
695 | 695 | |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | |
700 | 700 | } |
701 | 701 | |
702 | -add_filter( 'give_payment_confirm_paypal', 'give_paypal_success_page_content' ); |
|
702 | +add_filter('give_payment_confirm_paypal', 'give_paypal_success_page_content'); |
|
703 | 703 | |
704 | 704 | /** |
705 | 705 | * Given a Payment ID, extract the transaction ID |
@@ -710,22 +710,22 @@ discard block |
||
710 | 710 | * |
711 | 711 | * @return string Transaction ID |
712 | 712 | */ |
713 | -function give_paypal_get_payment_transaction_id( $payment_id ) { |
|
713 | +function give_paypal_get_payment_transaction_id($payment_id) { |
|
714 | 714 | |
715 | 715 | $transaction_id = ''; |
716 | - $notes = give_get_payment_notes( $payment_id ); |
|
716 | + $notes = give_get_payment_notes($payment_id); |
|
717 | 717 | |
718 | - foreach ( $notes as $note ) { |
|
719 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
718 | + foreach ($notes as $note) { |
|
719 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
720 | 720 | $transaction_id = $match[1]; |
721 | 721 | continue; |
722 | 722 | } |
723 | 723 | } |
724 | 724 | |
725 | - return apply_filters( 'give_paypal_set_payment_transaction_id', $transaction_id, $payment_id ); |
|
725 | + return apply_filters('give_paypal_set_payment_transaction_id', $transaction_id, $payment_id); |
|
726 | 726 | } |
727 | 727 | |
728 | -add_filter( 'give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1 ); |
|
728 | +add_filter('give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1); |
|
729 | 729 | |
730 | 730 | /** |
731 | 731 | * Given a transaction ID, generate a link to the PayPal transaction ID details |
@@ -737,13 +737,13 @@ discard block |
||
737 | 737 | * |
738 | 738 | * @return string A link to the PayPal transaction details |
739 | 739 | */ |
740 | -function give_paypal_link_transaction_id( $transaction_id, $payment_id ) { |
|
740 | +function give_paypal_link_transaction_id($transaction_id, $payment_id) { |
|
741 | 741 | |
742 | 742 | $paypal_base_url = 'https://history.paypal.com/cgi-bin/webscr?cmd=_history-details-from-hub&id='; |
743 | - $transaction_url = '<a href="' . esc_url( $paypal_base_url . $transaction_id ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
743 | + $transaction_url = '<a href="'.esc_url($paypal_base_url.$transaction_id).'" target="_blank">'.$transaction_id.'</a>'; |
|
744 | 744 | |
745 | - return apply_filters( 'give_paypal_link_payment_details_transaction_id', $transaction_url ); |
|
745 | + return apply_filters('give_paypal_link_payment_details_transaction_id', $transaction_url); |
|
746 | 746 | |
747 | 747 | } |
748 | 748 | |
749 | -add_filter( 'give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2 ); |
|
749 | +add_filter('give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2); |