Failed Conditions
Push — develop ( 905cdb...3b4fec )
by Reüel
09:35
created

templates/form.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Forms template.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay
9
 */
10
11
global $pronamic_pay_errors;
12
13
use Pronamic\WordPress\Money\Money;
14
use Pronamic\WordPress\Pay\Core\PaymentMethods;
15
use Pronamic\WordPress\Pay\Forms\FormPostType;
16
use Pronamic\WordPress\Pay\Plugin;
17
use Pronamic\WordPress\Pay\Util;
18
19
$methods_with_choices = array(
20
	\Pronamic\WordPress\Pay\Forms\FormPostType::AMOUNT_METHOD_CHOICES_ONLY,
21
	\Pronamic\WordPress\Pay\Forms\FormPostType::AMOUNT_METHOD_CHOICES_AND_INPUT,
22
);
23
24
$gateway = Plugin::get_gateway( $settings['config_id'] );
25
26
$amount_value = '';
27
28
if ( filter_has_var( INPUT_GET, 'amount' ) ) {
29
	$amount_value = filter_input( INPUT_GET, 'amount', FILTER_SANITIZE_STRING );
30
}
31
32
if ( $gateway ) : ?>
33
34
	<div class="pronamic-pay-form-wrap">
35
36
		<?php if ( ! is_singular( 'pronamic_pay_form' ) && ! empty( $settings['title'] ) ) : ?>
37
38
			<h2 class="pronamic-pay-form-title"><?php echo esc_html( $settings['title'] ); ?></h2>
39
40
		<?php endif; ?>
41
42
		<form id="pronamic-pay-form-<?php echo esc_attr( $id ); ?>" class="pronamic-pay-form" method="post">
43
			<?php if ( in_array( $settings['amount_method'], $methods_with_choices, true ) ) : ?>
44
45
			<fieldset>
46
				<legend><?php esc_html_e( 'Amount', 'pronamic_ideal' ); ?></legend>
47
48
			<?php endif; ?>
49
50
				<div class="pronamic-pay-amount pronamic-pay-form-row-wide">
51
					<?php if ( in_array( $settings['amount_method'], $methods_with_choices, true ) ) : ?>
52
53
							<?php foreach ( $settings['amounts'] as $amount ) : ?>
54
55
								<?php
56
57
								$input_id = 'pronamic-pay-amount-' . esc_attr( $amount );
58
59
								$money = new Money( $amount / 100 );
60
61
								?>
62
63
							<div>
64
								<input class="pronamic-pay-amount-input pronamic-pay-input" id="<?php echo esc_attr( $input_id ); ?>" name="pronamic_pay_amount" type="radio" required="required" value="<?php echo esc_attr( sprintf( '%F', $amount ) ); ?>" />
65
								<label for="<?php echo esc_attr( $input_id ); ?>">
66
									<span class="pronamic-pay-currency-symbol pronamic-pay-currency-position-before">€</span>
67
									<span class="pronamic-pay-amount-value"><?php echo esc_html( $money->format_i18n() ); ?></span>
68
								</label>
69
							</div>
70
71
							<?php endforeach; ?>
72
73
							<?php if ( \Pronamic\WordPress\Pay\Forms\FormPostType::AMOUNT_METHOD_CHOICES_AND_INPUT === $settings['amount_method'] ) : ?>
74
75
								<div>
76
									<input class="pronamic-pay-amount-input pronamic-pay-input" id="pronamic-pay-amount-other" name="pronamic_pay_amount" type="radio" required="required" value="other" />
77
									<label for="pronamic-pay-amount-other">
78
										<span class="pronamic-pay-currency-symbol pronamic-pay-currency-position-before">€</span>
79
										<input class="pronamic-pay-amount-input pronamic-pay-input" id="pronamic-pay-amount" name="pronamic_pay_amount_other" type="text" placeholder="" autocomplete="off" value="<?php echo esc_attr( $amount_value ); ?>" />
80
									</label>
81
								</div>
82
83
							<?php endif; ?>
84
85
					<?php endif; ?>
86
87
					<?php if ( \Pronamic\WordPress\Pay\Forms\FormPostType::AMOUNT_METHOD_INPUT_ONLY === $settings['amount_method'] ) : ?>
88
89
						<span class="pronamic-pay-currency-symbol pronamic-pay-currency-position-before">€</span>
90
						<input class="pronamic-pay-amount-input pronamic-pay-input" id="pronamic-pay-amount" name="pronamic_pay_amount" type="text" placeholder="" autocomplete="off" value="<?php echo esc_attr( $amount_value ); ?>" />
91
92
					<?php endif; ?>
93
				</div>
94
95
			<?php if ( in_array( $settings['amount_method'], $methods_with_choices, true ) ) : ?>
96
97
			</fieldset>
98
99
			<?php endif; ?>
100
101
			<fieldset>
102
				<legend><?php esc_html_e( 'Personal Info', 'pronamic_ideal' ); ?></legend>
103
104
				<p class="pronamic-pay-form-row pronamic-pay-form-row-first">
105
					<label class="pronamic-pay-label" for="pronamic-pay-first-name">
106
						<?php esc_html_e( 'First Name', 'pronamic_ideal' ); ?> <span class="pronamic-pay-required-indicator">*</span>
107
					</label>
108
109
					<input class="pronamic-pay-input pronamic-pay-required" type="text" name="pronamic_pay_first_name" placeholder="<?php esc_attr_e( 'First Name', 'pronamic_ideal' ); ?>" id="pronamic-pay-first-name" required="required" value="" />
110
				</p>
111
112
				<p class="pronamic-pay-form-row pronamic-pay-form-row-last">
113
					<label class="pronamic-pay-label" for="pronamic-pay-last-name">
114
						<?php esc_html_e( 'Last Name', 'pronamic_ideal' ); ?>
115
					</label>
116
117
					<input class="pronamic-pay-input" type="text" name="pronamic_pay_last_name" id="pronamic-pay-last-name" placeholder="<?php esc_attr_e( 'Last Name', 'pronamic_ideal' ); ?>" value="" />
118
				</p>
119
120
				<p class="pronamic-pay-form-row pronamic-pay-form-row-wide">
121
					<label class="pronamic-pay-label" for="pronamic-pay-email">
122
						<?php esc_html_e( 'Email Address', 'pronamic_ideal' ); ?>
123
						<span class="pronamic-pay-required-indicator">*</span>
124
					</label>
125
126
					<input class="pronamic-pay-input required" type="email" name="pronamic_pay_email" placeholder="<?php esc_attr_e( 'Email Address', 'pronamic_ideal' ); ?>" id="pronamic-pay-email" required="required" value="" />
127
				</p>
128
			</fieldset>
129
130
			<?php
131
132
			if ( $gateway->payment_method_is_required() ) {
133
134
				$gateway->set_payment_method( PaymentMethods::IDEAL );
135
136
			}
137
138
			$fields = $gateway->get_input_fields();
139
140
			?>
141
142
			<?php if ( ! empty( $fields ) ) : ?>
143
144
				<fieldset>
145
					<legend><?php esc_html_e( 'Payment Info', 'pronamic_ideal' ); ?></legend>
146
147
					<?php foreach ( $fields as $i => $field ) : ?>
148
149
						<p class="pronamic-pay-form-row pronamic-pay-form-row-wide">
150
							<label class="pronamic-pay-label" for="<?php echo esc_attr( $field['id'] ); ?>">
151
								<?php echo esc_html( $field['label'] ); ?>
152
								<span class="pronamic-pay-required-indicator">*</span>
153
							</label>
154
155
							<?php if ( 'select' === $field['type'] ) : ?>
156
157
								<select id="<?php echo esc_attr( $field['id'] ); ?>" name="<?php echo esc_attr( $field['name'] ); ?>">
158
									<?php
159
160
									echo Util::select_options_grouped( $field['choices'] ); // WPCS: XSS ok.
161
162
									?>
163
								</select>
164
165
							<?php endif; ?>
166
						</p>
167
168
					<?php endforeach; ?>
169
170
				</fieldset>
171
172
			<?php endif; ?>
173
174
			<?php if ( ! empty( $pronamic_pay_errors ) ) : ?>
175
176
				<div class="pronamic-pay-errors">
177
178
					<?php foreach ( $pronamic_pay_errors as $error ) : ?>
179
180
						<p class="pronamic-pay-error">
181
							<strong><?php esc_html_e( 'Error', 'pronamic_ideal' ); ?></strong>: <?php echo esc_html( $error ); ?>
182
						</p>
183
184
					<?php endforeach; ?>
185
186
				</div>
187
188
			<?php endif; ?>
189
190
			<div class="pronamic-pay-submit-button-wrap pronamic-pay-clearfix">
191
				<?php wp_nonce_field( 'pronamic_pay', 'pronamic_pay_nonce' ); ?>
192
193
				<input type="hidden" name="pronamic_pay_form_id" value="<?php echo esc_attr( $id ); ?>" />
194
195
				<?php if ( FormPostType::AMOUNT_METHOD_INPUT_FIXED === $settings['amount_method'] ) : ?>
0 ignored issues
show
The constant Pronamic\WordPress\Pay\F...OUNT_METHOD_INPUT_FIXED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
196
197
					<input type="hidden" name="pronamic_pay_amount" value="<?php echo esc_attr( array_shift( $settings['amounts'] ) ); ?>" />
198
199
				<?php endif; ?>
200
201
				<input type="submit" class="pronamic-pay-submit pronamic-pay-btn" id="pronamic-pay-purchase-button" name="pronamic_pay" value="<?php echo esc_attr( $settings['button_text'] ); ?>" />
202
			</div>
203
		</form>
204
	</div>
205
206
<?php endif; ?>
207