@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | public function __construct() { |
21 | 21 | self::$_this = $this; |
22 | 22 | |
23 | - add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) ); |
|
24 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
25 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
26 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
27 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
28 | - add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) ); |
|
23 | + add_action('wp', array($this, 'maybe_process_redirect_order')); |
|
24 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
25 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
26 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
27 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
28 | + add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -46,25 +46,25 @@ discard block |
||
46 | 46 | * @since 4.0.0 |
47 | 47 | * @version 4.0.0 |
48 | 48 | */ |
49 | - public function process_redirect_payment( $order_id, $retry = true ) { |
|
49 | + public function process_redirect_payment($order_id, $retry = true) { |
|
50 | 50 | try { |
51 | - $source = wc_clean( $_GET['source'] ); |
|
51 | + $source = wc_clean($_GET['source']); |
|
52 | 52 | |
53 | - if ( empty( $source ) ) { |
|
53 | + if (empty($source)) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | - if ( empty( $order_id ) ) { |
|
57 | + if (empty($order_id)) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | 60 | |
61 | - $order = wc_get_order( $order_id ); |
|
61 | + $order = wc_get_order($order_id); |
|
62 | 62 | |
63 | - if ( ! is_object( $order ) ) { |
|
63 | + if ( ! is_object($order)) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) { |
|
67 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
@@ -72,97 +72,97 @@ discard block |
||
72 | 72 | $response = null; |
73 | 73 | |
74 | 74 | // This will throw exception if not valid. |
75 | - $this->validate_minimum_order_amount( $order ); |
|
75 | + $this->validate_minimum_order_amount($order); |
|
76 | 76 | |
77 | - WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
77 | + WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
78 | 78 | |
79 | 79 | // Prep source object. |
80 | 80 | $source_object = new stdClass(); |
81 | 81 | $source_object->token_id = ''; |
82 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
82 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
83 | 83 | $source_object->source = $source; |
84 | 84 | |
85 | 85 | /** |
86 | 86 | * First check if the source is chargeable at this time. If not, |
87 | 87 | * webhook will take care of it later. |
88 | 88 | */ |
89 | - $source_info = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
89 | + $source_info = WC_Stripe_API::retrieve('sources/' . $source); |
|
90 | 90 | |
91 | - if ( ! empty( $source_info->error ) ) { |
|
92 | - throw new Exception( $source_info->error->message ); |
|
91 | + if ( ! empty($source_info->error)) { |
|
92 | + throw new Exception($source_info->error->message); |
|
93 | 93 | } |
94 | 94 | |
95 | - if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) { |
|
96 | - throw new Exception( __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) ); |
|
95 | + if ('failed' === $source_info->status || 'canceled' === $source_info->status) { |
|
96 | + throw new Exception(__('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe')); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | // If already consumed, then ignore request. |
100 | - if ( 'consumed' === $source_info->status ) { |
|
100 | + if ('consumed' === $source_info->status) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
104 | 104 | // If not chargeable, then ignore request. |
105 | - if ( 'chargeable' !== $source_info->status ) { |
|
105 | + if ('chargeable' !== $source_info->status) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | 109 | // Make the request. |
110 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
110 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
111 | 111 | |
112 | - if ( ! empty( $response->error ) ) { |
|
112 | + if ( ! empty($response->error)) { |
|
113 | 113 | // If it is an API error such connection or server, let's retry. |
114 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
115 | - if ( $retry ) { |
|
116 | - sleep( 5 ); |
|
117 | - return $this->process_redirect_payment( $order_id, false ); |
|
114 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
115 | + if ($retry) { |
|
116 | + sleep(5); |
|
117 | + return $this->process_redirect_payment($order_id, false); |
|
118 | 118 | } else { |
119 | 119 | $message = 'API connection error and retries exhausted.'; |
120 | - $order->add_order_note( $message ); |
|
121 | - throw new Exception( $message ); |
|
120 | + $order->add_order_note($message); |
|
121 | + throw new Exception($message); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | 125 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
126 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
127 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
126 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
127 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
128 | 128 | |
129 | - return $this->process_redirect_payment( $order_id, false ); |
|
129 | + return $this->process_redirect_payment($order_id, false); |
|
130 | 130 | |
131 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
131 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
132 | 132 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
133 | 133 | |
134 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
134 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
135 | 135 | $wc_token->delete(); |
136 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
137 | - $order->add_order_note( $message ); |
|
138 | - throw new Exception( $message ); |
|
136 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
137 | + $order->add_order_note($message); |
|
138 | + throw new Exception($message); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
142 | 142 | |
143 | - $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
143 | + $message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
144 | 144 | |
145 | - throw new Exception( $message ); |
|
145 | + throw new Exception($message); |
|
146 | 146 | } |
147 | 147 | |
148 | - do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
148 | + do_action('wc_gateway_stripe_process_redirect_payment', $response, $order); |
|
149 | 149 | |
150 | - $this->process_response( $response, $order ); |
|
150 | + $this->process_response($response, $order); |
|
151 | 151 | |
152 | - } catch ( Exception $e ) { |
|
153 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
152 | + } catch (Exception $e) { |
|
153 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
154 | 154 | |
155 | - do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order ); |
|
155 | + do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order); |
|
156 | 156 | |
157 | 157 | /* translators: error message */ |
158 | - $order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
158 | + $order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
159 | 159 | |
160 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
161 | - $this->send_failed_order_email( $order_id ); |
|
160 | + if ($order->has_status(array('pending', 'failed'))) { |
|
161 | + $this->send_failed_order_email($order_id); |
|
162 | 162 | } |
163 | 163 | |
164 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
165 | - wp_safe_redirect( wc_get_checkout_url() ); |
|
164 | + wc_add_notice($e->getMessage(), 'error'); |
|
165 | + wp_safe_redirect(wc_get_checkout_url()); |
|
166 | 166 | exit; |
167 | 167 | } |
168 | 168 | } |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * @version 4.0.0 |
175 | 175 | */ |
176 | 176 | public function maybe_process_redirect_order() { |
177 | - if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) { |
|
177 | + if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | 180 | |
181 | - $order_id = wc_clean( $_GET['order_id'] ); |
|
181 | + $order_id = wc_clean($_GET['order_id']); |
|
182 | 182 | |
183 | - $this->process_redirect_payment( $order_id ); |
|
183 | + $this->process_redirect_payment($order_id); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -190,52 +190,52 @@ discard block |
||
190 | 190 | * @version 4.0.0 |
191 | 191 | * @param int $order_id |
192 | 192 | */ |
193 | - public function capture_payment( $order_id ) { |
|
194 | - $order = wc_get_order( $order_id ); |
|
193 | + public function capture_payment($order_id) { |
|
194 | + $order = wc_get_order($order_id); |
|
195 | 195 | |
196 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
197 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
198 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
196 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
197 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
198 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
199 | 199 | |
200 | - if ( $charge && 'no' === $captured ) { |
|
200 | + if ($charge && 'no' === $captured) { |
|
201 | 201 | $order_total = $order->get_total(); |
202 | 202 | |
203 | - if ( 0 < $order->get_total_refunded() ) { |
|
203 | + if (0 < $order->get_total_refunded()) { |
|
204 | 204 | $order_total = $order_total - $order->get_total_refunded(); |
205 | 205 | } |
206 | 206 | |
207 | - $result = WC_Stripe_API::request( array( |
|
208 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order_total ), |
|
207 | + $result = WC_Stripe_API::request(array( |
|
208 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order_total), |
|
209 | 209 | 'expand[]' => 'balance_transaction', |
210 | - ), 'charges/' . $charge . '/capture' ); |
|
210 | + ), 'charges/' . $charge . '/capture'); |
|
211 | 211 | |
212 | - if ( ! empty( $result->error ) ) { |
|
212 | + if ( ! empty($result->error)) { |
|
213 | 213 | /* translators: error message */ |
214 | - $order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
214 | + $order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
215 | 215 | } else { |
216 | 216 | /* translators: transaction id */ |
217 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
218 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
217 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
218 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
219 | 219 | |
220 | 220 | // Store other data such as fees |
221 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id ); |
|
221 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id); |
|
222 | 222 | |
223 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
223 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
224 | 224 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
225 | 225 | // values are in the local currency of the Stripe account, not from WC. |
226 | - $fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0; |
|
227 | - $net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0; |
|
228 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee ); |
|
229 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net ); |
|
226 | + $fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0; |
|
227 | + $net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0; |
|
228 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee); |
|
229 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
232 | + if (is_callable(array($order, 'save'))) { |
|
233 | 233 | $order->save(); |
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
237 | 237 | // This hook fires when admin manually changes order status to processing or completed. |
238 | - do_action( 'woocommerce_stripe_process_manual_capture', $order, $result ); |
|
238 | + do_action('woocommerce_stripe_process_manual_capture', $order, $result); |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | } |
@@ -247,32 +247,32 @@ discard block |
||
247 | 247 | * @version 4.0.0 |
248 | 248 | * @param int $order_id |
249 | 249 | */ |
250 | - public function cancel_payment( $order_id ) { |
|
251 | - $order = wc_get_order( $order_id ); |
|
250 | + public function cancel_payment($order_id) { |
|
251 | + $order = wc_get_order($order_id); |
|
252 | 252 | |
253 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
254 | - $charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
253 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
254 | + $charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
255 | 255 | |
256 | - if ( $charge_id ) { |
|
257 | - $result = WC_Stripe_API::request( array( |
|
258 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ), |
|
259 | - ), 'charges/' . $charge_id . '/refund' ); |
|
256 | + if ($charge_id) { |
|
257 | + $result = WC_Stripe_API::request(array( |
|
258 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()), |
|
259 | + ), 'charges/' . $charge_id . '/refund'); |
|
260 | 260 | |
261 | - if ( ! empty( $result->error ) ) { |
|
262 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->error->message ); |
|
261 | + if ( ! empty($result->error)) { |
|
262 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->error->message); |
|
263 | 263 | } else { |
264 | 264 | /* translators: transaction id */ |
265 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
266 | - WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_stripe_charge_captured' ) : $order->delete_meta_data( '_stripe_charge_captured' ); |
|
267 | - WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_transaction_id' ) : $order->delete_meta_data( '_stripe_transaction_id' ); |
|
265 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
266 | + WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_stripe_charge_captured') : $order->delete_meta_data('_stripe_charge_captured'); |
|
267 | + WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_transaction_id') : $order->delete_meta_data('_stripe_transaction_id'); |
|
268 | 268 | |
269 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
269 | + if (is_callable(array($order, 'save'))) { |
|
270 | 270 | $order->save(); |
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | 274 | // This hook fires when admin manually changes order status to cancel. |
275 | - do_action( 'woocommerce_stripe_process_manual_cancel', $order, $result ); |
|
275 | + do_action('woocommerce_stripe_process_manual_cancel', $order, $result); |
|
276 | 276 | } |
277 | 277 | } |
278 | 278 | } |
@@ -285,17 +285,17 @@ discard block |
||
285 | 285 | * @param string $field |
286 | 286 | * @return string $error_field |
287 | 287 | */ |
288 | - public function normalize_field( $field ) { |
|
288 | + public function normalize_field($field) { |
|
289 | 289 | $checkout_fields = WC()->checkout->get_checkout_fields(); |
290 | 290 | $org_str = array(); |
291 | 291 | $replace_str = array(); |
292 | 292 | |
293 | - if ( array_key_exists( $field, $checkout_fields['billing'] ) ) { |
|
294 | - $error_field = $checkout_fields['billing'][ $field ]['label']; |
|
295 | - } elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) { |
|
296 | - $error_field = $checkout_fields['shipping'][ $field ]['label']; |
|
293 | + if (array_key_exists($field, $checkout_fields['billing'])) { |
|
294 | + $error_field = $checkout_fields['billing'][$field]['label']; |
|
295 | + } elseif (array_key_exists($field, $checkout_fields['shipping'])) { |
|
296 | + $error_field = $checkout_fields['shipping'][$field]['label']; |
|
297 | 297 | } else { |
298 | - $error_field = str_replace( '_', ' ', $field ); |
|
298 | + $error_field = str_replace('_', ' ', $field); |
|
299 | 299 | |
300 | 300 | $org_str[] = 'stripe'; |
301 | 301 | $replace_str[] = ''; |
@@ -310,9 +310,9 @@ discard block |
||
310 | 310 | $replace_str[] = 'SOFORT'; |
311 | 311 | |
312 | 312 | $org_str[] = 'owner'; |
313 | - $replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' ); |
|
313 | + $replace_str[] = __('Owner', 'woocommerce-gateway-stripe'); |
|
314 | 314 | |
315 | - $error_field = str_replace( $org_str, $replace_str, $error_field ); |
|
315 | + $error_field = str_replace($org_str, $replace_str, $error_field); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | return $error_field; |
@@ -325,154 +325,154 @@ discard block |
||
325 | 325 | * @version 4.0.0 |
326 | 326 | */ |
327 | 327 | public function validate_checkout() { |
328 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) { |
|
329 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
328 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) { |
|
329 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $errors = new WP_Error(); |
333 | - parse_str( $_POST['required_fields'], $required_fields ); |
|
334 | - parse_str( $_POST['all_fields'], $all_fields ); |
|
335 | - $source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : ''; |
|
333 | + parse_str($_POST['required_fields'], $required_fields); |
|
334 | + parse_str($_POST['all_fields'], $all_fields); |
|
335 | + $source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : ''; |
|
336 | 336 | $validate_shipping_fields = false; |
337 | 337 | $create_account = false; |
338 | 338 | |
339 | - array_walk_recursive( $required_fields, 'wc_clean' ); |
|
340 | - array_walk_recursive( $all_fields, 'wc_clean' ); |
|
339 | + array_walk_recursive($required_fields, 'wc_clean'); |
|
340 | + array_walk_recursive($all_fields, 'wc_clean'); |
|
341 | 341 | |
342 | 342 | // Remove unneeded required fields depending on source type. |
343 | - if ( 'stripe_sepa' !== $source_type ) { |
|
344 | - unset( $required_fields['stripe_sepa_owner'] ); |
|
345 | - unset( $required_fields['stripe_sepa_iban'] ); |
|
343 | + if ('stripe_sepa' !== $source_type) { |
|
344 | + unset($required_fields['stripe_sepa_owner']); |
|
345 | + unset($required_fields['stripe_sepa_iban']); |
|
346 | 346 | } |
347 | 347 | |
348 | - if ( 'stripe_sofort' !== $source_type ) { |
|
349 | - unset( $required_fields['stripe_sofort_bank_country'] ); |
|
348 | + if ('stripe_sofort' !== $source_type) { |
|
349 | + unset($required_fields['stripe_sofort_bank_country']); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
353 | 353 | * If ship to different address checkbox is checked then we need |
354 | 354 | * to validate shipping fields too. |
355 | 355 | */ |
356 | - if ( isset( $all_fields['ship_to_different_address'] ) ) { |
|
356 | + if (isset($all_fields['ship_to_different_address'])) { |
|
357 | 357 | $validate_shipping_fields = true; |
358 | 358 | } |
359 | 359 | |
360 | 360 | // Check if createaccount is checked. |
361 | - if ( isset( $all_fields['createaccount'] ) ) { |
|
361 | + if (isset($all_fields['createaccount'])) { |
|
362 | 362 | $create_account = true; |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Check if required fields are empty. |
366 | - foreach ( $required_fields as $field => $field_value ) { |
|
366 | + foreach ($required_fields as $field => $field_value) { |
|
367 | 367 | // Check for shipping field. |
368 | - if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) { |
|
368 | + if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) { |
|
369 | 369 | continue; |
370 | 370 | } |
371 | 371 | |
372 | 372 | // Check create account name. |
373 | - if ( 'account_username' === $field && ! $create_account ) { |
|
373 | + if ('account_username' === $field && ! $create_account) { |
|
374 | 374 | continue; |
375 | 375 | } |
376 | 376 | |
377 | 377 | // Check create account password. |
378 | - if ( 'account_password' === $field && ! $create_account ) { |
|
378 | + if ('account_password' === $field && ! $create_account) { |
|
379 | 379 | continue; |
380 | 380 | } |
381 | 381 | |
382 | 382 | // Check if is SEPA. |
383 | - if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field ) { |
|
383 | + if ('stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field) { |
|
384 | 384 | continue; |
385 | 385 | } |
386 | 386 | |
387 | - if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field ) { |
|
387 | + if ('stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field) { |
|
388 | 388 | $continue; |
389 | 389 | } |
390 | 390 | |
391 | - if ( empty( $field_value ) || '-1' === $field_value ) { |
|
392 | - $error_field = $this->normalize_field( $field ); |
|
391 | + if (empty($field_value) || '-1' === $field_value) { |
|
392 | + $error_field = $this->normalize_field($field); |
|
393 | 393 | /* translators: error field name */ |
394 | - $errors->add( 'validation', sprintf( __( '%s cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) ); |
|
394 | + $errors->add('validation', sprintf(__('%s cannot be empty', 'woocommerce-gateway-stripe'), $error_field)); |
|
395 | 395 | } |
396 | 396 | } |
397 | 397 | |
398 | 398 | // Check if email is valid format. |
399 | - if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) { |
|
400 | - $errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) ); |
|
399 | + if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) { |
|
400 | + $errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe')); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | // Check if phone number is valid format. |
404 | - if ( ! empty( $required_fields['billing_phone'] ) ) { |
|
405 | - $phone = wc_format_phone_number( $required_fields['billing_phone'] ); |
|
404 | + if ( ! empty($required_fields['billing_phone'])) { |
|
405 | + $phone = wc_format_phone_number($required_fields['billing_phone']); |
|
406 | 406 | |
407 | - if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) { |
|
407 | + if ('' !== $phone && ! WC_Validation::is_phone($phone)) { |
|
408 | 408 | /* translators: %s: phone number */ |
409 | - $errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) ); |
|
409 | + $errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe')); |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | |
413 | 413 | // Check if postal code is valid format. |
414 | - if ( ! empty( $required_fields['billing_postcode'] ) ) { |
|
415 | - $country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
416 | - $postcode = wc_format_postcode( $required_fields['billing_postcode'], $country ); |
|
414 | + if ( ! empty($required_fields['billing_postcode'])) { |
|
415 | + $country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
416 | + $postcode = wc_format_postcode($required_fields['billing_postcode'], $country); |
|
417 | 417 | |
418 | - if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
419 | - $errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
418 | + if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
419 | + $errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
420 | 420 | } |
421 | 421 | } |
422 | 422 | |
423 | 423 | // Don't check this on add payment method page. |
424 | - if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) { |
|
425 | - if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) { |
|
426 | - $errors->add( 'terms', __( 'You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe' ) ); |
|
424 | + if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) { |
|
425 | + if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) { |
|
426 | + $errors->add('terms', __('You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe')); |
|
427 | 427 | } |
428 | 428 | } |
429 | 429 | |
430 | - if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) { |
|
430 | + if (WC()->cart->needs_shipping() && $validate_shipping_fields) { |
|
431 | 431 | // Check if postal code is valid format. |
432 | - if ( ! empty( $required_fields['shipping_postcode'] ) ) { |
|
433 | - $country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
434 | - $postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country ); |
|
432 | + if ( ! empty($required_fields['shipping_postcode'])) { |
|
433 | + $country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
434 | + $postcode = wc_format_postcode($required_fields['shipping_postcode'], $country); |
|
435 | 435 | |
436 | - if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
437 | - $errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
436 | + if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
437 | + $errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
438 | 438 | } |
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | - if ( WC()->cart->needs_shipping() ) { |
|
442 | + if (WC()->cart->needs_shipping()) { |
|
443 | 443 | $shipping_country = WC()->customer->get_shipping_country(); |
444 | 444 | |
445 | - if ( empty( $shipping_country ) ) { |
|
446 | - $errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) ); |
|
447 | - } elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) { |
|
445 | + if (empty($shipping_country)) { |
|
446 | + $errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe')); |
|
447 | + } elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) { |
|
448 | 448 | /* translators: country name */ |
449 | - $errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) ); |
|
449 | + $errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country())); |
|
450 | 450 | } else { |
451 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
451 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
452 | 452 | |
453 | - foreach ( WC()->shipping->get_packages() as $i => $package ) { |
|
454 | - if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) { |
|
455 | - $errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) ); |
|
453 | + foreach (WC()->shipping->get_packages() as $i => $package) { |
|
454 | + if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) { |
|
455 | + $errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe')); |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | - if ( WC()->cart->needs_payment() ) { |
|
461 | + if (WC()->cart->needs_payment()) { |
|
462 | 462 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
463 | 463 | |
464 | - if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) { |
|
465 | - $errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) ); |
|
464 | + if ( ! isset($available_gateways[$all_fields['payment_method']])) { |
|
465 | + $errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe')); |
|
466 | 466 | } else { |
467 | - $available_gateways[ $all_fields['payment_method'] ]->validate_fields(); |
|
467 | + $available_gateways[$all_fields['payment_method']]->validate_fields(); |
|
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
471 | - if ( 0 === count( $errors->errors ) ) { |
|
472 | - wp_send_json( 'success' ); |
|
471 | + if (0 === count($errors->errors)) { |
|
472 | + wp_send_json('success'); |
|
473 | 473 | } else { |
474 | - foreach ( $errors->get_error_messages() as $message ) { |
|
475 | - wc_add_notice( $message, 'error' ); |
|
474 | + foreach ($errors->get_error_messages() as $message) { |
|
475 | + wc_add_notice($message, 'error'); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | $this->send_ajax_failure_response(); |
@@ -486,9 +486,9 @@ discard block |
||
486 | 486 | * @version 4.0.0 |
487 | 487 | */ |
488 | 488 | public function send_ajax_failure_response() { |
489 | - if ( is_ajax() ) { |
|
489 | + if (is_ajax()) { |
|
490 | 490 | // only print notices if not reloading the checkout, otherwise they're lost in the page reload. |
491 | - if ( ! isset( WC()->session->reload_checkout ) ) { |
|
491 | + if ( ! isset(WC()->session->reload_checkout)) { |
|
492 | 492 | ob_start(); |
493 | 493 | wc_print_notices(); |
494 | 494 | $messages = ob_get_clean(); |
@@ -496,14 +496,14 @@ discard block |
||
496 | 496 | |
497 | 497 | $response = array( |
498 | 498 | 'result' => 'failure', |
499 | - 'messages' => isset( $messages ) ? $messages : '', |
|
500 | - 'refresh' => isset( WC()->session->refresh_totals ), |
|
501 | - 'reload' => isset( WC()->session->reload_checkout ), |
|
499 | + 'messages' => isset($messages) ? $messages : '', |
|
500 | + 'refresh' => isset(WC()->session->refresh_totals), |
|
501 | + 'reload' => isset(WC()->session->reload_checkout), |
|
502 | 502 | ); |
503 | 503 | |
504 | - unset( WC()->session->refresh_totals, WC()->session->reload_checkout ); |
|
504 | + unset(WC()->session->refresh_totals, WC()->session->reload_checkout); |
|
505 | 505 | |
506 | - wp_send_json( $response ); |
|
506 | + wp_send_json($response); |
|
507 | 507 | } |
508 | 508 | } |
509 | 509 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -17,15 +17,15 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @return float|int |
19 | 19 | */ |
20 | - public static function get_stripe_amount( $total, $currency = '' ) { |
|
21 | - if ( ! $currency ) { |
|
20 | + public static function get_stripe_amount($total, $currency = '') { |
|
21 | + if ( ! $currency) { |
|
22 | 22 | $currency = get_woocommerce_currency(); |
23 | 23 | } |
24 | 24 | |
25 | - if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) { |
|
26 | - return absint( $total ); |
|
25 | + if (in_array(strtolower($currency), self::no_decimal_currencies())) { |
|
26 | + return absint($total); |
|
27 | 27 | } else { |
28 | - return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents. |
|
28 | + return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents. |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | * @return array |
38 | 38 | */ |
39 | 39 | public static function get_localized_messages() { |
40 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
41 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
42 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
43 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
44 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
45 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
46 | - 'incomplete_number' => __( 'Your card number is incomplete.', 'woocommerce-gateway-stripe' ), |
|
47 | - 'incomplete_cvc' => __( 'Your card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ), |
|
48 | - 'incomplete_expiry' => __( 'Your card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe' ), |
|
49 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
50 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
51 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
52 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
53 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
54 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
55 | - 'invalid_request_error' => __( 'Could not find payment information. Please try with another payment method.', 'woocommerce-gateway-stripe' ), |
|
56 | - 'invalid_expiry_year_past' => __( 'Your card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ), |
|
57 | - ) ); |
|
40 | + return apply_filters('wc_stripe_localized_messages', array( |
|
41 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
42 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
43 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
44 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
45 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
46 | + 'incomplete_number' => __('Your card number is incomplete.', 'woocommerce-gateway-stripe'), |
|
47 | + 'incomplete_cvc' => __('Your card\'s security code is incomplete.', 'woocommerce-gateway-stripe'), |
|
48 | + 'incomplete_expiry' => __('Your card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe'), |
|
49 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
50 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
51 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
52 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
53 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
54 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
55 | + 'invalid_request_error' => __('Could not find payment information. Please try with another payment method.', 'woocommerce-gateway-stripe'), |
|
56 | + 'invalid_expiry_year_past' => __('Your card\'s expiration year is in the past', 'woocommerce-gateway-stripe'), |
|
57 | + )); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -91,24 +91,24 @@ discard block |
||
91 | 91 | * @param string $type Type of number to format |
92 | 92 | * @return string |
93 | 93 | */ |
94 | - public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
95 | - if ( ! is_object( $balance_transaction ) ) { |
|
94 | + public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
95 | + if ( ! is_object($balance_transaction)) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
100 | - if ( 'fee' === $type ) { |
|
99 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
100 | + if ('fee' === $type) { |
|
101 | 101 | return $balance_transaction->fee; |
102 | 102 | } |
103 | 103 | |
104 | 104 | return $balance_transaction->net; |
105 | 105 | } |
106 | 106 | |
107 | - if ( 'fee' === $type ) { |
|
108 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
107 | + if ('fee' === $type) { |
|
108 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
109 | 109 | } |
110 | 110 | |
111 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
111 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public static function get_minimum_amount() { |
118 | 118 | // Check order amount |
119 | - switch ( get_woocommerce_currency() ) { |
|
119 | + switch (get_woocommerce_currency()) { |
|
120 | 120 | case 'USD': |
121 | 121 | case 'CAD': |
122 | 122 | case 'EUR': |
@@ -161,14 +161,14 @@ discard block |
||
161 | 161 | * @param string $method The payment method to get the settings from. |
162 | 162 | * @param string $setting The name of the setting to get. |
163 | 163 | */ |
164 | - public static function get_settings( $method = null, $setting = null ) { |
|
165 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
164 | + public static function get_settings($method = null, $setting = null) { |
|
165 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
166 | 166 | |
167 | - if ( null === $setting ) { |
|
167 | + if (null === $setting) { |
|
168 | 168 | return $all_settings; |
169 | 169 | } |
170 | 170 | |
171 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
171 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @return bool |
180 | 180 | */ |
181 | 181 | public static function is_pre_30() { |
182 | - return version_compare( WC_VERSION, '3.0.0', '<' ); |
|
182 | + return version_compare(WC_VERSION, '3.0.0', '<'); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @return string |
193 | 193 | */ |
194 | 194 | public static function get_webhook_url() { |
195 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
195 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | * @version 4.0.0 |
203 | 203 | * @param string $source_id |
204 | 204 | */ |
205 | - public static function get_order_by_source_id( $source_id ) { |
|
205 | + public static function get_order_by_source_id($source_id) { |
|
206 | 206 | global $wpdb; |
207 | 207 | |
208 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id ) ); |
|
208 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id)); |
|
209 | 209 | |
210 | - if ( ! empty( $order_id ) ) { |
|
211 | - return wc_get_order( $order_id ); |
|
210 | + if ( ! empty($order_id)) { |
|
211 | + return wc_get_order($order_id); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | return false; |
@@ -221,13 +221,13 @@ discard block |
||
221 | 221 | * @version 4.0.0 |
222 | 222 | * @param string $charge_id |
223 | 223 | */ |
224 | - public static function get_order_by_charge_id( $charge_id ) { |
|
224 | + public static function get_order_by_charge_id($charge_id) { |
|
225 | 225 | global $wpdb; |
226 | 226 | |
227 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id ) ); |
|
227 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id)); |
|
228 | 228 | |
229 | - if ( ! empty( $order_id ) ) { |
|
230 | - return wc_get_order( $order_id ); |
|
229 | + if ( ! empty($order_id)) { |
|
230 | + return wc_get_order($order_id); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | return false; |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | * @param string $statement_descriptor |
244 | 244 | * @return string $statement_descriptor Sanitized statement descriptor |
245 | 245 | */ |
246 | - public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
247 | - $disallowed_characters = array( '<', '>', '"', "'" ); |
|
246 | + public static function clean_statement_descriptor($statement_descriptor = '') { |
|
247 | + $disallowed_characters = array('<', '>', '"', "'"); |
|
248 | 248 | |
249 | 249 | // Remove special characters. |
250 | - $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
250 | + $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
251 | 251 | |
252 | - $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
252 | + $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
253 | 253 | |
254 | 254 | return $statement_descriptor; |
255 | 255 | } |
@@ -14,20 +14,20 @@ discard block |
||
14 | 14 | * |
15 | 15 | */ |
16 | 16 | |
17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
17 | +if ( ! defined('ABSPATH')) { |
|
18 | 18 | exit; |
19 | 19 | } |
20 | 20 | |
21 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
21 | +if ( ! class_exists('WC_Stripe')) : |
|
22 | 22 | /** |
23 | 23 | * Required minimums and constants |
24 | 24 | */ |
25 | - define( 'WC_STRIPE_VERSION', '4.0.1' ); |
|
26 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
27 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
28 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
29 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
30 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
25 | + define('WC_STRIPE_VERSION', '4.0.1'); |
|
26 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
27 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
28 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
29 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
30 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
31 | 31 | |
32 | 32 | class WC_Stripe { |
33 | 33 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return Singleton The *Singleton* instance. |
48 | 48 | */ |
49 | 49 | public static function get_instance() { |
50 | - if ( null === self::$instance ) { |
|
50 | + if (null === self::$instance) { |
|
51 | 51 | self::$instance = new self(); |
52 | 52 | } |
53 | 53 | return self::$instance; |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | * *Singleton* via the `new` operator from outside of this class. |
81 | 81 | */ |
82 | 82 | private function __construct() { |
83 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
84 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
85 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
86 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
83 | + add_action('admin_init', array($this, 'check_environment')); |
|
84 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
85 | + add_action('plugins_loaded', array($this, 'init')); |
|
86 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -93,42 +93,42 @@ discard block |
||
93 | 93 | * @version 4.0.0 |
94 | 94 | */ |
95 | 95 | public function init() { |
96 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
98 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
96 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
98 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
99 | 99 | |
100 | 100 | // Don't hook anything else in the plugin if we're in an incompatible environment |
101 | - if ( self::get_environment_warning() ) { |
|
101 | + if (self::get_environment_warning()) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
106 | - |
|
107 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
108 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
109 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
111 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
112 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
113 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
123 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
124 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
105 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
106 | + |
|
107 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
108 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
109 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
110 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
111 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
112 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
113 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
123 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
124 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
125 | 125 | |
126 | 126 | // REMOVE IN THE FUTURE. |
127 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
127 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
128 | 128 | |
129 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
130 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
131 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
129 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
130 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
131 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,23 +138,23 @@ discard block |
||
138 | 138 | * @version 4.0.0 |
139 | 139 | */ |
140 | 140 | public function hide_notices() { |
141 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
142 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
143 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
141 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
142 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
143 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
144 | 144 | } |
145 | 145 | |
146 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
147 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
146 | + if ( ! current_user_can('manage_woocommerce')) { |
|
147 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
148 | 148 | } |
149 | 149 | |
150 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
150 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
151 | 151 | |
152 | - switch ( $notice ) { |
|
152 | + switch ($notice) { |
|
153 | 153 | case 'ssl': |
154 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
154 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
155 | 155 | break; |
156 | 156 | case 'keys': |
157 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
157 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
158 | 158 | break; |
159 | 159 | } |
160 | 160 | } |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | * @since 1.0.0 |
167 | 167 | * @version 4.0.0 |
168 | 168 | */ |
169 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
170 | - $this->notices[ $slug ] = array( |
|
169 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
170 | + $this->notices[$slug] = array( |
|
171 | 171 | 'class' => $class, |
172 | 172 | 'message' => $message, |
173 | 173 | 'dismissible' => $dismissible, |
@@ -181,21 +181,21 @@ discard block |
||
181 | 181 | * @version 4.0.0 |
182 | 182 | */ |
183 | 183 | public function admin_notices() { |
184 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
184 | + if ( ! current_user_can('manage_woocommerce')) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
188 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
189 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
188 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
189 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
190 | 190 | |
191 | - if ( $notice['dismissible'] ) { |
|
191 | + if ($notice['dismissible']) { |
|
192 | 192 | ?> |
193 | - <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
193 | + <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
194 | 194 | <?php |
195 | 195 | } |
196 | 196 | |
197 | 197 | echo '<p>'; |
198 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
198 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
199 | 199 | echo '</p></div>'; |
200 | 200 | } |
201 | 201 | } |
@@ -208,26 +208,26 @@ discard block |
||
208 | 208 | * @version 4.0.0 |
209 | 209 | */ |
210 | 210 | public function get_environment_warning() { |
211 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
211 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
212 | 212 | /* translators: 1) int version 2) int version */ |
213 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
213 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
214 | 214 | |
215 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
215 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
216 | 216 | } |
217 | 217 | |
218 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
219 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
218 | + if ( ! defined('WC_VERSION')) { |
|
219 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
220 | 220 | } |
221 | 221 | |
222 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
222 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
223 | 223 | /* translators: 1) int version 2) int version */ |
224 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
224 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
225 | 225 | |
226 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
226 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
227 | 227 | } |
228 | 228 | |
229 | - if ( ! function_exists( 'curl_init' ) ) { |
|
230 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
229 | + if ( ! function_exists('curl_init')) { |
|
230 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | return false; |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | * @return string Setting link |
242 | 242 | */ |
243 | 243 | public function get_setting_link() { |
244 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
244 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
245 | 245 | |
246 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
246 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
247 | 247 | |
248 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
248 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -256,37 +256,37 @@ discard block |
||
256 | 256 | * @version 4.0.0 |
257 | 257 | */ |
258 | 258 | public function check_environment() { |
259 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
259 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
260 | 260 | $this->install(); |
261 | 261 | |
262 | - do_action( 'woocommerce_stripe_updated' ); |
|
262 | + do_action('woocommerce_stripe_updated'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | $environment_warning = $this->get_environment_warning(); |
266 | 266 | |
267 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
268 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
267 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
268 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
269 | 269 | } |
270 | 270 | |
271 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
272 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
273 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
271 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
272 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
273 | + $options = get_option('woocommerce_stripe_settings'); |
|
274 | 274 | |
275 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
276 | - $secret = WC_Stripe_API::get_secret_key(); |
|
275 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
276 | + $secret = WC_Stripe_API::get_secret_key(); |
|
277 | 277 | |
278 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
278 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
279 | 279 | $setting_link = $this->get_setting_link(); |
280 | 280 | /* translators: 1) link */ |
281 | - $this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
281 | + $this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
285 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
285 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
286 | 286 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
287 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
287 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
288 | 288 | /* translators: 1) link 2) link */ |
289 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
|
289 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true); |
|
290 | 290 | } |
291 | 291 | } |
292 | 292 | } |
@@ -298,8 +298,8 @@ discard block |
||
298 | 298 | * @version 4.0.0 |
299 | 299 | */ |
300 | 300 | public function update_plugin_version() { |
301 | - delete_option( 'wc_stripe_version' ); |
|
302 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
301 | + delete_option('wc_stripe_version'); |
|
302 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -309,8 +309,8 @@ discard block |
||
309 | 309 | * @version 3.1.0 |
310 | 310 | */ |
311 | 311 | public function install() { |
312 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
313 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
312 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
313 | + define('WC_STRIPE_INSTALLING', true); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | $this->update_plugin_version(); |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | * @since 1.0.0 |
323 | 323 | * @version 4.0.0 |
324 | 324 | */ |
325 | - public function plugin_action_links( $links ) { |
|
325 | + public function plugin_action_links($links) { |
|
326 | 326 | $plugin_links = array( |
327 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
328 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
329 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
327 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
328 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
329 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
330 | 330 | ); |
331 | - return array_merge( $plugin_links, $links ); |
|
331 | + return array_merge($plugin_links, $links); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
@@ -337,8 +337,8 @@ discard block |
||
337 | 337 | * @since 1.0.0 |
338 | 338 | * @version 4.0.0 |
339 | 339 | */ |
340 | - public function add_gateways( $methods ) { |
|
341 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
340 | + public function add_gateways($methods) { |
|
341 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
342 | 342 | $methods[] = 'WC_Stripe_Compat'; |
343 | 343 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
344 | 344 | } else { |
@@ -363,26 +363,26 @@ discard block |
||
363 | 363 | * @since 4.0.0 |
364 | 364 | * @version 4.0.0 |
365 | 365 | */ |
366 | - public function filter_gateway_order_admin( $sections ) { |
|
367 | - unset( $sections['stripe'] ); |
|
368 | - unset( $sections['stripe_bancontact'] ); |
|
369 | - unset( $sections['stripe_sofort'] ); |
|
370 | - unset( $sections['stripe_giropay'] ); |
|
371 | - unset( $sections['stripe_ideal'] ); |
|
372 | - unset( $sections['stripe_p24'] ); |
|
373 | - unset( $sections['stripe_alipay'] ); |
|
374 | - unset( $sections['stripe_sepa'] ); |
|
375 | - unset( $sections['stripe_bitcoin'] ); |
|
366 | + public function filter_gateway_order_admin($sections) { |
|
367 | + unset($sections['stripe']); |
|
368 | + unset($sections['stripe_bancontact']); |
|
369 | + unset($sections['stripe_sofort']); |
|
370 | + unset($sections['stripe_giropay']); |
|
371 | + unset($sections['stripe_ideal']); |
|
372 | + unset($sections['stripe_p24']); |
|
373 | + unset($sections['stripe_alipay']); |
|
374 | + unset($sections['stripe_sepa']); |
|
375 | + unset($sections['stripe_bitcoin']); |
|
376 | 376 | |
377 | 377 | $sections['stripe'] = 'Stripe'; |
378 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
379 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
380 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
381 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
382 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
383 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
384 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
385 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
378 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
379 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
380 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
381 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
382 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
383 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
384 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
385 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
386 | 386 | |
387 | 387 | return $sections; |
388 | 388 | } |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
7 | 7 | * DEPRECATED DO NOT USE!! |
8 | 8 | */ |
9 | -if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) { |
|
9 | +if ( ! class_exists('WC_Stripe_Apple_Pay')) { |
|
10 | 10 | class WC_Stripe_Apple_Pay { |
11 | 11 | /** |
12 | 12 | * This Instance. |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | } |
22 | 22 | |
23 | 23 | public static function instance() { |
24 | - WC_Stripe_Logger::log( "DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance." ); |
|
24 | + WC_Stripe_Logger::log("DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance."); |
|
25 | 25 | return self::$_this; |
26 | 26 | } |
27 | 27 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 3.1.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -42,30 +42,30 @@ discard block |
||
42 | 42 | * @version 4.0.0 |
43 | 43 | */ |
44 | 44 | public function __construct() { |
45 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
45 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
46 | 46 | $this->publishable_key = $this->get_publishable_key(); |
47 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
48 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
47 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
48 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
49 | 49 | |
50 | 50 | // If both site title and statement descriptor is not set. Fallback. |
51 | - if ( empty( $this->total_label ) ) { |
|
51 | + if (empty($this->total_label)) { |
|
52 | 52 | $this->total_label = $_SERVER['SERVER_NAME']; |
53 | 53 | } |
54 | 54 | |
55 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
55 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
56 | 56 | |
57 | 57 | // Checks if Stripe Gateway is enabled. |
58 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
58 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
62 | 62 | // Checks if Payment Request is enabled. |
63 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
63 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // Don't load for change payment method page. |
68 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
68 | + if (isset($_GET['change_payment_method'])) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
@@ -79,38 +79,38 @@ discard block |
||
79 | 79 | * @version 4.0.0 |
80 | 80 | */ |
81 | 81 | protected function init() { |
82 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
83 | - add_action( 'wp', array( $this, 'set_session' ) ); |
|
82 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
83 | + add_action('wp', array($this, 'set_session')); |
|
84 | 84 | |
85 | 85 | /* |
86 | 86 | * In order to display the Payment Request button in the correct position, |
87 | 87 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
88 | 88 | * CSS is used to position the button. |
89 | 89 | */ |
90 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
91 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
92 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
90 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
91 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
92 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
93 | 93 | } else { |
94 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
95 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
94 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
95 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
96 | 96 | } |
97 | 97 | |
98 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
99 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
98 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
99 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
100 | 100 | |
101 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
102 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
103 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
104 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
105 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
106 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
107 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
108 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
101 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
102 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
103 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
104 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
105 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
106 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
107 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
108 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
109 | 109 | |
110 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
111 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
110 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
111 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
112 | 112 | |
113 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 ); |
|
113 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | * @since 4.0.0 |
121 | 121 | */ |
122 | 122 | public function set_session() { |
123 | - if ( ! is_user_logged_in() ) { |
|
123 | + if ( ! is_user_logged_in()) { |
|
124 | 124 | $wc_session = new WC_Session_Handler(); |
125 | 125 | |
126 | - if ( ! $wc_session->has_session() ) { |
|
127 | - $wc_session->set_customer_session_cookie( true ); |
|
126 | + if ( ! $wc_session->has_session()) { |
|
127 | + $wc_session->set_customer_session_cookie(true); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | } |
@@ -135,15 +135,15 @@ discard block |
||
135 | 135 | * @return string |
136 | 136 | */ |
137 | 137 | protected function get_publishable_key() { |
138 | - if ( empty( $this->stripe_settings ) ) { |
|
138 | + if (empty($this->stripe_settings)) { |
|
139 | 139 | return ''; |
140 | 140 | } |
141 | 141 | |
142 | - if ( empty( $this->stripe_settings['testmode'] ) ) { |
|
142 | + if (empty($this->stripe_settings['testmode'])) { |
|
143 | 143 | return ''; |
144 | 144 | } |
145 | 145 | |
146 | - if ( empty( $this->stripe_settings['test_publishable_key'] ) ) { |
|
146 | + if (empty($this->stripe_settings['test_publishable_key'])) { |
|
147 | 147 | return ''; |
148 | 148 | } |
149 | 149 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | public function get_button_type() { |
161 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
161 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * @return string |
170 | 170 | */ |
171 | 171 | public function get_button_theme() { |
172 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
172 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @return string |
181 | 181 | */ |
182 | 182 | public function get_button_height() { |
183 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
183 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -190,40 +190,40 @@ discard block |
||
190 | 190 | * @version 4.0.0 |
191 | 191 | */ |
192 | 192 | public function get_product_data() { |
193 | - if ( ! is_product() ) { |
|
193 | + if ( ! is_product()) { |
|
194 | 194 | return false; |
195 | 195 | } |
196 | 196 | |
197 | 197 | global $post; |
198 | 198 | |
199 | - $product = wc_get_product( $post->ID ); |
|
199 | + $product = wc_get_product($post->ID); |
|
200 | 200 | |
201 | 201 | $data = array(); |
202 | 202 | $items = array(); |
203 | 203 | |
204 | 204 | $items[] = array( |
205 | 205 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
206 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
206 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
207 | 207 | ); |
208 | 208 | |
209 | - if ( wc_tax_enabled() ) { |
|
209 | + if (wc_tax_enabled()) { |
|
210 | 210 | $items[] = array( |
211 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
211 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
212 | 212 | 'amount' => 0, |
213 | 213 | 'pending' => true, |
214 | 214 | ); |
215 | 215 | } |
216 | 216 | |
217 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
217 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
218 | 218 | $items[] = array( |
219 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
219 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
220 | 220 | 'amount' => 0, |
221 | 221 | 'pending' => true, |
222 | 222 | ); |
223 | 223 | |
224 | - $data['shippingOptions'] = array( |
|
224 | + $data['shippingOptions'] = array( |
|
225 | 225 | 'id' => 'pending', |
226 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
226 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
227 | 227 | 'detail' => '', |
228 | 228 | 'amount' => 0, |
229 | 229 | ); |
@@ -232,13 +232,13 @@ discard block |
||
232 | 232 | $data['displayItems'] = $items; |
233 | 233 | $data['total'] = array( |
234 | 234 | 'label' => $this->total_label, |
235 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
235 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
236 | 236 | 'pending' => true, |
237 | 237 | ); |
238 | 238 | |
239 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
240 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
241 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
239 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
240 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
241 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
242 | 242 | |
243 | 243 | return $data; |
244 | 244 | } |
@@ -247,25 +247,25 @@ discard block |
||
247 | 247 | * Filters the gateway title to reflect Payment Request type |
248 | 248 | * |
249 | 249 | */ |
250 | - public function filter_gateway_title( $title, $id ) { |
|
250 | + public function filter_gateway_title($title, $id) { |
|
251 | 251 | global $post; |
252 | 252 | |
253 | - if ( ! is_object( $post ) ) { |
|
253 | + if ( ! is_object($post)) { |
|
254 | 254 | return $title; |
255 | 255 | } |
256 | 256 | |
257 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
258 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
257 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
258 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
259 | 259 | } else { |
260 | - $order = wc_get_order( $post->ID ); |
|
261 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
260 | + $order = wc_get_order($post->ID); |
|
261 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
262 | 262 | } |
263 | 263 | |
264 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
264 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
265 | 265 | return $method_title; |
266 | 266 | } |
267 | 267 | |
268 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
268 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
269 | 269 | return $method_title; |
270 | 270 | } |
271 | 271 | |
@@ -278,10 +278,10 @@ discard block |
||
278 | 278 | * @since 3.1.4 |
279 | 279 | * @version 4.0.0 |
280 | 280 | */ |
281 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
281 | + public function postal_code_validation($valid, $postcode, $country) { |
|
282 | 282 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
283 | 283 | |
284 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
284 | + if ( ! isset($gateways['stripe'])) { |
|
285 | 285 | return $valid; |
286 | 286 | } |
287 | 287 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * the order and not let it go through. The remedy for now is just to remove this validation. |
292 | 292 | * Note that this only works with shipping providers that don't validate full postal codes. |
293 | 293 | */ |
294 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
294 | + if ('GB' === $country || 'CA' === $country) { |
|
295 | 295 | return true; |
296 | 296 | } |
297 | 297 | |
@@ -307,27 +307,27 @@ discard block |
||
307 | 307 | * @param array $posted_data The posted data from checkout form. |
308 | 308 | * @param object $order |
309 | 309 | */ |
310 | - public function add_order_meta( $order_id, $posted_data, $order ) { |
|
311 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
310 | + public function add_order_meta($order_id, $posted_data, $order) { |
|
311 | + if (empty($_POST['payment_request_type'])) { |
|
312 | 312 | return; |
313 | 313 | } |
314 | 314 | |
315 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
315 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
316 | 316 | |
317 | - if ( 'apple_pay' === $payment_request_type ) { |
|
318 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
319 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
317 | + if ('apple_pay' === $payment_request_type) { |
|
318 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
319 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
320 | 320 | } else { |
321 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
321 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
322 | 322 | $order->save(); |
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
326 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
327 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
328 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
326 | + if ('payment_request_api' === $payment_request_type) { |
|
327 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
328 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
329 | 329 | } else { |
330 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
330 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
331 | 331 | $order->save(); |
332 | 332 | } |
333 | 333 | } |
@@ -341,11 +341,11 @@ discard block |
||
341 | 341 | * @return array |
342 | 342 | */ |
343 | 343 | public function supported_product_types() { |
344 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
344 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
345 | 345 | 'simple', |
346 | 346 | 'variable', |
347 | 347 | 'variation', |
348 | - ) ); |
|
348 | + )); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -356,15 +356,15 @@ discard block |
||
356 | 356 | * @return bool |
357 | 357 | */ |
358 | 358 | public function allowed_items_in_cart() { |
359 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
360 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
359 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
360 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
361 | 361 | |
362 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
362 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
363 | 363 | return false; |
364 | 364 | } |
365 | 365 | |
366 | 366 | // Pre Orders compatbility where we don't support charge upon release. |
367 | - 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() ) ) { |
|
367 | + 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())) { |
|
368 | 368 | return false; |
369 | 369 | } |
370 | 370 | } |
@@ -379,71 +379,71 @@ discard block |
||
379 | 379 | * @version 4.0.0 |
380 | 380 | */ |
381 | 381 | public function scripts() { |
382 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
382 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
383 | 383 | return; |
384 | 384 | } |
385 | 385 | |
386 | - if ( is_product() ) { |
|
386 | + if (is_product()) { |
|
387 | 387 | global $post; |
388 | 388 | |
389 | - $product = wc_get_product( $post->ID ); |
|
389 | + $product = wc_get_product($post->ID); |
|
390 | 390 | |
391 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
391 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
392 | 392 | return; |
393 | 393 | } |
394 | 394 | |
395 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
395 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
396 | 396 | return; |
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
400 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
400 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
401 | 401 | |
402 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
403 | - 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 ); |
|
402 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
403 | + 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); |
|
404 | 404 | |
405 | 405 | wp_localize_script( |
406 | 406 | 'wc_stripe_payment_request', |
407 | 407 | 'wc_stripe_payment_request_params', |
408 | 408 | array( |
409 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
409 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
410 | 410 | 'stripe' => array( |
411 | 411 | 'key' => $this->get_publishable_key(), |
412 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
412 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
413 | 413 | ), |
414 | 414 | 'nonce' => array( |
415 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
416 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
417 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
418 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
419 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
420 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
421 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
422 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
415 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
416 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
417 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
418 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
419 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
420 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
421 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
422 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
423 | 423 | ), |
424 | 424 | 'i18n' => array( |
425 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
425 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
426 | 426 | /* translators: Do not translate the [option] placeholder */ |
427 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
427 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
428 | 428 | ), |
429 | 429 | 'checkout' => array( |
430 | 430 | 'url' => wc_get_checkout_url(), |
431 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
432 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
431 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
432 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
433 | 433 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
434 | 434 | ), |
435 | 435 | 'button' => array( |
436 | 436 | 'type' => $this->get_button_type(), |
437 | 437 | 'theme' => $this->get_button_theme(), |
438 | 438 | 'height' => $this->get_button_height(), |
439 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
439 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
440 | 440 | ), |
441 | 441 | 'is_product_page' => is_product(), |
442 | 442 | 'product' => $this->get_product_data(), |
443 | 443 | ) |
444 | 444 | ); |
445 | 445 | |
446 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
446 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -455,35 +455,35 @@ discard block |
||
455 | 455 | public function display_payment_request_button_html() { |
456 | 456 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
457 | 457 | |
458 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
458 | + if ( ! isset($gateways['stripe'])) { |
|
459 | 459 | return; |
460 | 460 | } |
461 | 461 | |
462 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
462 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
463 | 463 | return; |
464 | 464 | } |
465 | 465 | |
466 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
466 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
467 | 467 | return; |
468 | 468 | } |
469 | 469 | |
470 | - if ( is_product() ) { |
|
470 | + if (is_product()) { |
|
471 | 471 | global $post; |
472 | 472 | |
473 | - $product = wc_get_product( $post->ID ); |
|
473 | + $product = wc_get_product($post->ID); |
|
474 | 474 | |
475 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
475 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
476 | 476 | return; |
477 | 477 | } |
478 | 478 | |
479 | 479 | // Pre Orders charge upon release not supported. |
480 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
481 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
480 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
481 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
482 | 482 | return; |
483 | 483 | } |
484 | 484 | } else { |
485 | - if ( ! $this->allowed_items_in_cart() ) { |
|
486 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
485 | + if ( ! $this->allowed_items_in_cart()) { |
|
486 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
487 | 487 | return; |
488 | 488 | } |
489 | 489 | } |
@@ -505,40 +505,40 @@ discard block |
||
505 | 505 | public function display_payment_request_button_separator_html() { |
506 | 506 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
507 | 507 | |
508 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
508 | + if ( ! isset($gateways['stripe'])) { |
|
509 | 509 | return; |
510 | 510 | } |
511 | 511 | |
512 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
512 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
513 | 513 | return; |
514 | 514 | } |
515 | 515 | |
516 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
516 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
517 | 517 | return; |
518 | 518 | } |
519 | 519 | |
520 | - if ( is_product() ) { |
|
520 | + if (is_product()) { |
|
521 | 521 | global $post; |
522 | 522 | |
523 | - $product = wc_get_product( $post->ID ); |
|
523 | + $product = wc_get_product($post->ID); |
|
524 | 524 | |
525 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
525 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
526 | 526 | return; |
527 | 527 | } |
528 | 528 | |
529 | 529 | // Pre Orders charge upon release not supported. |
530 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
531 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
530 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
531 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
532 | 532 | return; |
533 | 533 | } |
534 | 534 | } else { |
535 | - if ( ! $this->allowed_items_in_cart() ) { |
|
536 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
535 | + if ( ! $this->allowed_items_in_cart()) { |
|
536 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
537 | 537 | return; |
538 | 538 | } |
539 | 539 | } |
540 | 540 | ?> |
541 | - <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> |
|
541 | + <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> |
|
542 | 542 | <?php |
543 | 543 | } |
544 | 544 | |
@@ -549,11 +549,11 @@ discard block |
||
549 | 549 | * @version 4.0.0 |
550 | 550 | */ |
551 | 551 | public function ajax_log_errors() { |
552 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
552 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
553 | 553 | |
554 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
554 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
555 | 555 | |
556 | - WC_Stripe_Logger::log( $errors ); |
|
556 | + WC_Stripe_Logger::log($errors); |
|
557 | 557 | |
558 | 558 | exit; |
559 | 559 | } |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | * @version 4.0.0 |
566 | 566 | */ |
567 | 567 | public function ajax_clear_cart() { |
568 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
568 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
569 | 569 | |
570 | 570 | WC()->cart->empty_cart(); |
571 | 571 | exit; |
@@ -575,10 +575,10 @@ discard block |
||
575 | 575 | * Get cart details. |
576 | 576 | */ |
577 | 577 | public function ajax_get_cart_details() { |
578 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
578 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
579 | 579 | |
580 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
581 | - define( 'WOOCOMMERCE_CART', true ); |
|
580 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
581 | + define('WOOCOMMERCE_CART', true); |
|
582 | 582 | } |
583 | 583 | |
584 | 584 | WC()->cart->calculate_totals(); |
@@ -589,14 +589,14 @@ discard block |
||
589 | 589 | $data = array( |
590 | 590 | 'shipping_required' => WC()->cart->needs_shipping(), |
591 | 591 | 'order_data' => array( |
592 | - 'currency' => strtolower( $currency ), |
|
593 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
592 | + 'currency' => strtolower($currency), |
|
593 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
594 | 594 | ), |
595 | 595 | ); |
596 | 596 | |
597 | 597 | $data['order_data'] += $this->build_display_items(); |
598 | 598 | |
599 | - wp_send_json( $data ); |
|
599 | + wp_send_json($data); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | /** |
@@ -607,47 +607,47 @@ discard block |
||
607 | 607 | * @see WC_Shipping::get_packages(). |
608 | 608 | */ |
609 | 609 | public function ajax_get_shipping_options() { |
610 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
610 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
611 | 611 | |
612 | 612 | try { |
613 | 613 | // Set the shipping package. |
614 | - $posted = filter_input_array( INPUT_POST, array( |
|
614 | + $posted = filter_input_array(INPUT_POST, array( |
|
615 | 615 | 'country' => FILTER_SANITIZE_STRING, |
616 | 616 | 'state' => FILTER_SANITIZE_STRING, |
617 | 617 | 'postcode' => FILTER_SANITIZE_STRING, |
618 | 618 | 'city' => FILTER_SANITIZE_STRING, |
619 | 619 | 'address' => FILTER_SANITIZE_STRING, |
620 | 620 | 'address_2' => FILTER_SANITIZE_STRING, |
621 | - ) ); |
|
621 | + )); |
|
622 | 622 | |
623 | - $this->calculate_shipping( $posted ); |
|
623 | + $this->calculate_shipping($posted); |
|
624 | 624 | |
625 | 625 | // Set the shipping options. |
626 | 626 | $data = array(); |
627 | 627 | $packages = WC()->shipping->get_packages(); |
628 | 628 | |
629 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
630 | - foreach ( $packages as $package_key => $package ) { |
|
631 | - if ( empty( $package['rates'] ) ) { |
|
632 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
629 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
630 | + foreach ($packages as $package_key => $package) { |
|
631 | + if (empty($package['rates'])) { |
|
632 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
633 | 633 | } |
634 | 634 | |
635 | - foreach ( $package['rates'] as $key => $rate ) { |
|
635 | + foreach ($package['rates'] as $key => $rate) { |
|
636 | 636 | $data['shipping_options'][] = array( |
637 | 637 | 'id' => $rate->id, |
638 | 638 | 'label' => $rate->label, |
639 | 639 | 'detail' => '', |
640 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
640 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
641 | 641 | ); |
642 | 642 | } |
643 | 643 | } |
644 | 644 | } else { |
645 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
645 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
646 | 646 | } |
647 | 647 | |
648 | - if ( isset( $data[0] ) ) { |
|
648 | + if (isset($data[0])) { |
|
649 | 649 | // Auto select the first shipping method. |
650 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
650 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | WC()->cart->calculate_totals(); |
@@ -655,12 +655,12 @@ discard block |
||
655 | 655 | $data += $this->build_display_items(); |
656 | 656 | $data['result'] = 'success'; |
657 | 657 | |
658 | - wp_send_json( $data ); |
|
659 | - } catch ( Exception $e ) { |
|
658 | + wp_send_json($data); |
|
659 | + } catch (Exception $e) { |
|
660 | 660 | $data += $this->build_display_items(); |
661 | 661 | $data['result'] = 'invalid_shipping_address'; |
662 | 662 | |
663 | - wp_send_json( $data ); |
|
663 | + wp_send_json($data); |
|
664 | 664 | } |
665 | 665 | } |
666 | 666 | |
@@ -668,22 +668,22 @@ discard block |
||
668 | 668 | * Update shipping method. |
669 | 669 | */ |
670 | 670 | public function ajax_update_shipping_method() { |
671 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
671 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
672 | 672 | |
673 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
674 | - define( 'WOOCOMMERCE_CART', true ); |
|
673 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
674 | + define('WOOCOMMERCE_CART', true); |
|
675 | 675 | } |
676 | 676 | |
677 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
678 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
677 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
678 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
679 | 679 | |
680 | - if ( is_array( $shipping_method ) ) { |
|
681 | - foreach ( $shipping_method as $i => $value ) { |
|
682 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
680 | + if (is_array($shipping_method)) { |
|
681 | + foreach ($shipping_method as $i => $value) { |
|
682 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
683 | 683 | } |
684 | 684 | } |
685 | 685 | |
686 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
686 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
687 | 687 | |
688 | 688 | WC()->cart->calculate_totals(); |
689 | 689 | |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | $data += $this->build_display_items(); |
692 | 692 | $data['result'] = 'success'; |
693 | 693 | |
694 | - wp_send_json( $data ); |
|
694 | + wp_send_json($data); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
@@ -702,31 +702,31 @@ discard block |
||
702 | 702 | * @return array $data |
703 | 703 | */ |
704 | 704 | public function ajax_get_selected_product_data() { |
705 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
705 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
706 | 706 | |
707 | - $product_id = absint( $_POST['product_id'] ); |
|
708 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
707 | + $product_id = absint($_POST['product_id']); |
|
708 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
709 | 709 | |
710 | - $product = wc_get_product( $product_id ); |
|
710 | + $product = wc_get_product($product_id); |
|
711 | 711 | |
712 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
713 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
712 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
713 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
714 | 714 | |
715 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
716 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
715 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
716 | + $variation_id = $product->get_matching_variation($attributes); |
|
717 | 717 | } else { |
718 | - $data_store = WC_Data_Store::load( 'product' ); |
|
719 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
718 | + $data_store = WC_Data_Store::load('product'); |
|
719 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
720 | 720 | } |
721 | 721 | |
722 | - if ( ! empty( $variation_id ) ) { |
|
723 | - $product = wc_get_product( $variation_id ); |
|
722 | + if ( ! empty($variation_id)) { |
|
723 | + $product = wc_get_product($variation_id); |
|
724 | 724 | } |
725 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
726 | - $product = wc_get_product( $product_id ); |
|
725 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
726 | + $product = wc_get_product($product_id); |
|
727 | 727 | } |
728 | 728 | |
729 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
729 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
730 | 730 | |
731 | 731 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
732 | 732 | |
@@ -734,28 +734,28 @@ discard block |
||
734 | 734 | $items = array(); |
735 | 735 | |
736 | 736 | $items[] = array( |
737 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
738 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
737 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
738 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
739 | 739 | ); |
740 | 740 | |
741 | - if ( wc_tax_enabled() ) { |
|
741 | + if (wc_tax_enabled()) { |
|
742 | 742 | $items[] = array( |
743 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
743 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
744 | 744 | 'amount' => 0, |
745 | 745 | 'pending' => true, |
746 | 746 | ); |
747 | 747 | } |
748 | 748 | |
749 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
749 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
750 | 750 | $items[] = array( |
751 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
751 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
752 | 752 | 'amount' => 0, |
753 | 753 | 'pending' => true, |
754 | 754 | ); |
755 | 755 | |
756 | - $data['shippingOptions'] = array( |
|
756 | + $data['shippingOptions'] = array( |
|
757 | 757 | 'id' => 'pending', |
758 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
758 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
759 | 759 | 'detail' => '', |
760 | 760 | 'amount' => 0, |
761 | 761 | ); |
@@ -764,15 +764,15 @@ discard block |
||
764 | 764 | $data['displayItems'] = $items; |
765 | 765 | $data['total'] = array( |
766 | 766 | 'label' => $this->total_label, |
767 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
767 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
768 | 768 | 'pending' => true, |
769 | 769 | ); |
770 | 770 | |
771 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
772 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
773 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
771 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
772 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
773 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
774 | 774 | |
775 | - wp_send_json( $data ); |
|
775 | + wp_send_json($data); |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | /** |
@@ -783,37 +783,37 @@ discard block |
||
783 | 783 | * @return array $data |
784 | 784 | */ |
785 | 785 | public function ajax_add_to_cart() { |
786 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
786 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
787 | 787 | |
788 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
789 | - define( 'WOOCOMMERCE_CART', true ); |
|
788 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
789 | + define('WOOCOMMERCE_CART', true); |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | WC()->shipping->reset_shipping(); |
793 | 793 | |
794 | - $product_id = absint( $_POST['product_id'] ); |
|
795 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
794 | + $product_id = absint($_POST['product_id']); |
|
795 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
796 | 796 | |
797 | - $product = wc_get_product( $product_id ); |
|
797 | + $product = wc_get_product($product_id); |
|
798 | 798 | |
799 | 799 | // First empty the cart to prevent wrong calculation. |
800 | 800 | WC()->cart->empty_cart(); |
801 | 801 | |
802 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
803 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
802 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
803 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
804 | 804 | |
805 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
806 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
805 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
806 | + $variation_id = $product->get_matching_variation($attributes); |
|
807 | 807 | } else { |
808 | - $data_store = WC_Data_Store::load( 'product' ); |
|
809 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
808 | + $data_store = WC_Data_Store::load('product'); |
|
809 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
810 | 810 | } |
811 | 811 | |
812 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
812 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
813 | 813 | } |
814 | 814 | |
815 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
816 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
815 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
816 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
817 | 817 | } |
818 | 818 | |
819 | 819 | WC()->cart->calculate_totals(); |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | $data += $this->build_display_items(); |
823 | 823 | $data['result'] = 'success'; |
824 | 824 | |
825 | - wp_send_json( $data ); |
|
825 | + wp_send_json($data); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | /** |
@@ -835,31 +835,31 @@ discard block |
||
835 | 835 | * @version 4.0.0 |
836 | 836 | */ |
837 | 837 | public function normalize_state() { |
838 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
839 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
840 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
841 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
838 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
839 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
840 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
841 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
842 | 842 | |
843 | - if ( $billing_state && $billing_country ) { |
|
844 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
843 | + if ($billing_state && $billing_country) { |
|
844 | + $valid_states = WC()->countries->get_states($billing_country); |
|
845 | 845 | |
846 | 846 | // Valid states found for country. |
847 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
848 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
849 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
847 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
848 | + foreach ($valid_states as $state_abbr => $state) { |
|
849 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
850 | 850 | $_POST['billing_state'] = $state_abbr; |
851 | 851 | } |
852 | 852 | } |
853 | 853 | } |
854 | 854 | } |
855 | 855 | |
856 | - if ( $shipping_state && $shipping_country ) { |
|
857 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
856 | + if ($shipping_state && $shipping_country) { |
|
857 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
858 | 858 | |
859 | 859 | // Valid states found for country. |
860 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
861 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
862 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
860 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
861 | + foreach ($valid_states as $state_abbr => $state) { |
|
862 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
863 | 863 | $_POST['shipping_state'] = $state_abbr; |
864 | 864 | } |
865 | 865 | } |
@@ -874,19 +874,19 @@ discard block |
||
874 | 874 | * @version 4.0.0 |
875 | 875 | */ |
876 | 876 | public function ajax_create_order() { |
877 | - if ( WC()->cart->is_empty() ) { |
|
878 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
877 | + if (WC()->cart->is_empty()) { |
|
878 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
879 | 879 | } |
880 | 880 | |
881 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
882 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
881 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
882 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | $this->normalize_state(); |
886 | 886 | |
887 | 887 | WC()->checkout()->process_checkout(); |
888 | 888 | |
889 | - die( 0 ); |
|
889 | + die(0); |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | /** |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | * @version 4.0.0 |
897 | 897 | * @param array $address |
898 | 898 | */ |
899 | - protected function calculate_shipping( $address = array() ) { |
|
899 | + protected function calculate_shipping($address = array()) { |
|
900 | 900 | global $states; |
901 | 901 | |
902 | 902 | $country = $address['country']; |
@@ -913,28 +913,28 @@ discard block |
||
913 | 913 | * In some versions of Chrome, state can be a full name. So we need |
914 | 914 | * to convert that to abbreviation as WC is expecting that. |
915 | 915 | */ |
916 | - if ( 2 < strlen( $state ) ) { |
|
917 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
916 | + if (2 < strlen($state)) { |
|
917 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
918 | 918 | } |
919 | 919 | |
920 | 920 | WC()->shipping->reset_shipping(); |
921 | 921 | |
922 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
923 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
922 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
923 | + $postcode = wc_format_postcode($postcode, $country); |
|
924 | 924 | } |
925 | 925 | |
926 | - if ( $country ) { |
|
927 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
928 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
926 | + if ($country) { |
|
927 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
928 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
929 | 929 | } else { |
930 | 930 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
931 | 931 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
932 | 932 | } |
933 | 933 | |
934 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
935 | - WC()->customer->calculated_shipping( true ); |
|
934 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
935 | + WC()->customer->calculated_shipping(true); |
|
936 | 936 | } else { |
937 | - WC()->customer->set_calculated_shipping( true ); |
|
937 | + WC()->customer->set_calculated_shipping(true); |
|
938 | 938 | WC()->customer->save(); |
939 | 939 | } |
940 | 940 | |
@@ -951,17 +951,17 @@ discard block |
||
951 | 951 | $packages[0]['destination']['address'] = $address_1; |
952 | 952 | $packages[0]['destination']['address_2'] = $address_2; |
953 | 953 | |
954 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
955 | - if ( $item['data']->needs_shipping() ) { |
|
956 | - if ( isset( $item['line_total'] ) ) { |
|
954 | + foreach (WC()->cart->get_cart() as $item) { |
|
955 | + if ($item['data']->needs_shipping()) { |
|
956 | + if (isset($item['line_total'])) { |
|
957 | 957 | $packages[0]['contents_cost'] += $item['line_total']; |
958 | 958 | } |
959 | 959 | } |
960 | 960 | } |
961 | 961 | |
962 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
962 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
963 | 963 | |
964 | - WC()->shipping->calculate_shipping( $packages ); |
|
964 | + WC()->shipping->calculate_shipping($packages); |
|
965 | 965 | } |
966 | 966 | |
967 | 967 | /** |
@@ -970,19 +970,19 @@ discard block |
||
970 | 970 | * @since 3.1.0 |
971 | 971 | * @version 4.0.0 |
972 | 972 | */ |
973 | - protected function build_shipping_methods( $shipping_methods ) { |
|
974 | - if ( empty( $shipping_methods ) ) { |
|
973 | + protected function build_shipping_methods($shipping_methods) { |
|
974 | + if (empty($shipping_methods)) { |
|
975 | 975 | return array(); |
976 | 976 | } |
977 | 977 | |
978 | 978 | $shipping = array(); |
979 | 979 | |
980 | - foreach ( $shipping_methods as $method ) { |
|
980 | + foreach ($shipping_methods as $method) { |
|
981 | 981 | $shipping[] = array( |
982 | 982 | 'id' => $method['id'], |
983 | 983 | 'label' => $method['label'], |
984 | 984 | 'detail' => '', |
985 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
985 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
986 | 986 | ); |
987 | 987 | } |
988 | 988 | |
@@ -996,69 +996,69 @@ discard block |
||
996 | 996 | * @version 4.0.0 |
997 | 997 | */ |
998 | 998 | protected function build_display_items() { |
999 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1000 | - define( 'WOOCOMMERCE_CART', true ); |
|
999 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1000 | + define('WOOCOMMERCE_CART', true); |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | $items = array(); |
1004 | 1004 | $subtotal = 0; |
1005 | 1005 | |
1006 | 1006 | // Default show only subtotal instead of itemization. |
1007 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1008 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1007 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1008 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1009 | 1009 | $amount = $cart_item['line_subtotal']; |
1010 | - $subtotal += $cart_item['line_subtotal']; |
|
1010 | + $subtotal += $cart_item['line_subtotal']; |
|
1011 | 1011 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1012 | 1012 | |
1013 | 1013 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1014 | 1014 | |
1015 | 1015 | $item = array( |
1016 | 1016 | 'label' => $product_name . $quantity_label, |
1017 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1017 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1018 | 1018 | ); |
1019 | 1019 | |
1020 | 1020 | $items[] = $item; |
1021 | 1021 | } |
1022 | 1022 | } |
1023 | 1023 | |
1024 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1025 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1026 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1027 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1028 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1024 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1025 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1026 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1027 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1028 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1029 | 1029 | |
1030 | - if ( wc_tax_enabled() ) { |
|
1030 | + if (wc_tax_enabled()) { |
|
1031 | 1031 | $items[] = array( |
1032 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1033 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1032 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1033 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1034 | 1034 | ); |
1035 | 1035 | } |
1036 | 1036 | |
1037 | - if ( WC()->cart->needs_shipping() ) { |
|
1037 | + if (WC()->cart->needs_shipping()) { |
|
1038 | 1038 | $items[] = array( |
1039 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1040 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1039 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1040 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1041 | 1041 | ); |
1042 | 1042 | } |
1043 | 1043 | |
1044 | - if ( WC()->cart->has_discount() ) { |
|
1044 | + if (WC()->cart->has_discount()) { |
|
1045 | 1045 | $items[] = array( |
1046 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1047 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1046 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1047 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1048 | 1048 | ); |
1049 | 1049 | } |
1050 | 1050 | |
1051 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1051 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1052 | 1052 | $cart_fees = WC()->cart->fees; |
1053 | 1053 | } else { |
1054 | 1054 | $cart_fees = WC()->cart->get_fees(); |
1055 | 1055 | } |
1056 | 1056 | |
1057 | 1057 | // Include fees and taxes as display items. |
1058 | - foreach ( $cart_fees as $key => $fee ) { |
|
1058 | + foreach ($cart_fees as $key => $fee) { |
|
1059 | 1059 | $items[] = array( |
1060 | 1060 | 'label' => $fee->name, |
1061 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1061 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1062 | 1062 | ); |
1063 | 1063 | } |
1064 | 1064 | |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | 'displayItems' => $items, |
1067 | 1067 | 'total' => array( |
1068 | 1068 | 'label' => $this->total_label, |
1069 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1069 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1070 | 1070 | 'pending' => false, |
1071 | 1071 | ), |
1072 | 1072 | ); |