| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
/* |
| 6 |
* Plugin Name: DOKU Payment |
| 7 |
* Plugin URI: https://github.com/PTNUSASATUINTIARTHA-DOKU/doku-woocommerce-plugin |
| 8 |
* Description: Accept payment through various payment channels with DOKU. Make it easy for your customers to purchase on your store. |
| 9 |
* Version: 1.3.30 |
| 10 |
* Author: DOKU |
| 11 |
* Author URI: http://www.doku.com |
| 12 |
* License: GPLv2 or later |
| 13 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 14 |
* WC requires at least: 2.2 |
| 15 |
**/ |
| 16 |
|
| 17 |
/* |
| 18 |
* The class itself, please note that it is inside plugins_loaded action hook |
| 19 |
*/ |
| 20 |
define('DOKU_PAYMENT_MAIN_FILE', __FILE__); |
| 21 |
define('DOKU_PAYMENT_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
| 22 |
|
| 23 |
add_action('plugins_loaded', 'doku_payment_init_gateway_class'); |
| 24 |
function doku_payment_init_gateway_class() |
| 25 |
{ |
| 26 |
|
| 27 |
if (!class_exists('WC_Payment_Gateway')) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
if (!class_exists('DokuMainPg')) { |
| 32 |
class DokuMainPg |
| 33 |
{ |
| 34 |
private static $instance; |
| 35 |
|
| 36 |
public static function get_instance() |
| 37 |
{ |
| 38 |
if (self::$instance === null) { |
| 39 |
self::$instance = new self(); |
| 40 |
} |
| 41 |
|
| 42 |
return self::$instance; |
| 43 |
} |
| 44 |
|
| 45 |
private function __construct() |
| 46 |
{ |
| 47 |
$this->init(); |
| 48 |
} |
| 49 |
|
| 50 |
public function init() |
| 51 |
{ |
| 52 |
require_once dirname(__FILE__) . '/Common/JokulListModule.php'; |
| 53 |
add_filter('woocommerce_payment_gateways', array($this, 'addJokulGateway')); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Add jokul payment methods |
| 58 |
* |
| 59 |
* @param array $methods |
| 60 |
* @return array $methods |
| 61 |
*/ |
| 62 |
function addJokulGateway($methods) |
| 63 |
{ |
| 64 |
$methods[] = 'DokuCheckoutModule'; |
| 65 |
|
| 66 |
$is_wc_admin = false; |
| 67 |
if ( is_admin() ) { |
| 68 |
$is_post_edit = ( isset( $GLOBALS['pagenow'] ) && ( $GLOBALS['pagenow'] === 'post.php' || $GLOBALS['pagenow'] === 'post-new.php' ) ); |
| 69 |
if ( ! $is_post_edit ) { |
| 70 |
$is_wc_admin = true; |
| 71 |
} |
| 72 |
} elseif ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { |
| 73 |
$uri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : ''; |
| 74 |
$is_wc_rest = ( strpos( $uri, 'wp-json/wc/' ) !== false || strpos( $uri, 'wp-json/wc-admin/' ) !== false ); |
| 75 |
$is_store_api = ( strpos( $uri, '/store/' ) !== false ); |
| 76 |
if ( $is_wc_rest && ! $is_store_api ) { |
| 77 |
$is_wc_admin = true; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
if ( $is_wc_admin || wp_doing_ajax() ) { |
| 82 |
$methods[] = 'DokuMainModule'; |
| 83 |
} |
| 84 |
|
| 85 |
return $methods; |
| 86 |
} |
| 87 |
} |
| 88 |
$GLOBALS['doku_main_pg'] = DokuMainPg::get_instance(); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
register_activation_hook(__FILE__, 'doku_payment_install_db'); |
| 93 |
add_action('plugins_loaded', 'doku_payment_check_install_db'); |
| 94 |
function doku_payment_check_install_db() |
| 95 |
{ |
| 96 |
if (get_option('doku_db_version') !== '1.0') { |
| 97 |
doku_payment_install_db(); |
| 98 |
} |
| 99 |
} |
| 100 |
function doku_payment_install_db() |
| 101 |
{ |
| 102 |
global $wpdb; |
| 103 |
$doku_payment_db_version = "1.0"; |
| 104 |
$table_name = $wpdb->prefix . "jokuldb"; |
| 105 |
$sql = " |
| 106 |
CREATE TABLE $table_name ( |
| 107 |
trx_id int( 11 ) NOT NULL AUTO_INCREMENT, |
| 108 |
ip_address VARCHAR( 64 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 109 |
process_type VARCHAR( 20 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 110 |
process_datetime DATETIME NULL, |
| 111 |
doku_payment_datetime DATETIME NULL, |
| 112 |
invoice_number VARCHAR(30) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 113 |
amount DECIMAL( 20,2 ) NOT NULL DEFAULT '0', |
| 114 |
notify_type VARCHAR( 1 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 115 |
response_code VARCHAR( 4 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 116 |
status_code VARCHAR( 4 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 117 |
result_msg VARCHAR( 20 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 118 |
reversal INT( 1 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT 0, |
| 119 |
approval_code CHAR( 20 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 120 |
payment_channel VARCHAR( 20 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 121 |
payment_code VARCHAR( 20 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 122 |
bank_issuer VARCHAR( 100 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 123 |
creditcard VARCHAR( 16 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 124 |
words VARCHAR( 200 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 125 |
session_id VARCHAR( 48 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 126 |
verify_id VARCHAR( 30 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 127 |
verify_score INT( 3 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT 0, |
| 128 |
verify_status VARCHAR( 10 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', |
| 129 |
check_status INT( 1 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT 0, |
| 130 |
count_check_status INT( 1 ) COLLATE utf8_unicode_ci NOT NULL DEFAULT 0, |
| 131 |
raw_post_data TEXT COLLATE utf8_unicode_ci, |
| 132 |
message TEXT COLLATE utf8_unicode_ci, |
| 133 |
PRIMARY KEY (trx_id) |
| 134 |
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 |
| 135 |
|
| 136 |
"; |
| 137 |
|
| 138 |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 139 |
dbDelta($sql); |
| 140 |
|
| 141 |
add_option('doku_db_version', $doku_payment_db_version); |
| 142 |
} |
| 143 |
|
| 144 |
add_action('rest_api_init', function () { |
| 145 |
// Register route for Doku |
| 146 |
register_rest_route('doku', 'notification', array( |
| 147 |
'methods' => 'POST', |
| 148 |
'callback' => function ($request) { |
| 149 |
return doku_payment_order_update_status('doku',$request); |
| 150 |
}, |
| 151 |
'permission_callback' => '__return_true' |
| 152 |
)); |
| 153 |
}); |
| 154 |
|
| 155 |
function doku_payment_order_update_status($path,$request) |
| 156 |
{ |
| 157 |
$notificationService = new DokuNotificationService(); |
| 158 |
$response = $notificationService->getNotification($path,$request); |
| 159 |
return $response; |
| 160 |
} |
| 161 |
|
| 162 |
add_action('rest_api_init', 'doku_payment_qris_register_route'); |
| 163 |
function doku_payment_qris_register_route() |
| 164 |
{ |
| 165 |
register_rest_route('doku', 'qrisnotification', array( |
| 166 |
'methods' => 'POST', |
| 167 |
'callback' => function ($request) { |
| 168 |
return doku_payment_order_update_status_qris('doku',$request); |
| 169 |
}, |
| 170 |
'permission_callback' => '__return_true' |
| 171 |
)); |
| 172 |
} |
| 173 |
|
| 174 |
function doku_payment_order_update_status_qris($path, $request) |
| 175 |
{ |
| 176 |
$qrisNotificationService = new DokuQrisNotificationService(); |
| 177 |
$response = $qrisNotificationService->getQrisNotification($path,$request); |
| 178 |
} |
| 179 |
|
| 180 |
add_action('woocommerce_thankyou', 'doku_payment_thank_you_page_credit_card', 1, 10); |
| 181 |
function doku_payment_thank_you_page_credit_card($order_id) |
| 182 |
{ |
| 183 |
$chosen_payment_method = WC()->session->get('chosen_payment_method'); |
| 184 |
if ($chosen_payment_method == 'jokul_creditcard') { |
| 185 |
global $woocommerce; |
| 186 |
$woocommerce->cart->empty_cart(); |
| 187 |
wc_reduce_stock_levels($order_id); |
| 188 |
update_post_meta(1000, 'jokul_cc_order_id', ''); |
| 189 |
?> |
| 190 |
<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received">Your payment with Credit Card is success!</p> |
| 191 |
<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
| 192 |
<li class="woocommerce-order-overview__cc cc"> |
| 193 |
<?php esc_html_e('Payment Method', 'doku-payment'); ?> |
| 194 |
<strong><?php esc_html_e("Credit Card", 'doku-payment'); ?></strong> |
| 195 |
</li> |
| 196 |
</ul> |
| 197 |
<?php |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
add_action('before_woocommerce_init', 'doku_payment_declare_cart_checkout_blocks_compatibility'); |
| 203 |
function doku_payment_declare_cart_checkout_blocks_compatibility() { |
| 204 |
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) { |
| 205 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
add_action('woocommerce_blocks_loaded', 'doku_payment_register_payment_method_type'); |
| 210 |
function doku_payment_register_payment_method_type() { |
| 211 |
if (!class_exists('Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType')) { |
| 212 |
return; |
| 213 |
} |
| 214 |
|
| 215 |
require_once plugin_dir_path(__FILE__) . 'Block/DokuCheckoutBlock.php'; |
| 216 |
|
| 217 |
add_action('woocommerce_blocks_payment_method_type_registration', |
| 218 |
function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) { |
| 219 |
$payment_method_registry->register(new Doku_Checkout_Blocks); |
| 220 |
}); |
| 221 |
} |
| 222 |
|
| 223 |
add_filter('woocommerce_locate_template', 'doku_payment_plugin_template', 1, 3); |
| 224 |
function doku_payment_plugin_template($template, $template_name, $template_path) |
| 225 |
{ |
| 226 |
global $woocommerce; |
| 227 |
$_template = $template; |
| 228 |
if (!$template_path) |
| 229 |
$template_path = $woocommerce->template_url; |
| 230 |
|
| 231 |
$plugin_path = untrailingslashit(plugin_dir_path(__FILE__)) . '/templates/'; |
| 232 |
|
| 233 |
// Look within passed path within the theme - this is priority |
| 234 |
$template = locate_template( |
| 235 |
array( |
| 236 |
$template_path . $template_name, |
| 237 |
$template_name |
| 238 |
) |
| 239 |
); |
| 240 |
|
| 241 |
if (!$template && file_exists($plugin_path . $template_name)) { |
| 242 |
$template = $plugin_path . $template_name; |
| 243 |
} |
| 244 |
|
| 245 |
if (!$template) { |
| 246 |
$template = $_template; |
| 247 |
} |
| 248 |
|
| 249 |
return $template; |
| 250 |
} |
| 251 |
|