function fflcommerce_order_tracking($atts) { extract(shortcode_atts(array(), $atts)); global $post; $fflcommerce_options = FFLCommerce_Base::get_options(); if ($_POST) { $order = new fflcommerce_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 (!fflcommerce::verify_nonce('order_tracking')) { echo '<p>' . __('You have taken too long. Please refresh the page and retry.', 'fflcommerce') . '</p>'; } elseif ($order->id && $order_email && $order->get_order(apply_filters('fflcommerce_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"', 'fflcommerce'), $order->get_order_number(), human_time_diff(strtotime($order->order_date), current_time('timestamp')), __($order->status, 'fflcommerce')); 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', 'fflcommerce'), human_time_diff(strtotime($completed), current_time('timestamp'))); } echo '.</p>'; do_action('fflcommerce_tracking_details_info', $order); ?> <?php do_action('fflcommerce_before_track_order_details', $order->id); ?> <h2><?php _e('Order Details', 'fflcommerce'); ?> </h2> <table class="shop_table"> <thead> <tr> <th><?php _e('ID/SKU', 'fflcommerce'); ?> </th> <th><?php _e('Title', 'fflcommerce'); ?> </th> <th><?php _e('Price', 'fflcommerce'); ?> </th> <th><?php _e('Quantity', 'fflcommerce'); ?> </th> </tr> </thead> <tfoot> <tr> <?php if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) { ?> <td colspan="3"><?php _e('Retail Price', 'fflcommerce'); ?> </td> <?php } else { ?> <td colspan="3"><?php _e('Subtotal', 'fflcommerce'); ?> </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', 'fflcommerce'); ?> </td> <td><?php echo $order->get_shipping_to_display(); ?> </td> </tr> <?php } do_action('fflcommerce_processing_fee_after_shipping'); if ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) { ?> <tr class="discount"> <td colspan="3"><?php _e('Discount', 'fflcommerce'); ?> </td> <td>-<?php echo fflcommerce_price($order->order_discount); ?> </td> </tr> <?php } if ($fflcommerce_options->get('fflcommerce_calc_taxes') == 'yes' && $order->has_compound_tax() || $fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'yes' && $order->order_discount > 0) { ?> <tr> <td colspan="3"><?php _e('Subtotal', 'fflcommerce'); ?> </td> <td><?php echo fflcommerce_price($order->order_discount_subtotal); ?> </td> </tr> <?php } if ($fflcommerce_options->get('fflcommerce_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 ($fflcommerce_options->get('fflcommerce_tax_after_coupon') == 'no' && $order->order_discount > 0) { ?> <tr class="discount"> <td colspan="3"><?php _e('Discount', 'fflcommerce'); ?> </td> <td>-<?php echo fflcommerce_price($order->order_discount); ?> </td> </tr><?php } ?> <tr> <td colspan="3"><strong><?php _e('Grand Total', 'fflcommerce'); ?> </strong></td> <td><strong><?php echo fflcommerce_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 fflcommerce_product_variation($order_item['variation_id']); } else { $_product = new fflcommerce_product($order_item['id']); } echo '<tr>'; echo '<td>' . $_product->sku . '</td>'; echo '<td class="product-name">' . $_product->get_title(); if ($_product instanceof fflcommerce_product_variation) { echo fflcommerce_get_formatted_variation($_product, $order_item['variation']); } do_action('fflcommerce_display_item_meta_data', $order_item); echo '</td>'; echo '<td>' . fflcommerce_price($order_item['cost']) . '</td>'; echo '<td>' . $order_item['qty'] . '</td>'; echo '</tr>'; } ?> </tbody> </table> <?php do_action('fflcommerce_after_track_order_details', $order->id); ?> <div style="width: 49%; float:left;"> <h2><?php _e('Billing Address', 'fflcommerce'); ?> </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', 'fflcommerce'); ?> </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>', 'fflcommerce') . '</p>'; } } else { echo '<p>' . sprintf(__('Sorry, we could not find that order id in our database. <a href="%s">Want to retry?</a></p>', 'fflcommerce'), 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.', 'fflcommerce'); ?> </p> <p class="form-row form-row-first"><label for="orderid"><?php _e('Order ID', 'fflcommerce'); ?> </label> <input class="input-text" type="text" name="orderid" id="orderid" placeholder="<?php _e('Found in your order confirmation email.', 'fflcommerce'); ?> " /></p> <p class="form-row form-row-last"><label for="order_email"><?php _e('Billing Email', 'fflcommerce'); ?> </label> <input class="input-text" type="text" name="order_email" id="order_email" placeholder="<?php _e('Email you used during checkout.', 'fflcommerce'); ?> " /></p> <div class="clear"></div> <p class="form-row"><input type="submit" class="button" name="track" value="<?php _e('Track"', 'fflcommerce'); ?> " /></p> <?php fflcommerce::nonce_field('order_tracking'); ?> </form> <?php } }
/** * Gets a user's downloadable products if they are logged in * * @return array Array of downloadable products */ public static function get_downloadable_products() { global $wpdb; $downloads = array(); if (is_user_logged_in()) { $fflcommerce_orders = new fflcommerce_orders(); $fflcommerce_orders->get_customer_orders(get_current_user_id()); if ($fflcommerce_orders->orders) { $user_info = get_userdata(get_current_user_id()); foreach ($fflcommerce_orders->orders as $order) { if ($order->status == 'completed') { $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}fflcommerce_downloadable_product_permissions WHERE order_key = %s AND user_id = %d;", $order->order_key, get_current_user_id())); if ($results) { foreach ($results as $result) { $_product = new fflcommerce_product_variation($result->product_id); $download_name = $_product->ID ? get_the_title($_product->ID) : get_the_title($result->product_id); if (isset($_product->variation_data)) { $download_name .= ' (' . fflcommerce_get_formatted_variation($_product, array(), true) . ')'; } $downloads[] = array('download_url' => add_query_arg('download_file', $result->product_id, add_query_arg('order', $result->order_key, add_query_arg('email', $user_info->user_email, home_url()))), 'product_id' => $result->product_id, 'download_name' => $download_name, 'order_key' => $result->order_key, 'downloads_remaining' => $result->downloads_remaining); } } } } } } return apply_filters('fflcommerce_downloadable_products', $downloads); }
} ?> <tr> <td><?php echo $product->get_sku(); ?> </td> <td class="product-name"> <?php echo $item['name']; ?> <?php if ($product instanceof fflcommerce_product_variation) { ?> <?php echo fflcommerce_get_formatted_variation($product, $item['variation']); ?> <?php } ?> <?php do_action('fflcommerce_display_item_meta_data', $item); ?> </td> <td><?php echo $item['qty']; ?> </td> <td><?php echo fflcommerce_price($item['cost'], array('ex_tax_label' => 1)); ?>
/** * Generate the paypal button link * * @param int $order_id * @return string */ public function generate_paypal_form($order_id) { $order = new fflcommerce_order($order_id); if ($this->testmode == 'yes') { $url = $this->testurl . '?test_ipn=1&'; } else { $url = $this->liveurl . '?'; } if (in_array($order->billing_country, array('US', 'CA'))) { $order->billing_phone = str_replace(array('(', '-', ' ', ')'), '', $order->billing_phone); $phone_args = array('night_phone_a' => substr($order->billing_phone, 0, 3), 'night_phone_b' => substr($order->billing_phone, 3, 3), 'night_phone_c' => substr($order->billing_phone, 6, 4), 'day_phone_a' => substr($order->billing_phone, 0, 3), 'day_phone_b' => substr($order->billing_phone, 3, 3), 'day_phone_c' => substr($order->billing_phone, 6, 4)); } else { $phone_args = array('night_phone_b' => $order->billing_phone, 'day_phone_b' => $order->billing_phone); } // filter redirect page $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks')); $paypal_args = array_merge(array('cmd' => '_cart', 'business' => $this->testmode == 'yes' ? $this->testemail : $this->email, 'no_note' => 1, 'currency_code' => FFLCommerce_Base::get_options()->get('fflcommerce_currency'), 'charset' => 'UTF-8', 'rm' => 2, 'upload' => 1, 'return' => add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink($checkout_redirect))), 'cancel_return' => $order->get_cancel_order_url(), 'custom' => $order_id, 'notify_url' => $this->notify_url, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address1' => $order->billing_address_1, 'address2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zip' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'invoice' => $order->get_order_number(), 'amount' => number_format((double) $order->order_total, $this->decimals), 'bn' => 'FFLCommerce_SP'), $phone_args); if ($this->send_shipping == 'yes') { $paypal_args['no_shipping'] = 1; $paypal_args['address_override'] = 1; $paypal_args['first_name'] = $order->shipping_first_name; $paypal_args['last_name'] = $order->shipping_last_name; $paypal_args['address1'] = $order->shipping_address_1; $paypal_args['address2'] = $order->shipping_address_2; $paypal_args['city'] = $order->shipping_city; $paypal_args['state'] = $order->shipping_state; $paypal_args['zip'] = $order->shipping_postcode; $paypal_args['country'] = $order->shipping_country; // PayPal counts Puerto Rico as a US Territory, won't allow payment without it if ($paypal_args['country'] == 'PR') { $paypal_args['country'] = 'US'; $paypal_args['state'] = 'PR'; } } else { $paypal_args['no_shipping'] = 1; $paypal_args['address_override'] = 0; } // If prices include tax, send the whole order as a single item if (FFLCommerce_Base::get_options()->get('fflcommerce_prices_include_tax') == 'yes') { // Discount $paypal_args['discount_amount_cart'] = number_format((double) $order->order_discount, $this->decimals); // Don't pass items - PayPal breaks tax due to catalog prices include tax. // PayPal has no option for tax inclusive pricing. // Pass 1 item for the order items overall $item_names = array(); 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 fflcommerce_product_variation) { $title .= ' (' . fflcommerce_get_formatted_variation($_product, $item['variation'], true) . ')'; } $item_names[] = $title . ' x ' . $item['qty']; } $paypal_args['item_name_1'] = sprintf(__('Order %s', 'fflcommerce'), $order->get_order_number()) . ' - ' . implode(', ', $item_names); $paypal_args['quantity_1'] = 1; $paypal_args['amount_1'] = number_format($order->order_total - $order->order_shipping - $order->order_shipping_tax + $order->order_discount, $this->decimals, '.', ''); if ($order->order_shipping + $order->order_shipping_tax > 0) { $paypal_args['item_name_2'] = __('Shipping cost', 'fflcommerce'); $paypal_args['quantity_2'] = '1'; $paypal_args['amount_2'] = number_format($order->order_shipping + $order->order_shipping_tax, $this->decimals, '.', ''); } } else { // Cart Contents $item_loop = 0; foreach ($order->items as $item) { $_product = $order->get_product_from_item($item); if ($_product->exists() && $item['qty']) { $item_loop++; $title = $_product->get_title(); //if variation, insert variation details into product title if ($_product instanceof fflcommerce_product_variation) { $title .= ' (' . fflcommerce_get_formatted_variation($_product, $item['variation'], true) . ')'; } $paypal_args['item_name_' . $item_loop] = $title; $paypal_args['quantity_' . $item_loop] = $item['qty']; $paypal_args['amount_' . $item_loop] = number_format(apply_filters('fflcommerce_paypal_adjust_item_price', $item['cost'], $item, 10, 2), $this->decimals); //Apparently, Paypal did not like "28.4525" as the amount. Changing that to "28.45" fixed the issue. } } // Shipping Cost if (fflcommerce_shipping::is_enabled() && $order->order_shipping > 0) { $item_loop++; $paypal_args['item_name_' . $item_loop] = __('Shipping cost', 'fflcommerce'); $paypal_args['quantity_' . $item_loop] = '1'; $paypal_args['amount_' . $item_loop] = number_format((double) $order->order_shipping, $this->decimals); } $paypal_args['tax'] = $order->get_total_tax(false, false); // no currency sign or pricing options for separators $paypal_args['tax_cart'] = $order->get_total_tax(false, false); // no currency sign or pricing options for separators $paypal_args['discount_amount_cart'] = $order->order_discount; if ($this->force_payment == 'yes') { $sum = 0; for ($i = 1; $i < $item_loop; $i++) { $sum += $paypal_args['amount_' . $i]; } $item_loop++; if ($sum == 0 || $order->order_discount && $sum - $order->order_discount == 0) { $paypal_args['item_name_' . $item_loop] = __('Force payment on free', 'fflcommerce'); $paypal_args['quantity_' . $item_loop] = '1'; $paypal_args['amount_' . $item_loop] = 0.01; // force payment } } } $paypal_args = apply_filters('fflcommerce_paypal_args', $paypal_args); return fflcommerce_render_result('gateways/paypal', array('url' => $url, 'fields' => $paypal_args)); }
/** * Order items meta box * * Displays the order items meta box - for showing individual items in the order * * @since 1.0 */ function fflcommerce_order_items_meta_box($post) { $order_items = (array) maybe_unserialize(get_post_meta($post->ID, 'order_items', true)); ?> <div class="fflcommerce_order_items_wrapper"> <table cellpadding="0" cellspacing="0" class="fflcommerce_order_items"> <thead> <tr> <?php do_action('fflcommerce_admin_order_item_header_before_prod_id'); ?> <th class="product-id"><?php _e('ID', 'fflcommerce'); ?> </th> <th class="variation-id"><?php _e('Variation ID', 'fflcommerce'); ?> </th> <th class="product-sku"><?php _e('SKU', 'fflcommerce'); ?> </th> <th class="name"><?php _e('Name', 'fflcommerce'); ?> </th> <th class="variation"><?php _e('Variation', 'fflcommerce'); ?> </th> <!--<th class="meta"><?php _e('Order Item Meta', 'fflcommerce'); ?> </th>--> <?php do_action('fflcommerce_admin_order_item_headers'); ?> <th class="quantity"><?php _e('Quantity', 'fflcommerce'); ?> </th> <th class="cost"><?php _e('Cost', 'fflcommerce'); ?> </th> <th class="tax"><?php _e('Tax Rate', 'fflcommerce'); ?> </th> <th class="center" width="1%"><?php _e('Remove', 'fflcommerce'); ?> </th> </tr> </thead> <tbody id="order_items_list"> <?php if (sizeof($order_items) > 0 && isset($order_items[0]['id'])) { foreach ($order_items as $item_no => $item) { if (isset($item['variation_id']) && $item['variation_id'] > 0) { $_product = new fflcommerce_product_variation($item['variation_id']); if (is_array($item['variation'])) { $_product->set_variation_attributes($item['variation']); } } else { $_product = new fflcommerce_product($item['id']); } ?> <tr class="item"> <?php do_action('fflcommerce_admin_order_item_before_prod_id', $item_no); ?> <td class="product-id"><?php echo $item['id']; ?> </td> <td class="variation-id"><?php if (isset($item['variation_id'])) { echo $item['variation_id']; } else { echo '-'; } ?> </td> <td class="product-sku"><?php if ($_product->sku) { echo $_product->sku; } ?> </td> <td class="name"><a href="<?php echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit')); ?> "><?php echo $item['name']; ?> </a> <?php if (!empty($item['customization'])) { $custom = $item['customization']; $label = apply_filters('fflcommerce_customized_product_label', __(' Personal: ', 'fflcommerce')); ?> <div class="customization"> <span class="customized_product_label"><?php echo $label; ?> </span> <span class="customized_product"><?php echo $custom; ?> </span> </div> <?php } ?> </td> <td class="variation"><?php if (isset($_product->variation_data)) { echo fflcommerce_get_formatted_variation($_product, $item['variation'], true); } else { echo '-'; } ?> </td> <?php do_action('fflcommerce_admin_order_item_values', $_product, $item, $post->ID); ?> <td class="quantity"> <input type="text" name="item_quantity[]" placeholder="<?php _e('Quantity e.g. 2', 'fflcommerce'); ?> " value="<?php echo esc_attr($item['qty']); ?> " /> </td> <td class="cost"> <input type="text" name="item_cost[]" placeholder="<?php _e('Cost per unit ex. tax e.g. 2.99', 'fflcommerce'); ?> " value="<?php echo esc_attr($item['cost']); ?> " /> </td> <td class="tax"> <input type="text" name="item_tax_rate[]" placeholder="<?php _e('Tax Rate e.g. 20.0000', 'fflcommerce'); ?> " value="<?php echo esc_attr($item['taxrate']); ?> " /> </td> <td class="center"> <input type="hidden" name="item_id[]" value="<?php echo esc_attr($item['id']); ?> " /> <input type="hidden" name="item_name[]" value="<?php echo esc_attr($item['name']); ?> " /> <input type="hidden" name="item_variation_id[]" value="<?php if ($item['variation_id']) { echo $item['variation_id']; } else { echo ''; } ?> " /> <button type="button" class="remove_row button">×</button> </td> </tr> <?php } } ?> </tbody> </table> </div> <p class="buttons"> <input type='text' class='item_id' name='order_product_select' id='order_product_select' value='' placeholder="<?php _e('Choose a Product', 'fflcommerce'); ?> " /> <script type="text/javascript"> /*<![CDATA[*/ jQuery(function() { jQuery("#order_product_select").select2({ minimumInputLength: 3, multiple: false, closeOnSelect: true, ajax: { url: "<?php echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php'); ?> ", dataType: 'json', quietMillis: 100, data: function(term, page) { return { term: term, action: 'fflcommerce_json_search_products_and_variations', security: '<?php echo wp_create_nonce("search-products"); ?> ' }; }, results: function( data, page ) { return { results: data }; } }, initSelection: function( element, callback ) { var stuff = { action: 'fflcommerce_json_search_products_and_variations', security: '<?php echo wp_create_nonce("search-products"); ?> ', term: element.val() }; jQuery.ajax({ type: 'GET', url: "<?php echo !is_ssl() ? str_replace('https', 'http', admin_url('admin-ajax.php')) : admin_url('admin-ajax.php'); ?> ", dataType: "json", data: stuff, success: function( result ) { callback( result ); } }); } }); }); /*]]>*/ </script> <button type="button" class="button button-primary add_shop_order_item"><?php _e('Add item', 'fflcommerce'); ?> </button> </p> <p class="buttons buttons-alt"> <button type="button" class="button button calc_totals"><?php _e('Calculate totals', 'fflcommerce'); ?> </button> </p> <div class="clear"></div> <?php }
function fflcommerce_ga_ecommerce_tracking($order_id) { $options = FFLCommerce_Base::get_options(); // Skip if disabled if ($options->get('fflcommerce_ga_ecommerce_tracking_enabled') != 'yes') { return; } // Don't track the shop owners roaming if (current_user_can('manage_fflcommerce')) { return; } $tracking_id = $options->get('fflcommerce_ga_id'); if (!$tracking_id) { return; } // Get the order and output tracking code $order = new fflcommerce_order($order_id); ?> <script type="text/javascript"> fflcommerceGA('require', 'ecommerce'); fflcommerceGA('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); ?> fflcommerceGA('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 fflcommerce_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 } ?> fflcommerceGA('ecommerce:send'); </script> <?php }
/** * Generates WorldPay form and redirects to WordPay with Order information */ public function display_worldpay_redirect_form($order_id) { $order = new fflcommerce_order($order_id); if ($this->testmode == 'yes') { $worldpay_url = "https://secure-test.worldpay.com/wcc/purchase"; $testmode = (int) 100; } else { $worldpay_url = "https://secure.worldpay.com/wcc/purchase"; $testmode = (int) 0; } $order_total = number_format($order->order_total, 2, '.', ''); $worldpay_args = array('instId' => $this->installation_id, 'cartId' => $order_id, 'amount' => $order_total, 'currency' => $this->currency, 'testMode' => $testmode, 'email' => $order->billing_email, 'MC_invoice' => $order->order_key); // Send 'canned' name if testmode or full name if not testmode. if ($this->testmode == 'yes') { $worldpay_args['name'] = 'AUTHORISED'; } else { $worldpay_args['name'] = $order->billing_first_name . ' ' . $order->billing_last_name; } // Address info $worldpay_args['address1'] = $order->billing_address_1; $worldpay_args['address2'] = $order->billing_address_2; $worldpay_args['town'] = $order->billing_city; $worldpay_args['region'] = $order->billing_state; $worldpay_args['postcode'] = $order->billing_postcode; $worldpay_args['country'] = $order->billing_country; $worldpay_args['fixContact'] = ''; /* no address editing */ // Setup the Dymanic URL properties using FFL Commerce Request API $worldpay_args['MC_callback'] = $this->notify_url; $worldpay_args['MC_cancel_return'] = $order->get_cancel_order_url(); // Cart Contents - Generate cart description $desc = ''; if (sizeof($order->items) > 0) { foreach ($order->items as $item) { $_product = $order->get_product_from_item($item); if ($_product->exists() && $item['qty']) { $title = $_product->get_title(); // if variation, insert variation details into product title if ($_product instanceof fflcommerce_product_variation) { $title .= ' (' . fflcommerce_get_formatted_variation($_product, $item['variation'], true) . ')'; } $desc .= $item['qty'] . ' x ' . $title . '<br/>'; } } // Add the description $worldpay_args['desc'] = $desc; } if ($this->fixed_currency == 'yes') { $worldpay_args['hideCurrency'] = ''; } // MD5 hash the main parameters we are sending to WorldPay if ($this->md5_encrypt == 'yes' && !empty($this->secret_word)) { // Add the fields you are hashing $hash_fields = 'instId:cartId:amount:currency'; $worldpay_args['signatureFields'] = $hash_fields; // Add the hash signature $hash_message = $this->secret_word . ':' . $this->installation_id . ':' . $order_id . ':' . $order_total . ':' . $this->currency; $worldpay_args['signature'] = md5($hash_message); } $worldpay_form_array = array(); foreach ($worldpay_args as $key => $value) { if ($key == 'hideCurrency') { $worldpay_form_array[] = '<input type="hidden" name="' . $key . '" />'; continue; } if ($key == 'fixContact') { $worldpay_form_array[] = '<input type="hidden" name="' . $key . '" />'; continue; } $worldpay_form_array[] = '<input type="hidden" name="' . $key . '" value="' . $value . '" />'; } return fflcommerce_render_result('gateways/worldpay', array('url' => $worldpay_url, 'fields' => $worldpay_args)); }
/** Output items for display in emails */ public function email_order_items_list($show_download_links = false, $show_sku = false, $price_inc_tax = false) { $return = ''; // validate if any item has cost less than 0. If that's the case, we can't use price including tax $use_inc_tax = $price_inc_tax; if ($price_inc_tax) { foreach ($this->items as $item) { $use_inc_tax = $item['cost_inc_tax'] >= 0; if (!$use_inc_tax) { break; } } } foreach ($this->items as $item) { $_product = $this->get_product_from_item($item); $return .= $item['qty'] . ' x ' . html_entity_decode(apply_filters('fflcommerce_order_product_title', $item['name'], $_product, $item), ENT_QUOTES, 'UTF-8'); if ($show_sku && self::get_options()->get('fflcommerce_enable_sku') == 'yes') { $return .= ' (#' . $_product->sku . ')'; } if ($use_inc_tax && $item['cost_inc_tax'] >= 0) { $return .= ' - ' . html_entity_decode(strip_tags(fflcommerce_price($item['cost_inc_tax'] * $item['qty'], array('ex_tax_label' => 0))), ENT_COMPAT, 'UTF-8'); } else { $return .= ' - ' . html_entity_decode(strip_tags(fflcommerce_price($item['cost'], array('ex_tax_label' => 1))), ENT_COMPAT, 'UTF-8'); } if ($_product instanceof fflcommerce_product_variation) { $return .= PHP_EOL . fflcommerce_get_formatted_variation($_product, $item['variation'], true); } // Very hacky, used for GFORMS ADDONS -Rob if (!isset($_product->variation_data) && isset($item['variation'])) { if (!empty($item['variation'])) { foreach ($item['variation'] as $variation) { $return .= PHP_EOL . $variation['name'] . ': ' . $variation['value']; } } } // Check that this filter supplied by OptArt is in use before applying it. // This filter in FFL Commerce 1.3 is only used by FFL Commerce Product Addons and should be revised because // if that plugin is not active, emails will have a line item with 'Array' on each product description. // TODO: FFLCommerce never intends to use $item like this, a filter is incorrect. -JAP- global $wp_filter; if (isset($wp_filter['fflcommerce_display_item_meta_data_email'])) { $meta_data = apply_filters('fflcommerce_display_item_meta_data_email', $item); if ($meta_data != '') { $return .= PHP_EOL . $meta_data; } } if (!empty($item['customization'])) { $return .= PHP_EOL . apply_filters('fflcommerce_customized_product_label', __(' Personal: ', 'fflcommerce')) . PHP_EOL . $item['customization']; } if ($show_download_links) { if ($_product->exists()) { if ($_product->is_type('downloadable')) { if ((bool) $item['variation_id']) { $product_id = $_product->variation_id; } else { $product_id = $_product->ID; } if ($this->get_downloadable_file_url($product_id)) { $return .= PHP_EOL . __('Your download link for this file is:', 'fflcommerce'); $return .= PHP_EOL . ' - ' . apply_filters('downloadable_file_url', $this->get_downloadable_file_url($product_id), $_product, $this) . ''; } } } } $return .= PHP_EOL; } return $return; }
/** * Generate the futurepay payment iframe */ protected function call_futurepay($order_id) { // Get the order $order = new fflcommerce_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 FFL Commerce 1.0, 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 fflcommerce_product_variation) { $title .= ' (' . fflcommerce_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', 'fflcommerce'), $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 { fflcommerce_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 = ', 'fflcommerce') . $response; $order->add_order_note(sprintf(__('FUTUREPAY: %s', 'fflcommerce'), $error_message)); fflcommerce::add_error(sprintf(__('FUTUREPAY: %s. Please try again or select another gateway for your Order.', 'fflcommerce'), $error_message)); wp_safe_redirect(get_permalink(fflcommerce_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="fflcommerce_error">' . $e->getMessage() . '</div>'; fflcommerce_log('FUTUREPAY ERROR: ' . $e->getMessage()); } }