@@ -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 | } |
@@ -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 | } |
@@ -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 | } |