|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Plugin Name: WooCommerce First Atlantic Commerce Gateway |
|
4
|
|
|
* Plugin URI: https://github.com/Strikewood/woocommerce-first-atlantic-commerce |
|
5
|
|
|
* Description: First Atlantic Commerce gateway extension for WooCommerce. |
|
6
|
|
|
* Version: 0.1.7 |
|
7
|
|
|
* Author: Strikewood Studios |
|
8
|
|
|
* Author URI: http://strikewood.com/ |
|
9
|
|
|
* License: MIT |
|
10
|
|
|
* License URI: https://github.com/Strikewood/woocommerce-first-atlantic-commerce/blob/master/LICENSE |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
if ( !defined('ABSPATH') ) exit; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
function woocommerce_init_fac_gateway() |
|
16
|
|
|
{ |
|
17
|
|
|
// Make sure WooCommerce is available |
|
18
|
|
|
if ( !class_exists('WC_Payment_Gateway') ) return; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
// Localisation |
|
21
|
|
|
load_plugin_textdomain('wc-gateway-fac', false, dirname( plugin_basename(__FILE__) ) . '/languages'); |
|
22
|
|
|
|
|
23
|
|
|
// Our classes and depdencies (if not using composer) |
|
24
|
|
|
if ( is_file( dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php' ) ) require_once('vendor/autoload.php'); |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
// Make sure the FAC class was autoloaded |
|
27
|
|
|
if ( !class_exists('WC_Gateway_FirstAtlanticCommerce') ) return; |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
// Register the gateway in WC |
|
30
|
|
|
function woocommerce_register_fac_gateway($methods) |
|
31
|
|
|
{ |
|
32
|
|
|
$methods[] = 'WC_Gateway_FirstAtlanticCommerce'; |
|
33
|
|
|
|
|
34
|
|
|
return $methods; |
|
35
|
|
|
} |
|
36
|
|
|
add_filter('woocommerce_payment_gateways', 'woocommerce_register_fac_gateway'); |
|
37
|
|
|
|
|
38
|
|
|
function woocommerce_fac_process_payment($order_id) |
|
39
|
|
|
{ |
|
40
|
|
|
$fac = new WC_Gateway_FirstAtlanticCommerce; |
|
41
|
|
|
|
|
42
|
|
|
$fac->process_payment($order_id); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
function woocommerce_fac_process_refund($order_id) |
|
46
|
|
|
{ |
|
47
|
|
|
$fac = new WC_Gateway_FirstAtlanticCommerce; |
|
48
|
|
|
|
|
49
|
|
|
$fac->process_refund($order_id); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
// Actions to capture or void authorized transactions |
|
53
|
|
|
add_action('woocommerce_order_status_on-hold_to_processing', 'woocommerce_fac_process_payment'); |
|
54
|
|
|
add_action('woocommerce_order_status_on-hold_to_completed', 'woocommerce_fac_process_payment'); |
|
55
|
|
|
add_action('woocommerce_order_status_on-hold_to_cancelled', 'woocommerce_fac_process_refund'); |
|
56
|
|
|
add_action('woocommerce_order_status_on-hold_to_refunded', 'woocommerce_fac_process_refund'); |
|
57
|
|
|
} |
|
58
|
|
|
add_action('plugins_loaded', 'woocommerce_init_fac_gateway', 0); |
|
59
|
|
|
|
Adding braces to control structures avoids accidental mistakes as your code changes: