1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Manual Gateway |
4
|
|
|
* |
5
|
|
|
* @package Give |
6
|
|
|
* @subpackage Gateways |
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
|
|
|
* Manual Gateway does not need a CC form, so remove it. |
19
|
|
|
* |
20
|
|
|
* @since 1.0 |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
add_action( 'give_manual_cc_form', '__return_false' ); |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Processes the donation data and uses the Manual Payment gateway to record |
27
|
|
|
* the donation in the Donation History |
28
|
|
|
* |
29
|
|
|
* @since 1.0 |
30
|
|
|
* |
31
|
|
|
* @param array $purchase_data Donation Data |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
function give_manual_payment( $purchase_data ) { |
36
|
|
|
|
37
|
|
View Code Duplication |
if ( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'give-gateway' ) ) { |
|
|
|
|
38
|
|
|
wp_die( esc_html__( 'Nonce verification failed.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
//Create payment_data array |
42
|
|
|
$payment_data = array( |
43
|
|
|
'price' => $purchase_data['price'], |
44
|
|
|
'give_form_title' => $purchase_data['post_data']['give-form-title'], |
45
|
|
|
'give_form_id' => intval( $purchase_data['post_data']['give-form-id'] ), |
46
|
|
|
'give_price_id' => isset($purchase_data['post_data']['give-price-id']) ? $purchase_data['post_data']['give-price-id'] : '', |
|
|
|
|
47
|
|
|
'date' => $purchase_data['date'], |
48
|
|
|
'user_email' => $purchase_data['user_email'], |
49
|
|
|
'purchase_key' => $purchase_data['purchase_key'], |
50
|
|
|
'currency' => give_get_currency( $purchase_data['post_data']['give-form-id'], $purchase_data ), |
51
|
|
|
'user_info' => $purchase_data['user_info'], |
52
|
|
|
'status' => 'pending' |
53
|
|
|
); |
54
|
|
|
// Record the pending payment |
55
|
|
|
$payment = give_insert_payment( $payment_data ); |
56
|
|
|
|
57
|
|
View Code Duplication |
if ( $payment ) { |
|
|
|
|
58
|
|
|
give_update_payment_status( $payment, 'publish' ); |
59
|
|
|
give_send_to_success_page(); |
60
|
|
|
} else { |
61
|
|
|
give_record_gateway_error( |
62
|
|
|
esc_html__( 'Payment Error', 'give' ), |
63
|
|
|
sprintf( |
64
|
|
|
/* translators: %s: payment data */ |
65
|
|
|
esc_html__( 'The payment creation failed while processing a manual (free or test) donation. Payment data: %s', 'give' ), |
66
|
|
|
json_encode( $payment_data ) |
67
|
|
|
), |
68
|
|
|
$payment |
|
|
|
|
69
|
|
|
); |
70
|
|
|
// If errors are present, send the user back to the donation page so they can be corrected |
71
|
|
|
give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] ); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
add_action( 'give_gateway_manual', 'give_manual_payment' ); |
76
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.