Failed Conditions
Push — develop ( 5619b1...05b205 )
by Remco
04:23
created

admin/meta-box-payment-update.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Meta Box Payment Update
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
use Pronamic\WordPress\Pay\Core\PaymentMethods;
12
use Pronamic\WordPress\Pay\Payments\PaymentPostType;
13
use Pronamic\WordPress\Pay\Plugin;
14
15
$states = PaymentPostType::get_payment_states();
16
17
$payment = get_pronamic_payment( get_the_ID() );
0 ignored issues
show
It seems like get_the_ID() can also be of type false; however, parameter $post_id of get_pronamic_payment() does only seem to accept integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

17
$payment = get_pronamic_payment( /** @scrutinizer ignore-type */ get_the_ID() );
Loading history...
18
19
if ( null === $payment ) {
20
	return;
21
}
22
23
// WordPress by default doesn't allow `post_author` values of `0`, that's why we use a dash (`-`).
24
// @link https://github.com/WordPress/WordPress/blob/4.9.5/wp-admin/includes/post.php#L56-L64.
25
$post_author = get_post_field( 'post_author' );
26
$post_author = empty( $post_author ) ? '-' : $post_author;
27
28
?>
29
<input type="hidden" name="post_author_override" value="<?php echo esc_attr( $post_author ); ?>" />
30
31
<div class="pronamic-pay-inner">
32
	<p>
33
		<label for="pronamic-payment-status">Status:&nbsp;</label>
34
		<select id="pronamic-payment-status" name="pronamic_payment_post_status" class="medium-text">
35
			<?php
36
37
			foreach ( $states as $status => $label ) {
38
				printf(
39
					'<option value="%s" %s>%s</option>',
40
					esc_attr( $status ),
41
					selected( $status, $post->post_status, false ),
42
					esc_html( $label )
43
				);
44
			}
45
46
			?>
47
		</select>
48
	</p>
49
50
	<?php
51
52
	$config_id = get_post_meta( $post->ID, '_pronamic_payment_config_id', true );
53
54
	$gateway = Plugin::get_gateway( $config_id );
55
56
	/**
57
	 * Check status button.
58
	 */
59
	if ( $gateway && $gateway->supports( 'payment_status_request' ) ) {
60
		// Only show button if gateway exists and status check is supported.
61
		$action_url = wp_nonce_url(
62
			add_query_arg(
63
				array(
64
					'post'                      => $post->ID,
65
					'action'                    => 'edit',
66
					'pronamic_pay_check_status' => true,
67
				),
68
				admin_url( 'post.php' )
69
			),
70
			'pronamic_payment_check_status_' . $post->ID
71
		);
72
73
		printf(
74
			'<p><a class="button" href="%s">%s</a></p>',
75
			esc_url( $action_url ),
76
			esc_html__( 'Check status', 'pronamic_ideal' )
77
		);
78
	}
79
80
	/**
81
	 * Create invoice for reserved payment.
82
	 */
83
	if ( $gateway && $gateway->supports( 'reservation_payments' ) && 'payment_reserved' === get_post_status( $post->ID ) ) {
84
		// Only show button if gateway exists and reservation payments are supported.
85
		$action_url = wp_nonce_url(
86
			add_query_arg(
87
				array(
88
					'post'                        => $post->ID,
89
					'action'                      => 'edit',
90
					'pronamic_pay_create_invoice' => true,
91
				),
92
				admin_url( 'post.php' )
93
			),
94
			'pronamic_payment_create_invoice_' . $post->ID
95
		);
96
97
		$link_text = sprintf(
98
			/* translators: %s: payment method name */
99
			__( 'Create %1$s invoice', 'pronamic_ideal' ),
100
			PaymentMethods::get_name( $payment->get_method() )
101
		);
102
103
		printf(
104
			'<p><a class="button" href="%s">%s</a></p>',
105
			esc_url( $action_url ),
106
			esc_html( $link_text )
107
		);
108
	}
109
110
	/**
111
	 * Cancel payment reservations.
112
	 */
113
	if ( $gateway && $gateway->supports( 'reservation_payments' ) && 'payment_reserved' === get_post_status( $post->ID ) ) {
114
		// Only show button if gateway exists and reservation payments are supported.
115
		$action_url = wp_nonce_url(
116
			add_query_arg(
117
				array(
118
					'post'                            => $post->ID,
119
					'action'                          => 'edit',
120
					'pronamic_pay_cancel_reservation' => true,
121
				),
122
				admin_url( 'post.php' )
123
			),
124
			'pronamic_payment_cancel_reservation_' . $post->ID
125
		);
126
127
		$link_text = sprintf(
128
			/* translators: %s: payment method name */
129
			__( 'Cancel %1$s reservation', 'pronamic_ideal' ),
130
			PaymentMethods::get_name( $payment->get_method() )
131
		);
132
133
		printf(
134
			'<p><a class="button" href="%s">%s</a></p>',
135
			esc_url( $action_url ),
136
			esc_html( $link_text )
137
		);
138
	}
139
140
	/**
141
	 * Send to Google Analytics button.
142
	 */
143
	$can_track = pronamic_pay_plugin()->google_analytics_ecommerce->valid_payment( $payment );
144
145
	if ( $can_track ) {
146
		// Only show button for payments that can be tracked.
147
		$action_url = wp_nonce_url(
148
			add_query_arg(
149
				array(
150
					'post'                  => $post->ID,
151
					'action'                => 'edit',
152
					'pronamic_pay_ga_track' => true,
153
				),
154
				admin_url( 'post.php' )
155
			),
156
			'pronamic_payment_ga_track_' . $post->ID
157
		);
158
159
		printf(
160
			'<p><a class="button" href="%s">%s</a></p>',
161
			esc_url( $action_url ),
162
			esc_html__( 'Send to Google Analytics', 'pronamic_ideal' )
163
		);
164
	}
165
166
	?>
167
</div>
168
169
<div class="pronamic-pay-major-actions">
170
	<div class="pronamic-pay-action">
171
		<?php
172
173
		wp_nonce_field( 'pronamic_payment_update', 'pronamic_payment_nonce' );
174
175
		submit_button(
176
			__( 'Update', 'pronamic_ideal' ),
177
			'primary',
178
			'pronamic_payment_update',
179
			false
180
		);
181
182
		?>
183
	</div>
184
185
	<div class="clear"></div>
186
</div>
187