private function replace_placeholders($str)
 {
     $placeholders = apply_filters('bewpi_placeholders', array('[payment_method]' => $this->order->payment_method_title, '[shipping_method]' => $this->order->get_shipping_method()), $this->order->id);
     foreach ($placeholders as $placeholder => $value) {
         $str = str_replace($placeholder, $value, $str);
     }
     return $str;
 }
/**
 * Bundle and format the order information
 * @param WC_Order $order
 * Send as much information about the order as possible to Conekta
 */
function getRequestData($order)
{
    if ($order and $order != null) {
        // custom fields
        $custom_fields = array("total_discount" => (double) $order->get_total_discount() * 100);
        // $user_id = $order->get_user_id();
        // $is_paying_customer = false;
        $order_coupons = $order->get_used_coupons();
        // if ($user_id != 0) {
        //     $custom_fields = array_merge($custom_fields, array(
        //         "is_paying_customer" => is_paying_customer($user_id)
        //     ));
        // }
        if (count($order_coupons) > 0) {
            $custom_fields = array_merge($custom_fields, array("coupon_code" => $order_coupons[0]));
        }
        return array("amount" => (double) $order->get_total() * 100, "token" => $_POST['conektaToken'], "shipping_method" => $order->get_shipping_method(), "shipping_carrier" => $order->get_shipping_method(), "shipping_cost" => (double) $order->get_total_shipping() * 100, "monthly_installments" => (int) $_POST['monthly_installments'], "currency" => strtolower(get_woocommerce_currency()), "description" => sprintf("Charge for %s", $order->billing_email), "card" => array_merge(array("name" => sprintf("%s %s", $order->billing_first_name, $order->billing_last_name), "address_line1" => $order->billing_address_1, "address_line2" => $order->billing_address_2, "billing_company" => $order->billing_company, "phone" => $order->billing_phone, "email" => $order->billing_email, "address_city" => $order->billing_city, "address_zip" => $order->billing_postcode, "address_state" => $order->billing_state, "address_country" => $order->billing_country, "shipping_address_line1" => $order->shipping_address_1, "shipping_address_line2" => $order->shipping_address_2, "shipping_phone" => $order->shipping_phone, "shipping_email" => $order->shipping_email, "shipping_address_city" => $order->shipping_city, "shipping_address_zip" => $order->shipping_postcode, "shipping_address_state" => $order->shipping_state, "shipping_address_country" => $order->shipping_country), $custom_fields));
    }
    return false;
}
                    $totalAmount += $item_price * (int) $item['qty'];
                }
                // End if qty
            }
            // End foreach
        }
        // End if sizeof get_items()
        // We manually calculate the tax percentage here
        if ($order->get_total_shipping() > 0) {
            // Calculate tax percentage
            $shipping_tax_percentage = round($order->get_shipping_tax() / $order->get_total_shipping(), 2) * 100;
        } else {
            $shipping_tax_percentage = 00;
        }
        $shipping_price = number_format(($order->get_total_shipping() + $order->get_shipping_tax()) * 100, 0, '', '');
        $cart[] = array('ArticleNumber' => '999', 'ArticleName' => $order->get_shipping_method(), 'Description' => $order->get_shipping_method(), 'Quantity' => 100, 'Price' => intval($shipping_price), 'VAT' => intval($shipping_tax_percentage . '00'));
        $totalAmount += $shipping_price;
        //Create postData
        $create['MerchantKey'] = $merchantid;
        $create['Checksum'] = SHA1($totalAmount * 100 . $sharedSecret);
        $create['Token'] = strtoupper($storedGet['token']);
        foreach ($cart as $item) {
            $create['Articles'][] = $item;
        }
        // Setup cURL
        $ch = curl_init($updateCheckoutAPI);
        curl_setopt_array($ch, array(CURLOPT_POST => TRUE, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HTTPHEADER => array('Content-Type: application/json'), CURLOPT_POSTFIELDS => json_encode($create)));
        // Send the request
        $response = curl_exec($ch);
    }
}
 /**
  * Get the order data for the given ID.
  *
  * @since  2.5.0
  * @param  WC_Order $order The order instance
  * @return array
  */
 protected function get_order_data($order)
 {
     $order_post = get_post($order->id);
     $dp = wc_get_price_decimals();
     $order_data = array('id' => $order->id, 'order_number' => $order->get_order_number(), 'created_at' => $this->format_datetime($order_post->post_date_gmt), 'updated_at' => $this->format_datetime($order_post->post_modified_gmt), 'completed_at' => $this->format_datetime($order->completed_date, true), 'status' => $order->get_status(), 'currency' => $order->get_order_currency(), 'total' => wc_format_decimal($order->get_total(), $dp), 'subtotal' => wc_format_decimal($order->get_subtotal(), $dp), 'total_line_items_quantity' => $order->get_item_count(), 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp), 'total_shipping' => wc_format_decimal($order->get_total_shipping(), $dp), 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp), 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp), 'total_discount' => wc_format_decimal($order->get_total_discount(), $dp), 'shipping_methods' => $order->get_shipping_method(), 'payment_details' => array('method_id' => $order->payment_method, 'method_title' => $order->payment_method_title, 'paid' => isset($order->paid_date)), 'billing_address' => array('first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_1' => $order->billing_address_1, 'address_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postcode' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'phone' => $order->billing_phone), 'shipping_address' => array('first_name' => $order->shipping_first_name, 'last_name' => $order->shipping_last_name, 'company' => $order->shipping_company, 'address_1' => $order->shipping_address_1, 'address_2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postcode' => $order->shipping_postcode, 'country' => $order->shipping_country), 'note' => $order->customer_note, 'customer_ip' => $order->customer_ip_address, 'customer_user_agent' => $order->customer_user_agent, 'customer_id' => $order->get_user_id(), 'view_order_url' => $order->get_view_order_url(), 'line_items' => array(), 'shipping_lines' => array(), 'tax_lines' => array(), 'fee_lines' => array(), 'coupon_lines' => array());
     // add line items
     foreach ($order->get_items() as $item_id => $item) {
         $product = $order->get_product_from_item($item);
         $product_id = null;
         $product_sku = null;
         // Check if the product exists.
         if (is_object($product)) {
             $product_id = isset($product->variation_id) ? $product->variation_id : $product->id;
             $product_sku = $product->get_sku();
         }
         $meta = new WC_Order_Item_Meta($item, $product);
         $item_meta = array();
         foreach ($meta->get_formatted(null) as $meta_key => $formatted_meta) {
             $item_meta[] = array('key' => $meta_key, 'label' => $formatted_meta['label'], 'value' => $formatted_meta['value']);
         }
         $order_data['line_items'][] = array('id' => $item_id, 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp), 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp), 'total_tax' => wc_format_decimal($item['line_tax'], $dp), 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'quantity' => wc_stock_amount($item['qty']), 'tax_class' => !empty($item['tax_class']) ? $item['tax_class'] : null, 'name' => $item['name'], 'product_id' => $product_id, 'sku' => $product_sku, 'meta' => $item_meta);
     }
     // Add shipping.
     foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
         $order_data['shipping_lines'][] = array('id' => $shipping_item_id, 'method_id' => $shipping_item['method_id'], 'method_title' => $shipping_item['name'], 'total' => wc_format_decimal($shipping_item['cost'], $dp));
     }
     // Add taxes.
     foreach ($order->get_tax_totals() as $tax_code => $tax) {
         $order_data['tax_lines'][] = array('id' => $tax->id, 'rate_id' => $tax->rate_id, 'code' => $tax_code, 'title' => $tax->label, 'total' => wc_format_decimal($tax->amount, $dp), 'compound' => (bool) $tax->is_compound);
     }
     // Add fees.
     foreach ($order->get_fees() as $fee_item_id => $fee_item) {
         $order_data['fee_lines'][] = array('id' => $fee_item_id, 'title' => $fee_item['name'], 'tax_class' => !empty($fee_item['tax_class']) ? $fee_item['tax_class'] : null, 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp));
     }
     // Add coupons.
     foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
         $order_data['coupon_lines'][] = array('id' => $coupon_item_id, 'code' => $coupon_item['name'], 'amount' => wc_format_decimal($coupon_item['discount_amount'], $dp));
     }
     $order_data = apply_filters('woocommerce_cli_order_data', $order_data);
     return $this->flatten_array($order_data);
 }
示例#5
0
 /**
  * Test: get_shipping_method
  */
 function test_get_shipping_method()
 {
     $object = new WC_Order();
     $rate = new WC_Shipping_Rate('flat_rate_shipping', 'Flat rate shipping', '10', array(), 'flat_rate');
     $item = new WC_Order_Item_Shipping();
     $item->set_props(array('method_title' => $rate->label, 'method_id' => $rate->id, 'total' => wc_format_decimal($rate->cost), 'taxes' => $rate->taxes, 'meta_data' => $rate->get_meta_data()));
     $object->add_item($item);
     $object->save();
     $this->assertEquals('Flat rate shipping', $object->get_shipping_method());
     $rate = new WC_Shipping_Rate('flat_rate_shipping', 'Flat rate shipping 2', '10', array(), 'flat_rate');
     $item = new WC_Order_Item_Shipping();
     $item->set_props(array('method_title' => $rate->label, 'method_id' => $rate->id, 'total' => wc_format_decimal($rate->cost), 'taxes' => $rate->taxes, 'meta_data' => $rate->get_meta_data()));
     $object->add_item($item);
     $object->save();
     $this->assertEquals('Flat rate shipping, Flat rate shipping 2', $object->get_shipping_method());
 }
 /**
  * Get shipping data.
  *
  * @param  WC_Order $order
  *
  * @return array
  */
 protected function get_shipping_data($order)
 {
     $data = array('shipping_address_name' => $order->shipping_address_1, 'shipping_address_number' => $order->shipping_number, 'shipping_address_complement' => $order->shipping_address_2, 'shipping_address_district' => $order->shipping_neighborhood, 'shipping_address_city' => $order->shipping_city, 'shipping_address_state' => $order->shipping_state, 'shipping_zipcode' => $this->only_numbers($order->shipping_postcode));
     if (0 < $order->get_total_shipping()) {
         $data['shipping_type'] = '2';
         // Flat rate.
         $data['shipping_1_name'] = $order->get_shipping_method();
         $data['shipping_1_price'] = $this->get_price($order->get_total_shipping());
     } else {
         $data['shipping_type'] = '3';
     }
     return $data;
 }
 /**
  * Get line items to send to paypal
  *
  * @param  WC_Order $order
  * @return array on success, or false when it is not possible to send line items
  */
 private function get_line_items($order)
 {
     // Do not send lines for tax inclusive prices
     if ('yes' === get_option('woocommerce_calc_taxes') && 'yes' === get_option('woocommerce_prices_include_tax')) {
         return false;
     }
     // Do not send lines when order discount is present, or too many line items in the order.
     if ($order->get_order_discount() > 0 || sizeof($order->get_items()) + sizeof($order->get_fees()) >= 9) {
         return false;
     }
     $item_loop = 0;
     $args = array();
     $args['tax_cart'] = $order->get_total_tax();
     // Products
     if (sizeof($order->get_items()) > 0) {
         foreach ($order->get_items() as $item) {
             if (!$item['qty']) {
                 continue;
             }
             $item_loop++;
             $product = $order->get_product_from_item($item);
             $item_name = $item['name'];
             $item_meta = new WC_Order_Item_Meta($item['item_meta']);
             if ($meta = $item_meta->display(true, true)) {
                 $item_name .= ' ( ' . $meta . ' )';
             }
             $args['item_name_' . $item_loop] = $this->paypal_item_name($item_name);
             $args['quantity_' . $item_loop] = $item['qty'];
             $args['amount_' . $item_loop] = $order->get_item_subtotal($item, false);
             if ($args['amount_' . $item_loop] < 0) {
                 return false;
                 // Abort - negative line
             }
             if ($product->get_sku()) {
                 $args['item_number_' . $item_loop] = $product->get_sku();
             }
         }
     }
     // Discount
     if ($order->get_cart_discount() > 0) {
         $args['discount_amount_cart'] = round($order->get_cart_discount(), 2);
     }
     // Fees
     if (sizeof($order->get_fees()) > 0) {
         foreach ($order->get_fees() as $item) {
             $item_loop++;
             $args['item_name_' . $item_loop] = $this->paypal_item_name($item['name']);
             $args['quantity_' . $item_loop] = 1;
             $args['amount_' . $item_loop] = $item['line_total'];
             if ($args['amount_' . $item_loop] < 0) {
                 return false;
                 // Abort - negative line
             }
         }
     }
     // Shipping Cost item - paypal only allows shipping per item, we want to send shipping for the order
     if ($order->get_total_shipping() > 0) {
         $item_loop++;
         $args['item_name_' . $item_loop] = $this->paypal_item_name(sprintf(__('Shipping via %s', 'woocommerce'), $order->get_shipping_method()));
         $args['quantity_' . $item_loop] = '1';
         $args['amount_' . $item_loop] = number_format($order->get_total_shipping(), 2, '.', '');
     }
     return $args;
 }
function orderpost($orderId)
{
    global $wpdb;
    $testMode = get_option('linksync_test');
    $LAIDKey = get_option('linksync_laid');
    $apicall = new linksync_class($LAIDKey, $testMode);
    //Checking for already sent Order
    $sentOrderIds = get_option('linksync_sent_order_id');
    if (isset($sentOrderIds)) {
        if (!empty($sentOrderIds)) {
            $order_id_array = unserialize($sentOrderIds);
        } else {
            $order_id_array = array();
        }
        if (!in_array($orderId, $order_id_array)) {
            $order = new WC_Order($orderId);
            if ($order->post_status == get_option('order_status_wc_to_vend')) {
                update_option('linksync_sent_order_id', serialize(array_merge($order_id_array, array($orderId))));
                $order_no = $order->get_order_number();
                if (strpos($order_no, '#') !== false) {
                    $order_no = str_replace('#', '', $order_no);
                }
                $get_total = $order->get_total();
                $get_user = $order->get_user();
                $comments = $order->post->post_excerpt;
                $primary_email_address = $get_user->data->user_email;
                $currency = $order->get_order_currency();
                $shipping_method = $order->get_shipping_method();
                $order_total = $order->get_order_item_totals();
                $transaction_id = $order->get_transaction_id();
                $taxes_included = false;
                $total_discount = $order->get_total_discount();
                $total_quantity = 0;
                $registerDb = get_option('wc_to_vend_register');
                $vend_uid = get_option('wc_to_vend_user');
                $total_tax = $order->get_total_tax();
                // Geting Payment object details
                if (isset($order_total['payment_method']['value']) && !empty($order_total['payment_method']['value'])) {
                    $wc_payment = get_option('wc_to_vend_payment');
                    if (isset($wc_payment) && !empty($wc_payment)) {
                        $total_payments = explode(",", $wc_payment);
                        foreach ($total_payments as $mapped_payment) {
                            $exploded_mapped_payment = explode("|", $mapped_payment);
                            if (isset($exploded_mapped_payment[1]) && !empty($exploded_mapped_payment[1]) && isset($exploded_mapped_payment[0]) && !empty($exploded_mapped_payment[0])) {
                                if ($exploded_mapped_payment[1] == $order_total['payment_method']['value']) {
                                    $vend_payment_data = explode("%%", $exploded_mapped_payment[0]);
                                    if (isset($vend_payment_data[0])) {
                                        $payment_method = $vend_payment_data[0];
                                    }
                                    if (isset($vend_payment_data[1])) {
                                        $payment_method_id = $vend_payment_data[1];
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    $payment = array("retailer_payment_type_id" => isset($payment_method_id) ? $payment_method_id : null, "amount" => isset($get_total) ? $get_total : 0, "method" => isset($payment_method) ? $payment_method : null, "transactionNumber" => isset($transaction_id) ? $transaction_id : null);
                }
                $export_user_details = get_option('wc_to_vend_export');
                if (isset($export_user_details) && !empty($export_user_details)) {
                    if ($export_user_details == 'customer') {
                        //woocommerce filter
                        $billingAddress_filter = apply_filters('woocommerce_order_formatted_billing_address', array('firstName' => $order->billing_first_name, 'lastName' => $order->billing_last_name, 'phone' => $order->billing_phone, 'street1' => $order->billing_address_1, 'street2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postalCode' => $order->billing_postcode, 'country' => $order->billing_country, 'company' => $order->billing_company, 'email_address' => $order->billing_email), $order);
                        $billingAddress = array('firstName' => $billingAddress_filter['firstName'], 'lastName' => $billingAddress_filter['lastName'], 'phone' => $billingAddress_filter['phone'], 'street1' => $billingAddress_filter['street1'], 'street2' => $billingAddress_filter['street2'], 'city' => $billingAddress_filter['city'], 'state' => $billingAddress_filter['state'], 'postalCode' => $billingAddress_filter['postalCode'], 'country' => $billingAddress_filter['country'], 'company' => $billingAddress_filter['company'], 'email_address' => $billingAddress_filter['email_address']);
                        $deliveryAddress_filter = apply_filters('woocommerce_order_formatted_shipping_address', array('firstName' => $order->shipping_first_name, 'lastName' => $order->shipping_last_name, 'phone' => $order->shipping_phone, 'street1' => $order->shipping_address_1, 'street2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postalCode' => $order->shipping_postcode, 'country' => $order->shipping_country, 'company' => $order->shipping_company), $order);
                        $deliveryAddress = array('firstName' => $deliveryAddress_filter['firstName'], 'lastName' => $deliveryAddress_filter['lastName'], 'phone' => $deliveryAddress_filter['phone'], 'street1' => $deliveryAddress_filter['street1'], 'street2' => $deliveryAddress_filter['street2'], 'city' => $deliveryAddress_filter['city'], 'state' => $deliveryAddress_filter['state'], 'postalCode' => $deliveryAddress_filter['postalCode'], 'country' => $deliveryAddress_filter['country'], 'company' => $deliveryAddress_filter['company']);
                        $primary_email = isset($primary_email_address) ? $primary_email_address : $billingAddress['email_address'];
                        unset($billingAddress['email_address']);
                    }
                }
                $vend_user_detail = get_option('wc_to_vend_user');
                if (isset($vend_user_detail) && !empty($vend_user_detail)) {
                    $user = explode('|', $vend_user_detail);
                    $vend_uid = isset($user[0]) ? $user[0] : null;
                    $vend_username = isset($user[1]) ? $user[1] : null;
                }
                //Ordered product(s)
                $items = $order->get_items();
                $taxes = $order->get_taxes();
                foreach ($items as $item) {
                    foreach ($taxes as $tax_label) {
                        $sql = mysql_query("SELECT  tax_rate_id FROM  `" . $wpdb->prefix . "woocommerce_tax_rates` WHERE  tax_rate_name='" . $tax_label['label'] . "' AND tax_rate_class='" . $item['item_meta']['_tax_class'][0] . "'");
                        if (mysql_num_rows($sql) != 0) {
                            $tax_classes = linksync_tax_classes($tax_label['label'], $item['item_meta']['_tax_class'][0]);
                            if ($tax_classes['result'] == 'success') {
                                $vend_taxes = explode('/', $tax_classes['tax_classes']);
                            }
                        }
                    }
                    $taxId = isset($vend_taxes[0]) ? $vend_taxes[0] : null;
                    $taxName = isset($vend_taxes[1]) ? $vend_taxes[1] : null;
                    $taxRate = isset($vend_taxes[2]) ? $vend_taxes[2] : null;
                    if (isset($item['variation_id']) && !empty($item['variation_id'])) {
                        $product_id = $item['variation_id'];
                    } else {
                        $product_id = $item['product_id'];
                    }
                    $pro_object = new WC_Product($product_id);
                    $itemtotal = (double) $item['item_meta']['_line_subtotal'][0];
                    if (isset($item['line_subtotal']) && !empty($item['line_subtotal'])) {
                        $product_amount = (double) ($item['line_subtotal'] / $item['qty']);
                    }
                    $discount = (double) $item['item_meta']['_line_subtotal'][0] - (double) $item['item_meta']['_line_total'][0];
                    if (isset($discount) && !empty($discount)) {
                        $discount = (double) ($discount / $item['qty']);
                    }
                    #---------Changes--------#
                    //Product Amount = product org amount - discount amount
                    $product_total_amount = (double) $product_amount - (double) $discount;
                    $product_sku = $pro_object->get_sku();
                    if (isset($product_total_amount) && isset($taxRate) && !empty($product_total_amount) && !empty($taxRate)) {
                        $taxValue = $product_total_amount * $taxRate;
                    }
                    $products[] = array('sku' => $product_sku, 'title' => $item['name'], 'price' => $product_total_amount, 'quantity' => $item['qty'], 'discountAmount' => isset($discount) ? $discount : 0, 'taxName' => isset($taxName) ? $taxName : null, 'taxId' => isset($taxId) ? $taxId : null, 'taxRate' => isset($taxRate) ? $taxRate : null, 'taxValue' => isset($taxValue) ? $taxValue : null, 'discountTitle' => isset($discountTitle) ? $discountTitle : 'sale');
                    $total_quantity += $item['qty'];
                    unset($taxId);
                    unset($taxName);
                    unset($taxRate);
                    unset($taxValue);
                }
                #---------Discount-----#
                //              if (isset($total_discount) && !empty($total_discount)) {
                //                    $taxes_Discount = $apicall->linksync_getTaxes();
                //                    if (isset($taxes_Discount) && !empty($taxes_Discount)) {
                //                        if (!isset($taxes_Discount['errorCode'])) {
                //                            if (isset($taxes_Discount['taxes'])) {
                //                                foreach ($taxes_Discount['taxes'] as $select_tax) {
                //                                    if ($select_tax['name'] == 'GST') {
                //                                        $discountTaxName = $select_tax['name'];
                //                                        $discountTaxId = $select_tax['id'];
                //                                        $discountTaxRate = $select_tax['rate'];
                //                                    }
                //                                }
                //                            }
                //                        }
                //                    }
                //                    if (isset($total_discount)) {
                //                        if (isset($discountTaxRate) && !empty($discountTaxRate)) {
                //                            $taxValue_discount = $discountTaxRate * $total_discount;
                //                        }
                //                    }
                //                    $products[] = array(
                //                        "price" => isset($total_discount) ? $total_discount : null,
                //                        "quantity" => 1,
                //                        "sku" => "vend-discount",
                //                        'taxName' => isset($discountTaxName) ? $discountTaxName : null,
                //                        'taxId' => isset($discountTaxId) ? $discountTaxId : null,
                //                        'taxRate' => isset($discountTaxRate) ? $discountTaxRate : null,
                //                        'taxValue' => isset($taxValue_discount) ? $taxValue_discount : null
                //                    );
                //                    $products[] = array(
                //                        "price" => isset($total_discount) ? $total_discount : null,
                //                        "quantity" => 1,
                //                        "sku" => "vend-discount",
                //                        'taxName' => null,
                //                        'taxId' => null,
                //                        'taxRate' => null,
                //                        'taxValue' => null
                //                    );
                //            }
                #----------Shipping------------#
                foreach ($taxes as $tax_label) {
                    if (isset($tax_label['shipping_tax_amount']) && !empty($tax_label['shipping_tax_amount'])) {
                        $tax_classes = linksync_tax_classes($tax_label['label'], $item['item_meta']['_tax_class'][0]);
                        if ($tax_classes['result'] == 'success') {
                            $vend_taxes = explode('/', $tax_classes['tax_classes']);
                            $taxId_shipping = isset($vend_taxes[0]) ? $vend_taxes[0] : null;
                            $taxName_shipping = isset($vend_taxes[1]) ? $vend_taxes[1] : null;
                            $taxRate_shipping = isset($vend_taxes[2]) ? $vend_taxes[2] : null;
                        }
                    }
                }
                if (isset($shipping_method) && !empty($shipping_method)) {
                    $shipping_cost = $order->get_total_shipping();
                    $shipping_with_tax = $order->get_shipping_tax();
                    if ($shipping_with_tax > 0) {
                        if (isset($shipping_cost) && isset($taxRate_shipping) && !empty($shipping_cost) && !empty($taxRate_shipping)) {
                            $taxValue_shipping = $shipping_cost * $taxRate_shipping;
                        }
                    }
                    $products[] = array("price" => isset($shipping_cost) ? $shipping_cost : null, "quantity" => 1, "sku" => "shipping", 'taxName' => isset($taxName_shipping) ? $taxName_shipping : null, 'taxId' => isset($taxId_shipping) ? $taxId_shipping : null, 'taxRate' => isset($taxRate_shipping) ? $taxRate_shipping : null, 'taxValue' => isset($taxValue_shipping) ? $taxValue_shipping : null);
                }
                //UTC Time
                date_default_timezone_set("UTC");
                $order_created = date("Y-m-d H:i:s", time());
                $OrderArray = array('uid' => isset($vend_uid) ? $vend_uid : null, 'created' => isset($order_created) ? $order_created : null, "orderId" => isset($order_no) ? $order_no : null, "source" => "WooCommerce", 'register_id' => isset($registerDb) ? $registerDb : null, 'user_name' => isset($vend_username) ? $vend_username : null, 'primary_email' => isset($primary_email) && !empty($primary_email) ? $primary_email : null, 'total' => isset($get_total) ? $get_total : 0, 'total_tax' => isset($total_tax) ? $total_tax : 0, 'comments' => isset($comments) ? $comments : null, 'taxes_included' => $taxes_included, 'currency' => isset($currency) ? $currency : 'USD', 'shipping_method' => isset($shipping_method) ? $shipping_method : null, 'payment' => isset($payment) && !empty($payment) ? $payment : null, 'products' => isset($products) && !empty($products) ? $products : null, 'payment_type_id' => isset($payment_method_id) ? $payment_method_id : null, 'billingAddress' => isset($billingAddress) && !empty($billingAddress) ? $billingAddress : null, 'deliveryAddress' => isset($deliveryAddress) && !empty($deliveryAddress) ? $deliveryAddress : null);
                $json = json_encode($OrderArray);
                $apicall->linksync_postOrder($json);
                linksync_class::add('Order Sync Woo to Vend', 'success', 'Woo Order no:' . $order_no, $LAIDKey);
            }
        } else {
            linksync_class::add('Order Sync Woo to Vend', 'Error', 'Already Sent Order', $LAIDKey);
        }
    }
}
示例#9
0
 /**
  * Tracks a checkout
  * @return none
  */
 function track_checkout($order_id, $params)
 {
     $this->user["wc cart size"] = 0;
     $this->user["wc cart value"] = 0;
     if (!is_user_logged_in()) {
         $this->user['name'] = $params["billing_first_name"] . " " . $params["billing_last_name"];
         $this->user['email'] = $params["billing_email"];
         $this->woopra->identify($this->user);
     } else {
         $this->woopra_detect();
     }
     global $woocommerce;
     $cart = $woocommerce->cart;
     $order = new WC_Order($order_id);
     $new_params = array("cart subtotal" => $cart->subtotal, "cart value" => $order->get_total(), "cart size" => $order->get_item_count(), "payment method" => $params["payment_method"], "shipping method" => $order->get_shipping_method(), "order discount" => $order->get_total_discount(), "order number" => $order->get_order_number());
     $this->woopra->track('wc checkout', $new_params, true);
 }
        /**
         * Define our custom columns shown in admin.
         * @param  string $column
         */
        public function custom_columns($column)
        {
            global $post, $woocommerce, $the_order;
            if (empty($the_order) || $the_order->id != $post->ID) {
                $the_order = new WC_Order($post->ID);
            }
            switch ($column) {
                case 'order_status':
                    printf('<mark class="%s tips" data-tip="%s">%s</mark>', sanitize_title($the_order->status), esc_html__($the_order->status, 'woocommerce'), esc_html__($the_order->status, 'woocommerce'));
                    break;
                case 'order_date':
                    if ('0000-00-00 00:00:00' == $post->post_date) {
                        $t_time = $h_time = __('Unpublished', 'woocommerce');
                    } else {
                        $t_time = get_the_time(__('Y/m/d g:i:s A', 'woocommerce'), $post);
                        $gmt_time = strtotime($post->post_date_gmt . ' UTC');
                        $time_diff = current_time('timestamp', 1) - $gmt_time;
                        $h_time = get_the_time(__('Y/m/d', 'woocommerce'), $post);
                    }
                    echo '<abbr title="' . esc_attr($t_time) . '">' . esc_html(apply_filters('post_date_column_time', $h_time, $post)) . '</abbr>';
                    break;
                case 'customer_message':
                    if ($the_order->customer_message) {
                        echo '<span class="note-on tips" data-tip="' . esc_attr($the_order->customer_message) . '">' . __('Yes', 'woocommerce') . '</span>';
                    } else {
                        echo '<span class="na">&ndash;</span>';
                    }
                    break;
                case 'billing_address':
                    if ($the_order->get_formatted_billing_address()) {
                        echo '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode($the_order->get_billing_address()) . '&z=16') . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $the_order->get_formatted_billing_address())) . '</a>';
                    } else {
                        echo '&ndash;';
                    }
                    if ($the_order->payment_method_title) {
                        echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->payment_method_title) . '</small>';
                    }
                    break;
                case 'order_items':
                    printf('<a href="#" class="show_order_items">' . _n('%d item', '%d items', sizeof($the_order->get_items()), 'woocommerce') . '</a>', sizeof($the_order->get_items()));
                    if (sizeof($the_order->get_items()) > 0) {
                        echo '<table class="order_items" cellspacing="0">';
                        foreach ($the_order->get_items() as $item) {
                            $_product = apply_filters('woocommerce_order_item_product', $the_order->get_product_from_item($item), $item);
                            $item_meta = new WC_Order_Item_Meta($item['item_meta']);
                            $item_meta_html = $item_meta->display(true, true);
                            ?>
						<tr>
							<td class="qty"><?php 
                            echo absint($item['qty']);
                            ?>
</td>
							<td class="name">
								<?php 
                            if (wc_product_sku_enabled() && $_product && $_product->get_sku()) {
                                echo $_product->get_sku() . ' - ';
                            }
                            echo apply_filters('woocommerce_order_item_name', $item['name'], $item);
                            ?>
								<?php 
                            if ($item_meta_html) {
                                ?>
									<a class="tips" href="#" data-tip="<?php 
                                echo esc_attr($item_meta_html);
                                ?>
">[?]</a>
								<?php 
                            }
                            ?>
							</td>
						</tr>
						<?php 
                        }
                        echo '</table>';
                    } else {
                        echo '&ndash;';
                    }
                    break;
                case 'shipping_address':
                    if ($the_order->get_formatted_shipping_address()) {
                        echo '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode($the_order->get_shipping_address()) . '&z=16') . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $the_order->get_formatted_shipping_address())) . '</a>';
                    } else {
                        echo '&ndash;';
                    }
                    if ($the_order->get_shipping_method()) {
                        echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->get_shipping_method()) . '</small>';
                    }
                    break;
                case 'order_notes':
                    if ($post->comment_count) {
                        // check the status of the post
                        $post->post_status !== 'trash' ? $status = '' : ($status = 'post-trashed');
                        $latest_notes = get_comments(array('post_id' => $post->ID, 'number' => 1, 'status' => $status));
                        $latest_note = current($latest_notes);
                        if ($post->comment_count == 1) {
                            echo '<span class="note-on tips" data-tip="' . esc_attr($latest_note->comment_content) . '">' . __('Yes', 'woocommerce') . '</span>';
                        } else {
                            $note_tip = isset($latest_note->comment_content) ? esc_attr($latest_note->comment_content . '<small style="display:block">' . sprintf(_n('plus %d other note', 'plus %d other notes', $post->comment_count - 1, 'woocommerce'), $post->comment_count - 1) . '</small>') : sprintf(_n('%d note', '%d notes', $post->comment_count, 'woocommerce'), $post->comment_count);
                            echo '<span class="note-on tips" data-tip="' . $note_tip . '">' . __('Yes', 'woocommerce') . '</span>';
                        }
                    } else {
                        echo '<span class="na">&ndash;</span>';
                    }
                    break;
                case 'order_total':
                    echo esc_html(strip_tags($the_order->get_formatted_order_total()));
                    if ($the_order->payment_method_title) {
                        echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->payment_method_title) . '</small>';
                    }
                    break;
                case 'order_title':
                    $customer_tip = '';
                    if ($address = $the_order->get_formatted_billing_address()) {
                        $customer_tip .= __('Billing:', 'woocommerce') . ' ' . $address . '<br/><br/>';
                    }
                    if ($the_order->billing_phone) {
                        $customer_tip .= __('Tel:', 'woocommerce') . ' ' . $the_order->billing_phone;
                    }
                    echo '<div class="tips" data-tip="' . esc_attr($customer_tip) . '">';
                    if ($the_order->user_id) {
                        $user_info = get_userdata($the_order->user_id);
                    }
                    if (!empty($user_info)) {
                        $username = '******' . absint($user_info->ID) . '">';
                        if ($user_info->first_name || $user_info->last_name) {
                            $username .= esc_html(ucfirst($user_info->first_name) . ' ' . ucfirst($user_info->last_name));
                        } else {
                            $username .= esc_html(ucfirst($user_info->display_name));
                        }
                        $username .= '</a>';
                    } else {
                        if ($the_order->billing_first_name || $the_order->billing_last_name) {
                            $username = trim($the_order->billing_first_name . ' ' . $the_order->billing_last_name);
                        } else {
                            $username = __('Guest', 'woocommerce');
                        }
                    }
                    printf(__('%s by %s', 'woocommerce'), '<a href="' . admin_url('post.php?post=' . absint($post->ID) . '&action=edit') . '"><strong>' . esc_attr($the_order->get_order_number()) . '</strong></a>', $username);
                    if ($the_order->billing_email) {
                        echo '<small class="meta email"><a href="' . esc_url('mailto:' . $the_order->billing_email) . '">' . esc_html($the_order->billing_email) . '</a></small>';
                    }
                    echo '</div>';
                    break;
                case 'order_actions':
                    ?>
<p>
					<?php 
                    do_action('woocommerce_admin_order_actions_start', $the_order);
                    $actions = array();
                    if (in_array($the_order->status, array('pending', 'on-hold'))) {
                        $actions['processing'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_processing&order_id=' . $post->ID), 'woocommerce-mark-order-processing'), 'name' => __('Processing', 'woocommerce'), 'action' => "processing");
                    }
                    if (in_array($the_order->status, array('pending', 'on-hold', 'processing'))) {
                        $actions['complete'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_complete&order_id=' . $post->ID), 'woocommerce-mark-order-complete'), 'name' => __('Complete', 'woocommerce'), 'action' => "complete");
                    }
                    $actions['view'] = array('url' => admin_url('post.php?post=' . $post->ID . '&action=edit'), 'name' => __('View', 'woocommerce'), 'action' => "view");
                    $actions = apply_filters('woocommerce_admin_order_actions', $actions, $the_order);
                    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('woocommerce_admin_order_actions_end', $the_order);
                    ?>
				</p><?php 
                    break;
            }
        }
示例#11
0
 public function generate_invoice($orderId)
 {
     global $wpdb, $woocommerce;
     $order = new WC_Order($orderId);
     $order_items = $order->get_items();
     //Build Xml
     $szamla = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><xmlszamla xmlns="http://www.szamlazz.hu/xmlszamla" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.szamlazz.hu/xmlszamla xmlszamla.xsd"></xmlszamla>');
     //If custom details
     if (isset($_POST['note']) && isset($_POST['deadline']) && isset($_POST['completed'])) {
         $note = $_POST['note'];
         $deadline = $_POST['deadline'];
         $complated_date = $_POST['completed'];
     } else {
         $note = get_option('wc_szamlazz_note');
         $deadline = get_option('wc_szamlazz_payment_deadline');
         $complated_date = date('Y-m-d');
     }
     //Account & Invoice settings
     $beallitasok = $szamla->addChild('beallitasok');
     $beallitasok->addChild('felhasznalo', get_option('wc_szamlazz_username'));
     $beallitasok->addChild('jelszo', get_option('wc_szamlazz_password'));
     if (get_option('wc_szamlazz_invoice_type') != 'paper') {
         $beallitasok->addChild('eszamla', 'true');
     } else {
         $beallitasok->addChild('eszamla', 'false');
     }
     $beallitasok->addChild('szamlaLetoltes', 'true');
     //Invoice details
     $fejlec = $szamla->addChild('fejlec');
     $fejlec->addChild('keltDatum', date('Y-m-d'));
     $fejlec->addChild('teljesitesDatum', $complated_date);
     if ($deadline) {
         $fejlec->addChild('fizetesiHataridoDatum', date('Y-m-d', strtotime('+' . $deadline . ' days')));
     } else {
         $fejlec->addChild('fizetesiHataridoDatum', date('Y-m-d'));
     }
     $fejlec->addChild('fizmod', $order->payment_method_title);
     $fejlec->addChild('penznem', $order->get_order_currency());
     $fejlec->addChild('szamlaNyelve', 'hu');
     $fejlec->addChild('megjegyzes', $note);
     if ($order->get_order_currency() != 'HUF') {
         //if the base currency is not HUF, we should define currency rates
         $fejlec->addChild('arfolyamBank', '');
         $fejlec->addChild('arfolyam', 0);
     }
     $fejlec->addChild('rendelesSzam', $order->get_order_number());
     $fejlec->addChild('elolegszamla', 'false');
     $fejlec->addChild('vegszamla', 'false');
     //Seller details
     $elado = $szamla->addChild('elado');
     //Customer details
     $vevo = $szamla->addChild('vevo');
     $vevo->addChild('nev', ($order->billing_company ? $order->billing_company . ' - ' : '') . $order->billing_first_name . ' ' . $order->billing_last_name);
     $vevo->addChild('irsz', $order->billing_postcode);
     $vevo->addChild('telepules', $order->billing_city);
     $vevo->addChild('cim', $order->billing_address_1);
     $vevo->addChild('email', $order->billing_email);
     $vevo->addChild('adoszam', '');
     $vevo->addChild('telefonszam', $order->billing_phone);
     //Customer Shipping details if needed
     if ($order->shipping_address) {
         $vevo->addChild('postazasiNev', ($order->shipping_company ? $order->shipping_company . ' - ' : '') . $order->shipping_first_name . ' ' . $order->shipping_last_name);
         $vevo->addChild('postazasiIrsz', $order->shipping_postcode);
         $vevo->addChild('postazasiTelepules', $order->shipping_city);
         $vevo->addChild('postazasiCim', $order->shipping_address_1);
     }
     //Order Items
     $tetelek = $szamla->addChild('tetelek');
     foreach ($order_items as $termek) {
         $tetel = $tetelek->addChild('tetel');
         $tetel->addChild('megnevezes', htmlspecialchars($termek["name"]));
         $tetel->addChild('mennyiseg', $termek["qty"]);
         $tetel->addChild('mennyisegiEgyseg', '');
         $tetel->addChild('nettoEgysegar', round($termek["line_total"], 2) / $termek["qty"]);
         $tetel->addChild('afakulcs', round($termek["line_tax"] / $termek["line_total"] * 100));
         $tetel->addChild('nettoErtek', round($termek["line_total"], 2));
         $tetel->addChild('afaErtek', round($termek["line_tax"], 2));
         $tetel->addChild('bruttoErtek', round($termek["line_total"], 2) + round($termek["line_tax"], 2));
         $tetel->addChild('megjegyzes', '');
     }
     //Shipping
     if ($order->get_shipping_methods()) {
         $tetel = $tetelek->addChild('tetel');
         $tetel->addChild('megnevezes', htmlspecialchars($order->get_shipping_method()));
         $tetel->addChild('mennyiseg', '1');
         $tetel->addChild('mennyisegiEgyseg', '');
         $tetel->addChild('nettoEgysegar', round($order->order_shipping, 2));
         if ($order->order_shipping == 0) {
             $tetel->addChild('afakulcs', '0');
         } else {
             $tetel->addChild('afakulcs', round($order->order_shipping_tax / $order->order_shipping * 100));
         }
         $tetel->addChild('nettoErtek', round($order->order_shipping, 2));
         $tetel->addChild('afaErtek', round($order->order_shipping_tax, 2));
         $tetel->addChild('bruttoErtek', round($order->order_shipping, 2) + round($order->order_shipping_tax, 2));
         $tetel->addChild('megjegyzes', '');
     }
     //Extra Fees
     $fees = $order->get_fees();
     if (!empty($fees)) {
         foreach ($fees as $fee) {
             $tetel = $tetelek->addChild('tetel');
             $tetel->addChild('megnevezes', htmlspecialchars($fee["name"]));
             $tetel->addChild('mennyiseg', 1);
             $tetel->addChild('mennyisegiEgyseg', '');
             $tetel->addChild('nettoEgysegar', round($fee["line_total"], 2));
             $tetel->addChild('afakulcs', round($fee["line_tax"] / $fee["line_total"] * 100));
             $tetel->addChild('nettoErtek', round($fee["line_total"], 2));
             $tetel->addChild('afaErtek', round($fee["line_tax"], 2));
             $tetel->addChild('bruttoErtek', round($fee["line_total"], 2) + round($fee["line_tax"], 2));
             $tetel->addChild('megjegyzes', '');
         }
     }
     //Discount
     if ($order->order_discount > 0) {
         $tetel = $tetelek->addChild('tetel');
         $tetel->addChild('megnevezes', 'Kedvezmény');
         $tetel->addChild('mennyiseg', '1');
         $tetel->addChild('mennyisegiEgyseg', '');
         $tetel->addChild('nettoEgysegar', -$order->order_discount);
         $tetel->addChild('afakulcs', 0);
         $tetel->addChild('nettoErtek', -$order->order_discount);
         $tetel->addChild('afaErtek', 0);
         $tetel->addChild('bruttoErtek', -$order->order_discount);
         $tetel->addChild('megjegyzes', '');
     }
     //Generate XML
     $xml_szamla = apply_filters('wc_szamlazz_xml', $szamla, $order);
     $xml = $xml_szamla->asXML();
     //Temporarily save XML
     $UploadDir = wp_upload_dir();
     $UploadURL = $UploadDir['basedir'];
     $location = realpath($UploadURL . "/wc_szamlazz/");
     $xmlfile = $location . '/' . $orderId . '.xml';
     $test = file_put_contents($xmlfile, $xml);
     //Generate cookie
     $cookie_file = $location . '/szamlazz_cookie.txt';
     //Agent URL
     $agent_url = 'https://www.szamlazz.hu/szamla/';
     //Geerate Cookie if not already exists
     if (!file_exists($cookie_file)) {
         file_put_contents($cookie_file, '');
     }
     // a CURL inicializálása
     $ch = curl_init($agent_url);
     // A curl hívás esetén tanúsítványhibát kaphatunk az SSL tanúsítvány valódiságától
     // függetlenül, ez az alábbi CURL paraméter állítással kiküszöbölhető,
     // ilyenkor nincs külön SSL ellenőrzés:
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     // POST-ban küldjük az adatokat
     curl_setopt($ch, CURLOPT_POST, true);
     // Kérjük a HTTP headert a válaszba, fontos információk vannak benne
     curl_setopt($ch, CURLOPT_HEADER, true);
     // változóban tároljuk a válasz tartalmát, nem írjuk a kimenetbe
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // Beállítjuk, hol van az XML, amiből számlát szeretnénk csinálni (= file upload)
     // az xmlfile-t itt fullpath-al kell megadni
     if (!class_exists('CurlFile')) {
         curl_setopt($ch, CURLOPT_POSTFIELDS, array('action-xmlagentxmlfile' => '@' . $xmlfile));
     } else {
         curl_setopt($ch, CURLOPT_POSTFIELDS, array('action-xmlagentxmlfile' => new CurlFile($xmlfile)));
     }
     // 30 másodpercig tartjuk fenn a kapcsolatot (ha valami bökkenő volna)
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     // Itt állítjuk be, hogy az érkező cookie a $cookie_file-ba kerüljön mentésre
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
     // Ha van már cookie file-unk, és van is benne valami, elküldjük a Számlázz.hu-nak
     if (file_exists($cookie_file) && filesize($cookie_file) > 0) {
         curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
     }
     // elküldjük a kérést a Számlázz.hu felé, és eltároljuk a választ
     $agent_response = curl_exec($ch);
     // kiolvassuk a curl-ból volt-e hiba
     $http_error = curl_error($ch);
     // ezekben a változókban tároljuk a szétbontott választ
     $agent_header = '';
     $agent_body = '';
     $agent_http_code = '';
     // lekérjük a válasz HTTP_CODE-ját, ami ha 200, akkor a http kommunikáció rendben volt
     // ettől még egyáltalán nem biztos, hogy a számla elkészült
     $agent_http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     // a válasz egy byte kupac, ebből az első "header_size" darab byte lesz a header
     $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     // a header tárolása, ebben lesznek majd a számlaszám, bruttó nettó összegek, errorcode, stb.
     $agent_header = substr($agent_response, 0, $header_size);
     // a body tárolása, ez lesz a pdf, vagy szöveges üzenet
     $agent_body = substr($agent_response, $header_size);
     // a curl már nem kell, lezárjuk
     curl_close($ch);
     // a header soronként tartalmazza az információkat, egy tömbbe teszük a külön sorokat
     $header_array = explode("\n", $agent_header);
     // ezt majd true-ra állítjuk ha volt hiba
     $volt_hiba = false;
     // ebben lesznek a hiba információk, plusz a bodyban
     $agent_error = '';
     $agent_error_code = '';
     // menjünk végig a header sorokon, ami "szlahu"-val kezdődik az érdekes nekünk és írjuk ki
     foreach ($header_array as $val) {
         if (substr($val, 0, strlen('szlahu')) === 'szlahu') {
             // megvizsgáljuk, hogy volt-e hiba
             if (substr($val, 0, strlen('szlahu_error:')) === 'szlahu_error:') {
                 // sajnos volt
                 $volt_hiba = true;
                 $agent_error = substr($val, strlen('szlahu_error:'));
             }
             if (substr($val, 0, strlen('szlahu_error_code:')) === 'szlahu_error_code:') {
                 // sajnos volt
                 $volt_hiba = true;
                 $agent_error_code = substr($val, strlen('szlahu_error_code:'));
             }
         }
     }
     // ha volt http hiba dobunk egy kivételt
     $response = array();
     $response['error'] = false;
     if ($http_error != "") {
         $response['error'] = true;
         $response['messages'][] = 'Http hiba történt:' . $http_error;
         return $response;
     }
     //Delete the XML if not debug mode
     if (!get_option('wc_szamlazz_debug')) {
         unlink($xmlfile);
     } else {
         //Rename XML file for security
         $random_file_name = substr(md5(rand()), 5);
         rename($xmlfile, $location . '/' . $orderId . '-' . $random_file_name . '.xml');
     }
     if ($volt_hiba) {
         $response['error'] = true;
         // ha a számla nem készült el kiírjuk amit lehet
         $response['messages'][] = 'Agent hibakód: ' . $agent_error_code;
         $response['messages'][] = 'Agent hibaüzenet: ' . urldecode($agent_error);
         $response['messages'][] = 'Agent válasz: ' . urldecode($agent_body);
         //Update order notes
         $order->add_order_note(__('Szamlazz.hu számlakészítás sikertelen! Agent hibakód: ', 'wc-szamlazz') . $agent_error_code);
         // dobunk egy kivételt
         return $response;
     } else {
         //Get the Invoice ID from the response header
         $szlahu_szamlaszam = '';
         foreach ($header_array as $val) {
             if (substr($val, 0, strlen('szlahu_szamlaszam')) === 'szlahu_szamlaszam') {
                 $szlahu_szamlaszam = substr($val, strlen('szlahu_szamlaszam:'));
                 break;
             }
         }
         //Build response array
         $response['messages'][] = __('Számla sikeresen létrehozva és elküldve a vásárlónak emailben.', 'wc-szamlazz');
         $response['invoice_name'] = $szlahu_szamlaszam;
         //Store as a custom field
         update_post_meta($orderId, '_wc_szamlazz', $szlahu_szamlaszam);
         //Update order notes
         $order->add_order_note(__('Szamlazz.hu számla sikeresen létrehozva. A számla sorszáma: ', 'wc-szamlazz') . $szlahu_szamlaszam);
         //Download & Store PDF - generate a random file name so it will be downloadable later only by you
         $random_file_name = substr(md5(rand()), 5);
         $pdf_file_name = 'szamla_' . $random_file_name . '_' . $orderId . '.pdf';
         $pdf_file = $location . '/' . $pdf_file_name;
         file_put_contents($pdf_file, $agent_body);
         //Store the filename
         update_post_meta($orderId, '_wc_szamlazz_pdf', $pdf_file_name);
         //Return the download url
         $response['link'] = '<p><a href="' . $this->generate_download_link($orderId) . '" id="wc_szamlazz_download" class="button button-primary" target="_blank">' . __('Számla megtekintése', 'wc-szamlazz') . '</a></p>';
         return $response;
     }
 }
示例#12
0
function sendDataToEPOS($order_id)
{
    if (!session_id()) {
        session_start();
    }
    $transaction_id = $_SESSION["TransactionID"];
    $collection_time = $_SESSION["CollectionTime"];
    $order = new WC_Order($order_id);
    $itemList = array();
    foreach ($order->get_items() as $key => $value) {
        $epos_product_id = get_field('epos_product_id', $value["item_meta"]["_product_id"][0]);
        $quantity = $value["item_meta"]["_qty"][0];
        array_push($itemList, array("ID" => "{$epos_product_id}", "Quantity" => "{$quantity}"));
    }
    $discountAmount = $order->cart_discount;
    $cartTotal = $order->get_total();
    //shipping address
    $customer_name = $order->shipping_first_name;
    $customer_name .= ' ' . $order->shipping_last_name;
    $shipping_address = $order->shipping_address_1;
    $shipping_address .= ' ' . $order->shipping_address_2;
    $shipping_address .= ' ' . $order->shipping_city;
    $shipping_address .= ' ' . $order->shipping_state;
    $shipping_postcode = $order->shipping_postcode;
    $email = $order->billing_email;
    $phone = $order->billing_phone;
    $comment = $order->order_comments;
    $shipping_fee = $order->get_total_shipping();
    $today = date("d/m/Y");
    $chosen_methods = $order->get_shipping_method();
    $chosen_methods == 'Local Pickup' ? $chosen_shipping_id = 0 : ($chosen_shipping_id = 1);
    //0=pick / 1=deli
    //wc_add_notice( $amount2 ,'error' );
    $jsonValue = array("APIKey" => royaltyCardAPI::APIKEY, "SiteID" => royaltyCardAPI::SITEID, "UserID" => "ab9d1dd6-52ea-4acf-bb29-06f2da959f33", "OrderItems" => $itemList, "OrderType" => $chosen_shipping_id, "RequiredDate" => $today, "RequiredTime" => $collection_time, "Name" => $customer_name, "DeliveryAddress" => $shipping_address, "DeliveryPostcode" => $shipping_postcode, "TelNo" => $phone, "Email" => $email, "DeliveryInstructions" => $comment, "DeliveryCost" => $shipping_fee, "PromoCode" => "sample", "PromoCodeDiscount" => $discountAmount, "Payment" => array("PaymentType" => "4", "TransactionID" => $transaction_id), "OrderTotal" => $cartTotal - $shipping_fee + $discountAmount);
    $arg = array('method' => 'POST', 'timeout' => 120, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array('Content-Type' => 'application/json'), 'body' => json_encode($jsonValue, JSON_UNESCAPED_SLASHES));
    $response = wp_remote_post(royaltyCardAPI::validateOrder, $arg);
    if (is_wp_error($response)) {
        //return $response->get_error_message();
        wc_add_notice($response->get_error_message(), 'error');
    }
    $json_header = 'application/json; charset=utf-8';
    if (!isset($response['headers']['content-type']) || $response['headers']['content-type'] != $json_header) {
        return 'Error - Header is not json format, please contact us.';
    }
    $obj = json_decode($response['body']);
    if (!is_a($obj, 'stdClass')) {
        return 'Error - Data may not be correct format.';
    }
    if ($obj->Result == 4) {
        //wc_add_notice( $obj->ResultString ,'error' );
        echo $obj->ResultString;
        session_destroy();
    } else {
        echo $obj->ResultString;
        session_destroy();
    }
}
示例#13
0
    $quantity = $value["item_meta"]["_qty"][0];
    array_push($itemList, array("ID" => "{$epos_product_id}", "Quantity" => "{$quantity}"));
}
$cartTotal = $order->get_total();
//shipping address
$customer_name = $order->shipping_first_name;
$customer_name .= ' ' . $order->shipping_last_name;
$shipping_address = $order->shipping_address_1;
$shipping_address .= ' ' . $order->shipping_address_2;
$shipping_address .= ' ' . $order->shipping_city;
$shipping_address .= ' ' . $order->shipping_state;
$shipping_postcode = $order->shipping_postcode;
$email = $order->billing_email;
$phone = $order->billing_phone;
$comment = $order->order_comments;
$shipping_fee = $order->get_total_shipping();
$today = date("d/m/Y");
$chosen_methods = $order->get_shipping_method();
$chosen_methods == 'Local Pickup' ? $chosen_shipping_id = 0 : ($chosen_shipping_id = 1);
//0=pick / 1=deli
//wc_add_notice( $amount2 ,'error' );
$jsonValue = array("APIKey" => royaltyCardAPI::APIKEY, "SiteID" => royaltyCardAPI::SITEID, "UserID" => "ab9d1dd6-52ea-4acf-bb29-06f2da959f33", "OrderItems" => $itemList, "OrderType" => $chosen_shipping_id, "RequiredDate" => '22/12/2015', "RequiredTime" => $collection_time, "Name" => $customer_name, "DeliveryAddress" => $shipping_address, "DeliveryPostcode" => $shipping_postcode, "TelNo" => $phone, "Email" => $email, "DeliveryInstructions" => $comment, "DeliveryCost" => $shipping_fee, "Payment" => array("PaymentType" => "4", "TransactionID" => $transaction_id), "OrderTotal" => $cartTotal);
var_dump($jsonValue);
?>
</pre>




<?php 
get_footer();
function sendCustomerInvoice($order_id)
{
    PlexLog::addLog(' Info =>@sendCustomerInvoice order_id=' . $order_id);
    $wooCommerceOrderObject = new WC_Order($order_id);
    $user_id = $wooCommerceOrderObject->get_user_id();
    $customerMailId = $wooCommerceOrderObject->billing_email;
    $invoice_mail_content = '';
    $invoice_mail_content .= '
	<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_container">
		<tbody>
			<tr>
				<td align="center" valign="top">
					<font face="Arial" style="font-weight:bold;background-color:#8fd1c8;color:#202020;"></font>
					<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_header" bgcolor="#8fd1c8">
						<tbody>
							<tr >
					            <td width="20" height="20"  bgcolor="#8fd1c8">&nbsp;</td>
					            <td bgcolor="#8fd1c8">&nbsp;</td>
					            <td width="20" bgcolor="#8fd1c8">&nbsp;</td>
					        </tr>
					        <tr >
					            <td width="20"  bgcolor="#8fd1c8">&nbsp;</td>
					            <td bgcolor="#8fd1c8" style="font-weight:bold;font-size:24px;color:#ffffff;" ><h2 style="margin:0;">Welcome to ' . get_option('blogname') . '! <br>Thank you for your order. We\'ll be in touch shortly with additional order and shipping information.</h2></td>
					            <td width="20" bgcolor="#8fd1c8">&nbsp;</td>
					        </tr>
					        <tr >
					            <td width="20" height="20"  bgcolor="#8fd1c8">&nbsp;</td>
					            <td bgcolor="#8fd1c8">&nbsp;</td>
					            <td width="20" bgcolor="#8fd1c8">&nbsp;</td>
					        </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
            	<td align="center" valign="top">
            		<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_body">
            			<tbody>
            				<tr>
            					<td valign="top">
            						<font style="background-color:#f9f9f9">
            							<table border="0" cellpadding="20" cellspacing="0" width="100%">
            								<tbody>
            									<tr>
	            									<td valign="top">
	            										<div>
	            											<font face="Arial" align="left" style="font-size:18px;color:#8a8a8a">
	            												<p>Your order #' . get_post_meta($order_id, "plexOrderId", true) . ' has been received and is now being processed. Your order details are shown below for your reference:</p>
																<table cellspacing="0" cellpadding="6" border="1" style="width:100%;">
																	<thead>
																		<tr>
																			<th scope="col">
																				<font align="left">Product</font>
																			</th>
																			<th scope="col">
																				<font align="left">Quantity</font>
																			</th>
																			<th scope="col">
																				<font align="left">Price</font>
																			</th>
																		</tr>
																	</thead>
																	<tbody>';
    $allItems = $wooCommerceOrderObject->get_items();
    foreach ($allItems as $key => $value) {
        $invoice_mail_content .= '
																				<tr>
																					<td>
																						<font align="left">' . $value["name"] . '<br><small></small></font>
																					</td>
																					<td>
																						<font align="left">' . $value["qty"] . '</font>
																					</td>
																					<td>
																						<font align="left">
																							<span class="amount">$' . $value["line_subtotal"] . '</span>
																						</font>
																					</td>
																				</tr>';
    }
    $invoice_mail_content .= '																		
																	</tbody>
																	<tfoot style="text-align: left;">
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Cart Subtotal:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_subtotal()) . '</span>
																				</font>
																			</td>
																		</tr>';
    if ($wooCommerceOrderObject->get_total_discount() > 0.0) {
        $invoice_mail_content .= '<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Discount:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_total_discount()) . '</span>
																				</font>
																			</td>
																		</tr>';
    }
    $invoice_mail_content .= '<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Tax:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_cart_tax() + $wooCommerceOrderObject->get_shipping_tax()) . '</span>
																				</font>
																			</td>
																		</tr>
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Shipping:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . $wooCommerceOrderObject->get_total_shipping() . '</span>&nbsp;<small>via ' . $wooCommerceOrderObject->get_shipping_method() . '</small>
																				</font>
																			</td>
																		</tr>
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Payment Method:</font>
																			</th>
																			<td>
																				<font align="left">' . $wooCommerceOrderObject->payment_method_title . '</font>
																			</td>
																		</tr>
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Order Total:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_total()) . '</span>
																				</font>
																			</td>
																		</tr>
																	</tfoot>
																</table>
																<h2>
																	<font face="Arial" align="left" style="font-weight:bold;font-size:30px;color:#6d6d6d">Customer details</font>
																</h2>
																<p><strong>Email:</strong> ' . $customerMailId . '</p>
																<p><strong>Tel:</strong> ' . $wooCommerceOrderObject->billing_phone . '</p>
																<table cellspacing="0" cellpadding="0" border="0">
																	<tbody>
																		<tr>
																			<td valign="top" width="50%">
																				<h3>
																					<font face="Arial" align="left" style="font-weight:bold;font-size:26px;color:#6d6d6d">Billing address</font>
																				</h3>
																				<p>' . $wooCommerceOrderObject->get_formatted_billing_address() . '</p>

																			</td>
																			<td valign="top" width="50%">
																				<h3>
																					<font face="Arial" align="left" style="font-weight:bold;font-size:26px;color:#6d6d6d">Shipping address</font>
																				</h3>
																				<p>' . $wooCommerceOrderObject->get_formatted_shipping_address() . '</p>
																			</td>
																		</tr>
																	</tbody>
																</table>
															</font>
														</div>
													</td>
												</tr>
											</tbody>
										</table>
									</font>
								</td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<td align="center" valign="top">
					<table border="0" cellpadding="10" cellspacing="0" width="600" id="template_footer">
						<tbody>
							<tr>
								<td valign="top">
	                                <table border="0" cellpadding="4" cellspacing="0" width="100%">
	                                	<tbody>
	                                		<tr>
	                                			<td colspan="2" valign="middle" id="credit" style="background-color: #777;">
	                                				<font face="Arial" align="center" style="font-size:12px;color:#bce3de">
	                                					<p>' . site_url() . '</p>
	                                                </font>
	                                            </td>
	                                        </tr>
	                                    </tbody>
	                                </table>
	                            </td>
	                        </tr>
	                    </tbody>
	                </table>
	            </td>
	        </tr>
	    </tbody>
	</table>';
    $emailHeader = "Content-type: text/html";
    // To send HTML mail, the Content-type header must be set
    $emailHeader = 'MIME-Version: 1.0' . "\r\n";
    $emailHeader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    // Additional emailHeader
    $emailHeader .= 'From: ' . get_bloginfo('name') . ' <*****@*****.**>' . "\r\n";
    $emailSubject = "Your plexuser order receipt from " . date_i18n(wc_date_format(), strtotime($wooCommerceOrderObject->order_date));
    wp_mail($customerMailId, $emailSubject, $invoice_mail_content, $emailHeader);
}