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