Completed
Pull Request — master (#1155)
by Devin
18:24
created
includes/gateways/paypal-standard.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -661,7 +661,7 @@
 block discarded – undo
661 661
  *
662 662
  * @since 1.6.3
663 663
  *
664
- * @param $pending_reason
664
+ * @param string $pending_reason
665 665
  *
666 666
  * @return string
667 667
  */
Please login to merge, or discard this patch.
Spacing   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,101 +57,101 @@  discard block
 block discarded – undo
57 57
 	);
58 58
 
59 59
 	// Record the pending payment.
60
-	$payment_id = give_insert_payment( $payment_data );
60
+	$payment_id = give_insert_payment($payment_data);
61 61
 
62 62
 	// Check payment.
63
-	if ( ! $payment_id ) {
63
+	if ( ! $payment_id) {
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 donor to PayPal. Payment data: %s', 'give' ),
70
-				json_encode( $payment_data )
69
+				esc_html__('Payment creation failed before sending donor to PayPal. Payment data: %s', 'give'),
70
+				json_encode($payment_data)
71 71
 			),
72 72
 			$payment_id
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_id
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 API params.
121 121
 		$paypal_args = array(
122
-			'business'      => give_get_option( 'paypal_email', false ),
122
+			'business'      => give_get_option('paypal_email', false),
123 123
 			'first_name'    => $purchase_data['user_info']['first_name'],
124 124
 			'last_name'     => $purchase_data['user_info']['last_name'],
125 125
 			'email'         => $purchase_data['user_email'],
126 126
 			'invoice'       => $purchase_data['purchase_key'],
127 127
 			'amount'        => $purchase_data['price'],
128
-			'item_name'     => stripslashes( $item_name ),
128
+			'item_name'     => stripslashes($item_name),
129 129
 			'no_shipping'   => '1',
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_id,
135 135
 			'rm'            => '2',
136 136
 			'return'        => $return_url,
137
-			'cancel_return' => give_get_failed_transaction_uri( '?payment-id=' . $payment_id ),
137
+			'cancel_return' => give_get_failed_transaction_uri('?payment-id='.$payment_id),
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 144
 		//Add user address if present.
145
-		if ( ! empty( $purchase_data['user_info']['address'] ) ) {
146
-			$paypal_args['address1'] = isset( $purchase_data['user_info']['address']['line1'] ) ? $purchase_data['user_info']['address']['line1'] : '';
147
-			$paypal_args['address2'] = isset( $purchase_data['user_info']['address']['line2'] ) ? $purchase_data['user_info']['address']['line2'] : '';
148
-			$paypal_args['city']     = isset( $purchase_data['user_info']['address']['city'] ) ? $purchase_data['user_info']['address']['city'] : '';
149
-			$paypal_args['state']    = isset( $purchase_data['user_info']['address']['state'] ) ? $purchase_data['user_info']['address']['state'] : '';
150
-			$paypal_args['country']  = isset( $purchase_data['user_info']['address']['country'] ) ? $purchase_data['user_info']['address']['country'] : '';
145
+		if ( ! empty($purchase_data['user_info']['address'])) {
146
+			$paypal_args['address1'] = isset($purchase_data['user_info']['address']['line1']) ? $purchase_data['user_info']['address']['line1'] : '';
147
+			$paypal_args['address2'] = isset($purchase_data['user_info']['address']['line2']) ? $purchase_data['user_info']['address']['line2'] : '';
148
+			$paypal_args['city']     = isset($purchase_data['user_info']['address']['city']) ? $purchase_data['user_info']['address']['city'] : '';
149
+			$paypal_args['state']    = isset($purchase_data['user_info']['address']['state']) ? $purchase_data['user_info']['address']['state'] : '';
150
+			$paypal_args['country']  = isset($purchase_data['user_info']['address']['country']) ? $purchase_data['user_info']['address']['country'] : '';
151 151
 		}
152 152
 
153 153
 		//Donations or regular transactions?
154
-		if ( give_get_option( 'paypal_button_type' ) === 'standard' ) {
154
+		if (give_get_option('paypal_button_type') === 'standard') {
155 155
 			$paypal_extra_args = array(
156 156
 				'cmd' => '_xclick',
157 157
 			);
@@ -161,23 +161,23 @@  discard block
 block discarded – undo
161 161
 			);
162 162
 		}
163 163
 
164
-		$paypal_args = array_merge( $paypal_extra_args, $paypal_args );
165
-		$paypal_args = apply_filters( 'give_paypal_redirect_args', $paypal_args, $purchase_data );
164
+		$paypal_args = array_merge($paypal_extra_args, $paypal_args);
165
+		$paypal_args = apply_filters('give_paypal_redirect_args', $paypal_args, $purchase_data);
166 166
 
167 167
 		// Build query.
168
-		$paypal_redirect .= http_build_query( $paypal_args );
168
+		$paypal_redirect .= http_build_query($paypal_args);
169 169
 
170 170
 		// Fix for some sites that encode the entities.
171
-		$paypal_redirect = str_replace( '&', '&', $paypal_redirect );
171
+		$paypal_redirect = str_replace('&', '&', $paypal_redirect);
172 172
 
173 173
 		// Redirect to PayPal.
174
-		wp_redirect( $paypal_redirect );
174
+		wp_redirect($paypal_redirect);
175 175
 		exit;
176 176
 	}
177 177
 
178 178
 }
179 179
 
180
-add_action( 'give_gateway_paypal', 'give_process_paypal_purchase' );
180
+add_action('give_gateway_paypal', 'give_process_paypal_purchase');
181 181
 
182 182
 /**
183 183
  * Listens for a PayPal IPN requests and then sends to the processing function
@@ -187,12 +187,12 @@  discard block
 block discarded – undo
187 187
  */
188 188
 function give_listen_for_paypal_ipn() {
189 189
 	// Regular PayPal IPN
190
-	if ( isset( $_GET['give-listener'] ) && $_GET['give-listener'] == 'IPN' ) {
191
-		do_action( 'give_verify_paypal_ipn' );
190
+	if (isset($_GET['give-listener']) && $_GET['give-listener'] == 'IPN') {
191
+		do_action('give_verify_paypal_ipn');
192 192
 	}
193 193
 }
194 194
 
195
-add_action( 'init', 'give_listen_for_paypal_ipn' );
195
+add_action('init', 'give_listen_for_paypal_ipn');
196 196
 
197 197
 /**
198 198
  * Process PayPal IPN
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 function give_process_paypal_ipn() {
204 204
 
205 205
 	// Check the request method is POST
206
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
206
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
207 207
 		return;
208 208
 	}
209 209
 
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
 	$post_data = '';
212 212
 
213 213
 	// Fallback just in case post_max_size is lower than needed
214
-	if ( ini_get( 'allow_url_fopen' ) ) {
215
-		$post_data = file_get_contents( 'php://input' );
214
+	if (ini_get('allow_url_fopen')) {
215
+		$post_data = file_get_contents('php://input');
216 216
 	} else {
217 217
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
218
-		ini_set( 'post_max_size', '12M' );
218
+		ini_set('post_max_size', '12M');
219 219
 	}
220 220
 	// Start the encoded data collection with notification command
221 221
 	$encoded_data = 'cmd=_notify-validate';
@@ -224,40 +224,40 @@  discard block
 block discarded – undo
224 224
 	$arg_separator = give_get_php_arg_separator_output();
225 225
 
226 226
 	// Verify there is a post_data
227
-	if ( $post_data || strlen( $post_data ) > 0 ) {
227
+	if ($post_data || strlen($post_data) > 0) {
228 228
 		// Append the data
229
-		$encoded_data .= $arg_separator . $post_data;
229
+		$encoded_data .= $arg_separator.$post_data;
230 230
 	} else {
231 231
 		// Check if POST is empty
232
-		if ( empty( $_POST ) ) {
232
+		if (empty($_POST)) {
233 233
 			// Nothing to do
234 234
 			return;
235 235
 		} else {
236 236
 			// Loop through each POST
237
-			foreach ( $_POST as $key => $value ) {
237
+			foreach ($_POST as $key => $value) {
238 238
 				// Encode the value and append the data.
239
-				$encoded_data .= $arg_separator . "$key=" . urlencode( $value );
239
+				$encoded_data .= $arg_separator."$key=".urlencode($value);
240 240
 			}
241 241
 		}
242 242
 	}
243 243
 
244 244
 	// Convert collected post data to an array.
245
-	parse_str( $encoded_data, $encoded_data_array );
245
+	parse_str($encoded_data, $encoded_data_array);
246 246
 
247
-	foreach ( $encoded_data_array as $key => $value ) {
247
+	foreach ($encoded_data_array as $key => $value) {
248 248
 
249
-		if ( false !== strpos( $key, 'amp;' ) ) {
250
-			$new_key = str_replace( '&', '&', $key );
251
-			$new_key = str_replace( 'amp;', '&', $new_key );
249
+		if (false !== strpos($key, 'amp;')) {
250
+			$new_key = str_replace('&', '&', $key);
251
+			$new_key = str_replace('amp;', '&', $new_key);
252 252
 
253
-			unset( $encoded_data_array[ $key ] );
254
-			$encoded_data_array[ $new_key ] = $value;
253
+			unset($encoded_data_array[$key]);
254
+			$encoded_data_array[$new_key] = $value;
255 255
 		}
256 256
 
257 257
 	}
258 258
 
259 259
 	//Validate IPN request w/ PayPal if user hasn't disabled this security measure.
260
-	if ( ! give_get_option( 'disable_paypal_verification' ) ) {
260
+	if ( ! give_get_option('disable_paypal_verification')) {
261 261
 
262 262
 		$remote_post_vars = array(
263 263
 			'method'      => 'POST',
@@ -277,28 +277,28 @@  discard block
 block discarded – undo
277 277
 		);
278 278
 
279 279
 		// Validate the IPN.
280
-		$api_response = wp_remote_post( give_get_paypal_redirect(), $remote_post_vars );
280
+		$api_response = wp_remote_post(give_get_paypal_redirect(), $remote_post_vars);
281 281
 
282
-		if ( is_wp_error( $api_response ) ) {
282
+		if (is_wp_error($api_response)) {
283 283
 			give_record_gateway_error(
284
-				esc_html__( 'IPN Error', 'give' ),
284
+				esc_html__('IPN Error', 'give'),
285 285
 				sprintf(
286 286
 				/* translators: %s: Paypal IPN response */
287
-					esc_html__( 'Invalid IPN verification response. IPN data: %s', 'give' ),
288
-					json_encode( $api_response )
287
+					esc_html__('Invalid IPN verification response. IPN data: %s', 'give'),
288
+					json_encode($api_response)
289 289
 				)
290 290
 			);
291 291
 
292 292
 			return; // Something went wrong
293 293
 		}
294 294
 
295
-		if ( $api_response['body'] !== 'VERIFIED' && give_get_option( 'disable_paypal_verification', false ) ) {
295
+		if ($api_response['body'] !== 'VERIFIED' && give_get_option('disable_paypal_verification', false)) {
296 296
 			give_record_gateway_error(
297
-				esc_html__( 'IPN Error', 'give' ),
297
+				esc_html__('IPN Error', 'give'),
298 298
 				sprintf(
299 299
 				/* translators: %s: Paypal IPN response */
300
-					esc_html__( 'Invalid IPN verification response. IPN data: %s', 'give' ),
301
-					json_encode( $api_response )
300
+					esc_html__('Invalid IPN verification response. IPN data: %s', 'give'),
301
+					json_encode($api_response)
302 302
 				)
303 303
 			);
304 304
 
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	}
309 309
 
310 310
 	// Check if $post_data_array has been populated
311
-	if ( ! is_array( $encoded_data_array ) && ! empty( $encoded_data_array ) ) {
311
+	if ( ! is_array($encoded_data_array) && ! empty($encoded_data_array)) {
312 312
 		return;
313 313
 	}
314 314
 
@@ -317,21 +317,21 @@  discard block
 block discarded – undo
317 317
 		'payment_status' => ''
318 318
 	);
319 319
 
320
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
321 321
 
322
-	$payment_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
322
+	$payment_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
323 323
 
324
-	if ( has_action( 'give_paypal_' . $encoded_data_array['txn_type'] ) ) {
324
+	if (has_action('give_paypal_'.$encoded_data_array['txn_type'])) {
325 325
 		// Allow PayPal IPN types to be processed separately.
326
-		do_action( 'give_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $payment_id );
326
+		do_action('give_paypal_'.$encoded_data_array['txn_type'], $encoded_data_array, $payment_id);
327 327
 	} else {
328 328
 		// Fallback to web accept just in case the txn_type isn't present.
329
-		do_action( 'give_paypal_web_accept', $encoded_data_array, $payment_id );
329
+		do_action('give_paypal_web_accept', $encoded_data_array, $payment_id);
330 330
 	}
331 331
 	exit;
332 332
 }
333 333
 
334
-add_action( 'give_verify_paypal_ipn', 'give_process_paypal_ipn' );
334
+add_action('give_verify_paypal_ipn', 'give_process_paypal_ipn');
335 335
 
336 336
 /**
337 337
  * Process web accept (one time) payment IPNs.
@@ -343,127 +343,127 @@  discard block
 block discarded – undo
343 343
  *
344 344
  * @return void
345 345
  */
346
-function give_process_paypal_web_accept_and_cart( $data, $payment_id ) {
346
+function give_process_paypal_web_accept_and_cart($data, $payment_id) {
347 347
 
348 348
 	//Only allow through these transaction types.
349
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && strtolower( $data['payment_status'] ) != 'refunded' ) {
349
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && strtolower($data['payment_status']) != 'refunded') {
350 350
 		return;
351 351
 	}
352 352
 
353 353
 	//Need $payment_id to continue.
354
-	if ( empty( $payment_id ) ) {
354
+	if (empty($payment_id)) {
355 355
 		return;
356 356
 	}
357 357
 
358 358
 	// Collect donation payment details.
359 359
 	$paypal_amount  = $data['mc_gross'];
360
-	$payment_status = strtolower( $data['payment_status'] );
361
-	$currency_code  = strtolower( $data['mc_currency'] );
362
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
363
-	$payment_meta   = give_get_payment_meta( $payment_id );
360
+	$payment_status = strtolower($data['payment_status']);
361
+	$currency_code  = strtolower($data['mc_currency']);
362
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
363
+	$payment_meta   = give_get_payment_meta($payment_id);
364 364
 
365 365
 	// Must be a PayPal standard IPN.
366
-	if ( give_get_payment_gateway( $payment_id ) != 'paypal' ) {
366
+	if (give_get_payment_gateway($payment_id) != 'paypal') {
367 367
 		return;
368 368
 	}
369 369
 
370 370
 	// Verify payment recipient
371
-	if ( strcasecmp( $business_email, trim( give_get_option( 'paypal_email' ) ) ) != 0 ) {
371
+	if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) != 0) {
372 372
 
373 373
 		give_record_gateway_error(
374
-			esc_html__( 'IPN Error', 'give' ),
374
+			esc_html__('IPN Error', 'give'),
375 375
 			sprintf(
376 376
 			/* translators: %s: Paypal IPN response */
377
-				esc_html__( 'Invalid business email in IPN response. IPN data: %s', 'give' ),
378
-				json_encode( $data )
377
+				esc_html__('Invalid business email in IPN response. IPN data: %s', 'give'),
378
+				json_encode($data)
379 379
 			),
380 380
 			$payment_id
381 381
 		);
382
-		give_update_payment_status( $payment_id, 'failed' );
383
-		give_insert_payment_note( $payment_id, esc_html__( 'Payment failed due to invalid PayPal business email.', 'give' ) );
382
+		give_update_payment_status($payment_id, 'failed');
383
+		give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid PayPal business email.', 'give'));
384 384
 
385 385
 		return;
386 386
 	}
387 387
 
388 388
 	// Verify payment currency.
389
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
389
+	if ($currency_code != strtolower($payment_meta['currency'])) {
390 390
 
391 391
 		give_record_gateway_error(
392
-			esc_html__( 'IPN Error', 'give' ),
392
+			esc_html__('IPN Error', 'give'),
393 393
 			sprintf(
394 394
 			/* translators: %s: Paypal IPN response */
395
-				esc_html__( 'Invalid currency in IPN response. IPN data: %s', 'give' ),
396
-				json_encode( $data )
395
+				esc_html__('Invalid currency in IPN response. IPN data: %s', 'give'),
396
+				json_encode($data)
397 397
 			),
398 398
 			$payment_id
399 399
 		);
400
-		give_update_payment_status( $payment_id, 'failed' );
401
-		give_insert_payment_note( $payment_id, esc_html__( 'Payment failed due to invalid currency in PayPal IPN.', 'give' ) );
400
+		give_update_payment_status($payment_id, 'failed');
401
+		give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid currency in PayPal IPN.', 'give'));
402 402
 
403 403
 		return;
404 404
 	}
405 405
 
406 406
 	//Process refunds & reversed.
407
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
408
-		give_process_paypal_refund( $data, $payment_id );
407
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
408
+		give_process_paypal_refund($data, $payment_id);
409 409
 		return;
410 410
 	}
411 411
 
412 412
 	// Only complete payments once.
413
-	if ( get_post_status( $payment_id ) == 'publish' ) {
413
+	if (get_post_status($payment_id) == 'publish') {
414 414
 		return;
415 415
 	}
416 416
 
417 417
 	// Retrieve the total donation amount (before PayPal).
418
-	$payment_amount = give_get_payment_amount( $payment_id );
418
+	$payment_amount = give_get_payment_amount($payment_id);
419 419
 
420 420
 	//Check that the donation PP and local db amounts match.
421
-	if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
421
+	if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) {
422 422
 		// The prices don't match
423 423
 		give_record_gateway_error(
424
-			esc_html__( 'IPN Error', 'give' ),
424
+			esc_html__('IPN Error', 'give'),
425 425
 			sprintf(
426 426
 			/* translators: %s: Paypal IPN response */
427
-				esc_html__( 'Invalid payment amount in IPN response. IPN data: %s', 'give' ),
428
-				json_encode( $data )
427
+				esc_html__('Invalid payment amount in IPN response. IPN data: %s', 'give'),
428
+				json_encode($data)
429 429
 			),
430 430
 			$payment_id
431 431
 		);
432
-		give_update_payment_status( $payment_id, 'failed' );
433
-		give_insert_payment_note( $payment_id, esc_html__( 'Payment failed due to invalid amount in PayPal IPN.', 'give' ) );
432
+		give_update_payment_status($payment_id, 'failed');
433
+		give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid amount in PayPal IPN.', 'give'));
434 434
 
435 435
 		return;
436 436
 	}
437 437
 
438 438
 	//Process completed donations.
439
-	if ( $payment_status == 'completed' || give_is_test_mode() ) {
439
+	if ($payment_status == 'completed' || give_is_test_mode()) {
440 440
 
441 441
 		give_insert_payment_note(
442 442
 			$payment_id,
443 443
 			sprintf(
444 444
 			/* translators: %s: Paypal transaction ID */
445
-				esc_html__( 'PayPal Transaction ID: %s', 'give' ),
445
+				esc_html__('PayPal Transaction ID: %s', 'give'),
446 446
 				$data['txn_id']
447 447
 			)
448 448
 		);
449
-		give_set_payment_transaction_id( $payment_id, $data['txn_id'] );
450
-		give_update_payment_status( $payment_id, 'publish' );
449
+		give_set_payment_transaction_id($payment_id, $data['txn_id']);
450
+		give_update_payment_status($payment_id, 'publish');
451 451
 
452
-	} elseif ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
452
+	} elseif ('pending' == $payment_status && isset($data['pending_reason'])) {
453 453
 
454 454
 		// Look for possible pending reasons, such as an echeck.
455
-		$note = give_paypal_get_pending_donation_note( strtolower( $data['pending_reason'] ) );
455
+		$note = give_paypal_get_pending_donation_note(strtolower($data['pending_reason']));
456 456
 
457
-		if ( ! empty( $note ) ) {
457
+		if ( ! empty($note)) {
458 458
 
459
-			give_insert_payment_note( $payment_id, $note );
459
+			give_insert_payment_note($payment_id, $note);
460 460
 
461 461
 		}
462 462
 	}
463 463
 
464 464
 }
465 465
 
466
-add_action( 'give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2 );
466
+add_action('give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2);
467 467
 
468 468
 /**
469 469
  * Process PayPal IPN Refunds
@@ -475,28 +475,28 @@  discard block
 block discarded – undo
475 475
  *
476 476
  * @return void
477 477
  */
478
-function give_process_paypal_refund( $data, $payment_id = 0 ) {
478
+function give_process_paypal_refund($data, $payment_id = 0) {
479 479
 
480 480
 	// Collect payment details
481 481
 
482
-	if ( empty( $payment_id ) ) {
482
+	if (empty($payment_id)) {
483 483
 		return;
484 484
 	}
485 485
 
486
-	if ( get_post_status( $payment_id ) == 'refunded' ) {
486
+	if (get_post_status($payment_id) == 'refunded') {
487 487
 		return; // Only refund payments once
488 488
 	}
489 489
 
490
-	$payment_amount = give_get_payment_amount( $payment_id );
490
+	$payment_amount = give_get_payment_amount($payment_id);
491 491
 	$refund_amount  = $data['payment_gross'] * - 1;
492 492
 
493
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
493
+	if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) {
494 494
 
495 495
 		give_insert_payment_note(
496 496
 			$payment_id,
497 497
 			sprintf(
498 498
 			/* translators: %s: Paypal parent transaction ID */
499
-				esc_html__( 'Partial PayPal refund processed: %s', 'give' ),
499
+				esc_html__('Partial PayPal refund processed: %s', 'give'),
500 500
 				$data['parent_txn_id']
501 501
 			)
502 502
 		);
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 		$payment_id,
510 510
 		sprintf(
511 511
 		/* translators: %s: Paypal parent transaction ID */
512
-			esc_html__( 'PayPal Payment #%s Refunded for reason: %s', 'give' ),
512
+			esc_html__('PayPal Payment #%s Refunded for reason: %s', 'give'),
513 513
 			$data['parent_txn_id'], $data['reason_code']
514 514
 		)
515 515
 	);
@@ -517,11 +517,11 @@  discard block
 block discarded – undo
517 517
 		$payment_id,
518 518
 		sprintf(
519 519
 		/* translators: %s: Paypal transaction ID */
520
-			esc_html__( 'PayPal Refund Transaction ID: %s', 'give' ),
520
+			esc_html__('PayPal Refund Transaction ID: %s', 'give'),
521 521
 			$data['txn_id']
522 522
 		)
523 523
 	);
524
-	give_update_payment_status( $payment_id, 'refunded' );
524
+	give_update_payment_status($payment_id, 'refunded');
525 525
 }
526 526
 
527 527
 /**
@@ -533,24 +533,24 @@  discard block
 block discarded – undo
533 533
  *
534 534
  * @return string
535 535
  */
536
-function give_get_paypal_redirect( $ssl_check = false ) {
536
+function give_get_paypal_redirect($ssl_check = false) {
537 537
 
538
-	if ( is_ssl() || ! $ssl_check ) {
538
+	if (is_ssl() || ! $ssl_check) {
539 539
 		$protocal = 'https://';
540 540
 	} else {
541 541
 		$protocal = 'http://';
542 542
 	}
543 543
 
544 544
 	// Check the current payment mode
545
-	if ( give_is_test_mode() ) {
545
+	if (give_is_test_mode()) {
546 546
 		// Test mode
547
-		$paypal_uri = $protocal . 'www.sandbox.paypal.com/cgi-bin/webscr';
547
+		$paypal_uri = $protocal.'www.sandbox.paypal.com/cgi-bin/webscr';
548 548
 	} else {
549 549
 		// Live mode
550
-		$paypal_uri = $protocal . 'www.paypal.com/cgi-bin/webscr';
550
+		$paypal_uri = $protocal.'www.paypal.com/cgi-bin/webscr';
551 551
 	}
552 552
 
553
-	return apply_filters( 'give_paypal_uri', $paypal_uri );
553
+	return apply_filters('give_paypal_uri', $paypal_uri);
554 554
 }
555 555
 
556 556
 /**
@@ -560,9 +560,9 @@  discard block
 block discarded – undo
560 560
  * @return string
561 561
  */
562 562
 function give_get_paypal_page_style() {
563
-	$page_style = trim( give_get_option( 'paypal_page_style', 'PayPal' ) );
563
+	$page_style = trim(give_get_option('paypal_page_style', 'PayPal'));
564 564
 
565
-	return apply_filters( 'give_paypal_page_style', $page_style );
565
+	return apply_filters('give_paypal_page_style', $page_style);
566 566
 }
567 567
 
568 568
 /**
@@ -577,26 +577,26 @@  discard block
 block discarded – undo
577 577
  * @return string
578 578
  *
579 579
  */
580
-function give_paypal_success_page_content( $content ) {
580
+function give_paypal_success_page_content($content) {
581 581
 
582
-	if ( ! isset( $_GET['payment-id'] ) && ! give_get_purchase_session() ) {
582
+	if ( ! isset($_GET['payment-id']) && ! give_get_purchase_session()) {
583 583
 		return $content;
584 584
 	}
585 585
 
586
-	$payment_id = isset( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : false;
586
+	$payment_id = isset($_GET['payment-id']) ? absint($_GET['payment-id']) : false;
587 587
 
588
-	if ( ! $payment_id ) {
588
+	if ( ! $payment_id) {
589 589
 		$session    = give_get_purchase_session();
590
-		$payment_id = give_get_purchase_id_by_key( $session['purchase_key'] );
590
+		$payment_id = give_get_purchase_id_by_key($session['purchase_key']);
591 591
 	}
592 592
 
593
-	$payment = get_post( $payment_id );
594
-	if ( $payment && 'pending' == $payment->post_status ) {
593
+	$payment = get_post($payment_id);
594
+	if ($payment && 'pending' == $payment->post_status) {
595 595
 
596 596
 		// Payment is still pending so show processing indicator to fix the race condition.
597 597
 		ob_start();
598 598
 
599
-		give_get_template_part( 'payment', 'processing' );
599
+		give_get_template_part('payment', 'processing');
600 600
 
601 601
 		$content = ob_get_clean();
602 602
 
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 
607 607
 }
608 608
 
609
-add_filter( 'give_payment_confirm_paypal', 'give_paypal_success_page_content' );
609
+add_filter('give_payment_confirm_paypal', 'give_paypal_success_page_content');
610 610
 
611 611
 /**
612 612
  * Given a Payment ID, extract the transaction ID
@@ -617,22 +617,22 @@  discard block
 block discarded – undo
617 617
  *
618 618
  * @return string                   Transaction ID
619 619
  */
620
-function give_paypal_get_payment_transaction_id( $payment_id ) {
620
+function give_paypal_get_payment_transaction_id($payment_id) {
621 621
 
622 622
 	$transaction_id = '';
623
-	$notes          = give_get_payment_notes( $payment_id );
623
+	$notes          = give_get_payment_notes($payment_id);
624 624
 
625
-	foreach ( $notes as $note ) {
626
-		if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
625
+	foreach ($notes as $note) {
626
+		if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
627 627
 			$transaction_id = $match[1];
628 628
 			continue;
629 629
 		}
630 630
 	}
631 631
 
632
-	return apply_filters( 'give_paypal_set_payment_transaction_id', $transaction_id, $payment_id );
632
+	return apply_filters('give_paypal_set_payment_transaction_id', $transaction_id, $payment_id);
633 633
 }
634 634
 
635
-add_filter( 'give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1 );
635
+add_filter('give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1);
636 636
 
637 637
 /**
638 638
  * Given a transaction ID, generate a link to the PayPal transaction ID details
@@ -644,16 +644,16 @@  discard block
 block discarded – undo
644 644
  *
645 645
  * @return string                 A link to the PayPal transaction details
646 646
  */
647
-function give_paypal_link_transaction_id( $transaction_id, $payment_id ) {
647
+function give_paypal_link_transaction_id($transaction_id, $payment_id) {
648 648
 
649 649
 	$paypal_base_url = 'https://history.paypal.com/cgi-bin/webscr?cmd=_history-details-from-hub&id=';
650
-	$transaction_url = '<a href="' . esc_url( $paypal_base_url . $transaction_id ) . '" target="_blank">' . $transaction_id . '</a>';
650
+	$transaction_url = '<a href="'.esc_url($paypal_base_url.$transaction_id).'" target="_blank">'.$transaction_id.'</a>';
651 651
 
652
-	return apply_filters( 'give_paypal_link_payment_details_transaction_id', $transaction_url );
652
+	return apply_filters('give_paypal_link_payment_details_transaction_id', $transaction_url);
653 653
 
654 654
 }
655 655
 
656
-add_filter( 'give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2 );
656
+add_filter('give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2);
657 657
 
658 658
 
659 659
 /**
@@ -665,62 +665,62 @@  discard block
 block discarded – undo
665 665
  *
666 666
  * @return string
667 667
  */
668
-function give_paypal_get_pending_donation_note( $pending_reason ) {
668
+function give_paypal_get_pending_donation_note($pending_reason) {
669 669
 
670
-	switch ( $pending_reason ) {
670
+	switch ($pending_reason) {
671 671
 
672 672
 		case 'echeck' :
673 673
 
674
-			$note = esc_html__( 'Payment made via eCheck and will clear automatically in 5-8 days.', 'give' );
674
+			$note = esc_html__('Payment made via eCheck and will clear automatically in 5-8 days.', 'give');
675 675
 
676 676
 			break;
677 677
 
678 678
 		case 'address' :
679 679
 
680
-			$note = esc_html__( 'Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give' );
680
+			$note = esc_html__('Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give');
681 681
 
682 682
 			break;
683 683
 
684 684
 		case 'intl' :
685 685
 
686
-			$note = esc_html__( 'Payment must be accepted manually through PayPal due to international account regulations.', 'give' );
686
+			$note = esc_html__('Payment must be accepted manually through PayPal due to international account regulations.', 'give');
687 687
 
688 688
 			break;
689 689
 
690 690
 		case 'multi-currency' :
691 691
 
692
-			$note = esc_html__( 'Payment received in non-shop currency and must be accepted manually through PayPal.', 'give' );
692
+			$note = esc_html__('Payment received in non-shop currency and must be accepted manually through PayPal.', 'give');
693 693
 
694 694
 			break;
695 695
 
696 696
 		case 'paymentreview' :
697 697
 		case 'regulatory_review' :
698 698
 
699
-			$note = esc_html__( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give' );
699
+			$note = esc_html__('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give');
700 700
 
701 701
 			break;
702 702
 
703 703
 		case 'unilateral' :
704 704
 
705
-			$note = esc_html__( 'Payment was sent to non-confirmed or non-registered email address.', 'give' );
705
+			$note = esc_html__('Payment was sent to non-confirmed or non-registered email address.', 'give');
706 706
 
707 707
 			break;
708 708
 
709 709
 		case 'upgrade' :
710 710
 
711
-			$note = esc_html__( 'PayPal account must be upgraded before this payment can be accepted.', 'give' );
711
+			$note = esc_html__('PayPal account must be upgraded before this payment can be accepted.', 'give');
712 712
 
713 713
 			break;
714 714
 
715 715
 		case 'verify' :
716 716
 
717
-			$note = esc_html__( 'PayPal account is not verified. Verify account in order to accept this donation.', 'give' );
717
+			$note = esc_html__('PayPal account is not verified. Verify account in order to accept this donation.', 'give');
718 718
 
719 719
 			break;
720 720
 
721 721
 		case 'other' :
722 722
 
723
-			$note = esc_html__( 'Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give' );
723
+			$note = esc_html__('Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give');
724 724
 
725 725
 			break;
726 726
 
Please login to merge, or discard this patch.