Get available gateways.
public get_available_payment_gateways ( ) : array | ||
return | array |
public function importOrderToWoocommerce($orders) { if (isset($orders) && !empty($orders)) { $order_status = get_option('order_vend_to_wc'); //Order Status from order config setting foreach ($orders['orders'] as $order) { if (isset($order['id']) && !empty($order['id'])) { $OrderIds = get_option("Vend_orderIDs"); if (isset($OrderIds) && !empty($OrderIds)) { $Ids = unserialize($OrderIds); } else { $Ids = array(); } if (!in_array($order['id'], $Ids)) { update_option('Vend_orderIDs', serialize(array_merge($Ids, array($order['id'])))); $order_data = array('post_name' => 'order-' . date('M-d-Y-hi-a'), 'post_type' => 'shop_order', 'post_title' => date('M d, Y @ h:i A'), 'post_excerpt' => 'Source: ' . ucfirst($order['source']) . ' Order #' . $order['orderId'], 'post_status' => $order_status, 'ping_status' => 'closed', 'comment_status' => 'open'); $order_id = wp_insert_post($order_data, true); // create order if (is_wp_error($order_id)) { $order->errors = $order_id; } else { if (isset($order['payment']['transactionNumber']) && !empty($order['payment']['transactionNumber'])) { add_post_meta($order_id, 'transaction_id', $order['payment']['transactionNumber'], true); } /* ---------------------------------------Payment Mapping --------------------------------- */ if (isset($order['payment']['retailer_payment_type_id']) && !empty($order['payment']['retailer_payment_type_id'])) { $all_payment = get_option('vend_to_wc_payments'); if (isset($all_payment) && !empty($all_payment)) { $explode_payment = explode(',', $all_payment); foreach ($explode_payment as $payments_method) { $payment_method = explode('|', $payments_method); if (in_array($order['payment']['retailer_payment_type_id'], $payment_method)) { $gatways = new WC_Payment_Gateways(); $payment = $gatways->get_available_payment_gateways(); $wocoomercepayment = $payment_method[1]; foreach ($payment as $payment_method_id => $payment_method_title) { if ($payment_method_title->title == $wocoomercepayment) { add_post_meta($order_id, '_payment_method_title', $wocoomercepayment, true); add_post_meta($order_id, '_payment_method', $payment_method_id, true); } } } } } } $customer_import = get_option('vend_to_wc_customer'); if (isset($customer_import) && $customer_import == 'customer_data') { if (isset($order['billingAddress'])) { add_post_meta($order_id, '_billing_first_name', isset($order['billingAddress']['firstName']) ? $order['billingAddress']['firstName'] : NULL, true); add_post_meta($order_id, '_billing_last_name', isset($order['billingAddress']['lastName']) ? $order['billingAddress']['lastName'] : NULL, true); add_post_meta($order_id, '_billing_company', isset($order['billingAddress']['company']) ? $order['billingAddress']['company'] : NULL, true); add_post_meta($order_id, '_billing_address_1', isset($order['billingAddress']['street1']) ? $order['billingAddress']['street1'] : NULL, true); add_post_meta($order_id, '_billing_address_2', isset($order['billingAddress']['street2']) ? $order['billingAddress']['street2'] : NULL, true); add_post_meta($order_id, '_billing_city', isset($order['billingAddress']['city']) ? $order['billingAddress']['city'] : NULL, true); add_post_meta($order_id, '_billing_postcode', isset($order['billingAddress']['postalCode']) ? $order['billingAddress']['postalCode'] : NULL, true); add_post_meta($order_id, '_billing_country', isset($order['billingAddress']['country']) ? $order['billingAddress']['country'] : NULL, true); add_post_meta($order_id, '_billing_state', isset($order['billingAddress']['state']) ? $order['billingAddress']['state'] : NULL, true); add_post_meta($order_id, '_billing_phone', isset($order['billingAddress']['phone']) ? $order['billingAddress']['phone'] : NULL, true); } if (isset($order['deliveryAddress'])) { add_post_meta($order_id, '_shipping_first_name', isset($order['deliveryAddress']['firstName']) ? $order['deliveryAddress']['firstName'] : NULL, true); add_post_meta($order_id, '_shipping_last_name', isset($order['deliveryAddress']['lastName']) ? $order['deliveryAddress']['lastName'] : NULL, true); add_post_meta($order_id, '_shipping_company', isset($order['deliveryAddress']['company']) ? $order['deliveryAddress']['company'] : NULL, true); add_post_meta($order_id, '_shipping_address_1', isset($order['deliveryAddress']['street1']) ? $order['deliveryAddress']['street1'] : NULL, true); add_post_meta($order_id, '_shipping_address_2', isset($order['deliveryAddress']['street2']) ? $order['deliveryAddress']['street2'] : NULL, true); add_post_meta($order_id, '_shipping_city', isset($order['deliveryAddress']['city']) ? $order['deliveryAddress']['city'] : NULL, true); add_post_meta($order_id, '_shipping_postcode', isset($order['deliveryAddress']['postalCode']) ? $order['deliveryAddress']['postalCode'] : NULL, true); add_post_meta($order_id, '_shipping_country', isset($order['deliveryAddress']['country']) ? $order['deliveryAddress']['country'] : NULL, true); add_post_meta($order_id, '_shipping_state', isset($order['deliveryAddress']['state']) ? $order['deliveryAddress']['state'] : NULL, true); } if (isset($order['primary_email'])) { require_once ABSPATH . 'wp-includes/user.php'; require_once ABSPATH . 'wp-includes/pluggable.php'; $user_email = $order['primary_email']; $user_name = $order['billingAddress']['firstName'] . ' ' . $order['billingAddress']['lastName']; $user_id = email_exists($user_email); $email_password = false; if (!$user_id) { $user_password = wp_generate_password(12, false); $user_id = wp_create_user($user_name, $user_password, $user_email); update_user_option($user_id, 'default_password_nag', true, true); $email_password = true; $message = " Username: {$user_name}\n Password: {$user_password}\n " . wp_login_url(); if (isset($order['billingAddress'])) { add_user_meta($user_id, 'billing_first_name', isset($order['billingAddress']['firstName']) ? $order['billingAddress']['firstName'] : NULL, true); add_user_meta($user_id, 'billing_last_name', isset($order['billingAddress']['lastName']) ? $order['billingAddress']['lastName'] : NULL, true); add_user_meta($user_id, 'billing_company', isset($order['billingAddress']['company']) ? $order['billingAddress']['company'] : NULL, true); add_user_meta($user_id, 'billing_address_1', isset($order['billingAddress']['street1']) ? $order['billingAddress']['street1'] : NULL, true); add_user_meta($user_id, 'billing_address_2', isset($order['billingAddress']['street2']) ? $order['billingAddress']['street2'] : NULL, true); add_user_meta($user_id, 'billing_city', isset($order['billingAddress']['city']) ? $order['billingAddress']['city'] : NULL, true); add_user_meta($user_id, 'billing_postcode', isset($order['billingAddress']['postalCode']) ? $order['billingAddress']['postalCode'] : NULL, true); add_user_meta($user_id, 'billing_country', isset($order['billingAddress']['country']) ? $order['billingAddress']['country'] : NULL, true); add_user_meta($user_id, 'billing_state', isset($order['billingAddress']['state']) ? $order['billingAddress']['state'] : NULL, true); add_user_meta($user_id, 'billing_phone', isset($order['billingAddress']['phone']) ? $order['billingAddress']['phone'] : NULL, true); } if (isset($order['deliveryAddress'])) { add_user_meta($user_id, 'shipping_first_name', isset($order['deliveryAddress']['firstName']) ? $order['deliveryAddress']['firstName'] : NULL, true); add_user_meta($user_id, 'shipping_last_name', isset($order['deliveryAddress']['lastName']) ? $order['deliveryAddress']['lastName'] : NULL, true); add_user_meta($user_id, 'shipping_company', isset($order['deliveryAddress']['company']) ? $order['deliveryAddress']['company'] : NULL, true); add_user_meta($user_id, 'shipping_address_1', isset($order['deliveryAddress']['street1']) ? $order['deliveryAddress']['street1'] : NULL, true); add_user_meta($user_id, 'shipping_address_2', isset($order['deliveryAddress']['street2']) ? $order['deliveryAddress']['street2'] : NULL, true); add_user_meta($user_id, 'shipping_city', isset($order['deliveryAddress']['city']) ? $order['deliveryAddress']['city'] : NULL, true); add_user_meta($user_id, 'shipping_postcode', isset($order['deliveryAddress']['postalCode']) ? $order['deliveryAddress']['postalCode'] : NULL, true); add_user_meta($user_id, 'shipping_country', isset($order['deliveryAddress']['country']) ? $order['deliveryAddress']['country'] : NULL, true); add_user_meta($user_id, 'shipping_state', isset($order['deliveryAddress']['state']) ? $order['deliveryAddress']['state'] : NULL, true); } wp_mail($user_email, 'Your username and password', $message); $user = new WP_User($user_id); $user->set_role('customer'); } add_post_meta($order_id, '_customer_user', $user_id); } } if (isset($order['total']) && !empty($order['total'])) { if (isset($order['total_tax'])) { $order['total'] = $order['total_tax'] + $order['total']; } add_post_meta($order_id, '_order_total', $order['total'], true); } if (isset($order['taxes_included']) && $order['taxes_included'] == true) { add_post_meta($order_id, '_order_tax', $order['total_tax'], true); } if (isset($order['updated_at']) && !empty($order['updated_at'])) { add_post_meta($order_id, '_completed_date', $order['updated_at'], true); } if (isset($order['id']) && !empty($order['id'])) { add_post_meta($order_id, '_vend_orderid', $order['id'], true); } if (isset($order['currency']) && !empty($order['currency'])) { add_post_meta($order_id, '_order_currency', $order['currency'], true); } // billing info if (isset($order['user_name']) && !empty($order['user_name'])) { add_post_meta($order_id, '_billing_email', $order['user_name'], true); } $i = 0; foreach ($order['products'] as $products) { $product_id = $this->isReferenceExists_order($products['sku']); if ($product_id['result'] == 'success' && !empty($product_id['data'])) { $product = new WC_Product($product_id['data']); if ($product->post->post_type == 'product_variation') { $variant_id = $product->id; $product->id = $product->post->post_parent; } $wcproduct = $product->post; if ($product) { // add item $item_id = wc_add_order_item($order_id, array('order_item_name' => $wcproduct->post_title, 'order_item_type' => 'line_item')); if ($item_id) { $line_tax = array(); $line_subtax = array(); // add item meta data if (isset($products['price']) && !empty($products['price'])) { $products['price'] = (double) ($products['price'] * $products['quantity']); } $line_total = (double) $products['price']; wc_add_order_item_meta($item_id, '_qty', $products['quantity']); //Product Order Quantity From Vend wc_add_order_item_meta($item_id, '_product_id', $product->id); wc_add_order_item_meta($item_id, '_line_total', $line_total); wc_add_order_item_meta($item_id, '_variation_id', isset($variant_id) ? $variant_id : ''); $result_tax_class = $this->linksync_tax_classes_vend_to_wc($products['taxId']); if ($result_tax_class['result'] == 'success') { $tax_class = $result_tax_class['tax_class']; } wc_add_order_item_meta($item_id, '_tax_class', isset($tax_class) ? $tax_class : ''); wc_add_order_item_meta($item_id, '_line_tax', $products['taxValue']); wc_add_order_item_meta($item_id, '_line_subtotal', $products['price']); wc_add_order_item_meta($item_id, '_line_subtotal_tax', $products['taxValue']); $line_tax['total'][1] = $products['taxValue']; $line_subtax['subtotal'][1] = $products['taxValue']; $line_tax_data = array_merge($line_tax, $line_subtax); wc_add_order_item_meta($item_id, '_line_tax_data', $line_tax_data); if (isset($variant_id) && !empty($variant_id)) { global $wpdb; $query = mysql_query("SELECT meta_key,meta_value FROM `" . $wpdb->prefix . "postmeta` WHERE post_id='" . $variant_id . "' AND meta_key LIKE 'attribute_pa_%'"); while ($result = mysql_fetch_assoc($query)) { $meta_key = str_replace('attribute_', '', $result['meta_key']); wc_add_order_item_meta($item_id, $meta_key, $result['meta_value']); } } } } else { $order->errors = 'Product SKU (' . $order->{$item_id} . ') not found.'; } } elseif ($products['sku'] == 'shipping') { $taxes = array(); // add item $shipping_id = wc_add_order_item($order_id, array('order_item_name' => $products['title'], 'order_item_type' => 'shipping')); if ($shipping_id) { wc_add_order_item_meta($shipping_id, 'cost', $products['price']); wc_add_order_item_meta($shipping_id, 'method_id', ''); wc_add_order_item_meta($shipping_id, 'taxes', ''); add_post_meta($order_id, '_order_shipping', $products['price']); add_post_meta($order_id, '_order_shipping_tax', $products['taxValue']); $shippping_tax_amount = $products['taxValue']; $taxes[1] = $products['taxValue']; wc_add_order_item_meta($shipping_id, 'taxes', $taxes); } } elseif ($products['sku'] == 'vend-discount') { add_post_meta($order_id, '_cart_discount', $products['price']); } /* ---------------------------------------Tax Mapping --------------------------------- */ if ($products['sku'] != 'shipping' || $products['sku'] != 'vend-discount') { if ($i == 0) { $tax_class_name = $this->linksync_tax_classes_vend_to_wc($products['taxId']); if ($tax_class_name['result'] == 'success') { // add item $tax_id = wc_add_order_item($order_id, array('order_item_name' => $tax_class_name['tax_class_name'] . '-' . $tax_class_name['tax_rate_id'], 'order_item_type' => 'tax')); if ($tax_id) { wc_add_order_item_meta($tax_id, 'rate_id', $tax_class_name['tax_rate_id']); wc_add_order_item_meta($tax_id, 'label', $tax_class_name['tax_class_name']); wc_add_order_item_meta($tax_id, 'compound', 0); $tax_amount = $order['total_tax']; wc_add_order_item_meta($tax_id, 'tax_amount', isset($tax_amount) ? $tax_amount : 0); wc_add_order_item_meta($tax_id, 'shipping_tax_amount', isset($shippping_tax_amount) ? $shippping_tax_amount : 0); } } $i++; } } } } linksync_class::add('Order Sync Vend to Woo', 'success', 'Vend Order no:' . $order['orderId'] . ', Woo Order no:' . $order_id, get_option('linksync_laid')); } } } } return true; }
/** * WooCommerce Fortnox General Settings * * @access public * @param void * @return void */ function register_woocommerce_advanced_accounting_settings() { $this->plugin_settings_tabs[$this->advanced_accounting_key] = 'Avancerade Bokföringsinställningar'; $pg = new WC_Payment_Gateways(); $payment_gateways = $pg->get_available_payment_gateways(); register_setting($this->advanced_accounting_key, $this->advanced_accounting_key); add_settings_section('section_general', 'Avancerade Bokföringsinställningar', array(&$this, 'section_freight_desc'), $this->advanced_accounting_key); foreach ($payment_gateways as $payment_gateway) { logthis($payment_gateway->enabled); //add_settings_field( 'woocommerce-fortnox-api-key', 'API Nyckel', array( &$this, 'field_hidden_option_text' ), $this->general_settings_key, 'section_general', array ( 'tab_key' => $this->general_settings_key, 'key' => 'api-key', 'desc' => '') ); if ($payment_gateway->enabled == 'yes') { add_settings_field('woocommerce-fortnox-advanced-accounting-' . $payment_gateway->id, $payment_gateway->title, array(&$this, 'field_option_text'), $this->advanced_accounting_key, 'section_general', array('tab_key' => $this->advanced_accounting_key, 'key' => $payment_gateway->id, 'desc' => '')); } } add_settings_field('woocommerce-fortnox-product-sales-account-25', 'Bokföringskonto försäljning 25% Moms', array(&$this, 'field_option_text'), $this->advanced_accounting_key, 'section_general', array('tab_key' => $this->advanced_accounting_key, 'key' => 'product_sales_account_25', 'desc' => '')); add_settings_field('woocommerce-fortnox-product-sales-account-12', 'Bokföringskonto försäljning 12% Moms', array(&$this, 'field_option_text'), $this->advanced_accounting_key, 'section_general', array('tab_key' => $this->advanced_accounting_key, 'key' => 'product_sales_account_12', 'desc' => '')); add_settings_field('woocommerce-fortnox-product-sales-account-6', 'Bokföringskonto försäljning 6% Moms', array(&$this, 'field_option_text'), $this->advanced_accounting_key, 'section_general', array('tab_key' => $this->advanced_accounting_key, 'key' => 'product_sales_account_6', 'desc' => '')); add_settings_field('woocommerce-fortnox-product-eu-sales-account', 'Bokföringskonto försäljning EU', array(&$this, 'field_option_text'), $this->advanced_accounting_key, 'section_general', array('tab_key' => $this->advanced_accounting_key, 'key' => 'product_eu_sales_account', 'desc' => '')); add_settings_field('woocommerce-fortnox-product-eu-sales-vat-account', 'Bokföringskonto Moms EU', array(&$this, 'field_option_text'), $this->advanced_accounting_key, 'section_general', array('tab_key' => $this->advanced_accounting_key, 'key' => 'product_eu_sales_vat_account', 'desc' => '')); add_settings_field('woocommerce-fortnox-product-export-sales-account', 'Bokföringskonto försäljning export', array(&$this, 'field_option_text'), $this->advanced_accounting_key, 'section_general', array('tab_key' => $this->advanced_accounting_key, 'key' => 'product_export_sales_account', 'desc' => '')); add_settings_field('woocommerce-fortnox-product-purchase-account', 'Bokföringskonto inköp', array(&$this, 'field_option_text'), $this->advanced_accounting_key, 'section_general', array('tab_key' => $this->advanced_accounting_key, 'key' => 'product_purchase_account', 'desc' => '')); }
</p> </td> </tr> <tr> <th scope="row"> <label for="wcw_transfer_only"><?php _e('Credits Transfered When Order Status is in', WC_WALLET_TEXT); ?> </label> </th> <td> <?php $sts = wc_get_order_statuses(); $array = new WC_Payment_Gateways(); $methods = $array->get_available_payment_gateways(); if (count($methods) != 0) { echo "<table>"; foreach ($methods as $key => $method) { $current_status = $wcw_transfer_only["{$key}"]; echo "<tr>"; echo "<td style ='padding-left: 0px; vertical-align: top;'>" . $method->title . "</td><td>"; foreach ($sts as $keys => $status) { ?> <label class = "w200" for="dashboard_right_now-hide_<?php echo $keys; ?> _<?php echo $key; ?> ">