2012-12-31 18:25:09 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pay Shortcode
|
|
|
|
*
|
|
|
|
* The pay page. Used for form based gateways to show payment forms and order info.
|
|
|
|
*
|
|
|
|
* @author WooThemes
|
|
|
|
* @category Shortcodes
|
|
|
|
* @package WooCommerce/Shortcodes/Pay
|
|
|
|
* @version 2.0.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
class WC_Shortcode_Pay {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the shortcode content.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $atts
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function get( $atts ) {
|
|
|
|
global $woocommerce;
|
|
|
|
return $woocommerce->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output the shortcode.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $atts
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function output( $atts ) {
|
|
|
|
global $woocommerce;
|
|
|
|
|
2013-01-02 12:59:36 +00:00
|
|
|
do_action( 'before_woocommerce_pay' );
|
2012-12-31 18:25:09 +00:00
|
|
|
|
|
|
|
$woocommerce->show_messages();
|
|
|
|
|
2013-01-02 12:59:36 +00:00
|
|
|
if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) {
|
2012-12-31 18:25:09 +00:00
|
|
|
|
|
|
|
// Pay for existing order
|
2013-03-06 23:42:48 +00:00
|
|
|
$order_key = urldecode( $_GET[ 'order' ] );
|
|
|
|
$order_id = absint( $_GET[ 'order_id' ] );
|
|
|
|
$order = new WC_Order( $order_id );
|
|
|
|
$valid_order_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $order );
|
2012-12-31 18:25:09 +00:00
|
|
|
|
2013-03-06 23:42:48 +00:00
|
|
|
if ( $order->id == $order_id && $order->order_key == $order_key && in_array( $order->status, $valid_order_statuses ) ) {
|
2012-12-31 18:25:09 +00:00
|
|
|
|
|
|
|
// Set customer location to order location
|
2013-01-02 12:59:36 +00:00
|
|
|
if ( $order->billing_country )
|
|
|
|
$woocommerce->customer->set_country( $order->billing_country );
|
|
|
|
if ( $order->billing_state )
|
|
|
|
$woocommerce->customer->set_state( $order->billing_state );
|
|
|
|
if ( $order->billing_postcode )
|
|
|
|
$woocommerce->customer->set_postcode( $order->billing_postcode );
|
2012-12-31 18:25:09 +00:00
|
|
|
|
|
|
|
// Show form
|
2013-01-07 17:23:09 +00:00
|
|
|
woocommerce_get_template( 'checkout/form-pay.php', array( 'order' => $order ) );
|
2012-12-31 18:25:09 +00:00
|
|
|
|
2013-03-06 23:42:48 +00:00
|
|
|
} elseif ( ! in_array( $order->status, $valid_order_statuses ) ) {
|
2012-12-31 18:25:09 +00:00
|
|
|
|
|
|
|
$woocommerce->add_error( __( 'Your order has already been paid for. Please contact us if you need assistance.', 'woocommerce' ) );
|
|
|
|
$woocommerce->show_messages();
|
|
|
|
|
2013-01-02 12:59:36 +00:00
|
|
|
} else {
|
2012-12-31 18:25:09 +00:00
|
|
|
|
|
|
|
$woocommerce->add_error( __( 'Invalid order.', 'woocommerce' ) );
|
|
|
|
$woocommerce->show_messages();
|
|
|
|
|
2013-01-02 12:59:36 +00:00
|
|
|
}
|
2012-12-31 18:25:09 +00:00
|
|
|
|
2013-01-02 12:59:36 +00:00
|
|
|
} else {
|
2012-12-31 18:25:09 +00:00
|
|
|
|
|
|
|
// Pay for order after checkout step
|
2013-01-02 12:59:36 +00:00
|
|
|
$order_id = isset( $_GET['order'] ) ? absint( $_GET['order'] ) : 0;
|
|
|
|
$order_key = isset( $_GET['key'] ) ? woocommerce_clean( $_GET['key'] ) : '';
|
2012-12-31 18:25:09 +00:00
|
|
|
|
2013-01-02 12:59:36 +00:00
|
|
|
if ( $order_id > 0 ) {
|
2012-12-31 18:25:09 +00:00
|
|
|
|
2013-03-06 23:42:48 +00:00
|
|
|
$order = new WC_Order( $order_id );
|
|
|
|
$valid_order_statuses = apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $order );
|
2012-12-31 18:25:09 +00:00
|
|
|
|
2013-03-06 23:42:48 +00:00
|
|
|
if ( $order->order_key == $order_key && in_array( $order->status, $valid_order_statuses ) ) {
|
2012-12-31 18:25:09 +00:00
|
|
|
|
|
|
|
?>
|
|
|
|
<ul class="order_details">
|
|
|
|
<li class="order">
|
|
|
|
<?php _e( 'Order:', 'woocommerce' ); ?>
|
|
|
|
<strong><?php echo $order->get_order_number(); ?></strong>
|
|
|
|
</li>
|
|
|
|
<li class="date">
|
|
|
|
<?php _e( 'Date:', 'woocommerce' ); ?>
|
|
|
|
<strong><?php echo date_i18n(get_option('date_format'), strtotime($order->order_date)); ?></strong>
|
|
|
|
</li>
|
|
|
|
<li class="total">
|
|
|
|
<?php _e( 'Total:', 'woocommerce' ); ?>
|
|
|
|
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
|
|
|
|
</li>
|
|
|
|
<?php if ($order->payment_method_title) : ?>
|
|
|
|
<li class="method">
|
|
|
|
<?php _e( 'Payment method:', 'woocommerce' ); ?>
|
|
|
|
<strong><?php
|
|
|
|
echo $order->payment_method_title;
|
|
|
|
?></strong>
|
|
|
|
</li>
|
|
|
|
<?php endif; ?>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<?php do_action( 'woocommerce_receipt_' . $order->payment_method, $order_id ); ?>
|
|
|
|
|
|
|
|
<div class="clear"></div>
|
|
|
|
<?php
|
|
|
|
|
2013-03-06 23:42:48 +00:00
|
|
|
} elseif ( ! in_array( $order->status, $valid_order_statuses ) ) {
|
2012-12-31 18:25:09 +00:00
|
|
|
|
|
|
|
$woocommerce->add_error( __( 'Your order has already been paid for. Please contact us if you need assistance.', 'woocommerce' ) );
|
|
|
|
$woocommerce->show_messages();
|
|
|
|
|
2013-01-02 12:59:36 +00:00
|
|
|
}
|
2012-12-31 18:25:09 +00:00
|
|
|
|
2013-01-02 12:59:36 +00:00
|
|
|
} else {
|
2012-12-31 18:25:09 +00:00
|
|
|
|
|
|
|
$woocommerce->add_error( __( 'Invalid order.', 'woocommerce' ) );
|
|
|
|
$woocommerce->show_messages();
|
|
|
|
|
2013-01-02 12:59:36 +00:00
|
|
|
}
|
2012-12-31 18:25:09 +00:00
|
|
|
|
2013-01-02 12:59:36 +00:00
|
|
|
}
|
2012-12-31 18:25:09 +00:00
|
|
|
|
2013-01-02 12:59:36 +00:00
|
|
|
do_action( 'after_woocommerce_pay' );
|
2012-12-31 18:25:09 +00:00
|
|
|
}
|
|
|
|
}
|