Failed Conditions
Push — develop ( 1adb31...ae1cfb )
by Reüel
04:39
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( $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' ) ) : ?>
37
38
			<h2 class="pronamic-pay-form-title"><?php echo esc_html( $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 ( FormPostType::AMOUNT_METHOD_INPUT_FIXED !== $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...
44
45
				<?php if ( in_array( $amount_method, $methods_with_choices, true ) ) : ?>
46
47
				<fieldset>
48
					<legend><?php esc_html_e( 'Amount', 'pronamic_ideal' ); ?></legend>
49
50
				<?php endif; ?>
51
52
					<div class="pronamic-pay-amount pronamic-pay-form-row-wide">
53
						<?php if ( in_array( $amount_method, $methods_with_choices, true ) ) : ?>
54
55
								<?php foreach ( $amounts as $amount ) : ?>
56
57
									<?php
58
59
									$input_id = 'pronamic-pay-amount-' . esc_attr( $amount );
60
61
									$money = new Money( $amount / 100 );
62
63
									?>
64
65
								<div>
66
									<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 ) ); ?>" />
67
									<label for="<?php echo esc_attr( $input_id ); ?>">
68
										<span class="pronamic-pay-currency-symbol pronamic-pay-currency-position-before">€</span>
69
										<span class="pronamic-pay-amount-value"><?php echo esc_html( $money->format_i18n() ); ?></span>
70
									</label>
71
								</div>
72
73
								<?php endforeach; ?>
74
75
								<?php if ( \Pronamic\WordPress\Pay\Forms\FormPostType::AMOUNT_METHOD_CHOICES_AND_INPUT === $amount_method ) : ?>
76
77
									<div>
78
										<input class="pronamic-pay-amount-input pronamic-pay-input" id="pronamic-pay-amount-other" name="pronamic_pay_amount" type="radio" required="required" value="other" />
79
										<label for="pronamic-pay-amount-other">
80
											<span class="pronamic-pay-currency-symbol pronamic-pay-currency-position-before">€</span>
81
											<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 ); ?>" />
82
										</label>
83
									</div>
84
85
								<?php endif; ?>
86
87
						<?php endif; ?>
88
89
						<?php if ( \Pronamic\WordPress\Pay\Forms\FormPostType::AMOUNT_METHOD_INPUT_ONLY === $amount_method ) : ?>
90
91
							<span class="pronamic-pay-currency-symbol pronamic-pay-currency-position-before">€</span>
92
							<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 ); ?>" />
93
94
						<?php endif; ?>
95
					</div>
96
97
				<?php if ( in_array( $amount_method, $methods_with_choices, true ) ) : ?>
98
99
				</fieldset>
100
101
				<?php endif; ?>
102
103
				<fieldset>
104
					<legend><?php esc_html_e( 'Personal Info', 'pronamic_ideal' ); ?></legend>
105
106
					<p class="pronamic-pay-form-row pronamic-pay-form-row-first">
107
						<label class="pronamic-pay-label" for="pronamic-pay-first-name">
108
							<?php esc_html_e( 'First Name', 'pronamic_ideal' ); ?> <span class="pronamic-pay-required-indicator">*</span>
109
						</label>
110
111
						<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="" />
112
					</p>
113
114
					<p class="pronamic-pay-form-row pronamic-pay-form-row-last">
115
						<label class="pronamic-pay-label" for="pronamic-pay-last-name">
116
							<?php esc_html_e( 'Last Name', 'pronamic_ideal' ); ?>
117
						</label>
118
119
						<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="" />
120
					</p>
121
122
					<p class="pronamic-pay-form-row pronamic-pay-form-row-wide">
123
						<label class="pronamic-pay-label" for="pronamic-pay-email">
124
							<?php esc_html_e( 'Email Address', 'pronamic_ideal' ); ?>
125
							<span class="pronamic-pay-required-indicator">*</span>
126
						</label>
127
128
						<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="" />
129
					</p>
130
				</fieldset>
131
132
			<?php endif; ?>
133
134
			<?php
135
136
			if ( $gateway->payment_method_is_required() ) {
137
138
				$gateway->set_payment_method( PaymentMethods::IDEAL );
139
140
			}
141
142
			$fields = $gateway->get_input_fields();
143
144
			?>
145
146
			<?php if ( ! empty( $fields ) ) : ?>
147
148
				<fieldset>
149
					<legend><?php esc_html_e( 'Payment Info', 'pronamic_ideal' ); ?></legend>
150
151
					<?php foreach ( $fields as $i => $field ) : ?>
152
153
						<p class="pronamic-pay-form-row pronamic-pay-form-row-wide">
154
							<label class="pronamic-pay-label" for="<?php echo esc_attr( $field['id'] ); ?>">
155
								<?php echo esc_html( $field['label'] ); ?>
156
								<span class="pronamic-pay-required-indicator">*</span>
157
							</label>
158
159
							<?php if ( 'select' === $field['type'] ) : ?>
160
161
								<select id="<?php echo esc_attr( $field['id'] ); ?>" name="<?php echo esc_attr( $field['name'] ); ?>">
162
									<?php
163
164
									echo Util::select_options_grouped( $field['choices'] ); // WPCS: XSS ok.
165
166
									?>
167
								</select>
168
169
							<?php endif; ?>
170
						</p>
171
172
					<?php endforeach; ?>
173
174
				</fieldset>
175
176
			<?php endif; ?>
177
178
			<?php if ( ! empty( $pronamic_pay_errors ) ) : ?>
179
180
				<div class="pronamic-pay-errors">
181
182
					<?php foreach ( $pronamic_pay_errors as $error ) : ?>
183
184
						<p class="pronamic-pay-error">
185
							<strong><?php esc_html_e( 'Error', 'pronamic_ideal' ); ?></strong>: <?php echo esc_html( $error ); ?>
186
						</p>
187
188
					<?php endforeach; ?>
189
190
				</div>
191
192
			<?php endif; ?>
193
194
			<div class="pronamic-pay-submit-button-wrap pronamic-pay-clearfix">
195
				<?php wp_nonce_field( 'pronamic_pay', 'pronamic_pay_nonce' ); ?>
196
197
				<input type="hidden" name="pronamic_pay_form_id" value="<?php echo esc_attr( $id ); ?>" />
198
199
				<?php if ( FormPostType::AMOUNT_METHOD_INPUT_FIXED === $amount_method ) : ?>
200
201
					<input type="hidden" name="pronamic_pay_amount" value="<?php echo esc_attr( array_shift( $amounts ) ); ?>" />
202
203
				<?php endif; ?>
204
205
				<input type="submit" class="pronamic-pay-submit pronamic-pay-btn" id="pronamic-pay-purchase-button" name="pronamic_pay" value="<?php echo esc_attr( $button_text ); ?>" />
206
			</div>
207
		</form>
208
	</div>
209
210
<?php endif; ?>
211