Exemplo n.º 1
0
function get_order_email_arguments($order_id)
{
    $options = Jigoshop_Base::get_options();
    $order = new jigoshop_order($order_id);
    $inc_tax = $options->get('jigoshop_calc_taxes') == 'no' || $options->get('jigoshop_prices_include_tax') == 'yes';
    $can_show_links = $order->status == 'completed' || $order->status == 'processing';
    $statuses = $order->get_order_statuses_and_names();
    $variables = array('blog_name' => get_bloginfo('name'), 'order_number' => $order->get_order_number(), 'order_date' => date_i18n(get_option('date_format')), 'order_status' => $statuses[$order->status], 'shop_name' => $options->get('jigoshop_company_name'), 'shop_address_1' => $options->get('jigoshop_address_1'), 'shop_address_2' => $options->get('jigoshop_address_2'), 'shop_tax_number' => $options->get('jigoshop_tax_number'), 'shop_phone' => $options->get('jigoshop_company_phone'), 'shop_email' => $options->get('jigoshop_company_email'), 'customer_note' => $order->customer_note, 'order_items_table' => jigoshop_get_order_items_table($order, $can_show_links, true, $inc_tax), 'order_items' => $order->email_order_items_list($can_show_links, true, $inc_tax), 'order_taxes' => jigoshop_get_order_taxes_list($order), 'subtotal' => $order->get_subtotal_to_display(), 'shipping' => $order->get_shipping_to_display(), 'shipping_cost' => jigoshop_price($order->order_shipping), 'shipping_method' => $order->shipping_service, 'discount' => jigoshop_price($order->order_discount), 'applied_coupons' => jigoshop_get_order_coupon_list($order), 'total_tax' => jigoshop_price($order->get_total_tax()), 'total' => jigoshop_price($order->order_total), 'is_local_pickup' => $order->shipping_method == 'local_pickup' ? true : null, 'checkout_url' => $order->status == 'pending' ? $order->get_checkout_payment_url() : null, 'payment_method' => $order->payment_method_title, 'is_bank_transfer' => $order->payment_method == 'bank_transfer' ? true : null, 'is_cash_on_delivery' => $order->payment_method == 'cod' ? true : null, 'is_cheque' => $order->payment_method == 'cheque' ? true : null, 'bank_info' => str_replace(PHP_EOL, '', jigoshop_bank_transfer::get_bank_details()), 'cheque_info' => str_replace(PHP_EOL, '', $options->get('jigoshop_cheque_description')), 'billing_first_name' => $order->billing_first_name, 'billing_last_name' => $order->billing_last_name, 'billing_company' => $order->billing_company, 'billing_euvatno' => $order->billing_euvatno, 'billing_address_1' => $order->billing_address_1, 'billing_address_2' => $order->billing_address_2, 'billing_postcode' => $order->billing_postcode, 'billing_city' => $order->billing_city, 'billing_country' => jigoshop_countries::get_country($order->billing_country), 'billing_state' => strlen($order->billing_state) == 2 ? jigoshop_countries::get_state($order->billing_country, $order->billing_state) : $order->billing_state, 'billing_country_raw' => $order->billing_country, 'billing state_raw' => $order->billing_state, 'billing_email' => $order->billing_email, 'billing_phone' => $order->billing_phone, 'shipping_first_name' => $order->shipping_first_name, 'shipping_last_name' => $order->shipping_last_name, 'shipping_company' => $order->shipping_company, 'shipping_address_1' => $order->shipping_address_1, 'shipping_address_2' => $order->shipping_address_2, 'shipping_postcode' => $order->shipping_postcode, 'shipping_city' => $order->shipping_city, 'shipping_country' => jigoshop_countries::get_country($order->shipping_country), 'shipping_state' => strlen($order->shipping_state) == 2 ? jigoshop_countries::get_state($order->shipping_country, $order->shipping_state) : $order->shipping_state, 'shipping_country_raw' => $order->shipping_country, 'shipping_state_raw' => $order->shipping_state);
    if ($options->get('jigoshop_calc_taxes') == 'yes') {
        $variables['all_tax_classes'] = $variables['order_taxes'];
    } else {
        unset($variables['order_taxes']);
    }
    return apply_filters('jigoshop_order_email_variables', $variables, $order_id);
}
Exemplo n.º 2
0
/**
 * Outputs the pay page - payment gateways can hook in here to show payment forms etc
 **/
function jigoshop_pay()
{
    if (isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id'])) {
        // Pay for existing order
        $order_key = urldecode($_GET['order']);
        $order_id = (int) $_GET['order_id'];
        $order = new jigoshop_order($order_id);
        jigoshop::show_messages();
        if ($order->id == $order_id && $order->order_key == $order_key && $order->status == 'pending') {
            jigoshop_pay_for_existing_order($order);
        }
    } else {
        // Pay for order after checkout step
        if (isset($_GET['order'])) {
            $order_id = $_GET['order'];
        } else {
            $order_id = 0;
        }
        if (isset($_GET['key'])) {
            $order_key = $_GET['key'];
        } else {
            $order_key = '';
        }
        if ($order_id > 0) {
            $order = new jigoshop_order($order_id);
            if ($order->order_key == $order_key && $order->status == 'pending') {
                jigoshop::show_messages();
                ?>
				<ul class="order_details">
					<li class="order">
						<?php 
                _e('Order:', 'jigoshop');
                ?>
						<strong><?php 
                echo $order->get_order_number();
                ?>
</strong>
					</li>
					<li class="date">
						<?php 
                _e('Date:', 'jigoshop');
                ?>
						<strong><?php 
                echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($order->order_date));
                ?>
</strong>
					</li>
					<li class="total">
						<?php 
                _e('Total:', 'jigoshop');
                ?>
						<strong><?php 
                echo jigoshop_price($order->order_total);
                ?>
</strong>
					</li>
					<li class="method">
						<?php 
                _e('Payment method:', 'jigoshop');
                ?>
						<strong><?php 
                $gateways = jigoshop_payment_gateways::payment_gateways();
                if (isset($gateways[$order->payment_method])) {
                    echo $gateways[$order->payment_method]->title;
                } else {
                    echo $order->payment_method;
                }
                ?>
</strong>
					</li>
				</ul>

				<?php 
                do_action('receipt_' . $order->payment_method, $order_id);
                ?>

				<div class="clear"></div>
			<?php 
            }
        }
    }
}
Exemplo n.º 3
0
 /**
  * Successful payment processing
  *
  * @param array $posted
  */
 function successful_request($posted)
 {
     $posted = stripslashes_deep($posted);
     // 'custom' holds post ID (Order ID)
     if (!empty($posted['custom']) && !empty($posted['txn_type']) && !empty($posted['invoice'])) {
         $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money', 'subscr_payment');
         $order = new jigoshop_order((int) $posted['custom']);
         // Sandbox fix
         if (isset($posted['test_ipn']) && $posted['test_ipn'] == 1 && strtolower($posted['payment_status']) == 'pending') {
             $posted['payment_status'] = 'completed';
         }
         $merchant = $this->testmode == 'no' ? $this->email : $this->testemail;
         if ($order->status !== 'completed') {
             // We are here so lets check status and do actions
             switch (strtolower($posted['payment_status'])) {
                 case 'completed':
                     if (!in_array(strtolower($posted['txn_type']), $accepted_types)) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Unknown "txn_type" of "%s" for Order ID: %s.', 'jigoshop'), $posted['txn_type'], $posted['custom']));
                         exit;
                     }
                     if ($order->get_order_number() !== $posted['invoice']) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Order Invoice Number does NOT match PayPal posted invoice (%s) for Order ID: .', 'jigoshop'), $posted['invoice'], $posted['custom']));
                         exit;
                     }
                     // Validate Amount
                     if (number_format((double) $order->order_total, $this->decimals, '.', '') != $posted['mc_gross']) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment amounts do not match initial order (gross %s).', 'jigoshop'), $posted['mc_gross']));
                         exit;
                     }
                     if (strcasecmp(trim($posted['business']), trim($merchant)) != 0) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment Merchant email received does not match PayPal Gateway settings. (%s)', 'jigoshop'), $posted['business']));
                         exit;
                     }
                     if (!in_array($posted['mc_currency'], apply_filters('jigoshop_multi_currencies_available', array(Jigoshop_Base::get_options()->get('jigoshop_currency'))))) {
                         // Put this order on-hold for manual checking
                         $order->update_status('on-hold', sprintf(__('PayPal Validation Error: Payment currency received (%s) does not match Shop currency.', 'jigoshop'), $posted['mc_currency']));
                         exit;
                     }
                     $order->add_order_note(__('PayPal Standard payment completed', 'jigoshop'));
                     $order->payment_complete();
                     jigoshop_log('PAYPAL: IPN payment completed for Order ID: ' . $posted['custom']);
                     break;
                 case 'denied':
                 case 'expired':
                 case 'failed':
                 case 'voided':
                     // Failed order
                     $order->update_status('failed', sprintf(__('Payment %s via IPN.', 'jigoshop'), strtolower($posted['payment_status'])));
                     jigoshop_log("PAYPAL: failed order with status = " . strtolower($posted['payment_status']) . "for Order ID: " . $posted['custom']);
                     break;
                 case 'refunded':
                 case 'reversed':
                 case 'chargeback':
                     jigoshop_log("PAYPAL: payment status type - '" . $posted['payment_status'] . "' - not supported for Order ID: " . $posted['custom']);
                     break;
             }
         }
         exit;
     } else {
         jigoshop_log("PAYPAL: function 'successful_request' -- empty initial required values -- EXITING!\n'posted' values = " . print_r($posted, true));
     }
 }
function jigoshop_custom_order_columns($column)
{
    global $post;
    $jigoshop_options = Jigoshop_Base::get_options();
    $order = new jigoshop_order($post->ID);
    switch ($column) {
        case "order_status":
            echo sprintf('<mark class="%s">%s</mark>', sanitize_title($order->status), __($order->status, 'jigoshop'));
            break;
        case "order_title":
            echo '<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '">' . sprintf(__('Order %s', 'jigoshop'), $order->get_order_number()) . '</a>';
            echo '<time title="' . date_i18n(_x('c', 'date', 'jigoshop'), strtotime($post->post_date)) . '">' . date_i18n(__('F j, Y, g:i a', 'jigoshop'), strtotime($post->post_date)) . '</time>';
            break;
        case "customer":
            if ($order->user_id) {
                $user_info = get_userdata($order->user_id);
            }
            ?>
            <dl>
                <dt><?php 
            _e('User:'******'jigoshop');
            ?>
</dt>
                <dd><?php 
            if (isset($user_info) && $user_info) {
                echo '<a href="user-edit.php?user_id=' . $user_info->ID . '">#' . $user_info->ID . ' &ndash; <strong>';
                if ($user_info->first_name || $user_info->last_name) {
                    echo $user_info->first_name . ' ' . $user_info->last_name;
                } else {
                    echo $user_info->display_name;
                }
                echo '</strong></a>';
            } else {
                _e('Guest', 'jigoshop');
            }
            ?>
</dd>
                <?php 
            if ($order->billing_email) {
                ?>
<dt><?php 
                _e('Billing Email:', 'jigoshop');
                ?>
</dt>
                    <dd><a href="mailto:<?php 
                echo $order->billing_email;
                ?>
"><?php 
                echo $order->billing_email;
                ?>
</a></dd><?php 
            }
            ?>
                <?php 
            if ($order->billing_phone) {
                ?>
<dt><?php 
                _e('Billing Phone:', 'jigoshop');
                ?>
</dt>
                    <dd><?php 
                echo $order->billing_phone;
                ?>
</dd><?php 
            }
            ?>
            </dl>
            <?php 
            break;
        case "billing_address":
            echo '<strong>' . $order->billing_first_name . ' ' . $order->billing_last_name;
            if ($order->billing_company) {
                echo ', ' . $order->billing_company;
            }
            echo '</strong><br/>';
            echo '<a target="_blank" href="http://maps.google.co.uk/maps?&q=' . urlencode($order->formatted_billing_address) . '&z=16">' . $order->formatted_billing_address . '</a>';
            break;
        case "shipping_address":
            if ($order->formatted_shipping_address) {
                echo '<strong>' . $order->shipping_first_name . ' ' . $order->shipping_last_name;
                if ($order->shipping_company) {
                    echo ', ' . $order->shipping_company;
                }
                echo '</strong><br/>';
                echo '<a target="_blank" href="http://maps.google.co.uk/maps?&q=' . urlencode($order->formatted_shipping_address) . '&z=16">' . $order->formatted_shipping_address . '</a>';
            } else {
                echo '&ndash;';
            }
            break;
        case "billing_and_shipping":
            ?>
            <dl>
	              <?php 
            if ($order->payment_method_title) {
                ?>
                <dt><?php 
                _e('Payment:', 'jigoshop');
                ?>
</dt>
                <dd><?php 
                echo $order->payment_method_title;
                ?>
</dd>
	              <?php 
            }
            ?>
	              <?php 
            if ($order->shipping_service) {
                ?>
                <dt><?php 
                _e('Shipping:', 'jigoshop');
                ?>
</dt>
                <dd><?php 
                echo sprintf(__('%s', 'jigoshop'), $order->shipping_service);
                ?>
</dd>
	              <?php 
            }
            ?>
            </dl>
            <?php 
            break;
        case "total_cost":
            ?>
            <table cellpadding="0" cellspacing="0" class="cost">
                <tr>
                    <?php 
            if ($jigoshop_options->get('jigoshop_calc_taxes') == 'yes' && $order->has_compound_tax() || $jigoshop_options->get('jigoshop_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                ?>
                        <th><?php 
                _e('Retail Price', 'jigoshop');
                ?>
</th>
                    <?php 
            } else {
                ?>
                        <th><?php 
                _e('Subtotal', 'jigoshop');
                ?>
</th>
                    <?php 
            }
            ?>
                    <td><?php 
            echo jigoshop_price($order->order_subtotal);
            ?>
</td>
                </tr>
                <?php 
            if ($order->order_shipping > 0) {
                ?>
<tr>
                        <th><?php 
                _e('Shipping', 'jigoshop');
                ?>
</th>
                        <td><?php 
                echo jigoshop_price($order->order_shipping);
                ?>
</td>
                    </tr>
                    <?php 
            }
            do_action('jigoshop_processing_fee_after_shipping');
            if ($jigoshop_options->get('jigoshop_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                ?>
                    <tr>
                        <th><?php 
                _e('Discount', 'jigoshop');
                ?>
</th>
                        <td>-<?php 
                echo jigoshop_price($order->order_discount);
                ?>
</td>
                    </tr>
                    <?php 
            }
            if ($jigoshop_options->get('jigoshop_calc_taxes') == 'yes' && $order->has_compound_tax() || $jigoshop_options->get('jigoshop_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                ?>
<tr>
                        <th><?php 
                _e('Subtotal', 'jigoshop');
                ?>
</th>
                        <td><?php 
                echo jigoshop_price($order->order_discount_subtotal);
                ?>
</td>
                    </tr>
                    <?php 
            }
            if ($jigoshop_options->get('jigoshop_calc_taxes') == 'yes') {
                foreach ($order->get_tax_classes() as $tax_class) {
                    if ($order->show_tax_entry($tax_class)) {
                        ?>
                            <tr>
                                <th><?php 
                        echo $order->get_tax_class_for_display($tax_class) . ' (' . (double) $order->get_tax_rate($tax_class) . '%):';
                        ?>
</th>
                                <td><?php 
                        echo $order->get_tax_amount($tax_class);
                        ?>
</td>
                            </tr>
                            <?php 
                    }
                }
            }
            if ($jigoshop_options->get('jigoshop_tax_after_coupon') == 'no' && $order->order_discount > 0) {
                ?>
<tr>
                        <th><?php 
                _e('Discount', 'jigoshop');
                ?>
</th>
                        <td>-<?php 
                echo jigoshop_price($order->order_discount);
                ?>
</td>
                    </tr><?php 
            }
            ?>
                <tr>
                    <th><?php 
            _e('Total', 'jigoshop');
            ?>
</th>
                    <td><?php 
            echo jigoshop_price($order->order_total);
            ?>
</td>
                </tr>
            </table>
            <?php 
            break;
        case 'order_coupons':
            if (!empty($order->order_discount_coupons)) {
                foreach ($order->order_discount_coupons as $used_coupon) {
                    ?>
			           <p class="order_coupon"><?php 
                    echo '#' . $used_coupon['id'] . ' - ' . $used_coupon['code'];
                    ?>
</p>
				<?php 
                }
            }
            break;
    }
}
Exemplo n.º 5
0
/**
 * Outputs the thankyou page
 **/
function jigoshop_thankyou()
{
    $thankyou_message = __('<p>Thank you. Your order has been processed successfully.</p>', 'jigoshop');
    echo apply_filters('jigoshop_thankyou_message', $thankyou_message);
    // Pay for order after checkout step
    if (isset($_GET['order'])) {
        $order_id = $_GET['order'];
    } else {
        $order_id = 0;
    }
    if (isset($_GET['key'])) {
        $order_key = $_GET['key'];
    } else {
        $order_key = '';
    }
    if ($order_id > 0) {
        $order = new jigoshop_order($order_id);
        if ($order->order_key == $order_key) {
            ?>
			<?php 
            do_action('jigoshop_thankyou_before_order_details', $order->id);
            ?>
			<ul class="order_details">
				<li class="order">
					<?php 
            _e('Order:', 'jigoshop');
            ?>
					<strong><?php 
            echo $order->get_order_number();
            ?>
</strong>
				</li>
				<li class="date">
					<?php 
            _e('Date:', 'jigoshop');
            ?>
					<strong><?php 
            echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($order->order_date));
            ?>
</strong>
				</li>
				<li class="total">
					<?php 
            _e('Total:', 'jigoshop');
            ?>
					<strong><?php 
            echo jigoshop_price($order->order_total);
            ?>
</strong>
				</li>
				<li class="method">
					<?php 
            _e('Payment method:', 'jigoshop');
            ?>
					<strong><?php 
            $gateways = jigoshop_payment_gateways::payment_gateways();
            if (isset($gateways[$order->payment_method])) {
                echo $gateways[$order->payment_method]->title;
            } else {
                echo $order->payment_method;
            }
            ?>
</strong>
				</li>
			</ul>
			<div class="clear"></div>
			<?php 
            do_action('thankyou_' . $order->payment_method, $order_id);
            do_action('jigoshop_thankyou', $order->id);
        }
    }
    echo '<p><a class="button" href="' . esc_url(jigoshop_cart::get_shop_url()) . '">' . __('&larr; Continue Shopping', 'jigoshop') . '</a></p>';
}
Exemplo n.º 6
0
function jigoshop_ga_ecommerce_tracking($order_id)
{
    $options = Jigoshop_Base::get_options();
    // Skip if disabled
    if ($options->get('jigoshop_ga_ecommerce_tracking_enabled') != 'yes') {
        return;
    }
    // Don't track the shop owners roaming
    if (current_user_can('manage_jigoshop')) {
        return;
    }
    $tracking_id = $options->get('jigoshop_ga_id');
    if (!$tracking_id) {
        return;
    }
    // Get the order and output tracking code
    $order = new jigoshop_order($order_id);
    ?>
	<script type="text/javascript">
		jigoshopGA('require', 'ecommerce');

		jigoshopGA('ecommerce:addTransaction', {
			'id': '<?php 
    echo $order->get_order_number();
    ?>
', // Transaction ID. Required.
			'affiliation': '<?php 
    bloginfo('name');
    ?>
', // Affiliation or store name.
			'revenue': '<?php 
    echo $order->order_total;
    ?>
', // Grand Total.
			'shipping': '<?php 
    echo $order->order_shipping;
    ?>
', // Shipping.
			'tax': '<?php 
    echo $order->get_total_tax();
    ?>
' // Tax.
		});

		<?php 
    foreach ($order->items as $item) {
        $_product = $order->get_product_from_item($item);
        ?>
		jigoshopGA('ecommerce:addItem', {
			'id': '<?php 
        echo $order->get_order_number();
        ?>
', // Transaction ID. Required.
			'name': '<?php 
        echo $item['name'];
        ?>
', // Product name. Required.
			'sku': '<?php 
        echo $_product->sku;
        ?>
', // SKU/code.
			'category': '<?php 
        if (isset($_product->variation_data)) {
            echo jigoshop_get_formatted_variation($_product, $item['variation'], true);
        }
        ?>
', // Category or variation.
			'price': '<?php 
        echo $item['cost'] / $item['qty'];
        ?>
', // Unit price.
			'quantity': '<?php 
        echo $item['qty'];
        ?>
' // Quantity.
		});
		<?php 
    }
    ?>

		jigoshopGA('ecommerce:send');
	</script>
	<?php 
}
Exemplo n.º 7
0
    function column_default($user, $column_name)
    {
        switch ($column_name) {
            case 'customer_name':
                if ($user->last_name && $user->first_name) {
                    return $user->last_name . ', ' . $user->first_name;
                } else {
                    return '-';
                }
            case 'username':
                return $user->user_login;
            case 'location':
                $state_code = get_user_meta($user->ID, 'billing_state', true);
                $country_code = get_user_meta($user->ID, 'billing_country', true);
                $state = jigoshop_countries::has_state($country_code, $state_code) ? jigoshop_countries::get_state($country_code, $state_code) : $state_code;
                $country = jigoshop_countries::has_country($country_code) ? jigoshop_countries::get_country($country_code) : $country_code;
                $value = '';
                if ($state) {
                    $value .= $state . ', ';
                }
                $value .= $country;
                if ($value) {
                    return $value;
                } else {
                    return '-';
                }
            case 'email':
                return '<a href="mailto:' . $user->user_email . '">' . $user->user_email . '</a>';
            case 'spent':
                return jigoshop_price(jigoshop_get_customer_total_spent($user->ID));
            case 'orders':
                return jigoshop_get_customer_order_count($user->ID);
            case 'last_order':
                $order_ids = get_posts(array('posts_per_page' => 1, 'post_type' => 'shop_order', 'post_status' => array('publish'), 'orderby' => 'date', 'order' => 'desc', 'meta_query' => array(array('key' => 'customer_user', 'value' => $user->ID)), 'fields' => 'ids'));
                if ($order_ids) {
                    $order = new jigoshop_order($order_ids[0]);
                    return '<a href="' . admin_url('post.php?post=' . $order->id . '&action=edit') . '">' . $order->get_order_number() . '</a> &ndash; ' . date_i18n(get_option('date_format'), strtotime($order->order_date));
                } else {
                    return '-';
                }
                break;
            case 'user_actions':
                ob_start();
                ?>
<p>
				<?php 
                do_action('jigoshop_admin_user_actions_start', $user);
                $actions = array();
                $actions['refresh'] = array('url' => wp_nonce_url(add_query_arg('refresh', $user->ID), 'refresh'), 'name' => __('Refresh stats', 'jigoshop'), 'action' => 'refresh');
                $actions['edit'] = array('url' => admin_url('user-edit.php?user_id=' . $user->ID), 'name' => __('Edit', 'jigoshop'), 'action' => 'edit');
                $order_ids = $this->get_guest_orders();
                $order_ids = array_map(function ($order) {
                    return $order->ID;
                }, array_filter($order_ids, function ($order) use($user) {
                    return $order->data['billing_email'] == $user->user_email;
                }));
                if ($order_ids) {
                    $actions['link'] = array('url' => wp_nonce_url(add_query_arg('link_orders', $user->ID), 'link_orders'), 'name' => __('Link previous orders', 'jigoshop'), 'action' => 'link');
                }
                $actions = apply_filters('jigoshop_admin_user_actions', $actions, $user);
                foreach ($actions as $action) {
                    printf('<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr($action['action']), esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name']));
                }
                do_action('jigoshop_admin_user_actions_end', $user);
                ?>
				</p><?php 
                $user_actions = ob_get_contents();
                ob_end_clean();
                return $user_actions;
        }
        return '';
    }
Exemplo n.º 8
0
    /**
     *  Generate the futurepay payment iframe
     */
    protected function call_futurepay($order_id)
    {
        // Get the order
        $order = new jigoshop_order($order_id);
        $data = array('gmid' => $this->gmid, 'reference' => $order_id . '-' . uniqid(), 'email' => $order->billing_email, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_line_1' => $order->billing_address_1, 'address_line_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'country' => $order->billing_country, 'zip' => $order->billing_postcode, 'phone' => $order->billing_phone, 'shipping_address_line_1' => $order->shipping_address_1, 'shipping_address_line_2' => $order->shipping_address_2, 'shipping_city' => $order->shipping_city, 'shipping_state' => $order->shipping_state, 'shipping_country' => $order->shipping_country, 'shipping_zip' => $order->shipping_postcode, 'shipping_date' => date('Y/m/d g:i:s'));
        // for Jigoshop 1.7, FuturePay doesn't allow negative prices (or 0.00 ) which affects discounts
        // with FuturePay doing the calcs, so we will bundle all products into ONE line item with
        // a quantity of ONE and send it that way using the final order total after shipping
        // and discounts are applied
        // all product titles will be comma delimited with their quantities
        $item_names = array();
        if (sizeof($order->items) > 0) {
            foreach ($order->items as $item) {
                $_product = $order->get_product_from_item($item);
                $title = $_product->get_title();
                // if variation, insert variation details into product title
                if ($_product instanceof jigoshop_product_variation) {
                    $title .= ' (' . jigoshop_get_formatted_variation($_product, $item['variation'], true) . ')';
                }
                $item_names[] = $item['qty'] . ' x ' . $title;
            }
        }
        // now add the one line item to the necessary product field arrays
        $data['sku'][] = "Products";
        $data['price'][] = $order->order_total;
        // futurepay only needs final order amount
        $data['tax_amount'][] = 0;
        $data['description'][] = sprintf(__('Order %s', 'jigoshop'), $order->get_order_number()) . ' = ' . implode(', ', $item_names);
        $data['quantity'][] = 1;
        try {
            $response = wp_remote_post(self::$request_url . 'merchant-request-order-token', array('body' => http_build_query($data), 'sslverify' => false));
            // Convert error to exception
            if (is_wp_error($response)) {
                if (class_exists('WP_Exception') && $response instanceof WP_Exception) {
                    throw $response;
                } else {
                    jigoshop_log($response->get_error_message());
                    throw new Exception($response->get_error_message());
                }
            }
            // Fetch the body from the result, any errors should be caught before proceeding
            $response = trim(wp_remote_retrieve_body($response));
            // we need something to validate the response.  Valid transactions begin with 'FPTK'
            if (!strstr($response, 'FPTK')) {
                $error_message = isset(self::$futurepay_errorcodes[$response]) ? self::$futurepay_errorcodes[$response] : __('An unknown error has occured with code = ', 'jigoshop') . $response;
                $order->add_order_note(sprintf(__('FUTUREPAY: %s', 'jigoshop'), $error_message));
                jigoshop::add_error(sprintf(__('FUTUREPAY: %s.  Please try again or select another gateway for your Order.', 'jigoshop'), $error_message));
                wp_safe_redirect(get_permalink(jigoshop_get_page_id('checkout')));
                exit;
            }
            /**
             *  If we're good to go, haul in FuturePay's javascript and display the payment form
             *  so that the customer can enter his ID and password
             */
            echo '<div id="futurepay"></div>';
            echo '<script src="' . self::$request_url . 'cart-integration/' . $response . '"></script>';
            echo '<script type="text/javascript">
				/*<![CDATA[*/
				jQuery(window).load( function() {
					FP.CartIntegration();

					// Need to replace form html
					jQuery("#futurepay").html(FP.CartIntegration.getFormContent());
					FP.CartIntegration.displayFuturePay();
				});

				function FuturePayResponseHandler(response) {
					if (response.error) {
						// TODO: we need something better than this
						alert(response.code + " " + response.message);
					}
					else {
						window.location.replace("./?futurepay="+response.transaction_id);
					}

				}
				/*]]>*/
			</script>';
            echo '<input type="button" class="button alt" name="place_order" id="place_order" value="Place Order" onclick="FP.CartIntegration.placeOrder();" />';
        } catch (Exception $e) {
            echo '<div class="jigoshop_error">' . $e->getMessage() . '</div>';
            jigoshop_log('FUTUREPAY ERROR: ' . $e->getMessage());
        }
    }
    /**
     * Recent Orders
     */
    function jigoshop_dash_recent_orders()
    {
        $args = array('numberposts' => 10, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'shop_order', 'post_status' => 'publish');
        $orders = get_posts($args);
        if ($orders) {
            echo '<ul class="recent-orders">';
            foreach ($orders as $order) {
                $this_order = new jigoshop_order($order->ID);
                $user = get_userdata($this_order->user_id);
                if ($user) {
                    $user = array('link' => get_edit_user_link($user->ID), 'name' => $user->display_name);
                } else {
                    $user = array('link' => '', 'name' => __('guest', 'jigoshop'));
                }
                $total_items = 0;
                foreach ($this_order->items as $index => $item) {
                    $total_items += $item['qty'];
                }
                echo '
				<li>
					<span class="order-status ' . sanitize_title($this_order->status) . '">' . ucwords(__($this_order->status, 'jigoshop')) . '</span> <a href="' . admin_url('post.php?post=' . $order->ID) . '&action=edit">' . $this_order->get_order_number() . '</a>
					<span class="order-time">' . get_the_time(__('M d, Y', 'jigoshop'), $order->ID) . '</span> <span class="order-customer"><a href="' . $user['link'] . '">' . $user['name'] . '</a></span>
					<small>' . sizeof($this_order->items) . ' ' . _n('Item', 'Items', sizeof($this_order->items), 'jigoshop') . ', <span class="total-quantity">' . __('Total Quantity', 'jigoshop') . ' ' . $total_items . '</span> <span class="order-cost">' . jigoshop_price($this_order->order_total) . '</span></small>
				</li>';
            }
            echo '</ul>';
        }
    }
Exemplo n.º 10
0
function jigoshop_order_tracking($atts)
{
    extract(shortcode_atts(array(), $atts));
    global $post;
    $jigoshop_options = Jigoshop_Base::get_options();
    if ($_POST) {
        $order = new jigoshop_order();
        $order->id = !empty($_POST['orderid']) ? $_POST['orderid'] : 0;
        if (isset($_POST['order_email']) && $_POST['order_email']) {
            $order_email = trim($_POST['order_email']);
        } else {
            $order_email = '';
        }
        if (!jigoshop::verify_nonce('order_tracking')) {
            echo '<p>' . __('You have taken too long. Please refresh the page and retry.', 'jigoshop') . '</p>';
        } elseif ($order->id && $order_email && $order->get_order(apply_filters('jigoshop_shortcode_order_tracking_order_id', $order->id))) {
            if ($order->billing_email == $order_email) {
                echo '<p>' . sprintf(__('Order %s which was made %s ago and has the status "%s"', 'jigoshop'), $order->get_order_number(), human_time_diff(strtotime($order->order_date), current_time('timestamp')), __($order->status, 'jigoshop'));
                if ($order->status == 'completed') {
                    $completed = (array) get_post_meta($order->id, '_js_completed_date', true);
                    if (!empty($completed)) {
                        $completed = $completed[0];
                    } else {
                        $completed = '';
                    }
                    // shouldn't happen, reset to be sure
                    echo sprintf(__(' was completed %s ago', 'jigoshop'), human_time_diff(strtotime($completed), current_time('timestamp')));
                }
                echo '.</p>';
                do_action('jigoshop_tracking_details_info', $order);
                ?>
				<?php 
                do_action('jigoshop_before_track_order_details', $order->id);
                ?>
				<h2><?php 
                _e('Order Details', 'jigoshop');
                ?>
</h2>
				<table class="shop_table">
					<thead>
						<tr>
							<th><?php 
                _e('ID/SKU', 'jigoshop');
                ?>
</th>
							<th><?php 
                _e('Title', 'jigoshop');
                ?>
</th>
							<th><?php 
                _e('Price', 'jigoshop');
                ?>
</th>
							<th><?php 
                _e('Quantity', 'jigoshop');
                ?>
</th>
						</tr>
					</thead>
					<tfoot>
                        <tr>
                            <?php 
                if ($jigoshop_options->get('jigoshop_calc_taxes') == 'yes' && $order->has_compound_tax() || $jigoshop_options->get('jigoshop_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                    ?>
                                <td colspan="3"><?php 
                    _e('Retail Price', 'jigoshop');
                    ?>
</td>
                            <?php 
                } else {
                    ?>
                                <td colspan="3"><?php 
                    _e('Subtotal', 'jigoshop');
                    ?>
</td>
                            <?php 
                }
                ?>
                                <td><?php 
                echo $order->get_subtotal_to_display();
                ?>
</td>
                        </tr>
                        <?php 
                if ($order->order_shipping > 0) {
                    ?>
                            <tr>
                                <td colspan="3"><?php 
                    _e('Shipping', 'jigoshop');
                    ?>
</td>
                                <td><?php 
                    echo $order->get_shipping_to_display();
                    ?>
</td>
                            </tr>
                            <?php 
                }
                do_action('jigoshop_processing_fee_after_shipping');
                if ($jigoshop_options->get('jigoshop_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                    ?>
                            <tr class="discount">
                                <td colspan="3"><?php 
                    _e('Discount', 'jigoshop');
                    ?>
</td>
                                <td>-<?php 
                    echo jigoshop_price($order->order_discount);
                    ?>
</td>
                            </tr>
                            <?php 
                }
                if ($jigoshop_options->get('jigoshop_calc_taxes') == 'yes' && $order->has_compound_tax() || $jigoshop_options->get('jigoshop_tax_after_coupon') == 'yes' && $order->order_discount > 0) {
                    ?>
                            <tr>
                                <td colspan="3"><?php 
                    _e('Subtotal', 'jigoshop');
                    ?>
</td>
                                <td><?php 
                    echo jigoshop_price($order->order_discount_subtotal);
                    ?>
</td>
                            </tr>
                            <?php 
                }
                if ($jigoshop_options->get('jigoshop_calc_taxes') == 'yes') {
                    foreach ($order->get_tax_classes() as $tax_class) {
                        if ($order->show_tax_entry($tax_class)) {
                            ?>
                                    <tr>
                                        <td colspan="3"><?php 
                            echo $order->get_tax_class_for_display($tax_class) . ' (' . (double) $order->get_tax_rate($tax_class) . '%):';
                            ?>
</td>
                                        <td><?php 
                            echo $order->get_tax_amount($tax_class);
                            ?>
</td>
                                    </tr>
                                    <?php 
                        }
                    }
                }
                ?>
						<?php 
                if ($jigoshop_options->get('jigoshop_tax_after_coupon') == 'no' && $order->order_discount > 0) {
                    ?>
<tr class="discount">
							<td colspan="3"><?php 
                    _e('Discount', 'jigoshop');
                    ?>
</td>
							<td>-<?php 
                    echo jigoshop_price($order->order_discount);
                    ?>
</td>
						</tr><?php 
                }
                ?>
						<tr>
							<td colspan="3"><strong><?php 
                _e('Grand Total', 'jigoshop');
                ?>
</strong></td>
							<td><strong><?php 
                echo jigoshop_price($order->order_total);
                ?>
</strong></td>
						</tr>
					</tfoot>
					<tbody>
						<?php 
                foreach ($order->items as $order_item) {
                    if (isset($order_item['variation_id']) && $order_item['variation_id'] > 0) {
                        $_product = new jigoshop_product_variation($order_item['variation_id']);
                    } else {
                        $_product = new jigoshop_product($order_item['id']);
                    }
                    echo '<tr>';
                    echo '<td>' . $_product->sku . '</td>';
                    echo '<td class="product-name">' . $_product->get_title();
                    if ($_product instanceof jigoshop_product_variation) {
                        echo jigoshop_get_formatted_variation($_product, $order_item['variation']);
                    }
                    do_action('jigoshop_display_item_meta_data', $order_item);
                    echo '</td>';
                    echo '<td>' . jigoshop_price($order_item['cost']) . '</td>';
                    echo '<td>' . $order_item['qty'] . '</td>';
                    echo '</tr>';
                }
                ?>
					</tbody>
				</table>
				<?php 
                do_action('jigoshop_after_track_order_details', $order->id);
                ?>

				<div style="width: 49%; float:left;">
					<h2><?php 
                _e('Billing Address', 'jigoshop');
                ?>
</h2>
					<p><?php 
                $address = $order->billing_first_name . ' ' . $order->billing_last_name . '<br/>';
                if ($order->billing_company) {
                    $address .= $order->billing_company . '<br/>';
                }
                $address .= $order->formatted_billing_address;
                echo $address;
                ?>
</p>
				</div>
				<div style="width: 49%; float:right;">
					<h2><?php 
                _e('Shipping Address', 'jigoshop');
                ?>
</h2>
					<p><?php 
                $address = $order->shipping_first_name . ' ' . $order->shipping_last_name . '<br/>';
                if ($order->shipping_company) {
                    $address .= $order->shipping_company . '<br/>';
                }
                $address .= $order->formatted_shipping_address;
                echo $address;
                ?>
</p>
				</div>
				<div class="clear"></div>
				<?php 
            } else {
                echo '<p>' . __('Sorry, we could not find that order id in our database. <a href="' . get_permalink($post->ID) . '">Want to retry?</a>', 'jigoshop') . '</p>';
            }
        } else {
            echo '<p>' . sprintf(__('Sorry, we could not find that order id in our database. <a href="%s">Want to retry?</a></p>', 'jigoshop'), get_permalink($post->ID));
        }
    } else {
        ?>
		<form action="<?php 
        echo esc_url(get_permalink($post->ID));
        ?>
" method="post" class="track_order">

			<p><?php 
        _e('To track your order please enter your Order ID and email address in the boxes below and press return. This was given to you on your receipt and in the confirmation email you should have received.', 'jigoshop');
        ?>
</p>

			<p class="form-row form-row-first"><label for="orderid"><?php 
        _e('Order ID', 'jigoshop');
        ?>
</label> <input class="input-text" type="text" name="orderid" id="orderid" placeholder="<?php 
        _e('Found in your order confirmation email.', 'jigoshop');
        ?>
" /></p>
			<p class="form-row form-row-last"><label for="order_email"><?php 
        _e('Billing Email', 'jigoshop');
        ?>
</label> <input class="input-text" type="text" name="order_email" id="order_email" placeholder="<?php 
        _e('Email you used during checkout.', 'jigoshop');
        ?>
" /></p>
			<div class="clear"></div>
			<p class="form-row"><input type="submit" class="button" name="track" value="<?php 
        _e('Track"', 'jigoshop');
        ?>
" /></p>
			<?php 
        jigoshop::nonce_field('order_tracking');
        ?>
		</form>
		<?php 
    }
}