@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public function __construct() { |
| 17 | 17 | $this->id = 'stripe'; |
| 18 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
| 19 | - $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' ); |
|
| 18 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
| 19 | + $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'); |
|
| 20 | 20 | $this->has_fields = true; |
| 21 | 21 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
| 22 | 22 | $this->supports = array( |
@@ -42,35 +42,35 @@ discard block |
||
| 42 | 42 | $this->init_settings(); |
| 43 | 43 | |
| 44 | 44 | // Get setting values. |
| 45 | - $this->title = $this->get_option( 'title' ); |
|
| 46 | - $this->description = $this->get_option( 'description' ); |
|
| 47 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 48 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
| 49 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
| 50 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
| 51 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
| 52 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
| 53 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
| 54 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 55 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
| 56 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
| 57 | - $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
| 58 | - |
|
| 59 | - if ( $this->stripe_checkout ) { |
|
| 60 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
| 45 | + $this->title = $this->get_option('title'); |
|
| 46 | + $this->description = $this->get_option('description'); |
|
| 47 | + $this->enabled = $this->get_option('enabled'); |
|
| 48 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
| 49 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
| 50 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
| 51 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
| 52 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
| 53 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
| 54 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 55 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
| 56 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
| 57 | + $this->logging = 'yes' === $this->get_option('logging'); |
|
| 58 | + |
|
| 59 | + if ($this->stripe_checkout) { |
|
| 60 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - if ( $this->testmode ) { |
|
| 64 | - $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' ); |
|
| 65 | - $this->description = trim( $this->description ); |
|
| 63 | + if ($this->testmode) { |
|
| 64 | + $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'); |
|
| 65 | + $this->description = trim($this->description); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
| 68 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
| 69 | 69 | |
| 70 | 70 | // Hooks |
| 71 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 72 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 73 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 71 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 72 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 73 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -80,35 +80,35 @@ discard block |
||
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | 82 | public function get_icon() { |
| 83 | - $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
| 84 | - $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
| 83 | + $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
| 84 | + $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
| 85 | 85 | |
| 86 | - $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 87 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 88 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 86 | + $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 87 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 88 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 89 | 89 | |
| 90 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
| 91 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 92 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 93 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 90 | + if ('USD' === get_woocommerce_currency()) { |
|
| 91 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 92 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 93 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if ( $this->bitcoin ) { |
|
| 97 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
| 96 | + if ($this->bitcoin) { |
|
| 97 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
| 100 | + return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * Get Stripe amount to pay |
| 105 | 105 | * @return float |
| 106 | 106 | */ |
| 107 | - public function get_stripe_amount( $total, $currency = '' ) { |
|
| 108 | - if ( ! $currency ) { |
|
| 107 | + public function get_stripe_amount($total, $currency = '') { |
|
| 108 | + if ( ! $currency) { |
|
| 109 | 109 | $currency = get_woocommerce_currency(); |
| 110 | 110 | } |
| 111 | - switch ( strtoupper( $currency ) ) { |
|
| 111 | + switch (strtoupper($currency)) { |
|
| 112 | 112 | // Zero decimal currencies |
| 113 | 113 | case 'BIF' : |
| 114 | 114 | case 'CLP' : |
@@ -125,10 +125,10 @@ discard block |
||
| 125 | 125 | case 'XAF' : |
| 126 | 126 | case 'XOF' : |
| 127 | 127 | case 'XPF' : |
| 128 | - $total = absint( $total ); |
|
| 128 | + $total = absint($total); |
|
| 129 | 129 | break; |
| 130 | 130 | default : |
| 131 | - $total = round( $total, 2 ) * 100; // In cents |
|
| 131 | + $total = round($total, 2) * 100; // In cents |
|
| 132 | 132 | break; |
| 133 | 133 | } |
| 134 | 134 | return $total; |
@@ -138,31 +138,31 @@ discard block |
||
| 138 | 138 | * Check if SSL is enabled and notify the user |
| 139 | 139 | */ |
| 140 | 140 | public function admin_notices() { |
| 141 | - if ( $this->enabled == 'no' ) { |
|
| 141 | + if ($this->enabled == 'no') { |
|
| 142 | 142 | return; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $addons = ( class_exists( 'WC_Subscriptions_Order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) ? '_addons' : ''; |
|
| 145 | + $addons = (class_exists('WC_Subscriptions_Order') || class_exists('WC_Pre_Orders_Order')) ? '_addons' : ''; |
|
| 146 | 146 | |
| 147 | 147 | // Check required fields |
| 148 | - if ( ! $this->secret_key ) { |
|
| 149 | - echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons ) ) . '</p></div>'; |
|
| 148 | + if ( ! $this->secret_key) { |
|
| 149 | + echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; |
|
| 150 | 150 | return; |
| 151 | 151 | |
| 152 | - } elseif ( ! $this->publishable_key ) { |
|
| 153 | - echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons ) ) . '</p></div>'; |
|
| 152 | + } elseif ( ! $this->publishable_key) { |
|
| 153 | + echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; |
|
| 154 | 154 | return; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Simple check for duplicate keys |
| 158 | - if ( $this->secret_key == $this->publishable_key ) { |
|
| 159 | - echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons ) ) . '</p></div>'; |
|
| 158 | + if ($this->secret_key == $this->publishable_key) { |
|
| 159 | + echo '<div class="error"><p>' . sprintf(__('Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; |
|
| 160 | 160 | return; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected |
| 164 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
| 165 | - echo '<div class="error"><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>'; |
|
| 164 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
| 165 | + echo '<div class="error"><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>'; |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | |
@@ -170,11 +170,11 @@ discard block |
||
| 170 | 170 | * Check if this gateway is enabled |
| 171 | 171 | */ |
| 172 | 172 | public function is_available() { |
| 173 | - if ( 'yes' === $this->enabled ) { |
|
| 174 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
| 173 | + if ('yes' === $this->enabled) { |
|
| 174 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
| 175 | 175 | return false; |
| 176 | 176 | } |
| 177 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
| 177 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
| 178 | 178 | return false; |
| 179 | 179 | } |
| 180 | 180 | return true; |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | * Initialise Gateway Settings Form Fields |
| 187 | 187 | */ |
| 188 | 188 | public function init_form_fields() { |
| 189 | - $this->form_fields = include( untrailingslashit( plugin_dir_path( WC_STRIPE_MAIN_FILE ) ) . '/includes/settings-stripe.php' ); |
|
| 189 | + $this->form_fields = include(untrailingslashit(plugin_dir_path(WC_STRIPE_MAIN_FILE)) . '/includes/settings-stripe.php'); |
|
| 190 | 190 | |
| 191 | - wc_enqueue_js( " |
|
| 191 | + wc_enqueue_js(" |
|
| 192 | 192 | jQuery( function( $ ) { |
| 193 | 193 | $( '#woocommerce_stripe_stripe_checkout' ).change(function(){ |
| 194 | 194 | if ( $( this ).is( ':checked' ) ) { |
@@ -208,25 +208,25 @@ discard block |
||
| 208 | 208 | ?> |
| 209 | 209 | <fieldset class="stripe-legacy-payment-fields"> |
| 210 | 210 | <?php |
| 211 | - if ( $this->description ) { |
|
| 212 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 211 | + if ($this->description) { |
|
| 212 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 213 | 213 | } |
| 214 | - if ( $this->saved_cards && is_user_logged_in() ) { |
|
| 215 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 214 | + if ($this->saved_cards && is_user_logged_in()) { |
|
| 215 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 216 | 216 | ?> |
| 217 | 217 | <p class="form-row form-row-wide"> |
| 218 | - <a class="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_class', 'button' ); ?>" style="float:right;" href="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_url', get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ); ?>#saved-cards"><?php esc_html_e( 'Manage cards', 'woocommerce-gateway-stripe' ); ?></a> |
|
| 218 | + <a class="<?php echo apply_filters('wc_stripe_manage_saved_cards_class', 'button'); ?>" style="float:right;" href="<?php echo apply_filters('wc_stripe_manage_saved_cards_url', get_permalink(get_option('woocommerce_myaccount_page_id'))); ?>#saved-cards"><?php esc_html_e('Manage cards', 'woocommerce-gateway-stripe'); ?></a> |
|
| 219 | 219 | <?php |
| 220 | - if ( $cards = $stripe_customer->get_cards() ) { |
|
| 220 | + if ($cards = $stripe_customer->get_cards()) { |
|
| 221 | 221 | $default_card = $cards[0]->id; |
| 222 | - foreach ( (array) $cards as $card ) { |
|
| 223 | - if ( 'card' !== $card->object ) { |
|
| 222 | + foreach ((array) $cards as $card) { |
|
| 223 | + if ('card' !== $card->object) { |
|
| 224 | 224 | continue; |
| 225 | 225 | } |
| 226 | 226 | ?> |
| 227 | - <label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr( strtolower( $card->brand ) ); ?>"> |
|
| 228 | - <input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked( $default_card, $card->id ) ?> /> |
|
| 229 | - <?php printf( __( '%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4, $card->exp_month, $card->exp_year ); ?> |
|
| 227 | + <label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr(strtolower($card->brand)); ?>"> |
|
| 228 | + <input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked($default_card, $card->id) ?> /> |
|
| 229 | + <?php printf(__('%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe'), $card->brand, $card->last4, $card->exp_month, $card->exp_year); ?> |
|
| 230 | 230 | </label> |
| 231 | 231 | <?php |
| 232 | 232 | } |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | ?> |
| 235 | 235 | <label for="new"> |
| 236 | 236 | <input type="radio" id="new" name="wc-stripe-payment-token" value="new" /> |
| 237 | - <?php _e( 'Use a new credit card', 'woocommerce-gateway-stripe' ); ?> |
|
| 237 | + <?php _e('Use a new credit card', 'woocommerce-gateway-stripe'); ?> |
|
| 238 | 238 | </label> |
| 239 | 239 | </p> |
| 240 | 240 | <?php |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | $user = wp_get_current_user(); |
| 244 | 244 | |
| 245 | - if ( $user ) { |
|
| 246 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 245 | + if ($user) { |
|
| 246 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 247 | 247 | $user_email = $user_email ? $user_email : $user->user_email; |
| 248 | 248 | } else { |
| 249 | 249 | $user_email = ''; |
@@ -251,22 +251,22 @@ discard block |
||
| 251 | 251 | |
| 252 | 252 | $display = ''; |
| 253 | 253 | |
| 254 | - if ( $this->stripe_checkout || $this->saved_cards && ! empty( $cards ) ) { |
|
| 254 | + if ($this->stripe_checkout || $this->saved_cards && ! empty($cards)) { |
|
| 255 | 255 | $display = 'style="display:none;"'; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | echo '<div ' . $display . ' id="stripe-payment-data" |
| 259 | 259 | data-description="" |
| 260 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 261 | - data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '" |
|
| 262 | - data-name="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '" |
|
| 263 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 264 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
| 265 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
| 266 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">'; |
|
| 267 | - |
|
| 268 | - if ( ! $this->stripe_checkout ) { |
|
| 269 | - $this->credit_card_form( array( 'fields_have_names' => false ) ); |
|
| 260 | + data-email="' . esc_attr($user_email) . '" |
|
| 261 | + data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '" |
|
| 262 | + data-name="' . esc_attr(get_bloginfo('name', 'display')) . '" |
|
| 263 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 264 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
| 265 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
| 266 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">'; |
|
| 267 | + |
|
| 268 | + if ( ! $this->stripe_checkout) { |
|
| 269 | + $this->credit_card_form(array('fields_have_names' => false)); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | echo '</div>'; |
@@ -283,27 +283,27 @@ discard block |
||
| 283 | 283 | * @access public |
| 284 | 284 | */ |
| 285 | 285 | public function payment_scripts() { |
| 286 | - if ( $this->stripe_checkout ) { |
|
| 287 | - wp_enqueue_script( 'stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true ); |
|
| 288 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 286 | + if ($this->stripe_checkout) { |
|
| 287 | + wp_enqueue_script('stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true); |
|
| 288 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
| 289 | 289 | } else { |
| 290 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 291 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 290 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 291 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | $stripe_params = array( |
| 295 | 295 | 'key' => $this->publishable_key, |
| 296 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 297 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 296 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 297 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 298 | 298 | ); |
| 299 | 299 | |
| 300 | 300 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 301 | - if ( is_checkout_pay_page() && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) { |
|
| 302 | - $order_key = urldecode( $_GET['order'] ); |
|
| 303 | - $order_id = absint( $_GET['order_id'] ); |
|
| 304 | - $order = wc_get_order( $order_id ); |
|
| 301 | + if (is_checkout_pay_page() && isset($_GET['order']) && isset($_GET['order_id'])) { |
|
| 302 | + $order_key = urldecode($_GET['order']); |
|
| 303 | + $order_id = absint($_GET['order_id']); |
|
| 304 | + $order = wc_get_order($order_id); |
|
| 305 | 305 | |
| 306 | - if ( $order->id === $order_id && $order->order_key === $order_key ) { |
|
| 306 | + if ($order->id === $order_id && $order->order_key === $order_key) { |
|
| 307 | 307 | $stripe_params['billing_first_name'] = $order->billing_first_name; |
| 308 | 308 | $stripe_params['billing_last_name'] = $order->billing_last_name; |
| 309 | 309 | $stripe_params['billing_address_1'] = $order->billing_address_1; |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 318 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -324,28 +324,28 @@ discard block |
||
| 324 | 324 | * @param object $source |
| 325 | 325 | * @return array() |
| 326 | 326 | */ |
| 327 | - protected function generate_payment_request( $order, $source ) { |
|
| 327 | + protected function generate_payment_request($order, $source) { |
|
| 328 | 328 | $post_data = array(); |
| 329 | - $post_data['currency'] = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() ); |
|
| 330 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 331 | - $post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
| 329 | + $post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency()); |
|
| 330 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 331 | + $post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
| 332 | 332 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
| 333 | 333 | |
| 334 | - if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 334 | + if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 335 | 335 | $post_data['receipt_email'] = $order->billing_email; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - $post_data['expand[]'] = 'balance_transaction'; |
|
| 338 | + $post_data['expand[]'] = 'balance_transaction'; |
|
| 339 | 339 | |
| 340 | - if ( $source->customer ) { |
|
| 340 | + if ($source->customer) { |
|
| 341 | 341 | $post_data['customer'] = $source->customer; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - if ( $source->source ) { |
|
| 344 | + if ($source->source) { |
|
| 345 | 345 | $post_data['source'] = $source->source; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
| 348 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
@@ -353,22 +353,22 @@ discard block |
||
| 353 | 353 | * @param bool $force_customer Should we force customer creation? |
| 354 | 354 | * @return object |
| 355 | 355 | */ |
| 356 | - protected function get_source( $user_id, $force_customer = false ) { |
|
| 357 | - $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
| 356 | + protected function get_source($user_id, $force_customer = false) { |
|
| 357 | + $stripe_customer = new WC_Stripe_Customer($user_id); |
|
| 358 | 358 | $stripe_source = false; |
| 359 | 359 | $token_id = false; |
| 360 | 360 | |
| 361 | 361 | // New CC info was entered and we have a new token to process |
| 362 | - if ( isset( $_POST['stripe_token'] ) ) { |
|
| 363 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
| 364 | - $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
| 362 | + if (isset($_POST['stripe_token'])) { |
|
| 363 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
| 364 | + $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
| 365 | 365 | |
| 366 | 366 | // This is true if the user wants to store the card to their account. |
| 367 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
| 368 | - $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
| 367 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
| 368 | + $stripe_source = $stripe_customer->add_card($stripe_token); |
|
| 369 | 369 | |
| 370 | - if ( is_wp_error( $stripe_source ) ) { |
|
| 371 | - throw new Exception( $stripe_source->get_error_message() ); |
|
| 370 | + if (is_wp_error($stripe_source)) { |
|
| 371 | + throw new Exception($stripe_source->get_error_message()); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | } else { |
@@ -379,8 +379,8 @@ discard block |
||
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | // Use an existing token, and then process the payment |
| 382 | - elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
| 383 | - $stripe_source = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
| 382 | + elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
| 383 | + $stripe_source = wc_clean($_POST['wc-stripe-payment-token']); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | return (object) array( |
@@ -401,16 +401,16 @@ discard block |
||
| 401 | 401 | * @param object $order |
| 402 | 402 | * @return object |
| 403 | 403 | */ |
| 404 | - protected function get_order_source( $order = null ) { |
|
| 404 | + protected function get_order_source($order = null) { |
|
| 405 | 405 | $stripe_customer = new WC_Stripe_Customer(); |
| 406 | 406 | $stripe_source = false; |
| 407 | 407 | $token_id = false; |
| 408 | 408 | |
| 409 | - if ( $order ) { |
|
| 410 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) { |
|
| 411 | - $stripe_customer->set_id( $meta_value ); |
|
| 409 | + if ($order) { |
|
| 410 | + if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) { |
|
| 411 | + $stripe_customer->set_id($meta_value); |
|
| 412 | 412 | } |
| 413 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) { |
|
| 413 | + if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) { |
|
| 414 | 414 | $stripe_source = $meta_value; |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -425,43 +425,43 @@ discard block |
||
| 425 | 425 | /** |
| 426 | 426 | * Process the payment |
| 427 | 427 | */ |
| 428 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
| 428 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
| 429 | 429 | try { |
| 430 | - $order = wc_get_order( $order_id ); |
|
| 431 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
| 430 | + $order = wc_get_order($order_id); |
|
| 431 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
| 432 | 432 | |
| 433 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
| 434 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
| 435 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
| 436 | - throw new Exception( $error_msg ); |
|
| 433 | + if (empty($source->source) && empty($source->customer)) { |
|
| 434 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
| 435 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
| 436 | + throw new Exception($error_msg); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // Store source to order meta |
| 440 | - $this->save_source( $order, $source ); |
|
| 440 | + $this->save_source($order, $source); |
|
| 441 | 441 | |
| 442 | 442 | // Handle payment |
| 443 | - if ( $order->get_total() > 0 ) { |
|
| 443 | + if ($order->get_total() > 0) { |
|
| 444 | 444 | |
| 445 | - if ( $order->get_total() * 100 < 50 ) { |
|
| 446 | - throw new Exception( __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe' ) ); |
|
| 445 | + if ($order->get_total() * 100 < 50) { |
|
| 446 | + throw new Exception(__('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe')); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 449 | + WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 450 | 450 | |
| 451 | 451 | // Make the request |
| 452 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 452 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 453 | 453 | |
| 454 | - if ( is_wp_error( $response ) ) { |
|
| 454 | + if (is_wp_error($response)) { |
|
| 455 | 455 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 456 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
| 457 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
| 458 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
| 456 | + if ('customer' === $response->get_error_code() && $retry) { |
|
| 457 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
| 458 | + return $this->process_payment($order_id, false, $force_customer); |
|
| 459 | 459 | } |
| 460 | - throw new Exception( $response->get_error_code() . ': ' . $response->get_error_message() ); |
|
| 460 | + throw new Exception($response->get_error_code() . ': ' . $response->get_error_message()); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | // Process valid response |
| 464 | - $this->process_response( $response, $order ); |
|
| 464 | + $this->process_response($response, $order); |
|
| 465 | 465 | } else { |
| 466 | 466 | $order->payment_complete(); |
| 467 | 467 | } |
@@ -472,13 +472,13 @@ discard block |
||
| 472 | 472 | // Return thank you page redirect |
| 473 | 473 | return array( |
| 474 | 474 | 'result' => 'success', |
| 475 | - 'redirect' => $this->get_return_url( $order ) |
|
| 475 | + 'redirect' => $this->get_return_url($order) |
|
| 476 | 476 | ); |
| 477 | 477 | |
| 478 | - } catch ( Exception $e ) { |
|
| 479 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 480 | - WC()->session->set( 'refresh_totals', true ); |
|
| 481 | - WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 478 | + } catch (Exception $e) { |
|
| 479 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 480 | + WC()->session->set('refresh_totals', true); |
|
| 481 | + WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 482 | 482 | return; |
| 483 | 483 | } |
| 484 | 484 | } |
@@ -486,45 +486,45 @@ discard block |
||
| 486 | 486 | /** |
| 487 | 487 | * Save source to order. |
| 488 | 488 | */ |
| 489 | - protected function save_source( $order, $source ) { |
|
| 489 | + protected function save_source($order, $source) { |
|
| 490 | 490 | // Store source in the order |
| 491 | - if ( $source->customer ) { |
|
| 492 | - update_post_meta( $order->id, '_stripe_customer_id', $source->customer ); |
|
| 491 | + if ($source->customer) { |
|
| 492 | + update_post_meta($order->id, '_stripe_customer_id', $source->customer); |
|
| 493 | 493 | } |
| 494 | - if ( $source->source ) { |
|
| 495 | - update_post_meta( $order->id, '_stripe_card_id', $source->source->id ); |
|
| 494 | + if ($source->source) { |
|
| 495 | + update_post_meta($order->id, '_stripe_card_id', $source->source->id); |
|
| 496 | 496 | } |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
| 500 | 500 | * Store extra meta data for an order from a Stripe Response. |
| 501 | 501 | */ |
| 502 | - public function process_response( $response, $order ) { |
|
| 503 | - WC_Stripe::log( "Processing response: " . print_r( $response, true ) ); |
|
| 502 | + public function process_response($response, $order) { |
|
| 503 | + WC_Stripe::log("Processing response: " . print_r($response, true)); |
|
| 504 | 504 | |
| 505 | 505 | // Store charge data |
| 506 | - update_post_meta( $order->id, '_stripe_charge_id', $response->id ); |
|
| 507 | - update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
| 506 | + update_post_meta($order->id, '_stripe_charge_id', $response->id); |
|
| 507 | + update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
| 508 | 508 | |
| 509 | 509 | // Store other data such as fees |
| 510 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
| 511 | - $fee = number_format( $response->balance_transaction->fee / 100, 2, '.', '' ); |
|
| 512 | - update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
| 513 | - update_post_meta( $order->id, 'Net Revenue From Stripe', $order->get_total() - $fee ); |
|
| 510 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
| 511 | + $fee = number_format($response->balance_transaction->fee / 100, 2, '.', ''); |
|
| 512 | + update_post_meta($order->id, 'Stripe Fee', $fee); |
|
| 513 | + update_post_meta($order->id, 'Net Revenue From Stripe', $order->get_total() - $fee); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - if ( $response->captured ) { |
|
| 517 | - $order->payment_complete( $response->id ); |
|
| 518 | - WC_Stripe::log( "Successful charge: $response->id" ); |
|
| 516 | + if ($response->captured) { |
|
| 517 | + $order->payment_complete($response->id); |
|
| 518 | + WC_Stripe::log("Successful charge: $response->id"); |
|
| 519 | 519 | } else { |
| 520 | - add_post_meta( $order->id, '_transaction_id', $response->id, true ); |
|
| 520 | + add_post_meta($order->id, '_transaction_id', $response->id, true); |
|
| 521 | 521 | |
| 522 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 522 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 523 | 523 | $order->reduce_order_stock(); |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - $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 ) ); |
|
| 527 | - WC_Stripe::log( "Successful auth: $response->id" ); |
|
| 526 | + $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)); |
|
| 527 | + WC_Stripe::log("Successful auth: $response->id"); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | return $response; |
@@ -536,21 +536,21 @@ discard block |
||
| 536 | 536 | * @since 3.0.0 |
| 537 | 537 | */ |
| 538 | 538 | public function add_payment_method() { |
| 539 | - if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
| 540 | - wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
| 539 | + if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
| 540 | + wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
| 541 | 541 | return; |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 545 | - $result = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
| 544 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 545 | + $result = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
| 546 | 546 | |
| 547 | - if ( is_wp_error( $result ) ) { |
|
| 548 | - throw new Exception( $result->get_error_message() ); |
|
| 547 | + if (is_wp_error($result)) { |
|
| 548 | + throw new Exception($result->get_error_message()); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | return array( |
| 552 | 552 | 'result' => 'success', |
| 553 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
| 553 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
| 554 | 554 | ); |
| 555 | 555 | } |
| 556 | 556 | |
@@ -560,36 +560,36 @@ discard block |
||
| 560 | 560 | * @param float $amount |
| 561 | 561 | * @return bool |
| 562 | 562 | */ |
| 563 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 564 | - $order = wc_get_order( $order_id ); |
|
| 563 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
| 564 | + $order = wc_get_order($order_id); |
|
| 565 | 565 | |
| 566 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 566 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
| 567 | 567 | return false; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | $body = array(); |
| 571 | 571 | |
| 572 | - if ( ! is_null( $amount ) ) { |
|
| 573 | - $body['amount'] = $this->get_stripe_amount( $amount ); |
|
| 572 | + if ( ! is_null($amount)) { |
|
| 573 | + $body['amount'] = $this->get_stripe_amount($amount); |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | - if ( $reason ) { |
|
| 576 | + if ($reason) { |
|
| 577 | 577 | $body['metadata'] = array( |
| 578 | 578 | 'reason' => $reason, |
| 579 | 579 | ); |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
| 582 | + WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
| 583 | 583 | |
| 584 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
| 584 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
| 585 | 585 | |
| 586 | - if ( is_wp_error( $response ) ) { |
|
| 587 | - WC_Stripe::log( "Error: " . $response->get_error_message() ); |
|
| 586 | + if (is_wp_error($response)) { |
|
| 587 | + WC_Stripe::log("Error: " . $response->get_error_message()); |
|
| 588 | 588 | return $response; |
| 589 | - } elseif ( ! empty( $response->id ) ) { |
|
| 590 | - $refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
| 591 | - $order->add_order_note( $refund_message ); |
|
| 592 | - WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 589 | + } elseif ( ! empty($response->id)) { |
|
| 590 | + $refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
| 591 | + $order->add_order_note($refund_message); |
|
| 592 | + WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message))); |
|
| 593 | 593 | return true; |
| 594 | 594 | } |
| 595 | 595 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function __construct() { |
| 87 | 87 | $this->id = 'stripe'; |
| 88 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
| 89 | - $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' ); |
|
| 88 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
| 89 | + $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'); |
|
| 90 | 90 | $this->has_fields = true; |
| 91 | 91 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
| 92 | 92 | $this->supports = array( |
@@ -114,35 +114,35 @@ discard block |
||
| 114 | 114 | $this->init_settings(); |
| 115 | 115 | |
| 116 | 116 | // Get setting values. |
| 117 | - $this->title = $this->get_option( 'title' ); |
|
| 118 | - $this->description = $this->get_option( 'description' ); |
|
| 119 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 120 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
| 121 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
| 122 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
| 123 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
| 124 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
| 125 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
| 126 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 127 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
| 128 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
| 129 | - $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
| 117 | + $this->title = $this->get_option('title'); |
|
| 118 | + $this->description = $this->get_option('description'); |
|
| 119 | + $this->enabled = $this->get_option('enabled'); |
|
| 120 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
| 121 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
| 122 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
| 123 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
| 124 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
| 125 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
| 126 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 127 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
| 128 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
| 129 | + $this->logging = 'yes' === $this->get_option('logging'); |
|
| 130 | 130 | |
| 131 | - if ( $this->stripe_checkout ) { |
|
| 132 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
| 131 | + if ($this->stripe_checkout) { |
|
| 132 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if ( $this->testmode ) { |
|
| 136 | - $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' ); |
|
| 137 | - $this->description = trim( $this->description ); |
|
| 135 | + if ($this->testmode) { |
|
| 136 | + $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'); |
|
| 137 | + $this->description = trim($this->description); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
| 140 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
| 141 | 141 | |
| 142 | 142 | // Hooks. |
| 143 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 144 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 145 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 143 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 144 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 145 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -152,24 +152,24 @@ discard block |
||
| 152 | 152 | * @return string |
| 153 | 153 | */ |
| 154 | 154 | public function get_icon() { |
| 155 | - $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
| 156 | - $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
| 155 | + $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
| 156 | + $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
| 157 | 157 | |
| 158 | - $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 159 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 160 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 158 | + $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 159 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 160 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 161 | 161 | |
| 162 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
| 163 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 164 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 165 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 162 | + if ('USD' === get_woocommerce_currency()) { |
|
| 163 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 164 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 165 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if ( 'yes' === $this->bitcoin && 'yes' === $this->stripe_checkout ) { |
|
| 169 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
| 168 | + if ('yes' === $this->bitcoin && 'yes' === $this->stripe_checkout) { |
|
| 169 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
| 172 | + return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | * |
| 181 | 181 | * @return float|int |
| 182 | 182 | */ |
| 183 | - public function get_stripe_amount( $total, $currency = '' ) { |
|
| 184 | - if ( ! $currency ) { |
|
| 183 | + public function get_stripe_amount($total, $currency = '') { |
|
| 184 | + if ( ! $currency) { |
|
| 185 | 185 | $currency = get_woocommerce_currency(); |
| 186 | 186 | } |
| 187 | - switch ( strtoupper( $currency ) ) { |
|
| 187 | + switch (strtoupper($currency)) { |
|
| 188 | 188 | // Zero decimal currencies. |
| 189 | 189 | case 'BIF' : |
| 190 | 190 | case 'CLP' : |
@@ -201,10 +201,10 @@ discard block |
||
| 201 | 201 | case 'XAF' : |
| 202 | 202 | case 'XOF' : |
| 203 | 203 | case 'XPF' : |
| 204 | - $total = absint( $total ); |
|
| 204 | + $total = absint($total); |
|
| 205 | 205 | break; |
| 206 | 206 | default : |
| 207 | - $total = round( $total, 2 ) * 100; // In cents. |
|
| 207 | + $total = round($total, 2) * 100; // In cents. |
|
| 208 | 208 | break; |
| 209 | 209 | } |
| 210 | 210 | return $total; |
@@ -214,13 +214,13 @@ discard block |
||
| 214 | 214 | * Check if SSL is enabled and notify the user |
| 215 | 215 | */ |
| 216 | 216 | public function admin_notices() { |
| 217 | - if ( 'no' === $this->enabled ) { |
|
| 217 | + if ('no' === $this->enabled) { |
|
| 218 | 218 | return; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
| 222 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
| 223 | - 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>'; |
|
| 222 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
| 223 | + 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>'; |
|
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | |
@@ -228,11 +228,11 @@ discard block |
||
| 228 | 228 | * Check if this gateway is enabled |
| 229 | 229 | */ |
| 230 | 230 | public function is_available() { |
| 231 | - if ( 'yes' === $this->enabled ) { |
|
| 232 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
| 231 | + if ('yes' === $this->enabled) { |
|
| 232 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
| 233 | 233 | return false; |
| 234 | 234 | } |
| 235 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
| 235 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
| 236 | 236 | return false; |
| 237 | 237 | } |
| 238 | 238 | return true; |
@@ -244,9 +244,9 @@ discard block |
||
| 244 | 244 | * Initialise Gateway Settings Form Fields |
| 245 | 245 | */ |
| 246 | 246 | public function init_form_fields() { |
| 247 | - $this->form_fields = include( 'settings-stripe.php' ); |
|
| 247 | + $this->form_fields = include('settings-stripe.php'); |
|
| 248 | 248 | |
| 249 | - wc_enqueue_js( " |
|
| 249 | + wc_enqueue_js(" |
|
| 250 | 250 | jQuery( function( $ ) { |
| 251 | 251 | $( '#woocommerce_stripe_stripe_checkout' ).change(function(){ |
| 252 | 252 | if ( $( this ).is( ':checked' ) ) { |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | var value = $( this ).val(); |
| 261 | 261 | |
| 262 | 262 | if ( value.indexOf( '_test_' ) >= 0 ) { |
| 263 | - $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ) . "</span>' ); |
|
| 263 | + $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe') . "</span>' ); |
|
| 264 | 264 | } else { |
| 265 | 265 | $( this ).css( 'border-color', '' ); |
| 266 | 266 | $( '.stripe-error-description', $( this ).parent() ).remove(); |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | var value = $( this ).val(); |
| 272 | 272 | |
| 273 | 273 | if ( value.indexOf( '_live_' ) >= 0 ) { |
| 274 | - $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ) . "</span>' ); |
|
| 274 | + $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe') . "</span>' ); |
|
| 275 | 275 | } else { |
| 276 | 276 | $( this ).css( 'border-color', '' ); |
| 277 | 277 | $( '.stripe-error-description', $( this ).parent() ).remove(); |
@@ -286,46 +286,46 @@ discard block |
||
| 286 | 286 | */ |
| 287 | 287 | public function payment_fields() { |
| 288 | 288 | $user = wp_get_current_user(); |
| 289 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
| 289 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
| 290 | 290 | |
| 291 | - if ( $user->ID ) { |
|
| 292 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 291 | + if ($user->ID) { |
|
| 292 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 293 | 293 | $user_email = $user_email ? $user_email : $user->user_email; |
| 294 | 294 | } else { |
| 295 | 295 | $user_email = ''; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if ( is_add_payment_method_page() ) { |
|
| 299 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
| 298 | + if (is_add_payment_method_page()) { |
|
| 299 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
| 300 | 300 | } else { |
| 301 | 301 | $pay_button_text = ''; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | echo '<div |
| 305 | 305 | id="stripe-payment-data" |
| 306 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
| 306 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
| 307 | 307 | data-description="" |
| 308 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 309 | - data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '" |
|
| 310 | - data-name="' . esc_attr( get_bloginfo( 'name', 'display' ) ) . '" |
|
| 311 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 312 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
| 313 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
| 314 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">'; |
|
| 308 | + data-email="' . esc_attr($user_email) . '" |
|
| 309 | + data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '" |
|
| 310 | + data-name="' . esc_attr(get_bloginfo('name', 'display')) . '" |
|
| 311 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 312 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
| 313 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
| 314 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">'; |
|
| 315 | 315 | |
| 316 | - if ( $this->description ) { |
|
| 317 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 316 | + if ($this->description) { |
|
| 317 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - if ( $display_tokenization ) { |
|
| 320 | + if ($display_tokenization) { |
|
| 321 | 321 | $this->tokenization_script(); |
| 322 | 322 | $this->saved_payment_methods(); |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - if ( ! $this->stripe_checkout ) { |
|
| 325 | + if ( ! $this->stripe_checkout) { |
|
| 326 | 326 | $this->form(); |
| 327 | 327 | |
| 328 | - if ( $display_tokenization ) { |
|
| 328 | + if ($display_tokenization) { |
|
| 329 | 329 | $this->save_payment_method_checkbox(); |
| 330 | 330 | } |
| 331 | 331 | } |
@@ -341,20 +341,20 @@ discard block |
||
| 341 | 341 | * @return array |
| 342 | 342 | */ |
| 343 | 343 | public function get_localized_messages() { |
| 344 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
| 345 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
| 346 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 347 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 348 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 349 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 350 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
| 351 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 352 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
| 353 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
| 354 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
| 355 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
| 356 | - 'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ), |
|
| 357 | - ) ); |
|
| 344 | + return apply_filters('wc_stripe_localized_messages', array( |
|
| 345 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
| 346 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
| 347 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
| 348 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
| 349 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 350 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
| 351 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 352 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
| 353 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
| 354 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
| 355 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
| 356 | + 'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'), |
|
| 357 | + )); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -365,26 +365,26 @@ discard block |
||
| 365 | 365 | * @access public |
| 366 | 366 | */ |
| 367 | 367 | public function payment_scripts() { |
| 368 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 368 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 369 | 369 | |
| 370 | - if ( $this->stripe_checkout ) { |
|
| 371 | - wp_enqueue_script( 'stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true ); |
|
| 372 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 370 | + if ($this->stripe_checkout) { |
|
| 371 | + wp_enqueue_script('stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true); |
|
| 372 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
| 373 | 373 | } else { |
| 374 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
| 375 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 374 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
| 375 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | $stripe_params = array( |
| 379 | 379 | 'key' => $this->publishable_key, |
| 380 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 381 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 380 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 381 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 382 | 382 | ); |
| 383 | 383 | |
| 384 | 384 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 385 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
| 386 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
| 387 | - $order = wc_get_order( $order_id ); |
|
| 385 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
| 386 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
| 387 | + $order = wc_get_order($order_id); |
|
| 388 | 388 | |
| 389 | 389 | $stripe_params['billing_first_name'] = $order->billing_first_name; |
| 390 | 390 | $stripe_params['billing_last_name'] = $order->billing_last_name; |
@@ -396,14 +396,14 @@ discard block |
||
| 396 | 396 | $stripe_params['billing_country'] = $order->billing_country; |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ); |
|
| 400 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
| 401 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
| 399 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'); |
|
| 400 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
| 401 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
| 402 | 402 | |
| 403 | 403 | // merge localized messages to be use in JS |
| 404 | - $stripe_params = array_merge( $stripe_params, $this->get_localized_messages() ); |
|
| 404 | + $stripe_params = array_merge($stripe_params, $this->get_localized_messages()); |
|
| 405 | 405 | |
| 406 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 406 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -412,24 +412,24 @@ discard block |
||
| 412 | 412 | * @param object $source |
| 413 | 413 | * @return array() |
| 414 | 414 | */ |
| 415 | - protected function generate_payment_request( $order, $source ) { |
|
| 415 | + protected function generate_payment_request($order, $source) { |
|
| 416 | 416 | $post_data = array(); |
| 417 | - $post_data['currency'] = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() ); |
|
| 418 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 419 | - $post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
| 417 | + $post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency()); |
|
| 418 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 419 | + $post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
| 420 | 420 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
| 421 | 421 | |
| 422 | - if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 422 | + if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 423 | 423 | $post_data['receipt_email'] = $order->billing_email; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - $post_data['expand[]'] = 'balance_transaction'; |
|
| 426 | + $post_data['expand[]'] = 'balance_transaction'; |
|
| 427 | 427 | |
| 428 | - if ( $source->customer ) { |
|
| 428 | + if ($source->customer) { |
|
| 429 | 429 | $post_data['customer'] = $source->customer; |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - if ( $source->source ) { |
|
| 432 | + if ($source->source) { |
|
| 433 | 433 | $post_data['source'] = $source->source; |
| 434 | 434 | } |
| 435 | 435 | |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | * @param WC_Order $order |
| 442 | 442 | * @param object $source |
| 443 | 443 | */ |
| 444 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
| 444 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -453,22 +453,22 @@ discard block |
||
| 453 | 453 | * @throws Exception When card was not added or for and invalid card. |
| 454 | 454 | * @return object |
| 455 | 455 | */ |
| 456 | - protected function get_source( $user_id, $force_customer = false ) { |
|
| 457 | - $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
| 456 | + protected function get_source($user_id, $force_customer = false) { |
|
| 457 | + $stripe_customer = new WC_Stripe_Customer($user_id); |
|
| 458 | 458 | $stripe_source = false; |
| 459 | 459 | $token_id = false; |
| 460 | 460 | |
| 461 | 461 | // New CC info was entered and we have a new token to process |
| 462 | - if ( isset( $_POST['stripe_token'] ) ) { |
|
| 463 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
| 464 | - $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
| 462 | + if (isset($_POST['stripe_token'])) { |
|
| 463 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
| 464 | + $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
| 465 | 465 | |
| 466 | 466 | // This is true if the user wants to store the card to their account. |
| 467 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
| 468 | - $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
| 467 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
| 468 | + $stripe_source = $stripe_customer->add_card($stripe_token); |
|
| 469 | 469 | |
| 470 | - if ( is_wp_error( $stripe_source ) ) { |
|
| 471 | - throw new Exception( $stripe_source->get_error_message() ); |
|
| 470 | + if (is_wp_error($stripe_source)) { |
|
| 471 | + throw new Exception($stripe_source->get_error_message()); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | } else { |
@@ -479,13 +479,13 @@ discard block |
||
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | // Use an existing token, and then process the payment |
| 482 | - elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
| 483 | - $token_id = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
| 484 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 482 | + elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
| 483 | + $token_id = wc_clean($_POST['wc-stripe-payment-token']); |
|
| 484 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 485 | 485 | |
| 486 | - if ( ! $token || $token->get_user_id() !== get_current_user_id() ) { |
|
| 487 | - WC()->session->set( 'refresh_totals', true ); |
|
| 488 | - throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
| 486 | + if ( ! $token || $token->get_user_id() !== get_current_user_id()) { |
|
| 487 | + WC()->session->set('refresh_totals', true); |
|
| 488 | + throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | $stripe_source = $token->get_token(); |
@@ -509,16 +509,16 @@ discard block |
||
| 509 | 509 | * @param object $order |
| 510 | 510 | * @return object |
| 511 | 511 | */ |
| 512 | - protected function get_order_source( $order = null ) { |
|
| 512 | + protected function get_order_source($order = null) { |
|
| 513 | 513 | $stripe_customer = new WC_Stripe_Customer(); |
| 514 | 514 | $stripe_source = false; |
| 515 | 515 | $token_id = false; |
| 516 | 516 | |
| 517 | - if ( $order ) { |
|
| 518 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) { |
|
| 519 | - $stripe_customer->set_id( $meta_value ); |
|
| 517 | + if ($order) { |
|
| 518 | + if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) { |
|
| 519 | + $stripe_customer->set_id($meta_value); |
|
| 520 | 520 | } |
| 521 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) { |
|
| 521 | + if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) { |
|
| 522 | 522 | $stripe_source = $meta_value; |
| 523 | 523 | } |
| 524 | 524 | } |
@@ -541,50 +541,50 @@ discard block |
||
| 541 | 541 | * |
| 542 | 542 | * @return array|void |
| 543 | 543 | */ |
| 544 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
| 544 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
| 545 | 545 | try { |
| 546 | - $order = wc_get_order( $order_id ); |
|
| 547 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
| 546 | + $order = wc_get_order($order_id); |
|
| 547 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
| 548 | 548 | |
| 549 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
| 550 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
| 551 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
| 552 | - throw new Exception( $error_msg ); |
|
| 549 | + if (empty($source->source) && empty($source->customer)) { |
|
| 550 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
| 551 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
| 552 | + throw new Exception($error_msg); |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | // Store source to order meta. |
| 556 | - $this->save_source( $order, $source ); |
|
| 556 | + $this->save_source($order, $source); |
|
| 557 | 557 | |
| 558 | 558 | // Handle payment. |
| 559 | - if ( $order->get_total() > 0 ) { |
|
| 559 | + if ($order->get_total() > 0) { |
|
| 560 | 560 | |
| 561 | - if ( $order->get_total() * 100 < 50 ) { |
|
| 562 | - throw new Exception( __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe' ) ); |
|
| 561 | + if ($order->get_total() * 100 < 50) { |
|
| 562 | + throw new Exception(__('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe')); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | - WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 565 | + WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 566 | 566 | |
| 567 | 567 | // Make the request. |
| 568 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 568 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 569 | 569 | |
| 570 | - if ( is_wp_error( $response ) ) { |
|
| 570 | + if (is_wp_error($response)) { |
|
| 571 | 571 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 572 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
| 573 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
| 574 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
| 572 | + if ('customer' === $response->get_error_code() && $retry) { |
|
| 573 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
| 574 | + return $this->process_payment($order_id, false, $force_customer); |
|
| 575 | 575 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 576 | - } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
| 577 | - $token = WC_Payment_Tokens::get( $source->token_id ); |
|
| 576 | + } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
| 577 | + $token = WC_Payment_Tokens::get($source->token_id); |
|
| 578 | 578 | $token->delete(); |
| 579 | - throw new Exception( __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ) ); |
|
| 579 | + throw new Exception(__('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe')); |
|
| 580 | 580 | } |
| 581 | 581 | $localized_messages = $this->get_localized_messages(); |
| 582 | 582 | |
| 583 | - throw new Exception( ( isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message() ) ); |
|
| 583 | + throw new Exception((isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message())); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | // Process valid response. |
| 587 | - $this->process_response( $response, $order ); |
|
| 587 | + $this->process_response($response, $order); |
|
| 588 | 588 | } else { |
| 589 | 589 | $order->payment_complete(); |
| 590 | 590 | } |
@@ -592,23 +592,23 @@ discard block |
||
| 592 | 592 | // Remove cart. |
| 593 | 593 | WC()->cart->empty_cart(); |
| 594 | 594 | |
| 595 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 595 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
| 596 | 596 | |
| 597 | 597 | // Return thank you page redirect. |
| 598 | 598 | return array( |
| 599 | 599 | 'result' => 'success', |
| 600 | - 'redirect' => $this->get_return_url( $order ) |
|
| 600 | + 'redirect' => $this->get_return_url($order) |
|
| 601 | 601 | ); |
| 602 | 602 | |
| 603 | - } catch ( Exception $e ) {error_log( 'order: ' . print_r($order,true)); |
|
| 604 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 605 | - WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 603 | + } catch (Exception $e) {error_log('order: ' . print_r($order, true)); |
|
| 604 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 605 | + WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 606 | 606 | |
| 607 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 608 | - $this->send_failed_order_email( $order_id ); |
|
| 607 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 608 | + $this->send_failed_order_email($order_id); |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 611 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 612 | 612 | |
| 613 | 613 | return array( |
| 614 | 614 | 'result' => 'fail', |
@@ -623,52 +623,52 @@ discard block |
||
| 623 | 623 | * @param WC_Order $order For to which the source applies. |
| 624 | 624 | * @param stdClass $source Source information. |
| 625 | 625 | */ |
| 626 | - protected function save_source( $order, $source ) { |
|
| 626 | + protected function save_source($order, $source) { |
|
| 627 | 627 | // Store source in the order. |
| 628 | - if ( $source->customer ) { |
|
| 629 | - update_post_meta( $order->id, '_stripe_customer_id', $source->customer ); |
|
| 628 | + if ($source->customer) { |
|
| 629 | + update_post_meta($order->id, '_stripe_customer_id', $source->customer); |
|
| 630 | 630 | } |
| 631 | - if ( $source->source ) { |
|
| 632 | - update_post_meta( $order->id, '_stripe_card_id', $source->source ); |
|
| 631 | + if ($source->source) { |
|
| 632 | + update_post_meta($order->id, '_stripe_card_id', $source->source); |
|
| 633 | 633 | } |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | /** |
| 637 | 637 | * Store extra meta data for an order from a Stripe Response. |
| 638 | 638 | */ |
| 639 | - public function process_response( $response, $order ) { |
|
| 640 | - WC_Stripe::log( "Processing response: " . print_r( $response, true ) ); |
|
| 639 | + public function process_response($response, $order) { |
|
| 640 | + WC_Stripe::log("Processing response: " . print_r($response, true)); |
|
| 641 | 641 | |
| 642 | 642 | // Store charge data |
| 643 | - update_post_meta( $order->id, '_stripe_charge_id', $response->id ); |
|
| 644 | - update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
| 643 | + update_post_meta($order->id, '_stripe_charge_id', $response->id); |
|
| 644 | + update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
| 645 | 645 | |
| 646 | 646 | // Store other data such as fees |
| 647 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
| 647 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
| 648 | 648 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 649 | 649 | // values are in the local currency of the Stripe account, not from WC. |
| 650 | - $fee = ! empty( $response->balance_transaction->fee ) ? number_format( $response->balance_transaction->fee / 100, 2, '.', '' ) : 0; |
|
| 651 | - $net = ! empty( $response->balance_transaction->net ) ? number_format( $response->balance_transaction->net / 100, 2, '.', '' ) : 0; |
|
| 652 | - update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
| 653 | - update_post_meta( $order->id, 'Net Revenue From Stripe', $net ); |
|
| 650 | + $fee = ! empty($response->balance_transaction->fee) ? number_format($response->balance_transaction->fee / 100, 2, '.', '') : 0; |
|
| 651 | + $net = ! empty($response->balance_transaction->net) ? number_format($response->balance_transaction->net / 100, 2, '.', '') : 0; |
|
| 652 | + update_post_meta($order->id, 'Stripe Fee', $fee); |
|
| 653 | + update_post_meta($order->id, 'Net Revenue From Stripe', $net); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | - if ( $response->captured ) { |
|
| 657 | - $order->payment_complete( $response->id ); |
|
| 656 | + if ($response->captured) { |
|
| 657 | + $order->payment_complete($response->id); |
|
| 658 | 658 | |
| 659 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
| 660 | - $order->add_order_note( $message ); |
|
| 661 | - WC_Stripe::log( 'Success: ' . $message ); |
|
| 659 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
| 660 | + $order->add_order_note($message); |
|
| 661 | + WC_Stripe::log('Success: ' . $message); |
|
| 662 | 662 | |
| 663 | 663 | } else { |
| 664 | - add_post_meta( $order->id, '_transaction_id', $response->id, true ); |
|
| 664 | + add_post_meta($order->id, '_transaction_id', $response->id, true); |
|
| 665 | 665 | |
| 666 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 666 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 667 | 667 | $order->reduce_order_stock(); |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | - $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 ) ); |
|
| 671 | - WC_Stripe::log( "Successful auth: $response->id" ); |
|
| 670 | + $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)); |
|
| 671 | + WC_Stripe::log("Successful auth: $response->id"); |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | return $response; |
@@ -680,32 +680,32 @@ discard block |
||
| 680 | 680 | * @since 3.0.0 |
| 681 | 681 | */ |
| 682 | 682 | public function add_payment_method() { |
| 683 | - if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
| 684 | - wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
| 683 | + if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
| 684 | + wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
| 685 | 685 | return; |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 689 | - $card = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
| 688 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 689 | + $card = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
| 690 | 690 | |
| 691 | - if ( is_wp_error( $card ) ) { |
|
| 691 | + if (is_wp_error($card)) { |
|
| 692 | 692 | $localized_messages = $this->get_localized_messages(); |
| 693 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
| 693 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
| 694 | 694 | |
| 695 | 695 | // loop through the errors to find matching localized message |
| 696 | - foreach ( $card->errors as $error => $msg ) { |
|
| 697 | - if ( isset( $localized_messages[ $error ] ) ) { |
|
| 698 | - $error_msg = $localized_messages[ $error ]; |
|
| 696 | + foreach ($card->errors as $error => $msg) { |
|
| 697 | + if (isset($localized_messages[$error])) { |
|
| 698 | + $error_msg = $localized_messages[$error]; |
|
| 699 | 699 | } |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - wc_add_notice( $error_msg, 'error' ); |
|
| 702 | + wc_add_notice($error_msg, 'error'); |
|
| 703 | 703 | return; |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | return array( |
| 707 | 707 | 'result' => 'success', |
| 708 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
| 708 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
| 709 | 709 | ); |
| 710 | 710 | } |
| 711 | 711 | |
@@ -715,36 +715,36 @@ discard block |
||
| 715 | 715 | * @param float $amount |
| 716 | 716 | * @return bool |
| 717 | 717 | */ |
| 718 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 719 | - $order = wc_get_order( $order_id ); |
|
| 718 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
| 719 | + $order = wc_get_order($order_id); |
|
| 720 | 720 | |
| 721 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 721 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
| 722 | 722 | return false; |
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | $body = array(); |
| 726 | 726 | |
| 727 | - if ( ! is_null( $amount ) ) { |
|
| 728 | - $body['amount'] = $this->get_stripe_amount( $amount ); |
|
| 727 | + if ( ! is_null($amount)) { |
|
| 728 | + $body['amount'] = $this->get_stripe_amount($amount); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | - if ( $reason ) { |
|
| 731 | + if ($reason) { |
|
| 732 | 732 | $body['metadata'] = array( |
| 733 | 733 | 'reason' => $reason, |
| 734 | 734 | ); |
| 735 | 735 | } |
| 736 | 736 | |
| 737 | - WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
| 737 | + WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
| 738 | 738 | |
| 739 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
| 739 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
| 740 | 740 | |
| 741 | - if ( is_wp_error( $response ) ) { |
|
| 742 | - WC_Stripe::log( "Error: " . $response->get_error_message() ); |
|
| 741 | + if (is_wp_error($response)) { |
|
| 742 | + WC_Stripe::log("Error: " . $response->get_error_message()); |
|
| 743 | 743 | return $response; |
| 744 | - } elseif ( ! empty( $response->id ) ) { |
|
| 745 | - $refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
| 746 | - $order->add_order_note( $refund_message ); |
|
| 747 | - WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 744 | + } elseif ( ! empty($response->id)) { |
|
| 745 | + $refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
| 746 | + $order->add_order_note($refund_message); |
|
| 747 | + WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message))); |
|
| 748 | 748 | return true; |
| 749 | 749 | } |
| 750 | 750 | } |
@@ -757,10 +757,10 @@ discard block |
||
| 757 | 757 | * @param int $order_id |
| 758 | 758 | * @return null |
| 759 | 759 | */ |
| 760 | - public function send_failed_order_email( $order_id ) { |
|
| 760 | + public function send_failed_order_email($order_id) { |
|
| 761 | 761 | $emails = WC()->mailer()->get_emails(); |
| 762 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
| 763 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
| 762 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
| 763 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
| 764 | 764 | } |
| 765 | 765 | } |
| 766 | 766 | } |
@@ -25,20 +25,20 @@ discard block |
||
| 25 | 25 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 28 | +if ( ! defined('ABSPATH')) { |
|
| 29 | 29 | exit; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Required minimums and constants |
| 34 | 34 | */ |
| 35 | -define( 'WC_STRIPE_VERSION', '3.0.5' ); |
|
| 36 | -define( 'WC_STRIPE_MIN_PHP_VER', '5.3.0' ); |
|
| 37 | -define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' ); |
|
| 38 | -define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
| 39 | -define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
| 35 | +define('WC_STRIPE_VERSION', '3.0.5'); |
|
| 36 | +define('WC_STRIPE_MIN_PHP_VER', '5.3.0'); |
|
| 37 | +define('WC_STRIPE_MIN_WC_VER', '2.5.0'); |
|
| 38 | +define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
| 39 | +define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
| 40 | 40 | |
| 41 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
| 41 | +if ( ! class_exists('WC_Stripe')) : |
|
| 42 | 42 | |
| 43 | 43 | class WC_Stripe { |
| 44 | 44 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @return Singleton The *Singleton* instance. |
| 59 | 59 | */ |
| 60 | 60 | public static function get_instance() { |
| 61 | - if ( null === self::$instance ) { |
|
| 61 | + if (null === self::$instance) { |
|
| 62 | 62 | self::$instance = new self(); |
| 63 | 63 | } |
| 64 | 64 | return self::$instance; |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | * *Singleton* via the `new` operator from outside of this class. |
| 108 | 108 | */ |
| 109 | 109 | protected function __construct() { |
| 110 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
| 111 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
| 112 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
| 110 | + add_action('admin_init', array($this, 'check_environment')); |
|
| 111 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
| 112 | + add_action('plugins_loaded', array($this, 'init')); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -117,31 +117,31 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | public function init() { |
| 119 | 119 | // Don't hook anything else in the plugin if we're in an incompatible environment |
| 120 | - if ( self::get_environment_warning() ) { |
|
| 120 | + if (self::get_environment_warning()) { |
|
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
| 125 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
| 124 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
| 125 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
| 126 | 126 | |
| 127 | 127 | // Init the gateway itself |
| 128 | 128 | $this->init_gateways(); |
| 129 | 129 | |
| 130 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
| 131 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
| 132 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
| 133 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
| 134 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
| 135 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
| 136 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
| 137 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
| 130 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
| 131 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
| 132 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
| 133 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
| 134 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
| 135 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
| 136 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
| 137 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | 141 | * Allow this class and other classes to add slug keyed notices (to avoid duplication) |
| 142 | 142 | */ |
| 143 | - public function add_admin_notice( $slug, $class, $message ) { |
|
| 144 | - $this->notices[ $slug ] = array( |
|
| 143 | + public function add_admin_notice($slug, $class, $message) { |
|
| 144 | + $this->notices[$slug] = array( |
|
| 145 | 145 | 'class' => $class, |
| 146 | 146 | 'message' => $message |
| 147 | 147 | ); |
@@ -154,21 +154,21 @@ discard block |
||
| 154 | 154 | public function check_environment() { |
| 155 | 155 | $environment_warning = self::get_environment_warning(); |
| 156 | 156 | |
| 157 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
| 158 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 157 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
| 158 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | // Check if secret key present. Otherwise prompt, via notice, to go to |
| 162 | 162 | // setting. |
| 163 | - if ( ! class_exists( 'WC_Stripe_API' ) ) { |
|
| 164 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
| 163 | + if ( ! class_exists('WC_Stripe_API')) { |
|
| 164 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $secret = WC_Stripe_API::get_secret_key(); |
| 168 | 168 | |
| 169 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
| 169 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
| 170 | 170 | $setting_link = $this->get_setting_link(); |
| 171 | - $this->add_admin_notice( 'prompt_connect', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ) ); |
|
| 171 | + $this->add_admin_notice('prompt_connect', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link)); |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
@@ -177,24 +177,24 @@ discard block |
||
| 177 | 177 | * found or false if the environment has no problems. |
| 178 | 178 | */ |
| 179 | 179 | static function get_environment_warning() { |
| 180 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
| 181 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe' ); |
|
| 180 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
| 181 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe'); |
|
| 182 | 182 | |
| 183 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
| 183 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
| 187 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
| 186 | + if ( ! defined('WC_VERSION')) { |
|
| 187 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
| 191 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe' ); |
|
| 190 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
| 191 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe'); |
|
| 192 | 192 | |
| 193 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
| 193 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - if ( ! function_exists( 'curl_init' ) ) { |
|
| 197 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
| 196 | + if ( ! function_exists('curl_init')) { |
|
| 197 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | return false; |
@@ -205,15 +205,15 @@ discard block |
||
| 205 | 205 | * |
| 206 | 206 | * @since 1.0.0 |
| 207 | 207 | */ |
| 208 | - public function plugin_action_links( $links ) { |
|
| 208 | + public function plugin_action_links($links) { |
|
| 209 | 209 | $setting_link = $this->get_setting_link(); |
| 210 | 210 | |
| 211 | 211 | $plugin_links = array( |
| 212 | - '<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 213 | - '<a href="https://docs.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 214 | - '<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 212 | + '<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
| 213 | + '<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
| 214 | + '<a href="http://support.woothemes.com/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
| 215 | 215 | ); |
| 216 | - return array_merge( $plugin_links, $links ); |
|
| 216 | + return array_merge($plugin_links, $links); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -224,20 +224,20 @@ discard block |
||
| 224 | 224 | * @return string Setting link |
| 225 | 225 | */ |
| 226 | 226 | public function get_setting_link() { |
| 227 | - $use_id_as_section = version_compare( WC()->version, '2.6', '>=' ); |
|
| 227 | + $use_id_as_section = version_compare(WC()->version, '2.6', '>='); |
|
| 228 | 228 | |
| 229 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
| 229 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
| 230 | 230 | |
| 231 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
| 231 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
| 235 | 235 | * Display any notices we've collected thus far (e.g. for connection, disconnection) |
| 236 | 236 | */ |
| 237 | 237 | public function admin_notices() { |
| 238 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 239 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 240 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 238 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 239 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 240 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 241 | 241 | echo "</p></div>"; |
| 242 | 242 | } |
| 243 | 243 | } |
@@ -248,27 +248,27 @@ discard block |
||
| 248 | 248 | * @since 1.0.0 |
| 249 | 249 | */ |
| 250 | 250 | public function init_gateways() { |
| 251 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
| 251 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
| 252 | 252 | $this->subscription_support_enabled = true; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 255 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
| 256 | 256 | $this->pre_order_enabled = true; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if ( ! class_exists( 'WC_Payment_Gateway' ) ) { |
|
| 259 | + if ( ! class_exists('WC_Payment_Gateway')) { |
|
| 260 | 260 | return; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if ( class_exists( 'WC_Payment_Gateway_CC' ) ) { |
|
| 264 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
| 263 | + if (class_exists('WC_Payment_Gateway_CC')) { |
|
| 264 | + include_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
| 265 | 265 | } else { |
| 266 | - include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe.php' ); |
|
| 267 | - include_once( dirname( __FILE__ ) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php' ); |
|
| 266 | + include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe.php'); |
|
| 267 | + include_once(dirname(__FILE__) . '/includes/legacy/class-wc-gateway-stripe-saved-cards.php'); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
| 271 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
| 270 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
| 271 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
| 272 | 272 | |
| 273 | 273 | $load_addons = ( |
| 274 | 274 | $this->subscription_support_enabled |
@@ -276,8 +276,8 @@ discard block |
||
| 276 | 276 | $this->pre_order_enabled |
| 277 | 277 | ); |
| 278 | 278 | |
| 279 | - if ( $load_addons ) { |
|
| 280 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe-addons.php' ); |
|
| 279 | + if ($load_addons) { |
|
| 280 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe-addons.php'); |
|
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | * |
| 287 | 287 | * @since 1.0.0 |
| 288 | 288 | */ |
| 289 | - public function add_gateways( $methods ) { |
|
| 290 | - if ( $this->subscription_support_enabled || $this->pre_order_enabled ) { |
|
| 289 | + public function add_gateways($methods) { |
|
| 290 | + if ($this->subscription_support_enabled || $this->pre_order_enabled) { |
|
| 291 | 291 | $methods[] = 'WC_Gateway_Stripe_Addons'; |
| 292 | 292 | } else { |
| 293 | 293 | $methods[] = 'WC_Gateway_Stripe'; |
@@ -300,35 +300,35 @@ discard block |
||
| 300 | 300 | * |
| 301 | 301 | * @param int $order_id |
| 302 | 302 | */ |
| 303 | - public function capture_payment( $order_id ) { |
|
| 304 | - $order = wc_get_order( $order_id ); |
|
| 303 | + public function capture_payment($order_id) { |
|
| 304 | + $order = wc_get_order($order_id); |
|
| 305 | 305 | |
| 306 | - if ( 'stripe' === $order->payment_method ) { |
|
| 307 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
| 308 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
| 306 | + if ('stripe' === $order->payment_method) { |
|
| 307 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
| 308 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
| 309 | 309 | |
| 310 | - if ( $charge && 'no' === $captured ) { |
|
| 311 | - $result = WC_Stripe_API::request( array( |
|
| 310 | + if ($charge && 'no' === $captured) { |
|
| 311 | + $result = WC_Stripe_API::request(array( |
|
| 312 | 312 | 'amount' => $order->get_total() * 100, |
| 313 | 313 | 'expand[]' => 'balance_transaction' |
| 314 | - ), 'charges/' . $charge . '/capture' ); |
|
| 314 | + ), 'charges/' . $charge . '/capture'); |
|
| 315 | 315 | |
| 316 | - if ( is_wp_error( $result ) ) { |
|
| 317 | - $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
| 316 | + if (is_wp_error($result)) { |
|
| 317 | + $order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
| 318 | 318 | } else { |
| 319 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
| 320 | - update_post_meta( $order->id, '_stripe_charge_captured', 'yes' ); |
|
| 319 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
| 320 | + update_post_meta($order->id, '_stripe_charge_captured', 'yes'); |
|
| 321 | 321 | |
| 322 | 322 | // Store other data such as fees |
| 323 | - update_post_meta( $order->id, 'Stripe Payment ID', $result->id ); |
|
| 323 | + update_post_meta($order->id, 'Stripe Payment ID', $result->id); |
|
| 324 | 324 | |
| 325 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
| 325 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
| 326 | 326 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 327 | 327 | // values are in the local currency of the Stripe account, not from WC. |
| 328 | - $fee = ! empty( $result->balance_transaction->fee ) ? number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) : 0; |
|
| 329 | - $net = ! empty( $result->balance_transaction->net ) ? number_format( $result->balance_transaction->net / 100, 2, '.', '' ) : 0; |
|
| 330 | - update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
| 331 | - update_post_meta( $order->id, 'Net Revenue From Stripe', $net ); |
|
| 328 | + $fee = ! empty($result->balance_transaction->fee) ? number_format($result->balance_transaction->fee / 100, 2, '.', '') : 0; |
|
| 329 | + $net = ! empty($result->balance_transaction->net) ? number_format($result->balance_transaction->net / 100, 2, '.', '') : 0; |
|
| 330 | + update_post_meta($order->id, 'Stripe Fee', $fee); |
|
| 331 | + update_post_meta($order->id, 'Net Revenue From Stripe', $net); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | } |
@@ -340,23 +340,23 @@ discard block |
||
| 340 | 340 | * |
| 341 | 341 | * @param int $order_id |
| 342 | 342 | */ |
| 343 | - public function cancel_payment( $order_id ) { |
|
| 344 | - $order = wc_get_order( $order_id ); |
|
| 343 | + public function cancel_payment($order_id) { |
|
| 344 | + $order = wc_get_order($order_id); |
|
| 345 | 345 | |
| 346 | - if ( 'stripe' === $order->payment_method ) { |
|
| 347 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
| 346 | + if ('stripe' === $order->payment_method) { |
|
| 347 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
| 348 | 348 | |
| 349 | - if ( $charge ) { |
|
| 350 | - $result = WC_Stripe_API::request( array( |
|
| 349 | + if ($charge) { |
|
| 350 | + $result = WC_Stripe_API::request(array( |
|
| 351 | 351 | 'amount' => $order->get_total() * 100, |
| 352 | - ), 'charges/' . $charge . '/refund' ); |
|
| 352 | + ), 'charges/' . $charge . '/refund'); |
|
| 353 | 353 | |
| 354 | - if ( is_wp_error( $result ) ) { |
|
| 355 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
| 354 | + if (is_wp_error($result)) { |
|
| 355 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
| 356 | 356 | } else { |
| 357 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
| 358 | - delete_post_meta( $order->id, '_stripe_charge_captured' ); |
|
| 359 | - delete_post_meta( $order->id, '_stripe_charge_id' ); |
|
| 357 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
| 358 | + delete_post_meta($order->id, '_stripe_charge_captured'); |
|
| 359 | + delete_post_meta($order->id, '_stripe_charge_id'); |
|
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | 362 | } |
@@ -367,28 +367,28 @@ discard block |
||
| 367 | 367 | * @param array $tokens |
| 368 | 368 | * @return array |
| 369 | 369 | */ |
| 370 | - public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) { |
|
| 371 | - if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 372 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 370 | + public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) { |
|
| 371 | + if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) { |
|
| 372 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 373 | 373 | $stripe_cards = $stripe_customer->get_cards(); |
| 374 | 374 | $stored_tokens = array(); |
| 375 | 375 | |
| 376 | - foreach ( $tokens as $token ) { |
|
| 376 | + foreach ($tokens as $token) { |
|
| 377 | 377 | $stored_tokens[] = $token->get_token(); |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - foreach ( $stripe_cards as $card ) { |
|
| 381 | - if ( ! in_array( $card->id, $stored_tokens ) ) { |
|
| 380 | + foreach ($stripe_cards as $card) { |
|
| 381 | + if ( ! in_array($card->id, $stored_tokens)) { |
|
| 382 | 382 | $token = new WC_Payment_Token_CC(); |
| 383 | - $token->set_token( $card->id ); |
|
| 384 | - $token->set_gateway_id( 'stripe' ); |
|
| 385 | - $token->set_card_type( strtolower( $card->brand ) ); |
|
| 386 | - $token->set_last4( $card->last4 ); |
|
| 387 | - $token->set_expiry_month( $card->exp_month ); |
|
| 388 | - $token->set_expiry_year( $card->exp_year ); |
|
| 389 | - $token->set_user_id( $customer_id ); |
|
| 383 | + $token->set_token($card->id); |
|
| 384 | + $token->set_gateway_id('stripe'); |
|
| 385 | + $token->set_card_type(strtolower($card->brand)); |
|
| 386 | + $token->set_last4($card->last4); |
|
| 387 | + $token->set_expiry_month($card->exp_month); |
|
| 388 | + $token->set_expiry_year($card->exp_year); |
|
| 389 | + $token->set_user_id($customer_id); |
|
| 390 | 390 | $token->save(); |
| 391 | - $tokens[ $token->get_id() ] = $token; |
|
| 391 | + $tokens[$token->get_id()] = $token; |
|
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | } |
@@ -398,21 +398,21 @@ discard block |
||
| 398 | 398 | /** |
| 399 | 399 | * Delete token from Stripe |
| 400 | 400 | */ |
| 401 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
| 402 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
| 403 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 404 | - $stripe_customer->delete_card( $token->get_token() ); |
|
| 401 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
| 402 | + if ('stripe' === $token->get_gateway_id()) { |
|
| 403 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 404 | + $stripe_customer->delete_card($token->get_token()); |
|
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
| 409 | 409 | * Set as default in Stripe |
| 410 | 410 | */ |
| 411 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
| 412 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 413 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
| 414 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 415 | - $stripe_customer->set_default_card( $token->get_token() ); |
|
| 411 | + public function woocommerce_payment_token_set_default($token_id) { |
|
| 412 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 413 | + if ('stripe' === $token->get_gateway_id()) { |
|
| 414 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 415 | + $stripe_customer->set_default_card($token->get_token()); |
|
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | 418 | |
@@ -424,15 +424,15 @@ discard block |
||
| 424 | 424 | * And fits on your back? |
| 425 | 425 | * It's log, log, log |
| 426 | 426 | */ |
| 427 | - public static function log( $message ) { |
|
| 428 | - if ( empty( self::$log ) ) { |
|
| 427 | + public static function log($message) { |
|
| 428 | + if (empty(self::$log)) { |
|
| 429 | 429 | self::$log = new WC_Logger(); |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - self::$log->add( 'woocommerce-gateway-stripe', $message ); |
|
| 432 | + self::$log->add('woocommerce-gateway-stripe', $message); |
|
| 433 | 433 | |
| 434 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 435 | - error_log( $message ); |
|
| 434 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 435 | + error_log($message); |
|
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | } |