@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -15,24 +15,24 @@ discard block |
||
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | |
| 18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 23 | 23 | |
| 24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
| 25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 26 | 26 | |
| 27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
| 28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
| 31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
| 28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
| 31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
| 34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
| 35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @since 4.0.0 |
| 44 | 44 | * @version 4.0.0 |
| 45 | 45 | */ |
| 46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
| 47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
| 46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
| 47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
| 48 | 48 | return false; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @param int $order_id |
| 57 | 57 | * @return boolean |
| 58 | 58 | */ |
| 59 | - public function has_subscription( $order_id ) { |
|
| 60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 59 | + public function has_subscription($order_id) { |
|
| 60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * @param int $order_id |
| 66 | 66 | * @return boolean |
| 67 | 67 | */ |
| 68 | - protected function is_pre_order( $order_id ) { |
|
| 69 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
| 68 | + protected function is_pre_order($order_id) { |
|
| 69 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * @param int $order_id |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 78 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 77 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 78 | + if ($this->has_subscription($order_id)) { |
|
| 79 | 79 | // Regular payment with force customer enabled |
| 80 | - return parent::process_payment( $order_id, true, true ); |
|
| 81 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
| 82 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
| 80 | + return parent::process_payment($order_id, true, true); |
|
| 81 | + } elseif ($this->is_pre_order($order_id)) { |
|
| 82 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
| 83 | 83 | } else { |
| 84 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 84 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | * @param array $metadata |
| 93 | 93 | * @param object $order |
| 94 | 94 | */ |
| 95 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
| 96 | - if ( ! $this->has_subscription( $order->get_id() ) ) { |
|
| 95 | + public function add_subscription_meta_data($metadata, $order) { |
|
| 96 | + if ( ! $this->has_subscription($order->get_id())) { |
|
| 97 | 97 | return $metadata; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | return $metadata += array( |
| 101 | 101 | 'payment_type' => 'recurring', |
| 102 | - 'site_url' => esc_url( get_site_url() ), |
|
| 102 | + 'site_url' => esc_url(get_site_url()), |
|
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -109,24 +109,24 @@ discard block |
||
| 109 | 109 | * @since 3.1.0 |
| 110 | 110 | * @version 4.0.0 |
| 111 | 111 | */ |
| 112 | - public function save_source( $order, $source ) { |
|
| 113 | - parent::save_source( $order, $source ); |
|
| 112 | + public function save_source($order, $source) { |
|
| 113 | + parent::save_source($order, $source); |
|
| 114 | 114 | |
| 115 | - $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 115 | + $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 116 | 116 | |
| 117 | 117 | // Also store it on the subscriptions being purchased or paid for in the order |
| 118 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 119 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 120 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 121 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 118 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 119 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 120 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 121 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 122 | 122 | } else { |
| 123 | 123 | $subscriptions = array(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - foreach ( $subscriptions as $subscription ) { |
|
| 126 | + foreach ($subscriptions as $subscription) { |
|
| 127 | 127 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
| 128 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 129 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 128 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 129 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -137,37 +137,37 @@ discard block |
||
| 137 | 137 | * @param string $stripe_token (default: '') |
| 138 | 138 | * @param bool initial_payment |
| 139 | 139 | */ |
| 140 | - public function process_subscription_payment( $order = '', $amount = 0 ) { |
|
| 141 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 140 | + public function process_subscription_payment($order = '', $amount = 0) { |
|
| 141 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 142 | 142 | /* translators: minimum amount */ |
| 143 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 143 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | $customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 147 | 147 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 148 | 148 | |
| 149 | 149 | // Get source from order |
| 150 | - $prepared_source = $this->prepare_order_source( $order ); |
|
| 150 | + $prepared_source = $this->prepare_order_source($order); |
|
| 151 | 151 | |
| 152 | 152 | // Or fail :( |
| 153 | - if ( ! $prepared_source->customer ) { |
|
| 154 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 153 | + if ( ! $prepared_source->customer) { |
|
| 154 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 157 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 158 | 158 | |
| 159 | 159 | // Make the request |
| 160 | - $request = $this->generate_payment_request( $order, $prepared_source ); |
|
| 160 | + $request = $this->generate_payment_request($order, $prepared_source); |
|
| 161 | 161 | $request['capture'] = 'true'; |
| 162 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 163 | - $response = WC_Stripe_API::request( $request ); |
|
| 162 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
| 163 | + $response = WC_Stripe_API::request($request); |
|
| 164 | 164 | |
| 165 | 165 | // Process valid response |
| 166 | - if ( ! empty( $response->error ) ) { |
|
| 166 | + if ( ! empty($response->error)) { |
|
| 167 | 167 | return $response; // Default catch all errors. |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - $this->process_response( $response, $order ); |
|
| 170 | + $this->process_response($response, $order); |
|
| 171 | 171 | |
| 172 | 172 | return $response; |
| 173 | 173 | } |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 177 | 177 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 178 | 178 | */ |
| 179 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 180 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 181 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 179 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 180 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 181 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 182 | 182 | // For BW compat will remove in future |
| 183 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 184 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 183 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 184 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 189 | 189 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 190 | 190 | */ |
| 191 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 192 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
| 193 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
| 191 | + public function delete_renewal_meta($renewal_order) { |
|
| 192 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
| 193 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
| 194 | 194 | return $renewal_order; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -200,17 +200,17 @@ discard block |
||
| 200 | 200 | * @param $amount_to_charge float The amount to charge. |
| 201 | 201 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 202 | 202 | */ |
| 203 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 204 | - $response = $this->process_subscription_payment( $renewal_order, $amount_to_charge ); |
|
| 203 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 204 | + $response = $this->process_subscription_payment($renewal_order, $amount_to_charge); |
|
| 205 | 205 | |
| 206 | - if ( is_wp_error( $response ) ) { |
|
| 206 | + if (is_wp_error($response)) { |
|
| 207 | 207 | /* translators: error message */ |
| 208 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 208 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( ! empty( $response->error ) ) { |
|
| 211 | + if ( ! empty($response->error)) { |
|
| 212 | 212 | /* translators: error message */ |
| 213 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 213 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
@@ -218,20 +218,20 @@ discard block |
||
| 218 | 218 | * Remove order meta |
| 219 | 219 | * @param object $order |
| 220 | 220 | */ |
| 221 | - public function remove_order_source_before_retry( $order ) { |
|
| 221 | + public function remove_order_source_before_retry($order) { |
|
| 222 | 222 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 223 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
| 223 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
| 224 | 224 | // For BW compat will remove in the future. |
| 225 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
| 225 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
| 229 | 229 | * Remove order meta |
| 230 | 230 | * @param object $order |
| 231 | 231 | */ |
| 232 | - public function remove_order_customer_before_retry( $order ) { |
|
| 232 | + public function remove_order_customer_before_retry($order) { |
|
| 233 | 233 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 234 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 234 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -243,14 +243,14 @@ discard block |
||
| 243 | 243 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 244 | 244 | * @return void |
| 245 | 245 | */ |
| 246 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 247 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 248 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 249 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 246 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 247 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 248 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 249 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 250 | 250 | |
| 251 | 251 | } else { |
| 252 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 253 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 252 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 253 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
@@ -263,21 +263,21 @@ discard block |
||
| 263 | 263 | * @param WC_Subscription $subscription An instance of a subscription object |
| 264 | 264 | * @return array |
| 265 | 265 | */ |
| 266 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 267 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 266 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 267 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 268 | 268 | |
| 269 | 269 | // For BW compat will remove in future. |
| 270 | - if ( empty( $source_id ) ) { |
|
| 271 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 270 | + if (empty($source_id)) { |
|
| 271 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 272 | 272 | |
| 273 | 273 | // Take this opportunity to update the key name. |
| 274 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
| 274 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $payment_meta[ $this->id ] = array( |
|
| 277 | + $payment_meta[$this->id] = array( |
|
| 278 | 278 | 'post_meta' => array( |
| 279 | 279 | '_stripe_customer_id' => array( |
| 280 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
| 280 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
| 281 | 281 | 'label' => 'Stripe Customer ID', |
| 282 | 282 | ), |
| 283 | 283 | '_stripe_source_id' => array( |
@@ -299,17 +299,17 @@ discard block |
||
| 299 | 299 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 300 | 300 | * @return array |
| 301 | 301 | */ |
| 302 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 303 | - if ( $this->id === $payment_method_id ) { |
|
| 302 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 303 | + if ($this->id === $payment_method_id) { |
|
| 304 | 304 | |
| 305 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 306 | - throw new Exception( 'A "_stripe_customer_id" value is required.' ); |
|
| 307 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 308 | - throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' ); |
|
| 305 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 306 | + throw new Exception('A "_stripe_customer_id" value is required.'); |
|
| 307 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 308 | + throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".'); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) { |
|
| 312 | - throw new Exception( 'A "_stripe_source_id" value is required.' ); |
|
| 311 | + if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) { |
|
| 312 | + throw new Exception('A "_stripe_source_id" value is required.'); |
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | } |
@@ -322,89 +322,89 @@ discard block |
||
| 322 | 322 | * @param WC_Subscription $subscription the subscription details |
| 323 | 323 | * @return string the subscription payment method |
| 324 | 324 | */ |
| 325 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 325 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 326 | 326 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
| 327 | 327 | |
| 328 | 328 | // bail for other payment methods |
| 329 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 329 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 330 | 330 | return $payment_method_to_display; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 333 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 334 | 334 | |
| 335 | 335 | // For BW compat will remove in future. |
| 336 | - if ( empty( $stripe_source_id ) ) { |
|
| 337 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 336 | + if (empty($stripe_source_id)) { |
|
| 337 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 338 | 338 | |
| 339 | 339 | // Take this opportunity to update the key name. |
| 340 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 340 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | $stripe_customer = new WC_Stripe_Customer(); |
| 344 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 344 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 345 | 345 | |
| 346 | 346 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 347 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 347 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 348 | 348 | $user_id = $customer_user; |
| 349 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 350 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 349 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 350 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 351 | 351 | |
| 352 | 352 | // For BW compat will remove in future. |
| 353 | - if ( empty( $stripe_source_id ) ) { |
|
| 354 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 353 | + if (empty($stripe_source_id)) { |
|
| 354 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 355 | 355 | |
| 356 | 356 | // Take this opportunity to update the key name. |
| 357 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 357 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 362 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 363 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 364 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 362 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 363 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 364 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 365 | 365 | |
| 366 | 366 | // For BW compat will remove in future. |
| 367 | - if ( empty( $stripe_source_id ) ) { |
|
| 368 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 367 | + if (empty($stripe_source_id)) { |
|
| 368 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 369 | 369 | |
| 370 | 370 | // Take this opportunity to update the key name. |
| 371 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 371 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 375 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 376 | 376 | $sources = $stripe_customer->get_sources(); |
| 377 | 377 | |
| 378 | - if ( $sources ) { |
|
| 378 | + if ($sources) { |
|
| 379 | 379 | $found_source = false; |
| 380 | - foreach ( $sources as $source ) { |
|
| 381 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 380 | + foreach ($sources as $source) { |
|
| 381 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 382 | 382 | $card = $source->card; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - if ( $source->id === $stripe_source_id ) { |
|
| 385 | + if ($source->id === $stripe_source_id) { |
|
| 386 | 386 | $found_source = true; |
| 387 | 387 | |
| 388 | - if ( $card ) { |
|
| 388 | + if ($card) { |
|
| 389 | 389 | /* translators: 1) card brand 2) last 4 digits */ |
| 390 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 390 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 391 | 391 | } else { |
| 392 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 392 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 393 | 393 | } |
| 394 | 394 | break; |
| 395 | 395 | } |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - if ( ! $found_source ) { |
|
| 399 | - if ( 'card' === $sources[0]->type ) { |
|
| 398 | + if ( ! $found_source) { |
|
| 399 | + if ('card' === $sources[0]->type) { |
|
| 400 | 400 | $card = $sources[0]->card; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - if ( $card ) { |
|
| 403 | + if ($card) { |
|
| 404 | 404 | /* translators: 1) card brand 2) last 4 digits */ |
| 405 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 405 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 406 | 406 | } else { |
| 407 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 407 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | } |
@@ -417,43 +417,43 @@ discard block |
||
| 417 | 417 | * @param int $order_id |
| 418 | 418 | * @return array |
| 419 | 419 | */ |
| 420 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
| 421 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
| 420 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
| 421 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
| 422 | 422 | try { |
| 423 | - $order = wc_get_order( $order_id ); |
|
| 423 | + $order = wc_get_order($order_id); |
|
| 424 | 424 | |
| 425 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 425 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 426 | 426 | /* translators: minimum amount */ |
| 427 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 427 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - $source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), true ); |
|
| 430 | + $source = $this->prepare_source($this->create_source_object(), get_current_user_id(), true); |
|
| 431 | 431 | |
| 432 | 432 | // We need a source on file to continue. |
| 433 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 434 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 433 | + if (empty($source->customer) || empty($source->source)) { |
|
| 434 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | // Store source to order meta |
| 438 | - $this->save_source( $order, $source ); |
|
| 438 | + $this->save_source($order, $source); |
|
| 439 | 439 | |
| 440 | 440 | // Remove cart |
| 441 | 441 | WC()->cart->empty_cart(); |
| 442 | 442 | |
| 443 | 443 | // Is pre ordered! |
| 444 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 444 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 445 | 445 | |
| 446 | 446 | // Return thank you page redirect |
| 447 | 447 | return array( |
| 448 | 448 | 'result' => 'success', |
| 449 | - 'redirect' => $this->get_return_url( $order ), |
|
| 449 | + 'redirect' => $this->get_return_url($order), |
|
| 450 | 450 | ); |
| 451 | - } catch ( Exception $e ) { |
|
| 452 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 451 | + } catch (Exception $e) { |
|
| 452 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 453 | 453 | return; |
| 454 | 454 | } |
| 455 | 455 | } else { |
| 456 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 456 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | * @param WC_Order $order |
| 463 | 463 | * @return void |
| 464 | 464 | */ |
| 465 | - public function process_pre_order_release_payment( $order ) { |
|
| 465 | + public function process_pre_order_release_payment($order) { |
|
| 466 | 466 | try { |
| 467 | 467 | // Define some callbacks if the first attempt fails. |
| 468 | 468 | $retry_callbacks = array( |
@@ -470,33 +470,33 @@ discard block |
||
| 470 | 470 | 'remove_order_customer_before_retry', |
| 471 | 471 | ); |
| 472 | 472 | |
| 473 | - while ( 1 ) { |
|
| 474 | - $source = $this->prepare_order_source( $order ); |
|
| 475 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 473 | + while (1) { |
|
| 474 | + $source = $this->prepare_order_source($order); |
|
| 475 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 476 | 476 | |
| 477 | - if ( ! empty( $response->error ) ) { |
|
| 478 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
| 479 | - throw new Exception( $response->error->message ); |
|
| 477 | + if ( ! empty($response->error)) { |
|
| 478 | + if (0 === sizeof($retry_callbacks)) { |
|
| 479 | + throw new Exception($response->error->message); |
|
| 480 | 480 | } else { |
| 481 | - $retry_callback = array_shift( $retry_callbacks ); |
|
| 482 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
| 481 | + $retry_callback = array_shift($retry_callbacks); |
|
| 482 | + call_user_func(array($this, $retry_callback), $order); |
|
| 483 | 483 | } |
| 484 | 484 | } else { |
| 485 | 485 | // Successful |
| 486 | - $this->process_response( $response, $order ); |
|
| 486 | + $this->process_response($response, $order); |
|
| 487 | 487 | break; |
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | - } catch ( Exception $e ) { |
|
| 490 | + } catch (Exception $e) { |
|
| 491 | 491 | /* translators: error message */ |
| 492 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
| 492 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
| 493 | 493 | |
| 494 | 494 | // Mark order as failed if not already set, |
| 495 | 495 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
| 496 | - if ( ! $order->has_status( 'failed' ) ) { |
|
| 497 | - $order->update_status( 'failed', $order_note ); |
|
| 496 | + if ( ! $order->has_status('failed')) { |
|
| 497 | + $order->update_status('failed', $order_note); |
|
| 498 | 498 | } else { |
| 499 | - $order->add_order_note( $order_note ); |
|
| 499 | + $order->add_order_note($order_note); |
|
| 500 | 500 | } |
| 501 | 501 | } |
| 502 | 502 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -15,24 +15,24 @@ discard block |
||
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | |
| 18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 23 | 23 | |
| 24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
| 25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 26 | 26 | |
| 27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
| 28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
| 31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
| 28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
| 31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
| 34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
| 35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @since 4.0.0 |
| 44 | 44 | * @version 4.0.0 |
| 45 | 45 | */ |
| 46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
| 47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
| 46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
| 47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
| 48 | 48 | return false; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @param int $order_id |
| 57 | 57 | * @return boolean |
| 58 | 58 | */ |
| 59 | - public function has_subscription( $order_id ) { |
|
| 60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 59 | + public function has_subscription($order_id) { |
|
| 60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * @param int $order_id |
| 66 | 66 | * @return boolean |
| 67 | 67 | */ |
| 68 | - protected function is_pre_order( $order_id ) { |
|
| 69 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
| 68 | + protected function is_pre_order($order_id) { |
|
| 69 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * @param int $order_id |
| 75 | 75 | * @return array |
| 76 | 76 | */ |
| 77 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 78 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 77 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 78 | + if ($this->has_subscription($order_id)) { |
|
| 79 | 79 | // Regular payment with force customer enabled |
| 80 | - return parent::process_payment( $order_id, true, true ); |
|
| 81 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
| 82 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
| 80 | + return parent::process_payment($order_id, true, true); |
|
| 81 | + } elseif ($this->is_pre_order($order_id)) { |
|
| 82 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
| 83 | 83 | } else { |
| 84 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 84 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | * @param array $metadata |
| 93 | 93 | * @param object $order |
| 94 | 94 | */ |
| 95 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
| 96 | - if ( ! $this->has_subscription( $order->get_id() ) ) { |
|
| 95 | + public function add_subscription_meta_data($metadata, $order) { |
|
| 96 | + if ( ! $this->has_subscription($order->get_id())) { |
|
| 97 | 97 | return $metadata; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | return $metadata += array( |
| 101 | 101 | 'payment_type' => 'recurring', |
| 102 | - 'site_url' => esc_url( get_site_url() ), |
|
| 102 | + 'site_url' => esc_url(get_site_url()), |
|
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -109,24 +109,24 @@ discard block |
||
| 109 | 109 | * @since 3.1.0 |
| 110 | 110 | * @version 4.0.0 |
| 111 | 111 | */ |
| 112 | - public function save_source( $order, $source ) { |
|
| 113 | - parent::save_source( $order, $source ); |
|
| 112 | + public function save_source($order, $source) { |
|
| 113 | + parent::save_source($order, $source); |
|
| 114 | 114 | |
| 115 | - $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 115 | + $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
| 116 | 116 | |
| 117 | 117 | // Also store it on the subscriptions being purchased or paid for in the order |
| 118 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 119 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 120 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 121 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 118 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 119 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 120 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 121 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 122 | 122 | } else { |
| 123 | 123 | $subscriptions = array(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - foreach ( $subscriptions as $subscription ) { |
|
| 126 | + foreach ($subscriptions as $subscription) { |
|
| 127 | 127 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
| 128 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 129 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 128 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 129 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
@@ -137,37 +137,37 @@ discard block |
||
| 137 | 137 | * @param string $stripe_token (default: '') |
| 138 | 138 | * @param bool initial_payment |
| 139 | 139 | */ |
| 140 | - public function process_subscription_payment( $order = '', $amount = 0 ) { |
|
| 141 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 140 | + public function process_subscription_payment($order = '', $amount = 0) { |
|
| 141 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 142 | 142 | /* translators: minimum amount */ |
| 143 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 143 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | $customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 147 | 147 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 148 | 148 | |
| 149 | 149 | // Get source from order |
| 150 | - $prepared_source = $this->prepare_order_source( $order ); |
|
| 150 | + $prepared_source = $this->prepare_order_source($order); |
|
| 151 | 151 | |
| 152 | 152 | // Or fail :( |
| 153 | - if ( ! $prepared_source->customer ) { |
|
| 154 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 153 | + if ( ! $prepared_source->customer) { |
|
| 154 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 157 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 158 | 158 | |
| 159 | 159 | // Make the request |
| 160 | - $request = $this->generate_payment_request( $order, $prepared_source ); |
|
| 160 | + $request = $this->generate_payment_request($order, $prepared_source); |
|
| 161 | 161 | $request['capture'] = 'true'; |
| 162 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 163 | - $response = WC_Stripe_API::request( $request ); |
|
| 162 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
| 163 | + $response = WC_Stripe_API::request($request); |
|
| 164 | 164 | |
| 165 | 165 | // Process valid response |
| 166 | - if ( ! empty( $response->error ) ) { |
|
| 166 | + if ( ! empty($response->error)) { |
|
| 167 | 167 | return $response; // Default catch all errors. |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - $this->process_response( $response, $order ); |
|
| 170 | + $this->process_response($response, $order); |
|
| 171 | 171 | |
| 172 | 172 | return $response; |
| 173 | 173 | } |
@@ -176,21 +176,21 @@ discard block |
||
| 176 | 176 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 177 | 177 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 178 | 178 | */ |
| 179 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 180 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 181 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 179 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 180 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 181 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 182 | 182 | // For BW compat will remove in future |
| 183 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 184 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 183 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 184 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 189 | 189 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 190 | 190 | */ |
| 191 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 192 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
| 193 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
| 191 | + public function delete_renewal_meta($renewal_order) { |
|
| 192 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
| 193 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
| 194 | 194 | return $renewal_order; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -200,17 +200,17 @@ discard block |
||
| 200 | 200 | * @param $amount_to_charge float The amount to charge. |
| 201 | 201 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 202 | 202 | */ |
| 203 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 204 | - $response = $this->process_subscription_payment( $renewal_order, $amount_to_charge ); |
|
| 203 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 204 | + $response = $this->process_subscription_payment($renewal_order, $amount_to_charge); |
|
| 205 | 205 | |
| 206 | - if ( is_wp_error( $response ) ) { |
|
| 206 | + if (is_wp_error($response)) { |
|
| 207 | 207 | /* translators: error message */ |
| 208 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 208 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( ! empty( $response->error ) ) { |
|
| 211 | + if ( ! empty($response->error)) { |
|
| 212 | 212 | /* translators: error message */ |
| 213 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
| 213 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
@@ -218,20 +218,20 @@ discard block |
||
| 218 | 218 | * Remove order meta |
| 219 | 219 | * @param object $order |
| 220 | 220 | */ |
| 221 | - public function remove_order_source_before_retry( $order ) { |
|
| 221 | + public function remove_order_source_before_retry($order) { |
|
| 222 | 222 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 223 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
| 223 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
| 224 | 224 | // For BW compat will remove in the future. |
| 225 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
| 225 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
| 229 | 229 | * Remove order meta |
| 230 | 230 | * @param object $order |
| 231 | 231 | */ |
| 232 | - public function remove_order_customer_before_retry( $order ) { |
|
| 232 | + public function remove_order_customer_before_retry($order) { |
|
| 233 | 233 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 234 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 234 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -243,14 +243,14 @@ discard block |
||
| 243 | 243 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 244 | 244 | * @return void |
| 245 | 245 | */ |
| 246 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 247 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 248 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 249 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 246 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 247 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 248 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 249 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 250 | 250 | |
| 251 | 251 | } else { |
| 252 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 253 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 252 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 253 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
@@ -263,21 +263,21 @@ discard block |
||
| 263 | 263 | * @param WC_Subscription $subscription An instance of a subscription object |
| 264 | 264 | * @return array |
| 265 | 265 | */ |
| 266 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 267 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 266 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 267 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 268 | 268 | |
| 269 | 269 | // For BW compat will remove in future. |
| 270 | - if ( empty( $source_id ) ) { |
|
| 271 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 270 | + if (empty($source_id)) { |
|
| 271 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 272 | 272 | |
| 273 | 273 | // Take this opportunity to update the key name. |
| 274 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
| 274 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $payment_meta[ $this->id ] = array( |
|
| 277 | + $payment_meta[$this->id] = array( |
|
| 278 | 278 | 'post_meta' => array( |
| 279 | 279 | '_stripe_customer_id' => array( |
| 280 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
| 280 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
| 281 | 281 | 'label' => 'Stripe Customer ID', |
| 282 | 282 | ), |
| 283 | 283 | '_stripe_source_id' => array( |
@@ -299,17 +299,17 @@ discard block |
||
| 299 | 299 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 300 | 300 | * @return array |
| 301 | 301 | */ |
| 302 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 303 | - if ( $this->id === $payment_method_id ) { |
|
| 302 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 303 | + if ($this->id === $payment_method_id) { |
|
| 304 | 304 | |
| 305 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 306 | - throw new Exception( 'A "_stripe_customer_id" value is required.' ); |
|
| 307 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 308 | - throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' ); |
|
| 305 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 306 | + throw new Exception('A "_stripe_customer_id" value is required.'); |
|
| 307 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 308 | + throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".'); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) { |
|
| 312 | - throw new Exception( 'A "_stripe_source_id" value is required.' ); |
|
| 311 | + if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) { |
|
| 312 | + throw new Exception('A "_stripe_source_id" value is required.'); |
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | } |
@@ -322,89 +322,89 @@ discard block |
||
| 322 | 322 | * @param WC_Subscription $subscription the subscription details |
| 323 | 323 | * @return string the subscription payment method |
| 324 | 324 | */ |
| 325 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 325 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 326 | 326 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
| 327 | 327 | |
| 328 | 328 | // bail for other payment methods |
| 329 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 329 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 330 | 330 | return $payment_method_to_display; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 333 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 334 | 334 | |
| 335 | 335 | // For BW compat will remove in future. |
| 336 | - if ( empty( $stripe_source_id ) ) { |
|
| 337 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 336 | + if (empty($stripe_source_id)) { |
|
| 337 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 338 | 338 | |
| 339 | 339 | // Take this opportunity to update the key name. |
| 340 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 340 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | $stripe_customer = new WC_Stripe_Customer(); |
| 344 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 344 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 345 | 345 | |
| 346 | 346 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 347 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 347 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 348 | 348 | $user_id = $customer_user; |
| 349 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 350 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 349 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 350 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 351 | 351 | |
| 352 | 352 | // For BW compat will remove in future. |
| 353 | - if ( empty( $stripe_source_id ) ) { |
|
| 354 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 353 | + if (empty($stripe_source_id)) { |
|
| 354 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 355 | 355 | |
| 356 | 356 | // Take this opportunity to update the key name. |
| 357 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 357 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 362 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 363 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 364 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 362 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 363 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 364 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 365 | 365 | |
| 366 | 366 | // For BW compat will remove in future. |
| 367 | - if ( empty( $stripe_source_id ) ) { |
|
| 368 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 367 | + if (empty($stripe_source_id)) { |
|
| 368 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 369 | 369 | |
| 370 | 370 | // Take this opportunity to update the key name. |
| 371 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 371 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 375 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 376 | 376 | $sources = $stripe_customer->get_sources(); |
| 377 | 377 | |
| 378 | - if ( $sources ) { |
|
| 378 | + if ($sources) { |
|
| 379 | 379 | $found_source = false; |
| 380 | - foreach ( $sources as $source ) { |
|
| 381 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 380 | + foreach ($sources as $source) { |
|
| 381 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 382 | 382 | $card = $source->card; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - if ( $source->id === $stripe_source_id ) { |
|
| 385 | + if ($source->id === $stripe_source_id) { |
|
| 386 | 386 | $found_source = true; |
| 387 | 387 | |
| 388 | - if ( $card ) { |
|
| 388 | + if ($card) { |
|
| 389 | 389 | /* translators: 1) card brand 2) last 4 digits */ |
| 390 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 390 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 391 | 391 | } else { |
| 392 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 392 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 393 | 393 | } |
| 394 | 394 | break; |
| 395 | 395 | } |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - if ( ! $found_source ) { |
|
| 399 | - if ( 'card' === $sources[0]->type ) { |
|
| 398 | + if ( ! $found_source) { |
|
| 399 | + if ('card' === $sources[0]->type) { |
|
| 400 | 400 | $card = $sources[0]->card; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - if ( $card ) { |
|
| 403 | + if ($card) { |
|
| 404 | 404 | /* translators: 1) card brand 2) last 4 digits */ |
| 405 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
| 405 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
| 406 | 406 | } else { |
| 407 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 407 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | } |
@@ -417,43 +417,43 @@ discard block |
||
| 417 | 417 | * @param int $order_id |
| 418 | 418 | * @return array |
| 419 | 419 | */ |
| 420 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
| 421 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
| 420 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
| 421 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
| 422 | 422 | try { |
| 423 | - $order = wc_get_order( $order_id ); |
|
| 423 | + $order = wc_get_order($order_id); |
|
| 424 | 424 | |
| 425 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 425 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 426 | 426 | /* translators: minimum amount */ |
| 427 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 427 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - $source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), true ); |
|
| 430 | + $source = $this->prepare_source($this->create_source_object(), get_current_user_id(), true); |
|
| 431 | 431 | |
| 432 | 432 | // We need a source on file to continue. |
| 433 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
| 434 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
| 433 | + if (empty($source->customer) || empty($source->source)) { |
|
| 434 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | // Store source to order meta |
| 438 | - $this->save_source( $order, $source ); |
|
| 438 | + $this->save_source($order, $source); |
|
| 439 | 439 | |
| 440 | 440 | // Remove cart |
| 441 | 441 | WC()->cart->empty_cart(); |
| 442 | 442 | |
| 443 | 443 | // Is pre ordered! |
| 444 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
| 444 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
| 445 | 445 | |
| 446 | 446 | // Return thank you page redirect |
| 447 | 447 | return array( |
| 448 | 448 | 'result' => 'success', |
| 449 | - 'redirect' => $this->get_return_url( $order ), |
|
| 449 | + 'redirect' => $this->get_return_url($order), |
|
| 450 | 450 | ); |
| 451 | - } catch ( Exception $e ) { |
|
| 452 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
| 451 | + } catch (Exception $e) { |
|
| 452 | + wc_add_notice($e->getMessage(), 'error'); |
|
| 453 | 453 | return; |
| 454 | 454 | } |
| 455 | 455 | } else { |
| 456 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
| 456 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | * @param WC_Order $order |
| 463 | 463 | * @return void |
| 464 | 464 | */ |
| 465 | - public function process_pre_order_release_payment( $order ) { |
|
| 465 | + public function process_pre_order_release_payment($order) { |
|
| 466 | 466 | try { |
| 467 | 467 | // Define some callbacks if the first attempt fails. |
| 468 | 468 | $retry_callbacks = array( |
@@ -470,33 +470,33 @@ discard block |
||
| 470 | 470 | 'remove_order_customer_before_retry', |
| 471 | 471 | ); |
| 472 | 472 | |
| 473 | - while ( 1 ) { |
|
| 474 | - $source = $this->prepare_order_source( $order ); |
|
| 475 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
| 473 | + while (1) { |
|
| 474 | + $source = $this->prepare_order_source($order); |
|
| 475 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
| 476 | 476 | |
| 477 | - if ( ! empty( $response->error ) ) { |
|
| 478 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
| 479 | - throw new Exception( $response->error->message ); |
|
| 477 | + if ( ! empty($response->error)) { |
|
| 478 | + if (0 === sizeof($retry_callbacks)) { |
|
| 479 | + throw new Exception($response->error->message); |
|
| 480 | 480 | } else { |
| 481 | - $retry_callback = array_shift( $retry_callbacks ); |
|
| 482 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
| 481 | + $retry_callback = array_shift($retry_callbacks); |
|
| 482 | + call_user_func(array($this, $retry_callback), $order); |
|
| 483 | 483 | } |
| 484 | 484 | } else { |
| 485 | 485 | // Successful |
| 486 | - $this->process_response( $response, $order ); |
|
| 486 | + $this->process_response($response, $order); |
|
| 487 | 487 | break; |
| 488 | 488 | } |
| 489 | 489 | } |
| 490 | - } catch ( Exception $e ) { |
|
| 490 | + } catch (Exception $e) { |
|
| 491 | 491 | /* translators: error message */ |
| 492 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
| 492 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
| 493 | 493 | |
| 494 | 494 | // Mark order as failed if not already set, |
| 495 | 495 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
| 496 | - if ( ! $order->has_status( 'failed' ) ) { |
|
| 497 | - $order->update_status( 'failed', $order_note ); |
|
| 496 | + if ( ! $order->has_status('failed')) { |
|
| 497 | + $order->update_status('failed', $order_note); |
|
| 498 | 498 | } else { |
| 499 | - $order->add_order_note( $order_note ); |
|
| 499 | + $order->add_order_note($order_note); |
|
| 500 | 500 | } |
| 501 | 501 | } |
| 502 | 502 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function __construct() { |
| 66 | 66 | $this->id = 'stripe_bitcoin'; |
| 67 | - $this->method_title = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
| 67 | + $this->method_title = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
| 68 | 68 | /* translators: link */ |
| 69 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 69 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 70 | 70 | $this->supports = array( |
| 71 | 71 | 'products', |
| 72 | 72 | 'refunds', |
@@ -78,29 +78,29 @@ discard block |
||
| 78 | 78 | // Load the settings. |
| 79 | 79 | $this->init_settings(); |
| 80 | 80 | |
| 81 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 82 | - $this->title = $this->get_option( 'title' ); |
|
| 83 | - $this->description = $this->get_option( 'description' ); |
|
| 84 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 85 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 86 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 87 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 88 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 89 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 90 | - |
|
| 91 | - if ( $this->testmode ) { |
|
| 92 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 93 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 81 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 82 | + $this->title = $this->get_option('title'); |
|
| 83 | + $this->description = $this->get_option('description'); |
|
| 84 | + $this->enabled = $this->get_option('enabled'); |
|
| 85 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 86 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 87 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 88 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 89 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 90 | + |
|
| 91 | + if ($this->testmode) { |
|
| 92 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 93 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 97 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 98 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 99 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 100 | - add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) ); |
|
| 96 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 97 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 98 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 99 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 100 | + add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page')); |
|
| 101 | 101 | |
| 102 | 102 | // Customer Emails |
| 103 | - add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); |
|
| 103 | + add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | * @version 4.0.0 |
| 111 | 111 | */ |
| 112 | 112 | public function check_environment() { |
| 113 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 113 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $environment_warning = $this->get_environment_warning(); |
| 118 | 118 | |
| 119 | - if ( $environment_warning ) { |
|
| 120 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 119 | + if ($environment_warning) { |
|
| 120 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 124 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 125 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 123 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 124 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 125 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 126 | 126 | echo '</p></div>'; |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | * @version 4.0.0 |
| 136 | 136 | */ |
| 137 | 137 | public function get_environment_warning() { |
| 138 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 139 | - $message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' ); |
|
| 138 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 139 | + $message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe'); |
|
| 140 | 140 | |
| 141 | 141 | return $message; |
| 142 | 142 | } |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | * @return array |
| 153 | 153 | */ |
| 154 | 154 | public function get_supported_currency() { |
| 155 | - return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array( |
|
| 155 | + return apply_filters('wc_stripe_bitcoin_supported_currencies', array( |
|
| 156 | 156 | 'USD', |
| 157 | - ) ); |
|
| 157 | + )); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @return bool |
| 166 | 166 | */ |
| 167 | 167 | public function is_available() { |
| 168 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 168 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 169 | 169 | return false; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | $icons_str .= $icons['bitcoin']; |
| 188 | 188 | |
| 189 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 189 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -197,19 +197,19 @@ discard block |
||
| 197 | 197 | * @access public |
| 198 | 198 | */ |
| 199 | 199 | public function payment_scripts() { |
| 200 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 200 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 201 | 201 | return; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 205 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 204 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 205 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
| 209 | 209 | * Initialize Gateway Settings Form Fields. |
| 210 | 210 | */ |
| 211 | 211 | public function init_form_fields() { |
| 212 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' ); |
|
| 212 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php'); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -220,25 +220,25 @@ discard block |
||
| 220 | 220 | $total = WC()->cart->total; |
| 221 | 221 | |
| 222 | 222 | // If paying from order, we need to get total from order not cart. |
| 223 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 224 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 223 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 224 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 225 | 225 | $total = $order->get_total(); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - if ( is_add_payment_method_page() ) { |
|
| 229 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 230 | - $total = ''; |
|
| 228 | + if (is_add_payment_method_page()) { |
|
| 229 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 230 | + $total = ''; |
|
| 231 | 231 | } else { |
| 232 | 232 | $pay_button_text = ''; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | echo '<div |
| 236 | 236 | id="stripe-bitcoin-payment-data" |
| 237 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 238 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 237 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 238 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 239 | 239 | |
| 240 | - if ( $this->description ) { |
|
| 241 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 240 | + if ($this->description) { |
|
| 241 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | echo '</div>'; |
@@ -249,8 +249,8 @@ discard block |
||
| 249 | 249 | * |
| 250 | 250 | * @param int $order_id |
| 251 | 251 | */ |
| 252 | - public function thankyou_page( $order_id ) { |
|
| 253 | - $this->get_instructions( $order_id ); |
|
| 252 | + public function thankyou_page($order_id) { |
|
| 253 | + $this->get_instructions($order_id); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -262,13 +262,13 @@ discard block |
||
| 262 | 262 | * @param bool $sent_to_admin |
| 263 | 263 | * @param bool $plain_text |
| 264 | 264 | */ |
| 265 | - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { |
|
| 265 | + public function email_instructions($order, $sent_to_admin, $plain_text = false) { |
|
| 266 | 266 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 267 | 267 | |
| 268 | 268 | $payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method(); |
| 269 | 269 | |
| 270 | - if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) { |
|
| 271 | - $this->get_instructions( $order_id, $plain_text ); |
|
| 270 | + if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) { |
|
| 271 | + $this->get_instructions($order_id, $plain_text); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | |
@@ -279,38 +279,38 @@ discard block |
||
| 279 | 279 | * @version 4.0.0 |
| 280 | 280 | * @param int $order_id |
| 281 | 281 | */ |
| 282 | - public function get_instructions( $order_id, $plain_text = false ) { |
|
| 283 | - $data = get_post_meta( $order_id, '_stripe_bitcoin', true ); |
|
| 282 | + public function get_instructions($order_id, $plain_text = false) { |
|
| 283 | + $data = get_post_meta($order_id, '_stripe_bitcoin', true); |
|
| 284 | 284 | |
| 285 | - if ( $plain_text ) { |
|
| 286 | - esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 285 | + if ($plain_text) { |
|
| 286 | + esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 287 | 287 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 288 | - esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 288 | + esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 289 | 289 | echo $data['amount'] . "\n\n"; |
| 290 | 290 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 291 | - esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 291 | + esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 292 | 292 | echo $data['address'] . "\n\n"; |
| 293 | 293 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 294 | - esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
| 294 | + esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
| 295 | 295 | echo $data['uri'] . "\n\n"; |
| 296 | 296 | } else { |
| 297 | 297 | ?> |
| 298 | - <h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3> |
|
| 298 | + <h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3> |
|
| 299 | 299 | <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
| 300 | 300 | <li class="woocommerce-order-overview__order order"> |
| 301 | - <?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?> |
|
| 301 | + <?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?> |
|
| 302 | 302 | <strong><?php echo $data['amount']; ?></strong> |
| 303 | 303 | </li> |
| 304 | 304 | <li class="woocommerce-order-overview__order order"> |
| 305 | - <?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?> |
|
| 305 | + <?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?> |
|
| 306 | 306 | <strong><?php echo $data['address']; ?></strong> |
| 307 | 307 | </li> |
| 308 | 308 | <li class="woocommerce-order-overview__order order"> |
| 309 | - <?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?> |
|
| 309 | + <?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?> |
|
| 310 | 310 | <strong> |
| 311 | 311 | <?php |
| 312 | 312 | /* translators: link */ |
| 313 | - printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] ); |
|
| 313 | + printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']); |
|
| 314 | 314 | ?> |
| 315 | 315 | </strong> |
| 316 | 316 | </li> |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | * @param object $order |
| 328 | 328 | * @param object $source_object |
| 329 | 329 | */ |
| 330 | - public function save_instructions( $order, $source_object ) { |
|
| 330 | + public function save_instructions($order, $source_object) { |
|
| 331 | 331 | $data = array( |
| 332 | 332 | 'amount' => $source_object->bitcoin->amount, |
| 333 | 333 | 'address' => $source_object->bitcoin->address, |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | |
| 337 | 337 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 338 | 338 | |
| 339 | - update_post_meta( $order_id, '_stripe_bitcoin', $data ); |
|
| 339 | + update_post_meta($order_id, '_stripe_bitcoin', $data); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -350,39 +350,39 @@ discard block |
||
| 350 | 350 | * |
| 351 | 351 | * @return array|void |
| 352 | 352 | */ |
| 353 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 353 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 354 | 354 | try { |
| 355 | - $order = wc_get_order( $order_id ); |
|
| 355 | + $order = wc_get_order($order_id); |
|
| 356 | 356 | |
| 357 | 357 | // This comes from the create account checkbox in the checkout page. |
| 358 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 358 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 359 | 359 | |
| 360 | - if ( $create_account ) { |
|
| 360 | + if ($create_account) { |
|
| 361 | 361 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 362 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 362 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 363 | 363 | $new_stripe_customer->create_customer(); |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - $prepared_source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), $force_save_source ); |
|
| 366 | + $prepared_source = $this->prepare_source($this->create_source_object(), get_current_user_id(), $force_save_source); |
|
| 367 | 367 | |
| 368 | - if ( empty( $prepared_source->source ) ) { |
|
| 369 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 370 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 368 | + if (empty($prepared_source->source)) { |
|
| 369 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 370 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | // Store source to order meta. |
| 374 | - $this->save_source( $order, $prepared_source ); |
|
| 374 | + $this->save_source($order, $prepared_source); |
|
| 375 | 375 | |
| 376 | 376 | |
| 377 | 377 | // This will throw exception if not valid. |
| 378 | - $this->validate_minimum_order_amount( $order ); |
|
| 378 | + $this->validate_minimum_order_amount($order); |
|
| 379 | 379 | |
| 380 | - $this->save_instructions( $order, $this->create_source_object() ); |
|
| 380 | + $this->save_instructions($order, $this->create_source_object()); |
|
| 381 | 381 | |
| 382 | 382 | // Mark as on-hold (we're awaiting the payment) |
| 383 | - $order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) ); |
|
| 383 | + $order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe')); |
|
| 384 | 384 | |
| 385 | - wc_reduce_stock_levels( $order_id ); |
|
| 385 | + wc_reduce_stock_levels($order_id); |
|
| 386 | 386 | |
| 387 | 387 | // Remove cart |
| 388 | 388 | WC()->cart->empty_cart(); |
@@ -390,16 +390,16 @@ discard block |
||
| 390 | 390 | // Return thankyou redirect |
| 391 | 391 | return array( |
| 392 | 392 | 'result' => 'success', |
| 393 | - 'redirect' => $this->get_return_url( $order ), |
|
| 393 | + 'redirect' => $this->get_return_url($order), |
|
| 394 | 394 | ); |
| 395 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 396 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 397 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 395 | + } catch (WC_Stripe_Exception $e) { |
|
| 396 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 397 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 398 | 398 | |
| 399 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 399 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 400 | 400 | |
| 401 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 402 | - $this->send_failed_order_email( $order_id ); |
|
| 401 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 402 | + $this->send_failed_order_email($order_id); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | return array( |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @since 3.1.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -56,35 +56,35 @@ discard block |
||
| 56 | 56 | * @version 4.0.0 |
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 60 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
| 61 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
| 62 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
| 63 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
| 64 | - |
|
| 65 | - if ( $this->testmode ) { |
|
| 66 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
| 59 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
| 60 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
| 61 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
| 62 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
| 63 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
| 64 | + |
|
| 65 | + if ($this->testmode) { |
|
| 66 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // If both site title and statement descriptor is not set. Fallback. |
| 70 | - if ( empty( $this->total_label ) ) { |
|
| 70 | + if (empty($this->total_label)) { |
|
| 71 | 71 | $this->total_label = $_SERVER['SERVER_NAME']; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
| 74 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
| 75 | 75 | |
| 76 | 76 | // Checks if Stripe Gateway is enabled. |
| 77 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
| 77 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
| 78 | 78 | return; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // Checks if Payment Request is enabled. |
| 82 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
| 82 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
| 83 | 83 | return; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // Don't load for change payment method page. |
| 87 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
| 87 | + if (isset($_GET['change_payment_method'])) { |
|
| 88 | 88 | return; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -98,43 +98,43 @@ discard block |
||
| 98 | 98 | * @version 4.0.0 |
| 99 | 99 | */ |
| 100 | 100 | protected function init() { |
| 101 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
| 102 | - add_action( 'wp', array( $this, 'set_session' ) ); |
|
| 101 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
| 102 | + add_action('wp', array($this, 'set_session')); |
|
| 103 | 103 | |
| 104 | 104 | /* |
| 105 | 105 | * In order to display the Payment Request button in the correct position, |
| 106 | 106 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
| 107 | 107 | * CSS is used to position the button. |
| 108 | 108 | */ |
| 109 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 110 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 111 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 109 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 110 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
| 111 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 112 | 112 | } else { |
| 113 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 114 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 113 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
| 114 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 118 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 117 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
| 118 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 119 | 119 | |
| 120 | - if ( apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
| 121 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
| 122 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
| 120 | + if (apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
| 121 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
| 122 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
| 126 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
| 127 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
| 128 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
| 129 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
| 130 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
| 131 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
| 132 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
| 125 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
| 126 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
| 127 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
| 128 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
| 129 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
| 130 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
| 131 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
| 132 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
| 133 | 133 | |
| 134 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
| 135 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
| 134 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
| 135 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
| 136 | 136 | |
| 137 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 3 ); |
|
| 137 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 3); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -144,11 +144,11 @@ discard block |
||
| 144 | 144 | * @since 4.0.0 |
| 145 | 145 | */ |
| 146 | 146 | public function set_session() { |
| 147 | - if ( ! is_user_logged_in() ) { |
|
| 147 | + if ( ! is_user_logged_in()) { |
|
| 148 | 148 | $wc_session = new WC_Session_Handler(); |
| 149 | 149 | |
| 150 | - if ( ! $wc_session->has_session() ) { |
|
| 151 | - $wc_session->set_customer_session_cookie( true ); |
|
| 150 | + if ( ! $wc_session->has_session()) { |
|
| 151 | + $wc_session->set_customer_session_cookie(true); |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @return string |
| 162 | 162 | */ |
| 163 | 163 | public function get_button_type() { |
| 164 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 164 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @return string |
| 173 | 173 | */ |
| 174 | 174 | public function get_button_theme() { |
| 175 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 175 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @return string |
| 184 | 184 | */ |
| 185 | 185 | public function get_button_height() { |
| 186 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
| 186 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -193,40 +193,40 @@ discard block |
||
| 193 | 193 | * @version 4.0.0 |
| 194 | 194 | */ |
| 195 | 195 | public function get_product_data() { |
| 196 | - if ( ! is_product() ) { |
|
| 196 | + if ( ! is_product()) { |
|
| 197 | 197 | return false; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | global $post; |
| 201 | 201 | |
| 202 | - $product = wc_get_product( $post->ID ); |
|
| 202 | + $product = wc_get_product($post->ID); |
|
| 203 | 203 | |
| 204 | 204 | $data = array(); |
| 205 | 205 | $items = array(); |
| 206 | 206 | |
| 207 | 207 | $items[] = array( |
| 208 | 208 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
| 209 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
| 209 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
| 210 | 210 | ); |
| 211 | 211 | |
| 212 | - if ( wc_tax_enabled() ) { |
|
| 212 | + if (wc_tax_enabled()) { |
|
| 213 | 213 | $items[] = array( |
| 214 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 214 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 215 | 215 | 'amount' => 0, |
| 216 | 216 | 'pending' => true, |
| 217 | 217 | ); |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 220 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 221 | 221 | $items[] = array( |
| 222 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 222 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 223 | 223 | 'amount' => 0, |
| 224 | 224 | 'pending' => true, |
| 225 | 225 | ); |
| 226 | 226 | |
| 227 | - $data['shippingOptions'] = array( |
|
| 227 | + $data['shippingOptions'] = array( |
|
| 228 | 228 | 'id' => 'pending', |
| 229 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 229 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 230 | 230 | 'detail' => '', |
| 231 | 231 | 'amount' => 0, |
| 232 | 232 | ); |
@@ -235,13 +235,13 @@ discard block |
||
| 235 | 235 | $data['displayItems'] = $items; |
| 236 | 236 | $data['total'] = array( |
| 237 | 237 | 'label' => $this->total_label, |
| 238 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
| 238 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
| 239 | 239 | 'pending' => true, |
| 240 | 240 | ); |
| 241 | 241 | |
| 242 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 243 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 244 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 242 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 243 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 244 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 245 | 245 | |
| 246 | 246 | return $data; |
| 247 | 247 | } |
@@ -250,25 +250,25 @@ discard block |
||
| 250 | 250 | * Filters the gateway title to reflect Payment Request type |
| 251 | 251 | * |
| 252 | 252 | */ |
| 253 | - public function filter_gateway_title( $title, $id ) { |
|
| 253 | + public function filter_gateway_title($title, $id) { |
|
| 254 | 254 | global $post; |
| 255 | 255 | |
| 256 | - if ( ! is_object( $post ) ) { |
|
| 256 | + if ( ! is_object($post)) { |
|
| 257 | 257 | return $title; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 261 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
| 260 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 261 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
| 262 | 262 | } else { |
| 263 | - $order = wc_get_order( $post->ID ); |
|
| 264 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
| 263 | + $order = wc_get_order($post->ID); |
|
| 264 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
| 267 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
| 268 | 268 | return $method_title; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
| 271 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
| 272 | 272 | return $method_title; |
| 273 | 273 | } |
| 274 | 274 | |
@@ -281,10 +281,10 @@ discard block |
||
| 281 | 281 | * @since 3.1.4 |
| 282 | 282 | * @version 4.0.0 |
| 283 | 283 | */ |
| 284 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
| 284 | + public function postal_code_validation($valid, $postcode, $country) { |
|
| 285 | 285 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 286 | 286 | |
| 287 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 287 | + if ( ! isset($gateways['stripe'])) { |
|
| 288 | 288 | return $valid; |
| 289 | 289 | } |
| 290 | 290 | |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | * the order and not let it go through. The remedy for now is just to remove this validation. |
| 295 | 295 | * Note that this only works with shipping providers that don't validate full postal codes. |
| 296 | 296 | */ |
| 297 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
| 297 | + if ('GB' === $country || 'CA' === $country) { |
|
| 298 | 298 | return true; |
| 299 | 299 | } |
| 300 | 300 | |
@@ -310,27 +310,27 @@ discard block |
||
| 310 | 310 | * @param array $posted_data The posted data from checkout form. |
| 311 | 311 | * @param object $order |
| 312 | 312 | */ |
| 313 | - public function add_order_meta( $order_id, $posted_data, $order ) { |
|
| 314 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
| 313 | + public function add_order_meta($order_id, $posted_data, $order) { |
|
| 314 | + if (empty($_POST['payment_request_type'])) { |
|
| 315 | 315 | return; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
| 318 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
| 319 | 319 | |
| 320 | - if ( 'apple_pay' === $payment_request_type ) { |
|
| 321 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 322 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
| 320 | + if ('apple_pay' === $payment_request_type) { |
|
| 321 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 322 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
| 323 | 323 | } else { |
| 324 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
| 324 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
| 325 | 325 | $order->save(); |
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
| 330 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 331 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
| 329 | + if ('payment_request_api' === $payment_request_type) { |
|
| 330 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 331 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
| 332 | 332 | } else { |
| 333 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
| 333 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
| 334 | 334 | $order->save(); |
| 335 | 335 | } |
| 336 | 336 | } |
@@ -344,11 +344,11 @@ discard block |
||
| 344 | 344 | * @return array |
| 345 | 345 | */ |
| 346 | 346 | public function supported_product_types() { |
| 347 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
| 347 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
| 348 | 348 | 'simple', |
| 349 | 349 | 'variable', |
| 350 | 350 | 'variation', |
| 351 | - ) ); |
|
| 351 | + )); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -359,15 +359,15 @@ discard block |
||
| 359 | 359 | * @return bool |
| 360 | 360 | */ |
| 361 | 361 | public function allowed_items_in_cart() { |
| 362 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 363 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
| 362 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 363 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
| 364 | 364 | |
| 365 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
| 365 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
| 366 | 366 | return false; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | // Pre Orders compatbility where we don't support charge upon release. |
| 370 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
| 370 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
| 371 | 371 | return false; |
| 372 | 372 | } |
| 373 | 373 | } |
@@ -382,71 +382,71 @@ discard block |
||
| 382 | 382 | * @version 4.0.0 |
| 383 | 383 | */ |
| 384 | 384 | public function scripts() { |
| 385 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 385 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
| 386 | 386 | return; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - if ( is_product() ) { |
|
| 389 | + if (is_product()) { |
|
| 390 | 390 | global $post; |
| 391 | 391 | |
| 392 | - $product = wc_get_product( $post->ID ); |
|
| 392 | + $product = wc_get_product($post->ID); |
|
| 393 | 393 | |
| 394 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 394 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 395 | 395 | return; |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 398 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 399 | 399 | return; |
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 403 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 404 | 404 | |
| 405 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 406 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 405 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 406 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 407 | 407 | |
| 408 | 408 | wp_localize_script( |
| 409 | 409 | 'wc_stripe_payment_request', |
| 410 | 410 | 'wc_stripe_payment_request_params', |
| 411 | 411 | array( |
| 412 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
| 412 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
| 413 | 413 | 'stripe' => array( |
| 414 | 414 | 'key' => $this->publishable_key, |
| 415 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
| 415 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
| 416 | 416 | ), |
| 417 | 417 | 'nonce' => array( |
| 418 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
| 419 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
| 420 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
| 421 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
| 422 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
| 423 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
| 424 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
| 425 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
| 418 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
| 419 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
| 420 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
| 421 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
| 422 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
| 423 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
| 424 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
| 425 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
| 426 | 426 | ), |
| 427 | 427 | 'i18n' => array( |
| 428 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
| 428 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
| 429 | 429 | /* translators: Do not translate the [option] placeholder */ |
| 430 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
| 430 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
| 431 | 431 | ), |
| 432 | 432 | 'checkout' => array( |
| 433 | 433 | 'url' => wc_get_checkout_url(), |
| 434 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
| 435 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 434 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
| 435 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 436 | 436 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
| 437 | 437 | ), |
| 438 | 438 | 'button' => array( |
| 439 | 439 | 'type' => $this->get_button_type(), |
| 440 | 440 | 'theme' => $this->get_button_theme(), |
| 441 | 441 | 'height' => $this->get_button_height(), |
| 442 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
| 442 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
| 443 | 443 | ), |
| 444 | 444 | 'is_product_page' => is_product(), |
| 445 | 445 | 'product' => $this->get_product_data(), |
| 446 | 446 | ) |
| 447 | 447 | ); |
| 448 | 448 | |
| 449 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
| 449 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -458,35 +458,35 @@ discard block |
||
| 458 | 458 | public function display_payment_request_button_html() { |
| 459 | 459 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 460 | 460 | |
| 461 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 461 | + if ( ! isset($gateways['stripe'])) { |
|
| 462 | 462 | return; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 465 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 466 | 466 | return; |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 469 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 470 | 470 | return; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - if ( is_product() ) { |
|
| 473 | + if (is_product()) { |
|
| 474 | 474 | global $post; |
| 475 | 475 | |
| 476 | - $product = wc_get_product( $post->ID ); |
|
| 476 | + $product = wc_get_product($post->ID); |
|
| 477 | 477 | |
| 478 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 478 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 479 | 479 | return; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | // Pre Orders charge upon release not supported. |
| 483 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 484 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 483 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 484 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 485 | 485 | return; |
| 486 | 486 | } |
| 487 | 487 | } else { |
| 488 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 489 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 488 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 489 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 490 | 490 | return; |
| 491 | 491 | } |
| 492 | 492 | } |
@@ -508,40 +508,40 @@ discard block |
||
| 508 | 508 | public function display_payment_request_button_separator_html() { |
| 509 | 509 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
| 510 | 510 | |
| 511 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
| 511 | + if ( ! isset($gateways['stripe'])) { |
|
| 512 | 512 | return; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
| 515 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
| 516 | 516 | return; |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
| 519 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
| 520 | 520 | return; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - if ( is_product() ) { |
|
| 523 | + if (is_product()) { |
|
| 524 | 524 | global $post; |
| 525 | 525 | |
| 526 | - $product = wc_get_product( $post->ID ); |
|
| 526 | + $product = wc_get_product($post->ID); |
|
| 527 | 527 | |
| 528 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
| 528 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
| 529 | 529 | return; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | // Pre Orders charge upon release not supported. |
| 533 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
| 534 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
| 533 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
| 534 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
| 535 | 535 | return; |
| 536 | 536 | } |
| 537 | 537 | } else { |
| 538 | - if ( ! $this->allowed_items_in_cart() ) { |
|
| 539 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
| 538 | + if ( ! $this->allowed_items_in_cart()) { |
|
| 539 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
| 540 | 540 | return; |
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | 543 | ?> |
| 544 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> -</p> |
|
| 544 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">- <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> -</p> |
|
| 545 | 545 | <?php |
| 546 | 546 | } |
| 547 | 547 | |
@@ -552,11 +552,11 @@ discard block |
||
| 552 | 552 | * @version 4.0.0 |
| 553 | 553 | */ |
| 554 | 554 | public function ajax_log_errors() { |
| 555 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
| 555 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
| 556 | 556 | |
| 557 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
| 557 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
| 558 | 558 | |
| 559 | - WC_Stripe_Logger::log( $errors ); |
|
| 559 | + WC_Stripe_Logger::log($errors); |
|
| 560 | 560 | |
| 561 | 561 | exit; |
| 562 | 562 | } |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | * @version 4.0.0 |
| 569 | 569 | */ |
| 570 | 570 | public function ajax_clear_cart() { |
| 571 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
| 571 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
| 572 | 572 | |
| 573 | 573 | WC()->cart->empty_cart(); |
| 574 | 574 | exit; |
@@ -578,10 +578,10 @@ discard block |
||
| 578 | 578 | * Get cart details. |
| 579 | 579 | */ |
| 580 | 580 | public function ajax_get_cart_details() { |
| 581 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
| 581 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
| 582 | 582 | |
| 583 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 584 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 583 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 584 | + define('WOOCOMMERCE_CART', true); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | WC()->cart->calculate_totals(); |
@@ -592,14 +592,14 @@ discard block |
||
| 592 | 592 | $data = array( |
| 593 | 593 | 'shipping_required' => WC()->cart->needs_shipping(), |
| 594 | 594 | 'order_data' => array( |
| 595 | - 'currency' => strtolower( $currency ), |
|
| 596 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
| 595 | + 'currency' => strtolower($currency), |
|
| 596 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
| 597 | 597 | ), |
| 598 | 598 | ); |
| 599 | 599 | |
| 600 | 600 | $data['order_data'] += $this->build_display_items(); |
| 601 | 601 | |
| 602 | - wp_send_json( $data ); |
|
| 602 | + wp_send_json($data); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -610,47 +610,47 @@ discard block |
||
| 610 | 610 | * @see WC_Shipping::get_packages(). |
| 611 | 611 | */ |
| 612 | 612 | public function ajax_get_shipping_options() { |
| 613 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
| 613 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
| 614 | 614 | |
| 615 | 615 | try { |
| 616 | 616 | // Set the shipping package. |
| 617 | - $posted = filter_input_array( INPUT_POST, array( |
|
| 617 | + $posted = filter_input_array(INPUT_POST, array( |
|
| 618 | 618 | 'country' => FILTER_SANITIZE_STRING, |
| 619 | 619 | 'state' => FILTER_SANITIZE_STRING, |
| 620 | 620 | 'postcode' => FILTER_SANITIZE_STRING, |
| 621 | 621 | 'city' => FILTER_SANITIZE_STRING, |
| 622 | 622 | 'address' => FILTER_SANITIZE_STRING, |
| 623 | 623 | 'address_2' => FILTER_SANITIZE_STRING, |
| 624 | - ) ); |
|
| 624 | + )); |
|
| 625 | 625 | |
| 626 | - $this->calculate_shipping( $posted ); |
|
| 626 | + $this->calculate_shipping($posted); |
|
| 627 | 627 | |
| 628 | 628 | // Set the shipping options. |
| 629 | 629 | $data = array(); |
| 630 | 630 | $packages = WC()->shipping->get_packages(); |
| 631 | 631 | |
| 632 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
| 633 | - foreach ( $packages as $package_key => $package ) { |
|
| 634 | - if ( empty( $package['rates'] ) ) { |
|
| 635 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 632 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
| 633 | + foreach ($packages as $package_key => $package) { |
|
| 634 | + if (empty($package['rates'])) { |
|
| 635 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - foreach ( $package['rates'] as $key => $rate ) { |
|
| 638 | + foreach ($package['rates'] as $key => $rate) { |
|
| 639 | 639 | $data['shipping_options'][] = array( |
| 640 | 640 | 'id' => $rate->id, |
| 641 | 641 | 'label' => $rate->label, |
| 642 | 642 | 'detail' => '', |
| 643 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
| 643 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
| 644 | 644 | ); |
| 645 | 645 | } |
| 646 | 646 | } |
| 647 | 647 | } else { |
| 648 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
| 648 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | - if ( isset( $data[0] ) ) { |
|
| 651 | + if (isset($data[0])) { |
|
| 652 | 652 | // Auto select the first shipping method. |
| 653 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
| 653 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | WC()->cart->calculate_totals(); |
@@ -658,12 +658,12 @@ discard block |
||
| 658 | 658 | $data += $this->build_display_items(); |
| 659 | 659 | $data['result'] = 'success'; |
| 660 | 660 | |
| 661 | - wp_send_json( $data ); |
|
| 662 | - } catch ( Exception $e ) { |
|
| 661 | + wp_send_json($data); |
|
| 662 | + } catch (Exception $e) { |
|
| 663 | 663 | $data += $this->build_display_items(); |
| 664 | 664 | $data['result'] = 'invalid_shipping_address'; |
| 665 | 665 | |
| 666 | - wp_send_json( $data ); |
|
| 666 | + wp_send_json($data); |
|
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | |
@@ -671,22 +671,22 @@ discard block |
||
| 671 | 671 | * Update shipping method. |
| 672 | 672 | */ |
| 673 | 673 | public function ajax_update_shipping_method() { |
| 674 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
| 674 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
| 675 | 675 | |
| 676 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 677 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 676 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 677 | + define('WOOCOMMERCE_CART', true); |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
| 681 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
| 680 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
| 681 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
| 682 | 682 | |
| 683 | - if ( is_array( $shipping_method ) ) { |
|
| 684 | - foreach ( $shipping_method as $i => $value ) { |
|
| 685 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
| 683 | + if (is_array($shipping_method)) { |
|
| 684 | + foreach ($shipping_method as $i => $value) { |
|
| 685 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
| 686 | 686 | } |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
| 689 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
| 690 | 690 | |
| 691 | 691 | WC()->cart->calculate_totals(); |
| 692 | 692 | |
@@ -694,7 +694,7 @@ discard block |
||
| 694 | 694 | $data += $this->build_display_items(); |
| 695 | 695 | $data['result'] = 'success'; |
| 696 | 696 | |
| 697 | - wp_send_json( $data ); |
|
| 697 | + wp_send_json($data); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | /** |
@@ -705,31 +705,31 @@ discard block |
||
| 705 | 705 | * @return array $data |
| 706 | 706 | */ |
| 707 | 707 | public function ajax_get_selected_product_data() { |
| 708 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
| 708 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
| 709 | 709 | |
| 710 | - $product_id = absint( $_POST['product_id'] ); |
|
| 711 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 710 | + $product_id = absint($_POST['product_id']); |
|
| 711 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 712 | 712 | |
| 713 | - $product = wc_get_product( $product_id ); |
|
| 713 | + $product = wc_get_product($product_id); |
|
| 714 | 714 | |
| 715 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 716 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 715 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 716 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 717 | 717 | |
| 718 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 719 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 718 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 719 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 720 | 720 | } else { |
| 721 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 722 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 721 | + $data_store = WC_Data_Store::load('product'); |
|
| 722 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | - if ( ! empty( $variation_id ) ) { |
|
| 726 | - $product = wc_get_product( $variation_id ); |
|
| 725 | + if ( ! empty($variation_id)) { |
|
| 726 | + $product = wc_get_product($variation_id); |
|
| 727 | 727 | } |
| 728 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
| 729 | - $product = wc_get_product( $product_id ); |
|
| 728 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
| 729 | + $product = wc_get_product($product_id); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
| 732 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
| 733 | 733 | |
| 734 | 734 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
| 735 | 735 | |
@@ -737,28 +737,28 @@ discard block |
||
| 737 | 737 | $items = array(); |
| 738 | 738 | |
| 739 | 739 | $items[] = array( |
| 740 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
| 741 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 740 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
| 741 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 742 | 742 | ); |
| 743 | 743 | |
| 744 | - if ( wc_tax_enabled() ) { |
|
| 744 | + if (wc_tax_enabled()) { |
|
| 745 | 745 | $items[] = array( |
| 746 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
| 746 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
| 747 | 747 | 'amount' => 0, |
| 748 | 748 | 'pending' => true, |
| 749 | 749 | ); |
| 750 | 750 | } |
| 751 | 751 | |
| 752 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
| 752 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
| 753 | 753 | $items[] = array( |
| 754 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
| 754 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
| 755 | 755 | 'amount' => 0, |
| 756 | 756 | 'pending' => true, |
| 757 | 757 | ); |
| 758 | 758 | |
| 759 | - $data['shippingOptions'] = array( |
|
| 759 | + $data['shippingOptions'] = array( |
|
| 760 | 760 | 'id' => 'pending', |
| 761 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
| 761 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
| 762 | 762 | 'detail' => '', |
| 763 | 763 | 'amount' => 0, |
| 764 | 764 | ); |
@@ -767,15 +767,15 @@ discard block |
||
| 767 | 767 | $data['displayItems'] = $items; |
| 768 | 768 | $data['total'] = array( |
| 769 | 769 | 'label' => $this->total_label, |
| 770 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
| 770 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
| 771 | 771 | 'pending' => true, |
| 772 | 772 | ); |
| 773 | 773 | |
| 774 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
| 775 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
| 776 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
| 774 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
| 775 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
| 776 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
| 777 | 777 | |
| 778 | - wp_send_json( $data ); |
|
| 778 | + wp_send_json($data); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | /** |
@@ -786,37 +786,37 @@ discard block |
||
| 786 | 786 | * @return array $data |
| 787 | 787 | */ |
| 788 | 788 | public function ajax_add_to_cart() { |
| 789 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
| 789 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
| 790 | 790 | |
| 791 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 792 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 791 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 792 | + define('WOOCOMMERCE_CART', true); |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | WC()->shipping->reset_shipping(); |
| 796 | 796 | |
| 797 | - $product_id = absint( $_POST['product_id'] ); |
|
| 798 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
| 797 | + $product_id = absint($_POST['product_id']); |
|
| 798 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
| 799 | 799 | |
| 800 | - $product = wc_get_product( $product_id ); |
|
| 800 | + $product = wc_get_product($product_id); |
|
| 801 | 801 | |
| 802 | 802 | // First empty the cart to prevent wrong calculation. |
| 803 | 803 | WC()->cart->empty_cart(); |
| 804 | 804 | |
| 805 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
| 806 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
| 805 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
| 806 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
| 807 | 807 | |
| 808 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 809 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
| 808 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 809 | + $variation_id = $product->get_matching_variation($attributes); |
|
| 810 | 810 | } else { |
| 811 | - $data_store = WC_Data_Store::load( 'product' ); |
|
| 812 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
| 811 | + $data_store = WC_Data_Store::load('product'); |
|
| 812 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
| 815 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
| 819 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
| 818 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
| 819 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | WC()->cart->calculate_totals(); |
@@ -825,7 +825,7 @@ discard block |
||
| 825 | 825 | $data += $this->build_display_items(); |
| 826 | 826 | $data['result'] = 'success'; |
| 827 | 827 | |
| 828 | - wp_send_json( $data ); |
|
| 828 | + wp_send_json($data); |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | /** |
@@ -838,31 +838,31 @@ discard block |
||
| 838 | 838 | * @version 4.0.0 |
| 839 | 839 | */ |
| 840 | 840 | public function normalize_state() { |
| 841 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
| 842 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
| 843 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
| 844 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
| 841 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
| 842 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
| 843 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
| 844 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
| 845 | 845 | |
| 846 | - if ( $billing_state && $billing_country ) { |
|
| 847 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
| 846 | + if ($billing_state && $billing_country) { |
|
| 847 | + $valid_states = WC()->countries->get_states($billing_country); |
|
| 848 | 848 | |
| 849 | 849 | // Valid states found for country. |
| 850 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 851 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 852 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
| 850 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 851 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 852 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
| 853 | 853 | $_POST['billing_state'] = $state_abbr; |
| 854 | 854 | } |
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | } |
| 858 | 858 | |
| 859 | - if ( $shipping_state && $shipping_country ) { |
|
| 860 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
| 859 | + if ($shipping_state && $shipping_country) { |
|
| 860 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
| 861 | 861 | |
| 862 | 862 | // Valid states found for country. |
| 863 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
| 864 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
| 865 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
| 863 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
| 864 | + foreach ($valid_states as $state_abbr => $state) { |
|
| 865 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
| 866 | 866 | $_POST['shipping_state'] = $state_abbr; |
| 867 | 867 | } |
| 868 | 868 | } |
@@ -877,19 +877,19 @@ discard block |
||
| 877 | 877 | * @version 4.0.0 |
| 878 | 878 | */ |
| 879 | 879 | public function ajax_create_order() { |
| 880 | - if ( WC()->cart->is_empty() ) { |
|
| 881 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
| 880 | + if (WC()->cart->is_empty()) { |
|
| 881 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
| 885 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
| 884 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
| 885 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | $this->normalize_state(); |
| 889 | 889 | |
| 890 | 890 | WC()->checkout()->process_checkout(); |
| 891 | 891 | |
| 892 | - die( 0 ); |
|
| 892 | + die(0); |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
@@ -899,7 +899,7 @@ discard block |
||
| 899 | 899 | * @version 4.0.0 |
| 900 | 900 | * @param array $address |
| 901 | 901 | */ |
| 902 | - protected function calculate_shipping( $address = array() ) { |
|
| 902 | + protected function calculate_shipping($address = array()) { |
|
| 903 | 903 | global $states; |
| 904 | 904 | |
| 905 | 905 | $country = $address['country']; |
@@ -916,28 +916,28 @@ discard block |
||
| 916 | 916 | * In some versions of Chrome, state can be a full name. So we need |
| 917 | 917 | * to convert that to abbreviation as WC is expecting that. |
| 918 | 918 | */ |
| 919 | - if ( 2 < strlen( $state ) ) { |
|
| 920 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
| 919 | + if (2 < strlen($state)) { |
|
| 920 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | WC()->shipping->reset_shipping(); |
| 924 | 924 | |
| 925 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
| 926 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
| 925 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
| 926 | + $postcode = wc_format_postcode($postcode, $country); |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | - if ( $country ) { |
|
| 930 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
| 931 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
| 929 | + if ($country) { |
|
| 930 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
| 931 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
| 932 | 932 | } else { |
| 933 | 933 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
| 934 | 934 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
| 935 | 935 | } |
| 936 | 936 | |
| 937 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 938 | - WC()->customer->calculated_shipping( true ); |
|
| 937 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 938 | + WC()->customer->calculated_shipping(true); |
|
| 939 | 939 | } else { |
| 940 | - WC()->customer->set_calculated_shipping( true ); |
|
| 940 | + WC()->customer->set_calculated_shipping(true); |
|
| 941 | 941 | WC()->customer->save(); |
| 942 | 942 | } |
| 943 | 943 | |
@@ -954,17 +954,17 @@ discard block |
||
| 954 | 954 | $packages[0]['destination']['address'] = $address_1; |
| 955 | 955 | $packages[0]['destination']['address_2'] = $address_2; |
| 956 | 956 | |
| 957 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
| 958 | - if ( $item['data']->needs_shipping() ) { |
|
| 959 | - if ( isset( $item['line_total'] ) ) { |
|
| 957 | + foreach (WC()->cart->get_cart() as $item) { |
|
| 958 | + if ($item['data']->needs_shipping()) { |
|
| 959 | + if (isset($item['line_total'])) { |
|
| 960 | 960 | $packages[0]['contents_cost'] += $item['line_total']; |
| 961 | 961 | } |
| 962 | 962 | } |
| 963 | 963 | } |
| 964 | 964 | |
| 965 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
| 965 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
| 966 | 966 | |
| 967 | - WC()->shipping->calculate_shipping( $packages ); |
|
| 967 | + WC()->shipping->calculate_shipping($packages); |
|
| 968 | 968 | } |
| 969 | 969 | |
| 970 | 970 | /** |
@@ -973,19 +973,19 @@ discard block |
||
| 973 | 973 | * @since 3.1.0 |
| 974 | 974 | * @version 4.0.0 |
| 975 | 975 | */ |
| 976 | - protected function build_shipping_methods( $shipping_methods ) { |
|
| 977 | - if ( empty( $shipping_methods ) ) { |
|
| 976 | + protected function build_shipping_methods($shipping_methods) { |
|
| 977 | + if (empty($shipping_methods)) { |
|
| 978 | 978 | return array(); |
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | $shipping = array(); |
| 982 | 982 | |
| 983 | - foreach ( $shipping_methods as $method ) { |
|
| 983 | + foreach ($shipping_methods as $method) { |
|
| 984 | 984 | $shipping[] = array( |
| 985 | 985 | 'id' => $method['id'], |
| 986 | 986 | 'label' => $method['label'], |
| 987 | 987 | 'detail' => '', |
| 988 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
| 988 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
| 989 | 989 | ); |
| 990 | 990 | } |
| 991 | 991 | |
@@ -999,69 +999,69 @@ discard block |
||
| 999 | 999 | * @version 4.0.0 |
| 1000 | 1000 | */ |
| 1001 | 1001 | protected function build_display_items() { |
| 1002 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
| 1003 | - define( 'WOOCOMMERCE_CART', true ); |
|
| 1002 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
| 1003 | + define('WOOCOMMERCE_CART', true); |
|
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | $items = array(); |
| 1007 | 1007 | $subtotal = 0; |
| 1008 | 1008 | |
| 1009 | 1009 | // Default show only subtotal instead of itemization. |
| 1010 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
| 1011 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
| 1010 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
| 1011 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
| 1012 | 1012 | $amount = $cart_item['line_subtotal']; |
| 1013 | - $subtotal += $cart_item['line_subtotal']; |
|
| 1013 | + $subtotal += $cart_item['line_subtotal']; |
|
| 1014 | 1014 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
| 1015 | 1015 | |
| 1016 | 1016 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
| 1017 | 1017 | |
| 1018 | 1018 | $item = array( |
| 1019 | 1019 | 'label' => $product_name . $quantity_label, |
| 1020 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
| 1020 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
| 1021 | 1021 | ); |
| 1022 | 1022 | |
| 1023 | 1023 | $items[] = $item; |
| 1024 | 1024 | } |
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 1027 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
| 1028 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
| 1029 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
| 1030 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
| 1031 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
| 1027 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
| 1028 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
| 1029 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
| 1030 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
| 1031 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
| 1032 | 1032 | |
| 1033 | - if ( wc_tax_enabled() ) { |
|
| 1033 | + if (wc_tax_enabled()) { |
|
| 1034 | 1034 | $items[] = array( |
| 1035 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
| 1036 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
| 1035 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
| 1036 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
| 1037 | 1037 | ); |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | - if ( WC()->cart->needs_shipping() ) { |
|
| 1040 | + if (WC()->cart->needs_shipping()) { |
|
| 1041 | 1041 | $items[] = array( |
| 1042 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
| 1043 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
| 1042 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
| 1043 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
| 1044 | 1044 | ); |
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | - if ( WC()->cart->has_discount() ) { |
|
| 1047 | + if (WC()->cart->has_discount()) { |
|
| 1048 | 1048 | $items[] = array( |
| 1049 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
| 1050 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
| 1049 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
| 1050 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
| 1051 | 1051 | ); |
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
| 1054 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
| 1055 | 1055 | $cart_fees = WC()->cart->fees; |
| 1056 | 1056 | } else { |
| 1057 | 1057 | $cart_fees = WC()->cart->get_fees(); |
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | 1060 | // Include fees and taxes as display items. |
| 1061 | - foreach ( $cart_fees as $key => $fee ) { |
|
| 1061 | + foreach ($cart_fees as $key => $fee) { |
|
| 1062 | 1062 | $items[] = array( |
| 1063 | 1063 | 'label' => $fee->name, |
| 1064 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
| 1064 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
| 1065 | 1065 | ); |
| 1066 | 1066 | } |
| 1067 | 1067 | |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | 'displayItems' => $items, |
| 1070 | 1070 | 'total' => array( |
| 1071 | 1071 | 'label' => $this->total_label, |
| 1072 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
| 1072 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
| 1073 | 1073 | 'pending' => false, |
| 1074 | 1074 | ), |
| 1075 | 1075 | ); |
@@ -14,20 +14,20 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 17 | +if ( ! defined('ABSPATH')) { |
|
| 18 | 18 | exit; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
| 21 | +if ( ! class_exists('WC_Stripe')) : |
|
| 22 | 22 | /** |
| 23 | 23 | * Required minimums and constants |
| 24 | 24 | */ |
| 25 | - define( 'WC_STRIPE_VERSION', '4.0.3' ); |
|
| 26 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
| 27 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
| 28 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
| 29 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
| 30 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
| 25 | + define('WC_STRIPE_VERSION', '4.0.3'); |
|
| 26 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
| 27 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
| 28 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
| 29 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
| 30 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
| 31 | 31 | |
| 32 | 32 | class WC_Stripe { |
| 33 | 33 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return Singleton The *Singleton* instance. |
| 48 | 48 | */ |
| 49 | 49 | public static function get_instance() { |
| 50 | - if ( null === self::$instance ) { |
|
| 50 | + if (null === self::$instance) { |
|
| 51 | 51 | self::$instance = new self(); |
| 52 | 52 | } |
| 53 | 53 | return self::$instance; |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | * *Singleton* via the `new` operator from outside of this class. |
| 81 | 81 | */ |
| 82 | 82 | private function __construct() { |
| 83 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
| 84 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
| 85 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
| 86 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
| 83 | + add_action('admin_init', array($this, 'check_environment')); |
|
| 84 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
| 85 | + add_action('plugins_loaded', array($this, 'init')); |
|
| 86 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -93,43 +93,43 @@ discard block |
||
| 93 | 93 | * @version 4.0.0 |
| 94 | 94 | */ |
| 95 | 95 | public function init() { |
| 96 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' ); |
|
| 97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
| 98 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
| 99 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
| 96 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'); |
|
| 97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
| 98 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
| 99 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
| 100 | 100 | |
| 101 | 101 | // Don't hook anything else in the plugin if we're in an incompatible environment |
| 102 | - if ( self::get_environment_warning() ) { |
|
| 102 | + if (self::get_environment_warning()) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
| 107 | - |
|
| 108 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
| 109 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
| 110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
| 111 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
| 112 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
| 113 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
| 114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
| 115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
| 116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
| 117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
| 118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
| 119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
| 120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
| 121 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
| 122 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
| 123 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
| 124 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
| 125 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
| 106 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
| 107 | + |
|
| 108 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
| 109 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
| 110 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
| 111 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
| 112 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
| 113 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
| 114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
| 115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
| 116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
| 117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
| 118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
| 119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
| 120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
| 121 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
| 122 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
| 123 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
| 124 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
| 125 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
| 126 | 126 | |
| 127 | 127 | // REMOVE IN THE FUTURE. |
| 128 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
| 128 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
| 129 | 129 | |
| 130 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
| 131 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
| 132 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
| 130 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
| 131 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
| 132 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -139,23 +139,23 @@ discard block |
||
| 139 | 139 | * @version 4.0.0 |
| 140 | 140 | */ |
| 141 | 141 | public function hide_notices() { |
| 142 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
| 143 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
| 144 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
| 142 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
| 143 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
| 144 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 148 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
| 147 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 148 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
| 151 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
| 152 | 152 | |
| 153 | - switch ( $notice ) { |
|
| 153 | + switch ($notice) { |
|
| 154 | 154 | case 'ssl': |
| 155 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
| 155 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
| 156 | 156 | break; |
| 157 | 157 | case 'keys': |
| 158 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
| 158 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
| 159 | 159 | break; |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | * @since 1.0.0 |
| 168 | 168 | * @version 4.0.0 |
| 169 | 169 | */ |
| 170 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
| 171 | - $this->notices[ $slug ] = array( |
|
| 170 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
| 171 | + $this->notices[$slug] = array( |
|
| 172 | 172 | 'class' => $class, |
| 173 | 173 | 'message' => $message, |
| 174 | 174 | 'dismissible' => $dismissible, |
@@ -182,21 +182,21 @@ discard block |
||
| 182 | 182 | * @version 4.0.0 |
| 183 | 183 | */ |
| 184 | 184 | public function admin_notices() { |
| 185 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 185 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 186 | 186 | return; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 190 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
| 189 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 190 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
| 191 | 191 | |
| 192 | - if ( $notice['dismissible'] ) { |
|
| 192 | + if ($notice['dismissible']) { |
|
| 193 | 193 | ?> |
| 194 | - <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
| 194 | + <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
| 195 | 195 | <?php |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | echo '<p>'; |
| 199 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 199 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 200 | 200 | echo '</p></div>'; |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -209,26 +209,26 @@ discard block |
||
| 209 | 209 | * @version 4.0.0 |
| 210 | 210 | */ |
| 211 | 211 | public function get_environment_warning() { |
| 212 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
| 212 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
| 213 | 213 | /* translators: 1) int version 2) int version */ |
| 214 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
| 214 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
| 215 | 215 | |
| 216 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
| 216 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
| 220 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
| 219 | + if ( ! defined('WC_VERSION')) { |
|
| 220 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
| 223 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
| 224 | 224 | /* translators: 1) int version 2) int version */ |
| 225 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
| 225 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
| 226 | 226 | |
| 227 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
| 227 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ( ! function_exists( 'curl_init' ) ) { |
|
| 231 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
| 230 | + if ( ! function_exists('curl_init')) { |
|
| 231 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | return false; |
@@ -242,11 +242,11 @@ discard block |
||
| 242 | 242 | * @return string Setting link |
| 243 | 243 | */ |
| 244 | 244 | public function get_setting_link() { |
| 245 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
| 245 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
| 246 | 246 | |
| 247 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
| 247 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
| 248 | 248 | |
| 249 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
| 249 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -257,37 +257,37 @@ discard block |
||
| 257 | 257 | * @version 4.0.0 |
| 258 | 258 | */ |
| 259 | 259 | public function check_environment() { |
| 260 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
| 260 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
| 261 | 261 | $this->install(); |
| 262 | 262 | |
| 263 | - do_action( 'woocommerce_stripe_updated' ); |
|
| 263 | + do_action('woocommerce_stripe_updated'); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | $environment_warning = $this->get_environment_warning(); |
| 267 | 267 | |
| 268 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
| 269 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 268 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
| 269 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
| 273 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
| 274 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 272 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
| 273 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
| 274 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 275 | 275 | |
| 276 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
| 277 | - $secret = WC_Stripe_API::get_secret_key(); |
|
| 276 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
| 277 | + $secret = WC_Stripe_API::get_secret_key(); |
|
| 278 | 278 | |
| 279 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
| 279 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
| 280 | 280 | $setting_link = $this->get_setting_link(); |
| 281 | 281 | /* translators: 1) link */ |
| 282 | - $this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
| 282 | + $this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
| 286 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
| 287 | 287 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
| 288 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
| 288 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
| 289 | 289 | /* translators: 1) link 2) link */ |
| 290 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
|
| 290 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | } |
@@ -299,8 +299,8 @@ discard block |
||
| 299 | 299 | * @version 4.0.0 |
| 300 | 300 | */ |
| 301 | 301 | public function update_plugin_version() { |
| 302 | - delete_option( 'wc_stripe_version' ); |
|
| 303 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
| 302 | + delete_option('wc_stripe_version'); |
|
| 303 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -310,8 +310,8 @@ discard block |
||
| 310 | 310 | * @version 3.1.0 |
| 311 | 311 | */ |
| 312 | 312 | public function install() { |
| 313 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
| 314 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
| 313 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
| 314 | + define('WC_STRIPE_INSTALLING', true); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | $this->update_plugin_version(); |
@@ -323,13 +323,13 @@ discard block |
||
| 323 | 323 | * @since 1.0.0 |
| 324 | 324 | * @version 4.0.0 |
| 325 | 325 | */ |
| 326 | - public function plugin_action_links( $links ) { |
|
| 326 | + public function plugin_action_links($links) { |
|
| 327 | 327 | $plugin_links = array( |
| 328 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 329 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 330 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
| 328 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
| 329 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
| 330 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
| 331 | 331 | ); |
| 332 | - return array_merge( $plugin_links, $links ); |
|
| 332 | + return array_merge($plugin_links, $links); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -338,8 +338,8 @@ discard block |
||
| 338 | 338 | * @since 1.0.0 |
| 339 | 339 | * @version 4.0.0 |
| 340 | 340 | */ |
| 341 | - public function add_gateways( $methods ) { |
|
| 342 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
| 341 | + public function add_gateways($methods) { |
|
| 342 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
| 343 | 343 | $methods[] = 'WC_Stripe_Compat'; |
| 344 | 344 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
| 345 | 345 | } else { |
@@ -364,26 +364,26 @@ discard block |
||
| 364 | 364 | * @since 4.0.0 |
| 365 | 365 | * @version 4.0.0 |
| 366 | 366 | */ |
| 367 | - public function filter_gateway_order_admin( $sections ) { |
|
| 368 | - unset( $sections['stripe'] ); |
|
| 369 | - unset( $sections['stripe_bancontact'] ); |
|
| 370 | - unset( $sections['stripe_sofort'] ); |
|
| 371 | - unset( $sections['stripe_giropay'] ); |
|
| 372 | - unset( $sections['stripe_ideal'] ); |
|
| 373 | - unset( $sections['stripe_p24'] ); |
|
| 374 | - unset( $sections['stripe_alipay'] ); |
|
| 375 | - unset( $sections['stripe_sepa'] ); |
|
| 376 | - unset( $sections['stripe_bitcoin'] ); |
|
| 367 | + public function filter_gateway_order_admin($sections) { |
|
| 368 | + unset($sections['stripe']); |
|
| 369 | + unset($sections['stripe_bancontact']); |
|
| 370 | + unset($sections['stripe_sofort']); |
|
| 371 | + unset($sections['stripe_giropay']); |
|
| 372 | + unset($sections['stripe_ideal']); |
|
| 373 | + unset($sections['stripe_p24']); |
|
| 374 | + unset($sections['stripe_alipay']); |
|
| 375 | + unset($sections['stripe_sepa']); |
|
| 376 | + unset($sections['stripe_bitcoin']); |
|
| 377 | 377 | |
| 378 | 378 | $sections['stripe'] = 'Stripe'; |
| 379 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
| 380 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
| 381 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
| 382 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
| 383 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
| 384 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
| 385 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
| 386 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
| 379 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
| 380 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
| 381 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
| 382 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
| 383 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
| 384 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
| 385 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
| 386 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
| 387 | 387 | |
| 388 | 388 | return $sections; |
| 389 | 389 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | public function __construct() { |
| 121 | 121 | $this->id = 'stripe'; |
| 122 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
| 122 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
| 123 | 123 | /* translators: 1) link to Stripe register page 2) link to Stripe api keys page */ |
| 124 | - $this->method_description = sprintf( __( 'Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys' ); |
|
| 124 | + $this->method_description = sprintf(__('Stripe works by adding payment fields on the checkout and then sending the details to Stripe for verification. <a href="%1$s" target="_blank">Sign up</a> for a Stripe account, and <a href="%2$s" target="_blank">get your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), 'https://dashboard.stripe.com/register', 'https://dashboard.stripe.com/account/apikeys'); |
|
| 125 | 125 | $this->has_fields = true; |
| 126 | 126 | $this->supports = array( |
| 127 | 127 | 'products', |
@@ -148,38 +148,38 @@ discard block |
||
| 148 | 148 | $this->init_settings(); |
| 149 | 149 | |
| 150 | 150 | // Get setting values. |
| 151 | - $this->title = $this->get_option( 'title' ); |
|
| 152 | - $this->description = $this->get_option( 'description' ); |
|
| 153 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 154 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
| 155 | - $this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' ); |
|
| 156 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
| 157 | - $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) ); |
|
| 158 | - $this->three_d_secure = 'yes' === $this->get_option( 'three_d_secure' ); |
|
| 159 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
| 160 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
| 161 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
| 162 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
| 163 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 164 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
| 165 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
| 166 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
| 167 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
| 151 | + $this->title = $this->get_option('title'); |
|
| 152 | + $this->description = $this->get_option('description'); |
|
| 153 | + $this->enabled = $this->get_option('enabled'); |
|
| 154 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
| 155 | + $this->inline_cc_form = 'yes' === $this->get_option('inline_cc_form'); |
|
| 156 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
| 157 | + $this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->get_option('statement_descriptor')); |
|
| 158 | + $this->three_d_secure = 'yes' === $this->get_option('three_d_secure'); |
|
| 159 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
| 160 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
| 161 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
| 162 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
| 163 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 164 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
| 165 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
| 166 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
| 167 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
| 168 | 168 | $this->apple_pay_verify_notice = ''; |
| 169 | 169 | |
| 170 | - if ( $this->stripe_checkout ) { |
|
| 171 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
| 170 | + if ($this->stripe_checkout) { |
|
| 171 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
| 174 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
| 175 | 175 | |
| 176 | 176 | $this->init_apple_pay(); |
| 177 | 177 | |
| 178 | 178 | // Hooks. |
| 179 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 180 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
|
| 181 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 182 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 179 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 180 | + add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); |
|
| 181 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 182 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * @since 4.0.2 |
| 189 | 189 | */ |
| 190 | 190 | public function is_available() { |
| 191 | - if ( is_add_payment_method_page() && ! $this->saved_cards ) { |
|
| 191 | + if (is_add_payment_method_page() && ! $this->saved_cards) { |
|
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -211,17 +211,17 @@ discard block |
||
| 211 | 211 | $icons_str .= $icons['amex']; |
| 212 | 212 | $icons_str .= $icons['mastercard']; |
| 213 | 213 | |
| 214 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
| 214 | + if ('USD' === get_woocommerce_currency()) { |
|
| 215 | 215 | $icons_str .= $icons['discover']; |
| 216 | 216 | $icons_str .= $icons['jcb']; |
| 217 | 217 | $icons_str .= $icons['diners']; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if ( $this->bitcoin && $this->stripe_checkout ) { |
|
| 220 | + if ($this->bitcoin && $this->stripe_checkout) { |
|
| 221 | 221 | $icons_str .= $icons['bitcoin']; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 224 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -233,9 +233,9 @@ discard block |
||
| 233 | 233 | public function init_apple_pay() { |
| 234 | 234 | if ( |
| 235 | 235 | is_admin() && |
| 236 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
| 237 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
| 238 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
| 236 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
| 237 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
| 238 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
| 239 | 239 | $this->payment_request |
| 240 | 240 | ) { |
| 241 | 241 | $this->process_apple_pay_verification(); |
@@ -249,9 +249,9 @@ discard block |
||
| 249 | 249 | * @version 3.1.0 |
| 250 | 250 | * @param string $secret_key |
| 251 | 251 | */ |
| 252 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
| 253 | - if ( empty( $secret_key ) ) { |
|
| 254 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
| 252 | + private function register_apple_pay_domain($secret_key = '') { |
|
| 253 | + if (empty($secret_key)) { |
|
| 254 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -265,23 +265,23 @@ discard block |
||
| 265 | 265 | 'Authorization' => 'Bearer ' . $secret_key, |
| 266 | 266 | ); |
| 267 | 267 | |
| 268 | - $response = wp_remote_post( $endpoint, array( |
|
| 268 | + $response = wp_remote_post($endpoint, array( |
|
| 269 | 269 | 'headers' => $headers, |
| 270 | - 'body' => http_build_query( $data ), |
|
| 271 | - ) ); |
|
| 270 | + 'body' => http_build_query($data), |
|
| 271 | + )); |
|
| 272 | 272 | |
| 273 | - if ( is_wp_error( $response ) ) { |
|
| 273 | + if (is_wp_error($response)) { |
|
| 274 | 274 | /* translators: error message */ |
| 275 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 275 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if ( 200 !== $response['response']['code'] ) { |
|
| 279 | - $parsed_response = json_decode( $response['body'] ); |
|
| 278 | + if (200 !== $response['response']['code']) { |
|
| 279 | + $parsed_response = json_decode($response['body']); |
|
| 280 | 280 | |
| 281 | 281 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
| 282 | 282 | |
| 283 | 283 | /* translators: error message */ |
| 284 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
| 284 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | |
@@ -292,48 +292,48 @@ discard block |
||
| 292 | 292 | * @version 3.1.0 |
| 293 | 293 | */ |
| 294 | 294 | public function process_apple_pay_verification() { |
| 295 | - $gateway_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 295 | + $gateway_settings = get_option('woocommerce_stripe_settings', array()); |
|
| 296 | 296 | |
| 297 | 297 | try { |
| 298 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
| 298 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
| 299 | 299 | $dir = '.well-known'; |
| 300 | 300 | $file = 'apple-developer-merchantid-domain-association'; |
| 301 | 301 | $fullpath = $path . '/' . $dir . '/' . $file; |
| 302 | 302 | |
| 303 | - if ( ! empty( $gateway_settings['apple_pay_domain_set'] ) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists( $fullpath ) ) { |
|
| 303 | + if ( ! empty($gateway_settings['apple_pay_domain_set']) && 'yes' === $gateway_settings['apple_pay_domain_set'] && file_exists($fullpath)) { |
|
| 304 | 304 | return; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
| 308 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { |
|
| 309 | - throw new Exception( __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 307 | + if ( ! file_exists($path . '/' . $dir)) { |
|
| 308 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { |
|
| 309 | + throw new Exception(__('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - if ( ! file_exists( $fullpath ) ) { |
|
| 314 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { |
|
| 315 | - throw new Exception( __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 313 | + if ( ! file_exists($fullpath)) { |
|
| 314 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { |
|
| 315 | + throw new Exception(__('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
| 316 | 316 | } |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | // At this point then the domain association folder and file should be available. |
| 320 | 320 | // Proceed to verify/and or verify again. |
| 321 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
| 321 | + $this->register_apple_pay_domain($this->secret_key); |
|
| 322 | 322 | |
| 323 | 323 | // No errors to this point, verification success! |
| 324 | 324 | $gateway_settings['apple_pay_domain_set'] = 'yes'; |
| 325 | 325 | $this->apple_pay_domain_set = true; |
| 326 | 326 | |
| 327 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 327 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 328 | 328 | |
| 329 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
| 329 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
| 330 | 330 | |
| 331 | - } catch ( Exception $e ) { |
|
| 331 | + } catch (Exception $e) { |
|
| 332 | 332 | $gateway_settings['apple_pay_domain_set'] = 'no'; |
| 333 | 333 | |
| 334 | - update_option( 'woocommerce_stripe_settings', $gateway_settings ); |
|
| 334 | + update_option('woocommerce_stripe_settings', $gateway_settings); |
|
| 335 | 335 | |
| 336 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 336 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | |
@@ -341,11 +341,11 @@ discard block |
||
| 341 | 341 | * Check if SSL is enabled and notify the user |
| 342 | 342 | */ |
| 343 | 343 | public function admin_notices() { |
| 344 | - if ( 'no' === $this->enabled ) { |
|
| 344 | + if ('no' === $this->enabled) { |
|
| 345 | 345 | return; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
| 348 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
| 349 | 349 | $allowed_html = array( |
| 350 | 350 | 'a' => array( |
| 351 | 351 | 'href' => array(), |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | ), |
| 354 | 354 | ); |
| 355 | 355 | |
| 356 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
| 356 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -361,9 +361,9 @@ discard block |
||
| 361 | 361 | * when setting screen is displayed. So if domain verification is not set, |
| 362 | 362 | * something went wrong so lets notify user. |
| 363 | 363 | */ |
| 364 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
| 364 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
| 365 | 365 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
| 366 | - 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>'; |
|
| 366 | + 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>'; |
|
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | 369 | |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * Initialise Gateway Settings Form Fields |
| 372 | 372 | */ |
| 373 | 373 | public function init_form_fields() { |
| 374 | - $this->form_fields = require( dirname( __FILE__ ) . '/admin/stripe-settings.php' ); |
|
| 374 | + $this->form_fields = require(dirname(__FILE__) . '/admin/stripe-settings.php'); |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
@@ -379,59 +379,59 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | public function payment_fields() { |
| 381 | 381 | $user = wp_get_current_user(); |
| 382 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
| 382 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
| 383 | 383 | $total = WC()->cart->total; |
| 384 | 384 | $user_email = ''; |
| 385 | 385 | |
| 386 | 386 | // If paying from order, we need to get total from order not cart. |
| 387 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 388 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 387 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 388 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 389 | 389 | $total = $order->get_total(); |
| 390 | 390 | $user_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
| 391 | 391 | } else { |
| 392 | - if ( $user->ID ) { |
|
| 393 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
| 392 | + if ($user->ID) { |
|
| 393 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
| 394 | 394 | $user_email = $user_email ? $user_email : $user->user_email; |
| 395 | 395 | } |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - if ( is_add_payment_method_page() ) { |
|
| 399 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
| 400 | - $total = ''; |
|
| 398 | + if (is_add_payment_method_page()) { |
|
| 399 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
| 400 | + $total = ''; |
|
| 401 | 401 | } else { |
| 402 | 402 | $pay_button_text = ''; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | echo '<div |
| 406 | 406 | id="stripe-payment-data" |
| 407 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
| 407 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
| 408 | 408 | data-description="" |
| 409 | - data-email="' . esc_attr( $user_email ) . '" |
|
| 410 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 411 | - data-name="' . esc_attr( $this->statement_descriptor ) . '" |
|
| 412 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
| 413 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
| 414 | - data-bitcoin="' . esc_attr( ( $this->bitcoin && $this->capture ) ? 'true' : 'false' ) . '" |
|
| 415 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '" |
|
| 416 | - data-three-d-secure="' . esc_attr( $this->three_d_secure ? 'true' : 'false' ) . '" |
|
| 417 | - data-allow-remember-me="' . esc_attr( $this->saved_cards ? 'true' : 'false' ) . '">'; |
|
| 418 | - |
|
| 419 | - if ( $this->description ) { |
|
| 420 | - if ( $this->testmode ) { |
|
| 409 | + data-email="' . esc_attr($user_email) . '" |
|
| 410 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 411 | + data-name="' . esc_attr($this->statement_descriptor) . '" |
|
| 412 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
| 413 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
| 414 | + data-bitcoin="' . esc_attr(($this->bitcoin && $this->capture) ? 'true' : 'false') . '" |
|
| 415 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '" |
|
| 416 | + data-three-d-secure="' . esc_attr($this->three_d_secure ? 'true' : 'false') . '" |
|
| 417 | + data-allow-remember-me="' . esc_attr($this->saved_cards ? 'true' : 'false') . '">'; |
|
| 418 | + |
|
| 419 | + if ($this->description) { |
|
| 420 | + if ($this->testmode) { |
|
| 421 | 421 | /* translators: link to Stripe testing page */ |
| 422 | - $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" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
| 423 | - $this->description = trim( $this->description ); |
|
| 422 | + $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" target="_blank">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
| 423 | + $this->description = trim($this->description); |
|
| 424 | 424 | } |
| 425 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 425 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - if ( $display_tokenization ) { |
|
| 428 | + if ($display_tokenization) { |
|
| 429 | 429 | $this->tokenization_script(); |
| 430 | 430 | $this->saved_payment_methods(); |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - if ( ! $this->stripe_checkout ) { |
|
| 434 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
| 433 | + if ( ! $this->stripe_checkout) { |
|
| 434 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
| 435 | 435 | $this->elements_form(); |
| 436 | 436 | } else { |
| 437 | 437 | $this->form(); |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | } |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - if ( apply_filters( 'wc_stripe_display_save_payment_method_checkbox', $display_tokenization ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
| 442 | + if (apply_filters('wc_stripe_display_save_payment_method_checkbox', $display_tokenization) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
| 443 | 443 | $this->save_payment_method_checkbox(); |
| 444 | 444 | } |
| 445 | 445 | |
@@ -454,12 +454,12 @@ discard block |
||
| 454 | 454 | */ |
| 455 | 455 | public function elements_form() { |
| 456 | 456 | ?> |
| 457 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 458 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
| 457 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-cc-form" class="wc-credit-card-form wc-payment-form" style="background:transparent;"> |
|
| 458 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
| 459 | 459 | |
| 460 | - <?php if ( $this->inline_cc_form ) { ?> |
|
| 460 | + <?php if ($this->inline_cc_form) { ?> |
|
| 461 | 461 | <label for="card-element"> |
| 462 | - <?php esc_html_e( 'Credit or debit card', 'woocommerce-gateway-stripe' ); ?> |
|
| 462 | + <?php esc_html_e('Credit or debit card', 'woocommerce-gateway-stripe'); ?> |
|
| 463 | 463 | </label> |
| 464 | 464 | |
| 465 | 465 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | </div> |
| 468 | 468 | <?php } else { ?> |
| 469 | 469 | <div class="form-row form-row-wide"> |
| 470 | - <label><?php _e( 'Card Number', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 470 | + <label><?php _e('Card Number', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 471 | 471 | |
| 472 | 472 | <div id="stripe-card-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
| 473 | 473 | <!-- a Stripe Element will be inserted here. --> |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | </div> |
| 476 | 476 | |
| 477 | 477 | <div class="form-row form-row-first"> |
| 478 | - <label><?php _e( 'Expiry Date', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 478 | + <label><?php _e('Expiry Date', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 479 | 479 | |
| 480 | 480 | <div id="stripe-exp-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
| 481 | 481 | <!-- a Stripe Element will be inserted here. --> |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | </div> |
| 484 | 484 | |
| 485 | 485 | <div class="form-row form-row-last"> |
| 486 | - <label><?php _e( 'Card Code (CVC)', 'woocommerce-gateway-stripe' ); ?> <span class="required">*</span></label> |
|
| 486 | + <label><?php _e('Card Code (CVC)', 'woocommerce-gateway-stripe'); ?> <span class="required">*</span></label> |
|
| 487 | 487 | <div id="stripe-cvc-element" style="background:#fff;padding:0 1em;border:1px solid #ddd;margin:5px 0;padding:10px 5px;"> |
| 488 | 488 | <!-- a Stripe Element will be inserted here. --> |
| 489 | 489 | </div> |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | |
| 494 | 494 | <!-- Used to display form errors --> |
| 495 | 495 | <div class="stripe-source-errors" role="alert"></div> |
| 496 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
| 496 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
| 497 | 497 | <div class="clear"></div> |
| 498 | 498 | </fieldset> |
| 499 | 499 | <?php |
@@ -506,13 +506,13 @@ discard block |
||
| 506 | 506 | * @version 3.1.0 |
| 507 | 507 | */ |
| 508 | 508 | public function admin_scripts() { |
| 509 | - if ( 'woocommerce_page_wc-settings' !== get_current_screen()->id ) { |
|
| 509 | + if ('woocommerce_page_wc-settings' !== get_current_screen()->id) { |
|
| 510 | 510 | return; |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 513 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 514 | 514 | |
| 515 | - wp_enqueue_script( 'woocommerce_stripe_admin', plugins_url( 'assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array(), WC_STRIPE_VERSION, true ); |
|
| 515 | + wp_enqueue_script('woocommerce_stripe_admin', plugins_url('assets/js/stripe-admin' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array(), WC_STRIPE_VERSION, true); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -524,29 +524,29 @@ discard block |
||
| 524 | 524 | * @version 4.0.0 |
| 525 | 525 | */ |
| 526 | 526 | public function payment_scripts() { |
| 527 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() && ! isset( $_GET['change_payment_method'] ) ) { |
|
| 527 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page() && ! isset($_GET['change_payment_method'])) { |
|
| 528 | 528 | return; |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 531 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 532 | 532 | |
| 533 | - wp_register_style( 'stripe_paymentfonts', plugins_url( 'assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE ), array(), '1.2.5' ); |
|
| 534 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 535 | - wp_register_script( 'stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true ); |
|
| 536 | - wp_register_script( 'stripev2', 'https://js.stripe.com/v2/', '', '2.0', true ); |
|
| 537 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
| 538 | - wp_register_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripev2', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
| 533 | + wp_register_style('stripe_paymentfonts', plugins_url('assets/css/stripe-paymentfonts.css', WC_STRIPE_MAIN_FILE), array(), '1.2.5'); |
|
| 534 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 535 | + wp_register_script('stripe_checkout', 'https://checkout.stripe.com/checkout.js', '', WC_STRIPE_VERSION, true); |
|
| 536 | + wp_register_script('stripev2', 'https://js.stripe.com/v2/', '', '2.0', true); |
|
| 537 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
| 538 | + wp_register_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripev2', 'stripe'), WC_STRIPE_VERSION, true); |
|
| 539 | 539 | |
| 540 | 540 | $stripe_params = array( |
| 541 | 541 | 'key' => $this->publishable_key, |
| 542 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
| 543 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
| 542 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
| 543 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
| 544 | 544 | ); |
| 545 | 545 | |
| 546 | 546 | // If we're on the pay page we need to pass stripe.js the address of the order. |
| 547 | - if ( isset( $_GET['pay_for_order'] ) && 'true' === $_GET['pay_for_order'] ) { |
|
| 548 | - $order_id = wc_get_order_id_by_order_key( urldecode( $_GET['key'] ) ); |
|
| 549 | - $order = wc_get_order( $order_id ); |
|
| 547 | + if (isset($_GET['pay_for_order']) && 'true' === $_GET['pay_for_order']) { |
|
| 548 | + $order_id = wc_get_order_id_by_order_key(urldecode($_GET['key'])); |
|
| 549 | + $order = wc_get_order($order_id); |
|
| 550 | 550 | |
| 551 | 551 | $stripe_params['billing_first_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
| 552 | 552 | $stripe_params['billing_last_name'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
@@ -558,38 +558,38 @@ discard block |
||
| 558 | 558 | $stripe_params['billing_country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
| 562 | - $stripe_params['no_bank_country_msg'] = __( 'Please select a country for your bank.', 'woocommerce-gateway-stripe' ); |
|
| 563 | - $stripe_params['no_sepa_owner_msg'] = __( 'Please enter your IBAN account name.', 'woocommerce-gateway-stripe' ); |
|
| 564 | - $stripe_params['no_sepa_iban_msg'] = __( 'Please enter your IBAN account number.', 'woocommerce-gateway-stripe' ); |
|
| 565 | - $stripe_params['sepa_mandate_notification'] = apply_filters( 'wc_stripe_sepa_mandate_notification', 'email' ); |
|
| 566 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
| 561 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
| 562 | + $stripe_params['no_bank_country_msg'] = __('Please select a country for your bank.', 'woocommerce-gateway-stripe'); |
|
| 563 | + $stripe_params['no_sepa_owner_msg'] = __('Please enter your IBAN account name.', 'woocommerce-gateway-stripe'); |
|
| 564 | + $stripe_params['no_sepa_iban_msg'] = __('Please enter your IBAN account number.', 'woocommerce-gateway-stripe'); |
|
| 565 | + $stripe_params['sepa_mandate_notification'] = apply_filters('wc_stripe_sepa_mandate_notification', 'email'); |
|
| 566 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
| 567 | 567 | $stripe_params['inline_cc_form'] = $this->inline_cc_form ? 'yes' : 'no'; |
| 568 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
| 569 | - $stripe_params['is_checkout'] = ( is_checkout() && empty( $_GET['pay_for_order'] ) ); |
|
| 568 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
| 569 | + $stripe_params['is_checkout'] = (is_checkout() && empty($_GET['pay_for_order'])); |
|
| 570 | 570 | $stripe_params['return_url'] = $this->get_stripe_return_url(); |
| 571 | - $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint( '%%endpoint%%' ); |
|
| 572 | - $stripe_params['stripe_nonce'] = wp_create_nonce( '_wc_stripe_nonce' ); |
|
| 571 | + $stripe_params['ajaxurl'] = WC_AJAX::get_endpoint('%%endpoint%%'); |
|
| 572 | + $stripe_params['stripe_nonce'] = wp_create_nonce('_wc_stripe_nonce'); |
|
| 573 | 573 | $stripe_params['statement_descriptor'] = $this->statement_descriptor; |
| 574 | - $stripe_params['use_elements'] = apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ? 'yes' : 'no'; |
|
| 574 | + $stripe_params['use_elements'] = apply_filters('wc_stripe_use_elements_checkout_form', true) ? 'yes' : 'no'; |
|
| 575 | 575 | $stripe_params['is_stripe_checkout'] = $this->stripe_checkout ? 'yes' : 'no'; |
| 576 | - $stripe_params['is_change_payment_page'] = ( isset( $_GET['pay_for_order'] ) || isset( $_GET['change_payment_method'] ) ) ? 'yes' : 'no'; |
|
| 576 | + $stripe_params['is_change_payment_page'] = (isset($_GET['pay_for_order']) || isset($_GET['change_payment_method'])) ? 'yes' : 'no'; |
|
| 577 | 577 | $stripe_params['is_add_payment_method_page'] = is_add_payment_method_page() ? 'yes' : 'no'; |
| 578 | - $stripe_params['elements_styling'] = apply_filters( 'wc_stripe_elements_styling', false ); |
|
| 579 | - $stripe_params['elements_classes'] = apply_filters( 'wc_stripe_elements_classes', false ); |
|
| 578 | + $stripe_params['elements_styling'] = apply_filters('wc_stripe_elements_styling', false); |
|
| 579 | + $stripe_params['elements_classes'] = apply_filters('wc_stripe_elements_classes', false); |
|
| 580 | 580 | |
| 581 | 581 | // merge localized messages to be use in JS |
| 582 | - $stripe_params = array_merge( $stripe_params, WC_Stripe_Helper::get_localized_messages() ); |
|
| 582 | + $stripe_params = array_merge($stripe_params, WC_Stripe_Helper::get_localized_messages()); |
|
| 583 | 583 | |
| 584 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 585 | - wp_localize_script( 'woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
| 584 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 585 | + wp_localize_script('woocommerce_stripe_checkout', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
| 586 | 586 | |
| 587 | - if ( $this->stripe_checkout ) { |
|
| 588 | - wp_enqueue_script( 'stripe_checkout' ); |
|
| 587 | + if ($this->stripe_checkout) { |
|
| 588 | + wp_enqueue_script('stripe_checkout'); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | $this->tokenization_script(); |
| 592 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 592 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -601,22 +601,22 @@ discard block |
||
| 601 | 601 | * @param object $source_object |
| 602 | 602 | * @return mixed |
| 603 | 603 | */ |
| 604 | - public function create_3ds_source( $order, $source_object ) { |
|
| 604 | + public function create_3ds_source($order, $source_object) { |
|
| 605 | 605 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 606 | 606 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 607 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 607 | + $return_url = $this->get_stripe_return_url($order); |
|
| 608 | 608 | |
| 609 | 609 | $post_data = array(); |
| 610 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 611 | - $post_data['currency'] = strtolower( $currency ); |
|
| 610 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 611 | + $post_data['currency'] = strtolower($currency); |
|
| 612 | 612 | $post_data['type'] = 'three_d_secure'; |
| 613 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 614 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
| 615 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 613 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 614 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
| 615 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 616 | 616 | |
| 617 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source' ); |
|
| 617 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source'); |
|
| 618 | 618 | |
| 619 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 619 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -632,45 +632,45 @@ discard block |
||
| 632 | 632 | * |
| 633 | 633 | * @return array|void |
| 634 | 634 | */ |
| 635 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 635 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 636 | 636 | try { |
| 637 | - $order = wc_get_order( $order_id ); |
|
| 637 | + $order = wc_get_order($order_id); |
|
| 638 | 638 | |
| 639 | 639 | // This comes from the create account checkbox in the checkout page. |
| 640 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 640 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 641 | 641 | |
| 642 | - if ( $create_account ) { |
|
| 642 | + if ($create_account) { |
|
| 643 | 643 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 644 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 644 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 645 | 645 | $new_stripe_customer->create_customer(); |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | $source_object = $this->create_source_object(); |
| 649 | 649 | |
| 650 | - $prepared_source = $this->prepare_source( $source_object, get_current_user_id(), $force_save_source ); |
|
| 650 | + $prepared_source = $this->prepare_source($source_object, get_current_user_id(), $force_save_source); |
|
| 651 | 651 | |
| 652 | 652 | // Check if we don't allow prepaid credit cards. |
| 653 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
| 654 | - if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) { |
|
| 655 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
| 656 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
| 653 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
| 654 | + if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) { |
|
| 655 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
| 656 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
| 657 | 657 | } |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | - if ( empty( $prepared_source->source ) ) { |
|
| 661 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 662 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 660 | + if (empty($prepared_source->source)) { |
|
| 661 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 662 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | // Store source to order meta. |
| 666 | - $this->save_source( $order, $prepared_source ); |
|
| 666 | + $this->save_source($order, $prepared_source); |
|
| 667 | 667 | |
| 668 | 668 | // Result from Stripe API request. |
| 669 | 669 | $response = null; |
| 670 | 670 | |
| 671 | - if ( $order->get_total() > 0 ) { |
|
| 671 | + if ($order->get_total() > 0) { |
|
| 672 | 672 | // This will throw exception if not valid. |
| 673 | - $this->validate_minimum_order_amount( $order ); |
|
| 673 | + $this->validate_minimum_order_amount($order); |
|
| 674 | 674 | |
| 675 | 675 | /** |
| 676 | 676 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -679,83 +679,83 @@ discard block |
||
| 679 | 679 | * Note that if we need to save source, the original source must be first |
| 680 | 680 | * attached to a customer in Stripe before it can be charged. |
| 681 | 681 | */ |
| 682 | - if ( ( $source_object && ! empty( $source_object->card ) ) && ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) ) ) { |
|
| 682 | + if (($source_object && ! empty($source_object->card)) && ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure))) { |
|
| 683 | 683 | |
| 684 | - $response = $this->create_3ds_source( $order, $source_object ); |
|
| 684 | + $response = $this->create_3ds_source($order, $source_object); |
|
| 685 | 685 | |
| 686 | - if ( ! empty( $response->error ) ) { |
|
| 686 | + if ( ! empty($response->error)) { |
|
| 687 | 687 | $localized_message = $response->error->message; |
| 688 | 688 | |
| 689 | - $order->add_order_note( $localized_message ); |
|
| 689 | + $order->add_order_note($localized_message); |
|
| 690 | 690 | |
| 691 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 691 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | // Update order meta with 3DS source. |
| 695 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 696 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 695 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 696 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 697 | 697 | } else { |
| 698 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 698 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 699 | 699 | $order->save(); |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
| 702 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
| 703 | 703 | |
| 704 | 704 | return array( |
| 705 | 705 | 'result' => 'success', |
| 706 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 706 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 707 | 707 | ); |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 710 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 711 | 711 | |
| 712 | 712 | // Make the request. |
| 713 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $prepared_source ) ); |
|
| 713 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $prepared_source)); |
|
| 714 | 714 | |
| 715 | - if ( ! empty( $response->error ) ) { |
|
| 715 | + if ( ! empty($response->error)) { |
|
| 716 | 716 | // If it is an API error such connection or server, let's retry. |
| 717 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
| 718 | - if ( $retry ) { |
|
| 719 | - sleep( 5 ); |
|
| 720 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 717 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
| 718 | + if ($retry) { |
|
| 719 | + sleep(5); |
|
| 720 | + return $this->process_payment($order_id, false, $force_save_source); |
|
| 721 | 721 | } else { |
| 722 | 722 | $localized_message = 'API connection error and retries exhausted.'; |
| 723 | - $order->add_order_note( $localized_message ); |
|
| 724 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 723 | + $order->add_order_note($localized_message); |
|
| 724 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 725 | 725 | } |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 729 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
| 730 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 729 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
| 730 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
| 731 | 731 | |
| 732 | - return $this->process_payment( $order_id, false, $force_save_source ); |
|
| 733 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $prepared_source->token_id ) { |
|
| 732 | + return $this->process_payment($order_id, false, $force_save_source); |
|
| 733 | + } elseif (preg_match('/No such token/i', $response->error->message) && $prepared_source->token_id) { |
|
| 734 | 734 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 735 | - $wc_token = WC_Payment_Tokens::get( $prepared_source->token_id ); |
|
| 735 | + $wc_token = WC_Payment_Tokens::get($prepared_source->token_id); |
|
| 736 | 736 | $wc_token->delete(); |
| 737 | - $localized_message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 738 | - $order->add_order_note( $localized_message ); |
|
| 739 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 737 | + $localized_message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 738 | + $order->add_order_note($localized_message); |
|
| 739 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 743 | 743 | |
| 744 | - if ( 'card_error' === $response->error->type ) { |
|
| 745 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 744 | + if ('card_error' === $response->error->type) { |
|
| 745 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 746 | 746 | } else { |
| 747 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 747 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - $order->add_order_note( $localized_message ); |
|
| 750 | + $order->add_order_note($localized_message); |
|
| 751 | 751 | |
| 752 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 752 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
| 755 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
| 756 | 756 | |
| 757 | 757 | // Process valid response. |
| 758 | - $this->process_response( $response, $order ); |
|
| 758 | + $this->process_response($response, $order); |
|
| 759 | 759 | } else { |
| 760 | 760 | $order->payment_complete(); |
| 761 | 761 | } |
@@ -766,17 +766,17 @@ discard block |
||
| 766 | 766 | // Return thank you page redirect. |
| 767 | 767 | return array( |
| 768 | 768 | 'result' => 'success', |
| 769 | - 'redirect' => $this->get_return_url( $order ), |
|
| 769 | + 'redirect' => $this->get_return_url($order), |
|
| 770 | 770 | ); |
| 771 | 771 | |
| 772 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 773 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 774 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 772 | + } catch (WC_Stripe_Exception $e) { |
|
| 773 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 774 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 775 | 775 | |
| 776 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 776 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 777 | 777 | |
| 778 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 779 | - $this->send_failed_order_email( $order_id ); |
|
| 778 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 779 | + $this->send_failed_order_email($order_id); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | return array( |