|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Gateway Actions |
|
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
|
|
|
* Processes gateway select on checkout. Only for users without ajax / javascript |
|
19
|
|
|
* |
|
20
|
|
|
* @since 1.0 |
|
21
|
|
|
* |
|
22
|
|
|
* @param $data |
|
23
|
|
|
*/ |
|
24
|
|
|
function give_process_gateway_select( $data ) { |
|
|
|
|
|
|
25
|
|
|
if ( isset( $_POST['gateway_submit'] ) ) { |
|
|
|
|
|
|
26
|
|
|
wp_redirect( esc_url( add_query_arg( 'payment-mode', $_POST['payment-mode'] ) ) ); |
|
|
|
|
|
|
27
|
|
|
exit; |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
add_action( 'give_gateway_select', 'give_process_gateway_select' ); |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Loads a payment gateway via AJAX. |
|
35
|
|
|
* |
|
36
|
|
|
* @since 1.0 |
|
37
|
|
|
* |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
|
|
function give_load_ajax_gateway() { |
|
41
|
|
|
if ( isset( $_POST['give_payment_mode'] ) ) { |
|
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Fire to render donation form. |
|
44
|
|
|
* |
|
45
|
|
|
* @since 1.7 |
|
46
|
|
|
*/ |
|
47
|
|
|
do_action( 'give_donation_form', $_POST['give_form_id'] ); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
exit(); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
add_action( 'wp_ajax_give_load_gateway', 'give_load_ajax_gateway' ); |
|
54
|
|
|
add_action( 'wp_ajax_nopriv_give_load_gateway', 'give_load_ajax_gateway' ); |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Create wp nonce using Ajax call. |
|
58
|
|
|
* |
|
59
|
|
|
* Use give_donation_form_nonce() js fn to create nonce. |
|
60
|
|
|
* |
|
61
|
|
|
* @since 2.0 |
|
62
|
|
|
* |
|
63
|
|
|
* @return void |
|
64
|
|
|
*/ |
|
65
|
|
|
function give_donation_form_nonce() { |
|
66
|
|
|
if ( isset( $_POST['give_form_id'] ) ) { |
|
67
|
|
|
|
|
68
|
|
|
// Get donation form id. |
|
69
|
|
|
$form_id = is_numeric( $_POST['give_form_id'] ) ? absint( $_POST['give_form_id'] ) : 0; |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
// Send nonce json data. |
|
72
|
|
|
wp_send_json_success( wp_create_nonce( "donation_form_nonce_{$form_id}" ) ); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
add_action( 'wp_ajax_give_donation_form_nonce', 'give_donation_form_nonce' ); |
|
77
|
|
|
add_action( 'wp_ajax_nopriv_give_donation_form_nonce', 'give_donation_form_nonce' ); |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Sets an error within the donation form if no gateways are enabled. |
|
81
|
|
|
* |
|
82
|
|
|
* @since 1.0 |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
*/ |
|
86
|
|
|
function give_no_gateway_error() { |
|
87
|
|
|
$gateways = give_get_enabled_payment_gateways(); |
|
88
|
|
|
|
|
89
|
|
|
if ( empty( $gateways ) ) { |
|
90
|
|
|
give_set_error( 'no_gateways', esc_html__( 'You must enable a payment gateway to use Give.', 'give' ) ); |
|
91
|
|
|
} else { |
|
92
|
|
|
give_unset_error( 'no_gateways' ); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
add_action( 'init', 'give_no_gateway_error' ); |
|
97
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.