</div><!-- /.inside -->
							</div><!-- /#edd-billing-details -->

							<?php 
do_action('edd_view_order_details_billing_after', $payment_id);
?>

							<div id="edd-payment-notes" class="postbox">
								<h3 class="hndle"><span><?php 
_e('Payment Notes', 'edd');
?>
</span></h3>
								<div class="inside">
									<div id="edd-payment-notes-inner">
										<?php 
$notes = edd_get_payment_notes($payment_id);
if (!empty($notes)) {
    $no_notes_display = ' style="display:none;"';
    foreach ($notes as $note) {
        echo edd_get_payment_note_html($note, $payment_id);
    }
} else {
    $no_notes_display = '';
}
echo '<p class="edd-no-payment-notes"' . $no_notes_display . '>' . __('No payment notes', 'edd') . '</p>';
?>
									</div>
									<textarea name="edd-payment-note" id="edd-payment-note" class="large-text"></textarea>

									<p>
										<button id="edd-add-payment-note" class="button button-secondary right" data-payment-id="<?php 
/**
 * Given a Payment ID, extract the transaction ID
 *
 * @since  2.1
 * @param  string $payment_id       Payment ID
 * @return string                   Transaction ID
 */
function edd_paypal_get_payment_transaction_id($payment_id)
{
    $transaction_id = '';
    $notes = edd_get_payment_notes($payment_id);
    foreach ($notes as $note) {
        if (preg_match('/^PayPal Transaction ID: ([^\\s]+)/', $note->comment_content, $match)) {
            $transaction_id = $match[1];
            continue;
        }
    }
    return apply_filters('edd_paypal_set_payment_transaction_id', $transaction_id, $payment_id);
}
 /**
  * Search
  *
  * @access public
  * @since 1.8
  * @return void
  */
 public function search()
 {
     if (!isset($this->args['s'])) {
         return;
     }
     $search = trim($this->args['s']);
     if (empty($search)) {
         return;
     }
     $is_email = is_email($search) || strpos($search, '@') !== false;
     $is_user = strpos($search, strtolower('user:'******'search_in_notes'])) {
         $notes = edd_get_payment_notes(0, $search);
         if (!empty($notes)) {
             $payment_ids = wp_list_pluck((array) $notes, 'comment_post_ID');
             $this->__set('post__in', $payment_ids);
         }
         $this->__unset('s');
     } elseif ($is_email || strlen($search) == 32) {
         $key = $is_email ? '_edd_payment_user_email' : '_edd_payment_purchase_key';
         $search_meta = array('key' => $key, 'value' => $search, 'compare' => 'LIKE');
         $this->__set('meta_query', $search_meta);
         $this->__unset('s');
     } elseif ($is_user) {
         $search_meta = array('key' => '_edd_payment_user_id', 'value' => trim(str_replace('user:'******'', strtolower($search))));
         $this->__set('meta_query', $search_meta);
         if (edd_get_option('enable_sequential')) {
             $search_meta = array('key' => '_edd_payment_number', 'value' => $search, 'compare' => 'LIKE');
             $this->__set('meta_query', $search_meta);
             $this->args['meta_query']['relation'] = 'OR';
         }
         $this->__unset('s');
     } elseif (edd_get_option('enable_sequential') && (false !== strpos($search, edd_get_option('sequential_prefix')) || false !== strpos($search, edd_get_option('sequential_postfix')))) {
         $search_meta = array('key' => '_edd_payment_number', 'value' => $search, 'compare' => 'LIKE');
         $this->__set('meta_query', $search_meta);
         $this->__unset('s');
     } elseif (is_numeric($search)) {
         $post = get_post($search);
         if (is_object($post) && $post->post_type == 'edd_payment') {
             $arr = array();
             $arr[] = $search;
             $this->__set('post__in', $arr);
             $this->__unset('s');
         }
     } elseif ('#' == substr($search, 0, 1)) {
         $search = str_replace('#:', '', $search);
         $search = str_replace('#', '', $search);
         $this->__set('download', $search);
         $this->__unset('s');
     } elseif (0 === strpos($search, 'discount:')) {
         $search = trim(str_replace('discount:', '', $search));
         $search = 'discount.*' . $search;
         $search_meta = array('key' => '_edd_payment_meta', 'value' => $search, 'compare' => 'REGEXP');
         $this->__set('meta_query', $search_meta);
         $this->__unset('s');
     } else {
         $this->__set('s', $search);
     }
 }
 /**
  * Get the payment method used for the given $payment_id. Returns a link to the transaction in Stripe or PayPal if possible.
  *
  * @param int $payment_id
  *
  * @return string
  */
 private function get_payment_method($payment_id)
 {
     $payment_method = edd_get_payment_gateway($payment_id);
     switch ($payment_method) {
         case 'paypal':
             $notes = edd_get_payment_notes($payment_id);
             foreach ($notes as $note) {
                 if (preg_match('/^PayPal Transaction ID: ([^\\s]+)/', $note->comment_content, $match)) {
                     $transaction_id = $match[1];
                     $payment_method = '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . esc_attr($transaction_id) . '" target="_blank">PayPal</a>';
                     break 2;
                 }
             }
             break;
         case 'stripe':
             $notes = edd_get_payment_notes($payment_id);
             foreach ($notes as $note) {
                 if (preg_match('/^Stripe Charge ID: ([^\\s]+)/', $note->comment_content, $match)) {
                     $transaction_id = $match[1];
                     $payment_method = '<a href="https://dashboard.stripe.com/payments/' . esc_attr($transaction_id) . '" target="_blank">Stripe</a>';
                     break 2;
                 }
             }
             break;
         case 'manual_purchases':
             $payment_method = 'Manual';
             break;
     }
     return $payment_method;
 }
"><?php 
printf(__('Add %s to purchase', 'edd'), strtolower(edd_get_label_plural()));
?>
</a></p>
					</td>
				</tr>
				<tr>
					<th scope="row" valign="top">
						<span><?php 
_e('Payment Notes', 'edd');
?>
</span>
					</th>
					<td>
						<?php 
$notes = edd_get_payment_notes($payment->ID);
if (!empty($notes)) {
    echo '<ul id="payment-notes">';
    foreach ($notes as $note) {
        if (!empty($note->user_id)) {
            $user = get_userdata($note->user_id);
            $user = $user->display_name;
        } else {
            $user = __('EDD Bot', 'edd');
        }
        $delete_note_url = wp_nonce_url(add_query_arg(array('edd-action' => 'delete_payment_note', 'note_id' => $note->comment_ID)), 'edd_delete_payment_note');
        echo '<li>';
        echo '<strong>' . $user . '</strong>&nbsp;<em>' . $note->comment_date . '</em>&nbsp;&mdash;&nbsp;' . $note->comment_content;
        echo '&nbsp;&ndash;&nbsp;<a href="' . $delete_note_url . '" class="edd-delete-payment-note" title="' . __('Delete this payment note', 'edd') . '">' . __('Delete', 'edd') . '</a>';
        echo '</li>';
    }
    /**
     * Render the details column
     *
     * @access      private
     * @since       1.3.4
     * @return      string
     */
    function column_details($item)
    {
        $details = "<a href='#TB_inline?width=640&amp;inlineId=purchased-files-" . $item['ID'] . "' class='thickbox' title='" . sprintf(__('Purchase Details for Payment #%s', 'edd'), $item['ID']) . "'>" . __('View Order Details', 'edd') . "</a>";
        ob_start();
        ?>
			<div id="purchased-files-<?php 
        echo $item['ID'];
        ?>
" style="display: none;">
				<?php 
        $payment_meta = edd_get_payment_meta($item['ID']);
        $cart_items = isset($payment_meta['cart_details']) ? maybe_unserialize($payment_meta['cart_details']) : false;
        if (empty($cart_items) || !$cart_items) {
            $cart_items = maybe_unserialize($payment_meta['downloads']);
        }
        ?>
				<h4><?php 
        echo _n(__('Purchased File', 'edd'), __('Purchased Files', 'edd'), count($cart_items));
        ?>
</h4>
				<ul class="purchased-files-list">
				<?php 
        if ($cart_items) {
            foreach ($cart_items as $key => $cart_item) {
                echo '<li>';
                // Retrieve the ID of the download
                $id = isset($payment_meta['cart_details']) ? $cart_item['id'] : $cart_item;
                // If download has variable prices, override the default price
                $price_override = isset($payment_meta['cart_details']) ? $cart_item['price'] : null;
                // Get the user information
                $user_info = edd_get_payment_meta_user_info($item['ID']);
                // Calculate the final item price
                $price = edd_get_download_final_price($id, $user_info, $price_override);
                // Show name of download
                echo '<a href="' . admin_url('post.php?post=' . $id . '&action=edit') . '" target="_blank">' . get_the_title($id) . '</a>';
                echo ' - ';
                if (isset($cart_items[$key]['item_number'])) {
                    $price_options = $cart_items[$key]['item_number']['options'];
                    if (isset($price_options['price_id'])) {
                        echo edd_get_price_option_name($id, $price_options['price_id']);
                        echo ' - ';
                    }
                }
                // Show the price
                echo edd_currency_filter(edd_format_amount($price));
                echo '</li>';
            }
        }
        ?>
				</ul>
				<?php 
        $payment_date = strtotime($item['date']);
        ?>
				<p><?php 
        echo __('Date and Time:', 'edd') . ' ' . date_i18n(get_option('date_format'), $payment_date) . ' ' . date_i18n(get_option('time_format'), $payment_date);
        ?>
				<p><?php 
        echo __('Discount used:', 'edd') . ' ';
        if (isset($user_info['discount']) && $user_info['discount'] != 'none') {
            echo $user_info['discount'];
        } else {
            _e('none', 'edd');
        }
        ?>
				<p><?php 
        echo __('Total:', 'edd') . ' ' . edd_currency_filter(edd_format_amount(edd_get_payment_amount($item['ID'])));
        ?>
</p>

				<div class="purcase-personal-details">
					<h4><?php 
        _e('Buyer\'s Personal Details:', 'edd');
        ?>
</h4>
					<ul>
						<li><?php 
        echo __('Name:', 'edd') . ' ' . $user_info['first_name'] . ' ' . $user_info['last_name'];
        ?>
</li>
						<li><?php 
        echo __('Email:', 'edd') . ' ' . $payment_meta['email'];
        ?>
</li>
						<?php 
        do_action('edd_payment_personal_details_list', $payment_meta, $user_info);
        ?>
					</ul>
				</div>
				<div class="payment-notes">
					<h4><?php 
        _e('Payment Notes', 'edd');
        ?>
</h4>
					<?php 
        $notes = edd_get_payment_notes($item['ID']);
        if (!empty($notes)) {
            echo '<ul id="payment-notes">';
            foreach ($notes as $note) {
                if (!empty($note->user_id)) {
                    $user = get_userdata($note->user_id);
                    $user = $user->display_name;
                } else {
                    $user = __('EDD Bot', 'edd');
                }
                echo '<div class="edd-payment-note"><strong>' . $user . '</strong>&nbsp;<em>' . $note->comment_date . '</em>&nbsp;&mdash;' . $note->comment_content . '</div>';
            }
            echo '</ul>';
        } else {
            echo '<p>' . __('No payment notes', 'edd') . '</p>';
        }
        ?>
				</div>
				<?php 
        $gateway = edd_get_payment_gateway($item['ID']);
        if ($gateway) {
            ?>
				<div class="payment-method">
					<h4><?php 
            _e('Payment Method:', 'edd');
            ?>
</h4>
					<span class="payment-method-name"><?php 
            echo edd_get_gateway_admin_label($gateway);
            ?>
</span>
				</div>
				<?php 
        }
        ?>
				<div class="purchase-key-wrap">
					<h4><?php 
        _e('Purchase Key', 'edd');
        ?>
</h4>
					<span class="purchase-key"><?php 
        echo $payment_meta['key'];
        ?>
</span>
				</div>
				<p><a id="edd-close-purchase-details" class="button-secondary" onclick="tb_remove();" title="<?php 
        _e('Close', 'edd');
        ?>
"><?php 
        _e('Close', 'edd');
        ?>
</a></p>
			</div>
<?php 
        $details .= ob_get_clean();
        return $details;
    }