|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Admin Payment Actions |
|
4
|
|
|
* |
|
5
|
|
|
* @package Give |
|
6
|
|
|
* @subpackage Admin/Payments |
|
7
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
|
8
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
|
9
|
|
|
* @since 1.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
|
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
14
|
|
|
exit; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* |
|
19
|
|
|
* Process the payment details edit |
|
20
|
|
|
* |
|
21
|
|
|
* @since 1.0 |
|
22
|
|
|
* @access private |
|
23
|
|
|
* |
|
24
|
|
|
* @param array $data Donation data. |
|
25
|
|
|
* |
|
26
|
|
|
* @return void |
|
27
|
|
|
*/ |
|
28
|
|
|
function give_update_payment_details( $data ) { |
|
29
|
|
|
|
|
30
|
|
|
if ( ! current_user_can( 'edit_give_payments', $data['give_payment_id'] ) ) { |
|
31
|
|
|
wp_die( __( 'You do not have permission to edit payments.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
check_admin_referer( 'give_update_payment_details_nonce' ); |
|
35
|
|
|
|
|
36
|
|
|
// Retrieve the payment ID. |
|
37
|
|
|
$payment_id = absint( $data['give_payment_id'] ); |
|
38
|
|
|
|
|
39
|
|
|
/* @var Give_Payment $payment */ |
|
40
|
|
|
$payment = new Give_Payment( $payment_id ); |
|
41
|
|
|
|
|
42
|
|
|
$status = $data['give-payment-status']; |
|
43
|
|
|
$date = sanitize_text_field( $data['give-payment-date'] ); |
|
44
|
|
|
$hour = sanitize_text_field( $data['give-payment-time-hour'] ); |
|
45
|
|
|
|
|
46
|
|
|
// Restrict to our high and low. |
|
47
|
|
|
if ( $hour > 23 ) { |
|
48
|
|
|
$hour = 23; |
|
49
|
|
|
} elseif ( $hour < 0 ) { |
|
50
|
|
|
$hour = 00; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$minute = sanitize_text_field( $data['give-payment-time-min'] ); |
|
54
|
|
|
|
|
55
|
|
|
// Restrict to our high and low. |
|
56
|
|
|
if ( $minute > 59 ) { |
|
57
|
|
|
$minute = 59; |
|
58
|
|
|
} elseif ( $minute < 0 ) { |
|
59
|
|
|
$minute = 00; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$address = give_clean( $data['give-payment-address'][0] ); |
|
63
|
|
|
|
|
64
|
|
|
$curr_total = $payment->total; |
|
65
|
|
|
$new_total = give_maybe_sanitize_amount( ( ! empty( $data['give-payment-total'] ) ? $data['give-payment-total'] : 0 ) ); |
|
66
|
|
|
$date = date( get_option( 'date_format' ), strtotime( $date ) ) . ' ' . $hour . ':' . $minute . ':00'; |
|
67
|
|
|
|
|
68
|
|
|
$curr_donor_id = sanitize_text_field( $data['give-current-donor'] ); |
|
69
|
|
|
$new_donor_id = sanitize_text_field( $data['donor-id'] ); |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Fires before updating edited donation. |
|
73
|
|
|
* |
|
74
|
|
|
* @since 1.0 |
|
75
|
|
|
* @since 1.8.9 Changes hook name give_update_edited_purchase -> give_update_edited_donation |
|
76
|
|
|
* |
|
77
|
|
|
* @param int $payment_id The ID of the payment. |
|
78
|
|
|
*/ |
|
79
|
|
|
do_action( 'give_update_edited_donation', $payment_id ); |
|
80
|
|
|
|
|
81
|
|
|
$payment->date = $date; |
|
82
|
|
|
$payment->anonymous = isset( $data['give_anonymous_donation'] ) ? absint( $data['give_anonymous_donation'] ) : 0; |
|
83
|
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
$updated = $payment->save(); |
|
86
|
|
|
|
|
87
|
|
|
if ( 0 === $updated ) { |
|
88
|
|
|
wp_die( __( 'Error Updating Donation.', 'give' ), __( 'Error', 'give' ), array( 'response' => 400 ) ); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$donor_changed = false; |
|
92
|
|
|
|
|
93
|
|
|
if ( isset( $data['give-new-donor'] ) && $data['give-new-donor'] == '1' ) { |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
$email = ! empty( $data['give-new-donor-email'] ) ? sanitize_text_field( $data['give-new-donor-email'] ) : ''; |
|
96
|
|
|
$first_name = ! empty( $data['give-new-donor-first-name'] ) ? sanitize_text_field( $data['give-new-donor-first-name'] ) : ''; |
|
97
|
|
|
$last_name = ! empty( $data['give-new-donor-last-name'] ) ? sanitize_text_field( $data['give-new-donor-last-name'] ) : ''; |
|
98
|
|
|
$names = strip_tags( wp_unslash( trim( "{$first_name} {$last_name}" ) ) ); |
|
99
|
|
|
|
|
100
|
|
|
if ( empty( $email ) || empty( $first_name ) ) { |
|
101
|
|
|
wp_die( __( 'New Donor requires first name and email address.', 'give' ), __( 'Error', 'give' ), array( 'response' => 400 ) ); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$donor = new Give_Donor( $email ); |
|
105
|
|
|
if ( empty( $donor->id ) ) { |
|
106
|
|
|
$donor_data = array( 'name' => $names, 'email' => $email ); |
|
107
|
|
|
$user_id = email_exists( $email ); |
|
108
|
|
|
if ( false !== $user_id ) { |
|
109
|
|
|
$donor_data['user_id'] = $user_id; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
if ( ! $donor->create( $donor_data ) ) { |
|
|
|
|
|
|
113
|
|
|
// Failed to create the new donor, assume the previous donor. |
|
114
|
|
|
$donor_changed = false; |
|
|
|
|
|
|
115
|
|
|
$donor = new Give_Donor( $curr_donor_id ); |
|
116
|
|
|
give_set_error( 'give-payment-new-donor-fail', __( 'Error creating new donor.', 'give' ) ); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
// Create and Update Donor First Name and Last Name in Meta Fields. |
|
121
|
|
|
$donor->update_meta( '_give_donor_first_name', $first_name ); |
|
122
|
|
|
$donor->update_meta( '_give_donor_last_name', $last_name ); |
|
123
|
|
|
|
|
124
|
|
|
$new_donor_id = $donor->id; |
|
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
$previous_donor = new Give_Donor( $curr_donor_id ); |
|
127
|
|
|
|
|
128
|
|
|
$donor_changed = true; |
|
129
|
|
|
|
|
130
|
|
|
} elseif ( $curr_donor_id !== $new_donor_id ) { |
|
131
|
|
|
|
|
132
|
|
|
$donor = new Give_Donor( $new_donor_id ); |
|
133
|
|
|
$email = $donor->email; |
|
|
|
|
|
|
134
|
|
|
$names = $donor->name; |
|
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
$previous_donor = new Give_Donor( $curr_donor_id ); |
|
137
|
|
|
|
|
138
|
|
|
$donor_changed = true; |
|
139
|
|
|
|
|
140
|
|
|
} else { |
|
141
|
|
|
$donor = new Give_Donor( $curr_donor_id ); |
|
142
|
|
|
$email = $donor->email; |
|
|
|
|
|
|
143
|
|
|
$names = $donor->name; |
|
|
|
|
|
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
if ( $donor_changed ) { |
|
147
|
|
|
|
|
148
|
|
|
// Setup first and last name from input values. |
|
149
|
|
|
$first_name = $donor->get_first_name(); |
|
150
|
|
|
$last_name = $donor->get_last_name(); |
|
151
|
|
|
|
|
152
|
|
|
$payment->first_name = $first_name; |
|
153
|
|
|
$payment->last_name = $last_name; |
|
154
|
|
|
|
|
155
|
|
|
// Remove the stats and payment from the previous donor and attach it to the new donor. |
|
156
|
|
|
$previous_donor->remove_payment( $payment_id, false ); |
|
157
|
|
|
$donor->attach_payment( $payment_id, false ); |
|
158
|
|
|
|
|
159
|
|
|
if ( 'publish' == $status ) { |
|
160
|
|
|
|
|
161
|
|
|
// Reduce previous user donation count and amount. |
|
162
|
|
|
$previous_donor->decrease_donation_count(); |
|
163
|
|
|
$previous_donor->decrease_value( $curr_total ); |
|
164
|
|
|
|
|
165
|
|
|
// If donation was completed adjust stats of new donors. |
|
166
|
|
|
$donor->increase_purchase_count(); |
|
167
|
|
|
$donor->increase_value( $new_total ); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
$payment->customer_id = $donor->id; |
|
171
|
|
|
} else { |
|
172
|
|
|
|
|
173
|
|
|
if ( 'publish' === $status ) { |
|
174
|
|
|
// Update user donation stat. |
|
175
|
|
|
$donor->update_donation_value( $curr_total, $new_total ); |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
// Set new meta values. |
|
180
|
|
|
$payment->user_id = $donor->user_id; |
|
181
|
|
|
$payment->email = $donor->email; |
|
182
|
|
|
$payment->address = $address; |
|
|
|
|
|
|
183
|
|
|
$payment->total = $new_total; |
|
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
// Check for payment notes. |
|
186
|
|
|
if ( ! empty( $data['give-payment-note'] ) ) { |
|
187
|
|
|
|
|
188
|
|
|
$note = wp_kses( $data['give-payment-note'], array() ); |
|
189
|
|
|
give_insert_payment_note( $payment_id, $note ); |
|
190
|
|
|
|
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
// Set new status. |
|
194
|
|
|
$payment->status = $status; |
|
195
|
|
|
|
|
196
|
|
|
// Adjust total store earnings if the payment total has been changed. |
|
197
|
|
|
if ( $new_total !== $curr_total && 'publish' == $status ) { |
|
198
|
|
|
|
|
199
|
|
|
if ( $new_total > $curr_total ) { |
|
200
|
|
|
// Increase if our new total is higher. |
|
201
|
|
|
$difference = $new_total - $curr_total; |
|
202
|
|
|
give_increase_total_earnings( $difference ); |
|
203
|
|
|
|
|
204
|
|
|
// Increase form earnings. |
|
205
|
|
|
give_increase_earnings( $payment->form_id, $difference, $payment->ID ); |
|
206
|
|
|
} elseif ( $curr_total > $new_total ) { |
|
207
|
|
|
// Decrease if our new total is lower. |
|
208
|
|
|
$difference = $curr_total - $new_total; |
|
209
|
|
|
give_decrease_total_earnings( $difference ); |
|
210
|
|
|
|
|
211
|
|
|
// Decrease form earnings. |
|
212
|
|
|
give_decrease_form_earnings( $payment->form_id, $difference, $payment->ID ); |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
$payment->save(); |
|
217
|
|
|
|
|
218
|
|
|
// Get new give form ID. |
|
219
|
|
|
$new_form_id = absint( $data['give-payment-form-select'] ); |
|
220
|
|
|
$current_form_id = absint( $payment->get_meta( '_give_payment_form_id' ) ); |
|
221
|
|
|
|
|
222
|
|
|
// We are adding payment transfer code in last to remove any conflict with above functionality. |
|
223
|
|
|
// For example: above code will automatically handle form stat (increase/decrease) when payment status changes. |
|
224
|
|
|
// Check if user want to transfer current payment to new give form id. |
|
225
|
|
|
if ( $new_form_id && $new_form_id != $current_form_id ) { |
|
226
|
|
|
|
|
227
|
|
|
// Get new give form title. |
|
228
|
|
|
$new_form_title = get_the_title( $new_form_id ); |
|
229
|
|
|
|
|
230
|
|
|
// Update payment give form meta data. |
|
231
|
|
|
$payment->update_meta( '_give_payment_form_id', $new_form_id ); |
|
232
|
|
|
$payment->update_meta( '_give_payment_form_title', $new_form_title ); |
|
233
|
|
|
|
|
234
|
|
|
// Update price id payment metadata. |
|
235
|
|
|
if ( ! give_has_variable_prices( $new_form_id ) ) { |
|
236
|
|
|
$payment->update_meta( '_give_payment_price_id', '' ); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
// If donation was completed, adjust stats of forms. |
|
240
|
|
|
if ( 'publish' == $status ) { |
|
241
|
|
|
|
|
242
|
|
|
// Decrease sale of old give form. For other payment status. |
|
243
|
|
|
$current_form = new Give_Donate_Form( $current_form_id ); |
|
244
|
|
|
$current_form->decrease_sales(); |
|
245
|
|
|
$current_form->decrease_earnings( $curr_total, $payment->ID ); |
|
246
|
|
|
|
|
247
|
|
|
// Increase sale of new give form. |
|
248
|
|
|
$new_form = new Give_Donate_Form( $new_form_id ); |
|
249
|
|
|
$new_form->increase_sales(); |
|
250
|
|
|
$new_form->increase_earnings( $new_total, $payment->ID ); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
// Re setup payment to update new meta value in object. |
|
254
|
|
|
$payment->update_payment_setup( $payment->ID ); |
|
255
|
|
|
|
|
256
|
|
|
// Update form id in payment logs. |
|
257
|
|
|
Give()->async_process->data( array( |
|
258
|
|
|
'data' => array( $new_form_id, $payment_id ), |
|
259
|
|
|
'hook' => 'give_update_log_form_id', |
|
260
|
|
|
) )->dispatch(); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
// Update price id if current form is variable form. |
|
264
|
|
|
/* @var Give_Donate_Form $form */ |
|
265
|
|
|
$form = new Give_Donate_Form( $payment->form_id ); |
|
266
|
|
|
|
|
267
|
|
|
if ( isset( $data['give-variable-price'] ) && $form->has_variable_prices() ) { |
|
268
|
|
|
|
|
269
|
|
|
// Get payment meta data. |
|
270
|
|
|
$payment_meta = $payment->get_meta(); |
|
271
|
|
|
|
|
272
|
|
|
$price_info = array(); |
|
273
|
|
|
$price_id = ''; |
|
274
|
|
|
|
|
275
|
|
|
// Get price info |
|
276
|
|
|
if( 0 <= $data['give-variable-price'] ) { |
|
|
|
|
|
|
277
|
|
|
foreach ( $form->prices as $variable_price ) { |
|
278
|
|
|
if( $new_total === give_maybe_sanitize_amount( $variable_price['_give_amount'] ) ) { |
|
|
|
|
|
|
279
|
|
|
$price_info = $variable_price; |
|
280
|
|
|
break; |
|
281
|
|
|
} |
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
// Set price id. |
|
286
|
|
|
if( ! empty( $price_info ) ) { |
|
|
|
|
|
|
287
|
|
|
$price_id = $data['give-variable-price']; |
|
288
|
|
|
|
|
289
|
|
|
if( $data['give-variable-price'] !== $price_info['_give_id']['level_id'] ) { |
|
|
|
|
|
|
290
|
|
|
// Set price id to amount match. |
|
291
|
|
|
$price_id = $price_info['_give_id']['level_id']; |
|
292
|
|
|
} |
|
|
|
|
|
|
293
|
|
|
|
|
294
|
|
|
} elseif( $form->is_custom_price_mode() ){ |
|
|
|
|
|
|
295
|
|
|
$price_id = 'custom'; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
// Update payment meta data. |
|
299
|
|
|
$payment_meta['price_id'] = $price_id; |
|
300
|
|
|
|
|
301
|
|
|
// Update payment give form meta data. |
|
302
|
|
|
$payment->update_meta( '_give_payment_price_id', $price_id ); |
|
303
|
|
|
$payment->update_meta( '_give_payment_meta', $payment_meta ); |
|
304
|
|
|
|
|
305
|
|
|
// Re setup payment to update new meta value in object. |
|
306
|
|
|
$payment->update_payment_setup( $payment->ID ); |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
$comment_id = isset( $data['give_comment_id'] ) ? absint( $data['give_comment_id'] ) : 0; |
|
310
|
|
|
$is_anonymous_donation = give_is_anonymous_donation_field_enabled( $payment->form_id ); |
|
311
|
|
|
|
|
312
|
|
|
if ( $is_anonymous_donation ) { |
|
313
|
|
|
give_update_meta( $payment->ID, '_give_anonymous_donation', $payment->anonymous ); |
|
314
|
|
|
Give()->donor_meta->update_meta( $payment->donor_id, '_give_anonymous_donor', $payment->anonymous ); |
|
315
|
|
|
|
|
316
|
|
|
// Update comment meta if admin is not updating comment. |
|
317
|
|
|
if( $comment_id ) { |
|
|
|
|
|
|
318
|
|
|
update_comment_meta( $comment_id, '_give_anonymous_donation', $payment->anonymous ); |
|
319
|
|
|
} |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
// Update comment. |
|
323
|
|
|
if ( give_is_donor_comment_field_enabled( $payment->form_id ) ) { |
|
324
|
|
|
// We are access comment directly from $_POST because comment formatting remove because of give_clean in give_post_actions. |
|
325
|
|
|
$data['give_comment'] = trim( $_POST['give_comment'] ); |
|
|
|
|
|
|
326
|
|
|
|
|
327
|
|
|
if ( empty( $data['give_comment'] ) ) { |
|
328
|
|
|
// Delete comment if empty |
|
329
|
|
|
Give_Comment::delete( $comment_id, $payment_id, 'payment' ); |
|
330
|
|
|
|
|
331
|
|
|
} else { |
|
332
|
|
|
|
|
333
|
|
|
// Update/Insert comment. |
|
334
|
|
|
$is_update_comment_meta = ! $comment_id; |
|
335
|
|
|
|
|
336
|
|
|
$comment_args = array( |
|
337
|
|
|
'comment_author_email' => $payment->email |
|
338
|
|
|
); |
|
339
|
|
|
|
|
340
|
|
|
if ( $comment_id ) { |
|
341
|
|
|
$comment_args['comment_ID'] = $comment_id; |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
$comment_id = give_insert_donor_donation_comment( |
|
345
|
|
|
$payment->ID, |
|
346
|
|
|
$payment->donor_id, |
|
347
|
|
|
$data['give_comment'], |
|
348
|
|
|
$comment_args |
|
349
|
|
|
); |
|
350
|
|
|
|
|
351
|
|
|
if ( $is_update_comment_meta ) { |
|
352
|
|
|
update_comment_meta( $comment_id, '_give_anonymous_donation', $is_anonymous_donation ); |
|
353
|
|
|
} |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
$donor_has_comment = empty( $data['give_comment'] ) |
|
357
|
|
|
? ( $latest_comment = give_get_donor_latest_comment( $payment->donor_id ) && empty( $latest_comment ) ? '0' : '1' ) |
|
358
|
|
|
: '1'; |
|
359
|
|
|
|
|
360
|
|
|
Give()->donor_meta->update_meta( $payment->donor_id, '_give_has_comment', $donor_has_comment ); |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* Fires after updating edited donation. |
|
365
|
|
|
* |
|
366
|
|
|
* @since 1.0 |
|
367
|
|
|
* @since 1.8.9 Changes hook name give_updated_edited_purchase -> give_updated_edited_donation |
|
368
|
|
|
* |
|
369
|
|
|
* @param int $payment_id The ID of the payment. |
|
370
|
|
|
*/ |
|
371
|
|
|
do_action( 'give_updated_edited_donation', $payment_id ); |
|
372
|
|
|
|
|
373
|
|
|
wp_safe_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&give-messages[]=payment-updated&id=' . $payment_id ) ); |
|
374
|
|
|
exit; |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
add_action( 'give_update_payment_details', 'give_update_payment_details' ); |
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* Trigger a Donation Deletion. |
|
381
|
|
|
* |
|
382
|
|
|
* @since 1.0 |
|
383
|
|
|
* |
|
384
|
|
|
* @param array $data Arguments passed. |
|
385
|
|
|
* |
|
386
|
|
|
* @return void |
|
387
|
|
|
*/ |
|
388
|
|
|
function give_trigger_donation_delete( $data ) { |
|
389
|
|
|
if ( wp_verify_nonce( $data['_wpnonce'], 'give_donation_nonce' ) ) { |
|
390
|
|
|
|
|
391
|
|
|
$payment_id = absint( $data['purchase_id'] ); |
|
392
|
|
|
|
|
393
|
|
|
if ( ! current_user_can( 'edit_give_payments', $payment_id ) ) { |
|
394
|
|
|
wp_die( __( 'You do not have permission to edit payments.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
give_delete_donation( $payment_id ); |
|
398
|
|
|
wp_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&give-messages[]=donation-deleted' ) ); |
|
399
|
|
|
give_die(); |
|
400
|
|
|
} |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
add_action( 'give_delete_payment', 'give_trigger_donation_delete' ); |
|
404
|
|
|
|
|
405
|
|
|
/** |
|
406
|
|
|
* AJAX Store Donation Note |
|
407
|
|
|
*/ |
|
408
|
|
|
function give_ajax_store_payment_note() { |
|
409
|
|
|
$payment_id = absint( $_POST['payment_id'] ); |
|
|
|
|
|
|
410
|
|
|
$note = wp_kses( $_POST['note'], array() ); |
|
|
|
|
|
|
411
|
|
|
$note_type = give_clean( $_POST['type'] ); |
|
|
|
|
|
|
412
|
|
|
|
|
413
|
|
|
if ( ! current_user_can( 'edit_give_payments', $payment_id ) ) { |
|
414
|
|
|
wp_die( __( 'You do not have permission to edit payments.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
if ( empty( $payment_id ) ) { |
|
418
|
|
|
die( '-1' ); |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
if ( empty( $note ) ) { |
|
422
|
|
|
die( '-1' ); |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
$note_id = give_insert_payment_note( $payment_id, $note ); |
|
426
|
|
|
|
|
427
|
|
|
if( $note_id && $note_type ) { |
|
|
|
|
|
|
428
|
|
|
add_comment_meta( $note_id, 'note_type', $note_type, true ); |
|
429
|
|
|
|
|
430
|
|
|
/** |
|
431
|
|
|
* Fire the action |
|
432
|
|
|
* |
|
433
|
|
|
* @since 2.3.0 |
|
434
|
|
|
*/ |
|
435
|
|
|
do_action( 'give_donor-note_email_notification', $note_id, $payment_id ); |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
die( give_get_payment_note_html( $note_id ) ); |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
add_action( 'wp_ajax_give_insert_payment_note', 'give_ajax_store_payment_note' ); |
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* Triggers a donation note deletion without ajax |
|
445
|
|
|
* |
|
446
|
|
|
* @since 1.0 |
|
447
|
|
|
* |
|
448
|
|
|
* @param array $data Arguments passed |
|
449
|
|
|
* |
|
450
|
|
|
* @return void |
|
451
|
|
|
*/ |
|
452
|
|
|
function give_trigger_payment_note_deletion( $data ) { |
|
453
|
|
|
|
|
454
|
|
|
if ( ! wp_verify_nonce( $data['_wpnonce'], 'give_delete_payment_note_' . $data['note_id'] ) ) { |
|
455
|
|
|
return; |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
View Code Duplication |
if ( ! current_user_can( 'edit_give_payments', $data['payment_id'] ) ) { |
|
|
|
|
|
|
459
|
|
|
wp_die( __( 'You do not have permission to edit payments.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
$edit_order_url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&give-messages[]=donation-note-deleted&id=' . absint( $data['payment_id'] ) ); |
|
463
|
|
|
|
|
464
|
|
|
give_delete_payment_note( $data['note_id'], $data['payment_id'] ); |
|
465
|
|
|
|
|
466
|
|
|
wp_redirect( $edit_order_url ); |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
add_action( 'give_delete_payment_note', 'give_trigger_payment_note_deletion' ); |
|
470
|
|
|
|
|
471
|
|
|
/** |
|
472
|
|
|
* Delete a payment note deletion with ajax |
|
473
|
|
|
* |
|
474
|
|
|
* @since 1.0 |
|
475
|
|
|
* |
|
476
|
|
|
* @return void |
|
477
|
|
|
*/ |
|
478
|
|
|
function give_ajax_delete_payment_note() { |
|
479
|
|
|
|
|
480
|
|
View Code Duplication |
if ( ! current_user_can( 'edit_give_payments', $_POST['payment_id'] ) ) { |
|
|
|
|
|
|
481
|
|
|
wp_die( __( 'You do not have permission to edit payments.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) ); |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
if ( give_delete_payment_note( $_POST['note_id'], $_POST['payment_id'] ) ) { |
|
|
|
|
|
|
485
|
|
|
die( '1' ); |
|
486
|
|
|
} else { |
|
487
|
|
|
die( '-1' ); |
|
488
|
|
|
} |
|
489
|
|
|
|
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
add_action( 'wp_ajax_give_delete_payment_note', 'give_ajax_delete_payment_note' ); |
|
493
|
|
|
|