mirror of
https://github.com/invite-frey/is-woo-payment-fps.git
synced 2025-04-06 22:30:42 +00:00
Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
0f6af16e2d | ||
|
b0d9f87a5c | ||
|
488336bce4 | ||
|
114d068585 | ||
|
f3a0b6de96 | ||
|
25db807a1d | ||
|
4b60d7f9ed | ||
|
3722338708 | ||
|
3bb1d92138 | ||
|
ad3937dbce | ||
|
b487cdc0c5 | ||
|
14d4d6f931 | ||
|
572b7f3e03 | ||
|
c4c3991890 | ||
|
252795d70e | ||
|
4bf51e1778 | ||
|
102b41354d | ||
|
544529348a | ||
|
7651a99563 | ||
|
2c589eda57 | ||
|
bcd53e59ed | ||
|
334b8dba52 | ||
|
04c8b35ee4 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
._*
|
._*
|
||||||
.fuse_*
|
.fuse_*
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
qrcodes/*.png
|
27
README.md
27
README.md
@ -49,13 +49,34 @@ $ 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: 32AULufQ6AUzq9jKZdcLjSxfePZbsqQKEp
|
Bitcoin, Lightning Network and most major credit cards available for donations at [https://frey.hk](https://frey.hk).
|
||||||
* BTC Lightning via tippin.me: [https://tippin.me/@freyhk](https://tippin.me/@freyhk)
|
|
||||||
* [Other forms of payment](https://frey.hk/#donations)
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @package Hong_Kong_FPS_Woo_Payment
|
* @package Hong_Kong_FPS_Woo_Payment
|
||||||
* @version 1.2
|
* @version 1.44
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
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: Frey Mansikkaniemi, invITe Services
|
Author: invITe Services
|
||||||
Version: 1.2
|
Version: 1.44
|
||||||
Author URI: http://frey.hk/
|
Author URI: http://frey.hk/
|
||||||
License: GPLv3
|
License: GPLv3
|
||||||
*/
|
*/
|
||||||
@ -52,35 +52,6 @@ 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.
|
||||||
@ -88,7 +59,7 @@ function its_wpf_qrcode_catch()
|
|||||||
|
|
||||||
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($gateways[ITS_WPF_PLUGIN_ID]) {
|
if(!empty($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;
|
||||||
@ -128,6 +99,3 @@ 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';
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
|
@ -145,5 +145,3 @@ if( !class_exists('ITS_FPS_QRCodeData') ){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
1
qrcodes/readme.txt
Normal file
1
qrcodes/readme.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Dynamically generated qrcodes are saved here
|
23
readme.txt
23
readme.txt
@ -54,3 +54,26 @@ 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
|
@ -24,6 +24,7 @@ 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' ) );
|
||||||
}
|
}
|
||||||
@ -68,12 +69,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 number Hong Kong bank code.',ITS_WPF_PLUGIN_ID)
|
'description' => __('Three digit 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 input the payment reference number below after payment has been completed.',ITS_WPF_PLUGIN_ID),
|
'default' => __('Please use the code below as a Message to Payee when initiating the transaction in your bank\'s app.',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(
|
||||||
@ -86,6 +87,106 @@ 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;
|
||||||
@ -134,6 +235,22 @@ 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;
|
||||||
@ -149,11 +266,7 @@ 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_url = add_query_arg(
|
$qr_code_img = $this->qrcode_img_data($qrcode->getDataString());
|
||||||
'_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 ) );
|
||||||
@ -163,7 +276,7 @@ if( !class_exists('WC_Gateway_Invite_FPS_Payment_Gateway') ){
|
|||||||
|
|
||||||
?>
|
?>
|
||||||
<div class="form-row form-row-wide">
|
<div class="form-row form-row-wide">
|
||||||
FPS id: <strong><?php echo $this->account_fps_id ?></strong>
|
<?php __("FPS id:",ITS_WPF_PLUGIN_ID); ?> <strong><?php echo $this->account_fps_id ?></strong>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
@ -180,7 +293,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 src="<?php echo $qr_code_url?>">
|
<img style="margin: 0 auto;" src="data:image/png;base64,<?php echo base64_encode($qr_code_img); ?>" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@ -229,7 +342,3 @@ if( !class_exists('WC_Gateway_Invite_FPS_Payment_Gateway') ){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user