Included method to define a link format for a transaction ID, set transaction ID manually, and tweaked display.

This commit is contained in:
Mike Jolley 2014-06-27 13:12:10 +01:00
parent 50a4c5bd23
commit cc1d1e2237
5 changed files with 64 additions and 39 deletions

File diff suppressed because one or more lines are too long

View File

@ -517,7 +517,7 @@ ul.wc_coupon_list_block {
._shipping_last_name_field, ._shipping_address_2_field, ._shipping_postcode_field, ._shipping_state_field {
float: right;
}
._billing_company_field, ._shipping_company_field {
._billing_company_field, ._shipping_company_field, ._transaction_id_field {
clear: both;
width: 100%;
}

View File

@ -17,41 +17,44 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
abstract class WC_Payment_Gateway extends WC_Settings_API {
/** @var string Payment method ID. */
var $id;
public $id;
/** @var string Set if the place order button should be renamed on selection. */
var $order_button_text;
public $order_button_text;
/** @var string Payment method title. */
var $title;
public $title;
/** @var string Chosen payment method id. */
var $chosen;
public $chosen;
/** @var bool True if the gateway shows fields on the checkout. */
var $has_fields;
public $has_fields;
/** @var array Array of countries this gateway is allowed for. */
var $countries;
public $countries;
/** @var string Available for all counties or specific. */
var $availability;
public $availability;
/** @var string 'yes' if the method is enabled. */
var $enabled;
public $enabled;
/** @var string Icon for the gateway. */
var $icon;
public $icon;
/** @var string Description for the gateway. */
var $description;
public $description;
/** @var array Array of supported features such as 'default_credit_card_form' */
var $supports = array( 'products' );
public $supports = array( 'products' );
/** @var int Maximum transaction amount, zero does not define a maximum */
public $max_amount = 0;
/** @var string Optional URL to view a transaction */
public $view_transaction_url = '';
/**
* Get the return url (thank you page)
*
@ -73,6 +76,19 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
return apply_filters( 'woocommerce_get_return_url', $return_url );
}
/**
* Get a link to the transaction on the 3rd party gateway size (if applicable)
* @param string $transaction_id
* @return string
*/
public function get_transaction_url( $transaction_id ) {
$return_url = '';
if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
$return_url = sprintf( $this->view_transaction_url, $transaction_id );
}
return apply_filters( 'woocommerce_get_transaction_url', $return_url, $transaction_id, $this );
}
/**
* Get the order total in checkout and pay_for_order.
*

View File

@ -140,6 +140,12 @@ class WC_Meta_Box_Order_Data {
self::init_address_fields();
if ( WC()->payment_gateways() ) {
$payment_gateways = WC()->payment_gateways->payment_gateways();
}
$payment_method = ! empty( $order->payment_method ) ? $order->payment_method : '';
wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
?>
<style type="text/css">
@ -150,13 +156,24 @@ class WC_Meta_Box_Order_Data {
<input name="post_status" type="hidden" value="publish" />
<div id="order_data" class="panel">
<h2><?php _e( 'Order Details', 'woocommerce' ); ?></h2>
<h2><?php printf( __( 'Order %s details', 'woocommerce' ), esc_html( $order->get_order_number() ) ); ?></h2>
<p class="order_number"><?php
echo __( 'Order number', 'woocommerce' ) . ' ' . esc_html( $order->get_order_number() ) . '. ';
if ( $payment_method ) {
printf( __( 'Payment via %s', 'woocommerce' ), ( isset( $payment_gateways[ $payment_method ] ) ? esc_html( $payment_gateways[ $payment_method ]->get_title() ) : esc_html( $payment_method ) ) );
if ( $transaction_id = get_post_meta( $order->id, '_transaction_id', true ) ) {
if ( isset( $payment_gateways[ $payment_method ] ) && ( $url = $payment_gateways[ $payment_method ]->get_transaction_url( $transaction_id ) ) ) {
echo ' (<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $transaction_id ) . '</a>)';
} else {
echo ' (' . esc_html( $transaction_id ) . ')';
}
}
echo '. ';
}
if ( $ip_address = get_post_meta( $post->ID, '_customer_ip_address', true ) ) {
echo __( 'Customer IP:', 'woocommerce' ) . ' ' . esc_html( $ip_address );
echo __( 'Customer IP', 'woocommerce' ) . ': ' . esc_html( $ip_address );
}
?></p>
@ -217,20 +234,6 @@ class WC_Meta_Box_Order_Data {
}
}
if ( WC()->payment_gateways() ) {
$payment_gateways = WC()->payment_gateways->payment_gateways();
}
$payment_method = ! empty( $order->payment_method ) ? $order->payment_method : '';
if ( $payment_method ) {
echo '<p><strong>' . __( 'Payment Method', 'woocommerce' ) . ':</strong> ' . ( isset( $payment_gateways[ $payment_method ] ) ? esc_html( $payment_gateways[ $payment_method ]->get_title() ) : esc_html( $payment_method ) ) . '</p>';
}
if ( $transaction_id = get_post_meta( $order->id, '_transaction_id', true ) ) {
echo '<p><strong>' . __( 'Payment Transaction ID', 'woocommerce' ) . ':</strong> ' . esc_html( $transaction_id ) . '</p>';
}
echo '</div>';
// Display form
@ -278,6 +281,8 @@ class WC_Meta_Box_Order_Data {
</p>
<?php
woocommerce_wp_text_input( array( 'id' => '_transaction_id', 'label' => __( 'Transaction ID', 'woocommerce' ) ) );
echo '</div>';
do_action( 'woocommerce_admin_order_data_after_billing_address', $order );
@ -405,6 +410,10 @@ class WC_Meta_Box_Order_Data {
}
}
if ( isset( $_POST['_transaction_id'] ) ) {
update_post_meta( $post_id, '_transaction_id', wc_clean( $_POST[ '_transaction_id' ] ) );
}
// Payment method handling
if ( get_post_meta( $post_id, '_payment_method', true ) !== stripslashes( $_POST['_payment_method'] ) ) {

View File

@ -24,15 +24,15 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
* @return void
*/
public function __construct() {
$this->id = 'paypal';
$this->icon = apply_filters( 'woocommerce_paypal_icon', WC()->plugin_url() . '/assets/images/icons/paypal.png' );
$this->has_fields = false;
$this->order_button_text = __( 'Proceed to PayPal', 'woocommerce' );
$this->liveurl = 'https://www.paypal.com/cgi-bin/webscr';
$this->testurl = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$this->method_title = __( 'PayPal', 'woocommerce' );
$this->notify_url = WC()->api_request_url( 'WC_Gateway_Paypal' );
$this->id = 'paypal';
$this->icon = apply_filters( 'woocommerce_paypal_icon', WC()->plugin_url() . '/assets/images/icons/paypal.png' );
$this->has_fields = false;
$this->order_button_text = __( 'Proceed to PayPal', 'woocommerce' );
$this->liveurl = 'https://www.paypal.com/cgi-bin/webscr';
$this->testurl = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$this->method_title = __( 'PayPal', 'woocommerce' );
$this->view_transaction_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=%s';
$this->notify_url = WC()->api_request_url( 'WC_Gateway_Paypal' );
// Load the settings.
$this->init_form_fields();