@@ -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; |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | $user_agent = self::get_user_agent(); |
| 79 | 79 | $app_info = $user_agent['application']; |
| 80 | 80 | |
| 81 | - return apply_filters( 'woocommerce_stripe_request_headers', array( |
|
| 82 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
| 81 | + return apply_filters('woocommerce_stripe_request_headers', array( |
|
| 82 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
| 83 | 83 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
| 84 | 84 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
| 85 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
| 86 | - ) ); |
|
| 85 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
| 86 | + )); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -95,14 +95,14 @@ discard block |
||
| 95 | 95 | * @param string $api |
| 96 | 96 | * @return array|WP_Error |
| 97 | 97 | */ |
| 98 | - public static function request( $request, $api = 'charges', $method = 'POST' ) { |
|
| 99 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
| 98 | + public static function request($request, $api = 'charges', $method = 'POST') { |
|
| 99 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
| 100 | 100 | |
| 101 | 101 | $headers = self::get_headers(); |
| 102 | 102 | |
| 103 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
| 104 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
| 105 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
| 103 | + if ('charges' === $api && 'POST' === $method) { |
|
| 104 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
| 105 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
| 106 | 106 | |
| 107 | 107 | $headers['Idempotency-Key'] = $request['metadata']['order_id'] . '-' . $source; |
| 108 | 108 | } |
@@ -112,17 +112,17 @@ discard block |
||
| 112 | 112 | array( |
| 113 | 113 | 'method' => $method, |
| 114 | 114 | 'headers' => $headers, |
| 115 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
| 115 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
| 116 | 116 | 'timeout' => 70, |
| 117 | 117 | ) |
| 118 | 118 | ); |
| 119 | 119 | |
| 120 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 121 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
| 122 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 120 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 121 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
| 122 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - return json_decode( $response['body'] ); |
|
| 125 | + return json_decode($response['body']); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | * @version 4.0.0 |
| 133 | 133 | * @param string $api |
| 134 | 134 | */ |
| 135 | - public static function retrieve( $api ) { |
|
| 136 | - WC_Stripe_Logger::log( "{$api}" ); |
|
| 135 | + public static function retrieve($api) { |
|
| 136 | + WC_Stripe_Logger::log("{$api}"); |
|
| 137 | 137 | |
| 138 | 138 | $response = wp_safe_remote_get( |
| 139 | 139 | self::ENDPOINT . $api, |
@@ -144,11 +144,11 @@ discard block |
||
| 144 | 144 | ) |
| 145 | 145 | ); |
| 146 | 146 | |
| 147 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 148 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
| 149 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 147 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 148 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
| 149 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - return json_decode( $response['body'] ); |
|
| 152 | + return json_decode($response['body']); |
|
| 153 | 153 | } |
| 154 | 154 | } |
@@ -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,19 +21,19 @@ discard block |
||
| 21 | 21 | * @since 4.0.5 |
| 22 | 22 | * @param array $error |
| 23 | 23 | */ |
| 24 | - public function is_idempotency_error( $error ) { |
|
| 25 | - return ( 'invalid_request_error' === $error->type && preg_match( '/There is currently another in-progress request using this Idempotent Key/', $error->message ) ); |
|
| 24 | + public function is_idempotency_error($error) { |
|
| 25 | + return ('invalid_request_error' === $error->type && preg_match('/There is currently another in-progress request using this Idempotent Key/', $error->message)); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Check if this gateway is enabled |
| 30 | 30 | */ |
| 31 | 31 | public function is_available() { |
| 32 | - if ( 'yes' === $this->enabled ) { |
|
| 33 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
| 32 | + if ('yes' === $this->enabled) { |
|
| 33 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
| 34 | 34 | return false; |
| 35 | 35 | } |
| 36 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
| 36 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
| 37 | 37 | return false; |
| 38 | 38 | } |
| 39 | 39 | return true; |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | * @since 4.0.0 |
| 49 | 49 | * @version 4.0.0 |
| 50 | 50 | */ |
| 51 | - public function add_admin_notice( $slug, $class, $message ) { |
|
| 52 | - $this->notices[ $slug ] = array( |
|
| 51 | + public function add_admin_notice($slug, $class, $message) { |
|
| 52 | + $this->notices[$slug] = array( |
|
| 53 | 53 | 'class' => $class, |
| 54 | 54 | 'message' => $message, |
| 55 | 55 | ); |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * @version 4.0.0 |
| 63 | 63 | */ |
| 64 | 64 | public function remove_admin_notice() { |
| 65 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
| 66 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 65 | + if (did_action('woocommerce_update_options')) { |
|
| 66 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | 77 | public function payment_icons() { |
| 78 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 78 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 79 | 79 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
| 80 | 80 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
| 81 | 81 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
| 93 | 93 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
| 94 | 94 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
| 95 | - ) ); |
|
| 95 | + )); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -103,10 +103,10 @@ discard block |
||
| 103 | 103 | * @version 4.0.0 |
| 104 | 104 | * @param object $order |
| 105 | 105 | */ |
| 106 | - public function validate_minimum_order_amount( $order ) { |
|
| 107 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 106 | + public function validate_minimum_order_amount($order) { |
|
| 107 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 108 | 108 | /* translators: 1) dollar amount */ |
| 109 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', 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 ) ) ); |
|
| 109 | + throw new WC_Stripe_Exception('Did not meet minimum amount', 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))); |
|
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
@@ -116,14 +116,14 @@ discard block |
||
| 116 | 116 | * @since 4.0.0 |
| 117 | 117 | * @version 4.0.0 |
| 118 | 118 | */ |
| 119 | - public function get_transaction_url( $order ) { |
|
| 120 | - if ( $this->testmode ) { |
|
| 119 | + public function get_transaction_url($order) { |
|
| 120 | + if ($this->testmode) { |
|
| 121 | 121 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
| 122 | 122 | } else { |
| 123 | 123 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - return parent::get_transaction_url( $order ); |
|
| 126 | + return parent::get_transaction_url($order); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -132,15 +132,15 @@ discard block |
||
| 132 | 132 | * @since 4.0.0 |
| 133 | 133 | * @version 4.0.0 |
| 134 | 134 | */ |
| 135 | - public function get_stripe_customer_id( $order ) { |
|
| 136 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
| 135 | + public function get_stripe_customer_id($order) { |
|
| 136 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
| 137 | 137 | |
| 138 | - if ( empty( $customer ) ) { |
|
| 138 | + if (empty($customer)) { |
|
| 139 | 139 | // Try to get it via the order. |
| 140 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 141 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
| 140 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 141 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
| 142 | 142 | } else { |
| 143 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
| 143 | + return $order->get_meta('_stripe_customer_id', true); |
|
| 144 | 144 | } |
| 145 | 145 | } else { |
| 146 | 146 | return $customer; |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | * @param object $order |
| 158 | 158 | * @param int $id Stripe session id. |
| 159 | 159 | */ |
| 160 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
| 161 | - if ( is_object( $order ) ) { |
|
| 162 | - if ( empty( $id ) ) { |
|
| 160 | + public function get_stripe_return_url($order = null, $id = null) { |
|
| 161 | + if (is_object($order)) { |
|
| 162 | + if (empty($id)) { |
|
| 163 | 163 | $id = uniqid(); |
| 164 | 164 | } |
| 165 | 165 | |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | 'order_id' => $order_id, |
| 171 | 171 | ); |
| 172 | 172 | |
| 173 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
| 173 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
| 176 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -185,34 +185,33 @@ discard block |
||
| 185 | 185 | * @param object $source |
| 186 | 186 | * @return array() |
| 187 | 187 | */ |
| 188 | - public function generate_payment_request( $order, $source ) { |
|
| 189 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 190 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
| 191 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
| 188 | + public function generate_payment_request($order, $source) { |
|
| 189 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
| 190 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
| 191 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
| 192 | 192 | $post_data = array(); |
| 193 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
| 194 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 193 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
| 194 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 195 | 195 | /* translators: 1) blog name 2) order number */ |
| 196 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
| 196 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
| 197 | 197 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
| 198 | 198 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 199 | 199 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
| 200 | 200 | |
| 201 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 201 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 202 | 202 | $post_data['receipt_email'] = $billing_email; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
| 206 | - case 'stripe': |
|
| 207 | - if ( ! empty( $statement_descriptor ) ) { |
|
| 208 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
| 205 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
| 206 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
| 207 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
| 209 | 208 | } |
| 210 | 209 | |
| 211 | 210 | $post_data['capture'] = $capture ? 'true' : 'false'; |
| 212 | 211 | break; |
| 213 | 212 | case 'stripe_sepa': |
| 214 | - if ( ! empty( $statement_descriptor ) ) { |
|
| 215 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
| 213 | + if ( ! empty($statement_descriptor)) { |
|
| 214 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
| 216 | 215 | } |
| 217 | 216 | break; |
| 218 | 217 | } |
@@ -220,18 +219,18 @@ discard block |
||
| 220 | 219 | $post_data['expand[]'] = 'balance_transaction'; |
| 221 | 220 | |
| 222 | 221 | $metadata = array( |
| 223 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
| 224 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
| 222 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
| 223 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
| 225 | 224 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
| 226 | 225 | ); |
| 227 | 226 | |
| 228 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
| 227 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
| 229 | 228 | |
| 230 | - if ( $source->customer ) { |
|
| 229 | + if ($source->customer) { |
|
| 231 | 230 | $post_data['customer'] = $source->customer; |
| 232 | 231 | } |
| 233 | 232 | |
| 234 | - if ( $source->source ) { |
|
| 233 | + if ($source->source) { |
|
| 235 | 234 | $post_data['source'] = $source->source; |
| 236 | 235 | } |
| 237 | 236 | |
@@ -243,77 +242,77 @@ discard block |
||
| 243 | 242 | * @param WC_Order $order |
| 244 | 243 | * @param object $source |
| 245 | 244 | */ |
| 246 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
| 245 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
| 247 | 246 | } |
| 248 | 247 | |
| 249 | 248 | /** |
| 250 | 249 | * Store extra meta data for an order from a Stripe Response. |
| 251 | 250 | */ |
| 252 | - public function process_response( $response, $order ) { |
|
| 253 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
| 251 | + public function process_response($response, $order) { |
|
| 252 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
| 254 | 253 | |
| 255 | 254 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 256 | 255 | |
| 257 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
| 256 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
| 258 | 257 | |
| 259 | 258 | // Store charge data |
| 260 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
| 259 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
| 261 | 260 | |
| 262 | 261 | // Store other data such as fees |
| 263 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
| 262 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
| 264 | 263 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 265 | 264 | // values are in the local currency of the Stripe account, not from WC. |
| 266 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
| 267 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
| 268 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
| 269 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
| 265 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
| 266 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
| 267 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
| 268 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
| 270 | 269 | } |
| 271 | 270 | |
| 272 | - if ( 'yes' === $captured ) { |
|
| 271 | + if ('yes' === $captured) { |
|
| 273 | 272 | /** |
| 274 | 273 | * Charge can be captured but in a pending state. Payment methods |
| 275 | 274 | * that are asynchronous may take couple days to clear. Webhook will |
| 276 | 275 | * take care of the status changes. |
| 277 | 276 | */ |
| 278 | - if ( 'pending' === $response->status ) { |
|
| 279 | - if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) { |
|
| 280 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
| 277 | + if ('pending' === $response->status) { |
|
| 278 | + if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) { |
|
| 279 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
| 281 | 280 | } |
| 282 | 281 | |
| 283 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
| 282 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
| 284 | 283 | /* translators: transaction id */ |
| 285 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
| 284 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
| 286 | 285 | } |
| 287 | 286 | |
| 288 | - if ( 'succeeded' === $response->status ) { |
|
| 289 | - $order->payment_complete( $response->id ); |
|
| 287 | + if ('succeeded' === $response->status) { |
|
| 288 | + $order->payment_complete($response->id); |
|
| 290 | 289 | |
| 291 | 290 | /* translators: transaction id */ |
| 292 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
| 293 | - $order->add_order_note( $message ); |
|
| 291 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
| 292 | + $order->add_order_note($message); |
|
| 294 | 293 | } |
| 295 | 294 | |
| 296 | - if ( 'failed' === $response->status ) { |
|
| 297 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 298 | - $order->add_order_note( $localized_message ); |
|
| 299 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 295 | + if ('failed' === $response->status) { |
|
| 296 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 297 | + $order->add_order_note($localized_message); |
|
| 298 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 300 | 299 | } |
| 301 | 300 | } else { |
| 302 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
| 301 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
| 303 | 302 | |
| 304 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 305 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
| 303 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 304 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
| 306 | 305 | } |
| 307 | 306 | |
| 308 | 307 | /* translators: transaction id */ |
| 309 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
| 308 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
| 310 | 309 | } |
| 311 | 310 | |
| 312 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 311 | + if (is_callable(array($order, 'save'))) { |
|
| 313 | 312 | $order->save(); |
| 314 | 313 | } |
| 315 | 314 | |
| 316 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
| 315 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
| 317 | 316 | |
| 318 | 317 | return $response; |
| 319 | 318 | } |
@@ -326,10 +325,10 @@ discard block |
||
| 326 | 325 | * @param int $order_id |
| 327 | 326 | * @return null |
| 328 | 327 | */ |
| 329 | - public function send_failed_order_email( $order_id ) { |
|
| 328 | + public function send_failed_order_email($order_id) { |
|
| 330 | 329 | $emails = WC()->mailer()->get_emails(); |
| 331 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
| 332 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
| 330 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
| 331 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
| 333 | 332 | } |
| 334 | 333 | } |
| 335 | 334 | |
@@ -341,7 +340,7 @@ discard block |
||
| 341 | 340 | * @param object $order |
| 342 | 341 | * @return object $details |
| 343 | 342 | */ |
| 344 | - public function get_owner_details( $order ) { |
|
| 343 | + public function get_owner_details($order) { |
|
| 345 | 344 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 346 | 345 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
| 347 | 346 | |
@@ -352,8 +351,8 @@ discard block |
||
| 352 | 351 | |
| 353 | 352 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
| 354 | 353 | |
| 355 | - if ( ! empty( $phone ) ) { |
|
| 356 | - $details['phone'] = $phone; |
|
| 354 | + if ( ! empty($phone)) { |
|
| 355 | + $details['phone'] = $phone; |
|
| 357 | 356 | } |
| 358 | 357 | |
| 359 | 358 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -363,7 +362,7 @@ discard block |
||
| 363 | 362 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
| 364 | 363 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
| 365 | 364 | |
| 366 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
| 365 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
| 367 | 366 | } |
| 368 | 367 | |
| 369 | 368 | /** |
@@ -372,16 +371,16 @@ discard block |
||
| 372 | 371 | * @since 4.0.3 |
| 373 | 372 | */ |
| 374 | 373 | public function get_source_object() { |
| 375 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
| 374 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
| 376 | 375 | |
| 377 | - if ( empty( $source ) ) { |
|
| 376 | + if (empty($source)) { |
|
| 378 | 377 | return ''; |
| 379 | 378 | } |
| 380 | 379 | |
| 381 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
| 380 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
| 382 | 381 | |
| 383 | - if ( ! empty( $source_object->error ) ) { |
|
| 384 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
| 382 | + if ( ! empty($source_object->error)) { |
|
| 383 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
| 385 | 384 | } |
| 386 | 385 | |
| 387 | 386 | return $source_object; |
@@ -394,11 +393,11 @@ discard block |
||
| 394 | 393 | * @param object $source_object |
| 395 | 394 | * @return bool |
| 396 | 395 | */ |
| 397 | - public function is_3ds_required( $source_object ) { |
|
| 396 | + public function is_3ds_required($source_object) { |
|
| 398 | 397 | return ( |
| 399 | - $source_object && ! empty( $source_object->card ) ) && |
|
| 400 | - ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
| 401 | - ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) |
|
| 398 | + $source_object && ! empty($source_object->card) ) && |
|
| 399 | + ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
| 400 | + ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure) |
|
| 402 | 401 | ); |
| 403 | 402 | } |
| 404 | 403 | |
@@ -409,8 +408,8 @@ discard block |
||
| 409 | 408 | * @param object $source_object |
| 410 | 409 | * @return bool |
| 411 | 410 | */ |
| 412 | - public function is_3ds_card( $source_object ) { |
|
| 413 | - return ( $source_object && 'three_d_secure' === $source_object->type ); |
|
| 411 | + public function is_3ds_card($source_object) { |
|
| 412 | + return ($source_object && 'three_d_secure' === $source_object->type); |
|
| 414 | 413 | } |
| 415 | 414 | |
| 416 | 415 | /** |
@@ -423,22 +422,22 @@ discard block |
||
| 423 | 422 | * @param string $return_url |
| 424 | 423 | * @return mixed |
| 425 | 424 | */ |
| 426 | - public function create_3ds_source( $order, $source_object, $return_url = '' ) { |
|
| 425 | + public function create_3ds_source($order, $source_object, $return_url = '') { |
|
| 427 | 426 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 428 | 427 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 429 | - $return_url = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url; |
|
| 428 | + $return_url = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url; |
|
| 430 | 429 | |
| 431 | 430 | $post_data = array(); |
| 432 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 433 | - $post_data['currency'] = strtolower( $currency ); |
|
| 431 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 432 | + $post_data['currency'] = strtolower($currency); |
|
| 434 | 433 | $post_data['type'] = 'three_d_secure'; |
| 435 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 436 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
| 437 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 434 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 435 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
| 436 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 438 | 437 | |
| 439 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' ); |
|
| 438 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source...'); |
|
| 440 | 439 | |
| 441 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' ); |
|
| 440 | + return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources'); |
|
| 442 | 441 | } |
| 443 | 442 | |
| 444 | 443 | /** |
@@ -455,54 +454,54 @@ discard block |
||
| 455 | 454 | * @throws Exception When card was not added or for and invalid card. |
| 456 | 455 | * @return object |
| 457 | 456 | */ |
| 458 | - public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) { |
|
| 459 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
| 457 | + public function prepare_source($source_object = '', $user_id, $force_save_source = false) { |
|
| 458 | + $customer = new WC_Stripe_Customer($user_id); |
|
| 460 | 459 | $set_customer = true; |
| 461 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
| 460 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
| 462 | 461 | $source_id = ''; |
| 463 | 462 | $wc_token_id = false; |
| 464 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
| 463 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
| 465 | 464 | |
| 466 | 465 | // New CC info was entered and we have a new source to process. |
| 467 | - if ( ! empty( $source_object ) ) { |
|
| 466 | + if ( ! empty($source_object)) { |
|
| 468 | 467 | $source_id = $source_object->id; |
| 469 | 468 | |
| 470 | 469 | // This checks to see if customer opted to save the payment method to file. |
| 471 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
| 470 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
| 472 | 471 | |
| 473 | 472 | /** |
| 474 | 473 | * This is true if the user wants to store the card to their account. |
| 475 | 474 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
| 476 | 475 | * actually reusable. Either that or force_save_source is true. |
| 477 | 476 | */ |
| 478 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
| 479 | - $response = $customer->add_source( $source_object->id ); |
|
| 477 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
| 478 | + $response = $customer->add_source($source_object->id); |
|
| 480 | 479 | |
| 481 | - if ( ! empty( $response->error ) ) { |
|
| 482 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 480 | + if ( ! empty($response->error)) { |
|
| 481 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 483 | 482 | } |
| 484 | 483 | } |
| 485 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
| 484 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
| 486 | 485 | // Use an existing token, and then process the payment |
| 487 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
| 488 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
| 486 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
| 487 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
| 489 | 488 | |
| 490 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
| 491 | - WC()->session->set( 'refresh_totals', true ); |
|
| 492 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
| 489 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
| 490 | + WC()->session->set('refresh_totals', true); |
|
| 491 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
| 493 | 492 | } |
| 494 | 493 | |
| 495 | 494 | $source_id = $wc_token->get_token(); |
| 496 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
| 497 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
| 498 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
| 495 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
| 496 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
| 497 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
| 499 | 498 | |
| 500 | 499 | // This is true if the user wants to store the card to their account. |
| 501 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
| 502 | - $response = $customer->add_source( $stripe_token ); |
|
| 500 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
| 501 | + $response = $customer->add_source($stripe_token); |
|
| 503 | 502 | |
| 504 | - if ( ! empty( $response->error ) ) { |
|
| 505 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 503 | + if ( ! empty($response->error)) { |
|
| 504 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 506 | 505 | } |
| 507 | 506 | } else { |
| 508 | 507 | $set_customer = false; |
@@ -510,7 +509,7 @@ discard block |
||
| 510 | 509 | } |
| 511 | 510 | } |
| 512 | 511 | |
| 513 | - if ( ! $set_customer ) { |
|
| 512 | + if ( ! $set_customer) { |
|
| 514 | 513 | $customer_id = false; |
| 515 | 514 | } else { |
| 516 | 515 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
@@ -536,37 +535,37 @@ discard block |
||
| 536 | 535 | * @param object $order |
| 537 | 536 | * @return object |
| 538 | 537 | */ |
| 539 | - public function prepare_order_source( $order = null ) { |
|
| 538 | + public function prepare_order_source($order = null) { |
|
| 540 | 539 | $stripe_customer = new WC_Stripe_Customer(); |
| 541 | 540 | $stripe_source = false; |
| 542 | 541 | $token_id = false; |
| 543 | 542 | |
| 544 | - if ( $order ) { |
|
| 543 | + if ($order) { |
|
| 545 | 544 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 546 | 545 | |
| 547 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
| 546 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
| 548 | 547 | |
| 549 | - if ( $stripe_customer_id ) { |
|
| 550 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 548 | + if ($stripe_customer_id) { |
|
| 549 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 551 | 550 | } |
| 552 | 551 | |
| 553 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
| 552 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
| 554 | 553 | |
| 555 | 554 | // Since 4.0.0, we changed card to source so we need to account for that. |
| 556 | - if ( empty( $source_id ) ) { |
|
| 557 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
| 555 | + if (empty($source_id)) { |
|
| 556 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
| 558 | 557 | |
| 559 | 558 | // Take this opportunity to update the key name. |
| 560 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
| 559 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
| 561 | 560 | |
| 562 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 561 | + if (is_callable(array($order, 'save'))) { |
|
| 563 | 562 | $order->save(); |
| 564 | 563 | } |
| 565 | 564 | } |
| 566 | 565 | |
| 567 | - if ( $source_id ) { |
|
| 566 | + if ($source_id) { |
|
| 568 | 567 | $stripe_source = $source_id; |
| 569 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
| 568 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
| 570 | 569 | /* |
| 571 | 570 | * We can attempt to charge the customer's default source |
| 572 | 571 | * by sending empty source id. |
@@ -590,27 +589,27 @@ discard block |
||
| 590 | 589 | * @param WC_Order $order For to which the source applies. |
| 591 | 590 | * @param stdClass $source Source information. |
| 592 | 591 | */ |
| 593 | - public function save_source_to_order( $order, $source ) { |
|
| 592 | + public function save_source_to_order($order, $source) { |
|
| 594 | 593 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 595 | 594 | |
| 596 | 595 | // Store source in the order. |
| 597 | - if ( $source->customer ) { |
|
| 598 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 599 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
| 596 | + if ($source->customer) { |
|
| 597 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 598 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
| 600 | 599 | } else { |
| 601 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
| 600 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
| 602 | 601 | } |
| 603 | 602 | } |
| 604 | 603 | |
| 605 | - if ( $source->source ) { |
|
| 606 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 607 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
| 604 | + if ($source->source) { |
|
| 605 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 606 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
| 608 | 607 | } else { |
| 609 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
| 608 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
| 610 | 609 | } |
| 611 | 610 | } |
| 612 | 611 | |
| 613 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 612 | + if (is_callable(array($order, 'save'))) { |
|
| 614 | 613 | $order->save(); |
| 615 | 614 | } |
| 616 | 615 | } |
@@ -624,27 +623,27 @@ discard block |
||
| 624 | 623 | * @param object $order The order object |
| 625 | 624 | * @param int $balance_transaction_id |
| 626 | 625 | */ |
| 627 | - public function update_fees( $order, $balance_transaction_id ) { |
|
| 626 | + public function update_fees($order, $balance_transaction_id) { |
|
| 628 | 627 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 629 | 628 | |
| 630 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
| 629 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
| 631 | 630 | |
| 632 | - if ( empty( $balance_transaction->error ) ) { |
|
| 633 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
| 631 | + if (empty($balance_transaction->error)) { |
|
| 632 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
| 634 | 633 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 635 | 634 | // values are in the local currency of the Stripe account, not from WC. |
| 636 | - $fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
| 637 | - $net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
| 635 | + $fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
| 636 | + $net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
| 638 | 637 | |
| 639 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
| 640 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
| 638 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
| 639 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
| 641 | 640 | |
| 642 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 641 | + if (is_callable(array($order, 'save'))) { |
|
| 643 | 642 | $order->save(); |
| 644 | 643 | } |
| 645 | 644 | } |
| 646 | 645 | } else { |
| 647 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
| 646 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
| 648 | 647 | } |
| 649 | 648 | } |
| 650 | 649 | |
@@ -657,33 +656,33 @@ discard block |
||
| 657 | 656 | * @param float $amount |
| 658 | 657 | * @return bool |
| 659 | 658 | */ |
| 660 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 661 | - $order = wc_get_order( $order_id ); |
|
| 659 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
| 660 | + $order = wc_get_order($order_id); |
|
| 662 | 661 | |
| 663 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 662 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
| 664 | 663 | return false; |
| 665 | 664 | } |
| 666 | 665 | |
| 667 | 666 | $request = array(); |
| 668 | 667 | |
| 669 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 670 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
| 671 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
| 668 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 669 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
| 670 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
| 672 | 671 | } else { |
| 673 | 672 | $order_currency = $order->get_currency(); |
| 674 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
| 673 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
| 675 | 674 | } |
| 676 | 675 | |
| 677 | - if ( ! is_null( $amount ) ) { |
|
| 678 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
| 676 | + if ( ! is_null($amount)) { |
|
| 677 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
| 679 | 678 | } |
| 680 | 679 | |
| 681 | 680 | // If order is only authorized, don't pass amount. |
| 682 | - if ( 'yes' !== $captured ) { |
|
| 683 | - unset( $request['amount'] ); |
|
| 681 | + if ('yes' !== $captured) { |
|
| 682 | + unset($request['amount']); |
|
| 684 | 683 | } |
| 685 | 684 | |
| 686 | - if ( $reason ) { |
|
| 685 | + if ($reason) { |
|
| 687 | 686 | $request['metadata'] = array( |
| 688 | 687 | 'reason' => $reason, |
| 689 | 688 | ); |
@@ -691,33 +690,33 @@ discard block |
||
| 691 | 690 | |
| 692 | 691 | $request['charge'] = $order->get_transaction_id(); |
| 693 | 692 | |
| 694 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
| 693 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
| 695 | 694 | |
| 696 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
| 695 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
| 697 | 696 | |
| 698 | - if ( ! empty( $response->error ) ) { |
|
| 699 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
| 697 | + if ( ! empty($response->error)) { |
|
| 698 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
| 700 | 699 | |
| 701 | 700 | return $response; |
| 702 | 701 | |
| 703 | - } elseif ( ! empty( $response->id ) ) { |
|
| 704 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
| 702 | + } elseif ( ! empty($response->id)) { |
|
| 703 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
| 705 | 704 | |
| 706 | - $amount = wc_price( $response->amount / 100 ); |
|
| 705 | + $amount = wc_price($response->amount / 100); |
|
| 707 | 706 | |
| 708 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
| 709 | - $amount = wc_price( $response->amount ); |
|
| 707 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
| 708 | + $amount = wc_price($response->amount); |
|
| 710 | 709 | } |
| 711 | 710 | |
| 712 | - if ( isset( $response->balance_transaction ) ) { |
|
| 713 | - $this->update_fees( $order, $response->balance_transaction ); |
|
| 711 | + if (isset($response->balance_transaction)) { |
|
| 712 | + $this->update_fees($order, $response->balance_transaction); |
|
| 714 | 713 | } |
| 715 | 714 | |
| 716 | 715 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
| 717 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' ); |
|
| 716 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe'); |
|
| 718 | 717 | |
| 719 | - $order->add_order_note( $refund_message ); |
|
| 720 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 718 | + $order->add_order_note($refund_message); |
|
| 719 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
| 721 | 720 | |
| 722 | 721 | return true; |
| 723 | 722 | } |
@@ -732,44 +731,44 @@ discard block |
||
| 732 | 731 | */ |
| 733 | 732 | public function add_payment_method() { |
| 734 | 733 | $error = false; |
| 735 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
| 734 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
| 736 | 735 | $source_id = ''; |
| 737 | 736 | |
| 738 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
| 737 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
| 739 | 738 | $error = true; |
| 740 | 739 | } |
| 741 | 740 | |
| 742 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 741 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 743 | 742 | |
| 744 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
| 743 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
| 745 | 744 | |
| 746 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
| 745 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
| 747 | 746 | |
| 748 | - if ( isset( $source_object ) ) { |
|
| 749 | - if ( ! empty( $source_object->error ) ) { |
|
| 747 | + if (isset($source_object)) { |
|
| 748 | + if ( ! empty($source_object->error)) { |
|
| 750 | 749 | $error = true; |
| 751 | 750 | } |
| 752 | 751 | |
| 753 | 752 | $source_id = $source_object->id; |
| 754 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
| 755 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
| 753 | + } elseif (isset($_POST['stripe_token'])) { |
|
| 754 | + $source_id = wc_clean($_POST['stripe_token']); |
|
| 756 | 755 | } |
| 757 | 756 | |
| 758 | - $response = $stripe_customer->add_source( $source_id ); |
|
| 757 | + $response = $stripe_customer->add_source($source_id); |
|
| 759 | 758 | |
| 760 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
| 759 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
| 761 | 760 | $error = true; |
| 762 | 761 | } |
| 763 | 762 | |
| 764 | - if ( $error ) { |
|
| 765 | - wc_add_notice( $error_msg, 'error' ); |
|
| 766 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
| 763 | + if ($error) { |
|
| 764 | + wc_add_notice($error_msg, 'error'); |
|
| 765 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
| 767 | 766 | return; |
| 768 | 767 | } |
| 769 | 768 | |
| 770 | 769 | return array( |
| 771 | 770 | 'result' => 'success', |
| 772 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
| 771 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
| 773 | 772 | ); |
| 774 | 773 | } |
| 775 | 774 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | public function __construct() { |
| 22 | 22 | $this->retry_interval = 2; |
| 23 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
| 23 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -30,24 +30,24 @@ discard block |
||
| 30 | 30 | * @version 4.0.0 |
| 31 | 31 | */ |
| 32 | 32 | public function check_for_webhook() { |
| 33 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
| 34 | - || ! isset( $_GET['wc-api'] ) |
|
| 35 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
| 33 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
| 34 | + || ! isset($_GET['wc-api']) |
|
| 35 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
| 36 | 36 | ) { |
| 37 | 37 | return; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - $request_body = file_get_contents( 'php://input' ); |
|
| 41 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
| 40 | + $request_body = file_get_contents('php://input'); |
|
| 41 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
| 42 | 42 | |
| 43 | 43 | // Validate it to make sure it is legit. |
| 44 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
| 45 | - $this->process_webhook( $request_body ); |
|
| 46 | - status_header( 200 ); |
|
| 44 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
| 45 | + $this->process_webhook($request_body); |
|
| 46 | + status_header(200); |
|
| 47 | 47 | exit; |
| 48 | 48 | } else { |
| 49 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
| 50 | - status_header( 400 ); |
|
| 49 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
| 50 | + status_header(400); |
|
| 51 | 51 | exit; |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | * @param string $request_body The request body from Stripe. |
| 63 | 63 | * @return bool |
| 64 | 64 | */ |
| 65 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
| 66 | - if ( null === $request_headers || null === $request_body ) { |
|
| 65 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
| 66 | + if (null === $request_headers || null === $request_body) { |
|
| 67 | 67 | return false; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
| 70 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
| 71 | 71 | return false; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -83,11 +83,11 @@ discard block |
||
| 83 | 83 | * @version 4.0.0 |
| 84 | 84 | */ |
| 85 | 85 | public function get_request_headers() { |
| 86 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
| 86 | + if ( ! function_exists('getallheaders')) { |
|
| 87 | 87 | $headers = []; |
| 88 | - foreach ( $_SERVER as $name => $value ) { |
|
| 89 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
| 90 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
| 88 | + foreach ($_SERVER as $name => $value) { |
|
| 89 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
| 90 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
@@ -106,30 +106,30 @@ discard block |
||
| 106 | 106 | * @param object $notification |
| 107 | 107 | * @param bool $retry |
| 108 | 108 | */ |
| 109 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
| 109 | + public function process_webhook_payment($notification, $retry = true) { |
|
| 110 | 110 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
| 111 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
| 111 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
| 115 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
| 116 | 116 | |
| 117 | - if ( ! $order ) { |
|
| 118 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
| 117 | + if ( ! $order) { |
|
| 118 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
| 119 | 119 | return; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 123 | 123 | $source_id = $notification->data->object->id; |
| 124 | 124 | |
| 125 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
| 125 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
| 126 | 126 | |
| 127 | 127 | try { |
| 128 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
| 128 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
| 129 | 129 | return; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
| 132 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | |
@@ -137,100 +137,100 @@ discard block |
||
| 137 | 137 | $response = null; |
| 138 | 138 | |
| 139 | 139 | // This will throw exception if not valid. |
| 140 | - $this->validate_minimum_order_amount( $order ); |
|
| 140 | + $this->validate_minimum_order_amount($order); |
|
| 141 | 141 | |
| 142 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 142 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 143 | 143 | |
| 144 | 144 | // Prep source object. |
| 145 | 145 | $source_object = new stdClass(); |
| 146 | 146 | $source_object->token_id = ''; |
| 147 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
| 147 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
| 148 | 148 | $source_object->source = $source_id; |
| 149 | 149 | |
| 150 | 150 | // Make the request. |
| 151 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
| 151 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
| 152 | 152 | |
| 153 | - if ( ! empty( $response->error ) ) { |
|
| 153 | + if ( ! empty($response->error)) { |
|
| 154 | 154 | // If it is an API error such connection or server, let's retry. |
| 155 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
| 156 | - if ( $retry ) { |
|
| 157 | - sleep( 5 ); |
|
| 158 | - return $this->process_webhook_payment( $notification, false ); |
|
| 155 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
| 156 | + if ($retry) { |
|
| 157 | + sleep(5); |
|
| 158 | + return $this->process_webhook_payment($notification, false); |
|
| 159 | 159 | } else { |
| 160 | 160 | $localized_message = 'API connection error and retries exhausted.'; |
| 161 | - $order->add_order_note( $localized_message ); |
|
| 162 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 161 | + $order->add_order_note($localized_message); |
|
| 162 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // We want to retry. |
| 167 | - if ( $this->is_idempotency_error( $response->error ) ) { |
|
| 168 | - if ( $retry ) { |
|
| 167 | + if ($this->is_idempotency_error($response->error)) { |
|
| 168 | + if ($retry) { |
|
| 169 | 169 | // Don't do anymore retries after this. |
| 170 | - if ( 5 <= $this->retry_interval ) { |
|
| 170 | + if (5 <= $this->retry_interval) { |
|
| 171 | 171 | |
| 172 | - return $this->process_webhook_payment( $notification, false ); |
|
| 172 | + return $this->process_webhook_payment($notification, false); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - sleep( $this->retry_interval ); |
|
| 175 | + sleep($this->retry_interval); |
|
| 176 | 176 | |
| 177 | 177 | $this->retry_interval++; |
| 178 | - return $this->process_webhook_payment( $notification, true ); |
|
| 178 | + return $this->process_webhook_payment($notification, true); |
|
| 179 | 179 | } else { |
| 180 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
| 181 | - $order->add_order_note( $localized_message ); |
|
| 182 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 180 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
| 181 | + $order->add_order_note($localized_message); |
|
| 182 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 187 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
| 188 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 189 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
| 190 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 187 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
| 188 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 189 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
| 190 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 191 | 191 | } else { |
| 192 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 193 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 192 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
| 193 | + $order->delete_meta_data('_stripe_customer_id'); |
|
| 194 | 194 | $order->save(); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - return $this->process_webhook_payment( $notification, false ); |
|
| 197 | + return $this->process_webhook_payment($notification, false); |
|
| 198 | 198 | |
| 199 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
| 199 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
| 200 | 200 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 201 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
| 201 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
| 202 | 202 | $wc_token->delete(); |
| 203 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 204 | - $order->add_order_note( $message ); |
|
| 205 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
| 203 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 204 | + $order->add_order_note($message); |
|
| 205 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 209 | 209 | |
| 210 | - if ( 'card_error' === $response->error->type ) { |
|
| 211 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 210 | + if ('card_error' === $response->error->type) { |
|
| 211 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 212 | 212 | } else { |
| 213 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 213 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - $order->add_order_note( $localized_message ); |
|
| 216 | + $order->add_order_note($localized_message); |
|
| 217 | 217 | |
| 218 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 218 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
| 221 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
| 222 | 222 | |
| 223 | - $this->process_response( $response, $order ); |
|
| 223 | + $this->process_response($response, $order); |
|
| 224 | 224 | |
| 225 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 226 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 225 | + } catch (WC_Stripe_Exception $e) { |
|
| 226 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 227 | 227 | |
| 228 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order ); |
|
| 228 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order); |
|
| 229 | 229 | |
| 230 | - $statuses = array( 'pending', 'failed' ); |
|
| 230 | + $statuses = array('pending', 'failed'); |
|
| 231 | 231 | |
| 232 | - if ( $order->has_status( $statuses ) ) { |
|
| 233 | - $this->send_failed_order_email( $order_id ); |
|
| 232 | + if ($order->has_status($statuses)) { |
|
| 233 | + $this->send_failed_order_email($order_id); |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | } |
@@ -243,20 +243,20 @@ discard block |
||
| 243 | 243 | * @since 4.0.0 |
| 244 | 244 | * @param object $notification |
| 245 | 245 | */ |
| 246 | - public function process_webhook_dispute( $notification ) { |
|
| 247 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
| 246 | + public function process_webhook_dispute($notification) { |
|
| 247 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
| 248 | 248 | |
| 249 | - if ( ! $order ) { |
|
| 250 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
| 249 | + if ( ! $order) { |
|
| 250 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
| 251 | 251 | return; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - $order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) ); |
|
| 254 | + $order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe')); |
|
| 255 | 255 | |
| 256 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
| 256 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
| 257 | 257 | |
| 258 | 258 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 259 | - $this->send_failed_order_email( $order_id ); |
|
| 259 | + $this->send_failed_order_email($order_id); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -267,41 +267,41 @@ discard block |
||
| 267 | 267 | * @version 4.0.0 |
| 268 | 268 | * @param object $notification |
| 269 | 269 | */ |
| 270 | - public function process_webhook_capture( $notification ) { |
|
| 271 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 270 | + public function process_webhook_capture($notification) { |
|
| 271 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 272 | 272 | |
| 273 | - if ( ! $order ) { |
|
| 274 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 273 | + if ( ! $order) { |
|
| 274 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 279 | 279 | |
| 280 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
| 281 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
| 282 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
| 280 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
| 281 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
| 282 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
| 283 | 283 | |
| 284 | - if ( $charge && 'no' === $captured ) { |
|
| 285 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
| 284 | + if ($charge && 'no' === $captured) { |
|
| 285 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
| 286 | 286 | |
| 287 | 287 | // Store other data such as fees |
| 288 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
| 288 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
| 289 | 289 | |
| 290 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
| 291 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
| 290 | + if (isset($notification->data->object->balance_transaction)) { |
|
| 291 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 294 | + if (is_callable(array($order, 'save'))) { |
|
| 295 | 295 | $order->save(); |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /* translators: transaction id */ |
| 299 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
| 299 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
| 300 | 300 | |
| 301 | 301 | // Check and see if capture is partial. |
| 302 | - if ( $this->is_partial_capture( $notification ) ) { |
|
| 303 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
| 304 | - $order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
| 302 | + if ($this->is_partial_capture($notification)) { |
|
| 303 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
| 304 | + $order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
| 305 | 305 | $order->save(); |
| 306 | 306 | } |
| 307 | 307 | } |
@@ -316,38 +316,38 @@ discard block |
||
| 316 | 316 | * @version 4.0.0 |
| 317 | 317 | * @param object $notification |
| 318 | 318 | */ |
| 319 | - public function process_webhook_charge_succeeded( $notification ) { |
|
| 319 | + public function process_webhook_charge_succeeded($notification) { |
|
| 320 | 320 | // The following payment methods are synchronous so does not need to be handle via webhook. |
| 321 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
| 321 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
| 322 | 322 | return; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 325 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 326 | 326 | |
| 327 | - if ( ! $order ) { |
|
| 328 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 327 | + if ( ! $order) { |
|
| 328 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 329 | 329 | return; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 333 | 333 | |
| 334 | - if ( 'on-hold' !== $order->get_status() ) { |
|
| 334 | + if ('on-hold' !== $order->get_status()) { |
|
| 335 | 335 | return; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | // Store other data such as fees |
| 339 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
| 339 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
| 340 | 340 | |
| 341 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
| 342 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
| 341 | + if (isset($notification->data->object->balance_transaction)) { |
|
| 342 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 345 | + if (is_callable(array($order, 'save'))) { |
|
| 346 | 346 | $order->save(); |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /* translators: transaction id */ |
| 350 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
| 350 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | /** |
@@ -358,23 +358,23 @@ discard block |
||
| 358 | 358 | * @version 4.0.0 |
| 359 | 359 | * @param object $notification |
| 360 | 360 | */ |
| 361 | - public function process_webhook_charge_failed( $notification ) { |
|
| 362 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 361 | + public function process_webhook_charge_failed($notification) { |
|
| 362 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 363 | 363 | |
| 364 | - if ( ! $order ) { |
|
| 365 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 364 | + if ( ! $order) { |
|
| 365 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 366 | 366 | return; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 370 | 370 | |
| 371 | - if ( 'on-hold' !== $order->get_status() ) { |
|
| 371 | + if ('on-hold' !== $order->get_status()) { |
|
| 372 | 372 | return; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
| 375 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
| 376 | 376 | |
| 377 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
| 377 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -385,23 +385,23 @@ discard block |
||
| 385 | 385 | * @version 4.0.0 |
| 386 | 386 | * @param object $notification |
| 387 | 387 | */ |
| 388 | - public function process_webhook_source_canceled( $notification ) { |
|
| 389 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 388 | + public function process_webhook_source_canceled($notification) { |
|
| 389 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 390 | 390 | |
| 391 | - if ( ! $order ) { |
|
| 392 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 391 | + if ( ! $order) { |
|
| 392 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 393 | 393 | return; |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 397 | 397 | |
| 398 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
| 398 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
| 399 | 399 | return; |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
| 402 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
| 403 | 403 | |
| 404 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
| 404 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | /** |
@@ -412,42 +412,42 @@ discard block |
||
| 412 | 412 | * @version 4.0.0 |
| 413 | 413 | * @param object $notification |
| 414 | 414 | */ |
| 415 | - public function process_webhook_refund( $notification ) { |
|
| 416 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 415 | + public function process_webhook_refund($notification) { |
|
| 416 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 417 | 417 | |
| 418 | - if ( ! $order ) { |
|
| 419 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 418 | + if ( ! $order) { |
|
| 419 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 420 | 420 | return; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 424 | 424 | |
| 425 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
| 426 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
| 427 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
| 428 | - $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true ); |
|
| 425 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
| 426 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
| 427 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
| 428 | + $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true); |
|
| 429 | 429 | |
| 430 | 430 | // If the refund ID matches, don't continue to prevent double refunding. |
| 431 | - if ( $notification->data->object->refunds->data[0]->id === $refund_id ) { |
|
| 431 | + if ($notification->data->object->refunds->data[0]->id === $refund_id) { |
|
| 432 | 432 | return; |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | // Only refund captured charge. |
| 436 | - if ( $charge ) { |
|
| 437 | - $reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
| 436 | + if ($charge) { |
|
| 437 | + $reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
| 438 | 438 | |
| 439 | 439 | // Create the refund. |
| 440 | - $refund = wc_create_refund( array( |
|
| 440 | + $refund = wc_create_refund(array( |
|
| 441 | 441 | 'order_id' => $order_id, |
| 442 | - 'amount' => $this->get_refund_amount( $notification ), |
|
| 442 | + 'amount' => $this->get_refund_amount($notification), |
|
| 443 | 443 | 'reason' => $reason, |
| 444 | - ) ); |
|
| 444 | + )); |
|
| 445 | 445 | |
| 446 | - if ( is_wp_error( $refund ) ) { |
|
| 447 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
| 446 | + if (is_wp_error($refund)) { |
|
| 447 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | - $order->add_order_note( $reason ); |
|
| 450 | + $order->add_order_note($reason); |
|
| 451 | 451 | } |
| 452 | 452 | } |
| 453 | 453 | } |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | * @version 4.0.0 |
| 460 | 460 | * @param object $notification |
| 461 | 461 | */ |
| 462 | - public function is_partial_capture( $notification ) { |
|
| 462 | + public function is_partial_capture($notification) { |
|
| 463 | 463 | return 0 < $notification->data->object->amount_refunded; |
| 464 | 464 | } |
| 465 | 465 | |
@@ -470,11 +470,11 @@ discard block |
||
| 470 | 470 | * @version 4.0.0 |
| 471 | 471 | * @param object $notification |
| 472 | 472 | */ |
| 473 | - public function get_refund_amount( $notification ) { |
|
| 474 | - if ( $this->is_partial_capture( $notification ) ) { |
|
| 473 | + public function get_refund_amount($notification) { |
|
| 474 | + if ($this->is_partial_capture($notification)) { |
|
| 475 | 475 | $amount = $notification->data->object->amount_refunded / 100; |
| 476 | 476 | |
| 477 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
| 477 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
| 478 | 478 | $amount = $notification->data->object->amount_refunded; |
| 479 | 479 | } |
| 480 | 480 | |
@@ -491,12 +491,12 @@ discard block |
||
| 491 | 491 | * @version 4.0.0 |
| 492 | 492 | * @param object $notification |
| 493 | 493 | */ |
| 494 | - public function get_partial_amount_to_charge( $notification ) { |
|
| 495 | - if ( $this->is_partial_capture( $notification ) ) { |
|
| 496 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
| 494 | + public function get_partial_amount_to_charge($notification) { |
|
| 495 | + if ($this->is_partial_capture($notification)) { |
|
| 496 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
| 497 | 497 | |
| 498 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
| 499 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
| 498 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
| 499 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | return $amount; |
@@ -512,36 +512,36 @@ discard block |
||
| 512 | 512 | * @version 4.0.0 |
| 513 | 513 | * @param string $request_body |
| 514 | 514 | */ |
| 515 | - public function process_webhook( $request_body ) { |
|
| 516 | - $notification = json_decode( $request_body ); |
|
| 515 | + public function process_webhook($request_body) { |
|
| 516 | + $notification = json_decode($request_body); |
|
| 517 | 517 | |
| 518 | - switch ( $notification->type ) { |
|
| 518 | + switch ($notification->type) { |
|
| 519 | 519 | case 'source.chargeable': |
| 520 | - $this->process_webhook_payment( $notification ); |
|
| 520 | + $this->process_webhook_payment($notification); |
|
| 521 | 521 | break; |
| 522 | 522 | |
| 523 | 523 | case 'source.canceled': |
| 524 | - $this->process_webhook_source_canceled( $notification ); |
|
| 524 | + $this->process_webhook_source_canceled($notification); |
|
| 525 | 525 | break; |
| 526 | 526 | |
| 527 | 527 | case 'charge.succeeded': |
| 528 | - $this->process_webhook_charge_succeeded( $notification ); |
|
| 528 | + $this->process_webhook_charge_succeeded($notification); |
|
| 529 | 529 | break; |
| 530 | 530 | |
| 531 | 531 | case 'charge.failed': |
| 532 | - $this->process_webhook_charge_failed( $notification ); |
|
| 532 | + $this->process_webhook_charge_failed($notification); |
|
| 533 | 533 | break; |
| 534 | 534 | |
| 535 | 535 | case 'charge.captured': |
| 536 | - $this->process_webhook_capture( $notification ); |
|
| 536 | + $this->process_webhook_capture($notification); |
|
| 537 | 537 | break; |
| 538 | 538 | |
| 539 | 539 | case 'charge.dispute.created': |
| 540 | - $this->process_webhook_dispute( $notification ); |
|
| 540 | + $this->process_webhook_dispute($notification); |
|
| 541 | 541 | break; |
| 542 | 542 | |
| 543 | 543 | case 'charge.refunded': |
| 544 | - $this->process_webhook_refund( $notification ); |
|
| 544 | + $this->process_webhook_refund($notification); |
|
| 545 | 545 | break; |
| 546 | 546 | |
| 547 | 547 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -23,12 +23,12 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | $this->retry_interval = 2; |
| 25 | 25 | |
| 26 | - add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) ); |
|
| 27 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
| 28 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
| 29 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
| 30 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
| 31 | - add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) ); |
|
| 26 | + add_action('wp', array($this, 'maybe_process_redirect_order')); |
|
| 27 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
| 28 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
| 29 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
| 30 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
| 31 | + add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout')); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -49,25 +49,25 @@ discard block |
||
| 49 | 49 | * @since 4.0.0 |
| 50 | 50 | * @version 4.0.0 |
| 51 | 51 | */ |
| 52 | - public function process_redirect_payment( $order_id, $retry = true ) { |
|
| 52 | + public function process_redirect_payment($order_id, $retry = true) { |
|
| 53 | 53 | try { |
| 54 | - $source = wc_clean( $_GET['source'] ); |
|
| 54 | + $source = wc_clean($_GET['source']); |
|
| 55 | 55 | |
| 56 | - if ( empty( $source ) ) { |
|
| 56 | + if (empty($source)) { |
|
| 57 | 57 | return; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if ( empty( $order_id ) ) { |
|
| 60 | + if (empty($order_id)) { |
|
| 61 | 61 | return; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $order = wc_get_order( $order_id ); |
|
| 64 | + $order = wc_get_order($order_id); |
|
| 65 | 65 | |
| 66 | - if ( ! is_object( $order ) ) { |
|
| 66 | + if ( ! is_object($order)) { |
|
| 67 | 67 | return; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) { |
|
| 70 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) { |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -75,127 +75,127 @@ discard block |
||
| 75 | 75 | $response = null; |
| 76 | 76 | |
| 77 | 77 | // This will throw exception if not valid. |
| 78 | - $this->validate_minimum_order_amount( $order ); |
|
| 78 | + $this->validate_minimum_order_amount($order); |
|
| 79 | 79 | |
| 80 | - WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 80 | + WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * First check if the source is chargeable at this time. If not, |
| 84 | 84 | * webhook will take care of it later. |
| 85 | 85 | */ |
| 86 | - $source_info = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
| 86 | + $source_info = WC_Stripe_API::retrieve('sources/' . $source); |
|
| 87 | 87 | |
| 88 | - if ( ! empty( $source_info->error ) ) { |
|
| 89 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message ); |
|
| 88 | + if ( ! empty($source_info->error)) { |
|
| 89 | + throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) { |
|
| 93 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) ); |
|
| 92 | + if ('failed' === $source_info->status || 'canceled' === $source_info->status) { |
|
| 93 | + throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe')); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // If already consumed, then ignore request. |
| 97 | - if ( 'consumed' === $source_info->status ) { |
|
| 97 | + if ('consumed' === $source_info->status) { |
|
| 98 | 98 | return; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // If not chargeable, then ignore request. |
| 102 | - if ( 'chargeable' !== $source_info->status ) { |
|
| 102 | + if ('chargeable' !== $source_info->status) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Prep source object. |
| 107 | 107 | $source_object = new stdClass(); |
| 108 | 108 | $source_object->token_id = ''; |
| 109 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
| 109 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
| 110 | 110 | $source_object->source = $source_info->id; |
| 111 | 111 | |
| 112 | 112 | // Make the request. |
| 113 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
| 113 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
| 114 | 114 | |
| 115 | - if ( ! empty( $response->error ) ) { |
|
| 115 | + if ( ! empty($response->error)) { |
|
| 116 | 116 | // If it is an API error such connection or server, let's retry. |
| 117 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
| 118 | - if ( $retry ) { |
|
| 119 | - sleep( 5 ); |
|
| 120 | - return $this->process_redirect_payment( $order_id, false ); |
|
| 117 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
| 118 | + if ($retry) { |
|
| 119 | + sleep(5); |
|
| 120 | + return $this->process_redirect_payment($order_id, false); |
|
| 121 | 121 | } else { |
| 122 | - $localized_message = __( 'API connection error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
| 123 | - $order->add_order_note( $localized_message ); |
|
| 124 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 122 | + $localized_message = __('API connection error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
| 123 | + $order->add_order_note($localized_message); |
|
| 124 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // We want to retry. |
| 129 | - if ( $this->is_idempotency_error( $response->error ) ) { |
|
| 130 | - if ( $retry ) { |
|
| 129 | + if ($this->is_idempotency_error($response->error)) { |
|
| 130 | + if ($retry) { |
|
| 131 | 131 | // Don't do anymore retries after this. |
| 132 | - if ( 5 <= $this->retry_interval ) { |
|
| 133 | - return $this->process_redirect_payment( $order_id, false ); |
|
| 132 | + if (5 <= $this->retry_interval) { |
|
| 133 | + return $this->process_redirect_payment($order_id, false); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - sleep( $this->retry_interval ); |
|
| 136 | + sleep($this->retry_interval); |
|
| 137 | 137 | |
| 138 | 138 | $this->retry_interval++; |
| 139 | - return $this->process_redirect_payment( $order_id, true ); |
|
| 139 | + return $this->process_redirect_payment($order_id, true); |
|
| 140 | 140 | } else { |
| 141 | - $localized_message = __( 'On going requests error and retries exhausted.', 'woocommerce-gateway-stripe' ); |
|
| 142 | - $order->add_order_note( $localized_message ); |
|
| 143 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 141 | + $localized_message = __('On going requests error and retries exhausted.', 'woocommerce-gateway-stripe'); |
|
| 142 | + $order->add_order_note($localized_message); |
|
| 143 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 148 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
| 149 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 150 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
| 151 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 148 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
| 149 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 150 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
| 151 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 152 | 152 | } else { |
| 153 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 154 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
| 153 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
| 154 | + $order->delete_meta_data('_stripe_customer_id'); |
|
| 155 | 155 | $order->save(); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - return $this->process_redirect_payment( $order_id, false ); |
|
| 158 | + return $this->process_redirect_payment($order_id, false); |
|
| 159 | 159 | |
| 160 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
| 160 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
| 161 | 161 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 162 | 162 | |
| 163 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
| 163 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
| 164 | 164 | $wc_token->delete(); |
| 165 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 166 | - $order->add_order_note( $message ); |
|
| 167 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
| 165 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 166 | + $order->add_order_note($message); |
|
| 167 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 171 | 171 | |
| 172 | - if ( 'card_error' === $response->error->type ) { |
|
| 173 | - $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 172 | + if ('card_error' === $response->error->type) { |
|
| 173 | + $message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 174 | 174 | } else { |
| 175 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 175 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
| 178 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
| 181 | + do_action('wc_gateway_stripe_process_redirect_payment', $response, $order); |
|
| 182 | 182 | |
| 183 | - $this->process_response( $response, $order ); |
|
| 183 | + $this->process_response($response, $order); |
|
| 184 | 184 | |
| 185 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 186 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 185 | + } catch (WC_Stripe_Exception $e) { |
|
| 186 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 187 | 187 | |
| 188 | - do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order ); |
|
| 188 | + do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order); |
|
| 189 | 189 | |
| 190 | 190 | /* translators: error message */ |
| 191 | - $order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) ); |
|
| 191 | + $order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage())); |
|
| 192 | 192 | |
| 193 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 194 | - $this->send_failed_order_email( $order_id ); |
|
| 193 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 194 | + $this->send_failed_order_email($order_id); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 198 | - wp_safe_redirect( wc_get_checkout_url() ); |
|
| 197 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 198 | + wp_safe_redirect(wc_get_checkout_url()); |
|
| 199 | 199 | exit; |
| 200 | 200 | } |
| 201 | 201 | } |
@@ -207,13 +207,13 @@ discard block |
||
| 207 | 207 | * @version 4.0.0 |
| 208 | 208 | */ |
| 209 | 209 | public function maybe_process_redirect_order() { |
| 210 | - if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) { |
|
| 210 | + if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) { |
|
| 211 | 211 | return; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - $order_id = wc_clean( $_GET['order_id'] ); |
|
| 214 | + $order_id = wc_clean($_GET['order_id']); |
|
| 215 | 215 | |
| 216 | - $this->process_redirect_payment( $order_id ); |
|
| 216 | + $this->process_redirect_payment($order_id); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -223,52 +223,52 @@ discard block |
||
| 223 | 223 | * @version 4.0.0 |
| 224 | 224 | * @param int $order_id |
| 225 | 225 | */ |
| 226 | - public function capture_payment( $order_id ) { |
|
| 227 | - $order = wc_get_order( $order_id ); |
|
| 226 | + public function capture_payment($order_id) { |
|
| 227 | + $order = wc_get_order($order_id); |
|
| 228 | 228 | |
| 229 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
| 230 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
| 231 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
| 229 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
| 230 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
| 231 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
| 232 | 232 | |
| 233 | - if ( $charge && 'no' === $captured ) { |
|
| 233 | + if ($charge && 'no' === $captured) { |
|
| 234 | 234 | $order_total = $order->get_total(); |
| 235 | 235 | |
| 236 | - if ( 0 < $order->get_total_refunded() ) { |
|
| 236 | + if (0 < $order->get_total_refunded()) { |
|
| 237 | 237 | $order_total = $order_total - $order->get_total_refunded(); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - $result = WC_Stripe_API::request( array( |
|
| 241 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order_total ), |
|
| 240 | + $result = WC_Stripe_API::request(array( |
|
| 241 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order_total), |
|
| 242 | 242 | 'expand[]' => 'balance_transaction', |
| 243 | - ), 'charges/' . $charge . '/capture' ); |
|
| 243 | + ), 'charges/' . $charge . '/capture'); |
|
| 244 | 244 | |
| 245 | - if ( ! empty( $result->error ) ) { |
|
| 245 | + if ( ! empty($result->error)) { |
|
| 246 | 246 | /* translators: error message */ |
| 247 | - $order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
| 247 | + $order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
| 248 | 248 | } else { |
| 249 | 249 | /* translators: transaction id */ |
| 250 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
| 251 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
| 250 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
| 251 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
| 252 | 252 | |
| 253 | 253 | // Store other data such as fees |
| 254 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id ); |
|
| 254 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id); |
|
| 255 | 255 | |
| 256 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
| 256 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
| 257 | 257 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 258 | 258 | // values are in the local currency of the Stripe account, not from WC. |
| 259 | - $fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0; |
|
| 260 | - $net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0; |
|
| 261 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee ); |
|
| 262 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net ); |
|
| 259 | + $fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0; |
|
| 260 | + $net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0; |
|
| 261 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee); |
|
| 262 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 265 | + if (is_callable(array($order, 'save'))) { |
|
| 266 | 266 | $order->save(); |
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // This hook fires when admin manually changes order status to processing or completed. |
| 271 | - do_action( 'woocommerce_stripe_process_manual_capture', $order, $result ); |
|
| 271 | + do_action('woocommerce_stripe_process_manual_capture', $order, $result); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | } |
@@ -280,14 +280,14 @@ discard block |
||
| 280 | 280 | * @version 4.0.0 |
| 281 | 281 | * @param int $order_id |
| 282 | 282 | */ |
| 283 | - public function cancel_payment( $order_id ) { |
|
| 284 | - $order = wc_get_order( $order_id ); |
|
| 283 | + public function cancel_payment($order_id) { |
|
| 284 | + $order = wc_get_order($order_id); |
|
| 285 | 285 | |
| 286 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
| 287 | - $this->process_refund( $order_id ); |
|
| 286 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
| 287 | + $this->process_refund($order_id); |
|
| 288 | 288 | |
| 289 | 289 | // This hook fires when admin manually changes order status to cancel. |
| 290 | - do_action( 'woocommerce_stripe_process_manual_cancel', $order ); |
|
| 290 | + do_action('woocommerce_stripe_process_manual_cancel', $order); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
@@ -299,21 +299,21 @@ discard block |
||
| 299 | 299 | * @param string $field |
| 300 | 300 | * @return string $error_field |
| 301 | 301 | */ |
| 302 | - public function normalize_field( $field ) { |
|
| 302 | + public function normalize_field($field) { |
|
| 303 | 303 | $checkout_fields = WC()->checkout->get_checkout_fields(); |
| 304 | 304 | $org_str = array(); |
| 305 | 305 | $replace_str = array(); |
| 306 | 306 | |
| 307 | - if ( array_key_exists( $field, $checkout_fields['billing'] ) ) { |
|
| 308 | - $error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label']; |
|
| 309 | - } elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) { |
|
| 310 | - $error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label']; |
|
| 311 | - } elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) { |
|
| 312 | - $error_field = $checkout_fields['order'][ $field ]['label']; |
|
| 313 | - } elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) { |
|
| 314 | - $error_field = $checkout_fields['account'][ $field ]['label']; |
|
| 307 | + if (array_key_exists($field, $checkout_fields['billing'])) { |
|
| 308 | + $error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label']; |
|
| 309 | + } elseif (array_key_exists($field, $checkout_fields['shipping'])) { |
|
| 310 | + $error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label']; |
|
| 311 | + } elseif (array_key_exists($field, $checkout_fields['order'])) { |
|
| 312 | + $error_field = $checkout_fields['order'][$field]['label']; |
|
| 313 | + } elseif (array_key_exists($field, $checkout_fields['account'])) { |
|
| 314 | + $error_field = $checkout_fields['account'][$field]['label']; |
|
| 315 | 315 | } else { |
| 316 | - $error_field = str_replace( '_', ' ', $field ); |
|
| 316 | + $error_field = str_replace('_', ' ', $field); |
|
| 317 | 317 | |
| 318 | 318 | $org_str[] = 'stripe'; |
| 319 | 319 | $replace_str[] = ''; |
@@ -328,9 +328,9 @@ discard block |
||
| 328 | 328 | $replace_str[] = 'SOFORT'; |
| 329 | 329 | |
| 330 | 330 | $org_str[] = 'owner'; |
| 331 | - $replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' ); |
|
| 331 | + $replace_str[] = __('Owner', 'woocommerce-gateway-stripe'); |
|
| 332 | 332 | |
| 333 | - $error_field = str_replace( $org_str, $replace_str, $error_field ); |
|
| 333 | + $error_field = str_replace($org_str, $replace_str, $error_field); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | return $error_field; |
@@ -343,138 +343,138 @@ discard block |
||
| 343 | 343 | * @version 4.0.0 |
| 344 | 344 | */ |
| 345 | 345 | public function validate_checkout() { |
| 346 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) { |
|
| 347 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 346 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) { |
|
| 347 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | $errors = new WP_Error(); |
| 351 | - parse_str( $_POST['required_fields'], $required_fields ); |
|
| 352 | - parse_str( $_POST['all_fields'], $all_fields ); |
|
| 353 | - $source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : ''; |
|
| 351 | + parse_str($_POST['required_fields'], $required_fields); |
|
| 352 | + parse_str($_POST['all_fields'], $all_fields); |
|
| 353 | + $source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : ''; |
|
| 354 | 354 | $validate_shipping_fields = false; |
| 355 | 355 | $create_account = false; |
| 356 | 356 | |
| 357 | - $all_fields = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields ); |
|
| 358 | - $required_fields = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields ); |
|
| 357 | + $all_fields = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields); |
|
| 358 | + $required_fields = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields); |
|
| 359 | 359 | |
| 360 | - array_walk_recursive( $required_fields, 'wc_clean' ); |
|
| 361 | - array_walk_recursive( $all_fields, 'wc_clean' ); |
|
| 360 | + array_walk_recursive($required_fields, 'wc_clean'); |
|
| 361 | + array_walk_recursive($all_fields, 'wc_clean'); |
|
| 362 | 362 | |
| 363 | 363 | /** |
| 364 | 364 | * If ship to different address checkbox is checked then we need |
| 365 | 365 | * to validate shipping fields too. |
| 366 | 366 | */ |
| 367 | - if ( isset( $all_fields['ship_to_different_address'] ) ) { |
|
| 367 | + if (isset($all_fields['ship_to_different_address'])) { |
|
| 368 | 368 | $validate_shipping_fields = true; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // Check if createaccount is checked. |
| 372 | - if ( isset( $all_fields['createaccount'] ) ) { |
|
| 372 | + if (isset($all_fields['createaccount'])) { |
|
| 373 | 373 | $create_account = true; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | // Check if required fields are empty. |
| 377 | - foreach ( $required_fields as $field => $field_value ) { |
|
| 377 | + foreach ($required_fields as $field => $field_value) { |
|
| 378 | 378 | // Check for shipping field. |
| 379 | - if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) { |
|
| 379 | + if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) { |
|
| 380 | 380 | continue; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | // Check create account name. |
| 384 | - if ( 'account_username' === $field && ! $create_account ) { |
|
| 384 | + if ('account_username' === $field && ! $create_account) { |
|
| 385 | 385 | continue; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | // Check create account password. |
| 389 | - if ( 'account_password' === $field && ! $create_account ) { |
|
| 389 | + if ('account_password' === $field && ! $create_account) { |
|
| 390 | 390 | continue; |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - if ( empty( $field_value ) || '-1' === $field_value ) { |
|
| 394 | - $error_field = $this->normalize_field( $field ); |
|
| 393 | + if (empty($field_value) || '-1' === $field_value) { |
|
| 394 | + $error_field = $this->normalize_field($field); |
|
| 395 | 395 | /* translators: error field name */ |
| 396 | - $errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) ); |
|
| 396 | + $errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field)); |
|
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | // Check if email is valid format. |
| 401 | - if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) { |
|
| 402 | - $errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) ); |
|
| 401 | + if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) { |
|
| 402 | + $errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe')); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | // Check if phone number is valid format. |
| 406 | - if ( ! empty( $required_fields['billing_phone'] ) ) { |
|
| 407 | - $phone = wc_format_phone_number( $required_fields['billing_phone'] ); |
|
| 406 | + if ( ! empty($required_fields['billing_phone'])) { |
|
| 407 | + $phone = wc_format_phone_number($required_fields['billing_phone']); |
|
| 408 | 408 | |
| 409 | - if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) { |
|
| 409 | + if ('' !== $phone && ! WC_Validation::is_phone($phone)) { |
|
| 410 | 410 | /* translators: %s: phone number */ |
| 411 | - $errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) ); |
|
| 411 | + $errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe')); |
|
| 412 | 412 | } |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | // Check if postal code is valid format. |
| 416 | - if ( ! empty( $required_fields['billing_postcode'] ) ) { |
|
| 417 | - $country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
| 418 | - $postcode = wc_format_postcode( $required_fields['billing_postcode'], $country ); |
|
| 416 | + if ( ! empty($required_fields['billing_postcode'])) { |
|
| 417 | + $country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
| 418 | + $postcode = wc_format_postcode($required_fields['billing_postcode'], $country); |
|
| 419 | 419 | |
| 420 | - if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 421 | - $errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
| 420 | + if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
| 421 | + $errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | // Don't check this on add payment method page. |
| 426 | - if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) { |
|
| 427 | - if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) { |
|
| 428 | - $errors->add( 'terms', __( 'You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe' ) ); |
|
| 426 | + if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) { |
|
| 427 | + if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) { |
|
| 428 | + $errors->add('terms', __('You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe')); |
|
| 429 | 429 | } |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) { |
|
| 432 | + if (WC()->cart->needs_shipping() && $validate_shipping_fields) { |
|
| 433 | 433 | // Check if postal code is valid format. |
| 434 | - if ( ! empty( $required_fields['shipping_postcode'] ) ) { |
|
| 435 | - $country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
| 436 | - $postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country ); |
|
| 434 | + if ( ! empty($required_fields['shipping_postcode'])) { |
|
| 435 | + $country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
| 436 | + $postcode = wc_format_postcode($required_fields['shipping_postcode'], $country); |
|
| 437 | 437 | |
| 438 | - if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 439 | - $errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
| 438 | + if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
| 439 | + $errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
| 440 | 440 | } |
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - if ( WC()->cart->needs_shipping() ) { |
|
| 444 | + if (WC()->cart->needs_shipping()) { |
|
| 445 | 445 | $shipping_country = WC()->customer->get_shipping_country(); |
| 446 | 446 | |
| 447 | - if ( empty( $shipping_country ) ) { |
|
| 448 | - $errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) ); |
|
| 449 | - } elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) { |
|
| 447 | + if (empty($shipping_country)) { |
|
| 448 | + $errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe')); |
|
| 449 | + } elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) { |
|
| 450 | 450 | /* translators: country name */ |
| 451 | - $errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) ); |
|
| 451 | + $errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country())); |
|
| 452 | 452 | } else { |
| 453 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
| 453 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
| 454 | 454 | |
| 455 | - foreach ( WC()->shipping->get_packages() as $i => $package ) { |
|
| 456 | - if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) { |
|
| 457 | - $errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) ); |
|
| 455 | + foreach (WC()->shipping->get_packages() as $i => $package) { |
|
| 456 | + if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) { |
|
| 457 | + $errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe')); |
|
| 458 | 458 | } |
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - if ( WC()->cart->needs_payment() ) { |
|
| 463 | + if (WC()->cart->needs_payment()) { |
|
| 464 | 464 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 465 | 465 | |
| 466 | - if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) { |
|
| 467 | - $errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) ); |
|
| 466 | + if ( ! isset($available_gateways[$all_fields['payment_method']])) { |
|
| 467 | + $errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe')); |
|
| 468 | 468 | } else { |
| 469 | - $available_gateways[ $all_fields['payment_method'] ]->validate_fields(); |
|
| 469 | + $available_gateways[$all_fields['payment_method']]->validate_fields(); |
|
| 470 | 470 | } |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - if ( 0 === count( $errors->errors ) ) { |
|
| 474 | - wp_send_json( 'success' ); |
|
| 473 | + if (0 === count($errors->errors)) { |
|
| 474 | + wp_send_json('success'); |
|
| 475 | 475 | } else { |
| 476 | - foreach ( $errors->get_error_messages() as $message ) { |
|
| 477 | - wc_add_notice( $message, 'error' ); |
|
| 476 | + foreach ($errors->get_error_messages() as $message) { |
|
| 477 | + wc_add_notice($message, 'error'); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | $this->send_ajax_failure_response(); |
@@ -488,9 +488,9 @@ discard block |
||
| 488 | 488 | * @version 4.0.0 |
| 489 | 489 | */ |
| 490 | 490 | public function send_ajax_failure_response() { |
| 491 | - if ( is_ajax() ) { |
|
| 491 | + if (is_ajax()) { |
|
| 492 | 492 | // only print notices if not reloading the checkout, otherwise they're lost in the page reload. |
| 493 | - if ( ! isset( WC()->session->reload_checkout ) ) { |
|
| 493 | + if ( ! isset(WC()->session->reload_checkout)) { |
|
| 494 | 494 | ob_start(); |
| 495 | 495 | wc_print_notices(); |
| 496 | 496 | $messages = ob_get_clean(); |
@@ -498,14 +498,14 @@ discard block |
||
| 498 | 498 | |
| 499 | 499 | $response = array( |
| 500 | 500 | 'result' => 'failure', |
| 501 | - 'messages' => isset( $messages ) ? $messages : '', |
|
| 502 | - 'refresh' => isset( WC()->session->refresh_totals ), |
|
| 503 | - 'reload' => isset( WC()->session->reload_checkout ), |
|
| 501 | + 'messages' => isset($messages) ? $messages : '', |
|
| 502 | + 'refresh' => isset(WC()->session->refresh_totals), |
|
| 503 | + 'reload' => isset(WC()->session->reload_checkout), |
|
| 504 | 504 | ); |
| 505 | 505 | |
| 506 | - unset( WC()->session->refresh_totals, WC()->session->reload_checkout ); |
|
| 506 | + unset(WC()->session->refresh_totals, WC()->session->reload_checkout); |
|
| 507 | 507 | |
| 508 | - wp_send_json( $response ); |
|
| 508 | + wp_send_json($response); |
|
| 509 | 509 | } |
| 510 | 510 | } |
| 511 | 511 | } |