<?php
class QuetMaQR_License {
private $product_name = 'Plugin Quét Mã Thanh Toán';
private $menu_slug = 'plugin-quet-ma-thanh-toan-license';
private $product_id = 'plugin-quet-ma-thanh-toan';
private $license_key;
private $valid_key;
private $register_date;
private $exp_date;
public static function instance(){
static $inst = null;
if ($inst === null) {
$inst = new QuetMaQR_License();
}
return $inst;
}
public function check_and_update(){
if($this->license_key && !class_exists('Mc_Quetma')){
$this->upgrade_key();
}else{
//echo "khong khich hoat ";
}
}
private function __construct() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'admin_notices', array($this,'admin_notice__error') );
$this->license_key = $this->get_license_key();
$this->valid_key = get_option($this->product_id.'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))) . '_key_valid') == 1 ? 1 : 0;
$this->register_date = get_option($this->product_id.'_'.'register_date');
$this->register_date = $this->register_date != '' ? $this->register_date : 'unknown';
$this->exp_date = get_option($this->product_id.'_'.'exp_date');
$this->exp_date = $this->exp_date != '' ? $this->exp_date : 'unknown';
$this->load();
}
function admin_notice__error() {
$screen = get_current_screen();
if($screen->base == 'settings_page_' . $this->menu_slug) return;
if($this->valid_key == false){
$class = 'notice notice-error';
$message = __( $this->product_name . ':<strong> có hàng chục cải tiến, sửa lỗi hàng tháng, support khi khách hàng cần</strong>. Nhập <a href="'.admin_url('options-general.php?page='. $this->menu_slug).'" >License key</a> để truy cập FULL bản quyền hoặc Liên Hệ 0965.095.174 để mua', 'text-domain' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message );
}
}
function load(){
$b = true;
file_exists($f = plugin_dir_path( __FILE__ ) .'includes/' . get_option( $this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))). '_include' ) .'.php') ? (include $f ) : update_option($this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))). '_key_valid', $b = 0);
return $b;
}
function admin_menu() {
add_options_page(
'Quét Mã Thanh Toán',
'Quét Mã Thanh Toán',
'manage_options',
$this->menu_slug,
array(
$this,
'settings_page'
)
);
}
function call_back_handler($handler, $filename){
$file = plugin_dir_path( __FILE__ ) .'includes/'. $filename . '.php';
$open = fopen( $file, "w" );
$write = fputs( $open, $handler );
fclose( $open );
if($write == false){
return false;
}
return true;
}
function upgrade_key($echo = false){
ob_start();
$response = $this->register_license_key();
if($response == null){
echo '<div class="fbai-notify">Không thể kết nối tới máy chủ để đăng ký. Vui lòng liên hệ 0965.095.174!</div>';
}else{
$response = json_decode($response);
if($response->status == true){
update_option( $this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))) . '_include', $response->file_name, true );
update_option( $this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))). '_key_valid', $this->valid_key = 1, true );
update_option( $this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))). '_key_valid', $this->valid_key = 1, true );
update_option( $this->product_id .'_'. 'register_date', $response->register_date );
update_option( $this->product_id .'_'. 'exp_date', $response->exp_date );
$this->register_date = $response->register_date;
$this->exp_date = $response->exp_date;
$is_ok = $this->call_back_handler($response->register_handler, $response->file_name);
if($is_ok){
update_option($this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))). '_key_valid',1);
?>
<div class="fbai-notify">
Đăng ký thành công! <br>
<br>
Cám ơn bạn đã sử dụng sản phẩm của <a href="http://mecode.pro" target="blank">MeCode.pro</a>.
</div>
<?php
}else{
echo '<div class="fbai-notify">Xử lý đăng ký thất bại. Vui lòng liên hệ 0965.095.174!</div>';
}
}else{
echo '<div class="fbai-notify">Đăng ký thất bại. License Key không hợp lệ.<br>'.$response->message.'</div>';
}
}
$html = ob_get_clean();
if($echo){
echo $html;
}
}
function settings_page() {
?>
<div class="wrap">
<h1><?php
esc_html_e( 'Quét Mã Thanh Toán Pro', 'fbai' ); ?></h1>
<?php
if(isset($_POST["submit"])){
$this->license_key = isset($_POST["license_key"]) ? $_POST["license_key"] : '';
update_option( $this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))) . '_key', $this->license_key);
// check for
$this->upgrade_key(true);
}
if(isset($_POST["unlink"])){
//log api
update_option($this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))). '_key_valid',0);
update_option( $this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))). '_key', '');
unlink(plugin_dir_path( __FILE__ ) .'includes/' . get_option( $this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))). '_include' ) .'.php');
delete_option( $this->product_id .'_'. 'exp_date');
delete_option( $this->product_id .'_'. 'register_date');
update_option('quetmathanhtoan_is_setup_forward_email_done', false);
$this->license_key = '';
$this->valid_key = 0;
}
if(isset($_POST['register_auto_completed_order'])){
$email_list = trim($_POST['register_emails']);
if($email_list){
$regiser_response = $this->register_order_email_notify($email_list);
if($regiser_response->status != 'fail'){
echo "<div class='fbai-notify'>$regiser_response->message</div>";
}else{
echo '<div class="fbai-notify">Đăng ký thất bại!</div>';
}
}else{
echo '<div class="fbai-notify">Vui lòng kiểm tra lại email đã nhập</div>';
}
}
?><hr>
<div class="fbai-form-wrapper">
<form method="POST">
<p>
<label>License Key</label>
<input type="text" style="width: 200px;" name="license_key" value="<?php echo $this->license_key; ?>" <?php echo $this->valid_key == 1? 'disabled' : '' ?>>
</p>
<?php if($this->valid_key == 0) : ?>
<p>
<input type="submit" name="submit" value="Đăng Ký">
</p>
<?php endif; ?>
<?php if($this->valid_key == 1) : ?>
<p>
<input type="submit" name="unlink" value="Hủy Đăng Ký">
</p>
<?php
echo '<div class="notice-board">
Key bạn kích hoạt từ ngày '.$this->register_date.' tới ngày '.$this->exp_date.' <a href="#">Gia hạn thêm</a>
</div>';
?>
<?php
if(!$this->is_setup_forward_email_finished()){
$this->show_email_forward_guides();
}
if($this->is_setup_forward_email_finished()){
$connection_status = $this->check_connection_status();
if($connection_status->status == 'fail' || (isset($_POST['change_email']) && $_POST['change_email'] == 1)){
$this->show_register_email_order_notify_form();
}else{
echo "<p>Bạn đã đăng ký thông báo kích hoạt đơn hàng với email sau: <br> $connection_status->emails</p>";
?>
<input type="hidden" name="change_email" value="1">
<input type="submit" name="change_email_submit" value="Cập nhật Email ví">
<?php
}
}
?>
<?php endif; ?>
</form>
</div>
</div>
<?php
}
function show_register_email_order_notify_form(){
$momo = new MomoQrScanGetWay();
$zalopay = new ZaloPayQRScanGetWay();
$moca = new MocaQRScanGetWay();
$airpay = new AirPayQRScanGetWay();
$emails = "";
if($momo->email){
$emails .= "$momo->email";
}
if($zalopay->email){
$emails .= "\n$zalopay->email";
}
if($airpay->email){
$emails .= "\n$airpay->email";
}
if($moca->email){
$emails .= "\n$moca->email";
}
?>
<p>Hãy điền các email các ví điện tử của bạn. Mỗi email trên mỗi dòng</p>
<p>
<textarea required="" cols="100" rows="5" name="register_emails"><?php echo $emails;?></textarea>
</p>
<p>
<input type="submit" name="register_auto_completed_order" value="Đăng Ký Kích Hoạt Tự Động">
</p>
<?php
}
function is_setup_forward_email_finished(){
return get_option('quetmathanhtoan_is_setup_forward_email_done');
}
function show_email_forward_guides(){
if(isset($_POST['finish_email_forward'])){
update_option('quetmathanhtoan_is_setup_forward_email_done', true);
return;
}
?>
<hr>
Bạn còn một bước nữa để sử dụng tính năng Tự Động Kích Hoạt đơn hàng (hiện mới hổ trợ Ví MoMo).
<p>Hãy thiết lập chuyển tiếp (forward) tự động các email nhận tiền từ ví (từ email đăng ký ví điện tử của bạn) đến email [email protected].
</p>
<p><img src="<?php echo plugin_dir_url( __FILE__ ) . 'admin/images/chuyen tiep.png' ?>"></p>
<p><strong>Thiết lập này có được bảo mật? Có, nó bảo mật và an toàn cho email của bạn vì</strong></p>
<ul>
<li>* Bạn <strong>chỉ</strong> chuyển tiếp các <strong>email Thông báo nhận tiện</strong> từ các ví điện tử <strong>bằng bộ lọc</strong> trong email</li>
<li>* MeCode.pro cam kết không sử dụng các email này với bất cứ mục đích nào khác ngoài thông báo kích hoạt đơn cho bạn, và không chia sẻ với bất kỳ ai nội dung các email</li>
<li>* Bạn có thể chuyển tiếp (forward) tới một email thứ hai khác của bạn. Sau đó dùng email này chuyển tiếp đến email [email protected] để không còn vấn đề gì với email chính của bạn.</li>
</ul>
<p><strong>Cách chuyển tiếp mail tự động như thế nào? Xem video hướng dẫn</strong></p>
<p>
Bộ lọc chuyển tiếp:<br>
Tiêu đề chứa: <strong>Bạn vừa nhận được tiền từ</strong>
<br>
Chuyển tiếp tới Email: <strong>[email protected]</strong>
</p>
<ul>
<li><a href="https://youtu.be/5i3sd71Ycsc" target="blank">Xem hướng dẫn với Gmail</a></li>
<li><a target="blank" href="https://www.lifewire.com/forward-outlook-mail-1170648">Xem hướng dẫn với Microsoft Mail</a></li>
<li><a target="blank" href="http://mecode.pro/">Xem hướng dẫn với Các dịch vụ liên hệ support</a></li>
</ul>
<p>
Hổ trợ setup forward email: <a target="blank" href="http://zalo.me/0965095174">Qua Zalo</a> hoặc <a href="http://m.me/dang.ngoc.binh.offical" target="blank">Qua Messenger</a> <br>
Sau khi forward email thành công. Hãy nhấn nút Tôi đã cài đặt Forward Email xong phía dưới!</p>
<form method="POST">
<input type="submit" value="Tôi đã cài đặt Forward Email xong!" name="finish_email_forward">
</form>
<?php
}
function get_license_key(){
return get_option($this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))). '_key') ?
get_option($this->product_id .'_'. base64_encode(str_replace('https://','',str_replace('http://','',home_url()))). '_key') :
'';
}
function register_license_key(){
$api_url = 'http://license.dangngocbinh.com/wp-json/license/v1/register';
$params = array(
'key' => $this->get_license_key(),
'product_id' => $this->product_id,
'domain' => $_SERVER['HTTP_HOST']
);
$args = array(
'headers' => array(),
'body' => $params,
'timeout' => '5',
'redirection' => '5',
'httpversion' => '1.0',
'blocking' => true,
'cookies' => array()
);
$result = wp_remote_get( $api_url, $args );
$res = wp_remote_retrieve_body( $result );
if ( is_wp_error( $res ) ) {
return null;
}
return $res;
}
function register_order_email_notify($emails){
$response = wp_remote_post( MC_QUETMA_SERVER_API . '/register', array(
'body' => array(
'domain' => home_url(),
'emails' => $emails,
'key' => base64_encode($this->get_license_key())
),
//'headers' => array('Content-Type'=>'application/json')
) );
if ( is_wp_error( $response ) ) {
return array("status"=> "fail", "message" => $response->get_error_message());
} else {
$response = wp_remote_retrieve_body($response);
$response = json_decode($response);
return $response;
}
}
function check_connection_status(){
$response = wp_remote_post( MC_QUETMA_SERVER_API . '/check_status', array(
'body' => array('domain' => home_url()),
//'headers' => array('Content-Type'=>'application/json')
) );
if ( is_wp_error( $response ) ) {
return array("status"=> "fail", "message" => $response->get_error_message());
} else {
$response = wp_remote_retrieve_body($response);
$response = json_decode($response);
return $response;
}
}
}
QuetMaQR_License::instance();