@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | |
24 | 24 | $this->retry_interval = 1; |
25 | 25 | |
26 | - add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) ); |
|
27 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
28 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
29 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
30 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
26 | + add_action('wp', array($this, 'maybe_process_redirect_order')); |
|
27 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
28 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
29 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
30 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -48,25 +48,25 @@ discard block |
||
48 | 48 | * @since 4.0.0 |
49 | 49 | * @version 4.0.0 |
50 | 50 | */ |
51 | - public function process_redirect_payment( $order_id, $retry = true ) { |
|
51 | + public function process_redirect_payment($order_id, $retry = true) { |
|
52 | 52 | try { |
53 | - $source = wc_clean( $_GET['source'] ); |
|
53 | + $source = wc_clean($_GET['source']); |
|
54 | 54 | |
55 | - if ( empty( $source ) ) { |
|
55 | + if (empty($source)) { |
|
56 | 56 | return; |
57 | 57 | } |
58 | 58 | |
59 | - if ( empty( $order_id ) ) { |
|
59 | + if (empty($order_id)) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | - $order = wc_get_order( $order_id ); |
|
63 | + $order = wc_get_order($order_id); |
|
64 | 64 | |
65 | - if ( ! is_object( $order ) ) { |
|
65 | + if ( ! is_object($order)) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) { |
|
69 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) { |
|
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
@@ -74,127 +74,127 @@ discard block |
||
74 | 74 | $response = null; |
75 | 75 | |
76 | 76 | // This will throw exception if not valid. |
77 | - $this->validate_minimum_order_amount( $order ); |
|
77 | + $this->validate_minimum_order_amount($order); |
|
78 | 78 | |
79 | - WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
79 | + WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * First check if the source is chargeable at this time. If not, |
83 | 83 | * webhook will take care of it later. |
84 | 84 | */ |
85 | - $source_info = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
85 | + $source_info = WC_Stripe_API::retrieve('sources/' . $source); |
|
86 | 86 | |
87 | - if ( ! empty( $source_info->error ) ) { |
|
88 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message ); |
|
87 | + if ( ! empty($source_info->error)) { |
|
88 | + throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message); |
|
89 | 89 | } |
90 | 90 | |
91 | - if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) { |
|
92 | - 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' ) ); |
|
91 | + if ('failed' === $source_info->status || 'canceled' === $source_info->status) { |
|
92 | + 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')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // If already consumed, then ignore request. |
96 | - if ( 'consumed' === $source_info->status ) { |
|
96 | + if ('consumed' === $source_info->status) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
100 | 100 | // If not chargeable, then ignore request. |
101 | - if ( 'chargeable' !== $source_info->status ) { |
|
101 | + if ('chargeable' !== $source_info->status) { |
|
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | 105 | // Prep source object. |
106 | 106 | $source_object = new stdClass(); |
107 | 107 | $source_object->token_id = ''; |
108 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
108 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
109 | 109 | $source_object->source = $source_info->id; |
110 | 110 | |
111 | 111 | /* If we're doing a retry and source is chargeable, we need to pass |
112 | 112 | * a different idempotency key and retry for success. |
113 | 113 | */ |
114 | - if ( 1 < $this->retry_interval && 'chargeable' === $source_info->status ) { |
|
115 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
114 | + if (1 < $this->retry_interval && 'chargeable' === $source_info->status) { |
|
115 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // Make the request. |
119 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true ); |
|
119 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true); |
|
120 | 120 | $headers = $response['headers']; |
121 | 121 | $response = $response['body']; |
122 | 122 | |
123 | - if ( ! empty( $response->error ) ) { |
|
123 | + if ( ! empty($response->error)) { |
|
124 | 124 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
125 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
126 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
127 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
128 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
125 | + if ($this->is_no_such_customer_error($response->error)) { |
|
126 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
127 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
128 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
129 | 129 | } else { |
130 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
131 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
130 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
131 | + $order->delete_meta_data('_stripe_customer_id'); |
|
132 | 132 | $order->save(); |
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
136 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
137 | 137 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
138 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
138 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
139 | 139 | $wc_token->delete(); |
140 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
141 | - $order->add_order_note( $localized_message ); |
|
142 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
140 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
141 | + $order->add_order_note($localized_message); |
|
142 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | // We want to retry. |
146 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
147 | - if ( $retry ) { |
|
146 | + if ($this->is_retryable_error($response->error)) { |
|
147 | + if ($retry) { |
|
148 | 148 | // Don't do anymore retries after this. |
149 | - if ( 5 <= $this->retry_interval ) { |
|
150 | - return $this->process_redirect_payment( $order_id, false ); |
|
149 | + if (5 <= $this->retry_interval) { |
|
150 | + return $this->process_redirect_payment($order_id, false); |
|
151 | 151 | } |
152 | 152 | |
153 | - sleep( $this->retry_interval ); |
|
153 | + sleep($this->retry_interval); |
|
154 | 154 | |
155 | 155 | $this->retry_interval++; |
156 | - return $this->process_redirect_payment( $order_id, true ); |
|
156 | + return $this->process_redirect_payment($order_id, true); |
|
157 | 157 | } else { |
158 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
159 | - $order->add_order_note( $localized_message ); |
|
160 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
158 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
159 | + $order->add_order_note($localized_message); |
|
160 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | 164 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
165 | 165 | |
166 | - if ( 'card_error' === $response->error->type ) { |
|
167 | - $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
166 | + if ('card_error' === $response->error->type) { |
|
167 | + $message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
168 | 168 | } else { |
169 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
169 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
170 | 170 | } |
171 | 171 | |
172 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
172 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | // To prevent double processing the order on WC side. |
176 | - if ( ! $this->is_original_request( $headers ) ) { |
|
176 | + if ( ! $this->is_original_request($headers)) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | - do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
180 | + do_action('wc_gateway_stripe_process_redirect_payment', $response, $order); |
|
181 | 181 | |
182 | - $this->process_response( $response, $order ); |
|
182 | + $this->process_response($response, $order); |
|
183 | 183 | |
184 | - } catch ( WC_Stripe_Exception $e ) { |
|
185 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
184 | + } catch (WC_Stripe_Exception $e) { |
|
185 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
186 | 186 | |
187 | - do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order ); |
|
187 | + do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order); |
|
188 | 188 | |
189 | 189 | /* translators: error message */ |
190 | - $order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) ); |
|
190 | + $order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage())); |
|
191 | 191 | |
192 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
193 | - $this->send_failed_order_email( $order_id ); |
|
192 | + if ($order->has_status(array('pending', 'failed'))) { |
|
193 | + $this->send_failed_order_email($order_id); |
|
194 | 194 | } |
195 | 195 | |
196 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
197 | - wp_safe_redirect( wc_get_checkout_url() ); |
|
196 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
197 | + wp_safe_redirect(wc_get_checkout_url()); |
|
198 | 198 | exit; |
199 | 199 | } |
200 | 200 | } |
@@ -206,13 +206,13 @@ discard block |
||
206 | 206 | * @version 4.0.0 |
207 | 207 | */ |
208 | 208 | public function maybe_process_redirect_order() { |
209 | - if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) { |
|
209 | + if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) { |
|
210 | 210 | return; |
211 | 211 | } |
212 | 212 | |
213 | - $order_id = wc_clean( $_GET['order_id'] ); |
|
213 | + $order_id = wc_clean($_GET['order_id']); |
|
214 | 214 | |
215 | - $this->process_redirect_payment( $order_id ); |
|
215 | + $this->process_redirect_payment($order_id); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -222,52 +222,52 @@ discard block |
||
222 | 222 | * @version 4.0.0 |
223 | 223 | * @param int $order_id |
224 | 224 | */ |
225 | - public function capture_payment( $order_id ) { |
|
226 | - $order = wc_get_order( $order_id ); |
|
225 | + public function capture_payment($order_id) { |
|
226 | + $order = wc_get_order($order_id); |
|
227 | 227 | |
228 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
229 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
230 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
228 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
229 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
230 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
231 | 231 | |
232 | - if ( $charge && 'no' === $captured ) { |
|
232 | + if ($charge && 'no' === $captured) { |
|
233 | 233 | $order_total = $order->get_total(); |
234 | 234 | |
235 | - if ( 0 < $order->get_total_refunded() ) { |
|
235 | + if (0 < $order->get_total_refunded()) { |
|
236 | 236 | $order_total = $order_total - $order->get_total_refunded(); |
237 | 237 | } |
238 | 238 | |
239 | - $result = WC_Stripe_API::request( array( |
|
240 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order_total ), |
|
239 | + $result = WC_Stripe_API::request(array( |
|
240 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order_total), |
|
241 | 241 | 'expand[]' => 'balance_transaction', |
242 | - ), 'charges/' . $charge . '/capture' ); |
|
242 | + ), 'charges/' . $charge . '/capture'); |
|
243 | 243 | |
244 | - if ( ! empty( $result->error ) ) { |
|
244 | + if ( ! empty($result->error)) { |
|
245 | 245 | /* translators: error message */ |
246 | - $order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
246 | + $order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
247 | 247 | } else { |
248 | 248 | /* translators: transaction id */ |
249 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
250 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
249 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
250 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
251 | 251 | |
252 | 252 | // Store other data such as fees |
253 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id ); |
|
253 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id); |
|
254 | 254 | |
255 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
255 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
256 | 256 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
257 | 257 | // values are in the local currency of the Stripe account, not from WC. |
258 | - $fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0; |
|
259 | - $net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0; |
|
260 | - WC_Stripe_Helper::update_stripe_fee( $order, $fee ); |
|
261 | - WC_Stripe_Helper::update_stripe_net( $order, $net ); |
|
258 | + $fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0; |
|
259 | + $net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0; |
|
260 | + WC_Stripe_Helper::update_stripe_fee($order, $fee); |
|
261 | + WC_Stripe_Helper::update_stripe_net($order, $net); |
|
262 | 262 | } |
263 | 263 | |
264 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
264 | + if (is_callable(array($order, 'save'))) { |
|
265 | 265 | $order->save(); |
266 | 266 | } |
267 | 267 | } |
268 | 268 | |
269 | 269 | // This hook fires when admin manually changes order status to processing or completed. |
270 | - do_action( 'woocommerce_stripe_process_manual_capture', $order, $result ); |
|
270 | + do_action('woocommerce_stripe_process_manual_capture', $order, $result); |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | } |
@@ -279,14 +279,14 @@ discard block |
||
279 | 279 | * @version 4.0.0 |
280 | 280 | * @param int $order_id |
281 | 281 | */ |
282 | - public function cancel_payment( $order_id ) { |
|
283 | - $order = wc_get_order( $order_id ); |
|
282 | + public function cancel_payment($order_id) { |
|
283 | + $order = wc_get_order($order_id); |
|
284 | 284 | |
285 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
286 | - $this->process_refund( $order_id ); |
|
285 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
286 | + $this->process_refund($order_id); |
|
287 | 287 | |
288 | 288 | // This hook fires when admin manually changes order status to cancel. |
289 | - do_action( 'woocommerce_stripe_process_manual_cancel', $order ); |
|
289 | + do_action('woocommerce_stripe_process_manual_cancel', $order); |
|
290 | 290 | } |
291 | 291 | } |
292 | 292 | } |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | * |
16 | 16 | */ |
17 | 17 | |
18 | -if ( ! defined( 'ABSPATH' ) ) { |
|
18 | +if ( ! defined('ABSPATH')) { |
|
19 | 19 | exit; |
20 | 20 | } |
21 | 21 | |
22 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
22 | +if ( ! class_exists('WC_Stripe')) : |
|
23 | 23 | /** |
24 | 24 | * Required minimums and constants |
25 | 25 | */ |
26 | - define( 'WC_STRIPE_VERSION', '4.1.0' ); |
|
27 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
28 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
29 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
30 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
31 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
26 | + define('WC_STRIPE_VERSION', '4.1.0'); |
|
27 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
28 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
29 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
30 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
31 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
32 | 32 | |
33 | 33 | class WC_Stripe { |
34 | 34 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @return Singleton The *Singleton* instance. |
49 | 49 | */ |
50 | 50 | public static function get_instance() { |
51 | - if ( null === self::$instance ) { |
|
51 | + if (null === self::$instance) { |
|
52 | 52 | self::$instance = new self(); |
53 | 53 | } |
54 | 54 | return self::$instance; |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | * *Singleton* via the `new` operator from outside of this class. |
76 | 76 | */ |
77 | 77 | private function __construct() { |
78 | - add_action( 'admin_init', array( $this, 'install' ) ); |
|
79 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
78 | + add_action('admin_init', array($this, 'install')); |
|
79 | + add_action('plugins_loaded', array($this, 'init')); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -86,51 +86,51 @@ discard block |
||
86 | 86 | * @version 4.0.0 |
87 | 87 | */ |
88 | 88 | public function init() { |
89 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' ); |
|
90 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
91 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
92 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
89 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'); |
|
90 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
91 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
92 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
93 | 93 | |
94 | 94 | // Don't hook anything else in the plugin if we're in an incompatible environment. |
95 | - if ( $this->get_environment_warning() && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
95 | + if ($this->get_environment_warning() && is_plugin_active(plugin_basename(__FILE__))) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
100 | - |
|
101 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
102 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
103 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
104 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay-registration.php' ); |
|
105 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-pre-orders-compat.php' ); |
|
106 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
107 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
108 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
109 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
110 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php' ); |
|
111 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
112 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
113 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-subs-compat.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
123 | - |
|
124 | - if ( is_admin() ) { |
|
125 | - require_once( dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-admin-notices.php' ); |
|
99 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
100 | + |
|
101 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
102 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
103 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
104 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay-registration.php'); |
|
105 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-pre-orders-compat.php'); |
|
106 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
107 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
108 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
109 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
110 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-eps.php'); |
|
111 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
112 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
113 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-multibanco.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-subs-compat.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-subs-compat.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
123 | + |
|
124 | + if (is_admin()) { |
|
125 | + require_once(dirname(__FILE__) . '/includes/admin/class-wc-stripe-admin-notices.php'); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | // REMOVE IN THE FUTURE. |
129 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
129 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
130 | 130 | |
131 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
132 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
133 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
131 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
132 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
133 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -142,26 +142,26 @@ discard block |
||
142 | 142 | * @version 4.0.0 |
143 | 143 | */ |
144 | 144 | public function get_environment_warning() { |
145 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
145 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
146 | 146 | /* translators: 1) int version 2) int version */ |
147 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
147 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
148 | 148 | |
149 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
149 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
150 | 150 | } |
151 | 151 | |
152 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
153 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
152 | + if ( ! defined('WC_VERSION')) { |
|
153 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
154 | 154 | } |
155 | 155 | |
156 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
156 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
157 | 157 | /* translators: 1) int version 2) int version */ |
158 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
158 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
159 | 159 | |
160 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
160 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
161 | 161 | } |
162 | 162 | |
163 | - if ( ! function_exists( 'curl_init' ) ) { |
|
164 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
163 | + if ( ! function_exists('curl_init')) { |
|
164 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | return false; |
@@ -174,8 +174,8 @@ discard block |
||
174 | 174 | * @version 4.0.0 |
175 | 175 | */ |
176 | 176 | public function update_plugin_version() { |
177 | - delete_option( 'wc_stripe_version' ); |
|
178 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
177 | + delete_option('wc_stripe_version'); |
|
178 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | * @version 3.1.0 |
186 | 186 | */ |
187 | 187 | public function install() { |
188 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
189 | - do_action( 'woocommerce_stripe_updated' ); |
|
188 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
189 | + do_action('woocommerce_stripe_updated'); |
|
190 | 190 | |
191 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
192 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
191 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
192 | + define('WC_STRIPE_INSTALLING', true); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | $this->update_plugin_version(); |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | * @since 1.0.0 |
203 | 203 | * @version 4.0.0 |
204 | 204 | */ |
205 | - public function plugin_action_links( $links ) { |
|
205 | + public function plugin_action_links($links) { |
|
206 | 206 | $plugin_links = array( |
207 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
208 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
209 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
207 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
208 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
209 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
210 | 210 | ); |
211 | - return array_merge( $plugin_links, $links ); |
|
211 | + return array_merge($plugin_links, $links); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | * @since 1.0.0 |
218 | 218 | * @version 4.0.0 |
219 | 219 | */ |
220 | - public function add_gateways( $methods ) { |
|
221 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
220 | + public function add_gateways($methods) { |
|
221 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
222 | 222 | $methods[] = 'WC_Stripe_Subs_Compat'; |
223 | 223 | $methods[] = 'WC_Stripe_Sepa_Subs_Compat'; |
224 | 224 | } else { |
@@ -245,30 +245,30 @@ discard block |
||
245 | 245 | * @since 4.0.0 |
246 | 246 | * @version 4.0.0 |
247 | 247 | */ |
248 | - public function filter_gateway_order_admin( $sections ) { |
|
249 | - unset( $sections['stripe'] ); |
|
250 | - unset( $sections['stripe_bancontact'] ); |
|
251 | - unset( $sections['stripe_sofort'] ); |
|
252 | - unset( $sections['stripe_giropay'] ); |
|
253 | - unset( $sections['stripe_eps'] ); |
|
254 | - unset( $sections['stripe_ideal'] ); |
|
255 | - unset( $sections['stripe_p24'] ); |
|
256 | - unset( $sections['stripe_alipay'] ); |
|
257 | - unset( $sections['stripe_sepa'] ); |
|
258 | - unset( $sections['stripe_bitcoin'] ); |
|
259 | - unset( $sections['stripe_multibanco'] ); |
|
248 | + public function filter_gateway_order_admin($sections) { |
|
249 | + unset($sections['stripe']); |
|
250 | + unset($sections['stripe_bancontact']); |
|
251 | + unset($sections['stripe_sofort']); |
|
252 | + unset($sections['stripe_giropay']); |
|
253 | + unset($sections['stripe_eps']); |
|
254 | + unset($sections['stripe_ideal']); |
|
255 | + unset($sections['stripe_p24']); |
|
256 | + unset($sections['stripe_alipay']); |
|
257 | + unset($sections['stripe_sepa']); |
|
258 | + unset($sections['stripe_bitcoin']); |
|
259 | + unset($sections['stripe_multibanco']); |
|
260 | 260 | |
261 | 261 | $sections['stripe'] = 'Stripe'; |
262 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
263 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
264 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
265 | - $sections['stripe_eps'] = __( 'Stripe EPS', 'woocommerce-gateway-stripe' ); |
|
266 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
267 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
268 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
269 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
270 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
271 | - $sections['stripe_multibanco'] = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' ); |
|
262 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
263 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
264 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
265 | + $sections['stripe_eps'] = __('Stripe EPS', 'woocommerce-gateway-stripe'); |
|
266 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
267 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
268 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
269 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
270 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
271 | + $sections['stripe_multibanco'] = __('Stripe Multibanco', 'woocommerce-gateway-stripe'); |
|
272 | 272 | |
273 | 273 | return $sections; |
274 | 274 | } |
@@ -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,9 +32,9 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function __construct() { |
34 | 34 | $this->retry_interval = 2; |
35 | - $stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
36 | - $this->testmode = ( ! empty( $stripe_settings['testmode'] ) && 'yes' === $stripe_settings['testmode'] ) ? true : false; |
|
37 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
35 | + $stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
36 | + $this->testmode = ( ! empty($stripe_settings['testmode']) && 'yes' === $stripe_settings['testmode']) ? true : false; |
|
37 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -44,24 +44,24 @@ discard block |
||
44 | 44 | * @version 4.0.0 |
45 | 45 | */ |
46 | 46 | public function check_for_webhook() { |
47 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
48 | - || ! isset( $_GET['wc-api'] ) |
|
49 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
47 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
48 | + || ! isset($_GET['wc-api']) |
|
49 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
50 | 50 | ) { |
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | - $request_body = file_get_contents( 'php://input' ); |
|
55 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
54 | + $request_body = file_get_contents('php://input'); |
|
55 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
56 | 56 | |
57 | 57 | // Validate it to make sure it is legit. |
58 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
59 | - $this->process_webhook( $request_body ); |
|
60 | - status_header( 200 ); |
|
58 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
59 | + $this->process_webhook($request_body); |
|
60 | + status_header(200); |
|
61 | 61 | exit; |
62 | 62 | } else { |
63 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
64 | - status_header( 400 ); |
|
63 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
64 | + status_header(400); |
|
65 | 65 | exit; |
66 | 66 | } |
67 | 67 | } |
@@ -76,12 +76,12 @@ discard block |
||
76 | 76 | * @param string $request_body The request body from Stripe. |
77 | 77 | * @return bool |
78 | 78 | */ |
79 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
80 | - if ( null === $request_headers || null === $request_body ) { |
|
79 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
80 | + if (null === $request_headers || null === $request_body) { |
|
81 | 81 | return false; |
82 | 82 | } |
83 | 83 | |
84 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
84 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
85 | 85 | return false; |
86 | 86 | } |
87 | 87 | |
@@ -97,11 +97,11 @@ discard block |
||
97 | 97 | * @version 4.0.0 |
98 | 98 | */ |
99 | 99 | public function get_request_headers() { |
100 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
100 | + if ( ! function_exists('getallheaders')) { |
|
101 | 101 | $headers = []; |
102 | - foreach ( $_SERVER as $name => $value ) { |
|
103 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
104 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
102 | + foreach ($_SERVER as $name => $value) { |
|
103 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
104 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
@@ -120,30 +120,30 @@ discard block |
||
120 | 120 | * @param object $notification |
121 | 121 | * @param bool $retry |
122 | 122 | */ |
123 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
123 | + public function process_webhook_payment($notification, $retry = true) { |
|
124 | 124 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
125 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
125 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
129 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
130 | 130 | |
131 | - if ( ! $order ) { |
|
132 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
131 | + if ( ! $order) { |
|
132 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
137 | 137 | $source_id = $notification->data->object->id; |
138 | 138 | |
139 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
139 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
140 | 140 | |
141 | 141 | try { |
142 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
142 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | 145 | |
146 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
146 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | |
@@ -151,94 +151,94 @@ discard block |
||
151 | 151 | $response = null; |
152 | 152 | |
153 | 153 | // This will throw exception if not valid. |
154 | - $this->validate_minimum_order_amount( $order ); |
|
154 | + $this->validate_minimum_order_amount($order); |
|
155 | 155 | |
156 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
156 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
157 | 157 | |
158 | 158 | // Prep source object. |
159 | 159 | $source_object = new stdClass(); |
160 | 160 | $source_object->token_id = ''; |
161 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
161 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
162 | 162 | $source_object->source = $source_id; |
163 | 163 | |
164 | 164 | // Make the request. |
165 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ), 'charges', 'POST', true ); |
|
165 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object), 'charges', 'POST', true); |
|
166 | 166 | $headers = $response['headers']; |
167 | 167 | $response = $response['body']; |
168 | 168 | |
169 | - if ( ! empty( $response->error ) ) { |
|
169 | + if ( ! empty($response->error)) { |
|
170 | 170 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
171 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
172 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
173 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
174 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
171 | + if ($this->is_no_such_customer_error($response->error)) { |
|
172 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
173 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
174 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
175 | 175 | } else { |
176 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
177 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
176 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
177 | + $order->delete_meta_data('_stripe_customer_id'); |
|
178 | 178 | $order->save(); |
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
182 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
183 | 183 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
184 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
184 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
185 | 185 | $wc_token->delete(); |
186 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
187 | - $order->add_order_note( $localized_message ); |
|
188 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
186 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
187 | + $order->add_order_note($localized_message); |
|
188 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | // We want to retry. |
192 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
193 | - if ( $retry ) { |
|
192 | + if ($this->is_retryable_error($response->error)) { |
|
193 | + if ($retry) { |
|
194 | 194 | // Don't do anymore retries after this. |
195 | - if ( 5 <= $this->retry_interval ) { |
|
195 | + if (5 <= $this->retry_interval) { |
|
196 | 196 | |
197 | - return $this->process_webhook_payment( $notification, false ); |
|
197 | + return $this->process_webhook_payment($notification, false); |
|
198 | 198 | } |
199 | 199 | |
200 | - sleep( $this->retry_interval ); |
|
200 | + sleep($this->retry_interval); |
|
201 | 201 | |
202 | 202 | $this->retry_interval++; |
203 | - return $this->process_webhook_payment( $notification, true ); |
|
203 | + return $this->process_webhook_payment($notification, true); |
|
204 | 204 | } else { |
205 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
206 | - $order->add_order_note( $localized_message ); |
|
207 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
205 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
206 | + $order->add_order_note($localized_message); |
|
207 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
211 | 211 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
212 | 212 | |
213 | - if ( 'card_error' === $response->error->type ) { |
|
214 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
213 | + if ('card_error' === $response->error->type) { |
|
214 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
215 | 215 | } else { |
216 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
216 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
217 | 217 | } |
218 | 218 | |
219 | - $order->add_order_note( $localized_message ); |
|
219 | + $order->add_order_note($localized_message); |
|
220 | 220 | |
221 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
221 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | // To prevent double processing the order on WC side. |
225 | - if ( ! $this->is_original_request( $headers ) ) { |
|
225 | + if ( ! $this->is_original_request($headers)) { |
|
226 | 226 | return; |
227 | 227 | } |
228 | 228 | |
229 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
229 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
230 | 230 | |
231 | - $this->process_response( $response, $order ); |
|
231 | + $this->process_response($response, $order); |
|
232 | 232 | |
233 | - } catch ( WC_Stripe_Exception $e ) { |
|
234 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
233 | + } catch (WC_Stripe_Exception $e) { |
|
234 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
235 | 235 | |
236 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e ); |
|
236 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification, $e); |
|
237 | 237 | |
238 | - $statuses = array( 'pending', 'failed' ); |
|
238 | + $statuses = array('pending', 'failed'); |
|
239 | 239 | |
240 | - if ( $order->has_status( $statuses ) ) { |
|
241 | - $this->send_failed_order_email( $order_id ); |
|
240 | + if ($order->has_status($statuses)) { |
|
241 | + $this->send_failed_order_email($order_id); |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 | } |
@@ -251,21 +251,21 @@ discard block |
||
251 | 251 | * @since 4.0.0 |
252 | 252 | * @param object $notification |
253 | 253 | */ |
254 | - public function process_webhook_dispute( $notification ) { |
|
255 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
254 | + public function process_webhook_dispute($notification) { |
|
255 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
256 | 256 | |
257 | - if ( ! $order ) { |
|
258 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
257 | + if ( ! $order) { |
|
258 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
259 | 259 | return; |
260 | 260 | } |
261 | 261 | |
262 | 262 | /* translators: 1) The URL to the order. */ |
263 | - $order->update_status( 'on-hold', sprintf( __( 'A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ) ) ); |
|
263 | + $order->update_status('on-hold', sprintf(__('A dispute was created for this order. Response is needed. Please go to your <a href="%s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review this dispute.', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order))); |
|
264 | 264 | |
265 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
265 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
266 | 266 | |
267 | 267 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
268 | - $this->send_failed_order_email( $order_id ); |
|
268 | + $this->send_failed_order_email($order_id); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -276,41 +276,41 @@ discard block |
||
276 | 276 | * @version 4.0.0 |
277 | 277 | * @param object $notification |
278 | 278 | */ |
279 | - public function process_webhook_capture( $notification ) { |
|
280 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
279 | + public function process_webhook_capture($notification) { |
|
280 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
281 | 281 | |
282 | - if ( ! $order ) { |
|
283 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
282 | + if ( ! $order) { |
|
283 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
284 | 284 | return; |
285 | 285 | } |
286 | 286 | |
287 | 287 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
288 | 288 | |
289 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
290 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
291 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
289 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
290 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
291 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
292 | 292 | |
293 | - if ( $charge && 'no' === $captured ) { |
|
294 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
293 | + if ($charge && 'no' === $captured) { |
|
294 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
295 | 295 | |
296 | 296 | // Store other data such as fees |
297 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
297 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
298 | 298 | |
299 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
300 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
299 | + if (isset($notification->data->object->balance_transaction)) { |
|
300 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
301 | 301 | } |
302 | 302 | |
303 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
303 | + if (is_callable(array($order, 'save'))) { |
|
304 | 304 | $order->save(); |
305 | 305 | } |
306 | 306 | |
307 | 307 | /* translators: transaction id */ |
308 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
308 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
309 | 309 | |
310 | 310 | // Check and see if capture is partial. |
311 | - if ( $this->is_partial_capture( $notification ) ) { |
|
312 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
313 | - $order->add_order_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
311 | + if ($this->is_partial_capture($notification)) { |
|
312 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
313 | + $order->add_order_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
314 | 314 | $order->save(); |
315 | 315 | } |
316 | 316 | } |
@@ -325,38 +325,38 @@ discard block |
||
325 | 325 | * @version 4.0.0 |
326 | 326 | * @param object $notification |
327 | 327 | */ |
328 | - public function process_webhook_charge_succeeded( $notification ) { |
|
328 | + public function process_webhook_charge_succeeded($notification) { |
|
329 | 329 | // The following payment methods are synchronous so does not need to be handle via webhook. |
330 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
330 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
331 | 331 | return; |
332 | 332 | } |
333 | 333 | |
334 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
334 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
335 | 335 | |
336 | - if ( ! $order ) { |
|
337 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
336 | + if ( ! $order) { |
|
337 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
338 | 338 | return; |
339 | 339 | } |
340 | 340 | |
341 | 341 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
342 | 342 | |
343 | - if ( 'on-hold' !== $order->get_status() ) { |
|
343 | + if ('on-hold' !== $order->get_status()) { |
|
344 | 344 | return; |
345 | 345 | } |
346 | 346 | |
347 | 347 | // Store other data such as fees |
348 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
348 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
349 | 349 | |
350 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
351 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
350 | + if (isset($notification->data->object->balance_transaction)) { |
|
351 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
352 | 352 | } |
353 | 353 | |
354 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
354 | + if (is_callable(array($order, 'save'))) { |
|
355 | 355 | $order->save(); |
356 | 356 | } |
357 | 357 | |
358 | 358 | /* translators: transaction id */ |
359 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
359 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
@@ -367,23 +367,23 @@ discard block |
||
367 | 367 | * @version 4.0.0 |
368 | 368 | * @param object $notification |
369 | 369 | */ |
370 | - public function process_webhook_charge_failed( $notification ) { |
|
371 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
370 | + public function process_webhook_charge_failed($notification) { |
|
371 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
372 | 372 | |
373 | - if ( ! $order ) { |
|
374 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
373 | + if ( ! $order) { |
|
374 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
375 | 375 | return; |
376 | 376 | } |
377 | 377 | |
378 | 378 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
379 | 379 | |
380 | - if ( 'on-hold' !== $order->get_status() ) { |
|
380 | + if ('on-hold' !== $order->get_status()) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
384 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
385 | 385 | |
386 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
386 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -394,23 +394,23 @@ discard block |
||
394 | 394 | * @version 4.0.0 |
395 | 395 | * @param object $notification |
396 | 396 | */ |
397 | - public function process_webhook_source_canceled( $notification ) { |
|
398 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
397 | + public function process_webhook_source_canceled($notification) { |
|
398 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
399 | 399 | |
400 | - if ( ! $order ) { |
|
401 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
400 | + if ( ! $order) { |
|
401 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
402 | 402 | return; |
403 | 403 | } |
404 | 404 | |
405 | 405 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
406 | 406 | |
407 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
407 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
408 | 408 | return; |
409 | 409 | } |
410 | 410 | |
411 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
411 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
412 | 412 | |
413 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
413 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,57 +420,57 @@ discard block |
||
420 | 420 | * @version 4.0.0 |
421 | 421 | * @param object $notification |
422 | 422 | */ |
423 | - public function process_webhook_refund( $notification ) { |
|
424 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
423 | + public function process_webhook_refund($notification) { |
|
424 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
425 | 425 | |
426 | - if ( ! $order ) { |
|
427 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
426 | + if ( ! $order) { |
|
427 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
428 | 428 | return; |
429 | 429 | } |
430 | 430 | |
431 | 431 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
432 | 432 | |
433 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
434 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
435 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
436 | - $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true ); |
|
433 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
434 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
435 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
436 | + $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true); |
|
437 | 437 | |
438 | 438 | // If the refund ID matches, don't continue to prevent double refunding. |
439 | - if ( $notification->data->object->refunds->data[0]->id === $refund_id ) { |
|
439 | + if ($notification->data->object->refunds->data[0]->id === $refund_id) { |
|
440 | 440 | return; |
441 | 441 | } |
442 | 442 | |
443 | 443 | // Only refund captured charge. |
444 | - if ( $charge ) { |
|
445 | - $reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
444 | + if ($charge) { |
|
445 | + $reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
446 | 446 | |
447 | 447 | // Create the refund. |
448 | - $refund = wc_create_refund( array( |
|
448 | + $refund = wc_create_refund(array( |
|
449 | 449 | 'order_id' => $order_id, |
450 | - 'amount' => $this->get_refund_amount( $notification ), |
|
450 | + 'amount' => $this->get_refund_amount($notification), |
|
451 | 451 | 'reason' => $reason, |
452 | - ) ); |
|
452 | + )); |
|
453 | 453 | |
454 | - if ( is_wp_error( $refund ) ) { |
|
455 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
454 | + if (is_wp_error($refund)) { |
|
455 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
456 | 456 | } |
457 | 457 | |
458 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $notification->data->object->refunds->data[0]->id ) : $order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id ); |
|
458 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $notification->data->object->refunds->data[0]->id) : $order->update_meta_data('_stripe_refund_id', $notification->data->object->refunds->data[0]->id); |
|
459 | 459 | |
460 | - $amount = wc_price( $notification->data->object->refunds->data[0]->amount / 100 ); |
|
460 | + $amount = wc_price($notification->data->object->refunds->data[0]->amount / 100); |
|
461 | 461 | |
462 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
463 | - $amount = wc_price( $notification->data->object->refunds->data[0]->amount ); |
|
462 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
463 | + $amount = wc_price($notification->data->object->refunds->data[0]->amount); |
|
464 | 464 | } |
465 | 465 | |
466 | - if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) { |
|
467 | - $this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction ); |
|
466 | + if (isset($notification->data->object->refunds->data[0]->balance_transaction)) { |
|
467 | + $this->update_fees($order, $notification->data->object->refunds->data[0]->balance_transaction); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
471 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe' ), $amount, $notification->data->object->refunds->data[0]->id, $reason ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
471 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe'), $amount, $notification->data->object->refunds->data[0]->id, $reason) : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
472 | 472 | |
473 | - $order->add_order_note( $refund_message ); |
|
473 | + $order->add_order_note($refund_message); |
|
474 | 474 | } |
475 | 475 | } |
476 | 476 | } |
@@ -481,21 +481,21 @@ discard block |
||
481 | 481 | * @since 4.0.6 |
482 | 482 | * @param object $notification |
483 | 483 | */ |
484 | - public function process_review_opened( $notification ) { |
|
485 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
484 | + public function process_review_opened($notification) { |
|
485 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
486 | 486 | |
487 | - if ( ! $order ) { |
|
488 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
487 | + if ( ! $order) { |
|
488 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
489 | 489 | return; |
490 | 490 | } |
491 | 491 | |
492 | 492 | /* translators: 1) The URL to the order. 2) The reason type. */ |
493 | - $message = sprintf( __( 'A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe' ), $this->get_transaction_url( $order ), $notification->data->object->reason ); |
|
493 | + $message = sprintf(__('A review has been opened for this order. Action is needed. Please go to your <a href="%1$s" title="Stripe Dashboard" target="_blank">Stripe Dashboard</a> to review the issue. Reason: (%2$s)', 'woocommerce-gateway-stripe'), $this->get_transaction_url($order), $notification->data->object->reason); |
|
494 | 494 | |
495 | - if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) { |
|
496 | - $order->update_status( 'on-hold', $message ); |
|
495 | + if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) { |
|
496 | + $order->update_status('on-hold', $message); |
|
497 | 497 | } else { |
498 | - $order->add_order_note( $message ); |
|
498 | + $order->add_order_note($message); |
|
499 | 499 | } |
500 | 500 | } |
501 | 501 | |
@@ -505,25 +505,25 @@ discard block |
||
505 | 505 | * @since 4.0.6 |
506 | 506 | * @param object $notification |
507 | 507 | */ |
508 | - public function process_review_closed( $notification ) { |
|
509 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
508 | + public function process_review_closed($notification) { |
|
509 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
510 | 510 | |
511 | - if ( ! $order ) { |
|
512 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
511 | + if ( ! $order) { |
|
512 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
513 | 513 | return; |
514 | 514 | } |
515 | 515 | |
516 | 516 | /* translators: 1) The reason type. */ |
517 | - $message = sprintf( __( 'The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe' ), $notification->data->object->reason ); |
|
517 | + $message = sprintf(__('The opened review for this order is now closed. Reason: (%s)', 'woocommerce-gateway-stripe'), $notification->data->object->reason); |
|
518 | 518 | |
519 | - if ( 'on-hold' === $order->get_status() ) { |
|
520 | - if ( apply_filters( 'wc_stripe_webhook_review_change_order_status', true, $order, $notification ) ) { |
|
521 | - $order->update_status( 'processing', $message ); |
|
519 | + if ('on-hold' === $order->get_status()) { |
|
520 | + if (apply_filters('wc_stripe_webhook_review_change_order_status', true, $order, $notification)) { |
|
521 | + $order->update_status('processing', $message); |
|
522 | 522 | } else { |
523 | - $order->add_order_note( $message ); |
|
523 | + $order->add_order_note($message); |
|
524 | 524 | } |
525 | 525 | } else { |
526 | - $order->add_order_note( $message ); |
|
526 | + $order->add_order_note($message); |
|
527 | 527 | } |
528 | 528 | } |
529 | 529 | |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | * @version 4.0.0 |
535 | 535 | * @param object $notification |
536 | 536 | */ |
537 | - public function is_partial_capture( $notification ) { |
|
537 | + public function is_partial_capture($notification) { |
|
538 | 538 | return 0 < $notification->data->object->amount_refunded; |
539 | 539 | } |
540 | 540 | |
@@ -545,11 +545,11 @@ discard block |
||
545 | 545 | * @version 4.0.0 |
546 | 546 | * @param object $notification |
547 | 547 | */ |
548 | - public function get_refund_amount( $notification ) { |
|
549 | - if ( $this->is_partial_capture( $notification ) ) { |
|
548 | + public function get_refund_amount($notification) { |
|
549 | + if ($this->is_partial_capture($notification)) { |
|
550 | 550 | $amount = $notification->data->object->refunds->data[0]->amount / 100; |
551 | 551 | |
552 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
552 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
553 | 553 | $amount = $notification->data->object->refunds->data[0]->amount; |
554 | 554 | } |
555 | 555 | |
@@ -566,12 +566,12 @@ discard block |
||
566 | 566 | * @version 4.0.0 |
567 | 567 | * @param object $notification |
568 | 568 | */ |
569 | - public function get_partial_amount_to_charge( $notification ) { |
|
570 | - if ( $this->is_partial_capture( $notification ) ) { |
|
571 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
569 | + public function get_partial_amount_to_charge($notification) { |
|
570 | + if ($this->is_partial_capture($notification)) { |
|
571 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
572 | 572 | |
573 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
574 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
573 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
574 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | return $amount; |
@@ -587,44 +587,44 @@ discard block |
||
587 | 587 | * @version 4.0.0 |
588 | 588 | * @param string $request_body |
589 | 589 | */ |
590 | - public function process_webhook( $request_body ) { |
|
591 | - $notification = json_decode( $request_body ); |
|
590 | + public function process_webhook($request_body) { |
|
591 | + $notification = json_decode($request_body); |
|
592 | 592 | |
593 | - switch ( $notification->type ) { |
|
593 | + switch ($notification->type) { |
|
594 | 594 | case 'source.chargeable': |
595 | - $this->process_webhook_payment( $notification ); |
|
595 | + $this->process_webhook_payment($notification); |
|
596 | 596 | break; |
597 | 597 | |
598 | 598 | case 'source.canceled': |
599 | - $this->process_webhook_source_canceled( $notification ); |
|
599 | + $this->process_webhook_source_canceled($notification); |
|
600 | 600 | break; |
601 | 601 | |
602 | 602 | case 'charge.succeeded': |
603 | - $this->process_webhook_charge_succeeded( $notification ); |
|
603 | + $this->process_webhook_charge_succeeded($notification); |
|
604 | 604 | break; |
605 | 605 | |
606 | 606 | case 'charge.failed': |
607 | - $this->process_webhook_charge_failed( $notification ); |
|
607 | + $this->process_webhook_charge_failed($notification); |
|
608 | 608 | break; |
609 | 609 | |
610 | 610 | case 'charge.captured': |
611 | - $this->process_webhook_capture( $notification ); |
|
611 | + $this->process_webhook_capture($notification); |
|
612 | 612 | break; |
613 | 613 | |
614 | 614 | case 'charge.dispute.created': |
615 | - $this->process_webhook_dispute( $notification ); |
|
615 | + $this->process_webhook_dispute($notification); |
|
616 | 616 | break; |
617 | 617 | |
618 | 618 | case 'charge.refunded': |
619 | - $this->process_webhook_refund( $notification ); |
|
619 | + $this->process_webhook_refund($notification); |
|
620 | 620 | break; |
621 | 621 | |
622 | 622 | case 'review.opened': |
623 | - $this->process_review_opened( $notification ); |
|
623 | + $this->process_review_opened($notification); |
|
624 | 624 | break; |
625 | 625 | |
626 | 626 | case 'review.closed': |
627 | - $this->process_review_closed( $notification ); |
|
627 | + $this->process_review_closed($notification); |
|
628 | 628 | break; |
629 | 629 | |
630 | 630 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | public function __construct() { |
121 | 121 | $this->retry_interval = 1; |
122 | 122 | $this->id = 'stripe'; |
123 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
123 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
124 | 124 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
125 | - $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 | + $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'); |
|
126 | 126 | $this->has_fields = true; |
127 | 127 | $this->supports = array( |
128 | 128 | 'products', |
@@ -149,43 +149,43 @@ discard block |
||
149 | 149 | $this->init_settings(); |
150 | 150 | |
151 | 151 | // Get setting values. |
152 | - $this->title = $this->get_option( 'title' ); |
|
153 | - $this->description = $this->get_option( 'description' ); |
|
154 | - $this->enabled = $this->get_option( 'enabled' ); |
|
155 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
156 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
157 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
158 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
159 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
160 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
161 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
162 | - $this->stripe_checkout_description = $this->get_option( 'stripe_checkout_description' ); |
|
163 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
164 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
165 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
166 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
167 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
168 | - |
|
169 | - if ( $this->stripe_checkout ) { |
|
170 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
171 | - } |
|
172 | - |
|
173 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
152 | + $this->title = $this->get_option('title'); |
|
153 | + $this->description = $this->get_option('description'); |
|
154 | + $this->enabled = $this->get_option('enabled'); |
|
155 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
156 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
157 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
158 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
159 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
160 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
161 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
162 | + $this->stripe_checkout_description = $this->get_option('stripe_checkout_description'); |
|
163 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
164 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
165 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
166 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
167 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
168 | + |
|
169 | + if ($this->stripe_checkout) { |
|
170 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
171 | + } |
|
172 | + |
|
173 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
174 | 174 | |
175 | 175 | // Hooks. |
176 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
177 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
178 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
179 | - add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_fee' ), 10, 1 ); |
|
180 | - add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'display_order_payout' ), 20, 1 ); |
|
181 | - add_action( 'woocommerce_customer_save_address', array( $this, 'show_update_card_notice' ), 10, 2 ); |
|
182 | - add_action( 'woocommerce_receipt_stripe', array( $this, 'stripe_checkout_receipt_page' ) ); |
|
183 | - add_action( 'woocommerce_api_' . strtolower( get_class( $this ) ), array( $this, 'stripe_checkout_return_handler' ) ); |
|
184 | - |
|
185 | - if ( WC_Stripe_Helper::is_pre_orders_exists() ) { |
|
176 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
177 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
178 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
179 | + add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_fee'), 10, 1); |
|
180 | + add_action('woocommerce_admin_order_totals_after_total', array($this, 'display_order_payout'), 20, 1); |
|
181 | + add_action('woocommerce_customer_save_address', array($this, 'show_update_card_notice'), 10, 2); |
|
182 | + add_action('woocommerce_receipt_stripe', array($this, 'stripe_checkout_receipt_page')); |
|
183 | + add_action('woocommerce_api_' . strtolower(get_class($this)), array($this, 'stripe_checkout_return_handler')); |
|
184 | + |
|
185 | + if (WC_Stripe_Helper::is_pre_orders_exists()) { |
|
186 | 186 | $this->pre_orders = new WC_Stripe_Pre_Orders_Compat(); |
187 | 187 | |
188 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) ); |
|
188 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment')); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @return bool |
197 | 197 | */ |
198 | 198 | public function are_keys_set() { |
199 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
199 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
200 | 200 | return false; |
201 | 201 | } |
202 | 202 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @since 4.0.2 |
210 | 210 | */ |
211 | 211 | public function is_available() { |
212 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
212 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
213 | 213 | return false; |
214 | 214 | } |
215 | 215 | |
@@ -223,13 +223,13 @@ discard block |
||
223 | 223 | * @param int $user_id |
224 | 224 | * @param array $load_address |
225 | 225 | */ |
226 | - public function show_update_card_notice( $user_id, $load_address ) { |
|
227 | - if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods( $user_id ) || 'billing' !== $load_address ) { |
|
226 | + public function show_update_card_notice($user_id, $load_address) { |
|
227 | + if ( ! $this->saved_cards || ! WC_Stripe_Payment_Tokens::customer_has_saved_methods($user_id) || 'billing' !== $load_address) { |
|
228 | 228 | return; |
229 | 229 | } |
230 | 230 | |
231 | 231 | /* translators: 1) Opening anchor tag 2) closing anchor tag */ |
232 | - wc_add_notice( sprintf( __( 'If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe' ), '<a href="' . esc_url( wc_get_endpoint_url( 'payment-methods' ) ) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>' ), 'notice' ); |
|
232 | + wc_add_notice(sprintf(__('If your billing address has been changed for saved payment methods, be sure to remove any %1$ssaved payment methods%2$s on file and re-add them.', 'woocommerce-gateway-stripe'), '<a href="' . esc_url(wc_get_endpoint_url('payment-methods')) . '" class="wc-stripe-update-card-notice" style="text-decoration:underline;">', '</a>'), 'notice'); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -248,24 +248,24 @@ discard block |
||
248 | 248 | $icons_str .= $icons['amex']; |
249 | 249 | $icons_str .= $icons['mastercard']; |
250 | 250 | |
251 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
251 | + if ('USD' === get_woocommerce_currency()) { |
|
252 | 252 | $icons_str .= $icons['discover']; |
253 | 253 | $icons_str .= $icons['jcb']; |
254 | 254 | $icons_str .= $icons['diners']; |
255 | 255 | } |
256 | 256 | |
257 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
257 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
258 | 258 | $icons_str .= $icons['bitcoin']; |
259 | 259 | } |
260 | 260 | |
261 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
261 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
265 | 265 | * Initialise Gateway Settings Form Fields |
266 | 266 | */ |
267 | 267 | public function init_form_fields() { |
268 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
268 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -273,27 +273,27 @@ discard block |
||
273 | 273 | */ |
274 | 274 | public function payment_fields() { |
275 | 275 | $user = wp_get_current_user(); |
276 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
276 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
277 | 277 | $total = WC()->cart->total; |
278 | 278 | $user_email = ''; |
279 | 279 | |
280 | 280 | // If paying from order, we need to get total from order not cart. |
281 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
282 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
281 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
282 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
283 | 283 | $total = $order->get_total(); |
284 | 284 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
285 | 285 | } else { |
286 | - if ( $user->ID ) { |
|
287 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
286 | + if ($user->ID) { |
|
287 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
288 | 288 | $user_email = $user_email ? $user_email : $user->user_email; |
289 | 289 | } |
290 | 290 | } |
291 | 291 | |
292 | - if ( is_add_payment_method_page() ) { |
|
293 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
292 | + if (is_add_payment_method_page()) { |
|
293 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
294 | 294 | $total = ''; |
295 | - } elseif ( function_exists( 'wcs_order_contains_subscription' ) && isset( $_GET['change_payment_method'] ) ) { |
|
296 | - $pay_button_text = __( 'Change Payment Method', 'woocommerce-gateway-stripe' ); |
|
295 | + } elseif (function_exists('wcs_order_contains_subscription') && isset($_GET['change_payment_method'])) { |
|
296 | + $pay_button_text = __('Change Payment Method', 'woocommerce-gateway-stripe'); |
|
297 | 297 | $total = ''; |
298 | 298 | } else { |
299 | 299 | $pay_button_text = ''; |
@@ -303,45 +303,45 @@ discard block |
||
303 | 303 | |
304 | 304 | echo '<div |
305 | 305 | id="stripe-payment-data" |
306 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
307 | - data-description="' . esc_attr( strip_tags( $this->stripe_checkout_description ) ) . '" |
|
308 | - data-email="' . esc_attr( $user_email ) . '" |
|
309 | - data-verify-zip="' . esc_attr( apply_filters( 'wc_stripe_checkout_verify_zip', false ) ? 'true' : 'false' ) . '" |
|
310 | - data-billing-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'true' : 'false' ) . '" |
|
311 | - data-shipping-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_shipping_address', false ) ? 'true' : 'false' ) . '" |
|
312 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
313 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
314 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
315 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
316 | - data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '" |
|
317 | - data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '" |
|
318 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
319 | - data-allow-remember-me="' . esc_attr( apply_filters( 'wc_stripe_allow_remember_me', true ) ? 'true' : 'false' ) . '">'; |
|
320 | - |
|
321 | - if ( $this->description ) { |
|
322 | - if ( $this->testmode ) { |
|
306 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
307 | + data-description="' . esc_attr(strip_tags($this->stripe_checkout_description)) . '" |
|
308 | + data-email="' . esc_attr($user_email) . '" |
|
309 | + data-verify-zip="' . esc_attr(apply_filters('wc_stripe_checkout_verify_zip', false) ? 'true' : 'false') . '" |
|
310 | + data-billing-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'true' : 'false') . '" |
|
311 | + data-shipping-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_shipping_address', false) ? 'true' : 'false') . '" |
|
312 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
313 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
314 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
315 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
316 | + data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '" |
|
317 | + data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '" |
|
318 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
319 | + data-allow-remember-me="' . esc_attr(apply_filters('wc_stripe_allow_remember_me', true) ? 'true' : 'false') . '">'; |
|
320 | + |
|
321 | + if ($this->description) { |
|
322 | + if ($this->testmode) { |
|
323 | 323 | /* translators: link to Stripe testing page */ |
324 | - $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 <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
325 | - $this->description = trim( $this->description ); |
|
324 | + $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 <a href="%s" target="_blank">Testing Stripe documentation</a> for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
325 | + $this->description = trim($this->description); |
|
326 | 326 | } |
327 | 327 | |
328 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id ); |
|
328 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id); |
|
329 | 329 | } |
330 | 330 | |
331 | - if ( $display_tokenization ) { |
|
331 | + if ($display_tokenization) { |
|
332 | 332 | $this->tokenization_script(); |
333 | 333 | $this->saved_payment_methods(); |
334 | 334 | } |
335 | 335 | |
336 | - if ( ! $this->stripe_checkout ) { |
|
336 | + if ( ! $this->stripe_checkout) { |
|
337 | 337 | $this->elements_form(); |
338 | 338 | } |
339 | 339 | |
340 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
340 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
341 | 341 | |
342 | - if ( ! $this->stripe_checkout ) { |
|
342 | + if ( ! $this->stripe_checkout) { |
|
343 | 343 | $this->save_payment_method_checkbox(); |
344 | - } elseif ( $this->stripe_checkout && isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
344 | + } elseif ($this->stripe_checkout && isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
345 | 345 | $this->save_payment_method_checkbox(); |
346 | 346 | } |
347 | 347 | } |
@@ -359,12 +359,12 @@ discard block |
||
359 | 359 | */ |
360 | 360 | public function elements_form() { |
361 | 361 | ?> |
362 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
363 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
362 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
363 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
364 | 364 | |
365 | - <?php if ( $this->inline_cc_form ) { ?> |
|
365 | + <?php if ($this->inline_cc_form) { ?> |
|
366 | 366 | <label for="card-element"> |
367 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
367 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
368 | 368 | </label> |
369 | 369 | |
370 | 370 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | </div> |
373 | 373 | <?php } else { ?> |
374 | 374 | <div class="form-row form-row-wide"> |
375 | - <label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
375 | + <label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
376 | 376 | |
377 | 377 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
378 | 378 | <!-- a Stripe Element will be inserted here. --> |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | </div> |
381 | 381 | |
382 | 382 | <div class="form-row form-row-first"> |
383 | - <label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
383 | + <label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
384 | 384 | |
385 | 385 | <div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
386 | 386 | <!-- a Stripe Element will be inserted here. --> |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | </div> |
389 | 389 | |
390 | 390 | <div class="form-row form-row-last"> |
391 | - <label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
391 | + <label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
392 | 392 | <div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
393 | 393 | <!-- a Stripe Element will be inserted here. --> |
394 | 394 | </div> |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | |
399 | 399 | <!-- Used to display form errors --> |
400 | 400 | <div class="stripe-source-errors" role="alert"></div> |
401 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
401 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
402 | 402 | <div class="clear"></div> |
403 | 403 | </fieldset> |
404 | 404 | <?php |
@@ -411,13 +411,13 @@ discard block |
||
411 | 411 | * @version 3.1.0 |
412 | 412 | */ |
413 | 413 | public function admin_scripts() { |
414 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
414 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
415 | 415 | return; |
416 | 416 | } |
417 | 417 | |
418 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
418 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
419 | 419 | |
420 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
420 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -429,44 +429,44 @@ discard block |
||
429 | 429 | * @version 4.0.0 |
430 | 430 | */ |
431 | 431 | public function payment_scripts() { |
432 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
432 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
433 | 433 | return; |
434 | 434 | } |
435 | 435 | |
436 | 436 | // If Stripe is not enabled bail. |
437 | - if ( 'no' === $this->enabled ) { |
|
437 | + if ('no' === $this->enabled) { |
|
438 | 438 | return; |
439 | 439 | } |
440 | 440 | |
441 | 441 | // If keys are not set bail. |
442 | - if ( ! $this->are_keys_set() ) { |
|
443 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
442 | + if ( ! $this->are_keys_set()) { |
|
443 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
444 | 444 | return; |
445 | 445 | } |
446 | 446 | |
447 | 447 | // If no SSL bail. |
448 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
449 | - WC_Stripe_Logger::log( 'Stripe live mode requires SSL.' ); |
|
448 | + if ( ! $this->testmode && ! is_ssl()) { |
|
449 | + WC_Stripe_Logger::log('Stripe live mode requires SSL.'); |
|
450 | 450 | } |
451 | 451 | |
452 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
452 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
453 | 453 | |
454 | - wp_register_style( 'stripe_styles', plugins_url( 'assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
455 | - wp_enqueue_style( 'stripe_styles' ); |
|
456 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
457 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
458 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
454 | + wp_register_style('stripe_styles', plugins_url('assets/css/stripe-styles.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
455 | + wp_enqueue_style('stripe_styles'); |
|
456 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
457 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
458 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
459 | 459 | |
460 | 460 | $stripe_params = array( |
461 | 461 | 'key' => $this->publishable_key, |
462 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
463 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
462 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
463 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
464 | 464 | ); |
465 | 465 | |
466 | 466 | // If we're on the pay page we need to pass stripe.js the address of the order. |
467 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
468 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
469 | - $order = wc_get_order( $order_id ); |
|
467 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
468 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
469 | + $order = wc_get_order($order_id); |
|
470 | 470 | |
471 | 471 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
472 | 472 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -478,38 +478,38 @@ discard block |
||
478 | 478 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
479 | 479 | } |
480 | 480 | |
481 | - $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' ); |
|
482 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
483 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
484 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
485 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
481 | + $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'); |
|
482 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
483 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
484 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
485 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
486 | 486 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
487 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
488 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ) ? 'yes' : 'no'; |
|
487 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
488 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])) ? 'yes' : 'no'; |
|
489 | 489 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
490 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
491 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
490 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
491 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
492 | 492 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
493 | - $stripe_params['elements_options'] = apply_filters( 'wc_stripe_elements_options', array() ); |
|
493 | + $stripe_params['elements_options'] = apply_filters('wc_stripe_elements_options', array()); |
|
494 | 494 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
495 | - $stripe_params['is_change_payment_page'] = isset( $_GET['change_payment_method'] ) ? 'yes' : 'no'; |
|
496 | - $stripe_params['is_add_payment_page'] = is_wc_endpoint_url( 'add-payment-method' ) ? 'yes' : 'no'; |
|
497 | - $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url( 'order-pay' ) ? 'yes' : 'no'; |
|
498 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
499 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
495 | + $stripe_params['is_change_payment_page'] = isset($_GET['change_payment_method']) ? 'yes' : 'no'; |
|
496 | + $stripe_params['is_add_payment_page'] = is_wc_endpoint_url('add-payment-method') ? 'yes' : 'no'; |
|
497 | + $stripe_params['is_pay_for_order_page'] = is_wc_endpoint_url('order-pay') ? 'yes' : 'no'; |
|
498 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
499 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
500 | 500 | |
501 | 501 | // merge localized messages to be use in JS |
502 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
502 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
503 | 503 | |
504 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
505 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
504 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
505 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
506 | 506 | |
507 | - if ( $this->stripe_checkout ) { |
|
508 | - wp_enqueue_script( 'stripe_checkout' ); |
|
507 | + if ($this->stripe_checkout) { |
|
508 | + wp_enqueue_script('stripe_checkout'); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | $this->tokenization_script(); |
512 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
512 | + wp_enqueue_script('woocommerce_stripe'); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -517,71 +517,71 @@ discard block |
||
517 | 517 | * |
518 | 518 | * @since 4.1.0 |
519 | 519 | */ |
520 | - public function stripe_checkout_receipt_page( $order_id ) { |
|
521 | - if ( ! $this->stripe_checkout ) { |
|
520 | + public function stripe_checkout_receipt_page($order_id) { |
|
521 | + if ( ! $this->stripe_checkout) { |
|
522 | 522 | return; |
523 | 523 | } |
524 | 524 | |
525 | 525 | $user = wp_get_current_user(); |
526 | 526 | $total = WC()->cart->total; |
527 | 527 | $user_email = ''; |
528 | - $display_tokenization = $this->supports( 'tokenization' ) && $this->saved_cards; |
|
528 | + $display_tokenization = $this->supports('tokenization') && $this->saved_cards; |
|
529 | 529 | |
530 | 530 | // If paying from order, we need to get total from order not cart. |
531 | - if ( ! empty( $_GET['key'] ) ) { |
|
532 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
531 | + if ( ! empty($_GET['key'])) { |
|
532 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
533 | 533 | $total = $order->get_total(); |
534 | 534 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
535 | 535 | } else { |
536 | - if ( $user->ID ) { |
|
537 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
536 | + if ($user->ID) { |
|
537 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
538 | 538 | $user_email = $user_email ? $user_email : $user->user_email; |
539 | 539 | } |
540 | 540 | } |
541 | 541 | |
542 | 542 | ob_start(); |
543 | 543 | |
544 | - do_action( 'wc_stripe_checkout_receipt_page_before_form' ); |
|
544 | + do_action('wc_stripe_checkout_receipt_page_before_form'); |
|
545 | 545 | |
546 | - echo '<form method="post" class="woocommerce-checkout" action="' . WC()->api_request_url( get_class( $this ) ) . '">'; |
|
546 | + echo '<form method="post" class="woocommerce-checkout" action="' . WC()->api_request_url(get_class($this)) . '">'; |
|
547 | 547 | echo '<div |
548 | 548 | id="stripe-payment-data" |
549 | - data-panel-label="' . esc_attr( apply_filters( 'wc_stripe_checkout_label', '' ) ) . '" |
|
550 | - data-description="' . esc_attr( strip_tags( $this->stripe_checkout_description ) ) . '" |
|
551 | - data-email="' . esc_attr( $user_email ) . '" |
|
552 | - data-verify-zip="' . esc_attr( apply_filters( 'wc_stripe_checkout_verify_zip', false ) ? 'true' : 'false' ) . '" |
|
553 | - data-billing-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'true' : 'false' ) . '" |
|
554 | - data-shipping-address="' . esc_attr( apply_filters( 'wc_stripe_checkout_require_shipping_address', false ) ? 'true' : 'false' ) . '" |
|
555 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
556 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
557 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
558 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
559 | - data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '" |
|
560 | - data-locale="' . esc_attr( apply_filters( 'wc_stripe_checkout_locale', $this->get_locale() ) ) . '" |
|
561 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
562 | - data-allow-remember-me="' . esc_attr( apply_filters( 'wc_stripe_allow_remember_me', true ) ? 'true' : 'false' ) . '">'; |
|
563 | - echo '<input type="hidden" name="order_id" value="' . esc_attr( $order_id ) . '" />'; |
|
549 | + data-panel-label="' . esc_attr(apply_filters('wc_stripe_checkout_label', '')) . '" |
|
550 | + data-description="' . esc_attr(strip_tags($this->stripe_checkout_description)) . '" |
|
551 | + data-email="' . esc_attr($user_email) . '" |
|
552 | + data-verify-zip="' . esc_attr(apply_filters('wc_stripe_checkout_verify_zip', false) ? 'true' : 'false') . '" |
|
553 | + data-billing-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'true' : 'false') . '" |
|
554 | + data-shipping-address="' . esc_attr(apply_filters('wc_stripe_checkout_require_shipping_address', false) ? 'true' : 'false') . '" |
|
555 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
556 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
557 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
558 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
559 | + data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '" |
|
560 | + data-locale="' . esc_attr(apply_filters('wc_stripe_checkout_locale', $this->get_locale())) . '" |
|
561 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
562 | + data-allow-remember-me="' . esc_attr(apply_filters('wc_stripe_allow_remember_me', true) ? 'true' : 'false') . '">'; |
|
563 | + echo '<input type="hidden" name="order_id" value="' . esc_attr($order_id) . '" />'; |
|
564 | 564 | echo '<input type="hidden" name="stripe_checkout_order" value="yes" />'; |
565 | 565 | |
566 | 566 | if ( |
567 | - apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && |
|
568 | - ( ! function_exists( 'wcs_order_contains_subscription' ) || ( function_exists( 'wcs_order_contains_subscription' ) && ! WC_Subscriptions_Cart::cart_contains_subscription() ) ) && |
|
569 | - ( ! WC_Stripe_Helper::is_pre_orders_exists() || ( WC_Stripe_Helper::is_pre_orders_exists() && ! $this->pre_orders->is_pre_order( $order_id ) ) ) |
|
567 | + apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && |
|
568 | + ( ! function_exists('wcs_order_contains_subscription') || (function_exists('wcs_order_contains_subscription') && ! WC_Subscriptions_Cart::cart_contains_subscription())) && |
|
569 | + ( ! WC_Stripe_Helper::is_pre_orders_exists() || (WC_Stripe_Helper::is_pre_orders_exists() && ! $this->pre_orders->is_pre_order($order_id))) |
|
570 | 570 | ) { |
571 | 571 | $this->save_payment_method_checkbox(); |
572 | 572 | } |
573 | 573 | |
574 | - wp_nonce_field( 'stripe-checkout-process', 'stripe_checkout_process_nonce' ); |
|
574 | + wp_nonce_field('stripe-checkout-process', 'stripe_checkout_process_nonce'); |
|
575 | 575 | |
576 | - do_action( 'wc_stripe_checkout_receipt_page_before_form_submit' ); |
|
576 | + do_action('wc_stripe_checkout_receipt_page_before_form_submit'); |
|
577 | 577 | |
578 | - echo '<button type="submit" class="wc-stripe-checkout-button">' . __( 'Place Order', 'woocommerce-gateway-stripe' ) . '</button>'; |
|
578 | + echo '<button type="submit" class="wc-stripe-checkout-button">' . __('Place Order', 'woocommerce-gateway-stripe') . '</button>'; |
|
579 | 579 | |
580 | - do_action( 'wc_stripe_checkout_receipt_page_after_form_submit' ); |
|
580 | + do_action('wc_stripe_checkout_receipt_page_after_form_submit'); |
|
581 | 581 | |
582 | 582 | echo '</form>'; |
583 | 583 | |
584 | - do_action( 'wc_stripe_checkout_receipt_page_after_form' ); |
|
584 | + do_action('wc_stripe_checkout_receipt_page_after_form'); |
|
585 | 585 | |
586 | 586 | echo '</div>'; |
587 | 587 | |
@@ -594,32 +594,32 @@ discard block |
||
594 | 594 | * @since 4.1.0 |
595 | 595 | */ |
596 | 596 | public function stripe_checkout_return_handler() { |
597 | - if ( ! $this->stripe_checkout ) { |
|
597 | + if ( ! $this->stripe_checkout) { |
|
598 | 598 | return; |
599 | 599 | } |
600 | 600 | |
601 | - if ( ! wp_verify_nonce( $_POST['stripe_checkout_process_nonce'], 'stripe-checkout-process' ) ) { |
|
601 | + if ( ! wp_verify_nonce($_POST['stripe_checkout_process_nonce'], 'stripe-checkout-process')) { |
|
602 | 602 | return; |
603 | 603 | } |
604 | 604 | |
605 | - $order_id = wc_clean( $_POST['order_id'] ); |
|
606 | - $order = wc_get_order( $order_id ); |
|
605 | + $order_id = wc_clean($_POST['order_id']); |
|
606 | + $order = wc_get_order($order_id); |
|
607 | 607 | |
608 | - do_action( 'wc_stripe_checkout_return_handler', $order ); |
|
608 | + do_action('wc_stripe_checkout_return_handler', $order); |
|
609 | 609 | |
610 | - if ( WC_Stripe_Helper::is_pre_orders_exists() && $this->pre_orders->is_pre_order( $order_id ) && WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
611 | - $result = $this->pre_orders->process_pre_order( $order_id ); |
|
610 | + if (WC_Stripe_Helper::is_pre_orders_exists() && $this->pre_orders->is_pre_order($order_id) && WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
611 | + $result = $this->pre_orders->process_pre_order($order_id); |
|
612 | 612 | } else { |
613 | - $result = $this->process_payment( $order_id ); |
|
613 | + $result = $this->process_payment($order_id); |
|
614 | 614 | } |
615 | 615 | |
616 | - if ( 'success' === $result['result'] ) { |
|
617 | - wp_redirect( $result['redirect'] ); |
|
616 | + if ('success' === $result['result']) { |
|
617 | + wp_redirect($result['redirect']); |
|
618 | 618 | exit; |
619 | 619 | } |
620 | 620 | |
621 | 621 | // Redirects back to pay order page. |
622 | - wp_safe_redirect( $order->get_checkout_payment_url( true ) ); |
|
622 | + wp_safe_redirect($order->get_checkout_payment_url(true)); |
|
623 | 623 | exit; |
624 | 624 | } |
625 | 625 | |
@@ -632,9 +632,9 @@ discard block |
||
632 | 632 | public function maybe_redirect_stripe_checkout() { |
633 | 633 | return ( |
634 | 634 | $this->stripe_checkout && |
635 | - ! isset( $_POST['stripe_checkout_order'] ) && |
|
635 | + ! isset($_POST['stripe_checkout_order']) && |
|
636 | 636 | ! $this->is_using_saved_payment_method() && |
637 | - ! is_wc_endpoint_url( 'order-pay' ) |
|
637 | + ! is_wc_endpoint_url('order-pay') |
|
638 | 638 | ); |
639 | 639 | } |
640 | 640 | |
@@ -652,54 +652,54 @@ discard block |
||
652 | 652 | * |
653 | 653 | * @return array|void |
654 | 654 | */ |
655 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
655 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
656 | 656 | try { |
657 | - $order = wc_get_order( $order_id ); |
|
657 | + $order = wc_get_order($order_id); |
|
658 | 658 | |
659 | - if ( $this->maybe_redirect_stripe_checkout() ) { |
|
660 | - WC_Stripe_Logger::log( sprintf( 'Redirecting to Stripe Checkout page for order %s', $order_id ) ); |
|
659 | + if ($this->maybe_redirect_stripe_checkout()) { |
|
660 | + WC_Stripe_Logger::log(sprintf('Redirecting to Stripe Checkout page for order %s', $order_id)); |
|
661 | 661 | |
662 | 662 | return array( |
663 | 663 | 'result' => 'success', |
664 | - 'redirect' => $order->get_checkout_payment_url( true ), |
|
664 | + 'redirect' => $order->get_checkout_payment_url(true), |
|
665 | 665 | ); |
666 | 666 | } |
667 | 667 | |
668 | - if ( $this->maybe_process_pre_orders( $order_id ) ) { |
|
669 | - return $this->pre_orders->process_pre_order( $order_id ); |
|
668 | + if ($this->maybe_process_pre_orders($order_id)) { |
|
669 | + return $this->pre_orders->process_pre_order($order_id); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // This comes from the create account checkbox in the checkout page. |
673 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
673 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
674 | 674 | |
675 | - if ( $create_account ) { |
|
675 | + if ($create_account) { |
|
676 | 676 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
677 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
677 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
678 | 678 | $new_stripe_customer->create_customer(); |
679 | 679 | } |
680 | 680 | |
681 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
681 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
682 | 682 | $source_object = $prepared_source->source_object; |
683 | 683 | |
684 | 684 | // Check if we don't allow prepaid credit cards. |
685 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) { |
|
686 | - $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' ); |
|
687 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
685 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) { |
|
686 | + $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'); |
|
687 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
688 | 688 | } |
689 | 689 | |
690 | - if ( empty( $prepared_source->source ) ) { |
|
691 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
692 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
690 | + if (empty($prepared_source->source)) { |
|
691 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
692 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
693 | 693 | } |
694 | 694 | |
695 | - $this->save_source_to_order( $order, $prepared_source ); |
|
695 | + $this->save_source_to_order($order, $prepared_source); |
|
696 | 696 | |
697 | 697 | // Result from Stripe API request. |
698 | 698 | $response = null; |
699 | 699 | |
700 | - if ( $order->get_total() > 0 ) { |
|
700 | + if ($order->get_total() > 0) { |
|
701 | 701 | // This will throw exception if not valid. |
702 | - $this->validate_minimum_order_amount( $order ); |
|
702 | + $this->validate_minimum_order_amount($order); |
|
703 | 703 | |
704 | 704 | /* |
705 | 705 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -708,104 +708,104 @@ discard block |
||
708 | 708 | * Note that if we need to save source, the original source must be first |
709 | 709 | * attached to a customer in Stripe before it can be charged. |
710 | 710 | */ |
711 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
712 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
711 | + if ($this->is_3ds_required($source_object)) { |
|
712 | + $response = $this->create_3ds_source($order, $source_object); |
|
713 | 713 | |
714 | - if ( ! empty( $response->error ) ) { |
|
714 | + if ( ! empty($response->error)) { |
|
715 | 715 | $localized_message = $response->error->message; |
716 | 716 | |
717 | - $order->add_order_note( $localized_message ); |
|
717 | + $order->add_order_note($localized_message); |
|
718 | 718 | |
719 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
719 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | // Update order meta with 3DS source. |
723 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
724 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
723 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
724 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
725 | 725 | } else { |
726 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
726 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
727 | 727 | $order->save(); |
728 | 728 | } |
729 | 729 | |
730 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
730 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
731 | 731 | |
732 | 732 | return array( |
733 | 733 | 'result' => 'success', |
734 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
734 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
735 | 735 | ); |
736 | 736 | } |
737 | 737 | |
738 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
738 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
739 | 739 | |
740 | 740 | /* If we're doing a retry and source is chargeable, we need to pass |
741 | 741 | * a different idempotency key and retry for success. |
742 | 742 | */ |
743 | - if ( $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
744 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
743 | + if ($this->need_update_idempotency_key($source_object, $previous_error)) { |
|
744 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | // Make the request. |
748 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
748 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
749 | 749 | |
750 | - if ( ! empty( $response->error ) ) { |
|
750 | + if ( ! empty($response->error)) { |
|
751 | 751 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
752 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
753 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
754 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
755 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
752 | + if ($this->is_no_such_customer_error($response->error)) { |
|
753 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
754 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
755 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
756 | 756 | } else { |
757 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
758 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
757 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
758 | + $order->delete_meta_data('_stripe_customer_id'); |
|
759 | 759 | $order->save(); |
760 | 760 | } |
761 | 761 | } |
762 | 762 | |
763 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
763 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
764 | 764 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
765 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
765 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
766 | 766 | $wc_token->delete(); |
767 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
768 | - $order->add_order_note( $localized_message ); |
|
769 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
767 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
768 | + $order->add_order_note($localized_message); |
|
769 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
770 | 770 | } |
771 | 771 | |
772 | 772 | // We want to retry. |
773 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
774 | - if ( $retry ) { |
|
773 | + if ($this->is_retryable_error($response->error)) { |
|
774 | + if ($retry) { |
|
775 | 775 | // Don't do anymore retries after this. |
776 | - if ( 5 <= $this->retry_interval ) { |
|
777 | - return $this->process_payment( $order_id, false, $force_save_source, $response->error ); |
|
776 | + if (5 <= $this->retry_interval) { |
|
777 | + return $this->process_payment($order_id, false, $force_save_source, $response->error); |
|
778 | 778 | } |
779 | 779 | |
780 | - sleep( $this->retry_interval ); |
|
780 | + sleep($this->retry_interval); |
|
781 | 781 | |
782 | 782 | $this->retry_interval++; |
783 | 783 | |
784 | - return $this->process_payment( $order_id, true, $force_save_source, $response->error ); |
|
784 | + return $this->process_payment($order_id, true, $force_save_source, $response->error); |
|
785 | 785 | } else { |
786 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
787 | - $order->add_order_note( $localized_message ); |
|
788 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
786 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
787 | + $order->add_order_note($localized_message); |
|
788 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
789 | 789 | } |
790 | 790 | } |
791 | 791 | |
792 | 792 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
793 | 793 | |
794 | - if ( 'card_error' === $response->error->type ) { |
|
795 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
794 | + if ('card_error' === $response->error->type) { |
|
795 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
796 | 796 | } else { |
797 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
797 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
798 | 798 | } |
799 | 799 | |
800 | - $order->add_order_note( $localized_message ); |
|
800 | + $order->add_order_note($localized_message); |
|
801 | 801 | |
802 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
802 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
803 | 803 | } |
804 | 804 | |
805 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
805 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
806 | 806 | |
807 | 807 | // Process valid response. |
808 | - $this->process_response( $response, $order ); |
|
808 | + $this->process_response($response, $order); |
|
809 | 809 | } else { |
810 | 810 | $order->payment_complete(); |
811 | 811 | } |
@@ -816,20 +816,20 @@ discard block |
||
816 | 816 | // Return thank you page redirect. |
817 | 817 | return array( |
818 | 818 | 'result' => 'success', |
819 | - 'redirect' => $this->get_return_url( $order ), |
|
819 | + 'redirect' => $this->get_return_url($order), |
|
820 | 820 | ); |
821 | 821 | |
822 | - } catch ( WC_Stripe_Exception $e ) { |
|
823 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
824 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
822 | + } catch (WC_Stripe_Exception $e) { |
|
823 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
824 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
825 | 825 | |
826 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
826 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
827 | 827 | |
828 | 828 | /* translators: error message */ |
829 | - $order->update_status( 'failed' ); |
|
829 | + $order->update_status('failed'); |
|
830 | 830 | |
831 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
832 | - $this->send_failed_order_email( $order_id ); |
|
831 | + if ($order->has_status(array('pending', 'failed'))) { |
|
832 | + $this->send_failed_order_email($order_id); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | return array( |
@@ -846,17 +846,17 @@ discard block |
||
846 | 846 | * |
847 | 847 | * @param int $order_id |
848 | 848 | */ |
849 | - public function display_order_fee( $order_id ) { |
|
850 | - if ( apply_filters( 'wc_stripe_hide_display_order_fee', false, $order_id ) ) { |
|
849 | + public function display_order_fee($order_id) { |
|
850 | + if (apply_filters('wc_stripe_hide_display_order_fee', false, $order_id)) { |
|
851 | 851 | return; |
852 | 852 | } |
853 | 853 | |
854 | - $order = wc_get_order( $order_id ); |
|
854 | + $order = wc_get_order($order_id); |
|
855 | 855 | |
856 | - $fee = WC_Stripe_Helper::get_stripe_fee( $order ); |
|
857 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
856 | + $fee = WC_Stripe_Helper::get_stripe_fee($order); |
|
857 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
858 | 858 | |
859 | - if ( ! $fee || ! $currency ) { |
|
859 | + if ( ! $fee || ! $currency) { |
|
860 | 860 | return; |
861 | 861 | } |
862 | 862 | |
@@ -864,12 +864,12 @@ discard block |
||
864 | 864 | |
865 | 865 | <tr> |
866 | 866 | <td class="label stripe-fee"> |
867 | - <?php echo wc_help_tip( __( 'This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe' ) ); ?> |
|
868 | - <?php esc_html_e( 'Stripe Fee:', 'woocommerce-gateway-stripe' ); ?> |
|
867 | + <?php echo wc_help_tip(__('This represents the fee Stripe collects for the transaction.', 'woocommerce-gateway-stripe')); ?> |
|
868 | + <?php esc_html_e('Stripe Fee:', 'woocommerce-gateway-stripe'); ?> |
|
869 | 869 | </td> |
870 | 870 | <td width="1%"></td> |
871 | 871 | <td class="total"> |
872 | - - <?php echo wc_price( $fee, array( 'currency' => $currency ) ); ?> |
|
872 | + - <?php echo wc_price($fee, array('currency' => $currency)); ?> |
|
873 | 873 | </td> |
874 | 874 | </tr> |
875 | 875 | |
@@ -883,17 +883,17 @@ discard block |
||
883 | 883 | * |
884 | 884 | * @param int $order_id |
885 | 885 | */ |
886 | - public function display_order_payout( $order_id ) { |
|
887 | - if ( apply_filters( 'wc_stripe_hide_display_order_payout', false, $order_id ) ) { |
|
886 | + public function display_order_payout($order_id) { |
|
887 | + if (apply_filters('wc_stripe_hide_display_order_payout', false, $order_id)) { |
|
888 | 888 | return; |
889 | 889 | } |
890 | 890 | |
891 | - $order = wc_get_order( $order_id ); |
|
891 | + $order = wc_get_order($order_id); |
|
892 | 892 | |
893 | - $net = WC_Stripe_Helper::get_stripe_net( $order ); |
|
894 | - $currency = WC_Stripe_Helper::get_stripe_currency( $order ); |
|
893 | + $net = WC_Stripe_Helper::get_stripe_net($order); |
|
894 | + $currency = WC_Stripe_Helper::get_stripe_currency($order); |
|
895 | 895 | |
896 | - if ( ! $net || ! $currency ) { |
|
896 | + if ( ! $net || ! $currency) { |
|
897 | 897 | return; |
898 | 898 | } |
899 | 899 | |
@@ -901,12 +901,12 @@ discard block |
||
901 | 901 | |
902 | 902 | <tr> |
903 | 903 | <td class="label stripe-payout"> |
904 | - <?php echo wc_help_tip( __( 'This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe' ) ); ?> |
|
905 | - <?php esc_html_e( 'Stripe Payout:', 'woocommerce-gateway-stripe' ); ?> |
|
904 | + <?php echo wc_help_tip(__('This represents the net total that will be credited to your Stripe bank account. This may be in the currency that is set in your Stripe account.', 'woocommerce-gateway-stripe')); ?> |
|
905 | + <?php esc_html_e('Stripe Payout:', 'woocommerce-gateway-stripe'); ?> |
|
906 | 906 | </td> |
907 | 907 | <td width="1%"></td> |
908 | 908 | <td class="total"> |
909 | - <?php echo wc_price( $net, array( 'currency' => $currency ) ); ?> |
|
909 | + <?php echo wc_price($net, array('currency' => $currency)); ?> |
|
910 | 910 | </td> |
911 | 911 | </tr> |
912 | 912 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function __construct() { |
66 | 66 | $this->id = 'stripe_bitcoin'; |
67 | - $this->method_title = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
67 | + $this->method_title = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
68 | 68 | /* translators: link */ |
69 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
69 | + $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')); |
|
70 | 70 | $this->supports = array( |
71 | 71 | 'products', |
72 | 72 | 'refunds', |
@@ -78,27 +78,27 @@ discard block |
||
78 | 78 | // Load the settings. |
79 | 79 | $this->init_settings(); |
80 | 80 | |
81 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
82 | - $this->title = $this->get_option( 'title' ); |
|
83 | - $this->description = $this->get_option( 'description' ); |
|
84 | - $this->enabled = $this->get_option( 'enabled' ); |
|
85 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
86 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
87 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
88 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
89 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
90 | - |
|
91 | - if ( $this->testmode ) { |
|
92 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
93 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
81 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
82 | + $this->title = $this->get_option('title'); |
|
83 | + $this->description = $this->get_option('description'); |
|
84 | + $this->enabled = $this->get_option('enabled'); |
|
85 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
86 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
87 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
88 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
89 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
90 | + |
|
91 | + if ($this->testmode) { |
|
92 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
93 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
94 | 94 | } |
95 | 95 | |
96 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
97 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
98 | - add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) ); |
|
96 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
97 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
98 | + add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page')); |
|
99 | 99 | |
100 | 100 | // Customer Emails. |
101 | - add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); |
|
101 | + add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | * @return array |
110 | 110 | */ |
111 | 111 | public function get_supported_currency() { |
112 | - return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array( |
|
112 | + return apply_filters('wc_stripe_bitcoin_supported_currencies', array( |
|
113 | 113 | 'USD', |
114 | - ) ); |
|
114 | + )); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @return bool |
123 | 123 | */ |
124 | 124 | public function is_available() { |
125 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
125 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
126 | 126 | return false; |
127 | 127 | } |
128 | 128 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $icons_str .= $icons['bitcoin']; |
145 | 145 | |
146 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
146 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,19 +154,19 @@ discard block |
||
154 | 154 | * @access public |
155 | 155 | */ |
156 | 156 | public function payment_scripts() { |
157 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
157 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
158 | 158 | return; |
159 | 159 | } |
160 | 160 | |
161 | - wp_enqueue_style( 'stripe_styles' ); |
|
162 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
161 | + wp_enqueue_style('stripe_styles'); |
|
162 | + wp_enqueue_script('woocommerce_stripe'); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | 166 | * Initialize Gateway Settings Form Fields. |
167 | 167 | */ |
168 | 168 | public function init_form_fields() { |
169 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' ); |
|
169 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php'); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -177,25 +177,25 @@ discard block |
||
177 | 177 | $total = WC()->cart->total; |
178 | 178 | |
179 | 179 | // If paying from order, we need to get total from order not cart. |
180 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
181 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
180 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
181 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
182 | 182 | $total = $order->get_total(); |
183 | 183 | } |
184 | 184 | |
185 | - if ( is_add_payment_method_page() ) { |
|
186 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
187 | - $total = ''; |
|
185 | + if (is_add_payment_method_page()) { |
|
186 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
187 | + $total = ''; |
|
188 | 188 | } else { |
189 | 189 | $pay_button_text = ''; |
190 | 190 | } |
191 | 191 | |
192 | 192 | echo '<div |
193 | 193 | id="stripe-bitcoin-payment-data" |
194 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
195 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
194 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
195 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
196 | 196 | |
197 | - if ( $this->description ) { |
|
198 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id ); |
|
197 | + if ($this->description) { |
|
198 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | echo '</div>'; |
@@ -206,8 +206,8 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @param int $order_id |
208 | 208 | */ |
209 | - public function thankyou_page( $order_id ) { |
|
210 | - $this->get_instructions( $order_id ); |
|
209 | + public function thankyou_page($order_id) { |
|
210 | + $this->get_instructions($order_id); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -219,15 +219,15 @@ discard block |
||
219 | 219 | * @param bool $sent_to_admin |
220 | 220 | * @param bool $plain_text |
221 | 221 | */ |
222 | - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { |
|
222 | + public function email_instructions($order, $sent_to_admin, $plain_text = false) { |
|
223 | 223 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
224 | 224 | |
225 | 225 | $payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method(); |
226 | 226 | |
227 | - if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) { |
|
228 | - WC_Stripe_Logger::log( 'Sending bitcoin email for order #' . $order_id ); |
|
227 | + if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) { |
|
228 | + WC_Stripe_Logger::log('Sending bitcoin email for order #' . $order_id); |
|
229 | 229 | |
230 | - $this->get_instructions( $order_id, $plain_text ); |
|
230 | + $this->get_instructions($order_id, $plain_text); |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
@@ -238,38 +238,38 @@ discard block |
||
238 | 238 | * @version 4.0.0 |
239 | 239 | * @param int $order_id |
240 | 240 | */ |
241 | - public function get_instructions( $order_id, $plain_text = false ) { |
|
242 | - $data = get_post_meta( $order_id, '_stripe_bitcoin', true ); |
|
241 | + public function get_instructions($order_id, $plain_text = false) { |
|
242 | + $data = get_post_meta($order_id, '_stripe_bitcoin', true); |
|
243 | 243 | |
244 | - if ( $plain_text ) { |
|
245 | - esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
244 | + if ($plain_text) { |
|
245 | + esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
246 | 246 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
247 | - esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
247 | + esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
248 | 248 | echo $data['amount'] . "\n\n"; |
249 | 249 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
250 | - esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
250 | + esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
251 | 251 | echo $data['address'] . "\n\n"; |
252 | 252 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
253 | - esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
253 | + esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
254 | 254 | echo $data['uri'] . "\n\n"; |
255 | 255 | } else { |
256 | 256 | ?> |
257 | - <h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3> |
|
257 | + <h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3> |
|
258 | 258 | <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
259 | 259 | <li class="woocommerce-order-overview__order order"> |
260 | - <?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?> |
|
260 | + <?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?> |
|
261 | 261 | <strong><?php echo $data['amount']; ?></strong> |
262 | 262 | </li> |
263 | 263 | <li class="woocommerce-order-overview__order order"> |
264 | - <?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?> |
|
264 | + <?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?> |
|
265 | 265 | <strong><?php echo $data['address']; ?></strong> |
266 | 266 | </li> |
267 | 267 | <li class="woocommerce-order-overview__order order"> |
268 | - <?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?> |
|
268 | + <?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?> |
|
269 | 269 | <strong> |
270 | 270 | <?php |
271 | 271 | /* translators: link */ |
272 | - printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] ); |
|
272 | + printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']); |
|
273 | 273 | ?> |
274 | 274 | </strong> |
275 | 275 | </li> |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * @param object $order |
287 | 287 | * @param object $source_object |
288 | 288 | */ |
289 | - public function save_instructions( $order, $source_object ) { |
|
289 | + public function save_instructions($order, $source_object) { |
|
290 | 290 | $data = array( |
291 | 291 | 'amount' => $source_object->bitcoin->amount, |
292 | 292 | 'address' => $source_object->bitcoin->address, |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | |
296 | 296 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
297 | 297 | |
298 | - update_post_meta( $order_id, '_stripe_bitcoin', $data ); |
|
298 | + update_post_meta($order_id, '_stripe_bitcoin', $data); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -309,37 +309,37 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @return array|void |
311 | 311 | */ |
312 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
312 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
313 | 313 | try { |
314 | - $order = wc_get_order( $order_id ); |
|
314 | + $order = wc_get_order($order_id); |
|
315 | 315 | |
316 | 316 | // This comes from the create account checkbox in the checkout page. |
317 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
317 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
318 | 318 | |
319 | - if ( $create_account ) { |
|
319 | + if ($create_account) { |
|
320 | 320 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
321 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
321 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
322 | 322 | $new_stripe_customer->create_customer(); |
323 | 323 | } |
324 | 324 | |
325 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
325 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
326 | 326 | |
327 | - if ( empty( $prepared_source->source ) ) { |
|
328 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
329 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
327 | + if (empty($prepared_source->source)) { |
|
328 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
329 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
330 | 330 | } |
331 | 331 | |
332 | - $this->save_source_to_order( $order, $prepared_source ); |
|
332 | + $this->save_source_to_order($order, $prepared_source); |
|
333 | 333 | |
334 | 334 | // This will throw exception if not valid. |
335 | - $this->validate_minimum_order_amount( $order ); |
|
335 | + $this->validate_minimum_order_amount($order); |
|
336 | 336 | |
337 | - $this->save_instructions( $order, $this->get_source_object( $prepared_source->source ) ); |
|
337 | + $this->save_instructions($order, $this->get_source_object($prepared_source->source)); |
|
338 | 338 | |
339 | 339 | // Mark as on-hold (we're awaiting the payment). |
340 | - $order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) ); |
|
340 | + $order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe')); |
|
341 | 341 | |
342 | - wc_reduce_stock_levels( $order_id ); |
|
342 | + wc_reduce_stock_levels($order_id); |
|
343 | 343 | |
344 | 344 | // Remove cart. |
345 | 345 | WC()->cart->empty_cart(); |
@@ -347,16 +347,16 @@ discard block |
||
347 | 347 | // Return thankyou redirect. |
348 | 348 | return array( |
349 | 349 | 'result' => 'success', |
350 | - 'redirect' => $this->get_return_url( $order ), |
|
350 | + 'redirect' => $this->get_return_url($order), |
|
351 | 351 | ); |
352 | - } catch ( WC_Stripe_Exception $e ) { |
|
353 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
354 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
352 | + } catch (WC_Stripe_Exception $e) { |
|
353 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
354 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
355 | 355 | |
356 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
356 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
357 | 357 | |
358 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
359 | - $this->send_failed_order_email( $order_id ); |
|
358 | + if ($order->has_status(array('pending', 'failed'))) { |
|
359 | + $this->send_failed_order_email($order_id); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_eps'; |
60 | - $this->method_title = __( 'Stripe EPS', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe EPS', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | * @return array |
99 | 99 | */ |
100 | 100 | public function get_supported_currency() { |
101 | - return apply_filters( 'wc_stripe_eps_supported_currencies', array( |
|
101 | + return apply_filters('wc_stripe_eps_supported_currencies', array( |
|
102 | 102 | 'EUR', |
103 | - ) ); |
|
103 | + )); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return bool |
112 | 112 | */ |
113 | 113 | public function is_available() { |
114 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
114 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | $icons_str .= $icons['eps']; |
134 | 134 | |
135 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
135 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -143,19 +143,19 @@ discard block |
||
143 | 143 | * @access public |
144 | 144 | */ |
145 | 145 | public function payment_scripts() { |
146 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
146 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | |
150 | - wp_enqueue_style( 'stripe_styles' ); |
|
151 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
150 | + wp_enqueue_style('stripe_styles'); |
|
151 | + wp_enqueue_script('woocommerce_stripe'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Initialize Gateway Settings Form Fields. |
156 | 156 | */ |
157 | 157 | public function init_form_fields() { |
158 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-eps-settings.php' ); |
|
158 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-eps-settings.php'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -166,25 +166,25 @@ discard block |
||
166 | 166 | $total = WC()->cart->total; |
167 | 167 | |
168 | 168 | // If paying from order, we need to get total from order not cart. |
169 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
170 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
169 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
170 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
171 | 171 | $total = $order->get_total(); |
172 | 172 | } |
173 | 173 | |
174 | - if ( is_add_payment_method_page() ) { |
|
175 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
176 | - $total = ''; |
|
174 | + if (is_add_payment_method_page()) { |
|
175 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
176 | + $total = ''; |
|
177 | 177 | } else { |
178 | 178 | $pay_button_text = ''; |
179 | 179 | } |
180 | 180 | |
181 | 181 | echo '<div |
182 | 182 | id="stripe-eps-payment-data" |
183 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
184 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
183 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
184 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
185 | 185 | |
186 | - if ( $this->description ) { |
|
187 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id ); |
|
186 | + if ($this->description) { |
|
187 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | echo '</div>'; |
@@ -198,24 +198,24 @@ discard block |
||
198 | 198 | * @param object $order |
199 | 199 | * @return mixed |
200 | 200 | */ |
201 | - public function create_source( $order ) { |
|
201 | + public function create_source($order) { |
|
202 | 202 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
203 | 203 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
204 | - $return_url = $this->get_stripe_return_url( $order ); |
|
204 | + $return_url = $this->get_stripe_return_url($order); |
|
205 | 205 | $post_data = array(); |
206 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
207 | - $post_data['currency'] = strtolower( $currency ); |
|
206 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
207 | + $post_data['currency'] = strtolower($currency); |
|
208 | 208 | $post_data['type'] = 'eps'; |
209 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
210 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
209 | + $post_data['owner'] = $this->get_owner_details($order); |
|
210 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
211 | 211 | |
212 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
213 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
212 | + if ( ! empty($this->statement_descriptor)) { |
|
213 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
214 | 214 | } |
215 | 215 | |
216 | - WC_Stripe_Logger::log( 'Info: Begin creating EPS source' ); |
|
216 | + WC_Stripe_Logger::log('Info: Begin creating EPS source'); |
|
217 | 217 | |
218 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
218 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -229,51 +229,51 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return array|void |
231 | 231 | */ |
232 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
232 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
233 | 233 | try { |
234 | - $order = wc_get_order( $order_id ); |
|
234 | + $order = wc_get_order($order_id); |
|
235 | 235 | |
236 | 236 | // This will throw exception if not valid. |
237 | - $this->validate_minimum_order_amount( $order ); |
|
237 | + $this->validate_minimum_order_amount($order); |
|
238 | 238 | |
239 | 239 | // This comes from the create account checkbox in the checkout page. |
240 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
240 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
241 | 241 | |
242 | - if ( $create_account ) { |
|
242 | + if ($create_account) { |
|
243 | 243 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
244 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
244 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
245 | 245 | $new_stripe_customer->create_customer(); |
246 | 246 | } |
247 | 247 | |
248 | - $response = $this->create_source( $order ); |
|
248 | + $response = $this->create_source($order); |
|
249 | 249 | |
250 | - if ( ! empty( $response->error ) ) { |
|
251 | - $order->add_order_note( $response->error->message ); |
|
250 | + if ( ! empty($response->error)) { |
|
251 | + $order->add_order_note($response->error->message); |
|
252 | 252 | |
253 | - throw new Exception( $response->error->message ); |
|
253 | + throw new Exception($response->error->message); |
|
254 | 254 | } |
255 | 255 | |
256 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
257 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
256 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
257 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
258 | 258 | } else { |
259 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
259 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
260 | 260 | $order->save(); |
261 | 261 | } |
262 | 262 | |
263 | - WC_Stripe_Logger::log( 'Info: Redirecting to EPS...' ); |
|
263 | + WC_Stripe_Logger::log('Info: Redirecting to EPS...'); |
|
264 | 264 | |
265 | 265 | return array( |
266 | 266 | 'result' => 'success', |
267 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
267 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
268 | 268 | ); |
269 | - } catch ( Exception $e ) { |
|
270 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
271 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
269 | + } catch (Exception $e) { |
|
270 | + wc_add_notice($e->getMessage(), 'error'); |
|
271 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
272 | 272 | |
273 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
273 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
274 | 274 | |
275 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
276 | - $this->send_failed_order_email( $order_id ); |
|
275 | + if ($order->has_status(array('pending', 'failed'))) { |
|
276 | + $this->send_failed_order_email($order_id); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | 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_bancontact'; |
60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | * @return array |
99 | 99 | */ |
100 | 100 | public function get_supported_currency() { |
101 | - return apply_filters( 'wc_stripe_bancontact_supported_currencies', array( |
|
101 | + return apply_filters('wc_stripe_bancontact_supported_currencies', array( |
|
102 | 102 | 'EUR', |
103 | - ) ); |
|
103 | + )); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return bool |
112 | 112 | */ |
113 | 113 | public function is_available() { |
114 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
114 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | $icons_str .= $icons['bancontact']; |
134 | 134 | |
135 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
135 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -143,19 +143,19 @@ discard block |
||
143 | 143 | * @access public |
144 | 144 | */ |
145 | 145 | public function payment_scripts() { |
146 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
146 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | |
150 | - wp_enqueue_style( 'stripe_styles' ); |
|
151 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
150 | + wp_enqueue_style('stripe_styles'); |
|
151 | + wp_enqueue_script('woocommerce_stripe'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Initialize Gateway Settings Form Fields. |
156 | 156 | */ |
157 | 157 | public function init_form_fields() { |
158 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
158 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -166,25 +166,25 @@ discard block |
||
166 | 166 | $total = WC()->cart->total; |
167 | 167 | |
168 | 168 | // If paying from order, we need to get total from order not cart. |
169 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
170 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
169 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
170 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
171 | 171 | $total = $order->get_total(); |
172 | 172 | } |
173 | 173 | |
174 | - if ( is_add_payment_method_page() ) { |
|
175 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
176 | - $total = ''; |
|
174 | + if (is_add_payment_method_page()) { |
|
175 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
176 | + $total = ''; |
|
177 | 177 | } else { |
178 | 178 | $pay_button_text = ''; |
179 | 179 | } |
180 | 180 | |
181 | 181 | echo '<div |
182 | 182 | id="stripe-bancontact-payment-data" |
183 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
184 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
183 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
184 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
185 | 185 | |
186 | - if ( $this->description ) { |
|
187 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id ); |
|
186 | + if ($this->description) { |
|
187 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | echo '</div>'; |
@@ -198,25 +198,25 @@ discard block |
||
198 | 198 | * @param object $order |
199 | 199 | * @return mixed |
200 | 200 | */ |
201 | - public function create_source( $order ) { |
|
201 | + public function create_source($order) { |
|
202 | 202 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
203 | 203 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
204 | - $return_url = $this->get_stripe_return_url( $order ); |
|
204 | + $return_url = $this->get_stripe_return_url($order); |
|
205 | 205 | $post_data = array(); |
206 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
207 | - $post_data['currency'] = strtolower( $currency ); |
|
206 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
207 | + $post_data['currency'] = strtolower($currency); |
|
208 | 208 | $post_data['type'] = 'bancontact'; |
209 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
210 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
211 | - $post_data['bancontact'] = array( 'preferred_language' => $this->get_locale() ); |
|
209 | + $post_data['owner'] = $this->get_owner_details($order); |
|
210 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
211 | + $post_data['bancontact'] = array('preferred_language' => $this->get_locale()); |
|
212 | 212 | |
213 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
214 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
213 | + if ( ! empty($this->statement_descriptor)) { |
|
214 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
215 | 215 | } |
216 | 216 | |
217 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
217 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
218 | 218 | |
219 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' ); |
|
219 | + return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources'); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -230,51 +230,51 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @return array|void |
232 | 232 | */ |
233 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
233 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
234 | 234 | try { |
235 | - $order = wc_get_order( $order_id ); |
|
235 | + $order = wc_get_order($order_id); |
|
236 | 236 | |
237 | 237 | // This will throw exception if not valid. |
238 | - $this->validate_minimum_order_amount( $order ); |
|
238 | + $this->validate_minimum_order_amount($order); |
|
239 | 239 | |
240 | 240 | // This comes from the create account checkbox in the checkout page. |
241 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
241 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
242 | 242 | |
243 | - if ( $create_account ) { |
|
243 | + if ($create_account) { |
|
244 | 244 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
245 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
245 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
246 | 246 | $new_stripe_customer->create_customer(); |
247 | 247 | } |
248 | 248 | |
249 | - $response = $this->create_source( $order ); |
|
249 | + $response = $this->create_source($order); |
|
250 | 250 | |
251 | - if ( ! empty( $response->error ) ) { |
|
252 | - $order->add_order_note( $response->error->message ); |
|
251 | + if ( ! empty($response->error)) { |
|
252 | + $order->add_order_note($response->error->message); |
|
253 | 253 | |
254 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
254 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
258 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
257 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
258 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
259 | 259 | } else { |
260 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
260 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
261 | 261 | $order->save(); |
262 | 262 | } |
263 | 263 | |
264 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
264 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
265 | 265 | |
266 | 266 | return array( |
267 | 267 | 'result' => 'success', |
268 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
268 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
269 | 269 | ); |
270 | - } catch ( WC_Stripe_Exception $e ) { |
|
271 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
272 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
270 | + } catch (WC_Stripe_Exception $e) { |
|
271 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
272 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
273 | 273 | |
274 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
274 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
275 | 275 | |
276 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
277 | - $this->send_failed_order_email( $order_id ); |
|
276 | + if ($order->has_status(array('pending', 'failed'))) { |
|
277 | + $this->send_failed_order_email($order_id); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | public function __construct() { |
73 | 73 | $this->retry_interval = 1; |
74 | 74 | $this->id = 'stripe_sepa'; |
75 | - $this->method_title = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
75 | + $this->method_title = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
76 | 76 | /* translators: link */ |
77 | - $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' ) ); |
|
77 | + $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')); |
|
78 | 78 | $this->supports = array( |
79 | 79 | 'products', |
80 | 80 | 'refunds', |
@@ -99,28 +99,28 @@ discard block |
||
99 | 99 | // Load the settings. |
100 | 100 | $this->init_settings(); |
101 | 101 | |
102 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
103 | - $this->title = $this->get_option( 'title' ); |
|
104 | - $this->description = $this->get_option( 'description' ); |
|
105 | - $this->enabled = $this->get_option( 'enabled' ); |
|
106 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
107 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
108 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
109 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
110 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
111 | - |
|
112 | - if ( $this->testmode ) { |
|
113 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
114 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
102 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
103 | + $this->title = $this->get_option('title'); |
|
104 | + $this->description = $this->get_option('description'); |
|
105 | + $this->enabled = $this->get_option('enabled'); |
|
106 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
107 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
108 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
109 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
110 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
111 | + |
|
112 | + if ($this->testmode) { |
|
113 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
114 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
115 | 115 | } |
116 | 116 | |
117 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
118 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
117 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
118 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
119 | 119 | |
120 | - if ( WC_Stripe_Helper::is_pre_orders_exists() ) { |
|
120 | + if (WC_Stripe_Helper::is_pre_orders_exists()) { |
|
121 | 121 | $this->pre_orders = new WC_Stripe_Pre_Orders_Compat(); |
122 | 122 | |
123 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this->pre_orders, 'process_pre_order_release_payment' ) ); |
|
123 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this->pre_orders, 'process_pre_order_release_payment')); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @return array |
133 | 133 | */ |
134 | 134 | public function get_supported_currency() { |
135 | - return apply_filters( 'wc_stripe_sepa_supported_currencies', array( |
|
135 | + return apply_filters('wc_stripe_sepa_supported_currencies', array( |
|
136 | 136 | 'EUR', |
137 | - ) ); |
|
137 | + )); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | * @return bool |
146 | 146 | */ |
147 | 147 | public function is_available() { |
148 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
148 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
149 | 149 | return false; |
150 | 150 | } |
151 | 151 | |
152 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
152 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | |
171 | 171 | $icons_str .= $icons['sepa']; |
172 | 172 | |
173 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
173 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -181,19 +181,19 @@ discard block |
||
181 | 181 | * @access public |
182 | 182 | */ |
183 | 183 | public function payment_scripts() { |
184 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
184 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
188 | - wp_enqueue_style( 'stripe_styles' ); |
|
189 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
188 | + wp_enqueue_style('stripe_styles'); |
|
189 | + wp_enqueue_script('woocommerce_stripe'); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | 193 | * Initialize Gateway Settings Form Fields. |
194 | 194 | */ |
195 | 195 | public function init_form_fields() { |
196 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' ); |
|
196 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php'); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public function mandate_display() { |
207 | 207 | /* translators: statement descriptor */ |
208 | - 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 ) ); |
|
208 | + 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)); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -216,24 +216,24 @@ discard block |
||
216 | 216 | */ |
217 | 217 | public function form() { |
218 | 218 | ?> |
219 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
220 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
219 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
220 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
221 | 221 | <p class="wc-stripe-sepa-mandate" style="margin-bottom:40px;"><?php $this->mandate_display(); ?></p> |
222 | 222 | <p class="form-row form-row-wide"> |
223 | 223 | <label for="stripe-sepa-owner"> |
224 | - <?php esc_html_e( 'IBAN Account Name.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span> |
|
224 | + <?php esc_html_e('IBAN Account Name.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span> |
|
225 | 225 | </label> |
226 | 226 | <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;" /> |
227 | 227 | </p> |
228 | 228 | <p class="form-row form-row-wide"> |
229 | 229 | <label for="stripe-sepa-iban"> |
230 | - <?php esc_html_e( 'IBAN Account Number.', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span> |
|
230 | + <?php esc_html_e('IBAN Account Number.', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span> |
|
231 | 231 | </label> |
232 | 232 | <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;" /> |
233 | 233 | </p> |
234 | 234 | <!-- Used to display form errors --> |
235 | 235 | <div class="stripe-source-errors" role="alert"></div> |
236 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
236 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
237 | 237 | <div class="clear"></div> |
238 | 238 | </fieldset> |
239 | 239 | <?php |
@@ -245,42 +245,42 @@ discard block |
||
245 | 245 | public function payment_fields() { |
246 | 246 | $user = wp_get_current_user(); |
247 | 247 | $total = WC()->cart->total; |
248 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
248 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
249 | 249 | |
250 | 250 | // If paying from order, we need to get total from order not cart. |
251 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
252 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
251 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
252 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
253 | 253 | $total = $order->get_total(); |
254 | 254 | } |
255 | 255 | |
256 | - if ( is_add_payment_method_page() ) { |
|
257 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
258 | - $total = ''; |
|
256 | + if (is_add_payment_method_page()) { |
|
257 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
258 | + $total = ''; |
|
259 | 259 | } else { |
260 | 260 | $pay_button_text = ''; |
261 | 261 | } |
262 | 262 | |
263 | 263 | echo '<div |
264 | 264 | id="stripe-sepa_debit-payment-data" |
265 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
266 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
265 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
266 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
267 | 267 | |
268 | - if ( $this->description ) { |
|
269 | - if ( $this->testmode ) { |
|
270 | - $this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' ); |
|
271 | - $this->description = trim( $this->description ); |
|
268 | + if ($this->description) { |
|
269 | + if ($this->testmode) { |
|
270 | + $this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe'); |
|
271 | + $this->description = trim($this->description); |
|
272 | 272 | } |
273 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id ); |
|
273 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id); |
|
274 | 274 | } |
275 | 275 | |
276 | - if ( $display_tokenization ) { |
|
276 | + if ($display_tokenization) { |
|
277 | 277 | $this->tokenization_script(); |
278 | 278 | $this->saved_payment_methods(); |
279 | 279 | } |
280 | 280 | |
281 | 281 | $this->form(); |
282 | 282 | |
283 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
283 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
284 | 284 | $this->save_payment_method_checkbox(); |
285 | 285 | } |
286 | 286 | |
@@ -298,99 +298,99 @@ discard block |
||
298 | 298 | * |
299 | 299 | * @return array|void |
300 | 300 | */ |
301 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
301 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
302 | 302 | try { |
303 | - $order = wc_get_order( $order_id ); |
|
303 | + $order = wc_get_order($order_id); |
|
304 | 304 | |
305 | - if ( $this->maybe_process_pre_orders( $order_id ) ) { |
|
306 | - return $this->pre_orders->process_pre_order( $order_id ); |
|
305 | + if ($this->maybe_process_pre_orders($order_id)) { |
|
306 | + return $this->pre_orders->process_pre_order($order_id); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | // This comes from the create account checkbox in the checkout page. |
310 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
310 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
311 | 311 | |
312 | - if ( $create_account ) { |
|
312 | + if ($create_account) { |
|
313 | 313 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
314 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
314 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
315 | 315 | $new_stripe_customer->create_customer(); |
316 | 316 | } |
317 | 317 | |
318 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
318 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
319 | 319 | |
320 | - $this->save_source_to_order( $order, $prepared_source ); |
|
320 | + $this->save_source_to_order($order, $prepared_source); |
|
321 | 321 | |
322 | 322 | // Result from Stripe API request. |
323 | 323 | $response = null; |
324 | 324 | |
325 | - if ( $order->get_total() > 0 ) { |
|
325 | + if ($order->get_total() > 0) { |
|
326 | 326 | // This will throw exception if not valid. |
327 | - $this->validate_minimum_order_amount( $order ); |
|
327 | + $this->validate_minimum_order_amount($order); |
|
328 | 328 | |
329 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
329 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
330 | 330 | |
331 | 331 | // Make the request. |
332 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
332 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
333 | 333 | |
334 | - if ( ! empty( $response->error ) ) { |
|
334 | + if ( ! empty($response->error)) { |
|
335 | 335 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
336 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
337 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
338 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
339 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
336 | + if ($this->is_no_such_customer_error($response->error)) { |
|
337 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
338 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
339 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
340 | 340 | } else { |
341 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
342 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
341 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
342 | + $order->delete_meta_data('_stripe_customer_id'); |
|
343 | 343 | $order->save(); |
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | - if ( $this->is_no_such_token_error( $response->error ) && $prepared_source->token_id ) { |
|
347 | + if ($this->is_no_such_token_error($response->error) && $prepared_source->token_id) { |
|
348 | 348 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
349 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
349 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
350 | 350 | $wc_token->delete(); |
351 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
352 | - $order->add_order_note( $localized_message ); |
|
353 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
351 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
352 | + $order->add_order_note($localized_message); |
|
353 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | // We want to retry. |
357 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
358 | - if ( $retry ) { |
|
357 | + if ($this->is_retryable_error($response->error)) { |
|
358 | + if ($retry) { |
|
359 | 359 | // Don't do anymore retries after this. |
360 | - if ( 5 <= $this->retry_interval ) { |
|
360 | + if (5 <= $this->retry_interval) { |
|
361 | 361 | |
362 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
362 | + return $this->process_payment($order_id, false, $force_save_source); |
|
363 | 363 | } |
364 | 364 | |
365 | - sleep( $this->retry_interval ); |
|
365 | + sleep($this->retry_interval); |
|
366 | 366 | |
367 | 367 | $this->retry_interval++; |
368 | 368 | |
369 | - return $this->process_payment( $order_id, true, $force_save_source ); |
|
369 | + return $this->process_payment($order_id, true, $force_save_source); |
|
370 | 370 | } else { |
371 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
372 | - $order->add_order_note( $localized_message ); |
|
373 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
371 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
372 | + $order->add_order_note($localized_message); |
|
373 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
374 | 374 | } |
375 | 375 | } |
376 | 376 | |
377 | 377 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
378 | 378 | |
379 | - if ( 'card_error' === $response->error->type ) { |
|
380 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
379 | + if ('card_error' === $response->error->type) { |
|
380 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
381 | 381 | } else { |
382 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
382 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
383 | 383 | } |
384 | 384 | |
385 | - $order->add_order_note( $localized_message ); |
|
385 | + $order->add_order_note($localized_message); |
|
386 | 386 | |
387 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
387 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
388 | 388 | } |
389 | 389 | |
390 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
390 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
391 | 391 | |
392 | 392 | // Process valid response. |
393 | - $this->process_response( $response, $order ); |
|
393 | + $this->process_response($response, $order); |
|
394 | 394 | } else { |
395 | 395 | $order->payment_complete(); |
396 | 396 | } |
@@ -401,17 +401,17 @@ discard block |
||
401 | 401 | // Return thank you page redirect. |
402 | 402 | return array( |
403 | 403 | 'result' => 'success', |
404 | - 'redirect' => $this->get_return_url( $order ), |
|
404 | + 'redirect' => $this->get_return_url($order), |
|
405 | 405 | ); |
406 | 406 | |
407 | - } catch ( WC_Stripe_Exception $e ) { |
|
408 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
409 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
407 | + } catch (WC_Stripe_Exception $e) { |
|
408 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
409 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
410 | 410 | |
411 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
411 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
412 | 412 | |
413 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
414 | - $this->send_failed_order_email( $order_id ); |
|
413 | + if ($order->has_status(array('pending', 'failed'))) { |
|
414 | + $this->send_failed_order_email($order_id); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_giropay'; |
60 | - $this->method_title = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | * @return array |
99 | 99 | */ |
100 | 100 | public function get_supported_currency() { |
101 | - return apply_filters( 'wc_stripe_giropay_supported_currencies', array( |
|
101 | + return apply_filters('wc_stripe_giropay_supported_currencies', array( |
|
102 | 102 | 'EUR', |
103 | - ) ); |
|
103 | + )); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return bool |
112 | 112 | */ |
113 | 113 | public function is_available() { |
114 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
114 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | $icons_str .= $icons['giropay']; |
134 | 134 | |
135 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
135 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -143,19 +143,19 @@ discard block |
||
143 | 143 | * @access public |
144 | 144 | */ |
145 | 145 | public function payment_scripts() { |
146 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
146 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | |
150 | - wp_enqueue_style( 'stripe_styles' ); |
|
151 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
150 | + wp_enqueue_style('stripe_styles'); |
|
151 | + wp_enqueue_script('woocommerce_stripe'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Initialize Gateway Settings Form Fields. |
156 | 156 | */ |
157 | 157 | public function init_form_fields() { |
158 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' ); |
|
158 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -166,25 +166,25 @@ discard block |
||
166 | 166 | $total = WC()->cart->total; |
167 | 167 | |
168 | 168 | // If paying from order, we need to get total from order not cart. |
169 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
170 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
169 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
170 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
171 | 171 | $total = $order->get_total(); |
172 | 172 | } |
173 | 173 | |
174 | - if ( is_add_payment_method_page() ) { |
|
175 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
176 | - $total = ''; |
|
174 | + if (is_add_payment_method_page()) { |
|
175 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
176 | + $total = ''; |
|
177 | 177 | } else { |
178 | 178 | $pay_button_text = ''; |
179 | 179 | } |
180 | 180 | |
181 | 181 | echo '<div |
182 | 182 | id="stripe-giropay-payment-data" |
183 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
184 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
183 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
184 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
185 | 185 | |
186 | - if ( $this->description ) { |
|
187 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ), $this->id ); |
|
186 | + if ($this->description) { |
|
187 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description)), $this->id); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | echo '</div>'; |
@@ -198,24 +198,24 @@ discard block |
||
198 | 198 | * @param object $order |
199 | 199 | * @return mixed |
200 | 200 | */ |
201 | - public function create_source( $order ) { |
|
201 | + public function create_source($order) { |
|
202 | 202 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
203 | 203 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
204 | - $return_url = $this->get_stripe_return_url( $order ); |
|
204 | + $return_url = $this->get_stripe_return_url($order); |
|
205 | 205 | $post_data = array(); |
206 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
207 | - $post_data['currency'] = strtolower( $currency ); |
|
206 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
207 | + $post_data['currency'] = strtolower($currency); |
|
208 | 208 | $post_data['type'] = 'giropay'; |
209 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
210 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
209 | + $post_data['owner'] = $this->get_owner_details($order); |
|
210 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
211 | 211 | |
212 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
213 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
212 | + if ( ! empty($this->statement_descriptor)) { |
|
213 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
214 | 214 | } |
215 | 215 | |
216 | - WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' ); |
|
216 | + WC_Stripe_Logger::log('Info: Begin creating Giropay source'); |
|
217 | 217 | |
218 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_giropay_source', $post_data, $order ), 'sources' ); |
|
218 | + return WC_Stripe_API::request(apply_filters('wc_stripe_giropay_source', $post_data, $order), 'sources'); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -229,51 +229,51 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return array|void |
231 | 231 | */ |
232 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
232 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
233 | 233 | try { |
234 | - $order = wc_get_order( $order_id ); |
|
234 | + $order = wc_get_order($order_id); |
|
235 | 235 | |
236 | 236 | // This will throw exception if not valid. |
237 | - $this->validate_minimum_order_amount( $order ); |
|
237 | + $this->validate_minimum_order_amount($order); |
|
238 | 238 | |
239 | 239 | // This comes from the create account checkbox in the checkout page. |
240 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
240 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
241 | 241 | |
242 | - if ( $create_account ) { |
|
242 | + if ($create_account) { |
|
243 | 243 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
244 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
244 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
245 | 245 | $new_stripe_customer->create_customer(); |
246 | 246 | } |
247 | 247 | |
248 | - $response = $this->create_source( $order ); |
|
248 | + $response = $this->create_source($order); |
|
249 | 249 | |
250 | - if ( ! empty( $response->error ) ) { |
|
251 | - $order->add_order_note( $response->error->message ); |
|
250 | + if ( ! empty($response->error)) { |
|
251 | + $order->add_order_note($response->error->message); |
|
252 | 252 | |
253 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
253 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
254 | 254 | } |
255 | 255 | |
256 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
257 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
256 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
257 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
258 | 258 | } else { |
259 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
259 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
260 | 260 | $order->save(); |
261 | 261 | } |
262 | 262 | |
263 | - WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' ); |
|
263 | + WC_Stripe_Logger::log('Info: Redirecting to Giropay...'); |
|
264 | 264 | |
265 | 265 | return array( |
266 | 266 | 'result' => 'success', |
267 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
267 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
268 | 268 | ); |
269 | - } catch ( WC_Stripe_Exception $e ) { |
|
270 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
271 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
269 | + } catch (WC_Stripe_Exception $e) { |
|
270 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
271 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
272 | 272 | |
273 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
273 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
274 | 274 | |
275 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
276 | - $this->send_failed_order_email( $order_id ); |
|
275 | + if ($order->has_status(array('pending', 'failed'))) { |
|
276 | + $this->send_failed_order_email($order_id); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | return array( |