@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_alipay'; |
60 | - $this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
61 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
60 | + $this->method_title = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
61 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
62 | 62 | |
63 | 63 | // Load the form fields. |
64 | 64 | $this->init_form_fields(); |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | // Load the settings. |
67 | 67 | $this->init_settings(); |
68 | 68 | |
69 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
70 | - $this->title = $this->get_option( 'title' ); |
|
71 | - $this->description = $this->get_option( 'description' ); |
|
72 | - $this->enabled = $this->get_option( 'enabled' ); |
|
73 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
74 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
75 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
76 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
77 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
78 | - |
|
79 | - if ( $this->testmode ) { |
|
80 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
69 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
70 | + $this->title = $this->get_option('title'); |
|
71 | + $this->description = $this->get_option('description'); |
|
72 | + $this->enabled = $this->get_option('enabled'); |
|
73 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
74 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
75 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
76 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
77 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
78 | + |
|
79 | + if ($this->testmode) { |
|
80 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
82 | 82 | } |
83 | 83 | |
84 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
85 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
86 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
84 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
85 | + add_action('admin_notices', array($this, 'check_environment')); |
|
86 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | public function check_environment() { |
96 | 96 | $environment_warning = $this->get_environment_warning(); |
97 | 97 | |
98 | - if ( $environment_warning ) { |
|
99 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
98 | + if ($environment_warning) { |
|
99 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
100 | 100 | } |
101 | 101 | |
102 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
103 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
104 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
102 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
103 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
104 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
105 | 105 | echo '</p></div>'; |
106 | 106 | } |
107 | 107 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | 'SGD' !== get_woocommerce_currency() && |
127 | 127 | 'USD' !== get_woocommerce_currency() |
128 | 128 | ) { |
129 | - $message = __( 'Alipay is enabled - it requires store currency to be set to USD, EUR, AUD, CAD, GBP, HKD, JPY, NZD or SGD.', 'woocommerce-gateway-stripe' ); |
|
129 | + $message = __('Alipay is enabled - it requires store currency to be set to USD, EUR, AUD, CAD, GBP, HKD, JPY, NZD or SGD.', 'woocommerce-gateway-stripe'); |
|
130 | 130 | |
131 | 131 | return $message; |
132 | 132 | } |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | * @return array |
143 | 143 | */ |
144 | 144 | public function payment_icons() { |
145 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
145 | + return apply_filters('wc_stripe_payment_icons', array( |
|
146 | 146 | 'alipay' => '<i class="stripe-pf stripe-pf-alipay stripe-pf-right" alt="Alipay" aria-hidden="true"></i>', |
147 | - ) ); |
|
147 | + )); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | $icons_str .= $icons['alipay']; |
163 | 163 | |
164 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
164 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | * @access public |
173 | 173 | */ |
174 | 174 | public function payment_scripts() { |
175 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
175 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
179 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
180 | 180 | |
181 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
181 | + wp_enqueue_style('stripe_paymentfonts'); |
|
182 | 182 | |
183 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
184 | - wp_enqueue_script( 'stripev3' ); |
|
185 | - wp_enqueue_script( 'woocommerce_stripe_elements' ); |
|
183 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
184 | + wp_enqueue_script('stripev3'); |
|
185 | + wp_enqueue_script('woocommerce_stripe_elements'); |
|
186 | 186 | } else { |
187 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
187 | + wp_enqueue_script('woocommerce_stripe'); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * Initialize Gateway Settings Form Fields. |
193 | 193 | */ |
194 | 194 | public function init_form_fields() { |
195 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' ); |
|
195 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php'); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -203,25 +203,25 @@ discard block |
||
203 | 203 | $total = WC()->cart->total; |
204 | 204 | |
205 | 205 | // If paying from order, we need to get total from order not cart. |
206 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
207 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
206 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
207 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
208 | 208 | $total = $order->get_total(); |
209 | 209 | } |
210 | 210 | |
211 | - if ( is_add_payment_method_page() ) { |
|
212 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
213 | - $total = ''; |
|
211 | + if (is_add_payment_method_page()) { |
|
212 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
213 | + $total = ''; |
|
214 | 214 | } else { |
215 | 215 | $pay_button_text = ''; |
216 | 216 | } |
217 | 217 | |
218 | 218 | echo '<div |
219 | 219 | id="stripe-alipay-payment-data" |
220 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
221 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
220 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
221 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
222 | 222 | |
223 | - if ( $this->description ) { |
|
224 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
223 | + if ($this->description) { |
|
224 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | echo '</div>'; |
@@ -235,26 +235,26 @@ discard block |
||
235 | 235 | * @param object $order |
236 | 236 | * @return mixed |
237 | 237 | */ |
238 | - public function create_source( $order ) { |
|
239 | - $currency = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency(); |
|
240 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
238 | + public function create_source($order) { |
|
239 | + $currency = version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency(); |
|
240 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
241 | 241 | $stripe_session_id = uniqid(); |
242 | 242 | |
243 | 243 | // Set the stripe session id in order meta to later match it for security purposes. |
244 | - update_post_meta( $order_id, '_stripe_session_id', $stripe_session_id ); |
|
245 | - $return_url = $this->get_stripe_return_url( $order, $stripe_session_id ); |
|
244 | + update_post_meta($order_id, '_stripe_session_id', $stripe_session_id); |
|
245 | + $return_url = $this->get_stripe_return_url($order, $stripe_session_id); |
|
246 | 246 | |
247 | 247 | $post_data = array(); |
248 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
249 | - $post_data['currency'] = strtolower( $currency ); |
|
248 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
249 | + $post_data['currency'] = strtolower($currency); |
|
250 | 250 | $post_data['type'] = 'alipay'; |
251 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
252 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
253 | - $post_data['alipay'] = array( 'statement_descriptor' => $this->statement_descriptor ); |
|
251 | + $post_data['owner'] = $this->get_owner_details($order); |
|
252 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
253 | + $post_data['alipay'] = array('statement_descriptor' => $this->statement_descriptor); |
|
254 | 254 | |
255 | - WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' ); |
|
255 | + WC_Stripe_Logger::log('Info: Begin creating Alipay source'); |
|
256 | 256 | |
257 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
257 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -268,45 +268,45 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @return array|void |
270 | 270 | */ |
271 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
271 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
272 | 272 | try { |
273 | - $order = wc_get_order( $order_id ); |
|
273 | + $order = wc_get_order($order_id); |
|
274 | 274 | |
275 | 275 | // Handle payment. |
276 | - if ( $order->get_total() > 0 ) { |
|
276 | + if ($order->get_total() > 0) { |
|
277 | 277 | |
278 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
279 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
278 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
279 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
280 | 280 | } |
281 | 281 | |
282 | - $response = $this->create_source( $order ); |
|
282 | + $response = $this->create_source($order); |
|
283 | 283 | |
284 | - if ( is_wp_error( $response ) ) { |
|
284 | + if (is_wp_error($response)) { |
|
285 | 285 | $message = $response->get_error_message(); |
286 | 286 | |
287 | - $order->add_order_note( $message ); |
|
287 | + $order->add_order_note($message); |
|
288 | 288 | |
289 | - throw new Exception( $message ); |
|
289 | + throw new Exception($message); |
|
290 | 290 | } |
291 | 291 | |
292 | - WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); |
|
292 | + WC_Stripe_Logger::log('Info: Redirecting to Alipay...'); |
|
293 | 293 | |
294 | 294 | return array( |
295 | 295 | 'result' => 'success', |
296 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
296 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
297 | 297 | ); |
298 | 298 | } else { |
299 | 299 | $order->payment_complete(); |
300 | 300 | } |
301 | - } catch ( Exception $e ) { |
|
302 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
303 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
301 | + } catch (Exception $e) { |
|
302 | + wc_add_notice($e->getMessage(), 'error'); |
|
303 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
304 | 304 | |
305 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
306 | - $this->send_failed_order_email( $order_id ); |
|
305 | + if ($order->has_status(array('pending', 'failed'))) { |
|
306 | + $this->send_failed_order_email($order_id); |
|
307 | 307 | } |
308 | 308 | |
309 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
309 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
310 | 310 | |
311 | 311 | return array( |
312 | 312 | 'result' => 'fail', |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_sepa'; |
60 | - $this->method_title = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
61 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
60 | + $this->method_title = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
61 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
62 | 62 | |
63 | 63 | // Load the form fields. |
64 | 64 | $this->init_form_fields(); |
@@ -66,27 +66,27 @@ discard block |
||
66 | 66 | // Load the settings. |
67 | 67 | $this->init_settings(); |
68 | 68 | |
69 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
70 | - $this->title = $this->get_option( 'title' ); |
|
71 | - $this->description = $this->get_option( 'description' ); |
|
72 | - $this->enabled = $this->get_option( 'enabled' ); |
|
73 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
74 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
75 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
76 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
77 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
78 | - |
|
79 | - if ( $this->testmode ) { |
|
80 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
82 | - |
|
83 | - $this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' ); |
|
84 | - $this->description = trim( $this->description ); |
|
69 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
70 | + $this->title = $this->get_option('title'); |
|
71 | + $this->description = $this->get_option('description'); |
|
72 | + $this->enabled = $this->get_option('enabled'); |
|
73 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
74 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
75 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
76 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
77 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
78 | + |
|
79 | + if ($this->testmode) { |
|
80 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
82 | + |
|
83 | + $this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe'); |
|
84 | + $this->description = trim($this->description); |
|
85 | 85 | } |
86 | 86 | |
87 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
88 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
89 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
87 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
88 | + add_action('admin_notices', array($this, 'check_environment')); |
|
89 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | public function check_environment() { |
99 | 99 | $environment_warning = $this->get_environment_warning(); |
100 | 100 | |
101 | - if ( $environment_warning ) { |
|
102 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
101 | + if ($environment_warning) { |
|
102 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
103 | 103 | } |
104 | 104 | |
105 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
106 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
107 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
105 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
106 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
107 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
108 | 108 | echo '</p></div>'; |
109 | 109 | } |
110 | 110 | } |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | * @version 4.0.0 |
118 | 118 | */ |
119 | 119 | public function get_environment_warning() { |
120 | - if ( 'yes' === $this->enabled && 'EUR' !== get_woocommerce_currency() ) { |
|
121 | - $message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
120 | + if ('yes' === $this->enabled && 'EUR' !== get_woocommerce_currency()) { |
|
121 | + $message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
122 | 122 | |
123 | 123 | return $message; |
124 | 124 | } |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | * @return array |
135 | 135 | */ |
136 | 136 | public function payment_icons() { |
137 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
137 | + return apply_filters('wc_stripe_payment_icons', array( |
|
138 | 138 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
139 | - ) ); |
|
139 | + )); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | $icons_str .= $icons['sepa']; |
155 | 155 | |
156 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
156 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -164,19 +164,19 @@ discard block |
||
164 | 164 | * @access public |
165 | 165 | */ |
166 | 166 | public function payment_scripts() { |
167 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
167 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
168 | 168 | return; |
169 | 169 | } |
170 | 170 | |
171 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
171 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
172 | 172 | |
173 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
173 | + wp_enqueue_style('stripe_paymentfonts'); |
|
174 | 174 | |
175 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
176 | - wp_enqueue_script( 'stripev3' ); |
|
177 | - wp_enqueue_script( 'woocommerce_stripe_elements' ); |
|
175 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
176 | + wp_enqueue_script('stripev3'); |
|
177 | + wp_enqueue_script('woocommerce_stripe_elements'); |
|
178 | 178 | } else { |
179 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
179 | + wp_enqueue_script('woocommerce_stripe'); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * Initialize Gateway Settings Form Fields. |
185 | 185 | */ |
186 | 186 | public function init_form_fields() { |
187 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' ); |
|
187 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php'); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @return string |
196 | 196 | */ |
197 | 197 | public function mandate_display() { |
198 | - printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), $this->statement_descriptor ); |
|
198 | + printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), $this->statement_descriptor); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -206,18 +206,18 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function form() { |
208 | 208 | ?> |
209 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
210 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
209 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
210 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
211 | 211 | <?php $this->mandate_display(); ?> |
212 | 212 | <p class="form-row form-row-wide validate-required"> |
213 | 213 | <label for="stripe-sepa-iban"> |
214 | - <?php esc_html_e( 'IBAN.', 'woocommerce-gateway-stripe' ); ?> |
|
214 | + <?php esc_html_e('IBAN.', 'woocommerce-gateway-stripe'); ?> |
|
215 | 215 | </label> |
216 | 216 | <input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" /> |
217 | 217 | </p> |
218 | 218 | <!-- Used to display form errors --> |
219 | 219 | <div class="stripe-source-errors" role="alert"></div> |
220 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
220 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
221 | 221 | <div class="clear"></div> |
222 | 222 | </fieldset> |
223 | 223 | <?php |
@@ -231,25 +231,25 @@ discard block |
||
231 | 231 | $total = WC()->cart->total; |
232 | 232 | |
233 | 233 | // If paying from order, we need to get total from order not cart. |
234 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
235 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
234 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
235 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
236 | 236 | $total = $order->get_total(); |
237 | 237 | } |
238 | 238 | |
239 | - if ( is_add_payment_method_page() ) { |
|
240 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
241 | - $total = ''; |
|
239 | + if (is_add_payment_method_page()) { |
|
240 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
241 | + $total = ''; |
|
242 | 242 | } else { |
243 | 243 | $pay_button_text = ''; |
244 | 244 | } |
245 | 245 | |
246 | 246 | echo '<div |
247 | 247 | id="stripe-sepa_debit-payment-data" |
248 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
249 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
248 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
249 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
250 | 250 | |
251 | - if ( $this->description ) { |
|
252 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
251 | + if ($this->description) { |
|
252 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | $this->form(); |
@@ -268,66 +268,66 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @return array|void |
270 | 270 | */ |
271 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
271 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
272 | 272 | try { |
273 | - $order = wc_get_order( $order_id ); |
|
274 | - $source_object = ! empty( $_POST['stripe_source_object'] ) ? json_decode( stripslashes( $_POST['stripe_source_object'] ) ) : false; |
|
273 | + $order = wc_get_order($order_id); |
|
274 | + $source_object = ! empty($_POST['stripe_source_object']) ? json_decode(stripslashes($_POST['stripe_source_object'])) : false; |
|
275 | 275 | |
276 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
276 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
277 | 277 | |
278 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
279 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
280 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
281 | - throw new Exception( $error_msg ); |
|
278 | + if (empty($source->source) && empty($source->customer)) { |
|
279 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
280 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
281 | + throw new Exception($error_msg); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | // Store source to order meta. |
285 | - $this->save_source( $order, $source ); |
|
285 | + $this->save_source($order, $source); |
|
286 | 286 | |
287 | 287 | // Result from Stripe API request. |
288 | 288 | $response = null; |
289 | 289 | |
290 | 290 | // Handle payment. |
291 | - if ( $order->get_total() > 0 ) { |
|
291 | + if ($order->get_total() > 0) { |
|
292 | 292 | |
293 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
294 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
293 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
294 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
295 | 295 | } |
296 | 296 | |
297 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
297 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
298 | 298 | |
299 | 299 | // Make the request. |
300 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
300 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
301 | 301 | |
302 | - if ( is_wp_error( $response ) ) { |
|
302 | + if (is_wp_error($response)) { |
|
303 | 303 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
304 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
305 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
306 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
307 | - } elseif ( preg_match( '/No such customer/i', $response->get_error_message() ) && $retry ) { |
|
308 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
304 | + if ('customer' === $response->get_error_code() && $retry) { |
|
305 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
306 | + return $this->process_payment($order_id, false, $force_customer); |
|
307 | + } elseif (preg_match('/No such customer/i', $response->get_error_message()) && $retry) { |
|
308 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
309 | 309 | |
310 | - return $this->process_redirect_payment( $order_id, false, $source ); |
|
310 | + return $this->process_redirect_payment($order_id, false, $source); |
|
311 | 311 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
312 | - } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
313 | - $token = WC_Payment_Tokens::get( $source->token_id ); |
|
312 | + } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
313 | + $token = WC_Payment_Tokens::get($source->token_id); |
|
314 | 314 | $token->delete(); |
315 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
316 | - $order->add_order_note( $message ); |
|
317 | - throw new Exception( $message ); |
|
315 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
316 | + $order->add_order_note($message); |
|
317 | + throw new Exception($message); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
321 | 321 | |
322 | - $message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message(); |
|
322 | + $message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message(); |
|
323 | 323 | |
324 | - $order->add_order_note( $message ); |
|
324 | + $order->add_order_note($message); |
|
325 | 325 | |
326 | - throw new Exception( $message ); |
|
326 | + throw new Exception($message); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // Process valid response. |
330 | - $this->process_response( $response, $order ); |
|
330 | + $this->process_response($response, $order); |
|
331 | 331 | } else { |
332 | 332 | $order->payment_complete(); |
333 | 333 | } |
@@ -335,23 +335,23 @@ discard block |
||
335 | 335 | // Remove cart. |
336 | 336 | WC()->cart->empty_cart(); |
337 | 337 | |
338 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
338 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
339 | 339 | |
340 | 340 | // Return thank you page redirect. |
341 | 341 | return array( |
342 | 342 | 'result' => 'success', |
343 | - 'redirect' => $this->get_return_url( $order ), |
|
343 | + 'redirect' => $this->get_return_url($order), |
|
344 | 344 | ); |
345 | 345 | |
346 | - } catch ( Exception $e ) { |
|
347 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
348 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
346 | + } catch (Exception $e) { |
|
347 | + wc_add_notice($e->getMessage(), 'error'); |
|
348 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
349 | 349 | |
350 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
351 | - $this->send_failed_order_email( $order_id ); |
|
350 | + if ($order->has_status(array('pending', 'failed'))) { |
|
351 | + $this->send_failed_order_email($order_id); |
|
352 | 352 | } |
353 | 353 | |
354 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
354 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
355 | 355 | |
356 | 356 | return array( |
357 | 357 | 'result' => 'fail', |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function __construct() { |
66 | 66 | $this->id = 'stripe_bitcoin'; |
67 | - $this->method_title = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
68 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
67 | + $this->method_title = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
68 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
69 | 69 | |
70 | 70 | // Load the form fields. |
71 | 71 | $this->init_form_fields(); |
@@ -73,28 +73,28 @@ discard block |
||
73 | 73 | // Load the settings. |
74 | 74 | $this->init_settings(); |
75 | 75 | |
76 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
77 | - $this->title = $this->get_option( 'title' ); |
|
78 | - $this->description = $this->get_option( 'description' ); |
|
79 | - $this->enabled = $this->get_option( 'enabled' ); |
|
80 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
81 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
82 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
83 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
84 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
85 | - |
|
86 | - if ( $this->testmode ) { |
|
87 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
88 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
76 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
77 | + $this->title = $this->get_option('title'); |
|
78 | + $this->description = $this->get_option('description'); |
|
79 | + $this->enabled = $this->get_option('enabled'); |
|
80 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
81 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
82 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
83 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
84 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
85 | + |
|
86 | + if ($this->testmode) { |
|
87 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
88 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
89 | 89 | } |
90 | 90 | |
91 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
92 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
93 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
94 | - add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) ); |
|
91 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
92 | + add_action('admin_notices', array($this, 'check_environment')); |
|
93 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
94 | + add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page')); |
|
95 | 95 | |
96 | 96 | // Customer Emails |
97 | - add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); |
|
97 | + add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | public function check_environment() { |
107 | 107 | $environment_warning = $this->get_environment_warning(); |
108 | 108 | |
109 | - if ( $environment_warning ) { |
|
110 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
109 | + if ($environment_warning) { |
|
110 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
111 | 111 | } |
112 | 112 | |
113 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
114 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
115 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
113 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
114 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
115 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
116 | 116 | echo '</p></div>'; |
117 | 117 | } |
118 | 118 | } |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @version 4.0.0 |
126 | 126 | */ |
127 | 127 | public function get_environment_warning() { |
128 | - if ( 'yes' === $this->enabled && 'EUR' !== get_woocommerce_currency() ) { |
|
129 | - $message = __( 'Bitcoin is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
128 | + if ('yes' === $this->enabled && 'EUR' !== get_woocommerce_currency()) { |
|
129 | + $message = __('Bitcoin is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
130 | 130 | |
131 | 131 | return $message; |
132 | 132 | } |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | * @return array |
143 | 143 | */ |
144 | 144 | public function payment_icons() { |
145 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
145 | + return apply_filters('wc_stripe_payment_icons', array( |
|
146 | 146 | 'bitcoin' => '<i class="stripe-pf stripe-pf-bitcoin stripe-pf-right" alt="Bitcoin" aria-hidden="true"></i>', |
147 | - ) ); |
|
147 | + )); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | $icons_str .= $icons['bitcoin']; |
163 | 163 | |
164 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
164 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | * @access public |
173 | 173 | */ |
174 | 174 | public function payment_scripts() { |
175 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
175 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
179 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
180 | 180 | |
181 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
181 | + wp_enqueue_style('stripe_paymentfonts'); |
|
182 | 182 | |
183 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
184 | - wp_enqueue_script( 'stripev3' ); |
|
185 | - wp_enqueue_script( 'woocommerce_stripe_elements' ); |
|
183 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
184 | + wp_enqueue_script('stripev3'); |
|
185 | + wp_enqueue_script('woocommerce_stripe_elements'); |
|
186 | 186 | } else { |
187 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
187 | + wp_enqueue_script('woocommerce_stripe'); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * Initialize Gateway Settings Form Fields. |
193 | 193 | */ |
194 | 194 | public function init_form_fields() { |
195 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' ); |
|
195 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php'); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -203,25 +203,25 @@ discard block |
||
203 | 203 | $total = WC()->cart->total; |
204 | 204 | |
205 | 205 | // If paying from order, we need to get total from order not cart. |
206 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
207 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
206 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
207 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
208 | 208 | $total = $order->get_total(); |
209 | 209 | } |
210 | 210 | |
211 | - if ( is_add_payment_method_page() ) { |
|
212 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
213 | - $total = ''; |
|
211 | + if (is_add_payment_method_page()) { |
|
212 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
213 | + $total = ''; |
|
214 | 214 | } else { |
215 | 215 | $pay_button_text = ''; |
216 | 216 | } |
217 | 217 | |
218 | 218 | echo '<div |
219 | 219 | id="stripe-bitcoin-payment-data" |
220 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
221 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
220 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
221 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
222 | 222 | |
223 | - if ( $this->description ) { |
|
224 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
223 | + if ($this->description) { |
|
224 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | echo '</div>'; |
@@ -232,8 +232,8 @@ discard block |
||
232 | 232 | * |
233 | 233 | * @param int $order_id |
234 | 234 | */ |
235 | - public function thankyou_page( $order_id ) { |
|
236 | - $this->get_instructions( $order_id ); |
|
235 | + public function thankyou_page($order_id) { |
|
236 | + $this->get_instructions($order_id); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -245,11 +245,11 @@ discard block |
||
245 | 245 | * @param bool $sent_to_admin |
246 | 246 | * @param bool $plain_text |
247 | 247 | */ |
248 | - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { |
|
249 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
248 | + public function email_instructions($order, $sent_to_admin, $plain_text = false) { |
|
249 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
250 | 250 | |
251 | - if ( ! $sent_to_admin && 'stripe_bitcoin' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) { |
|
252 | - $this->get_instructions( $order_id, $plain_text ); |
|
251 | + if ( ! $sent_to_admin && 'stripe_bitcoin' === $order->get_payment_method() && $order->has_status('on-hold')) { |
|
252 | + $this->get_instructions($order_id, $plain_text); |
|
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
@@ -260,35 +260,35 @@ discard block |
||
260 | 260 | * @version 4.0.0 |
261 | 261 | * @param int $order_id |
262 | 262 | */ |
263 | - public function get_instructions( $order_id, $plain_text = false ) { |
|
264 | - $data = get_post_meta( $order_id, '_stripe_bitcoin', true ); |
|
263 | + public function get_instructions($order_id, $plain_text = false) { |
|
264 | + $data = get_post_meta($order_id, '_stripe_bitcoin', true); |
|
265 | 265 | |
266 | - if ( $plain_text ) { |
|
267 | - esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
266 | + if ($plain_text) { |
|
267 | + esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
268 | 268 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
269 | - esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
269 | + esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
270 | 270 | echo $data['amount'] . "\n\n"; |
271 | 271 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
272 | - esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
272 | + esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
273 | 273 | echo $data['address'] . "\n\n"; |
274 | 274 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
275 | - esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
275 | + esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
276 | 276 | echo $data['uri'] . "\n\n"; |
277 | 277 | } else { |
278 | 278 | ?> |
279 | - <h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3> |
|
279 | + <h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3> |
|
280 | 280 | <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
281 | 281 | <li class="woocommerce-order-overview__order order"> |
282 | - <?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?> |
|
282 | + <?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?> |
|
283 | 283 | <strong><?php echo $data['amount']; ?></strong> |
284 | 284 | </li> |
285 | 285 | <li class="woocommerce-order-overview__order order"> |
286 | - <?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?> |
|
286 | + <?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?> |
|
287 | 287 | <strong><?php echo $data['address']; ?></strong> |
288 | 288 | </li> |
289 | 289 | <li class="woocommerce-order-overview__order order"> |
290 | - <?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?> |
|
291 | - <strong><?php printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] ); ?></strong> |
|
290 | + <?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?> |
|
291 | + <strong><?php printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']); ?></strong> |
|
292 | 292 | </li> |
293 | 293 | </ul> |
294 | 294 | <?php |
@@ -303,16 +303,16 @@ discard block |
||
303 | 303 | * @param object $order |
304 | 304 | * @param object $source_object |
305 | 305 | */ |
306 | - public function save_instructions( $order, $source_object ) { |
|
306 | + public function save_instructions($order, $source_object) { |
|
307 | 307 | $data = array( |
308 | 308 | 'amount' => $source_object->bitcoin->amount, |
309 | 309 | 'address' => $source_object->bitcoin->address, |
310 | 310 | 'uri' => $source_object->bitcoin->uri, |
311 | 311 | ); |
312 | 312 | |
313 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
313 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
314 | 314 | |
315 | - update_post_meta( $order_id, '_stripe_bitcoin', $data ); |
|
315 | + update_post_meta($order_id, '_stripe_bitcoin', $data); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -326,39 +326,39 @@ discard block |
||
326 | 326 | * |
327 | 327 | * @return array|void |
328 | 328 | */ |
329 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
329 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
330 | 330 | try { |
331 | - $order = wc_get_order( $order_id ); |
|
332 | - $source_object = ! empty( $_POST['stripe_source_object'] ) ? json_decode( stripslashes( $_POST['stripe_source_object'] ) ) : false; |
|
331 | + $order = wc_get_order($order_id); |
|
332 | + $source_object = ! empty($_POST['stripe_source_object']) ? json_decode(stripslashes($_POST['stripe_source_object'])) : false; |
|
333 | 333 | |
334 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
334 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
335 | 335 | |
336 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
337 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
338 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
339 | - throw new Exception( $error_msg ); |
|
336 | + if (empty($source->source) && empty($source->customer)) { |
|
337 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
338 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
339 | + throw new Exception($error_msg); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | // Store source to order meta. |
343 | - $this->save_source( $order, $source ); |
|
343 | + $this->save_source($order, $source); |
|
344 | 344 | |
345 | 345 | // Result from Stripe API request. |
346 | 346 | $response = null; |
347 | 347 | |
348 | 348 | // Handle payment. |
349 | - if ( $order->get_total() > 0 ) { |
|
349 | + if ($order->get_total() > 0) { |
|
350 | 350 | |
351 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
352 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
351 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
352 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
353 | 353 | } |
354 | 354 | |
355 | - $this->save_instructions( $order, $source_object ); |
|
355 | + $this->save_instructions($order, $source_object); |
|
356 | 356 | |
357 | 357 | // Mark as on-hold (we're awaiting the payment) |
358 | - $order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) ); |
|
358 | + $order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe')); |
|
359 | 359 | |
360 | 360 | // Reduce stock levels |
361 | - wc_reduce_stock_levels( $order_id ); |
|
361 | + wc_reduce_stock_levels($order_id); |
|
362 | 362 | |
363 | 363 | // Remove cart |
364 | 364 | WC()->cart->empty_cart(); |
@@ -366,21 +366,21 @@ discard block |
||
366 | 366 | // Return thankyou redirect |
367 | 367 | return array( |
368 | 368 | 'result' => 'success', |
369 | - 'redirect' => $this->get_return_url( $order ), |
|
369 | + 'redirect' => $this->get_return_url($order), |
|
370 | 370 | ); |
371 | 371 | } else { |
372 | 372 | $order->payment_complete(); |
373 | 373 | } |
374 | 374 | |
375 | - } catch ( Exception $e ) { |
|
376 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
377 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
375 | + } catch (Exception $e) { |
|
376 | + wc_add_notice($e->getMessage(), 'error'); |
|
377 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
378 | 378 | |
379 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
380 | - $this->send_failed_order_email( $order_id ); |
|
379 | + if ($order->has_status(array('pending', 'failed'))) { |
|
380 | + $this->send_failed_order_email($order_id); |
|
381 | 381 | } |
382 | 382 | |
383 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
383 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
384 | 384 | |
385 | 385 | return array( |
386 | 386 | 'result' => 'fail', |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_bancontact'; |
60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
61 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
60 | + $this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
61 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
62 | 62 | |
63 | 63 | // Load the form fields. |
64 | 64 | $this->init_form_fields(); |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | // Load the settings. |
67 | 67 | $this->init_settings(); |
68 | 68 | |
69 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
70 | - $this->title = $this->get_option( 'title' ); |
|
71 | - $this->description = $this->get_option( 'description' ); |
|
72 | - $this->enabled = $this->get_option( 'enabled' ); |
|
73 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
74 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
75 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
76 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
77 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
78 | - |
|
79 | - if ( $this->testmode ) { |
|
80 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
69 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
70 | + $this->title = $this->get_option('title'); |
|
71 | + $this->description = $this->get_option('description'); |
|
72 | + $this->enabled = $this->get_option('enabled'); |
|
73 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
74 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
75 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
76 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
77 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
78 | + |
|
79 | + if ($this->testmode) { |
|
80 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
82 | 82 | } |
83 | 83 | |
84 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
85 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
86 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
84 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
85 | + add_action('admin_notices', array($this, 'check_environment')); |
|
86 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | public function check_environment() { |
96 | 96 | $environment_warning = $this->get_environment_warning(); |
97 | 97 | |
98 | - if ( $environment_warning ) { |
|
99 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
98 | + if ($environment_warning) { |
|
99 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
100 | 100 | } |
101 | 101 | |
102 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
103 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
104 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
102 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
103 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
104 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
105 | 105 | echo '</p></div>'; |
106 | 106 | } |
107 | 107 | } |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @version 4.0.0 |
115 | 115 | */ |
116 | 116 | public function get_environment_warning() { |
117 | - if ( 'yes' === $this->enabled && 'EUR' !== get_woocommerce_currency() ) { |
|
118 | - $message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
117 | + if ('yes' === $this->enabled && 'EUR' !== get_woocommerce_currency()) { |
|
118 | + $message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
119 | 119 | |
120 | 120 | return $message; |
121 | 121 | } |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * @return array |
132 | 132 | */ |
133 | 133 | public function payment_icons() { |
134 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
134 | + return apply_filters('wc_stripe_payment_icons', array( |
|
135 | 135 | 'bancontact' => '<i class="stripe-pf stripe-pf-bancontact-mister-cash stripe-pf-right" alt="Bancontact" aria-hidden="true"></i>', |
136 | - ) ); |
|
136 | + )); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | |
151 | 151 | $icons_str .= $icons['bancontact']; |
152 | 152 | |
153 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
153 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -161,19 +161,19 @@ discard block |
||
161 | 161 | * @access public |
162 | 162 | */ |
163 | 163 | public function payment_scripts() { |
164 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
164 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | 167 | |
168 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
168 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
169 | 169 | |
170 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
170 | + wp_enqueue_style('stripe_paymentfonts'); |
|
171 | 171 | |
172 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
173 | - wp_enqueue_script( 'stripev3' ); |
|
174 | - wp_enqueue_script( 'woocommerce_stripe_elements' ); |
|
172 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
173 | + wp_enqueue_script('stripev3'); |
|
174 | + wp_enqueue_script('woocommerce_stripe_elements'); |
|
175 | 175 | } else { |
176 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
176 | + wp_enqueue_script('woocommerce_stripe'); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * Initialize Gateway Settings Form Fields. |
182 | 182 | */ |
183 | 183 | public function init_form_fields() { |
184 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
184 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -192,25 +192,25 @@ discard block |
||
192 | 192 | $total = WC()->cart->total; |
193 | 193 | |
194 | 194 | // If paying from order, we need to get total from order not cart. |
195 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
196 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
195 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
196 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
197 | 197 | $total = $order->get_total(); |
198 | 198 | } |
199 | 199 | |
200 | - if ( is_add_payment_method_page() ) { |
|
201 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
202 | - $total = ''; |
|
200 | + if (is_add_payment_method_page()) { |
|
201 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
202 | + $total = ''; |
|
203 | 203 | } else { |
204 | 204 | $pay_button_text = ''; |
205 | 205 | } |
206 | 206 | |
207 | 207 | echo '<div |
208 | 208 | id="stripe-bancontact-payment-data" |
209 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
210 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
209 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
210 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
211 | 211 | |
212 | - if ( $this->description ) { |
|
213 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
212 | + if ($this->description) { |
|
213 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | echo '</div>'; |
@@ -224,26 +224,26 @@ discard block |
||
224 | 224 | * @param object $order |
225 | 225 | * @return mixed |
226 | 226 | */ |
227 | - public function create_source( $order ) { |
|
228 | - $currency = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency(); |
|
229 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
227 | + public function create_source($order) { |
|
228 | + $currency = version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency(); |
|
229 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
230 | 230 | $stripe_session_id = uniqid(); |
231 | 231 | |
232 | 232 | // Set the stripe session id in order meta to later match it for security purposes. |
233 | - update_post_meta( $order_id, '_stripe_session_id', $stripe_session_id ); |
|
234 | - $return_url = $this->get_stripe_return_url( $order, $stripe_session_id ); |
|
233 | + update_post_meta($order_id, '_stripe_session_id', $stripe_session_id); |
|
234 | + $return_url = $this->get_stripe_return_url($order, $stripe_session_id); |
|
235 | 235 | |
236 | 236 | $post_data = array(); |
237 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
238 | - $post_data['currency'] = strtolower( $currency ); |
|
237 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
238 | + $post_data['currency'] = strtolower($currency); |
|
239 | 239 | $post_data['type'] = 'bancontact'; |
240 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
241 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
242 | - $post_data['bancontact'] = array( 'statement_descriptor' => $this->statement_descriptor ); |
|
240 | + $post_data['owner'] = $this->get_owner_details($order); |
|
241 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
242 | + $post_data['bancontact'] = array('statement_descriptor' => $this->statement_descriptor); |
|
243 | 243 | |
244 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
244 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
245 | 245 | |
246 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
246 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -257,45 +257,45 @@ discard block |
||
257 | 257 | * |
258 | 258 | * @return array|void |
259 | 259 | */ |
260 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
260 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
261 | 261 | try { |
262 | - $order = wc_get_order( $order_id ); |
|
262 | + $order = wc_get_order($order_id); |
|
263 | 263 | |
264 | 264 | // Handle payment. |
265 | - if ( $order->get_total() > 0 ) { |
|
265 | + if ($order->get_total() > 0) { |
|
266 | 266 | |
267 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
268 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
267 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
268 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
269 | 269 | } |
270 | 270 | |
271 | - $response = $this->create_source( $order ); |
|
271 | + $response = $this->create_source($order); |
|
272 | 272 | |
273 | - if ( is_wp_error( $response ) ) { |
|
273 | + if (is_wp_error($response)) { |
|
274 | 274 | $message = $response->get_error_message(); |
275 | 275 | |
276 | - $order->add_order_note( $message ); |
|
276 | + $order->add_order_note($message); |
|
277 | 277 | |
278 | - throw new Exception( $message ); |
|
278 | + throw new Exception($message); |
|
279 | 279 | } |
280 | 280 | |
281 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
281 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
282 | 282 | |
283 | 283 | return array( |
284 | 284 | 'result' => 'success', |
285 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
285 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
286 | 286 | ); |
287 | 287 | } else { |
288 | 288 | $order->payment_complete(); |
289 | 289 | } |
290 | - } catch ( Exception $e ) { |
|
291 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
292 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
290 | + } catch (Exception $e) { |
|
291 | + wc_add_notice($e->getMessage(), 'error'); |
|
292 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
293 | 293 | |
294 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
295 | - $this->send_failed_order_email( $order_id ); |
|
294 | + if ($order->has_status(array('pending', 'failed'))) { |
|
295 | + $this->send_failed_order_email($order_id); |
|
296 | 296 | } |
297 | 297 | |
298 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
298 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
299 | 299 | |
300 | 300 | return array( |
301 | 301 | 'result' => 'fail', |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_sofort'; |
60 | - $this->method_title = __( 'Stripe Sofort', 'woocommerce-gateway-stripe' ); |
|
61 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
60 | + $this->method_title = __('Stripe Sofort', 'woocommerce-gateway-stripe'); |
|
61 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
62 | 62 | |
63 | 63 | // Load the form fields. |
64 | 64 | $this->init_form_fields(); |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | // Load the settings. |
67 | 67 | $this->init_settings(); |
68 | 68 | |
69 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
70 | - $this->title = $this->get_option( 'title' ); |
|
71 | - $this->description = $this->get_option( 'description' ); |
|
72 | - $this->enabled = $this->get_option( 'enabled' ); |
|
73 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
74 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
75 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
76 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
77 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
78 | - |
|
79 | - if ( $this->testmode ) { |
|
80 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
69 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
70 | + $this->title = $this->get_option('title'); |
|
71 | + $this->description = $this->get_option('description'); |
|
72 | + $this->enabled = $this->get_option('enabled'); |
|
73 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
74 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
75 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
76 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
77 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
78 | + |
|
79 | + if ($this->testmode) { |
|
80 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
82 | 82 | } |
83 | 83 | |
84 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
85 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
86 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
84 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
85 | + add_action('admin_notices', array($this, 'check_environment')); |
|
86 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | public function check_environment() { |
96 | 96 | $environment_warning = $this->get_environment_warning(); |
97 | 97 | |
98 | - if ( $environment_warning ) { |
|
99 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
98 | + if ($environment_warning) { |
|
99 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
100 | 100 | } |
101 | 101 | |
102 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
103 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
104 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
102 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
103 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
104 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
105 | 105 | echo '</p></div>'; |
106 | 106 | } |
107 | 107 | } |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @version 4.0.0 |
115 | 115 | */ |
116 | 116 | public function get_environment_warning() { |
117 | - if ( 'yes' === $this->enabled && 'EUR' !== get_woocommerce_currency() ) { |
|
118 | - $message = __( 'Sofort is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
117 | + if ('yes' === $this->enabled && 'EUR' !== get_woocommerce_currency()) { |
|
118 | + $message = __('Sofort is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
119 | 119 | |
120 | 120 | return $message; |
121 | 121 | } |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * @return array |
132 | 132 | */ |
133 | 133 | public function payment_icons() { |
134 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
134 | + return apply_filters('wc_stripe_payment_icons', array( |
|
135 | 135 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="Sofort" aria-hidden="true"></i>', |
136 | - ) ); |
|
136 | + )); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | |
151 | 151 | $icons_str .= $icons['sofort']; |
152 | 152 | |
153 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
153 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -161,19 +161,19 @@ discard block |
||
161 | 161 | * @access public |
162 | 162 | */ |
163 | 163 | public function payment_scripts() { |
164 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
164 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | 167 | |
168 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
168 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
169 | 169 | |
170 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
170 | + wp_enqueue_style('stripe_paymentfonts'); |
|
171 | 171 | |
172 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
173 | - wp_enqueue_script( 'stripev3' ); |
|
174 | - wp_enqueue_script( 'woocommerce_stripe_elements' ); |
|
172 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
173 | + wp_enqueue_script('stripev3'); |
|
174 | + wp_enqueue_script('woocommerce_stripe_elements'); |
|
175 | 175 | } else { |
176 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
176 | + wp_enqueue_script('woocommerce_stripe'); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * Initialize Gateway Settings Form Fields. |
182 | 182 | */ |
183 | 183 | public function init_form_fields() { |
184 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
184 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -191,24 +191,24 @@ discard block |
||
191 | 191 | * @version 4.0.0 |
192 | 192 | */ |
193 | 193 | public function form() { |
194 | - $supported_countries = array( 'AT' => 'Austria', 'BE' => 'Belgium', 'DE' => 'Germany', 'NL' => 'Netherlands', 'ES' => 'Spain', 'IT' => 'Italy' ); |
|
194 | + $supported_countries = array('AT' => 'Austria', 'BE' => 'Belgium', 'DE' => 'Germany', 'NL' => 'Netherlands', 'ES' => 'Spain', 'IT' => 'Italy'); |
|
195 | 195 | ?> |
196 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
197 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
196 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
197 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
198 | 198 | <label for="stripe-bank-country"> |
199 | - <?php _e( 'Country origin of your bank.', 'woocommerce-gateway-stripe' ); ?> |
|
199 | + <?php _e('Country origin of your bank.', 'woocommerce-gateway-stripe'); ?> |
|
200 | 200 | </label> |
201 | 201 | <br /> |
202 | 202 | <select id="stripe-bank-country" class="wc-enhanced-select validate-required" name="stripe_sofort_bank_country"> |
203 | - <option value="-1"><?php esc_html_e( 'Choose Bank Country', 'woocommerce-gateway-stripe' ); ?></option> |
|
204 | - <?php foreach ( $supported_countries as $code => $country ) { ?> |
|
205 | - <option value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $country ); ?></option> |
|
203 | + <option value="-1"><?php esc_html_e('Choose Bank Country', 'woocommerce-gateway-stripe'); ?></option> |
|
204 | + <?php foreach ($supported_countries as $code => $country) { ?> |
|
205 | + <option value="<?php echo esc_attr($code); ?>"><?php echo esc_html($country); ?></option> |
|
206 | 206 | <?php } ?> |
207 | 207 | </select> |
208 | 208 | |
209 | 209 | <!-- Used to display form errors --> |
210 | 210 | <div class="stripe-source-errors" role="alert"></div> |
211 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
211 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
212 | 212 | <div class="clear"></div> |
213 | 213 | </fieldset> |
214 | 214 | <?php |
@@ -222,25 +222,25 @@ discard block |
||
222 | 222 | $total = WC()->cart->total; |
223 | 223 | |
224 | 224 | // If paying from order, we need to get total from order not cart. |
225 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
226 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
225 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
226 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
227 | 227 | $total = $order->get_total(); |
228 | 228 | } |
229 | 229 | |
230 | - if ( is_add_payment_method_page() ) { |
|
231 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
232 | - $total = ''; |
|
230 | + if (is_add_payment_method_page()) { |
|
231 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
232 | + $total = ''; |
|
233 | 233 | } else { |
234 | 234 | $pay_button_text = ''; |
235 | 235 | } |
236 | 236 | |
237 | 237 | echo '<div |
238 | 238 | id="stripe-sofort-payment-data" |
239 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
240 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
239 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
240 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
241 | 241 | |
242 | - if ( $this->description ) { |
|
243 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
242 | + if ($this->description) { |
|
243 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | $this->form(); |
@@ -256,27 +256,27 @@ discard block |
||
256 | 256 | * @param object $order |
257 | 257 | * @return mixed |
258 | 258 | */ |
259 | - public function create_source( $order ) { |
|
260 | - $currency = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency(); |
|
261 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
262 | - $bank_country = wc_clean( $_POST['stripe_sofort_bank_country'] ); |
|
259 | + public function create_source($order) { |
|
260 | + $currency = version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency(); |
|
261 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
262 | + $bank_country = wc_clean($_POST['stripe_sofort_bank_country']); |
|
263 | 263 | $stripe_session_id = uniqid(); |
264 | 264 | |
265 | 265 | // Set the stripe session id in order meta to later match it for security purposes. |
266 | - update_post_meta( $order_id, '_stripe_session_id', $stripe_session_id ); |
|
267 | - $return_url = $this->get_stripe_return_url( $order, $stripe_session_id ); |
|
266 | + update_post_meta($order_id, '_stripe_session_id', $stripe_session_id); |
|
267 | + $return_url = $this->get_stripe_return_url($order, $stripe_session_id); |
|
268 | 268 | |
269 | 269 | $post_data = array(); |
270 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
271 | - $post_data['currency'] = strtolower( $currency ); |
|
270 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
271 | + $post_data['currency'] = strtolower($currency); |
|
272 | 272 | $post_data['type'] = 'sofort'; |
273 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
274 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
275 | - $post_data['sofort'] = array( 'statement_descriptor' => $this->statement_descriptor, 'country' => $bank_country ); |
|
273 | + $post_data['owner'] = $this->get_owner_details($order); |
|
274 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
275 | + $post_data['sofort'] = array('statement_descriptor' => $this->statement_descriptor, 'country' => $bank_country); |
|
276 | 276 | |
277 | - WC_Stripe_Logger::log( 'Info: Begin creating Sofort source' ); |
|
277 | + WC_Stripe_Logger::log('Info: Begin creating Sofort source'); |
|
278 | 278 | |
279 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
279 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -290,45 +290,45 @@ discard block |
||
290 | 290 | * |
291 | 291 | * @return array|void |
292 | 292 | */ |
293 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
293 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
294 | 294 | try { |
295 | - $order = wc_get_order( $order_id ); |
|
295 | + $order = wc_get_order($order_id); |
|
296 | 296 | |
297 | 297 | // Handle payment. |
298 | - if ( $order->get_total() > 0 ) { |
|
298 | + if ($order->get_total() > 0) { |
|
299 | 299 | |
300 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
301 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
300 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
301 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
302 | 302 | } |
303 | 303 | |
304 | - $response = $this->create_source( $order ); |
|
304 | + $response = $this->create_source($order); |
|
305 | 305 | |
306 | - if ( is_wp_error( $response ) ) { |
|
306 | + if (is_wp_error($response)) { |
|
307 | 307 | $message = $response->get_error_message(); |
308 | 308 | |
309 | - $order->add_order_note( $message ); |
|
309 | + $order->add_order_note($message); |
|
310 | 310 | |
311 | - throw new Exception( $message ); |
|
311 | + throw new Exception($message); |
|
312 | 312 | } |
313 | 313 | |
314 | - WC_Stripe_Logger::log( 'Info: Redirecting to Sofort...' ); |
|
314 | + WC_Stripe_Logger::log('Info: Redirecting to Sofort...'); |
|
315 | 315 | |
316 | 316 | return array( |
317 | 317 | 'result' => 'success', |
318 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
318 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
319 | 319 | ); |
320 | 320 | } else { |
321 | 321 | $order->payment_complete(); |
322 | 322 | } |
323 | - } catch ( Exception $e ) { |
|
324 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
325 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
323 | + } catch (Exception $e) { |
|
324 | + wc_add_notice($e->getMessage(), 'error'); |
|
325 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
326 | 326 | |
327 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
328 | - $this->send_failed_order_email( $order_id ); |
|
327 | + if ($order->has_status(array('pending', 'failed'))) { |
|
328 | + $this->send_failed_order_email($order_id); |
|
329 | 329 | } |
330 | 330 | |
331 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
331 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
332 | 332 | |
333 | 333 | return array( |
334 | 334 | 'result' => 'fail', |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_ideal'; |
60 | - $this->method_title = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
61 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
60 | + $this->method_title = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
61 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
62 | 62 | |
63 | 63 | // Load the form fields. |
64 | 64 | $this->init_form_fields(); |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | // Load the settings. |
67 | 67 | $this->init_settings(); |
68 | 68 | |
69 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
70 | - $this->title = $this->get_option( 'title' ); |
|
71 | - $this->description = $this->get_option( 'description' ); |
|
72 | - $this->enabled = $this->get_option( 'enabled' ); |
|
73 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
74 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
75 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
76 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
77 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
78 | - |
|
79 | - if ( $this->testmode ) { |
|
80 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
69 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
70 | + $this->title = $this->get_option('title'); |
|
71 | + $this->description = $this->get_option('description'); |
|
72 | + $this->enabled = $this->get_option('enabled'); |
|
73 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
74 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
75 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
76 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
77 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
78 | + |
|
79 | + if ($this->testmode) { |
|
80 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
82 | 82 | } |
83 | 83 | |
84 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
85 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
86 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
84 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
85 | + add_action('admin_notices', array($this, 'check_environment')); |
|
86 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | public function check_environment() { |
96 | 96 | $environment_warning = $this->get_environment_warning(); |
97 | 97 | |
98 | - if ( $environment_warning ) { |
|
99 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
98 | + if ($environment_warning) { |
|
99 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
100 | 100 | } |
101 | 101 | |
102 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
103 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
104 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
102 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
103 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
104 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
105 | 105 | echo '</p></div>'; |
106 | 106 | } |
107 | 107 | } |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @version 4.0.0 |
115 | 115 | */ |
116 | 116 | public function get_environment_warning() { |
117 | - if ( 'yes' === $this->enabled && 'EUR' !== get_woocommerce_currency() ) { |
|
118 | - $message = __( 'iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
117 | + if ('yes' === $this->enabled && 'EUR' !== get_woocommerce_currency()) { |
|
118 | + $message = __('iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
119 | 119 | |
120 | 120 | return $message; |
121 | 121 | } |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * @return array |
132 | 132 | */ |
133 | 133 | public function payment_icons() { |
134 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
134 | + return apply_filters('wc_stripe_payment_icons', array( |
|
135 | 135 | 'ideal' => '<i class="stripe-pf stripe-pf-ideal stripe-pf-right" alt="iDeal" aria-hidden="true"></i>', |
136 | - ) ); |
|
136 | + )); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | |
151 | 151 | $icons_str .= $icons['ideal']; |
152 | 152 | |
153 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
153 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -161,19 +161,19 @@ discard block |
||
161 | 161 | * @access public |
162 | 162 | */ |
163 | 163 | public function payment_scripts() { |
164 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
164 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | 167 | |
168 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
168 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
169 | 169 | |
170 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
170 | + wp_enqueue_style('stripe_paymentfonts'); |
|
171 | 171 | |
172 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
173 | - wp_enqueue_script( 'stripev3' ); |
|
174 | - wp_enqueue_script( 'woocommerce_stripe_elements' ); |
|
172 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
173 | + wp_enqueue_script('stripev3'); |
|
174 | + wp_enqueue_script('woocommerce_stripe_elements'); |
|
175 | 175 | } else { |
176 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
176 | + wp_enqueue_script('woocommerce_stripe'); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * Initialize Gateway Settings Form Fields. |
182 | 182 | */ |
183 | 183 | public function init_form_fields() { |
184 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' ); |
|
184 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php'); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -192,25 +192,25 @@ discard block |
||
192 | 192 | $total = WC()->cart->total; |
193 | 193 | |
194 | 194 | // If paying from order, we need to get total from order not cart. |
195 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
196 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
195 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
196 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
197 | 197 | $total = $order->get_total(); |
198 | 198 | } |
199 | 199 | |
200 | - if ( is_add_payment_method_page() ) { |
|
201 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
202 | - $total = ''; |
|
200 | + if (is_add_payment_method_page()) { |
|
201 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
202 | + $total = ''; |
|
203 | 203 | } else { |
204 | 204 | $pay_button_text = ''; |
205 | 205 | } |
206 | 206 | |
207 | 207 | echo '<div |
208 | 208 | id="stripe-ideal-payment-data" |
209 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
210 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
209 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
210 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
211 | 211 | |
212 | - if ( $this->description ) { |
|
213 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
212 | + if ($this->description) { |
|
213 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | echo '</div>'; |
@@ -224,26 +224,26 @@ discard block |
||
224 | 224 | * @param object $order |
225 | 225 | * @return mixed |
226 | 226 | */ |
227 | - public function create_source( $order ) { |
|
228 | - $currency = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency(); |
|
229 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
227 | + public function create_source($order) { |
|
228 | + $currency = version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency(); |
|
229 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
230 | 230 | $stripe_session_id = uniqid(); |
231 | 231 | |
232 | 232 | // Set the stripe session id in order meta to later match it for security purposes. |
233 | - update_post_meta( $order_id, '_stripe_session_id', $stripe_session_id ); |
|
234 | - $return_url = $this->get_stripe_return_url( $order, $stripe_session_id ); |
|
233 | + update_post_meta($order_id, '_stripe_session_id', $stripe_session_id); |
|
234 | + $return_url = $this->get_stripe_return_url($order, $stripe_session_id); |
|
235 | 235 | |
236 | 236 | $post_data = array(); |
237 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
238 | - $post_data['currency'] = strtolower( $currency ); |
|
237 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
238 | + $post_data['currency'] = strtolower($currency); |
|
239 | 239 | $post_data['type'] = 'ideal'; |
240 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
241 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
242 | - $post_data['ideal'] = array( 'statement_descriptor' => $this->statement_descriptor ); |
|
240 | + $post_data['owner'] = $this->get_owner_details($order); |
|
241 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
242 | + $post_data['ideal'] = array('statement_descriptor' => $this->statement_descriptor); |
|
243 | 243 | |
244 | - WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' ); |
|
244 | + WC_Stripe_Logger::log('Info: Begin creating iDeal source'); |
|
245 | 245 | |
246 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
246 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -257,45 +257,45 @@ discard block |
||
257 | 257 | * |
258 | 258 | * @return array|void |
259 | 259 | */ |
260 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
260 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
261 | 261 | try { |
262 | - $order = wc_get_order( $order_id ); |
|
262 | + $order = wc_get_order($order_id); |
|
263 | 263 | |
264 | 264 | // Handle payment. |
265 | - if ( $order->get_total() > 0 ) { |
|
265 | + if ($order->get_total() > 0) { |
|
266 | 266 | |
267 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
268 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
267 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
268 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
269 | 269 | } |
270 | 270 | |
271 | - $response = $this->create_source( $order ); |
|
271 | + $response = $this->create_source($order); |
|
272 | 272 | |
273 | - if ( is_wp_error( $response ) ) { |
|
273 | + if (is_wp_error($response)) { |
|
274 | 274 | $message = $response->get_error_message(); |
275 | 275 | |
276 | - $order->add_order_note( $message ); |
|
276 | + $order->add_order_note($message); |
|
277 | 277 | |
278 | - throw new Exception( $message ); |
|
278 | + throw new Exception($message); |
|
279 | 279 | } |
280 | 280 | |
281 | - WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' ); |
|
281 | + WC_Stripe_Logger::log('Info: Redirecting to iDeal...'); |
|
282 | 282 | |
283 | 283 | return array( |
284 | 284 | 'result' => 'success', |
285 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
285 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
286 | 286 | ); |
287 | 287 | } else { |
288 | 288 | $order->payment_complete(); |
289 | 289 | } |
290 | - } catch ( Exception $e ) { |
|
291 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
292 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
290 | + } catch (Exception $e) { |
|
291 | + wc_add_notice($e->getMessage(), 'error'); |
|
292 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
293 | 293 | |
294 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
295 | - $this->send_failed_order_email( $order_id ); |
|
294 | + if ($order->has_status(array('pending', 'failed'))) { |
|
295 | + $this->send_failed_order_email($order_id); |
|
296 | 296 | } |
297 | 297 | |
298 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
298 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
299 | 299 | |
300 | 300 | return array( |
301 | 301 | 'result' => 'fail', |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @version 4.0.0 |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
20 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -27,21 +27,21 @@ discard block |
||
27 | 27 | * @version 4.0.0 |
28 | 28 | */ |
29 | 29 | public function check_for_webhook() { |
30 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
31 | - || ! isset( $_GET['wc-api'] ) |
|
32 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
30 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
31 | + || ! isset($_GET['wc-api']) |
|
32 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
33 | 33 | ) { |
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | - $request_body = file_get_contents( 'php://input' ); |
|
38 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
37 | + $request_body = file_get_contents('php://input'); |
|
38 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
39 | 39 | |
40 | 40 | // Validate it to make sure it is legit. |
41 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
42 | - $this->process_webhook( $request_body ); |
|
41 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
42 | + $this->process_webhook($request_body); |
|
43 | 43 | } else { |
44 | - status_header( 400 ); |
|
44 | + status_header(400); |
|
45 | 45 | exit; |
46 | 46 | } |
47 | 47 | } |
@@ -55,16 +55,16 @@ discard block |
||
55 | 55 | * @param string $request_body The request body from Stripe. |
56 | 56 | * @return bool |
57 | 57 | */ |
58 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
59 | - if ( null === $request_headers || null === $request_body ) { |
|
58 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
59 | + if (null === $request_headers || null === $request_body) { |
|
60 | 60 | return false; |
61 | 61 | } |
62 | 62 | |
63 | 63 | try { |
64 | 64 | |
65 | 65 | return false; |
66 | - } catch ( Exception $e ) { |
|
67 | - WC_Stripe_Logger::log( $e->getMessage() ); |
|
66 | + } catch (Exception $e) { |
|
67 | + WC_Stripe_Logger::log($e->getMessage()); |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | } |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | * @version 4.0.0 |
79 | 79 | */ |
80 | 80 | public function get_request_headers() { |
81 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
81 | + if ( ! function_exists('getallheaders')) { |
|
82 | 82 | $headers = []; |
83 | - foreach ( $_SERVER as $name => $value ) { |
|
84 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
85 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
83 | + foreach ($_SERVER as $name => $value) { |
|
84 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
85 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | * @param string $request_body |
101 | 101 | */ |
102 | - public function process_webhook( $request_body = null ) { |
|
103 | - if ( null === $request_body ) { |
|
104 | - status_header( 400 ); |
|
102 | + public function process_webhook($request_body = null) { |
|
103 | + if (null === $request_body) { |
|
104 | + status_header(400); |
|
105 | 105 | exit; |
106 | 106 | } |
107 | 107 | |
108 | - $notification = json_decode( $request_body ); |
|
108 | + $notification = json_decode($request_body); |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -96,28 +96,28 @@ discard block |
||
96 | 96 | public function __construct() { |
97 | 97 | self::$_this = $this; |
98 | 98 | |
99 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
99 | + $gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
100 | 100 | |
101 | - $this->statement_descriptor = ! empty( $gateway_settings['statement_descriptor'] ) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
101 | + $this->statement_descriptor = ! empty($gateway_settings['statement_descriptor']) ? $gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
102 | 102 | |
103 | 103 | // If both site title and statement descriptor is not set. Fallback. |
104 | - if ( empty( $this->statement_descriptor ) ) { |
|
104 | + if (empty($this->statement_descriptor)) { |
|
105 | 105 | $this->statement_descriptor = $_SERVER['SERVER_NAME']; |
106 | 106 | } |
107 | 107 | |
108 | 108 | $this->dp = wc_get_price_decimals(); |
109 | - $this->enabled = ( ! empty( $gateway_settings['enabled'] ) && 'yes' === $gateway_settings['enabled'] ) ? true : false; |
|
110 | - $this->testmode = ( ! empty( $gateway_settings['testmode'] ) && 'yes' === $gateway_settings['testmode'] ) ? true : false; |
|
111 | - $this->capture = ( ! empty( $gateway_settings['capture'] ) && 'yes' === $gateway_settings['capture'] ) ? true : false; |
|
112 | - $this->saved_cards = ( ! empty( $gateway_settings['saved_cards'] ) && 'yes' === $gateway_settings['saved_cards'] ) ? true : false; |
|
113 | - $this->apple_pay = ( ! empty( $gateway_settings['apple_pay'] ) && 'yes' === $gateway_settings['apple_pay'] ) ? true : false; |
|
114 | - $this->apple_pay_button = ! empty( $gateway_settings['apple_pay_button'] ) ? $gateway_settings['apple_pay_button'] : 'black'; |
|
115 | - $this->apple_pay_button_lang = ! empty( $gateway_settings['apple_pay_button_lang'] ) ? $gateway_settings['apple_pay_button_lang'] : 'en'; |
|
116 | - $this->publishable_key = ! empty( $gateway_settings['publishable_key'] ) ? $gateway_settings['publishable_key'] : ''; |
|
109 | + $this->enabled = ( ! empty($gateway_settings['enabled']) && 'yes' === $gateway_settings['enabled']) ? true : false; |
|
110 | + $this->testmode = ( ! empty($gateway_settings['testmode']) && 'yes' === $gateway_settings['testmode']) ? true : false; |
|
111 | + $this->capture = ( ! empty($gateway_settings['capture']) && 'yes' === $gateway_settings['capture']) ? true : false; |
|
112 | + $this->saved_cards = ( ! empty($gateway_settings['saved_cards']) && 'yes' === $gateway_settings['saved_cards']) ? true : false; |
|
113 | + $this->apple_pay = ( ! empty($gateway_settings['apple_pay']) && 'yes' === $gateway_settings['apple_pay']) ? true : false; |
|
114 | + $this->apple_pay_button = ! empty($gateway_settings['apple_pay_button']) ? $gateway_settings['apple_pay_button'] : 'black'; |
|
115 | + $this->apple_pay_button_lang = ! empty($gateway_settings['apple_pay_button_lang']) ? $gateway_settings['apple_pay_button_lang'] : 'en'; |
|
116 | + $this->publishable_key = ! empty($gateway_settings['publishable_key']) ? $gateway_settings['publishable_key'] : ''; |
|
117 | 117 | $this->is_shipping_enabled = $this->is_shipping_enabled(); |
118 | 118 | |
119 | - if ( $this->testmode ) { |
|
120 | - $this->publishable_key = ! empty( $gateway_settings['test_publishable_key'] ) ? $gateway_settings['test_publishable_key'] : ''; |
|
119 | + if ($this->testmode) { |
|
120 | + $this->publishable_key = ! empty($gateway_settings['test_publishable_key']) ? $gateway_settings['test_publishable_key'] : ''; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | $this->init(); |
@@ -136,53 +136,53 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function init() { |
138 | 138 | // If Apple Pay is not enabled no need to proceed further. |
139 | - if ( ! $this->apple_pay || ! $this->enabled ) { |
|
139 | + if ( ! $this->apple_pay || ! $this->enabled) { |
|
140 | 140 | return; |
141 | 141 | } |
142 | 142 | |
143 | - add_action( 'wp_enqueue_scripts', array( $this, 'cart_scripts' ) ); |
|
144 | - add_action( 'wp_enqueue_scripts', array( $this, 'single_scripts' ) ); |
|
143 | + add_action('wp_enqueue_scripts', array($this, 'cart_scripts')); |
|
144 | + add_action('wp_enqueue_scripts', array($this, 'single_scripts')); |
|
145 | 145 | |
146 | 146 | /** |
147 | 147 | * In order to display the Apple Pay button in the correct position, |
148 | 148 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
149 | 149 | * CSS is used to position the button. |
150 | 150 | */ |
151 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
152 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_apple_pay_button' ), 1 ); |
|
151 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
152 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_apple_pay_button'), 1); |
|
153 | 153 | } else { |
154 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_apple_pay_button' ), 1 ); |
|
154 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_apple_pay_button'), 1); |
|
155 | 155 | } |
156 | 156 | |
157 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 ); |
|
158 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
159 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 ); |
|
160 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
161 | - add_action( 'wc_ajax_wc_stripe_log_apple_pay_errors', array( $this, 'log_apple_pay_errors' ) ); |
|
162 | - add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) ); |
|
163 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) ); |
|
164 | - add_action( 'wc_ajax_wc_stripe_apple_pay_clear_cart', array( $this, 'clear_cart' ) ); |
|
165 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_single', array( $this, 'generate_apple_pay_single' ) ); |
|
166 | - add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) ); |
|
167 | - add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) ); |
|
168 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
169 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
157 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1); |
|
158 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_separator_html'), 2); |
|
159 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1); |
|
160 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2); |
|
161 | + add_action('wc_ajax_wc_stripe_log_apple_pay_errors', array($this, 'log_apple_pay_errors')); |
|
162 | + add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay')); |
|
163 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart')); |
|
164 | + add_action('wc_ajax_wc_stripe_apple_pay_clear_cart', array($this, 'clear_cart')); |
|
165 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_single', array($this, 'generate_apple_pay_single')); |
|
166 | + add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods')); |
|
167 | + add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method')); |
|
168 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
169 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Filters the gateway title to reflect Apple Pay. |
174 | 174 | * |
175 | 175 | */ |
176 | - public function filter_gateway_title( $title, $id ) { |
|
176 | + public function filter_gateway_title($title, $id) { |
|
177 | 177 | global $post; |
178 | 178 | |
179 | - if ( ! is_object( $post ) ) { |
|
179 | + if ( ! is_object($post)) { |
|
180 | 180 | return $title; |
181 | 181 | } |
182 | 182 | |
183 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
183 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
184 | 184 | |
185 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
185 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
186 | 186 | return $method_title; |
187 | 187 | } |
188 | 188 | |
@@ -196,13 +196,13 @@ discard block |
||
196 | 196 | * @version 3.1.4 |
197 | 197 | */ |
198 | 198 | public function log_apple_pay_errors() { |
199 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) && ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
200 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
199 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce') && ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
200 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
201 | 201 | } |
202 | 202 | |
203 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
203 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
204 | 204 | |
205 | - WC_Stripe_Logger::log( $errors ); |
|
205 | + WC_Stripe_Logger::log($errors); |
|
206 | 206 | |
207 | 207 | exit; |
208 | 208 | } |
@@ -213,10 +213,10 @@ discard block |
||
213 | 213 | * @since 3.1.4 |
214 | 214 | * @version 3.1.4 |
215 | 215 | */ |
216 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
216 | + public function postal_code_validation($valid, $postcode, $country) { |
|
217 | 217 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
218 | 218 | |
219 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
219 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
220 | 220 | return $valid; |
221 | 221 | } |
222 | 222 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * the order and not let it go through. The remedy for now is just to remove this validation. |
227 | 227 | * Note that this only works with shipping providers that don't validate full postal codes. |
228 | 228 | */ |
229 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
229 | + if ('GB' === $country || 'CA' === $country) { |
|
230 | 230 | return true; |
231 | 231 | } |
232 | 232 | |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | * @return bool |
242 | 242 | */ |
243 | 243 | public function is_shipping_enabled() { |
244 | - $shipping_enabled = get_option( 'woocommerce_ship_to_countries', '' ); |
|
244 | + $shipping_enabled = get_option('woocommerce_ship_to_countries', ''); |
|
245 | 245 | |
246 | - if ( 'disabled' === $shipping_enabled ) { |
|
246 | + if ('disabled' === $shipping_enabled) { |
|
247 | 247 | return false; |
248 | 248 | } |
249 | 249 | |
@@ -257,42 +257,42 @@ discard block |
||
257 | 257 | * @version 3.1.4 |
258 | 258 | */ |
259 | 259 | public function single_scripts() { |
260 | - if ( ! is_single() ) { |
|
260 | + if ( ! is_single()) { |
|
261 | 261 | return; |
262 | 262 | } |
263 | 263 | |
264 | 264 | global $post; |
265 | 265 | |
266 | - $product = wc_get_product( $post->ID ); |
|
266 | + $product = wc_get_product($post->ID); |
|
267 | 267 | |
268 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
268 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | |
272 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
272 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
273 | 273 | |
274 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
274 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
275 | 275 | |
276 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
277 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay_single', plugins_url( 'assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
276 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
277 | + wp_enqueue_script('woocommerce_stripe_apple_pay_single', plugins_url('assets/js/stripe-apple-pay-single' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
278 | 278 | |
279 | 279 | $stripe_params = array( |
280 | 280 | 'key' => $this->publishable_key, |
281 | 281 | 'currency_code' => get_woocommerce_currency(), |
282 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
282 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
283 | 283 | 'label' => $this->statement_descriptor . ' (via WooCommerce)', |
284 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
285 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
286 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
287 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
288 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
289 | - 'needs_shipping' => ( $product->needs_shipping() && $this->is_shipping_enabled ) ? 'yes' : 'no', |
|
284 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
285 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
286 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
287 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
288 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
289 | + 'needs_shipping' => ($product->needs_shipping() && $this->is_shipping_enabled) ? 'yes' : 'no', |
|
290 | 290 | 'i18n' => array( |
291 | - 'sub_total' => __( 'Sub-Total', 'woocommerce-gateway-stripe' ), |
|
291 | + 'sub_total' => __('Sub-Total', 'woocommerce-gateway-stripe'), |
|
292 | 292 | ), |
293 | 293 | ); |
294 | 294 | |
295 | - wp_localize_script( 'woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters( 'wc_stripe_apple_pay_single_params', $stripe_params ) ); |
|
295 | + wp_localize_script('woocommerce_stripe_apple_pay_single', 'wc_stripe_apple_pay_single_params', apply_filters('wc_stripe_apple_pay_single_params', $stripe_params)); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -302,32 +302,32 @@ discard block |
||
302 | 302 | * @version 3.1.0 |
303 | 303 | */ |
304 | 304 | public function cart_scripts() { |
305 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
305 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
306 | 306 | return; |
307 | 307 | } |
308 | 308 | |
309 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
309 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
310 | 310 | |
311 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
311 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
312 | 312 | |
313 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
314 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
313 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
314 | + wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
315 | 315 | |
316 | 316 | $stripe_params = array( |
317 | 317 | 'key' => $this->publishable_key, |
318 | 318 | 'currency_code' => get_woocommerce_currency(), |
319 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
319 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
320 | 320 | 'label' => $this->statement_descriptor . ' (via WooCommerce)', |
321 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
322 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
323 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
324 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
325 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
326 | - 'needs_shipping' => ( WC()->cart->needs_shipping() && $this->is_shipping_enabled ) ? 'yes' : 'no', |
|
321 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
322 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
323 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
324 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
325 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
326 | + 'needs_shipping' => (WC()->cart->needs_shipping() && $this->is_shipping_enabled) ? 'yes' : 'no', |
|
327 | 327 | 'is_cart_page' => is_cart() ? 'yes' : 'no', |
328 | 328 | ); |
329 | 329 | |
330 | - wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) ); |
|
330 | + wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params)); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -338,11 +338,11 @@ discard block |
||
338 | 338 | * @return array |
339 | 339 | */ |
340 | 340 | public function supported_product_types() { |
341 | - return apply_filters( 'wc_stripe_apple_pay_supported_types', array( |
|
341 | + return apply_filters('wc_stripe_apple_pay_supported_types', array( |
|
342 | 342 | 'simple', |
343 | 343 | 'variable', |
344 | 344 | 'variation', |
345 | - ) ); |
|
345 | + )); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -354,10 +354,10 @@ discard block |
||
354 | 354 | * @return bool |
355 | 355 | */ |
356 | 356 | public function allowed_items_in_cart() { |
357 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
358 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
357 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
358 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
359 | 359 | |
360 | - if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
360 | + if ( ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
361 | 361 | return false; |
362 | 362 | } |
363 | 363 | } |
@@ -378,29 +378,29 @@ discard block |
||
378 | 378 | * In order for the Apple Pay button to show on product detail page, |
379 | 379 | * Apple Pay must be enabled and Stripe gateway must be enabled. |
380 | 380 | */ |
381 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
382 | - WC_Stripe_Logger::log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' ); |
|
381 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
382 | + WC_Stripe_Logger::log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )'); |
|
383 | 383 | return; |
384 | 384 | } |
385 | 385 | |
386 | - if ( is_single() ) { |
|
386 | + if (is_single()) { |
|
387 | 387 | global $post; |
388 | 388 | |
389 | - $product = wc_get_product( $post->ID ); |
|
389 | + $product = wc_get_product($post->ID); |
|
390 | 390 | |
391 | - if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
391 | + if ( ! is_object($product) || ! in_array((version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
392 | 392 | return; |
393 | 393 | } |
394 | 394 | } else { |
395 | - if ( ! $this->allowed_items_in_cart() ) { |
|
396 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' ); |
|
395 | + if ( ! $this->allowed_items_in_cart()) { |
|
396 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Apple Pay button disabled )'); |
|
397 | 397 | return; |
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
401 | 401 | ?> |
402 | 402 | <div class="apple-pay-button-wrapper"> |
403 | - <button class="apple-pay-button" lang="<?php echo esc_attr( $this->apple_pay_button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $this->apple_pay_button ); ?>;display:none;" alt="<?php esc_attr_e( 'Buy with Apple Pay', 'woocommerce-gateway-stripe' ); ?>"></button> |
|
403 | + <button class="apple-pay-button" lang="<?php echo esc_attr($this->apple_pay_button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($this->apple_pay_button); ?>;display:none;" alt="<?php esc_attr_e('Buy with Apple Pay', 'woocommerce-gateway-stripe'); ?>"></button> |
|
404 | 404 | </div> |
405 | 405 | <?php |
406 | 406 | } |
@@ -418,17 +418,17 @@ discard block |
||
418 | 418 | * In order for the Apple Pay button to show on cart page, |
419 | 419 | * Apple Pay must be enabled and Stripe gateway must be enabled. |
420 | 420 | */ |
421 | - if ( ! $this->apple_pay || ! isset( $gateways['stripe'] ) ) { |
|
422 | - WC_Stripe_Logger::log( 'Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )' ); |
|
421 | + if ( ! $this->apple_pay || ! isset($gateways['stripe'])) { |
|
422 | + WC_Stripe_Logger::log('Apple Pay not enabled or Stripe is not an available gateway ( Apple Pay button disabled )'); |
|
423 | 423 | return; |
424 | 424 | } |
425 | 425 | |
426 | - if ( ! $this->allowed_items_in_cart() ) { |
|
427 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Apple Pay button disabled )' ); |
|
426 | + if ( ! $this->allowed_items_in_cart()) { |
|
427 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Apple Pay button disabled )'); |
|
428 | 428 | return; |
429 | 429 | } |
430 | 430 | ?> |
431 | - <p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
431 | + <p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p> |
|
432 | 432 | <?php |
433 | 433 | } |
434 | 434 | |
@@ -439,45 +439,45 @@ discard block |
||
439 | 439 | * @version 3.1.0 |
440 | 440 | */ |
441 | 441 | public function generate_apple_pay_single() { |
442 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
443 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
442 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
443 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
447 | - define( 'WOOCOMMERCE_CART', true ); |
|
446 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
447 | + define('WOOCOMMERCE_CART', true); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | WC()->shipping->reset_shipping(); |
451 | 451 | |
452 | 452 | global $post; |
453 | 453 | |
454 | - $product = wc_get_product( $post->ID ); |
|
455 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
454 | + $product = wc_get_product($post->ID); |
|
455 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
456 | 456 | |
457 | 457 | /** |
458 | 458 | * If this page is single product page, we need to simulate |
459 | 459 | * adding the product to the cart taken account if it is a |
460 | 460 | * simple or variable product. |
461 | 461 | */ |
462 | - if ( is_single() ) { |
|
462 | + if (is_single()) { |
|
463 | 463 | // First empty the cart to prevent wrong calculation. |
464 | 464 | WC()->cart->empty_cart(); |
465 | 465 | |
466 | - if ( 'variable' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
467 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
466 | + if ('variable' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
467 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
468 | 468 | |
469 | - if ( version_compare( WC_VERSION, '3.0.0', '<' ) ) { |
|
470 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
469 | + if (version_compare(WC_VERSION, '3.0.0', '<')) { |
|
470 | + $variation_id = $product->get_matching_variation($attributes); |
|
471 | 471 | } else { |
472 | - $data_store = WC_Data_Store::load( 'product' ); |
|
473 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
472 | + $data_store = WC_Data_Store::load('product'); |
|
473 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
474 | 474 | } |
475 | 475 | |
476 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
476 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
477 | 477 | } |
478 | 478 | |
479 | - if ( 'simple' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ) ) { |
|
480 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
479 | + if ('simple' === (version_compare(WC_VERSION, '3.0.0', '<') ? $product->product_type : $product->get_type())) { |
|
480 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | |
486 | 486 | $build_items = $this->build_line_items(); |
487 | 487 | |
488 | - wp_send_json( array( 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
488 | + wp_send_json(array('line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | /** |
@@ -495,13 +495,13 @@ discard block |
||
495 | 495 | * @version 3.1.0 |
496 | 496 | */ |
497 | 497 | public function generate_apple_pay_cart() { |
498 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
499 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
498 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
499 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | $build_items = $this->build_line_items(); |
503 | 503 | |
504 | - wp_send_json( array( 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
504 | + wp_send_json(array('line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
@@ -522,32 +522,32 @@ discard block |
||
522 | 522 | * @version 3.1.0 |
523 | 523 | * @param array $address |
524 | 524 | */ |
525 | - public function calculate_shipping( $address = array() ) { |
|
526 | - $country = strtoupper( $address['countryCode'] ); |
|
527 | - $state = strtoupper( $address['administrativeArea'] ); |
|
525 | + public function calculate_shipping($address = array()) { |
|
526 | + $country = strtoupper($address['countryCode']); |
|
527 | + $state = strtoupper($address['administrativeArea']); |
|
528 | 528 | $postcode = $address['postalCode']; |
529 | 529 | $city = $address['locality']; |
530 | 530 | |
531 | 531 | WC()->shipping->reset_shipping(); |
532 | 532 | |
533 | - if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
534 | - throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
535 | - } elseif ( $postcode ) { |
|
536 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
533 | + if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) { |
|
534 | + throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe')); |
|
535 | + } elseif ($postcode) { |
|
536 | + $postcode = wc_format_postcode($postcode, $country); |
|
537 | 537 | } |
538 | 538 | |
539 | - if ( $country ) { |
|
540 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
541 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
539 | + if ($country) { |
|
540 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
541 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
542 | 542 | } else { |
543 | 543 | WC()->customer->set_to_base(); |
544 | 544 | WC()->customer->set_shipping_to_base(); |
545 | 545 | } |
546 | 546 | |
547 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
548 | - WC()->customer->calculated_shipping( true ); |
|
547 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
548 | + WC()->customer->calculated_shipping(true); |
|
549 | 549 | } else { |
550 | - WC()->customer->set_calculated_shipping( true ); |
|
550 | + WC()->customer->set_calculated_shipping(true); |
|
551 | 551 | WC()->customer->save(); |
552 | 552 | } |
553 | 553 | |
@@ -571,17 +571,17 @@ discard block |
||
571 | 571 | $packages[0]['destination']['postcode'] = $postcode; |
572 | 572 | $packages[0]['destination']['city'] = $city; |
573 | 573 | |
574 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
575 | - if ( $item['data']->needs_shipping() ) { |
|
576 | - if ( isset( $item['line_total'] ) ) { |
|
574 | + foreach (WC()->cart->get_cart() as $item) { |
|
575 | + if ($item['data']->needs_shipping()) { |
|
576 | + if (isset($item['line_total'])) { |
|
577 | 577 | $packages[0]['contents_cost'] += $item['line_total']; |
578 | 578 | } |
579 | 579 | } |
580 | 580 | } |
581 | 581 | |
582 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
582 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
583 | 583 | |
584 | - WC()->shipping->calculate_shipping( $packages ); |
|
584 | + WC()->shipping->calculate_shipping($packages); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -591,18 +591,18 @@ discard block |
||
591 | 591 | * @version 3.1.0 |
592 | 592 | */ |
593 | 593 | public function get_shipping_methods() { |
594 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) { |
|
595 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
594 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) { |
|
595 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
596 | 596 | } |
597 | 597 | |
598 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
599 | - define( 'WOOCOMMERCE_CART', true ); |
|
598 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
599 | + define('WOOCOMMERCE_CART', true); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | try { |
603 | - $address = array_map( 'wc_clean', $_POST['address'] ); |
|
603 | + $address = array_map('wc_clean', $_POST['address']); |
|
604 | 604 | |
605 | - $this->calculate_shipping( $address ); |
|
605 | + $this->calculate_shipping($address); |
|
606 | 606 | |
607 | 607 | // Set the shipping options. |
608 | 608 | $currency = get_woocommerce_currency(); |
@@ -610,13 +610,13 @@ discard block |
||
610 | 610 | |
611 | 611 | $packages = WC()->shipping->get_packages(); |
612 | 612 | |
613 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
614 | - foreach ( $packages as $package_key => $package ) { |
|
615 | - if ( empty( $package['rates'] ) ) { |
|
616 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
613 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
614 | + foreach ($packages as $package_key => $package) { |
|
615 | + if (empty($package['rates'])) { |
|
616 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
617 | 617 | } |
618 | 618 | |
619 | - foreach ( $package['rates'] as $key => $rate ) { |
|
619 | + foreach ($package['rates'] as $key => $rate) { |
|
620 | 620 | $data[] = array( |
621 | 621 | 'id' => $rate->id, |
622 | 622 | 'label' => $rate->label, |
@@ -630,19 +630,19 @@ discard block |
||
630 | 630 | } |
631 | 631 | |
632 | 632 | // Auto select the first shipping method. |
633 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
633 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
634 | 634 | |
635 | 635 | WC()->cart->calculate_totals(); |
636 | 636 | |
637 | 637 | $build_items = $this->build_line_items(); |
638 | 638 | |
639 | - wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
639 | + wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
640 | 640 | } else { |
641 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
641 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
642 | 642 | } |
643 | - } catch ( Exception $e ) { |
|
643 | + } catch (Exception $e) { |
|
644 | 644 | $build_items = $this->build_line_items(); |
645 | - wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
645 | + wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
646 | 646 | } |
647 | 647 | } |
648 | 648 | |
@@ -653,22 +653,22 @@ discard block |
||
653 | 653 | * @version 3.1.0 |
654 | 654 | */ |
655 | 655 | public function update_shipping_method() { |
656 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
657 | - define( 'WOOCOMMERCE_CART', true ); |
|
656 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
657 | + define('WOOCOMMERCE_CART', true); |
|
658 | 658 | } |
659 | 659 | |
660 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) { |
|
661 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
660 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) { |
|
661 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
662 | 662 | } |
663 | 663 | |
664 | - $selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] ); |
|
664 | + $selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']); |
|
665 | 665 | |
666 | - WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) ); |
|
666 | + WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier'])); |
|
667 | 667 | |
668 | 668 | WC()->cart->calculate_totals(); |
669 | 669 | |
670 | 670 | $build_items = $this->build_line_items(); |
671 | - wp_send_json( array( 'success' => 'true', 'line_items' => $build_items['line_items'], 'total' => $build_items['total'] ) ); |
|
671 | + wp_send_json(array('success' => 'true', 'line_items' => $build_items['line_items'], 'total' => $build_items['total'])); |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | /** |
@@ -679,37 +679,37 @@ discard block |
||
679 | 679 | * @version 3.1.0 |
680 | 680 | */ |
681 | 681 | public function process_apple_pay() { |
682 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) { |
|
683 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
682 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) { |
|
683 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
684 | 684 | } |
685 | 685 | |
686 | 686 | try { |
687 | - $result = array_map( 'wc_clean', $_POST['result'] ); |
|
687 | + $result = array_map('wc_clean', $_POST['result']); |
|
688 | 688 | |
689 | - $order = $this->create_order( $result ); |
|
689 | + $order = $this->create_order($result); |
|
690 | 690 | |
691 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
691 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
692 | 692 | |
693 | 693 | // Handle payment. |
694 | - if ( $order->get_total() > 0 ) { |
|
694 | + if ($order->get_total() > 0) { |
|
695 | 695 | |
696 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
697 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
696 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
697 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
698 | 698 | } |
699 | 699 | |
700 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}" ); |
|
700 | + WC_Stripe_Logger::log("Info: Begin processing payment for order {$order_id} for the amount of {$order->get_total()}"); |
|
701 | 701 | |
702 | 702 | // Make the request. |
703 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) ); |
|
703 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id'])); |
|
704 | 704 | |
705 | - if ( is_wp_error( $response ) ) { |
|
705 | + if (is_wp_error($response)) { |
|
706 | 706 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
707 | 707 | |
708 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
708 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | // Process valid response. |
712 | - $this->process_response( $response, $order ); |
|
712 | + $this->process_response($response, $order); |
|
713 | 713 | } else { |
714 | 714 | $order->payment_complete(); |
715 | 715 | } |
@@ -717,24 +717,24 @@ discard block |
||
717 | 717 | // Remove cart. |
718 | 718 | WC()->cart->empty_cart(); |
719 | 719 | |
720 | - update_post_meta( $order_id, '_customer_user', get_current_user_id() ); |
|
721 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
720 | + update_post_meta($order_id, '_customer_user', get_current_user_id()); |
|
721 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
722 | 722 | |
723 | 723 | // Return thank you page redirect. |
724 | - wp_send_json( array( |
|
724 | + wp_send_json(array( |
|
725 | 725 | 'success' => 'true', |
726 | - 'redirect' => $this->get_return_url( $order ), |
|
727 | - ) ); |
|
726 | + 'redirect' => $this->get_return_url($order), |
|
727 | + )); |
|
728 | 728 | |
729 | - } catch ( Exception $e ) { |
|
730 | - WC()->session->set( 'refresh_totals', true ); |
|
731 | - WC_Stripe_Logger::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
729 | + } catch (Exception $e) { |
|
730 | + WC()->session->set('refresh_totals', true); |
|
731 | + WC_Stripe_Logger::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
732 | 732 | |
733 | - if ( is_object( $order ) && isset( $order_id ) && $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
734 | - $this->send_failed_order_email( $order_id ); |
|
733 | + if (is_object($order) && isset($order_id) && $order->has_status(array('pending', 'failed'))) { |
|
734 | + $this->send_failed_order_email($order_id); |
|
735 | 735 | } |
736 | 736 | |
737 | - wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) ); |
|
737 | + wp_send_json(array('success' => 'false', 'msg' => $e->getMessage())); |
|
738 | 738 | } |
739 | 739 | } |
740 | 740 | |
@@ -744,16 +744,16 @@ discard block |
||
744 | 744 | * @param string $source token |
745 | 745 | * @return array() |
746 | 746 | */ |
747 | - public function generate_payment_request( $order, $source ) { |
|
747 | + public function generate_payment_request($order, $source) { |
|
748 | 748 | $post_data = array(); |
749 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
750 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
751 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
749 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
750 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
751 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
752 | 752 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
753 | 753 | |
754 | - $billing_email = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
754 | + $billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
755 | 755 | |
756 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
756 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
757 | 757 | $post_data['receipt_email'] = $billing_email; |
758 | 758 | } |
759 | 759 | |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | * @param WC_Order $order |
769 | 769 | * @param object $source |
770 | 770 | */ |
771 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order ); |
|
771 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | /** |
@@ -777,14 +777,14 @@ discard block |
||
777 | 777 | * @since 3.1.0 |
778 | 778 | * @version 3.1.0 |
779 | 779 | */ |
780 | - public function build_shipping_methods( $shipping_methods ) { |
|
781 | - if ( empty( $shipping_methods ) ) { |
|
780 | + public function build_shipping_methods($shipping_methods) { |
|
781 | + if (empty($shipping_methods)) { |
|
782 | 782 | return array(); |
783 | 783 | } |
784 | 784 | |
785 | 785 | $shipping = array(); |
786 | 786 | |
787 | - foreach ( $shipping_methods as $method ) { |
|
787 | + foreach ($shipping_methods as $method) { |
|
788 | 788 | $shipping[] = array( |
789 | 789 | 'label' => $method['label'], |
790 | 790 | 'detail' => '', |
@@ -803,70 +803,70 @@ discard block |
||
803 | 803 | * @version 3.2.0 |
804 | 804 | */ |
805 | 805 | public function build_line_items() { |
806 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
807 | - define( 'WOOCOMMERCE_CART', true ); |
|
806 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
807 | + define('WOOCOMMERCE_CART', true); |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | $items = array(); |
811 | 811 | $subtotal = 0; |
812 | 812 | |
813 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
814 | - $amount = wc_format_decimal( $cart_item['line_subtotal'], $this->dp ); |
|
815 | - $subtotal += $cart_item['line_subtotal']; |
|
813 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
814 | + $amount = wc_format_decimal($cart_item['line_subtotal'], $this->dp); |
|
815 | + $subtotal += $cart_item['line_subtotal']; |
|
816 | 816 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
817 | 817 | |
818 | - $product_name = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
818 | + $product_name = version_compare(WC_VERSION, '3.0', '<') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
819 | 819 | |
820 | 820 | $item = array( |
821 | 821 | 'type' => 'final', |
822 | 822 | 'label' => $product_name . $quantity_label, |
823 | - 'amount' => wc_format_decimal( $amount, $this->dp ), |
|
823 | + 'amount' => wc_format_decimal($amount, $this->dp), |
|
824 | 824 | ); |
825 | 825 | |
826 | 826 | $items[] = $item; |
827 | 827 | } |
828 | 828 | |
829 | 829 | // Default show only subtotal instead of itemization. |
830 | - if ( apply_filters( 'wc_stripe_apple_pay_disable_itemization', true ) ) { |
|
830 | + if (apply_filters('wc_stripe_apple_pay_disable_itemization', true)) { |
|
831 | 831 | $items = array(); |
832 | 832 | $items[] = array( |
833 | 833 | 'type' => 'final', |
834 | - 'label' => esc_html( __( 'Sub-Total', 'woocommerce-gateway-stripe' ) ), |
|
835 | - 'amount' => wc_format_decimal( $subtotal, $this->dp ), |
|
834 | + 'label' => esc_html(__('Sub-Total', 'woocommerce-gateway-stripe')), |
|
835 | + 'amount' => wc_format_decimal($subtotal, $this->dp), |
|
836 | 836 | ); |
837 | 837 | } |
838 | 838 | |
839 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $this->dp ); |
|
840 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp ); |
|
841 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $this->dp ); |
|
842 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $this->dp ) + $discounts; |
|
843 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping - $discounts, $this->dp ); |
|
839 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $this->dp); |
|
840 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp); |
|
841 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $this->dp); |
|
842 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $this->dp) + $discounts; |
|
843 | + $order_total = wc_format_decimal($item_total + $tax + $shipping - $discounts, $this->dp); |
|
844 | 844 | |
845 | - if ( wc_tax_enabled() ) { |
|
845 | + if (wc_tax_enabled()) { |
|
846 | 846 | $items[] = array( |
847 | 847 | 'type' => 'final', |
848 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
848 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
849 | 849 | 'amount' => $tax, |
850 | 850 | ); |
851 | 851 | } |
852 | 852 | |
853 | - if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled ) { |
|
853 | + if (WC()->cart->needs_shipping() && $this->is_shipping_enabled) { |
|
854 | 854 | $items[] = array( |
855 | 855 | 'type' => 'final', |
856 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
856 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
857 | 857 | 'amount' => $shipping, |
858 | 858 | ); |
859 | 859 | } |
860 | 860 | |
861 | - if ( WC()->cart->has_discount() ) { |
|
861 | + if (WC()->cart->has_discount()) { |
|
862 | 862 | $items[] = array( |
863 | 863 | 'type' => 'final', |
864 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
864 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
865 | 865 | 'amount' => '-' . $discounts, |
866 | 866 | ); |
867 | 867 | } |
868 | 868 | |
869 | - return array( 'line_items' => $items, 'total' => $order_total ); |
|
869 | + return array('line_items' => $items, 'total' => $order_total); |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | /** |
@@ -877,28 +877,28 @@ discard block |
||
877 | 877 | * @param array $data |
878 | 878 | * @return object $order |
879 | 879 | */ |
880 | - public function create_order( $data = array() ) { |
|
881 | - if ( empty( $data ) ) { |
|
882 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
880 | + public function create_order($data = array()) { |
|
881 | + if (empty($data)) { |
|
882 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
883 | 883 | } |
884 | 884 | |
885 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
886 | - define( 'WOOCOMMERCE_CART', true ); |
|
885 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
886 | + define('WOOCOMMERCE_CART', true); |
|
887 | 887 | } |
888 | 888 | |
889 | 889 | $order = wc_create_order(); |
890 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
890 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
891 | 891 | |
892 | - if ( is_wp_error( $order ) ) { |
|
893 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
894 | - } elseif ( false === $order ) { |
|
895 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) ); |
|
892 | + if (is_wp_error($order)) { |
|
893 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
894 | + } elseif (false === $order) { |
|
895 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521)); |
|
896 | 896 | } else { |
897 | - do_action( 'woocommerce_new_order', $order_id ); |
|
897 | + do_action('woocommerce_new_order', $order_id); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | // Store the line items to the new/resumed order |
901 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
901 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
902 | 902 | $item_id = $order->add_product( |
903 | 903 | $values['data'], |
904 | 904 | $values['quantity'], |
@@ -914,25 +914,25 @@ discard block |
||
914 | 914 | ) |
915 | 915 | ); |
916 | 916 | |
917 | - if ( ! $item_id ) { |
|
918 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) ); |
|
917 | + if ( ! $item_id) { |
|
918 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525)); |
|
919 | 919 | } |
920 | 920 | |
921 | 921 | // Allow plugins to add order item meta |
922 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
923 | - do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key ); |
|
922 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
923 | + do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key); |
|
924 | 924 | } else { |
925 | - do_action( 'woocommerce_new_order_item', $item_id, wc_get_product( $item_id ), $order->get_id() ); |
|
925 | + do_action('woocommerce_new_order_item', $item_id, wc_get_product($item_id), $order->get_id()); |
|
926 | 926 | } |
927 | 927 | } |
928 | 928 | |
929 | 929 | // Store fees |
930 | - foreach ( WC()->cart->get_fees() as $fee_key => $fee ) { |
|
931 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
932 | - $item_id = $order->add_fee( $fee ); |
|
930 | + foreach (WC()->cart->get_fees() as $fee_key => $fee) { |
|
931 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
932 | + $item_id = $order->add_fee($fee); |
|
933 | 933 | } else { |
934 | 934 | $item = new WC_Order_Item_Fee(); |
935 | - $item->set_props( array( |
|
935 | + $item->set_props(array( |
|
936 | 936 | 'name' => $fee->name, |
937 | 937 | 'tax_class' => $fee->taxable ? $fee->tax_class : 0, |
938 | 938 | 'total' => $fee->amount, |
@@ -941,79 +941,79 @@ discard block |
||
941 | 941 | 'total' => $fee->tax_data, |
942 | 942 | ), |
943 | 943 | 'order_id' => $order->get_id(), |
944 | - ) ); |
|
944 | + )); |
|
945 | 945 | $item_id = $item->save(); |
946 | - $order->add_item( $item ); |
|
946 | + $order->add_item($item); |
|
947 | 947 | } |
948 | 948 | |
949 | - if ( ! $item_id ) { |
|
950 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) ); |
|
949 | + if ( ! $item_id) { |
|
950 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526)); |
|
951 | 951 | } |
952 | 952 | |
953 | 953 | // Allow plugins to add order item meta to fees |
954 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
955 | - do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key ); |
|
954 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
955 | + do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key); |
|
956 | 956 | } else { |
957 | - do_action( 'woocommerce_new_order_item', $item_id, $fee, $order->get_id() ); |
|
957 | + do_action('woocommerce_new_order_item', $item_id, $fee, $order->get_id()); |
|
958 | 958 | } |
959 | 959 | } |
960 | 960 | |
961 | 961 | // Store tax rows |
962 | - foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { |
|
963 | - $tax_amount = WC()->cart->get_tax_amount( $tax_rate_id ); |
|
964 | - $shipping_tax_amount = WC()->cart->get_shipping_tax_amount( $tax_rate_id ); |
|
962 | + foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) { |
|
963 | + $tax_amount = WC()->cart->get_tax_amount($tax_rate_id); |
|
964 | + $shipping_tax_amount = WC()->cart->get_shipping_tax_amount($tax_rate_id); |
|
965 | 965 | |
966 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
967 | - $item_id = $order->add_tax( $tax_rate_id, $tax_amount, $shipping_tax_amount ); |
|
966 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
967 | + $item_id = $order->add_tax($tax_rate_id, $tax_amount, $shipping_tax_amount); |
|
968 | 968 | } else { |
969 | 969 | $item = new WC_Order_Item_Tax(); |
970 | - $item->set_props( array( |
|
970 | + $item->set_props(array( |
|
971 | 971 | 'rate_id' => $tax_rate_id, |
972 | 972 | 'tax_total' => $tax_amount, |
973 | 973 | 'shipping_tax_total' => $shipping_tax_amount, |
974 | - ) ); |
|
975 | - $item->set_rate( $tax_rate_id ); |
|
976 | - $item->set_order_id( $order->get_id() ); |
|
974 | + )); |
|
975 | + $item->set_rate($tax_rate_id); |
|
976 | + $item->set_order_id($order->get_id()); |
|
977 | 977 | $item_id = $item->save(); |
978 | - $order->add_item( $item ); |
|
978 | + $order->add_item($item); |
|
979 | 979 | } |
980 | 980 | |
981 | - if ( $tax_rate_id && ! $item_id && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { |
|
982 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) ); |
|
981 | + if ($tax_rate_id && ! $item_id && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) { |
|
982 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528)); |
|
983 | 983 | } |
984 | 984 | } |
985 | 985 | |
986 | 986 | // Store coupons |
987 | - $discount = WC()->cart->get_coupon_discount_amount( $code ); |
|
988 | - $discount_tax = WC()->cart->get_coupon_discount_tax_amount( $code ); |
|
987 | + $discount = WC()->cart->get_coupon_discount_amount($code); |
|
988 | + $discount_tax = WC()->cart->get_coupon_discount_tax_amount($code); |
|
989 | 989 | |
990 | - foreach ( WC()->cart->get_coupons() as $code => $coupon ) { |
|
991 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
992 | - $coupon_id = $order->add_coupon( $code, $discount, $discount_tax ); |
|
990 | + foreach (WC()->cart->get_coupons() as $code => $coupon) { |
|
991 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
992 | + $coupon_id = $order->add_coupon($code, $discount, $discount_tax); |
|
993 | 993 | } else { |
994 | 994 | $item = new WC_Order_Item_Coupon(); |
995 | - $item->set_props( array( |
|
995 | + $item->set_props(array( |
|
996 | 996 | 'code' => $code, |
997 | 997 | 'discount' => $discount, |
998 | 998 | 'discount_tax' => $discount_tax, |
999 | 999 | 'order_id' => $order->get_id(), |
1000 | - ) ); |
|
1000 | + )); |
|
1001 | 1001 | $coupon_id = $item->save(); |
1002 | - $order->add_item( $item ); |
|
1002 | + $order->add_item($item); |
|
1003 | 1003 | } |
1004 | 1004 | |
1005 | - if ( ! $coupon_id ) { |
|
1006 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) ); |
|
1005 | + if ( ! $coupon_id) { |
|
1006 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529)); |
|
1007 | 1007 | } |
1008 | 1008 | } |
1009 | 1009 | |
1010 | 1010 | // Billing address |
1011 | 1011 | $billing_address = array(); |
1012 | - if ( ! empty( $data['token']['card'] ) ) { |
|
1012 | + if ( ! empty($data['token']['card'])) { |
|
1013 | 1013 | // Name from Stripe is a full name string. |
1014 | - $name = explode( ' ', $data['token']['card']['name'] ); |
|
1015 | - $lastname = array_pop( $name ); |
|
1016 | - $firstname = implode( ' ', $name ); |
|
1014 | + $name = explode(' ', $data['token']['card']['name']); |
|
1015 | + $lastname = array_pop($name); |
|
1016 | + $firstname = implode(' ', $name); |
|
1017 | 1017 | $billing_address['first_name'] = $firstname; |
1018 | 1018 | $billing_address['last_name'] = $lastname; |
1019 | 1019 | $billing_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1028,7 +1028,7 @@ discard block |
||
1028 | 1028 | |
1029 | 1029 | // Shipping address. |
1030 | 1030 | $shipping_address = array(); |
1031 | - if ( WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty( $data['shippingContact'] ) ) { |
|
1031 | + if (WC()->cart->needs_shipping() && $this->is_shipping_enabled && ! empty($data['shippingContact'])) { |
|
1032 | 1032 | $shipping_address['first_name'] = $data['shippingContact']['givenName']; |
1033 | 1033 | $shipping_address['last_name'] = $data['shippingContact']['familyName']; |
1034 | 1034 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1039,7 +1039,7 @@ discard block |
||
1039 | 1039 | $shipping_address['city'] = $data['shippingContact']['locality']; |
1040 | 1040 | $shipping_address['state'] = $data['shippingContact']['administrativeArea']; |
1041 | 1041 | $shipping_address['postcode'] = $data['shippingContact']['postalCode']; |
1042 | - } elseif ( ! empty( $data['shippingContact'] ) ) { |
|
1042 | + } elseif ( ! empty($data['shippingContact'])) { |
|
1043 | 1043 | $shipping_address['first_name'] = $firstname; |
1044 | 1044 | $shipping_address['last_name'] = $lastname; |
1045 | 1045 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -1052,33 +1052,33 @@ discard block |
||
1052 | 1052 | $shipping_address['postcode'] = $data['token']['card']['address_zip']; |
1053 | 1053 | } |
1054 | 1054 | |
1055 | - $order->set_address( $billing_address, 'billing' ); |
|
1056 | - $order->set_address( $shipping_address, 'shipping' ); |
|
1055 | + $order->set_address($billing_address, 'billing'); |
|
1056 | + $order->set_address($shipping_address, 'shipping'); |
|
1057 | 1057 | |
1058 | - WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() ); |
|
1058 | + WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages()); |
|
1059 | 1059 | |
1060 | 1060 | // Get the rate object selected by user. |
1061 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
1062 | - foreach ( $package['rates'] as $key => $rate ) { |
|
1061 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
1062 | + foreach ($package['rates'] as $key => $rate) { |
|
1063 | 1063 | // Loop through user chosen shipping methods. |
1064 | - foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) { |
|
1065 | - if ( $method === $key ) { |
|
1066 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
1067 | - $order->add_shipping( $rate ); |
|
1064 | + foreach (WC()->session->get('chosen_shipping_methods') as $method) { |
|
1065 | + if ($method === $key) { |
|
1066 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
1067 | + $order->add_shipping($rate); |
|
1068 | 1068 | } else { |
1069 | 1069 | $item = new WC_Order_Item_Shipping(); |
1070 | - $item->set_props( array( |
|
1070 | + $item->set_props(array( |
|
1071 | 1071 | 'method_title' => $rate->label, |
1072 | 1072 | 'method_id' => $rate->id, |
1073 | - 'total' => wc_format_decimal( $rate->cost ), |
|
1073 | + 'total' => wc_format_decimal($rate->cost), |
|
1074 | 1074 | 'taxes' => $rate->taxes, |
1075 | 1075 | 'order_id' => $order->get_id(), |
1076 | - ) ); |
|
1077 | - foreach ( $rate->get_meta_data() as $key => $value ) { |
|
1078 | - $item->add_meta_data( $key, $value, true ); |
|
1076 | + )); |
|
1077 | + foreach ($rate->get_meta_data() as $key => $value) { |
|
1078 | + $item->add_meta_data($key, $value, true); |
|
1079 | 1079 | } |
1080 | 1080 | $item->save(); |
1081 | - $order->add_item( $item ); |
|
1081 | + $order->add_item($item); |
|
1082 | 1082 | } |
1083 | 1083 | } |
1084 | 1084 | } |
@@ -1086,37 +1086,37 @@ discard block |
||
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
1089 | - $order->set_payment_method( $available_gateways['stripe'] ); |
|
1089 | + $order->set_payment_method($available_gateways['stripe']); |
|
1090 | 1090 | WC()->cart->calculate_totals(); |
1091 | 1091 | |
1092 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
1093 | - $order->set_total( WC()->cart->shipping_total, 'shipping' ); |
|
1094 | - $order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' ); |
|
1095 | - $order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' ); |
|
1096 | - $order->set_total( WC()->cart->tax_total, 'tax' ); |
|
1097 | - $order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' ); |
|
1098 | - $order->set_total( WC()->cart->total ); |
|
1092 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
1093 | + $order->set_total(WC()->cart->shipping_total, 'shipping'); |
|
1094 | + $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount'); |
|
1095 | + $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax'); |
|
1096 | + $order->set_total(WC()->cart->tax_total, 'tax'); |
|
1097 | + $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax'); |
|
1098 | + $order->set_total(WC()->cart->total); |
|
1099 | 1099 | } else { |
1100 | - $order->set_shipping_total( WC()->cart->shipping_total ); |
|
1101 | - $order->set_discount_total( WC()->cart->get_cart_discount_total() ); |
|
1102 | - $order->set_discount_tax( WC()->cart->get_cart_discount_tax_total() ); |
|
1103 | - $order->set_cart_tax( WC()->cart->tax_total ); |
|
1104 | - $order->set_shipping_tax( WC()->cart->shipping_tax_total ); |
|
1105 | - |
|
1106 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $this->dp ); |
|
1107 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp ); |
|
1108 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $this->dp ); |
|
1109 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $this->dp ) + $discounts; |
|
1110 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping - $discounts, $this->dp ); |
|
1111 | - |
|
1112 | - $order->set_total( $order_total ); |
|
1100 | + $order->set_shipping_total(WC()->cart->shipping_total); |
|
1101 | + $order->set_discount_total(WC()->cart->get_cart_discount_total()); |
|
1102 | + $order->set_discount_tax(WC()->cart->get_cart_discount_tax_total()); |
|
1103 | + $order->set_cart_tax(WC()->cart->tax_total); |
|
1104 | + $order->set_shipping_tax(WC()->cart->shipping_tax_total); |
|
1105 | + |
|
1106 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $this->dp); |
|
1107 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $this->dp); |
|
1108 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $this->dp); |
|
1109 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $this->dp) + $discounts; |
|
1110 | + $order_total = wc_format_decimal($item_total + $tax + $shipping - $discounts, $this->dp); |
|
1111 | + |
|
1112 | + $order->set_total($order_total); |
|
1113 | 1113 | $order->save(); |
1114 | 1114 | } |
1115 | 1115 | |
1116 | 1116 | // If we got here, the order was created without problems! |
1117 | - wc_transaction_query( 'commit' ); |
|
1117 | + wc_transaction_query('commit'); |
|
1118 | 1118 | |
1119 | - do_action( 'woocommerce_checkout_update_order_meta', $order_id, array() ); |
|
1119 | + do_action('woocommerce_checkout_update_order_meta', $order_id, array()); |
|
1120 | 1120 | |
1121 | 1121 | return $order; |
1122 | 1122 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @return float|int |
19 | 19 | */ |
20 | - public static function get_stripe_amount( $total, $currency = '' ) { |
|
21 | - if ( ! $currency ) { |
|
20 | + public static function get_stripe_amount($total, $currency = '') { |
|
21 | + if ( ! $currency) { |
|
22 | 22 | $currency = get_woocommerce_currency(); |
23 | 23 | } |
24 | - switch ( strtoupper( $currency ) ) { |
|
24 | + switch (strtoupper($currency)) { |
|
25 | 25 | // Zero decimal currencies. |
26 | 26 | case 'BIF' : |
27 | 27 | case 'CLP' : |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | case 'XAF' : |
39 | 39 | case 'XOF' : |
40 | 40 | case 'XPF' : |
41 | - $total = absint( $total ); |
|
41 | + $total = absint($total); |
|
42 | 42 | break; |
43 | 43 | default : |
44 | - $total = round( $total, 2 ) * 100; // In cents. |
|
44 | + $total = round($total, 2) * 100; // In cents. |
|
45 | 45 | break; |
46 | 46 | } |
47 | 47 | return $total; |
@@ -55,20 +55,20 @@ discard block |
||
55 | 55 | * @return array |
56 | 56 | */ |
57 | 57 | public static function get_localized_messages() { |
58 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
59 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
60 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
61 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
62 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
63 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
64 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
65 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
66 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
67 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
68 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
69 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
70 | - 'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ), |
|
71 | - ) ); |
|
58 | + return apply_filters('wc_stripe_localized_messages', array( |
|
59 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
60 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
61 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
62 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
63 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
64 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
65 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
66 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
67 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
68 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
69 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
70 | + 'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'), |
|
71 | + )); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -103,24 +103,24 @@ discard block |
||
103 | 103 | * @param object $balance_transaction |
104 | 104 | * @param string $type Type of number to format |
105 | 105 | */ |
106 | - public static function format_number( $balance_transaction, $type = 'fee' ) { |
|
107 | - if ( ! is_object( $balance_transaction ) ) { |
|
106 | + public static function format_number($balance_transaction, $type = 'fee') { |
|
107 | + if ( ! is_object($balance_transaction)) { |
|
108 | 108 | return; |
109 | 109 | } |
110 | 110 | |
111 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
112 | - if ( 'fee' === $type ) { |
|
111 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
112 | + if ('fee' === $type) { |
|
113 | 113 | return $balance_transaction->fee; |
114 | 114 | } |
115 | 115 | |
116 | 116 | return $balance_transaction->net; |
117 | 117 | } |
118 | 118 | |
119 | - if ( 'fee' === $type ) { |
|
120 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
119 | + if ('fee' === $type) { |
|
120 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
121 | 121 | } |
122 | 122 | |
123 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
123 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public static function get_minimum_amount() { |
130 | 130 | // Check order amount |
131 | - switch ( get_woocommerce_currency() ) { |
|
131 | + switch (get_woocommerce_currency()) { |
|
132 | 132 | case 'USD': |
133 | 133 | case 'CAD': |
134 | 134 | case 'EUR': |
@@ -173,14 +173,14 @@ discard block |
||
173 | 173 | * @param string $method The payment method to get the settings from. |
174 | 174 | * @param string $setting The name of the setting to get. |
175 | 175 | */ |
176 | - public static function get_settings( $method = null, $setting = null ) { |
|
177 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
176 | + public static function get_settings($method = null, $setting = null) { |
|
177 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
178 | 178 | |
179 | - if ( null === $setting ) { |
|
179 | + if (null === $setting) { |
|
180 | 180 | return $all_settings; |
181 | 181 | } |
182 | 182 | |
183 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
183 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @return bool |
192 | 192 | */ |
193 | 193 | public static function is_pre_30() { |
194 | - return version_compare( WC_VERSION, '3.0.0', '<' ); |
|
194 | + return version_compare(WC_VERSION, '3.0.0', '<'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @return string |
205 | 205 | */ |
206 | 206 | public static function get_webhook_url() { |
207 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
207 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -214,9 +214,9 @@ discard block |
||
214 | 214 | * @version 4.0.0 |
215 | 215 | * @param string $source_id |
216 | 216 | */ |
217 | - public static function get_order_by_source_id( $source_id ) { |
|
217 | + public static function get_order_by_source_id($source_id) { |
|
218 | 218 | global $wpdb; |
219 | 219 | |
220 | - return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id ) ); |
|
220 | + return $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id)); |
|
221 | 221 | } |
222 | 222 | } |