@@ -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' ) && function_exists( 'WC' ) ) : |
|
| 41 | +if ( ! class_exists('WC_Stripe') && function_exists('WC')) : |
|
| 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( plugin_basename( 'includes/class-wc-stripe-api.php' ) ); |
|
| 125 | - include_once( plugin_basename( 'includes/class-wc-stripe-customer.php' ) ); |
|
| 124 | + include_once(plugin_basename('includes/class-wc-stripe-api.php')); |
|
| 125 | + include_once(plugin_basename('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( plugin_basename( 'includes/class-wc-stripe-api.php' ) ); |
|
| 163 | + if ( ! class_exists('WC_Stripe_API')) { |
|
| 164 | + include_once(plugin_basename('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( plugin_basename( 'includes/class-wc-gateway-stripe.php' ) ); |
|
| 263 | + if (class_exists('WC_Payment_Gateway_CC')) { |
|
| 264 | + include_once(plugin_basename('includes/class-wc-gateway-stripe.php')); |
|
| 265 | 265 | } else { |
| 266 | - include_once( plugin_basename( 'includes/legacy/class-wc-gateway-stripe.php' ) ); |
|
| 267 | - include_once( plugin_basename( 'includes/legacy/class-wc-gateway-stripe-saved-cards.php' ) ); |
|
| 266 | + include_once(plugin_basename('includes/legacy/class-wc-gateway-stripe.php')); |
|
| 267 | + include_once(plugin_basename('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( plugin_basename( 'includes/class-wc-gateway-stripe-addons.php' ) ); |
|
| 279 | + if ($load_addons) { |
|
| 280 | + require_once(plugin_basename('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,31 +300,31 @@ 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 ) ) { |
|
| 326 | - update_post_meta( $order->id, 'Stripe Fee', number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) ); |
|
| 327 | - update_post_meta( $order->id, 'Net Revenue From Stripe', ( $order->order_total - number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) ) ); |
|
| 325 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
| 326 | + update_post_meta($order->id, 'Stripe Fee', number_format($result->balance_transaction->fee / 100, 2, '.', '')); |
|
| 327 | + update_post_meta($order->id, 'Net Revenue From Stripe', ($order->order_total - number_format($result->balance_transaction->fee / 100, 2, '.', ''))); |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | } |
@@ -336,23 +336,23 @@ discard block |
||
| 336 | 336 | * |
| 337 | 337 | * @param int $order_id |
| 338 | 338 | */ |
| 339 | - public function cancel_payment( $order_id ) { |
|
| 340 | - $order = wc_get_order( $order_id ); |
|
| 339 | + public function cancel_payment($order_id) { |
|
| 340 | + $order = wc_get_order($order_id); |
|
| 341 | 341 | |
| 342 | - if ( 'stripe' === $order->payment_method ) { |
|
| 343 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
| 342 | + if ('stripe' === $order->payment_method) { |
|
| 343 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
| 344 | 344 | |
| 345 | - if ( $charge ) { |
|
| 346 | - $result = WC_Stripe_API::request( array( |
|
| 345 | + if ($charge) { |
|
| 346 | + $result = WC_Stripe_API::request(array( |
|
| 347 | 347 | 'amount' => $order->get_total() * 100, |
| 348 | - ), 'charges/' . $charge . '/refund' ); |
|
| 348 | + ), 'charges/' . $charge . '/refund'); |
|
| 349 | 349 | |
| 350 | - if ( is_wp_error( $result ) ) { |
|
| 351 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
| 350 | + if (is_wp_error($result)) { |
|
| 351 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
| 352 | 352 | } else { |
| 353 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
| 354 | - delete_post_meta( $order->id, '_stripe_charge_captured' ); |
|
| 355 | - delete_post_meta( $order->id, '_stripe_charge_id' ); |
|
| 353 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
| 354 | + delete_post_meta($order->id, '_stripe_charge_captured'); |
|
| 355 | + delete_post_meta($order->id, '_stripe_charge_id'); |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | } |
@@ -363,28 +363,28 @@ discard block |
||
| 363 | 363 | * @param array $tokens |
| 364 | 364 | * @return array |
| 365 | 365 | */ |
| 366 | - public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) { |
|
| 367 | - if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 368 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 366 | + public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) { |
|
| 367 | + if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) { |
|
| 368 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 369 | 369 | $stripe_cards = $stripe_customer->get_cards(); |
| 370 | 370 | $stored_tokens = array(); |
| 371 | 371 | |
| 372 | - foreach ( $tokens as $token ) { |
|
| 372 | + foreach ($tokens as $token) { |
|
| 373 | 373 | $stored_tokens[] = $token->get_token(); |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - foreach ( $stripe_cards as $card ) { |
|
| 377 | - if ( ! in_array( $card->id, $stored_tokens ) ) { |
|
| 376 | + foreach ($stripe_cards as $card) { |
|
| 377 | + if ( ! in_array($card->id, $stored_tokens)) { |
|
| 378 | 378 | $token = new WC_Payment_Token_CC(); |
| 379 | - $token->set_token( $card->id ); |
|
| 380 | - $token->set_gateway_id( 'stripe' ); |
|
| 381 | - $token->set_card_type( strtolower( $card->brand ) ); |
|
| 382 | - $token->set_last4( $card->last4 ); |
|
| 383 | - $token->set_expiry_month( $card->exp_month ); |
|
| 384 | - $token->set_expiry_year( $card->exp_year ); |
|
| 385 | - $token->set_user_id( $customer_id ); |
|
| 379 | + $token->set_token($card->id); |
|
| 380 | + $token->set_gateway_id('stripe'); |
|
| 381 | + $token->set_card_type(strtolower($card->brand)); |
|
| 382 | + $token->set_last4($card->last4); |
|
| 383 | + $token->set_expiry_month($card->exp_month); |
|
| 384 | + $token->set_expiry_year($card->exp_year); |
|
| 385 | + $token->set_user_id($customer_id); |
|
| 386 | 386 | $token->save(); |
| 387 | - $tokens[ $token->get_id() ] = $token; |
|
| 387 | + $tokens[$token->get_id()] = $token; |
|
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | } |
@@ -394,21 +394,21 @@ discard block |
||
| 394 | 394 | /** |
| 395 | 395 | * Delete token from Stripe |
| 396 | 396 | */ |
| 397 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
| 398 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
| 399 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 400 | - $stripe_customer->delete_card( $token->get_token() ); |
|
| 397 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
| 398 | + if ('stripe' === $token->get_gateway_id()) { |
|
| 399 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 400 | + $stripe_customer->delete_card($token->get_token()); |
|
| 401 | 401 | } |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
| 405 | 405 | * Set as default in Stripe |
| 406 | 406 | */ |
| 407 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
| 408 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 409 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
| 410 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 411 | - $stripe_customer->set_default_card( $token->get_token() ); |
|
| 407 | + public function woocommerce_payment_token_set_default($token_id) { |
|
| 408 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 409 | + if ('stripe' === $token->get_gateway_id()) { |
|
| 410 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 411 | + $stripe_customer->set_default_card($token->get_token()); |
|
| 412 | 412 | } |
| 413 | 413 | } |
| 414 | 414 | |
@@ -420,15 +420,15 @@ discard block |
||
| 420 | 420 | * And fits on your back? |
| 421 | 421 | * It's log, log, log |
| 422 | 422 | */ |
| 423 | - public static function log( $message ) { |
|
| 424 | - if ( empty( self::$log ) ) { |
|
| 423 | + public static function log($message) { |
|
| 424 | + if (empty(self::$log)) { |
|
| 425 | 425 | self::$log = new WC_Logger(); |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - self::$log->add( 'woocommerce-gateway-stripe', $message ); |
|
| 428 | + self::$log->add('woocommerce-gateway-stripe', $message); |
|
| 429 | 429 | |
| 430 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 431 | - error_log( $message ); |
|
| 430 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 431 | + error_log($message); |
|
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | 434 | } |