is-woo-payment-fps/is-woo-payment-fps.php
Frey Mansikkaniemi dc2a69cdd1 License updated
2020-07-26 13:01:53 +08:00

134 lines
3.1 KiB
PHP

<?php
/**
* @package Woo_Payment_FPS
* @version 1.0
*/
/*
Plugin Name: Woo Payment FPS
Plugin URI: http://invite.hk/
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
Version: 1.0
Author URI: http://frey.hk/
License: GPLv3
*/
if (!defined('ABSPATH')) {
return;
}
/**
* Check if WooCommerce is active
**/
if (
!in_array(
'woocommerce/woocommerce.php',
apply_filters('active_plugins', get_option('active_plugins'))
)
) {
add_action('admin_notices', function () {
?>
<div class="error notice">
<strong><?php __('Woo Payment FPS requires WooCommerce to be installed & activated.',ITS_WPF_PLUGIN_ID)?></strong>
</div>
<?php
});
return;
}
define('ITS_WPF_PLUGIN_ID','its_wpf_payment_gateway');
/**
* Register payment gateway class
*/
add_filter( 'woocommerce_payment_gateways', 'its_wpf_add_class' );
function its_wpf_add_class( $methods ){
$methods[] = 'WC_Gateway_Invite_FPS_Payment_Gateway';
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 ) )
{
ob_clean(); //Clean the output buffer before printing out image
require_once('libs/phpqrcode.php');
header('Content-Type: image/png');
QRcode::png($qrcode_string);
exit();
}
}
/**
* Change text on the Pay order button.
*/
add_filter('woocommerce_available_payment_gateways', 'its_wpf_pay_order_label');
function its_wpf_pay_order_label($gateways) {
if($gateways[ITS_WPF_PLUGIN_ID]) {
$gateways[ITS_WPF_PLUGIN_ID]->order_button_text = __('Confirm FPS Payment Completed',ITS_WPF_PLUGIN_ID);
}
return $gateways;
}
/**
* Change text on the Thank You page.
*/
add_filter('woocommerce_thankyou_' . ITS_WPF_PLUGIN_ID, 'its_wpf_thankyou', 10, 1);
function its_wpf_thankyou($order_id){
global $woocommerce;
$order = wc_get_order( $order_id );
echo '<p>';
echo __('Your payment will be confirmed manually.',ITS_WPF_PLUGIN_ID);
echo '</p><p>';
echo __('FPS Transaction Reference: ',ITS_WPF_PLUGIN_ID) . $order->get_transaction_id();
}
/**
* Load payment gateway class
*/
add_action( 'plugins_loaded', 'its_wpf_init_gateway' );
function its_wpf_init_gateway(){
require_once 'wc-gateway-invite-fps-payment-gateway-class.php';
}
/**
* Load class that generates qrcode data.
*/
add_action('init', 'its_wpf_init_fps_qrcode_class');
function its_wpf_init_fps_qrcode_class(){
require_once 'its-fps-qrcodedata-class.php';
}
?>