Skip to content

Commit

Permalink
Merge pull request #29 from PTNUSASATUINTIARTHA-DOKU/regex_line_items…
Browse files Browse the repository at this point in the history
…_address

regex filter line_items and address
  • Loading branch information
dokudevex authored Sep 2, 2022
2 parents accdab2 + d4885e8 commit 4626a7e
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 35 deletions.
2 changes: 1 addition & 1 deletion woo-doku-jokul/JokulMainPg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Jokul - WooCommerce
* Plugin URI: http://www.doku.com
* Description: Accept payment through various payment channels with Jokul. Make it easy for your customers to purchase on your store.
* Version: 1.3.7
* Version: 1.3.8
* Author: DOKU
* Author URI: http://www.doku.com
* WC requires at least: 2.2
Expand Down
14 changes: 8 additions & 6 deletions woo-doku-jokul/Module/JokulCheckoutModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function __construct()

public function get_order_data($order)
{
$pattern = "/[^A-Za-z0-9? .,_-]/";
$order_post = get_post($order->id);
$dp = wc_get_price_decimals();
$order_data = array();
Expand All @@ -83,32 +84,32 @@ public function get_order_data($order)
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[] = array('price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'quantity' => wc_stock_amount($item['qty']), 'name' => str_replace(array( '(', ')', ','), '', $item['name']), 'sku' => $product_sku, 'category' => $categories_string);
$order_data[] = array('price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'quantity' => wc_stock_amount($item['qty']), 'name' => preg_replace($pattern, "", $item['name']), 'sku' => $product_sku, 'category' => $categories_string);


}
// Add shipping.
foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
if (wc_format_decimal($shipping_item['cost'], $dp) > 0) {
$order_data[] = array('name' => str_replace(array( '(', ')' ), '', $shipping_item['name']), 'price' => wc_format_decimal($shipping_item['cost'], $dp), 'quantity' => '1', 'sku' => 'ship-01', 'category' => 'uncategorized');
$order_data[] = array('name' => preg_replace($pattern, "", $shipping_item['name']), 'price' => wc_format_decimal($shipping_item['cost'], $dp), 'quantity' => '1', 'sku' => '0', 'category' => 'uncategorized');
}
}
// Add taxes.
foreach ($order->get_tax_totals() as $tax_code => $tax) {
if (wc_format_decimal($tax->amount, $dp) > 0) {
$order_data[] = array('name' => $tax->label, 'price' => wc_format_decimal($tax->amount, $dp), 'quantity' => '1', 'sku' => 'tax-01', 'category' => 'uncategorized');
$order_data[] = array('name' => preg_replace($pattern, "", $tax->label), 'price' => wc_format_decimal($tax->amount, $dp), 'quantity' => '1', 'sku' => '0', 'category' => 'uncategorized');
}
}
// Add fees.
foreach ($order->get_fees() as $fee_item_id => $fee_item) {
if (wc_format_decimal($order->get_line_total($fee_item), $dp) > 0) {
$order_data[] = array('name' => $fee_item['name'], 'price' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'quantity' => '1', 'sku' => 'fee-01', 'category' => 'uncategorized');
$order_data[] = array('name' => preg_replace($pattern, "", $fee_item['name']), 'price' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'quantity' => '1', 'sku' => '0', 'category' => 'uncategorized');
}
}
// Add coupons.
foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
if (wc_format_decimal($coupon_item['discount_amount'], $dp) > 0) {
$order_data[] = array('name' => $coupon_item['name'], 'price' => wc_format_decimal($coupon_item['discount_amount'], $dp), 'quantity' => '1', 'sku' => 'coupon-01', 'category' => 'uncategorized');
$order_data[] = array('name' => preg_replace($pattern, "", $coupon_item['name']), 'price' => wc_format_decimal($coupon_item['discount_amount'], $dp), 'quantity' => '1', 'sku' => '0', 'category' => 'uncategorized');
}
}
$order_data = apply_filters('woocommerce_cli_order_data', $order_data);
Expand All @@ -118,6 +119,7 @@ public function get_order_data($order)
public function process_payment($order_id)
{
global $woocommerce;
$pattern = "/[^A-Za-z0-9? .-\/+,=_:@]/";

$order = wc_get_order($order_id);
$amount = $order->order_total;
Expand All @@ -132,7 +134,7 @@ public function process_payment($order_id)
'expiryTime' => $this->expiredTime,
'phone' => preg_replace('/[^0-9]/', '', $order->billing_phone),
'country' => $order->billing_country,
'address' => $order->shipping_address_1,
'address' => preg_replace($pattern, "", $order->shipping_address_1),
'itemQty' => $this->get_order_data($order),
'payment_method' => $this->payment_method,
'postcode' => $order_data['billing']['postcode'],
Expand Down
68 changes: 58 additions & 10 deletions woo-doku-jokul/Module/JokulCreditCardModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,68 @@ function my_disruptive_filter($content) {
return $url;
}

public function get_order_data($order)
{
$pattern = "/[^A-Za-z0-9? .,_-]/";
$order_post = get_post($order->id);
$dp = wc_get_price_decimals();
$order_data = array();
// add line items
foreach ($order->get_items() as $item_id => $item) {
$product = $order->get_product_from_item($item);
$term_names = wp_get_post_terms( $item->get_product_id(), 'product_cat', array('fields' => 'names') );
$categories_string = implode(',', $term_names);
$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[] = array('price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'quantity' => wc_stock_amount($item['qty']), 'name' => preg_replace($pattern, "", $item['name']), 'sku' => $product_sku, 'category' => $categories_string);


}
// Add shipping.
foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
if (wc_format_decimal($shipping_item['cost'], $dp) > 0) {
$order_data[] = array('name' => preg_replace($pattern, "", $shipping_item['name']), 'price' => wc_format_decimal($shipping_item['cost'], $dp), 'quantity' => '1', 'sku' => '0', 'category' => 'uncategorized');
}
}
// Add taxes.
foreach ($order->get_tax_totals() as $tax_code => $tax) {
if (wc_format_decimal($tax->amount, $dp) > 0) {
$order_data[] = array('name' => preg_replace($pattern, "", $tax->label), 'price' => wc_format_decimal($tax->amount, $dp), 'quantity' => '1', 'sku' => '0', 'category' => 'uncategorized');
}
}
// Add fees.
foreach ($order->get_fees() as $fee_item_id => $fee_item) {
if (wc_format_decimal($order->get_line_total($fee_item), $dp) > 0) {
$order_data[] = array('name' => preg_replace($pattern, "", $fee_item['name']), 'price' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'quantity' => '1', 'sku' => '0', 'category' => 'uncategorized');
}
}
// Add coupons.
foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
if (wc_format_decimal($coupon_item['discount_amount'], $dp) > 0) {
$order_data[] = array('name' => preg_replace($pattern, "", $coupon_item['name']), 'price' => wc_format_decimal($coupon_item['discount_amount'], $dp), 'quantity' => '1', 'sku' => '0', 'category' => 'uncategorized');
}
}
$order_data = apply_filters('woocommerce_cli_order_data', $order_data);
return $order_data;
}

public function process_payment($order_id)
{
global $woocommerce;
$pattern = "/[^A-Za-z0-9? .-\/+,=_:@]/";

$order = wc_get_order($order_id);
$amount = $order->order_total;
$itemQty = array();

foreach ($order->get_items() as $item_id => $item ) {
$_product = wc_get_product($item->get_product_id());
$Price = $_product->get_price();

$itemQty[] = array('name' => $item->get_name(), 'price' => $Price, 'quantity' => $item->get_quantity());
}

$params = array(
'customerId' => 0 !== $order->get_customer_id() ? $order->get_customer_id() : null,
Expand All @@ -104,8 +152,8 @@ public function process_payment($order_id)
'expiryTime' => $this->expiredTime,
'phone' => $order->billing_phone,
'country' => $order->billing_country,
'address' => $order->shipping_address_1,
'itemQty' => $itemQty,
'address' => preg_replace($pattern, "", $order->shipping_address_1),
'itemQty' => $this->get_order_data($order),
'language' => $this->language,
'backgroundColor' => $this->backgroundColor,
'fontColor' => $this->fontColor,
Expand Down
4 changes: 2 additions & 2 deletions woo-doku-jokul/Service/JokulAlfaO2OService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"account" => array(
Expand Down Expand Up @@ -66,7 +66,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Direct"
Expand Down
4 changes: 2 additions & 2 deletions woo-doku-jokul/Service/JokulBcaVaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"account" => array(
Expand All @@ -55,7 +55,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Direct"
Expand Down
4 changes: 2 additions & 2 deletions woo-doku-jokul/Service/JokulBriVaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"account" => array(
Expand All @@ -55,7 +55,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Direct"
Expand Down
4 changes: 2 additions & 2 deletions woo-doku-jokul/Service/JokulBsmVaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"account" => array(
Expand All @@ -55,7 +55,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Direct"
Expand Down
4 changes: 2 additions & 2 deletions woo-doku-jokul/Service/JokulCheckoutService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function generated($config, $params)
"additional_info" => array (
"integration" => array (
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"account" => array(
Expand Down Expand Up @@ -74,7 +74,7 @@ public function generated($config, $params)
"additional_info" => array (
"integration" => array (
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Checkout"
Expand Down
4 changes: 2 additions & 2 deletions woo-doku-jokul/Service/JokulCreditCardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function generated($config, $params)
"additional_info" => array (
"integration" => array (
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"account" => array(
Expand Down Expand Up @@ -80,7 +80,7 @@ public function generated($config, $params)
"additional_info" => array (
"integration" => array (
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Direct"
Expand Down
4 changes: 2 additions & 2 deletions woo-doku-jokul/Service/JokulDokuVaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"account" => array(
Expand All @@ -55,7 +55,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Direct"
Expand Down
4 changes: 2 additions & 2 deletions woo-doku-jokul/Service/JokulMandiriVaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function generated($config, $params)
"additional_info" => array (
"integration" => array (
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"account" => array(
Expand All @@ -54,7 +54,7 @@ public function generated($config, $params)
"additional_info" => array (
"integration" => array (
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Direct"
Expand Down
4 changes: 2 additions & 2 deletions woo-doku-jokul/Service/JokulPermataVaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"account" => array(
Expand All @@ -48,7 +48,7 @@ public function generated($config, $params)
"additional_info" => array(
"integration" => array(
"name" => "woocommerce-plugin",
"version" => "1.3.7",
"version" => "1.3.8",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Direct"
Expand Down

0 comments on commit 4626a7e

Please sign in to comment.