@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * @version 4.0.0 |
| 18 | 18 | */ |
| 19 | 19 | public function __construct() { |
| 20 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
| 20 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -27,24 +27,24 @@ discard block |
||
| 27 | 27 | * @version 4.0.0 |
| 28 | 28 | */ |
| 29 | 29 | public function check_for_webhook() { |
| 30 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
| 31 | - || ! isset( $_GET['wc-api'] ) |
|
| 32 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
| 30 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
| 31 | + || ! isset($_GET['wc-api']) |
|
| 32 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
| 33 | 33 | ) { |
| 34 | 34 | return; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - $request_body = file_get_contents( 'php://input' ); |
|
| 38 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
| 37 | + $request_body = file_get_contents('php://input'); |
|
| 38 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
| 39 | 39 | |
| 40 | 40 | // Validate it to make sure it is legit. |
| 41 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
| 42 | - $this->process_webhook( $request_body ); |
|
| 43 | - status_header( 200 ); |
|
| 41 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
| 42 | + $this->process_webhook($request_body); |
|
| 43 | + status_header(200); |
|
| 44 | 44 | exit; |
| 45 | 45 | } else { |
| 46 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
| 47 | - status_header( 400 ); |
|
| 46 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
| 47 | + status_header(400); |
|
| 48 | 48 | exit; |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | * @param string $request_body The request body from Stripe. |
| 60 | 60 | * @return bool |
| 61 | 61 | */ |
| 62 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
| 63 | - if ( null === $request_headers || null === $request_body ) { |
|
| 62 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
| 63 | + if (null === $request_headers || null === $request_body) { |
|
| 64 | 64 | return false; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
| 67 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
| 68 | 68 | return false; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | * @version 4.0.0 |
| 81 | 81 | */ |
| 82 | 82 | public function get_request_headers() { |
| 83 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
| 83 | + if ( ! function_exists('getallheaders')) { |
|
| 84 | 84 | $headers = []; |
| 85 | - foreach ( $_SERVER as $name => $value ) { |
|
| 86 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
| 87 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
| 85 | + foreach ($_SERVER as $name => $value) { |
|
| 86 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
| 87 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | |
@@ -103,30 +103,30 @@ discard block |
||
| 103 | 103 | * @param object $notification |
| 104 | 104 | * @param bool $retry |
| 105 | 105 | */ |
| 106 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
| 106 | + public function process_webhook_payment($notification, $retry = true) { |
|
| 107 | 107 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
| 108 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
| 108 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
| 109 | 109 | return; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
| 112 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
| 113 | 113 | |
| 114 | - if ( ! $order ) { |
|
| 115 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
| 114 | + if ( ! $order) { |
|
| 115 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
| 116 | 116 | return; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 120 | 120 | $source_id = $notification->data->object->id; |
| 121 | 121 | |
| 122 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
| 122 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
| 123 | 123 | |
| 124 | 124 | try { |
| 125 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
| 125 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
| 126 | 126 | return; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
| 129 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | 132 | |
@@ -134,73 +134,73 @@ discard block |
||
| 134 | 134 | $response = null; |
| 135 | 135 | |
| 136 | 136 | // This will throw exception if not valid. |
| 137 | - $this->validate_minimum_order_amount( $order ); |
|
| 137 | + $this->validate_minimum_order_amount($order); |
|
| 138 | 138 | |
| 139 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
| 139 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
| 140 | 140 | |
| 141 | 141 | // Prep source object. |
| 142 | 142 | $source_object = new stdClass(); |
| 143 | 143 | $source_object->token_id = ''; |
| 144 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
| 144 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
| 145 | 145 | $source_object->source = $source_id; |
| 146 | 146 | |
| 147 | 147 | // Make the request. |
| 148 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
| 148 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
| 149 | 149 | |
| 150 | - if ( ! empty( $response->error ) ) { |
|
| 150 | + if ( ! empty($response->error)) { |
|
| 151 | 151 | // If it is an API error such connection or server, let's retry. |
| 152 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
| 153 | - if ( $retry ) { |
|
| 154 | - sleep( 5 ); |
|
| 155 | - return $this->process_payment( $order_id, false ); |
|
| 152 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
| 153 | + if ($retry) { |
|
| 154 | + sleep(5); |
|
| 155 | + return $this->process_payment($order_id, false); |
|
| 156 | 156 | } else { |
| 157 | 157 | $localized_message = 'API connection error and retries exhausted.'; |
| 158 | - $order->add_order_note( $localized_message ); |
|
| 159 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 158 | + $order->add_order_note($localized_message); |
|
| 159 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
| 164 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
| 165 | - delete_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id' ); |
|
| 164 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
| 165 | + delete_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id'); |
|
| 166 | 166 | |
| 167 | - return $this->process_payment( $order_id, false ); |
|
| 167 | + return $this->process_payment($order_id, false); |
|
| 168 | 168 | |
| 169 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
| 169 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
| 170 | 170 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
| 171 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
| 171 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
| 172 | 172 | $wc_token->delete(); |
| 173 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
| 174 | - $order->add_order_note( $message ); |
|
| 175 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
| 173 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
| 174 | + $order->add_order_note($message); |
|
| 175 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 179 | 179 | |
| 180 | - if ( 'card_error' === $response->error->type ) { |
|
| 181 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 180 | + if ('card_error' === $response->error->type) { |
|
| 181 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 182 | 182 | } else { |
| 183 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 183 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - $order->add_order_note( $localized_message ); |
|
| 186 | + $order->add_order_note($localized_message); |
|
| 187 | 187 | |
| 188 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 188 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
| 191 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
| 192 | 192 | |
| 193 | - $this->process_response( $response, $order ); |
|
| 193 | + $this->process_response($response, $order); |
|
| 194 | 194 | |
| 195 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 196 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 195 | + } catch (WC_Stripe_Exception $e) { |
|
| 196 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 197 | 197 | |
| 198 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order ); |
|
| 198 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order); |
|
| 199 | 199 | |
| 200 | - $statuses = array( 'pending', 'failed' ); |
|
| 200 | + $statuses = array('pending', 'failed'); |
|
| 201 | 201 | |
| 202 | - if ( $order->has_status( $statuses ) ) { |
|
| 203 | - $this->send_failed_order_email( $order_id ); |
|
| 202 | + if ($order->has_status($statuses)) { |
|
| 203 | + $this->send_failed_order_email($order_id); |
|
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -214,18 +214,18 @@ discard block |
||
| 214 | 214 | * @version 4.0.0 |
| 215 | 215 | * @param object $notification |
| 216 | 216 | */ |
| 217 | - public function process_webhook_dispute( $notification ) { |
|
| 218 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 217 | + public function process_webhook_dispute($notification) { |
|
| 218 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 219 | 219 | |
| 220 | - if ( ! $order ) { |
|
| 221 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 220 | + if ( ! $order) { |
|
| 221 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 222 | 222 | return; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - $order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) ); |
|
| 225 | + $order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe')); |
|
| 226 | 226 | |
| 227 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
| 228 | - $this->send_failed_order_email( $order_id ); |
|
| 227 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
| 228 | + $this->send_failed_order_email($order_id); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -236,41 +236,41 @@ discard block |
||
| 236 | 236 | * @version 4.0.0 |
| 237 | 237 | * @param object $notification |
| 238 | 238 | */ |
| 239 | - public function process_webhook_capture( $notification ) { |
|
| 240 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 239 | + public function process_webhook_capture($notification) { |
|
| 240 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 241 | 241 | |
| 242 | - if ( ! $order ) { |
|
| 243 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 242 | + if ( ! $order) { |
|
| 243 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 244 | 244 | return; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 248 | 248 | |
| 249 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
| 250 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
| 251 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
| 249 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
| 250 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
| 251 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
| 252 | 252 | |
| 253 | - if ( $charge && 'no' === $captured ) { |
|
| 254 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
| 253 | + if ($charge && 'no' === $captured) { |
|
| 254 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
| 255 | 255 | |
| 256 | 256 | // Store other data such as fees |
| 257 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
| 257 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
| 258 | 258 | |
| 259 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
| 260 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
| 259 | + if (isset($notification->data->object->balance_transaction)) { |
|
| 260 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 263 | + if (is_callable(array($order, 'save'))) { |
|
| 264 | 264 | $order->save(); |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /* translators: transaction id */ |
| 268 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
| 268 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
| 269 | 269 | |
| 270 | 270 | // Check and see if capture is partial. |
| 271 | - if ( $this->is_partial_capture( $notification ) ) { |
|
| 272 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
| 273 | - $order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
| 271 | + if ($this->is_partial_capture($notification)) { |
|
| 272 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
| 273 | + $order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
| 274 | 274 | $order->save(); |
| 275 | 275 | } |
| 276 | 276 | } |
@@ -285,38 +285,38 @@ discard block |
||
| 285 | 285 | * @version 4.0.0 |
| 286 | 286 | * @param object $notification |
| 287 | 287 | */ |
| 288 | - public function process_webhook_charge_succeeded( $notification ) { |
|
| 288 | + public function process_webhook_charge_succeeded($notification) { |
|
| 289 | 289 | // The following payment methods are synchronous so does not need to be handle via webhook. |
| 290 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
| 290 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
| 291 | 291 | return; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 294 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 295 | 295 | |
| 296 | - if ( ! $order ) { |
|
| 297 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 296 | + if ( ! $order) { |
|
| 297 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 298 | 298 | return; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 302 | 302 | |
| 303 | - if ( 'on-hold' !== $order->get_status() ) { |
|
| 303 | + if ('on-hold' !== $order->get_status()) { |
|
| 304 | 304 | return; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // Store other data such as fees |
| 308 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
| 308 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
| 309 | 309 | |
| 310 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
| 311 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
| 310 | + if (isset($notification->data->object->balance_transaction)) { |
|
| 311 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
| 314 | + if (is_callable(array($order, 'save'))) { |
|
| 315 | 315 | $order->save(); |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /* translators: transaction id */ |
| 319 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
| 319 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | /** |
@@ -327,23 +327,23 @@ discard block |
||
| 327 | 327 | * @version 4.0.0 |
| 328 | 328 | * @param object $notification |
| 329 | 329 | */ |
| 330 | - public function process_webhook_charge_failed( $notification ) { |
|
| 331 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 330 | + public function process_webhook_charge_failed($notification) { |
|
| 331 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 332 | 332 | |
| 333 | - if ( ! $order ) { |
|
| 334 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 333 | + if ( ! $order) { |
|
| 334 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 335 | 335 | return; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 339 | 339 | |
| 340 | - if ( 'on-hold' !== $order->get_status() ) { |
|
| 340 | + if ('on-hold' !== $order->get_status()) { |
|
| 341 | 341 | return; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
| 344 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
| 345 | 345 | |
| 346 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
| 346 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -354,23 +354,23 @@ discard block |
||
| 354 | 354 | * @version 4.0.0 |
| 355 | 355 | * @param object $notification |
| 356 | 356 | */ |
| 357 | - public function process_webhook_source_canceled( $notification ) { |
|
| 358 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 357 | + public function process_webhook_source_canceled($notification) { |
|
| 358 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 359 | 359 | |
| 360 | - if ( ! $order ) { |
|
| 361 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 360 | + if ( ! $order) { |
|
| 361 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 362 | 362 | return; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 366 | 366 | |
| 367 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
| 367 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
| 368 | 368 | return; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
| 371 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
| 372 | 372 | |
| 373 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
| 373 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -381,31 +381,31 @@ discard block |
||
| 381 | 381 | * @version 4.0.0 |
| 382 | 382 | * @param object $notification |
| 383 | 383 | */ |
| 384 | - public function process_webhook_refund( $notification ) { |
|
| 385 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
| 384 | + public function process_webhook_refund($notification) { |
|
| 385 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
| 386 | 386 | |
| 387 | - if ( ! $order ) { |
|
| 388 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
| 387 | + if ( ! $order) { |
|
| 388 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
| 389 | 389 | return; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 393 | 393 | |
| 394 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
| 395 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
| 396 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
| 394 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
| 395 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
| 396 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
| 397 | 397 | |
| 398 | 398 | // Only refund captured charge. |
| 399 | - if ( $charge && 'yes' === $captured ) { |
|
| 399 | + if ($charge && 'yes' === $captured) { |
|
| 400 | 400 | // Create the refund. |
| 401 | - $refund = wc_create_refund( array( |
|
| 401 | + $refund = wc_create_refund(array( |
|
| 402 | 402 | 'order_id' => $order_id, |
| 403 | - 'amount' => $this->get_refund_amount( $notification ), |
|
| 404 | - 'reason' => __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ), |
|
| 405 | - ) ); |
|
| 403 | + 'amount' => $this->get_refund_amount($notification), |
|
| 404 | + 'reason' => __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe'), |
|
| 405 | + )); |
|
| 406 | 406 | |
| 407 | - if ( is_wp_error( $refund ) ) { |
|
| 408 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
| 407 | + if (is_wp_error($refund)) { |
|
| 408 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | } |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | * @version 4.0.0 |
| 419 | 419 | * @param object $notification |
| 420 | 420 | */ |
| 421 | - public function is_partial_capture( $notification ) { |
|
| 421 | + public function is_partial_capture($notification) { |
|
| 422 | 422 | return 0 < $notification->data->object->amount_refunded; |
| 423 | 423 | } |
| 424 | 424 | |
@@ -429,11 +429,11 @@ discard block |
||
| 429 | 429 | * @version 4.0.0 |
| 430 | 430 | * @param object $notification |
| 431 | 431 | */ |
| 432 | - public function get_refund_amount( $notification ) { |
|
| 433 | - if ( $this->is_partial_capture( $notification ) ) { |
|
| 432 | + public function get_refund_amount($notification) { |
|
| 433 | + if ($this->is_partial_capture($notification)) { |
|
| 434 | 434 | $amount = $notification->data->object->amount_refunded / 100; |
| 435 | 435 | |
| 436 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
| 436 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
| 437 | 437 | $amount = $notification->data->object->amount_refunded; |
| 438 | 438 | } |
| 439 | 439 | |
@@ -450,12 +450,12 @@ discard block |
||
| 450 | 450 | * @version 4.0.0 |
| 451 | 451 | * @param object $notification |
| 452 | 452 | */ |
| 453 | - public function get_partial_amount_to_charge( $notification ) { |
|
| 454 | - if ( $this->is_partial_capture( $notification ) ) { |
|
| 455 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
| 453 | + public function get_partial_amount_to_charge($notification) { |
|
| 454 | + if ($this->is_partial_capture($notification)) { |
|
| 455 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
| 456 | 456 | |
| 457 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
| 458 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
| 457 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
| 458 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | return $amount; |
@@ -471,36 +471,36 @@ discard block |
||
| 471 | 471 | * @version 4.0.0 |
| 472 | 472 | * @param string $request_body |
| 473 | 473 | */ |
| 474 | - public function process_webhook( $request_body ) { |
|
| 475 | - $notification = json_decode( $request_body ); |
|
| 474 | + public function process_webhook($request_body) { |
|
| 475 | + $notification = json_decode($request_body); |
|
| 476 | 476 | |
| 477 | - switch ( $notification->type ) { |
|
| 477 | + switch ($notification->type) { |
|
| 478 | 478 | case 'source.chargeable': |
| 479 | - $this->process_webhook_payment( $notification ); |
|
| 479 | + $this->process_webhook_payment($notification); |
|
| 480 | 480 | break; |
| 481 | 481 | |
| 482 | 482 | case 'source.canceled': |
| 483 | - $this->process_webhook_source_canceled( $notification ); |
|
| 483 | + $this->process_webhook_source_canceled($notification); |
|
| 484 | 484 | break; |
| 485 | 485 | |
| 486 | 486 | case 'charge.succeeded': |
| 487 | - $this->process_webhook_charge_succeeded( $notification ); |
|
| 487 | + $this->process_webhook_charge_succeeded($notification); |
|
| 488 | 488 | break; |
| 489 | 489 | |
| 490 | 490 | case 'charge.failed': |
| 491 | - $this->process_webhook_charge_failed( $notification ); |
|
| 491 | + $this->process_webhook_charge_failed($notification); |
|
| 492 | 492 | break; |
| 493 | 493 | |
| 494 | 494 | case 'charge.captured': |
| 495 | - $this->process_webhook_capture( $notification ); |
|
| 495 | + $this->process_webhook_capture($notification); |
|
| 496 | 496 | break; |
| 497 | 497 | |
| 498 | 498 | case 'charge.dispute.created': |
| 499 | - $this->process_webhook_dispute( $notification ); |
|
| 499 | + $this->process_webhook_dispute($notification); |
|
| 500 | 500 | break; |
| 501 | 501 | |
| 502 | 502 | case 'charge.refunded': |
| 503 | - $this->process_webhook_refund( $notification ); |
|
| 503 | + $this->process_webhook_refund($notification); |
|
| 504 | 504 | break; |
| 505 | 505 | |
| 506 | 506 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_ideal'; |
| 60 | - $this->method_title = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_ideal_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_ideal_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $icons_str .= $icons['ideal']; |
| 177 | 177 | |
| 178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | * @access public |
| 187 | 187 | */ |
| 188 | 188 | public function payment_scripts() { |
| 189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 190 | 190 | return; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 194 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Initialize Gateway Settings Form Fields. |
| 199 | 199 | */ |
| 200 | 200 | public function init_form_fields() { |
| 201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' ); |
|
| 201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | $total = WC()->cart->total; |
| 210 | 210 | |
| 211 | 211 | // If paying from order, we need to get total from order not cart. |
| 212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 214 | 214 | $total = $order->get_total(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( is_add_payment_method_page() ) { |
|
| 218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 219 | - $total = ''; |
|
| 217 | + if (is_add_payment_method_page()) { |
|
| 218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 219 | + $total = ''; |
|
| 220 | 220 | } else { |
| 221 | 221 | $pay_button_text = ''; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | echo '<div |
| 225 | 225 | id="stripe-ideal-payment-data" |
| 226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 228 | 228 | |
| 229 | - if ( $this->description ) { |
|
| 230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 229 | + if ($this->description) { |
|
| 230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | echo '</div>'; |
@@ -241,24 +241,24 @@ discard block |
||
| 241 | 241 | * @param object $order |
| 242 | 242 | * @return mixed |
| 243 | 243 | */ |
| 244 | - public function create_source( $order ) { |
|
| 244 | + public function create_source($order) { |
|
| 245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 247 | + $return_url = $this->get_stripe_return_url($order); |
|
| 248 | 248 | $post_data = array(); |
| 249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 250 | - $post_data['currency'] = strtolower( $currency ); |
|
| 249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 250 | + $post_data['currency'] = strtolower($currency); |
|
| 251 | 251 | $post_data['type'] = 'ideal'; |
| 252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 256 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 255 | + if ( ! empty($this->statement_descriptor)) { |
|
| 256 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' ); |
|
| 259 | + WC_Stripe_Logger::log('Info: Begin creating iDeal source'); |
|
| 260 | 260 | |
| 261 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 261 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @return array|void |
| 274 | 274 | */ |
| 275 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 275 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 276 | 276 | try { |
| 277 | - $order = wc_get_order( $order_id ); |
|
| 277 | + $order = wc_get_order($order_id); |
|
| 278 | 278 | |
| 279 | 279 | // This will throw exception if not valid. |
| 280 | - $this->validate_minimum_order_amount( $order ); |
|
| 280 | + $this->validate_minimum_order_amount($order); |
|
| 281 | 281 | |
| 282 | 282 | // This comes from the create account checkbox in the checkout page. |
| 283 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 283 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 284 | 284 | |
| 285 | - if ( $create_account ) { |
|
| 285 | + if ($create_account) { |
|
| 286 | 286 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 287 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 287 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 288 | 288 | $new_stripe_customer->create_customer(); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - $response = $this->create_source( $order ); |
|
| 291 | + $response = $this->create_source($order); |
|
| 292 | 292 | |
| 293 | - if ( ! empty( $response->error ) ) { |
|
| 294 | - $order->add_order_note( $response->error->message ); |
|
| 293 | + if ( ! empty($response->error)) { |
|
| 294 | + $order->add_order_note($response->error->message); |
|
| 295 | 295 | |
| 296 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 296 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 300 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 300 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 301 | 301 | } else { |
| 302 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 302 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 303 | 303 | $order->save(); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' ); |
|
| 306 | + WC_Stripe_Logger::log('Info: Redirecting to iDeal...'); |
|
| 307 | 307 | |
| 308 | 308 | return array( |
| 309 | 309 | 'result' => 'success', |
| 310 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 310 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 311 | 311 | ); |
| 312 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 312 | + } catch (WC_Stripe_Exception $e) { |
|
| 313 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 314 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 315 | 315 | |
| 316 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 316 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 317 | 317 | |
| 318 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 319 | - $this->send_failed_order_email( $order_id ); |
|
| 318 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 319 | + $this->send_failed_order_email($order_id); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_bancontact'; |
| 60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_bancontact_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_bancontact_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $icons_str .= $icons['bancontact']; |
| 177 | 177 | |
| 178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | * @access public |
| 187 | 187 | */ |
| 188 | 188 | public function payment_scripts() { |
| 189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 190 | 190 | return; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 194 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Initialize Gateway Settings Form Fields. |
| 199 | 199 | */ |
| 200 | 200 | public function init_form_fields() { |
| 201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
| 201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | $total = WC()->cart->total; |
| 210 | 210 | |
| 211 | 211 | // If paying from order, we need to get total from order not cart. |
| 212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 214 | 214 | $total = $order->get_total(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( is_add_payment_method_page() ) { |
|
| 218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 219 | - $total = ''; |
|
| 217 | + if (is_add_payment_method_page()) { |
|
| 218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 219 | + $total = ''; |
|
| 220 | 220 | } else { |
| 221 | 221 | $pay_button_text = ''; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | echo '<div |
| 225 | 225 | id="stripe-bancontact-payment-data" |
| 226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 228 | 228 | |
| 229 | - if ( $this->description ) { |
|
| 230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 229 | + if ($this->description) { |
|
| 230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | echo '</div>'; |
@@ -241,24 +241,24 @@ discard block |
||
| 241 | 241 | * @param object $order |
| 242 | 242 | * @return mixed |
| 243 | 243 | */ |
| 244 | - public function create_source( $order ) { |
|
| 244 | + public function create_source($order) { |
|
| 245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 247 | + $return_url = $this->get_stripe_return_url($order); |
|
| 248 | 248 | $post_data = array(); |
| 249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 250 | - $post_data['currency'] = strtolower( $currency ); |
|
| 249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 250 | + $post_data['currency'] = strtolower($currency); |
|
| 251 | 251 | $post_data['type'] = 'bancontact'; |
| 252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 256 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 255 | + if ( ! empty($this->statement_descriptor)) { |
|
| 256 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
| 259 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
| 260 | 260 | |
| 261 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 261 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @return array|void |
| 274 | 274 | */ |
| 275 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 275 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 276 | 276 | try { |
| 277 | - $order = wc_get_order( $order_id ); |
|
| 277 | + $order = wc_get_order($order_id); |
|
| 278 | 278 | |
| 279 | 279 | // This will throw exception if not valid. |
| 280 | - $this->validate_minimum_order_amount( $order ); |
|
| 280 | + $this->validate_minimum_order_amount($order); |
|
| 281 | 281 | |
| 282 | 282 | // This comes from the create account checkbox in the checkout page. |
| 283 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 283 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 284 | 284 | |
| 285 | - if ( $create_account ) { |
|
| 285 | + if ($create_account) { |
|
| 286 | 286 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 287 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 287 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 288 | 288 | $new_stripe_customer->create_customer(); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - $response = $this->create_source( $order ); |
|
| 291 | + $response = $this->create_source($order); |
|
| 292 | 292 | |
| 293 | - if ( ! empty( $response->error ) ) { |
|
| 294 | - $order->add_order_note( $response->error->message ); |
|
| 293 | + if ( ! empty($response->error)) { |
|
| 294 | + $order->add_order_note($response->error->message); |
|
| 295 | 295 | |
| 296 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 296 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 300 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 300 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 301 | 301 | } else { |
| 302 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 302 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 303 | 303 | $order->save(); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
| 306 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
| 307 | 307 | |
| 308 | 308 | return array( |
| 309 | 309 | 'result' => 'success', |
| 310 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 310 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 311 | 311 | ); |
| 312 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 312 | + } catch (WC_Stripe_Exception $e) { |
|
| 313 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 314 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 315 | 315 | |
| 316 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 316 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 317 | 317 | |
| 318 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 319 | - $this->send_failed_order_email( $order_id ); |
|
| 318 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 319 | + $this->send_failed_order_email($order_id); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_alipay'; |
| 60 | - $this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -125,10 +125,10 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | 127 | if ( |
| 128 | - 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) |
|
| 128 | + 'yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency()) |
|
| 129 | 129 | ) { |
| 130 | 130 | /* translators: supported currency list */ |
| 131 | - $message = sprintf( __( 'Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe' ), implode( ', ', $this->get_supported_currency() ) ); |
|
| 131 | + $message = sprintf(__('Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe'), implode(', ', $this->get_supported_currency())); |
|
| 132 | 132 | |
| 133 | 133 | return $message; |
| 134 | 134 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @return array |
| 145 | 145 | */ |
| 146 | 146 | public function get_supported_currency() { |
| 147 | - return apply_filters( 'wc_stripe_alipay_supported_currencies', array( |
|
| 147 | + return apply_filters('wc_stripe_alipay_supported_currencies', array( |
|
| 148 | 148 | 'EUR', |
| 149 | 149 | 'AUD', |
| 150 | 150 | 'CAD', |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | 'NZD', |
| 155 | 155 | 'SGD', |
| 156 | 156 | 'USD', |
| 157 | - ) ); |
|
| 157 | + )); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @return bool |
| 166 | 166 | */ |
| 167 | 167 | public function is_available() { |
| 168 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 168 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 169 | 169 | return false; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | $icons_str .= $icons['alipay']; |
| 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 | /** |
@@ -196,19 +196,19 @@ discard block |
||
| 196 | 196 | * @version 4.0.0 |
| 197 | 197 | */ |
| 198 | 198 | public function payment_scripts() { |
| 199 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 199 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 200 | 200 | return; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 204 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 203 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 204 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * Initialize Gateway Settings Form Fields. |
| 209 | 209 | */ |
| 210 | 210 | public function init_form_fields() { |
| 211 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' ); |
|
| 211 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php'); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -219,25 +219,25 @@ discard block |
||
| 219 | 219 | $total = WC()->cart->total; |
| 220 | 220 | |
| 221 | 221 | // If paying from order, we need to get total from order not cart. |
| 222 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 223 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 222 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 223 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 224 | 224 | $total = $order->get_total(); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - if ( is_add_payment_method_page() ) { |
|
| 228 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 229 | - $total = ''; |
|
| 227 | + if (is_add_payment_method_page()) { |
|
| 228 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 229 | + $total = ''; |
|
| 230 | 230 | } else { |
| 231 | 231 | $pay_button_text = ''; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | echo '<div |
| 235 | 235 | id="stripe-alipay-payment-data" |
| 236 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 237 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 236 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 237 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 238 | 238 | |
| 239 | - if ( $this->description ) { |
|
| 240 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 239 | + if ($this->description) { |
|
| 240 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | echo '</div>'; |
@@ -251,24 +251,24 @@ discard block |
||
| 251 | 251 | * @param object $order |
| 252 | 252 | * @return mixed |
| 253 | 253 | */ |
| 254 | - public function create_source( $order ) { |
|
| 254 | + public function create_source($order) { |
|
| 255 | 255 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 256 | 256 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 257 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 257 | + $return_url = $this->get_stripe_return_url($order); |
|
| 258 | 258 | $post_data = array(); |
| 259 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 260 | - $post_data['currency'] = strtolower( $currency ); |
|
| 259 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 260 | + $post_data['currency'] = strtolower($currency); |
|
| 261 | 261 | $post_data['type'] = 'alipay'; |
| 262 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 263 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 262 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 263 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 264 | 264 | |
| 265 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 266 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 265 | + if ( ! empty($this->statement_descriptor)) { |
|
| 266 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' ); |
|
| 269 | + WC_Stripe_Logger::log('Info: Begin creating Alipay source'); |
|
| 270 | 270 | |
| 271 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 271 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -282,53 +282,53 @@ discard block |
||
| 282 | 282 | * |
| 283 | 283 | * @return array|void |
| 284 | 284 | */ |
| 285 | - public function process_payment( $order_id, $retry = true, $force_save_save = false ) { |
|
| 285 | + public function process_payment($order_id, $retry = true, $force_save_save = false) { |
|
| 286 | 286 | try { |
| 287 | - $order = wc_get_order( $order_id ); |
|
| 287 | + $order = wc_get_order($order_id); |
|
| 288 | 288 | |
| 289 | 289 | // This will throw exception if not valid. |
| 290 | - $this->validate_minimum_order_amount( $order ); |
|
| 290 | + $this->validate_minimum_order_amount($order); |
|
| 291 | 291 | |
| 292 | 292 | // This comes from the create account checkbox in the checkout page. |
| 293 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 293 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 294 | 294 | |
| 295 | - if ( $create_account ) { |
|
| 295 | + if ($create_account) { |
|
| 296 | 296 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 297 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 297 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 298 | 298 | $new_stripe_customer->create_customer(); |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - $response = $this->create_source( $order ); |
|
| 301 | + $response = $this->create_source($order); |
|
| 302 | 302 | |
| 303 | - if ( ! empty( $response->error ) ) { |
|
| 304 | - $order->add_order_note( $response->error->message ); |
|
| 303 | + if ( ! empty($response->error)) { |
|
| 304 | + $order->add_order_note($response->error->message); |
|
| 305 | 305 | |
| 306 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 306 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 310 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 309 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 310 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 311 | 311 | } else { |
| 312 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 312 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 313 | 313 | $order->save(); |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); |
|
| 316 | + WC_Stripe_Logger::log('Info: Redirecting to Alipay...'); |
|
| 317 | 317 | |
| 318 | 318 | return array( |
| 319 | 319 | 'result' => 'success', |
| 320 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 320 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 321 | 321 | ); |
| 322 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 323 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 324 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 322 | + } catch (WC_Stripe_Exception $e) { |
|
| 323 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 324 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 325 | 325 | |
| 326 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 326 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 327 | 327 | |
| 328 | - $statuses = array( 'pending', 'failed' ); |
|
| 328 | + $statuses = array('pending', 'failed'); |
|
| 329 | 329 | |
| 330 | - if ( $order->has_status( $statuses ) ) { |
|
| 331 | - $this->send_failed_order_email( $order_id ); |
|
| 330 | + if ($order->has_status($statuses)) { |
|
| 331 | + $this->send_failed_order_email($order_id); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -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,40 +350,40 @@ 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 ); |
|
| 356 | - $source_object = ! empty( $_POST['stripe_source'] ) ? json_decode( stripslashes( $_POST['stripe_source'] ) ) : false; |
|
| 355 | + $order = wc_get_order($order_id); |
|
| 356 | + $source_object = ! empty($_POST['stripe_source']) ? json_decode(stripslashes($_POST['stripe_source'])) : false; |
|
| 357 | 357 | |
| 358 | 358 | // This comes from the create account checkbox in the checkout page. |
| 359 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 359 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 360 | 360 | |
| 361 | - if ( $create_account ) { |
|
| 361 | + if ($create_account) { |
|
| 362 | 362 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 363 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 363 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 364 | 364 | $new_stripe_customer->create_customer(); |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
| 367 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
| 368 | 368 | |
| 369 | - if ( empty( $prepared_source->source ) ) { |
|
| 370 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 371 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 369 | + if (empty($prepared_source->source)) { |
|
| 370 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 371 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // Store source to order meta. |
| 375 | - $this->save_source( $order, $prepared_source ); |
|
| 375 | + $this->save_source($order, $prepared_source); |
|
| 376 | 376 | |
| 377 | 377 | |
| 378 | 378 | // This will throw exception if not valid. |
| 379 | - $this->validate_minimum_order_amount( $order ); |
|
| 379 | + $this->validate_minimum_order_amount($order); |
|
| 380 | 380 | |
| 381 | - $this->save_instructions( $order, $source_object ); |
|
| 381 | + $this->save_instructions($order, $source_object); |
|
| 382 | 382 | |
| 383 | 383 | // Mark as on-hold (we're awaiting the payment) |
| 384 | - $order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) ); |
|
| 384 | + $order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe')); |
|
| 385 | 385 | |
| 386 | - wc_reduce_stock_levels( $order_id ); |
|
| 386 | + wc_reduce_stock_levels($order_id); |
|
| 387 | 387 | |
| 388 | 388 | // Remove cart |
| 389 | 389 | WC()->cart->empty_cart(); |
@@ -391,16 +391,16 @@ discard block |
||
| 391 | 391 | // Return thankyou redirect |
| 392 | 392 | return array( |
| 393 | 393 | 'result' => 'success', |
| 394 | - 'redirect' => $this->get_return_url( $order ), |
|
| 394 | + 'redirect' => $this->get_return_url($order), |
|
| 395 | 395 | ); |
| 396 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 397 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 398 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 396 | + } catch (WC_Stripe_Exception $e) { |
|
| 397 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 398 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 399 | 399 | |
| 400 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 400 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 401 | 401 | |
| 402 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 403 | - $this->send_failed_order_email( $order_id ); |
|
| 402 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 403 | + $this->send_failed_order_email($order_id); |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_sofort'; |
| 60 | - $this->method_title = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_sofort_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_sofort_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $icons_str .= $icons['sofort']; |
| 177 | 177 | |
| 178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | * @access public |
| 187 | 187 | */ |
| 188 | 188 | public function payment_scripts() { |
| 189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 190 | 190 | return; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 194 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Initialize Gateway Settings Form Fields. |
| 199 | 199 | */ |
| 200 | 200 | public function init_form_fields() { |
| 201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
| 201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | $total = WC()->cart->total; |
| 210 | 210 | |
| 211 | 211 | // If paying from order, we need to get total from order not cart. |
| 212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 214 | 214 | $total = $order->get_total(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( is_add_payment_method_page() ) { |
|
| 218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 219 | - $total = ''; |
|
| 217 | + if (is_add_payment_method_page()) { |
|
| 218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 219 | + $total = ''; |
|
| 220 | 220 | } else { |
| 221 | 221 | $pay_button_text = ''; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | echo '<div |
| 225 | 225 | id="stripe-sofort-payment-data" |
| 226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 228 | 228 | |
| 229 | - if ( $this->description ) { |
|
| 230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 229 | + if ($this->description) { |
|
| 230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | echo '</div>'; |
@@ -241,25 +241,25 @@ discard block |
||
| 241 | 241 | * @param object $order |
| 242 | 242 | * @return mixed |
| 243 | 243 | */ |
| 244 | - public function create_source( $order ) { |
|
| 244 | + public function create_source($order) { |
|
| 245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 246 | 246 | $bank_country = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
| 247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 247 | + $return_url = $this->get_stripe_return_url($order); |
|
| 248 | 248 | $post_data = array(); |
| 249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 250 | - $post_data['currency'] = strtolower( $currency ); |
|
| 249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 250 | + $post_data['currency'] = strtolower($currency); |
|
| 251 | 251 | $post_data['type'] = 'sofort'; |
| 252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 254 | - $post_data['sofort'] = array( 'country' => $bank_country ); |
|
| 252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 254 | + $post_data['sofort'] = array('country' => $bank_country); |
|
| 255 | 255 | |
| 256 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 257 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 256 | + if ( ! empty($this->statement_descriptor)) { |
|
| 257 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' ); |
|
| 260 | + WC_Stripe_Logger::log('Info: Begin creating SOFORT source'); |
|
| 261 | 261 | |
| 262 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 262 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -273,51 +273,51 @@ discard block |
||
| 273 | 273 | * |
| 274 | 274 | * @return array|void |
| 275 | 275 | */ |
| 276 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 276 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 277 | 277 | try { |
| 278 | - $order = wc_get_order( $order_id ); |
|
| 278 | + $order = wc_get_order($order_id); |
|
| 279 | 279 | |
| 280 | 280 | // This will throw exception if not valid. |
| 281 | - $this->validate_minimum_order_amount( $order ); |
|
| 281 | + $this->validate_minimum_order_amount($order); |
|
| 282 | 282 | |
| 283 | 283 | // This comes from the create account checkbox in the checkout page. |
| 284 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 284 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 285 | 285 | |
| 286 | - if ( $create_account ) { |
|
| 286 | + if ($create_account) { |
|
| 287 | 287 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 288 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 288 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 289 | 289 | $new_stripe_customer->create_customer(); |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $response = $this->create_source( $order ); |
|
| 292 | + $response = $this->create_source($order); |
|
| 293 | 293 | |
| 294 | - if ( ! empty( $response->error ) ) { |
|
| 295 | - $order->add_order_note( $response->error->message ); |
|
| 294 | + if ( ! empty($response->error)) { |
|
| 295 | + $order->add_order_note($response->error->message); |
|
| 296 | 296 | |
| 297 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 297 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 301 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 300 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 301 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 302 | 302 | } else { |
| 303 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 303 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 304 | 304 | $order->save(); |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' ); |
|
| 307 | + WC_Stripe_Logger::log('Info: Redirecting to SOFORT...'); |
|
| 308 | 308 | |
| 309 | 309 | return array( |
| 310 | 310 | 'result' => 'success', |
| 311 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 311 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 312 | 312 | ); |
| 313 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 314 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 315 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 313 | + } catch (WC_Stripe_Exception $e) { |
|
| 314 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 315 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 316 | 316 | |
| 317 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 317 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 318 | 318 | |
| 319 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 320 | - $this->send_failed_order_email( $order_id ); |
|
| 319 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 320 | + $this->send_failed_order_email($order_id); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_giropay'; |
| 60 | - $this->method_title = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_giropay_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_giropay_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | - ) ); |
|
| 146 | + )); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | 156 | public function is_available() { |
| 157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $icons_str .= $icons['giropay']; |
| 177 | 177 | |
| 178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
| 186 | 186 | * @access public |
| 187 | 187 | */ |
| 188 | 188 | public function payment_scripts() { |
| 189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 190 | 190 | return; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 194 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | 198 | * Initialize Gateway Settings Form Fields. |
| 199 | 199 | */ |
| 200 | 200 | public function init_form_fields() { |
| 201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' ); |
|
| 201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | $total = WC()->cart->total; |
| 210 | 210 | |
| 211 | 211 | // If paying from order, we need to get total from order not cart. |
| 212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 214 | 214 | $total = $order->get_total(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( is_add_payment_method_page() ) { |
|
| 218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 219 | - $total = ''; |
|
| 217 | + if (is_add_payment_method_page()) { |
|
| 218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 219 | + $total = ''; |
|
| 220 | 220 | } else { |
| 221 | 221 | $pay_button_text = ''; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | echo '<div |
| 225 | 225 | id="stripe-giropay-payment-data" |
| 226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 228 | 228 | |
| 229 | - if ( $this->description ) { |
|
| 230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 229 | + if ($this->description) { |
|
| 230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | echo '</div>'; |
@@ -241,24 +241,24 @@ discard block |
||
| 241 | 241 | * @param object $order |
| 242 | 242 | * @return mixed |
| 243 | 243 | */ |
| 244 | - public function create_source( $order ) { |
|
| 244 | + public function create_source($order) { |
|
| 245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 247 | + $return_url = $this->get_stripe_return_url($order); |
|
| 248 | 248 | $post_data = array(); |
| 249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 250 | - $post_data['currency'] = strtolower( $currency ); |
|
| 249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 250 | + $post_data['currency'] = strtolower($currency); |
|
| 251 | 251 | $post_data['type'] = 'giropay'; |
| 252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
| 256 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
| 255 | + if ( ! empty($this->statement_descriptor)) { |
|
| 256 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' ); |
|
| 259 | + WC_Stripe_Logger::log('Info: Begin creating Giropay source'); |
|
| 260 | 260 | |
| 261 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 261 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @return array|void |
| 274 | 274 | */ |
| 275 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 275 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 276 | 276 | try { |
| 277 | - $order = wc_get_order( $order_id ); |
|
| 277 | + $order = wc_get_order($order_id); |
|
| 278 | 278 | |
| 279 | 279 | // This will throw exception if not valid. |
| 280 | - $this->validate_minimum_order_amount( $order ); |
|
| 280 | + $this->validate_minimum_order_amount($order); |
|
| 281 | 281 | |
| 282 | 282 | // This comes from the create account checkbox in the checkout page. |
| 283 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 283 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 284 | 284 | |
| 285 | - if ( $create_account ) { |
|
| 285 | + if ($create_account) { |
|
| 286 | 286 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 287 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 287 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 288 | 288 | $new_stripe_customer->create_customer(); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - $response = $this->create_source( $order ); |
|
| 291 | + $response = $this->create_source($order); |
|
| 292 | 292 | |
| 293 | - if ( ! empty( $response->error ) ) { |
|
| 294 | - $order->add_order_note( $response->error->message ); |
|
| 293 | + if ( ! empty($response->error)) { |
|
| 294 | + $order->add_order_note($response->error->message); |
|
| 295 | 295 | |
| 296 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 296 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 300 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 300 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 301 | 301 | } else { |
| 302 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 302 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 303 | 303 | $order->save(); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' ); |
|
| 306 | + WC_Stripe_Logger::log('Info: Redirecting to Giropay...'); |
|
| 307 | 307 | |
| 308 | 308 | return array( |
| 309 | 309 | 'result' => 'success', |
| 310 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 310 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 311 | 311 | ); |
| 312 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 312 | + } catch (WC_Stripe_Exception $e) { |
|
| 313 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 314 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 315 | 315 | |
| 316 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 316 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 317 | 317 | |
| 318 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 319 | - $this->send_failed_order_email( $order_id ); |
|
| 318 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 319 | + $this->send_failed_order_email($order_id); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function __construct() { |
| 59 | 59 | $this->id = 'stripe_p24'; |
| 60 | - $this->method_title = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
| 60 | + $this->method_title = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
| 61 | 61 | /* translators: link */ |
| 62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
| 62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
| 63 | 63 | $this->supports = array( |
| 64 | 64 | 'products', |
| 65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
| 71 | 71 | // Load the settings. |
| 72 | 72 | $this->init_settings(); |
| 73 | 73 | |
| 74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
| 75 | - $this->title = $this->get_option( 'title' ); |
|
| 76 | - $this->description = $this->get_option( 'description' ); |
|
| 77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
| 78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
| 79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
| 80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
| 81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
| 82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | - |
|
| 84 | - if ( $this->testmode ) { |
|
| 85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
| 74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
| 75 | + $this->title = $this->get_option('title'); |
|
| 76 | + $this->description = $this->get_option('description'); |
|
| 77 | + $this->enabled = $this->get_option('enabled'); |
|
| 78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
| 79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
| 80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
| 81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
| 82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
| 83 | + |
|
| 84 | + if ($this->testmode) { |
|
| 85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
| 86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
| 90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
| 91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
| 92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
| 89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
| 90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
| 91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
| 92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | * @version 4.0.0 |
| 100 | 100 | */ |
| 101 | 101 | public function check_environment() { |
| 102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $environment_warning = $this->get_environment_warning(); |
| 107 | 107 | |
| 108 | - if ( $environment_warning ) { |
|
| 109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
| 108 | + if ($environment_warning) { |
|
| 109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
| 113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
| 114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
| 112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
| 113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
| 114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
| 115 | 115 | echo '</p></div>'; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | * @version 4.0.0 |
| 125 | 125 | */ |
| 126 | 126 | public function get_environment_warning() { |
| 127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 128 | - $message = __( 'P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe' ); |
|
| 127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 128 | + $message = __('P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe'); |
|
| 129 | 129 | |
| 130 | 130 | return $message; |
| 131 | 131 | } |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | * @return array |
| 142 | 142 | */ |
| 143 | 143 | public function get_supported_currency() { |
| 144 | - return apply_filters( 'wc_stripe_p24_supported_currencies', array( |
|
| 144 | + return apply_filters('wc_stripe_p24_supported_currencies', array( |
|
| 145 | 145 | 'EUR', |
| 146 | 146 | 'PLN', |
| 147 | - ) ); |
|
| 147 | + )); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @return bool |
| 156 | 156 | */ |
| 157 | 157 | public function is_available() { |
| 158 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
| 158 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
| 159 | 159 | return false; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | $icons_str .= $icons['p24']; |
| 178 | 178 | |
| 179 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
| 179 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -187,19 +187,19 @@ discard block |
||
| 187 | 187 | * @access public |
| 188 | 188 | */ |
| 189 | 189 | public function payment_scripts() { |
| 190 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
| 190 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
| 191 | 191 | return; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
| 195 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
| 194 | + wp_enqueue_style('stripe_paymentfonts'); |
|
| 195 | + wp_enqueue_script('woocommerce_stripe'); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
| 199 | 199 | * Initialize Gateway Settings Form Fields. |
| 200 | 200 | */ |
| 201 | 201 | public function init_form_fields() { |
| 202 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php' ); |
|
| 202 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php'); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -210,25 +210,25 @@ discard block |
||
| 210 | 210 | $total = WC()->cart->total; |
| 211 | 211 | |
| 212 | 212 | // If paying from order, we need to get total from order not cart. |
| 213 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
| 214 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
| 213 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
| 214 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
| 215 | 215 | $total = $order->get_total(); |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - if ( is_add_payment_method_page() ) { |
|
| 219 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
| 220 | - $total = ''; |
|
| 218 | + if (is_add_payment_method_page()) { |
|
| 219 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
| 220 | + $total = ''; |
|
| 221 | 221 | } else { |
| 222 | 222 | $pay_button_text = ''; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | echo '<div |
| 226 | 226 | id="stripe-p24-payment-data" |
| 227 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
| 228 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
| 227 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
| 228 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
| 229 | 229 | |
| 230 | - if ( $this->description ) { |
|
| 231 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
| 230 | + if ($this->description) { |
|
| 231 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | echo '</div>'; |
@@ -242,20 +242,20 @@ discard block |
||
| 242 | 242 | * @param object $order |
| 243 | 243 | * @return mixed |
| 244 | 244 | */ |
| 245 | - public function create_source( $order ) { |
|
| 245 | + public function create_source($order) { |
|
| 246 | 246 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
| 247 | 247 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
| 248 | - $return_url = $this->get_stripe_return_url( $order ); |
|
| 248 | + $return_url = $this->get_stripe_return_url($order); |
|
| 249 | 249 | $post_data = array(); |
| 250 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
| 251 | - $post_data['currency'] = strtolower( $currency ); |
|
| 250 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
| 251 | + $post_data['currency'] = strtolower($currency); |
|
| 252 | 252 | $post_data['type'] = 'p24'; |
| 253 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
| 254 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
| 253 | + $post_data['owner'] = $this->get_owner_details($order); |
|
| 254 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
| 255 | 255 | |
| 256 | - WC_Stripe_Logger::log( 'Info: Begin creating P24 source' ); |
|
| 256 | + WC_Stripe_Logger::log('Info: Begin creating P24 source'); |
|
| 257 | 257 | |
| 258 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
| 258 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -269,51 +269,51 @@ discard block |
||
| 269 | 269 | * |
| 270 | 270 | * @return array|void |
| 271 | 271 | */ |
| 272 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
| 272 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
| 273 | 273 | try { |
| 274 | - $order = wc_get_order( $order_id ); |
|
| 274 | + $order = wc_get_order($order_id); |
|
| 275 | 275 | |
| 276 | 276 | // This will throw exception if not valid. |
| 277 | - $this->validate_minimum_order_amount( $order ); |
|
| 277 | + $this->validate_minimum_order_amount($order); |
|
| 278 | 278 | |
| 279 | 279 | // This comes from the create account checkbox in the checkout page. |
| 280 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
| 280 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
| 281 | 281 | |
| 282 | - if ( $create_account ) { |
|
| 282 | + if ($create_account) { |
|
| 283 | 283 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
| 284 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
| 284 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
| 285 | 285 | $new_stripe_customer->create_customer(); |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - $response = $this->create_source( $order ); |
|
| 288 | + $response = $this->create_source($order); |
|
| 289 | 289 | |
| 290 | - if ( ! empty( $response->error ) ) { |
|
| 291 | - $order->add_order_note( $response->error->message ); |
|
| 290 | + if ( ! empty($response->error)) { |
|
| 291 | + $order->add_order_note($response->error->message); |
|
| 292 | 292 | |
| 293 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 293 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
| 297 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
| 296 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
| 297 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
| 298 | 298 | } else { |
| 299 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
| 299 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
| 300 | 300 | $order->save(); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - WC_Stripe_Logger::log( 'Info: Redirecting to P24...' ); |
|
| 303 | + WC_Stripe_Logger::log('Info: Redirecting to P24...'); |
|
| 304 | 304 | |
| 305 | 305 | return array( |
| 306 | 306 | 'result' => 'success', |
| 307 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
| 307 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
| 308 | 308 | ); |
| 309 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 310 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 311 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 309 | + } catch (WC_Stripe_Exception $e) { |
|
| 310 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 311 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 312 | 312 | |
| 313 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
| 313 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
| 314 | 314 | |
| 315 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
| 316 | - $this->send_failed_order_email( $order_id ); |
|
| 315 | + if ($order->has_status(array('pending', 'failed'))) { |
|
| 316 | + $this->send_failed_order_email($order_id); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * Set secret API Key. |
| 27 | 27 | * @param string $key |
| 28 | 28 | */ |
| 29 | - public static function set_secret_key( $secret_key ) { |
|
| 29 | + public static function set_secret_key($secret_key) { |
|
| 30 | 30 | self::$secret_key = $secret_key; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | 37 | public static function get_secret_key() { |
| 38 | - if ( ! self::$secret_key ) { |
|
| 39 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 38 | + if ( ! self::$secret_key) { |
|
| 39 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 40 | 40 | |
| 41 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
| 42 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
| 41 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
| 42 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | return self::$secret_key; |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | $user_agent = self::get_user_agent(); |
| 79 | 79 | $app_info = $user_agent['application']; |
| 80 | 80 | |
| 81 | - return apply_filters( 'woocommerce_stripe_request_headers', array( |
|
| 82 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
| 81 | + return apply_filters('woocommerce_stripe_request_headers', array( |
|
| 82 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
| 83 | 83 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
| 84 | 84 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
| 85 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
| 86 | - ) ); |
|
| 85 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
| 86 | + )); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -95,13 +95,13 @@ discard block |
||
| 95 | 95 | * @param string $api |
| 96 | 96 | * @return array|WP_Error |
| 97 | 97 | */ |
| 98 | - public static function request( $request, $api = 'charges', $method = 'POST' ) { |
|
| 99 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
| 98 | + public static function request($request, $api = 'charges', $method = 'POST') { |
|
| 99 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
| 100 | 100 | |
| 101 | 101 | $headers = self::get_headers(); |
| 102 | 102 | |
| 103 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
| 104 | - $headers['Idempotency-Key'] = uniqid( 'stripe_' ); |
|
| 103 | + if ('charges' === $api && 'POST' === $method) { |
|
| 104 | + $headers['Idempotency-Key'] = uniqid('stripe_'); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $response = wp_safe_remote_post( |
@@ -109,17 +109,17 @@ discard block |
||
| 109 | 109 | array( |
| 110 | 110 | 'method' => $method, |
| 111 | 111 | 'headers' => $headers, |
| 112 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
| 112 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
| 113 | 113 | 'timeout' => 70, |
| 114 | 114 | ) |
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 118 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
| 119 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 117 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 118 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
| 119 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - return json_decode( $response['body'] ); |
|
| 122 | + return json_decode($response['body']); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | * @version 4.0.0 |
| 130 | 130 | * @param string $api |
| 131 | 131 | */ |
| 132 | - public static function retrieve( $api ) { |
|
| 133 | - WC_Stripe_Logger::log( "{$api}" ); |
|
| 132 | + public static function retrieve($api) { |
|
| 133 | + WC_Stripe_Logger::log("{$api}"); |
|
| 134 | 134 | |
| 135 | 135 | $ua = self::get_user_agent(); |
| 136 | 136 | |
@@ -143,11 +143,11 @@ discard block |
||
| 143 | 143 | ) |
| 144 | 144 | ); |
| 145 | 145 | |
| 146 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 147 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
| 148 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 146 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 147 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
| 148 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - return json_decode( $response['body'] ); |
|
| 151 | + return json_decode($response['body']); |
|
| 152 | 152 | } |
| 153 | 153 | } |