Skip to content

Commit

Permalink
Merge pull request #58 from PTNUSASATUINTIARTHA-DOKU/revision
Browse files Browse the repository at this point in the history
Fixing minor bug and adjust code to wordpress standards
  • Loading branch information
rafidoku authored Nov 25, 2024
2 parents 1f70b8d + 2dd6eeb commit 1cadb30
Show file tree
Hide file tree
Showing 24 changed files with 471 additions and 293 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
*.zip
*.zip
.DS_Store
1 change: 0 additions & 1 deletion woo-doku-jokul/Block/DokuCheckoutBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ public function get_payment_method_data() {
}

}
?>
3 changes: 2 additions & 1 deletion woo-doku-jokul/Common/JokulConfig.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

if ( ! defined( 'ABSPATH' ) ) exit;

class JokulConfig {

const SANDBOX_BASE_URL = 'https://api-sandbox.doku.com';
Expand All @@ -14,4 +16,3 @@ public function getBaseUrl($state)
}
}

?>
53 changes: 37 additions & 16 deletions woo-doku-jokul/Common/JokulDb.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
<?php

if ( ! defined( 'ABSPATH' ) ) exit;

class JokulDb {

function addData($datainsert)
{
global $wpdb;
$SQL = "";

foreach ( $datainsert as $field_name=>$field_data )
{
$SQL .= " $field_name = '$field_data',";
}
$SQL = substr( $SQL, 0, -1 );

$wpdb->query("INSERT INTO ".$wpdb->prefix."jokuldb SET $SQL");
}
$table = $wpdb->prefix . "jokuldb";

$columns = array_keys($datainsert);
$placeholders = array_map(function ($value) {
return is_numeric($value) ? '%d' : '%s';
}, $datainsert);

$columns_str = implode(', ', $columns);
$placeholders_str = implode(', ', $placeholders);

$query = $wpdb->prepare(
"INSERT INTO $table ($columns_str) VALUES ($placeholders_str)",
array_values($datainsert)
);

$result = $wpdb->query($query);
}

function updateData($invoice, $status)
{
Expand All @@ -25,21 +34,33 @@ function updateData($invoice, $status)
function checkTrx($order_id, $amount, $vaNumber)
{
global $wpdb;
$db_prefix = $wpdb->prefix;
$table = $wpdb->prefix . "jokuldb";

$query="SELECT * FROM ".$db_prefix."jokuldb where invoice_number='".$order_id."' and amount='".$amount."' ORDER BY trx_id DESC LIMIT 1";
$result = $wpdb->get_var($query);
$query = $wpdb->prepare(
"SELECT * FROM $table WHERE invoice_number = %s AND amount = %d ORDER BY trx_id DESC LIMIT 1",
$order_id,
$amount
);

$result = $wpdb->get_row($query);

return $result;
}

function checkStatusTrx($order_id, $amount, $vaNumber, $processType)
{
global $wpdb;
$db_prefix = $wpdb->prefix;
$query="SELECT payment_code FROM ".$db_prefix."jokuldb where invoice_number='".$order_id."' and amount='".$amount."' and process_type = 'PAYMENT_COMPLETED' ORDER BY trx_id DESC LIMIT 1";
$table = $wpdb->prefix . "jokuldb";

$query = $wpdb->prepare(
"SELECT payment_code FROM $table WHERE invoice_number = %s AND amount = %d AND process_type = %s ORDER BY trx_id DESC LIMIT 1",
$order_id,
$amount,
$processType
);

$result = $wpdb->get_var($query);
return $result;
}
}
?>

11 changes: 6 additions & 5 deletions woo-doku-jokul/Common/JokulListModule.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

if ( ! defined( 'ABSPATH' ) ) exit;

// Check PHP version.
if (version_compare(PHP_VERSION, '5.2.1', '<')) {
throw new Exception('PHP version >= 5.2.1 required');
Expand All @@ -15,11 +17,10 @@
}

// Modules
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulMainModule.php');
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Module/JokulCheckoutModule.php');
require_once(DOKU_PAYMENT_PLUGIN_PATH . '/Module/JokulMainModule.php');
require_once(DOKU_PAYMENT_PLUGIN_PATH . '/Module/JokulCheckoutModule.php');

//API End Point
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Service/JokulNotificationService.php');
require_once(DOKU_JOKUL_PLUGIN_PATH . '/Service/JokulQrisNotificationService.php');
require_once(DOKU_PAYMENT_PLUGIN_PATH . '/Service/JokulNotificationService.php');
require_once(DOKU_PAYMENT_PLUGIN_PATH . '/Service/JokulQrisNotificationService.php');

?>
88 changes: 67 additions & 21 deletions woo-doku-jokul/Common/JokulUtils.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

if ( ! defined( 'ABSPATH' ) ) exit;

define("HTML_EMAIL_HEADERS", array('Content-Type: text/html; charset=UTF-8'));

class JokulUtils
Expand Down Expand Up @@ -47,18 +50,33 @@ public function generateSignatureNotification($headers, $body, $secret, $request
return 'HMACSHA256=' . $signature;
}

// public function getIpaddress()
// {
// if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
// $ip = $_SERVER['HTTP_CLIENT_IP'];
// } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
// } else {
// $ip = $_SERVER['REMOTE_ADDR'];
// }
// return $ip;
// }

public function getIpaddress()
{
$ip = '';
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$ipArray = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = trim($ipArray[0]);
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
return filter_var($ip, FILTER_VALIDATE_IP) ? $ip : null;
}


public function guidv4($data = null)
{
$data = $data ?? random_bytes(16);
Expand All @@ -71,15 +89,13 @@ public function guidv4($data = null)

function doku_log($class, $log_msg, $invoice_number = '')
{

$log_filename = "doku_log";
$log_header = date(DATE_ATOM, time()) . ' ' . '---> ' . $invoice_number . " : ";
$log_header = gmdate(DATE_ATOM) . ' ' . '---> ' . $invoice_number . " : ";
if (!file_exists($log_filename)) {
// create directory/folder uploads.
mkdir($log_filename, 0777, true);
}
$log_file_data = $log_filename . '/log_' . date('d-M-Y') . '.log';
// if you don't add `FILE_APPEND`, the file will be erased each time you add a log
$log_file_data = $log_filename . '/log_' . gmdate('d-M-Y') . '.log';
file_put_contents($log_file_data, $log_header . $log_msg . "\n", FILE_APPEND);
}

Expand All @@ -90,7 +106,12 @@ public function send_email($order, $emailParams, $howToPayUrl)

//format the email
$recipient = $emailParams['customerEmail'];
$subject = __("Hi " . $emailParams['customerName']. ", here is your payment instructions for order number " . $order->get_order_number() . "!", 'theme_name');
$subject = sprintf(
/* translators: %1$s: Customer name, %2$s: Order number */
__("Hi %1$s, here is your payment instructions for order number %2$s!", 'doku-payment'),
$emailParams['customerName'],
$order->get_order_number()
);
$content = $this->get_custom_email_html($order, $this->getEmailMessage($howToPayUrl), $mailer, $subject);
$headers = "Content-Type: text/html\r\n";

Expand All @@ -111,27 +132,52 @@ function get_custom_email_html($order, $instructions, $mailer, $heading = false)
));
}

// function getEmailMessage($url)
// {
// $ch = curl_init();
// $headers = array(
// 'Accept: application/json',
// 'Content-Type: application/json',

// );
// curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// curl_setopt($ch, CURLOPT_HEADER, 0);

// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// // Timeout in seconds
// curl_setopt($ch, CURLOPT_TIMEOUT, 30);

// $response = curl_exec($ch);
// $responseJson = json_decode($response, true);
// return $responseJson['payment_instruction'];
// }
function getEmailMessage($url)
{
$ch = curl_init();
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
'Accept' => 'application/json',
'Content-Type' => 'application/json',
);

$args = array(
'headers' => $headers,
'timeout' => 30,
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = wp_remote_get($url, $args);

if (is_wp_error($response)) {
$error_message = $response->get_error_message();
return "Error fetching payment instructions: $error_message";
}

// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
// Ambil isi body dari respons
$response_body = wp_remote_retrieve_body($response);
$responseJson = json_decode($response_body, true);

$response = curl_exec($ch);
$responseJson = json_decode($response, true);
return $responseJson['payment_instruction'];
return $responseJson['payment_instruction'] ?? null;
}

function formatPhoneNumber($phoneNumber) {
Expand Down
14 changes: 8 additions & 6 deletions woo-doku-jokul/Form/JokulAlfaO2OSetting.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<?php

if ( ! defined( 'ABSPATH' ) ) exit;

return apply_filters(
'jokul_alfa_o2o_settings',
array(
'channel_name' => array(
'title' => __('Payment Channel Display Name', 'woocommerce-gateway-jokul'),
'title' => __('Payment Channel Display Name', 'doku-payment'),
'type' => 'text',
'description' => __('Default : Alfamart', 'woocommerce-gateway-jokul'),
'description' => __('Default : Alfamart', 'doku-payment'),
'placeholder' => 'Alfamart',
),
'payment_description' => array(
'title' => __('Payment Description', 'woocommerce-gateway-jokul'),
'title' => __('Payment Description', 'doku-payment'),
'type' => 'textarea',
'css' => 'width: 400px;',
'description' => __('Change your payment description for payment using Alfamart', 'woocommerce-gateway-jokul'),
'description' => __('Change your payment description for payment using Alfamart', 'doku-payment'),
'placeholder' => 'Bayar pesanan dengan transfer melalui Alfamart',
),
'footer_message' => array(
'title' => __('Footer Message', 'woocommerce-gateway-jokul'),
'title' => __('Footer Message', 'doku-payment'),
'type' => 'text',
'description' => __('Change your footer message for payment using Alfamart', 'woocommerce-gateway-jokul'),
'description' => __('Change your footer message for payment using Alfamart', 'doku-payment'),
'placeholder' => 'ex: Call Center 021 555-0525',
)
)
Expand Down
12 changes: 6 additions & 6 deletions woo-doku-jokul/Form/JokulBcaVaSetting.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

if ( ! defined( 'ABSPATH' ) ) exit;

return apply_filters(
'jokul_bca_va_settings',
array(
'channel_name' => array(
'title' => __('Payment Channel Display Name', 'woocommerce-gateway-jokul'),
'title' => __('Payment Channel Display Name', 'doku-payment'),
'type' => 'text',
'description' => __('Default : BCA VA', 'woocommerce-gateway-jokul'),
'description' => __('Default : BCA VA', 'doku-payment'),
'placeholder' => 'BCA VA',
),
'payment_description' => array(
'title' => __('Payment Description', 'woocommerce-gateway-jokul'),
'title' => __('Payment Description', 'doku-payment'),
'type' => 'textarea',
'css' => 'width: 400px;',
'description' => __('Change your payment description for BCA VA', 'woocommerce-gateway-jokul'),
'description' => __('Change your payment description for BCA VA', 'doku-payment'),
'placeholder' => 'Bayar pesanan dengan transfer dari BCA',
)
)
);

?>
12 changes: 6 additions & 6 deletions woo-doku-jokul/Form/JokulBriVaSetting.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

if ( ! defined( 'ABSPATH' ) ) exit;

return apply_filters(
'jokul_bri_va_settings',
array(
'channel_name' => array(
'title' => __('Payment Channel Display Name', 'woocommerce-gateway-jokul'),
'title' => __('Payment Channel Display Name', 'doku-payment'),
'type' => 'text',
'description' => __('Default : Bank Rakyat Indonesia VA', 'woocommerce-gateway-jokul'),
'description' => __('Default : Bank Rakyat Indonesia VA', 'doku-payment'),
'placeholder' => 'Bank Rakyat Indonesia VA',
),
'payment_description' => array(
'title' => __('Payment Description', 'woocommerce-gateway-jokul'),
'title' => __('Payment Description', 'doku-payment'),
'type' => 'textarea',
'css' => 'width: 400px;',
'description' => __('Change your payment description for Bank Rakyat Indonesia VA', 'woocommerce-gateway-jokul'),
'description' => __('Change your payment description for Bank Rakyat Indonesia VA', 'doku-payment'),
'placeholder' => 'Bayar pesanan dengan transfer Bank Rakyat Indonesia VA',
)
)
);

?>
12 changes: 6 additions & 6 deletions woo-doku-jokul/Form/JokulBsmVaSetting.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

if ( ! defined( 'ABSPATH' ) ) exit;

return apply_filters(
'jokul_bsm_va_settings',
array(
'channel_name' => array(
'title' => __('Payment Channel Display Name', 'woocommerce-gateway-jokul'),
'title' => __('Payment Channel Display Name', 'doku-payment'),
'type' => 'text',
'description' => __('Default : Bank Syariah Indonesia VA', 'woocommerce-gateway-jokul'),
'description' => __('Default : Bank Syariah Indonesia VA', 'doku-payment'),
'placeholder' => 'Bank Syariah Indonesia VA',
),
'payment_description' => array(
'title' => __('Payment Description', 'woocommerce-gateway-jokul'),
'title' => __('Payment Description', 'doku-payment'),
'type' => 'textarea',
'css' => 'width: 400px;',
'description' => __('Change your payment description for Bank Syariah Indonesia VA', 'woocommerce-gateway-jokul'),
'description' => __('Change your payment description for Bank Syariah Indonesia VA', 'doku-payment'),
'placeholder' => 'Bayar pesanan dengan transfer Bank Syariah Indonesia VA',
)
)
);

?>
Loading

0 comments on commit 1cadb30

Please sign in to comment.