@@ -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 ); |
@@ -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 | } |
@@ -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; |