Skip to content

Commit

Permalink
Merge pull request #31 from PTNUSASATUINTIARTHA-DOKU/doku_checkout_v2
Browse files Browse the repository at this point in the history
Merchant only receive payment through DOKU Checkout V2
  • Loading branch information
dokudevex authored Feb 10, 2023
2 parents 15972af + 06ff6da commit a9632d0
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 53 deletions.
8 changes: 0 additions & 8 deletions woo-doku-jokul/Common/JokulListModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@

// Modules
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulMainModule.php');
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulDokuVaModule.php');
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulBsmVaModule.php');
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulMandiriVaModule.php');
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulBcaVaModule.php');
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulPermataVaModule.php');
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulAlfaO2OModule.php');
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulCreditCardModule.php');
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulBriVaModule.php');
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulCheckoutModule.php');

//API End Point
Expand Down
9 changes: 9 additions & 0 deletions woo-doku-jokul/Form/JokulCheckoutSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
'type' => 'text',
'description' => __('Default: Merchant PAN', 'woocommerce-gateway-jokul'),
'placeholder' => '0',
),
'auto_redirect_jokul' => array(
'title' => __('Auto Redirect', 'woocommerce-gateway-jokul'),
'type' => 'select',
'default' => 'false',
'options' => array(
'false' => __('FALSE', 'woocommerce-gateway-jokul'),
'true' => __('TRUE', 'woocommerce-gateway-jokul'),
),
)
)
);
Expand Down
10 changes: 1 addition & 9 deletions 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.8
* Version: 1.3.9
* Author: DOKU
* Author URI: http://www.doku.com
* WC requires at least: 2.2
Expand Down Expand Up @@ -59,14 +59,6 @@ function addJokulGateway($methods)
{
$mainSettings = get_option('woocommerce_jokul_gateway_settings');
$methods[] = 'JokulMainModule';
$methods[] = 'JokulDokuVaModule';
$methods[] = 'JokulBsmVaModule';
$methods[] = 'JokulMandiriVaModule';
$methods[] = 'JokulBcaVaModule';
$methods[] = 'JokulPermataVaModule';
$methods[] = 'JokulAlfaO2OModule';
$methods[] = 'JokulCreditCardModule';
$methods[] = 'JokulBriVaModule';
$methods[] = 'JokulCheckoutModule';

return $methods;
Expand Down
27 changes: 16 additions & 11 deletions woo-doku-jokul/Module/JokulCheckoutModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __construct()
$paymentDescription = $this->get_option('payment_description');

$this->payment_method = $this->get_option('payment_method');
$this->auto_redirect_jokul = $this->get_option('auto_redirect_jokul');

$this->sac_check = $mainSettings['sac_check' ];
$this->sac_textbox = $mainSettings['sac_textbox'];
Expand Down Expand Up @@ -84,32 +85,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' => preg_replace($pattern, "", $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, 'url' => 'https://www.doku.com/');


}
// 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');
$order_data[] = array('name' => preg_replace($pattern, "", $shipping_item['name']), 'price' => wc_format_decimal($shipping_item['cost'], $dp), 'quantity' => '1', 'sku' => '0', 'category' => 'uncategorized', 'url' => 'https://www.doku.com/');
}
}
// 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');
$order_data[] = array('name' => preg_replace($pattern, "", $tax->label), 'price' => wc_format_decimal($tax->amount, $dp), 'quantity' => '1', 'sku' => '0', 'category' => 'uncategorized', 'url' => 'https://www.doku.com/');
}
}
// 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');
$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', 'url' => 'https://www.doku.com/');
}
}
// 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[] = array('name' => preg_replace($pattern, "", $coupon_item['name']), 'price' => wc_format_decimal($coupon_item['discount_amount'], $dp), 'quantity' => '1', 'sku' => '0', 'category' => 'uncategorized', 'url' => 'https://www.doku.com/');
}
}
$order_data = apply_filters('woocommerce_cli_order_data', $order_data);
Expand All @@ -126,19 +127,19 @@ public function process_payment($order_id)
$order_data = $order->get_data();

$params = array(
'customerId' => 0 !== $order->get_customer_id() ? $order->get_customer_id() : preg_replace('/[^0-9]/', '', $order->billing_phone),
'customerId' => 0 !== $order->get_customer_id() ? $order->get_customer_id() : null,
'customerEmail' => $order->get_billing_email(),
'customerName' => $order->get_billing_first_name() . " " . $order->get_billing_last_name(),
'amount' => $amount,
'invoiceNumber' => $order->get_order_number(),
'expiryTime' => $this->expiredTime,
'phone' => preg_replace('/[^0-9]/', '', $order->billing_phone),
'phone' => $order->billing_phone,
'country' => $order->billing_country,
'address' => preg_replace($pattern, "", $order->shipping_address_1),
'itemQty' => $this->get_order_data($order),
'payment_method' => $this->payment_method,
'postcode' => $order_data['billing']['postcode'],
'state' => $order_data['billing']['state'] !== null ? $order_data['billing']['state'] : "",
'state' => $order_data['billing']['state'],
'city' => $order_data['billing']['city'],
'info1' => '',
'info2' => '',
Expand All @@ -147,7 +148,12 @@ public function process_payment($order_id)
'reusableStatus' => false,
'callback_url' => $this->get_return_url($order) . '&' . $order_id,
'sac_check' => $this->sac_check,
'auto_redirect' => $this->auto_redirect_jokul,
'sac_textbox' => $this->sac_textbox,
'first_name_shipping' => $order->shipping_first_name,
'address_shipping' => preg_replace($pattern, "",$order->shipping_address_1),
'city_shipping' => $order->shipping_city,
'postal_code_shipping' => $order->shipping_postcode
);

if ($this->environmentPaymentJokul == 'false') {
Expand Down Expand Up @@ -177,7 +183,6 @@ public function process_payment($order_id)
return array(
'result' => 'success',
'redirect' => $this->get_return_url($order) . "&jokul=show&" . $order_id
// 'redirect' => wc_get_page_permalink('checkout')."?jokul=show"
);
} else {
wc_add_notice('There is something wrong. Please try again.', 'error');
Expand Down Expand Up @@ -326,8 +331,8 @@ function woo_title_order_received($title)
global $woocommerce;

if (function_exists('is_order_received_page') && is_order_received_page() && $title === 'Order received') {
$haystack = explode("&", $_SERVER['QUERY_STRING']);
$order = wc_get_order($haystack[1]);
$haystack = explode('/', $_SERVER['REQUEST_URI']);
$order = wc_get_order($haystack[4]);
$woocommerce->cart->empty_cart();
wc_reduce_stock_levels($order->get_id());

Expand Down
3 changes: 2 additions & 1 deletion woo-doku-jokul/Module/JokulCreditCardModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function my_disruptive_filter($content) {

return $url;
}

public function get_order_data($order)
{
$pattern = "/[^A-Za-z0-9? .,_-]/";
Expand Down Expand Up @@ -142,6 +142,7 @@ public function process_payment($order_id)

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

$params = array(
'customerId' => 0 !== $order->get_customer_id() ? $order->get_customer_id() : null,
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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Direct"
Expand Down
50 changes: 42 additions & 8 deletions woo-doku-jokul/Service/JokulCheckoutService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ public function generated($config, $params)
$dateTimeFinal = substr($dateTime,0,19)."Z";

$data = $params['sac_check'] === 'yes' ? array(
"order" => array(
"order" => $params['auto_redirect'] === 'true' ? array(
"invoice_number" => $params['invoiceNumber'],
"line_items" => $params['itemQty'],
"amount" => $params['amount'],
"callback_url" => $params['callback_url'],
"currency" => "IDR",
"auto_redirect" => true,
"disable_retry_payment" => true
): array(
"invoice_number" => $params['invoiceNumber'],
"line_items" => $params['itemQty'],
"amount" => $params['amount'],
Expand All @@ -38,19 +46,36 @@ public function generated($config, $params)
"city" => $params['city'],
"address" => $params['address']
),
"shipping_address" => array(
"first_name" => $params['first_name_shipping'],
"address" => trim($params['address_shipping']),
"city" => $params['city_shipping'],
"postal_code" => $params['postal_code_shipping'],
"phone" => $params['phone'],
"country_code" => "ID"
),
"additional_info" => array (
"integration" => array (
"name" => "woocommerce-plugin",
"version" => "1.3.8",
"version" => "1.3.9",
"cms_version" => $params['woo_version']
),
"account" => array(
"id" => $params['sac_textbox']
),
"method" => "Jokul Checkout"
"method" => "Jokul Checkout",
"doku_wallet_notify_url" => ""
)
) : array(
"order" => array(
"order" => $params['auto_redirect'] === 'true' ? array(
"invoice_number" => $params['invoiceNumber'],
"line_items" => $params['itemQty'],
"amount" => $params['amount'],
"callback_url" => $params['callback_url'],
"currency" => "IDR",
"auto_redirect" => true,
"disable_retry_payment" => true
): array(
"invoice_number" => $params['invoiceNumber'],
"line_items" => $params['itemQty'],
"amount" => $params['amount'],
Expand All @@ -71,13 +96,22 @@ public function generated($config, $params)
"city" => $params['city'],
"address" => $params['address']
),
"shipping_address" => array(
"first_name" => $params['first_name_shipping'],
"address" => trim($params['address_shipping']),
"city" => $params['city_shipping'],
"postal_code" => $params['postal_code_shipping'],
"phone" => $params['phone'],
"country_code" => "ID"
),
"additional_info" => array (
"integration" => array (
"name" => "woocommerce-plugin",
"version" => "1.3.8",
"version" => "1.3.9",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Checkout"
"method" => "Jokul Checkout",
"doku_wallet_notify_url" => ""
)
);

Expand All @@ -104,13 +138,13 @@ public function generated($config, $params)
'Request-Id:'.$requestId,
'Client-Id:'.$config['client_id'],
'Request-Timestamp:'.$dateTimeFinal,

));

$responseJson = curl_exec($ch);

curl_close($ch);

$this->jokulUtils->doku_log($this, 'Jokul Checkout REQUEST : ' . json_encode($data), $params['invoiceNumber']);
$this->jokulUtils->doku_log($this, 'Jokul Checkout REQUEST URL : ' . $url, $params['invoiceNumber']);
$this->jokulUtils->doku_log($this, 'Jokul Checkout RESPONSE : ' . json_encode($responseJson, JSON_PRETTY_PRINT), $params['invoiceNumber']);
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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"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.8",
"version" => "1.3.9",
"cms_version" => $params['woo_version']
),
"method" => "Jokul Direct"
Expand Down
Loading

0 comments on commit a9632d0

Please sign in to comment.