@@ -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,25 +18,25 @@ discard block |
||
| 18 | 18 | public function __construct() { |
| 19 | 19 | parent::__construct(); |
| 20 | 20 | |
| 21 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 22 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 23 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 24 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 25 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 21 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 22 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 23 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 24 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 25 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 26 | 26 | |
| 27 | 27 | // display the credit card used for a subscription in the "My Subscriptions" table |
| 28 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 28 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 29 | 29 | |
| 30 | 30 | // allow store managers to manually set Stripe as the payment method on a subscription |
| 31 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 32 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 31 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 32 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 36 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
| 35 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
| 36 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - $this->wc_pre_30 = version_compare( WC_VERSION, '3.0.0', '<' ); |
|
| 39 | + $this->wc_pre_30 = version_compare(WC_VERSION, '3.0.0', '<'); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | * @param int $order_id |
| 45 | 45 | * @return boolean |
| 46 | 46 | */ |
| 47 | - protected function is_subscription( $order_id ) { |
|
| 48 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 47 | + protected function is_subscription($order_id) { |
|
| 48 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | * @param int $order_id |
| 54 | 54 | * @return boolean |
| 55 | 55 | */ |
| 56 | - protected function is_pre_order( $order_id ) { |
|
| 57 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
| 56 | + protected function is_pre_order($order_id) { |
|
| 57 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -62,40 +62,40 @@ discard block |
||
| 62 | 62 | * @param int $order_id |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
| 66 | - if ( $this->is_subscription( $order_id ) ) { |
|
| 65 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
| 66 | + if ($this->is_subscription($order_id)) { |
|
| 67 | 67 | // Regular payment with force customer enabled |
| 68 | - return parent::process_payment( $order_id, true, true ); |
|
| 68 | + return parent::process_payment($order_id, true, true); |
|
| 69 | 69 | |
| 70 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
| 71 | - return $this->process_pre_order( $order_id, $retry, $force_customer ); |
|
| 70 | + } elseif ($this->is_pre_order($order_id)) { |
|
| 71 | + return $this->process_pre_order($order_id, $retry, $force_customer); |
|
| 72 | 72 | |
| 73 | 73 | } else { |
| 74 | - return parent::process_payment( $order_id, $retry, $force_customer ); |
|
| 74 | + return parent::process_payment($order_id, $retry, $force_customer); |
|
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * Updates other subscription sources. |
| 80 | 80 | */ |
| 81 | - protected function save_source( $order, $source ) { |
|
| 82 | - parent::save_source( $order, $source ); |
|
| 81 | + protected function save_source($order, $source) { |
|
| 82 | + parent::save_source($order, $source); |
|
| 83 | 83 | |
| 84 | - $order_id = $this->wc_pre_30 ? $order->id : $order->get_id(); |
|
| 84 | + $order_id = $this->wc_pre_30 ? $order->id : $order->get_id(); |
|
| 85 | 85 | |
| 86 | 86 | // Also store it on the subscriptions being purchased or paid for in the order |
| 87 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 88 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 89 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 90 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 87 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 88 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 89 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 90 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 91 | 91 | } else { |
| 92 | 92 | $subscriptions = array(); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - foreach ( $subscriptions as $subscription ) { |
|
| 95 | + foreach ($subscriptions as $subscription) { |
|
| 96 | 96 | $subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id(); |
| 97 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 98 | - update_post_meta( $subscription_id, '_stripe_card_id', $source->source ); |
|
| 97 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 98 | + update_post_meta($subscription_id, '_stripe_card_id', $source->source); |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
@@ -106,55 +106,55 @@ discard block |
||
| 106 | 106 | * @param string $stripe_token (default: '') |
| 107 | 107 | * @param bool initial_payment |
| 108 | 108 | */ |
| 109 | - public function process_subscription_payment( $order = '', $amount = 0 ) { |
|
| 110 | - if ( $amount * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 111 | - 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::get_minimum_amount() / 100 ) ) ); |
|
| 109 | + public function process_subscription_payment($order = '', $amount = 0) { |
|
| 110 | + if ($amount * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 111 | + 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::get_minimum_amount() / 100))); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // Get source from order |
| 115 | - $source = $this->get_order_source( $order ); |
|
| 115 | + $source = $this->get_order_source($order); |
|
| 116 | 116 | |
| 117 | 117 | // If no order source was defined, use user source instead. |
| 118 | - if ( ! $source->customer ) { |
|
| 119 | - $source = $this->get_source( ( $this->wc_pre_30 ? $order->customer_user : $order->get_customer_id() ) ); |
|
| 118 | + if ( ! $source->customer) { |
|
| 119 | + $source = $this->get_source(($this->wc_pre_30 ? $order->customer_user : $order->get_customer_id())); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Or fail :( |
| 123 | - if ( ! $source->customer ) { |
|
| 124 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 123 | + if ( ! $source->customer) { |
|
| 124 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $order_id = $this->wc_pre_30 ? $order->id : $order->get_id(); |
| 128 | - $this->log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 128 | + $this->log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 129 | 129 | |
| 130 | 130 | // Make the request |
| 131 | - $request = $this->generate_payment_request( $order, $source ); |
|
| 131 | + $request = $this->generate_payment_request($order, $source); |
|
| 132 | 132 | $request['capture'] = 'true'; |
| 133 | - $request['amount'] = $this->get_stripe_amount( $amount, $request['currency'] ); |
|
| 133 | + $request['amount'] = $this->get_stripe_amount($amount, $request['currency']); |
|
| 134 | 134 | $request['metadata'] = array( |
| 135 | 135 | 'payment_type' => 'recurring', |
| 136 | - 'site_url' => esc_url( get_site_url() ), |
|
| 136 | + 'site_url' => esc_url(get_site_url()), |
|
| 137 | 137 | ); |
| 138 | - $response = WC_Stripe_API::request( $request ); |
|
| 138 | + $response = WC_Stripe_API::request($request); |
|
| 139 | 139 | |
| 140 | 140 | // Process valid response |
| 141 | - if ( is_wp_error( $response ) ) { |
|
| 142 | - if ( 'missing' === $response->get_error_code() ) { |
|
| 141 | + if (is_wp_error($response)) { |
|
| 142 | + if ('missing' === $response->get_error_code()) { |
|
| 143 | 143 | // If we can't link customer to a card, we try to charge by customer ID. |
| 144 | - $request = $this->generate_payment_request( $order, $this->get_source( ( $this->wc_pre_30 ? $order->customer_user : $order->get_customer_id() ) ) ); |
|
| 144 | + $request = $this->generate_payment_request($order, $this->get_source(($this->wc_pre_30 ? $order->customer_user : $order->get_customer_id()))); |
|
| 145 | 145 | $request['capture'] = 'true'; |
| 146 | - $request['amount'] = $this->get_stripe_amount( $amount, $request['currency'] ); |
|
| 146 | + $request['amount'] = $this->get_stripe_amount($amount, $request['currency']); |
|
| 147 | 147 | $request['metadata'] = array( |
| 148 | 148 | 'payment_type' => 'recurring', |
| 149 | - 'site_url' => esc_url( get_site_url() ), |
|
| 149 | + 'site_url' => esc_url(get_site_url()), |
|
| 150 | 150 | ); |
| 151 | - $response = WC_Stripe_API::request( $request ); |
|
| 151 | + $response = WC_Stripe_API::request($request); |
|
| 152 | 152 | } else { |
| 153 | 153 | return $response; // Default catch all errors. |
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - $this->process_response( $response, $order ); |
|
| 157 | + $this->process_response($response, $order); |
|
| 158 | 158 | |
| 159 | 159 | return $response; |
| 160 | 160 | } |
@@ -164,42 +164,42 @@ discard block |
||
| 164 | 164 | * @param int $order_id |
| 165 | 165 | * @return array |
| 166 | 166 | */ |
| 167 | - public function process_pre_order( $order_id, $retry, $force_customer ) { |
|
| 168 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
| 167 | + public function process_pre_order($order_id, $retry, $force_customer) { |
|
| 168 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
| 169 | 169 | try { |
| 170 | - $order = wc_get_order( $order_id ); |
|
| 170 | + $order = wc_get_order($order_id); |
|
| 171 | 171 | |
| 172 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 173 | - 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::get_minimum_amount() / 100 ) ) ); |
|
| 172 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 173 | + 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::get_minimum_amount() / 100))); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - $source = $this->get_source( get_current_user_id(), true ); |
|
| 176 | + $source = $this->get_source(get_current_user_id(), true); |
|
| 177 | 177 | |
| 178 | 178 | // We need a source on file to continue. |
| 179 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 180 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 179 | + if (empty($source->customer) || empty($source->source)) { |
|
| 180 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // Store source to order meta |
| 184 | - $this->save_source( $order, $source ); |
|
| 184 | + $this->save_source($order, $source); |
|
| 185 | 185 | |
| 186 | 186 | // Remove cart |
| 187 | 187 | WC()->cart->empty_cart(); |
| 188 | 188 | |
| 189 | 189 | // Is pre ordered! |
| 190 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 190 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 191 | 191 | |
| 192 | 192 | // Return thank you page redirect |
| 193 | 193 | return array( |
| 194 | 194 | 'result' => 'success', |
| 195 | - 'redirect' => $this->get_return_url( $order ), |
|
| 195 | + 'redirect' => $this->get_return_url($order), |
|
| 196 | 196 | ); |
| 197 | - } catch ( Exception $e ) { |
|
| 198 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 197 | + } catch (Exception $e) { |
|
| 198 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 199 | 199 | return; |
| 200 | 200 | } |
| 201 | 201 | } else { |
| 202 | - return parent::process_payment( $order_id, $retry, $force_customer ); |
|
| 202 | + return parent::process_payment($order_id, $retry, $force_customer); |
|
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @param WC_Order $order |
| 209 | 209 | * @return void |
| 210 | 210 | */ |
| 211 | - public function process_pre_order_release_payment( $order ) { |
|
| 211 | + public function process_pre_order_release_payment($order) { |
|
| 212 | 212 | try { |
| 213 | 213 | // Define some callbacks if the first attempt fails. |
| 214 | 214 | $retry_callbacks = array( |
@@ -216,32 +216,32 @@ discard block |
||
| 216 | 216 | 'remove_order_customer_before_retry', |
| 217 | 217 | ); |
| 218 | 218 | |
| 219 | - while ( 1 ) { |
|
| 220 | - $source = $this->get_order_source( $order ); |
|
| 221 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 219 | + while (1) { |
|
| 220 | + $source = $this->get_order_source($order); |
|
| 221 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 222 | 222 | |
| 223 | - if ( is_wp_error( $response ) ) { |
|
| 224 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
| 225 | - throw new Exception( $response->get_error_message() ); |
|
| 223 | + if (is_wp_error($response)) { |
|
| 224 | + if (0 === sizeof($retry_callbacks)) { |
|
| 225 | + throw new Exception($response->get_error_message()); |
|
| 226 | 226 | } else { |
| 227 | - $retry_callback = array_shift( $retry_callbacks ); |
|
| 228 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
| 227 | + $retry_callback = array_shift($retry_callbacks); |
|
| 228 | + call_user_func(array($this, $retry_callback), $order); |
|
| 229 | 229 | } |
| 230 | 230 | } else { |
| 231 | 231 | // Successful |
| 232 | - $this->process_response( $response, $order ); |
|
| 232 | + $this->process_response($response, $order); |
|
| 233 | 233 | break; |
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | - } catch ( Exception $e ) { |
|
| 237 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
| 236 | + } catch (Exception $e) { |
|
| 237 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
| 238 | 238 | |
| 239 | 239 | // Mark order as failed if not already set, |
| 240 | 240 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
| 241 | - if ( ! $order->has_status( 'failed' ) ) { |
|
| 242 | - $order->update_status( 'failed', $order_note ); |
|
| 241 | + if ( ! $order->has_status('failed')) { |
|
| 242 | + $order->update_status('failed', $order_note); |
|
| 243 | 243 | } else { |
| 244 | - $order->add_order_note( $order_note ); |
|
| 244 | + $order->add_order_note($order_note); |
|
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | } |
@@ -250,20 +250,20 @@ discard block |
||
| 250 | 250 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 251 | 251 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 252 | 252 | */ |
| 253 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 254 | - delete_post_meta( ( $this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 255 | - delete_post_meta( ( $this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 256 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 253 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 254 | + delete_post_meta(($this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 255 | + delete_post_meta(($this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 256 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | 260 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 261 | 261 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 262 | 262 | */ |
| 263 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 264 | - delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
| 265 | - delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
| 266 | - delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Payment ID' ); |
|
| 263 | + public function delete_renewal_meta($renewal_order) { |
|
| 264 | + delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
| 265 | + delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
| 266 | + delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Payment ID'); |
|
| 267 | 267 | return $renewal_order; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -273,11 +273,11 @@ discard block |
||
| 273 | 273 | * @param $amount_to_charge float The amount to charge. |
| 274 | 274 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 275 | 275 | */ |
| 276 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 277 | - $response = $this->process_subscription_payment( $renewal_order, $amount_to_charge ); |
|
| 276 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 277 | + $response = $this->process_subscription_payment($renewal_order, $amount_to_charge); |
|
| 278 | 278 | |
| 279 | - if ( is_wp_error( $response ) ) { |
|
| 280 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 279 | + if (is_wp_error($response)) { |
|
| 280 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | |
@@ -285,18 +285,18 @@ discard block |
||
| 285 | 285 | * Remove order meta |
| 286 | 286 | * @param object $order |
| 287 | 287 | */ |
| 288 | - public function remove_order_source_before_retry( $order ) { |
|
| 288 | + public function remove_order_source_before_retry($order) { |
|
| 289 | 289 | $order_id = $this->wc_pre_30 ? $order->id : $order->get_id(); |
| 290 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
| 290 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | 294 | * Remove order meta |
| 295 | 295 | * @param object $order |
| 296 | 296 | */ |
| 297 | - public function remove_order_customer_before_retry( $order ) { |
|
| 297 | + public function remove_order_customer_before_retry($order) { |
|
| 298 | 298 | $order_id = $this->wc_pre_30 ? $order->id : $order->get_id(); |
| 299 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 299 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -308,13 +308,13 @@ discard block |
||
| 308 | 308 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 309 | 309 | * @return void |
| 310 | 310 | */ |
| 311 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 312 | - if ( $this->wc_pre_30 ) { |
|
| 313 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 314 | - update_post_meta( $subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id ); |
|
| 311 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 312 | + if ($this->wc_pre_30) { |
|
| 313 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 314 | + update_post_meta($subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id); |
|
| 315 | 315 | } else { |
| 316 | - $subscription->update_meta_data( '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 317 | - $subscription->update_meta_data( '_stripe_card_id', $renewal_order->get_meta( '_stripe_card_id', true ) ); |
|
| 316 | + $subscription->update_meta_data('_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 317 | + $subscription->update_meta_data('_stripe_card_id', $renewal_order->get_meta('_stripe_card_id', true)); |
|
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | |
@@ -327,15 +327,15 @@ discard block |
||
| 327 | 327 | * @param WC_Subscription $subscription An instance of a subscription object |
| 328 | 328 | * @return array |
| 329 | 329 | */ |
| 330 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 331 | - $payment_meta[ $this->id ] = array( |
|
| 330 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 331 | + $payment_meta[$this->id] = array( |
|
| 332 | 332 | 'post_meta' => array( |
| 333 | 333 | '_stripe_customer_id' => array( |
| 334 | - 'value' => get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
| 334 | + 'value' => get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
| 335 | 335 | 'label' => 'Stripe Customer ID', |
| 336 | 336 | ), |
| 337 | 337 | '_stripe_card_id' => array( |
| 338 | - 'value' => get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ), |
|
| 338 | + 'value' => get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true), |
|
| 339 | 339 | 'label' => 'Stripe Card ID', |
| 340 | 340 | ), |
| 341 | 341 | ), |
@@ -352,17 +352,17 @@ discard block |
||
| 352 | 352 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 353 | 353 | * @return array |
| 354 | 354 | */ |
| 355 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 356 | - if ( $this->id === $payment_method_id ) { |
|
| 355 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 356 | + if ($this->id === $payment_method_id) { |
|
| 357 | 357 | |
| 358 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 359 | - throw new Exception( 'A "_stripe_customer_id" value is required.' ); |
|
| 360 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 361 | - throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' ); |
|
| 358 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 359 | + throw new Exception('A "_stripe_customer_id" value is required.'); |
|
| 360 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 361 | + throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".'); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - if ( ! empty( $payment_meta['post_meta']['_stripe_card_id']['value'] ) && 0 !== strpos( $payment_meta['post_meta']['_stripe_card_id']['value'], 'card_' ) ) { |
|
| 365 | - throw new Exception( 'Invalid card ID. A valid "_stripe_card_id" must begin with "card_".' ); |
|
| 364 | + if ( ! empty($payment_meta['post_meta']['_stripe_card_id']['value']) && 0 !== strpos($payment_meta['post_meta']['_stripe_card_id']['value'], 'card_')) { |
|
| 365 | + throw new Exception('Invalid card ID. A valid "_stripe_card_id" must begin with "card_".'); |
|
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | } |
@@ -375,45 +375,45 @@ discard block |
||
| 375 | 375 | * @param WC_Subscription $subscription the subscription details |
| 376 | 376 | * @return string the subscription payment method |
| 377 | 377 | */ |
| 378 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 378 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 379 | 379 | $customer_user = $this->wc_pre_30 ? $subscription->customer_user : $subscription->get_customer_id(); |
| 380 | 380 | |
| 381 | 381 | // bail for other payment methods |
| 382 | - if ( $this->id !== ( $this->wc_pre_30 ? $subscription->payment_method : $subscription->get_payment_method() ) || ! $customer_user ) { |
|
| 382 | + if ($this->id !== ($this->wc_pre_30 ? $subscription->payment_method : $subscription->get_payment_method()) || ! $customer_user) { |
|
| 383 | 383 | return $payment_method_to_display; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $stripe_customer = new WC_Stripe_Customer(); |
| 387 | - $stripe_customer_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 388 | - $stripe_card_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 387 | + $stripe_customer_id = get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 388 | + $stripe_card_id = get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 389 | 389 | |
| 390 | 390 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 391 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 391 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 392 | 392 | $user_id = $customer_user; |
| 393 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 394 | - $stripe_card_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 393 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 394 | + $stripe_card_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 398 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 399 | - $stripe_customer_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 400 | - $stripe_card_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 398 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 399 | + $stripe_customer_id = get_post_meta(($this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 400 | + $stripe_card_id = get_post_meta(($this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 403 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 404 | 404 | $cards = $stripe_customer->get_cards(); |
| 405 | 405 | |
| 406 | - if ( $cards ) { |
|
| 406 | + if ($cards) { |
|
| 407 | 407 | $found_card = false; |
| 408 | - foreach ( $cards as $card ) { |
|
| 409 | - if ( $card->id === $stripe_card_id ) { |
|
| 408 | + foreach ($cards as $card) { |
|
| 409 | + if ($card->id === $stripe_card_id) { |
|
| 410 | 410 | $found_card = true; |
| 411 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->type ) ? $card->type : $card->brand ), $card->last4 ); |
|
| 411 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->type) ? $card->type : $card->brand), $card->last4); |
|
| 412 | 412 | break; |
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | - if ( ! $found_card ) { |
|
| 416 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $cards[0]->type ) ? $cards[0]->type : $cards[0]->brand ), $cards[0]->last4 ); |
|
| 415 | + if ( ! $found_card) { |
|
| 416 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($cards[0]->type) ? $cards[0]->type : $cards[0]->brand), $cards[0]->last4); |
|
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | 419 | |
@@ -428,11 +428,11 @@ discard block |
||
| 428 | 428 | * |
| 429 | 429 | * @param string $message |
| 430 | 430 | */ |
| 431 | - public function log( $message ) { |
|
| 432 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 431 | + public function log($message) { |
|
| 432 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 433 | 433 | |
| 434 | - if ( 'yes' === $options['logging'] ) { |
|
| 435 | - WC_Stripe::log( $message ); |
|
| 434 | + if ('yes' === $options['logging']) { |
|
| 435 | + WC_Stripe::log($message); |
|
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function __construct() { |
| 122 | 122 | $this->id = 'stripe'; |
| 123 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
| 124 | - $this->method_description = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
| 123 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
| 124 | + $this->method_description = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
| 125 | 125 | $this->has_fields = true; |
| 126 | 126 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
| 127 | 127 | $this->supports = array( |
@@ -149,43 +149,43 @@ discard block |
||
| 149 | 149 | $this->init_settings(); |
| 150 | 150 | |
| 151 | 151 | // Get setting values. |
| 152 | - $this->title = $this->get_option( 'title' ); |
|
| 153 | - $this->description = $this->get_option( 'description' ); |
|
| 154 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 155 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
| 156 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
| 157 | - $this->statement_descriptor = $this->get_option( 'statement_descriptor', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
|
| 158 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
| 159 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
| 160 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
| 161 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
| 162 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 163 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
| 164 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
| 165 | - $this->apple_pay = 'yes' === $this->get_option( 'apple_pay', 'yes' ); |
|
| 166 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
| 167 | - $this->apple_pay_button = $this->get_option( 'apple_pay_button', 'black' ); |
|
| 168 | - $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
| 152 | + $this->title = $this->get_option('title'); |
|
| 153 | + $this->description = $this->get_option('description'); |
|
| 154 | + $this->enabled = $this->get_option('enabled'); |
|
| 155 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
| 156 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
| 157 | + $this->statement_descriptor = $this->get_option('statement_descriptor', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); |
|
| 158 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
| 159 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
| 160 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
| 161 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
| 162 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 163 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
| 164 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
| 165 | + $this->apple_pay = 'yes' === $this->get_option('apple_pay', 'yes'); |
|
| 166 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
| 167 | + $this->apple_pay_button = $this->get_option('apple_pay_button', 'black'); |
|
| 168 | + $this->logging = 'yes' === $this->get_option('logging'); |
|
| 169 | 169 | $this->apple_pay_verify_notice = ''; |
| 170 | 170 | |
| 171 | - if ( $this->stripe_checkout ) { |
|
| 172 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
| 171 | + if ($this->stripe_checkout) { |
|
| 172 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - if ( $this->testmode ) { |
|
| 176 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
| 177 | - $this->description = trim( $this->description ); |
|
| 175 | + if ($this->testmode) { |
|
| 176 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
| 177 | + $this->description = trim($this->description); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
| 180 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
| 181 | 181 | |
| 182 | 182 | $this->init_apple_pay(); |
| 183 | 183 | |
| 184 | 184 | // Hooks. |
| 185 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 186 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
| 187 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 188 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 185 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 186 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
| 187 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 188 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -195,26 +195,26 @@ discard block |
||
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | 197 | public function get_icon() { |
| 198 | - $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
| 199 | - $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
| 198 | + $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
| 199 | + $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
| 200 | 200 | |
| 201 | - $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 202 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 203 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 201 | + $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
| 202 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
| 203 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
| 204 | 204 | |
| 205 | 205 | $base_location = wc_get_base_location(); |
| 206 | 206 | |
| 207 | - if ( 'US' === $base_location['country'] ) { |
|
| 208 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 209 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 210 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 207 | + if ('US' === $base_location['country']) { |
|
| 208 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
| 209 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
| 210 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
| 214 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
| 213 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
| 214 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="24" ' . $style . ' />'; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
| 217 | + return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -225,11 +225,11 @@ discard block |
||
| 225 | 225 | * |
| 226 | 226 | * @return float|int |
| 227 | 227 | */ |
| 228 | - public function get_stripe_amount( $total, $currency = '' ) { |
|
| 229 | - if ( ! $currency ) { |
|
| 228 | + public function get_stripe_amount($total, $currency = '') { |
|
| 229 | + if ( ! $currency) { |
|
| 230 | 230 | $currency = get_woocommerce_currency(); |
| 231 | 231 | } |
| 232 | - switch ( strtoupper( $currency ) ) { |
|
| 232 | + switch (strtoupper($currency)) { |
|
| 233 | 233 | // Zero decimal currencies. |
| 234 | 234 | case 'BIF' : |
| 235 | 235 | case 'CLP' : |
@@ -246,10 +246,10 @@ discard block |
||
| 246 | 246 | case 'XAF' : |
| 247 | 247 | case 'XOF' : |
| 248 | 248 | case 'XPF' : |
| 249 | - $total = absint( $total ); |
|
| 249 | + $total = absint($total); |
|
| 250 | 250 | break; |
| 251 | 251 | default : |
| 252 | - $total = round( $total, 2 ) * 100; // In cents. |
|
| 252 | + $total = round($total, 2) * 100; // In cents. |
|
| 253 | 253 | break; |
| 254 | 254 | } |
| 255 | 255 | return $total; |
@@ -264,9 +264,9 @@ discard block |
||
| 264 | 264 | public function init_apple_pay() { |
| 265 | 265 | if ( |
| 266 | 266 | is_admin() && |
| 267 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
| 268 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
| 269 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
| 267 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
| 268 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
| 269 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
| 270 | 270 | $this->apple_pay |
| 271 | 271 | ) { |
| 272 | 272 | $this->process_apple_pay_verification(); |
@@ -280,9 +280,9 @@ discard block |
||
| 280 | 280 | * @version 3.1.0 |
| 281 | 281 | * @param string $secret_key |
| 282 | 282 | */ |
| 283 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
| 284 | - if ( empty( $secret_key ) ) { |
|
| 285 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
| 283 | + private function register_apple_pay_domain($secret_key = '') { |
|
| 284 | + if (empty($secret_key)) { |
|
| 285 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -296,21 +296,21 @@ discard block |
||
| 296 | 296 | 'Authorization' => 'Bearer ' . $secret_key, |
| 297 | 297 | ); |
| 298 | 298 | |
| 299 | - $response = wp_remote_post( $endpoint, array( |
|
| 299 | + $response = wp_remote_post($endpoint, array( |
|
| 300 | 300 | 'headers' => $headers, |
| 301 | - 'body' => http_build_query( $data ), |
|
| 302 | - ) ); |
|
| 301 | + 'body' => http_build_query($data), |
|
| 302 | + )); |
|
| 303 | 303 | |
| 304 | - if ( is_wp_error( $response ) ) { |
|
| 305 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 304 | + if (is_wp_error($response)) { |
|
| 305 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - if ( 200 !== $response['response']['code'] ) { |
|
| 309 | - $parsed_response = json_decode( $response['body'] ); |
|
| 308 | + if (200 !== $response['response']['code']) { |
|
| 309 | + $parsed_response = json_decode($response['body']); |
|
| 310 | 310 | |
| 311 | 311 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
| 312 | 312 | |
| 313 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
| 313 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | |
@@ -321,48 +321,48 @@ discard block |
||
| 321 | 321 | * @version 3.1.0 |
| 322 | 322 | */ |
| 323 | 323 | public function process_apple_pay_verification() { |
| 324 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', '' ); |
|
| 324 | + $gateway_settings = get_option('woocommerce_stripe_settings', ''); |
|
| 325 | 325 | |
| 326 | 326 | try { |
| 327 | - $path = untrailingslashit( preg_replace( "!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] ) ); |
|
| 327 | + $path = untrailingslashit(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'])); |
|
| 328 | 328 | $dir = '.well-known'; |
| 329 | 329 | $file = 'apple-developer-merchantid-domain-association'; |
| 330 | 330 | $fullpath = $path . '/' . $dir . '/' . $file; |
| 331 | 331 | |
| 332 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
| 332 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
| 333 | 333 | return; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
| 337 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
| 338 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 336 | + if ( ! file_exists($path . '/' . $dir)) { |
|
| 337 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
| 338 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
| 339 | 339 | } |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - if ( ! file_exists( $fullpath ) ) { |
|
| 343 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
| 344 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 342 | + if ( ! file_exists($fullpath)) { |
|
| 343 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
| 344 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
| 345 | 345 | } |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | // At this point then the domain association folder and file should be available. |
| 349 | 349 | // Proceed to verify/and or verify again. |
| 350 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
| 350 | + $this->register_apple_pay_domain($this->secret_key); |
|
| 351 | 351 | |
| 352 | 352 | // No errors to this point, verification success! |
| 353 | 353 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
| 354 | 354 | $this->apple_pay_domain_set = true; |
| 355 | 355 | |
| 356 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 356 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 357 | 357 | |
| 358 | - $this->log( __( 'Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe' ) ); |
|
| 358 | + $this->log(__('Your domain has been verified with Apple Pay!', 'woocommerce-gateway-stripe')); |
|
| 359 | 359 | |
| 360 | - } catch ( Exception $e ) { |
|
| 360 | + } catch (Exception $e) { |
|
| 361 | 361 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
| 362 | 362 | |
| 363 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 363 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 364 | 364 | |
| 365 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 365 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | |
@@ -370,11 +370,11 @@ discard block |
||
| 370 | 370 | * Check if SSL is enabled and notify the user |
| 371 | 371 | */ |
| 372 | 372 | public function admin_notices() { |
| 373 | - if ( 'no' === $this->enabled ) { |
|
| 373 | + if ('no' === $this->enabled) { |
|
| 374 | 374 | return; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if ( $this->apple_pay && ! empty( $this->apple_pay_verify_notice ) ) { |
|
| 377 | + if ($this->apple_pay && ! empty($this->apple_pay_verify_notice)) { |
|
| 378 | 378 | $allowed_html = array( |
| 379 | 379 | 'a' => array( |
| 380 | 380 | 'href' => array(), |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | ), |
| 383 | 383 | ); |
| 384 | 384 | |
| 385 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
| 385 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -390,13 +390,13 @@ discard block |
||
| 390 | 390 | * when setting screen is displayed. So if domain verification is not set, |
| 391 | 391 | * something went wrong so lets notify user. |
| 392 | 392 | */ |
| 393 | - if ( ! empty( $this->secret_key ) && $this->apple_pay && ! $this->apple_pay_domain_set ) { |
|
| 394 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
| 393 | + if ( ! empty($this->secret_key) && $this->apple_pay && ! $this->apple_pay_domain_set) { |
|
| 394 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
| 398 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
| 399 | - echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>'; |
|
| 398 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
| 399 | + echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>'; |
|
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | |
@@ -404,11 +404,11 @@ discard block |
||
| 404 | 404 | * Check if this gateway is enabled |
| 405 | 405 | */ |
| 406 | 406 | public function is_available() { |
| 407 | - if ( 'yes' === $this->enabled ) { |
|
| 408 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
| 407 | + if ('yes' === $this->enabled) { |
|
| 408 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
| 409 | 409 | return false; |
| 410 | 410 | } |
| 411 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
| 411 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
| 412 | 412 | return false; |
| 413 | 413 | } |
| 414 | 414 | return true; |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | * Initialise Gateway Settings Form Fields |
| 421 | 421 | */ |
| 422 | 422 | public function init_form_fields() { |
| 423 | - $this->form_fields = include( 'settings-stripe.php' ); |
|
| 423 | + $this->form_fields = include('settings-stripe.php'); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -428,55 +428,55 @@ discard block |
||
| 428 | 428 | */ |
| 429 | 429 | public function payment_fields() { |
| 430 | 430 | $user = wp_get_current_user(); |
| 431 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
| 431 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
| 432 | 432 | $total = WC()->cart->total; |
| 433 | 433 | |
| 434 | 434 | // If paying from order, we need to get total from order not cart. |
| 435 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 436 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 435 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 436 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 437 | 437 | $total = $order->get_total(); |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - if ( $user->ID ) { |
|
| 441 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 440 | + if ($user->ID) { |
|
| 441 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 442 | 442 | $user_email = $user_email ? $user_email : $user->user_email; |
| 443 | 443 | } else { |
| 444 | 444 | $user_email = ''; |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - if ( is_add_payment_method_page() ) { |
|
| 448 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
| 449 | - $total = ''; |
|
| 447 | + if (is_add_payment_method_page()) { |
|
| 448 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
| 449 | + $total = ''; |
|
| 450 | 450 | } else { |
| 451 | 451 | $pay_button_text = ''; |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | echo '<div |
| 455 | 455 | id="stripe-payment-data" |
| 456 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
| 456 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
| 457 | 457 | data-description="" |
| 458 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 459 | - data-amount="' . esc_attr( $this->get_stripe_amount( $total ) ) . '" |
|
| 460 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
| 461 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 462 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
| 463 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
| 464 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
| 465 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
| 458 | + data-email="' . esc_attr($user_email) . '" |
|
| 459 | + data-amount="' . esc_attr($this->get_stripe_amount($total)) . '" |
|
| 460 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
| 461 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 462 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
| 463 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
| 464 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
| 465 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
| 466 | 466 | |
| 467 | - if ( $this->description ) { |
|
| 468 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 467 | + if ($this->description) { |
|
| 468 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - if ( $display_tokenization ) { |
|
| 471 | + if ($display_tokenization) { |
|
| 472 | 472 | $this->tokenization_script(); |
| 473 | 473 | $this->saved_payment_methods(); |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - if ( ! $this->stripe_checkout ) { |
|
| 476 | + if ( ! $this->stripe_checkout) { |
|
| 477 | 477 | $this->form(); |
| 478 | 478 | |
| 479 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) ) { |
|
| 479 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization)) { |
|
| 480 | 480 | $this->save_payment_method_checkbox(); |
| 481 | 481 | } |
| 482 | 482 | } |
@@ -492,20 +492,20 @@ discard block |
||
| 492 | 492 | * @return array |
| 493 | 493 | */ |
| 494 | 494 | public function get_localized_messages() { |
| 495 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
| 496 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
| 497 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 498 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 499 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
| 500 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 501 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
| 502 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
| 503 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
| 504 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
| 505 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
| 506 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
| 507 | - 'invalid_request_error' => __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ), |
|
| 508 | - ) ); |
|
| 495 | + return apply_filters('wc_stripe_localized_messages', array( |
|
| 496 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
| 497 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
| 498 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
| 499 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
| 500 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 501 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
| 502 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
| 503 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
| 504 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
| 505 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
| 506 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
| 507 | + 'invalid_request_error' => __('Could not find payment information.', 'woocommerce-gateway-stripe'), |
|
| 508 | + )); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | /** |
@@ -515,28 +515,28 @@ discard block |
||
| 515 | 515 | * @version 3.1.0 |
| 516 | 516 | */ |
| 517 | 517 | public function admin_scripts() { |
| 518 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
| 518 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
| 519 | 519 | return; |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 522 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 523 | 523 | |
| 524 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
| 524 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
| 525 | 525 | |
| 526 | 526 | $stripe_admin_params = array( |
| 527 | 527 | 'localized_messages' => array( |
| 528 | - 'not_valid_live_key_msg' => __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ), |
|
| 529 | - 'not_valid_test_key_msg' => __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ), |
|
| 530 | - 're_verify_button_text' => __( 'Re-verify Domain', 'woocommerce-gateway-stripe' ), |
|
| 531 | - 'missing_secret_key' => __( 'Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe' ), |
|
| 528 | + 'not_valid_live_key_msg' => __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe'), |
|
| 529 | + 'not_valid_test_key_msg' => __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe'), |
|
| 530 | + 're_verify_button_text' => __('Re-verify Domain', 'woocommerce-gateway-stripe'), |
|
| 531 | + 'missing_secret_key' => __('Missing Secret Key. Please set the secret key field above and re-try.', 'woocommerce-gateway-stripe'), |
|
| 532 | 532 | ), |
| 533 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
| 533 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
| 534 | 534 | 'nonce' => array( |
| 535 | - 'apple_pay_domain_nonce' => wp_create_nonce( '_wc_stripe_apple_pay_domain_nonce' ), |
|
| 535 | + 'apple_pay_domain_nonce' => wp_create_nonce('_wc_stripe_apple_pay_domain_nonce'), |
|
| 536 | 536 | ), |
| 537 | 537 | ); |
| 538 | 538 | |
| 539 | - wp_localize_script( 'woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters( 'wc_stripe_admin_params', $stripe_admin_params ) ); |
|
| 539 | + wp_localize_script('woocommerce_stripe_admin', 'wc_stripe_admin_params', apply_filters('wc_stripe_admin_params', $stripe_admin_params)); |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | /** |
@@ -547,49 +547,49 @@ discard block |
||
| 547 | 547 | * @access public |
| 548 | 548 | */ |
| 549 | 549 | public function payment_scripts() { |
| 550 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 550 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 551 | 551 | return; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 554 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 555 | 555 | |
| 556 | - if ( $this->stripe_checkout ) { |
|
| 557 | - wp_enqueue_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
| 558 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe_checkout' ), WC_STRIPE_VERSION, true ); |
|
| 556 | + if ($this->stripe_checkout) { |
|
| 557 | + wp_enqueue_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
| 558 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe-checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe_checkout'), WC_STRIPE_VERSION, true); |
|
| 559 | 559 | } else { |
| 560 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
| 561 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 560 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
| 561 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | $stripe_params = array( |
| 565 | 565 | 'key' => $this->publishable_key, |
| 566 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 567 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 566 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 567 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 568 | 568 | ); |
| 569 | 569 | |
| 570 | 570 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 571 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
| 572 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
| 573 | - $order = wc_get_order( $order_id ); |
|
| 571 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
| 572 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
| 573 | + $order = wc_get_order($order_id); |
|
| 574 | 574 | |
| 575 | - $stripe_params['billing_first_name'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
| 576 | - $stripe_params['billing_last_name'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
| 577 | - $stripe_params['billing_address_1'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
| 578 | - $stripe_params['billing_address_2'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
| 579 | - $stripe_params['billing_state'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_state : $order->get_billing_state(); |
|
| 580 | - $stripe_params['billing_city'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_city : $order->get_billing_city(); |
|
| 581 | - $stripe_params['billing_postcode'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_postcode : $order->get_billing_postcode(); |
|
| 582 | - $stripe_params['billing_country'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_country : $order->get_billing_country(); |
|
| 575 | + $stripe_params['billing_first_name'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
| 576 | + $stripe_params['billing_last_name'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
| 577 | + $stripe_params['billing_address_1'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
| 578 | + $stripe_params['billing_address_2'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
| 579 | + $stripe_params['billing_state'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_state : $order->get_billing_state(); |
|
| 580 | + $stripe_params['billing_city'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_city : $order->get_billing_city(); |
|
| 581 | + $stripe_params['billing_postcode'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_postcode : $order->get_billing_postcode(); |
|
| 582 | + $stripe_params['billing_country'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_country : $order->get_billing_country(); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ); |
|
| 586 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
| 587 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
| 585 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'); |
|
| 586 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
| 587 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
| 588 | 588 | |
| 589 | 589 | // merge localized messages to be use in JS |
| 590 | - $stripe_params = array_merge( $stripe_params, $this->get_localized_messages() ); |
|
| 590 | + $stripe_params = array_merge($stripe_params, $this->get_localized_messages()); |
|
| 591 | 591 | |
| 592 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 592 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -598,35 +598,35 @@ discard block |
||
| 598 | 598 | * @param object $source |
| 599 | 599 | * @return array() |
| 600 | 600 | */ |
| 601 | - protected function generate_payment_request( $order, $source ) { |
|
| 601 | + protected function generate_payment_request($order, $source) { |
|
| 602 | 602 | $post_data = array(); |
| 603 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
| 604 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
| 605 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $this->statement_descriptor, $order->get_order_number() ); |
|
| 603 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
| 604 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
| 605 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $this->statement_descriptor, $order->get_order_number()); |
|
| 606 | 606 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
| 607 | 607 | |
| 608 | - $billing_email = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
| 609 | - $billing_first_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
| 610 | - $billing_last_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
| 608 | + $billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
| 609 | + $billing_first_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
| 610 | + $billing_last_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
| 611 | 611 | |
| 612 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
| 612 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
| 613 | 613 | $post_data['receipt_email'] = $billing_email; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | - $post_data['expand[]'] = 'balance_transaction'; |
|
| 616 | + $post_data['expand[]'] = 'balance_transaction'; |
|
| 617 | 617 | |
| 618 | 618 | $metadata = array( |
| 619 | - __( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
| 620 | - __( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
| 619 | + __('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
| 620 | + __('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
| 621 | 621 | ); |
| 622 | 622 | |
| 623 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
| 623 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
| 624 | 624 | |
| 625 | - if ( $source->customer ) { |
|
| 625 | + if ($source->customer) { |
|
| 626 | 626 | $post_data['customer'] = $source->customer; |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - if ( $source->source ) { |
|
| 629 | + if ($source->source) { |
|
| 630 | 630 | $post_data['source'] = $source->source; |
| 631 | 631 | } |
| 632 | 632 | |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | * @param WC_Order $order |
| 639 | 639 | * @param object $source |
| 640 | 640 | */ |
| 641 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
| 641 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | /** |
@@ -650,38 +650,38 @@ discard block |
||
| 650 | 650 | * @throws Exception When card was not added or for and invalid card. |
| 651 | 651 | * @return object |
| 652 | 652 | */ |
| 653 | - protected function get_source( $user_id, $force_customer = false ) { |
|
| 654 | - $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
| 655 | - $force_customer = apply_filters( 'wc_stripe_force_customer_creation', $force_customer, $stripe_customer ); |
|
| 653 | + protected function get_source($user_id, $force_customer = false) { |
|
| 654 | + $stripe_customer = new WC_Stripe_Customer($user_id); |
|
| 655 | + $force_customer = apply_filters('wc_stripe_force_customer_creation', $force_customer, $stripe_customer); |
|
| 656 | 656 | $stripe_source = false; |
| 657 | 657 | $token_id = false; |
| 658 | 658 | |
| 659 | 659 | // New CC info was entered and we have a new token to process |
| 660 | - if ( isset( $_POST['stripe_token'] ) ) { |
|
| 661 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
| 662 | - $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
| 660 | + if (isset($_POST['stripe_token'])) { |
|
| 661 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
| 662 | + $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
| 663 | 663 | |
| 664 | 664 | // This is true if the user wants to store the card to their account. |
| 665 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
| 666 | - $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
| 665 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
| 666 | + $stripe_source = $stripe_customer->add_card($stripe_token); |
|
| 667 | 667 | |
| 668 | - if ( is_wp_error( $stripe_source ) ) { |
|
| 669 | - throw new Exception( $stripe_source->get_error_message() ); |
|
| 668 | + if (is_wp_error($stripe_source)) { |
|
| 669 | + throw new Exception($stripe_source->get_error_message()); |
|
| 670 | 670 | } |
| 671 | 671 | } else { |
| 672 | 672 | // Not saving token, so don't define customer either. |
| 673 | 673 | $stripe_source = $stripe_token; |
| 674 | 674 | $stripe_customer = false; |
| 675 | 675 | } |
| 676 | - } elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
| 676 | + } elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
| 677 | 677 | // Use an existing token, and then process the payment |
| 678 | 678 | |
| 679 | - $token_id = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
| 680 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 679 | + $token_id = wc_clean($_POST['wc-stripe-payment-token']); |
|
| 680 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 681 | 681 | |
| 682 | - if ( ! $token || $token->get_user_id() !== get_current_user_id() ) { |
|
| 683 | - WC()->session->set( 'refresh_totals', true ); |
|
| 684 | - throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
| 682 | + if ( ! $token || $token->get_user_id() !== get_current_user_id()) { |
|
| 683 | + WC()->session->set('refresh_totals', true); |
|
| 684 | + throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | $stripe_source = $token->get_token(); |
@@ -705,19 +705,19 @@ discard block |
||
| 705 | 705 | * @param object $order |
| 706 | 706 | * @return object |
| 707 | 707 | */ |
| 708 | - protected function get_order_source( $order = null ) { |
|
| 708 | + protected function get_order_source($order = null) { |
|
| 709 | 709 | $stripe_customer = new WC_Stripe_Customer(); |
| 710 | 710 | $stripe_source = false; |
| 711 | 711 | $token_id = false; |
| 712 | 712 | |
| 713 | - if ( $order ) { |
|
| 714 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
| 713 | + if ($order) { |
|
| 714 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
| 715 | 715 | |
| 716 | - if ( $meta_value = get_post_meta( $order_id, '_stripe_customer_id', true ) ) { |
|
| 717 | - $stripe_customer->set_id( $meta_value ); |
|
| 716 | + if ($meta_value = get_post_meta($order_id, '_stripe_customer_id', true)) { |
|
| 717 | + $stripe_customer->set_id($meta_value); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | - if ( $meta_value = get_post_meta( $order_id, '_stripe_card_id', true ) ) { |
|
| 720 | + if ($meta_value = get_post_meta($order_id, '_stripe_card_id', true)) { |
|
| 721 | 721 | $stripe_source = $meta_value; |
| 722 | 722 | } |
| 723 | 723 | } |
@@ -740,60 +740,60 @@ discard block |
||
| 740 | 740 | * |
| 741 | 741 | * @return array|void |
| 742 | 742 | */ |
| 743 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
| 743 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
| 744 | 744 | try { |
| 745 | - $order = wc_get_order( $order_id ); |
|
| 746 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
| 745 | + $order = wc_get_order($order_id); |
|
| 746 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
| 747 | 747 | |
| 748 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
| 749 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
| 750 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
| 751 | - throw new Exception( $error_msg ); |
|
| 748 | + if (empty($source->source) && empty($source->customer)) { |
|
| 749 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
| 750 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
| 751 | + throw new Exception($error_msg); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | // Store source to order meta. |
| 755 | - $this->save_source( $order, $source ); |
|
| 755 | + $this->save_source($order, $source); |
|
| 756 | 756 | |
| 757 | 757 | // Result from Stripe API request. |
| 758 | 758 | $response = null; |
| 759 | 759 | |
| 760 | 760 | // Handle payment. |
| 761 | - if ( $order->get_total() > 0 ) { |
|
| 761 | + if ($order->get_total() > 0) { |
|
| 762 | 762 | |
| 763 | - if ( $order->get_total() * 100 < WC_Stripe::get_minimum_amount() ) { |
|
| 764 | - 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::get_minimum_amount() / 100 ) ) ); |
|
| 763 | + if ($order->get_total() * 100 < WC_Stripe::get_minimum_amount()) { |
|
| 764 | + 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::get_minimum_amount() / 100))); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | - $this->log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 767 | + $this->log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 768 | 768 | |
| 769 | 769 | // Make the request. |
| 770 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 770 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 771 | 771 | |
| 772 | - if ( is_wp_error( $response ) ) { |
|
| 772 | + if (is_wp_error($response)) { |
|
| 773 | 773 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 774 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
| 775 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
| 776 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
| 774 | + if ('customer' === $response->get_error_code() && $retry) { |
|
| 775 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
| 776 | + return $this->process_payment($order_id, false, $force_customer); |
|
| 777 | 777 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 778 | - } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
| 779 | - $token = WC_Payment_Tokens::get( $source->token_id ); |
|
| 778 | + } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
| 779 | + $token = WC_Payment_Tokens::get($source->token_id); |
|
| 780 | 780 | $token->delete(); |
| 781 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 782 | - $order->add_order_note( $message ); |
|
| 783 | - throw new Exception( $message ); |
|
| 781 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 782 | + $order->add_order_note($message); |
|
| 783 | + throw new Exception($message); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | $localized_messages = $this->get_localized_messages(); |
| 787 | 787 | |
| 788 | - $message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message(); |
|
| 788 | + $message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message(); |
|
| 789 | 789 | |
| 790 | - $order->add_order_note( $message ); |
|
| 790 | + $order->add_order_note($message); |
|
| 791 | 791 | |
| 792 | - throw new Exception( $message ); |
|
| 792 | + throw new Exception($message); |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | // Process valid response. |
| 796 | - $this->process_response( $response, $order ); |
|
| 796 | + $this->process_response($response, $order); |
|
| 797 | 797 | } else { |
| 798 | 798 | $order->payment_complete(); |
| 799 | 799 | } |
@@ -801,23 +801,23 @@ discard block |
||
| 801 | 801 | // Remove cart. |
| 802 | 802 | WC()->cart->empty_cart(); |
| 803 | 803 | |
| 804 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 804 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
| 805 | 805 | |
| 806 | 806 | // Return thank you page redirect. |
| 807 | 807 | return array( |
| 808 | 808 | 'result' => 'success', |
| 809 | - 'redirect' => $this->get_return_url( $order ), |
|
| 809 | + 'redirect' => $this->get_return_url($order), |
|
| 810 | 810 | ); |
| 811 | 811 | |
| 812 | - } catch ( Exception $e ) { |
|
| 813 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 814 | - $this->log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
| 812 | + } catch (Exception $e) { |
|
| 813 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 814 | + $this->log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
| 815 | 815 | |
| 816 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 817 | - $this->send_failed_order_email( $order_id ); |
|
| 816 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 817 | + $this->send_failed_order_email($order_id); |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 820 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 821 | 821 | |
| 822 | 822 | return array( |
| 823 | 823 | 'result' => 'fail', |
@@ -832,59 +832,59 @@ discard block |
||
| 832 | 832 | * @param WC_Order $order For to which the source applies. |
| 833 | 833 | * @param stdClass $source Source information. |
| 834 | 834 | */ |
| 835 | - protected function save_source( $order, $source ) { |
|
| 836 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
| 835 | + protected function save_source($order, $source) { |
|
| 836 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
| 837 | 837 | |
| 838 | 838 | // Store source in the order. |
| 839 | - if ( $source->customer ) { |
|
| 840 | - version_compare( WC_VERSION, '3.0.0', '<' ) ? update_post_meta( $order_id, '_stripe_customer_id', $source->customer ) : $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
| 839 | + if ($source->customer) { |
|
| 840 | + version_compare(WC_VERSION, '3.0.0', '<') ? update_post_meta($order_id, '_stripe_customer_id', $source->customer) : $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
| 841 | 841 | } |
| 842 | - if ( $source->source ) { |
|
| 843 | - version_compare( WC_VERSION, '3.0.0', '<' ) ? update_post_meta( $order_id, '_stripe_card_id', $source->source ) : $order->update_meta_data( '_stripe_card_id', $source->source ); |
|
| 842 | + if ($source->source) { |
|
| 843 | + version_compare(WC_VERSION, '3.0.0', '<') ? update_post_meta($order_id, '_stripe_card_id', $source->source) : $order->update_meta_data('_stripe_card_id', $source->source); |
|
| 844 | 844 | } |
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | /** |
| 848 | 848 | * Store extra meta data for an order from a Stripe Response. |
| 849 | 849 | */ |
| 850 | - public function process_response( $response, $order ) { |
|
| 851 | - $this->log( 'Processing response: ' . print_r( $response, true ) ); |
|
| 850 | + public function process_response($response, $order) { |
|
| 851 | + $this->log('Processing response: ' . print_r($response, true)); |
|
| 852 | 852 | |
| 853 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
| 853 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
| 854 | 854 | |
| 855 | 855 | // Store charge data |
| 856 | - update_post_meta( $order_id, '_stripe_charge_id', $response->id ); |
|
| 857 | - update_post_meta( $order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
| 856 | + update_post_meta($order_id, '_stripe_charge_id', $response->id); |
|
| 857 | + update_post_meta($order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
| 858 | 858 | |
| 859 | 859 | // Store other data such as fees |
| 860 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
| 860 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
| 861 | 861 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
| 862 | 862 | // values are in the local currency of the Stripe account, not from WC. |
| 863 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe::format_number( $response->balance_transaction, 'fee' ) : 0; |
|
| 864 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe::format_number( $response->balance_transaction, 'net' ) : 0; |
|
| 865 | - update_post_meta( $order_id, 'Stripe Fee', $fee ); |
|
| 866 | - update_post_meta( $order_id, 'Net Revenue From Stripe', $net ); |
|
| 863 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe::format_number($response->balance_transaction, 'fee') : 0; |
|
| 864 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe::format_number($response->balance_transaction, 'net') : 0; |
|
| 865 | + update_post_meta($order_id, 'Stripe Fee', $fee); |
|
| 866 | + update_post_meta($order_id, 'Net Revenue From Stripe', $net); |
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | - if ( $response->captured ) { |
|
| 870 | - $order->payment_complete( $response->id ); |
|
| 869 | + if ($response->captured) { |
|
| 870 | + $order->payment_complete($response->id); |
|
| 871 | 871 | |
| 872 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
| 873 | - $order->add_order_note( $message ); |
|
| 874 | - $this->log( 'Success: ' . $message ); |
|
| 872 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
| 873 | + $order->add_order_note($message); |
|
| 874 | + $this->log('Success: ' . $message); |
|
| 875 | 875 | |
| 876 | 876 | } else { |
| 877 | - update_post_meta( $order_id, '_transaction_id', $response->id, true ); |
|
| 877 | + update_post_meta($order_id, '_transaction_id', $response->id, true); |
|
| 878 | 878 | |
| 879 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 880 | - version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
| 879 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 880 | + version_compare(WC_VERSION, '3.0.0', '<') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
| 881 | 881 | } |
| 882 | 882 | |
| 883 | - $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 ) ); |
|
| 884 | - $this->log( "Successful auth: $response->id" ); |
|
| 883 | + $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)); |
|
| 884 | + $this->log("Successful auth: $response->id"); |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
| 887 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
| 888 | 888 | |
| 889 | 889 | return $response; |
| 890 | 890 | } |
@@ -895,32 +895,32 @@ discard block |
||
| 895 | 895 | * @since 3.0.0 |
| 896 | 896 | */ |
| 897 | 897 | public function add_payment_method() { |
| 898 | - if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
| 899 | - wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
| 898 | + if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
| 899 | + wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
| 900 | 900 | return; |
| 901 | 901 | } |
| 902 | 902 | |
| 903 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 904 | - $card = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
| 903 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 904 | + $card = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
| 905 | 905 | |
| 906 | - if ( is_wp_error( $card ) ) { |
|
| 906 | + if (is_wp_error($card)) { |
|
| 907 | 907 | $localized_messages = $this->get_localized_messages(); |
| 908 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
| 908 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
| 909 | 909 | |
| 910 | 910 | // loop through the errors to find matching localized message |
| 911 | - foreach ( $card->errors as $error => $msg ) { |
|
| 912 | - if ( isset( $localized_messages[ $error ] ) ) { |
|
| 913 | - $error_msg = $localized_messages[ $error ]; |
|
| 911 | + foreach ($card->errors as $error => $msg) { |
|
| 912 | + if (isset($localized_messages[$error])) { |
|
| 913 | + $error_msg = $localized_messages[$error]; |
|
| 914 | 914 | } |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | - wc_add_notice( $error_msg, 'error' ); |
|
| 917 | + wc_add_notice($error_msg, 'error'); |
|
| 918 | 918 | return; |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | return array( |
| 922 | 922 | 'result' => 'success', |
| 923 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
| 923 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
| 924 | 924 | ); |
| 925 | 925 | } |
| 926 | 926 | |
@@ -930,36 +930,36 @@ discard block |
||
| 930 | 930 | * @param float $amount |
| 931 | 931 | * @return bool |
| 932 | 932 | */ |
| 933 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
| 934 | - $order = wc_get_order( $order_id ); |
|
| 933 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
| 934 | + $order = wc_get_order($order_id); |
|
| 935 | 935 | |
| 936 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
| 936 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
| 937 | 937 | return false; |
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | $body = array(); |
| 941 | 941 | |
| 942 | - if ( ! is_null( $amount ) ) { |
|
| 943 | - $body['amount'] = $this->get_stripe_amount( $amount ); |
|
| 942 | + if ( ! is_null($amount)) { |
|
| 943 | + $body['amount'] = $this->get_stripe_amount($amount); |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | - if ( $reason ) { |
|
| 946 | + if ($reason) { |
|
| 947 | 947 | $body['metadata'] = array( |
| 948 | 948 | 'reason' => $reason, |
| 949 | 949 | ); |
| 950 | 950 | } |
| 951 | 951 | |
| 952 | - $this->log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
| 952 | + $this->log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
| 953 | 953 | |
| 954 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
| 954 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
| 955 | 955 | |
| 956 | - if ( is_wp_error( $response ) ) { |
|
| 957 | - $this->log( 'Error: ' . $response->get_error_message() ); |
|
| 956 | + if (is_wp_error($response)) { |
|
| 957 | + $this->log('Error: ' . $response->get_error_message()); |
|
| 958 | 958 | return $response; |
| 959 | - } elseif ( ! empty( $response->id ) ) { |
|
| 960 | - $refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
| 961 | - $order->add_order_note( $refund_message ); |
|
| 962 | - $this->log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
| 959 | + } elseif ( ! empty($response->id)) { |
|
| 960 | + $refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
| 961 | + $order->add_order_note($refund_message); |
|
| 962 | + $this->log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
| 963 | 963 | return true; |
| 964 | 964 | } |
| 965 | 965 | } |
@@ -972,10 +972,10 @@ discard block |
||
| 972 | 972 | * @param int $order_id |
| 973 | 973 | * @return null |
| 974 | 974 | */ |
| 975 | - public function send_failed_order_email( $order_id ) { |
|
| 975 | + public function send_failed_order_email($order_id) { |
|
| 976 | 976 | $emails = WC()->mailer()->get_emails(); |
| 977 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
| 978 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
| 977 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
| 978 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
| 979 | 979 | } |
| 980 | 980 | } |
| 981 | 981 | |
@@ -987,9 +987,9 @@ discard block |
||
| 987 | 987 | * |
| 988 | 988 | * @param string $message |
| 989 | 989 | */ |
| 990 | - public function log( $message ) { |
|
| 991 | - if ( $this->logging ) { |
|
| 992 | - WC_Stripe::log( $message ); |
|
| 990 | + public function log($message) { |
|
| 991 | + if ($this->logging) { |
|
| 992 | + WC_Stripe::log($message); |
|
| 993 | 993 | } |
| 994 | 994 | } |
| 995 | 995 | } |