@@ -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,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_giropay'; |
60 | - $this->method_title = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $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 | + $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')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_giropay_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_giropay_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | * @return array |
170 | 170 | */ |
171 | 171 | public function payment_icons() { |
172 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
172 | + return apply_filters('wc_stripe_payment_icons', array( |
|
173 | 173 | 'giropay' => '<i class="stripe-pf stripe-pf-giropay stripe-pf-right" alt="Giropay" aria-hidden="true"></i>', |
174 | - ) ); |
|
174 | + )); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | $icons_str .= $icons['giropay']; |
190 | 190 | |
191 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
191 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -199,19 +199,19 @@ discard block |
||
199 | 199 | * @access public |
200 | 200 | */ |
201 | 201 | public function payment_scripts() { |
202 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
202 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
203 | 203 | return; |
204 | 204 | } |
205 | 205 | |
206 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
207 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
206 | + wp_enqueue_style('stripe_paymentfonts'); |
|
207 | + wp_enqueue_script('woocommerce_stripe'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * Initialize Gateway Settings Form Fields. |
212 | 212 | */ |
213 | 213 | public function init_form_fields() { |
214 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' ); |
|
214 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php'); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -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-giropay-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 | echo '</div>'; |
@@ -254,24 +254,24 @@ discard block |
||
254 | 254 | * @param object $order |
255 | 255 | * @return mixed |
256 | 256 | */ |
257 | - public function create_source( $order ) { |
|
257 | + public function create_source($order) { |
|
258 | 258 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
259 | 259 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
260 | - $return_url = $this->get_stripe_return_url( $order ); |
|
260 | + $return_url = $this->get_stripe_return_url($order); |
|
261 | 261 | $post_data = array(); |
262 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
263 | - $post_data['currency'] = strtolower( $currency ); |
|
262 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
263 | + $post_data['currency'] = strtolower($currency); |
|
264 | 264 | $post_data['type'] = 'giropay'; |
265 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
266 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
265 | + $post_data['owner'] = $this->get_owner_details($order); |
|
266 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
267 | 267 | |
268 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
269 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
268 | + if ( ! empty($this->statement_descriptor)) { |
|
269 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
270 | 270 | } |
271 | 271 | |
272 | - WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' ); |
|
272 | + WC_Stripe_Logger::log('Info: Begin creating Giropay source'); |
|
273 | 273 | |
274 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
274 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -285,51 +285,51 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return array|void |
287 | 287 | */ |
288 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
288 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
289 | 289 | try { |
290 | - $order = wc_get_order( $order_id ); |
|
290 | + $order = wc_get_order($order_id); |
|
291 | 291 | |
292 | 292 | // This will throw exception if not valid. |
293 | - $this->validate_minimum_order_amount( $order ); |
|
293 | + $this->validate_minimum_order_amount($order); |
|
294 | 294 | |
295 | 295 | // This comes from the create account checkbox in the checkout page. |
296 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
296 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
297 | 297 | |
298 | - if ( $create_account ) { |
|
298 | + if ($create_account) { |
|
299 | 299 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
300 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
300 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
301 | 301 | $new_stripe_customer->create_customer(); |
302 | 302 | } |
303 | 303 | |
304 | - $response = $this->create_source( $order ); |
|
304 | + $response = $this->create_source($order); |
|
305 | 305 | |
306 | - if ( ! empty( $response->error ) ) { |
|
307 | - $order->add_order_note( $response->error->message ); |
|
306 | + if ( ! empty($response->error)) { |
|
307 | + $order->add_order_note($response->error->message); |
|
308 | 308 | |
309 | - throw new Exception( $response->error->message ); |
|
309 | + throw new Exception($response->error->message); |
|
310 | 310 | } |
311 | 311 | |
312 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
313 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
312 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
313 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
314 | 314 | } else { |
315 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
315 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
316 | 316 | $order->save(); |
317 | 317 | } |
318 | 318 | |
319 | - WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' ); |
|
319 | + WC_Stripe_Logger::log('Info: Redirecting to Giropay...'); |
|
320 | 320 | |
321 | 321 | return array( |
322 | 322 | 'result' => 'success', |
323 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
323 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
324 | 324 | ); |
325 | - } catch ( Exception $e ) { |
|
326 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
327 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
325 | + } catch (Exception $e) { |
|
326 | + wc_add_notice($e->getMessage(), 'error'); |
|
327 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
328 | 328 | |
329 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
329 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
330 | 330 | |
331 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
332 | - $this->send_failed_order_email( $order_id ); |
|
331 | + if ($order->has_status(array('pending', 'failed'))) { |
|
332 | + $this->send_failed_order_email($order_id); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | return array( |
@@ -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,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_ideal'; |
60 | - $this->method_title = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $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 | + $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')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_ideal_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_ideal_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | * @return array |
170 | 170 | */ |
171 | 171 | public function payment_icons() { |
172 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
172 | + return apply_filters('wc_stripe_payment_icons', array( |
|
173 | 173 | 'ideal' => '<i class="stripe-pf stripe-pf-ideal stripe-pf-right" alt="iDeal" aria-hidden="true"></i>', |
174 | - ) ); |
|
174 | + )); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | $icons_str .= $icons['ideal']; |
190 | 190 | |
191 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
191 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -199,19 +199,19 @@ discard block |
||
199 | 199 | * @access public |
200 | 200 | */ |
201 | 201 | public function payment_scripts() { |
202 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
202 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
203 | 203 | return; |
204 | 204 | } |
205 | 205 | |
206 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
207 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
206 | + wp_enqueue_style('stripe_paymentfonts'); |
|
207 | + wp_enqueue_script('woocommerce_stripe'); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * Initialize Gateway Settings Form Fields. |
212 | 212 | */ |
213 | 213 | public function init_form_fields() { |
214 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' ); |
|
214 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php'); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -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-ideal-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 | echo '</div>'; |
@@ -254,24 +254,24 @@ discard block |
||
254 | 254 | * @param object $order |
255 | 255 | * @return mixed |
256 | 256 | */ |
257 | - public function create_source( $order ) { |
|
257 | + public function create_source($order) { |
|
258 | 258 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
259 | 259 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
260 | - $return_url = $this->get_stripe_return_url( $order ); |
|
260 | + $return_url = $this->get_stripe_return_url($order); |
|
261 | 261 | $post_data = array(); |
262 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
263 | - $post_data['currency'] = strtolower( $currency ); |
|
262 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
263 | + $post_data['currency'] = strtolower($currency); |
|
264 | 264 | $post_data['type'] = 'ideal'; |
265 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
266 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
265 | + $post_data['owner'] = $this->get_owner_details($order); |
|
266 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
267 | 267 | |
268 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
269 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
268 | + if ( ! empty($this->statement_descriptor)) { |
|
269 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
270 | 270 | } |
271 | 271 | |
272 | - WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' ); |
|
272 | + WC_Stripe_Logger::log('Info: Begin creating iDeal source'); |
|
273 | 273 | |
274 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
274 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -285,51 +285,51 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return array|void |
287 | 287 | */ |
288 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
288 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
289 | 289 | try { |
290 | - $order = wc_get_order( $order_id ); |
|
290 | + $order = wc_get_order($order_id); |
|
291 | 291 | |
292 | 292 | // This will throw exception if not valid. |
293 | - $this->validate_minimum_order_amount( $order ); |
|
293 | + $this->validate_minimum_order_amount($order); |
|
294 | 294 | |
295 | 295 | // This comes from the create account checkbox in the checkout page. |
296 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
296 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
297 | 297 | |
298 | - if ( $create_account ) { |
|
298 | + if ($create_account) { |
|
299 | 299 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
300 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
300 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
301 | 301 | $new_stripe_customer->create_customer(); |
302 | 302 | } |
303 | 303 | |
304 | - $response = $this->create_source( $order ); |
|
304 | + $response = $this->create_source($order); |
|
305 | 305 | |
306 | - if ( ! empty( $response->error ) ) { |
|
307 | - $order->add_order_note( $response->error->message ); |
|
306 | + if ( ! empty($response->error)) { |
|
307 | + $order->add_order_note($response->error->message); |
|
308 | 308 | |
309 | - throw new Exception( $response->error->message ); |
|
309 | + throw new Exception($response->error->message); |
|
310 | 310 | } |
311 | 311 | |
312 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
313 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
312 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
313 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
314 | 314 | } else { |
315 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
315 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
316 | 316 | $order->save(); |
317 | 317 | } |
318 | 318 | |
319 | - WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' ); |
|
319 | + WC_Stripe_Logger::log('Info: Redirecting to iDeal...'); |
|
320 | 320 | |
321 | 321 | return array( |
322 | 322 | 'result' => 'success', |
323 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
323 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
324 | 324 | ); |
325 | - } catch ( Exception $e ) { |
|
326 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
327 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
325 | + } catch (Exception $e) { |
|
326 | + wc_add_notice($e->getMessage(), 'error'); |
|
327 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
328 | 328 | |
329 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
329 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
330 | 330 | |
331 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
332 | - $this->send_failed_order_email( $order_id ); |
|
331 | + if ($order->has_status(array('pending', 'failed'))) { |
|
332 | + $this->send_failed_order_email($order_id); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | return array( |
@@ -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,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_p24'; |
60 | - $this->method_title = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $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 | + $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')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_p24_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_p24_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | 146 | 'PLN', |
147 | - ) ); |
|
147 | + )); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @return bool |
156 | 156 | */ |
157 | 157 | public function is_available() { |
158 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
158 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
159 | 159 | return false; |
160 | 160 | } |
161 | 161 | |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * @return array |
171 | 171 | */ |
172 | 172 | public function payment_icons() { |
173 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
173 | + return apply_filters('wc_stripe_payment_icons', array( |
|
174 | 174 | 'p24' => '<i class="stripe-pf stripe-pf-p24 stripe-pf-right" alt="P24" aria-hidden="true"></i>', |
175 | - ) ); |
|
175 | + )); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | |
190 | 190 | $icons_str .= $icons['p24']; |
191 | 191 | |
192 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
192 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -200,19 +200,19 @@ discard block |
||
200 | 200 | * @access public |
201 | 201 | */ |
202 | 202 | public function payment_scripts() { |
203 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
203 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
204 | 204 | return; |
205 | 205 | } |
206 | 206 | |
207 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
208 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
207 | + wp_enqueue_style('stripe_paymentfonts'); |
|
208 | + wp_enqueue_script('woocommerce_stripe'); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | 212 | * Initialize Gateway Settings Form Fields. |
213 | 213 | */ |
214 | 214 | public function init_form_fields() { |
215 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php' ); |
|
215 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php'); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -223,25 +223,25 @@ discard block |
||
223 | 223 | $total = WC()->cart->total; |
224 | 224 | |
225 | 225 | // If paying from order, we need to get total from order not cart. |
226 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
227 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
226 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
227 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
228 | 228 | $total = $order->get_total(); |
229 | 229 | } |
230 | 230 | |
231 | - if ( is_add_payment_method_page() ) { |
|
232 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
233 | - $total = ''; |
|
231 | + if (is_add_payment_method_page()) { |
|
232 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
233 | + $total = ''; |
|
234 | 234 | } else { |
235 | 235 | $pay_button_text = ''; |
236 | 236 | } |
237 | 237 | |
238 | 238 | echo '<div |
239 | 239 | id="stripe-p24-payment-data" |
240 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
241 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
240 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
241 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
242 | 242 | |
243 | - if ( $this->description ) { |
|
244 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
243 | + if ($this->description) { |
|
244 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | echo '</div>'; |
@@ -255,20 +255,20 @@ discard block |
||
255 | 255 | * @param object $order |
256 | 256 | * @return mixed |
257 | 257 | */ |
258 | - public function create_source( $order ) { |
|
258 | + public function create_source($order) { |
|
259 | 259 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
260 | 260 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
261 | - $return_url = $this->get_stripe_return_url( $order ); |
|
261 | + $return_url = $this->get_stripe_return_url($order); |
|
262 | 262 | $post_data = array(); |
263 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
264 | - $post_data['currency'] = strtolower( $currency ); |
|
263 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
264 | + $post_data['currency'] = strtolower($currency); |
|
265 | 265 | $post_data['type'] = 'p24'; |
266 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
267 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
266 | + $post_data['owner'] = $this->get_owner_details($order); |
|
267 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
268 | 268 | |
269 | - WC_Stripe_Logger::log( 'Info: Begin creating P24 source' ); |
|
269 | + WC_Stripe_Logger::log('Info: Begin creating P24 source'); |
|
270 | 270 | |
271 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
271 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -282,51 +282,51 @@ discard block |
||
282 | 282 | * |
283 | 283 | * @return array|void |
284 | 284 | */ |
285 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
285 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
286 | 286 | try { |
287 | - $order = wc_get_order( $order_id ); |
|
287 | + $order = wc_get_order($order_id); |
|
288 | 288 | |
289 | 289 | // This will throw exception if not valid. |
290 | - $this->validate_minimum_order_amount( $order ); |
|
290 | + $this->validate_minimum_order_amount($order); |
|
291 | 291 | |
292 | 292 | // This comes from the create account checkbox in the checkout page. |
293 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
293 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
294 | 294 | |
295 | - if ( $create_account ) { |
|
295 | + if ($create_account) { |
|
296 | 296 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
297 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
297 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
298 | 298 | $new_stripe_customer->create_customer(); |
299 | 299 | } |
300 | 300 | |
301 | - $response = $this->create_source( $order ); |
|
301 | + $response = $this->create_source($order); |
|
302 | 302 | |
303 | - if ( ! empty( $response->error ) ) { |
|
304 | - $order->add_order_note( $response->error->message ); |
|
303 | + if ( ! empty($response->error)) { |
|
304 | + $order->add_order_note($response->error->message); |
|
305 | 305 | |
306 | - throw new Exception( $response->error->message ); |
|
306 | + throw new Exception($response->error->message); |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
310 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
309 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
310 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
311 | 311 | } else { |
312 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
312 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
313 | 313 | $order->save(); |
314 | 314 | } |
315 | 315 | |
316 | - WC_Stripe_Logger::log( 'Info: Redirecting to P24...' ); |
|
316 | + WC_Stripe_Logger::log('Info: Redirecting to P24...'); |
|
317 | 317 | |
318 | 318 | return array( |
319 | 319 | 'result' => 'success', |
320 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
320 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
321 | 321 | ); |
322 | - } catch ( Exception $e ) { |
|
323 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
324 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
322 | + } catch (Exception $e) { |
|
323 | + wc_add_notice($e->getMessage(), 'error'); |
|
324 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
325 | 325 | |
326 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
326 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
327 | 327 | |
328 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
329 | - $this->send_failed_order_email( $order_id ); |
|
328 | + if ($order->has_status(array('pending', 'failed'))) { |
|
329 | + $this->send_failed_order_email($order_id); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | return array( |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if ( ! defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * @param string $deprecated Deprecated since WooCommerce 3.0 |
36 | 36 | * @return string |
37 | 37 | */ |
38 | - public function get_display_name( $deprecated = '' ) { |
|
38 | + public function get_display_name($deprecated = '') { |
|
39 | 39 | $display = sprintf( |
40 | 40 | /* translators: last 4 digits of IBAN account */ |
41 | - __( 'SEPA IBAN ending in %s', 'woocommerce-gateway-stripe' ), |
|
41 | + __('SEPA IBAN ending in %s', 'woocommerce-gateway-stripe'), |
|
42 | 42 | $this->get_last4() |
43 | 43 | ); |
44 | 44 | |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | * @return boolean True if the passed data is valid |
67 | 67 | */ |
68 | 68 | public function validate() { |
69 | - if ( false === parent::validate() ) { |
|
69 | + if (false === parent::validate()) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | - if ( ! $this->get_last4( 'edit' ) ) { |
|
73 | + if ( ! $this->get_last4('edit')) { |
|
74 | 74 | return false; |
75 | 75 | } |
76 | 76 | |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * @param string $context |
86 | 86 | * @return string Last 4 digits |
87 | 87 | */ |
88 | - public function get_last4( $context = 'view' ) { |
|
89 | - return $this->get_prop( 'last4', $context ); |
|
88 | + public function get_last4($context = 'view') { |
|
89 | + return $this->get_prop('last4', $context); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @version 4.0.0 |
96 | 96 | * @param string $last4 |
97 | 97 | */ |
98 | - public function set_last4( $last4 ) { |
|
99 | - $this->set_prop( 'last4', $last4 ); |
|
98 | + public function set_last4($last4) { |
|
99 | + $this->set_prop('last4', $last4); |
|
100 | 100 | } |
101 | 101 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | public function __construct() { |
22 | 22 | self::$_this = $this; |
23 | 23 | |
24 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
25 | - add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'get_account_saved_payment_methods_list_item_sepa' ), 10, 2 ); |
|
26 | - add_filter( 'woocommerce_get_credit_card_type_label', array( $this, 'normalize_sepa_label' ) ); |
|
27 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
28 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
24 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
25 | + add_filter('woocommerce_payment_methods_list_item', array($this, 'get_account_saved_payment_methods_list_item_sepa'), 10, 2); |
|
26 | + add_filter('woocommerce_get_credit_card_type_label', array($this, 'normalize_sepa_label')); |
|
27 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
28 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | * @param string $label |
47 | 47 | * @return string $label |
48 | 48 | */ |
49 | - public function normalize_sepa_label( $label ) { |
|
50 | - if ( 'sepa iban' === strtolower( $label ) ) { |
|
49 | + public function normalize_sepa_label($label) { |
|
50 | + if ('sepa iban' === strtolower($label)) { |
|
51 | 51 | return 'SEPA IBAN'; |
52 | 52 | } |
53 | 53 | |
@@ -62,67 +62,67 @@ discard block |
||
62 | 62 | * @param array $tokens |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) { |
|
66 | - if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
65 | + public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) { |
|
66 | + if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) { |
|
67 | 67 | $stored_tokens = array(); |
68 | 68 | |
69 | - foreach ( $tokens as $token ) { |
|
69 | + foreach ($tokens as $token) { |
|
70 | 70 | $stored_tokens[] = $token->get_token(); |
71 | 71 | } |
72 | 72 | |
73 | - if ( 'stripe' === $gateway_id ) { |
|
74 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
73 | + if ('stripe' === $gateway_id) { |
|
74 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
75 | 75 | $stripe_sources = $stripe_customer->get_sources(); |
76 | 76 | |
77 | - foreach ( $stripe_sources as $source ) { |
|
78 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
79 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
77 | + foreach ($stripe_sources as $source) { |
|
78 | + if (isset($source->type) && 'card' === $source->type) { |
|
79 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
80 | 80 | $token = new WC_Payment_Token_CC(); |
81 | - $token->set_token( $source->id ); |
|
82 | - $token->set_gateway_id( 'stripe' ); |
|
83 | - |
|
84 | - if ( 'source' === $source->object && 'card' === $source->type ) { |
|
85 | - $token->set_card_type( strtolower( $source->card->brand ) ); |
|
86 | - $token->set_last4( $source->card->last4 ); |
|
87 | - $token->set_expiry_month( $source->card->exp_month ); |
|
88 | - $token->set_expiry_year( $source->card->exp_year ); |
|
81 | + $token->set_token($source->id); |
|
82 | + $token->set_gateway_id('stripe'); |
|
83 | + |
|
84 | + if ('source' === $source->object && 'card' === $source->type) { |
|
85 | + $token->set_card_type(strtolower($source->card->brand)); |
|
86 | + $token->set_last4($source->card->last4); |
|
87 | + $token->set_expiry_month($source->card->exp_month); |
|
88 | + $token->set_expiry_year($source->card->exp_year); |
|
89 | 89 | } |
90 | 90 | |
91 | - $token->set_user_id( $customer_id ); |
|
91 | + $token->set_user_id($customer_id); |
|
92 | 92 | $token->save(); |
93 | - $tokens[ $token->get_id() ] = $token; |
|
93 | + $tokens[$token->get_id()] = $token; |
|
94 | 94 | } |
95 | 95 | } else { |
96 | - if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) { |
|
96 | + if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) { |
|
97 | 97 | $token = new WC_Payment_Token_CC(); |
98 | - $token->set_token( $source->id ); |
|
99 | - $token->set_gateway_id( 'stripe' ); |
|
100 | - $token->set_card_type( strtolower( $source->brand ) ); |
|
101 | - $token->set_last4( $source->last4 ); |
|
102 | - $token->set_expiry_month( $source->exp_month ); |
|
103 | - $token->set_expiry_year( $source->exp_year ); |
|
104 | - $token->set_user_id( $customer_id ); |
|
98 | + $token->set_token($source->id); |
|
99 | + $token->set_gateway_id('stripe'); |
|
100 | + $token->set_card_type(strtolower($source->brand)); |
|
101 | + $token->set_last4($source->last4); |
|
102 | + $token->set_expiry_month($source->exp_month); |
|
103 | + $token->set_expiry_year($source->exp_year); |
|
104 | + $token->set_user_id($customer_id); |
|
105 | 105 | $token->save(); |
106 | - $tokens[ $token->get_id() ] = $token; |
|
106 | + $tokens[$token->get_id()] = $token; |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - if ( 'stripe_sepa' === $gateway_id ) { |
|
113 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
112 | + if ('stripe_sepa' === $gateway_id) { |
|
113 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
114 | 114 | $stripe_sources = $stripe_customer->get_sources(); |
115 | 115 | |
116 | - foreach ( $stripe_sources as $source ) { |
|
117 | - if ( isset( $source->type ) && 'sepa_debit' === $source->type ) { |
|
118 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
116 | + foreach ($stripe_sources as $source) { |
|
117 | + if (isset($source->type) && 'sepa_debit' === $source->type) { |
|
118 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
119 | 119 | $token = new WC_Payment_Token_SEPA(); |
120 | - $token->set_token( $source->id ); |
|
121 | - $token->set_gateway_id( 'stripe_sepa' ); |
|
122 | - $token->set_last4( $source->sepa_debit->last4 ); |
|
123 | - $token->set_user_id( $customer_id ); |
|
120 | + $token->set_token($source->id); |
|
121 | + $token->set_gateway_id('stripe_sepa'); |
|
122 | + $token->set_last4($source->sepa_debit->last4); |
|
123 | + $token->set_user_id($customer_id); |
|
124 | 124 | $token->save(); |
125 | - $tokens[ $token->get_id() ] = $token; |
|
125 | + $tokens[$token->get_id()] = $token; |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | * @param WC_Payment_Token $payment_token The payment token associated with this method entry |
142 | 142 | * @return array Filtered item |
143 | 143 | */ |
144 | - public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) { |
|
145 | - if ( 'sepa' !== strtolower( $payment_token->get_type() ) ) { |
|
144 | + public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) { |
|
145 | + if ('sepa' !== strtolower($payment_token->get_type())) { |
|
146 | 146 | return $item; |
147 | 147 | } |
148 | 148 | |
149 | 149 | $item['method']['last4'] = $payment_token->get_last4(); |
150 | - $item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' ); |
|
150 | + $item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe'); |
|
151 | 151 | |
152 | 152 | return $item; |
153 | 153 | } |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | * @since 3.1.0 |
159 | 159 | * @version 4.0.0 |
160 | 160 | */ |
161 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
162 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
163 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
164 | - $stripe_customer->delete_source( $token->get_token() ); |
|
161 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
162 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
163 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
164 | + $stripe_customer->delete_source($token->get_token()); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -171,12 +171,12 @@ discard block |
||
171 | 171 | * @since 3.1.0 |
172 | 172 | * @version 4.0.0 |
173 | 173 | */ |
174 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
175 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
174 | + public function woocommerce_payment_token_set_default($token_id) { |
|
175 | + $token = WC_Payment_Tokens::get($token_id); |
|
176 | 176 | |
177 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
178 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
179 | - $stripe_customer->set_default_source( $token->get_token() ); |
|
177 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
178 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
179 | + $stripe_customer->set_default_source($token->get_token()); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | } |
@@ -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,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,24 +27,24 @@ 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 ); |
|
43 | - status_header( 200 ); |
|
41 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
42 | + $this->process_webhook($request_body); |
|
43 | + status_header(200); |
|
44 | 44 | exit; |
45 | 45 | } else { |
46 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
47 | - status_header( 400 ); |
|
46 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
47 | + status_header(400); |
|
48 | 48 | exit; |
49 | 49 | } |
50 | 50 | } |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | * @param string $request_body The request body from Stripe. |
60 | 60 | * @return bool |
61 | 61 | */ |
62 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
63 | - if ( null === $request_headers || null === $request_body ) { |
|
62 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
63 | + if (null === $request_headers || null === $request_body) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | |
67 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
67 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | * @version 4.0.0 |
81 | 81 | */ |
82 | 82 | public function get_request_headers() { |
83 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
83 | + if ( ! function_exists('getallheaders')) { |
|
84 | 84 | $headers = []; |
85 | - foreach ( $_SERVER as $name => $value ) { |
|
86 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
87 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
85 | + foreach ($_SERVER as $name => $value) { |
|
86 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
87 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -103,30 +103,30 @@ discard block |
||
103 | 103 | * @param object $notification |
104 | 104 | * @param bool $retry |
105 | 105 | */ |
106 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
106 | + public function process_webhook_payment($notification, $retry = true) { |
|
107 | 107 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
108 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
108 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
112 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
112 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
113 | 113 | |
114 | - if ( ! $order ) { |
|
115 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
114 | + if ( ! $order) { |
|
115 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | 119 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
120 | 120 | $source_id = $notification->data->object->id; |
121 | 121 | |
122 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
122 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
123 | 123 | |
124 | 124 | try { |
125 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
125 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
129 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
@@ -134,69 +134,69 @@ discard block |
||
134 | 134 | $response = null; |
135 | 135 | |
136 | 136 | // This will throw exception if not valid. |
137 | - $this->validate_minimum_order_amount( $order ); |
|
137 | + $this->validate_minimum_order_amount($order); |
|
138 | 138 | |
139 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
139 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
140 | 140 | |
141 | 141 | // Prep source object. |
142 | 142 | $source_object = new stdClass(); |
143 | 143 | $source_object->token_id = ''; |
144 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
144 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
145 | 145 | $source_object->source = $source_id; |
146 | 146 | |
147 | 147 | // Make the request. |
148 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
148 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
149 | 149 | |
150 | - if ( ! empty( $response->error ) ) { |
|
150 | + if ( ! empty($response->error)) { |
|
151 | 151 | // If it is an API error such connection or server, let's retry. |
152 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
153 | - if ( $retry ) { |
|
154 | - sleep( 5 ); |
|
155 | - return $this->process_payment( $order_id, false ); |
|
152 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
153 | + if ($retry) { |
|
154 | + sleep(5); |
|
155 | + return $this->process_payment($order_id, false); |
|
156 | 156 | } else { |
157 | 157 | $message = 'API connection error and retries exhausted.'; |
158 | - $order->add_order_note( $message ); |
|
159 | - throw new Exception( $message ); |
|
158 | + $order->add_order_note($message); |
|
159 | + throw new Exception($message); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
164 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
165 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
164 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
165 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
166 | 166 | |
167 | - return $this->process_payment( $order_id, false ); |
|
167 | + return $this->process_payment($order_id, false); |
|
168 | 168 | |
169 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
169 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
170 | 170 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
171 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
171 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
172 | 172 | $wc_token->delete(); |
173 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
174 | - $order->add_order_note( $message ); |
|
175 | - throw new Exception( $message ); |
|
173 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
174 | + $order->add_order_note($message); |
|
175 | + throw new Exception($message); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
179 | 179 | |
180 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
180 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
181 | 181 | |
182 | - $order->add_order_note( $message ); |
|
182 | + $order->add_order_note($message); |
|
183 | 183 | |
184 | - throw new Exception( $message ); |
|
184 | + throw new Exception($message); |
|
185 | 185 | } |
186 | 186 | |
187 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
187 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
188 | 188 | |
189 | - $this->process_response( $response, $order ); |
|
189 | + $this->process_response($response, $order); |
|
190 | 190 | |
191 | - } catch ( Exception $e ) { |
|
192 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
191 | + } catch (Exception $e) { |
|
192 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
193 | 193 | |
194 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order ); |
|
194 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order); |
|
195 | 195 | |
196 | - $statuses = array( 'pending', 'failed' ); |
|
196 | + $statuses = array('pending', 'failed'); |
|
197 | 197 | |
198 | - if ( $order->has_status( $statuses ) ) { |
|
199 | - $this->send_failed_order_email( $order_id ); |
|
198 | + if ($order->has_status($statuses)) { |
|
199 | + $this->send_failed_order_email($order_id); |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | } |
@@ -210,18 +210,18 @@ discard block |
||
210 | 210 | * @version 4.0.0 |
211 | 211 | * @param object $notification |
212 | 212 | */ |
213 | - public function process_webhook_dispute( $notification ) { |
|
214 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
213 | + public function process_webhook_dispute($notification) { |
|
214 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
215 | 215 | |
216 | - if ( ! $order ) { |
|
217 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
216 | + if ( ! $order) { |
|
217 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
218 | 218 | return; |
219 | 219 | } |
220 | 220 | |
221 | - $order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) ); |
|
221 | + $order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe')); |
|
222 | 222 | |
223 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
224 | - $this->send_failed_order_email( $order_id ); |
|
223 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
224 | + $this->send_failed_order_email($order_id); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -232,41 +232,41 @@ discard block |
||
232 | 232 | * @version 4.0.0 |
233 | 233 | * @param object $notification |
234 | 234 | */ |
235 | - public function process_webhook_capture( $notification ) { |
|
236 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
235 | + public function process_webhook_capture($notification) { |
|
236 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
237 | 237 | |
238 | - if ( ! $order ) { |
|
239 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
238 | + if ( ! $order) { |
|
239 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
240 | 240 | return; |
241 | 241 | } |
242 | 242 | |
243 | 243 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
244 | 244 | |
245 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
246 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
247 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
245 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
246 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
247 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
248 | 248 | |
249 | - if ( $charge && 'no' === $captured ) { |
|
250 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
249 | + if ($charge && 'no' === $captured) { |
|
250 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
251 | 251 | |
252 | 252 | // Store other data such as fees |
253 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
253 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
254 | 254 | |
255 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
256 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
255 | + if (isset($notification->data->object->balance_transaction)) { |
|
256 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
257 | 257 | } |
258 | 258 | |
259 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
259 | + if (is_callable(array($order, 'save'))) { |
|
260 | 260 | $order->save(); |
261 | 261 | } |
262 | 262 | |
263 | 263 | /* translators: transaction id */ |
264 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
264 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
265 | 265 | |
266 | 266 | // Check and see if capture is partial. |
267 | - if ( $this->is_partial_capture( $notification ) ) { |
|
268 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
269 | - $order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
267 | + if ($this->is_partial_capture($notification)) { |
|
268 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
269 | + $order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
270 | 270 | $order->save(); |
271 | 271 | } |
272 | 272 | } |
@@ -281,38 +281,38 @@ discard block |
||
281 | 281 | * @version 4.0.0 |
282 | 282 | * @param object $notification |
283 | 283 | */ |
284 | - public function process_webhook_charge_succeeded( $notification ) { |
|
284 | + public function process_webhook_charge_succeeded($notification) { |
|
285 | 285 | // The following payment methods are synchronous so does not need to be handle via webhook. |
286 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
286 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
287 | 287 | return; |
288 | 288 | } |
289 | 289 | |
290 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
290 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
291 | 291 | |
292 | - if ( ! $order ) { |
|
293 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
292 | + if ( ! $order) { |
|
293 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
294 | 294 | return; |
295 | 295 | } |
296 | 296 | |
297 | 297 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
298 | 298 | |
299 | - if ( 'on-hold' !== $order->get_status() ) { |
|
299 | + if ('on-hold' !== $order->get_status()) { |
|
300 | 300 | return; |
301 | 301 | } |
302 | 302 | |
303 | 303 | // Store other data such as fees |
304 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
304 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
305 | 305 | |
306 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
307 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
306 | + if (isset($notification->data->object->balance_transaction)) { |
|
307 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
308 | 308 | } |
309 | 309 | |
310 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
310 | + if (is_callable(array($order, 'save'))) { |
|
311 | 311 | $order->save(); |
312 | 312 | } |
313 | 313 | |
314 | 314 | /* translators: transaction id */ |
315 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
315 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -323,23 +323,23 @@ discard block |
||
323 | 323 | * @version 4.0.0 |
324 | 324 | * @param object $notification |
325 | 325 | */ |
326 | - public function process_webhook_charge_failed( $notification ) { |
|
327 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
326 | + public function process_webhook_charge_failed($notification) { |
|
327 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
328 | 328 | |
329 | - if ( ! $order ) { |
|
330 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
329 | + if ( ! $order) { |
|
330 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
331 | 331 | return; |
332 | 332 | } |
333 | 333 | |
334 | 334 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
335 | 335 | |
336 | - if ( 'on-hold' !== $order->get_status() ) { |
|
336 | + if ('on-hold' !== $order->get_status()) { |
|
337 | 337 | return; |
338 | 338 | } |
339 | 339 | |
340 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
340 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
341 | 341 | |
342 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
342 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -350,23 +350,23 @@ discard block |
||
350 | 350 | * @version 4.0.0 |
351 | 351 | * @param object $notification |
352 | 352 | */ |
353 | - public function process_webhook_source_canceled( $notification ) { |
|
354 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
353 | + public function process_webhook_source_canceled($notification) { |
|
354 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
355 | 355 | |
356 | - if ( ! $order ) { |
|
357 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
356 | + if ( ! $order) { |
|
357 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | 361 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
362 | 362 | |
363 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
363 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
364 | 364 | return; |
365 | 365 | } |
366 | 366 | |
367 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
367 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
368 | 368 | |
369 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
369 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -377,31 +377,31 @@ discard block |
||
377 | 377 | * @version 4.0.0 |
378 | 378 | * @param object $notification |
379 | 379 | */ |
380 | - public function process_webhook_refund( $notification ) { |
|
381 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
380 | + public function process_webhook_refund($notification) { |
|
381 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
382 | 382 | |
383 | - if ( ! $order ) { |
|
384 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
383 | + if ( ! $order) { |
|
384 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
385 | 385 | return; |
386 | 386 | } |
387 | 387 | |
388 | 388 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
389 | 389 | |
390 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
391 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
392 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
390 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
391 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
392 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
393 | 393 | |
394 | 394 | // Only refund captured charge. |
395 | - if ( $charge && 'yes' === $captured ) { |
|
395 | + if ($charge && 'yes' === $captured) { |
|
396 | 396 | // Create the refund. |
397 | - $refund = wc_create_refund( array( |
|
397 | + $refund = wc_create_refund(array( |
|
398 | 398 | 'order_id' => $order_id, |
399 | - 'amount' => $this->get_refund_amount( $notification ), |
|
400 | - 'reason' => __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ), |
|
401 | - ) ); |
|
399 | + 'amount' => $this->get_refund_amount($notification), |
|
400 | + 'reason' => __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe'), |
|
401 | + )); |
|
402 | 402 | |
403 | - if ( is_wp_error( $refund ) ) { |
|
404 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
403 | + if (is_wp_error($refund)) { |
|
404 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | } |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | * @version 4.0.0 |
415 | 415 | * @param object $notification |
416 | 416 | */ |
417 | - public function is_partial_capture( $notification ) { |
|
417 | + public function is_partial_capture($notification) { |
|
418 | 418 | return 0 < $notification->data->object->amount_refunded; |
419 | 419 | } |
420 | 420 | |
@@ -425,11 +425,11 @@ discard block |
||
425 | 425 | * @version 4.0.0 |
426 | 426 | * @param object $notification |
427 | 427 | */ |
428 | - public function get_refund_amount( $notification ) { |
|
429 | - if ( $this->is_partial_capture( $notification ) ) { |
|
428 | + public function get_refund_amount($notification) { |
|
429 | + if ($this->is_partial_capture($notification)) { |
|
430 | 430 | $amount = $notification->data->object->amount_refunded / 100; |
431 | 431 | |
432 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
432 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
433 | 433 | $amount = $notification->data->object->amount_refunded; |
434 | 434 | } |
435 | 435 | |
@@ -446,12 +446,12 @@ discard block |
||
446 | 446 | * @version 4.0.0 |
447 | 447 | * @param object $notification |
448 | 448 | */ |
449 | - public function get_partial_amount_to_charge( $notification ) { |
|
450 | - if ( $this->is_partial_capture( $notification ) ) { |
|
451 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
449 | + public function get_partial_amount_to_charge($notification) { |
|
450 | + if ($this->is_partial_capture($notification)) { |
|
451 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
452 | 452 | |
453 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
454 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
453 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
454 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | return $amount; |
@@ -467,36 +467,36 @@ discard block |
||
467 | 467 | * @version 4.0.0 |
468 | 468 | * @param string $request_body |
469 | 469 | */ |
470 | - public function process_webhook( $request_body ) { |
|
471 | - $notification = json_decode( $request_body ); |
|
470 | + public function process_webhook($request_body) { |
|
471 | + $notification = json_decode($request_body); |
|
472 | 472 | |
473 | - switch ( $notification->type ) { |
|
473 | + switch ($notification->type) { |
|
474 | 474 | case 'source.chargeable': |
475 | - $this->process_webhook_payment( $notification ); |
|
475 | + $this->process_webhook_payment($notification); |
|
476 | 476 | break; |
477 | 477 | |
478 | 478 | case 'source.canceled': |
479 | - $this->process_webhook_source_canceled( $notification ); |
|
479 | + $this->process_webhook_source_canceled($notification); |
|
480 | 480 | break; |
481 | 481 | |
482 | 482 | case 'charge.succeeded': |
483 | - $this->process_webhook_charge_succeeded( $notification ); |
|
483 | + $this->process_webhook_charge_succeeded($notification); |
|
484 | 484 | break; |
485 | 485 | |
486 | 486 | case 'charge.failed': |
487 | - $this->process_webhook_charge_failed( $notification ); |
|
487 | + $this->process_webhook_charge_failed($notification); |
|
488 | 488 | break; |
489 | 489 | |
490 | 490 | case 'charge.captured': |
491 | - $this->process_webhook_capture( $notification ); |
|
491 | + $this->process_webhook_capture($notification); |
|
492 | 492 | break; |
493 | 493 | |
494 | 494 | case 'charge.dispute.created': |
495 | - $this->process_webhook_dispute( $notification ); |
|
495 | + $this->process_webhook_dispute($notification); |
|
496 | 496 | break; |
497 | 497 | |
498 | 498 | case 'charge.refunded': |
499 | - $this->process_webhook_refund( $notification ); |
|
499 | + $this->process_webhook_refund($notification); |
|
500 | 500 | break; |
501 | 501 | |
502 | 502 | } |
@@ -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 | |
@@ -20,23 +20,23 @@ discard block |
||
20 | 20 | * @since 4.0.0 |
21 | 21 | * @version 4.0.0 |
22 | 22 | */ |
23 | - public static function log( $message, $start_time = null, $end_time = null ) { |
|
24 | - if ( empty( self::$logger ) ) { |
|
23 | + public static function log($message, $start_time = null, $end_time = null) { |
|
24 | + if (empty(self::$logger)) { |
|
25 | 25 | self::$logger = new WC_Logger(); |
26 | 26 | } |
27 | 27 | |
28 | - $settings = get_option( 'woocommerce_stripe_settings' ); |
|
28 | + $settings = get_option('woocommerce_stripe_settings'); |
|
29 | 29 | |
30 | - if ( empty( $settings ) || isset( $settings['logging'] ) && 'yes' !== $settings['logging'] ) { |
|
30 | + if (empty($settings) || isset($settings['logging']) && 'yes' !== $settings['logging']) { |
|
31 | 31 | return; |
32 | 32 | } |
33 | 33 | |
34 | - if ( ! is_null( $start_time ) ) { |
|
34 | + if ( ! is_null($start_time)) { |
|
35 | 35 | |
36 | - $formatted_start_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $start_time ); |
|
37 | - $end_time = is_null( $end_time ) ? current_time( 'timestamp' ) : $end_time; |
|
38 | - $formatted_end_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $end_time ); |
|
39 | - $elapsed_time = round( abs( $end_time - $start_time ) / 60, 2 ); |
|
36 | + $formatted_start_time = date_i18n(get_option('date_format') . ' g:ia', $start_time); |
|
37 | + $end_time = is_null($end_time) ? current_time('timestamp') : $end_time; |
|
38 | + $formatted_end_time = date_i18n(get_option('date_format') . ' g:ia', $end_time); |
|
39 | + $elapsed_time = round(abs($end_time - $start_time) / 60, 2); |
|
40 | 40 | |
41 | 41 | $log_entry = '====Start Log ' . $formatted_start_time . '====' . "\n" . $message . "\n"; |
42 | 42 | $log_entry .= '====End Log ' . $formatted_end_time . ' (' . $elapsed_time . ')====' . "\n\n"; |
@@ -47,6 +47,6 @@ discard block |
||
47 | 47 | |
48 | 48 | } |
49 | 49 | |
50 | - self::$logger->add( self::WC_LOG_FILENAME, $log_entry ); |
|
50 | + self::$logger->add(self::WC_LOG_FILENAME, $log_entry); |
|
51 | 51 | } |
52 | 52 | } |
@@ -1,50 +1,50 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | $webhook_url = WC_Stripe_Helper::get_webhook_url(); |
7 | 7 | |
8 | -return apply_filters( 'wc_stripe_bitcoin_settings', |
|
8 | +return apply_filters('wc_stripe_bitcoin_settings', |
|
9 | 9 | array( |
10 | 10 | 'geo_target' => array( |
11 | - 'description' => __( 'Relevant Payer Geography: Global', 'woocommerce-gateway-stripe' ), |
|
11 | + 'description' => __('Relevant Payer Geography: Global', 'woocommerce-gateway-stripe'), |
|
12 | 12 | 'type' => 'title', |
13 | 13 | ), |
14 | 14 | 'guide' => array( |
15 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#bitcoin" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
15 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#bitcoin" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
16 | 16 | 'type' => 'title', |
17 | 17 | ), |
18 | 18 | 'activation' => array( |
19 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
19 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'type' => 'title', |
21 | 21 | ), |
22 | 22 | 'enabled' => array( |
23 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
24 | - 'label' => __( 'Enable Stripe Bitcoin', 'woocommerce-gateway-stripe' ), |
|
23 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
24 | + 'label' => __('Enable Stripe Bitcoin', 'woocommerce-gateway-stripe'), |
|
25 | 25 | 'type' => 'checkbox', |
26 | 26 | 'description' => '', |
27 | 27 | 'default' => 'no', |
28 | 28 | ), |
29 | 29 | 'title' => array( |
30 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
30 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
31 | 31 | 'type' => 'text', |
32 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
33 | - 'default' => __( 'Bitcoin', 'woocommerce-gateway-stripe' ), |
|
32 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
33 | + 'default' => __('Bitcoin', 'woocommerce-gateway-stripe'), |
|
34 | 34 | 'desc_tip' => true, |
35 | 35 | ), |
36 | 36 | 'description' => array( |
37 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
37 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
38 | 38 | 'type' => 'text', |
39 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
40 | - 'default' => __( 'Bitcoin payment information will be provided when you place the order.', 'woocommerce-gateway-stripe' ), |
|
39 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
40 | + 'default' => __('Bitcoin payment information will be provided when you place the order.', 'woocommerce-gateway-stripe'), |
|
41 | 41 | 'desc_tip' => true, |
42 | 42 | ), |
43 | 43 | 'webhook' => array( |
44 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
44 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
45 | 45 | 'type' => 'title', |
46 | 46 | /* translators: webhook URL */ |
47 | - 'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ), |
|
47 | + 'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url), |
|
48 | 48 | ), |
49 | 49 | ) |
50 | 50 | ); |
@@ -1,50 +1,50 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | $webhook_url = WC_Stripe_Helper::get_webhook_url(); |
7 | 7 | |
8 | -return apply_filters( 'wc_stripe_ideal_settings', |
|
8 | +return apply_filters('wc_stripe_ideal_settings', |
|
9 | 9 | array( |
10 | 10 | 'geo_target' => array( |
11 | - 'description' => __( 'Relevant Payer Geography: The Netherlands', 'woocommerce-gateway-stripe' ), |
|
11 | + 'description' => __('Relevant Payer Geography: The Netherlands', 'woocommerce-gateway-stripe'), |
|
12 | 12 | 'type' => 'title', |
13 | 13 | ), |
14 | 14 | 'guide' => array( |
15 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#ideal" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
15 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#ideal" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
16 | 16 | 'type' => 'title', |
17 | 17 | ), |
18 | 18 | 'activation' => array( |
19 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
19 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'type' => 'title', |
21 | 21 | ), |
22 | 22 | 'enabled' => array( |
23 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
24 | - 'label' => __( 'Enable Stripe iDeal', 'woocommerce-gateway-stripe' ), |
|
23 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
24 | + 'label' => __('Enable Stripe iDeal', 'woocommerce-gateway-stripe'), |
|
25 | 25 | 'type' => 'checkbox', |
26 | 26 | 'description' => '', |
27 | 27 | 'default' => 'no', |
28 | 28 | ), |
29 | 29 | 'title' => array( |
30 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
30 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
31 | 31 | 'type' => 'text', |
32 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
33 | - 'default' => __( 'iDeal', 'woocommerce-gateway-stripe' ), |
|
32 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
33 | + 'default' => __('iDeal', 'woocommerce-gateway-stripe'), |
|
34 | 34 | 'desc_tip' => true, |
35 | 35 | ), |
36 | 36 | 'description' => array( |
37 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
37 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
38 | 38 | 'type' => 'text', |
39 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
40 | - 'default' => __( 'You will be redirected to iDeal.', 'woocommerce-gateway-stripe' ), |
|
39 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
40 | + 'default' => __('You will be redirected to iDeal.', 'woocommerce-gateway-stripe'), |
|
41 | 41 | 'desc_tip' => true, |
42 | 42 | ), |
43 | 43 | 'webhook' => array( |
44 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
44 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
45 | 45 | 'type' => 'title', |
46 | 46 | /* translators: webhook URL */ |
47 | - 'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ), |
|
47 | + 'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url), |
|
48 | 48 | ), |
49 | 49 | ) |
50 | 50 | ); |