@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | public function __construct() { |
| 48 | 48 | self::$_this = $this; |
| 49 | 49 | |
| 50 | - $this->_gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
| 50 | + $this->_gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
| 51 | 51 | |
| 52 | - $this->statement_descriptor = ! empty( $this->_gateway_settings['statement_descriptor'] ) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); |
|
| 52 | + $this->statement_descriptor = ! empty($this->_gateway_settings['statement_descriptor']) ? $this->_gateway_settings['statement_descriptor'] : wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 53 | 53 | |
| 54 | 54 | $this->init(); |
| 55 | 55 | } |
@@ -66,31 +66,31 @@ discard block |
||
| 66 | 66 | * @version 3.1.0 |
| 67 | 67 | */ |
| 68 | 68 | public function init() { |
| 69 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 70 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 71 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_button' ), 1 ); |
|
| 72 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_apple_pay_separator_html' ), 2 ); |
|
| 73 | - add_action( 'wc_ajax_wc_stripe_apple_pay', array( $this, 'process_apple_pay' ) ); |
|
| 74 | - add_action( 'wc_ajax_wc_stripe_generate_apple_pay_cart', array( $this, 'generate_apple_pay_cart' ) ); |
|
| 75 | - add_action( 'wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array( $this, 'get_shipping_methods' ) ); |
|
| 76 | - add_action( 'wc_ajax_wc_stripe_apple_pay_update_shipping_method', array( $this, 'update_shipping_method' ) ); |
|
| 77 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 69 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 70 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_apple_pay_button'), 1); |
|
| 71 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_button'), 1); |
|
| 72 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_apple_pay_separator_html'), 2); |
|
| 73 | + add_action('wc_ajax_wc_stripe_apple_pay', array($this, 'process_apple_pay')); |
|
| 74 | + add_action('wc_ajax_wc_stripe_generate_apple_pay_cart', array($this, 'generate_apple_pay_cart')); |
|
| 75 | + add_action('wc_ajax_wc_stripe_apple_pay_get_shipping_methods', array($this, 'get_shipping_methods')); |
|
| 76 | + add_action('wc_ajax_wc_stripe_apple_pay_update_shipping_method', array($this, 'update_shipping_method')); |
|
| 77 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Filters the gateway title to reflect Apple Pay. |
| 82 | 82 | * |
| 83 | 83 | */ |
| 84 | - public function filter_gateway_title( $title, $id ) { |
|
| 84 | + public function filter_gateway_title($title, $id) { |
|
| 85 | 85 | global $post; |
| 86 | 86 | |
| 87 | - if ( ! is_object( $post ) ) { |
|
| 87 | + if ( ! is_object($post)) { |
|
| 88 | 88 | return $title; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 91 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 92 | 92 | |
| 93 | - if ( 'stripe' === $id && ! empty( $method_title ) ) { |
|
| 93 | + if ('stripe' === $id && ! empty($method_title)) { |
|
| 94 | 94 | return $method_title; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -104,38 +104,38 @@ discard block |
||
| 104 | 104 | * @version 3.1.0 |
| 105 | 105 | */ |
| 106 | 106 | public function payment_scripts() { |
| 107 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 107 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 108 | 108 | return; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if ( ! $this->is_supported_product_type() ) { |
|
| 111 | + if ( ! $this->is_supported_product_type()) { |
|
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 115 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 116 | 116 | |
| 117 | - wp_enqueue_style( 'stripe_apple_pay', plugins_url( 'assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION ); |
|
| 117 | + wp_enqueue_style('stripe_apple_pay', plugins_url('assets/css/stripe-apple-pay.css', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION); |
|
| 118 | 118 | |
| 119 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 120 | - wp_enqueue_script( 'woocommerce_stripe_apple_pay', plugins_url( 'assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 119 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 120 | + wp_enqueue_script('woocommerce_stripe_apple_pay', plugins_url('assets/js/stripe-apple-pay' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
| 121 | 121 | |
| 122 | 122 | $publishable_key = 'yes' === $this->_gateway_settings['testmode'] ? $this->_gateway_settings['test_publishable_key'] : $this->_gateway_settings['publishable_key']; |
| 123 | 123 | |
| 124 | 124 | $stripe_params = array( |
| 125 | 125 | 'key' => $publishable_key, |
| 126 | 126 | 'currency_code' => get_woocommerce_currency(), |
| 127 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 127 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 128 | 128 | 'label' => $this->statement_descriptor, |
| 129 | - 'ajaxurl' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 130 | - 'stripe_apple_pay_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_nonce' ), |
|
| 131 | - 'stripe_apple_pay_cart_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_cart_nonce' ), |
|
| 132 | - 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_get_shipping_methods_nonce' ), |
|
| 133 | - 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_update_shipping_method_nonce' ), |
|
| 129 | + 'ajaxurl' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 130 | + 'stripe_apple_pay_nonce' => wp_create_nonce('_wc_stripe_apple_pay_nonce'), |
|
| 131 | + 'stripe_apple_pay_cart_nonce' => wp_create_nonce('_wc_stripe_apple_pay_cart_nonce'), |
|
| 132 | + 'stripe_apple_pay_get_shipping_methods_nonce' => wp_create_nonce('_wc_stripe_apple_pay_get_shipping_methods_nonce'), |
|
| 133 | + 'stripe_apple_pay_update_shipping_method_nonce' => wp_create_nonce('_wc_stripe_apple_pay_update_shipping_method_nonce'), |
|
| 134 | 134 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 135 | 135 | 'is_cart_page' => is_cart() ? 'yes' : 'no', |
| 136 | 136 | ); |
| 137 | 137 | |
| 138 | - wp_localize_script( 'woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters( 'wc_stripe_apple_pay_params', $stripe_params ) ); |
|
| 138 | + wp_localize_script('woocommerce_stripe_apple_pay', 'wc_stripe_apple_pay_params', apply_filters('wc_stripe_apple_pay_params', $stripe_params)); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -143,8 +143,8 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | */ |
| 145 | 145 | public function is_supported_product_type() { |
| 146 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 147 | - if ( 'subscription' === $values['data']->product_type ) { |
|
| 146 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 147 | + if ('subscription' === $values['data']->product_type) { |
|
| 148 | 148 | return false; |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -167,19 +167,19 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | if ( |
| 169 | 169 | 'yes' !== $this->_gateway_settings['apple_pay'] |
| 170 | - || ! isset( $gateways['stripe'] ) |
|
| 170 | + || ! isset($gateways['stripe']) |
|
| 171 | 171 | ) { |
| 172 | 172 | return; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - if ( ! $this->is_supported_product_type() ) { |
|
| 175 | + if ( ! $this->is_supported_product_type()) { |
|
| 176 | 176 | return; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - $apple_pay_button = ! empty( $this->_gateway_settings['apple_pay_button'] ) ? $this->_gateway_settings['apple_pay_button'] : 'black'; |
|
| 180 | - $button_lang = ! empty( $this->_gateway_settings['apple_pay_button_lang'] ) ? strtolower( $this->_gateway_settings['apple_pay_button_lang'] ) : 'en'; |
|
| 179 | + $apple_pay_button = ! empty($this->_gateway_settings['apple_pay_button']) ? $this->_gateway_settings['apple_pay_button'] : 'black'; |
|
| 180 | + $button_lang = ! empty($this->_gateway_settings['apple_pay_button_lang']) ? strtolower($this->_gateway_settings['apple_pay_button_lang']) : 'en'; |
|
| 181 | 181 | ?> |
| 182 | - <button class="apple-pay-button" lang="<?php echo esc_attr( $button_lang ); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr( $apple_pay_button ); ?>;"></button> |
|
| 182 | + <button class="apple-pay-button" lang="<?php echo esc_attr($button_lang); ?>" style="-webkit-appearance: -apple-pay-button; -apple-pay-button-type: buy; -apple-pay-button-style: <?php echo esc_attr($apple_pay_button); ?>;"></button> |
|
| 183 | 183 | <?php |
| 184 | 184 | } |
| 185 | 185 | |
@@ -198,16 +198,16 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | if ( |
| 200 | 200 | 'yes' !== $this->_gateway_settings['apple_pay'] |
| 201 | - || ! isset( $gateways['stripe'] ) |
|
| 201 | + || ! isset($gateways['stripe']) |
|
| 202 | 202 | ) { |
| 203 | 203 | return; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - if ( ! $this->is_supported_product_type() ) { |
|
| 206 | + if ( ! $this->is_supported_product_type()) { |
|
| 207 | 207 | return; |
| 208 | 208 | } |
| 209 | 209 | ?> |
| 210 | - <p class="apple-pay-button-checkout-separator">- <?php esc_html_e( 'Or', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
| 210 | + <p class="apple-pay-button-checkout-separator">- <?php esc_html_e('Or', 'woocommerce-gateway-stripe'); ?> -</p> |
|
| 211 | 211 | <?php |
| 212 | 212 | } |
| 213 | 213 | |
@@ -218,11 +218,11 @@ discard block |
||
| 218 | 218 | * @version 3.1.0 |
| 219 | 219 | */ |
| 220 | 220 | public function generate_apple_pay_cart() { |
| 221 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce' ) ) { |
|
| 222 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 221 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_cart_nonce')) { |
|
| 222 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - wp_send_json( array( 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 225 | + wp_send_json(array('line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -232,29 +232,29 @@ discard block |
||
| 232 | 232 | * @version 3.1.0 |
| 233 | 233 | * @param array $address |
| 234 | 234 | */ |
| 235 | - public function calculate_shipping( $address = array() ) { |
|
| 236 | - $country = strtoupper( $address['countryCode'] ); |
|
| 237 | - $state = strtoupper( $address['administrativeArea'] ); |
|
| 235 | + public function calculate_shipping($address = array()) { |
|
| 236 | + $country = strtoupper($address['countryCode']); |
|
| 237 | + $state = strtoupper($address['administrativeArea']); |
|
| 238 | 238 | $postcode = $address['postalCode']; |
| 239 | 239 | $city = $address['locality']; |
| 240 | 240 | |
| 241 | 241 | WC()->shipping->reset_shipping(); |
| 242 | 242 | |
| 243 | - if ( $postcode && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 244 | - throw new Exception( __( 'Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
| 245 | - } elseif ( $postcode ) { |
|
| 246 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 243 | + if ($postcode && ! WC_Validation::is_postcode($postcode, $country)) { |
|
| 244 | + throw new Exception(__('Please enter a valid postcode/ZIP.', 'woocommerce-gateway-stripe')); |
|
| 245 | + } elseif ($postcode) { |
|
| 246 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if ( $country ) { |
|
| 250 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 251 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 249 | + if ($country) { |
|
| 250 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 251 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 252 | 252 | } else { |
| 253 | 253 | WC()->customer->set_to_base(); |
| 254 | 254 | WC()->customer->set_shipping_to_base(); |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - WC()->customer->calculated_shipping( true ); |
|
| 257 | + WC()->customer->calculated_shipping(true); |
|
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | 260 | * Set the shipping package. |
@@ -276,17 +276,17 @@ discard block |
||
| 276 | 276 | $packages[0]['destination']['postcode'] = $postcode; |
| 277 | 277 | $packages[0]['destination']['city'] = $city; |
| 278 | 278 | |
| 279 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 280 | - if ( $item['data']->needs_shipping() ) { |
|
| 281 | - if ( isset( $item['line_total'] ) ) { |
|
| 279 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 280 | + if ($item['data']->needs_shipping()) { |
|
| 281 | + if (isset($item['line_total'])) { |
|
| 282 | 282 | $packages[0]['contents_cost'] += $item['line_total']; |
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 287 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 288 | 288 | |
| 289 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 289 | + WC()->shipping->calculate_shipping($packages); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -296,18 +296,18 @@ discard block |
||
| 296 | 296 | * @version 3.1.0 |
| 297 | 297 | */ |
| 298 | 298 | public function get_shipping_methods() { |
| 299 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce' ) ) { |
|
| 300 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 299 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_get_shipping_methods_nonce')) { |
|
| 300 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 304 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 303 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 304 | + define('WOOCOMMERCE_CART', true); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | try { |
| 308 | - $address = array_map( 'wc_clean', $_POST['address'] ); |
|
| 308 | + $address = array_map('wc_clean', $_POST['address']); |
|
| 309 | 309 | |
| 310 | - $this->calculate_shipping( $address ); |
|
| 310 | + $this->calculate_shipping($address); |
|
| 311 | 311 | |
| 312 | 312 | // Set the shipping options. |
| 313 | 313 | $currency = get_woocommerce_currency(); |
@@ -315,13 +315,13 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | $packages = WC()->shipping->get_packages(); |
| 317 | 317 | |
| 318 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 319 | - foreach ( $packages as $package_key => $package ) { |
|
| 320 | - if ( empty( $package['rates'] ) ) { |
|
| 321 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 318 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 319 | + foreach ($packages as $package_key => $package) { |
|
| 320 | + if (empty($package['rates'])) { |
|
| 321 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 324 | + foreach ($package['rates'] as $key => $rate) { |
|
| 325 | 325 | $data[] = array( |
| 326 | 326 | 'id' => $rate->id, |
| 327 | 327 | 'label' => $rate->label, |
@@ -335,16 +335,16 @@ discard block |
||
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | // Auto select the first shipping method. |
| 338 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 338 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 339 | 339 | |
| 340 | 340 | WC()->cart->calculate_totals(); |
| 341 | 341 | |
| 342 | - wp_send_json( array( 'success' => 'true', 'shipping_methods' => $this->build_shipping_methods( $data ), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 342 | + wp_send_json(array('success' => 'true', 'shipping_methods' => $this->build_shipping_methods($data), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 343 | 343 | } else { |
| 344 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 344 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 345 | 345 | } |
| 346 | - } catch ( Exception $e ) { |
|
| 347 | - wp_send_json( array( 'success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 346 | + } catch (Exception $e) { |
|
| 347 | + wp_send_json(array('success' => 'false', 'shipping_methods' => array(), 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | |
@@ -355,29 +355,29 @@ discard block |
||
| 355 | 355 | * @version 3.1.0 |
| 356 | 356 | */ |
| 357 | 357 | public function update_shipping_method() { |
| 358 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 359 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 358 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 359 | + define('WOOCOMMERCE_CART', true); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce' ) ) { |
|
| 363 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 362 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_update_shipping_method_nonce')) { |
|
| 363 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - $selected_shipping_method = array_map( 'wc_clean', $_POST['selected_shipping_method'] ); |
|
| 366 | + $selected_shipping_method = array_map('wc_clean', $_POST['selected_shipping_method']); |
|
| 367 | 367 | |
| 368 | - WC()->session->set( 'chosen_shipping_methods', array( $selected_shipping_method['identifier'] ) ); |
|
| 368 | + WC()->session->set('chosen_shipping_methods', array($selected_shipping_method['identifier'])); |
|
| 369 | 369 | |
| 370 | 370 | WC()->cart->calculate_totals(); |
| 371 | 371 | |
| 372 | 372 | // Send back the new cart total. |
| 373 | 373 | $currency = get_woocommerce_currency(); |
| 374 | - $tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) ); |
|
| 374 | + $tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp)); |
|
| 375 | 375 | $data = array( |
| 376 | 376 | 'total' => WC()->cart->total, |
| 377 | 377 | ); |
| 378 | 378 | |
| 379 | 379 | // Include fees and taxes as displayItems. |
| 380 | - foreach ( WC()->cart->fees as $key => $fee ) { |
|
| 380 | + foreach (WC()->cart->fees as $key => $fee) { |
|
| 381 | 381 | $data['items'][] = array( |
| 382 | 382 | 'label' => $fee->name, |
| 383 | 383 | 'amount' => array( |
@@ -386,9 +386,9 @@ discard block |
||
| 386 | 386 | ), |
| 387 | 387 | ); |
| 388 | 388 | } |
| 389 | - if ( 0 < $tax_total ) { |
|
| 389 | + if (0 < $tax_total) { |
|
| 390 | 390 | $data['items'][] = array( |
| 391 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 391 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 392 | 392 | 'amount' => array( |
| 393 | 393 | 'currency' => $currency, |
| 394 | 394 | 'value' => $tax_total, |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | ); |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - wp_send_json( array( 'success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total ) ); |
|
| 399 | + wp_send_json(array('success' => 'true', 'line_items' => $this->build_line_items(), 'total' => WC()->cart->total)); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -407,35 +407,35 @@ discard block |
||
| 407 | 407 | * @version 3.1.0 |
| 408 | 408 | */ |
| 409 | 409 | public function process_apple_pay() { |
| 410 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_apple_pay_nonce' ) ) { |
|
| 411 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 410 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_apple_pay_nonce')) { |
|
| 411 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | try { |
| 415 | - $result = array_map( 'wc_clean', $_POST['result'] ); |
|
| 415 | + $result = array_map('wc_clean', $_POST['result']); |
|
| 416 | 416 | |
| 417 | - $order = $this->create_order( $result ); |
|
| 417 | + $order = $this->create_order($result); |
|
| 418 | 418 | |
| 419 | 419 | // Handle payment. |
| 420 | - if ( $order->get_total() > 0 ) { |
|
| 420 | + if ($order->get_total() > 0) { |
|
| 421 | 421 | |
| 422 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 423 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
| 422 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 423 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - WC_Stripe::log( "Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}" ); |
|
| 426 | + WC_Stripe::log("Info: Begin processing payment for order $order->id for the amount of {$order->get_total()}"); |
|
| 427 | 427 | |
| 428 | 428 | // Make the request. |
| 429 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $result['token']['id'] ) ); |
|
| 429 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $result['token']['id'])); |
|
| 430 | 430 | |
| 431 | - if ( is_wp_error( $response ) ) { |
|
| 431 | + if (is_wp_error($response)) { |
|
| 432 | 432 | $localized_messages = $this->get_localized_messages(); |
| 433 | 433 | |
| 434 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
| 434 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | // Process valid response. |
| 438 | - $this->process_response( $response, $order ); |
|
| 438 | + $this->process_response($response, $order); |
|
| 439 | 439 | } else { |
| 440 | 440 | $order->payment_complete(); |
| 441 | 441 | } |
@@ -443,24 +443,24 @@ discard block |
||
| 443 | 443 | // Remove cart. |
| 444 | 444 | WC()->cart->empty_cart(); |
| 445 | 445 | |
| 446 | - update_post_meta( $order->id, '_customer_user', get_current_user_id() ); |
|
| 447 | - update_post_meta( $order->id, '_payment_method_title', __( 'Apple Pay (Stripe)', 'woocommerce-gateway-stripe' ) ); |
|
| 446 | + update_post_meta($order->id, '_customer_user', get_current_user_id()); |
|
| 447 | + update_post_meta($order->id, '_payment_method_title', __('Apple Pay (Stripe)', 'woocommerce-gateway-stripe')); |
|
| 448 | 448 | |
| 449 | 449 | // Return thank you page redirect. |
| 450 | - wp_send_json( array( |
|
| 450 | + wp_send_json(array( |
|
| 451 | 451 | 'success' => 'true', |
| 452 | - 'redirect' => $this->get_return_url( $order ), |
|
| 453 | - ) ); |
|
| 452 | + 'redirect' => $this->get_return_url($order), |
|
| 453 | + )); |
|
| 454 | 454 | |
| 455 | - } catch ( Exception $e ) { |
|
| 456 | - WC()->session->set( 'refresh_totals', true ); |
|
| 457 | - WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 455 | + } catch (Exception $e) { |
|
| 456 | + WC()->session->set('refresh_totals', true); |
|
| 457 | + WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 458 | 458 | |
| 459 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 460 | - $this->send_failed_order_email( $order->id ); |
|
| 459 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 460 | + $this->send_failed_order_email($order->id); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - wp_send_json( array( 'success' => 'false', 'msg' => $e->getMessage() ) ); |
|
| 463 | + wp_send_json(array('success' => 'false', 'msg' => $e->getMessage())); |
|
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | |
@@ -470,14 +470,14 @@ discard block |
||
| 470 | 470 | * @param string $source token |
| 471 | 471 | * @return array() |
| 472 | 472 | */ |
| 473 | - protected function generate_payment_request( $order, $source ) { |
|
| 473 | + protected function generate_payment_request($order, $source) { |
|
| 474 | 474 | $post_data = array(); |
| 475 | - $post_data['currency'] = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() ); |
|
| 476 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 477 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
| 475 | + $post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency()); |
|
| 476 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 477 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
| 478 | 478 | $post_data['capture'] = 'yes' === $this->_gateway_settings['capture'] ? 'true' : 'false'; |
| 479 | 479 | |
| 480 | - if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 480 | + if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 481 | 481 | $post_data['receipt_email'] = $order->billing_email; |
| 482 | 482 | } |
| 483 | 483 | |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | * @param WC_Order $order |
| 493 | 493 | * @param object $source |
| 494 | 494 | */ |
| 495 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order ); |
|
| 495 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | /** |
@@ -501,14 +501,14 @@ discard block |
||
| 501 | 501 | * @since 3.1.0 |
| 502 | 502 | * @version 3.1.0 |
| 503 | 503 | */ |
| 504 | - public function build_shipping_methods( $shipping_methods ) { |
|
| 505 | - if ( empty( $shipping_methods ) ) { |
|
| 504 | + public function build_shipping_methods($shipping_methods) { |
|
| 505 | + if (empty($shipping_methods)) { |
|
| 506 | 506 | return array(); |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | $shipping = array(); |
| 510 | 510 | |
| 511 | - foreach ( $shipping_methods as $method ) { |
|
| 511 | + foreach ($shipping_methods as $method) { |
|
| 512 | 512 | $shipping[] = array( |
| 513 | 513 | 'label' => $method['label'], |
| 514 | 514 | 'detail' => '', |
@@ -527,53 +527,53 @@ discard block |
||
| 527 | 527 | * @version 3.1.0 |
| 528 | 528 | */ |
| 529 | 529 | public function build_line_items() { |
| 530 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 531 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 530 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 531 | + define('WOOCOMMERCE_CART', true); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - $decimals = apply_filters( 'wc_stripe_apple_pay_decimals', 2 ); |
|
| 534 | + $decimals = apply_filters('wc_stripe_apple_pay_decimals', 2); |
|
| 535 | 535 | |
| 536 | 536 | $items = array(); |
| 537 | 537 | |
| 538 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 539 | - $amount = wc_format_decimal( $values['line_subtotal'], $decimals ); |
|
| 538 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 539 | + $amount = wc_format_decimal($values['line_subtotal'], $decimals); |
|
| 540 | 540 | $quantity_label = 1 < $values['quantity'] ? ' (x' . $values['quantity'] . ')' : ''; |
| 541 | 541 | |
| 542 | 542 | $item = array( |
| 543 | 543 | 'type' => 'final', |
| 544 | 544 | 'label' => $values['data']->post->post_title . $quantity_label, |
| 545 | - 'amount' => wc_format_decimal( $amount, $decimals ), |
|
| 545 | + 'amount' => wc_format_decimal($amount, $decimals), |
|
| 546 | 546 | ); |
| 547 | 547 | |
| 548 | 548 | $items[] = $item; |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), $decimals ); |
|
| 552 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals ); |
|
| 553 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, $decimals ); |
|
| 554 | - $item_total = wc_format_decimal( WC()->cart->cart_contents_total, $decimals ) + $discounts; |
|
| 555 | - $order_total = wc_format_decimal( $item_total + $tax + $shipping, $decimals ); |
|
| 551 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), $decimals); |
|
| 552 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, $decimals); |
|
| 553 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, $decimals); |
|
| 554 | + $item_total = wc_format_decimal(WC()->cart->cart_contents_total, $decimals) + $discounts; |
|
| 555 | + $order_total = wc_format_decimal($item_total + $tax + $shipping, $decimals); |
|
| 556 | 556 | |
| 557 | - if ( wc_tax_enabled() ) { |
|
| 557 | + if (wc_tax_enabled()) { |
|
| 558 | 558 | $items[] = array( |
| 559 | 559 | 'type' => 'final', |
| 560 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 560 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 561 | 561 | 'amount' => $tax, |
| 562 | 562 | ); |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - if ( WC()->cart->needs_shipping() ) { |
|
| 565 | + if (WC()->cart->needs_shipping()) { |
|
| 566 | 566 | $items[] = array( |
| 567 | 567 | 'type' => 'final', |
| 568 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 568 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 569 | 569 | 'amount' => $shipping, |
| 570 | 570 | ); |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - if ( WC()->cart->has_discount() ) { |
|
| 573 | + if (WC()->cart->has_discount()) { |
|
| 574 | 574 | $items[] = array( |
| 575 | 575 | 'type' => 'final', |
| 576 | - 'label' => __( 'Discount', 'woocommerce-gateway-stripe' ), |
|
| 576 | + 'label' => __('Discount', 'woocommerce-gateway-stripe'), |
|
| 577 | 577 | 'amount' => $discounts, |
| 578 | 578 | ); |
| 579 | 579 | } |
@@ -589,24 +589,24 @@ discard block |
||
| 589 | 589 | * @param array $data |
| 590 | 590 | * @return object $order |
| 591 | 591 | */ |
| 592 | - public function create_order( $data = array() ) { |
|
| 593 | - if ( empty( $data ) ) { |
|
| 594 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 592 | + public function create_order($data = array()) { |
|
| 593 | + if (empty($data)) { |
|
| 594 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | $order = wc_create_order(); |
| 598 | 598 | |
| 599 | - if ( is_wp_error( $order ) ) { |
|
| 600 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 520 ) ); |
|
| 601 | - } elseif ( false === $order ) { |
|
| 602 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 521 ) ); |
|
| 599 | + if (is_wp_error($order)) { |
|
| 600 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 520)); |
|
| 601 | + } elseif (false === $order) { |
|
| 602 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 521)); |
|
| 603 | 603 | } else { |
| 604 | 604 | $order_id = $order->id; |
| 605 | - do_action( 'woocommerce_new_order', $order_id ); |
|
| 605 | + do_action('woocommerce_new_order', $order_id); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | // Store the line items to the new/resumed order |
| 609 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 609 | + foreach (WC()->cart->get_cart() as $cart_item_key => $values) { |
|
| 610 | 610 | $item_id = $order->add_product( |
| 611 | 611 | $values['data'], |
| 612 | 612 | $values['quantity'], |
@@ -622,47 +622,47 @@ discard block |
||
| 622 | 622 | ) |
| 623 | 623 | ); |
| 624 | 624 | |
| 625 | - if ( ! $item_id ) { |
|
| 626 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 525 ) ); |
|
| 625 | + if ( ! $item_id) { |
|
| 626 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 525)); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | // Allow plugins to add order item meta |
| 630 | - do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key ); |
|
| 630 | + do_action('woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key); |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | // Store fees |
| 634 | - foreach ( WC()->cart->get_fees() as $fee_key => $fee ) { |
|
| 635 | - $item_id = $order->add_fee( $fee ); |
|
| 634 | + foreach (WC()->cart->get_fees() as $fee_key => $fee) { |
|
| 635 | + $item_id = $order->add_fee($fee); |
|
| 636 | 636 | |
| 637 | - if ( ! $item_id ) { |
|
| 638 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 526 ) ); |
|
| 637 | + if ( ! $item_id) { |
|
| 638 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 526)); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | // Allow plugins to add order item meta to fees |
| 642 | - do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key ); |
|
| 642 | + do_action('woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | // Store tax rows |
| 646 | - foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { |
|
| 647 | - if ( $tax_rate_id && ! $order->add_tax( $tax_rate_id, WC()->cart->get_tax_amount( $tax_rate_id ), WC()->cart->get_shipping_tax_amount( $tax_rate_id ) ) && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { |
|
| 648 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 528 ) ); |
|
| 646 | + foreach (array_keys(WC()->cart->taxes + WC()->cart->shipping_taxes) as $tax_rate_id) { |
|
| 647 | + if ($tax_rate_id && ! $order->add_tax($tax_rate_id, WC()->cart->get_tax_amount($tax_rate_id), WC()->cart->get_shipping_tax_amount($tax_rate_id)) && apply_filters('woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated') !== $tax_rate_id) { |
|
| 648 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 528)); |
|
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | // Store coupons |
| 653 | - foreach ( WC()->cart->get_coupons() as $code => $coupon ) { |
|
| 654 | - if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) { |
|
| 655 | - throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe' ), 529 ) ); |
|
| 653 | + foreach (WC()->cart->get_coupons() as $code => $coupon) { |
|
| 654 | + if ( ! $order->add_coupon($code, WC()->cart->get_coupon_discount_amount($code), WC()->cart->get_coupon_discount_tax_amount($code))) { |
|
| 655 | + throw new Exception(sprintf(__('Error %d: Unable to create order. Please try again.', 'woocommerce-gateway-stripe'), 529)); |
|
| 656 | 656 | } |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | // Billing address |
| 660 | 660 | $billing_address = array(); |
| 661 | - if ( ! empty( $data['token']['card'] ) ) { |
|
| 661 | + if ( ! empty($data['token']['card'])) { |
|
| 662 | 662 | // Name from Stripe is a full name string. |
| 663 | - $name = explode( ' ', $data['token']['card']['name'] ); |
|
| 664 | - $lastname = array_pop( $name ); |
|
| 665 | - $firstname = implode( ' ', $name ); |
|
| 663 | + $name = explode(' ', $data['token']['card']['name']); |
|
| 664 | + $lastname = array_pop($name); |
|
| 665 | + $firstname = implode(' ', $name); |
|
| 666 | 666 | $billing_address['first_name'] = $firstname; |
| 667 | 667 | $billing_address['last_name'] = $lastname; |
| 668 | 668 | $billing_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | |
| 678 | 678 | // Shipping address. |
| 679 | 679 | $shipping_address = array(); |
| 680 | - if ( WC()->cart->needs_shipping() && ! empty( $data['shippingContact'] ) ) { |
|
| 680 | + if (WC()->cart->needs_shipping() && ! empty($data['shippingContact'])) { |
|
| 681 | 681 | $shipping_address['first_name'] = $data['shippingContact']['givenName']; |
| 682 | 682 | $shipping_address['last_name'] = $data['shippingContact']['familyName']; |
| 683 | 683 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | $shipping_address['city'] = $data['shippingContact']['locality']; |
| 689 | 689 | $shipping_address['state'] = $data['shippingContact']['administrativeArea']; |
| 690 | 690 | $shipping_address['postcode'] = $data['shippingContact']['postalCode']; |
| 691 | - } elseif ( ! empty( $data['shippingContact'] ) ) { |
|
| 691 | + } elseif ( ! empty($data['shippingContact'])) { |
|
| 692 | 692 | $shipping_address['first_name'] = $firstname; |
| 693 | 693 | $shipping_address['last_name'] = $lastname; |
| 694 | 694 | $shipping_address['email'] = $data['shippingContact']['emailAddress']; |
@@ -701,34 +701,34 @@ discard block |
||
| 701 | 701 | $shipping_address['postcode'] = $data['token']['card']['address_zip']; |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | - $order->set_address( $billing_address, 'billing' ); |
|
| 705 | - $order->set_address( $shipping_address, 'shipping' ); |
|
| 704 | + $order->set_address($billing_address, 'billing'); |
|
| 705 | + $order->set_address($shipping_address, 'shipping'); |
|
| 706 | 706 | |
| 707 | - WC()->shipping->calculate_shipping( WC()->cart->get_shipping_packages() ); |
|
| 707 | + WC()->shipping->calculate_shipping(WC()->cart->get_shipping_packages()); |
|
| 708 | 708 | |
| 709 | 709 | // Get the rate object selected by user. |
| 710 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
| 711 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 710 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
| 711 | + foreach ($package['rates'] as $key => $rate) { |
|
| 712 | 712 | // Loop through user chosen shipping methods. |
| 713 | - foreach ( WC()->session->get( 'chosen_shipping_methods' ) as $method ) { |
|
| 714 | - if ( $method === $key ) { |
|
| 715 | - $order->add_shipping( $rate ); |
|
| 713 | + foreach (WC()->session->get('chosen_shipping_methods') as $method) { |
|
| 714 | + if ($method === $key) { |
|
| 715 | + $order->add_shipping($rate); |
|
| 716 | 716 | } |
| 717 | 717 | } |
| 718 | 718 | } |
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 722 | - $order->set_payment_method( $available_gateways['stripe'] ); |
|
| 723 | - $order->set_total( WC()->cart->shipping_total, 'shipping' ); |
|
| 724 | - $order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' ); |
|
| 725 | - $order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' ); |
|
| 726 | - $order->set_total( WC()->cart->tax_total, 'tax' ); |
|
| 727 | - $order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' ); |
|
| 728 | - $order->set_total( WC()->cart->total ); |
|
| 722 | + $order->set_payment_method($available_gateways['stripe']); |
|
| 723 | + $order->set_total(WC()->cart->shipping_total, 'shipping'); |
|
| 724 | + $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount'); |
|
| 725 | + $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax'); |
|
| 726 | + $order->set_total(WC()->cart->tax_total, 'tax'); |
|
| 727 | + $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax'); |
|
| 728 | + $order->set_total(WC()->cart->total); |
|
| 729 | 729 | |
| 730 | 730 | // If we got here, the order was created without problems! |
| 731 | - wc_transaction_query( 'commit' ); |
|
| 731 | + wc_transaction_query('commit'); |
|
| 732 | 732 | |
| 733 | 733 | return $order; |
| 734 | 734 | } |
@@ -1,184 +1,184 @@ |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | -return apply_filters( 'wc_stripe_settings', |
|
| 6 | +return apply_filters('wc_stripe_settings', |
|
| 7 | 7 | array( |
| 8 | 8 | 'enabled' => array( |
| 9 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
| 10 | - 'label' => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ), |
|
| 9 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
| 10 | + 'label' => __('Enable Stripe', 'woocommerce-gateway-stripe'), |
|
| 11 | 11 | 'type' => 'checkbox', |
| 12 | 12 | 'description' => '', |
| 13 | 13 | 'default' => 'no', |
| 14 | 14 | ), |
| 15 | 15 | 'title' => array( |
| 16 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
| 16 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
| 17 | 17 | 'type' => 'text', |
| 18 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
| 19 | - 'default' => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ), |
|
| 18 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
| 19 | + 'default' => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'), |
|
| 20 | 20 | 'desc_tip' => true, |
| 21 | 21 | ), |
| 22 | 22 | 'description' => array( |
| 23 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
| 23 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
| 24 | 24 | 'type' => 'text', |
| 25 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
| 26 | - 'default' => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe' ), |
|
| 25 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
| 26 | + 'default' => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'), |
|
| 27 | 27 | 'desc_tip' => true, |
| 28 | 28 | ), |
| 29 | 29 | 'testmode' => array( |
| 30 | - 'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ), |
|
| 31 | - 'label' => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ), |
|
| 30 | + 'title' => __('Test mode', 'woocommerce-gateway-stripe'), |
|
| 31 | + 'label' => __('Enable Test Mode', 'woocommerce-gateway-stripe'), |
|
| 32 | 32 | 'type' => 'checkbox', |
| 33 | - 'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ), |
|
| 33 | + 'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'), |
|
| 34 | 34 | 'default' => 'yes', |
| 35 | 35 | 'desc_tip' => true, |
| 36 | 36 | ), |
| 37 | 37 | 'test_secret_key' => array( |
| 38 | - 'title' => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ), |
|
| 38 | + 'title' => __('Test Secret Key', 'woocommerce-gateway-stripe'), |
|
| 39 | 39 | 'type' => 'text', |
| 40 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
| 40 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
| 41 | 41 | 'default' => '', |
| 42 | 42 | 'desc_tip' => true, |
| 43 | 43 | ), |
| 44 | 44 | 'test_publishable_key' => array( |
| 45 | - 'title' => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ), |
|
| 45 | + 'title' => __('Test Publishable Key', 'woocommerce-gateway-stripe'), |
|
| 46 | 46 | 'type' => 'text', |
| 47 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
| 47 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
| 48 | 48 | 'default' => '', |
| 49 | 49 | 'desc_tip' => true, |
| 50 | 50 | ), |
| 51 | 51 | 'secret_key' => array( |
| 52 | - 'title' => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ), |
|
| 52 | + 'title' => __('Live Secret Key', 'woocommerce-gateway-stripe'), |
|
| 53 | 53 | 'type' => 'text', |
| 54 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
| 54 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
| 55 | 55 | 'default' => '', |
| 56 | 56 | 'desc_tip' => true, |
| 57 | 57 | ), |
| 58 | 58 | 'publishable_key' => array( |
| 59 | - 'title' => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ), |
|
| 59 | + 'title' => __('Live Publishable Key', 'woocommerce-gateway-stripe'), |
|
| 60 | 60 | 'type' => 'text', |
| 61 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
| 61 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
| 62 | 62 | 'default' => '', |
| 63 | 63 | 'desc_tip' => true, |
| 64 | 64 | ), |
| 65 | 65 | 'statement_descriptor' => array( |
| 66 | - 'title' => __( 'Statement Descriptor', 'woocommerce-gateway-stripe' ), |
|
| 66 | + 'title' => __('Statement Descriptor', 'woocommerce-gateway-stripe'), |
|
| 67 | 67 | 'type' => 'text', |
| 68 | - 'description' => __( 'Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe' ), |
|
| 68 | + 'description' => __('Extra information about a charge. This will appear on your customer’s credit card statement.', 'woocommerce-gateway-stripe'), |
|
| 69 | 69 | 'default' => '', |
| 70 | 70 | 'desc_tip' => true, |
| 71 | 71 | ), |
| 72 | 72 | 'capture' => array( |
| 73 | - 'title' => __( 'Capture', 'woocommerce-gateway-stripe' ), |
|
| 74 | - 'label' => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ), |
|
| 73 | + 'title' => __('Capture', 'woocommerce-gateway-stripe'), |
|
| 74 | + 'label' => __('Capture charge immediately', 'woocommerce-gateway-stripe'), |
|
| 75 | 75 | 'type' => 'checkbox', |
| 76 | - 'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ), |
|
| 76 | + 'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'), |
|
| 77 | 77 | 'default' => 'yes', |
| 78 | 78 | 'desc_tip' => true, |
| 79 | 79 | ), |
| 80 | 80 | 'stripe_checkout' => array( |
| 81 | - 'title' => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
| 82 | - 'label' => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
| 81 | + 'title' => __('Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
| 82 | + 'label' => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
| 83 | 83 | 'type' => 'checkbox', |
| 84 | - 'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ), |
|
| 84 | + 'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'), |
|
| 85 | 85 | 'default' => 'no', |
| 86 | 86 | 'desc_tip' => true, |
| 87 | 87 | ), |
| 88 | 88 | 'allow_remember_me' => array( |
| 89 | - 'title' => __( 'Allow Remember Me', 'woocommerce-gateway-stripe' ), |
|
| 90 | - 'label' => __( 'Enable Remember Me', 'woocommerce-gateway-stripe' ), |
|
| 89 | + 'title' => __('Allow Remember Me', 'woocommerce-gateway-stripe'), |
|
| 90 | + 'label' => __('Enable Remember Me', 'woocommerce-gateway-stripe'), |
|
| 91 | 91 | 'type' => 'checkbox', |
| 92 | - 'description' => __( 'If enabled, this option shows a "Remember Me" checkbox which when checked by the customer will persist their details.', 'woocommerce-gateway-stripe' ), |
|
| 92 | + 'description' => __('If enabled, this option shows a "Remember Me" checkbox which when checked by the customer will persist their details.', 'woocommerce-gateway-stripe'), |
|
| 93 | 93 | 'default' => 'yes', |
| 94 | 94 | 'desc_tip' => true, |
| 95 | 95 | ), |
| 96 | 96 | 'stripe_checkout_locale' => array( |
| 97 | - 'title' => __( 'Stripe Checkout locale', 'woocommerce-gateway-stripe' ), |
|
| 97 | + 'title' => __('Stripe Checkout locale', 'woocommerce-gateway-stripe'), |
|
| 98 | 98 | 'type' => 'select', |
| 99 | 99 | 'class' => 'wc-enhanced-select', |
| 100 | - 'description' => __( 'Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe' ), |
|
| 100 | + 'description' => __('Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe'), |
|
| 101 | 101 | 'default' => 'en', |
| 102 | 102 | 'desc_tip' => true, |
| 103 | 103 | 'options' => array( |
| 104 | - 'auto' => __( 'Auto', 'woocommerce-gateway-stripe' ), |
|
| 105 | - 'zh' => __( 'Simplified Chinese', 'woocommerce-gateway-stripe' ), |
|
| 106 | - 'da' => __( 'Danish', 'woocommerce-gateway-stripe' ), |
|
| 107 | - 'nl' => __( 'Dutch', 'woocommerce-gateway-stripe' ), |
|
| 108 | - 'en' => __( 'English', 'woocommerce-gateway-stripe' ), |
|
| 109 | - 'fi' => __( 'Finnish', 'woocommerce-gateway-stripe' ), |
|
| 110 | - 'fr' => __( 'French', 'woocommerce-gateway-stripe' ), |
|
| 111 | - 'de' => __( 'German', 'woocommerce-gateway-stripe' ), |
|
| 112 | - 'it' => __( 'Italian', 'woocommerce-gateway-stripe' ), |
|
| 113 | - 'ja' => __( 'Japanese', 'woocommerce-gateway-stripe' ), |
|
| 114 | - 'no' => __( 'Norwegian', 'woocommerce-gateway-stripe' ), |
|
| 115 | - 'es' => __( 'Spanish', 'woocommerce-gateway-stripe' ), |
|
| 116 | - 'sv' => __( 'Swedish', 'woocommerce-gateway-stripe' ), |
|
| 104 | + 'auto' => __('Auto', 'woocommerce-gateway-stripe'), |
|
| 105 | + 'zh' => __('Simplified Chinese', 'woocommerce-gateway-stripe'), |
|
| 106 | + 'da' => __('Danish', 'woocommerce-gateway-stripe'), |
|
| 107 | + 'nl' => __('Dutch', 'woocommerce-gateway-stripe'), |
|
| 108 | + 'en' => __('English', 'woocommerce-gateway-stripe'), |
|
| 109 | + 'fi' => __('Finnish', 'woocommerce-gateway-stripe'), |
|
| 110 | + 'fr' => __('French', 'woocommerce-gateway-stripe'), |
|
| 111 | + 'de' => __('German', 'woocommerce-gateway-stripe'), |
|
| 112 | + 'it' => __('Italian', 'woocommerce-gateway-stripe'), |
|
| 113 | + 'ja' => __('Japanese', 'woocommerce-gateway-stripe'), |
|
| 114 | + 'no' => __('Norwegian', 'woocommerce-gateway-stripe'), |
|
| 115 | + 'es' => __('Spanish', 'woocommerce-gateway-stripe'), |
|
| 116 | + 'sv' => __('Swedish', 'woocommerce-gateway-stripe'), |
|
| 117 | 117 | ), |
| 118 | 118 | ), |
| 119 | 119 | 'stripe_bitcoin' => array( |
| 120 | - 'title' => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
| 121 | - 'label' => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
| 120 | + 'title' => __('Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
| 121 | + 'label' => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
| 122 | 122 | 'type' => 'checkbox', |
| 123 | - 'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ), |
|
| 123 | + 'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'), |
|
| 124 | 124 | 'default' => 'no', |
| 125 | 125 | 'desc_tip' => true, |
| 126 | 126 | ), |
| 127 | 127 | 'stripe_checkout_image' => array( |
| 128 | - 'title' => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ), |
|
| 129 | - 'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ), |
|
| 128 | + 'title' => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'), |
|
| 129 | + 'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'), |
|
| 130 | 130 | 'type' => 'text', |
| 131 | 131 | 'default' => '', |
| 132 | 132 | 'desc_tip' => true, |
| 133 | 133 | ), |
| 134 | 134 | 'request_payment_api' => array( |
| 135 | - 'title' => __( 'Payment Request API', 'woocommerce-gateway-stripe' ), |
|
| 136 | - 'label' => __( 'Enable Payment Request API', 'woocommerce-gateway-stripe' ), |
|
| 135 | + 'title' => __('Payment Request API', 'woocommerce-gateway-stripe'), |
|
| 136 | + 'label' => __('Enable Payment Request API', 'woocommerce-gateway-stripe'), |
|
| 137 | 137 | 'type' => 'checkbox', |
| 138 | - 'description' => __( 'If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe' ), |
|
| 138 | + 'description' => __('If enabled, users will be able to pay using the Payment Request API if supported by the browser.', 'woocommerce-gateway-stripe'), |
|
| 139 | 139 | 'default' => 'no', |
| 140 | 140 | 'desc_tip' => true, |
| 141 | 141 | ), |
| 142 | 142 | 'apple_pay' => array( |
| 143 | - 'title' => __( 'Apple Pay', 'woocommerce-gateway-stripe' ), |
|
| 144 | - 'label' => sprintf( __( 'Enable Apple Pay. %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe' ), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>' ), |
|
| 143 | + 'title' => __('Apple Pay', 'woocommerce-gateway-stripe'), |
|
| 144 | + 'label' => sprintf(__('Enable Apple Pay. %1$sBy using Apple Pay, you agree to %2$s and %3$s\'s terms of service.', 'woocommerce-gateway-stripe'), '<br />', '<a href="https://stripe.com/apple-pay/legal" target="_blank">Stripe</a>', '<a href="https://developer.apple.com/apple-pay/acceptable-use-guidelines-for-websites/" target="_blank">Apple</a>'), |
|
| 145 | 145 | 'type' => 'checkbox', |
| 146 | - 'description' => __( 'If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe' ), |
|
| 146 | + 'description' => __('If enabled, users will be able to pay with Apple Pay.', 'woocommerce-gateway-stripe'), |
|
| 147 | 147 | 'default' => 'yes', |
| 148 | 148 | 'desc_tip' => true, |
| 149 | 149 | ), |
| 150 | 150 | 'apple_pay_button' => array( |
| 151 | - 'title' => __( 'Apple Pay Button Style', 'woocommerce-gateway-stripe' ), |
|
| 152 | - 'label' => __( 'Button Style', 'woocommerce-gateway-stripe' ), |
|
| 151 | + 'title' => __('Apple Pay Button Style', 'woocommerce-gateway-stripe'), |
|
| 152 | + 'label' => __('Button Style', 'woocommerce-gateway-stripe'), |
|
| 153 | 153 | 'type' => 'select', |
| 154 | - 'description' => __( 'Select the button style you would like to show.', 'woocommerce-gateway-stripe' ), |
|
| 154 | + 'description' => __('Select the button style you would like to show.', 'woocommerce-gateway-stripe'), |
|
| 155 | 155 | 'default' => 'black', |
| 156 | 156 | 'desc_tip' => true, |
| 157 | 157 | 'options' => array( |
| 158 | - 'black' => __( 'Black', 'woocommerce-gateway-stripe' ), |
|
| 159 | - 'white' => __( 'White', 'woocommerce-gateway-stripe' ), |
|
| 158 | + 'black' => __('Black', 'woocommerce-gateway-stripe'), |
|
| 159 | + 'white' => __('White', 'woocommerce-gateway-stripe'), |
|
| 160 | 160 | ), |
| 161 | 161 | ), |
| 162 | 162 | 'apple_pay_button_lang' => array( |
| 163 | - 'title' => __( 'Apple Pay Button Language', 'woocommerce-gateway-stripe' ), |
|
| 164 | - 'description' => __( 'Enter the 2 letter ISO code for the language you would like your Apple Pay Button to display in. Reference available ISO codes here <code>http://www.w3schools.com/tags/ref_language_codes.asp</code>', 'woocommerce-gateway-stripe' ), |
|
| 163 | + 'title' => __('Apple Pay Button Language', 'woocommerce-gateway-stripe'), |
|
| 164 | + 'description' => __('Enter the 2 letter ISO code for the language you would like your Apple Pay Button to display in. Reference available ISO codes here <code>http://www.w3schools.com/tags/ref_language_codes.asp</code>', 'woocommerce-gateway-stripe'), |
|
| 165 | 165 | 'type' => 'text', |
| 166 | 166 | 'default' => 'en', |
| 167 | 167 | 'desc_tip' => false, |
| 168 | 168 | ), |
| 169 | 169 | 'saved_cards' => array( |
| 170 | - 'title' => __( 'Saved Cards', 'woocommerce-gateway-stripe' ), |
|
| 171 | - 'label' => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ), |
|
| 170 | + 'title' => __('Saved Cards', 'woocommerce-gateway-stripe'), |
|
| 171 | + 'label' => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'), |
|
| 172 | 172 | 'type' => 'checkbox', |
| 173 | - 'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ), |
|
| 173 | + 'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'), |
|
| 174 | 174 | 'default' => 'no', |
| 175 | 175 | 'desc_tip' => true, |
| 176 | 176 | ), |
| 177 | 177 | 'logging' => array( |
| 178 | - 'title' => __( 'Logging', 'woocommerce-gateway-stripe' ), |
|
| 179 | - 'label' => __( 'Log debug messages', 'woocommerce-gateway-stripe' ), |
|
| 178 | + 'title' => __('Logging', 'woocommerce-gateway-stripe'), |
|
| 179 | + 'label' => __('Log debug messages', 'woocommerce-gateway-stripe'), |
|
| 180 | 180 | 'type' => 'checkbox', |
| 181 | - 'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ), |
|
| 181 | + 'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'), |
|
| 182 | 182 | 'default' => 'no', |
| 183 | 183 | 'desc_tip' => true, |
| 184 | 184 | ), |
@@ -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,8 +120,8 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function __construct() { |
| 122 | 122 | $this->id = 'stripe'; |
| 123 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
| 124 | - $this->method_description = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
| 123 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
| 124 | + $this->method_description = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
| 125 | 125 | $this->has_fields = true; |
| 126 | 126 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
| 127 | 127 | $this->supports = array( |
@@ -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->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
| 157 | - $this->statement_descriptor = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
|
| 158 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
| 159 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
| 160 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
| 161 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
| 162 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 163 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
| 164 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
| 165 | - $this->apple_pay = 'yes' === $this->get_option( 'apple_pay', 'yes' ); |
|
| 166 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
| 167 | - $this->apple_pay_button = $this->get_option( 'apple_pay_button', 'black' ); |
|
| 168 | - $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
| 169 | - $this->allow_remember_me = 'yes' === $this->get_option( 'allow_remember_me', 'no' ); |
|
| 170 | - |
|
| 171 | - if ( $this->stripe_checkout ) { |
|
| 172 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ( $this->testmode ) { |
|
| 176 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
| 177 | - $this->description = trim( $this->description ); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - 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->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
| 157 | + $this->statement_descriptor = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); |
|
| 158 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
| 159 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
| 160 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
| 161 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
| 162 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 163 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
| 164 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
| 165 | + $this->apple_pay = 'yes' === $this->get_option('apple_pay', 'yes'); |
|
| 166 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
| 167 | + $this->apple_pay_button = $this->get_option('apple_pay_button', 'black'); |
|
| 168 | + $this->logging = 'yes' === $this->get_option('logging'); |
|
| 169 | + $this->allow_remember_me = 'yes' === $this->get_option('allow_remember_me', 'no'); |
|
| 170 | + |
|
| 171 | + if ($this->stripe_checkout) { |
|
| 172 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ($this->testmode) { |
|
| 176 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
| 177 | + $this->description = trim($this->description); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
| 181 | 181 | |
| 182 | 182 | $this->init_apple_pay(); |
| 183 | 183 | |
| 184 | 184 | // Hooks. |
| 185 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 186 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
| 187 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 188 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 185 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 186 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
| 187 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 188 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -195,24 +195,24 @@ discard block |
||
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | 197 | public function get_icon() { |
| 198 | - $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
| 199 | - $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
| 198 | + $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
| 199 | + $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
| 200 | 200 | |
| 201 | - $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 202 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 203 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 201 | + $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 202 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 203 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 204 | 204 | |
| 205 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
| 206 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 207 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 208 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 205 | + if ('USD' === get_woocommerce_currency()) { |
|
| 206 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 207 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 208 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
| 212 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
| 211 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
| 212 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
| 215 | + return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -223,11 +223,11 @@ discard block |
||
| 223 | 223 | * |
| 224 | 224 | * @return float|int |
| 225 | 225 | */ |
| 226 | - public function get_stripe_amount( $total, $currency = '' ) { |
|
| 227 | - if ( ! $currency ) { |
|
| 226 | + public function get_stripe_amount($total, $currency = '') { |
|
| 227 | + if ( ! $currency) { |
|
| 228 | 228 | $currency = get_woocommerce_currency(); |
| 229 | 229 | } |
| 230 | - switch ( strtoupper( $currency ) ) { |
|
| 230 | + switch (strtoupper($currency)) { |
|
| 231 | 231 | // Zero decimal currencies. |
| 232 | 232 | case 'BIF' : |
| 233 | 233 | case 'CLP' : |
@@ -244,10 +244,10 @@ discard block |
||
| 244 | 244 | case 'XAF' : |
| 245 | 245 | case 'XOF' : |
| 246 | 246 | case 'XPF' : |
| 247 | - $total = absint( $total ); |
|
| 247 | + $total = absint($total); |
|
| 248 | 248 | break; |
| 249 | 249 | default : |
| 250 | - $total = round( $total, 2 ) * 100; // In cents. |
|
| 250 | + $total = round($total, 2) * 100; // In cents. |
|
| 251 | 251 | break; |
| 252 | 252 | } |
| 253 | 253 | return $total; |
@@ -262,9 +262,9 @@ discard block |
||
| 262 | 262 | public function init_apple_pay() { |
| 263 | 263 | if ( |
| 264 | 264 | is_admin() && |
| 265 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
| 266 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
| 267 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] |
|
| 265 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
| 266 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
| 267 | + isset($_GET['section']) && 'stripe' === $_GET['section'] |
|
| 268 | 268 | ) { |
| 269 | 269 | $this->process_apple_pay_verification(); |
| 270 | 270 | } |
@@ -277,9 +277,9 @@ discard block |
||
| 277 | 277 | * @version 3.1.0 |
| 278 | 278 | * @param string $secret_key |
| 279 | 279 | */ |
| 280 | - private function _register_apple_pay_domain( $secret_key = '' ) { |
|
| 281 | - if ( empty( $secret_key ) ) { |
|
| 282 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
| 280 | + private function _register_apple_pay_domain($secret_key = '') { |
|
| 281 | + if (empty($secret_key)) { |
|
| 282 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -293,13 +293,13 @@ discard block |
||
| 293 | 293 | 'Authorization' => 'Bearer ' . $secret_key, |
| 294 | 294 | ); |
| 295 | 295 | |
| 296 | - $response = wp_remote_post( $endpoint, array( |
|
| 296 | + $response = wp_remote_post($endpoint, array( |
|
| 297 | 297 | 'headers' => $headers, |
| 298 | - 'body' => http_build_query( $data ), |
|
| 299 | - ) ); |
|
| 298 | + 'body' => http_build_query($data), |
|
| 299 | + )); |
|
| 300 | 300 | |
| 301 | - if ( 200 !== $response['response']['code'] ) { |
|
| 302 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response['response']['message'] ) ); |
|
| 301 | + if (200 !== $response['response']['code']) { |
|
| 302 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response['response']['message'])); |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | |
@@ -311,46 +311,46 @@ discard block |
||
| 311 | 311 | */ |
| 312 | 312 | public function process_apple_pay_verification() { |
| 313 | 313 | try { |
| 314 | - $path = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) ); |
|
| 314 | + $path = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'])); |
|
| 315 | 315 | $dir = '.well-known'; |
| 316 | 316 | $file = 'apple-developer-merchantid-domain-association'; |
| 317 | 317 | $fullpath = $path . '/' . $dir . '/' . $file; |
| 318 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
| 318 | + $gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
| 319 | 319 | |
| 320 | - if ( 'yes' === $gateway_settings['apple_pay_domain_set'] ) { |
|
| 320 | + if ('yes' === $gateway_settings['apple_pay_domain_set']) { |
|
| 321 | 321 | return; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - if ( ! file_exists( $path . '/' . $dir ) || ! file_exists( $fullpath ) ) { |
|
| 325 | - if ( ! mkdir( $path . '/' . $dir, 0755 ) ) { |
|
| 326 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 324 | + if ( ! file_exists($path . '/' . $dir) || ! file_exists($fullpath)) { |
|
| 325 | + if ( ! mkdir($path . '/' . $dir, 0755)) { |
|
| 326 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if ( ! file_exists( $path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association' ) ) { |
|
| 330 | - if ( ! copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
| 331 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 329 | + if ( ! file_exists($path . '/' . $dir . '/' . 'apple-developer-merchantid-domain-association')) { |
|
| 330 | + if ( ! copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
| 331 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | // At this point then the domain association folder and file should be available. |
| 337 | 337 | // Proceed to verify/and or verify again. |
| 338 | - $this->_register_apple_pay_domain( $this->secret_key ); |
|
| 338 | + $this->_register_apple_pay_domain($this->secret_key); |
|
| 339 | 339 | |
| 340 | 340 | // No errors to this point, verification success! |
| 341 | 341 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
| 342 | 342 | $this->apple_pay_domain_set = true; |
| 343 | 343 | |
| 344 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 344 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 345 | 345 | |
| 346 | - $this->log( __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) ); |
|
| 346 | + $this->log(__('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe')); |
|
| 347 | 347 | |
| 348 | - } catch ( Exception $e ) { |
|
| 348 | + } catch (Exception $e) { |
|
| 349 | 349 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
| 350 | 350 | |
| 351 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 351 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 352 | 352 | |
| 353 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 353 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 354 | 354 | } |
| 355 | 355 | } |
| 356 | 356 | |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | * Check if SSL is enabled and notify the user |
| 359 | 359 | */ |
| 360 | 360 | public function admin_notices() { |
| 361 | - if ( 'no' === $this->enabled ) { |
|
| 361 | + if ('no' === $this->enabled) { |
|
| 362 | 362 | return; |
| 363 | 363 | } |
| 364 | 364 | |
@@ -367,13 +367,13 @@ discard block |
||
| 367 | 367 | * when setting screen is displayed. So if domain verification is not set, |
| 368 | 368 | * something went wrong so lets notify user. |
| 369 | 369 | */ |
| 370 | - if ( ! empty( $this->secret_key ) && $this->apple_pay && ! $this->apple_pay_domain_set ) { |
|
| 371 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue.', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
| 370 | + if ( ! empty($this->secret_key) && $this->apple_pay && ! $this->apple_pay_domain_set) { |
|
| 371 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue.', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
| 375 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
| 376 | - echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>'; |
|
| 375 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
| 376 | + echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>'; |
|
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | |
@@ -381,11 +381,11 @@ discard block |
||
| 381 | 381 | * Check if this gateway is enabled |
| 382 | 382 | */ |
| 383 | 383 | public function is_available() { |
| 384 | - if ( 'yes' === $this->enabled ) { |
|
| 385 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
| 384 | + if ('yes' === $this->enabled) { |
|
| 385 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
| 386 | 386 | return false; |
| 387 | 387 | } |
| 388 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
| 388 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
| 389 | 389 | return false; |
| 390 | 390 | } |
| 391 | 391 | return true; |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | * Initialise Gateway Settings Form Fields |
| 398 | 398 | */ |
| 399 | 399 | public function init_form_fields() { |
| 400 | - $this->form_fields = include( 'settings-stripe.php' ); |
|
| 400 | + $this->form_fields = include('settings-stripe.php'); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | /** |
@@ -405,54 +405,54 @@ discard block |
||
| 405 | 405 | */ |
| 406 | 406 | public function payment_fields() { |
| 407 | 407 | $user = wp_get_current_user(); |
| 408 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
| 408 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
| 409 | 409 | $total = WC()->cart->total; |
| 410 | 410 | |
| 411 | 411 | // If paying from order, we need to get total from order not cart. |
| 412 | - if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['key'] ) ) { |
|
| 413 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 412 | + if (isset($_GET['pay_for_order']) && isset($_GET['key'])) { |
|
| 413 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 414 | 414 | $total = $order->get_total(); |
| 415 | 415 | } |
| 416 | 416 | |
| 417 | - if ( $user->ID ) { |
|
| 418 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 417 | + if ($user->ID) { |
|
| 418 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 419 | 419 | $user_email = $user_email ? $user_email : $user->user_email; |
| 420 | 420 | } else { |
| 421 | 421 | $user_email = ''; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - if ( is_add_payment_method_page() ) { |
|
| 425 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
| 424 | + if (is_add_payment_method_page()) { |
|
| 425 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
| 426 | 426 | } else { |
| 427 | 427 | $pay_button_text = ''; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | echo '<div |
| 431 | 431 | id="stripe-payment-data" |
| 432 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
| 432 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
| 433 | 433 | data-description="" |
| 434 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 435 | - data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '" |
|
| 436 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
| 437 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 438 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
| 439 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
| 440 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
| 441 | - data-allow-remember-me="' . esc_attr( $this->allow_remember_me ? 'true' : 'false' ) . '">'; |
|
| 434 | + data-email="' . esc_attr($user_email) . '" |
|
| 435 | + data-amount="' . esc_attr($this->get_stripe_amount($total)) . '" |
|
| 436 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
| 437 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 438 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
| 439 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
| 440 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
| 441 | + data-allow-remember-me="' . esc_attr($this->allow_remember_me ? 'true' : 'false') . '">'; |
|
| 442 | 442 | |
| 443 | - if ( $this->description ) { |
|
| 444 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 443 | + if ($this->description) { |
|
| 444 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - if ( $display_tokenization ) { |
|
| 447 | + if ($display_tokenization) { |
|
| 448 | 448 | $this->tokenization_script(); |
| 449 | 449 | $this->saved_payment_methods(); |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | - if ( ! $this->stripe_checkout ) { |
|
| 452 | + if ( ! $this->stripe_checkout) { |
|
| 453 | 453 | $this->form(); |
| 454 | 454 | |
| 455 | - if ( $display_tokenization ) { |
|
| 455 | + if ($display_tokenization) { |
|
| 456 | 456 | $this->save_payment_method_checkbox(); |
| 457 | 457 | } |
| 458 | 458 | } |
@@ -468,20 +468,20 @@ discard block |
||
| 468 | 468 | * @return array |
| 469 | 469 | */ |
| 470 | 470 | public function get_localized_messages() { |
| 471 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
| 472 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
| 473 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 474 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 475 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 476 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 477 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
| 478 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 479 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
| 480 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
| 481 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
| 482 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
| 483 | - 'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ), |
|
| 484 | - ) ); |
|
| 471 | + return apply_filters('wc_stripe_localized_messages', array( |
|
| 472 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
| 473 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
| 474 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
| 475 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
| 476 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 477 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
| 478 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 479 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
| 480 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
| 481 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
| 482 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
| 483 | + 'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'), |
|
| 484 | + )); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -491,28 +491,28 @@ discard block |
||
| 491 | 491 | * @version 3.1.0 |
| 492 | 492 | */ |
| 493 | 493 | public function admin_scripts() { |
| 494 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
| 494 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
| 495 | 495 | return; |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 498 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 499 | 499 | |
| 500 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
| 500 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
| 501 | 501 | |
| 502 | 502 | $stripe_admin_params = array( |
| 503 | 503 | 'localized_messages' => array( |
| 504 | - 'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ), |
|
| 505 | - 'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ), |
|
| 506 | - 're_verify_button_text' => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ), |
|
| 507 | - 'missing_secret_key' => __( 'Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe' ), |
|
| 504 | + 'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'), |
|
| 505 | + 'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'), |
|
| 506 | + 're_verify_button_text' => __('Re-verify Domain', 'woocommerce-gateway-stripe'), |
|
| 507 | + 'missing_secret_key' => __('Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe'), |
|
| 508 | 508 | ), |
| 509 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
| 509 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
| 510 | 510 | 'nonce' => array( |
| 511 | - 'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ), |
|
| 511 | + 'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'), |
|
| 512 | 512 | ), |
| 513 | 513 | ); |
| 514 | 514 | |
| 515 | - wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) ); |
|
| 515 | + wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params)); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -523,30 +523,30 @@ discard block |
||
| 523 | 523 | * @access public |
| 524 | 524 | */ |
| 525 | 525 | public function payment_scripts() { |
| 526 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 526 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 527 | 527 | return; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 530 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 531 | 531 | |
| 532 | - if ( $this->stripe_checkout ) { |
|
| 533 | - wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true ); |
|
| 534 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 532 | + if ($this->stripe_checkout) { |
|
| 533 | + wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true); |
|
| 534 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
| 535 | 535 | } else { |
| 536 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 537 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 536 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 537 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | $stripe_params = array( |
| 541 | 541 | 'key' => $this->publishable_key, |
| 542 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 543 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 542 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 543 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 544 | 544 | ); |
| 545 | 545 | |
| 546 | 546 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 547 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
| 548 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
| 549 | - $order = wc_get_order( $order_id ); |
|
| 547 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
| 548 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
| 549 | + $order = wc_get_order($order_id); |
|
| 550 | 550 | |
| 551 | 551 | $stripe_params['billing_first_name'] = $order->billing_first_name; |
| 552 | 552 | $stripe_params['billing_last_name'] = $order->billing_last_name; |
@@ -558,14 +558,14 @@ discard block |
||
| 558 | 558 | $stripe_params['billing_country'] = $order->billing_country; |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ); |
|
| 562 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
| 563 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
| 561 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'); |
|
| 562 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
| 563 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
| 564 | 564 | |
| 565 | 565 | // merge localized messages to be use in JS |
| 566 | - $stripe_params = array_merge( $stripe_params, $this->get_localized_messages() ); |
|
| 566 | + $stripe_params = array_merge($stripe_params, $this->get_localized_messages()); |
|
| 567 | 567 | |
| 568 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 568 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | /** |
@@ -574,31 +574,31 @@ discard block |
||
| 574 | 574 | * @param object $source |
| 575 | 575 | * @return array() |
| 576 | 576 | */ |
| 577 | - protected function generate_payment_request( $order, $source ) { |
|
| 577 | + protected function generate_payment_request($order, $source) { |
|
| 578 | 578 | $post_data = array(); |
| 579 | - $post_data['currency'] = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() ); |
|
| 580 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 581 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
| 579 | + $post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency()); |
|
| 580 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 581 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
| 582 | 582 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
| 583 | 583 | |
| 584 | - if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 584 | + if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 585 | 585 | $post_data['receipt_email'] = $order->billing_email; |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | - $post_data['expand[]'] = 'balance_transaction'; |
|
| 588 | + $post_data['expand[]'] = 'balance_transaction'; |
|
| 589 | 589 | |
| 590 | 590 | $metadata = array( |
| 591 | - __( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $order->billing_first_name ) . ' ' . sanitize_text_field( $order->billing_last_name ), |
|
| 592 | - __( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $order->billing_email ), |
|
| 591 | + __('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($order->billing_first_name) . ' ' . sanitize_text_field($order->billing_last_name), |
|
| 592 | + __('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($order->billing_email), |
|
| 593 | 593 | ); |
| 594 | 594 | |
| 595 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
| 595 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
| 596 | 596 | |
| 597 | - if ( $source->customer ) { |
|
| 597 | + if ($source->customer) { |
|
| 598 | 598 | $post_data['customer'] = $source->customer; |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | - if ( $source->source ) { |
|
| 601 | + if ($source->source) { |
|
| 602 | 602 | $post_data['source'] = $source->source; |
| 603 | 603 | } |
| 604 | 604 | |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | * @param WC_Order $order |
| 611 | 611 | * @param object $source |
| 612 | 612 | */ |
| 613 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
| 613 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -622,37 +622,37 @@ discard block |
||
| 622 | 622 | * @throws Exception When card was not added or for and invalid card. |
| 623 | 623 | * @return object |
| 624 | 624 | */ |
| 625 | - protected function get_source( $user_id, $force_customer = false ) { |
|
| 626 | - $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
| 625 | + protected function get_source($user_id, $force_customer = false) { |
|
| 626 | + $stripe_customer = new WC_Stripe_Customer($user_id); |
|
| 627 | 627 | $stripe_source = false; |
| 628 | 628 | $token_id = false; |
| 629 | 629 | |
| 630 | 630 | // New CC info was entered and we have a new token to process |
| 631 | - if ( isset( $_POST['stripe_token'] ) ) { |
|
| 632 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
| 633 | - $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
| 631 | + if (isset($_POST['stripe_token'])) { |
|
| 632 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
| 633 | + $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
| 634 | 634 | |
| 635 | 635 | // This is true if the user wants to store the card to their account. |
| 636 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
| 637 | - $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
| 636 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
| 637 | + $stripe_source = $stripe_customer->add_card($stripe_token); |
|
| 638 | 638 | |
| 639 | - if ( is_wp_error( $stripe_source ) ) { |
|
| 640 | - throw new Exception( $stripe_source->get_error_message() ); |
|
| 639 | + if (is_wp_error($stripe_source)) { |
|
| 640 | + throw new Exception($stripe_source->get_error_message()); |
|
| 641 | 641 | } |
| 642 | 642 | } else { |
| 643 | 643 | // Not saving token, so don't define customer either. |
| 644 | 644 | $stripe_source = $stripe_token; |
| 645 | 645 | $stripe_customer = false; |
| 646 | 646 | } |
| 647 | - } elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
| 647 | + } elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
| 648 | 648 | // Use an existing token, and then process the payment |
| 649 | 649 | |
| 650 | - $token_id = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
| 651 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 650 | + $token_id = wc_clean($_POST['wc-stripe-payment-token']); |
|
| 651 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 652 | 652 | |
| 653 | - if ( ! $token || $token->get_user_id() !== get_current_user_id() ) { |
|
| 654 | - WC()->session->set( 'refresh_totals', true ); |
|
| 655 | - throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
| 653 | + if ( ! $token || $token->get_user_id() !== get_current_user_id()) { |
|
| 654 | + WC()->session->set('refresh_totals', true); |
|
| 655 | + throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | $stripe_source = $token->get_token(); |
@@ -676,16 +676,16 @@ discard block |
||
| 676 | 676 | * @param object $order |
| 677 | 677 | * @return object |
| 678 | 678 | */ |
| 679 | - protected function get_order_source( $order = null ) { |
|
| 679 | + protected function get_order_source($order = null) { |
|
| 680 | 680 | $stripe_customer = new WC_Stripe_Customer(); |
| 681 | 681 | $stripe_source = false; |
| 682 | 682 | $token_id = false; |
| 683 | 683 | |
| 684 | - if ( $order ) { |
|
| 685 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) { |
|
| 686 | - $stripe_customer->set_id( $meta_value ); |
|
| 684 | + if ($order) { |
|
| 685 | + if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) { |
|
| 686 | + $stripe_customer->set_id($meta_value); |
|
| 687 | 687 | } |
| 688 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) { |
|
| 688 | + if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) { |
|
| 689 | 689 | $stripe_source = $meta_value; |
| 690 | 690 | } |
| 691 | 691 | } |
@@ -708,57 +708,57 @@ discard block |
||
| 708 | 708 | * |
| 709 | 709 | * @return array|void |
| 710 | 710 | */ |
| 711 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
| 711 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
| 712 | 712 | try { |
| 713 | - $order = wc_get_order( $order_id ); |
|
| 714 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
| 713 | + $order = wc_get_order($order_id); |
|
| 714 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
| 715 | 715 | |
| 716 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
| 717 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
| 718 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
| 719 | - throw new Exception( $error_msg ); |
|
| 716 | + if (empty($source->source) && empty($source->customer)) { |
|
| 717 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
| 718 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
| 719 | + throw new Exception($error_msg); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | // Store source to order meta. |
| 723 | - $this->save_source( $order, $source ); |
|
| 723 | + $this->save_source($order, $source); |
|
| 724 | 724 | |
| 725 | 725 | // Handle payment. |
| 726 | - if ( $order->get_total() > 0 ) { |
|
| 726 | + if ($order->get_total() > 0) { |
|
| 727 | 727 | |
| 728 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 729 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe::get_minimum_amount() / 100 ) ) ); |
|
| 728 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 729 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe::get_minimum_amount() / 100))); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | - $this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 732 | + $this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 733 | 733 | |
| 734 | 734 | // Make the request. |
| 735 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 735 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 736 | 736 | |
| 737 | - if ( is_wp_error( $response ) ) { |
|
| 737 | + if (is_wp_error($response)) { |
|
| 738 | 738 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 739 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
| 740 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
| 741 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
| 739 | + if ('customer' === $response->get_error_code() && $retry) { |
|
| 740 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
| 741 | + return $this->process_payment($order_id, false, $force_customer); |
|
| 742 | 742 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 743 | - } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
| 744 | - $token = WC_Payment_Tokens::get( $source->token_id ); |
|
| 743 | + } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
| 744 | + $token = WC_Payment_Tokens::get($source->token_id); |
|
| 745 | 745 | $token->delete(); |
| 746 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 747 | - $order->add_order_note( $message ); |
|
| 748 | - throw new Exception( $message ); |
|
| 746 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 747 | + $order->add_order_note($message); |
|
| 748 | + throw new Exception($message); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | $localized_messages = $this->get_localized_messages(); |
| 752 | 752 | |
| 753 | - $message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message(); |
|
| 753 | + $message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message(); |
|
| 754 | 754 | |
| 755 | - $order->add_order_note( $message ); |
|
| 755 | + $order->add_order_note($message); |
|
| 756 | 756 | |
| 757 | - throw new Exception( $message ); |
|
| 757 | + throw new Exception($message); |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | // Process valid response. |
| 761 | - $this->process_response( $response, $order ); |
|
| 761 | + $this->process_response($response, $order); |
|
| 762 | 762 | } else { |
| 763 | 763 | $order->payment_complete(); |
| 764 | 764 | } |
@@ -766,23 +766,23 @@ discard block |
||
| 766 | 766 | // Remove cart. |
| 767 | 767 | WC()->cart->empty_cart(); |
| 768 | 768 | |
| 769 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 769 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
| 770 | 770 | |
| 771 | 771 | // Return thank you page redirect. |
| 772 | 772 | return array( |
| 773 | 773 | 'result' => 'success', |
| 774 | - 'redirect' => $this->get_return_url( $order ), |
|
| 774 | + 'redirect' => $this->get_return_url($order), |
|
| 775 | 775 | ); |
| 776 | 776 | |
| 777 | - } catch ( Exception $e ) { |
|
| 778 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 779 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 777 | + } catch (Exception $e) { |
|
| 778 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 779 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 780 | 780 | |
| 781 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 782 | - $this->send_failed_order_email( $order_id ); |
|
| 781 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 782 | + $this->send_failed_order_email($order_id); |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 785 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 786 | 786 | |
| 787 | 787 | return array( |
| 788 | 788 | 'result' => 'fail', |
@@ -797,52 +797,52 @@ discard block |
||
| 797 | 797 | * @param WC_Order $order For to which the source applies. |
| 798 | 798 | * @param stdClass $source Source information. |
| 799 | 799 | */ |
| 800 | - protected function save_source( $order, $source ) { |
|
| 800 | + protected function save_source($order, $source) { |
|
| 801 | 801 | // Store source in the order. |
| 802 | - if ( $source->customer ) { |
|
| 803 | - update_post_meta( $order->id, '_stripe_customer_id', $source->customer ); |
|
| 802 | + if ($source->customer) { |
|
| 803 | + update_post_meta($order->id, '_stripe_customer_id', $source->customer); |
|
| 804 | 804 | } |
| 805 | - if ( $source->source ) { |
|
| 806 | - update_post_meta( $order->id, '_stripe_card_id', $source->source ); |
|
| 805 | + if ($source->source) { |
|
| 806 | + update_post_meta($order->id, '_stripe_card_id', $source->source); |
|
| 807 | 807 | } |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | /** |
| 811 | 811 | * Store extra meta data for an order from a Stripe Response. |
| 812 | 812 | */ |
| 813 | - public function process_response( $response, $order ) { |
|
| 814 | - $this->log( 'Processing response: ' . print_r( $response, true ) ); |
|
| 813 | + public function process_response($response, $order) { |
|
| 814 | + $this->log('Processing response: ' . print_r($response, true)); |
|
| 815 | 815 | |
| 816 | 816 | // Store charge data |
| 817 | - update_post_meta( $order->id, '_stripe_charge_id', $response->id ); |
|
| 818 | - update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
| 817 | + update_post_meta($order->id, '_stripe_charge_id', $response->id); |
|
| 818 | + update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
| 819 | 819 | |
| 820 | 820 | // Store other data such as fees |
| 821 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
| 821 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
| 822 | 822 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 823 | 823 | // values are in the local currency of the Stripe account, not from WC. |
| 824 | - $fee = ! empty( $response->balance_transaction->fee ) ? number_format( $response->balance_transaction->fee / 100, 2, '.', '' ) : 0; |
|
| 825 | - $net = ! empty( $response->balance_transaction->net ) ? number_format( $response->balance_transaction->net / 100, 2, '.', '' ) : 0; |
|
| 826 | - update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
| 827 | - update_post_meta( $order->id, 'Net Revenue From Stripe', $net ); |
|
| 824 | + $fee = ! empty($response->balance_transaction->fee) ? number_format($response->balance_transaction->fee / 100, 2, '.', '') : 0; |
|
| 825 | + $net = ! empty($response->balance_transaction->net) ? number_format($response->balance_transaction->net / 100, 2, '.', '') : 0; |
|
| 826 | + update_post_meta($order->id, 'Stripe Fee', $fee); |
|
| 827 | + update_post_meta($order->id, 'Net Revenue From Stripe', $net); |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | - if ( $response->captured ) { |
|
| 831 | - $order->payment_complete( $response->id ); |
|
| 830 | + if ($response->captured) { |
|
| 831 | + $order->payment_complete($response->id); |
|
| 832 | 832 | |
| 833 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
| 834 | - $order->add_order_note( $message ); |
|
| 835 | - $this->log( 'Success: ' . $message ); |
|
| 833 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
| 834 | + $order->add_order_note($message); |
|
| 835 | + $this->log('Success: ' . $message); |
|
| 836 | 836 | |
| 837 | 837 | } else { |
| 838 | - add_post_meta( $order->id, '_transaction_id', $response->id, true ); |
|
| 838 | + add_post_meta($order->id, '_transaction_id', $response->id, true); |
|
| 839 | 839 | |
| 840 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 840 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 841 | 841 | $order->reduce_order_stock(); |
| 842 | 842 | } |
| 843 | 843 | |
| 844 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
| 845 | - $this->log( "Successful auth: $response->id" ); |
|
| 844 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
| 845 | + $this->log("Successful auth: $response->id"); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | return $response; |
@@ -854,32 +854,32 @@ discard block |
||
| 854 | 854 | * @since 3.0.0 |
| 855 | 855 | */ |
| 856 | 856 | public function add_payment_method() { |
| 857 | - if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
| 858 | - wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
| 857 | + if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
| 858 | + wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
| 859 | 859 | return; |
| 860 | 860 | } |
| 861 | 861 | |
| 862 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 863 | - $card = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
| 862 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 863 | + $card = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
| 864 | 864 | |
| 865 | - if ( is_wp_error( $card ) ) { |
|
| 865 | + if (is_wp_error($card)) { |
|
| 866 | 866 | $localized_messages = $this->get_localized_messages(); |
| 867 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
| 867 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
| 868 | 868 | |
| 869 | 869 | // loop through the errors to find matching localized message |
| 870 | - foreach ( $card->errors as $error => $msg ) { |
|
| 871 | - if ( isset( $localized_messages[ $error ] ) ) { |
|
| 872 | - $error_msg = $localized_messages[ $error ]; |
|
| 870 | + foreach ($card->errors as $error => $msg) { |
|
| 871 | + if (isset($localized_messages[$error])) { |
|
| 872 | + $error_msg = $localized_messages[$error]; |
|
| 873 | 873 | } |
| 874 | 874 | } |
| 875 | 875 | |
| 876 | - wc_add_notice( $error_msg, 'error' ); |
|
| 876 | + wc_add_notice($error_msg, 'error'); |
|
| 877 | 877 | return; |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | return array( |
| 881 | 881 | 'result' => 'success', |
| 882 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
| 882 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
| 883 | 883 | ); |
| 884 | 884 | } |
| 885 | 885 | |
@@ -889,36 +889,36 @@ discard block |
||
| 889 | 889 | * @param float $amount |
| 890 | 890 | * @return bool |
| 891 | 891 | */ |
| 892 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 893 | - $order = wc_get_order( $order_id ); |
|
| 892 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
| 893 | + $order = wc_get_order($order_id); |
|
| 894 | 894 | |
| 895 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 895 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
| 896 | 896 | return false; |
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | $body = array(); |
| 900 | 900 | |
| 901 | - if ( ! is_null( $amount ) ) { |
|
| 902 | - $body['amount'] = $this->get_stripe_amount( $amount ); |
|
| 901 | + if ( ! is_null($amount)) { |
|
| 902 | + $body['amount'] = $this->get_stripe_amount($amount); |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | - if ( $reason ) { |
|
| 905 | + if ($reason) { |
|
| 906 | 906 | $body['metadata'] = array( |
| 907 | 907 | 'reason' => $reason, |
| 908 | 908 | ); |
| 909 | 909 | } |
| 910 | 910 | |
| 911 | - $this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
| 911 | + $this->log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
| 912 | 912 | |
| 913 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
| 913 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
| 914 | 914 | |
| 915 | - if ( is_wp_error( $response ) ) { |
|
| 916 | - $this->log( 'Error: ' . $response->get_error_message() ); |
|
| 915 | + if (is_wp_error($response)) { |
|
| 916 | + $this->log('Error: ' . $response->get_error_message()); |
|
| 917 | 917 | return $response; |
| 918 | - } elseif ( ! empty( $response->id ) ) { |
|
| 919 | - $refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
| 920 | - $order->add_order_note( $refund_message ); |
|
| 921 | - $this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 918 | + } elseif ( ! empty($response->id)) { |
|
| 919 | + $refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
| 920 | + $order->add_order_note($refund_message); |
|
| 921 | + $this->log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
| 922 | 922 | return true; |
| 923 | 923 | } |
| 924 | 924 | } |
@@ -931,10 +931,10 @@ discard block |
||
| 931 | 931 | * @param int $order_id |
| 932 | 932 | * @return null |
| 933 | 933 | */ |
| 934 | - public function send_failed_order_email( $order_id ) { |
|
| 934 | + public function send_failed_order_email($order_id) { |
|
| 935 | 935 | $emails = WC()->mailer()->get_emails(); |
| 936 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
| 937 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
| 936 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
| 937 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
| 938 | 938 | } |
| 939 | 939 | } |
| 940 | 940 | |
@@ -946,9 +946,9 @@ discard block |
||
| 946 | 946 | * |
| 947 | 947 | * @param string $message |
| 948 | 948 | */ |
| 949 | - public function log( $message ) { |
|
| 950 | - if ( $this->logging ) { |
|
| 951 | - WC_Stripe::log( $message ); |
|
| 949 | + public function log($message) { |
|
| 950 | + if ($this->logging) { |
|
| 951 | + WC_Stripe::log($message); |
|
| 952 | 952 | } |
| 953 | 953 | } |
| 954 | 954 | } |