Compare commits

..

No commits in common. "master" and "v1.2" have entirely different histories.
master ... v1.2

7 changed files with 58 additions and 179 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
._* ._*
.fuse_* .fuse_*
.DS_Store .DS_Store
qrcodes/*.png

View File

@ -49,34 +49,13 @@ $ git clone https://github.com/invite-frey/is-woo-payment-fps.git
### 1.2 ### 1.2
* Invalid QR Code problems fixed * Invalid QR Code problems fixed
### 1.3
* Output QR Code at a higher priority during WP startup
* Form validation for the Payment Gateway settings
### 1.31
* Bug fixes
### 1.4
* Optional QRCode caching added
### 1.41
* Bugfix
### 1.42
* QRCodes always cached to disk due to browser incompatibility issues with dynamic generation.
* Fixed bug preventing headers to be output on some systems
### 1.43
* Minor bug fixes
### 1.44
* base64 encoded png qrcode
## Donations ## Donations
Donations are much appreciated if you found this resource useful. Donations are much appreciated if you found this resource useful.
Bitcoin, Lightning Network and most major credit cards available for donations at [https://frey.hk](https://frey.hk). * Bitcoin: 32AULufQ6AUzq9jKZdcLjSxfePZbsqQKEp
* BTC Lightning via tippin.me: [https://tippin.me/@freyhk](https://tippin.me/@freyhk)
* [Other forms of payment](https://frey.hk/#donations)
## License ## License

View File

@ -1,14 +1,14 @@
<?php <?php
/** /**
* @package Hong_Kong_FPS_Woo_Payment * @package Hong_Kong_FPS_Woo_Payment
* @version 1.44 * @version 1.2
*/ */
/* /*
Plugin Name: Hong Kong FPS Woo Payment Plugin Name: Hong Kong FPS Woo Payment
Plugin URI: https://github.com/invite-frey/is-woo-payment-fps Plugin URI: https://github.com/invite-frey/is-woo-payment-fps
Description: Woocommerce payment method enabling Hong Kong FPS payments. Displays QR code and FPS payent if to user. Requires manual confirmation. Description: Woocommerce payment method enabling Hong Kong FPS payments. Displays QR code and FPS payent if to user. Requires manual confirmation.
Author: invITe Services Author: Frey Mansikkaniemi, invITe Services
Version: 1.44 Version: 1.2
Author URI: http://frey.hk/ Author URI: http://frey.hk/
License: GPLv3 License: GPLv3
*/ */
@ -52,6 +52,35 @@ function its_wpf_add_class( $methods ){
return $methods; return $methods;
} }
/**
* Reqister query var for qrcode image generation
*/
add_filter( 'query_vars', 'its_wpf_qrcode_add_var' );
function its_wpf_qrcode_add_var( $vars )
{
$vars[] = 'generate_fps_qrcode';
return $vars;
}
/**
* Print out qr code when the right query var is found
*/
add_action( 'template_redirect', 'its_wpf_qrcode_catch', 5 );
function its_wpf_qrcode_catch()
{
$qrcode_string = get_query_var( 'generate_fps_qrcode' );
$nonce = $_REQUEST['_wpnonce'];
if( $qrcode_string && $nonce && wp_verify_nonce( $nonce, ITS_WPF_PLUGIN_ID ) )
{
require_once('libs/phpqrcode.php');
ob_clean(); //Clean the output buffer before printing out image
header('Content-Type: image/png');
QRcode::png($qrcode_string,false,QR_ECLEVEL_H);
exit();
}
}
/** /**
* Change text on the Pay order button. * Change text on the Pay order button.
@ -59,7 +88,7 @@ function its_wpf_add_class( $methods ){
add_filter('woocommerce_available_payment_gateways', 'its_wpf_pay_order_label'); add_filter('woocommerce_available_payment_gateways', 'its_wpf_pay_order_label');
function its_wpf_pay_order_label($gateways) { function its_wpf_pay_order_label($gateways) {
if(!empty($gateways[ITS_WPF_PLUGIN_ID])) { if($gateways[ITS_WPF_PLUGIN_ID]) {
$gateways[ITS_WPF_PLUGIN_ID]->order_button_text = __('Confirm FPS Payment Completed',ITS_WPF_PLUGIN_ID); $gateways[ITS_WPF_PLUGIN_ID]->order_button_text = __('Confirm FPS Payment Completed',ITS_WPF_PLUGIN_ID);
} }
return $gateways; return $gateways;
@ -99,3 +128,6 @@ add_action('init', 'its_wpf_init_fps_qrcode_class');
function its_wpf_init_fps_qrcode_class(){ function its_wpf_init_fps_qrcode_class(){
require_once 'its-fps-qrcodedata-class.php'; require_once 'its-fps-qrcodedata-class.php';
} }
?>

View File

@ -145,3 +145,5 @@ if( !class_exists('ITS_FPS_QRCodeData') ){
} }
} }
} }
?>

View File

@ -1 +0,0 @@
Dynamically generated qrcodes are saved here

View File

@ -54,26 +54,3 @@ Enables [FPS](https://www.hkma.gov.hk/eng/key-functions/international-financial-
= 1.2 = = 1.2 =
* Invalid QR code problems fixed * Invalid QR code problems fixed
= 1.3 =
* Output QR Code at a higher priority during WP startup
* Form validation for the Payment Gateway settings
= 1.31 =
* Bug fixes
= 1.4 =
* Optional QRCode caching added
= 1.41 =
* Bugfix
= 1.42 =
* QRCodes always cached to disk due to browser incompatibility issues with dynamic generation.
* Fixed bug preventing headers to be output on some systems
= 1.43 =
* Minor bugfixes
= 1.44 =
* base64 encoded png qrcode

View File

@ -24,7 +24,6 @@ if( !class_exists('WC_Gateway_Invite_FPS_Payment_Gateway') ){
$this->account_bank_code = $this->get_option( 'account_bank_code' ); $this->account_bank_code = $this->get_option( 'account_bank_code' );
$this->ask_to_pay = $this->get_option( 'ask_to_pay' ); $this->ask_to_pay = $this->get_option( 'ask_to_pay' );
$this->fps_payment_reference_guide = $this->get_option( 'fps_payment_reference_guide' ); $this->fps_payment_reference_guide = $this->get_option( 'fps_payment_reference_guide' );
$this->write_qr_code_to_file = $this->get_option('write_qr_code_to_file');
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
} }
@ -69,12 +68,12 @@ if( !class_exists('WC_Gateway_Invite_FPS_Payment_Gateway') ){
'account_bank_code' => array( 'account_bank_code' => array(
'title' => __('Bank Code',ITS_WPF_PLUGIN_ID), 'title' => __('Bank Code',ITS_WPF_PLUGIN_ID),
'type' => 'text', 'type' => 'text',
'description' => __('Three digit Hong Kong bank code.',ITS_WPF_PLUGIN_ID) 'description' => __('Three number Hong Kong bank code.',ITS_WPF_PLUGIN_ID)
), ),
'fps_payment_reference_guide' => array( 'fps_payment_reference_guide' => array(
'title' => __('Payment Reference Guide',ITS_WPF_PLUGIN_ID), 'title' => __('Payment Reference Guide',ITS_WPF_PLUGIN_ID),
'type' => 'textarea', 'type' => 'textarea',
'default' => __('Please use the code below as a Message to Payee when initiating the transaction in your bank\'s app.',ITS_WPF_PLUGIN_ID), 'default' => __('Please input the payment reference number below after payment has been completed.',ITS_WPF_PLUGIN_ID),
'description' => __('Instructions visible to the customer for providing payment reference number after payment. This is not visble of Ask to Pay is active.',ITS_WPF_PLUGIN_ID) 'description' => __('Instructions visible to the customer for providing payment reference number after payment. This is not visble of Ask to Pay is active.',ITS_WPF_PLUGIN_ID)
), ),
'ask_to_pay' => array( 'ask_to_pay' => array(
@ -87,106 +86,6 @@ if( !class_exists('WC_Gateway_Invite_FPS_Payment_Gateway') ){
); );
} }
public function validate_text_field($key, $value){
switch($key){
case 'account_fps_id':
$fps_id = trim($value);
switch($this->get_option( 'account_id_type' )){
case '03':
if( preg_match('/^\+852\-[0-9]{8}$/', $fps_id) ){
return $fps_id;
}else{
function my_error_notice() {
?>
<div class="error notice">
<p><?php _e( 'The account id must be a HK phone number formatted: +852-xxxxxxxx.', ITS_WPF_PLUGIN_ID ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'my_error_notice' );
function alert_border_account_id(){
?>
<script language="javascript">
document.querySelector('#woocommerce_its_wpf_payment_gateway_account_fps_id').style.borderColor = 'red';
</script>
<?php
}
add_action( 'admin_footer', 'alert_border_account_id');
return $this->account_fps_id;
}
break;
case '04':
if( preg_match('/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/', $fps_id)){
return $fps_id;
}else{
function my_error_notice() {
?>
<div class="error notice">
<p><?php _e( 'The account id must be a valid e-mail address', ITS_WPF_PLUGIN_ID ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'my_error_notice' );
function alert_border_account_id(){
?>
<script language="javascript">
document.querySelector('#woocommerce_its_wpf_payment_gateway_account_fps_id').style.borderColor = 'red';
</script>
<?php
}
add_action( 'admin_footer', 'alert_border_account_id');
return $this->account_fps_id;
}
break;
default:
return parent::validate_text_field($key,$value);
break;
}
break;
case 'account_bank_code':
$account = trim($value);
if( preg_match('/^[0-9]{3}$/', $account) ){
return $account;
}else{
function my_error_notice() {
?>
<div class="error notice">
<p><?php _e( 'The bank code must consist of three digits, including leading zeros.', ITS_WPF_PLUGIN_ID ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'my_error_notice' );
function alert_border_bank_code(){
?>
<script language="javascript">
document.querySelector('#woocommerce_its_wpf_payment_gateway_account_bank_code').style.borderColor = 'red';
</script>
<?php
}
add_action( 'admin_footer', 'alert_border_bank_code');
return $this->account_bank_code;
}
break;
default:
return parent::validate_text_field($key,$value);
break;
}
}
private function fps_data($reference){ private function fps_data($reference){
global $woocommerce; global $woocommerce;
@ -235,22 +134,6 @@ if( !class_exists('WC_Gateway_Invite_FPS_Payment_Gateway') ){
return $url; return $url;
} }
private function qrcode_img_data($data_string){
/**
* Load the PHP QRcode library
*/
if( !class_exists( 'QRtools' ) ){
require_once 'libs/phpqrcode.php';
}
$fp = fopen('php://memory','r+');
QRCode::png($data_string,$fp,QR_ECLEVEL_H);
rewind($fp);
$qrcode = stream_get_contents($fp);
return $qrcode;
}
public function payment_fields() { public function payment_fields() {
global $wp; global $wp;
@ -266,7 +149,11 @@ if( !class_exists('WC_Gateway_Invite_FPS_Payment_Gateway') ){
$fps_data['currency'] = $fps_data['curr']; $fps_data['currency'] = $fps_data['curr'];
$qrcode = new ITS_FPS_QRCodeData($fps_data); $qrcode = new ITS_FPS_QRCodeData($fps_data);
$qr_code_img = $this->qrcode_img_data($qrcode->getDataString()); $qr_code_url = add_query_arg(
'_wpnonce',
wp_create_nonce(ITS_WPF_PLUGIN_ID),
get_site_url() . '/?generate_fps_qrcode=' . urlencode($qrcode->getDataString())
);
if ( $this->description ) { if ( $this->description ) {
echo wpautop( wp_kses_post( $this->description ) ); echo wpautop( wp_kses_post( $this->description ) );
@ -276,7 +163,7 @@ if( !class_exists('WC_Gateway_Invite_FPS_Payment_Gateway') ){
?> ?>
<div class="form-row form-row-wide"> <div class="form-row form-row-wide">
<?php __("FPS id:",ITS_WPF_PLUGIN_ID); ?> <strong><?php echo $this->account_fps_id ?></strong> FPS id: <strong><?php echo $this->account_fps_id ?></strong>
</div> </div>
<?php <?php
@ -293,7 +180,7 @@ if( !class_exists('WC_Gateway_Invite_FPS_Payment_Gateway') ){
} }
?> ?>
<div class="form-row form-row-wide" style="text-align: center;"> <div class="form-row form-row-wide" style="text-align: center;">
<img style="margin: 0 auto;" src="data:image/png;base64,<?php echo base64_encode($qr_code_img); ?>" /> <img src="<?php echo $qr_code_url?>">
</div> </div>
@ -342,3 +229,7 @@ if( !class_exists('WC_Gateway_Invite_FPS_Payment_Gateway') ){
} }
} }
} }
?>