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