@@ -23,7 +23,6 @@ |
||
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * Set secret API Key. |
| 26 | - * @param string $key |
|
| 27 | 26 | */ |
| 28 | 27 | public static function set_secret_key( $secret_key ) { |
| 29 | 28 | self::$secret_key = $secret_key; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * Set secret API Key. |
| 27 | 27 | * @param string $key |
| 28 | 28 | */ |
| 29 | - public static function set_secret_key( $secret_key ) { |
|
| 29 | + public static function set_secret_key($secret_key) { |
|
| 30 | 30 | self::$secret_key = $secret_key; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | 37 | public static function get_secret_key() { |
| 38 | - if ( ! self::$secret_key ) { |
|
| 39 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 38 | + if ( ! self::$secret_key) { |
|
| 39 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 40 | 40 | |
| 41 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
| 42 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
| 41 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
| 42 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | return self::$secret_key; |
@@ -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,16 +95,16 @@ 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 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
| 104 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
| 103 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
| 104 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
| 105 | 105 | |
| 106 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
| 107 | - $headers['Idempotency-Key'] = uniqid( 'stripe_' ); |
|
| 106 | + if ('charges' === $api && 'POST' === $method) { |
|
| 107 | + $headers['Idempotency-Key'] = uniqid('stripe_'); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | $response = wp_safe_remote_post( |
@@ -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 Exception( __( '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 Exception(__('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 | $ua = self::get_user_agent(); |
| 139 | 139 | |
@@ -146,11 +146,11 @@ discard block |
||
| 146 | 146 | ) |
| 147 | 147 | ); |
| 148 | 148 | |
| 149 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 150 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
| 151 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 149 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 150 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
| 151 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - return json_decode( $response['body'] ); |
|
| 154 | + return json_decode($response['body']); |
|
| 155 | 155 | } |
| 156 | 156 | } |
@@ -32,6 +32,8 @@ |
||
| 32 | 32 | * |
| 33 | 33 | * @since 4.0.0 |
| 34 | 34 | * @version 4.0.0 |
| 35 | + * @param string $slug |
|
| 36 | + * @param string $class |
|
| 35 | 37 | */ |
| 36 | 38 | public function add_admin_notice( $slug, $class, $message ) { |
| 37 | 39 | $this->notices[ $slug ] = array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | * Check if this gateway is enabled |
| 19 | 19 | */ |
| 20 | 20 | public function is_available() { |
| 21 | - if ( 'yes' === $this->enabled ) { |
|
| 22 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
| 21 | + if ('yes' === $this->enabled) { |
|
| 22 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
| 23 | 23 | return false; |
| 24 | 24 | } |
| 25 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
| 25 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
| 26 | 26 | return false; |
| 27 | 27 | } |
| 28 | 28 | return true; |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | * @since 4.0.0 |
| 38 | 38 | * @version 4.0.0 |
| 39 | 39 | */ |
| 40 | - public function add_admin_notice( $slug, $class, $message ) { |
|
| 41 | - $this->notices[ $slug ] = array( |
|
| 40 | + public function add_admin_notice($slug, $class, $message) { |
|
| 41 | + $this->notices[$slug] = array( |
|
| 42 | 42 | 'class' => $class, |
| 43 | 43 | 'message' => $message, |
| 44 | 44 | ); |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * @version 4.0.0 |
| 52 | 52 | */ |
| 53 | 53 | public function remove_admin_notice() { |
| 54 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
| 55 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 54 | + if (did_action('woocommerce_update_options')) { |
|
| 55 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
@@ -64,10 +64,10 @@ discard block |
||
| 64 | 64 | * @version 4.0.0 |
| 65 | 65 | * @param object $order |
| 66 | 66 | */ |
| 67 | - public function validate_minimum_order_amount( $order ) { |
|
| 68 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 67 | + public function validate_minimum_order_amount($order) { |
|
| 68 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 69 | 69 | /* translators: 1) dollar amount */ |
| 70 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 70 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
@@ -77,14 +77,14 @@ discard block |
||
| 77 | 77 | * @since 4.0.0 |
| 78 | 78 | * @version 4.0.0 |
| 79 | 79 | */ |
| 80 | - public function get_transaction_url( $order ) { |
|
| 81 | - if ( $this->testmode ) { |
|
| 80 | + public function get_transaction_url($order) { |
|
| 81 | + if ($this->testmode) { |
|
| 82 | 82 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
| 83 | 83 | } else { |
| 84 | 84 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - return parent::get_transaction_url( $order ); |
|
| 87 | + return parent::get_transaction_url($order); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -93,15 +93,15 @@ discard block |
||
| 93 | 93 | * @since 4.0.0 |
| 94 | 94 | * @version 4.0.0 |
| 95 | 95 | */ |
| 96 | - public function get_stripe_customer_id( $order ) { |
|
| 97 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
| 96 | + public function get_stripe_customer_id($order) { |
|
| 97 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
| 98 | 98 | |
| 99 | - if ( empty( $customer ) ) { |
|
| 99 | + if (empty($customer)) { |
|
| 100 | 100 | // Try to get it via the order. |
| 101 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 102 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
| 101 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 102 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
| 103 | 103 | } else { |
| 104 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
| 104 | + return $order->get_meta('_stripe_customer_id', true); |
|
| 105 | 105 | } |
| 106 | 106 | } else { |
| 107 | 107 | return $customer; |
@@ -118,9 +118,9 @@ discard block |
||
| 118 | 118 | * @param object $order |
| 119 | 119 | * @param int $id Stripe session id. |
| 120 | 120 | */ |
| 121 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
| 122 | - if ( is_object( $order ) ) { |
|
| 123 | - if ( empty( $id ) ) { |
|
| 121 | + public function get_stripe_return_url($order = null, $id = null) { |
|
| 122 | + if (is_object($order)) { |
|
| 123 | + if (empty($id)) { |
|
| 124 | 124 | $id = uniqid(); |
| 125 | 125 | } |
| 126 | 126 | |
@@ -131,10 +131,10 @@ discard block |
||
| 131 | 131 | 'order_id' => $order_id, |
| 132 | 132 | ); |
| 133 | 133 | |
| 134 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
| 134 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
| 137 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -146,48 +146,47 @@ discard block |
||
| 146 | 146 | * @param object $source |
| 147 | 147 | * @return array() |
| 148 | 148 | */ |
| 149 | - public function generate_payment_request( $order, $source ) { |
|
| 150 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 151 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
| 152 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
| 149 | + public function generate_payment_request($order, $source) { |
|
| 150 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
| 151 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
| 152 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
| 153 | 153 | $post_data = array(); |
| 154 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
| 155 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 154 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
| 155 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 156 | 156 | /* translators: 1) blog name 2) order number */ |
| 157 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
| 157 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
| 158 | 158 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
| 159 | 159 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 160 | 160 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
| 161 | 161 | |
| 162 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 162 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 163 | 163 | $post_data['receipt_email'] = $billing_email; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
| 167 | - case 'stripe': |
|
| 168 | - if ( ! empty( $statement_descriptor ) ) { |
|
| 169 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
| 166 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
| 167 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
| 168 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
| 170 | 169 | } |
| 171 | 170 | |
| 172 | - $post_data['capture'] = $capture ? 'true' : 'false'; |
|
| 171 | + $post_data['capture'] = $capture ? 'true' : 'false'; |
|
| 173 | 172 | break; |
| 174 | 173 | } |
| 175 | 174 | |
| 176 | 175 | $post_data['expand[]'] = 'balance_transaction'; |
| 177 | 176 | |
| 178 | 177 | $metadata = array( |
| 179 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
| 180 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
| 178 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
| 179 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
| 181 | 180 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
| 182 | 181 | ); |
| 183 | 182 | |
| 184 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
| 183 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
| 185 | 184 | |
| 186 | - if ( $source->customer ) { |
|
| 185 | + if ($source->customer) { |
|
| 187 | 186 | $post_data['customer'] = $source->customer; |
| 188 | 187 | } |
| 189 | 188 | |
| 190 | - if ( $source->source ) { |
|
| 189 | + if ($source->source) { |
|
| 191 | 190 | $post_data['source'] = $source->source; |
| 192 | 191 | } |
| 193 | 192 | |
@@ -199,77 +198,77 @@ discard block |
||
| 199 | 198 | * @param WC_Order $order |
| 200 | 199 | * @param object $source |
| 201 | 200 | */ |
| 202 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
| 201 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
| 203 | 202 | } |
| 204 | 203 | |
| 205 | 204 | /** |
| 206 | 205 | * Store extra meta data for an order from a Stripe Response. |
| 207 | 206 | */ |
| 208 | - public function process_response( $response, $order ) { |
|
| 209 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
| 207 | + public function process_response($response, $order) { |
|
| 208 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
| 210 | 209 | |
| 211 | 210 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 212 | 211 | |
| 213 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
| 212 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
| 214 | 213 | |
| 215 | 214 | // Store charge data |
| 216 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
| 215 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
| 217 | 216 | |
| 218 | 217 | // Store other data such as fees |
| 219 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
| 218 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
| 220 | 219 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 221 | 220 | // values are in the local currency of the Stripe account, not from WC. |
| 222 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
| 223 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
| 224 | - 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 ); |
|
| 225 | - 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 ); |
|
| 221 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
| 222 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
| 223 | + 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); |
|
| 224 | + 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); |
|
| 226 | 225 | } |
| 227 | 226 | |
| 228 | - if ( 'yes' === $captured ) { |
|
| 227 | + if ('yes' === $captured) { |
|
| 229 | 228 | /** |
| 230 | 229 | * Charge can be captured but in a pending state. Payment methods |
| 231 | 230 | * that are asynchronous may take couple days to clear. Webhook will |
| 232 | 231 | * take care of the status changes. |
| 233 | 232 | */ |
| 234 | - if ( 'pending' === $response->status ) { |
|
| 235 | - if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) { |
|
| 236 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
| 233 | + if ('pending' === $response->status) { |
|
| 234 | + if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) { |
|
| 235 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
| 237 | 236 | } |
| 238 | 237 | |
| 239 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id ); |
|
| 238 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id); |
|
| 240 | 239 | /* translators: transaction id */ |
| 241 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
| 240 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
| 242 | 241 | } |
| 243 | 242 | |
| 244 | - if ( 'succeeded' === $response->status ) { |
|
| 245 | - $order->payment_complete( $response->id ); |
|
| 243 | + if ('succeeded' === $response->status) { |
|
| 244 | + $order->payment_complete($response->id); |
|
| 246 | 245 | |
| 247 | 246 | /* translators: transaction id */ |
| 248 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
| 249 | - $order->add_order_note( $message ); |
|
| 247 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
| 248 | + $order->add_order_note($message); |
|
| 250 | 249 | } |
| 251 | 250 | |
| 252 | - if ( 'failed' === $response->status ) { |
|
| 253 | - $error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 254 | - $order->add_order_note( $error_msg ); |
|
| 255 | - throw new Exception( $error_msg ); |
|
| 251 | + if ('failed' === $response->status) { |
|
| 252 | + $error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 253 | + $order->add_order_note($error_msg); |
|
| 254 | + throw new Exception($error_msg); |
|
| 256 | 255 | } |
| 257 | 256 | } else { |
| 258 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id, true ) : $order->set_transaction_id( $response->id ); |
|
| 257 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id, true) : $order->set_transaction_id($response->id); |
|
| 259 | 258 | |
| 260 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 261 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
| 259 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 260 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
| 262 | 261 | } |
| 263 | 262 | |
| 264 | 263 | /* translators: transaction id */ |
| 265 | - $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 ) ); |
|
| 264 | + $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)); |
|
| 266 | 265 | } |
| 267 | 266 | |
| 268 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 267 | + if (is_callable(array($order, 'save'))) { |
|
| 269 | 268 | $order->save(); |
| 270 | 269 | } |
| 271 | 270 | |
| 272 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
| 271 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
| 273 | 272 | |
| 274 | 273 | return $response; |
| 275 | 274 | } |
@@ -282,10 +281,10 @@ discard block |
||
| 282 | 281 | * @param int $order_id |
| 283 | 282 | * @return null |
| 284 | 283 | */ |
| 285 | - public function send_failed_order_email( $order_id ) { |
|
| 284 | + public function send_failed_order_email($order_id) { |
|
| 286 | 285 | $emails = WC()->mailer()->get_emails(); |
| 287 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
| 288 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
| 286 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
| 287 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
| 289 | 288 | } |
| 290 | 289 | } |
| 291 | 290 | |
@@ -297,7 +296,7 @@ discard block |
||
| 297 | 296 | * @param object $order |
| 298 | 297 | * @return object $details |
| 299 | 298 | */ |
| 300 | - public function get_owner_details( $order ) { |
|
| 299 | + public function get_owner_details($order) { |
|
| 301 | 300 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 302 | 301 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
| 303 | 302 | |
@@ -308,8 +307,8 @@ discard block |
||
| 308 | 307 | |
| 309 | 308 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
| 310 | 309 | |
| 311 | - if ( ! empty( $phone ) ) { |
|
| 312 | - $details['phone'] = $phone; |
|
| 310 | + if ( ! empty($phone)) { |
|
| 311 | + $details['phone'] = $phone; |
|
| 313 | 312 | } |
| 314 | 313 | |
| 315 | 314 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -319,7 +318,7 @@ discard block |
||
| 319 | 318 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
| 320 | 319 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
| 321 | 320 | |
| 322 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
| 321 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
| 323 | 322 | } |
| 324 | 323 | |
| 325 | 324 | /** |
@@ -335,58 +334,58 @@ discard block |
||
| 335 | 334 | * @throws Exception When card was not added or for and invalid card. |
| 336 | 335 | * @return object |
| 337 | 336 | */ |
| 338 | - public function prepare_source( $user_id, $force_save_source = false ) { |
|
| 339 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
| 337 | + public function prepare_source($user_id, $force_save_source = false) { |
|
| 338 | + $customer = new WC_Stripe_Customer($user_id); |
|
| 340 | 339 | $set_customer = true; |
| 341 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
| 340 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
| 342 | 341 | $source = ''; |
| 343 | 342 | $wc_token_id = false; |
| 344 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
| 343 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
| 345 | 344 | |
| 346 | 345 | // New CC info was entered and we have a new source to process. |
| 347 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
| 346 | + if ( ! empty($_POST['stripe_source'])) { |
|
| 348 | 347 | // This gets the source object from Stripe. |
| 349 | - $source = json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ); |
|
| 348 | + $source = json_decode(wc_clean(stripslashes($_POST['stripe_source']))); |
|
| 350 | 349 | |
| 351 | 350 | // This checks to see if customer opted to save the payment method to file. |
| 352 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
| 351 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
| 353 | 352 | |
| 354 | 353 | /** |
| 355 | 354 | * This is true if the user wants to store the card to their account. |
| 356 | 355 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
| 357 | 356 | * actually reusable. Either that or force_save_source is true. |
| 358 | 357 | */ |
| 359 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage ) || $force_save_source ) { |
|
| 360 | - $source = $customer->add_source( $source->id ); |
|
| 358 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source->usage) || $force_save_source) { |
|
| 359 | + $source = $customer->add_source($source->id); |
|
| 361 | 360 | |
| 362 | - if ( ! empty( $source->error ) ) { |
|
| 363 | - throw new Exception( $source->error->message ); |
|
| 361 | + if ( ! empty($source->error)) { |
|
| 362 | + throw new Exception($source->error->message); |
|
| 364 | 363 | } |
| 365 | 364 | } else { |
| 366 | 365 | $source = $source->id; |
| 367 | 366 | } |
| 368 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
| 367 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
| 369 | 368 | // Use an existing token, and then process the payment |
| 370 | 369 | |
| 371 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
| 372 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
| 370 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
| 371 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
| 373 | 372 | |
| 374 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
| 375 | - WC()->session->set( 'refresh_totals', true ); |
|
| 376 | - throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
| 373 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
| 374 | + WC()->session->set('refresh_totals', true); |
|
| 375 | + throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
| 377 | 376 | } |
| 378 | 377 | |
| 379 | 378 | $source = $wc_token->get_token(); |
| 380 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
| 381 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
| 382 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
| 379 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
| 380 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
| 381 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
| 383 | 382 | |
| 384 | 383 | // This is true if the user wants to store the card to their account. |
| 385 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
| 386 | - $source = $customer->add_source( $stripe_token ); |
|
| 384 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
| 385 | + $source = $customer->add_source($stripe_token); |
|
| 387 | 386 | |
| 388 | - if ( ! empty( $source->error ) ) { |
|
| 389 | - throw new Exception( $source->error->message ); |
|
| 387 | + if ( ! empty($source->error)) { |
|
| 388 | + throw new Exception($source->error->message); |
|
| 390 | 389 | } |
| 391 | 390 | } else { |
| 392 | 391 | $set_customer = false; |
@@ -394,7 +393,7 @@ discard block |
||
| 394 | 393 | } |
| 395 | 394 | } |
| 396 | 395 | |
| 397 | - if ( ! $set_customer ) { |
|
| 396 | + if ( ! $set_customer) { |
|
| 398 | 397 | $customer_id = false; |
| 399 | 398 | } else { |
| 400 | 399 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
@@ -415,27 +414,27 @@ discard block |
||
| 415 | 414 | * @param WC_Order $order For to which the source applies. |
| 416 | 415 | * @param stdClass $source Source information. |
| 417 | 416 | */ |
| 418 | - public function save_source( $order, $source ) { |
|
| 417 | + public function save_source($order, $source) { |
|
| 419 | 418 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 420 | 419 | |
| 421 | 420 | // Store source in the order. |
| 422 | - if ( $source->customer ) { |
|
| 423 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 424 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
| 421 | + if ($source->customer) { |
|
| 422 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 423 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
| 425 | 424 | } else { |
| 426 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
| 425 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
| 427 | 426 | } |
| 428 | 427 | } |
| 429 | 428 | |
| 430 | - if ( $source->source ) { |
|
| 431 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 432 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
| 429 | + if ($source->source) { |
|
| 430 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 431 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
| 433 | 432 | } else { |
| 434 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
| 433 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
| 435 | 434 | } |
| 436 | 435 | } |
| 437 | 436 | |
| 438 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 437 | + if (is_callable(array($order, 'save'))) { |
|
| 439 | 438 | $order->save(); |
| 440 | 439 | } |
| 441 | 440 | } |
@@ -453,35 +452,35 @@ discard block |
||
| 453 | 452 | * @param object $order |
| 454 | 453 | * @return object |
| 455 | 454 | */ |
| 456 | - public function prepare_order_source( $order = null ) { |
|
| 455 | + public function prepare_order_source($order = null) { |
|
| 457 | 456 | $stripe_customer = new WC_Stripe_Customer(); |
| 458 | 457 | $stripe_source = false; |
| 459 | 458 | $token_id = false; |
| 460 | 459 | |
| 461 | - if ( $order ) { |
|
| 460 | + if ($order) { |
|
| 462 | 461 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 463 | 462 | |
| 464 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
| 463 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
| 465 | 464 | |
| 466 | - if ( $stripe_customer_id ) { |
|
| 467 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 465 | + if ($stripe_customer_id) { |
|
| 466 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 468 | 467 | } |
| 469 | 468 | |
| 470 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
| 469 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
| 471 | 470 | |
| 472 | 471 | // Since 4.0.0, we changed card to source so we need to account for that. |
| 473 | - if ( empty( $source_id ) ) { |
|
| 474 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
| 472 | + if (empty($source_id)) { |
|
| 473 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
| 475 | 474 | |
| 476 | 475 | // Take this opportunity to update the key name. |
| 477 | - 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 ); |
|
| 476 | + 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); |
|
| 478 | 477 | |
| 479 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 478 | + if (is_callable(array($order, 'save'))) { |
|
| 480 | 479 | $order->save(); |
| 481 | 480 | } |
| 482 | 481 | } |
| 483 | 482 | |
| 484 | - if ( $source_id ) { |
|
| 483 | + if ($source_id) { |
|
| 485 | 484 | $stripe_source = $source_id; |
| 486 | 485 | } |
| 487 | 486 | } |
@@ -502,27 +501,27 @@ discard block |
||
| 502 | 501 | * @param object $order The order object |
| 503 | 502 | * @param int $balance_transaction_id |
| 504 | 503 | */ |
| 505 | - public function update_fees( $order, $balance_transaction_id ) { |
|
| 504 | + public function update_fees($order, $balance_transaction_id) { |
|
| 506 | 505 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 507 | 506 | |
| 508 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
| 507 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
| 509 | 508 | |
| 510 | - if ( empty( $balance_transaction->error ) ) { |
|
| 511 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
| 509 | + if (empty($balance_transaction->error)) { |
|
| 510 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
| 512 | 511 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 513 | 512 | // values are in the local currency of the Stripe account, not from WC. |
| 514 | - $fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
| 515 | - $net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
| 513 | + $fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
| 514 | + $net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
| 516 | 515 | |
| 517 | - 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 ); |
|
| 518 | - 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 ); |
|
| 516 | + 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); |
|
| 517 | + 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); |
|
| 519 | 518 | |
| 520 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 519 | + if (is_callable(array($order, 'save'))) { |
|
| 521 | 520 | $order->save(); |
| 522 | 521 | } |
| 523 | 522 | } |
| 524 | 523 | } else { |
| 525 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
| 524 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
| 526 | 525 | } |
| 527 | 526 | } |
| 528 | 527 | |
@@ -535,53 +534,53 @@ discard block |
||
| 535 | 534 | * @param float $amount |
| 536 | 535 | * @return bool |
| 537 | 536 | */ |
| 538 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 539 | - $order = wc_get_order( $order_id ); |
|
| 537 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
| 538 | + $order = wc_get_order($order_id); |
|
| 540 | 539 | |
| 541 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 540 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
| 542 | 541 | return false; |
| 543 | 542 | } |
| 544 | 543 | |
| 545 | 544 | $body = array(); |
| 546 | 545 | |
| 547 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 548 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
| 546 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 547 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
| 549 | 548 | } else { |
| 550 | 549 | $order_currency = $order->get_currency(); |
| 551 | 550 | } |
| 552 | 551 | |
| 553 | - if ( ! is_null( $amount ) ) { |
|
| 554 | - $body['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
| 552 | + if ( ! is_null($amount)) { |
|
| 553 | + $body['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
| 555 | 554 | } |
| 556 | 555 | |
| 557 | - if ( $reason ) { |
|
| 556 | + if ($reason) { |
|
| 558 | 557 | $body['metadata'] = array( |
| 559 | 558 | 'reason' => $reason, |
| 560 | 559 | ); |
| 561 | 560 | } |
| 562 | 561 | |
| 563 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
| 562 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
| 564 | 563 | |
| 565 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
| 564 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
| 566 | 565 | |
| 567 | - if ( ! empty( $response->error ) ) { |
|
| 568 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
| 566 | + if ( ! empty($response->error)) { |
|
| 567 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
| 569 | 568 | return $response; |
| 570 | - } elseif ( ! empty( $response->id ) ) { |
|
| 571 | - $amount = wc_price( $response->amount / 100 ); |
|
| 569 | + } elseif ( ! empty($response->id)) { |
|
| 570 | + $amount = wc_price($response->amount / 100); |
|
| 572 | 571 | |
| 573 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
| 574 | - $amount = wc_price( $response->amount ); |
|
| 572 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
| 573 | + $amount = wc_price($response->amount); |
|
| 575 | 574 | } |
| 576 | 575 | |
| 577 | - if ( isset( $response->balance_transaction ) ) { |
|
| 578 | - $this->update_fees( $order, $response->balance_transaction ); |
|
| 576 | + if (isset($response->balance_transaction)) { |
|
| 577 | + $this->update_fees($order, $response->balance_transaction); |
|
| 579 | 578 | } |
| 580 | 579 | |
| 581 | 580 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
| 582 | - $refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ); |
|
| 583 | - $order->add_order_note( $refund_message ); |
|
| 584 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 581 | + $refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason); |
|
| 582 | + $order->add_order_note($refund_message); |
|
| 583 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
| 585 | 584 | |
| 586 | 585 | return true; |
| 587 | 586 | } |
@@ -596,41 +595,41 @@ discard block |
||
| 596 | 595 | */ |
| 597 | 596 | public function add_payment_method() { |
| 598 | 597 | $error = false; |
| 599 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
| 598 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
| 600 | 599 | $source_id = ''; |
| 601 | 600 | |
| 602 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
| 601 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
| 603 | 602 | $error = true; |
| 604 | 603 | } |
| 605 | 604 | |
| 606 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 605 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 607 | 606 | |
| 608 | - if ( isset( $_POST['stripe_source'] ) ) { |
|
| 609 | - $source = json_decode( wc_clean( stripslashes( $_POST['stripe_source'] ) ) ); |
|
| 607 | + if (isset($_POST['stripe_source'])) { |
|
| 608 | + $source = json_decode(wc_clean(stripslashes($_POST['stripe_source']))); |
|
| 610 | 609 | |
| 611 | - if ( ! empty( $source->error ) ) { |
|
| 610 | + if ( ! empty($source->error)) { |
|
| 612 | 611 | $error = true; |
| 613 | 612 | } |
| 614 | 613 | |
| 615 | 614 | $source_id = $source->id; |
| 616 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
| 617 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
| 615 | + } elseif (isset($_POST['stripe_token'])) { |
|
| 616 | + $source_id = wc_clean($_POST['stripe_token']); |
|
| 618 | 617 | } |
| 619 | 618 | |
| 620 | - $response = $stripe_customer->add_source( $source_id ); |
|
| 619 | + $response = $stripe_customer->add_source($source_id); |
|
| 621 | 620 | |
| 622 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
| 621 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
| 623 | 622 | $error = true; |
| 624 | 623 | } |
| 625 | 624 | |
| 626 | - if ( $error ) { |
|
| 627 | - wc_add_notice( $error_msg, 'error' ); |
|
| 625 | + if ($error) { |
|
| 626 | + wc_add_notice($error_msg, 'error'); |
|
| 628 | 627 | return; |
| 629 | 628 | } |
| 630 | 629 | |
| 631 | 630 | return array( |
| 632 | 631 | 'result' => 'success', |
| 633 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
| 632 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
| 634 | 633 | ); |
| 635 | 634 | } |
| 636 | 635 | } |
@@ -233,7 +233,6 @@ |
||
| 233 | 233 | /** |
| 234 | 234 | * Get a customers saved sources using their Stripe ID. Cached. |
| 235 | 235 | * |
| 236 | - * @param string $customer_id |
|
| 237 | 236 | * @return array |
| 238 | 237 | */ |
| 239 | 238 | public function get_sources() { |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | * Constructor |
| 33 | 33 | * @param int $user_id The WP user ID |
| 34 | 34 | */ |
| 35 | - public function __construct( $user_id = 0 ) { |
|
| 36 | - if ( $user_id ) { |
|
| 37 | - $this->set_user_id( $user_id ); |
|
| 38 | - $this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
| 35 | + public function __construct($user_id = 0) { |
|
| 36 | + if ($user_id) { |
|
| 37 | + $this->set_user_id($user_id); |
|
| 38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * Set Stripe customer ID. |
| 52 | 52 | * @param [type] $id [description] |
| 53 | 53 | */ |
| 54 | - public function set_id( $id ) { |
|
| 55 | - $this->id = wc_clean( $id ); |
|
| 54 | + public function set_id($id) { |
|
| 55 | + $this->id = wc_clean($id); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,15 +60,15 @@ discard block |
||
| 60 | 60 | * @return int |
| 61 | 61 | */ |
| 62 | 62 | public function get_user_id() { |
| 63 | - return absint( $this->user_id ); |
|
| 63 | + return absint($this->user_id); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Set User ID used by WordPress. |
| 68 | 68 | * @param int $user_id |
| 69 | 69 | */ |
| 70 | - public function set_user_id( $user_id ) { |
|
| 71 | - $this->user_id = absint( $user_id ); |
|
| 70 | + public function set_user_id($user_id) { |
|
| 71 | + $this->user_id = absint($user_id); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
| 76 | 76 | * @return WP_User |
| 77 | 77 | */ |
| 78 | 78 | protected function get_user() { |
| 79 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
| 79 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * Store data from the Stripe API about this customer |
| 84 | 84 | */ |
| 85 | - public function set_customer_data( $data ) { |
|
| 85 | + public function set_customer_data($data) { |
|
| 86 | 86 | $this->customer_data = $data; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | * Get data from the Stripe API about this customer |
| 91 | 91 | */ |
| 92 | 92 | public function get_customer_data() { |
| 93 | - $this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() ); |
|
| 93 | + $this->customer_data = get_transient('stripe_customer_' . $this->get_id()); |
|
| 94 | 94 | |
| 95 | - if ( empty( $this->customer_data ) && $this->get_id() && false === $this->customer_data ) { |
|
| 96 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() ); |
|
| 95 | + if (empty($this->customer_data) && $this->get_id() && false === $this->customer_data) { |
|
| 96 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id()); |
|
| 97 | 97 | |
| 98 | - if ( empty( $response->error ) ) { |
|
| 99 | - $this->set_customer_data( $response ); |
|
| 100 | - set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 ); |
|
| 98 | + if (empty($response->error)) { |
|
| 99 | + $this->set_customer_data($response); |
|
| 100 | + set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | $data = $this->get_customer_data(); |
| 113 | 113 | $source = ''; |
| 114 | 114 | |
| 115 | - if ( $data ) { |
|
| 115 | + if ($data) { |
|
| 116 | 116 | $source = $data->default_source; |
| 117 | 117 | } |
| 118 | 118 | |
@@ -124,13 +124,13 @@ discard block |
||
| 124 | 124 | * @param array $args |
| 125 | 125 | * @return WP_Error|int |
| 126 | 126 | */ |
| 127 | - public function create_customer( $args = array() ) { |
|
| 128 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
| 127 | + public function create_customer($args = array()) { |
|
| 128 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
| 129 | 129 | $user = $this->get_user(); |
| 130 | 130 | |
| 131 | - if ( $user ) { |
|
| 132 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
| 133 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
| 131 | + if ($user) { |
|
| 132 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
| 133 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
| 134 | 134 | |
| 135 | 135 | $defaults = array( |
| 136 | 136 | 'email' => $user->user_email, |
@@ -145,24 +145,24 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | $metadata = array(); |
| 147 | 147 | |
| 148 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
| 148 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
| 149 | 149 | |
| 150 | - $args = wp_parse_args( $args, $defaults ); |
|
| 151 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
| 150 | + $args = wp_parse_args($args, $defaults); |
|
| 151 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
| 152 | 152 | |
| 153 | - if ( ! empty( $response->error ) ) { |
|
| 154 | - throw new Exception( $response->error->message ); |
|
| 153 | + if ( ! empty($response->error)) { |
|
| 154 | + throw new Exception($response->error->message); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - $this->set_id( $response->id ); |
|
| 157 | + $this->set_id($response->id); |
|
| 158 | 158 | $this->clear_cache(); |
| 159 | - $this->set_customer_data( $response ); |
|
| 159 | + $this->set_customer_data($response); |
|
| 160 | 160 | |
| 161 | - if ( $this->get_user_id() ) { |
|
| 162 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
| 161 | + if ($this->get_user_id()) { |
|
| 162 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
| 165 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
| 166 | 166 | |
| 167 | 167 | return $response->id; |
| 168 | 168 | } |
@@ -173,72 +173,72 @@ discard block |
||
| 173 | 173 | * @param bool $retry |
| 174 | 174 | * @return WP_Error|int |
| 175 | 175 | */ |
| 176 | - public function add_source( $source_id, $retry = true ) { |
|
| 177 | - if ( ! $this->get_id() ) { |
|
| 176 | + public function add_source($source_id, $retry = true) { |
|
| 177 | + if ( ! $this->get_id()) { |
|
| 178 | 178 | $this->create_customer(); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - $response = WC_Stripe_API::request( array( |
|
| 181 | + $response = WC_Stripe_API::request(array( |
|
| 182 | 182 | 'source' => $source_id, |
| 183 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
| 183 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
| 184 | 184 | |
| 185 | - if ( ! empty( $response->error ) ) { |
|
| 185 | + if ( ! empty($response->error)) { |
|
| 186 | 186 | // It is possible the WC user once was linked to a customer on Stripe |
| 187 | 187 | // but no longer exists. Instead of failing, lets try to create a |
| 188 | 188 | // new customer. |
| 189 | - if ( preg_match( '/No such customer/i', $response->error->message ) ) { |
|
| 190 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
| 189 | + if (preg_match('/No such customer/i', $response->error->message)) { |
|
| 190 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
| 191 | 191 | $this->create_customer(); |
| 192 | - return $this->add_source( $source_id, false ); |
|
| 192 | + return $this->add_source($source_id, false); |
|
| 193 | 193 | } else { |
| 194 | 194 | return $response; |
| 195 | 195 | } |
| 196 | - } elseif ( empty( $response->id ) ) { |
|
| 197 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
| 196 | + } elseif (empty($response->id)) { |
|
| 197 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Add token to WooCommerce. |
| 201 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 202 | - if ( ! empty( $response->type ) ) { |
|
| 203 | - switch ( $response->type ) { |
|
| 201 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
| 202 | + if ( ! empty($response->type)) { |
|
| 203 | + switch ($response->type) { |
|
| 204 | 204 | case 'alipay': |
| 205 | 205 | break; |
| 206 | 206 | case 'sepa_debit': |
| 207 | 207 | $wc_token = new WC_Payment_Token_SEPA(); |
| 208 | - $wc_token->set_token( $response->id ); |
|
| 209 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
| 210 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
| 208 | + $wc_token->set_token($response->id); |
|
| 209 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
| 210 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
| 211 | 211 | break; |
| 212 | 212 | default: |
| 213 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
| 213 | + if ('source' === $response->object && 'card' === $response->type) { |
|
| 214 | 214 | $wc_token = new WC_Payment_Token_CC(); |
| 215 | - $wc_token->set_token( $response->id ); |
|
| 216 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 217 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
| 218 | - $wc_token->set_last4( $response->card->last4 ); |
|
| 219 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
| 220 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
| 215 | + $wc_token->set_token($response->id); |
|
| 216 | + $wc_token->set_gateway_id('stripe'); |
|
| 217 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
| 218 | + $wc_token->set_last4($response->card->last4); |
|
| 219 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
| 220 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
| 221 | 221 | } |
| 222 | 222 | break; |
| 223 | 223 | } |
| 224 | 224 | } else { |
| 225 | 225 | // Legacy. |
| 226 | 226 | $wc_token = new WC_Payment_Token_CC(); |
| 227 | - $wc_token->set_token( $response->id ); |
|
| 228 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 229 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
| 230 | - $wc_token->set_last4( $response->last4 ); |
|
| 231 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
| 232 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
| 227 | + $wc_token->set_token($response->id); |
|
| 228 | + $wc_token->set_gateway_id('stripe'); |
|
| 229 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
| 230 | + $wc_token->set_last4($response->last4); |
|
| 231 | + $wc_token->set_expiry_month($response->exp_month); |
|
| 232 | + $wc_token->set_expiry_year($response->exp_year); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
| 235 | + $wc_token->set_user_id($this->get_user_id()); |
|
| 236 | 236 | $wc_token->save(); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | $this->clear_cache(); |
| 240 | 240 | |
| 241 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
| 241 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
| 242 | 242 | |
| 243 | 243 | return $response->id; |
| 244 | 244 | } |
@@ -250,38 +250,38 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | 252 | public function get_sources() { |
| 253 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 253 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
| 254 | 254 | |
| 255 | - if ( false === $sources ) { |
|
| 256 | - $response = WC_Stripe_API::request( array( |
|
| 255 | + if (false === $sources) { |
|
| 256 | + $response = WC_Stripe_API::request(array( |
|
| 257 | 257 | 'limit' => 100, |
| 258 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
| 258 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
| 259 | 259 | |
| 260 | - if ( ! empty( $response->error ) ) { |
|
| 260 | + if ( ! empty($response->error)) { |
|
| 261 | 261 | return array(); |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - if ( is_array( $response->data ) ) { |
|
| 264 | + if (is_array($response->data)) { |
|
| 265 | 265 | $sources = $response->data; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - set_transient( 'stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24 ); |
|
| 268 | + set_transient('stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 24); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - return empty( $sources ) ? array() : $sources; |
|
| 271 | + return empty($sources) ? array() : $sources; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
| 275 | 275 | * Delete a source from stripe. |
| 276 | 276 | * @param string $source_id |
| 277 | 277 | */ |
| 278 | - public function delete_source( $source_id ) { |
|
| 279 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
| 278 | + public function delete_source($source_id) { |
|
| 279 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
| 280 | 280 | |
| 281 | 281 | $this->clear_cache(); |
| 282 | 282 | |
| 283 | - if ( empty( $response->error ) ) { |
|
| 284 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
| 283 | + if (empty($response->error)) { |
|
| 284 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
| 285 | 285 | |
| 286 | 286 | return true; |
| 287 | 287 | } |
@@ -293,15 +293,15 @@ discard block |
||
| 293 | 293 | * Set default source in Stripe |
| 294 | 294 | * @param string $source_id |
| 295 | 295 | */ |
| 296 | - public function set_default_source( $source_id ) { |
|
| 297 | - $response = WC_Stripe_API::request( array( |
|
| 298 | - 'default_source' => sanitize_text_field( $source_id ), |
|
| 299 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
| 296 | + public function set_default_source($source_id) { |
|
| 297 | + $response = WC_Stripe_API::request(array( |
|
| 298 | + 'default_source' => sanitize_text_field($source_id), |
|
| 299 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
| 300 | 300 | |
| 301 | 301 | $this->clear_cache(); |
| 302 | 302 | |
| 303 | - if ( empty( $response->error ) ) { |
|
| 304 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
| 303 | + if (empty($response->error)) { |
|
| 304 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
| 305 | 305 | |
| 306 | 306 | return true; |
| 307 | 307 | } |
@@ -313,8 +313,8 @@ discard block |
||
| 313 | 313 | * Deletes caches for this users cards. |
| 314 | 314 | */ |
| 315 | 315 | public function clear_cache() { |
| 316 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 317 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
| 316 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
| 317 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
| 318 | 318 | $this->customer_data = array(); |
| 319 | 319 | } |
| 320 | 320 | } |
@@ -134,7 +134,6 @@ discard block |
||
| 134 | 134 | * process_subscription_payment function. |
| 135 | 135 | * @param mixed $order |
| 136 | 136 | * @param int $amount (default: 0) |
| 137 | - * @param string $stripe_token (default: '') |
|
| 138 | 137 | * @param bool initial_payment |
| 139 | 138 | */ |
| 140 | 139 | public function process_subscription_payment( $order = '', $amount = 0 ) { |
@@ -186,7 +185,7 @@ discard block |
||
| 186 | 185 | |
| 187 | 186 | /** |
| 188 | 187 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 189 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
| 188 | + * @param integer $renewal_order |
|
| 190 | 189 | */ |
| 191 | 190 | public function delete_renewal_meta( $renewal_order ) { |
| 192 | 191 | delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
@@ -406,6 +405,8 @@ discard block |
||
| 406 | 405 | /** |
| 407 | 406 | * Process the pre-order |
| 408 | 407 | * @param int $order_id |
| 408 | + * @param boolean $retry |
|
| 409 | + * @param boolean $force_save_source |
|
| 409 | 410 | * @return array |
| 410 | 411 | */ |
| 411 | 412 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -15,24 +15,24 @@ discard block |
||
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | |
| 18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 23 | 23 | |
| 24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
| 25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 26 | 26 | |
| 27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
| 28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
| 31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
| 28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
| 31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
| 34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
| 35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @since 4.0.0 |
| 44 | 44 | * @version 4.0.0 |
| 45 | 45 | */ |
| 46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
| 47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
| 46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
| 47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
| 48 | 48 | return false; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @param int $order_id |
| 57 | 57 | * @return boolean |
| 58 | 58 | */ |
| 59 | - public function has_subscription( $order_id ) { |
|
| 60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 59 | + public function has_subscription($order_id) { |
|
| 60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * @param int $order_id |
| 66 | 66 | * @return boolean |
| 67 | 67 | */ |
| 68 | - protected function is_pre_order( $order_id ) { |
|
| 69 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
| 68 | + protected function is_pre_order($order_id) { |
|
| 69 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * @param int $order_id |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 78 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 77 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 78 | + if ($this->has_subscription($order_id)) { |
|
| 79 | 79 | // Regular payment with force customer enabled |
| 80 | - return parent::process_payment( $order_id, true, true ); |
|
| 81 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
| 82 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
| 80 | + return parent::process_payment($order_id, true, true); |
|
| 81 | + } elseif ($this->is_pre_order($order_id)) { |
|
| 82 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
| 83 | 83 | } else { |
| 84 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 84 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | * @param array $metadata |
| 93 | 93 | * @param object $order |
| 94 | 94 | */ |
| 95 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
| 96 | - if ( ! $this->has_subscription( $order->get_id() ) ) { |
|
| 95 | + public function add_subscription_meta_data($metadata, $order) { |
|
| 96 | + if ( ! $this->has_subscription($order->get_id())) { |
|
| 97 | 97 | return $metadata; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | return $metadata += array( |
| 101 | 101 | 'payment_type' => 'recurring', |
| 102 | - 'site_url' => esc_url( get_site_url() ), |
|
| 102 | + 'site_url' => esc_url(get_site_url()), |
|
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -109,24 +109,24 @@ discard block |
||
| 109 | 109 | * @since 3.1.0 |
| 110 | 110 | * @version 4.0.0 |
| 111 | 111 | */ |
| 112 | - public function save_source( $order, $source ) { |
|
| 113 | - parent::save_source( $order, $source ); |
|
| 112 | + public function save_source($order, $source) { |
|
| 113 | + parent::save_source($order, $source); |
|
| 114 | 114 | |
| 115 | - $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 115 | + $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 116 | 116 | |
| 117 | 117 | // Also store it on the subscriptions being purchased or paid for in the order |
| 118 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 119 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 120 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 121 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 118 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 119 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 120 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 121 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 122 | 122 | } else { |
| 123 | 123 | $subscriptions = array(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - foreach ( $subscriptions as $subscription ) { |
|
| 126 | + foreach ($subscriptions as $subscription) { |
|
| 127 | 127 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
| 128 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 129 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 128 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 129 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -137,37 +137,37 @@ discard block |
||
| 137 | 137 | * @param string $stripe_token (default: '') |
| 138 | 138 | * @param bool initial_payment |
| 139 | 139 | */ |
| 140 | - public function process_subscription_payment( $order = '', $amount = 0 ) { |
|
| 141 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 140 | + public function process_subscription_payment($order = '', $amount = 0) { |
|
| 141 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 142 | 142 | /* translators: minimum amount */ |
| 143 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 143 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | $customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 147 | 147 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 148 | 148 | |
| 149 | 149 | // Get source from order |
| 150 | - $prepared_source = $this->prepare_order_source( $order ); |
|
| 150 | + $prepared_source = $this->prepare_order_source($order); |
|
| 151 | 151 | |
| 152 | 152 | // Or fail :( |
| 153 | - if ( ! $prepared_source->customer ) { |
|
| 154 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 153 | + if ( ! $prepared_source->customer) { |
|
| 154 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 157 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 158 | 158 | |
| 159 | 159 | // Make the request |
| 160 | - $request = $this->generate_payment_request( $order, $prepared_source ); |
|
| 160 | + $request = $this->generate_payment_request($order, $prepared_source); |
|
| 161 | 161 | $request['capture'] = 'true'; |
| 162 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 163 | - $response = WC_Stripe_API::request( $request ); |
|
| 162 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
| 163 | + $response = WC_Stripe_API::request($request); |
|
| 164 | 164 | |
| 165 | 165 | // Process valid response |
| 166 | - if ( ! empty( $response->error ) ) { |
|
| 166 | + if ( ! empty($response->error)) { |
|
| 167 | 167 | return $response; // Default catch all errors. |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - $this->process_response( $response, $order ); |
|
| 170 | + $this->process_response($response, $order); |
|
| 171 | 171 | |
| 172 | 172 | return $response; |
| 173 | 173 | } |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 177 | 177 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 178 | 178 | */ |
| 179 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 180 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 181 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 179 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 180 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 181 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 182 | 182 | // For BW compat will remove in future |
| 183 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 184 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 183 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 184 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 189 | 189 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 190 | 190 | */ |
| 191 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 192 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
| 193 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
| 191 | + public function delete_renewal_meta($renewal_order) { |
|
| 192 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
| 193 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
| 194 | 194 | return $renewal_order; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -200,17 +200,17 @@ discard block |
||
| 200 | 200 | * @param $amount_to_charge float The amount to charge. |
| 201 | 201 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 202 | 202 | */ |
| 203 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 204 | - $response = $this->process_subscription_payment( $renewal_order, $amount_to_charge ); |
|
| 203 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 204 | + $response = $this->process_subscription_payment($renewal_order, $amount_to_charge); |
|
| 205 | 205 | |
| 206 | - if ( is_wp_error( $response ) ) { |
|
| 206 | + if (is_wp_error($response)) { |
|
| 207 | 207 | /* translators: error message */ |
| 208 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 208 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( ! empty( $response->error ) ) { |
|
| 211 | + if ( ! empty($response->error)) { |
|
| 212 | 212 | /* translators: error message */ |
| 213 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 213 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
@@ -218,20 +218,20 @@ discard block |
||
| 218 | 218 | * Remove order meta |
| 219 | 219 | * @param object $order |
| 220 | 220 | */ |
| 221 | - public function remove_order_source_before_retry( $order ) { |
|
| 221 | + public function remove_order_source_before_retry($order) { |
|
| 222 | 222 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 223 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
| 223 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
| 224 | 224 | // For BW compat will remove in the future. |
| 225 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
| 225 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
| 229 | 229 | * Remove order meta |
| 230 | 230 | * @param object $order |
| 231 | 231 | */ |
| 232 | - public function remove_order_customer_before_retry( $order ) { |
|
| 232 | + public function remove_order_customer_before_retry($order) { |
|
| 233 | 233 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 234 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 234 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -243,14 +243,14 @@ discard block |
||
| 243 | 243 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 244 | 244 | * @return void |
| 245 | 245 | */ |
| 246 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 247 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 248 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 249 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 246 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 247 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 248 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 249 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 250 | 250 | |
| 251 | 251 | } else { |
| 252 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 253 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 252 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 253 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
@@ -263,21 +263,21 @@ discard block |
||
| 263 | 263 | * @param WC_Subscription $subscription An instance of a subscription object |
| 264 | 264 | * @return array |
| 265 | 265 | */ |
| 266 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 267 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 266 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 267 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 268 | 268 | |
| 269 | 269 | // For BW compat will remove in future. |
| 270 | - if ( empty( $source_id ) ) { |
|
| 271 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 270 | + if (empty($source_id)) { |
|
| 271 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 272 | 272 | |
| 273 | 273 | // Take this opportunity to update the key name. |
| 274 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
| 274 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $payment_meta[ $this->id ] = array( |
|
| 277 | + $payment_meta[$this->id] = array( |
|
| 278 | 278 | 'post_meta' => array( |
| 279 | 279 | '_stripe_customer_id' => array( |
| 280 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
| 280 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
| 281 | 281 | 'label' => 'Stripe Customer ID', |
| 282 | 282 | ), |
| 283 | 283 | '_stripe_source_id' => array( |
@@ -298,17 +298,17 @@ discard block |
||
| 298 | 298 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 299 | 299 | * @return array |
| 300 | 300 | */ |
| 301 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 302 | - if ( $this->id === $payment_method_id ) { |
|
| 301 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 302 | + if ($this->id === $payment_method_id) { |
|
| 303 | 303 | |
| 304 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 305 | - throw new Exception( 'A "_stripe_customer_id" value is required.' ); |
|
| 306 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 307 | - throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' ); |
|
| 304 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 305 | + throw new Exception('A "_stripe_customer_id" value is required.'); |
|
| 306 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 307 | + throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".'); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) { |
|
| 311 | - throw new Exception( 'A "_stripe_source_id" value is required.' ); |
|
| 310 | + if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) { |
|
| 311 | + throw new Exception('A "_stripe_source_id" value is required.'); |
|
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | } |
@@ -321,89 +321,89 @@ discard block |
||
| 321 | 321 | * @param WC_Subscription $subscription the subscription details |
| 322 | 322 | * @return string the subscription payment method |
| 323 | 323 | */ |
| 324 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 324 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 325 | 325 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
| 326 | 326 | |
| 327 | 327 | // bail for other payment methods |
| 328 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 328 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 329 | 329 | return $payment_method_to_display; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 332 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 333 | 333 | |
| 334 | 334 | // For BW compat will remove in future. |
| 335 | - if ( empty( $stripe_source_id ) ) { |
|
| 336 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 335 | + if (empty($stripe_source_id)) { |
|
| 336 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 337 | 337 | |
| 338 | 338 | // Take this opportunity to update the key name. |
| 339 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 339 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | $stripe_customer = new WC_Stripe_Customer(); |
| 343 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 343 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 344 | 344 | |
| 345 | 345 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 346 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 346 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 347 | 347 | $user_id = $customer_user; |
| 348 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 349 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 348 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 349 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 350 | 350 | |
| 351 | 351 | // For BW compat will remove in future. |
| 352 | - if ( empty( $stripe_source_id ) ) { |
|
| 353 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 352 | + if (empty($stripe_source_id)) { |
|
| 353 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 354 | 354 | |
| 355 | 355 | // Take this opportunity to update the key name. |
| 356 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 356 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 361 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 362 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 363 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 361 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 362 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 363 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 364 | 364 | |
| 365 | 365 | // For BW compat will remove in future. |
| 366 | - if ( empty( $stripe_source_id ) ) { |
|
| 367 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 366 | + if (empty($stripe_source_id)) { |
|
| 367 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 368 | 368 | |
| 369 | 369 | // Take this opportunity to update the key name. |
| 370 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 370 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 374 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 375 | 375 | $sources = $stripe_customer->get_sources(); |
| 376 | 376 | |
| 377 | - if ( $sources ) { |
|
| 377 | + if ($sources) { |
|
| 378 | 378 | $found_source = false; |
| 379 | - foreach ( $sources as $source ) { |
|
| 380 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 379 | + foreach ($sources as $source) { |
|
| 380 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 381 | 381 | $card = $source->card; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - if ( $source->id === $stripe_source_id ) { |
|
| 384 | + if ($source->id === $stripe_source_id) { |
|
| 385 | 385 | $found_source = true; |
| 386 | 386 | |
| 387 | - if ( $card ) { |
|
| 387 | + if ($card) { |
|
| 388 | 388 | /* translators: 1) card brand 2) last 4 digits */ |
| 389 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 389 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 390 | 390 | } else { |
| 391 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 391 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 392 | 392 | } |
| 393 | 393 | break; |
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if ( ! $found_source ) { |
|
| 398 | - if ( 'card' === $sources[0]->type ) { |
|
| 397 | + if ( ! $found_source) { |
|
| 398 | + if ('card' === $sources[0]->type) { |
|
| 399 | 399 | $card = $sources[0]->card; |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - if ( $card ) { |
|
| 402 | + if ($card) { |
|
| 403 | 403 | /* translators: 1) card brand 2) last 4 digits */ |
| 404 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 404 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 405 | 405 | } else { |
| 406 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 406 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | } |
@@ -416,43 +416,43 @@ discard block |
||
| 416 | 416 | * @param int $order_id |
| 417 | 417 | * @return array |
| 418 | 418 | */ |
| 419 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
| 420 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
| 419 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
| 420 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
| 421 | 421 | try { |
| 422 | - $order = wc_get_order( $order_id ); |
|
| 422 | + $order = wc_get_order($order_id); |
|
| 423 | 423 | |
| 424 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 424 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 425 | 425 | /* translators: minimum amount */ |
| 426 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 426 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | - $source = $this->prepare_source( get_current_user_id(), true ); |
|
| 429 | + $source = $this->prepare_source(get_current_user_id(), true); |
|
| 430 | 430 | |
| 431 | 431 | // We need a source on file to continue. |
| 432 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 433 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 432 | + if (empty($source->customer) || empty($source->source)) { |
|
| 433 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | // Store source to order meta |
| 437 | - $this->save_source( $order, $source ); |
|
| 437 | + $this->save_source($order, $source); |
|
| 438 | 438 | |
| 439 | 439 | // Remove cart |
| 440 | 440 | WC()->cart->empty_cart(); |
| 441 | 441 | |
| 442 | 442 | // Is pre ordered! |
| 443 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 443 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 444 | 444 | |
| 445 | 445 | // Return thank you page redirect |
| 446 | 446 | return array( |
| 447 | 447 | 'result' => 'success', |
| 448 | - 'redirect' => $this->get_return_url( $order ), |
|
| 448 | + 'redirect' => $this->get_return_url($order), |
|
| 449 | 449 | ); |
| 450 | - } catch ( Exception $e ) { |
|
| 451 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 450 | + } catch (Exception $e) { |
|
| 451 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 452 | 452 | return; |
| 453 | 453 | } |
| 454 | 454 | } else { |
| 455 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 455 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | * @param WC_Order $order |
| 462 | 462 | * @return void |
| 463 | 463 | */ |
| 464 | - public function process_pre_order_release_payment( $order ) { |
|
| 464 | + public function process_pre_order_release_payment($order) { |
|
| 465 | 465 | try { |
| 466 | 466 | // Define some callbacks if the first attempt fails. |
| 467 | 467 | $retry_callbacks = array( |
@@ -469,33 +469,33 @@ discard block |
||
| 469 | 469 | 'remove_order_customer_before_retry', |
| 470 | 470 | ); |
| 471 | 471 | |
| 472 | - while ( 1 ) { |
|
| 473 | - $source = $this->prepare_order_source( $order ); |
|
| 474 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 472 | + while (1) { |
|
| 473 | + $source = $this->prepare_order_source($order); |
|
| 474 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 475 | 475 | |
| 476 | - if ( ! empty( $response->error ) ) { |
|
| 477 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
| 478 | - throw new Exception( $response->error->message ); |
|
| 476 | + if ( ! empty($response->error)) { |
|
| 477 | + if (0 === sizeof($retry_callbacks)) { |
|
| 478 | + throw new Exception($response->error->message); |
|
| 479 | 479 | } else { |
| 480 | - $retry_callback = array_shift( $retry_callbacks ); |
|
| 481 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
| 480 | + $retry_callback = array_shift($retry_callbacks); |
|
| 481 | + call_user_func(array($this, $retry_callback), $order); |
|
| 482 | 482 | } |
| 483 | 483 | } else { |
| 484 | 484 | // Successful |
| 485 | - $this->process_response( $response, $order ); |
|
| 485 | + $this->process_response($response, $order); |
|
| 486 | 486 | break; |
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | - } catch ( Exception $e ) { |
|
| 489 | + } catch (Exception $e) { |
|
| 490 | 490 | /* translators: error message */ |
| 491 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
| 491 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
| 492 | 492 | |
| 493 | 493 | // Mark order as failed if not already set, |
| 494 | 494 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
| 495 | - if ( ! $order->has_status( 'failed' ) ) { |
|
| 496 | - $order->update_status( 'failed', $order_note ); |
|
| 495 | + if ( ! $order->has_status('failed')) { |
|
| 496 | + $order->update_status('failed', $order_note); |
|
| 497 | 497 | } else { |
| 498 | - $order->add_order_note( $order_note ); |
|
| 498 | + $order->add_order_note($order_note); |
|
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | } |
@@ -289,7 +289,7 @@ |
||
| 289 | 289 | * |
| 290 | 290 | * @param int $order_id Reference. |
| 291 | 291 | * @param bool $retry Should we retry on fail. |
| 292 | - * @param bool $force_save_source Force payment source to be saved. |
|
| 292 | + * @param bool $force_save_save Force payment source to be saved. |
|
| 293 | 293 | * |
| 294 | 294 | * @throws Exception If payment will not be accepted. |
| 295 | 295 | * |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_alipay'; |
| 60 | - $this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -125,10 +125,10 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | 127 | if ( |
| 128 | - 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) |
|
| 128 | + 'yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency()) |
|
| 129 | 129 | ) { |
| 130 | 130 | /* translators: supported currency list */ |
| 131 | - $message = sprintf( __( 'Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe' ), implode( ', ', $this->get_supported_currency() ) ); |
|
| 131 | + $message = sprintf(__('Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe'), implode(', ', $this->get_supported_currency())); |
|
| 132 | 132 | |
| 133 | 133 | return $message; |
| 134 | 134 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @return array |
| 145 | 145 | */ |
| 146 | 146 | public function get_supported_currency() { |
| 147 | - return apply_filters( 'wc_stripe_alipay_supported_currencies', array( |
|
| 147 | + return apply_filters('wc_stripe_alipay_supported_currencies', array( |
|
| 148 | 148 | 'EUR', |
| 149 | 149 | 'AUD', |
| 150 | 150 | 'CAD', |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | 'NZD', |
| 155 | 155 | 'SGD', |
| 156 | 156 | 'USD', |
| 157 | - ) ); |
|
| 157 | + )); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @return bool |
| 166 | 166 | */ |
| 167 | 167 | public function is_available() { |
| 168 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 168 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 169 | 169 | return false; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -180,9 +180,9 @@ discard block |
||
| 180 | 180 | * @return array |
| 181 | 181 | */ |
| 182 | 182 | public function payment_icons() { |
| 183 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 183 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 184 | 184 | 'alipay' => '<i class="stripe-pf stripe-pf-alipay stripe-pf-right" alt="Alipay" aria-hidden="true"></i>', |
| 185 | - ) ); |
|
| 185 | + )); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $icons_str .= $icons['alipay']; |
| 201 | 201 | |
| 202 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 202 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -209,19 +209,19 @@ discard block |
||
| 209 | 209 | * @version 4.0.0 |
| 210 | 210 | */ |
| 211 | 211 | public function payment_scripts() { |
| 212 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 212 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 213 | 213 | return; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 217 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 216 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 217 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
| 221 | 221 | * Initialize Gateway Settings Form Fields. |
| 222 | 222 | */ |
| 223 | 223 | public function init_form_fields() { |
| 224 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' ); |
|
| 224 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php'); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -232,25 +232,25 @@ discard block |
||
| 232 | 232 | $total = WC()->cart->total; |
| 233 | 233 | |
| 234 | 234 | // If paying from order, we need to get total from order not cart. |
| 235 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 236 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 235 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 236 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 237 | 237 | $total = $order->get_total(); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - if ( is_add_payment_method_page() ) { |
|
| 241 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 242 | - $total = ''; |
|
| 240 | + if (is_add_payment_method_page()) { |
|
| 241 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 242 | + $total = ''; |
|
| 243 | 243 | } else { |
| 244 | 244 | $pay_button_text = ''; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | echo '<div |
| 248 | 248 | id="stripe-alipay-payment-data" |
| 249 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 250 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 249 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 250 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 251 | 251 | |
| 252 | - if ( $this->description ) { |
|
| 253 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 252 | + if ($this->description) { |
|
| 253 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | echo '</div>'; |
@@ -264,24 +264,24 @@ discard block |
||
| 264 | 264 | * @param object $order |
| 265 | 265 | * @return mixed |
| 266 | 266 | */ |
| 267 | - public function create_source( $order ) { |
|
| 267 | + public function create_source($order) { |
|
| 268 | 268 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 269 | 269 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 270 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 270 | + $return_url = $this->get_stripe_return_url($order); |
|
| 271 | 271 | $post_data = array(); |
| 272 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 273 | - $post_data['currency'] = strtolower( $currency ); |
|
| 272 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 273 | + $post_data['currency'] = strtolower($currency); |
|
| 274 | 274 | $post_data['type'] = 'alipay'; |
| 275 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 276 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 275 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 276 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 277 | 277 | |
| 278 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 279 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 278 | + if ( ! empty($this->statement_descriptor)) { |
|
| 279 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' ); |
|
| 282 | + WC_Stripe_Logger::log('Info: Begin creating Alipay source'); |
|
| 283 | 283 | |
| 284 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 284 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -295,53 +295,53 @@ discard block |
||
| 295 | 295 | * |
| 296 | 296 | * @return array|void |
| 297 | 297 | */ |
| 298 | - public function process_payment( $order_id, $retry = true, $force_save_save = false ) { |
|
| 298 | + public function process_payment($order_id, $retry = true, $force_save_save = false) { |
|
| 299 | 299 | try { |
| 300 | - $order = wc_get_order( $order_id ); |
|
| 300 | + $order = wc_get_order($order_id); |
|
| 301 | 301 | |
| 302 | 302 | // This will throw exception if not valid. |
| 303 | - $this->validate_minimum_order_amount( $order ); |
|
| 303 | + $this->validate_minimum_order_amount($order); |
|
| 304 | 304 | |
| 305 | 305 | // This comes from the create account checkbox in the checkout page. |
| 306 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 306 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 307 | 307 | |
| 308 | - if ( $create_account ) { |
|
| 308 | + if ($create_account) { |
|
| 309 | 309 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 310 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 310 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 311 | 311 | $new_stripe_customer->create_customer(); |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - $response = $this->create_source( $order ); |
|
| 314 | + $response = $this->create_source($order); |
|
| 315 | 315 | |
| 316 | - if ( ! empty( $response->error ) ) { |
|
| 317 | - $order->add_order_note( $response->error->message ); |
|
| 316 | + if ( ! empty($response->error)) { |
|
| 317 | + $order->add_order_note($response->error->message); |
|
| 318 | 318 | |
| 319 | - throw new Exception( $response->error->message ); |
|
| 319 | + throw new Exception($response->error->message); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 323 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 322 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 323 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 324 | 324 | } else { |
| 325 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 325 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 326 | 326 | $order->save(); |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); |
|
| 329 | + WC_Stripe_Logger::log('Info: Redirecting to Alipay...'); |
|
| 330 | 330 | |
| 331 | 331 | return array( |
| 332 | 332 | 'result' => 'success', |
| 333 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 333 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 334 | 334 | ); |
| 335 | - } catch ( Exception $e ) { |
|
| 336 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 337 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 335 | + } catch (Exception $e) { |
|
| 336 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 337 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 338 | 338 | |
| 339 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 339 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 340 | 340 | |
| 341 | - $statuses = array( 'pending', 'failed' ); |
|
| 341 | + $statuses = array('pending', 'failed'); |
|
| 342 | 342 | |
| 343 | - if ( $order->has_status( $statuses ) ) { |
|
| 344 | - $this->send_failed_order_email( $order_id ); |
|
| 343 | + if ($order->has_status($statuses)) { |
|
| 344 | + $this->send_failed_order_email($order_id); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | return array( |
@@ -162,6 +162,8 @@ |
||
| 162 | 162 | * |
| 163 | 163 | * @since 1.0.0 |
| 164 | 164 | * @version 4.0.0 |
| 165 | + * @param string $slug |
|
| 166 | + * @param string $class |
|
| 165 | 167 | */ |
| 166 | 168 | public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
| 167 | 169 | $this->notices[ $slug ] = array( |
@@ -14,20 +14,20 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 17 | +if ( ! defined('ABSPATH')) { |
|
| 18 | 18 | exit; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
| 21 | +if ( ! class_exists('WC_Stripe')) : |
|
| 22 | 22 | /** |
| 23 | 23 | * Required minimums and constants |
| 24 | 24 | */ |
| 25 | - define( 'WC_STRIPE_VERSION', '4.0.1' ); |
|
| 26 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
| 27 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
| 28 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
| 29 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
| 30 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
| 25 | + define('WC_STRIPE_VERSION', '4.0.1'); |
|
| 26 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
| 27 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
| 28 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
| 29 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
| 30 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
| 31 | 31 | |
| 32 | 32 | class WC_Stripe { |
| 33 | 33 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return Singleton The *Singleton* instance. |
| 48 | 48 | */ |
| 49 | 49 | public static function get_instance() { |
| 50 | - if ( null === self::$instance ) { |
|
| 50 | + if (null === self::$instance) { |
|
| 51 | 51 | self::$instance = new self(); |
| 52 | 52 | } |
| 53 | 53 | return self::$instance; |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | * *Singleton* via the `new` operator from outside of this class. |
| 81 | 81 | */ |
| 82 | 82 | private function __construct() { |
| 83 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
| 84 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
| 85 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
| 86 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
| 83 | + add_action('admin_init', array($this, 'check_environment')); |
|
| 84 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
| 85 | + add_action('plugins_loaded', array($this, 'init')); |
|
| 86 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -93,42 +93,42 @@ discard block |
||
| 93 | 93 | * @version 4.0.0 |
| 94 | 94 | */ |
| 95 | 95 | public function init() { |
| 96 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
| 97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
| 98 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
| 96 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
| 97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
| 98 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
| 99 | 99 | |
| 100 | 100 | // Don't hook anything else in the plugin if we're in an incompatible environment |
| 101 | - if ( self::get_environment_warning() ) { |
|
| 101 | + if (self::get_environment_warning()) { |
|
| 102 | 102 | return; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
| 106 | - |
|
| 107 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
| 108 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
| 109 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
| 110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
| 111 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
| 112 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
| 113 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
| 114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
| 115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
| 116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
| 117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
| 118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
| 119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
| 120 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
| 121 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
| 122 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
| 123 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
| 124 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
| 105 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
| 106 | + |
|
| 107 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
| 108 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
| 109 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
| 110 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
| 111 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
| 112 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
| 113 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
| 114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
| 115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
| 116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
| 117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
| 118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
| 119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
| 120 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
| 121 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
| 122 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
| 123 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
| 124 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
| 125 | 125 | |
| 126 | 126 | // REMOVE IN THE FUTURE. |
| 127 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
| 127 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
| 128 | 128 | |
| 129 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
| 130 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
| 131 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
| 129 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
| 130 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
| 131 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -138,23 +138,23 @@ discard block |
||
| 138 | 138 | * @version 4.0.0 |
| 139 | 139 | */ |
| 140 | 140 | public function hide_notices() { |
| 141 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
| 142 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
| 143 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
| 141 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
| 142 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
| 143 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 147 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 146 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 147 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
| 150 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
| 151 | 151 | |
| 152 | - switch ( $notice ) { |
|
| 152 | + switch ($notice) { |
|
| 153 | 153 | case 'ssl': |
| 154 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
| 154 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
| 155 | 155 | break; |
| 156 | 156 | case 'keys': |
| 157 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
| 157 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
| 158 | 158 | break; |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -166,8 +166,8 @@ discard block |
||
| 166 | 166 | * @since 1.0.0 |
| 167 | 167 | * @version 4.0.0 |
| 168 | 168 | */ |
| 169 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
| 170 | - $this->notices[ $slug ] = array( |
|
| 169 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
| 170 | + $this->notices[$slug] = array( |
|
| 171 | 171 | 'class' => $class, |
| 172 | 172 | 'message' => $message, |
| 173 | 173 | 'dismissible' => $dismissible, |
@@ -181,21 +181,21 @@ discard block |
||
| 181 | 181 | * @version 4.0.0 |
| 182 | 182 | */ |
| 183 | 183 | public function admin_notices() { |
| 184 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 184 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 185 | 185 | return; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 189 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
| 188 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 189 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
| 190 | 190 | |
| 191 | - if ( $notice['dismissible'] ) { |
|
| 191 | + if ($notice['dismissible']) { |
|
| 192 | 192 | ?> |
| 193 | - <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
| 193 | + <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
| 194 | 194 | <?php |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | echo '<p>'; |
| 198 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 198 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 199 | 199 | echo '</p></div>'; |
| 200 | 200 | } |
| 201 | 201 | } |
@@ -208,26 +208,26 @@ discard block |
||
| 208 | 208 | * @version 4.0.0 |
| 209 | 209 | */ |
| 210 | 210 | public function get_environment_warning() { |
| 211 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
| 211 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
| 212 | 212 | /* translators: 1) int version 2) int version */ |
| 213 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
| 213 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
| 214 | 214 | |
| 215 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
| 215 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
| 219 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
| 218 | + if ( ! defined('WC_VERSION')) { |
|
| 219 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
| 222 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
| 223 | 223 | /* translators: 1) int version 2) int version */ |
| 224 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
| 224 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
| 225 | 225 | |
| 226 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
| 226 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - if ( ! function_exists( 'curl_init' ) ) { |
|
| 230 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
| 229 | + if ( ! function_exists('curl_init')) { |
|
| 230 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | return false; |
@@ -241,11 +241,11 @@ discard block |
||
| 241 | 241 | * @return string Setting link |
| 242 | 242 | */ |
| 243 | 243 | public function get_setting_link() { |
| 244 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
| 244 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
| 245 | 245 | |
| 246 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
| 246 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
| 247 | 247 | |
| 248 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
| 248 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -256,37 +256,37 @@ discard block |
||
| 256 | 256 | * @version 4.0.0 |
| 257 | 257 | */ |
| 258 | 258 | public function check_environment() { |
| 259 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
| 259 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
| 260 | 260 | $this->install(); |
| 261 | 261 | |
| 262 | - do_action( 'woocommerce_stripe_updated' ); |
|
| 262 | + do_action('woocommerce_stripe_updated'); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | $environment_warning = $this->get_environment_warning(); |
| 266 | 266 | |
| 267 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
| 268 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 267 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
| 268 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
| 272 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
| 273 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 271 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
| 272 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
| 273 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 274 | 274 | |
| 275 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
| 276 | - $secret = WC_Stripe_API::get_secret_key(); |
|
| 275 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
| 276 | + $secret = WC_Stripe_API::get_secret_key(); |
|
| 277 | 277 | |
| 278 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
| 278 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
| 279 | 279 | $setting_link = $this->get_setting_link(); |
| 280 | 280 | /* translators: 1) link */ |
| 281 | - $this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
| 281 | + $this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
| 285 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
| 286 | 286 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
| 287 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
| 287 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
| 288 | 288 | /* translators: 1) link 2) link */ |
| 289 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
|
| 289 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true); |
|
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | } |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | * @version 4.0.0 |
| 299 | 299 | */ |
| 300 | 300 | public function update_plugin_version() { |
| 301 | - delete_option( 'wc_stripe_version' ); |
|
| 302 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
| 301 | + delete_option('wc_stripe_version'); |
|
| 302 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | * @version 3.1.0 |
| 310 | 310 | */ |
| 311 | 311 | public function install() { |
| 312 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
| 313 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
| 312 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
| 313 | + define('WC_STRIPE_INSTALLING', true); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | $this->update_plugin_version(); |
@@ -322,13 +322,13 @@ discard block |
||
| 322 | 322 | * @since 1.0.0 |
| 323 | 323 | * @version 4.0.0 |
| 324 | 324 | */ |
| 325 | - public function plugin_action_links( $links ) { |
|
| 325 | + public function plugin_action_links($links) { |
|
| 326 | 326 | $plugin_links = array( |
| 327 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 328 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 329 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 327 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
| 328 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
| 329 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
| 330 | 330 | ); |
| 331 | - return array_merge( $plugin_links, $links ); |
|
| 331 | + return array_merge($plugin_links, $links); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | * @since 1.0.0 |
| 338 | 338 | * @version 4.0.0 |
| 339 | 339 | */ |
| 340 | - public function add_gateways( $methods ) { |
|
| 341 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 340 | + public function add_gateways($methods) { |
|
| 341 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
| 342 | 342 | $methods[] = 'WC_Stripe_Compat'; |
| 343 | 343 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
| 344 | 344 | } else { |
@@ -363,26 +363,26 @@ discard block |
||
| 363 | 363 | * @since 4.0.0 |
| 364 | 364 | * @version 4.0.0 |
| 365 | 365 | */ |
| 366 | - public function filter_gateway_order_admin( $sections ) { |
|
| 367 | - unset( $sections['stripe'] ); |
|
| 368 | - unset( $sections['stripe_bancontact'] ); |
|
| 369 | - unset( $sections['stripe_sofort'] ); |
|
| 370 | - unset( $sections['stripe_giropay'] ); |
|
| 371 | - unset( $sections['stripe_ideal'] ); |
|
| 372 | - unset( $sections['stripe_p24'] ); |
|
| 373 | - unset( $sections['stripe_alipay'] ); |
|
| 374 | - unset( $sections['stripe_sepa'] ); |
|
| 375 | - unset( $sections['stripe_bitcoin'] ); |
|
| 366 | + public function filter_gateway_order_admin($sections) { |
|
| 367 | + unset($sections['stripe']); |
|
| 368 | + unset($sections['stripe_bancontact']); |
|
| 369 | + unset($sections['stripe_sofort']); |
|
| 370 | + unset($sections['stripe_giropay']); |
|
| 371 | + unset($sections['stripe_ideal']); |
|
| 372 | + unset($sections['stripe_p24']); |
|
| 373 | + unset($sections['stripe_alipay']); |
|
| 374 | + unset($sections['stripe_sepa']); |
|
| 375 | + unset($sections['stripe_bitcoin']); |
|
| 376 | 376 | |
| 377 | 377 | $sections['stripe'] = 'Stripe'; |
| 378 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
| 379 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
| 380 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
| 381 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
| 382 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
| 383 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
| 384 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
| 385 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
| 378 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
| 379 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
| 380 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
| 381 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
| 382 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
| 383 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
| 384 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
| 385 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
| 386 | 386 | |
| 387 | 387 | return $sections; |
| 388 | 388 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function __construct() { |
| 66 | 66 | $this->id = 'stripe_bitcoin'; |
| 67 | - $this->method_title = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
| 67 | + $this->method_title = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
| 68 | 68 | /* translators: link */ |
| 69 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 69 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 70 | 70 | $this->supports = array( |
| 71 | 71 | 'products', |
| 72 | 72 | 'refunds', |
@@ -78,29 +78,29 @@ discard block |
||
| 78 | 78 | // Load the settings. |
| 79 | 79 | $this->init_settings(); |
| 80 | 80 | |
| 81 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 82 | - $this->title = $this->get_option( 'title' ); |
|
| 83 | - $this->description = $this->get_option( 'description' ); |
|
| 84 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 85 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 86 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 87 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 88 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 89 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 90 | - |
|
| 91 | - if ( $this->testmode ) { |
|
| 92 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 93 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 81 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 82 | + $this->title = $this->get_option('title'); |
|
| 83 | + $this->description = $this->get_option('description'); |
|
| 84 | + $this->enabled = $this->get_option('enabled'); |
|
| 85 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 86 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 87 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 88 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 89 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 90 | + |
|
| 91 | + if ($this->testmode) { |
|
| 92 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 93 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 97 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 98 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 99 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 100 | - add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) ); |
|
| 96 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 97 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 98 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 99 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 100 | + add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page')); |
|
| 101 | 101 | |
| 102 | 102 | // Customer Emails |
| 103 | - add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); |
|
| 103 | + add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | * @version 4.0.0 |
| 111 | 111 | */ |
| 112 | 112 | public function check_environment() { |
| 113 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 113 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $environment_warning = $this->get_environment_warning(); |
| 118 | 118 | |
| 119 | - if ( $environment_warning ) { |
|
| 120 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 119 | + if ($environment_warning) { |
|
| 120 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 124 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 125 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 123 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 124 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 125 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 126 | 126 | echo '</p></div>'; |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | * @version 4.0.0 |
| 136 | 136 | */ |
| 137 | 137 | public function get_environment_warning() { |
| 138 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 139 | - $message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' ); |
|
| 138 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 139 | + $message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe'); |
|
| 140 | 140 | |
| 141 | 141 | return $message; |
| 142 | 142 | } |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | * @return array |
| 153 | 153 | */ |
| 154 | 154 | public function get_supported_currency() { |
| 155 | - return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array( |
|
| 155 | + return apply_filters('wc_stripe_bitcoin_supported_currencies', array( |
|
| 156 | 156 | 'USD', |
| 157 | - ) ); |
|
| 157 | + )); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @return bool |
| 166 | 166 | */ |
| 167 | 167 | public function is_available() { |
| 168 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 168 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 169 | 169 | return false; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -180,9 +180,9 @@ discard block |
||
| 180 | 180 | * @return array |
| 181 | 181 | */ |
| 182 | 182 | public function payment_icons() { |
| 183 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 183 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 184 | 184 | 'bitcoin' => '<i class="stripe-pf stripe-pf-bitcoin stripe-pf-right" alt="Bitcoin" aria-hidden="true"></i>', |
| 185 | - ) ); |
|
| 185 | + )); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $icons_str .= $icons['bitcoin']; |
| 201 | 201 | |
| 202 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 202 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -210,19 +210,19 @@ discard block |
||
| 210 | 210 | * @access public |
| 211 | 211 | */ |
| 212 | 212 | public function payment_scripts() { |
| 213 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 213 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 214 | 214 | return; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 218 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 217 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 218 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
| 222 | 222 | * Initialize Gateway Settings Form Fields. |
| 223 | 223 | */ |
| 224 | 224 | public function init_form_fields() { |
| 225 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' ); |
|
| 225 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php'); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -233,25 +233,25 @@ discard block |
||
| 233 | 233 | $total = WC()->cart->total; |
| 234 | 234 | |
| 235 | 235 | // If paying from order, we need to get total from order not cart. |
| 236 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 237 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 236 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 237 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 238 | 238 | $total = $order->get_total(); |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if ( is_add_payment_method_page() ) { |
|
| 242 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 243 | - $total = ''; |
|
| 241 | + if (is_add_payment_method_page()) { |
|
| 242 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 243 | + $total = ''; |
|
| 244 | 244 | } else { |
| 245 | 245 | $pay_button_text = ''; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | echo '<div |
| 249 | 249 | id="stripe-bitcoin-payment-data" |
| 250 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 251 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 250 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 251 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 252 | 252 | |
| 253 | - if ( $this->description ) { |
|
| 254 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 253 | + if ($this->description) { |
|
| 254 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | echo '</div>'; |
@@ -262,8 +262,8 @@ discard block |
||
| 262 | 262 | * |
| 263 | 263 | * @param int $order_id |
| 264 | 264 | */ |
| 265 | - public function thankyou_page( $order_id ) { |
|
| 266 | - $this->get_instructions( $order_id ); |
|
| 265 | + public function thankyou_page($order_id) { |
|
| 266 | + $this->get_instructions($order_id); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -275,13 +275,13 @@ discard block |
||
| 275 | 275 | * @param bool $sent_to_admin |
| 276 | 276 | * @param bool $plain_text |
| 277 | 277 | */ |
| 278 | - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { |
|
| 278 | + public function email_instructions($order, $sent_to_admin, $plain_text = false) { |
|
| 279 | 279 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 280 | 280 | |
| 281 | 281 | $payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method(); |
| 282 | 282 | |
| 283 | - if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) { |
|
| 284 | - $this->get_instructions( $order_id, $plain_text ); |
|
| 283 | + if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) { |
|
| 284 | + $this->get_instructions($order_id, $plain_text); |
|
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | |
@@ -292,38 +292,38 @@ discard block |
||
| 292 | 292 | * @version 4.0.0 |
| 293 | 293 | * @param int $order_id |
| 294 | 294 | */ |
| 295 | - public function get_instructions( $order_id, $plain_text = false ) { |
|
| 296 | - $data = get_post_meta( $order_id, '_stripe_bitcoin', true ); |
|
| 295 | + public function get_instructions($order_id, $plain_text = false) { |
|
| 296 | + $data = get_post_meta($order_id, '_stripe_bitcoin', true); |
|
| 297 | 297 | |
| 298 | - if ( $plain_text ) { |
|
| 299 | - esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 298 | + if ($plain_text) { |
|
| 299 | + esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 300 | 300 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 301 | - esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 301 | + esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 302 | 302 | echo $data['amount'] . "\n\n"; |
| 303 | 303 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 304 | - esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 304 | + esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 305 | 305 | echo $data['address'] . "\n\n"; |
| 306 | 306 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 307 | - esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 307 | + esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 308 | 308 | echo $data['uri'] . "\n\n"; |
| 309 | 309 | } else { |
| 310 | 310 | ?> |
| 311 | - <h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3> |
|
| 311 | + <h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3> |
|
| 312 | 312 | <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
| 313 | 313 | <li class="woocommerce-order-overview__order order"> |
| 314 | - <?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?> |
|
| 314 | + <?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?> |
|
| 315 | 315 | <strong><?php echo $data['amount']; ?></strong> |
| 316 | 316 | </li> |
| 317 | 317 | <li class="woocommerce-order-overview__order order"> |
| 318 | - <?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?> |
|
| 318 | + <?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?> |
|
| 319 | 319 | <strong><?php echo $data['address']; ?></strong> |
| 320 | 320 | </li> |
| 321 | 321 | <li class="woocommerce-order-overview__order order"> |
| 322 | - <?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?> |
|
| 322 | + <?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?> |
|
| 323 | 323 | <strong> |
| 324 | 324 | <?php |
| 325 | 325 | /* translators: link */ |
| 326 | - printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] ); |
|
| 326 | + printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']); |
|
| 327 | 327 | ?> |
| 328 | 328 | </strong> |
| 329 | 329 | </li> |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | * @param object $order |
| 341 | 341 | * @param object $source_object |
| 342 | 342 | */ |
| 343 | - public function save_instructions( $order, $source_object ) { |
|
| 343 | + public function save_instructions($order, $source_object) { |
|
| 344 | 344 | $data = array( |
| 345 | 345 | 'amount' => $source_object->bitcoin->amount, |
| 346 | 346 | 'address' => $source_object->bitcoin->address, |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | |
| 350 | 350 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 351 | 351 | |
| 352 | - update_post_meta( $order_id, '_stripe_bitcoin', $data ); |
|
| 352 | + update_post_meta($order_id, '_stripe_bitcoin', $data); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -363,40 +363,40 @@ discard block |
||
| 363 | 363 | * |
| 364 | 364 | * @return array|void |
| 365 | 365 | */ |
| 366 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 366 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 367 | 367 | try { |
| 368 | - $order = wc_get_order( $order_id ); |
|
| 369 | - $source_object = ! empty( $_POST['stripe_source'] ) ? json_decode( stripslashes( $_POST['stripe_source'] ) ) : false; |
|
| 368 | + $order = wc_get_order($order_id); |
|
| 369 | + $source_object = ! empty($_POST['stripe_source']) ? json_decode(stripslashes($_POST['stripe_source'])) : false; |
|
| 370 | 370 | |
| 371 | 371 | // This comes from the create account checkbox in the checkout page. |
| 372 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 372 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 373 | 373 | |
| 374 | - if ( $create_account ) { |
|
| 374 | + if ($create_account) { |
|
| 375 | 375 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 376 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 376 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 377 | 377 | $new_stripe_customer->create_customer(); |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
| 380 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
| 381 | 381 | |
| 382 | - if ( empty( $prepared_source->source ) ) { |
|
| 383 | - $error_msg = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 384 | - throw new Exception( $error_msg ); |
|
| 382 | + if (empty($prepared_source->source)) { |
|
| 383 | + $error_msg = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 384 | + throw new Exception($error_msg); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | // Store source to order meta. |
| 388 | - $this->save_source( $order, $prepared_source ); |
|
| 388 | + $this->save_source($order, $prepared_source); |
|
| 389 | 389 | |
| 390 | 390 | |
| 391 | 391 | // This will throw exception if not valid. |
| 392 | - $this->validate_minimum_order_amount( $order ); |
|
| 392 | + $this->validate_minimum_order_amount($order); |
|
| 393 | 393 | |
| 394 | - $this->save_instructions( $order, $source_object ); |
|
| 394 | + $this->save_instructions($order, $source_object); |
|
| 395 | 395 | |
| 396 | 396 | // Mark as on-hold (we're awaiting the payment) |
| 397 | - $order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) ); |
|
| 397 | + $order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe')); |
|
| 398 | 398 | |
| 399 | - wc_reduce_stock_levels( $order_id ); |
|
| 399 | + wc_reduce_stock_levels($order_id); |
|
| 400 | 400 | |
| 401 | 401 | // Remove cart |
| 402 | 402 | WC()->cart->empty_cart(); |
@@ -404,16 +404,16 @@ discard block |
||
| 404 | 404 | // Return thankyou redirect |
| 405 | 405 | return array( |
| 406 | 406 | 'result' => 'success', |
| 407 | - 'redirect' => $this->get_return_url( $order ), |
|
| 407 | + 'redirect' => $this->get_return_url($order), |
|
| 408 | 408 | ); |
| 409 | - } catch ( Exception $e ) { |
|
| 410 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 411 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 409 | + } catch (Exception $e) { |
|
| 410 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 411 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 412 | 412 | |
| 413 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 413 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 414 | 414 | |
| 415 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 416 | - $this->send_failed_order_email( $order_id ); |
|
| 415 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 416 | + $this->send_failed_order_email($order_id); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_bancontact'; |
| 60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_bancontact_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_bancontact_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | * @return array |
| 170 | 170 | */ |
| 171 | 171 | public function payment_icons() { |
| 172 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 172 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 173 | 173 | 'bancontact' => '<i class="stripe-pf stripe-pf-bancontact-mister-cash stripe-pf-right" alt="Bancontact" aria-hidden="true"></i>', |
| 174 | - ) ); |
|
| 174 | + )); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $icons_str .= $icons['bancontact']; |
| 190 | 190 | |
| 191 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 191 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,19 +199,19 @@ discard block |
||
| 199 | 199 | * @access public |
| 200 | 200 | */ |
| 201 | 201 | public function payment_scripts() { |
| 202 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 202 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 203 | 203 | return; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 207 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 206 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 207 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
| 211 | 211 | * Initialize Gateway Settings Form Fields. |
| 212 | 212 | */ |
| 213 | 213 | public function init_form_fields() { |
| 214 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
| 214 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -222,25 +222,25 @@ discard block |
||
| 222 | 222 | $total = WC()->cart->total; |
| 223 | 223 | |
| 224 | 224 | // If paying from order, we need to get total from order not cart. |
| 225 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 226 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 225 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 226 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 227 | 227 | $total = $order->get_total(); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ( is_add_payment_method_page() ) { |
|
| 231 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 232 | - $total = ''; |
|
| 230 | + if (is_add_payment_method_page()) { |
|
| 231 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 232 | + $total = ''; |
|
| 233 | 233 | } else { |
| 234 | 234 | $pay_button_text = ''; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | echo '<div |
| 238 | 238 | id="stripe-bancontact-payment-data" |
| 239 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 240 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 239 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 240 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 241 | 241 | |
| 242 | - if ( $this->description ) { |
|
| 243 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 242 | + if ($this->description) { |
|
| 243 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | echo '</div>'; |
@@ -254,24 +254,24 @@ discard block |
||
| 254 | 254 | * @param object $order |
| 255 | 255 | * @return mixed |
| 256 | 256 | */ |
| 257 | - public function create_source( $order ) { |
|
| 257 | + public function create_source($order) { |
|
| 258 | 258 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 259 | 259 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 260 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 260 | + $return_url = $this->get_stripe_return_url($order); |
|
| 261 | 261 | $post_data = array(); |
| 262 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 263 | - $post_data['currency'] = strtolower( $currency ); |
|
| 262 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 263 | + $post_data['currency'] = strtolower($currency); |
|
| 264 | 264 | $post_data['type'] = 'bancontact'; |
| 265 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 266 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 265 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 266 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 267 | 267 | |
| 268 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 269 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 268 | + if ( ! empty($this->statement_descriptor)) { |
|
| 269 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
| 272 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
| 273 | 273 | |
| 274 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 274 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -285,51 +285,51 @@ discard block |
||
| 285 | 285 | * |
| 286 | 286 | * @return array|void |
| 287 | 287 | */ |
| 288 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 288 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 289 | 289 | try { |
| 290 | - $order = wc_get_order( $order_id ); |
|
| 290 | + $order = wc_get_order($order_id); |
|
| 291 | 291 | |
| 292 | 292 | // This will throw exception if not valid. |
| 293 | - $this->validate_minimum_order_amount( $order ); |
|
| 293 | + $this->validate_minimum_order_amount($order); |
|
| 294 | 294 | |
| 295 | 295 | // This comes from the create account checkbox in the checkout page. |
| 296 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 296 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 297 | 297 | |
| 298 | - if ( $create_account ) { |
|
| 298 | + if ($create_account) { |
|
| 299 | 299 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 300 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 300 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 301 | 301 | $new_stripe_customer->create_customer(); |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - $response = $this->create_source( $order ); |
|
| 304 | + $response = $this->create_source($order); |
|
| 305 | 305 | |
| 306 | - if ( ! empty( $response->error ) ) { |
|
| 307 | - $order->add_order_note( $response->error->message ); |
|
| 306 | + if ( ! empty($response->error)) { |
|
| 307 | + $order->add_order_note($response->error->message); |
|
| 308 | 308 | |
| 309 | - throw new Exception( $response->error->message ); |
|
| 309 | + throw new Exception($response->error->message); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 313 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 312 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 313 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 314 | 314 | } else { |
| 315 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 315 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 316 | 316 | $order->save(); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
| 319 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
| 320 | 320 | |
| 321 | 321 | return array( |
| 322 | 322 | 'result' => 'success', |
| 323 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 323 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 324 | 324 | ); |
| 325 | - } catch ( Exception $e ) { |
|
| 326 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 327 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 325 | + } catch (Exception $e) { |
|
| 326 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 327 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 328 | 328 | |
| 329 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 329 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 330 | 330 | |
| 331 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 332 | - $this->send_failed_order_email( $order_id ); |
|
| 331 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 332 | + $this->send_failed_order_email($order_id); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_sofort'; |
| 60 | - $this->method_title = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_sofort_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_sofort_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | * @return array |
| 170 | 170 | */ |
| 171 | 171 | public function payment_icons() { |
| 172 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
| 172 | + return apply_filters('wc_stripe_payment_icons', array( |
|
| 173 | 173 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
| 174 | - ) ); |
|
| 174 | + )); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $icons_str .= $icons['sofort']; |
| 190 | 190 | |
| 191 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 191 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,19 +199,19 @@ discard block |
||
| 199 | 199 | * @access public |
| 200 | 200 | */ |
| 201 | 201 | public function payment_scripts() { |
| 202 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 202 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 203 | 203 | return; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 207 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 206 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 207 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
| 211 | 211 | * Initialize Gateway Settings Form Fields. |
| 212 | 212 | */ |
| 213 | 213 | public function init_form_fields() { |
| 214 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
| 214 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -230,24 +230,24 @@ discard block |
||
| 230 | 230 | 'IT' => 'Italy', |
| 231 | 231 | ); |
| 232 | 232 | ?> |
| 233 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
| 234 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
| 233 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
| 234 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
| 235 | 235 | <label for="stripe-bank-country"> |
| 236 | - <?php _e( 'Country origin of your bank.', 'woocommerce-gateway-stripe' ); ?> |
|
| 236 | + <?php _e('Country origin of your bank.', 'woocommerce-gateway-stripe'); ?> |
|
| 237 | 237 | </label> |
| 238 | 238 | <br /> |
| 239 | 239 | <p class="form-row form-row-wide validate-required"> |
| 240 | 240 | <select id="stripe-bank-country" class="wc-enhanced-select" name="stripe_sofort_bank_country"> |
| 241 | - <option value="-1"><?php esc_html_e( 'Choose Bank Country', 'woocommerce-gateway-stripe' ); ?></option> |
|
| 242 | - <?php foreach ( $supported_countries as $code => $country ) { ?> |
|
| 243 | - <option value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $country ); ?></option> |
|
| 241 | + <option value="-1"><?php esc_html_e('Choose Bank Country', 'woocommerce-gateway-stripe'); ?></option> |
|
| 242 | + <?php foreach ($supported_countries as $code => $country) { ?> |
|
| 243 | + <option value="<?php echo esc_attr($code); ?>"><?php echo esc_html($country); ?></option> |
|
| 244 | 244 | <?php } ?> |
| 245 | 245 | </select> |
| 246 | 246 | </p> |
| 247 | 247 | |
| 248 | 248 | <!-- Used to display form errors --> |
| 249 | 249 | <div class="stripe-source-errors" role="alert"></div> |
| 250 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
| 250 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
| 251 | 251 | <div class="clear"></div> |
| 252 | 252 | </fieldset> |
| 253 | 253 | <?php |
@@ -261,25 +261,25 @@ discard block |
||
| 261 | 261 | $total = WC()->cart->total; |
| 262 | 262 | |
| 263 | 263 | // If paying from order, we need to get total from order not cart. |
| 264 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 265 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 264 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 265 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 266 | 266 | $total = $order->get_total(); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - if ( is_add_payment_method_page() ) { |
|
| 270 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 271 | - $total = ''; |
|
| 269 | + if (is_add_payment_method_page()) { |
|
| 270 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 271 | + $total = ''; |
|
| 272 | 272 | } else { |
| 273 | 273 | $pay_button_text = ''; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | echo '<div |
| 277 | 277 | id="stripe-sofort-payment-data" |
| 278 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 279 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 278 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 279 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 280 | 280 | |
| 281 | - if ( $this->description ) { |
|
| 282 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 281 | + if ($this->description) { |
|
| 282 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | $this->form(); |
@@ -295,26 +295,26 @@ discard block |
||
| 295 | 295 | * @param object $order |
| 296 | 296 | * @return mixed |
| 297 | 297 | */ |
| 298 | - public function create_source( $order ) { |
|
| 298 | + public function create_source($order) { |
|
| 299 | 299 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 300 | 300 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 301 | - $bank_country = wc_clean( $_POST['stripe_sofort_bank_country'] ); |
|
| 302 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 301 | + $bank_country = wc_clean($_POST['stripe_sofort_bank_country']); |
|
| 302 | + $return_url = $this->get_stripe_return_url($order); |
|
| 303 | 303 | $post_data = array(); |
| 304 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 305 | - $post_data['currency'] = strtolower( $currency ); |
|
| 304 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 305 | + $post_data['currency'] = strtolower($currency); |
|
| 306 | 306 | $post_data['type'] = 'sofort'; |
| 307 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 308 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 309 | - $post_data['sofort'] = array( 'country' => $bank_country ); |
|
| 307 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 308 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 309 | + $post_data['sofort'] = array('country' => $bank_country); |
|
| 310 | 310 | |
| 311 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 312 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 311 | + if ( ! empty($this->statement_descriptor)) { |
|
| 312 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' ); |
|
| 315 | + WC_Stripe_Logger::log('Info: Begin creating SOFORT source'); |
|
| 316 | 316 | |
| 317 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 317 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -328,51 +328,51 @@ discard block |
||
| 328 | 328 | * |
| 329 | 329 | * @return array|void |
| 330 | 330 | */ |
| 331 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 331 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 332 | 332 | try { |
| 333 | - $order = wc_get_order( $order_id ); |
|
| 333 | + $order = wc_get_order($order_id); |
|
| 334 | 334 | |
| 335 | 335 | // This will throw exception if not valid. |
| 336 | - $this->validate_minimum_order_amount( $order ); |
|
| 336 | + $this->validate_minimum_order_amount($order); |
|
| 337 | 337 | |
| 338 | 338 | // This comes from the create account checkbox in the checkout page. |
| 339 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 339 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 340 | 340 | |
| 341 | - if ( $create_account ) { |
|
| 341 | + if ($create_account) { |
|
| 342 | 342 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 343 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 343 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 344 | 344 | $new_stripe_customer->create_customer(); |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - $response = $this->create_source( $order ); |
|
| 347 | + $response = $this->create_source($order); |
|
| 348 | 348 | |
| 349 | - if ( ! empty( $response->error ) ) { |
|
| 350 | - $order->add_order_note( $response->error->message ); |
|
| 349 | + if ( ! empty($response->error)) { |
|
| 350 | + $order->add_order_note($response->error->message); |
|
| 351 | 351 | |
| 352 | - throw new Exception( $response->error->message ); |
|
| 352 | + throw new Exception($response->error->message); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 356 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 355 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 356 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 357 | 357 | } else { |
| 358 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 358 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 359 | 359 | $order->save(); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' ); |
|
| 362 | + WC_Stripe_Logger::log('Info: Redirecting to SOFORT...'); |
|
| 363 | 363 | |
| 364 | 364 | return array( |
| 365 | 365 | 'result' => 'success', |
| 366 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 366 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 367 | 367 | ); |
| 368 | - } catch ( Exception $e ) { |
|
| 369 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 370 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 368 | + } catch (Exception $e) { |
|
| 369 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 370 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 371 | 371 | |
| 372 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 372 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 373 | 373 | |
| 374 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 375 | - $this->send_failed_order_email( $order_id ); |
|
| 374 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 375 | + $this->send_failed_order_email($order_id); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | return array( |