@@ -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,29 +78,29 @@ 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( 'admin_notices', array( $this, 'check_environment' ) ); |
|
98 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
99 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
100 | - 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('admin_notices', array($this, 'check_environment')); |
|
98 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
99 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
100 | + add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page')); |
|
101 | 101 | |
102 | 102 | // Customer Emails |
103 | - add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); |
|
103 | + add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,19 +110,19 @@ discard block |
||
110 | 110 | * @version 4.0.0 |
111 | 111 | */ |
112 | 112 | public function check_environment() { |
113 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
113 | + if ( ! current_user_can('manage_woocommerce')) { |
|
114 | 114 | return; |
115 | 115 | } |
116 | 116 | |
117 | 117 | $environment_warning = $this->get_environment_warning(); |
118 | 118 | |
119 | - if ( $environment_warning ) { |
|
120 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
119 | + if ($environment_warning) { |
|
120 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
121 | 121 | } |
122 | 122 | |
123 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
124 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
125 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
123 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
124 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
125 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
126 | 126 | echo '</p></div>'; |
127 | 127 | } |
128 | 128 | } |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | * @version 4.0.0 |
136 | 136 | */ |
137 | 137 | public function get_environment_warning() { |
138 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
139 | - $message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' ); |
|
138 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
139 | + $message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe'); |
|
140 | 140 | |
141 | 141 | return $message; |
142 | 142 | } |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | * @return array |
153 | 153 | */ |
154 | 154 | public function get_supported_currency() { |
155 | - return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array( |
|
155 | + return apply_filters('wc_stripe_bitcoin_supported_currencies', array( |
|
156 | 156 | 'USD', |
157 | - ) ); |
|
157 | + )); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @return bool |
166 | 166 | */ |
167 | 167 | public function is_available() { |
168 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
168 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
169 | 169 | return false; |
170 | 170 | } |
171 | 171 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | $icons_str .= $icons['bitcoin']; |
188 | 188 | |
189 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
189 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -197,19 +197,19 @@ discard block |
||
197 | 197 | * @access public |
198 | 198 | */ |
199 | 199 | public function payment_scripts() { |
200 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
200 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | 203 | |
204 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
205 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
204 | + wp_enqueue_style('stripe_paymentfonts'); |
|
205 | + wp_enqueue_script('woocommerce_stripe'); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
209 | 209 | * Initialize Gateway Settings Form Fields. |
210 | 210 | */ |
211 | 211 | public function init_form_fields() { |
212 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' ); |
|
212 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -220,25 +220,25 @@ discard block |
||
220 | 220 | $total = WC()->cart->total; |
221 | 221 | |
222 | 222 | // If paying from order, we need to get total from order not cart. |
223 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
224 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
223 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
224 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
225 | 225 | $total = $order->get_total(); |
226 | 226 | } |
227 | 227 | |
228 | - if ( is_add_payment_method_page() ) { |
|
229 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
230 | - $total = ''; |
|
228 | + if (is_add_payment_method_page()) { |
|
229 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
230 | + $total = ''; |
|
231 | 231 | } else { |
232 | 232 | $pay_button_text = ''; |
233 | 233 | } |
234 | 234 | |
235 | 235 | echo '<div |
236 | 236 | id="stripe-bitcoin-payment-data" |
237 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
238 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
237 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
238 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
239 | 239 | |
240 | - if ( $this->description ) { |
|
241 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
240 | + if ($this->description) { |
|
241 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | echo '</div>'; |
@@ -249,8 +249,8 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @param int $order_id |
251 | 251 | */ |
252 | - public function thankyou_page( $order_id ) { |
|
253 | - $this->get_instructions( $order_id ); |
|
252 | + public function thankyou_page($order_id) { |
|
253 | + $this->get_instructions($order_id); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -262,13 +262,13 @@ discard block |
||
262 | 262 | * @param bool $sent_to_admin |
263 | 263 | * @param bool $plain_text |
264 | 264 | */ |
265 | - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { |
|
265 | + public function email_instructions($order, $sent_to_admin, $plain_text = false) { |
|
266 | 266 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
267 | 267 | |
268 | 268 | $payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method(); |
269 | 269 | |
270 | - if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) { |
|
271 | - $this->get_instructions( $order_id, $plain_text ); |
|
270 | + if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) { |
|
271 | + $this->get_instructions($order_id, $plain_text); |
|
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
@@ -279,38 +279,38 @@ discard block |
||
279 | 279 | * @version 4.0.0 |
280 | 280 | * @param int $order_id |
281 | 281 | */ |
282 | - public function get_instructions( $order_id, $plain_text = false ) { |
|
283 | - $data = get_post_meta( $order_id, '_stripe_bitcoin', true ); |
|
282 | + public function get_instructions($order_id, $plain_text = false) { |
|
283 | + $data = get_post_meta($order_id, '_stripe_bitcoin', true); |
|
284 | 284 | |
285 | - if ( $plain_text ) { |
|
286 | - esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
285 | + if ($plain_text) { |
|
286 | + esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
287 | 287 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
288 | - esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
288 | + esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
289 | 289 | echo $data['amount'] . "\n\n"; |
290 | 290 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
291 | - esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
291 | + esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
292 | 292 | echo $data['address'] . "\n\n"; |
293 | 293 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
294 | - esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
294 | + esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
295 | 295 | echo $data['uri'] . "\n\n"; |
296 | 296 | } else { |
297 | 297 | ?> |
298 | - <h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3> |
|
298 | + <h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3> |
|
299 | 299 | <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
300 | 300 | <li class="woocommerce-order-overview__order order"> |
301 | - <?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?> |
|
301 | + <?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?> |
|
302 | 302 | <strong><?php echo $data['amount']; ?></strong> |
303 | 303 | </li> |
304 | 304 | <li class="woocommerce-order-overview__order order"> |
305 | - <?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?> |
|
305 | + <?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?> |
|
306 | 306 | <strong><?php echo $data['address']; ?></strong> |
307 | 307 | </li> |
308 | 308 | <li class="woocommerce-order-overview__order order"> |
309 | - <?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?> |
|
309 | + <?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?> |
|
310 | 310 | <strong> |
311 | 311 | <?php |
312 | 312 | /* translators: link */ |
313 | - printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] ); |
|
313 | + printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']); |
|
314 | 314 | ?> |
315 | 315 | </strong> |
316 | 316 | </li> |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | * @param object $order |
328 | 328 | * @param object $source_object |
329 | 329 | */ |
330 | - public function save_instructions( $order, $source_object ) { |
|
330 | + public function save_instructions($order, $source_object) { |
|
331 | 331 | $data = array( |
332 | 332 | 'amount' => $source_object->bitcoin->amount, |
333 | 333 | 'address' => $source_object->bitcoin->address, |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | |
337 | 337 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
338 | 338 | |
339 | - update_post_meta( $order_id, '_stripe_bitcoin', $data ); |
|
339 | + update_post_meta($order_id, '_stripe_bitcoin', $data); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
@@ -350,39 +350,39 @@ discard block |
||
350 | 350 | * |
351 | 351 | * @return array|void |
352 | 352 | */ |
353 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
353 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
354 | 354 | try { |
355 | - $order = wc_get_order( $order_id ); |
|
355 | + $order = wc_get_order($order_id); |
|
356 | 356 | |
357 | 357 | // This comes from the create account checkbox in the checkout page. |
358 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
358 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
359 | 359 | |
360 | - if ( $create_account ) { |
|
360 | + if ($create_account) { |
|
361 | 361 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
362 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
362 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
363 | 363 | $new_stripe_customer->create_customer(); |
364 | 364 | } |
365 | 365 | |
366 | - $prepared_source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), $force_save_source ); |
|
366 | + $prepared_source = $this->prepare_source($this->create_source_object(), get_current_user_id(), $force_save_source); |
|
367 | 367 | |
368 | - if ( empty( $prepared_source->source ) ) { |
|
369 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
370 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
368 | + if (empty($prepared_source->source)) { |
|
369 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
370 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | // Store source to order meta. |
374 | - $this->save_source( $order, $prepared_source ); |
|
374 | + $this->save_source($order, $prepared_source); |
|
375 | 375 | |
376 | 376 | |
377 | 377 | // This will throw exception if not valid. |
378 | - $this->validate_minimum_order_amount( $order ); |
|
378 | + $this->validate_minimum_order_amount($order); |
|
379 | 379 | |
380 | - $this->save_instructions( $order, $this->create_source_object() ); |
|
380 | + $this->save_instructions($order, $this->create_source_object()); |
|
381 | 381 | |
382 | 382 | // Mark as on-hold (we're awaiting the payment) |
383 | - $order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) ); |
|
383 | + $order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe')); |
|
384 | 384 | |
385 | - wc_reduce_stock_levels( $order_id ); |
|
385 | + wc_reduce_stock_levels($order_id); |
|
386 | 386 | |
387 | 387 | // Remove cart |
388 | 388 | WC()->cart->empty_cart(); |
@@ -390,16 +390,16 @@ discard block |
||
390 | 390 | // Return thankyou redirect |
391 | 391 | return array( |
392 | 392 | 'result' => 'success', |
393 | - 'redirect' => $this->get_return_url( $order ), |
|
393 | + 'redirect' => $this->get_return_url($order), |
|
394 | 394 | ); |
395 | - } catch ( WC_Stripe_Exception $e ) { |
|
396 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
397 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
395 | + } catch (WC_Stripe_Exception $e) { |
|
396 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
397 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
398 | 398 | |
399 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
399 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
400 | 400 | |
401 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
402 | - $this->send_failed_order_email( $order_id ); |
|
401 | + if ($order->has_status(array('pending', 'failed'))) { |
|
402 | + $this->send_failed_order_email($order_id); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | return array( |