@@ -23,7 +23,6 @@ |
||
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * Set secret API Key. |
| 26 | - * @param string $key |
|
| 27 | 26 | */ |
| 28 | 27 | public static function set_secret_key( $secret_key ) { |
| 29 | 28 | self::$secret_key = $secret_key; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * Set secret API Key. |
| 27 | 27 | * @param string $key |
| 28 | 28 | */ |
| 29 | - public static function set_secret_key( $secret_key ) { |
|
| 29 | + public static function set_secret_key($secret_key) { |
|
| 30 | 30 | self::$secret_key = $secret_key; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | 37 | public static function get_secret_key() { |
| 38 | - if ( ! self::$secret_key ) { |
|
| 39 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 38 | + if ( ! self::$secret_key) { |
|
| 39 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 40 | 40 | |
| 41 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
| 42 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
| 41 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
| 42 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | return self::$secret_key; |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | return apply_filters( |
| 82 | 82 | 'woocommerce_stripe_request_headers', |
| 83 | 83 | array( |
| 84 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
| 84 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
| 85 | 85 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
| 86 | 86 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
| 87 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
| 87 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
| 88 | 88 | ) |
| 89 | 89 | ); |
| 90 | 90 | } |
@@ -101,16 +101,16 @@ discard block |
||
| 101 | 101 | * @return stdClass|array |
| 102 | 102 | * @throws WC_Stripe_Exception |
| 103 | 103 | */ |
| 104 | - public static function request( $request, $api = 'charges', $method = 'POST', $with_headers = false ) { |
|
| 105 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
| 104 | + public static function request($request, $api = 'charges', $method = 'POST', $with_headers = false) { |
|
| 105 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
| 106 | 106 | |
| 107 | 107 | $headers = self::get_headers(); |
| 108 | 108 | $idempotency_key = ''; |
| 109 | 109 | |
| 110 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
| 111 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
| 112 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
| 113 | - $idempotency_key = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request ); |
|
| 110 | + if ('charges' === $api && 'POST' === $method) { |
|
| 111 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
| 112 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
| 113 | + $idempotency_key = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request); |
|
| 114 | 114 | |
| 115 | 115 | $headers['Idempotency-Key'] = $idempotency_key; |
| 116 | 116 | } |
@@ -120,14 +120,14 @@ discard block |
||
| 120 | 120 | array( |
| 121 | 121 | 'method' => $method, |
| 122 | 122 | 'headers' => $headers, |
| 123 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
| 123 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
| 124 | 124 | 'timeout' => 70, |
| 125 | 125 | ) |
| 126 | 126 | ); |
| 127 | 127 | |
| 128 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 128 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 129 | 129 | WC_Stripe_Logger::log( |
| 130 | - 'Error Response: ' . print_r( $response, true ) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( |
|
| 130 | + 'Error Response: ' . print_r($response, true) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( |
|
| 131 | 131 | array( |
| 132 | 132 | 'api' => $api, |
| 133 | 133 | 'request' => $request, |
@@ -137,17 +137,17 @@ discard block |
||
| 137 | 137 | ) |
| 138 | 138 | ); |
| 139 | 139 | |
| 140 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 140 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if ( $with_headers ) { |
|
| 143 | + if ($with_headers) { |
|
| 144 | 144 | return array( |
| 145 | - 'headers' => wp_remote_retrieve_headers( $response ), |
|
| 146 | - 'body' => json_decode( $response['body'] ), |
|
| 145 | + 'headers' => wp_remote_retrieve_headers($response), |
|
| 146 | + 'body' => json_decode($response['body']), |
|
| 147 | 147 | ); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - return json_decode( $response['body'] ); |
|
| 150 | + return json_decode($response['body']); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -157,8 +157,8 @@ discard block |
||
| 157 | 157 | * @version 4.0.0 |
| 158 | 158 | * @param string $api |
| 159 | 159 | */ |
| 160 | - public static function retrieve( $api ) { |
|
| 161 | - WC_Stripe_Logger::log( "{$api}" ); |
|
| 160 | + public static function retrieve($api) { |
|
| 161 | + WC_Stripe_Logger::log("{$api}"); |
|
| 162 | 162 | |
| 163 | 163 | $response = wp_safe_remote_get( |
| 164 | 164 | self::ENDPOINT . $api, |
@@ -169,11 +169,11 @@ discard block |
||
| 169 | 169 | ) |
| 170 | 170 | ); |
| 171 | 171 | |
| 172 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 173 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
| 174 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 172 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 173 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
| 174 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - return json_decode( $response['body'] ); |
|
| 177 | + return json_decode($response['body']); |
|
| 178 | 178 | } |
| 179 | 179 | } |
@@ -289,7 +289,7 @@ |
||
| 289 | 289 | * |
| 290 | 290 | * @param int $order_id Reference. |
| 291 | 291 | * @param bool $retry Should we retry on fail. |
| 292 | - * @param bool $force_save_source Force payment source to be saved. |
|
| 292 | + * @param bool $force_save_save Force payment source to be saved. |
|
| 293 | 293 | * |
| 294 | 294 | * @throws Exception If payment will not be accepted. |
| 295 | 295 | * |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_alipay'; |
| 60 | - $this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @return bool |
| 123 | 123 | */ |
| 124 | 124 | public function is_available() { |
| 125 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 125 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 126 | 126 | return false; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | |
| 142 | 142 | $icons_str = ''; |
| 143 | 143 | |
| 144 | - $icons_str .= isset( $icons['alipay'] ) ? $icons['alipay'] : ''; |
|
| 144 | + $icons_str .= isset($icons['alipay']) ? $icons['alipay'] : ''; |
|
| 145 | 145 | |
| 146 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 146 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -153,19 +153,19 @@ discard block |
||
| 153 | 153 | * @version 4.0.0 |
| 154 | 154 | */ |
| 155 | 155 | public function payment_scripts() { |
| 156 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 156 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 157 | 157 | return; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - wp_enqueue_style( 'stripe_styles' ); |
|
| 161 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 160 | + wp_enqueue_style('stripe_styles'); |
|
| 161 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | 165 | * Initialize Gateway Settings Form Fields. |
| 166 | 166 | */ |
| 167 | 167 | public function init_form_fields() { |
| 168 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' ); |
|
| 168 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php'); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -177,13 +177,13 @@ discard block |
||
| 177 | 177 | $description = $this->get_description(); |
| 178 | 178 | |
| 179 | 179 | // If paying from order, we need to get total from order not cart. |
| 180 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 181 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 180 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 181 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 182 | 182 | $total = $order->get_total(); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if ( is_add_payment_method_page() ) { |
|
| 186 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 185 | + if (is_add_payment_method_page()) { |
|
| 186 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 187 | 187 | $total = ''; |
| 188 | 188 | } else { |
| 189 | 189 | $pay_button_text = ''; |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | echo '<div |
| 193 | 193 | id="stripe-alipay-payment-data" |
| 194 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 195 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 194 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 195 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 196 | 196 | |
| 197 | - if ( $description ) { |
|
| 198 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
| 197 | + if ($description) { |
|
| 198 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | echo '</div>'; |
@@ -209,24 +209,24 @@ discard block |
||
| 209 | 209 | * @param object $order |
| 210 | 210 | * @return mixed |
| 211 | 211 | */ |
| 212 | - public function create_source( $order ) { |
|
| 213 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
| 214 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 215 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 212 | + public function create_source($order) { |
|
| 213 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
| 214 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 215 | + $return_url = $this->get_stripe_return_url($order); |
|
| 216 | 216 | $post_data = array(); |
| 217 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 218 | - $post_data['currency'] = strtolower( $currency ); |
|
| 217 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 218 | + $post_data['currency'] = strtolower($currency); |
|
| 219 | 219 | $post_data['type'] = 'alipay'; |
| 220 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 221 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 220 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 221 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 222 | 222 | |
| 223 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 224 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 223 | + if ( ! empty($this->statement_descriptor)) { |
|
| 224 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' ); |
|
| 227 | + WC_Stripe_Logger::log('Info: Begin creating Alipay source'); |
|
| 228 | 228 | |
| 229 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_alipay_source', $post_data, $order ), 'sources' ); |
|
| 229 | + return WC_Stripe_API::request(apply_filters('wc_stripe_alipay_source', $post_data, $order), 'sources'); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -240,53 +240,53 @@ discard block |
||
| 240 | 240 | * |
| 241 | 241 | * @return array|void |
| 242 | 242 | */ |
| 243 | - public function process_payment( $order_id, $retry = true, $force_save_save = false ) { |
|
| 243 | + public function process_payment($order_id, $retry = true, $force_save_save = false) { |
|
| 244 | 244 | try { |
| 245 | - $order = wc_get_order( $order_id ); |
|
| 245 | + $order = wc_get_order($order_id); |
|
| 246 | 246 | |
| 247 | 247 | // This will throw exception if not valid. |
| 248 | - $this->validate_minimum_order_amount( $order ); |
|
| 248 | + $this->validate_minimum_order_amount($order); |
|
| 249 | 249 | |
| 250 | 250 | // This comes from the create account checkbox in the checkout page. |
| 251 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 251 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 252 | 252 | |
| 253 | - if ( $create_account ) { |
|
| 254 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
| 255 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 253 | + if ($create_account) { |
|
| 254 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
| 255 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 256 | 256 | $new_stripe_customer->create_customer(); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - $response = $this->create_source( $order ); |
|
| 259 | + $response = $this->create_source($order); |
|
| 260 | 260 | |
| 261 | - if ( ! empty( $response->error ) ) { |
|
| 262 | - $order->add_order_note( $response->error->message ); |
|
| 261 | + if ( ! empty($response->error)) { |
|
| 262 | + $order->add_order_note($response->error->message); |
|
| 263 | 263 | |
| 264 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 264 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 268 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 267 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 268 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 269 | 269 | } else { |
| 270 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 270 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 271 | 271 | $order->save(); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); |
|
| 274 | + WC_Stripe_Logger::log('Info: Redirecting to Alipay...'); |
|
| 275 | 275 | |
| 276 | 276 | return array( |
| 277 | 277 | 'result' => 'success', |
| 278 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 278 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 279 | 279 | ); |
| 280 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 281 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 282 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 280 | + } catch (WC_Stripe_Exception $e) { |
|
| 281 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 282 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 283 | 283 | |
| 284 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 284 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 285 | 285 | |
| 286 | - $statuses = array( 'pending', 'failed' ); |
|
| 286 | + $statuses = array('pending', 'failed'); |
|
| 287 | 287 | |
| 288 | - if ( $order->has_status( $statuses ) ) { |
|
| 289 | - $this->send_failed_order_email( $order_id ); |
|
| 288 | + if ($order->has_status($statuses)) { |
|
| 289 | + $this->send_failed_order_email($order_id); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | return array( |
@@ -2,12 +2,12 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class WC_Stripe_Test extends WP_UnitTestCase { |
| 4 | 4 | public function test_constants_defined() { |
| 5 | - $this->assertTrue( defined( 'WC_STRIPE_VERSION' ) ); |
|
| 6 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) ); |
|
| 7 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) ); |
|
| 8 | - $this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) ); |
|
| 9 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) ); |
|
| 10 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) ); |
|
| 5 | + $this->assertTrue(defined('WC_STRIPE_VERSION')); |
|
| 6 | + $this->assertTrue(defined('WC_STRIPE_MIN_PHP_VER')); |
|
| 7 | + $this->assertTrue(defined('WC_STRIPE_MIN_WC_VER')); |
|
| 8 | + $this->assertTrue(defined('WC_STRIPE_MAIN_FILE')); |
|
| 9 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_URL')); |
|
| 10 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_PATH')); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | * This test will see if we're indeed converting the price correctly. |
| 16 | 16 | */ |
| 17 | 17 | public function test_price_conversion_before_send_to_stripe() { |
| 18 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
| 19 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) ); |
|
| 20 | - $this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) ); |
|
| 21 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) ); |
|
| 22 | - $this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
| 18 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
| 19 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(10050, 'JPY')); |
|
| 20 | + $this->assertEquals(100, WC_Stripe_Helper::get_stripe_amount(100.50, 'JPY')); |
|
| 21 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50)); |
|
| 22 | + $this->assertInternalType('int', WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -33,37 +33,37 @@ discard block |
||
| 33 | 33 | $balance_fee1->net = 10000; |
| 34 | 34 | $balance_fee1->currency = 'USD'; |
| 35 | 35 | |
| 36 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) ); |
|
| 36 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee1, 'fee')); |
|
| 37 | 37 | |
| 38 | 38 | $balance_fee2 = new stdClass(); |
| 39 | 39 | $balance_fee2->fee = 10500; |
| 40 | 40 | $balance_fee2->net = 10000; |
| 41 | 41 | $balance_fee2->currency = 'JPY'; |
| 42 | 42 | |
| 43 | - $this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) ); |
|
| 43 | + $this->assertEquals(10500, WC_Stripe_Helper::format_balance_fee($balance_fee2, 'fee')); |
|
| 44 | 44 | |
| 45 | 45 | $balance_fee3 = new stdClass(); |
| 46 | 46 | $balance_fee3->fee = 10500; |
| 47 | 47 | $balance_fee3->net = 10000; |
| 48 | 48 | $balance_fee3->currency = 'USD'; |
| 49 | 49 | |
| 50 | - $this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) ); |
|
| 50 | + $this->assertEquals(100.00, WC_Stripe_Helper::format_balance_fee($balance_fee3, 'net')); |
|
| 51 | 51 | |
| 52 | 52 | $balance_fee4 = new stdClass(); |
| 53 | 53 | $balance_fee4->fee = 10500; |
| 54 | 54 | $balance_fee4->net = 10000; |
| 55 | 55 | $balance_fee4->currency = 'JPY'; |
| 56 | 56 | |
| 57 | - $this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) ); |
|
| 57 | + $this->assertEquals(10000, WC_Stripe_Helper::format_balance_fee($balance_fee4, 'net')); |
|
| 58 | 58 | |
| 59 | 59 | $balance_fee5 = new stdClass(); |
| 60 | 60 | $balance_fee5->fee = 10500; |
| 61 | 61 | $balance_fee5->net = 10000; |
| 62 | 62 | $balance_fee5->currency = 'USD'; |
| 63 | 63 | |
| 64 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
| 64 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
| 65 | 65 | |
| 66 | - $this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
| 66 | + $this->assertInternalType('string', WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -76,27 +76,27 @@ discard block |
||
| 76 | 76 | 'expected' => 'Tests Store', |
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | - $this->assertEquals( $statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor1['actual'] ) ); |
|
| 79 | + $this->assertEquals($statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor1['actual'])); |
|
| 80 | 80 | |
| 81 | 81 | $statement_descriptor2 = array( |
| 82 | 82 | 'actual' => 'Test\'s Store > Driving Course Range', |
| 83 | 83 | 'expected' => 'Tests Store Driving C', |
| 84 | 84 | ); |
| 85 | 85 | |
| 86 | - $this->assertEquals( $statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor2['actual'] ) ); |
|
| 86 | + $this->assertEquals($statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor2['actual'])); |
|
| 87 | 87 | |
| 88 | 88 | $statement_descriptor3 = array( |
| 89 | 89 | 'actual' => 'Test\'s Store < Driving Course Range', |
| 90 | 90 | 'expected' => 'Tests Store Driving C', |
| 91 | 91 | ); |
| 92 | 92 | |
| 93 | - $this->assertEquals( $statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor3['actual'] ) ); |
|
| 93 | + $this->assertEquals($statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor3['actual'])); |
|
| 94 | 94 | |
| 95 | 95 | $statement_descriptor4 = array( |
| 96 | 96 | 'actual' => 'Test\'s Store " Driving Course Range', |
| 97 | 97 | 'expected' => 'Tests Store Driving C', |
| 98 | 98 | ); |
| 99 | 99 | |
| 100 | - $this->assertEquals( $statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor4['actual'] ) ); |
|
| 100 | + $this->assertEquals($statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor4['actual'])); |
|
| 101 | 101 | } |
| 102 | 102 | } |
@@ -213,7 +213,6 @@ |
||
| 213 | 213 | /** |
| 214 | 214 | * Get a customers saved sources using their Stripe ID. |
| 215 | 215 | * |
| 216 | - * @param string $customer_id |
|
| 217 | 216 | * @return array |
| 218 | 217 | */ |
| 219 | 218 | public function get_sources() { |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | * Constructor |
| 33 | 33 | * @param int $user_id The WP user ID |
| 34 | 34 | */ |
| 35 | - public function __construct( $user_id = 0 ) { |
|
| 36 | - if ( $user_id ) { |
|
| 37 | - $this->set_user_id( $user_id ); |
|
| 38 | - $this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
| 35 | + public function __construct($user_id = 0) { |
|
| 36 | + if ($user_id) { |
|
| 37 | + $this->set_user_id($user_id); |
|
| 38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -51,15 +51,15 @@ discard block |
||
| 51 | 51 | * Set Stripe customer ID. |
| 52 | 52 | * @param [type] $id [description] |
| 53 | 53 | */ |
| 54 | - public function set_id( $id ) { |
|
| 54 | + public function set_id($id) { |
|
| 55 | 55 | // Backwards compat for customer ID stored in array format. (Pre 3.0) |
| 56 | - if ( is_array( $id ) && isset( $id['customer_id'] ) ) { |
|
| 56 | + if (is_array($id) && isset($id['customer_id'])) { |
|
| 57 | 57 | $id = $id['customer_id']; |
| 58 | 58 | |
| 59 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $id ); |
|
| 59 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $id); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $this->id = wc_clean( $id ); |
|
| 62 | + $this->id = wc_clean($id); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return int |
| 68 | 68 | */ |
| 69 | 69 | public function get_user_id() { |
| 70 | - return absint( $this->user_id ); |
|
| 70 | + return absint($this->user_id); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Set User ID used by WordPress. |
| 75 | 75 | * @param int $user_id |
| 76 | 76 | */ |
| 77 | - public function set_user_id( $user_id ) { |
|
| 78 | - $this->user_id = absint( $user_id ); |
|
| 77 | + public function set_user_id($user_id) { |
|
| 78 | + $this->user_id = absint($user_id); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | * @return WP_User |
| 84 | 84 | */ |
| 85 | 85 | protected function get_user() { |
| 86 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
| 86 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * Store data from the Stripe API about this customer |
| 91 | 91 | */ |
| 92 | - public function set_customer_data( $data ) { |
|
| 92 | + public function set_customer_data($data) { |
|
| 93 | 93 | $this->customer_data = $data; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -99,37 +99,37 @@ discard block |
||
| 99 | 99 | * @param array $args Additional arguments (optional). |
| 100 | 100 | * @return array |
| 101 | 101 | */ |
| 102 | - protected function generate_customer_request( $args = array() ) { |
|
| 103 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
| 102 | + protected function generate_customer_request($args = array()) { |
|
| 103 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
| 104 | 104 | $user = $this->get_user(); |
| 105 | 105 | |
| 106 | - if ( $user ) { |
|
| 107 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
| 108 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
| 106 | + if ($user) { |
|
| 107 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
| 108 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
| 109 | 109 | |
| 110 | 110 | // If billing first name does not exists try the user first name. |
| 111 | - if ( empty( $billing_first_name ) ) { |
|
| 112 | - $billing_first_name = get_user_meta( $user->ID, 'first_name', true ); |
|
| 111 | + if (empty($billing_first_name)) { |
|
| 112 | + $billing_first_name = get_user_meta($user->ID, 'first_name', true); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // If billing last name does not exists try the user last name. |
| 116 | - if ( empty( $billing_last_name ) ) { |
|
| 117 | - $billing_last_name = get_user_meta( $user->ID, 'last_name', true ); |
|
| 116 | + if (empty($billing_last_name)) { |
|
| 117 | + $billing_last_name = get_user_meta($user->ID, 'last_name', true); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // translators: %1$s First name, %2$s Second name, %3$s Username. |
| 121 | - $description = sprintf( __( 'Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name, $user->user_login ); |
|
| 121 | + $description = sprintf(__('Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name, $user->user_login); |
|
| 122 | 122 | |
| 123 | 123 | $defaults = array( |
| 124 | 124 | 'email' => $user->user_email, |
| 125 | 125 | 'description' => $description, |
| 126 | 126 | ); |
| 127 | 127 | } else { |
| 128 | - $billing_first_name = isset( $_POST['billing_first_name'] ) ? filter_var( wp_unslash( $_POST['billing_first_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 129 | - $billing_last_name = isset( $_POST['billing_last_name'] ) ? filter_var( wp_unslash( $_POST['billing_last_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 128 | + $billing_first_name = isset($_POST['billing_first_name']) ? filter_var(wp_unslash($_POST['billing_first_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 129 | + $billing_last_name = isset($_POST['billing_last_name']) ? filter_var(wp_unslash($_POST['billing_last_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 130 | 130 | |
| 131 | 131 | // translators: %1$s First name, %2$s Second name. |
| 132 | - $description = sprintf( __( 'Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name ); |
|
| 132 | + $description = sprintf(__('Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name); |
|
| 133 | 133 | |
| 134 | 134 | $defaults = array( |
| 135 | 135 | 'email' => $billing_email, |
@@ -138,9 +138,9 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $metadata = array(); |
| 141 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
| 141 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
| 142 | 142 | |
| 143 | - return wp_parse_args( $args, $defaults ); |
|
| 143 | + return wp_parse_args($args, $defaults); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -148,23 +148,23 @@ discard block |
||
| 148 | 148 | * @param array $args |
| 149 | 149 | * @return WP_Error|int |
| 150 | 150 | */ |
| 151 | - public function create_customer( $args = array() ) { |
|
| 152 | - $args = $this->generate_customer_request( $args ); |
|
| 153 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
| 151 | + public function create_customer($args = array()) { |
|
| 152 | + $args = $this->generate_customer_request($args); |
|
| 153 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
| 154 | 154 | |
| 155 | - if ( ! empty( $response->error ) ) { |
|
| 156 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 155 | + if ( ! empty($response->error)) { |
|
| 156 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $this->set_id( $response->id ); |
|
| 159 | + $this->set_id($response->id); |
|
| 160 | 160 | $this->clear_cache(); |
| 161 | - $this->set_customer_data( $response ); |
|
| 161 | + $this->set_customer_data($response); |
|
| 162 | 162 | |
| 163 | - if ( $this->get_user_id() ) { |
|
| 164 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
| 163 | + if ($this->get_user_id()) { |
|
| 164 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
| 167 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
| 168 | 168 | |
| 169 | 169 | return $response->id; |
| 170 | 170 | } |
@@ -174,23 +174,23 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @param array $args Additional arguments for the request (optional). |
| 176 | 176 | */ |
| 177 | - public function update_customer( $args = array() ) { |
|
| 178 | - if ( empty( $this->id ) ) { |
|
| 179 | - throw new WC_Stripe_Exception( 'id_required_to_update_user', __( 'Attempting to update a Stripe customer without a customer ID.', 'woocommerce-gateway-stripe' ) ); |
|
| 177 | + public function update_customer($args = array()) { |
|
| 178 | + if (empty($this->id)) { |
|
| 179 | + throw new WC_Stripe_Exception('id_required_to_update_user', __('Attempting to update a Stripe customer without a customer ID.', 'woocommerce-gateway-stripe')); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - $args = $this->generate_customer_request( $args ); |
|
| 183 | - $args = apply_filters( 'wc_stripe_update_customer_args', $args ); |
|
| 184 | - $response = WC_Stripe_API::request( $args, 'customers/' . $this->id ); |
|
| 182 | + $args = $this->generate_customer_request($args); |
|
| 183 | + $args = apply_filters('wc_stripe_update_customer_args', $args); |
|
| 184 | + $response = WC_Stripe_API::request($args, 'customers/' . $this->id); |
|
| 185 | 185 | |
| 186 | - if ( ! empty( $response->error ) ) { |
|
| 187 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 186 | + if ( ! empty($response->error)) { |
|
| 187 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | $this->clear_cache(); |
| 191 | - $this->set_customer_data( $response ); |
|
| 191 | + $this->set_customer_data($response); |
|
| 192 | 192 | |
| 193 | - do_action( 'woocommerce_stripe_update_customer', $args, $response ); |
|
| 193 | + do_action('woocommerce_stripe_update_customer', $args, $response); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | * @since 4.1.2 |
| 201 | 201 | * @param array $error |
| 202 | 202 | */ |
| 203 | - public function is_no_such_customer_error( $error ) { |
|
| 203 | + public function is_no_such_customer_error($error) { |
|
| 204 | 204 | return ( |
| 205 | 205 | $error && |
| 206 | 206 | 'invalid_request_error' === $error->type && |
| 207 | - preg_match( '/No such customer/i', $error->message ) |
|
| 207 | + preg_match('/No such customer/i', $error->message) |
|
| 208 | 208 | ); |
| 209 | 209 | } |
| 210 | 210 | |
@@ -213,9 +213,9 @@ discard block |
||
| 213 | 213 | * @param string $source_id |
| 214 | 214 | * @return WP_Error|int |
| 215 | 215 | */ |
| 216 | - public function add_source( $source_id ) { |
|
| 217 | - if ( ! $this->get_id() ) { |
|
| 218 | - $this->set_id( $this->create_customer() ); |
|
| 216 | + public function add_source($source_id) { |
|
| 217 | + if ( ! $this->get_id()) { |
|
| 218 | + $this->set_id($this->create_customer()); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | $response = WC_Stripe_API::request( |
@@ -227,63 +227,63 @@ discard block |
||
| 227 | 227 | |
| 228 | 228 | $wc_token = false; |
| 229 | 229 | |
| 230 | - if ( ! empty( $response->error ) ) { |
|
| 230 | + if ( ! empty($response->error)) { |
|
| 231 | 231 | // It is possible the WC user once was linked to a customer on Stripe |
| 232 | 232 | // but no longer exists. Instead of failing, lets try to create a |
| 233 | 233 | // new customer. |
| 234 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
| 235 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
| 234 | + if ($this->is_no_such_customer_error($response->error)) { |
|
| 235 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
| 236 | 236 | $this->create_customer(); |
| 237 | - return $this->add_source( $source_id ); |
|
| 237 | + return $this->add_source($source_id); |
|
| 238 | 238 | } else { |
| 239 | 239 | return $response; |
| 240 | 240 | } |
| 241 | - } elseif ( empty( $response->id ) ) { |
|
| 242 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
| 241 | + } elseif (empty($response->id)) { |
|
| 242 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // Add token to WooCommerce. |
| 246 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 247 | - if ( ! empty( $response->type ) ) { |
|
| 248 | - switch ( $response->type ) { |
|
| 246 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
| 247 | + if ( ! empty($response->type)) { |
|
| 248 | + switch ($response->type) { |
|
| 249 | 249 | case 'alipay': |
| 250 | 250 | break; |
| 251 | 251 | case 'sepa_debit': |
| 252 | 252 | $wc_token = new WC_Payment_Token_SEPA(); |
| 253 | - $wc_token->set_token( $response->id ); |
|
| 254 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
| 255 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
| 253 | + $wc_token->set_token($response->id); |
|
| 254 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
| 255 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
| 256 | 256 | break; |
| 257 | 257 | default: |
| 258 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
| 258 | + if ('source' === $response->object && 'card' === $response->type) { |
|
| 259 | 259 | $wc_token = new WC_Payment_Token_CC(); |
| 260 | - $wc_token->set_token( $response->id ); |
|
| 261 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 262 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
| 263 | - $wc_token->set_last4( $response->card->last4 ); |
|
| 264 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
| 265 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
| 260 | + $wc_token->set_token($response->id); |
|
| 261 | + $wc_token->set_gateway_id('stripe'); |
|
| 262 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
| 263 | + $wc_token->set_last4($response->card->last4); |
|
| 264 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
| 265 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
| 266 | 266 | } |
| 267 | 267 | break; |
| 268 | 268 | } |
| 269 | 269 | } else { |
| 270 | 270 | // Legacy. |
| 271 | 271 | $wc_token = new WC_Payment_Token_CC(); |
| 272 | - $wc_token->set_token( $response->id ); |
|
| 273 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 274 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
| 275 | - $wc_token->set_last4( $response->last4 ); |
|
| 276 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
| 277 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
| 272 | + $wc_token->set_token($response->id); |
|
| 273 | + $wc_token->set_gateway_id('stripe'); |
|
| 274 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
| 275 | + $wc_token->set_last4($response->last4); |
|
| 276 | + $wc_token->set_expiry_month($response->exp_month); |
|
| 277 | + $wc_token->set_expiry_year($response->exp_year); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
| 280 | + $wc_token->set_user_id($this->get_user_id()); |
|
| 281 | 281 | $wc_token->save(); |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | $this->clear_cache(); |
| 285 | 285 | |
| 286 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
| 286 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
| 287 | 287 | |
| 288 | 288 | return $response->id; |
| 289 | 289 | } |
@@ -295,11 +295,11 @@ discard block |
||
| 295 | 295 | * @return array |
| 296 | 296 | */ |
| 297 | 297 | public function get_sources() { |
| 298 | - if ( ! $this->get_id() ) { |
|
| 298 | + if ( ! $this->get_id()) { |
|
| 299 | 299 | return array(); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 302 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
| 303 | 303 | |
| 304 | 304 | $response = WC_Stripe_API::request( |
| 305 | 305 | array( |
@@ -309,32 +309,32 @@ discard block |
||
| 309 | 309 | 'GET' |
| 310 | 310 | ); |
| 311 | 311 | |
| 312 | - if ( ! empty( $response->error ) ) { |
|
| 312 | + if ( ! empty($response->error)) { |
|
| 313 | 313 | return array(); |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - if ( is_array( $response->data ) ) { |
|
| 316 | + if (is_array($response->data)) { |
|
| 317 | 317 | $sources = $response->data; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - return empty( $sources ) ? array() : $sources; |
|
| 320 | + return empty($sources) ? array() : $sources; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
| 324 | 324 | * Delete a source from stripe. |
| 325 | 325 | * @param string $source_id |
| 326 | 326 | */ |
| 327 | - public function delete_source( $source_id ) { |
|
| 328 | - if ( ! $this->get_id() ) { |
|
| 327 | + public function delete_source($source_id) { |
|
| 328 | + if ( ! $this->get_id()) { |
|
| 329 | 329 | return false; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
| 332 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
| 333 | 333 | |
| 334 | 334 | $this->clear_cache(); |
| 335 | 335 | |
| 336 | - if ( empty( $response->error ) ) { |
|
| 337 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
| 336 | + if (empty($response->error)) { |
|
| 337 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
| 338 | 338 | |
| 339 | 339 | return true; |
| 340 | 340 | } |
@@ -346,10 +346,10 @@ discard block |
||
| 346 | 346 | * Set default source in Stripe |
| 347 | 347 | * @param string $source_id |
| 348 | 348 | */ |
| 349 | - public function set_default_source( $source_id ) { |
|
| 349 | + public function set_default_source($source_id) { |
|
| 350 | 350 | $response = WC_Stripe_API::request( |
| 351 | 351 | array( |
| 352 | - 'default_source' => sanitize_text_field( $source_id ), |
|
| 352 | + 'default_source' => sanitize_text_field($source_id), |
|
| 353 | 353 | ), |
| 354 | 354 | 'customers/' . $this->get_id(), |
| 355 | 355 | 'POST' |
@@ -357,8 +357,8 @@ discard block |
||
| 357 | 357 | |
| 358 | 358 | $this->clear_cache(); |
| 359 | 359 | |
| 360 | - if ( empty( $response->error ) ) { |
|
| 361 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
| 360 | + if (empty($response->error)) { |
|
| 361 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
| 362 | 362 | |
| 363 | 363 | return true; |
| 364 | 364 | } |
@@ -370,8 +370,8 @@ discard block |
||
| 370 | 370 | * Deletes caches for this users cards. |
| 371 | 371 | */ |
| 372 | 372 | public function clear_cache() { |
| 373 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 374 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
| 373 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
| 374 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
| 375 | 375 | $this->customer_data = array(); |
| 376 | 376 | } |
| 377 | 377 | } |
@@ -104,7 +104,7 @@ |
||
| 104 | 104 | * Get this instance. |
| 105 | 105 | * |
| 106 | 106 | * @since 4.0.6 |
| 107 | - * @return class |
|
| 107 | + * @return WC_Stripe_Payment_Request |
|
| 108 | 108 | */ |
| 109 | 109 | public static function instance() { |
| 110 | 110 | return self::$_this; |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @since 4.0.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -64,41 +64,41 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function __construct() { |
| 66 | 66 | self::$_this = $this; |
| 67 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 68 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
| 69 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
| 70 | - $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
| 71 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
| 67 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
| 68 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
| 69 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
| 70 | + $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
| 71 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
| 72 | 72 | |
| 73 | - if ( $this->testmode ) { |
|
| 74 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
| 75 | - $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
| 73 | + if ($this->testmode) { |
|
| 74 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
| 75 | + $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
| 78 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
| 79 | 79 | |
| 80 | 80 | // Checks if Stripe Gateway is enabled. |
| 81 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
| 81 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
| 82 | 82 | return; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | // Checks if Payment Request is enabled. |
| 86 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
| 86 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
| 87 | 87 | return; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // Don't load for change payment method page. |
| 91 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
| 91 | + if (isset($_GET['change_payment_method'])) { |
|
| 92 | 92 | return; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - $wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 95 | + $wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 96 | 96 | |
| 97 | - if ( ! in_array( $wc_default_country, $this->get_stripe_supported_countries() ) ) { |
|
| 97 | + if ( ! in_array($wc_default_country, $this->get_stripe_supported_countries())) { |
|
| 98 | 98 | return; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - add_action( 'template_redirect', array( $this, 'set_session' ) ); |
|
| 101 | + add_action('template_redirect', array($this, 'set_session')); |
|
| 102 | 102 | $this->init(); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @return array The list of countries. |
| 110 | 110 | */ |
| 111 | 111 | public function get_stripe_supported_countries() { |
| 112 | - return apply_filters( 'wc_stripe_supported_countries', array( 'AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US' ) ); |
|
| 112 | + return apply_filters('wc_stripe_supported_countries', array('AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PR', 'PT', 'RO', 'SE', 'SG', 'SK', 'US')); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @return bool |
| 120 | 120 | */ |
| 121 | 121 | public function are_keys_set() { |
| 122 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
| 122 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
| 123 | 123 | return false; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -143,18 +143,18 @@ discard block |
||
| 143 | 143 | * @since 4.0.0 |
| 144 | 144 | */ |
| 145 | 145 | public function set_session() { |
| 146 | - if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) { |
|
| 146 | + if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) { |
|
| 147 | 147 | return; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' ); |
|
| 150 | + $session_class = apply_filters('woocommerce_session_handler', 'WC_Session_Handler'); |
|
| 151 | 151 | $wc_session = new $session_class(); |
| 152 | 152 | |
| 153 | - if ( version_compare( WC_VERSION, '3.3', '>=' ) ) { |
|
| 153 | + if (version_compare(WC_VERSION, '3.3', '>=')) { |
|
| 154 | 154 | $wc_session->init(); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - $wc_session->set_customer_session_cookie( true ); |
|
| 157 | + $wc_session->set_customer_session_cookie(true); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -164,40 +164,40 @@ discard block |
||
| 164 | 164 | * @version 4.0.0 |
| 165 | 165 | */ |
| 166 | 166 | public function init() { |
| 167 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
| 167 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
| 168 | 168 | |
| 169 | 169 | /* |
| 170 | 170 | * In order to display the Payment Request button in the correct position, |
| 171 | 171 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
| 172 | 172 | * CSS is used to position the button. |
| 173 | 173 | */ |
| 174 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 175 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 176 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 174 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 175 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
| 176 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 177 | 177 | } else { |
| 178 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 179 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 178 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
| 179 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 183 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 182 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
| 183 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 184 | 184 | |
| 185 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 186 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 185 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
| 186 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 187 | 187 | |
| 188 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
| 189 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
| 190 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
| 191 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
| 192 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
| 193 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
| 194 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
| 195 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
| 188 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
| 189 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
| 190 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
| 191 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
| 192 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
| 193 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
| 194 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
| 195 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
| 196 | 196 | |
| 197 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 198 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
| 197 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 198 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
| 199 | 199 | |
| 200 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
| 200 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @return string |
| 209 | 209 | */ |
| 210 | 210 | public function get_button_type() { |
| 211 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 211 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * @return string |
| 220 | 220 | */ |
| 221 | 221 | public function get_button_theme() { |
| 222 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 222 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | /** |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | * @return string |
| 231 | 231 | */ |
| 232 | 232 | public function get_button_height() { |
| 233 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
| 233 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -240,40 +240,40 @@ discard block |
||
| 240 | 240 | * @version 4.0.0 |
| 241 | 241 | */ |
| 242 | 242 | public function get_product_data() { |
| 243 | - if ( ! is_product() ) { |
|
| 243 | + if ( ! is_product()) { |
|
| 244 | 244 | return false; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | global $post; |
| 248 | 248 | |
| 249 | - $product = wc_get_product( $post->ID ); |
|
| 249 | + $product = wc_get_product($post->ID); |
|
| 250 | 250 | |
| 251 | 251 | $data = array(); |
| 252 | 252 | $items = array(); |
| 253 | 253 | |
| 254 | 254 | $items[] = array( |
| 255 | - 'label' => WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name(), |
|
| 256 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ), |
|
| 255 | + 'label' => WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name(), |
|
| 256 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()), |
|
| 257 | 257 | ); |
| 258 | 258 | |
| 259 | - if ( wc_tax_enabled() ) { |
|
| 259 | + if (wc_tax_enabled()) { |
|
| 260 | 260 | $items[] = array( |
| 261 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 261 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 262 | 262 | 'amount' => 0, |
| 263 | 263 | 'pending' => true, |
| 264 | 264 | ); |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 267 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 268 | 268 | $items[] = array( |
| 269 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 269 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 270 | 270 | 'amount' => 0, |
| 271 | 271 | 'pending' => true, |
| 272 | 272 | ); |
| 273 | 273 | |
| 274 | 274 | $data['shippingOptions'] = array( |
| 275 | 275 | 'id' => 'pending', |
| 276 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 276 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 277 | 277 | 'detail' => '', |
| 278 | 278 | 'amount' => 0, |
| 279 | 279 | ); |
@@ -281,41 +281,41 @@ discard block |
||
| 281 | 281 | |
| 282 | 282 | $data['displayItems'] = $items; |
| 283 | 283 | $data['total'] = array( |
| 284 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
| 285 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ), |
|
| 284 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
| 285 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()), |
|
| 286 | 286 | 'pending' => true, |
| 287 | 287 | ); |
| 288 | 288 | |
| 289 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 290 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 291 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 289 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 290 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 291 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 292 | 292 | |
| 293 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
| 293 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
| 297 | 297 | * Filters the gateway title to reflect Payment Request type |
| 298 | 298 | * |
| 299 | 299 | */ |
| 300 | - public function filter_gateway_title( $title, $id ) { |
|
| 300 | + public function filter_gateway_title($title, $id) { |
|
| 301 | 301 | global $post; |
| 302 | 302 | |
| 303 | - if ( ! is_object( $post ) ) { |
|
| 303 | + if ( ! is_object($post)) { |
|
| 304 | 304 | return $title; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 308 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 307 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 308 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 309 | 309 | } else { |
| 310 | - $order = wc_get_order( $post->ID ); |
|
| 311 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
| 310 | + $order = wc_get_order($post->ID); |
|
| 311 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
| 314 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
| 315 | 315 | return $method_title; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
| 318 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
| 319 | 319 | return $method_title; |
| 320 | 320 | } |
| 321 | 321 | |
@@ -328,16 +328,16 @@ discard block |
||
| 328 | 328 | * @since 3.1.4 |
| 329 | 329 | * @version 4.0.0 |
| 330 | 330 | */ |
| 331 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
| 331 | + public function postal_code_validation($valid, $postcode, $country) { |
|
| 332 | 332 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 333 | 333 | |
| 334 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 334 | + if ( ! isset($gateways['stripe'])) { |
|
| 335 | 335 | return $valid; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
| 338 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
| 339 | 339 | |
| 340 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
| 340 | + if ('apple_pay' !== $payment_request_type) { |
|
| 341 | 341 | return $valid; |
| 342 | 342 | } |
| 343 | 343 | |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | * the order and not let it go through. The remedy for now is just to remove this validation. |
| 348 | 348 | * Note that this only works with shipping providers that don't validate full postal codes. |
| 349 | 349 | */ |
| 350 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
| 350 | + if ('GB' === $country || 'CA' === $country) { |
|
| 351 | 351 | return true; |
| 352 | 352 | } |
| 353 | 353 | |
@@ -362,29 +362,29 @@ discard block |
||
| 362 | 362 | * @param int $order_id |
| 363 | 363 | * @param array $posted_data The posted data from checkout form. |
| 364 | 364 | */ |
| 365 | - public function add_order_meta( $order_id, $posted_data ) { |
|
| 366 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
| 365 | + public function add_order_meta($order_id, $posted_data) { |
|
| 366 | + if (empty($_POST['payment_request_type'])) { |
|
| 367 | 367 | return; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - $order = wc_get_order( $order_id ); |
|
| 370 | + $order = wc_get_order($order_id); |
|
| 371 | 371 | |
| 372 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
| 372 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
| 373 | 373 | |
| 374 | - if ( 'apple_pay' === $payment_request_type ) { |
|
| 375 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 376 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
| 374 | + if ('apple_pay' === $payment_request_type) { |
|
| 375 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 376 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
| 377 | 377 | } else { |
| 378 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
| 378 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
| 379 | 379 | $order->save(); |
| 380 | 380 | } |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
| 384 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 385 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
| 383 | + if ('payment_request_api' === $payment_request_type) { |
|
| 384 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 385 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
| 386 | 386 | } else { |
| 387 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
| 387 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
| 388 | 388 | $order->save(); |
| 389 | 389 | } |
| 390 | 390 | } |
@@ -423,20 +423,20 @@ discard block |
||
| 423 | 423 | * @return bool |
| 424 | 424 | */ |
| 425 | 425 | public function allowed_items_in_cart() { |
| 426 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 427 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
| 426 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 427 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
| 428 | 428 | |
| 429 | - if ( ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
| 429 | + if ( ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
| 430 | 430 | return false; |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | // Trial subscriptions with shipping are not supported |
| 434 | - if ( class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $_product ) > 0 ) { |
|
| 434 | + if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Cart::cart_contains_subscription() && $_product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($_product) > 0) { |
|
| 435 | 435 | return false; |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | // Pre Orders compatbility where we don't support charge upon release. |
| 439 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
| 439 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
| 440 | 440 | return false; |
| 441 | 441 | } |
| 442 | 442 | } |
@@ -452,83 +452,83 @@ discard block |
||
| 452 | 452 | */ |
| 453 | 453 | public function scripts() { |
| 454 | 454 | // If keys are not set bail. |
| 455 | - if ( ! $this->are_keys_set() ) { |
|
| 456 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
| 455 | + if ( ! $this->are_keys_set()) { |
|
| 456 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
| 457 | 457 | return; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | // If no SSL bail. |
| 461 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
| 462 | - WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' ); |
|
| 461 | + if ( ! $this->testmode && ! is_ssl()) { |
|
| 462 | + WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.'); |
|
| 463 | 463 | return; |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 466 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 467 | 467 | return; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | - if ( is_product() ) { |
|
| 470 | + if (is_product()) { |
|
| 471 | 471 | global $post; |
| 472 | 472 | |
| 473 | - $product = wc_get_product( $post->ID ); |
|
| 473 | + $product = wc_get_product($post->ID); |
|
| 474 | 474 | |
| 475 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 475 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 476 | 476 | return; |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
| 479 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
| 480 | 480 | return; |
| 481 | 481 | } |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 484 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 485 | 485 | |
| 486 | 486 | $stripe_params = array( |
| 487 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 487 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 488 | 488 | 'stripe' => array( |
| 489 | 489 | 'key' => $this->publishable_key, |
| 490 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
| 490 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
| 491 | 491 | ), |
| 492 | 492 | 'nonce' => array( |
| 493 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
| 494 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
| 495 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
| 496 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
| 497 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
| 498 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
| 499 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
| 500 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
| 493 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
| 494 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
| 495 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
| 496 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
| 497 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
| 498 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
| 499 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
| 500 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
| 501 | 501 | ), |
| 502 | 502 | 'i18n' => array( |
| 503 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
| 503 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
| 504 | 504 | /* translators: Do not translate the [option] placeholder */ |
| 505 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
| 505 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
| 506 | 506 | ), |
| 507 | 507 | 'checkout' => array( |
| 508 | 508 | 'url' => wc_get_checkout_url(), |
| 509 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
| 510 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 509 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
| 510 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 511 | 511 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 512 | 512 | ), |
| 513 | 513 | 'button' => array( |
| 514 | 514 | 'type' => $this->get_button_type(), |
| 515 | 515 | 'theme' => $this->get_button_theme(), |
| 516 | 516 | 'height' => $this->get_button_height(), |
| 517 | - 'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US. |
|
| 517 | + 'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US. |
|
| 518 | 518 | ), |
| 519 | 519 | 'is_product_page' => is_product(), |
| 520 | 520 | 'product' => $this->get_product_data(), |
| 521 | 521 | ); |
| 522 | 522 | |
| 523 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 524 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 523 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 524 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 525 | 525 | |
| 526 | - wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) ); |
|
| 526 | + wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params)); |
|
| 527 | 527 | |
| 528 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
| 528 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
| 529 | 529 | |
| 530 | 530 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 531 | - if ( isset( $gateways['stripe'] ) ) { |
|
| 531 | + if (isset($gateways['stripe'])) { |
|
| 532 | 532 | $gateways['stripe']->payment_scripts(); |
| 533 | 533 | } |
| 534 | 534 | } |
@@ -544,42 +544,42 @@ discard block |
||
| 544 | 544 | |
| 545 | 545 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 546 | 546 | |
| 547 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 547 | + if ( ! isset($gateways['stripe'])) { |
|
| 548 | 548 | return; |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 551 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 552 | 552 | return; |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
| 555 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
| 556 | 556 | return; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
| 559 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
| 560 | 560 | return; |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | - if ( is_product() ) { |
|
| 564 | - $product = wc_get_product( $post->ID ); |
|
| 563 | + if (is_product()) { |
|
| 564 | + $product = wc_get_product($post->ID); |
|
| 565 | 565 | |
| 566 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 566 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 567 | 567 | return; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | // Trial subscriptions with shipping are not supported |
| 571 | - if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) { |
|
| 571 | + if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) { |
|
| 572 | 572 | return; |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | // Pre Orders charge upon release not supported. |
| 576 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 577 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 576 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 577 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 578 | 578 | return; |
| 579 | 579 | } |
| 580 | 580 | } else { |
| 581 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 582 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 581 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 582 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 583 | 583 | return; |
| 584 | 584 | } |
| 585 | 585 | } |
@@ -603,47 +603,47 @@ discard block |
||
| 603 | 603 | |
| 604 | 604 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 605 | 605 | |
| 606 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 606 | + if ( ! isset($gateways['stripe'])) { |
|
| 607 | 607 | return; |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 610 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 611 | 611 | return; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
| 614 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
| 615 | 615 | return; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
| 618 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
| 619 | 619 | return; |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | - if ( is_product() ) { |
|
| 623 | - $product = wc_get_product( $post->ID ); |
|
| 622 | + if (is_product()) { |
|
| 623 | + $product = wc_get_product($post->ID); |
|
| 624 | 624 | |
| 625 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 625 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 626 | 626 | return; |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | // Trial subscriptions with shipping are not supported |
| 630 | - if ( class_exists( 'WC_Subscriptions_Order' ) && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length( $product ) > 0 ) { |
|
| 630 | + if (class_exists('WC_Subscriptions_Order') && $product->needs_shipping() && WC_Subscriptions_Product::get_trial_length($product) > 0) { |
|
| 631 | 631 | return; |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | // Pre Orders charge upon release not supported. |
| 635 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 636 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 635 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 636 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 637 | 637 | return; |
| 638 | 638 | } |
| 639 | 639 | } else { |
| 640 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 641 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 640 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 641 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 642 | 642 | return; |
| 643 | 643 | } |
| 644 | 644 | } |
| 645 | 645 | ?> |
| 646 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> —</p> |
|
| 646 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> —</p> |
|
| 647 | 647 | <?php |
| 648 | 648 | } |
| 649 | 649 | |
@@ -654,11 +654,11 @@ discard block |
||
| 654 | 654 | * @version 4.0.0 |
| 655 | 655 | */ |
| 656 | 656 | public function ajax_log_errors() { |
| 657 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
| 657 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
| 658 | 658 | |
| 659 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
| 659 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
| 660 | 660 | |
| 661 | - WC_Stripe_Logger::log( $errors ); |
|
| 661 | + WC_Stripe_Logger::log($errors); |
|
| 662 | 662 | |
| 663 | 663 | exit; |
| 664 | 664 | } |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | * @version 4.0.0 |
| 671 | 671 | */ |
| 672 | 672 | public function ajax_clear_cart() { |
| 673 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
| 673 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
| 674 | 674 | |
| 675 | 675 | WC()->cart->empty_cart(); |
| 676 | 676 | exit; |
@@ -680,10 +680,10 @@ discard block |
||
| 680 | 680 | * Get cart details. |
| 681 | 681 | */ |
| 682 | 682 | public function ajax_get_cart_details() { |
| 683 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
| 683 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
| 684 | 684 | |
| 685 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 686 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 685 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 686 | + define('WOOCOMMERCE_CART', true); |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | WC()->cart->calculate_totals(); |
@@ -694,14 +694,14 @@ discard block |
||
| 694 | 694 | $data = array( |
| 695 | 695 | 'shipping_required' => WC()->cart->needs_shipping(), |
| 696 | 696 | 'order_data' => array( |
| 697 | - 'currency' => strtolower( $currency ), |
|
| 698 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 697 | + 'currency' => strtolower($currency), |
|
| 698 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 699 | 699 | ), |
| 700 | 700 | ); |
| 701 | 701 | |
| 702 | 702 | $data['order_data'] += $this->build_display_items(); |
| 703 | 703 | |
| 704 | - wp_send_json( $data ); |
|
| 704 | + wp_send_json($data); |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | /** |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | * @see WC_Shipping::get_packages(). |
| 713 | 713 | */ |
| 714 | 714 | public function ajax_get_shipping_options() { |
| 715 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
| 715 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
| 716 | 716 | |
| 717 | 717 | try { |
| 718 | 718 | // Set the shipping package. |
@@ -728,34 +728,34 @@ discard block |
||
| 728 | 728 | ) |
| 729 | 729 | ); |
| 730 | 730 | |
| 731 | - $this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $posted ) ); |
|
| 731 | + $this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $posted)); |
|
| 732 | 732 | |
| 733 | 733 | // Set the shipping options. |
| 734 | 734 | $data = array(); |
| 735 | 735 | $packages = WC()->shipping->get_packages(); |
| 736 | 736 | |
| 737 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 738 | - foreach ( $packages as $package_key => $package ) { |
|
| 739 | - if ( empty( $package['rates'] ) ) { |
|
| 740 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 737 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 738 | + foreach ($packages as $package_key => $package) { |
|
| 739 | + if (empty($package['rates'])) { |
|
| 740 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 743 | + foreach ($package['rates'] as $key => $rate) { |
|
| 744 | 744 | $data['shipping_options'][] = array( |
| 745 | 745 | 'id' => $rate->id, |
| 746 | 746 | 'label' => $rate->label, |
| 747 | 747 | 'detail' => '', |
| 748 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
| 748 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
| 749 | 749 | ); |
| 750 | 750 | } |
| 751 | 751 | } |
| 752 | 752 | } else { |
| 753 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 753 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 754 | 754 | } |
| 755 | 755 | |
| 756 | - if ( isset( $data[0] ) ) { |
|
| 756 | + if (isset($data[0])) { |
|
| 757 | 757 | // Auto select the first shipping method. |
| 758 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 758 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | WC()->cart->calculate_totals(); |
@@ -763,12 +763,12 @@ discard block |
||
| 763 | 763 | $data += $this->build_display_items(); |
| 764 | 764 | $data['result'] = 'success'; |
| 765 | 765 | |
| 766 | - wp_send_json( $data ); |
|
| 767 | - } catch ( Exception $e ) { |
|
| 766 | + wp_send_json($data); |
|
| 767 | + } catch (Exception $e) { |
|
| 768 | 768 | $data += $this->build_display_items(); |
| 769 | 769 | $data['result'] = 'invalid_shipping_address'; |
| 770 | 770 | |
| 771 | - wp_send_json( $data ); |
|
| 771 | + wp_send_json($data); |
|
| 772 | 772 | } |
| 773 | 773 | } |
| 774 | 774 | |
@@ -776,22 +776,22 @@ discard block |
||
| 776 | 776 | * Update shipping method. |
| 777 | 777 | */ |
| 778 | 778 | public function ajax_update_shipping_method() { |
| 779 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
| 779 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
| 780 | 780 | |
| 781 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 782 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 781 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 782 | + define('WOOCOMMERCE_CART', true); |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
| 786 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 785 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
| 786 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 787 | 787 | |
| 788 | - if ( is_array( $shipping_method ) ) { |
|
| 789 | - foreach ( $shipping_method as $i => $value ) { |
|
| 790 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
| 788 | + if (is_array($shipping_method)) { |
|
| 789 | + foreach ($shipping_method as $i => $value) { |
|
| 790 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
| 791 | 791 | } |
| 792 | 792 | } |
| 793 | 793 | |
| 794 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
| 794 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
| 795 | 795 | |
| 796 | 796 | WC()->cart->calculate_totals(); |
| 797 | 797 | |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | $data += $this->build_display_items(); |
| 800 | 800 | $data['result'] = 'success'; |
| 801 | 801 | |
| 802 | - wp_send_json( $data ); |
|
| 802 | + wp_send_json($data); |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | /** |
@@ -810,46 +810,46 @@ discard block |
||
| 810 | 810 | * @return array $data |
| 811 | 811 | */ |
| 812 | 812 | public function ajax_get_selected_product_data() { |
| 813 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
| 813 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
| 814 | 814 | |
| 815 | 815 | try { |
| 816 | - $product_id = absint( $_POST['product_id'] ); |
|
| 817 | - $qty = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id ); |
|
| 818 | - $product = wc_get_product( $product_id ); |
|
| 816 | + $product_id = absint($_POST['product_id']); |
|
| 817 | + $qty = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id); |
|
| 818 | + $product = wc_get_product($product_id); |
|
| 819 | 819 | $variation_id = null; |
| 820 | 820 | |
| 821 | - if ( ! is_a( $product, 'WC_Product' ) ) { |
|
| 822 | - throw new Exception( sprintf( __( 'Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe' ), $product_id ) ); |
|
| 821 | + if ( ! is_a($product, 'WC_Product')) { |
|
| 822 | + throw new Exception(sprintf(__('Product with the ID (%d) cannot be found.', 'woocommerce-gateway-stripe'), $product_id)); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | - if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 826 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 825 | + if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 826 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 827 | 827 | |
| 828 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 829 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 828 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 829 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 830 | 830 | } else { |
| 831 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 832 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 831 | + $data_store = WC_Data_Store::load('product'); |
|
| 832 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | - if ( ! empty( $variation_id ) ) { |
|
| 836 | - $product = wc_get_product( $variation_id ); |
|
| 835 | + if ( ! empty($variation_id)) { |
|
| 836 | + $product = wc_get_product($variation_id); |
|
| 837 | 837 | } |
| 838 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) { |
|
| 839 | - $product = wc_get_product( $product_id ); |
|
| 838 | + } elseif ('simple' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) { |
|
| 839 | + $product = wc_get_product($product_id); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | // Force quantity to 1 if sold individually and check for existing item in cart. |
| 843 | - if ( $product->is_sold_individually() ) { |
|
| 844 | - $qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id ); |
|
| 843 | + if ($product->is_sold_individually()) { |
|
| 844 | + $qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id); |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | - if ( ! $product->has_enough_stock( $qty ) ) { |
|
| 847 | + if ( ! $product->has_enough_stock($qty)) { |
|
| 848 | 848 | /* translators: 1: product name 2: quantity in stock */ |
| 849 | - throw new Exception( sprintf( __( 'You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity(), $product ) ) ); |
|
| 849 | + throw new Exception(sprintf(__('You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe'), $product->get_name(), wc_format_stock_quantity_for_display($product->get_stock_quantity(), $product))); |
|
| 850 | 850 | } |
| 851 | 851 | |
| 852 | - $total = $qty * ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ); |
|
| 852 | + $total = $qty * (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()); |
|
| 853 | 853 | |
| 854 | 854 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
| 855 | 855 | |
@@ -857,28 +857,28 @@ discard block |
||
| 857 | 857 | $items = array(); |
| 858 | 858 | |
| 859 | 859 | $items[] = array( |
| 860 | - 'label' => ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name() ) . $quantity_label, |
|
| 861 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 860 | + 'label' => (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name()) . $quantity_label, |
|
| 861 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 862 | 862 | ); |
| 863 | 863 | |
| 864 | - if ( wc_tax_enabled() ) { |
|
| 864 | + if (wc_tax_enabled()) { |
|
| 865 | 865 | $items[] = array( |
| 866 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 866 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 867 | 867 | 'amount' => 0, |
| 868 | 868 | 'pending' => true, |
| 869 | 869 | ); |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 872 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 873 | 873 | $items[] = array( |
| 874 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 874 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 875 | 875 | 'amount' => 0, |
| 876 | 876 | 'pending' => true, |
| 877 | 877 | ); |
| 878 | 878 | |
| 879 | 879 | $data['shippingOptions'] = array( |
| 880 | 880 | 'id' => 'pending', |
| 881 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 881 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 882 | 882 | 'detail' => '', |
| 883 | 883 | 'amount' => 0, |
| 884 | 884 | ); |
@@ -887,17 +887,17 @@ discard block |
||
| 887 | 887 | $data['displayItems'] = $items; |
| 888 | 888 | $data['total'] = array( |
| 889 | 889 | 'label' => $this->total_label, |
| 890 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 890 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 891 | 891 | 'pending' => true, |
| 892 | 892 | ); |
| 893 | 893 | |
| 894 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 895 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 896 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 894 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 895 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 896 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 897 | 897 | |
| 898 | - wp_send_json( $data ); |
|
| 899 | - } catch ( Exception $e ) { |
|
| 900 | - wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) ); |
|
| 898 | + wp_send_json($data); |
|
| 899 | + } catch (Exception $e) { |
|
| 900 | + wp_send_json(array('error' => wp_strip_all_tags($e->getMessage()))); |
|
| 901 | 901 | } |
| 902 | 902 | } |
| 903 | 903 | |
@@ -909,37 +909,37 @@ discard block |
||
| 909 | 909 | * @return array $data |
| 910 | 910 | */ |
| 911 | 911 | public function ajax_add_to_cart() { |
| 912 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
| 912 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
| 913 | 913 | |
| 914 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 915 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 914 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 915 | + define('WOOCOMMERCE_CART', true); |
|
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | WC()->shipping->reset_shipping(); |
| 919 | 919 | |
| 920 | - $product_id = absint( $_POST['product_id'] ); |
|
| 921 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 922 | - $product = wc_get_product( $product_id ); |
|
| 923 | - $product_type = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type(); |
|
| 920 | + $product_id = absint($_POST['product_id']); |
|
| 921 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 922 | + $product = wc_get_product($product_id); |
|
| 923 | + $product_type = WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type(); |
|
| 924 | 924 | |
| 925 | 925 | // First empty the cart to prevent wrong calculation. |
| 926 | 926 | WC()->cart->empty_cart(); |
| 927 | 927 | |
| 928 | - if ( ( 'variable' === $product_type || 'variable-subscription' === $product_type ) && isset( $_POST['attributes'] ) ) { |
|
| 929 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 928 | + if (('variable' === $product_type || 'variable-subscription' === $product_type) && isset($_POST['attributes'])) { |
|
| 929 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 930 | 930 | |
| 931 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 932 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 931 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 932 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 933 | 933 | } else { |
| 934 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 935 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 934 | + $data_store = WC_Data_Store::load('product'); |
|
| 935 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
| 938 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | - if ( 'simple' === $product_type || 'subscription' === $product_type ) { |
|
| 942 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
| 941 | + if ('simple' === $product_type || 'subscription' === $product_type) { |
|
| 942 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
| 943 | 943 | } |
| 944 | 944 | |
| 945 | 945 | WC()->cart->calculate_totals(); |
@@ -948,7 +948,7 @@ discard block |
||
| 948 | 948 | $data += $this->build_display_items(); |
| 949 | 949 | $data['result'] = 'success'; |
| 950 | 950 | |
| 951 | - wp_send_json( $data ); |
|
| 951 | + wp_send_json($data); |
|
| 952 | 952 | } |
| 953 | 953 | |
| 954 | 954 | /** |
@@ -961,31 +961,31 @@ discard block |
||
| 961 | 961 | * @version 4.0.0 |
| 962 | 962 | */ |
| 963 | 963 | public function normalize_state() { |
| 964 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
| 965 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
| 966 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
| 967 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
| 964 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
| 965 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
| 966 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
| 967 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
| 968 | 968 | |
| 969 | - if ( $billing_state && $billing_country ) { |
|
| 970 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
| 969 | + if ($billing_state && $billing_country) { |
|
| 970 | + $valid_states = WC()->countries->get_states($billing_country); |
|
| 971 | 971 | |
| 972 | 972 | // Valid states found for country. |
| 973 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 974 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 975 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
| 973 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 974 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 975 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
| 976 | 976 | $_POST['billing_state'] = $state_abbr; |
| 977 | 977 | } |
| 978 | 978 | } |
| 979 | 979 | } |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | - if ( $shipping_state && $shipping_country ) { |
|
| 983 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
| 982 | + if ($shipping_state && $shipping_country) { |
|
| 983 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
| 984 | 984 | |
| 985 | 985 | // Valid states found for country. |
| 986 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 987 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 988 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
| 986 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 987 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 988 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
| 989 | 989 | $_POST['shipping_state'] = $state_abbr; |
| 990 | 990 | } |
| 991 | 991 | } |
@@ -1000,19 +1000,19 @@ discard block |
||
| 1000 | 1000 | * @version 4.0.0 |
| 1001 | 1001 | */ |
| 1002 | 1002 | public function ajax_create_order() { |
| 1003 | - if ( WC()->cart->is_empty() ) { |
|
| 1004 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
| 1003 | + if (WC()->cart->is_empty()) { |
|
| 1004 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
| 1008 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
| 1007 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
| 1008 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | $this->normalize_state(); |
| 1012 | 1012 | |
| 1013 | 1013 | WC()->checkout()->process_checkout(); |
| 1014 | 1014 | |
| 1015 | - die( 0 ); |
|
| 1015 | + die(0); |
|
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | 1018 | /** |
@@ -1022,41 +1022,41 @@ discard block |
||
| 1022 | 1022 | * @version 4.0.0 |
| 1023 | 1023 | * @param array $address |
| 1024 | 1024 | */ |
| 1025 | - protected function calculate_shipping( $address = array() ) { |
|
| 1025 | + protected function calculate_shipping($address = array()) { |
|
| 1026 | 1026 | $country = $address['country']; |
| 1027 | 1027 | $state = $address['state']; |
| 1028 | 1028 | $postcode = $address['postcode']; |
| 1029 | 1029 | $city = $address['city']; |
| 1030 | 1030 | $address_1 = $address['address']; |
| 1031 | 1031 | $address_2 = $address['address_2']; |
| 1032 | - $wc_states = WC()->countries->get_states( $country ); |
|
| 1032 | + $wc_states = WC()->countries->get_states($country); |
|
| 1033 | 1033 | |
| 1034 | 1034 | /** |
| 1035 | 1035 | * In some versions of Chrome, state can be a full name. So we need |
| 1036 | 1036 | * to convert that to abbreviation as WC is expecting that. |
| 1037 | 1037 | */ |
| 1038 | - if ( 2 < strlen( $state ) && ! empty( $wc_states ) ) { |
|
| 1039 | - $state = array_search( ucwords( strtolower( $state ) ), $wc_states, true ); |
|
| 1038 | + if (2 < strlen($state) && ! empty($wc_states)) { |
|
| 1039 | + $state = array_search(ucwords(strtolower($state)), $wc_states, true); |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | WC()->shipping->reset_shipping(); |
| 1043 | 1043 | |
| 1044 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 1045 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 1044 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
| 1045 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | - if ( $country ) { |
|
| 1049 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 1050 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 1048 | + if ($country) { |
|
| 1049 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 1050 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 1051 | 1051 | } else { |
| 1052 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
|
| 1053 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
|
| 1052 | + WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
|
| 1053 | + WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
|
| 1054 | 1054 | } |
| 1055 | 1055 | |
| 1056 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 1057 | - WC()->customer->calculated_shipping( true ); |
|
| 1056 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 1057 | + WC()->customer->calculated_shipping(true); |
|
| 1058 | 1058 | } else { |
| 1059 | - WC()->customer->set_calculated_shipping( true ); |
|
| 1059 | + WC()->customer->set_calculated_shipping(true); |
|
| 1060 | 1060 | WC()->customer->save(); |
| 1061 | 1061 | } |
| 1062 | 1062 | |
@@ -1073,17 +1073,17 @@ discard block |
||
| 1073 | 1073 | $packages[0]['destination']['address'] = $address_1; |
| 1074 | 1074 | $packages[0]['destination']['address_2'] = $address_2; |
| 1075 | 1075 | |
| 1076 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 1077 | - if ( $item['data']->needs_shipping() ) { |
|
| 1078 | - if ( isset( $item['line_total'] ) ) { |
|
| 1076 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 1077 | + if ($item['data']->needs_shipping()) { |
|
| 1078 | + if (isset($item['line_total'])) { |
|
| 1079 | 1079 | $packages[0]['contents_cost'] += $item['line_total']; |
| 1080 | 1080 | } |
| 1081 | 1081 | } |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 1084 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 1085 | 1085 | |
| 1086 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 1086 | + WC()->shipping->calculate_shipping($packages); |
|
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | /** |
@@ -1092,19 +1092,19 @@ discard block |
||
| 1092 | 1092 | * @since 3.1.0 |
| 1093 | 1093 | * @version 4.0.0 |
| 1094 | 1094 | */ |
| 1095 | - protected function build_shipping_methods( $shipping_methods ) { |
|
| 1096 | - if ( empty( $shipping_methods ) ) { |
|
| 1095 | + protected function build_shipping_methods($shipping_methods) { |
|
| 1096 | + if (empty($shipping_methods)) { |
|
| 1097 | 1097 | return array(); |
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | $shipping = array(); |
| 1101 | 1101 | |
| 1102 | - foreach ( $shipping_methods as $method ) { |
|
| 1102 | + foreach ($shipping_methods as $method) { |
|
| 1103 | 1103 | $shipping[] = array( |
| 1104 | 1104 | 'id' => $method['id'], |
| 1105 | 1105 | 'label' => $method['label'], |
| 1106 | 1106 | 'detail' => '', |
| 1107 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
| 1107 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
| 1108 | 1108 | ); |
| 1109 | 1109 | } |
| 1110 | 1110 | |
@@ -1118,8 +1118,8 @@ discard block |
||
| 1118 | 1118 | * @version 4.0.0 |
| 1119 | 1119 | */ |
| 1120 | 1120 | protected function build_display_items() { |
| 1121 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 1122 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 1121 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 1122 | + define('WOOCOMMERCE_CART', true); |
|
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | $items = array(); |
@@ -1127,71 +1127,71 @@ discard block |
||
| 1127 | 1127 | $discounts = 0; |
| 1128 | 1128 | |
| 1129 | 1129 | // Default show only subtotal instead of itemization. |
| 1130 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
| 1131 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 1130 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
| 1131 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 1132 | 1132 | $amount = $cart_item['line_subtotal']; |
| 1133 | 1133 | $subtotal += $cart_item['line_subtotal']; |
| 1134 | 1134 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
| 1135 | 1135 | |
| 1136 | - $product_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
| 1136 | + $product_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
| 1137 | 1137 | |
| 1138 | 1138 | $item = array( |
| 1139 | 1139 | 'label' => $product_name . $quantity_label, |
| 1140 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
| 1140 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
| 1141 | 1141 | ); |
| 1142 | 1142 | |
| 1143 | 1143 | $items[] = $item; |
| 1144 | 1144 | } |
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
| 1148 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
| 1147 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
| 1148 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
| 1149 | 1149 | } else { |
| 1150 | - $applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() ); |
|
| 1150 | + $applied_coupons = array_values(WC()->cart->get_coupon_discount_totals()); |
|
| 1151 | 1151 | |
| 1152 | - foreach ( $applied_coupons as $amount ) { |
|
| 1152 | + foreach ($applied_coupons as $amount) { |
|
| 1153 | 1153 | $discounts += (float) $amount; |
| 1154 | 1154 | } |
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | - $discounts = wc_format_decimal( $discounts, WC()->cart->dp ); |
|
| 1158 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
| 1159 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
| 1160 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
| 1161 | - $order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false ); |
|
| 1157 | + $discounts = wc_format_decimal($discounts, WC()->cart->dp); |
|
| 1158 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
| 1159 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
| 1160 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
| 1161 | + $order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false); |
|
| 1162 | 1162 | |
| 1163 | - if ( wc_tax_enabled() ) { |
|
| 1163 | + if (wc_tax_enabled()) { |
|
| 1164 | 1164 | $items[] = array( |
| 1165 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
| 1166 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
| 1165 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
| 1166 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
| 1167 | 1167 | ); |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | - if ( WC()->cart->needs_shipping() ) { |
|
| 1170 | + if (WC()->cart->needs_shipping()) { |
|
| 1171 | 1171 | $items[] = array( |
| 1172 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
| 1173 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
| 1172 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
| 1173 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
| 1174 | 1174 | ); |
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | - if ( WC()->cart->has_discount() ) { |
|
| 1177 | + if (WC()->cart->has_discount()) { |
|
| 1178 | 1178 | $items[] = array( |
| 1179 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
| 1180 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
| 1179 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
| 1180 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
| 1181 | 1181 | ); |
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
| 1184 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
| 1185 | 1185 | $cart_fees = WC()->cart->fees; |
| 1186 | 1186 | } else { |
| 1187 | 1187 | $cart_fees = WC()->cart->get_fees(); |
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | // Include fees and taxes as display items. |
| 1191 | - foreach ( $cart_fees as $key => $fee ) { |
|
| 1191 | + foreach ($cart_fees as $key => $fee) { |
|
| 1192 | 1192 | $items[] = array( |
| 1193 | 1193 | 'label' => $fee->name, |
| 1194 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
| 1194 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
| 1195 | 1195 | ); |
| 1196 | 1196 | } |
| 1197 | 1197 | |
@@ -1199,7 +1199,7 @@ discard block |
||
| 1199 | 1199 | 'displayItems' => $items, |
| 1200 | 1200 | 'total' => array( |
| 1201 | 1201 | 'label' => $this->total_label, |
| 1202 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
| 1202 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
| 1203 | 1203 | 'pending' => false, |
| 1204 | 1204 | ), |
| 1205 | 1205 | ); |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @param float $amount |
| 139 | 139 | * @param mixed $renewal_order |
| 140 | 140 | * @param bool $retry Should we retry the process? |
| 141 | - * @param object $previous_error |
|
| 141 | + * @param boolean $previous_error |
|
| 142 | 142 | */ |
| 143 | 143 | public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
| 144 | 144 | try { |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | /** |
| 243 | 243 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 244 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
| 244 | + * @param integer $renewal_order |
|
| 245 | 245 | */ |
| 246 | 246 | public function delete_renewal_meta( $renewal_order ) { |
| 247 | 247 | WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
@@ -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,21 +15,21 @@ discard block |
||
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | |
| 18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 23 | - add_action( 'wc_stripe_sepa_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) ); |
|
| 24 | - add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 ); |
|
| 18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 23 | + add_action('wc_stripe_sepa_payment_fields', array($this, 'display_update_subs_payment_checkout')); |
|
| 24 | + add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2); |
|
| 25 | 25 | |
| 26 | 26 | // Display the credit card used for a subscription in the "My Subscriptions" table. |
| 27 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 27 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 28 | 28 | |
| 29 | 29 | // Allow store managers to manually set Stripe as the payment method on a subscription. |
| 30 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 31 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 32 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
| 30 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 31 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 32 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | * @since 4.0.0 |
| 41 | 41 | * @version 4.0.0 |
| 42 | 42 | */ |
| 43 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
| 44 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
| 43 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
| 44 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
| 45 | 45 | return false; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | * @param int $order_id |
| 54 | 54 | * @return boolean |
| 55 | 55 | */ |
| 56 | - public function has_subscription( $order_id ) { |
|
| 57 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 56 | + public function has_subscription($order_id) { |
|
| 57 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @return bool |
| 65 | 65 | */ |
| 66 | 66 | public function is_subs_change_payment() { |
| 67 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
| 67 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -74,20 +74,20 @@ discard block |
||
| 74 | 74 | * @since 4.1.11 |
| 75 | 75 | */ |
| 76 | 76 | public function display_update_subs_payment_checkout() { |
| 77 | - $subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) ); |
|
| 77 | + $subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active')); |
|
| 78 | 78 | if ( |
| 79 | - apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) && |
|
| 80 | - wcs_user_has_subscription( get_current_user_id(), '', $subs_statuses ) && |
|
| 79 | + apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) && |
|
| 80 | + wcs_user_has_subscription(get_current_user_id(), '', $subs_statuses) && |
|
| 81 | 81 | is_add_payment_method_page() |
| 82 | 82 | ) { |
| 83 | - $label = esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe' ) ) ); |
|
| 84 | - $id = sprintf( 'wc-%1$s-update-subs-payment-method-card', $this->id ); |
|
| 83 | + $label = esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe'))); |
|
| 84 | + $id = sprintf('wc-%1$s-update-subs-payment-method-card', $this->id); |
|
| 85 | 85 | woocommerce_form_field( |
| 86 | 86 | $id, |
| 87 | 87 | array( |
| 88 | 88 | 'type' => 'checkbox', |
| 89 | 89 | 'label' => $label, |
| 90 | - 'default' => apply_filters( 'wc_stripe_save_to_subs_checked', false ), |
|
| 90 | + 'default' => apply_filters('wc_stripe_save_to_subs_checked', false), |
|
| 91 | 91 | ) |
| 92 | 92 | ); |
| 93 | 93 | } |
@@ -100,17 +100,17 @@ discard block |
||
| 100 | 100 | * @param string $source_id |
| 101 | 101 | * @param object $source_object |
| 102 | 102 | */ |
| 103 | - public function handle_add_payment_method_success( $source_id, $source_object ) { |
|
| 104 | - if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) { |
|
| 103 | + public function handle_add_payment_method_success($source_id, $source_object) { |
|
| 104 | + if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) { |
|
| 105 | 105 | $all_subs = wcs_get_users_subscriptions(); |
| 106 | - $subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) ); |
|
| 107 | - |
|
| 108 | - if ( ! empty( $all_subs ) ) { |
|
| 109 | - foreach ( $all_subs as $sub ) { |
|
| 110 | - if ( $sub->has_status( $subs_statuses ) ) { |
|
| 111 | - update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id ); |
|
| 112 | - update_post_meta( $sub->get_id(), '_payment_method', $this->id ); |
|
| 113 | - update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title ); |
|
| 106 | + $subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active')); |
|
| 107 | + |
|
| 108 | + if ( ! empty($all_subs)) { |
|
| 109 | + foreach ($all_subs as $sub) { |
|
| 110 | + if ($sub->has_status($subs_statuses)) { |
|
| 111 | + update_post_meta($sub->get_id(), '_stripe_source_id', $source_id); |
|
| 112 | + update_post_meta($sub->get_id(), '_payment_method', $this->id); |
|
| 113 | + update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -123,24 +123,24 @@ discard block |
||
| 123 | 123 | * @since 3.1.0 |
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | - public function save_source_to_order( $order, $source ) { |
|
| 127 | - parent::save_source_to_order( $order, $source ); |
|
| 126 | + public function save_source_to_order($order, $source) { |
|
| 127 | + parent::save_source_to_order($order, $source); |
|
| 128 | 128 | |
| 129 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 129 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 130 | 130 | |
| 131 | 131 | // Also store it on the subscriptions being purchased or paid for in the order. |
| 132 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 133 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 134 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 135 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 132 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 133 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 134 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 135 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 136 | 136 | } else { |
| 137 | 137 | $subscriptions = array(); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - foreach ( $subscriptions as $subscription ) { |
|
| 141 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
| 142 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 143 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 140 | + foreach ($subscriptions as $subscription) { |
|
| 141 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
| 142 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 143 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
@@ -149,16 +149,16 @@ discard block |
||
| 149 | 149 | * @param int $order_id |
| 150 | 150 | * @return array |
| 151 | 151 | */ |
| 152 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
| 153 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 154 | - if ( $this->is_subs_change_payment() ) { |
|
| 155 | - return $this->change_subs_payment_method( $order_id ); |
|
| 152 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
| 153 | + if ($this->has_subscription($order_id)) { |
|
| 154 | + if ($this->is_subs_change_payment()) { |
|
| 155 | + return $this->change_subs_payment_method($order_id); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // Regular payment with force customer enabled |
| 159 | - return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
| 159 | + return parent::process_payment($order_id, $retry, true, $previous_error); |
|
| 160 | 160 | } else { |
| 161 | - return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
| 161 | + return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
@@ -168,27 +168,27 @@ discard block |
||
| 168 | 168 | * @since 4.0.4 |
| 169 | 169 | * @param int $order_id |
| 170 | 170 | */ |
| 171 | - public function change_subs_payment_method( $order_id ) { |
|
| 171 | + public function change_subs_payment_method($order_id) { |
|
| 172 | 172 | try { |
| 173 | - $subscription = wc_get_order( $order_id ); |
|
| 174 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
| 173 | + $subscription = wc_get_order($order_id); |
|
| 174 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
| 175 | 175 | |
| 176 | - if ( empty( $prepared_source->source ) ) { |
|
| 177 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 178 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 176 | + if (empty($prepared_source->source)) { |
|
| 177 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 178 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
| 181 | + $this->save_source_to_order($subscription, $prepared_source); |
|
| 182 | 182 | |
| 183 | - do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source ); |
|
| 183 | + do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source); |
|
| 184 | 184 | |
| 185 | 185 | return array( |
| 186 | 186 | 'result' => 'success', |
| 187 | - 'redirect' => $this->get_return_url( $subscription ), |
|
| 187 | + 'redirect' => $this->get_return_url($subscription), |
|
| 188 | 188 | ); |
| 189 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 190 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 191 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 189 | + } catch (WC_Stripe_Exception $e) { |
|
| 190 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 191 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | |
@@ -198,8 +198,8 @@ discard block |
||
| 198 | 198 | * @param $amount_to_charge float The amount to charge. |
| 199 | 199 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 200 | 200 | */ |
| 201 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 202 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
| 201 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 202 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -213,86 +213,86 @@ discard block |
||
| 213 | 213 | * @param bool $retry Should we retry the process? |
| 214 | 214 | * @param object $previous_error |
| 215 | 215 | */ |
| 216 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
| 216 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
| 217 | 217 | try { |
| 218 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 218 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 219 | 219 | /* translators: minimum amount */ |
| 220 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 220 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
| 223 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
| 224 | 224 | |
| 225 | 225 | // Get source from order |
| 226 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
| 226 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
| 227 | 227 | $source_object = $prepared_source->source_object; |
| 228 | 228 | |
| 229 | - if ( ! $prepared_source->customer ) { |
|
| 230 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 229 | + if ( ! $prepared_source->customer) { |
|
| 230 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 233 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 234 | 234 | |
| 235 | 235 | /* If we're doing a retry and source is chargeable, we need to pass |
| 236 | 236 | * a different idempotency key and retry for success. |
| 237 | 237 | */ |
| 238 | - if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
| 239 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
| 238 | + if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
| 239 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
| 242 | + if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
| 243 | 243 | // Passing empty source will charge customer default. |
| 244 | 244 | $prepared_source->source = ''; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
| 247 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
| 248 | 248 | $request['capture'] = 'true'; |
| 249 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 250 | - $response = WC_Stripe_API::request( $request ); |
|
| 249 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
| 250 | + $response = WC_Stripe_API::request($request); |
|
| 251 | 251 | |
| 252 | - if ( ! empty( $response->error ) ) { |
|
| 252 | + if ( ! empty($response->error)) { |
|
| 253 | 253 | // We want to retry. |
| 254 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
| 255 | - if ( $retry ) { |
|
| 254 | + if ($this->is_retryable_error($response->error)) { |
|
| 255 | + if ($retry) { |
|
| 256 | 256 | // Don't do anymore retries after this. |
| 257 | - if ( 5 <= $this->retry_interval ) { |
|
| 258 | - return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
| 257 | + if (5 <= $this->retry_interval) { |
|
| 258 | + return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - sleep( $this->retry_interval ); |
|
| 261 | + sleep($this->retry_interval); |
|
| 262 | 262 | |
| 263 | 263 | $this->retry_interval++; |
| 264 | 264 | |
| 265 | - return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
| 265 | + return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
| 266 | 266 | } else { |
| 267 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 268 | - $renewal_order->add_order_note( $localized_message ); |
|
| 269 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 267 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
| 268 | + $renewal_order->add_order_note($localized_message); |
|
| 269 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 274 | 274 | |
| 275 | - if ( 'card_error' === $response->error->type ) { |
|
| 276 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 275 | + if ('card_error' === $response->error->type) { |
|
| 276 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 277 | 277 | } else { |
| 278 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 278 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - $renewal_order->add_order_note( $localized_message ); |
|
| 281 | + $renewal_order->add_order_note($localized_message); |
|
| 282 | 282 | |
| 283 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 283 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
| 286 | + do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
| 287 | 287 | |
| 288 | - $this->process_response( $response, $renewal_order ); |
|
| 289 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 290 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 288 | + $this->process_response($response, $renewal_order); |
|
| 289 | + } catch (WC_Stripe_Exception $e) { |
|
| 290 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 291 | 291 | |
| 292 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
| 292 | + do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
| 293 | 293 | |
| 294 | 294 | /* translators: error message */ |
| 295 | - $renewal_order->update_status( 'failed' ); |
|
| 295 | + $renewal_order->update_status('failed'); |
|
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
@@ -300,21 +300,21 @@ discard block |
||
| 300 | 300 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 301 | 301 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 302 | 302 | */ |
| 303 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 304 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 305 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 303 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 304 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 305 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 306 | 306 | // For BW compat will remove in future |
| 307 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 308 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 307 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 308 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
| 312 | 312 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 313 | 313 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 314 | 314 | */ |
| 315 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 316 | - WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
| 317 | - WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
| 315 | + public function delete_renewal_meta($renewal_order) { |
|
| 316 | + WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
| 317 | + WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
| 318 | 318 | |
| 319 | 319 | return $renewal_order; |
| 320 | 320 | } |
@@ -328,14 +328,14 @@ discard block |
||
| 328 | 328 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 329 | 329 | * @return void |
| 330 | 330 | */ |
| 331 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 332 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 333 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 334 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 331 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 332 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 333 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 334 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 335 | 335 | |
| 336 | 336 | } else { |
| 337 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 338 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 337 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 338 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 339 | 339 | } |
| 340 | 340 | } |
| 341 | 341 | |
@@ -348,21 +348,21 @@ discard block |
||
| 348 | 348 | * @param WC_Subscription $subscription An instance of a subscription object |
| 349 | 349 | * @return array |
| 350 | 350 | */ |
| 351 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 352 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 351 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 352 | + $source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 353 | 353 | |
| 354 | 354 | // For BW compat will remove in future. |
| 355 | - if ( empty( $source_id ) ) { |
|
| 356 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 355 | + if (empty($source_id)) { |
|
| 356 | + $source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 357 | 357 | |
| 358 | 358 | // Take this opportunity to update the key name. |
| 359 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
| 359 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - $payment_meta[ $this->id ] = array( |
|
| 362 | + $payment_meta[$this->id] = array( |
|
| 363 | 363 | 'post_meta' => array( |
| 364 | 364 | '_stripe_customer_id' => array( |
| 365 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
| 365 | + 'value' => get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
| 366 | 366 | 'label' => 'Stripe Customer ID', |
| 367 | 367 | ), |
| 368 | 368 | '_stripe_source_id' => array( |
@@ -383,22 +383,22 @@ discard block |
||
| 383 | 383 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 384 | 384 | * @return array |
| 385 | 385 | */ |
| 386 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 387 | - if ( $this->id === $payment_method_id ) { |
|
| 386 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 387 | + if ($this->id === $payment_method_id) { |
|
| 388 | 388 | |
| 389 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 390 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
| 391 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 392 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
| 389 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 390 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
| 391 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 392 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | if ( |
| 396 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 397 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
| 398 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 399 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
| 396 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 397 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
| 398 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 399 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
| 400 | 400 | |
| 401 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
| 401 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
| 402 | 402 | } |
| 403 | 403 | } |
| 404 | 404 | } |
@@ -411,67 +411,67 @@ discard block |
||
| 411 | 411 | * @param WC_Subscription $subscription the subscription details |
| 412 | 412 | * @return string the subscription payment method |
| 413 | 413 | */ |
| 414 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 415 | - $customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id(); |
|
| 414 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 415 | + $customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id(); |
|
| 416 | 416 | |
| 417 | 417 | // bail for other payment methods |
| 418 | - if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 418 | + if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 419 | 419 | return $payment_method_to_display; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 422 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 423 | 423 | |
| 424 | 424 | // For BW compat will remove in future. |
| 425 | - if ( empty( $stripe_source_id ) ) { |
|
| 426 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 425 | + if (empty($stripe_source_id)) { |
|
| 426 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 427 | 427 | |
| 428 | 428 | // Take this opportunity to update the key name. |
| 429 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 429 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | $stripe_customer = new WC_Stripe_Customer(); |
| 433 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 433 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 434 | 434 | |
| 435 | 435 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 436 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 436 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 437 | 437 | $user_id = $customer_user; |
| 438 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 439 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 438 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 439 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 440 | 440 | |
| 441 | 441 | // For BW compat will remove in future. |
| 442 | - if ( empty( $stripe_source_id ) ) { |
|
| 443 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 442 | + if (empty($stripe_source_id)) { |
|
| 443 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 444 | 444 | |
| 445 | 445 | // Take this opportunity to update the key name. |
| 446 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 446 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 447 | 447 | } |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 451 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 452 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 453 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 451 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 452 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 453 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 454 | 454 | |
| 455 | 455 | // For BW compat will remove in future. |
| 456 | - if ( empty( $stripe_source_id ) ) { |
|
| 457 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 456 | + if (empty($stripe_source_id)) { |
|
| 457 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 458 | 458 | |
| 459 | 459 | // Take this opportunity to update the key name. |
| 460 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 460 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 464 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 465 | 465 | |
| 466 | 466 | $sources = $stripe_customer->get_sources(); |
| 467 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 467 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 468 | 468 | |
| 469 | - if ( $sources ) { |
|
| 470 | - foreach ( $sources as $source ) { |
|
| 471 | - if ( $source->id === $stripe_source_id ) { |
|
| 472 | - if ( $source->sepa_debit ) { |
|
| 469 | + if ($sources) { |
|
| 470 | + foreach ($sources as $source) { |
|
| 471 | + if ($source->id === $stripe_source_id) { |
|
| 472 | + if ($source->sepa_debit) { |
|
| 473 | 473 | /* translators: 1) last 4 digits of SEPA Direct Debit */ |
| 474 | - $payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 ); |
|
| 474 | + $payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | break; |
@@ -1,12 +1,12 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * DEPRECATED DO NOT USE!! |
| 8 | 8 | */ |
| 9 | -if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) { |
|
| 9 | +if ( ! class_exists('WC_Stripe_Apple_Pay')) { |
|
| 10 | 10 | class WC_Stripe_Apple_Pay { |
| 11 | 11 | /** |
| 12 | 12 | * This Instance. |
@@ -20,15 +20,15 @@ discard block |
||
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | public static function instance() { |
| 23 | - WC_Stripe_Logger::log( 'DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 4.2' ); |
|
| 23 | + WC_Stripe_Logger::log('DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 4.2'); |
|
| 24 | 24 | return self::$_this; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public function __get( $var ) { |
|
| 27 | + public function __get($var) { |
|
| 28 | 28 | return null; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function __call( $name, $arguments ) { |
|
| 31 | + public function __call($name, $arguments) { |
|
| 32 | 32 | return null; |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @param float $amount |
| 139 | 139 | * @param mixed $renewal_order |
| 140 | 140 | * @param bool $retry Should we retry the process? |
| 141 | - * @param object $previous_error |
|
| 141 | + * @param boolean $previous_error |
|
| 142 | 142 | */ |
| 143 | 143 | public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
| 144 | 144 | try { |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | /** |
| 243 | 243 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 244 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
| 244 | + * @param integer $renewal_order |
|
| 245 | 245 | */ |
| 246 | 246 | public function delete_renewal_meta( $renewal_order ) { |
| 247 | 247 | WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
@@ -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,21 +15,21 @@ discard block |
||
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | |
| 18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 23 | - add_action( 'wc_stripe_cards_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) ); |
|
| 24 | - add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 ); |
|
| 18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 23 | + add_action('wc_stripe_cards_payment_fields', array($this, 'display_update_subs_payment_checkout')); |
|
| 24 | + add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2); |
|
| 25 | 25 | |
| 26 | 26 | // display the credit card used for a subscription in the "My Subscriptions" table |
| 27 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 27 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 28 | 28 | |
| 29 | 29 | // allow store managers to manually set Stripe as the payment method on a subscription |
| 30 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 31 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 32 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
| 30 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 31 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 32 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
| 33 | 33 | |
| 34 | 34 | /* |
| 35 | 35 | * WC subscriptions hooks into the "template_redirect" hook with priority 100. |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | * See: https://github.com/woocommerce/woocommerce-subscriptions/blob/99a75687e109b64cbc07af6e5518458a6305f366/includes/class-wcs-cart-renewal.php#L165 |
| 38 | 38 | * If we are in the "You just need to authorize SCA" flow, we don't want that redirection to happen. |
| 39 | 39 | */ |
| 40 | - add_action( 'template_redirect', array( $this, 'remove_order_pay_var' ), 99 ); |
|
| 41 | - add_action( 'template_redirect', array( $this, 'restore_order_pay_var' ), 101 ); |
|
| 40 | + add_action('template_redirect', array($this, 'remove_order_pay_var'), 99); |
|
| 41 | + add_action('template_redirect', array($this, 'restore_order_pay_var'), 101); |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | * @since 4.0.0 |
| 50 | 50 | * @version 4.0.0 |
| 51 | 51 | */ |
| 52 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
| 53 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
| 52 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
| 53 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
| 54 | 54 | return false; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * @param int $order_id |
| 63 | 63 | * @return boolean |
| 64 | 64 | */ |
| 65 | - public function has_subscription( $order_id ) { |
|
| 66 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 65 | + public function has_subscription($order_id) { |
|
| 66 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @return bool |
| 74 | 74 | */ |
| 75 | 75 | public function is_subs_change_payment() { |
| 76 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
| 76 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -83,20 +83,20 @@ discard block |
||
| 83 | 83 | * @since 4.1.11 |
| 84 | 84 | */ |
| 85 | 85 | public function display_update_subs_payment_checkout() { |
| 86 | - $subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) ); |
|
| 86 | + $subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active')); |
|
| 87 | 87 | if ( |
| 88 | - apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) && |
|
| 89 | - wcs_user_has_subscription( get_current_user_id(), '', $subs_statuses ) && |
|
| 88 | + apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) && |
|
| 89 | + wcs_user_has_subscription(get_current_user_id(), '', $subs_statuses) && |
|
| 90 | 90 | is_add_payment_method_page() |
| 91 | 91 | ) { |
| 92 | - $label = esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe' ) ) ); |
|
| 93 | - $id = sprintf( 'wc-%1$s-update-subs-payment-method-card', $this->id ); |
|
| 92 | + $label = esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe'))); |
|
| 93 | + $id = sprintf('wc-%1$s-update-subs-payment-method-card', $this->id); |
|
| 94 | 94 | woocommerce_form_field( |
| 95 | 95 | $id, |
| 96 | 96 | array( |
| 97 | 97 | 'type' => 'checkbox', |
| 98 | 98 | 'label' => $label, |
| 99 | - 'default' => apply_filters( 'wc_stripe_save_to_subs_checked', false ), |
|
| 99 | + 'default' => apply_filters('wc_stripe_save_to_subs_checked', false), |
|
| 100 | 100 | ) |
| 101 | 101 | ); |
| 102 | 102 | } |
@@ -109,17 +109,17 @@ discard block |
||
| 109 | 109 | * @param string $source_id |
| 110 | 110 | * @param object $source_object |
| 111 | 111 | */ |
| 112 | - public function handle_add_payment_method_success( $source_id, $source_object ) { |
|
| 113 | - if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) { |
|
| 112 | + public function handle_add_payment_method_success($source_id, $source_object) { |
|
| 113 | + if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) { |
|
| 114 | 114 | $all_subs = wcs_get_users_subscriptions(); |
| 115 | - $subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) ); |
|
| 116 | - |
|
| 117 | - if ( ! empty( $all_subs ) ) { |
|
| 118 | - foreach ( $all_subs as $sub ) { |
|
| 119 | - if ( $sub->has_status( $subs_statuses ) ) { |
|
| 120 | - update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id ); |
|
| 121 | - update_post_meta( $sub->get_id(), '_payment_method', $this->id ); |
|
| 122 | - update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title ); |
|
| 115 | + $subs_statuses = apply_filters('wc_stripe_update_subs_payment_method_card_statuses', array('active')); |
|
| 116 | + |
|
| 117 | + if ( ! empty($all_subs)) { |
|
| 118 | + foreach ($all_subs as $sub) { |
|
| 119 | + if ($sub->has_status($subs_statuses)) { |
|
| 120 | + update_post_meta($sub->get_id(), '_stripe_source_id', $source_id); |
|
| 121 | + update_post_meta($sub->get_id(), '_payment_method', $this->id); |
|
| 122 | + update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title); |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -133,24 +133,24 @@ discard block |
||
| 133 | 133 | * @since 4.1.11 Remove 3DS check as it is not needed. |
| 134 | 134 | * @param int $order_id |
| 135 | 135 | */ |
| 136 | - public function change_subs_payment_method( $order_id ) { |
|
| 136 | + public function change_subs_payment_method($order_id) { |
|
| 137 | 137 | try { |
| 138 | - $subscription = wc_get_order( $order_id ); |
|
| 139 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
| 138 | + $subscription = wc_get_order($order_id); |
|
| 139 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
| 140 | 140 | |
| 141 | - $this->maybe_disallow_prepaid_card( $prepared_source ); |
|
| 142 | - $this->check_source( $prepared_source ); |
|
| 143 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
| 141 | + $this->maybe_disallow_prepaid_card($prepared_source); |
|
| 142 | + $this->check_source($prepared_source); |
|
| 143 | + $this->save_source_to_order($subscription, $prepared_source); |
|
| 144 | 144 | |
| 145 | - do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source ); |
|
| 145 | + do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source); |
|
| 146 | 146 | |
| 147 | 147 | return array( |
| 148 | 148 | 'result' => 'success', |
| 149 | - 'redirect' => $this->get_return_url( $subscription ), |
|
| 149 | + 'redirect' => $this->get_return_url($subscription), |
|
| 150 | 150 | ); |
| 151 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 152 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 153 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 151 | + } catch (WC_Stripe_Exception $e) { |
|
| 152 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 153 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
@@ -159,16 +159,16 @@ discard block |
||
| 159 | 159 | * @param int $order_id |
| 160 | 160 | * @return array |
| 161 | 161 | */ |
| 162 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
| 163 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 164 | - if ( $this->is_subs_change_payment() ) { |
|
| 165 | - return $this->change_subs_payment_method( $order_id ); |
|
| 162 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
| 163 | + if ($this->has_subscription($order_id)) { |
|
| 164 | + if ($this->is_subs_change_payment()) { |
|
| 165 | + return $this->change_subs_payment_method($order_id); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // Regular payment with force customer enabled |
| 169 | - return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
| 169 | + return parent::process_payment($order_id, $retry, true, $previous_error); |
|
| 170 | 170 | } else { |
| 171 | - return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
| 171 | + return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | * @param object $prepared_source The source that is used for the payment. |
| 181 | 181 | * @return array The arguments for the request. |
| 182 | 182 | */ |
| 183 | - public function generate_create_intent_request( $order, $prepared_source ) { |
|
| 184 | - $request = parent::generate_create_intent_request( $order, $prepared_source ); |
|
| 183 | + public function generate_create_intent_request($order, $prepared_source) { |
|
| 184 | + $request = parent::generate_create_intent_request($order, $prepared_source); |
|
| 185 | 185 | |
| 186 | 186 | // Non-subscription orders do not need any additional parameters. |
| 187 | - if ( ! $this->has_subscription( $order ) ) { |
|
| 187 | + if ( ! $this->has_subscription($order)) { |
|
| 188 | 188 | return $request; |
| 189 | 189 | } |
| 190 | 190 | |
@@ -200,8 +200,8 @@ discard block |
||
| 200 | 200 | * @param $amount_to_charge float The amount to charge. |
| 201 | 201 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 202 | 202 | */ |
| 203 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 204 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
| 203 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 204 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -215,115 +215,115 @@ discard block |
||
| 215 | 215 | * @param bool $retry Should we retry the process? |
| 216 | 216 | * @param object $previous_error |
| 217 | 217 | */ |
| 218 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
| 218 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
| 219 | 219 | try { |
| 220 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 220 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 221 | 221 | /* translators: minimum amount */ |
| 222 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 222 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
| 225 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
| 226 | 226 | |
| 227 | 227 | // Check for an existing intent, which is associated with the order. |
| 228 | - if ( $this->has_authentication_already_failed( $renewal_order ) ) { |
|
| 228 | + if ($this->has_authentication_already_failed($renewal_order)) { |
|
| 229 | 229 | return; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // Get source from order |
| 233 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
| 233 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
| 234 | 234 | $source_object = $prepared_source->source_object; |
| 235 | 235 | |
| 236 | - if ( ! $prepared_source->customer ) { |
|
| 237 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 236 | + if ( ! $prepared_source->customer) { |
|
| 237 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 240 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 241 | 241 | |
| 242 | 242 | /* If we're doing a retry and source is chargeable, we need to pass |
| 243 | 243 | * a different idempotency key and retry for success. |
| 244 | 244 | */ |
| 245 | - if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
| 246 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
| 245 | + if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
| 246 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
| 249 | + if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
| 250 | 250 | // Passing empty source will charge customer default. |
| 251 | 251 | $prepared_source->source = ''; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - $this->lock_order_payment( $renewal_order ); |
|
| 254 | + $this->lock_order_payment($renewal_order); |
|
| 255 | 255 | |
| 256 | - $response = $this->create_and_confirm_intent_for_off_session( $renewal_order, $prepared_source, $amount ); |
|
| 257 | - $is_authentication_required = $this->is_authentication_required_for_payment( $response ); |
|
| 256 | + $response = $this->create_and_confirm_intent_for_off_session($renewal_order, $prepared_source, $amount); |
|
| 257 | + $is_authentication_required = $this->is_authentication_required_for_payment($response); |
|
| 258 | 258 | |
| 259 | 259 | // It's only a failed payment if it's an error and it's not of the type 'authentication_required'. |
| 260 | 260 | // If it's 'authentication_required', then we should email the user and ask them to authenticate. |
| 261 | - if ( ! empty( $response->error ) && ! $is_authentication_required ) { |
|
| 261 | + if ( ! empty($response->error) && ! $is_authentication_required) { |
|
| 262 | 262 | // We want to retry. |
| 263 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
| 264 | - if ( $retry ) { |
|
| 263 | + if ($this->is_retryable_error($response->error)) { |
|
| 264 | + if ($retry) { |
|
| 265 | 265 | // Don't do anymore retries after this. |
| 266 | - if ( 5 <= $this->retry_interval ) { |
|
| 267 | - return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
| 266 | + if (5 <= $this->retry_interval) { |
|
| 267 | + return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - sleep( $this->retry_interval ); |
|
| 270 | + sleep($this->retry_interval); |
|
| 271 | 271 | |
| 272 | 272 | $this->retry_interval++; |
| 273 | 273 | |
| 274 | - return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
| 274 | + return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
| 275 | 275 | } else { |
| 276 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 277 | - $renewal_order->add_order_note( $localized_message ); |
|
| 278 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 276 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
| 277 | + $renewal_order->add_order_note($localized_message); |
|
| 278 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 283 | 283 | |
| 284 | - if ( 'card_error' === $response->error->type ) { |
|
| 285 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 284 | + if ('card_error' === $response->error->type) { |
|
| 285 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 286 | 286 | } else { |
| 287 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 287 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - $renewal_order->add_order_note( $localized_message ); |
|
| 290 | + $renewal_order->add_order_note($localized_message); |
|
| 291 | 291 | |
| 292 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 292 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | // Either the charge was successfully captured, or it requires further authentication. |
| 296 | 296 | |
| 297 | - if ( $is_authentication_required ) { |
|
| 298 | - do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response ); |
|
| 297 | + if ($is_authentication_required) { |
|
| 298 | + do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order, $response); |
|
| 299 | 299 | |
| 300 | - $error_message = __( 'This transaction requires authentication.', 'woocommerce-gateway-stripe' ); |
|
| 301 | - $renewal_order->add_order_note( $error_message ); |
|
| 300 | + $error_message = __('This transaction requires authentication.', 'woocommerce-gateway-stripe'); |
|
| 301 | + $renewal_order->add_order_note($error_message); |
|
| 302 | 302 | |
| 303 | - $charge = end( $response->error->payment_intent->charges->data ); |
|
| 303 | + $charge = end($response->error->payment_intent->charges->data); |
|
| 304 | 304 | $id = $charge->id; |
| 305 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
| 305 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
| 306 | 306 | |
| 307 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $id ) : $renewal_order->set_transaction_id( $id ); |
|
| 308 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $id ) ); |
|
| 309 | - if ( is_callable( array( $renewal_order, 'save' ) ) ) { |
|
| 307 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $id) : $renewal_order->set_transaction_id($id); |
|
| 308 | + $renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $id)); |
|
| 309 | + if (is_callable(array($renewal_order, 'save'))) { |
|
| 310 | 310 | $renewal_order->save(); |
| 311 | 311 | } |
| 312 | 312 | } else { |
| 313 | 313 | // The charge was successfully captured |
| 314 | - do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
| 314 | + do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
| 315 | 315 | |
| 316 | - $this->process_response( end( $response->charges->data ), $renewal_order ); |
|
| 316 | + $this->process_response(end($response->charges->data), $renewal_order); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - $this->unlock_order_payment( $renewal_order ); |
|
| 320 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 321 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 319 | + $this->unlock_order_payment($renewal_order); |
|
| 320 | + } catch (WC_Stripe_Exception $e) { |
|
| 321 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 322 | 322 | |
| 323 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
| 323 | + do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
| 324 | 324 | |
| 325 | 325 | /* translators: error message */ |
| 326 | - $renewal_order->update_status( 'failed' ); |
|
| 326 | + $renewal_order->update_status('failed'); |
|
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | |
@@ -333,24 +333,24 @@ discard block |
||
| 333 | 333 | * @since 3.1.0 |
| 334 | 334 | * @version 4.0.0 |
| 335 | 335 | */ |
| 336 | - public function save_source_to_order( $order, $source ) { |
|
| 337 | - parent::save_source_to_order( $order, $source ); |
|
| 336 | + public function save_source_to_order($order, $source) { |
|
| 337 | + parent::save_source_to_order($order, $source); |
|
| 338 | 338 | |
| 339 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 339 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 340 | 340 | |
| 341 | 341 | // Also store it on the subscriptions being purchased or paid for in the order |
| 342 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 343 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 344 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 345 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 342 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 343 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 344 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 345 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 346 | 346 | } else { |
| 347 | 347 | $subscriptions = array(); |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - foreach ( $subscriptions as $subscription ) { |
|
| 351 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
| 352 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 353 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 350 | + foreach ($subscriptions as $subscription) { |
|
| 351 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
| 352 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 353 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 354 | 354 | } |
| 355 | 355 | } |
| 356 | 356 | |
@@ -358,26 +358,26 @@ discard block |
||
| 358 | 358 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 359 | 359 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 360 | 360 | */ |
| 361 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 362 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 363 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 361 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 362 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 363 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 364 | 364 | // For BW compat will remove in future |
| 365 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 365 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 366 | 366 | // delete payment intent ID |
| 367 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_intent_id' ); |
|
| 368 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 367 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_intent_id'); |
|
| 368 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | /** |
| 372 | 372 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 373 | 373 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 374 | 374 | */ |
| 375 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 376 | - WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
| 377 | - WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
| 375 | + public function delete_renewal_meta($renewal_order) { |
|
| 376 | + WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
| 377 | + WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
| 378 | 378 | |
| 379 | 379 | // delete payment intent ID |
| 380 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id() ), '_stripe_intent_id' ); |
|
| 380 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id()), '_stripe_intent_id'); |
|
| 381 | 381 | |
| 382 | 382 | return $renewal_order; |
| 383 | 383 | } |
@@ -391,14 +391,14 @@ discard block |
||
| 391 | 391 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 392 | 392 | * @return void |
| 393 | 393 | */ |
| 394 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 395 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 396 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 397 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 394 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 395 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 396 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 397 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 398 | 398 | |
| 399 | 399 | } else { |
| 400 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 401 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 400 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 401 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 402 | 402 | } |
| 403 | 403 | } |
| 404 | 404 | |
@@ -411,23 +411,23 @@ discard block |
||
| 411 | 411 | * @param WC_Subscription $subscription An instance of a subscription object |
| 412 | 412 | * @return array |
| 413 | 413 | */ |
| 414 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 415 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
| 416 | - $source_id = get_post_meta( $subscription_id, '_stripe_source_id', true ); |
|
| 414 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 415 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
| 416 | + $source_id = get_post_meta($subscription_id, '_stripe_source_id', true); |
|
| 417 | 417 | |
| 418 | 418 | // For BW compat will remove in future. |
| 419 | - if ( empty( $source_id ) ) { |
|
| 420 | - $source_id = get_post_meta( $subscription_id, '_stripe_card_id', true ); |
|
| 419 | + if (empty($source_id)) { |
|
| 420 | + $source_id = get_post_meta($subscription_id, '_stripe_card_id', true); |
|
| 421 | 421 | |
| 422 | 422 | // Take this opportunity to update the key name. |
| 423 | - update_post_meta( $subscription_id, '_stripe_source_id', $source_id ); |
|
| 424 | - delete_post_meta( $subscription_id, '_stripe_card_id', $source_id ); |
|
| 423 | + update_post_meta($subscription_id, '_stripe_source_id', $source_id); |
|
| 424 | + delete_post_meta($subscription_id, '_stripe_card_id', $source_id); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - $payment_meta[ $this->id ] = array( |
|
| 427 | + $payment_meta[$this->id] = array( |
|
| 428 | 428 | 'post_meta' => array( |
| 429 | 429 | '_stripe_customer_id' => array( |
| 430 | - 'value' => get_post_meta( $subscription_id, '_stripe_customer_id', true ), |
|
| 430 | + 'value' => get_post_meta($subscription_id, '_stripe_customer_id', true), |
|
| 431 | 431 | 'label' => 'Stripe Customer ID', |
| 432 | 432 | ), |
| 433 | 433 | '_stripe_source_id' => array( |
@@ -450,22 +450,22 @@ discard block |
||
| 450 | 450 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 451 | 451 | * @return array |
| 452 | 452 | */ |
| 453 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 454 | - if ( $this->id === $payment_method_id ) { |
|
| 453 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 454 | + if ($this->id === $payment_method_id) { |
|
| 455 | 455 | |
| 456 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 457 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
| 458 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 459 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
| 456 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 457 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
| 458 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 459 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | if ( |
| 463 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 464 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
| 465 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 466 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
| 463 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 464 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
| 465 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 466 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
| 467 | 467 | |
| 468 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
| 468 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
| 469 | 469 | } |
| 470 | 470 | } |
| 471 | 471 | } |
@@ -478,75 +478,75 @@ discard block |
||
| 478 | 478 | * @param WC_Subscription $subscription the subscription details |
| 479 | 479 | * @return string the subscription payment method |
| 480 | 480 | */ |
| 481 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 482 | - $customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id(); |
|
| 481 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 482 | + $customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id(); |
|
| 483 | 483 | |
| 484 | 484 | // bail for other payment methods |
| 485 | - if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 485 | + if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 486 | 486 | return $payment_method_to_display; |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 489 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 490 | 490 | |
| 491 | 491 | // For BW compat will remove in future. |
| 492 | - if ( empty( $stripe_source_id ) ) { |
|
| 493 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 492 | + if (empty($stripe_source_id)) { |
|
| 493 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 494 | 494 | |
| 495 | 495 | // Take this opportunity to update the key name. |
| 496 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 496 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | $stripe_customer = new WC_Stripe_Customer(); |
| 500 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 500 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 501 | 501 | |
| 502 | 502 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 503 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 503 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 504 | 504 | $user_id = $customer_user; |
| 505 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 506 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 505 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 506 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 507 | 507 | |
| 508 | 508 | // For BW compat will remove in future. |
| 509 | - if ( empty( $stripe_source_id ) ) { |
|
| 510 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 509 | + if (empty($stripe_source_id)) { |
|
| 510 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 511 | 511 | |
| 512 | 512 | // Take this opportunity to update the key name. |
| 513 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 513 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 518 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 519 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 520 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 518 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 519 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 520 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 521 | 521 | |
| 522 | 522 | // For BW compat will remove in future. |
| 523 | - if ( empty( $stripe_source_id ) ) { |
|
| 524 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 523 | + if (empty($stripe_source_id)) { |
|
| 524 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 525 | 525 | |
| 526 | 526 | // Take this opportunity to update the key name. |
| 527 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 527 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
| 528 | 528 | } |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 531 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 532 | 532 | |
| 533 | 533 | $sources = $stripe_customer->get_sources(); |
| 534 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 534 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 535 | 535 | |
| 536 | - if ( $sources ) { |
|
| 536 | + if ($sources) { |
|
| 537 | 537 | $card = false; |
| 538 | 538 | |
| 539 | - foreach ( $sources as $source ) { |
|
| 540 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 539 | + foreach ($sources as $source) { |
|
| 540 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 541 | 541 | $card = $source->card; |
| 542 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
| 542 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
| 543 | 543 | $card = $source; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - if ( $source->id === $stripe_source_id ) { |
|
| 547 | - if ( $card ) { |
|
| 546 | + if ($source->id === $stripe_source_id) { |
|
| 547 | + if ($card) { |
|
| 548 | 548 | /* translators: 1) card brand 2) last 4 digits */ |
| 549 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 549 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | break; |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | */ |
| 564 | 564 | public function remove_order_pay_var() { |
| 565 | 565 | global $wp; |
| 566 | - if ( isset( $_GET['wc-stripe-confirmation'] ) ) { |
|
| 566 | + if (isset($_GET['wc-stripe-confirmation'])) { |
|
| 567 | 567 | $this->order_pay_var = $wp->query_vars['order-pay']; |
| 568 | 568 | $wp->query_vars['order-pay'] = null; |
| 569 | 569 | } |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | */ |
| 575 | 575 | public function restore_order_pay_var() { |
| 576 | 576 | global $wp; |
| 577 | - if ( isset( $this->order_pay_var ) ) { |
|
| 577 | + if (isset($this->order_pay_var)) { |
|
| 578 | 578 | $wp->query_vars['order-pay'] = $this->order_pay_var; |
| 579 | 579 | } |
| 580 | 580 | } |
@@ -585,13 +585,13 @@ discard block |
||
| 585 | 585 | * @param WC_Order $renewal_order The renewal order. |
| 586 | 586 | * @return boolean |
| 587 | 587 | */ |
| 588 | - public function has_authentication_already_failed( $renewal_order ) { |
|
| 589 | - $existing_intent = $this->get_intent_from_order( $renewal_order ); |
|
| 588 | + public function has_authentication_already_failed($renewal_order) { |
|
| 589 | + $existing_intent = $this->get_intent_from_order($renewal_order); |
|
| 590 | 590 | |
| 591 | 591 | if ( |
| 592 | 592 | ! $existing_intent |
| 593 | 593 | || 'requires_payment_method' !== $existing_intent->status |
| 594 | - || empty( $existing_intent->last_payment_error ) |
|
| 594 | + || empty($existing_intent->last_payment_error) |
|
| 595 | 595 | || 'authentication_required' !== $existing_intent->last_payment_error->code |
| 596 | 596 | ) { |
| 597 | 597 | return false; |
@@ -605,12 +605,12 @@ discard block |
||
| 605 | 605 | * |
| 606 | 606 | * @param WC_Order $renewal_order The order that is being renewed. |
| 607 | 607 | */ |
| 608 | - do_action( 'wc_gateway_stripe_process_payment_authentication_required', $renewal_order ); |
|
| 608 | + do_action('wc_gateway_stripe_process_payment_authentication_required', $renewal_order); |
|
| 609 | 609 | |
| 610 | 610 | // Fail the payment attempt (order would be currently pending because of retry rules). |
| 611 | - $charge = end( $existing_intent->charges->data ); |
|
| 611 | + $charge = end($existing_intent->charges->data); |
|
| 612 | 612 | $charge_id = $charge->id; |
| 613 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe' ), $charge_id ) ); |
|
| 613 | + $renewal_order->update_status('failed', sprintf(__('Stripe charge awaiting authentication by user: %s.', 'woocommerce-gateway-stripe'), $charge_id)); |
|
| 614 | 614 | |
| 615 | 615 | return true; |
| 616 | 616 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | public function __construct() { |
| 22 | 22 | self::$_this = $this; |
| 23 | 23 | |
| 24 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
| 25 | - add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'get_account_saved_payment_methods_list_item_sepa' ), 10, 2 ); |
|
| 26 | - add_filter( 'woocommerce_get_credit_card_type_label', array( $this, 'normalize_sepa_label' ) ); |
|
| 27 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
| 28 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
| 24 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
| 25 | + add_filter('woocommerce_payment_methods_list_item', array($this, 'get_account_saved_payment_methods_list_item_sepa'), 10, 2); |
|
| 26 | + add_filter('woocommerce_get_credit_card_type_label', array($this, 'normalize_sepa_label')); |
|
| 27 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
| 28 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | * @param string $label |
| 47 | 47 | * @return string $label |
| 48 | 48 | */ |
| 49 | - public function normalize_sepa_label( $label ) { |
|
| 50 | - if ( 'sepa iban' === strtolower( $label ) ) { |
|
| 49 | + public function normalize_sepa_label($label) { |
|
| 50 | + if ('sepa iban' === strtolower($label)) { |
|
| 51 | 51 | return 'SEPA IBAN'; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -61,19 +61,19 @@ discard block |
||
| 61 | 61 | * @param int $customer_id |
| 62 | 62 | * @return bool |
| 63 | 63 | */ |
| 64 | - public static function customer_has_saved_methods( $customer_id ) { |
|
| 65 | - $gateways = array( 'stripe', 'stripe_sepa' ); |
|
| 64 | + public static function customer_has_saved_methods($customer_id) { |
|
| 65 | + $gateways = array('stripe', 'stripe_sepa'); |
|
| 66 | 66 | |
| 67 | - if ( empty( $customer_id ) ) { |
|
| 67 | + if (empty($customer_id)) { |
|
| 68 | 68 | return false; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $has_token = false; |
| 72 | 72 | |
| 73 | - foreach ( $gateways as $gateway ) { |
|
| 74 | - $tokens = WC_Payment_Tokens::get_customer_tokens( $customer_id, $gateway ); |
|
| 73 | + foreach ($gateways as $gateway) { |
|
| 74 | + $tokens = WC_Payment_Tokens::get_customer_tokens($customer_id, $gateway); |
|
| 75 | 75 | |
| 76 | - if ( ! empty( $tokens ) ) { |
|
| 76 | + if ( ! empty($tokens)) { |
|
| 77 | 77 | $has_token = true; |
| 78 | 78 | break; |
| 79 | 79 | } |
@@ -90,67 +90,67 @@ discard block |
||
| 90 | 90 | * @param array $tokens |
| 91 | 91 | * @return array |
| 92 | 92 | */ |
| 93 | - public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) { |
|
| 94 | - if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 93 | + public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) { |
|
| 94 | + if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) { |
|
| 95 | 95 | $stored_tokens = array(); |
| 96 | 96 | |
| 97 | - foreach ( $tokens as $token ) { |
|
| 97 | + foreach ($tokens as $token) { |
|
| 98 | 98 | $stored_tokens[] = $token->get_token(); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - if ( 'stripe' === $gateway_id ) { |
|
| 102 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 101 | + if ('stripe' === $gateway_id) { |
|
| 102 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 103 | 103 | $stripe_sources = $stripe_customer->get_sources(); |
| 104 | 104 | |
| 105 | - foreach ( $stripe_sources as $source ) { |
|
| 106 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 107 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
| 105 | + foreach ($stripe_sources as $source) { |
|
| 106 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 107 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
| 108 | 108 | $token = new WC_Payment_Token_CC(); |
| 109 | - $token->set_token( $source->id ); |
|
| 110 | - $token->set_gateway_id( 'stripe' ); |
|
| 111 | - |
|
| 112 | - if ( 'source' === $source->object && 'card' === $source->type ) { |
|
| 113 | - $token->set_card_type( strtolower( $source->card->brand ) ); |
|
| 114 | - $token->set_last4( $source->card->last4 ); |
|
| 115 | - $token->set_expiry_month( $source->card->exp_month ); |
|
| 116 | - $token->set_expiry_year( $source->card->exp_year ); |
|
| 109 | + $token->set_token($source->id); |
|
| 110 | + $token->set_gateway_id('stripe'); |
|
| 111 | + |
|
| 112 | + if ('source' === $source->object && 'card' === $source->type) { |
|
| 113 | + $token->set_card_type(strtolower($source->card->brand)); |
|
| 114 | + $token->set_last4($source->card->last4); |
|
| 115 | + $token->set_expiry_month($source->card->exp_month); |
|
| 116 | + $token->set_expiry_year($source->card->exp_year); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $token->set_user_id( $customer_id ); |
|
| 119 | + $token->set_user_id($customer_id); |
|
| 120 | 120 | $token->save(); |
| 121 | - $tokens[ $token->get_id() ] = $token; |
|
| 121 | + $tokens[$token->get_id()] = $token; |
|
| 122 | 122 | } |
| 123 | 123 | } else { |
| 124 | - if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) { |
|
| 124 | + if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) { |
|
| 125 | 125 | $token = new WC_Payment_Token_CC(); |
| 126 | - $token->set_token( $source->id ); |
|
| 127 | - $token->set_gateway_id( 'stripe' ); |
|
| 128 | - $token->set_card_type( strtolower( $source->brand ) ); |
|
| 129 | - $token->set_last4( $source->last4 ); |
|
| 130 | - $token->set_expiry_month( $source->exp_month ); |
|
| 131 | - $token->set_expiry_year( $source->exp_year ); |
|
| 132 | - $token->set_user_id( $customer_id ); |
|
| 126 | + $token->set_token($source->id); |
|
| 127 | + $token->set_gateway_id('stripe'); |
|
| 128 | + $token->set_card_type(strtolower($source->brand)); |
|
| 129 | + $token->set_last4($source->last4); |
|
| 130 | + $token->set_expiry_month($source->exp_month); |
|
| 131 | + $token->set_expiry_year($source->exp_year); |
|
| 132 | + $token->set_user_id($customer_id); |
|
| 133 | 133 | $token->save(); |
| 134 | - $tokens[ $token->get_id() ] = $token; |
|
| 134 | + $tokens[$token->get_id()] = $token; |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ( 'stripe_sepa' === $gateway_id ) { |
|
| 141 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 140 | + if ('stripe_sepa' === $gateway_id) { |
|
| 141 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 142 | 142 | $stripe_sources = $stripe_customer->get_sources(); |
| 143 | 143 | |
| 144 | - foreach ( $stripe_sources as $source ) { |
|
| 145 | - if ( isset( $source->type ) && 'sepa_debit' === $source->type ) { |
|
| 146 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
| 144 | + foreach ($stripe_sources as $source) { |
|
| 145 | + if (isset($source->type) && 'sepa_debit' === $source->type) { |
|
| 146 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
| 147 | 147 | $token = new WC_Payment_Token_SEPA(); |
| 148 | - $token->set_token( $source->id ); |
|
| 149 | - $token->set_gateway_id( 'stripe_sepa' ); |
|
| 150 | - $token->set_last4( $source->sepa_debit->last4 ); |
|
| 151 | - $token->set_user_id( $customer_id ); |
|
| 148 | + $token->set_token($source->id); |
|
| 149 | + $token->set_gateway_id('stripe_sepa'); |
|
| 150 | + $token->set_last4($source->sepa_debit->last4); |
|
| 151 | + $token->set_user_id($customer_id); |
|
| 152 | 152 | $token->save(); |
| 153 | - $tokens[ $token->get_id() ] = $token; |
|
| 153 | + $tokens[$token->get_id()] = $token; |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | } |
@@ -169,10 +169,10 @@ discard block |
||
| 169 | 169 | * @param WC_Payment_Token $payment_token The payment token associated with this method entry |
| 170 | 170 | * @return array Filtered item |
| 171 | 171 | */ |
| 172 | - public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) { |
|
| 173 | - if ( 'sepa' === strtolower( $payment_token->get_type() ) ) { |
|
| 172 | + public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) { |
|
| 173 | + if ('sepa' === strtolower($payment_token->get_type())) { |
|
| 174 | 174 | $item['method']['last4'] = $payment_token->get_last4(); |
| 175 | - $item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' ); |
|
| 175 | + $item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe'); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | return $item; |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | * @since 3.1.0 |
| 185 | 185 | * @version 4.0.0 |
| 186 | 186 | */ |
| 187 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
| 188 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
| 189 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 190 | - $stripe_customer->delete_source( $token->get_token() ); |
|
| 187 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
| 188 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
| 189 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 190 | + $stripe_customer->delete_source($token->get_token()); |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
@@ -197,12 +197,12 @@ discard block |
||
| 197 | 197 | * @since 3.1.0 |
| 198 | 198 | * @version 4.0.0 |
| 199 | 199 | */ |
| 200 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
| 201 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 200 | + public function woocommerce_payment_token_set_default($token_id) { |
|
| 201 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 202 | 202 | |
| 203 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
| 204 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 205 | - $stripe_customer->set_default_source( $token->get_token() ); |
|
| 203 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
| 204 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 205 | + $stripe_customer->set_default_source($token->get_token()); |
|
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | } |