@@ -10,49 +10,49 @@ |
||
10 | 10 | * License URI: https://github.com/Strikewood/woocommerce-first-atlantic-commerce/blob/master/LICENSE |
11 | 11 | */ |
12 | 12 | |
13 | -if ( !defined('ABSPATH') ) exit; |
|
13 | +if ( !defined( 'ABSPATH' ) ) exit; |
|
14 | 14 | |
15 | 15 | function woocommerce_init_fac_gateway() |
16 | 16 | { |
17 | 17 | // Make sure WooCommerce is available |
18 | - if ( !class_exists('WC_Payment_Gateway') ) return; |
|
18 | + if ( !class_exists( 'WC_Payment_Gateway' ) ) return; |
|
19 | 19 | |
20 | 20 | // Localisation |
21 | - load_plugin_textdomain('wc-gateway-fac', false, dirname( plugin_basename(__FILE__) ) . '/languages'); |
|
21 | + load_plugin_textdomain( 'wc-gateway-fac', false, dirname( plugin_basename( __FILE__ ) ).'/languages' ); |
|
22 | 22 | |
23 | 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'); |
|
24 | + if ( is_file( dirname( __FILE__ ).DIRECTORY_SEPARATOR.'vendor/autoload.php' ) ) require_once('vendor/autoload.php'); |
|
25 | 25 | |
26 | 26 | // Make sure the FAC class was autoloaded |
27 | - if ( !class_exists('WC_Gateway_FirstAtlanticCommerce') ) return; |
|
27 | + if ( !class_exists( 'WC_Gateway_FirstAtlanticCommerce' ) ) return; |
|
28 | 28 | |
29 | 29 | // Register the gateway in WC |
30 | - function woocommerce_register_fac_gateway($methods) |
|
30 | + function woocommerce_register_fac_gateway( $methods ) |
|
31 | 31 | { |
32 | 32 | $methods[] = 'WC_Gateway_FirstAtlanticCommerce'; |
33 | 33 | |
34 | 34 | return $methods; |
35 | 35 | } |
36 | - add_filter('woocommerce_payment_gateways', 'woocommerce_register_fac_gateway'); |
|
36 | + add_filter( 'woocommerce_payment_gateways', 'woocommerce_register_fac_gateway' ); |
|
37 | 37 | |
38 | - function woocommerce_fac_process_payment($order_id) |
|
38 | + function woocommerce_fac_process_payment( $order_id ) |
|
39 | 39 | { |
40 | 40 | $fac = new WC_Gateway_FirstAtlanticCommerce; |
41 | 41 | |
42 | - $fac->process_payment($order_id); |
|
42 | + $fac->process_payment( $order_id ); |
|
43 | 43 | } |
44 | 44 | |
45 | - function woocommerce_fac_process_refund($order_id) |
|
45 | + function woocommerce_fac_process_refund( $order_id ) |
|
46 | 46 | { |
47 | 47 | $fac = new WC_Gateway_FirstAtlanticCommerce; |
48 | 48 | |
49 | - $fac->process_refund($order_id); |
|
49 | + $fac->process_refund( $order_id ); |
|
50 | 50 | } |
51 | 51 | |
52 | 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'); |
|
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 | 57 | } |
58 | -add_action('plugins_loaded', 'woocommerce_init_fac_gateway', 0); |
|
58 | +add_action( 'plugins_loaded', 'woocommerce_init_fac_gateway', 0 ); |
@@ -10,40 +10,44 @@ |
||
10 | 10 | * License URI: https://github.com/Strikewood/woocommerce-first-atlantic-commerce/blob/master/LICENSE |
11 | 11 | */ |
12 | 12 | |
13 | -if ( !defined('ABSPATH') ) exit; |
|
13 | +if ( !defined('ABSPATH') ) { |
|
14 | + exit; |
|
15 | +} |
|
14 | 16 | |
15 | -function woocommerce_init_fac_gateway() |
|
16 | -{ |
|
17 | +function woocommerce_init_fac_gateway() { |
|
17 | 18 | // Make sure WooCommerce is available |
18 | - if ( !class_exists('WC_Payment_Gateway') ) return; |
|
19 | + if ( !class_exists('WC_Payment_Gateway') ) { |
|
20 | + return; |
|
21 | + } |
|
19 | 22 | |
20 | 23 | // Localisation |
21 | 24 | load_plugin_textdomain('wc-gateway-fac', false, dirname( plugin_basename(__FILE__) ) . '/languages'); |
22 | 25 | |
23 | 26 | // Our classes and depdencies (if not using composer) |
24 | - if ( is_file( dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php' ) ) require_once('vendor/autoload.php'); |
|
27 | + if ( is_file( dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php' ) ) { |
|
28 | + require_once('vendor/autoload.php'); |
|
29 | + } |
|
25 | 30 | |
26 | 31 | // Make sure the FAC class was autoloaded |
27 | - if ( !class_exists('WC_Gateway_FirstAtlanticCommerce') ) return; |
|
32 | + if ( !class_exists('WC_Gateway_FirstAtlanticCommerce') ) { |
|
33 | + return; |
|
34 | + } |
|
28 | 35 | |
29 | 36 | // Register the gateway in WC |
30 | - function woocommerce_register_fac_gateway($methods) |
|
31 | - { |
|
37 | + function woocommerce_register_fac_gateway($methods) { |
|
32 | 38 | $methods[] = 'WC_Gateway_FirstAtlanticCommerce'; |
33 | 39 | |
34 | 40 | return $methods; |
35 | 41 | } |
36 | 42 | add_filter('woocommerce_payment_gateways', 'woocommerce_register_fac_gateway'); |
37 | 43 | |
38 | - function woocommerce_fac_process_payment($order_id) |
|
39 | - { |
|
44 | + function woocommerce_fac_process_payment($order_id) { |
|
40 | 45 | $fac = new WC_Gateway_FirstAtlanticCommerce; |
41 | 46 | |
42 | 47 | $fac->process_payment($order_id); |
43 | 48 | } |
44 | 49 | |
45 | - function woocommerce_fac_process_refund($order_id) |
|
46 | - { |
|
50 | + function woocommerce_fac_process_refund($order_id) { |
|
47 | 51 | $fac = new WC_Gateway_FirstAtlanticCommerce; |
48 | 52 | |
49 | 53 | $fac->process_refund($order_id); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use Omnipay\Common\Exception\InvalidResponseException; |
5 | 5 | use Omnipay\Common\Exception\OmnipayException; |
6 | 6 | |
7 | -if ( !defined('ABSPATH') ) exit; |
|
7 | +if ( !defined( 'ABSPATH' ) ) exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * WC_Gateway_FirstAtlanticCommerce class |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | public function __construct() |
20 | 20 | { |
21 | 21 | $this->id = 'fac'; |
22 | - $this->method_title = __('First Atlantic Commerce', 'wc-gateway-fac'); |
|
23 | - $this->method_description = __('First Atlantic Commerce works by adding credit card fields on the checkout and then sending the details to First Atlantic Commerce for verification.', 'wc-gateway-fac'); |
|
22 | + $this->method_title = __( 'First Atlantic Commerce', 'wc-gateway-fac' ); |
|
23 | + $this->method_description = __( 'First Atlantic Commerce works by adding credit card fields on the checkout and then sending the details to First Atlantic Commerce for verification.', 'wc-gateway-fac' ); |
|
24 | 24 | $this->has_fields = true; |
25 | 25 | $this->supports = [ |
26 | 26 | //'subscriptions', |
@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | $this->init_settings(); |
44 | 44 | |
45 | 45 | // User defined settings |
46 | - $this->title = $this->get_option('title'); |
|
47 | - $this->description = $this->get_option('description'); |
|
48 | - $this->enabled = $this->get_option('enabled'); |
|
49 | - $this->testmode = 'yes' === $this->get_option('testmode', 'no'); |
|
50 | - $this->capture = $this->get_option('capture', "yes") === "yes" ? true : false; |
|
46 | + $this->title = $this->get_option( 'title' ); |
|
47 | + $this->description = $this->get_option( 'description' ); |
|
48 | + $this->enabled = $this->get_option( 'enabled' ); |
|
49 | + $this->testmode = 'yes' === $this->get_option( 'testmode', 'no' ); |
|
50 | + $this->capture = $this->get_option( 'capture', "yes" ) === "yes" ? true : false; |
|
51 | 51 | //$this->saved_cards = $this->get_option( 'saved_cards' ) === "yes" ? true : false; |
52 | - $this->merchant_id = $this->testmode ? $this->get_option('test_merchant_id') : $this->get_option('merchant_id'); |
|
53 | - $this->merchant_password = $this->testmode ? $this->get_option('test_merchant_password') : $this->get_option('merchant_password'); |
|
52 | + $this->merchant_id = $this->testmode ? $this->get_option( 'test_merchant_id' ) : $this->get_option( 'merchant_id' ); |
|
53 | + $this->merchant_password = $this->testmode ? $this->get_option( 'test_merchant_password' ) : $this->get_option( 'merchant_password' ); |
|
54 | 54 | |
55 | 55 | // Hooks |
56 | - add_action('admin_notices', [$this, 'admin_notices']); |
|
57 | - add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']); |
|
56 | + add_action( 'admin_notices', [$this, 'admin_notices'] ); |
|
57 | + add_action( 'woocommerce_update_options_payment_gateways_'.$this->id, [$this, 'process_admin_options'] ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -62,26 +62,26 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function admin_notices() |
64 | 64 | { |
65 | - if ($this->enabled == 'no') |
|
65 | + if ( $this->enabled == 'no' ) |
|
66 | 66 | { |
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | 70 | // Check required fields |
71 | - if (!$this->merchant_id) |
|
71 | + if ( !$this->merchant_id ) |
|
72 | 72 | { |
73 | - echo '<div class="error"><p>' . sprintf( __( 'First Atlantic Commerce error: Please enter your merchant id <a href="%s">here</a>', 'woocommerce-gateway-fac' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_fac' ) ) . '</p></div>'; |
|
73 | + echo '<div class="error"><p>'.sprintf( __( 'First Atlantic Commerce error: Please enter your merchant id <a href="%s">here</a>', 'woocommerce-gateway-fac' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_fac' ) ).'</p></div>'; |
|
74 | 74 | return; |
75 | 75 | } |
76 | - elseif (!$this->merchant_password) |
|
76 | + elseif ( !$this->merchant_password ) |
|
77 | 77 | { |
78 | - echo '<div class="error"><p>' . sprintf( __( 'First Atlantic Commerce error: Please enter your merchant password <a href="%s">here</a>', 'woocommerce-gateway-fac' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_fac' ) ) . '</p></div>'; |
|
78 | + echo '<div class="error"><p>'.sprintf( __( 'First Atlantic Commerce error: Please enter your merchant password <a href="%s">here</a>', 'woocommerce-gateway-fac' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_fac' ) ).'</p></div>'; |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
82 | 82 | // Check if enabled and force SSL is disabled |
83 | - if ( get_option('woocommerce_force_ssl_checkout') == 'no' ) { |
|
84 | - echo '<div class="error"><p>' . sprintf( __( 'First Atlantic Commerce is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - First Atlantic Commerce will only work in test mode.', 'woocommerce-gateway-fac' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>'; |
|
83 | + if ( get_option( 'woocommerce_force_ssl_checkout' ) == 'no' ) { |
|
84 | + echo '<div class="error"><p>'.sprintf( __( 'First Atlantic Commerce is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - First Atlantic Commerce will only work in test mode.', 'woocommerce-gateway-fac' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ).'</p></div>'; |
|
85 | 85 | return; |
86 | 86 | } |
87 | 87 | } |
@@ -93,14 +93,14 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return void |
95 | 95 | */ |
96 | - public function log($message) |
|
96 | + public function log( $message ) |
|
97 | 97 | { |
98 | 98 | if ( empty($this->log) ) |
99 | 99 | { |
100 | 100 | $this->log = new WC_Logger(); |
101 | 101 | } |
102 | 102 | |
103 | - $this->log->add($this->id, $message); |
|
103 | + $this->log->add( $this->id, $message ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | $is_available = parent::is_available(); |
114 | 114 | |
115 | 115 | // Only allow unencrypted connections when testing |
116 | - if (!is_ssl() && !$this->testmode) |
|
116 | + if ( !is_ssl() && !$this->testmode ) |
|
117 | 117 | { |
118 | 118 | $is_available = false; |
119 | 119 | } |
120 | 120 | |
121 | 121 | // Required fields check |
122 | - if (!$this->merchant_id || !$this->merchant_password) |
|
122 | + if ( !$this->merchant_id || !$this->merchant_password ) |
|
123 | 123 | { |
124 | 124 | $is_available = false; |
125 | 125 | } |
@@ -132,62 +132,62 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function init_form_fields() |
134 | 134 | { |
135 | - $this->form_fields = apply_filters('wc_fac_settings', [ |
|
135 | + $this->form_fields = apply_filters( 'wc_fac_settings', [ |
|
136 | 136 | 'enabled' => [ |
137 | - 'title' => __('Enable/Disable', 'woocommerce-gateway-fac'), |
|
138 | - 'label' => __('Enable FAC', 'woocommerce-gateway-fac'), |
|
137 | + 'title' => __( 'Enable/Disable', 'woocommerce-gateway-fac' ), |
|
138 | + 'label' => __( 'Enable FAC', 'woocommerce-gateway-fac' ), |
|
139 | 139 | 'type' => 'checkbox', |
140 | 140 | 'description' => '', |
141 | 141 | 'default' => 'no' |
142 | 142 | ], |
143 | 143 | 'title' => [ |
144 | - 'title' => __('Title', 'woocommerce-gateway-fac'), |
|
144 | + 'title' => __( 'Title', 'woocommerce-gateway-fac' ), |
|
145 | 145 | 'type' => 'text', |
146 | - 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-fac'), |
|
147 | - 'default' => __('Credit card', 'woocommerce-gateway-fac') |
|
146 | + 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-fac' ), |
|
147 | + 'default' => __( 'Credit card', 'woocommerce-gateway-fac' ) |
|
148 | 148 | ], |
149 | 149 | 'description' => [ |
150 | - 'title' => __('Description', 'woocommerce-gateway-fac'), |
|
150 | + 'title' => __( 'Description', 'woocommerce-gateway-fac' ), |
|
151 | 151 | 'type' => 'textarea', |
152 | - 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-fac'), |
|
153 | - 'default' => __('Pay with your credit card.', 'woocommerce-gateway-fac') |
|
152 | + 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-fac' ), |
|
153 | + 'default' => __( 'Pay with your credit card.', 'woocommerce-gateway-fac' ) |
|
154 | 154 | ], |
155 | 155 | 'testmode' => [ |
156 | - 'title' => __('Test mode', 'woocommerce-gateway-fac'), |
|
157 | - 'label' => __('Enable Test Mode', 'woocommerce-gateway-fac'), |
|
156 | + 'title' => __( 'Test mode', 'woocommerce-gateway-fac' ), |
|
157 | + 'label' => __( 'Enable Test Mode', 'woocommerce-gateway-fac' ), |
|
158 | 158 | 'type' => 'checkbox', |
159 | - 'description' => __('Place the payment gateway in test mode using test API credentials.', 'woocommerce-gateway-fac'), |
|
159 | + 'description' => __( 'Place the payment gateway in test mode using test API credentials.', 'woocommerce-gateway-fac' ), |
|
160 | 160 | 'default' => 'yes' |
161 | 161 | ], |
162 | 162 | 'merchant_id' => [ |
163 | - 'title' => __('Live Merchant ID', 'woocommerce-gateway-fac'), |
|
163 | + 'title' => __( 'Live Merchant ID', 'woocommerce-gateway-fac' ), |
|
164 | 164 | 'type' => 'text', |
165 | - 'description' => __('Get your API credentials from your merchant account.', 'woocommerce-gateway-fac'), |
|
165 | + 'description' => __( 'Get your API credentials from your merchant account.', 'woocommerce-gateway-fac' ), |
|
166 | 166 | 'default' => '' |
167 | 167 | ], |
168 | 168 | 'merchant_password' => [ |
169 | - 'title' => __('Live Merchant Password', 'woocommerce-gateway-fac'), |
|
169 | + 'title' => __( 'Live Merchant Password', 'woocommerce-gateway-fac' ), |
|
170 | 170 | 'type' => 'text', |
171 | - 'description' => __('Get your API credentials from your merchant account.', 'woocommerce-gateway-fac'), |
|
171 | + 'description' => __( 'Get your API credentials from your merchant account.', 'woocommerce-gateway-fac' ), |
|
172 | 172 | 'default' => '' |
173 | 173 | ], |
174 | 174 | 'test_merchant_id' => [ |
175 | - 'title' => __('Test Merchant ID', 'woocommerce-gateway-fac'), |
|
175 | + 'title' => __( 'Test Merchant ID', 'woocommerce-gateway-fac' ), |
|
176 | 176 | 'type' => 'text', |
177 | - 'description' => __('Get your API credentials from your merchant account.', 'woocommerce-gateway-fac'), |
|
177 | + 'description' => __( 'Get your API credentials from your merchant account.', 'woocommerce-gateway-fac' ), |
|
178 | 178 | 'default' => '' |
179 | 179 | ], |
180 | 180 | 'test_merchant_password' => [ |
181 | - 'title' => __('Test Merchant Password', 'woocommerce-gateway-fac'), |
|
181 | + 'title' => __( 'Test Merchant Password', 'woocommerce-gateway-fac' ), |
|
182 | 182 | 'type' => 'text', |
183 | - 'description' => __('Get your API credentials from your merchant account.', 'woocommerce-gateway-fac'), |
|
183 | + 'description' => __( 'Get your API credentials from your merchant account.', 'woocommerce-gateway-fac' ), |
|
184 | 184 | 'default' => '' |
185 | 185 | ], |
186 | 186 | 'capture' => [ |
187 | - 'title' => __('Capture', 'woocommerce-gateway-fac'), |
|
188 | - 'label' => __('Capture charge immediately', 'woocommerce-gateway-fac'), |
|
187 | + 'title' => __( 'Capture', 'woocommerce-gateway-fac' ), |
|
188 | + 'label' => __( 'Capture charge immediately', 'woocommerce-gateway-fac' ), |
|
189 | 189 | 'type' => 'checkbox', |
190 | - 'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-fac'), |
|
190 | + 'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-fac' ), |
|
191 | 191 | 'default' => 'yes' |
192 | 192 | ]/*, |
193 | 193 | 'saved_cards' => [ |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | 'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on FAC servers, not on your store.', 'woocommerce-gateway-fac'), |
198 | 198 | 'default' => 'no' |
199 | 199 | ]*/ |
200 | - ]); |
|
200 | + ] ); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -205,14 +205,14 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public function setup_gateway() |
207 | 207 | { |
208 | - $gateway = Omnipay::create('FirstAtlanticCommerce'); |
|
208 | + $gateway = Omnipay::create( 'FirstAtlanticCommerce' ); |
|
209 | 209 | |
210 | - $gateway->setMerchantId($this->merchant_id); |
|
211 | - $gateway->setMerchantPassword($this->merchant_password); |
|
210 | + $gateway->setMerchantId( $this->merchant_id ); |
|
211 | + $gateway->setMerchantPassword( $this->merchant_password ); |
|
212 | 212 | |
213 | - if ($this->testmode) |
|
213 | + if ( $this->testmode ) |
|
214 | 214 | { |
215 | - $gateway->setTestMode(true); |
|
215 | + $gateway->setTestMode( true ); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | return $gateway; |
@@ -240,17 +240,17 @@ discard block |
||
240 | 240 | |
241 | 241 | if ( empty($_POST['fac-card-number']) ) |
242 | 242 | { |
243 | - wc_add_notice( $this->get_validation_error( __('Card Number', 'woocommerce-gateway-fac'), $_POST['fac-card-number'] ), 'error' ); |
|
243 | + wc_add_notice( $this->get_validation_error( __( 'Card Number', 'woocommerce-gateway-fac' ), $_POST['fac-card-number'] ), 'error' ); |
|
244 | 244 | $validated = false; |
245 | 245 | } |
246 | 246 | if ( empty($_POST['fac-card-expiry']) ) |
247 | 247 | { |
248 | - wc_add_notice( $this->get_validation_error( __('Card Expiry', 'woocommerce-gateway-fac'), $_POST['fac-card-number'] ), 'error' ); |
|
248 | + wc_add_notice( $this->get_validation_error( __( 'Card Expiry', 'woocommerce-gateway-fac' ), $_POST['fac-card-number'] ), 'error' ); |
|
249 | 249 | $validated = false; |
250 | 250 | } |
251 | 251 | if ( empty($_POST['fac-card-cvc']) ) |
252 | 252 | { |
253 | - wc_add_notice( $this->get_validation_error( __('Card Code', 'woocommerce-gateway-fac'), $_POST['fac-card-number'] ), 'error' ); |
|
253 | + wc_add_notice( $this->get_validation_error( __( 'Card Code', 'woocommerce-gateway-fac' ), $_POST['fac-card-number'] ), 'error' ); |
|
254 | 254 | $validated = false; |
255 | 255 | } |
256 | 256 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @param string $type |
265 | 265 | * @return string |
266 | 266 | */ |
267 | - protected function get_validation_error($field, $type = 'undefined') |
|
267 | + protected function get_validation_error( $field, $type = 'undefined' ) |
|
268 | 268 | { |
269 | 269 | if ( $type === 'invalid' ) |
270 | 270 | { |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @return bool |
285 | 285 | */ |
286 | - public function can_process_order($order) |
|
286 | + public function can_process_order( $order ) |
|
287 | 287 | { |
288 | 288 | return $order && $order->payment_method == 'fac'; |
289 | 289 | } |
@@ -295,17 +295,17 @@ discard block |
||
295 | 295 | * |
296 | 296 | * @return array |
297 | 297 | */ |
298 | - public function process_payment($order_id) |
|
298 | + public function process_payment( $order_id ) |
|
299 | 299 | { |
300 | - $order = new WC_Order($order_id); |
|
300 | + $order = new WC_Order( $order_id ); |
|
301 | 301 | |
302 | - if ( !$this->can_process_order($order) ) return; |
|
302 | + if ( !$this->can_process_order( $order ) ) return; |
|
303 | 303 | |
304 | 304 | $transaction = $order->get_transaction_id(); |
305 | - $captured = get_post_meta($order_id, '_fac_captured', true); |
|
305 | + $captured = get_post_meta( $order_id, '_fac_captured', true ); |
|
306 | 306 | |
307 | 307 | // Skip already captured transactions |
308 | - if ($captured) return; |
|
308 | + if ( $captured ) return; |
|
309 | 309 | |
310 | 310 | try |
311 | 311 | { |
@@ -320,13 +320,13 @@ discard block |
||
320 | 320 | // Already authorized transactions should be captured |
321 | 321 | if ( $transaction && !$captured ) |
322 | 322 | { |
323 | - $response = $gateway->capture($data)->send(); |
|
323 | + $response = $gateway->capture( $data )->send(); |
|
324 | 324 | } |
325 | 325 | else |
326 | 326 | { |
327 | - $card_number = str_replace( [' ', '-'], '', wc_clean($_POST['fac-card-number']) ); |
|
328 | - $card_cvv = wc_clean($_POST['fac-card-cvc']); |
|
329 | - $card_expiry = preg_split('/\s?\/\s?/', wc_clean($_POST['fac-card-expiry']), 2); |
|
327 | + $card_number = str_replace( [' ', '-'], '', wc_clean( $_POST['fac-card-number'] ) ); |
|
328 | + $card_cvv = wc_clean( $_POST['fac-card-cvc'] ); |
|
329 | + $card_expiry = preg_split( '/\s?\/\s?/', wc_clean( $_POST['fac-card-expiry'] ), 2 ); |
|
330 | 330 | |
331 | 331 | $data['card'] = [ |
332 | 332 | 'firstName' => $order->billing_first_name, |
@@ -345,13 +345,13 @@ discard block |
||
345 | 345 | ]; |
346 | 346 | |
347 | 347 | // Capture in one pass if enabled, otherwise authorize |
348 | - if ($this->capture) |
|
348 | + if ( $this->capture ) |
|
349 | 349 | { |
350 | - $response = $gateway->purchase($data)->send(); |
|
350 | + $response = $gateway->purchase( $data )->send(); |
|
351 | 351 | } |
352 | 352 | else |
353 | 353 | { |
354 | - $response = $gateway->authorize($data)->send(); |
|
354 | + $response = $gateway->authorize( $data )->send(); |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
@@ -363,23 +363,23 @@ discard block |
||
363 | 363 | if ( ($transaction && !$captured) || (!$transaction && $this->capture) ) |
364 | 364 | { |
365 | 365 | // Store captured |
366 | - update_post_meta($order_id, '_fac_captured', true); |
|
366 | + update_post_meta( $order_id, '_fac_captured', true ); |
|
367 | 367 | |
368 | 368 | // Complete payment |
369 | - $order->payment_complete($reference); |
|
369 | + $order->payment_complete( $reference ); |
|
370 | 370 | |
371 | 371 | // Add note to order |
372 | - $order->add_order_note( sprintf( __('FAC transaction complete (ID: %s)', 'woocommerce-gateway-fac'), $reference ) ); |
|
372 | + $order->add_order_note( sprintf( __( 'FAC transaction complete (ID: %s)', 'woocommerce-gateway-fac' ), $reference ) ); |
|
373 | 373 | } |
374 | 374 | // Authorized transaction |
375 | 375 | else |
376 | 376 | { |
377 | 377 | // Store captured |
378 | - update_post_meta($order_id, '_transaction_id', $reference, true); |
|
379 | - update_post_meta($order_id, '_fac_captured', false); |
|
378 | + update_post_meta( $order_id, '_transaction_id', $reference, true ); |
|
379 | + update_post_meta( $order_id, '_fac_captured', false ); |
|
380 | 380 | |
381 | 381 | // Mark order as on-hold and add note |
382 | - $order->update_status( 'on-hold', sprintf( __('FAC charge authorized (ID: %s). Process the order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-fac'), $reference ) ); |
|
382 | + $order->update_status( 'on-hold', sprintf( __( 'FAC charge authorized (ID: %s). Process the order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-fac' ), $reference ) ); |
|
383 | 383 | |
384 | 384 | // Reduce stock level |
385 | 385 | $order->reduce_order_stock(); |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | // Return thank you page redirect |
392 | 392 | return [ |
393 | 393 | 'result' => 'success', |
394 | - 'redirect' => $this->get_return_url($order) |
|
394 | + 'redirect' => $this->get_return_url( $order ) |
|
395 | 395 | ]; |
396 | 396 | } |
397 | 397 | else |
@@ -399,28 +399,28 @@ discard block |
||
399 | 399 | throw new InvalidResponseException( $response->getMessage(), $response->getCode() ); |
400 | 400 | } |
401 | 401 | } |
402 | - catch (OmnipayException $e) |
|
402 | + catch ( OmnipayException $e ) |
|
403 | 403 | { |
404 | - $message = 'Transaction Failed: '. $e->getCode() .' – '. $e->getMessage(); |
|
404 | + $message = 'Transaction Failed: '.$e->getCode().' – '.$e->getMessage(); |
|
405 | 405 | |
406 | - $this->log($message); |
|
407 | - $order->add_order_note( __($message, 'woocommerce-gateway-fac') ); |
|
406 | + $this->log( $message ); |
|
407 | + $order->add_order_note( __( $message, 'woocommerce-gateway-fac' ) ); |
|
408 | 408 | |
409 | 409 | // Friendly declined message |
410 | 410 | if ( in_array( $e->getCode(), [2, 3, 4, 35, 38, 39] ) ) |
411 | 411 | { |
412 | - $message = __('Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.', 'woocommerce') .' '. __('Please attempt your purchase again.', 'woocommerce'); |
|
412 | + $message = __( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.', 'woocommerce' ).' '.__( 'Please attempt your purchase again.', 'woocommerce' ); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | // Friendly error message |
416 | 416 | else |
417 | 417 | { |
418 | - $message = __('Unfortunately your order cannot be processed as an error has occured.', 'woocommerce') .' '. __('Please attempt your purchase again.', 'woocommerce'); |
|
418 | + $message = __( 'Unfortunately your order cannot be processed as an error has occured.', 'woocommerce' ).' '.__( 'Please attempt your purchase again.', 'woocommerce' ); |
|
419 | 419 | } |
420 | 420 | |
421 | - if ( !is_admin() || ( defined('DOING_AJAX') && DOING_AJAX ) ) |
|
421 | + if ( !is_admin() || (defined( 'DOING_AJAX' ) && DOING_AJAX) ) |
|
422 | 422 | { |
423 | - wc_add_notice($message, 'error'); |
|
423 | + wc_add_notice( $message, 'error' ); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | return; |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * |
435 | 435 | * @return bool |
436 | 436 | */ |
437 | - public function can_refund_order($order) |
|
437 | + public function can_refund_order( $order ) |
|
438 | 438 | { |
439 | 439 | return $order && $order->payment_method == 'fac' && $order->get_transaction_id(); |
440 | 440 | } |
@@ -447,20 +447,20 @@ discard block |
||
447 | 447 | * |
448 | 448 | * @return bool |
449 | 449 | */ |
450 | - public function process_refund($order_id, $amount = null, $reason = '') |
|
450 | + public function process_refund( $order_id, $amount = null, $reason = '' ) |
|
451 | 451 | { |
452 | - $order = wc_get_order($order_id); |
|
452 | + $order = wc_get_order( $order_id ); |
|
453 | 453 | |
454 | - if ( !$this->can_refund_order($order) ) |
|
454 | + if ( !$this->can_refund_order( $order ) ) |
|
455 | 455 | { |
456 | - $this->log('Refund Failed: No transaction ID for FAC'); |
|
456 | + $this->log( 'Refund Failed: No transaction ID for FAC' ); |
|
457 | 457 | return false; |
458 | 458 | } |
459 | 459 | |
460 | 460 | $transaction = $order->get_transaction_id(); |
461 | - $captured = get_post_meta($order_id, '_fac_captured', true); |
|
461 | + $captured = get_post_meta( $order_id, '_fac_captured', true ); |
|
462 | 462 | |
463 | - if ( is_null($amount) ) |
|
463 | + if ( is_null( $amount ) ) |
|
464 | 464 | { |
465 | 465 | $amount = $order->get_total(); |
466 | 466 | } |
@@ -474,18 +474,18 @@ discard block |
||
474 | 474 | 'amount' => $amount |
475 | 475 | ]; |
476 | 476 | |
477 | - if ($captured) |
|
477 | + if ( $captured ) |
|
478 | 478 | { |
479 | - $response = $gateway->refund($data)->send(); |
|
479 | + $response = $gateway->refund( $data )->send(); |
|
480 | 480 | } |
481 | 481 | else |
482 | 482 | { |
483 | - $response = $gateway->void($data)->send(); |
|
483 | + $response = $gateway->void( $data )->send(); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | if ( $response->isSuccessful() ) |
487 | 487 | { |
488 | - $order->add_order_note( sprintf( __('Refunded %s', 'woocommerce-gateway-fac'), $data['amount'] ) ); |
|
488 | + $order->add_order_note( sprintf( __( 'Refunded %s', 'woocommerce-gateway-fac' ), $data['amount'] ) ); |
|
489 | 489 | return true; |
490 | 490 | } |
491 | 491 | else |
@@ -493,14 +493,14 @@ discard block |
||
493 | 493 | throw new InvalidResponseException( $response->getMessage(), $response->getCode() ); |
494 | 494 | } |
495 | 495 | } |
496 | - catch (OmnipayException $e) |
|
496 | + catch ( OmnipayException $e ) |
|
497 | 497 | { |
498 | - $message = 'Refund Failed: '. $e->getCode() .' – '. $e->getMessage(); |
|
498 | + $message = 'Refund Failed: '.$e->getCode().' – '.$e->getMessage(); |
|
499 | 499 | |
500 | - $this->log($message); |
|
501 | - $order->add_order_note( __($message, 'woocommerce-gateway-fac') ); |
|
500 | + $this->log( $message ); |
|
501 | + $order->add_order_note( __( $message, 'woocommerce-gateway-fac' ) ); |
|
502 | 502 | |
503 | - return new WP_Error( 'fac-refund', __($e->getCode() .' – '.$e->getMessage(), 'woocommerce-gateway-fac') ); |
|
503 | + return new WP_Error( 'fac-refund', __( $e->getCode().' – '.$e->getMessage(), 'woocommerce-gateway-fac' ) ); |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | } |
@@ -4,20 +4,20 @@ discard block |
||
4 | 4 | use Omnipay\Common\Exception\InvalidResponseException; |
5 | 5 | use Omnipay\Common\Exception\OmnipayException; |
6 | 6 | |
7 | -if ( !defined('ABSPATH') ) exit; |
|
7 | +if ( !defined('ABSPATH') ) { |
|
8 | + exit; |
|
9 | +} |
|
8 | 10 | |
9 | 11 | /** |
10 | 12 | * WC_Gateway_FirstAtlanticCommerce class |
11 | 13 | * |
12 | 14 | * @extends WC_Payment_Gateway |
13 | 15 | */ |
14 | -class WC_Gateway_FirstAtlanticCommerce extends WC_Payment_Gateway |
|
15 | -{ |
|
16 | +class WC_Gateway_FirstAtlanticCommerce extends WC_Payment_Gateway { |
|
16 | 17 | /** |
17 | 18 | * Constructor |
18 | 19 | */ |
19 | - public function __construct() |
|
20 | - { |
|
20 | + public function __construct() { |
|
21 | 21 | $this->id = 'fac'; |
22 | 22 | $this->method_title = __('First Atlantic Commerce', 'wc-gateway-fac'); |
23 | 23 | $this->method_description = __('First Atlantic Commerce works by adding credit card fields on the checkout and then sending the details to First Atlantic Commerce for verification.', 'wc-gateway-fac'); |
@@ -60,21 +60,16 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * Notify of issues in wp-admin |
62 | 62 | */ |
63 | - public function admin_notices() |
|
64 | - { |
|
65 | - if ($this->enabled == 'no') |
|
66 | - { |
|
63 | + public function admin_notices() { |
|
64 | + if ($this->enabled == 'no') { |
|
67 | 65 | return; |
68 | 66 | } |
69 | 67 | |
70 | 68 | // Check required fields |
71 | - if (!$this->merchant_id) |
|
72 | - { |
|
69 | + if (!$this->merchant_id) { |
|
73 | 70 | echo '<div class="error"><p>' . sprintf( __( 'First Atlantic Commerce error: Please enter your merchant id <a href="%s">here</a>', 'woocommerce-gateway-fac' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_fac' ) ) . '</p></div>'; |
74 | 71 | return; |
75 | - } |
|
76 | - elseif (!$this->merchant_password) |
|
77 | - { |
|
72 | + } elseif (!$this->merchant_password) { |
|
78 | 73 | echo '<div class="error"><p>' . sprintf( __( 'First Atlantic Commerce error: Please enter your merchant password <a href="%s">here</a>', 'woocommerce-gateway-fac' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_fac' ) ) . '</p></div>'; |
79 | 74 | return; |
80 | 75 | } |
@@ -93,10 +88,8 @@ discard block |
||
93 | 88 | * |
94 | 89 | * @return void |
95 | 90 | */ |
96 | - public function log($message) |
|
97 | - { |
|
98 | - if ( empty($this->log) ) |
|
99 | - { |
|
91 | + public function log($message) { |
|
92 | + if ( empty($this->log) ) { |
|
100 | 93 | $this->log = new WC_Logger(); |
101 | 94 | } |
102 | 95 | |
@@ -108,19 +101,16 @@ discard block |
||
108 | 101 | * |
109 | 102 | * @return bool |
110 | 103 | */ |
111 | - public function is_available() |
|
112 | - { |
|
104 | + public function is_available() { |
|
113 | 105 | $is_available = parent::is_available(); |
114 | 106 | |
115 | 107 | // Only allow unencrypted connections when testing |
116 | - if (!is_ssl() && !$this->testmode) |
|
117 | - { |
|
108 | + if (!is_ssl() && !$this->testmode) { |
|
118 | 109 | $is_available = false; |
119 | 110 | } |
120 | 111 | |
121 | 112 | // Required fields check |
122 | - if (!$this->merchant_id || !$this->merchant_password) |
|
123 | - { |
|
113 | + if (!$this->merchant_id || !$this->merchant_password) { |
|
124 | 114 | $is_available = false; |
125 | 115 | } |
126 | 116 | |
@@ -130,8 +120,7 @@ discard block |
||
130 | 120 | /** |
131 | 121 | * Initialise Gateway Settings Form Fields |
132 | 122 | */ |
133 | - public function init_form_fields() |
|
134 | - { |
|
123 | + public function init_form_fields() { |
|
135 | 124 | $this->form_fields = apply_filters('wc_fac_settings', [ |
136 | 125 | 'enabled' => [ |
137 | 126 | 'title' => __('Enable/Disable', 'woocommerce-gateway-fac'), |
@@ -203,15 +192,13 @@ discard block |
||
203 | 192 | /** |
204 | 193 | * Setup the gateway object |
205 | 194 | */ |
206 | - public function setup_gateway() |
|
207 | - { |
|
195 | + public function setup_gateway() { |
|
208 | 196 | $gateway = Omnipay::create('FirstAtlanticCommerce'); |
209 | 197 | |
210 | 198 | $gateway->setMerchantId($this->merchant_id); |
211 | 199 | $gateway->setMerchantPassword($this->merchant_password); |
212 | 200 | |
213 | - if ($this->testmode) |
|
214 | - { |
|
201 | + if ($this->testmode) { |
|
215 | 202 | $gateway->setTestMode(true); |
216 | 203 | } |
217 | 204 | |
@@ -223,8 +210,7 @@ discard block |
||
223 | 210 | * |
224 | 211 | * @return void |
225 | 212 | */ |
226 | - public function payment_fields() |
|
227 | - { |
|
213 | + public function payment_fields() { |
|
228 | 214 | // Default credit card form |
229 | 215 | $this->credit_card_form(); |
230 | 216 | } |
@@ -234,22 +220,18 @@ discard block |
||
234 | 220 | * |
235 | 221 | * @return bool |
236 | 222 | */ |
237 | - public function validate_fields() |
|
238 | - { |
|
223 | + public function validate_fields() { |
|
239 | 224 | $validated = true; |
240 | 225 | |
241 | - if ( empty($_POST['fac-card-number']) ) |
|
242 | - { |
|
226 | + if ( empty($_POST['fac-card-number']) ) { |
|
243 | 227 | wc_add_notice( $this->get_validation_error( __('Card Number', 'woocommerce-gateway-fac'), $_POST['fac-card-number'] ), 'error' ); |
244 | 228 | $validated = false; |
245 | 229 | } |
246 | - if ( empty($_POST['fac-card-expiry']) ) |
|
247 | - { |
|
230 | + if ( empty($_POST['fac-card-expiry']) ) { |
|
248 | 231 | wc_add_notice( $this->get_validation_error( __('Card Expiry', 'woocommerce-gateway-fac'), $_POST['fac-card-number'] ), 'error' ); |
249 | 232 | $validated = false; |
250 | 233 | } |
251 | - if ( empty($_POST['fac-card-cvc']) ) |
|
252 | - { |
|
234 | + if ( empty($_POST['fac-card-cvc']) ) { |
|
253 | 235 | wc_add_notice( $this->get_validation_error( __('Card Code', 'woocommerce-gateway-fac'), $_POST['fac-card-number'] ), 'error' ); |
254 | 236 | $validated = false; |
255 | 237 | } |
@@ -264,14 +246,10 @@ discard block |
||
264 | 246 | * @param string $type |
265 | 247 | * @return string |
266 | 248 | */ |
267 | - protected function get_validation_error($field, $type = 'undefined') |
|
268 | - { |
|
269 | - if ( $type === 'invalid' ) |
|
270 | - { |
|
249 | + protected function get_validation_error($field, $type = 'undefined') { |
|
250 | + if ( $type === 'invalid' ) { |
|
271 | 251 | return sprintf( __( 'Please enter a valid %s.', 'woocommerce-gateway-fac' ), "<strong>$field</strong>" ); |
272 | - } |
|
273 | - else |
|
274 | - { |
|
252 | + } else { |
|
275 | 253 | return sprintf( __( '%s is a required field.', 'woocommerce-gateway-fac' ), "<strong>$field</strong>" ); |
276 | 254 | } |
277 | 255 | } |
@@ -283,8 +261,7 @@ discard block |
||
283 | 261 | * |
284 | 262 | * @return bool |
285 | 263 | */ |
286 | - public function can_process_order($order) |
|
287 | - { |
|
264 | + public function can_process_order($order) { |
|
288 | 265 | return $order && $order->payment_method == 'fac'; |
289 | 266 | } |
290 | 267 | |
@@ -295,20 +272,22 @@ discard block |
||
295 | 272 | * |
296 | 273 | * @return array |
297 | 274 | */ |
298 | - public function process_payment($order_id) |
|
299 | - { |
|
275 | + public function process_payment($order_id) { |
|
300 | 276 | $order = new WC_Order($order_id); |
301 | 277 | |
302 | - if ( !$this->can_process_order($order) ) return; |
|
278 | + if ( !$this->can_process_order($order) ) { |
|
279 | + return; |
|
280 | + } |
|
303 | 281 | |
304 | 282 | $transaction = $order->get_transaction_id(); |
305 | 283 | $captured = get_post_meta($order_id, '_fac_captured', true); |
306 | 284 | |
307 | 285 | // Skip already captured transactions |
308 | - if ($captured) return; |
|
286 | + if ($captured) { |
|
287 | + return; |
|
288 | + } |
|
309 | 289 | |
310 | - try |
|
311 | - { |
|
290 | + try { |
|
312 | 291 | $gateway = $this->setup_gateway(); |
313 | 292 | |
314 | 293 | $data = [ |
@@ -318,12 +297,9 @@ discard block |
||
318 | 297 | ]; |
319 | 298 | |
320 | 299 | // Already authorized transactions should be captured |
321 | - if ( $transaction && !$captured ) |
|
322 | - { |
|
300 | + if ( $transaction && !$captured ) { |
|
323 | 301 | $response = $gateway->capture($data)->send(); |
324 | - } |
|
325 | - else |
|
326 | - { |
|
302 | + } else { |
|
327 | 303 | $card_number = str_replace( [' ', '-'], '', wc_clean($_POST['fac-card-number']) ); |
328 | 304 | $card_cvv = wc_clean($_POST['fac-card-cvc']); |
329 | 305 | $card_expiry = preg_split('/\s?\/\s?/', wc_clean($_POST['fac-card-expiry']), 2); |
@@ -345,23 +321,18 @@ discard block |
||
345 | 321 | ]; |
346 | 322 | |
347 | 323 | // Capture in one pass if enabled, otherwise authorize |
348 | - if ($this->capture) |
|
349 | - { |
|
324 | + if ($this->capture) { |
|
350 | 325 | $response = $gateway->purchase($data)->send(); |
351 | - } |
|
352 | - else |
|
353 | - { |
|
326 | + } else { |
|
354 | 327 | $response = $gateway->authorize($data)->send(); |
355 | 328 | } |
356 | 329 | } |
357 | 330 | |
358 | - if ( $response->isSuccessful() ) |
|
359 | - { |
|
331 | + if ( $response->isSuccessful() ) { |
|
360 | 332 | $reference = $response->getTransactionReference(); |
361 | 333 | |
362 | 334 | // Captured transaction |
363 | - if ( ($transaction && !$captured) || (!$transaction && $this->capture) ) |
|
364 | - { |
|
335 | + if ( ($transaction && !$captured) || (!$transaction && $this->capture) ) { |
|
365 | 336 | // Store captured |
366 | 337 | update_post_meta($order_id, '_fac_captured', true); |
367 | 338 | |
@@ -372,8 +343,7 @@ discard block |
||
372 | 343 | $order->add_order_note( sprintf( __('FAC transaction complete (ID: %s)', 'woocommerce-gateway-fac'), $reference ) ); |
373 | 344 | } |
374 | 345 | // Authorized transaction |
375 | - else |
|
376 | - { |
|
346 | + else { |
|
377 | 347 | // Store captured |
378 | 348 | update_post_meta($order_id, '_transaction_id', $reference, true); |
379 | 349 | update_post_meta($order_id, '_fac_captured', false); |
@@ -393,33 +363,26 @@ discard block |
||
393 | 363 | 'result' => 'success', |
394 | 364 | 'redirect' => $this->get_return_url($order) |
395 | 365 | ]; |
396 | - } |
|
397 | - else |
|
398 | - { |
|
366 | + } else { |
|
399 | 367 | throw new InvalidResponseException( $response->getMessage(), $response->getCode() ); |
400 | 368 | } |
401 | - } |
|
402 | - catch (OmnipayException $e) |
|
403 | - { |
|
369 | + } catch (OmnipayException $e) { |
|
404 | 370 | $message = 'Transaction Failed: '. $e->getCode() .' – '. $e->getMessage(); |
405 | 371 | |
406 | 372 | $this->log($message); |
407 | 373 | $order->add_order_note( __($message, 'woocommerce-gateway-fac') ); |
408 | 374 | |
409 | 375 | // Friendly declined message |
410 | - if ( in_array( $e->getCode(), [2, 3, 4, 35, 38, 39] ) ) |
|
411 | - { |
|
376 | + if ( in_array( $e->getCode(), [2, 3, 4, 35, 38, 39] ) ) { |
|
412 | 377 | $message = __('Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.', 'woocommerce') .' '. __('Please attempt your purchase again.', 'woocommerce'); |
413 | 378 | } |
414 | 379 | |
415 | 380 | // Friendly error message |
416 | - else |
|
417 | - { |
|
381 | + else { |
|
418 | 382 | $message = __('Unfortunately your order cannot be processed as an error has occured.', 'woocommerce') .' '. __('Please attempt your purchase again.', 'woocommerce'); |
419 | 383 | } |
420 | 384 | |
421 | - if ( !is_admin() || ( defined('DOING_AJAX') && DOING_AJAX ) ) |
|
422 | - { |
|
385 | + if ( !is_admin() || ( defined('DOING_AJAX') && DOING_AJAX ) ) { |
|
423 | 386 | wc_add_notice($message, 'error'); |
424 | 387 | } |
425 | 388 | |
@@ -434,8 +397,7 @@ discard block |
||
434 | 397 | * |
435 | 398 | * @return bool |
436 | 399 | */ |
437 | - public function can_refund_order($order) |
|
438 | - { |
|
400 | + public function can_refund_order($order) { |
|
439 | 401 | return $order && $order->payment_method == 'fac' && $order->get_transaction_id(); |
440 | 402 | } |
441 | 403 | |
@@ -447,12 +409,10 @@ discard block |
||
447 | 409 | * |
448 | 410 | * @return bool |
449 | 411 | */ |
450 | - public function process_refund($order_id, $amount = null, $reason = '') |
|
451 | - { |
|
412 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
452 | 413 | $order = wc_get_order($order_id); |
453 | 414 | |
454 | - if ( !$this->can_refund_order($order) ) |
|
455 | - { |
|
415 | + if ( !$this->can_refund_order($order) ) { |
|
456 | 416 | $this->log('Refund Failed: No transaction ID for FAC'); |
457 | 417 | return false; |
458 | 418 | } |
@@ -460,13 +420,11 @@ discard block |
||
460 | 420 | $transaction = $order->get_transaction_id(); |
461 | 421 | $captured = get_post_meta($order_id, '_fac_captured', true); |
462 | 422 | |
463 | - if ( is_null($amount) ) |
|
464 | - { |
|
423 | + if ( is_null($amount) ) { |
|
465 | 424 | $amount = $order->get_total(); |
466 | 425 | } |
467 | 426 | |
468 | - try |
|
469 | - { |
|
427 | + try { |
|
470 | 428 | $gateway = $this->setup_gateway(); |
471 | 429 | |
472 | 430 | $data = [ |
@@ -474,27 +432,19 @@ discard block |
||
474 | 432 | 'amount' => $amount |
475 | 433 | ]; |
476 | 434 | |
477 | - if ($captured) |
|
478 | - { |
|
435 | + if ($captured) { |
|
479 | 436 | $response = $gateway->refund($data)->send(); |
480 | - } |
|
481 | - else |
|
482 | - { |
|
437 | + } else { |
|
483 | 438 | $response = $gateway->void($data)->send(); |
484 | 439 | } |
485 | 440 | |
486 | - if ( $response->isSuccessful() ) |
|
487 | - { |
|
441 | + if ( $response->isSuccessful() ) { |
|
488 | 442 | $order->add_order_note( sprintf( __('Refunded %s', 'woocommerce-gateway-fac'), $data['amount'] ) ); |
489 | 443 | return true; |
490 | - } |
|
491 | - else |
|
492 | - { |
|
444 | + } else { |
|
493 | 445 | throw new InvalidResponseException( $response->getMessage(), $response->getCode() ); |
494 | 446 | } |
495 | - } |
|
496 | - catch (OmnipayException $e) |
|
497 | - { |
|
447 | + } catch (OmnipayException $e) { |
|
498 | 448 | $message = 'Refund Failed: '. $e->getCode() .' – '. $e->getMessage(); |
499 | 449 | |
500 | 450 | $this->log($message); |
@@ -2,5 +2,5 @@ |
||
2 | 2 | |
3 | 3 | $root_dir = dirname( getcwd() ); |
4 | 4 | $src_dir = $root_dir; |
5 | -$tmp_dir = $root_dir . '/builds'; |
|
5 | +$tmp_dir = $root_dir.'/builds'; |
|
6 | 6 | $zip_dir = $tmp_dir; |