@@ -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,101 +72,101 @@ 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 WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message ); |
|
91 | + if ( ! empty($source_info->error)) { |
|
92 | + throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message); |
|
93 | 93 | } |
94 | 94 | |
95 | - if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) { |
|
96 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), __( '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 WC_Stripe_Exception(print_r($source_info, true), __('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 WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
120 | + $order->add_order_note($message); |
|
121 | + throw new WC_Stripe_Exception(print_r($response, true), $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 WC_Stripe_Exception( print_r( $response, true ), $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 WC_Stripe_Exception(print_r($response, true), $message); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
142 | 142 | |
143 | - if ( 'card_error' === $response->error->type ) { |
|
144 | - $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
143 | + if ('card_error' === $response->error->type) { |
|
144 | + $message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
145 | 145 | } else { |
146 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
146 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
147 | 147 | } |
148 | 148 | |
149 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
149 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
150 | 150 | } |
151 | 151 | |
152 | - do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
152 | + do_action('wc_gateway_stripe_process_redirect_payment', $response, $order); |
|
153 | 153 | |
154 | - $this->process_response( $response, $order ); |
|
154 | + $this->process_response($response, $order); |
|
155 | 155 | |
156 | - } catch ( WC_Stripe_Exception $e ) { |
|
157 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
156 | + } catch (WC_Stripe_Exception $e) { |
|
157 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
158 | 158 | |
159 | - do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order ); |
|
159 | + do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order); |
|
160 | 160 | |
161 | 161 | /* translators: error message */ |
162 | - $order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) ); |
|
162 | + $order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage())); |
|
163 | 163 | |
164 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
165 | - $this->send_failed_order_email( $order_id ); |
|
164 | + if ($order->has_status(array('pending', 'failed'))) { |
|
165 | + $this->send_failed_order_email($order_id); |
|
166 | 166 | } |
167 | 167 | |
168 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
169 | - wp_safe_redirect( wc_get_checkout_url() ); |
|
168 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
169 | + wp_safe_redirect(wc_get_checkout_url()); |
|
170 | 170 | exit; |
171 | 171 | } |
172 | 172 | } |
@@ -178,13 +178,13 @@ discard block |
||
178 | 178 | * @version 4.0.0 |
179 | 179 | */ |
180 | 180 | public function maybe_process_redirect_order() { |
181 | - if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) { |
|
181 | + if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) { |
|
182 | 182 | return; |
183 | 183 | } |
184 | 184 | |
185 | - $order_id = wc_clean( $_GET['order_id'] ); |
|
185 | + $order_id = wc_clean($_GET['order_id']); |
|
186 | 186 | |
187 | - $this->process_redirect_payment( $order_id ); |
|
187 | + $this->process_redirect_payment($order_id); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -194,52 +194,52 @@ discard block |
||
194 | 194 | * @version 4.0.0 |
195 | 195 | * @param int $order_id |
196 | 196 | */ |
197 | - public function capture_payment( $order_id ) { |
|
198 | - $order = wc_get_order( $order_id ); |
|
197 | + public function capture_payment($order_id) { |
|
198 | + $order = wc_get_order($order_id); |
|
199 | 199 | |
200 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
201 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
202 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
200 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
201 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
202 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
203 | 203 | |
204 | - if ( $charge && 'no' === $captured ) { |
|
204 | + if ($charge && 'no' === $captured) { |
|
205 | 205 | $order_total = $order->get_total(); |
206 | 206 | |
207 | - if ( 0 < $order->get_total_refunded() ) { |
|
207 | + if (0 < $order->get_total_refunded()) { |
|
208 | 208 | $order_total = $order_total - $order->get_total_refunded(); |
209 | 209 | } |
210 | 210 | |
211 | - $result = WC_Stripe_API::request( array( |
|
212 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order_total ), |
|
211 | + $result = WC_Stripe_API::request(array( |
|
212 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order_total), |
|
213 | 213 | 'expand[]' => 'balance_transaction', |
214 | - ), 'charges/' . $charge . '/capture' ); |
|
214 | + ), 'charges/' . $charge . '/capture'); |
|
215 | 215 | |
216 | - if ( ! empty( $result->error ) ) { |
|
216 | + if ( ! empty($result->error)) { |
|
217 | 217 | /* translators: error message */ |
218 | - $order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
218 | + $order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
219 | 219 | } else { |
220 | 220 | /* translators: transaction id */ |
221 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
222 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
221 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
222 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
223 | 223 | |
224 | 224 | // Store other data such as fees |
225 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id ); |
|
225 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id); |
|
226 | 226 | |
227 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
227 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
228 | 228 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
229 | 229 | // values are in the local currency of the Stripe account, not from WC. |
230 | - $fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0; |
|
231 | - $net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0; |
|
232 | - 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 ); |
|
233 | - 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 | + $fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0; |
|
231 | + $net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0; |
|
232 | + 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); |
|
233 | + 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); |
|
234 | 234 | } |
235 | 235 | |
236 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
236 | + if (is_callable(array($order, 'save'))) { |
|
237 | 237 | $order->save(); |
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | 241 | // This hook fires when admin manually changes order status to processing or completed. |
242 | - do_action( 'woocommerce_stripe_process_manual_capture', $order, $result ); |
|
242 | + do_action('woocommerce_stripe_process_manual_capture', $order, $result); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | } |
@@ -251,32 +251,32 @@ discard block |
||
251 | 251 | * @version 4.0.0 |
252 | 252 | * @param int $order_id |
253 | 253 | */ |
254 | - public function cancel_payment( $order_id ) { |
|
255 | - $order = wc_get_order( $order_id ); |
|
254 | + public function cancel_payment($order_id) { |
|
255 | + $order = wc_get_order($order_id); |
|
256 | 256 | |
257 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
258 | - $charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
257 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
258 | + $charge_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
259 | 259 | |
260 | - if ( $charge_id ) { |
|
261 | - $result = WC_Stripe_API::request( array( |
|
262 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order->get_total() ), |
|
263 | - ), 'charges/' . $charge_id . '/refund' ); |
|
260 | + if ($charge_id) { |
|
261 | + $result = WC_Stripe_API::request(array( |
|
262 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order->get_total()), |
|
263 | + ), 'charges/' . $charge_id . '/refund'); |
|
264 | 264 | |
265 | - if ( ! empty( $result->error ) ) { |
|
266 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->error->message ); |
|
265 | + if ( ! empty($result->error)) { |
|
266 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->error->message); |
|
267 | 267 | } else { |
268 | 268 | /* translators: transaction id */ |
269 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
270 | - WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_stripe_charge_captured' ) : $order->delete_meta_data( '_stripe_charge_captured' ); |
|
271 | - WC_Stripe_Helper::is_pre_30() ? delete_post_meta( $order_id, '_transaction_id' ) : $order->delete_meta_data( '_stripe_transaction_id' ); |
|
269 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
270 | + WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_stripe_charge_captured') : $order->delete_meta_data('_stripe_charge_captured'); |
|
271 | + WC_Stripe_Helper::is_pre_30() ? delete_post_meta($order_id, '_transaction_id') : $order->delete_meta_data('_stripe_transaction_id'); |
|
272 | 272 | |
273 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
273 | + if (is_callable(array($order, 'save'))) { |
|
274 | 274 | $order->save(); |
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | 278 | // This hook fires when admin manually changes order status to cancel. |
279 | - do_action( 'woocommerce_stripe_process_manual_cancel', $order, $result ); |
|
279 | + do_action('woocommerce_stripe_process_manual_cancel', $order, $result); |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | } |
@@ -289,21 +289,21 @@ discard block |
||
289 | 289 | * @param string $field |
290 | 290 | * @return string $error_field |
291 | 291 | */ |
292 | - public function normalize_field( $field ) { |
|
292 | + public function normalize_field($field) { |
|
293 | 293 | $checkout_fields = WC()->checkout->get_checkout_fields(); |
294 | 294 | $org_str = array(); |
295 | 295 | $replace_str = array(); |
296 | 296 | |
297 | - if ( array_key_exists( $field, $checkout_fields['billing'] ) ) { |
|
298 | - $error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label']; |
|
299 | - } elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) { |
|
300 | - $error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label']; |
|
301 | - } elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) { |
|
302 | - $error_field = $checkout_fields['order'][ $field ]['label']; |
|
303 | - } elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) { |
|
304 | - $error_field = $checkout_fields['account'][ $field ]['label']; |
|
297 | + if (array_key_exists($field, $checkout_fields['billing'])) { |
|
298 | + $error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label']; |
|
299 | + } elseif (array_key_exists($field, $checkout_fields['shipping'])) { |
|
300 | + $error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label']; |
|
301 | + } elseif (array_key_exists($field, $checkout_fields['order'])) { |
|
302 | + $error_field = $checkout_fields['order'][$field]['label']; |
|
303 | + } elseif (array_key_exists($field, $checkout_fields['account'])) { |
|
304 | + $error_field = $checkout_fields['account'][$field]['label']; |
|
305 | 305 | } else { |
306 | - $error_field = str_replace( '_', ' ', $field ); |
|
306 | + $error_field = str_replace('_', ' ', $field); |
|
307 | 307 | |
308 | 308 | $org_str[] = 'stripe'; |
309 | 309 | $replace_str[] = ''; |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | $replace_str[] = 'SOFORT'; |
319 | 319 | |
320 | 320 | $org_str[] = 'owner'; |
321 | - $replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' ); |
|
321 | + $replace_str[] = __('Owner', 'woocommerce-gateway-stripe'); |
|
322 | 322 | |
323 | - $error_field = str_replace( $org_str, $replace_str, $error_field ); |
|
323 | + $error_field = str_replace($org_str, $replace_str, $error_field); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | return $error_field; |
@@ -333,154 +333,154 @@ discard block |
||
333 | 333 | * @version 4.0.0 |
334 | 334 | */ |
335 | 335 | public function validate_checkout() { |
336 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) { |
|
337 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
336 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) { |
|
337 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | $errors = new WP_Error(); |
341 | - parse_str( $_POST['required_fields'], $required_fields ); |
|
342 | - parse_str( $_POST['all_fields'], $all_fields ); |
|
343 | - $source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : ''; |
|
341 | + parse_str($_POST['required_fields'], $required_fields); |
|
342 | + parse_str($_POST['all_fields'], $all_fields); |
|
343 | + $source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : ''; |
|
344 | 344 | $validate_shipping_fields = false; |
345 | 345 | $create_account = false; |
346 | 346 | |
347 | - array_walk_recursive( $required_fields, 'wc_clean' ); |
|
348 | - array_walk_recursive( $all_fields, 'wc_clean' ); |
|
347 | + array_walk_recursive($required_fields, 'wc_clean'); |
|
348 | + array_walk_recursive($all_fields, 'wc_clean'); |
|
349 | 349 | |
350 | 350 | // Remove unneeded required fields depending on source type. |
351 | - if ( 'stripe_sepa' !== $source_type ) { |
|
352 | - unset( $required_fields['stripe_sepa_owner'] ); |
|
353 | - unset( $required_fields['stripe_sepa_iban'] ); |
|
351 | + if ('stripe_sepa' !== $source_type) { |
|
352 | + unset($required_fields['stripe_sepa_owner']); |
|
353 | + unset($required_fields['stripe_sepa_iban']); |
|
354 | 354 | } |
355 | 355 | |
356 | - if ( 'stripe_sofort' !== $source_type ) { |
|
357 | - unset( $required_fields['stripe_sofort_bank_country'] ); |
|
356 | + if ('stripe_sofort' !== $source_type) { |
|
357 | + unset($required_fields['stripe_sofort_bank_country']); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | /** |
361 | 361 | * If ship to different address checkbox is checked then we need |
362 | 362 | * to validate shipping fields too. |
363 | 363 | */ |
364 | - if ( isset( $all_fields['ship_to_different_address'] ) ) { |
|
364 | + if (isset($all_fields['ship_to_different_address'])) { |
|
365 | 365 | $validate_shipping_fields = true; |
366 | 366 | } |
367 | 367 | |
368 | 368 | // Check if createaccount is checked. |
369 | - if ( isset( $all_fields['createaccount'] ) ) { |
|
369 | + if (isset($all_fields['createaccount'])) { |
|
370 | 370 | $create_account = true; |
371 | 371 | } |
372 | 372 | |
373 | 373 | // Check if required fields are empty. |
374 | - foreach ( $required_fields as $field => $field_value ) { |
|
374 | + foreach ($required_fields as $field => $field_value) { |
|
375 | 375 | // Check for shipping field. |
376 | - if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) { |
|
376 | + if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) { |
|
377 | 377 | continue; |
378 | 378 | } |
379 | 379 | |
380 | 380 | // Check create account name. |
381 | - if ( 'account_username' === $field && ! $create_account ) { |
|
381 | + if ('account_username' === $field && ! $create_account) { |
|
382 | 382 | continue; |
383 | 383 | } |
384 | 384 | |
385 | 385 | // Check create account password. |
386 | - if ( 'account_password' === $field && ! $create_account ) { |
|
386 | + if ('account_password' === $field && ! $create_account) { |
|
387 | 387 | continue; |
388 | 388 | } |
389 | 389 | |
390 | 390 | // Check if is SEPA. |
391 | - if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field ) { |
|
391 | + if ('stripe_sepa' !== $source_type && 'stripe_sepa_owner' === $field) { |
|
392 | 392 | continue; |
393 | 393 | } |
394 | 394 | |
395 | - if ( 'stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field ) { |
|
395 | + if ('stripe_sepa' !== $source_type && 'stripe_sepa_iban' === $field) { |
|
396 | 396 | $continue; |
397 | 397 | } |
398 | 398 | |
399 | - if ( empty( $field_value ) || '-1' === $field_value ) { |
|
400 | - $error_field = $this->normalize_field( $field ); |
|
399 | + if (empty($field_value) || '-1' === $field_value) { |
|
400 | + $error_field = $this->normalize_field($field); |
|
401 | 401 | /* translators: error field name */ |
402 | - $errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) ); |
|
402 | + $errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field)); |
|
403 | 403 | } |
404 | 404 | } |
405 | 405 | |
406 | 406 | // Check if email is valid format. |
407 | - if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) { |
|
408 | - $errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) ); |
|
407 | + if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) { |
|
408 | + $errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe')); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | // Check if phone number is valid format. |
412 | - if ( ! empty( $required_fields['billing_phone'] ) ) { |
|
413 | - $phone = wc_format_phone_number( $required_fields['billing_phone'] ); |
|
412 | + if ( ! empty($required_fields['billing_phone'])) { |
|
413 | + $phone = wc_format_phone_number($required_fields['billing_phone']); |
|
414 | 414 | |
415 | - if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) { |
|
415 | + if ('' !== $phone && ! WC_Validation::is_phone($phone)) { |
|
416 | 416 | /* translators: %s: phone number */ |
417 | - $errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) ); |
|
417 | + $errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe')); |
|
418 | 418 | } |
419 | 419 | } |
420 | 420 | |
421 | 421 | // Check if postal code is valid format. |
422 | - if ( ! empty( $required_fields['billing_postcode'] ) ) { |
|
423 | - $country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
424 | - $postcode = wc_format_postcode( $required_fields['billing_postcode'], $country ); |
|
422 | + if ( ! empty($required_fields['billing_postcode'])) { |
|
423 | + $country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
424 | + $postcode = wc_format_postcode($required_fields['billing_postcode'], $country); |
|
425 | 425 | |
426 | - if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
427 | - $errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
426 | + if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
427 | + $errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
428 | 428 | } |
429 | 429 | } |
430 | 430 | |
431 | 431 | // Don't check this on add payment method page. |
432 | - if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) { |
|
433 | - if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) { |
|
434 | - $errors->add( 'terms', __( 'You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe' ) ); |
|
432 | + if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) { |
|
433 | + if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) { |
|
434 | + $errors->add('terms', __('You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe')); |
|
435 | 435 | } |
436 | 436 | } |
437 | 437 | |
438 | - if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) { |
|
438 | + if (WC()->cart->needs_shipping() && $validate_shipping_fields) { |
|
439 | 439 | // Check if postal code is valid format. |
440 | - if ( ! empty( $required_fields['shipping_postcode'] ) ) { |
|
441 | - $country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
442 | - $postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country ); |
|
440 | + if ( ! empty($required_fields['shipping_postcode'])) { |
|
441 | + $country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
442 | + $postcode = wc_format_postcode($required_fields['shipping_postcode'], $country); |
|
443 | 443 | |
444 | - if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
445 | - $errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
444 | + if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
445 | + $errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 | } |
449 | 449 | |
450 | - if ( WC()->cart->needs_shipping() ) { |
|
450 | + if (WC()->cart->needs_shipping()) { |
|
451 | 451 | $shipping_country = WC()->customer->get_shipping_country(); |
452 | 452 | |
453 | - if ( empty( $shipping_country ) ) { |
|
454 | - $errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) ); |
|
455 | - } elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) { |
|
453 | + if (empty($shipping_country)) { |
|
454 | + $errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe')); |
|
455 | + } elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) { |
|
456 | 456 | /* translators: country name */ |
457 | - $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() ) ); |
|
457 | + $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())); |
|
458 | 458 | } else { |
459 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
459 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
460 | 460 | |
461 | - foreach ( WC()->shipping->get_packages() as $i => $package ) { |
|
462 | - if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) { |
|
463 | - $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' ) ); |
|
461 | + foreach (WC()->shipping->get_packages() as $i => $package) { |
|
462 | + if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) { |
|
463 | + $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')); |
|
464 | 464 | } |
465 | 465 | } |
466 | 466 | } |
467 | 467 | } |
468 | 468 | |
469 | - if ( WC()->cart->needs_payment() ) { |
|
469 | + if (WC()->cart->needs_payment()) { |
|
470 | 470 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
471 | 471 | |
472 | - if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) { |
|
473 | - $errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) ); |
|
472 | + if ( ! isset($available_gateways[$all_fields['payment_method']])) { |
|
473 | + $errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe')); |
|
474 | 474 | } else { |
475 | - $available_gateways[ $all_fields['payment_method'] ]->validate_fields(); |
|
475 | + $available_gateways[$all_fields['payment_method']]->validate_fields(); |
|
476 | 476 | } |
477 | 477 | } |
478 | 478 | |
479 | - if ( 0 === count( $errors->errors ) ) { |
|
480 | - wp_send_json( 'success' ); |
|
479 | + if (0 === count($errors->errors)) { |
|
480 | + wp_send_json('success'); |
|
481 | 481 | } else { |
482 | - foreach ( $errors->get_error_messages() as $message ) { |
|
483 | - wc_add_notice( $message, 'error' ); |
|
482 | + foreach ($errors->get_error_messages() as $message) { |
|
483 | + wc_add_notice($message, 'error'); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | $this->send_ajax_failure_response(); |
@@ -494,9 +494,9 @@ discard block |
||
494 | 494 | * @version 4.0.0 |
495 | 495 | */ |
496 | 496 | public function send_ajax_failure_response() { |
497 | - if ( is_ajax() ) { |
|
497 | + if (is_ajax()) { |
|
498 | 498 | // only print notices if not reloading the checkout, otherwise they're lost in the page reload. |
499 | - if ( ! isset( WC()->session->reload_checkout ) ) { |
|
499 | + if ( ! isset(WC()->session->reload_checkout)) { |
|
500 | 500 | ob_start(); |
501 | 501 | wc_print_notices(); |
502 | 502 | $messages = ob_get_clean(); |
@@ -504,14 +504,14 @@ discard block |
||
504 | 504 | |
505 | 505 | $response = array( |
506 | 506 | 'result' => 'failure', |
507 | - 'messages' => isset( $messages ) ? $messages : '', |
|
508 | - 'refresh' => isset( WC()->session->refresh_totals ), |
|
509 | - 'reload' => isset( WC()->session->reload_checkout ), |
|
507 | + 'messages' => isset($messages) ? $messages : '', |
|
508 | + 'refresh' => isset(WC()->session->refresh_totals), |
|
509 | + 'reload' => isset(WC()->session->reload_checkout), |
|
510 | 510 | ); |
511 | 511 | |
512 | - unset( WC()->session->refresh_totals, WC()->session->reload_checkout ); |
|
512 | + unset(WC()->session->refresh_totals, WC()->session->reload_checkout); |
|
513 | 513 | |
514 | - wp_send_json( $response ); |
|
514 | + wp_send_json($response); |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | } |
@@ -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' => __( 'The card number is incomplete.', 'woocommerce-gateway-stripe' ), |
|
47 | - 'incomplete_cvc' => __( 'The card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ), |
|
48 | - 'incomplete_expiry' => __( 'The 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 | - 'invalid_expiry_year_past' => __( 'The card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ), |
|
53 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
54 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
55 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
56 | - 'invalid_request_error' => __( 'Unable to process this payment, please try again or use alternative method.', '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' => __('The card number is incomplete.', 'woocommerce-gateway-stripe'), |
|
47 | + 'incomplete_cvc' => __('The card\'s security code is incomplete.', 'woocommerce-gateway-stripe'), |
|
48 | + 'incomplete_expiry' => __('The 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 | + 'invalid_expiry_year_past' => __('The card\'s expiration year is in the past', 'woocommerce-gateway-stripe'), |
|
53 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
54 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
55 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
56 | + 'invalid_request_error' => __('Unable to process this payment, please try again or use alternative method.', '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 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * Constructor |
33 | 33 | * @param int $user_id The WP user ID |
34 | 34 | */ |
35 | - public function __construct( $user_id = 0 ) { |
|
36 | - if ( $user_id ) { |
|
37 | - $this->set_user_id( $user_id ); |
|
38 | - $this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
35 | + public function __construct($user_id = 0) { |
|
36 | + if ($user_id) { |
|
37 | + $this->set_user_id($user_id); |
|
38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * Set Stripe customer ID. |
52 | 52 | * @param [type] $id [description] |
53 | 53 | */ |
54 | - public function set_id( $id ) { |
|
55 | - $this->id = wc_clean( $id ); |
|
54 | + public function set_id($id) { |
|
55 | + $this->id = wc_clean($id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | * @return int |
61 | 61 | */ |
62 | 62 | public function get_user_id() { |
63 | - return absint( $this->user_id ); |
|
63 | + return absint($this->user_id); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Set User ID used by WordPress. |
68 | 68 | * @param int $user_id |
69 | 69 | */ |
70 | - public function set_user_id( $user_id ) { |
|
71 | - $this->user_id = absint( $user_id ); |
|
70 | + public function set_user_id($user_id) { |
|
71 | + $this->user_id = absint($user_id); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | * @return WP_User |
77 | 77 | */ |
78 | 78 | protected function get_user() { |
79 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
79 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Store data from the Stripe API about this customer |
84 | 84 | */ |
85 | - public function set_customer_data( $data ) { |
|
85 | + public function set_customer_data($data) { |
|
86 | 86 | $this->customer_data = $data; |
87 | 87 | } |
88 | 88 | |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | * Get data from the Stripe API about this customer |
91 | 91 | */ |
92 | 92 | public function get_customer_data() { |
93 | - $this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() ); |
|
93 | + $this->customer_data = get_transient('stripe_customer_' . $this->get_id()); |
|
94 | 94 | |
95 | - if ( empty( $this->customer_data ) && $this->get_id() && false === $this->customer_data ) { |
|
96 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() ); |
|
95 | + if (empty($this->customer_data) && $this->get_id() && false === $this->customer_data) { |
|
96 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id()); |
|
97 | 97 | |
98 | - if ( empty( $response->error ) ) { |
|
99 | - $this->set_customer_data( $response ); |
|
100 | - set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 ); |
|
98 | + if (empty($response->error)) { |
|
99 | + $this->set_customer_data($response); |
|
100 | + set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $data = $this->get_customer_data(); |
113 | 113 | $source = ''; |
114 | 114 | |
115 | - if ( $data ) { |
|
115 | + if ($data) { |
|
116 | 116 | $source = $data->default_source; |
117 | 117 | } |
118 | 118 | |
@@ -124,13 +124,13 @@ discard block |
||
124 | 124 | * @param array $args |
125 | 125 | * @return WP_Error|int |
126 | 126 | */ |
127 | - public function create_customer( $args = array() ) { |
|
128 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
127 | + public function create_customer($args = array()) { |
|
128 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
129 | 129 | $user = $this->get_user(); |
130 | 130 | |
131 | - if ( $user ) { |
|
132 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
133 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
131 | + if ($user) { |
|
132 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
133 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
134 | 134 | |
135 | 135 | $defaults = array( |
136 | 136 | 'email' => $user->user_email, |
@@ -145,24 +145,24 @@ discard block |
||
145 | 145 | |
146 | 146 | $metadata = array(); |
147 | 147 | |
148 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
148 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
149 | 149 | |
150 | - $args = wp_parse_args( $args, $defaults ); |
|
151 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
150 | + $args = wp_parse_args($args, $defaults); |
|
151 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
152 | 152 | |
153 | - if ( ! empty( $response->error ) ) { |
|
154 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
153 | + if ( ! empty($response->error)) { |
|
154 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
155 | 155 | } |
156 | 156 | |
157 | - $this->set_id( $response->id ); |
|
157 | + $this->set_id($response->id); |
|
158 | 158 | $this->clear_cache(); |
159 | - $this->set_customer_data( $response ); |
|
159 | + $this->set_customer_data($response); |
|
160 | 160 | |
161 | - if ( $this->get_user_id() ) { |
|
162 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
161 | + if ($this->get_user_id()) { |
|
162 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
163 | 163 | } |
164 | 164 | |
165 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
165 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
166 | 166 | |
167 | 167 | return $response->id; |
168 | 168 | } |
@@ -173,72 +173,72 @@ discard block |
||
173 | 173 | * @param bool $retry |
174 | 174 | * @return WP_Error|int |
175 | 175 | */ |
176 | - public function add_source( $source_id, $retry = true ) { |
|
177 | - if ( ! $this->get_id() ) { |
|
178 | - $this->set_id( $this->create_customer() ); |
|
176 | + public function add_source($source_id, $retry = true) { |
|
177 | + if ( ! $this->get_id()) { |
|
178 | + $this->set_id($this->create_customer()); |
|
179 | 179 | } |
180 | 180 | |
181 | - $response = WC_Stripe_API::request( array( |
|
181 | + $response = WC_Stripe_API::request(array( |
|
182 | 182 | 'source' => $source_id, |
183 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
183 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
184 | 184 | |
185 | - if ( ! empty( $response->error ) ) { |
|
185 | + if ( ! empty($response->error)) { |
|
186 | 186 | // It is possible the WC user once was linked to a customer on Stripe |
187 | 187 | // but no longer exists. Instead of failing, lets try to create a |
188 | 188 | // new customer. |
189 | - if ( preg_match( '/No such customer/i', $response->error->message ) ) { |
|
190 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
189 | + if (preg_match('/No such customer/i', $response->error->message)) { |
|
190 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
191 | 191 | $this->create_customer(); |
192 | - return $this->add_source( $source_id, false ); |
|
192 | + return $this->add_source($source_id, false); |
|
193 | 193 | } else { |
194 | 194 | return $response; |
195 | 195 | } |
196 | - } elseif ( empty( $response->id ) ) { |
|
197 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
196 | + } elseif (empty($response->id)) { |
|
197 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | // Add token to WooCommerce. |
201 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
202 | - if ( ! empty( $response->type ) ) { |
|
203 | - switch ( $response->type ) { |
|
201 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
202 | + if ( ! empty($response->type)) { |
|
203 | + switch ($response->type) { |
|
204 | 204 | case 'alipay': |
205 | 205 | break; |
206 | 206 | case 'sepa_debit': |
207 | 207 | $wc_token = new WC_Payment_Token_SEPA(); |
208 | - $wc_token->set_token( $response->id ); |
|
209 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
210 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
208 | + $wc_token->set_token($response->id); |
|
209 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
210 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
211 | 211 | break; |
212 | 212 | default: |
213 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
213 | + if ('source' === $response->object && 'card' === $response->type) { |
|
214 | 214 | $wc_token = new WC_Payment_Token_CC(); |
215 | - $wc_token->set_token( $response->id ); |
|
216 | - $wc_token->set_gateway_id( 'stripe' ); |
|
217 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
218 | - $wc_token->set_last4( $response->card->last4 ); |
|
219 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
220 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
215 | + $wc_token->set_token($response->id); |
|
216 | + $wc_token->set_gateway_id('stripe'); |
|
217 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
218 | + $wc_token->set_last4($response->card->last4); |
|
219 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
220 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
221 | 221 | } |
222 | 222 | break; |
223 | 223 | } |
224 | 224 | } else { |
225 | 225 | // Legacy. |
226 | 226 | $wc_token = new WC_Payment_Token_CC(); |
227 | - $wc_token->set_token( $response->id ); |
|
228 | - $wc_token->set_gateway_id( 'stripe' ); |
|
229 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
230 | - $wc_token->set_last4( $response->last4 ); |
|
231 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
232 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
227 | + $wc_token->set_token($response->id); |
|
228 | + $wc_token->set_gateway_id('stripe'); |
|
229 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
230 | + $wc_token->set_last4($response->last4); |
|
231 | + $wc_token->set_expiry_month($response->exp_month); |
|
232 | + $wc_token->set_expiry_year($response->exp_year); |
|
233 | 233 | } |
234 | 234 | |
235 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
235 | + $wc_token->set_user_id($this->get_user_id()); |
|
236 | 236 | $wc_token->save(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $this->clear_cache(); |
240 | 240 | |
241 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
241 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
242 | 242 | |
243 | 243 | return $response->id; |
244 | 244 | } |
@@ -250,46 +250,46 @@ discard block |
||
250 | 250 | * @return array |
251 | 251 | */ |
252 | 252 | public function get_sources() { |
253 | - if ( ! $this->get_id() ) { |
|
253 | + if ( ! $this->get_id()) { |
|
254 | 254 | return array(); |
255 | 255 | } |
256 | 256 | |
257 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
257 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
258 | 258 | |
259 | - if ( false === $sources ) { |
|
260 | - $response = WC_Stripe_API::request( array( |
|
259 | + if (false === $sources) { |
|
260 | + $response = WC_Stripe_API::request(array( |
|
261 | 261 | 'limit' => 100, |
262 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
262 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
263 | 263 | |
264 | - if ( ! empty( $response->error ) ) { |
|
264 | + if ( ! empty($response->error)) { |
|
265 | 265 | return array(); |
266 | 266 | } |
267 | 267 | |
268 | - if ( is_array( $response->data ) ) { |
|
268 | + if (is_array($response->data)) { |
|
269 | 269 | $sources = $response->data; |
270 | 270 | } |
271 | 271 | |
272 | - set_transient( 'stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24 ); |
|
272 | + set_transient('stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24); |
|
273 | 273 | } |
274 | 274 | |
275 | - return empty( $sources ) ? array() : $sources; |
|
275 | + return empty($sources) ? array() : $sources; |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
279 | 279 | * Delete a source from stripe. |
280 | 280 | * @param string $source_id |
281 | 281 | */ |
282 | - public function delete_source( $source_id ) { |
|
283 | - if ( ! $this->get_id() ) { |
|
282 | + public function delete_source($source_id) { |
|
283 | + if ( ! $this->get_id()) { |
|
284 | 284 | return false; |
285 | 285 | } |
286 | 286 | |
287 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
287 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
288 | 288 | |
289 | 289 | $this->clear_cache(); |
290 | 290 | |
291 | - if ( empty( $response->error ) ) { |
|
292 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
291 | + if (empty($response->error)) { |
|
292 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
293 | 293 | |
294 | 294 | return true; |
295 | 295 | } |
@@ -301,15 +301,15 @@ discard block |
||
301 | 301 | * Set default source in Stripe |
302 | 302 | * @param string $source_id |
303 | 303 | */ |
304 | - public function set_default_source( $source_id ) { |
|
305 | - $response = WC_Stripe_API::request( array( |
|
306 | - 'default_source' => sanitize_text_field( $source_id ), |
|
307 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
304 | + public function set_default_source($source_id) { |
|
305 | + $response = WC_Stripe_API::request(array( |
|
306 | + 'default_source' => sanitize_text_field($source_id), |
|
307 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
308 | 308 | |
309 | 309 | $this->clear_cache(); |
310 | 310 | |
311 | - if ( empty( $response->error ) ) { |
|
312 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
311 | + if (empty($response->error)) { |
|
312 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
313 | 313 | |
314 | 314 | return true; |
315 | 315 | } |
@@ -321,8 +321,8 @@ discard block |
||
321 | 321 | * Deletes caches for this users cards. |
322 | 322 | */ |
323 | 323 | public function clear_cache() { |
324 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
325 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
324 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
325 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
326 | 326 | $this->customer_data = array(); |
327 | 327 | } |
328 | 328 | } |
@@ -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,43 +93,43 @@ discard block |
||
93 | 93 | * @version 4.0.0 |
94 | 94 | */ |
95 | 95 | public function init() { |
96 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' ); |
|
97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
98 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
99 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
96 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'); |
|
97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
98 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
99 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
100 | 100 | |
101 | 101 | // Don't hook anything else in the plugin if we're in an incompatible environment |
102 | - if ( self::get_environment_warning() ) { |
|
102 | + if (self::get_environment_warning()) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
107 | - |
|
108 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
109 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
111 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
112 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
113 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
123 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
124 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
125 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
106 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
107 | + |
|
108 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
109 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
110 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
111 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
112 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
113 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
123 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
124 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
125 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
126 | 126 | |
127 | 127 | // REMOVE IN THE FUTURE. |
128 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
128 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
129 | 129 | |
130 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
131 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
132 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
130 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
131 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
132 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,23 +139,23 @@ discard block |
||
139 | 139 | * @version 4.0.0 |
140 | 140 | */ |
141 | 141 | public function hide_notices() { |
142 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
143 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
144 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
142 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
143 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
144 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
145 | 145 | } |
146 | 146 | |
147 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
148 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
147 | + if ( ! current_user_can('manage_woocommerce')) { |
|
148 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
149 | 149 | } |
150 | 150 | |
151 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
151 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
152 | 152 | |
153 | - switch ( $notice ) { |
|
153 | + switch ($notice) { |
|
154 | 154 | case 'ssl': |
155 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
155 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
156 | 156 | break; |
157 | 157 | case 'keys': |
158 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
158 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
159 | 159 | break; |
160 | 160 | } |
161 | 161 | } |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * @since 1.0.0 |
168 | 168 | * @version 4.0.0 |
169 | 169 | */ |
170 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
171 | - $this->notices[ $slug ] = array( |
|
170 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
171 | + $this->notices[$slug] = array( |
|
172 | 172 | 'class' => $class, |
173 | 173 | 'message' => $message, |
174 | 174 | 'dismissible' => $dismissible, |
@@ -182,21 +182,21 @@ discard block |
||
182 | 182 | * @version 4.0.0 |
183 | 183 | */ |
184 | 184 | public function admin_notices() { |
185 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
185 | + if ( ! current_user_can('manage_woocommerce')) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
189 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
190 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
189 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
190 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
191 | 191 | |
192 | - if ( $notice['dismissible'] ) { |
|
192 | + if ($notice['dismissible']) { |
|
193 | 193 | ?> |
194 | - <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 | + <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> |
|
195 | 195 | <?php |
196 | 196 | } |
197 | 197 | |
198 | 198 | echo '<p>'; |
199 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
199 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
200 | 200 | echo '</p></div>'; |
201 | 201 | } |
202 | 202 | } |
@@ -209,26 +209,26 @@ discard block |
||
209 | 209 | * @version 4.0.0 |
210 | 210 | */ |
211 | 211 | public function get_environment_warning() { |
212 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
212 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
213 | 213 | /* translators: 1) int version 2) int version */ |
214 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
214 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
215 | 215 | |
216 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
216 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
217 | 217 | } |
218 | 218 | |
219 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
220 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
219 | + if ( ! defined('WC_VERSION')) { |
|
220 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
221 | 221 | } |
222 | 222 | |
223 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
223 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
224 | 224 | /* translators: 1) int version 2) int version */ |
225 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
225 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
226 | 226 | |
227 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
227 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
228 | 228 | } |
229 | 229 | |
230 | - if ( ! function_exists( 'curl_init' ) ) { |
|
231 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
230 | + if ( ! function_exists('curl_init')) { |
|
231 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | return false; |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | * @return string Setting link |
243 | 243 | */ |
244 | 244 | public function get_setting_link() { |
245 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
245 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
246 | 246 | |
247 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
247 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
248 | 248 | |
249 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
249 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -257,37 +257,37 @@ discard block |
||
257 | 257 | * @version 4.0.0 |
258 | 258 | */ |
259 | 259 | public function check_environment() { |
260 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
260 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
261 | 261 | $this->install(); |
262 | 262 | |
263 | - do_action( 'woocommerce_stripe_updated' ); |
|
263 | + do_action('woocommerce_stripe_updated'); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | $environment_warning = $this->get_environment_warning(); |
267 | 267 | |
268 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
269 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
268 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
269 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
270 | 270 | } |
271 | 271 | |
272 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
273 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
274 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
272 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
273 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
274 | + $options = get_option('woocommerce_stripe_settings'); |
|
275 | 275 | |
276 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
277 | - $secret = WC_Stripe_API::get_secret_key(); |
|
276 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
277 | + $secret = WC_Stripe_API::get_secret_key(); |
|
278 | 278 | |
279 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
279 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
280 | 280 | $setting_link = $this->get_setting_link(); |
281 | 281 | /* translators: 1) link */ |
282 | - $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 | + $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); |
|
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
286 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
287 | 287 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
288 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
288 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
289 | 289 | /* translators: 1) link 2) link */ |
290 | - $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 | + $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); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | } |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | * @version 4.0.0 |
300 | 300 | */ |
301 | 301 | public function update_plugin_version() { |
302 | - delete_option( 'wc_stripe_version' ); |
|
303 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
302 | + delete_option('wc_stripe_version'); |
|
303 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | * @version 3.1.0 |
311 | 311 | */ |
312 | 312 | public function install() { |
313 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
314 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
313 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
314 | + define('WC_STRIPE_INSTALLING', true); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | $this->update_plugin_version(); |
@@ -323,13 +323,13 @@ discard block |
||
323 | 323 | * @since 1.0.0 |
324 | 324 | * @version 4.0.0 |
325 | 325 | */ |
326 | - public function plugin_action_links( $links ) { |
|
326 | + public function plugin_action_links($links) { |
|
327 | 327 | $plugin_links = array( |
328 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
329 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
330 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
328 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
329 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
330 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
331 | 331 | ); |
332 | - return array_merge( $plugin_links, $links ); |
|
332 | + return array_merge($plugin_links, $links); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | * @since 1.0.0 |
339 | 339 | * @version 4.0.0 |
340 | 340 | */ |
341 | - public function add_gateways( $methods ) { |
|
342 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
341 | + public function add_gateways($methods) { |
|
342 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
343 | 343 | $methods[] = 'WC_Stripe_Compat'; |
344 | 344 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
345 | 345 | } else { |
@@ -364,26 +364,26 @@ discard block |
||
364 | 364 | * @since 4.0.0 |
365 | 365 | * @version 4.0.0 |
366 | 366 | */ |
367 | - public function filter_gateway_order_admin( $sections ) { |
|
368 | - unset( $sections['stripe'] ); |
|
369 | - unset( $sections['stripe_bancontact'] ); |
|
370 | - unset( $sections['stripe_sofort'] ); |
|
371 | - unset( $sections['stripe_giropay'] ); |
|
372 | - unset( $sections['stripe_ideal'] ); |
|
373 | - unset( $sections['stripe_p24'] ); |
|
374 | - unset( $sections['stripe_alipay'] ); |
|
375 | - unset( $sections['stripe_sepa'] ); |
|
376 | - unset( $sections['stripe_bitcoin'] ); |
|
367 | + public function filter_gateway_order_admin($sections) { |
|
368 | + unset($sections['stripe']); |
|
369 | + unset($sections['stripe_bancontact']); |
|
370 | + unset($sections['stripe_sofort']); |
|
371 | + unset($sections['stripe_giropay']); |
|
372 | + unset($sections['stripe_ideal']); |
|
373 | + unset($sections['stripe_p24']); |
|
374 | + unset($sections['stripe_alipay']); |
|
375 | + unset($sections['stripe_sepa']); |
|
376 | + unset($sections['stripe_bitcoin']); |
|
377 | 377 | |
378 | 378 | $sections['stripe'] = 'Stripe'; |
379 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
380 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
381 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
382 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
383 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
384 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
385 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
386 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
379 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
380 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
381 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
382 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
383 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
384 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
385 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
386 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
387 | 387 | |
388 | 388 | return $sections; |
389 | 389 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function __construct() { |
121 | 121 | $this->id = 'stripe'; |
122 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
122 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
123 | 123 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
124 | - $this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' ); |
|
124 | + $this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys'); |
|
125 | 125 | $this->has_fields = true; |
126 | 126 | $this->supports = array( |
127 | 127 | 'products', |
@@ -148,38 +148,38 @@ discard block |
||
148 | 148 | $this->init_settings(); |
149 | 149 | |
150 | 150 | // Get setting values. |
151 | - $this->title = $this->get_option( 'title' ); |
|
152 | - $this->description = $this->get_option( 'description' ); |
|
153 | - $this->enabled = $this->get_option( 'enabled' ); |
|
154 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
155 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
156 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
157 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
158 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
159 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
160 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
161 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
162 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
163 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
164 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
165 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
166 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
167 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
151 | + $this->title = $this->get_option('title'); |
|
152 | + $this->description = $this->get_option('description'); |
|
153 | + $this->enabled = $this->get_option('enabled'); |
|
154 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
155 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
156 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
157 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
158 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
159 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
160 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
161 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
162 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
163 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
164 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
165 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
166 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
167 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
168 | 168 | $this->apple_pay_verify_notice = ''; |
169 | 169 | |
170 | - if ( $this->stripe_checkout ) { |
|
171 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
170 | + if ($this->stripe_checkout) { |
|
171 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
172 | 172 | } |
173 | 173 | |
174 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
174 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
175 | 175 | |
176 | 176 | $this->init_apple_pay(); |
177 | 177 | |
178 | 178 | // Hooks. |
179 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
180 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
181 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
182 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
179 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
180 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
181 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
182 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @since 4.0.2 |
189 | 189 | */ |
190 | 190 | public function is_available() { |
191 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
191 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
192 | 192 | return false; |
193 | 193 | } |
194 | 194 | |
@@ -211,17 +211,17 @@ discard block |
||
211 | 211 | $icons_str .= $icons['amex']; |
212 | 212 | $icons_str .= $icons['mastercard']; |
213 | 213 | |
214 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
214 | + if ('USD' === get_woocommerce_currency()) { |
|
215 | 215 | $icons_str .= $icons['discover']; |
216 | 216 | $icons_str .= $icons['jcb']; |
217 | 217 | $icons_str .= $icons['diners']; |
218 | 218 | } |
219 | 219 | |
220 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
220 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
221 | 221 | $icons_str .= $icons['bitcoin']; |
222 | 222 | } |
223 | 223 | |
224 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
224 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -233,9 +233,9 @@ discard block |
||
233 | 233 | public function init_apple_pay() { |
234 | 234 | if ( |
235 | 235 | is_admin() && |
236 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
237 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
238 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
236 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
237 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
238 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
239 | 239 | $this->payment_request |
240 | 240 | ) { |
241 | 241 | $this->process_apple_pay_verification(); |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | * @version 3.1.0 |
250 | 250 | * @param string $secret_key |
251 | 251 | */ |
252 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
253 | - if ( empty( $secret_key ) ) { |
|
254 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
252 | + private function register_apple_pay_domain($secret_key = '') { |
|
253 | + if (empty($secret_key)) { |
|
254 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -265,23 +265,23 @@ discard block |
||
265 | 265 | 'Authorization' => 'Bearer ' . $secret_key, |
266 | 266 | ); |
267 | 267 | |
268 | - $response = wp_remote_post( $endpoint, array( |
|
268 | + $response = wp_remote_post($endpoint, array( |
|
269 | 269 | 'headers' => $headers, |
270 | - 'body' => http_build_query( $data ), |
|
271 | - ) ); |
|
270 | + 'body' => http_build_query($data), |
|
271 | + )); |
|
272 | 272 | |
273 | - if ( is_wp_error( $response ) ) { |
|
273 | + if (is_wp_error($response)) { |
|
274 | 274 | /* translators: error message */ |
275 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
275 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
276 | 276 | } |
277 | 277 | |
278 | - if ( 200 !== $response['response']['code'] ) { |
|
279 | - $parsed_response = json_decode( $response['body'] ); |
|
278 | + if (200 !== $response['response']['code']) { |
|
279 | + $parsed_response = json_decode($response['body']); |
|
280 | 280 | |
281 | 281 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
282 | 282 | |
283 | 283 | /* translators: error message */ |
284 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
284 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | |
@@ -292,48 +292,48 @@ discard block |
||
292 | 292 | * @version 3.1.0 |
293 | 293 | */ |
294 | 294 | public function process_apple_pay_verification() { |
295 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
295 | + $gateway_settings = get_option('woocommerce_stripe_settings', array()); |
|
296 | 296 | |
297 | 297 | try { |
298 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
298 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
299 | 299 | $dir = '.well-known'; |
300 | 300 | $file = 'apple-developer-merchantid-domain-association'; |
301 | 301 | $fullpath = $path . '/' . $dir . '/' . $file; |
302 | 302 | |
303 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
303 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
304 | 304 | return; |
305 | 305 | } |
306 | 306 | |
307 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
308 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
309 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
307 | + if ( ! file_exists($path . '/' . $dir)) { |
|
308 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
309 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
313 | - if ( ! file_exists( $fullpath ) ) { |
|
314 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
315 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
313 | + if ( ! file_exists($fullpath)) { |
|
314 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
315 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
316 | 316 | } |
317 | 317 | } |
318 | 318 | |
319 | 319 | // At this point then the domain association folder and file should be available. |
320 | 320 | // Proceed to verify/and or verify again. |
321 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
321 | + $this->register_apple_pay_domain($this->secret_key); |
|
322 | 322 | |
323 | 323 | // No errors to this point, verification success! |
324 | 324 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
325 | 325 | $this->apple_pay_domain_set = true; |
326 | 326 | |
327 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
327 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
328 | 328 | |
329 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
329 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
330 | 330 | |
331 | - } catch ( Exception $e ) { |
|
331 | + } catch (Exception $e) { |
|
332 | 332 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
333 | 333 | |
334 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
334 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
335 | 335 | |
336 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
336 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | |
@@ -341,11 +341,11 @@ discard block |
||
341 | 341 | * Check if SSL is enabled and notify the user |
342 | 342 | */ |
343 | 343 | public function admin_notices() { |
344 | - if ( 'no' === $this->enabled ) { |
|
344 | + if ('no' === $this->enabled) { |
|
345 | 345 | return; |
346 | 346 | } |
347 | 347 | |
348 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
348 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
349 | 349 | $allowed_html = array( |
350 | 350 | 'a' => array( |
351 | 351 | 'href' => array(), |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | ), |
354 | 354 | ); |
355 | 355 | |
356 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
356 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -361,9 +361,9 @@ discard block |
||
361 | 361 | * when setting screen is displayed. So if domain verification is not set, |
362 | 362 | * something went wrong so lets notify user. |
363 | 363 | */ |
364 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
364 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
365 | 365 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
366 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
366 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
367 | 367 | } |
368 | 368 | } |
369 | 369 | |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * Initialise Gateway Settings Form Fields |
372 | 372 | */ |
373 | 373 | public function init_form_fields() { |
374 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
374 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
@@ -379,59 +379,59 @@ discard block |
||
379 | 379 | */ |
380 | 380 | public function payment_fields() { |
381 | 381 | $user = wp_get_current_user(); |
382 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
382 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
383 | 383 | $total = WC()->cart->total; |
384 | 384 | $user_email = ''; |
385 | 385 | |
386 | 386 | // If paying from order, we need to get total from order not cart. |
387 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
388 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
387 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
388 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
389 | 389 | $total = $order->get_total(); |
390 | 390 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
391 | 391 | } else { |
392 | - if ( $user->ID ) { |
|
393 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
392 | + if ($user->ID) { |
|
393 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
394 | 394 | $user_email = $user_email ? $user_email : $user->user_email; |
395 | 395 | } |
396 | 396 | } |
397 | 397 | |
398 | - if ( is_add_payment_method_page() ) { |
|
399 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
400 | - $total = ''; |
|
398 | + if (is_add_payment_method_page()) { |
|
399 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
400 | + $total = ''; |
|
401 | 401 | } else { |
402 | 402 | $pay_button_text = ''; |
403 | 403 | } |
404 | 404 | |
405 | 405 | echo '<div |
406 | 406 | id="stripe-payment-data" |
407 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
407 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
408 | 408 | data-description="" |
409 | - data-email="' . esc_attr( $user_email ) . '" |
|
410 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
411 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
412 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
413 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
414 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
415 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
416 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
417 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
418 | - |
|
419 | - if ( $this->description ) { |
|
420 | - if ( $this->testmode ) { |
|
409 | + data-email="' . esc_attr($user_email) . '" |
|
410 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
411 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
412 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
413 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
414 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
415 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
416 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
417 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
418 | + |
|
419 | + if ($this->description) { |
|
420 | + if ($this->testmode) { |
|
421 | 421 | /* translators: link to Stripe testing page */ |
422 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
423 | - $this->description = trim( $this->description ); |
|
422 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
423 | + $this->description = trim($this->description); |
|
424 | 424 | } |
425 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
425 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
426 | 426 | } |
427 | 427 | |
428 | - if ( $display_tokenization ) { |
|
428 | + if ($display_tokenization) { |
|
429 | 429 | $this->tokenization_script(); |
430 | 430 | $this->saved_payment_methods(); |
431 | 431 | } |
432 | 432 | |
433 | - if ( ! $this->stripe_checkout ) { |
|
434 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
433 | + if ( ! $this->stripe_checkout) { |
|
434 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
435 | 435 | $this->elements_form(); |
436 | 436 | } else { |
437 | 437 | $this->form(); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
442 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
443 | 443 | $this->save_payment_method_checkbox(); |
444 | 444 | } |
445 | 445 | |
@@ -454,13 +454,13 @@ discard block |
||
454 | 454 | */ |
455 | 455 | public function elements_form() { |
456 | 456 | ?> |
457 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
458 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
457 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
458 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
459 | 459 | <label for="card-element"> |
460 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
460 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
461 | 461 | </label> |
462 | 462 | |
463 | - <?php if ( $this->inline_cc_form ) { ?> |
|
463 | + <?php if ($this->inline_cc_form) { ?> |
|
464 | 464 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
465 | 465 | <!-- a Stripe Element will be inserted here. --> |
466 | 466 | </div> |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | |
480 | 480 | <!-- Used to display form errors --> |
481 | 481 | <div class="stripe-source-errors" role="alert"></div> |
482 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
482 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
483 | 483 | <div class="clear"></div> |
484 | 484 | </fieldset> |
485 | 485 | <?php |
@@ -492,13 +492,13 @@ discard block |
||
492 | 492 | * @version 3.1.0 |
493 | 493 | */ |
494 | 494 | public function admin_scripts() { |
495 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
495 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
496 | 496 | return; |
497 | 497 | } |
498 | 498 | |
499 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
499 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
500 | 500 | |
501 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
501 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | /** |
@@ -510,29 +510,29 @@ discard block |
||
510 | 510 | * @version 4.0.0 |
511 | 511 | */ |
512 | 512 | public function payment_scripts() { |
513 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
513 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
514 | 514 | return; |
515 | 515 | } |
516 | 516 | |
517 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
517 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
518 | 518 | |
519 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
520 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
521 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
522 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
523 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
524 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
519 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
520 | + wp_enqueue_style('stripe_paymentfonts'); |
|
521 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
522 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
523 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
524 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true); |
|
525 | 525 | |
526 | 526 | $stripe_params = array( |
527 | 527 | 'key' => $this->publishable_key, |
528 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
529 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
528 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
529 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
530 | 530 | ); |
531 | 531 | |
532 | 532 | // If we're on the pay page we need to pass stripe.js the address of the order. |
533 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
534 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
535 | - $order = wc_get_order( $order_id ); |
|
533 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
534 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
535 | + $order = wc_get_order($order_id); |
|
536 | 536 | |
537 | 537 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
538 | 538 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -544,37 +544,37 @@ discard block |
||
544 | 544 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
545 | 545 | } |
546 | 546 | |
547 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
548 | - $stripe_params['no_bank_country_msg'] = __( 'Please select a country for your bank.', 'woocommerce-gateway-stripe' ); |
|
549 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
550 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
551 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
547 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
548 | + $stripe_params['no_bank_country_msg'] = __('Please select a country for your bank.', 'woocommerce-gateway-stripe'); |
|
549 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
550 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
551 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
552 | 552 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
553 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
554 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ); |
|
553 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
554 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])); |
|
555 | 555 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
556 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
557 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
556 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
557 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
558 | 558 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
559 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
559 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
560 | 560 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
561 | - $stripe_params['is_change_payment_page'] = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no'; |
|
561 | + $stripe_params['is_change_payment_page'] = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no'; |
|
562 | 562 | $stripe_params['is_add_payment_method_page'] = is_add_payment_method_page() ? 'yes' : 'no'; |
563 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
564 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
563 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
564 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
565 | 565 | |
566 | 566 | // merge localized messages to be use in JS |
567 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
567 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
568 | 568 | |
569 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
570 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
569 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
570 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
571 | 571 | |
572 | - if ( $this->stripe_checkout ) { |
|
573 | - wp_enqueue_script( 'stripe_checkout' ); |
|
572 | + if ($this->stripe_checkout) { |
|
573 | + wp_enqueue_script('stripe_checkout'); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | $this->tokenization_script(); |
577 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
577 | + wp_enqueue_script('woocommerce_stripe'); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | /** |
@@ -586,22 +586,22 @@ discard block |
||
586 | 586 | * @param object $source_object |
587 | 587 | * @return mixed |
588 | 588 | */ |
589 | - public function create_3ds_source( $order, $source_object ) { |
|
589 | + public function create_3ds_source($order, $source_object) { |
|
590 | 590 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
591 | 591 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
592 | - $return_url = $this->get_stripe_return_url( $order ); |
|
592 | + $return_url = $this->get_stripe_return_url($order); |
|
593 | 593 | |
594 | 594 | $post_data = array(); |
595 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
596 | - $post_data['currency'] = strtolower( $currency ); |
|
595 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
596 | + $post_data['currency'] = strtolower($currency); |
|
597 | 597 | $post_data['type'] = 'three_d_secure'; |
598 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
599 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
600 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
598 | + $post_data['owner'] = $this->get_owner_details($order); |
|
599 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
600 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
601 | 601 | |
602 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source' ); |
|
602 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source'); |
|
603 | 603 | |
604 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
604 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | /** |
@@ -617,46 +617,46 @@ discard block |
||
617 | 617 | * |
618 | 618 | * @return array|void |
619 | 619 | */ |
620 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
620 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
621 | 621 | try { |
622 | - $order = wc_get_order( $order_id ); |
|
623 | - $source_object = ! empty( $_POST['stripe_source'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ) : false; |
|
622 | + $order = wc_get_order($order_id); |
|
623 | + $source_object = ! empty($_POST['stripe_source']) ? json_decode(wc_clean(stripslashes($_POST['stripe_source']))) : false; |
|
624 | 624 | |
625 | 625 | // This comes from the create account checkbox in the checkout page. |
626 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
626 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
627 | 627 | |
628 | - if ( $create_account ) { |
|
628 | + if ($create_account) { |
|
629 | 629 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
630 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
630 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
631 | 631 | $new_stripe_customer->create_customer(); |
632 | 632 | } |
633 | 633 | |
634 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
634 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
635 | 635 | |
636 | 636 | // Check if we don't allow prepaid credit cards. |
637 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
638 | - $stripe_checkout_object = ! empty( $_POST['stripe_checkout_object'] ) ? json_decode( wc_clean( stripslashes( $_POST['stripe_checkout_object'] ) ) ) : false; |
|
637 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
638 | + $stripe_checkout_object = ! empty($_POST['stripe_checkout_object']) ? json_decode(wc_clean(stripslashes($_POST['stripe_checkout_object']))) : false; |
|
639 | 639 | |
640 | - if ( $stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding ) { |
|
641 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
642 | - throw new WC_Stripe_Exception( print_r( $stripe_checkout_object, true ), $localized_message ); |
|
640 | + if ($stripe_checkout_object && 'token' === $stripe_checkout_object->object && 'prepaid' === $stripe_checkout_object->card->funding) { |
|
641 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
642 | + throw new WC_Stripe_Exception(print_r($stripe_checkout_object, true), $localized_message); |
|
643 | 643 | } |
644 | 644 | } |
645 | 645 | |
646 | - if ( empty( $prepared_source->source ) ) { |
|
647 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
648 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
646 | + if (empty($prepared_source->source)) { |
|
647 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
648 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | // Store source to order meta. |
652 | - $this->save_source( $order, $prepared_source ); |
|
652 | + $this->save_source($order, $prepared_source); |
|
653 | 653 | |
654 | 654 | // Result from Stripe API request. |
655 | 655 | $response = null; |
656 | 656 | |
657 | - if ( $order->get_total() > 0 ) { |
|
657 | + if ($order->get_total() > 0) { |
|
658 | 658 | // This will throw exception if not valid. |
659 | - $this->validate_minimum_order_amount( $order ); |
|
659 | + $this->validate_minimum_order_amount($order); |
|
660 | 660 | |
661 | 661 | /** |
662 | 662 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -665,83 +665,83 @@ discard block |
||
665 | 665 | * Note that if we need to save source, the original source must be first |
666 | 666 | * attached to a customer in Stripe before it can be charged. |
667 | 667 | */ |
668 | - if ( $source_object && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) { |
|
668 | + if ($source_object && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) { |
|
669 | 669 | |
670 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
670 | + $response = $this->create_3ds_source($order, $source_object); |
|
671 | 671 | |
672 | - if ( ! empty( $response->error ) ) { |
|
672 | + if ( ! empty($response->error)) { |
|
673 | 673 | $localized_message = $response->error->message; |
674 | 674 | |
675 | - $order->add_order_note( $localized_message ); |
|
675 | + $order->add_order_note($localized_message); |
|
676 | 676 | |
677 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
677 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | // Update order meta with 3DS source. |
681 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
682 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
681 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
682 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
683 | 683 | } else { |
684 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
684 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
685 | 685 | $order->save(); |
686 | 686 | } |
687 | 687 | |
688 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
688 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
689 | 689 | |
690 | 690 | return array( |
691 | 691 | 'result' => 'success', |
692 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
692 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
693 | 693 | ); |
694 | 694 | } |
695 | 695 | |
696 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
696 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
697 | 697 | |
698 | 698 | // Make the request. |
699 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
699 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
700 | 700 | |
701 | - if ( ! empty( $response->error ) ) { |
|
701 | + if ( ! empty($response->error)) { |
|
702 | 702 | // If it is an API error such connection or server, let's retry. |
703 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
704 | - if ( $retry ) { |
|
705 | - sleep( 5 ); |
|
706 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
703 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
704 | + if ($retry) { |
|
705 | + sleep(5); |
|
706 | + return $this->process_payment($order_id, false, $force_save_source); |
|
707 | 707 | } else { |
708 | 708 | $localized_message = 'API connection error and retries exhausted.'; |
709 | - $order->add_order_note( $localized_message ); |
|
710 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
709 | + $order->add_order_note($localized_message); |
|
710 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
711 | 711 | } |
712 | 712 | } |
713 | 713 | |
714 | 714 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
715 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
716 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
715 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
716 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
717 | 717 | |
718 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
719 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
718 | + return $this->process_payment($order_id, false, $force_save_source); |
|
719 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
720 | 720 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
721 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
721 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
722 | 722 | $wc_token->delete(); |
723 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
724 | - $order->add_order_note( $localized_message ); |
|
725 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
723 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
724 | + $order->add_order_note($localized_message); |
|
725 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
726 | 726 | } |
727 | 727 | |
728 | 728 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
729 | 729 | |
730 | - if ( 'card_error' === $response->error->type ) { |
|
731 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
730 | + if ('card_error' === $response->error->type) { |
|
731 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
732 | 732 | } else { |
733 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
733 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
734 | 734 | } |
735 | 735 | |
736 | - $order->add_order_note( $localized_message ); |
|
736 | + $order->add_order_note($localized_message); |
|
737 | 737 | |
738 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
738 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
739 | 739 | } |
740 | 740 | |
741 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
741 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
742 | 742 | |
743 | 743 | // Process valid response. |
744 | - $this->process_response( $response, $order ); |
|
744 | + $this->process_response($response, $order); |
|
745 | 745 | } else { |
746 | 746 | $order->payment_complete(); |
747 | 747 | } |
@@ -752,17 +752,17 @@ discard block |
||
752 | 752 | // Return thank you page redirect. |
753 | 753 | return array( |
754 | 754 | 'result' => 'success', |
755 | - 'redirect' => $this->get_return_url( $order ), |
|
755 | + 'redirect' => $this->get_return_url($order), |
|
756 | 756 | ); |
757 | 757 | |
758 | - } catch ( WC_Stripe_Exception $e ) { |
|
759 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
760 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
758 | + } catch (WC_Stripe_Exception $e) { |
|
759 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
760 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
761 | 761 | |
762 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
762 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
763 | 763 | |
764 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
765 | - $this->send_failed_order_email( $order_id ); |
|
764 | + if ($order->has_status(array('pending', 'failed'))) { |
|
765 | + $this->send_failed_order_email($order_id); |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_sepa'; |
60 | - $this->method_title = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -84,25 +84,25 @@ discard block |
||
84 | 84 | // Load the settings. |
85 | 85 | $this->init_settings(); |
86 | 86 | |
87 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
88 | - $this->title = $this->get_option( 'title' ); |
|
89 | - $this->description = $this->get_option( 'description' ); |
|
90 | - $this->enabled = $this->get_option( 'enabled' ); |
|
91 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
92 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
93 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
94 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
95 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
96 | - |
|
97 | - if ( $this->testmode ) { |
|
98 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
99 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
87 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
88 | + $this->title = $this->get_option('title'); |
|
89 | + $this->description = $this->get_option('description'); |
|
90 | + $this->enabled = $this->get_option('enabled'); |
|
91 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
92 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
93 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
94 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
95 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
96 | + |
|
97 | + if ($this->testmode) { |
|
98 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
99 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
100 | 100 | } |
101 | 101 | |
102 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
103 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
104 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
105 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
102 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
103 | + add_action('admin_notices', array($this, 'check_environment')); |
|
104 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
105 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -112,19 +112,19 @@ discard block |
||
112 | 112 | * @version 4.0.0 |
113 | 113 | */ |
114 | 114 | public function check_environment() { |
115 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
115 | + if ( ! current_user_can('manage_woocommerce')) { |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | 119 | $environment_warning = $this->get_environment_warning(); |
120 | 120 | |
121 | - if ( $environment_warning ) { |
|
122 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
121 | + if ($environment_warning) { |
|
122 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
123 | 123 | } |
124 | 124 | |
125 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
126 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
127 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
125 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
126 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
127 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
128 | 128 | echo '</p></div>'; |
129 | 129 | } |
130 | 130 | } |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | * @version 4.0.0 |
138 | 138 | */ |
139 | 139 | public function get_environment_warning() { |
140 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
141 | - $message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
140 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
141 | + $message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
142 | 142 | |
143 | 143 | return $message; |
144 | 144 | } |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | * @return array |
155 | 155 | */ |
156 | 156 | public function get_supported_currency() { |
157 | - return apply_filters( 'wc_stripe_sepa_supported_currencies', array( |
|
157 | + return apply_filters('wc_stripe_sepa_supported_currencies', array( |
|
158 | 158 | 'EUR', |
159 | - ) ); |
|
159 | + )); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | * @return bool |
168 | 168 | */ |
169 | 169 | public function is_available() { |
170 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
170 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
171 | 171 | return false; |
172 | 172 | } |
173 | 173 | |
174 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
174 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | $icons_str .= $icons['sepa']; |
194 | 194 | |
195 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
195 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -203,19 +203,19 @@ discard block |
||
203 | 203 | * @access public |
204 | 204 | */ |
205 | 205 | public function payment_scripts() { |
206 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
206 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
207 | 207 | return; |
208 | 208 | } |
209 | 209 | |
210 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
211 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
210 | + wp_enqueue_style('stripe_paymentfonts'); |
|
211 | + wp_enqueue_script('woocommerce_stripe'); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | 215 | * Initialize Gateway Settings Form Fields. |
216 | 216 | */ |
217 | 217 | public function init_form_fields() { |
218 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' ); |
|
218 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php'); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function mandate_display() { |
229 | 229 | /* translators: statement descriptor */ |
230 | - printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ) ); |
|
230 | + printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor)); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -238,24 +238,24 @@ discard block |
||
238 | 238 | */ |
239 | 239 | public function form() { |
240 | 240 | ?> |
241 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
242 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
241 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
242 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
243 | 243 | <p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p> |
244 | 244 | <p class="form-row form-row-wide validate-required"> |
245 | 245 | <label for="stripe-sepa-owner"> |
246 | - <?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?> |
|
246 | + <?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?> |
|
247 | 247 | </label> |
248 | 248 | <input id="stripe-sepa-owner" name="stripe_sepa_owner" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" /> |
249 | 249 | </p> |
250 | 250 | <p class="form-row form-row-wide validate-required"> |
251 | 251 | <label for="stripe-sepa-iban"> |
252 | - <?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?> |
|
252 | + <?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?> |
|
253 | 253 | </label> |
254 | 254 | <input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" style="border:1px solid #ddd;margin:5px 0;padding:10px 5px;background-color:#fff;outline:0;" /> |
255 | 255 | </p> |
256 | 256 | <!-- Used to display form errors --> |
257 | 257 | <div class="stripe-source-errors" role="alert"></div> |
258 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
258 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
259 | 259 | <div class="clear"></div> |
260 | 260 | </fieldset> |
261 | 261 | <?php |
@@ -267,42 +267,42 @@ discard block |
||
267 | 267 | public function payment_fields() { |
268 | 268 | $user = wp_get_current_user(); |
269 | 269 | $total = WC()->cart->total; |
270 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
270 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
271 | 271 | |
272 | 272 | // If paying from order, we need to get total from order not cart. |
273 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
274 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
273 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
274 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
275 | 275 | $total = $order->get_total(); |
276 | 276 | } |
277 | 277 | |
278 | - if ( is_add_payment_method_page() ) { |
|
279 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
280 | - $total = ''; |
|
278 | + if (is_add_payment_method_page()) { |
|
279 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
280 | + $total = ''; |
|
281 | 281 | } else { |
282 | 282 | $pay_button_text = ''; |
283 | 283 | } |
284 | 284 | |
285 | 285 | echo '<div |
286 | 286 | id="stripe-sepa_debit-payment-data" |
287 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
288 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
287 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
288 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
289 | 289 | |
290 | - if ( $this->description ) { |
|
291 | - if ( $this->testmode ) { |
|
292 | - $this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' ); |
|
293 | - $this->description = trim( $this->description ); |
|
290 | + if ($this->description) { |
|
291 | + if ($this->testmode) { |
|
292 | + $this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe'); |
|
293 | + $this->description = trim($this->description); |
|
294 | 294 | } |
295 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
295 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
296 | 296 | } |
297 | 297 | |
298 | - if ( $display_tokenization ) { |
|
298 | + if ($display_tokenization) { |
|
299 | 299 | $this->tokenization_script(); |
300 | 300 | $this->saved_payment_methods(); |
301 | 301 | } |
302 | 302 | |
303 | 303 | $this->form(); |
304 | 304 | |
305 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
305 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
306 | 306 | $this->save_payment_method_checkbox(); |
307 | 307 | } |
308 | 308 | |
@@ -320,80 +320,80 @@ discard block |
||
320 | 320 | * |
321 | 321 | * @return array|void |
322 | 322 | */ |
323 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
323 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
324 | 324 | try { |
325 | - $order = wc_get_order( $order_id ); |
|
325 | + $order = wc_get_order($order_id); |
|
326 | 326 | |
327 | 327 | // This comes from the create account checkbox in the checkout page. |
328 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
328 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
329 | 329 | |
330 | - if ( $create_account ) { |
|
330 | + if ($create_account) { |
|
331 | 331 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
332 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
332 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
333 | 333 | $new_stripe_customer->create_customer(); |
334 | 334 | } |
335 | 335 | |
336 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
336 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
337 | 337 | |
338 | 338 | // Store source to order meta. |
339 | - $this->save_source( $order, $prepared_source ); |
|
339 | + $this->save_source($order, $prepared_source); |
|
340 | 340 | |
341 | 341 | // Result from Stripe API request. |
342 | 342 | $response = null; |
343 | 343 | |
344 | - if ( $order->get_total() > 0 ) { |
|
344 | + if ($order->get_total() > 0) { |
|
345 | 345 | // This will throw exception if not valid. |
346 | - $this->validate_minimum_order_amount( $order ); |
|
346 | + $this->validate_minimum_order_amount($order); |
|
347 | 347 | |
348 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
348 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
349 | 349 | |
350 | 350 | // Make the request. |
351 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
351 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
352 | 352 | |
353 | - if ( ! empty( $response->error ) ) { |
|
353 | + if ( ! empty($response->error)) { |
|
354 | 354 | // If it is an API error such connection or server, let's retry. |
355 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
356 | - if ( $retry ) { |
|
357 | - sleep( 5 ); |
|
358 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
355 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
356 | + if ($retry) { |
|
357 | + sleep(5); |
|
358 | + return $this->process_payment($order_id, false, $force_save_source); |
|
359 | 359 | } else { |
360 | 360 | $localized_message = 'API connection error and retries exhausted.'; |
361 | - $order->add_order_note( $localized_message ); |
|
362 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
361 | + $order->add_order_note($localized_message); |
|
362 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 | |
366 | 366 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
367 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
368 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
367 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
368 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
369 | 369 | |
370 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
371 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
370 | + return $this->process_payment($order_id, false, $force_save_source); |
|
371 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
372 | 372 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
373 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
373 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
374 | 374 | $wc_token->delete(); |
375 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
376 | - $order->add_order_note( $localized_message ); |
|
377 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
375 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
376 | + $order->add_order_note($localized_message); |
|
377 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
381 | 381 | |
382 | - if ( 'card_error' === $response->error->type ) { |
|
383 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
382 | + if ('card_error' === $response->error->type) { |
|
383 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
384 | 384 | } else { |
385 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
385 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
386 | 386 | } |
387 | 387 | |
388 | - $order->add_order_note( $localized_message ); |
|
388 | + $order->add_order_note($localized_message); |
|
389 | 389 | |
390 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
390 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
391 | 391 | } |
392 | 392 | |
393 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
393 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
394 | 394 | |
395 | 395 | // Process valid response. |
396 | - $this->process_response( $response, $order ); |
|
396 | + $this->process_response($response, $order); |
|
397 | 397 | } else { |
398 | 398 | $order->payment_complete(); |
399 | 399 | } |
@@ -404,17 +404,17 @@ discard block |
||
404 | 404 | // Return thank you page redirect. |
405 | 405 | return array( |
406 | 406 | 'result' => 'success', |
407 | - 'redirect' => $this->get_return_url( $order ), |
|
407 | + 'redirect' => $this->get_return_url($order), |
|
408 | 408 | ); |
409 | 409 | |
410 | - } catch ( WC_Stripe_Exception $e ) { |
|
411 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
412 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
410 | + } catch (WC_Stripe_Exception $e) { |
|
411 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
412 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
413 | 413 | |
414 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
414 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
415 | 415 | |
416 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
417 | - $this->send_failed_order_email( $order_id ); |
|
416 | + if ($order->has_status(array('pending', 'failed'))) { |
|
417 | + $this->send_failed_order_email($order_id); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | return array( |