@@ -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_alipay'; |
60 | - $this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Alipay', '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,23 +71,23 @@ 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( '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('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @return array |
99 | 99 | */ |
100 | 100 | public function get_supported_currency() { |
101 | - return apply_filters( 'wc_stripe_alipay_supported_currencies', array( |
|
101 | + return apply_filters('wc_stripe_alipay_supported_currencies', array( |
|
102 | 102 | 'EUR', |
103 | 103 | 'AUD', |
104 | 104 | 'CAD', |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | 'NZD', |
109 | 109 | 'SGD', |
110 | 110 | 'USD', |
111 | - ) ); |
|
111 | + )); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return bool |
120 | 120 | */ |
121 | 121 | public function is_available() { |
122 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
122 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
123 | 123 | return false; |
124 | 124 | } |
125 | 125 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | $icons_str .= $icons['alipay']; |
142 | 142 | |
143 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
143 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -150,19 +150,19 @@ discard block |
||
150 | 150 | * @version 4.0.0 |
151 | 151 | */ |
152 | 152 | public function payment_scripts() { |
153 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
153 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
154 | 154 | return; |
155 | 155 | } |
156 | 156 | |
157 | - wp_enqueue_style( 'stripe_styles' ); |
|
158 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
157 | + wp_enqueue_style('stripe_styles'); |
|
158 | + wp_enqueue_script('woocommerce_stripe'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * Initialize Gateway Settings Form Fields. |
163 | 163 | */ |
164 | 164 | public function init_form_fields() { |
165 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' ); |
|
165 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php'); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -174,25 +174,25 @@ discard block |
||
174 | 174 | $description = $this->get_description(); |
175 | 175 | |
176 | 176 | // If paying from order, we need to get total from order not cart. |
177 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
178 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
177 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
178 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
179 | 179 | $total = $order->get_total(); |
180 | 180 | } |
181 | 181 | |
182 | - if ( is_add_payment_method_page() ) { |
|
183 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
184 | - $total = ''; |
|
182 | + if (is_add_payment_method_page()) { |
|
183 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
184 | + $total = ''; |
|
185 | 185 | } else { |
186 | 186 | $pay_button_text = ''; |
187 | 187 | } |
188 | 188 | |
189 | 189 | echo '<div |
190 | 190 | id="stripe-alipay-payment-data" |
191 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
192 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
191 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
192 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
193 | 193 | |
194 | - if ( $description ) { |
|
195 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
194 | + if ($description) { |
|
195 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | echo '</div>'; |
@@ -206,24 +206,24 @@ discard block |
||
206 | 206 | * @param object $order |
207 | 207 | * @return mixed |
208 | 208 | */ |
209 | - public function create_source( $order ) { |
|
209 | + public function create_source($order) { |
|
210 | 210 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
211 | 211 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
212 | - $return_url = $this->get_stripe_return_url( $order ); |
|
212 | + $return_url = $this->get_stripe_return_url($order); |
|
213 | 213 | $post_data = array(); |
214 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
215 | - $post_data['currency'] = strtolower( $currency ); |
|
214 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
215 | + $post_data['currency'] = strtolower($currency); |
|
216 | 216 | $post_data['type'] = 'alipay'; |
217 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
218 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
217 | + $post_data['owner'] = $this->get_owner_details($order); |
|
218 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
219 | 219 | |
220 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
221 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
220 | + if ( ! empty($this->statement_descriptor)) { |
|
221 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
222 | 222 | } |
223 | 223 | |
224 | - WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' ); |
|
224 | + WC_Stripe_Logger::log('Info: Begin creating Alipay source'); |
|
225 | 225 | |
226 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_alipay_source', $post_data, $order ), 'sources' ); |
|
226 | + return WC_Stripe_API::request(apply_filters('wc_stripe_alipay_source', $post_data, $order), 'sources'); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -237,53 +237,53 @@ discard block |
||
237 | 237 | * |
238 | 238 | * @return array|void |
239 | 239 | */ |
240 | - public function process_payment( $order_id, $retry = true, $force_save_save = false ) { |
|
240 | + public function process_payment($order_id, $retry = true, $force_save_save = false) { |
|
241 | 241 | try { |
242 | - $order = wc_get_order( $order_id ); |
|
242 | + $order = wc_get_order($order_id); |
|
243 | 243 | |
244 | 244 | // This will throw exception if not valid. |
245 | - $this->validate_minimum_order_amount( $order ); |
|
245 | + $this->validate_minimum_order_amount($order); |
|
246 | 246 | |
247 | 247 | // This comes from the create account checkbox in the checkout page. |
248 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
248 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
249 | 249 | |
250 | - if ( $create_account ) { |
|
250 | + if ($create_account) { |
|
251 | 251 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
252 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
252 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
253 | 253 | $new_stripe_customer->create_customer(); |
254 | 254 | } |
255 | 255 | |
256 | - $response = $this->create_source( $order ); |
|
256 | + $response = $this->create_source($order); |
|
257 | 257 | |
258 | - if ( ! empty( $response->error ) ) { |
|
259 | - $order->add_order_note( $response->error->message ); |
|
258 | + if ( ! empty($response->error)) { |
|
259 | + $order->add_order_note($response->error->message); |
|
260 | 260 | |
261 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
261 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
262 | 262 | } |
263 | 263 | |
264 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
265 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
264 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
265 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
266 | 266 | } else { |
267 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
267 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
268 | 268 | $order->save(); |
269 | 269 | } |
270 | 270 | |
271 | - WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); |
|
271 | + WC_Stripe_Logger::log('Info: Redirecting to Alipay...'); |
|
272 | 272 | |
273 | 273 | return array( |
274 | 274 | 'result' => 'success', |
275 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
275 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
276 | 276 | ); |
277 | - } catch ( WC_Stripe_Exception $e ) { |
|
278 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
279 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
277 | + } catch (WC_Stripe_Exception $e) { |
|
278 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
279 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
280 | 280 | |
281 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
281 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
282 | 282 | |
283 | - $statuses = array( 'pending', 'failed' ); |
|
283 | + $statuses = array('pending', 'failed'); |
|
284 | 284 | |
285 | - if ( $order->has_status( $statuses ) ) { |
|
286 | - $this->send_failed_order_email( $order_id ); |
|
285 | + if ($order->has_status($statuses)) { |
|
286 | + $this->send_failed_order_email($order_id); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | 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_sofort'; |
60 | - $this->method_title = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe SOFORT', '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,23 +71,23 @@ 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( '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('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | * @return array |
99 | 99 | */ |
100 | 100 | public function get_supported_currency() { |
101 | - return apply_filters( 'wc_stripe_sofort_supported_currencies', array( |
|
101 | + return apply_filters('wc_stripe_sofort_supported_currencies', array( |
|
102 | 102 | 'EUR', |
103 | - ) ); |
|
103 | + )); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return bool |
112 | 112 | */ |
113 | 113 | public function is_available() { |
114 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
114 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | $icons_str .= $icons['sofort']; |
134 | 134 | |
135 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
135 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -143,19 +143,19 @@ discard block |
||
143 | 143 | * @access public |
144 | 144 | */ |
145 | 145 | public function payment_scripts() { |
146 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
146 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | |
150 | - wp_enqueue_style( 'stripe_styles' ); |
|
151 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
150 | + wp_enqueue_style('stripe_styles'); |
|
151 | + wp_enqueue_script('woocommerce_stripe'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Initialize Gateway Settings Form Fields. |
156 | 156 | */ |
157 | 157 | public function init_form_fields() { |
158 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
158 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -167,25 +167,25 @@ discard block |
||
167 | 167 | $description = $this->get_description(); |
168 | 168 | |
169 | 169 | // If paying from order, we need to get total from order not cart. |
170 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
171 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
170 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
171 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
172 | 172 | $total = $order->get_total(); |
173 | 173 | } |
174 | 174 | |
175 | - if ( is_add_payment_method_page() ) { |
|
176 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
177 | - $total = ''; |
|
175 | + if (is_add_payment_method_page()) { |
|
176 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
177 | + $total = ''; |
|
178 | 178 | } else { |
179 | 179 | $pay_button_text = ''; |
180 | 180 | } |
181 | 181 | |
182 | 182 | echo '<div |
183 | 183 | id="stripe-sofort-payment-data" |
184 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
185 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
184 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
185 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
186 | 186 | |
187 | - if ( $description ) { |
|
188 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
187 | + if ($description) { |
|
188 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | echo '</div>'; |
@@ -199,28 +199,28 @@ discard block |
||
199 | 199 | * @param object $order |
200 | 200 | * @return mixed |
201 | 201 | */ |
202 | - public function create_source( $order ) { |
|
202 | + public function create_source($order) { |
|
203 | 203 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
204 | 204 | $bank_country = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
205 | - $return_url = $this->get_stripe_return_url( $order ); |
|
205 | + $return_url = $this->get_stripe_return_url($order); |
|
206 | 206 | $post_data = array(); |
207 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
208 | - $post_data['currency'] = strtolower( $currency ); |
|
207 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
208 | + $post_data['currency'] = strtolower($currency); |
|
209 | 209 | $post_data['type'] = 'sofort'; |
210 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
211 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
210 | + $post_data['owner'] = $this->get_owner_details($order); |
|
211 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
212 | 212 | $post_data['sofort'] = array( |
213 | 213 | 'country' => $bank_country, |
214 | 214 | 'preferred_language' => $this->get_locale(), |
215 | 215 | ); |
216 | 216 | |
217 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
218 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
217 | + if ( ! empty($this->statement_descriptor)) { |
|
218 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
219 | 219 | } |
220 | 220 | |
221 | - WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' ); |
|
221 | + WC_Stripe_Logger::log('Info: Begin creating SOFORT source'); |
|
222 | 222 | |
223 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_sofort_source', $post_data, $order ), 'sources' ); |
|
223 | + return WC_Stripe_API::request(apply_filters('wc_stripe_sofort_source', $post_data, $order), 'sources'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -234,59 +234,59 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @return array|void |
236 | 236 | */ |
237 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
237 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
238 | 238 | try { |
239 | - $order = wc_get_order( $order_id ); |
|
239 | + $order = wc_get_order($order_id); |
|
240 | 240 | |
241 | 241 | // This will throw exception if not valid. |
242 | - $this->validate_minimum_order_amount( $order ); |
|
242 | + $this->validate_minimum_order_amount($order); |
|
243 | 243 | |
244 | 244 | // This comes from the create account checkbox in the checkout page. |
245 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
245 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
246 | 246 | |
247 | - if ( $create_account ) { |
|
247 | + if ($create_account) { |
|
248 | 248 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
249 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
249 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
250 | 250 | $new_stripe_customer->create_customer(); |
251 | 251 | } |
252 | 252 | |
253 | - $response = $this->create_source( $order ); |
|
253 | + $response = $this->create_source($order); |
|
254 | 254 | |
255 | - if ( ! empty( $response->error ) ) { |
|
256 | - $order->add_order_note( $response->error->message ); |
|
255 | + if ( ! empty($response->error)) { |
|
256 | + $order->add_order_note($response->error->message); |
|
257 | 257 | |
258 | 258 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
259 | 259 | |
260 | - if ( 'invalid_sofort_country' === $response->error->code ) { |
|
261 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
260 | + if ('invalid_sofort_country' === $response->error->code) { |
|
261 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
262 | 262 | } else { |
263 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
263 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
264 | 264 | } |
265 | 265 | |
266 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
266 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
267 | 267 | } |
268 | 268 | |
269 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
270 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
269 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
270 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
271 | 271 | } else { |
272 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
272 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
273 | 273 | $order->save(); |
274 | 274 | } |
275 | 275 | |
276 | - WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' ); |
|
276 | + WC_Stripe_Logger::log('Info: Redirecting to SOFORT...'); |
|
277 | 277 | |
278 | 278 | return array( |
279 | 279 | 'result' => 'success', |
280 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
280 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
281 | 281 | ); |
282 | - } catch ( WC_Stripe_Exception $e ) { |
|
283 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
284 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
282 | + } catch (WC_Stripe_Exception $e) { |
|
283 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
284 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
285 | 285 | |
286 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
286 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
287 | 287 | |
288 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
289 | - $this->send_failed_order_email( $order_id ); |
|
288 | + if ($order->has_status(array('pending', 'failed'))) { |
|
289 | + $this->send_failed_order_email($order_id); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | 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_eps'; |
60 | - $this->method_title = __( 'Stripe EPS', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe EPS', '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,23 +71,23 @@ 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( '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('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | * @return array |
99 | 99 | */ |
100 | 100 | public function get_supported_currency() { |
101 | - return apply_filters( 'wc_stripe_eps_supported_currencies', array( |
|
101 | + return apply_filters('wc_stripe_eps_supported_currencies', array( |
|
102 | 102 | 'EUR', |
103 | - ) ); |
|
103 | + )); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return bool |
112 | 112 | */ |
113 | 113 | public function is_available() { |
114 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
114 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | $icons_str .= $icons['eps']; |
134 | 134 | |
135 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
135 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -143,19 +143,19 @@ discard block |
||
143 | 143 | * @access public |
144 | 144 | */ |
145 | 145 | public function payment_scripts() { |
146 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
146 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | |
150 | - wp_enqueue_style( 'stripe_styles' ); |
|
151 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
150 | + wp_enqueue_style('stripe_styles'); |
|
151 | + wp_enqueue_script('woocommerce_stripe'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Initialize Gateway Settings Form Fields. |
156 | 156 | */ |
157 | 157 | public function init_form_fields() { |
158 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-eps-settings.php' ); |
|
158 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-eps-settings.php'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -167,25 +167,25 @@ discard block |
||
167 | 167 | $description = $this->get_description(); |
168 | 168 | |
169 | 169 | // If paying from order, we need to get total from order not cart. |
170 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
171 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
170 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
171 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
172 | 172 | $total = $order->get_total(); |
173 | 173 | } |
174 | 174 | |
175 | - if ( is_add_payment_method_page() ) { |
|
176 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
177 | - $total = ''; |
|
175 | + if (is_add_payment_method_page()) { |
|
176 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
177 | + $total = ''; |
|
178 | 178 | } else { |
179 | 179 | $pay_button_text = ''; |
180 | 180 | } |
181 | 181 | |
182 | 182 | echo '<div |
183 | 183 | id="stripe-eps-payment-data" |
184 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
185 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
184 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
185 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
186 | 186 | |
187 | - if ( $description ) { |
|
188 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
187 | + if ($description) { |
|
188 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | echo '</div>'; |
@@ -199,24 +199,24 @@ discard block |
||
199 | 199 | * @param object $order |
200 | 200 | * @return mixed |
201 | 201 | */ |
202 | - public function create_source( $order ) { |
|
202 | + public function create_source($order) { |
|
203 | 203 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
204 | 204 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
205 | - $return_url = $this->get_stripe_return_url( $order ); |
|
205 | + $return_url = $this->get_stripe_return_url($order); |
|
206 | 206 | $post_data = array(); |
207 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
208 | - $post_data['currency'] = strtolower( $currency ); |
|
207 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
208 | + $post_data['currency'] = strtolower($currency); |
|
209 | 209 | $post_data['type'] = 'eps'; |
210 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
211 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
210 | + $post_data['owner'] = $this->get_owner_details($order); |
|
211 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
212 | 212 | |
213 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
214 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
213 | + if ( ! empty($this->statement_descriptor)) { |
|
214 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
215 | 215 | } |
216 | 216 | |
217 | - WC_Stripe_Logger::log( 'Info: Begin creating EPS source' ); |
|
217 | + WC_Stripe_Logger::log('Info: Begin creating EPS source'); |
|
218 | 218 | |
219 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
219 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -230,51 +230,51 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @return array|void |
232 | 232 | */ |
233 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
233 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
234 | 234 | try { |
235 | - $order = wc_get_order( $order_id ); |
|
235 | + $order = wc_get_order($order_id); |
|
236 | 236 | |
237 | 237 | // This will throw exception if not valid. |
238 | - $this->validate_minimum_order_amount( $order ); |
|
238 | + $this->validate_minimum_order_amount($order); |
|
239 | 239 | |
240 | 240 | // This comes from the create account checkbox in the checkout page. |
241 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
241 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
242 | 242 | |
243 | - if ( $create_account ) { |
|
243 | + if ($create_account) { |
|
244 | 244 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
245 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
245 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
246 | 246 | $new_stripe_customer->create_customer(); |
247 | 247 | } |
248 | 248 | |
249 | - $response = $this->create_source( $order ); |
|
249 | + $response = $this->create_source($order); |
|
250 | 250 | |
251 | - if ( ! empty( $response->error ) ) { |
|
252 | - $order->add_order_note( $response->error->message ); |
|
251 | + if ( ! empty($response->error)) { |
|
252 | + $order->add_order_note($response->error->message); |
|
253 | 253 | |
254 | - throw new Exception( $response->error->message ); |
|
254 | + throw new Exception($response->error->message); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
258 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
257 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
258 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
259 | 259 | } else { |
260 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
260 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
261 | 261 | $order->save(); |
262 | 262 | } |
263 | 263 | |
264 | - WC_Stripe_Logger::log( 'Info: Redirecting to EPS...' ); |
|
264 | + WC_Stripe_Logger::log('Info: Redirecting to EPS...'); |
|
265 | 265 | |
266 | 266 | return array( |
267 | 267 | 'result' => 'success', |
268 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
268 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
269 | 269 | ); |
270 | - } catch ( Exception $e ) { |
|
271 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
272 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
270 | + } catch (Exception $e) { |
|
271 | + wc_add_notice($e->getMessage(), 'error'); |
|
272 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
273 | 273 | |
274 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
274 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
275 | 275 | |
276 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
277 | - $this->send_failed_order_email( $order_id ); |
|
276 | + if ($order->has_status(array('pending', 'failed'))) { |
|
277 | + $this->send_failed_order_email($order_id); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | 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_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,23 +71,23 @@ 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( '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('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | * @return array |
99 | 99 | */ |
100 | 100 | public function get_supported_currency() { |
101 | - return apply_filters( 'wc_stripe_giropay_supported_currencies', array( |
|
101 | + return apply_filters('wc_stripe_giropay_supported_currencies', array( |
|
102 | 102 | 'EUR', |
103 | - ) ); |
|
103 | + )); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return bool |
112 | 112 | */ |
113 | 113 | public function is_available() { |
114 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
114 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | $icons_str .= $icons['giropay']; |
134 | 134 | |
135 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
135 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -143,19 +143,19 @@ discard block |
||
143 | 143 | * @access public |
144 | 144 | */ |
145 | 145 | public function payment_scripts() { |
146 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
146 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | |
150 | - wp_enqueue_style( 'stripe_styles' ); |
|
151 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
150 | + wp_enqueue_style('stripe_styles'); |
|
151 | + wp_enqueue_script('woocommerce_stripe'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Initialize Gateway Settings Form Fields. |
156 | 156 | */ |
157 | 157 | public function init_form_fields() { |
158 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' ); |
|
158 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -167,25 +167,25 @@ discard block |
||
167 | 167 | $description = $this->get_description(); |
168 | 168 | |
169 | 169 | // If paying from order, we need to get total from order not cart. |
170 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
171 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
170 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
171 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
172 | 172 | $total = $order->get_total(); |
173 | 173 | } |
174 | 174 | |
175 | - if ( is_add_payment_method_page() ) { |
|
176 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
177 | - $total = ''; |
|
175 | + if (is_add_payment_method_page()) { |
|
176 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
177 | + $total = ''; |
|
178 | 178 | } else { |
179 | 179 | $pay_button_text = ''; |
180 | 180 | } |
181 | 181 | |
182 | 182 | echo '<div |
183 | 183 | id="stripe-giropay-payment-data" |
184 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
185 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
184 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
185 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
186 | 186 | |
187 | - if ( $description ) { |
|
188 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
187 | + if ($description) { |
|
188 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | echo '</div>'; |
@@ -199,24 +199,24 @@ discard block |
||
199 | 199 | * @param object $order |
200 | 200 | * @return mixed |
201 | 201 | */ |
202 | - public function create_source( $order ) { |
|
202 | + public function create_source($order) { |
|
203 | 203 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
204 | 204 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
205 | - $return_url = $this->get_stripe_return_url( $order ); |
|
205 | + $return_url = $this->get_stripe_return_url($order); |
|
206 | 206 | $post_data = array(); |
207 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
208 | - $post_data['currency'] = strtolower( $currency ); |
|
207 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
208 | + $post_data['currency'] = strtolower($currency); |
|
209 | 209 | $post_data['type'] = 'giropay'; |
210 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
211 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
210 | + $post_data['owner'] = $this->get_owner_details($order); |
|
211 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
212 | 212 | |
213 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
214 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
213 | + if ( ! empty($this->statement_descriptor)) { |
|
214 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
215 | 215 | } |
216 | 216 | |
217 | - WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' ); |
|
217 | + WC_Stripe_Logger::log('Info: Begin creating Giropay source'); |
|
218 | 218 | |
219 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_giropay_source', $post_data, $order ), 'sources' ); |
|
219 | + return WC_Stripe_API::request(apply_filters('wc_stripe_giropay_source', $post_data, $order), 'sources'); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -230,51 +230,51 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @return array|void |
232 | 232 | */ |
233 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
233 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
234 | 234 | try { |
235 | - $order = wc_get_order( $order_id ); |
|
235 | + $order = wc_get_order($order_id); |
|
236 | 236 | |
237 | 237 | // This will throw exception if not valid. |
238 | - $this->validate_minimum_order_amount( $order ); |
|
238 | + $this->validate_minimum_order_amount($order); |
|
239 | 239 | |
240 | 240 | // This comes from the create account checkbox in the checkout page. |
241 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
241 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
242 | 242 | |
243 | - if ( $create_account ) { |
|
243 | + if ($create_account) { |
|
244 | 244 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
245 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
245 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
246 | 246 | $new_stripe_customer->create_customer(); |
247 | 247 | } |
248 | 248 | |
249 | - $response = $this->create_source( $order ); |
|
249 | + $response = $this->create_source($order); |
|
250 | 250 | |
251 | - if ( ! empty( $response->error ) ) { |
|
252 | - $order->add_order_note( $response->error->message ); |
|
251 | + if ( ! empty($response->error)) { |
|
252 | + $order->add_order_note($response->error->message); |
|
253 | 253 | |
254 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
254 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
258 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
257 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
258 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
259 | 259 | } else { |
260 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
260 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
261 | 261 | $order->save(); |
262 | 262 | } |
263 | 263 | |
264 | - WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' ); |
|
264 | + WC_Stripe_Logger::log('Info: Redirecting to Giropay...'); |
|
265 | 265 | |
266 | 266 | return array( |
267 | 267 | 'result' => 'success', |
268 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
268 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
269 | 269 | ); |
270 | - } catch ( WC_Stripe_Exception $e ) { |
|
271 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
272 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
270 | + } catch (WC_Stripe_Exception $e) { |
|
271 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
272 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
273 | 273 | |
274 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
274 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
275 | 275 | |
276 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
277 | - $this->send_failed_order_email( $order_id ); |
|
276 | + if ($order->has_status(array('pending', 'failed'))) { |
|
277 | + $this->send_failed_order_email($order_id); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | 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_multibanco'; |
60 | - $this->method_title = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Multibanco', '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,27 +71,27 @@ 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( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
91 | - add_action( 'woocommerce_thankyou_stripe_multibanco', array( $this, 'thankyou_page' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | + add_action('woocommerce_thankyou_stripe_multibanco', array($this, 'thankyou_page')); |
|
92 | 92 | |
93 | 93 | // Customer Emails |
94 | - add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); |
|
94 | + add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | * @return array |
103 | 103 | */ |
104 | 104 | public function get_supported_currency() { |
105 | - return apply_filters( 'wc_stripe_multibanco_supported_currencies', array( |
|
105 | + return apply_filters('wc_stripe_multibanco_supported_currencies', array( |
|
106 | 106 | 'EUR', |
107 | - ) ); |
|
107 | + )); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @return bool |
116 | 116 | */ |
117 | 117 | public function is_available() { |
118 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
118 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
119 | 119 | return false; |
120 | 120 | } |
121 | 121 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | $icons_str .= $icons['multibanco']; |
138 | 138 | |
139 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
139 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -147,19 +147,19 @@ discard block |
||
147 | 147 | * @access public |
148 | 148 | */ |
149 | 149 | public function payment_scripts() { |
150 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
150 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
151 | 151 | return; |
152 | 152 | } |
153 | 153 | |
154 | - wp_enqueue_style( 'stripe_styles' ); |
|
155 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
154 | + wp_enqueue_style('stripe_styles'); |
|
155 | + wp_enqueue_script('woocommerce_stripe'); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * Initialize Gateway Settings Form Fields. |
160 | 160 | */ |
161 | 161 | public function init_form_fields() { |
162 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-multibanco-settings.php' ); |
|
162 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-multibanco-settings.php'); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -171,25 +171,25 @@ discard block |
||
171 | 171 | $description = $this->get_description(); |
172 | 172 | |
173 | 173 | // If paying from order, we need to get total from order not cart. |
174 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
175 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
174 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
175 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
176 | 176 | $total = $order->get_total(); |
177 | 177 | } |
178 | 178 | |
179 | - if ( is_add_payment_method_page() ) { |
|
180 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
181 | - $total = ''; |
|
179 | + if (is_add_payment_method_page()) { |
|
180 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
181 | + $total = ''; |
|
182 | 182 | } else { |
183 | 183 | $pay_button_text = ''; |
184 | 184 | } |
185 | 185 | |
186 | 186 | echo '<div |
187 | 187 | id="stripe-multibanco-payment-data" |
188 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
189 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
188 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
189 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
190 | 190 | |
191 | - if ( $description ) { |
|
192 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
191 | + if ($description) { |
|
192 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | echo '</div>'; |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @param int $order_id |
202 | 202 | */ |
203 | - public function thankyou_page( $order_id ) { |
|
204 | - $this->get_instructions( $order_id ); |
|
203 | + public function thankyou_page($order_id) { |
|
204 | + $this->get_instructions($order_id); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -213,15 +213,15 @@ discard block |
||
213 | 213 | * @param bool $sent_to_admin |
214 | 214 | * @param bool $plain_text |
215 | 215 | */ |
216 | - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { |
|
216 | + public function email_instructions($order, $sent_to_admin, $plain_text = false) { |
|
217 | 217 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
218 | 218 | |
219 | 219 | $payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method(); |
220 | 220 | |
221 | - if ( ! $sent_to_admin && 'stripe_multibanco' === $payment_method && $order->has_status( 'on-hold' ) ) { |
|
222 | - WC_Stripe_Logger::log( 'Sending multibanco email for order #' . $order_id ); |
|
221 | + if ( ! $sent_to_admin && 'stripe_multibanco' === $payment_method && $order->has_status('on-hold')) { |
|
222 | + WC_Stripe_Logger::log('Sending multibanco email for order #' . $order_id); |
|
223 | 223 | |
224 | - $this->get_instructions( $order_id, $plain_text ); |
|
224 | + $this->get_instructions($order_id, $plain_text); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
@@ -232,34 +232,34 @@ discard block |
||
232 | 232 | * @version 4.1.0 |
233 | 233 | * @param int $order_id |
234 | 234 | */ |
235 | - public function get_instructions( $order_id, $plain_text = false ) { |
|
236 | - $data = get_post_meta( $order_id, '_stripe_multibanco', true ); |
|
235 | + public function get_instructions($order_id, $plain_text = false) { |
|
236 | + $data = get_post_meta($order_id, '_stripe_multibanco', true); |
|
237 | 237 | |
238 | - if ( $plain_text ) { |
|
239 | - esc_html_e( 'MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
238 | + if ($plain_text) { |
|
239 | + esc_html_e('MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
240 | 240 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
241 | - esc_html_e( 'Montante:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
241 | + esc_html_e('Montante:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
242 | 242 | echo $data['amount'] . "\n\n"; |
243 | 243 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
244 | - esc_html_e( 'Entidade:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
244 | + esc_html_e('Entidade:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
245 | 245 | echo $data['entity'] . "\n\n"; |
246 | 246 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
247 | - esc_html_e( 'Referencia:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
247 | + esc_html_e('Referencia:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
248 | 248 | echo $data['reference'] . "\n\n"; |
249 | 249 | } else { |
250 | 250 | ?> |
251 | - <h3><?php esc_html_e( 'MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe' ); ?></h3> |
|
251 | + <h3><?php esc_html_e('MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe'); ?></h3> |
|
252 | 252 | <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
253 | 253 | <li class="woocommerce-order-overview__order order"> |
254 | - <?php esc_html_e( 'Montante:', 'woocommerce-gateway-stripe' ); ?> |
|
254 | + <?php esc_html_e('Montante:', 'woocommerce-gateway-stripe'); ?> |
|
255 | 255 | <strong><?php echo $data['amount']; ?></strong> |
256 | 256 | </li> |
257 | 257 | <li class="woocommerce-order-overview__order order"> |
258 | - <?php esc_html_e( 'Entidade:', 'woocommerce-gateway-stripe' ); ?> |
|
258 | + <?php esc_html_e('Entidade:', 'woocommerce-gateway-stripe'); ?> |
|
259 | 259 | <strong><?php echo $data['entity']; ?></strong> |
260 | 260 | </li> |
261 | 261 | <li class="woocommerce-order-overview__order order"> |
262 | - <?php esc_html_e( 'Referencia:', 'woocommerce-gateway-stripe' ); ?> |
|
262 | + <?php esc_html_e('Referencia:', 'woocommerce-gateway-stripe'); ?> |
|
263 | 263 | <strong><?php echo $data['reference']; ?></strong> |
264 | 264 | </li> |
265 | 265 | </ul> |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * @param object $order |
276 | 276 | * @param object $source_object |
277 | 277 | */ |
278 | - public function save_instructions( $order, $source_object ) { |
|
278 | + public function save_instructions($order, $source_object) { |
|
279 | 279 | $data = array( |
280 | 280 | 'amount' => $order->get_formatted_order_total(), |
281 | 281 | 'entity' => $source_object->multibanco->entity, |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | |
285 | 285 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
286 | 286 | |
287 | - update_post_meta( $order_id, '_stripe_multibanco', $data ); |
|
287 | + update_post_meta($order_id, '_stripe_multibanco', $data); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -295,24 +295,24 @@ discard block |
||
295 | 295 | * @param object $order |
296 | 296 | * @return mixed |
297 | 297 | */ |
298 | - public function create_source( $order ) { |
|
298 | + public function create_source($order) { |
|
299 | 299 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
300 | 300 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
301 | - $return_url = $this->get_stripe_return_url( $order ); |
|
301 | + $return_url = $this->get_stripe_return_url($order); |
|
302 | 302 | $post_data = array(); |
303 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
304 | - $post_data['currency'] = strtolower( $currency ); |
|
303 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
304 | + $post_data['currency'] = strtolower($currency); |
|
305 | 305 | $post_data['type'] = 'multibanco'; |
306 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
307 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
306 | + $post_data['owner'] = $this->get_owner_details($order); |
|
307 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
308 | 308 | |
309 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
310 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
309 | + if ( ! empty($this->statement_descriptor)) { |
|
310 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
311 | 311 | } |
312 | 312 | |
313 | - WC_Stripe_Logger::log( 'Info: Begin creating Multibanco source' ); |
|
313 | + WC_Stripe_Logger::log('Info: Begin creating Multibanco source'); |
|
314 | 314 | |
315 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
315 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -326,62 +326,62 @@ discard block |
||
326 | 326 | * |
327 | 327 | * @return array|void |
328 | 328 | */ |
329 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
329 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
330 | 330 | try { |
331 | - $order = wc_get_order( $order_id ); |
|
331 | + $order = wc_get_order($order_id); |
|
332 | 332 | |
333 | 333 | // This will throw exception if not valid. |
334 | - $this->validate_minimum_order_amount( $order ); |
|
334 | + $this->validate_minimum_order_amount($order); |
|
335 | 335 | |
336 | 336 | // This comes from the create account checkbox in the checkout page. |
337 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
337 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
338 | 338 | |
339 | - if ( $create_account ) { |
|
339 | + if ($create_account) { |
|
340 | 340 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
341 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
341 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
342 | 342 | $new_stripe_customer->create_customer(); |
343 | 343 | } |
344 | 344 | |
345 | - $response = $this->create_source( $order ); |
|
345 | + $response = $this->create_source($order); |
|
346 | 346 | |
347 | - if ( ! empty( $response->error ) ) { |
|
348 | - $order->add_order_note( $response->error->message ); |
|
347 | + if ( ! empty($response->error)) { |
|
348 | + $order->add_order_note($response->error->message); |
|
349 | 349 | |
350 | - throw new Exception( $response->error->message ); |
|
350 | + throw new Exception($response->error->message); |
|
351 | 351 | } |
352 | 352 | |
353 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
354 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
353 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
354 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
355 | 355 | } else { |
356 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
356 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
357 | 357 | $order->save(); |
358 | 358 | } |
359 | 359 | |
360 | - $this->save_instructions( $order, $response ); |
|
360 | + $this->save_instructions($order, $response); |
|
361 | 361 | |
362 | 362 | // Mark as on-hold (we're awaiting the payment) |
363 | - $order->update_status( 'on-hold', __( 'Awaiting Multibanco payment', 'woocommerce-gateway-stripe' ) ); |
|
363 | + $order->update_status('on-hold', __('Awaiting Multibanco payment', 'woocommerce-gateway-stripe')); |
|
364 | 364 | |
365 | 365 | // Reduce stock levels |
366 | - wc_reduce_stock_levels( $order_id ); |
|
366 | + wc_reduce_stock_levels($order_id); |
|
367 | 367 | |
368 | 368 | // Remove cart |
369 | 369 | WC()->cart->empty_cart(); |
370 | 370 | |
371 | - WC_Stripe_Logger::log( 'Info: Redirecting to Multibanco...' ); |
|
371 | + WC_Stripe_Logger::log('Info: Redirecting to Multibanco...'); |
|
372 | 372 | |
373 | 373 | return array( |
374 | 374 | 'result' => 'success', |
375 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
375 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
376 | 376 | ); |
377 | - } catch ( Exception $e ) { |
|
378 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
379 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
377 | + } catch (Exception $e) { |
|
378 | + wc_add_notice($e->getMessage(), 'error'); |
|
379 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
380 | 380 | |
381 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
381 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
382 | 382 | |
383 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
384 | - $this->send_failed_order_email( $order_id ); |
|
383 | + if ($order->has_status(array('pending', 'failed'))) { |
|
384 | + $this->send_failed_order_email($order_id); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | return array( |
@@ -1,181 +1,181 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | -return apply_filters( 'wc_stripe_settings', |
|
6 | +return apply_filters('wc_stripe_settings', |
|
7 | 7 | array( |
8 | 8 | 'enabled' => array( |
9 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
10 | - 'label' => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ), |
|
9 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
10 | + 'label' => __('Enable Stripe', 'woocommerce-gateway-stripe'), |
|
11 | 11 | 'type' => 'checkbox', |
12 | 12 | 'description' => '', |
13 | 13 | 'default' => 'no', |
14 | 14 | ), |
15 | 15 | 'title' => array( |
16 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
16 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
17 | 17 | 'type' => 'text', |
18 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
19 | - 'default' => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ), |
|
18 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
19 | + 'default' => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'desc_tip' => true, |
21 | 21 | ), |
22 | 22 | 'description' => array( |
23 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
23 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
24 | 24 | 'type' => 'text', |
25 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
26 | - 'default' => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ), |
|
25 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
26 | + 'default' => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'), |
|
27 | 27 | 'desc_tip' => true, |
28 | 28 | ), |
29 | 29 | 'webhook' => array( |
30 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
30 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
31 | 31 | 'type' => 'title', |
32 | 32 | /* translators: webhook URL */ |
33 | 33 | 'description' => $this->display_admin_settings_webhook_description(), |
34 | 34 | ), |
35 | 35 | 'testmode' => array( |
36 | - 'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ), |
|
37 | - 'label' => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ), |
|
36 | + 'title' => __('Test mode', 'woocommerce-gateway-stripe'), |
|
37 | + 'label' => __('Enable Test Mode', 'woocommerce-gateway-stripe'), |
|
38 | 38 | 'type' => 'checkbox', |
39 | - 'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ), |
|
39 | + 'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'), |
|
40 | 40 | 'default' => 'yes', |
41 | 41 | 'desc_tip' => true, |
42 | 42 | ), |
43 | 43 | 'test_publishable_key' => array( |
44 | - 'title' => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ), |
|
44 | + 'title' => __('Test Publishable Key', 'woocommerce-gateway-stripe'), |
|
45 | 45 | 'type' => 'password', |
46 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
46 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
47 | 47 | 'default' => '', |
48 | 48 | 'desc_tip' => true, |
49 | 49 | ), |
50 | 50 | 'test_secret_key' => array( |
51 | - 'title' => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ), |
|
51 | + 'title' => __('Test Secret Key', 'woocommerce-gateway-stripe'), |
|
52 | 52 | 'type' => 'password', |
53 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
53 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
54 | 54 | 'default' => '', |
55 | 55 | 'desc_tip' => true, |
56 | 56 | ), |
57 | 57 | 'publishable_key' => array( |
58 | - 'title' => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ), |
|
58 | + 'title' => __('Live Publishable Key', 'woocommerce-gateway-stripe'), |
|
59 | 59 | 'type' => 'password', |
60 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
60 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
61 | 61 | 'default' => '', |
62 | 62 | 'desc_tip' => true, |
63 | 63 | ), |
64 | 64 | 'secret_key' => array( |
65 | - 'title' => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ), |
|
65 | + 'title' => __('Live Secret Key', 'woocommerce-gateway-stripe'), |
|
66 | 66 | 'type' => 'password', |
67 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
67 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
68 | 68 | 'default' => '', |
69 | 69 | 'desc_tip' => true, |
70 | 70 | ), |
71 | 71 | 'inline_cc_form' => array( |
72 | - 'title' => __( 'Inline Credit Card Form', 'woocommerce-gateway-stripe' ), |
|
72 | + 'title' => __('Inline Credit Card Form', 'woocommerce-gateway-stripe'), |
|
73 | 73 | 'type' => 'checkbox', |
74 | - 'description' => __( 'Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe' ), |
|
74 | + 'description' => __('Choose the style you want to show for your credit card form. When unchecked, the credit card form will display separate credit card number field, expiry date field and cvc field.', 'woocommerce-gateway-stripe'), |
|
75 | 75 | 'default' => 'no', |
76 | 76 | 'desc_tip' => true, |
77 | 77 | ), |
78 | 78 | 'statement_descriptor' => array( |
79 | - 'title' => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ), |
|
79 | + 'title' => __('Statement Descriptor', 'woocommerce-gateway-stripe'), |
|
80 | 80 | 'type' => 'text', |
81 | - 'description' => __( 'This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe' ), |
|
81 | + 'description' => __('This may be up to 22 characters. The statement description must contain at least one letter, may not include ><"\' characters, and will appear on your customer\'s statement in capital letters.', 'woocommerce-gateway-stripe'), |
|
82 | 82 | 'default' => '', |
83 | 83 | 'desc_tip' => true, |
84 | 84 | ), |
85 | 85 | 'capture' => array( |
86 | - 'title' => __( 'Capture', 'woocommerce-gateway-stripe' ), |
|
87 | - 'label' => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ), |
|
86 | + 'title' => __('Capture', 'woocommerce-gateway-stripe'), |
|
87 | + 'label' => __('Capture charge immediately', 'woocommerce-gateway-stripe'), |
|
88 | 88 | 'type' => 'checkbox', |
89 | - 'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ), |
|
89 | + 'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'), |
|
90 | 90 | 'default' => 'yes', |
91 | 91 | 'desc_tip' => true, |
92 | 92 | ), |
93 | 93 | 'three_d_secure' => array( |
94 | - 'title' => __( '3D Secure', 'woocommerce-gateway-stripe' ), |
|
95 | - 'label' => __( 'Require 3D Secure when applicable', 'woocommerce-gateway-stripe' ), |
|
94 | + 'title' => __('3D Secure', 'woocommerce-gateway-stripe'), |
|
95 | + 'label' => __('Require 3D Secure when applicable', 'woocommerce-gateway-stripe'), |
|
96 | 96 | 'type' => 'checkbox', |
97 | - 'description' => __( 'Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is recommended. Enabling would require customers to use 3D Secure when recommended.', 'woocommerce-gateway-stripe' ), |
|
97 | + 'description' => __('Some payment methods have 3D Secure feature. This is an extra security layer for your store. Choose how to handle payments when 3D Secure is recommended. Enabling would require customers to use 3D Secure when recommended.', 'woocommerce-gateway-stripe'), |
|
98 | 98 | 'default' => 'yes', |
99 | 99 | 'desc_tip' => true, |
100 | 100 | ), |
101 | 101 | 'stripe_checkout' => array( |
102 | - 'title' => __( 'Stripe Modal Checkout', 'woocommerce-gateway-stripe' ), |
|
103 | - 'label' => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
102 | + 'title' => __('Stripe Modal Checkout', 'woocommerce-gateway-stripe'), |
|
103 | + 'label' => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
104 | 104 | 'type' => 'checkbox', |
105 | - 'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page. We recommend you leave this disabled and use the embedded form as that is the preferred method.', 'woocommerce-gateway-stripe' ), |
|
105 | + 'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page. We recommend you leave this disabled and use the embedded form as that is the preferred method.', 'woocommerce-gateway-stripe'), |
|
106 | 106 | 'default' => 'no', |
107 | 107 | 'desc_tip' => true, |
108 | 108 | ), |
109 | 109 | 'stripe_checkout_image' => array( |
110 | - 'title' => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ), |
|
111 | - 'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ), |
|
110 | + 'title' => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'), |
|
111 | + 'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'), |
|
112 | 112 | 'type' => 'text', |
113 | 113 | 'default' => '', |
114 | 114 | 'desc_tip' => true, |
115 | 115 | ), |
116 | 116 | 'stripe_checkout_description' => array( |
117 | - 'title' => __( 'Stripe Checkout Description', 'woocommerce-gateway-stripe' ), |
|
117 | + 'title' => __('Stripe Checkout Description', 'woocommerce-gateway-stripe'), |
|
118 | 118 | 'type' => 'text', |
119 | - 'description' => __( 'Shows a description of your store on Stripe Modal Checkout.', 'woocommerce-gateway-stripe' ), |
|
119 | + 'description' => __('Shows a description of your store on Stripe Modal Checkout.', 'woocommerce-gateway-stripe'), |
|
120 | 120 | 'default' => '', |
121 | 121 | 'desc_tip' => true, |
122 | 122 | ), |
123 | 123 | 'payment_request' => array( |
124 | - 'title' => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ), |
|
124 | + 'title' => __('Payment Request Buttons', 'woocommerce-gateway-stripe'), |
|
125 | 125 | /* translators: 1) br tag 2) opening anchor tag 3) closing anchor tag */ |
126 | - 'label' => sprintf( __( 'Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ), |
|
126 | + 'label' => sprintf(__('Enable Payment Request Buttons. (Apple Pay/Chrome Payment Request API) %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'), |
|
127 | 127 | 'type' => 'checkbox', |
128 | - 'description' => __( 'If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe' ), |
|
128 | + 'description' => __('If enabled, users will be able to pay using Apple Pay or Chrome Payment Request if supported by the browser.', 'woocommerce-gateway-stripe'), |
|
129 | 129 | 'default' => 'yes', |
130 | 130 | 'desc_tip' => true, |
131 | 131 | ), |
132 | 132 | 'payment_request_button_type' => array( |
133 | - 'title' => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ), |
|
134 | - 'label' => __( 'Button Type', 'woocommerce-gateway-stripe' ), |
|
133 | + 'title' => __('Payment Request Button Type', 'woocommerce-gateway-stripe'), |
|
134 | + 'label' => __('Button Type', 'woocommerce-gateway-stripe'), |
|
135 | 135 | 'type' => 'select', |
136 | - 'description' => __( 'Select the button type you would like to show.', 'woocommerce-gateway-stripe' ), |
|
136 | + 'description' => __('Select the button type you would like to show.', 'woocommerce-gateway-stripe'), |
|
137 | 137 | 'default' => 'buy', |
138 | 138 | 'desc_tip' => true, |
139 | 139 | 'options' => array( |
140 | - 'default' => __( 'Default', 'woocommerce-gateway-stripe' ), |
|
141 | - 'buy' => __( 'Buy', 'woocommerce-gateway-stripe' ), |
|
142 | - 'donate' => __( 'Donate', 'woocommerce-gateway-stripe' ), |
|
140 | + 'default' => __('Default', 'woocommerce-gateway-stripe'), |
|
141 | + 'buy' => __('Buy', 'woocommerce-gateway-stripe'), |
|
142 | + 'donate' => __('Donate', 'woocommerce-gateway-stripe'), |
|
143 | 143 | ), |
144 | 144 | ), |
145 | 145 | 'payment_request_button_theme' => array( |
146 | - 'title' => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ), |
|
147 | - 'label' => __( 'Button Theme', 'woocommerce-gateway-stripe' ), |
|
146 | + 'title' => __('Payment Request Button Theme', 'woocommerce-gateway-stripe'), |
|
147 | + 'label' => __('Button Theme', 'woocommerce-gateway-stripe'), |
|
148 | 148 | 'type' => 'select', |
149 | - 'description' => __( 'Select the button theme you would like to show.', 'woocommerce-gateway-stripe' ), |
|
149 | + 'description' => __('Select the button theme you would like to show.', 'woocommerce-gateway-stripe'), |
|
150 | 150 | 'default' => 'dark', |
151 | 151 | 'desc_tip' => true, |
152 | 152 | 'options' => array( |
153 | - 'dark' => __( 'Dark', 'woocommerce-gateway-stripe' ), |
|
154 | - 'light' => __( 'Light', 'woocommerce-gateway-stripe' ), |
|
155 | - 'light-outline' => __( 'Light-Outline', 'woocommerce-gateway-stripe' ), |
|
153 | + 'dark' => __('Dark', 'woocommerce-gateway-stripe'), |
|
154 | + 'light' => __('Light', 'woocommerce-gateway-stripe'), |
|
155 | + 'light-outline' => __('Light-Outline', 'woocommerce-gateway-stripe'), |
|
156 | 156 | ), |
157 | 157 | ), |
158 | 158 | 'payment_request_button_height' => array( |
159 | - 'title' => __( 'Payment Request Button Height', 'woocommerce-gateway-stripe' ), |
|
160 | - 'label' => __( 'Button Height', 'woocommerce-gateway-stripe' ), |
|
159 | + 'title' => __('Payment Request Button Height', 'woocommerce-gateway-stripe'), |
|
160 | + 'label' => __('Button Height', 'woocommerce-gateway-stripe'), |
|
161 | 161 | 'type' => 'text', |
162 | - 'description' => __( 'Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe' ), |
|
162 | + 'description' => __('Enter the height you would like the button to be in pixels. Width will always be 100%.', 'woocommerce-gateway-stripe'), |
|
163 | 163 | 'default' => '44', |
164 | 164 | 'desc_tip' => true, |
165 | 165 | ), |
166 | 166 | 'saved_cards' => array( |
167 | - 'title' => __( 'Saved Cards', 'woocommerce-gateway-stripe' ), |
|
168 | - 'label' => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ), |
|
167 | + 'title' => __('Saved Cards', 'woocommerce-gateway-stripe'), |
|
168 | + 'label' => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'), |
|
169 | 169 | 'type' => 'checkbox', |
170 | - 'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ), |
|
170 | + 'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'), |
|
171 | 171 | 'default' => 'no', |
172 | 172 | 'desc_tip' => true, |
173 | 173 | ), |
174 | 174 | 'logging' => array( |
175 | - 'title' => __( 'Logging', 'woocommerce-gateway-stripe' ), |
|
176 | - 'label' => __( 'Log debug messages', 'woocommerce-gateway-stripe' ), |
|
175 | + 'title' => __('Logging', 'woocommerce-gateway-stripe'), |
|
176 | + 'label' => __('Log debug messages', 'woocommerce-gateway-stripe'), |
|
177 | 177 | 'type' => 'checkbox', |
178 | - 'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ), |
|
178 | + 'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'), |
|
179 | 179 | 'default' => 'no', |
180 | 180 | 'desc_tip' => true, |
181 | 181 | ), |
@@ -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 | |
@@ -61,19 +61,19 @@ discard block |
||
61 | 61 | * @param int $customer_id |
62 | 62 | * @return bool |
63 | 63 | */ |
64 | - public static function customer_has_saved_methods( $customer_id ) { |
|
65 | - $gateways = array( 'stripe', 'stripe_sepa' ); |
|
64 | + public static function customer_has_saved_methods($customer_id) { |
|
65 | + $gateways = array('stripe', 'stripe_sepa'); |
|
66 | 66 | |
67 | - if ( empty( $customer_id ) ) { |
|
67 | + if (empty($customer_id)) { |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $has_token = false; |
72 | 72 | |
73 | - foreach ( $gateways as $gateway ) { |
|
74 | - $tokens = WC_Payment_Tokens::get_customer_tokens( $customer_id, $gateway ); |
|
73 | + foreach ($gateways as $gateway) { |
|
74 | + $tokens = WC_Payment_Tokens::get_customer_tokens($customer_id, $gateway); |
|
75 | 75 | |
76 | - if ( ! empty( $tokens ) ) { |
|
76 | + if ( ! empty($tokens)) { |
|
77 | 77 | $has_token = true; |
78 | 78 | break; |
79 | 79 | } |
@@ -90,67 +90,67 @@ discard block |
||
90 | 90 | * @param array $tokens |
91 | 91 | * @return array |
92 | 92 | */ |
93 | - public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) { |
|
94 | - if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
93 | + public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) { |
|
94 | + if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) { |
|
95 | 95 | $stored_tokens = array(); |
96 | 96 | |
97 | - foreach ( $tokens as $token ) { |
|
97 | + foreach ($tokens as $token) { |
|
98 | 98 | $stored_tokens[] = $token->get_token(); |
99 | 99 | } |
100 | 100 | |
101 | - if ( 'stripe' === $gateway_id ) { |
|
102 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
101 | + if ('stripe' === $gateway_id) { |
|
102 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
103 | 103 | $stripe_sources = $stripe_customer->get_sources(); |
104 | 104 | |
105 | - foreach ( $stripe_sources as $source ) { |
|
106 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
107 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
105 | + foreach ($stripe_sources as $source) { |
|
106 | + if (isset($source->type) && 'card' === $source->type) { |
|
107 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
108 | 108 | $token = new WC_Payment_Token_CC(); |
109 | - $token->set_token( $source->id ); |
|
110 | - $token->set_gateway_id( 'stripe' ); |
|
111 | - |
|
112 | - if ( 'source' === $source->object && 'card' === $source->type ) { |
|
113 | - $token->set_card_type( strtolower( $source->card->brand ) ); |
|
114 | - $token->set_last4( $source->card->last4 ); |
|
115 | - $token->set_expiry_month( $source->card->exp_month ); |
|
116 | - $token->set_expiry_year( $source->card->exp_year ); |
|
109 | + $token->set_token($source->id); |
|
110 | + $token->set_gateway_id('stripe'); |
|
111 | + |
|
112 | + if ('source' === $source->object && 'card' === $source->type) { |
|
113 | + $token->set_card_type(strtolower($source->card->brand)); |
|
114 | + $token->set_last4($source->card->last4); |
|
115 | + $token->set_expiry_month($source->card->exp_month); |
|
116 | + $token->set_expiry_year($source->card->exp_year); |
|
117 | 117 | } |
118 | 118 | |
119 | - $token->set_user_id( $customer_id ); |
|
119 | + $token->set_user_id($customer_id); |
|
120 | 120 | $token->save(); |
121 | - $tokens[ $token->get_id() ] = $token; |
|
121 | + $tokens[$token->get_id()] = $token; |
|
122 | 122 | } |
123 | 123 | } else { |
124 | - if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) { |
|
124 | + if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) { |
|
125 | 125 | $token = new WC_Payment_Token_CC(); |
126 | - $token->set_token( $source->id ); |
|
127 | - $token->set_gateway_id( 'stripe' ); |
|
128 | - $token->set_card_type( strtolower( $source->brand ) ); |
|
129 | - $token->set_last4( $source->last4 ); |
|
130 | - $token->set_expiry_month( $source->exp_month ); |
|
131 | - $token->set_expiry_year( $source->exp_year ); |
|
132 | - $token->set_user_id( $customer_id ); |
|
126 | + $token->set_token($source->id); |
|
127 | + $token->set_gateway_id('stripe'); |
|
128 | + $token->set_card_type(strtolower($source->brand)); |
|
129 | + $token->set_last4($source->last4); |
|
130 | + $token->set_expiry_month($source->exp_month); |
|
131 | + $token->set_expiry_year($source->exp_year); |
|
132 | + $token->set_user_id($customer_id); |
|
133 | 133 | $token->save(); |
134 | - $tokens[ $token->get_id() ] = $token; |
|
134 | + $tokens[$token->get_id()] = $token; |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
140 | - if ( 'stripe_sepa' === $gateway_id ) { |
|
141 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
140 | + if ('stripe_sepa' === $gateway_id) { |
|
141 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
142 | 142 | $stripe_sources = $stripe_customer->get_sources(); |
143 | 143 | |
144 | - foreach ( $stripe_sources as $source ) { |
|
145 | - if ( isset( $source->type ) && 'sepa_debit' === $source->type ) { |
|
146 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
144 | + foreach ($stripe_sources as $source) { |
|
145 | + if (isset($source->type) && 'sepa_debit' === $source->type) { |
|
146 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
147 | 147 | $token = new WC_Payment_Token_SEPA(); |
148 | - $token->set_token( $source->id ); |
|
149 | - $token->set_gateway_id( 'stripe_sepa' ); |
|
150 | - $token->set_last4( $source->sepa_debit->last4 ); |
|
151 | - $token->set_user_id( $customer_id ); |
|
148 | + $token->set_token($source->id); |
|
149 | + $token->set_gateway_id('stripe_sepa'); |
|
150 | + $token->set_last4($source->sepa_debit->last4); |
|
151 | + $token->set_user_id($customer_id); |
|
152 | 152 | $token->save(); |
153 | - $tokens[ $token->get_id() ] = $token; |
|
153 | + $tokens[$token->get_id()] = $token; |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | } |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | * @param WC_Payment_Token $payment_token The payment token associated with this method entry |
170 | 170 | * @return array Filtered item |
171 | 171 | */ |
172 | - public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) { |
|
173 | - if ( 'sepa' === strtolower( $payment_token->get_type() ) ) { |
|
172 | + public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) { |
|
173 | + if ('sepa' === strtolower($payment_token->get_type())) { |
|
174 | 174 | $item['method']['last4'] = $payment_token->get_last4(); |
175 | - $item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' ); |
|
175 | + $item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe'); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | return $item; |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | * @since 3.1.0 |
185 | 185 | * @version 4.0.0 |
186 | 186 | */ |
187 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
188 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
189 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
190 | - $stripe_customer->delete_source( $token->get_token() ); |
|
187 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
188 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
189 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
190 | + $stripe_customer->delete_source($token->get_token()); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -197,12 +197,12 @@ discard block |
||
197 | 197 | * @since 3.1.0 |
198 | 198 | * @version 4.0.0 |
199 | 199 | */ |
200 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
201 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
200 | + public function woocommerce_payment_token_set_default($token_id) { |
|
201 | + $token = WC_Payment_Tokens::get($token_id); |
|
202 | 202 | |
203 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
204 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
205 | - $stripe_customer->set_default_source( $token->get_token() ); |
|
203 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
204 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
205 | + $stripe_customer->set_default_source($token->get_token()); |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | } |
@@ -1,34 +1,34 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$_tests_dir = getenv( 'WP_TESTS_DIR' ); |
|
4 | -if ( ! $_tests_dir ) { |
|
3 | +$_tests_dir = getenv('WP_TESTS_DIR'); |
|
4 | +if ( ! $_tests_dir) { |
|
5 | 5 | $_tests_dir = '/tmp/wordpress-tests-lib'; |
6 | 6 | } |
7 | 7 | |
8 | 8 | require_once $_tests_dir . '/includes/functions.php'; |
9 | 9 | |
10 | 10 | function _manually_load_plugin() { |
11 | - $plugin_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/'; |
|
11 | + $plugin_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/'; |
|
12 | 12 | require $plugin_dir . 'woocommerce/woocommerce.php'; |
13 | 13 | require $plugin_dir . 'woocommerce-gateway-stripe/woocommerce-gateway-stripe.php'; |
14 | 14 | } |
15 | 15 | |
16 | -if ( ! function_exists( 'wc_stripe_is_wc_active' ) ) { |
|
16 | +if ( ! function_exists('wc_stripe_is_wc_active')) { |
|
17 | 17 | function wc_stripe_is_wc_active() { |
18 | 18 | return true; |
19 | 19 | } |
20 | 20 | } |
21 | 21 | |
22 | -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); |
|
22 | +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); |
|
23 | 23 | |
24 | 24 | require $_tests_dir . '/includes/bootstrap.php'; |
25 | 25 | |
26 | -$wc_tests_framework_base_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/woocommerce/tests/framework/'; |
|
27 | -require_once( $wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php' ); |
|
28 | -require_once( $wc_tests_framework_base_dir . 'class-wc-unit-test-case.php' ); |
|
29 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php' ); |
|
30 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php' ); |
|
31 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php' ); |
|
32 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php' ); |
|
33 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php' ); |
|
34 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php' ); |
|
26 | +$wc_tests_framework_base_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/woocommerce/tests/framework/'; |
|
27 | +require_once($wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php'); |
|
28 | +require_once($wc_tests_framework_base_dir . 'class-wc-unit-test-case.php'); |
|
29 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php'); |
|
30 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php'); |
|
31 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php'); |
|
32 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php'); |
|
33 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php'); |
|
34 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php'); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 4.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -71,42 +71,42 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function __construct() { |
73 | 73 | self::$_this = $this; |
74 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
75 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
76 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | - $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
74 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
75 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
76 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | + $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
80 | 80 | |
81 | - if ( $this->testmode ) { |
|
82 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | - $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
81 | + if ($this->testmode) { |
|
82 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | + $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
84 | 84 | } |
85 | 85 | |
86 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
86 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
87 | 87 | |
88 | 88 | // Checks if Stripe Gateway is enabled. |
89 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
89 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | 93 | // Checks if Payment Request is enabled. |
94 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
94 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // Don't load for change payment method page. |
99 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
99 | + if (isset($_GET['change_payment_method'])) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | - $wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
103 | + $wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2); |
|
104 | 104 | |
105 | - if ( ! in_array( $wc_default_country, $this->get_stripe_supported_countries() ) ) { |
|
105 | + if ( ! in_array($wc_default_country, $this->get_stripe_supported_countries())) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | - add_action( 'template_redirect', array( $this, 'set_session' ) ); |
|
109 | + add_action('template_redirect', array($this, 'set_session')); |
|
110 | 110 | $this->init(); |
111 | 111 | } |
112 | 112 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @return array The list of countries. |
118 | 118 | */ |
119 | 119 | public function get_stripe_supported_countries() { |
120 | - return apply_filters( 'wc_stripe_supported_countries', array( 'AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PT', 'RO', 'SE', 'SG', 'SK', 'US' ) ); |
|
120 | + return apply_filters('wc_stripe_supported_countries', array('AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PT', 'RO', 'SE', 'SG', 'SK', 'US')); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @return bool |
128 | 128 | */ |
129 | 129 | public function are_keys_set() { |
130 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
130 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
131 | 131 | return false; |
132 | 132 | } |
133 | 133 | |
@@ -151,18 +151,18 @@ discard block |
||
151 | 151 | * @since 4.0.0 |
152 | 152 | */ |
153 | 153 | public function set_session() { |
154 | - if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) { |
|
154 | + if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) { |
|
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | - $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' ); |
|
158 | + $session_class = apply_filters('woocommerce_session_handler', 'WC_Session_Handler'); |
|
159 | 159 | $wc_session = new $session_class(); |
160 | 160 | |
161 | - if ( version_compare( WC_VERSION, '3.3', '>=' ) ) { |
|
161 | + if (version_compare(WC_VERSION, '3.3', '>=')) { |
|
162 | 162 | $wc_session->init(); |
163 | 163 | } |
164 | 164 | |
165 | - $wc_session->set_customer_session_cookie( true ); |
|
165 | + $wc_session->set_customer_session_cookie(true); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,40 +172,40 @@ discard block |
||
172 | 172 | * @version 4.0.0 |
173 | 173 | */ |
174 | 174 | public function init() { |
175 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
175 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
176 | 176 | |
177 | 177 | /* |
178 | 178 | * In order to display the Payment Request button in the correct position, |
179 | 179 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
180 | 180 | * CSS is used to position the button. |
181 | 181 | */ |
182 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
183 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
184 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
182 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
183 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
184 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
185 | 185 | } else { |
186 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
187 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
186 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
187 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
188 | 188 | } |
189 | 189 | |
190 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
191 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
190 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
191 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
192 | 192 | |
193 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
194 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
193 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
194 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
195 | 195 | |
196 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
197 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
198 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
199 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
200 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
201 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
202 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
203 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
196 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
197 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
198 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
199 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
200 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
201 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
202 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
203 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
204 | 204 | |
205 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
206 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
205 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
206 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
207 | 207 | |
208 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
208 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @return string |
217 | 217 | */ |
218 | 218 | public function get_button_type() { |
219 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
219 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @return string |
228 | 228 | */ |
229 | 229 | public function get_button_theme() { |
230 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
230 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @return string |
239 | 239 | */ |
240 | 240 | public function get_button_height() { |
241 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
241 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -248,40 +248,40 @@ discard block |
||
248 | 248 | * @version 4.0.0 |
249 | 249 | */ |
250 | 250 | public function get_product_data() { |
251 | - if ( ! is_product() ) { |
|
251 | + if ( ! is_product()) { |
|
252 | 252 | return false; |
253 | 253 | } |
254 | 254 | |
255 | 255 | global $post; |
256 | 256 | |
257 | - $product = wc_get_product( $post->ID ); |
|
257 | + $product = wc_get_product($post->ID); |
|
258 | 258 | |
259 | 259 | $data = array(); |
260 | 260 | $items = array(); |
261 | 261 | |
262 | 262 | $items[] = array( |
263 | 263 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
264 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
264 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
265 | 265 | ); |
266 | 266 | |
267 | - if ( wc_tax_enabled() ) { |
|
267 | + if (wc_tax_enabled()) { |
|
268 | 268 | $items[] = array( |
269 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
269 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
270 | 270 | 'amount' => 0, |
271 | 271 | 'pending' => true, |
272 | 272 | ); |
273 | 273 | } |
274 | 274 | |
275 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
275 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
276 | 276 | $items[] = array( |
277 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
277 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
278 | 278 | 'amount' => 0, |
279 | 279 | 'pending' => true, |
280 | 280 | ); |
281 | 281 | |
282 | - $data['shippingOptions'] = array( |
|
282 | + $data['shippingOptions'] = array( |
|
283 | 283 | 'id' => 'pending', |
284 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
284 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
285 | 285 | 'detail' => '', |
286 | 286 | 'amount' => 0, |
287 | 287 | ); |
@@ -289,41 +289,41 @@ discard block |
||
289 | 289 | |
290 | 290 | $data['displayItems'] = $items; |
291 | 291 | $data['total'] = array( |
292 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
293 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
292 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
293 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
294 | 294 | 'pending' => true, |
295 | 295 | ); |
296 | 296 | |
297 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
298 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
299 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
297 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
298 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
299 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
300 | 300 | |
301 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
301 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
305 | 305 | * Filters the gateway title to reflect Payment Request type |
306 | 306 | * |
307 | 307 | */ |
308 | - public function filter_gateway_title( $title, $id ) { |
|
308 | + public function filter_gateway_title($title, $id) { |
|
309 | 309 | global $post; |
310 | 310 | |
311 | - if ( ! is_object( $post ) ) { |
|
311 | + if ( ! is_object($post)) { |
|
312 | 312 | return $title; |
313 | 313 | } |
314 | 314 | |
315 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
316 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
315 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
316 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
317 | 317 | } else { |
318 | - $order = wc_get_order( $post->ID ); |
|
319 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
318 | + $order = wc_get_order($post->ID); |
|
319 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
320 | 320 | } |
321 | 321 | |
322 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
322 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
323 | 323 | return $method_title; |
324 | 324 | } |
325 | 325 | |
326 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
326 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
327 | 327 | return $method_title; |
328 | 328 | } |
329 | 329 | |
@@ -336,16 +336,16 @@ discard block |
||
336 | 336 | * @since 3.1.4 |
337 | 337 | * @version 4.0.0 |
338 | 338 | */ |
339 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
339 | + public function postal_code_validation($valid, $postcode, $country) { |
|
340 | 340 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
341 | 341 | |
342 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
342 | + if ( ! isset($gateways['stripe'])) { |
|
343 | 343 | return $valid; |
344 | 344 | } |
345 | 345 | |
346 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
346 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
347 | 347 | |
348 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
348 | + if ('apple_pay' !== $payment_request_type) { |
|
349 | 349 | return $valid; |
350 | 350 | } |
351 | 351 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * the order and not let it go through. The remedy for now is just to remove this validation. |
356 | 356 | * Note that this only works with shipping providers that don't validate full postal codes. |
357 | 357 | */ |
358 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
358 | + if ('GB' === $country || 'CA' === $country) { |
|
359 | 359 | return true; |
360 | 360 | } |
361 | 361 | |
@@ -370,29 +370,29 @@ discard block |
||
370 | 370 | * @param int $order_id |
371 | 371 | * @param array $posted_data The posted data from checkout form. |
372 | 372 | */ |
373 | - public function add_order_meta( $order_id, $posted_data ) { |
|
374 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
373 | + public function add_order_meta($order_id, $posted_data) { |
|
374 | + if (empty($_POST['payment_request_type'])) { |
|
375 | 375 | return; |
376 | 376 | } |
377 | 377 | |
378 | - $order = wc_get_order( $order_id ); |
|
378 | + $order = wc_get_order($order_id); |
|
379 | 379 | |
380 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
380 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
381 | 381 | |
382 | - if ( 'apple_pay' === $payment_request_type ) { |
|
383 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
384 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
382 | + if ('apple_pay' === $payment_request_type) { |
|
383 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
384 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
385 | 385 | } else { |
386 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
386 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
387 | 387 | $order->save(); |
388 | 388 | } |
389 | 389 | } |
390 | 390 | |
391 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
392 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
393 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
391 | + if ('payment_request_api' === $payment_request_type) { |
|
392 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
393 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
394 | 394 | } else { |
395 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
395 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
396 | 396 | $order->save(); |
397 | 397 | } |
398 | 398 | } |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | * @return array |
407 | 407 | */ |
408 | 408 | public function supported_product_types() { |
409 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
409 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
410 | 410 | 'simple', |
411 | 411 | 'variable', |
412 | 412 | 'variation', |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | 'bundle', |
416 | 416 | 'composite', |
417 | 417 | 'mix-and-match', |
418 | - ) ); |
|
418 | + )); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -426,15 +426,15 @@ discard block |
||
426 | 426 | * @return bool |
427 | 427 | */ |
428 | 428 | public function allowed_items_in_cart() { |
429 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
430 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
429 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
430 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
431 | 431 | |
432 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
432 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
433 | 433 | return false; |
434 | 434 | } |
435 | 435 | |
436 | 436 | // Pre Orders compatbility where we don't support charge upon release. |
437 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
437 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
438 | 438 | return false; |
439 | 439 | } |
440 | 440 | } |
@@ -450,81 +450,81 @@ discard block |
||
450 | 450 | */ |
451 | 451 | public function scripts() { |
452 | 452 | // If keys are not set bail. |
453 | - if ( ! $this->are_keys_set() ) { |
|
454 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
453 | + if ( ! $this->are_keys_set()) { |
|
454 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
455 | 455 | return; |
456 | 456 | } |
457 | 457 | |
458 | 458 | // If no SSL bail. |
459 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
460 | - WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' ); |
|
459 | + if ( ! $this->testmode && ! is_ssl()) { |
|
460 | + WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.'); |
|
461 | 461 | } |
462 | 462 | |
463 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
463 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
464 | 464 | return; |
465 | 465 | } |
466 | 466 | |
467 | - if ( is_product() ) { |
|
467 | + if (is_product()) { |
|
468 | 468 | global $post; |
469 | 469 | |
470 | - $product = wc_get_product( $post->ID ); |
|
470 | + $product = wc_get_product($post->ID); |
|
471 | 471 | |
472 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
472 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
473 | 473 | return; |
474 | 474 | } |
475 | 475 | |
476 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
476 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
477 | 477 | return; |
478 | 478 | } |
479 | 479 | } |
480 | 480 | |
481 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
481 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
482 | 482 | |
483 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
484 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
483 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
484 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
485 | 485 | |
486 | 486 | wp_localize_script( |
487 | 487 | 'wc_stripe_payment_request', |
488 | 488 | 'wc_stripe_payment_request_params', |
489 | 489 | array( |
490 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
490 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
491 | 491 | 'stripe' => array( |
492 | 492 | 'key' => $this->publishable_key, |
493 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
493 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
494 | 494 | ), |
495 | 495 | 'nonce' => array( |
496 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
497 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
498 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
499 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
500 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
501 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
502 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
503 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
496 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
497 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
498 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
499 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
500 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
501 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
502 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
503 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
504 | 504 | ), |
505 | 505 | 'i18n' => array( |
506 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
506 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
507 | 507 | /* translators: Do not translate the [option] placeholder */ |
508 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
508 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
509 | 509 | ), |
510 | 510 | 'checkout' => array( |
511 | 511 | 'url' => wc_get_checkout_url(), |
512 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
513 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
512 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
513 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
514 | 514 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
515 | 515 | ), |
516 | 516 | 'button' => array( |
517 | 517 | 'type' => $this->get_button_type(), |
518 | 518 | 'theme' => $this->get_button_theme(), |
519 | 519 | 'height' => $this->get_button_height(), |
520 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
520 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
521 | 521 | ), |
522 | 522 | 'is_product_page' => is_product(), |
523 | 523 | 'product' => $this->get_product_data(), |
524 | 524 | ) |
525 | 525 | ); |
526 | 526 | |
527 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
527 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | /** |
@@ -538,37 +538,37 @@ discard block |
||
538 | 538 | |
539 | 539 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
540 | 540 | |
541 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
541 | + if ( ! isset($gateways['stripe'])) { |
|
542 | 542 | return; |
543 | 543 | } |
544 | 544 | |
545 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
545 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
546 | 546 | return; |
547 | 547 | } |
548 | 548 | |
549 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
549 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
550 | 550 | return; |
551 | 551 | } |
552 | 552 | |
553 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
553 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
554 | 554 | return; |
555 | 555 | } |
556 | 556 | |
557 | - if ( is_product() ) { |
|
558 | - $product = wc_get_product( $post->ID ); |
|
557 | + if (is_product()) { |
|
558 | + $product = wc_get_product($post->ID); |
|
559 | 559 | |
560 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
560 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
561 | 561 | return; |
562 | 562 | } |
563 | 563 | |
564 | 564 | // Pre Orders charge upon release not supported. |
565 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
566 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
565 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
566 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
567 | 567 | return; |
568 | 568 | } |
569 | 569 | } else { |
570 | - if ( ! $this->allowed_items_in_cart() ) { |
|
571 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
570 | + if ( ! $this->allowed_items_in_cart()) { |
|
571 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
572 | 572 | return; |
573 | 573 | } |
574 | 574 | } |
@@ -592,42 +592,42 @@ discard block |
||
592 | 592 | |
593 | 593 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
594 | 594 | |
595 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
595 | + if ( ! isset($gateways['stripe'])) { |
|
596 | 596 | return; |
597 | 597 | } |
598 | 598 | |
599 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
599 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
600 | 600 | return; |
601 | 601 | } |
602 | 602 | |
603 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
603 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
604 | 604 | return; |
605 | 605 | } |
606 | 606 | |
607 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
607 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
608 | 608 | return; |
609 | 609 | } |
610 | 610 | |
611 | - if ( is_product() ) { |
|
612 | - $product = wc_get_product( $post->ID ); |
|
611 | + if (is_product()) { |
|
612 | + $product = wc_get_product($post->ID); |
|
613 | 613 | |
614 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
614 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
615 | 615 | return; |
616 | 616 | } |
617 | 617 | |
618 | 618 | // Pre Orders charge upon release not supported. |
619 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
620 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
619 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
620 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
621 | 621 | return; |
622 | 622 | } |
623 | 623 | } else { |
624 | - if ( ! $this->allowed_items_in_cart() ) { |
|
625 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
624 | + if ( ! $this->allowed_items_in_cart()) { |
|
625 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
626 | 626 | return; |
627 | 627 | } |
628 | 628 | } |
629 | 629 | ?> |
630 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> —</p> |
|
630 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> —</p> |
|
631 | 631 | <?php |
632 | 632 | } |
633 | 633 | |
@@ -638,11 +638,11 @@ discard block |
||
638 | 638 | * @version 4.0.0 |
639 | 639 | */ |
640 | 640 | public function ajax_log_errors() { |
641 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
641 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
642 | 642 | |
643 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
643 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
644 | 644 | |
645 | - WC_Stripe_Logger::log( $errors ); |
|
645 | + WC_Stripe_Logger::log($errors); |
|
646 | 646 | |
647 | 647 | exit; |
648 | 648 | } |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | * @version 4.0.0 |
655 | 655 | */ |
656 | 656 | public function ajax_clear_cart() { |
657 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
657 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
658 | 658 | |
659 | 659 | WC()->cart->empty_cart(); |
660 | 660 | exit; |
@@ -664,10 +664,10 @@ discard block |
||
664 | 664 | * Get cart details. |
665 | 665 | */ |
666 | 666 | public function ajax_get_cart_details() { |
667 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
667 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
668 | 668 | |
669 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
670 | - define( 'WOOCOMMERCE_CART', true ); |
|
669 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
670 | + define('WOOCOMMERCE_CART', true); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | WC()->cart->calculate_totals(); |
@@ -678,14 +678,14 @@ discard block |
||
678 | 678 | $data = array( |
679 | 679 | 'shipping_required' => WC()->cart->needs_shipping(), |
680 | 680 | 'order_data' => array( |
681 | - 'currency' => strtolower( $currency ), |
|
682 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
681 | + 'currency' => strtolower($currency), |
|
682 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
683 | 683 | ), |
684 | 684 | ); |
685 | 685 | |
686 | 686 | $data['order_data'] += $this->build_display_items(); |
687 | 687 | |
688 | - wp_send_json( $data ); |
|
688 | + wp_send_json($data); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | /** |
@@ -696,47 +696,47 @@ discard block |
||
696 | 696 | * @see WC_Shipping::get_packages(). |
697 | 697 | */ |
698 | 698 | public function ajax_get_shipping_options() { |
699 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
699 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
700 | 700 | |
701 | 701 | try { |
702 | 702 | // Set the shipping package. |
703 | - $posted = filter_input_array( INPUT_POST, array( |
|
703 | + $posted = filter_input_array(INPUT_POST, array( |
|
704 | 704 | 'country' => FILTER_SANITIZE_STRING, |
705 | 705 | 'state' => FILTER_SANITIZE_STRING, |
706 | 706 | 'postcode' => FILTER_SANITIZE_STRING, |
707 | 707 | 'city' => FILTER_SANITIZE_STRING, |
708 | 708 | 'address' => FILTER_SANITIZE_STRING, |
709 | 709 | 'address_2' => FILTER_SANITIZE_STRING, |
710 | - ) ); |
|
710 | + )); |
|
711 | 711 | |
712 | - $this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $posted ) ); |
|
712 | + $this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $posted)); |
|
713 | 713 | |
714 | 714 | // Set the shipping options. |
715 | 715 | $data = array(); |
716 | 716 | $packages = WC()->shipping->get_packages(); |
717 | 717 | |
718 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
719 | - foreach ( $packages as $package_key => $package ) { |
|
720 | - if ( empty( $package['rates'] ) ) { |
|
721 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
718 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
719 | + foreach ($packages as $package_key => $package) { |
|
720 | + if (empty($package['rates'])) { |
|
721 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
722 | 722 | } |
723 | 723 | |
724 | - foreach ( $package['rates'] as $key => $rate ) { |
|
724 | + foreach ($package['rates'] as $key => $rate) { |
|
725 | 725 | $data['shipping_options'][] = array( |
726 | 726 | 'id' => $rate->id, |
727 | 727 | 'label' => $rate->label, |
728 | 728 | 'detail' => '', |
729 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
729 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
730 | 730 | ); |
731 | 731 | } |
732 | 732 | } |
733 | 733 | } else { |
734 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
734 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
735 | 735 | } |
736 | 736 | |
737 | - if ( isset( $data[0] ) ) { |
|
737 | + if (isset($data[0])) { |
|
738 | 738 | // Auto select the first shipping method. |
739 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
739 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | WC()->cart->calculate_totals(); |
@@ -744,12 +744,12 @@ discard block |
||
744 | 744 | $data += $this->build_display_items(); |
745 | 745 | $data['result'] = 'success'; |
746 | 746 | |
747 | - wp_send_json( $data ); |
|
748 | - } catch ( Exception $e ) { |
|
747 | + wp_send_json($data); |
|
748 | + } catch (Exception $e) { |
|
749 | 749 | $data += $this->build_display_items(); |
750 | 750 | $data['result'] = 'invalid_shipping_address'; |
751 | 751 | |
752 | - wp_send_json( $data ); |
|
752 | + wp_send_json($data); |
|
753 | 753 | } |
754 | 754 | } |
755 | 755 | |
@@ -757,22 +757,22 @@ discard block |
||
757 | 757 | * Update shipping method. |
758 | 758 | */ |
759 | 759 | public function ajax_update_shipping_method() { |
760 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
760 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
761 | 761 | |
762 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
763 | - define( 'WOOCOMMERCE_CART', true ); |
|
762 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
763 | + define('WOOCOMMERCE_CART', true); |
|
764 | 764 | } |
765 | 765 | |
766 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
767 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
766 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
767 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
768 | 768 | |
769 | - if ( is_array( $shipping_method ) ) { |
|
770 | - foreach ( $shipping_method as $i => $value ) { |
|
771 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
769 | + if (is_array($shipping_method)) { |
|
770 | + foreach ($shipping_method as $i => $value) { |
|
771 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
772 | 772 | } |
773 | 773 | } |
774 | 774 | |
775 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
775 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
776 | 776 | |
777 | 777 | WC()->cart->calculate_totals(); |
778 | 778 | |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | $data += $this->build_display_items(); |
781 | 781 | $data['result'] = 'success'; |
782 | 782 | |
783 | - wp_send_json( $data ); |
|
783 | + wp_send_json($data); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | /** |
@@ -791,31 +791,31 @@ discard block |
||
791 | 791 | * @return array $data |
792 | 792 | */ |
793 | 793 | public function ajax_get_selected_product_data() { |
794 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
794 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
795 | 795 | |
796 | - $product_id = absint( $_POST['product_id'] ); |
|
797 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
796 | + $product_id = absint($_POST['product_id']); |
|
797 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
798 | 798 | |
799 | - $product = wc_get_product( $product_id ); |
|
799 | + $product = wc_get_product($product_id); |
|
800 | 800 | |
801 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
802 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
801 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
802 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
803 | 803 | |
804 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
805 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
804 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
805 | + $variation_id = $product->get_matching_variation($attributes); |
|
806 | 806 | } else { |
807 | - $data_store = WC_Data_Store::load( 'product' ); |
|
808 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
807 | + $data_store = WC_Data_Store::load('product'); |
|
808 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
809 | 809 | } |
810 | 810 | |
811 | - if ( ! empty( $variation_id ) ) { |
|
812 | - $product = wc_get_product( $variation_id ); |
|
811 | + if ( ! empty($variation_id)) { |
|
812 | + $product = wc_get_product($variation_id); |
|
813 | 813 | } |
814 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
815 | - $product = wc_get_product( $product_id ); |
|
814 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
815 | + $product = wc_get_product($product_id); |
|
816 | 816 | } |
817 | 817 | |
818 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
818 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
819 | 819 | |
820 | 820 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
821 | 821 | |
@@ -823,28 +823,28 @@ discard block |
||
823 | 823 | $items = array(); |
824 | 824 | |
825 | 825 | $items[] = array( |
826 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
827 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
826 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
827 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
828 | 828 | ); |
829 | 829 | |
830 | - if ( wc_tax_enabled() ) { |
|
830 | + if (wc_tax_enabled()) { |
|
831 | 831 | $items[] = array( |
832 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
832 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
833 | 833 | 'amount' => 0, |
834 | 834 | 'pending' => true, |
835 | 835 | ); |
836 | 836 | } |
837 | 837 | |
838 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
838 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
839 | 839 | $items[] = array( |
840 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
840 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
841 | 841 | 'amount' => 0, |
842 | 842 | 'pending' => true, |
843 | 843 | ); |
844 | 844 | |
845 | - $data['shippingOptions'] = array( |
|
845 | + $data['shippingOptions'] = array( |
|
846 | 846 | 'id' => 'pending', |
847 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
847 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
848 | 848 | 'detail' => '', |
849 | 849 | 'amount' => 0, |
850 | 850 | ); |
@@ -853,15 +853,15 @@ discard block |
||
853 | 853 | $data['displayItems'] = $items; |
854 | 854 | $data['total'] = array( |
855 | 855 | 'label' => $this->total_label, |
856 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
856 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
857 | 857 | 'pending' => true, |
858 | 858 | ); |
859 | 859 | |
860 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
861 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
862 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
860 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
861 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
862 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
863 | 863 | |
864 | - wp_send_json( $data ); |
|
864 | + wp_send_json($data); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | /** |
@@ -872,37 +872,37 @@ discard block |
||
872 | 872 | * @return array $data |
873 | 873 | */ |
874 | 874 | public function ajax_add_to_cart() { |
875 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
875 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
876 | 876 | |
877 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
878 | - define( 'WOOCOMMERCE_CART', true ); |
|
877 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
878 | + define('WOOCOMMERCE_CART', true); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | WC()->shipping->reset_shipping(); |
882 | 882 | |
883 | - $product_id = absint( $_POST['product_id'] ); |
|
884 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
883 | + $product_id = absint($_POST['product_id']); |
|
884 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
885 | 885 | |
886 | - $product = wc_get_product( $product_id ); |
|
886 | + $product = wc_get_product($product_id); |
|
887 | 887 | |
888 | 888 | // First empty the cart to prevent wrong calculation. |
889 | 889 | WC()->cart->empty_cart(); |
890 | 890 | |
891 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
892 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
891 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
892 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
893 | 893 | |
894 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
895 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
894 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
895 | + $variation_id = $product->get_matching_variation($attributes); |
|
896 | 896 | } else { |
897 | - $data_store = WC_Data_Store::load( 'product' ); |
|
898 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
897 | + $data_store = WC_Data_Store::load('product'); |
|
898 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
899 | 899 | } |
900 | 900 | |
901 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
901 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
902 | 902 | } |
903 | 903 | |
904 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
905 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
904 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
905 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | WC()->cart->calculate_totals(); |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | $data += $this->build_display_items(); |
912 | 912 | $data['result'] = 'success'; |
913 | 913 | |
914 | - wp_send_json( $data ); |
|
914 | + wp_send_json($data); |
|
915 | 915 | } |
916 | 916 | |
917 | 917 | /** |
@@ -924,31 +924,31 @@ discard block |
||
924 | 924 | * @version 4.0.0 |
925 | 925 | */ |
926 | 926 | public function normalize_state() { |
927 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
928 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
929 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
930 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
927 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
928 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
929 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
930 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
931 | 931 | |
932 | - if ( $billing_state && $billing_country ) { |
|
933 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
932 | + if ($billing_state && $billing_country) { |
|
933 | + $valid_states = WC()->countries->get_states($billing_country); |
|
934 | 934 | |
935 | 935 | // Valid states found for country. |
936 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
937 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
938 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
936 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
937 | + foreach ($valid_states as $state_abbr => $state) { |
|
938 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
939 | 939 | $_POST['billing_state'] = $state_abbr; |
940 | 940 | } |
941 | 941 | } |
942 | 942 | } |
943 | 943 | } |
944 | 944 | |
945 | - if ( $shipping_state && $shipping_country ) { |
|
946 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
945 | + if ($shipping_state && $shipping_country) { |
|
946 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
947 | 947 | |
948 | 948 | // Valid states found for country. |
949 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
950 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
951 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
949 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
950 | + foreach ($valid_states as $state_abbr => $state) { |
|
951 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
952 | 952 | $_POST['shipping_state'] = $state_abbr; |
953 | 953 | } |
954 | 954 | } |
@@ -963,19 +963,19 @@ discard block |
||
963 | 963 | * @version 4.0.0 |
964 | 964 | */ |
965 | 965 | public function ajax_create_order() { |
966 | - if ( WC()->cart->is_empty() ) { |
|
967 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
966 | + if (WC()->cart->is_empty()) { |
|
967 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
968 | 968 | } |
969 | 969 | |
970 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
971 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
970 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
971 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | $this->normalize_state(); |
975 | 975 | |
976 | 976 | WC()->checkout()->process_checkout(); |
977 | 977 | |
978 | - die( 0 ); |
|
978 | + die(0); |
|
979 | 979 | } |
980 | 980 | |
981 | 981 | /** |
@@ -985,7 +985,7 @@ discard block |
||
985 | 985 | * @version 4.0.0 |
986 | 986 | * @param array $address |
987 | 987 | */ |
988 | - protected function calculate_shipping( $address = array() ) { |
|
988 | + protected function calculate_shipping($address = array()) { |
|
989 | 989 | global $states; |
990 | 990 | |
991 | 991 | $country = $address['country']; |
@@ -1002,28 +1002,28 @@ discard block |
||
1002 | 1002 | * In some versions of Chrome, state can be a full name. So we need |
1003 | 1003 | * to convert that to abbreviation as WC is expecting that. |
1004 | 1004 | */ |
1005 | - if ( 2 < strlen( $state ) ) { |
|
1006 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
1005 | + if (2 < strlen($state)) { |
|
1006 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
1007 | 1007 | } |
1008 | 1008 | |
1009 | 1009 | WC()->shipping->reset_shipping(); |
1010 | 1010 | |
1011 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
1012 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
1011 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
1012 | + $postcode = wc_format_postcode($postcode, $country); |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | - if ( $country ) { |
|
1016 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
1017 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
1015 | + if ($country) { |
|
1016 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
1017 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
1018 | 1018 | } else { |
1019 | 1019 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
1020 | 1020 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
1021 | 1021 | } |
1022 | 1022 | |
1023 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
1024 | - WC()->customer->calculated_shipping( true ); |
|
1023 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
1024 | + WC()->customer->calculated_shipping(true); |
|
1025 | 1025 | } else { |
1026 | - WC()->customer->set_calculated_shipping( true ); |
|
1026 | + WC()->customer->set_calculated_shipping(true); |
|
1027 | 1027 | WC()->customer->save(); |
1028 | 1028 | } |
1029 | 1029 | |
@@ -1040,17 +1040,17 @@ discard block |
||
1040 | 1040 | $packages[0]['destination']['address'] = $address_1; |
1041 | 1041 | $packages[0]['destination']['address_2'] = $address_2; |
1042 | 1042 | |
1043 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
1044 | - if ( $item['data']->needs_shipping() ) { |
|
1045 | - if ( isset( $item['line_total'] ) ) { |
|
1043 | + foreach (WC()->cart->get_cart() as $item) { |
|
1044 | + if ($item['data']->needs_shipping()) { |
|
1045 | + if (isset($item['line_total'])) { |
|
1046 | 1046 | $packages[0]['contents_cost'] += $item['line_total']; |
1047 | 1047 | } |
1048 | 1048 | } |
1049 | 1049 | } |
1050 | 1050 | |
1051 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
1051 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
1052 | 1052 | |
1053 | - WC()->shipping->calculate_shipping( $packages ); |
|
1053 | + WC()->shipping->calculate_shipping($packages); |
|
1054 | 1054 | } |
1055 | 1055 | |
1056 | 1056 | /** |
@@ -1059,19 +1059,19 @@ discard block |
||
1059 | 1059 | * @since 3.1.0 |
1060 | 1060 | * @version 4.0.0 |
1061 | 1061 | */ |
1062 | - protected function build_shipping_methods( $shipping_methods ) { |
|
1063 | - if ( empty( $shipping_methods ) ) { |
|
1062 | + protected function build_shipping_methods($shipping_methods) { |
|
1063 | + if (empty($shipping_methods)) { |
|
1064 | 1064 | return array(); |
1065 | 1065 | } |
1066 | 1066 | |
1067 | 1067 | $shipping = array(); |
1068 | 1068 | |
1069 | - foreach ( $shipping_methods as $method ) { |
|
1069 | + foreach ($shipping_methods as $method) { |
|
1070 | 1070 | $shipping[] = array( |
1071 | 1071 | 'id' => $method['id'], |
1072 | 1072 | 'label' => $method['label'], |
1073 | 1073 | 'detail' => '', |
1074 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1074 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1075 | 1075 | ); |
1076 | 1076 | } |
1077 | 1077 | |
@@ -1085,8 +1085,8 @@ discard block |
||
1085 | 1085 | * @version 4.0.0 |
1086 | 1086 | */ |
1087 | 1087 | protected function build_display_items() { |
1088 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1089 | - define( 'WOOCOMMERCE_CART', true ); |
|
1088 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1089 | + define('WOOCOMMERCE_CART', true); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | $items = array(); |
@@ -1094,71 +1094,71 @@ discard block |
||
1094 | 1094 | $discounts = 0; |
1095 | 1095 | |
1096 | 1096 | // Default show only subtotal instead of itemization. |
1097 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1098 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1097 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1098 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1099 | 1099 | $amount = $cart_item['line_subtotal']; |
1100 | - $subtotal += $cart_item['line_subtotal']; |
|
1100 | + $subtotal += $cart_item['line_subtotal']; |
|
1101 | 1101 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1102 | 1102 | |
1103 | 1103 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1104 | 1104 | |
1105 | 1105 | $item = array( |
1106 | 1106 | 'label' => $product_name . $quantity_label, |
1107 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1107 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1108 | 1108 | ); |
1109 | 1109 | |
1110 | 1110 | $items[] = $item; |
1111 | 1111 | } |
1112 | 1112 | } |
1113 | 1113 | |
1114 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1115 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1114 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1115 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1116 | 1116 | } else { |
1117 | - $applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() ); |
|
1117 | + $applied_coupons = array_values(WC()->cart->get_coupon_discount_totals()); |
|
1118 | 1118 | |
1119 | - foreach ( $applied_coupons as $amount ) { |
|
1119 | + foreach ($applied_coupons as $amount) { |
|
1120 | 1120 | $discounts += (float) $amount; |
1121 | 1121 | } |
1122 | 1122 | } |
1123 | 1123 | |
1124 | - $discounts = wc_format_decimal( $discounts, WC()->cart->dp ); |
|
1125 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1126 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1127 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1128 | - $order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false ); |
|
1124 | + $discounts = wc_format_decimal($discounts, WC()->cart->dp); |
|
1125 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1126 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1127 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1128 | + $order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false); |
|
1129 | 1129 | |
1130 | - if ( wc_tax_enabled() ) { |
|
1130 | + if (wc_tax_enabled()) { |
|
1131 | 1131 | $items[] = array( |
1132 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1133 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1132 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1133 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1134 | 1134 | ); |
1135 | 1135 | } |
1136 | 1136 | |
1137 | - if ( WC()->cart->needs_shipping() ) { |
|
1137 | + if (WC()->cart->needs_shipping()) { |
|
1138 | 1138 | $items[] = array( |
1139 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1140 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1139 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1140 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1141 | 1141 | ); |
1142 | 1142 | } |
1143 | 1143 | |
1144 | - if ( WC()->cart->has_discount() ) { |
|
1144 | + if (WC()->cart->has_discount()) { |
|
1145 | 1145 | $items[] = array( |
1146 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1147 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1146 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1147 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1148 | 1148 | ); |
1149 | 1149 | } |
1150 | 1150 | |
1151 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1151 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1152 | 1152 | $cart_fees = WC()->cart->fees; |
1153 | 1153 | } else { |
1154 | 1154 | $cart_fees = WC()->cart->get_fees(); |
1155 | 1155 | } |
1156 | 1156 | |
1157 | 1157 | // Include fees and taxes as display items. |
1158 | - foreach ( $cart_fees as $key => $fee ) { |
|
1158 | + foreach ($cart_fees as $key => $fee) { |
|
1159 | 1159 | $items[] = array( |
1160 | 1160 | 'label' => $fee->name, |
1161 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1161 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1162 | 1162 | ); |
1163 | 1163 | } |
1164 | 1164 | |
@@ -1166,7 +1166,7 @@ discard block |
||
1166 | 1166 | 'displayItems' => $items, |
1167 | 1167 | 'total' => array( |
1168 | 1168 | 'label' => $this->total_label, |
1169 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1169 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1170 | 1170 | 'pending' => false, |
1171 | 1171 | ), |
1172 | 1172 | ); |