@@ -23,7 +23,6 @@ |
||
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Set secret API Key. |
26 | - * @param string $key |
|
27 | 26 | */ |
28 | 27 | public static function set_secret_key( $secret_key ) { |
29 | 28 | self::$secret_key = $secret_key; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * Set secret API Key. |
27 | 27 | * @param string $key |
28 | 28 | */ |
29 | - public static function set_secret_key( $secret_key ) { |
|
29 | + public static function set_secret_key($secret_key) { |
|
30 | 30 | self::$secret_key = $secret_key; |
31 | 31 | } |
32 | 32 | |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | * @return string |
36 | 36 | */ |
37 | 37 | public static function get_secret_key() { |
38 | - if ( ! self::$secret_key ) { |
|
39 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
38 | + if ( ! self::$secret_key) { |
|
39 | + $options = get_option('woocommerce_stripe_settings'); |
|
40 | 40 | |
41 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
42 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
41 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
42 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | return self::$secret_key; |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | return apply_filters( |
82 | 82 | 'woocommerce_stripe_request_headers', |
83 | 83 | array( |
84 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
84 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
85 | 85 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
86 | 86 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
87 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
87 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
88 | 88 | ) |
89 | 89 | ); |
90 | 90 | } |
@@ -99,16 +99,16 @@ discard block |
||
99 | 99 | * @param bool $with_headers To get the response with headers. |
100 | 100 | * @return array|WP_Error |
101 | 101 | */ |
102 | - public static function request( $request, $api = 'charges', $method = 'POST', $with_headers = false ) { |
|
103 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
102 | + public static function request($request, $api = 'charges', $method = 'POST', $with_headers = false) { |
|
103 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
104 | 104 | |
105 | 105 | $headers = self::get_headers(); |
106 | 106 | $idempotency_key = ''; |
107 | 107 | |
108 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
109 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
110 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
111 | - $idempotency_key = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request ); |
|
108 | + if ('charges' === $api && 'POST' === $method) { |
|
109 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
110 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
111 | + $idempotency_key = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request); |
|
112 | 112 | |
113 | 113 | $headers['Idempotency-Key'] = $idempotency_key; |
114 | 114 | } |
@@ -118,14 +118,14 @@ discard block |
||
118 | 118 | array( |
119 | 119 | 'method' => $method, |
120 | 120 | 'headers' => $headers, |
121 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
121 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
122 | 122 | 'timeout' => 70, |
123 | 123 | ) |
124 | 124 | ); |
125 | 125 | |
126 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
126 | + if (is_wp_error($response) || empty($response['body'])) { |
|
127 | 127 | WC_Stripe_Logger::log( |
128 | - 'Error Response: ' . print_r( $response, true ) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( |
|
128 | + 'Error Response: ' . print_r($response, true) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( |
|
129 | 129 | array( |
130 | 130 | 'api' => $api, |
131 | 131 | 'request' => $request, |
@@ -135,17 +135,17 @@ discard block |
||
135 | 135 | ) |
136 | 136 | ); |
137 | 137 | |
138 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
138 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
139 | 139 | } |
140 | 140 | |
141 | - if ( $with_headers ) { |
|
141 | + if ($with_headers) { |
|
142 | 142 | return array( |
143 | - 'headers' => wp_remote_retrieve_headers( $response ), |
|
144 | - 'body' => json_decode( $response['body'] ), |
|
143 | + 'headers' => wp_remote_retrieve_headers($response), |
|
144 | + 'body' => json_decode($response['body']), |
|
145 | 145 | ); |
146 | 146 | } |
147 | 147 | |
148 | - return json_decode( $response['body'] ); |
|
148 | + return json_decode($response['body']); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | * @version 4.0.0 |
156 | 156 | * @param string $api |
157 | 157 | */ |
158 | - public static function retrieve( $api ) { |
|
159 | - WC_Stripe_Logger::log( "{$api}" ); |
|
158 | + public static function retrieve($api) { |
|
159 | + WC_Stripe_Logger::log("{$api}"); |
|
160 | 160 | |
161 | 161 | $response = wp_safe_remote_get( |
162 | 162 | self::ENDPOINT . $api, |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | ) |
168 | 168 | ); |
169 | 169 | |
170 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
171 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
172 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
170 | + if (is_wp_error($response) || empty($response['body'])) { |
|
171 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
172 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
173 | 173 | } |
174 | 174 | |
175 | - return json_decode( $response['body'] ); |
|
175 | + return json_decode($response['body']); |
|
176 | 176 | } |
177 | 177 | } |
@@ -289,7 +289,7 @@ |
||
289 | 289 | * |
290 | 290 | * @param int $order_id Reference. |
291 | 291 | * @param bool $retry Should we retry on fail. |
292 | - * @param bool $force_save_source Force payment source to be saved. |
|
292 | + * @param bool $force_save_save Force payment source to be saved. |
|
293 | 293 | * |
294 | 294 | * @throws Exception If payment will not be accepted. |
295 | 295 | * |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_alipay'; |
60 | - $this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ 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( '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('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @return bool |
123 | 123 | */ |
124 | 124 | public function is_available() { |
125 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
125 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
126 | 126 | return false; |
127 | 127 | } |
128 | 128 | |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | |
142 | 142 | $icons_str = ''; |
143 | 143 | |
144 | - $icons_str .= isset( $icons['alipay'] ) ? $icons['alipay'] : ''; |
|
144 | + $icons_str .= isset($icons['alipay']) ? $icons['alipay'] : ''; |
|
145 | 145 | |
146 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
146 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -153,19 +153,19 @@ discard block |
||
153 | 153 | * @version 4.0.0 |
154 | 154 | */ |
155 | 155 | public function payment_scripts() { |
156 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
156 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
157 | 157 | return; |
158 | 158 | } |
159 | 159 | |
160 | - wp_enqueue_style( 'stripe_styles' ); |
|
161 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
160 | + wp_enqueue_style('stripe_styles'); |
|
161 | + wp_enqueue_script('woocommerce_stripe'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * Initialize Gateway Settings Form Fields. |
166 | 166 | */ |
167 | 167 | public function init_form_fields() { |
168 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' ); |
|
168 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php'); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -177,13 +177,13 @@ discard block |
||
177 | 177 | $description = $this->get_description(); |
178 | 178 | |
179 | 179 | // If paying from order, we need to get total from order not cart. |
180 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
181 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
180 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
181 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
182 | 182 | $total = $order->get_total(); |
183 | 183 | } |
184 | 184 | |
185 | - if ( is_add_payment_method_page() ) { |
|
186 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
185 | + if (is_add_payment_method_page()) { |
|
186 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
187 | 187 | $total = ''; |
188 | 188 | } else { |
189 | 189 | $pay_button_text = ''; |
@@ -191,11 +191,11 @@ discard block |
||
191 | 191 | |
192 | 192 | echo '<div |
193 | 193 | id="stripe-alipay-payment-data" |
194 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
195 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
194 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
195 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
196 | 196 | |
197 | - if ( $description ) { |
|
198 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
197 | + if ($description) { |
|
198 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | echo '</div>'; |
@@ -209,24 +209,24 @@ discard block |
||
209 | 209 | * @param object $order |
210 | 210 | * @return mixed |
211 | 211 | */ |
212 | - public function create_source( $order ) { |
|
213 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
214 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
215 | - $return_url = $this->get_stripe_return_url( $order ); |
|
212 | + public function create_source($order) { |
|
213 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
214 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
215 | + $return_url = $this->get_stripe_return_url($order); |
|
216 | 216 | $post_data = array(); |
217 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
218 | - $post_data['currency'] = strtolower( $currency ); |
|
217 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
218 | + $post_data['currency'] = strtolower($currency); |
|
219 | 219 | $post_data['type'] = 'alipay'; |
220 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
221 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
220 | + $post_data['owner'] = $this->get_owner_details($order); |
|
221 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
222 | 222 | |
223 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
224 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
223 | + if ( ! empty($this->statement_descriptor)) { |
|
224 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
225 | 225 | } |
226 | 226 | |
227 | - WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' ); |
|
227 | + WC_Stripe_Logger::log('Info: Begin creating Alipay source'); |
|
228 | 228 | |
229 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_alipay_source', $post_data, $order ), 'sources' ); |
|
229 | + return WC_Stripe_API::request(apply_filters('wc_stripe_alipay_source', $post_data, $order), 'sources'); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -240,53 +240,53 @@ discard block |
||
240 | 240 | * |
241 | 241 | * @return array|void |
242 | 242 | */ |
243 | - public function process_payment( $order_id, $retry = true, $force_save_save = false ) { |
|
243 | + public function process_payment($order_id, $retry = true, $force_save_save = false) { |
|
244 | 244 | try { |
245 | - $order = wc_get_order( $order_id ); |
|
245 | + $order = wc_get_order($order_id); |
|
246 | 246 | |
247 | 247 | // This will throw exception if not valid. |
248 | - $this->validate_minimum_order_amount( $order ); |
|
248 | + $this->validate_minimum_order_amount($order); |
|
249 | 249 | |
250 | 250 | // This comes from the create account checkbox in the checkout page. |
251 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
251 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
252 | 252 | |
253 | - if ( $create_account ) { |
|
254 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
255 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
253 | + if ($create_account) { |
|
254 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
255 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
256 | 256 | $new_stripe_customer->create_customer(); |
257 | 257 | } |
258 | 258 | |
259 | - $response = $this->create_source( $order ); |
|
259 | + $response = $this->create_source($order); |
|
260 | 260 | |
261 | - if ( ! empty( $response->error ) ) { |
|
262 | - $order->add_order_note( $response->error->message ); |
|
261 | + if ( ! empty($response->error)) { |
|
262 | + $order->add_order_note($response->error->message); |
|
263 | 263 | |
264 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
264 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
265 | 265 | } |
266 | 266 | |
267 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
268 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
267 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
268 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
269 | 269 | } else { |
270 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
270 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
271 | 271 | $order->save(); |
272 | 272 | } |
273 | 273 | |
274 | - WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); |
|
274 | + WC_Stripe_Logger::log('Info: Redirecting to Alipay...'); |
|
275 | 275 | |
276 | 276 | return array( |
277 | 277 | 'result' => 'success', |
278 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
278 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
279 | 279 | ); |
280 | - } catch ( WC_Stripe_Exception $e ) { |
|
281 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
282 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
280 | + } catch (WC_Stripe_Exception $e) { |
|
281 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
282 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
283 | 283 | |
284 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
284 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
285 | 285 | |
286 | - $statuses = array( 'pending', 'failed' ); |
|
286 | + $statuses = array('pending', 'failed'); |
|
287 | 287 | |
288 | - if ( $order->has_status( $statuses ) ) { |
|
289 | - $this->send_failed_order_email( $order_id ); |
|
288 | + if ($order->has_status($statuses)) { |
|
289 | + $this->send_failed_order_email($order_id); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | return array( |
@@ -213,7 +213,6 @@ |
||
213 | 213 | /** |
214 | 214 | * Get a customers saved sources using their Stripe ID. |
215 | 215 | * |
216 | - * @param string $customer_id |
|
217 | 216 | * @return array |
218 | 217 | */ |
219 | 218 | public function get_sources() { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * Constructor |
33 | 33 | * @param int $user_id The WP user ID |
34 | 34 | */ |
35 | - public function __construct( $user_id = 0 ) { |
|
36 | - if ( $user_id ) { |
|
37 | - $this->set_user_id( $user_id ); |
|
38 | - $this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
35 | + public function __construct($user_id = 0) { |
|
36 | + if ($user_id) { |
|
37 | + $this->set_user_id($user_id); |
|
38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -51,15 +51,15 @@ discard block |
||
51 | 51 | * Set Stripe customer ID. |
52 | 52 | * @param [type] $id [description] |
53 | 53 | */ |
54 | - public function set_id( $id ) { |
|
54 | + public function set_id($id) { |
|
55 | 55 | // Backwards compat for customer ID stored in array format. (Pre 3.0) |
56 | - if ( is_array( $id ) && isset( $id['customer_id'] ) ) { |
|
56 | + if (is_array($id) && isset($id['customer_id'])) { |
|
57 | 57 | $id = $id['customer_id']; |
58 | 58 | |
59 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $id ); |
|
59 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $id); |
|
60 | 60 | } |
61 | 61 | |
62 | - $this->id = wc_clean( $id ); |
|
62 | + $this->id = wc_clean($id); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | * @return int |
68 | 68 | */ |
69 | 69 | public function get_user_id() { |
70 | - return absint( $this->user_id ); |
|
70 | + return absint($this->user_id); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | 74 | * Set User ID used by WordPress. |
75 | 75 | * @param int $user_id |
76 | 76 | */ |
77 | - public function set_user_id( $user_id ) { |
|
78 | - $this->user_id = absint( $user_id ); |
|
77 | + public function set_user_id($user_id) { |
|
78 | + $this->user_id = absint($user_id); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -83,13 +83,13 @@ discard block |
||
83 | 83 | * @return WP_User |
84 | 84 | */ |
85 | 85 | protected function get_user() { |
86 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
86 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
90 | 90 | * Store data from the Stripe API about this customer |
91 | 91 | */ |
92 | - public function set_customer_data( $data ) { |
|
92 | + public function set_customer_data($data) { |
|
93 | 93 | $this->customer_data = $data; |
94 | 94 | } |
95 | 95 | |
@@ -98,25 +98,25 @@ discard block |
||
98 | 98 | * @param array $args |
99 | 99 | * @return WP_Error|int |
100 | 100 | */ |
101 | - public function create_customer( $args = array() ) { |
|
102 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
101 | + public function create_customer($args = array()) { |
|
102 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
103 | 103 | $user = $this->get_user(); |
104 | 104 | |
105 | - if ( $user ) { |
|
106 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
107 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
105 | + if ($user) { |
|
106 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
107 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
108 | 108 | |
109 | 109 | // If billing first name does not exists try the user first name. |
110 | - if ( empty( $billing_first_name ) ) { |
|
111 | - $billing_first_name = get_user_meta( $user->ID, 'first_name', true ); |
|
110 | + if (empty($billing_first_name)) { |
|
111 | + $billing_first_name = get_user_meta($user->ID, 'first_name', true); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | // If billing last name does not exists try the user last name. |
115 | - if ( empty( $billing_last_name ) ) { |
|
116 | - $billing_last_name = get_user_meta( $user->ID, 'last_name', true ); |
|
115 | + if (empty($billing_last_name)) { |
|
116 | + $billing_last_name = get_user_meta($user->ID, 'last_name', true); |
|
117 | 117 | } |
118 | 118 | |
119 | - $description = __( 'Name', 'woocommerce-gateway-stripe' ) . ': ' . $billing_first_name . ' ' . $billing_last_name . ' ' . __( 'Username', 'woocommerce-gateway-stripe' ) . ': ' . $user->user_login; |
|
119 | + $description = __('Name', 'woocommerce-gateway-stripe') . ': ' . $billing_first_name . ' ' . $billing_last_name . ' ' . __('Username', 'woocommerce-gateway-stripe') . ': ' . $user->user_login; |
|
120 | 120 | |
121 | 121 | $defaults = array( |
122 | 122 | 'email' => $user->user_email, |
@@ -131,24 +131,24 @@ discard block |
||
131 | 131 | |
132 | 132 | $metadata = array(); |
133 | 133 | |
134 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
134 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
135 | 135 | |
136 | - $args = wp_parse_args( $args, $defaults ); |
|
137 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
136 | + $args = wp_parse_args($args, $defaults); |
|
137 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
138 | 138 | |
139 | - if ( ! empty( $response->error ) ) { |
|
140 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
139 | + if ( ! empty($response->error)) { |
|
140 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
141 | 141 | } |
142 | 142 | |
143 | - $this->set_id( $response->id ); |
|
143 | + $this->set_id($response->id); |
|
144 | 144 | $this->clear_cache(); |
145 | - $this->set_customer_data( $response ); |
|
145 | + $this->set_customer_data($response); |
|
146 | 146 | |
147 | - if ( $this->get_user_id() ) { |
|
148 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
147 | + if ($this->get_user_id()) { |
|
148 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
149 | 149 | } |
150 | 150 | |
151 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
151 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
152 | 152 | |
153 | 153 | return $response->id; |
154 | 154 | } |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | * @since 4.1.2 |
161 | 161 | * @param array $error |
162 | 162 | */ |
163 | - public function is_no_such_customer_error( $error ) { |
|
163 | + public function is_no_such_customer_error($error) { |
|
164 | 164 | return ( |
165 | 165 | $error && |
166 | 166 | 'invalid_request_error' === $error->type && |
167 | - preg_match( '/No such customer/i', $error->message ) |
|
167 | + preg_match('/No such customer/i', $error->message) |
|
168 | 168 | ); |
169 | 169 | } |
170 | 170 | |
@@ -174,9 +174,9 @@ discard block |
||
174 | 174 | * @param bool $retry |
175 | 175 | * @return WP_Error|int |
176 | 176 | */ |
177 | - public function add_source( $source_id, $retry = true ) { |
|
178 | - if ( ! $this->get_id() ) { |
|
179 | - $this->set_id( $this->create_customer() ); |
|
177 | + public function add_source($source_id, $retry = true) { |
|
178 | + if ( ! $this->get_id()) { |
|
179 | + $this->set_id($this->create_customer()); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | $response = WC_Stripe_API::request( |
@@ -188,63 +188,63 @@ discard block |
||
188 | 188 | |
189 | 189 | $wc_token = false; |
190 | 190 | |
191 | - if ( ! empty( $response->error ) ) { |
|
191 | + if ( ! empty($response->error)) { |
|
192 | 192 | // It is possible the WC user once was linked to a customer on Stripe |
193 | 193 | // but no longer exists. Instead of failing, lets try to create a |
194 | 194 | // new customer. |
195 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
196 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
195 | + if ($this->is_no_such_customer_error($response->error)) { |
|
196 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
197 | 197 | $this->create_customer(); |
198 | - return $this->add_source( $source_id, false ); |
|
198 | + return $this->add_source($source_id, false); |
|
199 | 199 | } else { |
200 | 200 | return $response; |
201 | 201 | } |
202 | - } elseif ( empty( $response->id ) ) { |
|
203 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
202 | + } elseif (empty($response->id)) { |
|
203 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | // Add token to WooCommerce. |
207 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
208 | - if ( ! empty( $response->type ) ) { |
|
209 | - switch ( $response->type ) { |
|
207 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
208 | + if ( ! empty($response->type)) { |
|
209 | + switch ($response->type) { |
|
210 | 210 | case 'alipay': |
211 | 211 | break; |
212 | 212 | case 'sepa_debit': |
213 | 213 | $wc_token = new WC_Payment_Token_SEPA(); |
214 | - $wc_token->set_token( $response->id ); |
|
215 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
216 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
214 | + $wc_token->set_token($response->id); |
|
215 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
216 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
217 | 217 | break; |
218 | 218 | default: |
219 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
219 | + if ('source' === $response->object && 'card' === $response->type) { |
|
220 | 220 | $wc_token = new WC_Payment_Token_CC(); |
221 | - $wc_token->set_token( $response->id ); |
|
222 | - $wc_token->set_gateway_id( 'stripe' ); |
|
223 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
224 | - $wc_token->set_last4( $response->card->last4 ); |
|
225 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
226 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
221 | + $wc_token->set_token($response->id); |
|
222 | + $wc_token->set_gateway_id('stripe'); |
|
223 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
224 | + $wc_token->set_last4($response->card->last4); |
|
225 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
226 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
227 | 227 | } |
228 | 228 | break; |
229 | 229 | } |
230 | 230 | } else { |
231 | 231 | // Legacy. |
232 | 232 | $wc_token = new WC_Payment_Token_CC(); |
233 | - $wc_token->set_token( $response->id ); |
|
234 | - $wc_token->set_gateway_id( 'stripe' ); |
|
235 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
236 | - $wc_token->set_last4( $response->last4 ); |
|
237 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
238 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
233 | + $wc_token->set_token($response->id); |
|
234 | + $wc_token->set_gateway_id('stripe'); |
|
235 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
236 | + $wc_token->set_last4($response->last4); |
|
237 | + $wc_token->set_expiry_month($response->exp_month); |
|
238 | + $wc_token->set_expiry_year($response->exp_year); |
|
239 | 239 | } |
240 | 240 | |
241 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
241 | + $wc_token->set_user_id($this->get_user_id()); |
|
242 | 242 | $wc_token->save(); |
243 | 243 | } |
244 | 244 | |
245 | 245 | $this->clear_cache(); |
246 | 246 | |
247 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
247 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
248 | 248 | |
249 | 249 | return $response->id; |
250 | 250 | } |
@@ -256,11 +256,11 @@ discard block |
||
256 | 256 | * @return array |
257 | 257 | */ |
258 | 258 | public function get_sources() { |
259 | - if ( ! $this->get_id() ) { |
|
259 | + if ( ! $this->get_id()) { |
|
260 | 260 | return array(); |
261 | 261 | } |
262 | 262 | |
263 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
263 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
264 | 264 | |
265 | 265 | $response = WC_Stripe_API::request( |
266 | 266 | array( |
@@ -270,32 +270,32 @@ discard block |
||
270 | 270 | 'GET' |
271 | 271 | ); |
272 | 272 | |
273 | - if ( ! empty( $response->error ) ) { |
|
273 | + if ( ! empty($response->error)) { |
|
274 | 274 | return array(); |
275 | 275 | } |
276 | 276 | |
277 | - if ( is_array( $response->data ) ) { |
|
277 | + if (is_array($response->data)) { |
|
278 | 278 | $sources = $response->data; |
279 | 279 | } |
280 | 280 | |
281 | - return empty( $sources ) ? array() : $sources; |
|
281 | + return empty($sources) ? array() : $sources; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
285 | 285 | * Delete a source from stripe. |
286 | 286 | * @param string $source_id |
287 | 287 | */ |
288 | - public function delete_source( $source_id ) { |
|
289 | - if ( ! $this->get_id() ) { |
|
288 | + public function delete_source($source_id) { |
|
289 | + if ( ! $this->get_id()) { |
|
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | |
293 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
293 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
294 | 294 | |
295 | 295 | $this->clear_cache(); |
296 | 296 | |
297 | - if ( empty( $response->error ) ) { |
|
298 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
297 | + if (empty($response->error)) { |
|
298 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
299 | 299 | |
300 | 300 | return true; |
301 | 301 | } |
@@ -307,10 +307,10 @@ discard block |
||
307 | 307 | * Set default source in Stripe |
308 | 308 | * @param string $source_id |
309 | 309 | */ |
310 | - public function set_default_source( $source_id ) { |
|
310 | + public function set_default_source($source_id) { |
|
311 | 311 | $response = WC_Stripe_API::request( |
312 | 312 | array( |
313 | - 'default_source' => sanitize_text_field( $source_id ), |
|
313 | + 'default_source' => sanitize_text_field($source_id), |
|
314 | 314 | ), |
315 | 315 | 'customers/' . $this->get_id(), |
316 | 316 | 'POST' |
@@ -318,8 +318,8 @@ discard block |
||
318 | 318 | |
319 | 319 | $this->clear_cache(); |
320 | 320 | |
321 | - if ( empty( $response->error ) ) { |
|
322 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
321 | + if (empty($response->error)) { |
|
322 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
323 | 323 | |
324 | 324 | return true; |
325 | 325 | } |
@@ -331,8 +331,8 @@ discard block |
||
331 | 331 | * Deletes caches for this users cards. |
332 | 332 | */ |
333 | 333 | public function clear_cache() { |
334 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
335 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
334 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
335 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
336 | 336 | $this->customer_data = array(); |
337 | 337 | } |
338 | 338 | } |
@@ -2,12 +2,12 @@ discard block |
||
2 | 2 | |
3 | 3 | class WC_Stripe_Test extends WP_UnitTestCase { |
4 | 4 | public function test_constants_defined() { |
5 | - $this->assertTrue( defined( 'WC_STRIPE_VERSION' ) ); |
|
6 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) ); |
|
7 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) ); |
|
8 | - $this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) ); |
|
9 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) ); |
|
10 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) ); |
|
5 | + $this->assertTrue(defined('WC_STRIPE_VERSION')); |
|
6 | + $this->assertTrue(defined('WC_STRIPE_MIN_PHP_VER')); |
|
7 | + $this->assertTrue(defined('WC_STRIPE_MIN_WC_VER')); |
|
8 | + $this->assertTrue(defined('WC_STRIPE_MAIN_FILE')); |
|
9 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_URL')); |
|
10 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_PATH')); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * This test will see if we're indeed converting the price correctly. |
16 | 16 | */ |
17 | 17 | public function test_price_conversion_before_send_to_stripe() { |
18 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
19 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) ); |
|
20 | - $this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) ); |
|
21 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) ); |
|
22 | - $this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
18 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
19 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(10050, 'JPY')); |
|
20 | + $this->assertEquals(100, WC_Stripe_Helper::get_stripe_amount(100.50, 'JPY')); |
|
21 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50)); |
|
22 | + $this->assertInternalType('int', WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -33,37 +33,37 @@ discard block |
||
33 | 33 | $balance_fee1->net = 10000; |
34 | 34 | $balance_fee1->currency = 'USD'; |
35 | 35 | |
36 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) ); |
|
36 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee1, 'fee')); |
|
37 | 37 | |
38 | 38 | $balance_fee2 = new stdClass(); |
39 | 39 | $balance_fee2->fee = 10500; |
40 | 40 | $balance_fee2->net = 10000; |
41 | 41 | $balance_fee2->currency = 'JPY'; |
42 | 42 | |
43 | - $this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) ); |
|
43 | + $this->assertEquals(10500, WC_Stripe_Helper::format_balance_fee($balance_fee2, 'fee')); |
|
44 | 44 | |
45 | 45 | $balance_fee3 = new stdClass(); |
46 | 46 | $balance_fee3->fee = 10500; |
47 | 47 | $balance_fee3->net = 10000; |
48 | 48 | $balance_fee3->currency = 'USD'; |
49 | 49 | |
50 | - $this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) ); |
|
50 | + $this->assertEquals(100.00, WC_Stripe_Helper::format_balance_fee($balance_fee3, 'net')); |
|
51 | 51 | |
52 | 52 | $balance_fee4 = new stdClass(); |
53 | 53 | $balance_fee4->fee = 10500; |
54 | 54 | $balance_fee4->net = 10000; |
55 | 55 | $balance_fee4->currency = 'JPY'; |
56 | 56 | |
57 | - $this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) ); |
|
57 | + $this->assertEquals(10000, WC_Stripe_Helper::format_balance_fee($balance_fee4, 'net')); |
|
58 | 58 | |
59 | 59 | $balance_fee5 = new stdClass(); |
60 | 60 | $balance_fee5->fee = 10500; |
61 | 61 | $balance_fee5->net = 10000; |
62 | 62 | $balance_fee5->currency = 'USD'; |
63 | 63 | |
64 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
64 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
65 | 65 | |
66 | - $this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
66 | + $this->assertInternalType('string', WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -76,28 +76,28 @@ discard block |
||
76 | 76 | 'expected' => 'Tests Store', |
77 | 77 | ); |
78 | 78 | |
79 | - $this->assertEquals( $statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor1['actual'] ) ); |
|
79 | + $this->assertEquals($statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor1['actual'])); |
|
80 | 80 | |
81 | 81 | $statement_descriptor2 = array( |
82 | 82 | 'actual' => 'Test\'s Store > Driving Course Range', |
83 | 83 | 'expected' => 'Tests Store Driving C', |
84 | 84 | ); |
85 | 85 | |
86 | - $this->assertEquals( $statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor2['actual'] ) ); |
|
86 | + $this->assertEquals($statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor2['actual'])); |
|
87 | 87 | |
88 | 88 | $statement_descriptor3 = array( |
89 | 89 | 'actual' => 'Test\'s Store < Driving Course Range', |
90 | 90 | 'expected' => 'Tests Store Driving C', |
91 | 91 | ); |
92 | 92 | |
93 | - $this->assertEquals( $statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor3['actual'] ) ); |
|
93 | + $this->assertEquals($statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor3['actual'])); |
|
94 | 94 | |
95 | 95 | $statement_descriptor4 = array( |
96 | 96 | 'actual' => 'Test\'s Store " Driving Course Range', |
97 | 97 | 'expected' => 'Tests Store Driving C', |
98 | 98 | ); |
99 | 99 | |
100 | - $this->assertEquals( $statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor4['actual'] ) ); |
|
100 | + $this->assertEquals($statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor4['actual'])); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | $source = new stdClass(); |
110 | 110 | $source->type = 'three_d_secure'; |
111 | 111 | |
112 | - $this->assertEquals( true, $stripe->is_3ds_card( $source ) ); |
|
112 | + $this->assertEquals(true, $stripe->is_3ds_card($source)); |
|
113 | 113 | |
114 | 114 | $source = new stdClass(); |
115 | 115 | $source->type = 'card'; |
116 | 116 | |
117 | - $this->assertEquals( false, $stripe->is_3ds_card( $source ) ); |
|
117 | + $this->assertEquals(false, $stripe->is_3ds_card($source)); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | $source->card = new stdClass(); |
129 | 129 | $source->card->three_d_secure = 'required'; |
130 | 130 | |
131 | - $this->assertEquals( true, $stripe->is_3ds_required( $source ) ); |
|
131 | + $this->assertEquals(true, $stripe->is_3ds_required($source)); |
|
132 | 132 | |
133 | 133 | $source = new stdClass(); |
134 | 134 | $source->type = 'card'; |
135 | 135 | $source->card = new stdClass(); |
136 | 136 | $source->card->three_d_secure = 'optional'; |
137 | 137 | |
138 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
138 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
139 | 139 | |
140 | 140 | $source = new stdClass(); |
141 | 141 | $source->type = 'card'; |
142 | 142 | $source->card = new stdClass(); |
143 | 143 | $source->card->three_d_secure = 'not_supported'; |
144 | 144 | |
145 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
145 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
146 | 146 | } |
147 | 147 | } |
@@ -104,7 +104,7 @@ |
||
104 | 104 | * Get this instance. |
105 | 105 | * |
106 | 106 | * @since 4.0.6 |
107 | - * @return class |
|
107 | + * @return WC_Stripe_Payment_Request |
|
108 | 108 | */ |
109 | 109 | public static function instance() { |
110 | 110 | return self::$_this; |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 4.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -71,42 +71,42 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function __construct() { |
73 | 73 | self::$_this = $this; |
74 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
75 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
76 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | - $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
74 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
75 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
76 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | + $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
80 | 80 | |
81 | - if ( $this->testmode ) { |
|
82 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | - $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
81 | + if ($this->testmode) { |
|
82 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | + $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
84 | 84 | } |
85 | 85 | |
86 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
86 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
87 | 87 | |
88 | 88 | // Checks if Stripe Gateway is enabled. |
89 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
89 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | 93 | // Checks if Payment Request is enabled. |
94 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
94 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // Don't load for change payment method page. |
99 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
99 | + if (isset($_GET['change_payment_method'])) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | - $wc_default_country = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
103 | + $wc_default_country = substr(get_option('woocommerce_default_country'), 0, 2); |
|
104 | 104 | |
105 | - if ( ! in_array( $wc_default_country, $this->get_stripe_supported_countries() ) ) { |
|
105 | + if ( ! in_array($wc_default_country, $this->get_stripe_supported_countries())) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | - add_action( 'template_redirect', array( $this, 'set_session' ) ); |
|
109 | + add_action('template_redirect', array($this, 'set_session')); |
|
110 | 110 | $this->init(); |
111 | 111 | } |
112 | 112 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @return array The list of countries. |
118 | 118 | */ |
119 | 119 | public function get_stripe_supported_countries() { |
120 | - return apply_filters( 'wc_stripe_supported_countries', array( 'AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PT', 'RO', 'SE', 'SG', 'SK', 'US' ) ); |
|
120 | + return apply_filters('wc_stripe_supported_countries', array('AT', 'AU', 'BE', 'BR', 'CA', 'CH', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'HK', 'IE', 'IN', 'IT', 'JP', 'LT', 'LU', 'LV', 'MX', 'NL', 'NZ', 'NO', 'PH', 'PL', 'PT', 'RO', 'SE', 'SG', 'SK', 'US')); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @return bool |
128 | 128 | */ |
129 | 129 | public function are_keys_set() { |
130 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
130 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
131 | 131 | return false; |
132 | 132 | } |
133 | 133 | |
@@ -151,18 +151,18 @@ discard block |
||
151 | 151 | * @since 4.0.0 |
152 | 152 | */ |
153 | 153 | public function set_session() { |
154 | - if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) { |
|
154 | + if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) { |
|
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | - $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' ); |
|
158 | + $session_class = apply_filters('woocommerce_session_handler', 'WC_Session_Handler'); |
|
159 | 159 | $wc_session = new $session_class(); |
160 | 160 | |
161 | - if ( version_compare( WC_VERSION, '3.3', '>=' ) ) { |
|
161 | + if (version_compare(WC_VERSION, '3.3', '>=')) { |
|
162 | 162 | $wc_session->init(); |
163 | 163 | } |
164 | 164 | |
165 | - $wc_session->set_customer_session_cookie( true ); |
|
165 | + $wc_session->set_customer_session_cookie(true); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,40 +172,40 @@ discard block |
||
172 | 172 | * @version 4.0.0 |
173 | 173 | */ |
174 | 174 | public function init() { |
175 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
175 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
176 | 176 | |
177 | 177 | /* |
178 | 178 | * In order to display the Payment Request button in the correct position, |
179 | 179 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
180 | 180 | * CSS is used to position the button. |
181 | 181 | */ |
182 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
183 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
184 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
182 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
183 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
184 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
185 | 185 | } else { |
186 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
187 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
186 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
187 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
188 | 188 | } |
189 | 189 | |
190 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
191 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
190 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
191 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
192 | 192 | |
193 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
194 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
193 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
194 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
195 | 195 | |
196 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
197 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
198 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
199 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
200 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
201 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
202 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
203 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
196 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
197 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
198 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
199 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
200 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
201 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
202 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
203 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
204 | 204 | |
205 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
206 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
205 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
206 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
207 | 207 | |
208 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
208 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @return string |
217 | 217 | */ |
218 | 218 | public function get_button_type() { |
219 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
219 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @return string |
228 | 228 | */ |
229 | 229 | public function get_button_theme() { |
230 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
230 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @return string |
239 | 239 | */ |
240 | 240 | public function get_button_height() { |
241 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
241 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -248,40 +248,40 @@ discard block |
||
248 | 248 | * @version 4.0.0 |
249 | 249 | */ |
250 | 250 | public function get_product_data() { |
251 | - if ( ! is_product() ) { |
|
251 | + if ( ! is_product()) { |
|
252 | 252 | return false; |
253 | 253 | } |
254 | 254 | |
255 | 255 | global $post; |
256 | 256 | |
257 | - $product = wc_get_product( $post->ID ); |
|
257 | + $product = wc_get_product($post->ID); |
|
258 | 258 | |
259 | 259 | $data = array(); |
260 | 260 | $items = array(); |
261 | 261 | |
262 | 262 | $items[] = array( |
263 | - 'label' => WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name(), |
|
264 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ), |
|
263 | + 'label' => WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name(), |
|
264 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()), |
|
265 | 265 | ); |
266 | 266 | |
267 | - if ( wc_tax_enabled() ) { |
|
267 | + if (wc_tax_enabled()) { |
|
268 | 268 | $items[] = array( |
269 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
269 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
270 | 270 | 'amount' => 0, |
271 | 271 | 'pending' => true, |
272 | 272 | ); |
273 | 273 | } |
274 | 274 | |
275 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
275 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
276 | 276 | $items[] = array( |
277 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
277 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
278 | 278 | 'amount' => 0, |
279 | 279 | 'pending' => true, |
280 | 280 | ); |
281 | 281 | |
282 | 282 | $data['shippingOptions'] = array( |
283 | 283 | 'id' => 'pending', |
284 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
284 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
285 | 285 | 'detail' => '', |
286 | 286 | 'amount' => 0, |
287 | 287 | ); |
@@ -289,41 +289,41 @@ discard block |
||
289 | 289 | |
290 | 290 | $data['displayItems'] = $items; |
291 | 291 | $data['total'] = array( |
292 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
293 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ), |
|
292 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
293 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()), |
|
294 | 294 | 'pending' => true, |
295 | 295 | ); |
296 | 296 | |
297 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
298 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
299 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
297 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
298 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
299 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
300 | 300 | |
301 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
301 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
305 | 305 | * Filters the gateway title to reflect Payment Request type |
306 | 306 | * |
307 | 307 | */ |
308 | - public function filter_gateway_title( $title, $id ) { |
|
308 | + public function filter_gateway_title($title, $id) { |
|
309 | 309 | global $post; |
310 | 310 | |
311 | - if ( ! is_object( $post ) ) { |
|
311 | + if ( ! is_object($post)) { |
|
312 | 312 | return $title; |
313 | 313 | } |
314 | 314 | |
315 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
316 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
315 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
316 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
317 | 317 | } else { |
318 | - $order = wc_get_order( $post->ID ); |
|
319 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
318 | + $order = wc_get_order($post->ID); |
|
319 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
320 | 320 | } |
321 | 321 | |
322 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
322 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
323 | 323 | return $method_title; |
324 | 324 | } |
325 | 325 | |
326 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
326 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
327 | 327 | return $method_title; |
328 | 328 | } |
329 | 329 | |
@@ -336,16 +336,16 @@ discard block |
||
336 | 336 | * @since 3.1.4 |
337 | 337 | * @version 4.0.0 |
338 | 338 | */ |
339 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
339 | + public function postal_code_validation($valid, $postcode, $country) { |
|
340 | 340 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
341 | 341 | |
342 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
342 | + if ( ! isset($gateways['stripe'])) { |
|
343 | 343 | return $valid; |
344 | 344 | } |
345 | 345 | |
346 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
346 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
347 | 347 | |
348 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
348 | + if ('apple_pay' !== $payment_request_type) { |
|
349 | 349 | return $valid; |
350 | 350 | } |
351 | 351 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * the order and not let it go through. The remedy for now is just to remove this validation. |
356 | 356 | * Note that this only works with shipping providers that don't validate full postal codes. |
357 | 357 | */ |
358 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
358 | + if ('GB' === $country || 'CA' === $country) { |
|
359 | 359 | return true; |
360 | 360 | } |
361 | 361 | |
@@ -370,29 +370,29 @@ discard block |
||
370 | 370 | * @param int $order_id |
371 | 371 | * @param array $posted_data The posted data from checkout form. |
372 | 372 | */ |
373 | - public function add_order_meta( $order_id, $posted_data ) { |
|
374 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
373 | + public function add_order_meta($order_id, $posted_data) { |
|
374 | + if (empty($_POST['payment_request_type'])) { |
|
375 | 375 | return; |
376 | 376 | } |
377 | 377 | |
378 | - $order = wc_get_order( $order_id ); |
|
378 | + $order = wc_get_order($order_id); |
|
379 | 379 | |
380 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
380 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
381 | 381 | |
382 | - if ( 'apple_pay' === $payment_request_type ) { |
|
383 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
384 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
382 | + if ('apple_pay' === $payment_request_type) { |
|
383 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
384 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
385 | 385 | } else { |
386 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
386 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
387 | 387 | $order->save(); |
388 | 388 | } |
389 | 389 | } |
390 | 390 | |
391 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
392 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
393 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
391 | + if ('payment_request_api' === $payment_request_type) { |
|
392 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
393 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
394 | 394 | } else { |
395 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
395 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
396 | 396 | $order->save(); |
397 | 397 | } |
398 | 398 | } |
@@ -429,15 +429,15 @@ discard block |
||
429 | 429 | * @return bool |
430 | 430 | */ |
431 | 431 | public function allowed_items_in_cart() { |
432 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
433 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
432 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
433 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
434 | 434 | |
435 | - if ( ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
435 | + if ( ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
436 | 436 | return false; |
437 | 437 | } |
438 | 438 | |
439 | 439 | // Pre Orders compatbility where we don't support charge upon release. |
440 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
440 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
441 | 441 | return false; |
442 | 442 | } |
443 | 443 | } |
@@ -453,80 +453,80 @@ discard block |
||
453 | 453 | */ |
454 | 454 | public function scripts() { |
455 | 455 | // If keys are not set bail. |
456 | - if ( ! $this->are_keys_set() ) { |
|
457 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
456 | + if ( ! $this->are_keys_set()) { |
|
457 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
458 | 458 | return; |
459 | 459 | } |
460 | 460 | |
461 | 461 | // If no SSL bail. |
462 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
463 | - WC_Stripe_Logger::log( 'Stripe Payment Request live mode requires SSL.' ); |
|
462 | + if ( ! $this->testmode && ! is_ssl()) { |
|
463 | + WC_Stripe_Logger::log('Stripe Payment Request live mode requires SSL.'); |
|
464 | 464 | return; |
465 | 465 | } |
466 | 466 | |
467 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
467 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
468 | 468 | return; |
469 | 469 | } |
470 | 470 | |
471 | - if ( is_product() ) { |
|
471 | + if (is_product()) { |
|
472 | 472 | global $post; |
473 | 473 | |
474 | - $product = wc_get_product( $post->ID ); |
|
474 | + $product = wc_get_product($post->ID); |
|
475 | 475 | |
476 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
476 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
477 | 477 | return; |
478 | 478 | } |
479 | 479 | |
480 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
480 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
481 | 481 | return; |
482 | 482 | } |
483 | 483 | } |
484 | 484 | |
485 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
485 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
486 | 486 | |
487 | 487 | $stripe_params = array( |
488 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
488 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
489 | 489 | 'stripe' => array( |
490 | 490 | 'key' => $this->publishable_key, |
491 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
491 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
492 | 492 | ), |
493 | 493 | 'nonce' => array( |
494 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
495 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
496 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
497 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
498 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
499 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
500 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
501 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
494 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
495 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
496 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
497 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
498 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
499 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
500 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
501 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
502 | 502 | ), |
503 | 503 | 'i18n' => array( |
504 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
504 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
505 | 505 | /* translators: Do not translate the [option] placeholder */ |
506 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
506 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
507 | 507 | ), |
508 | 508 | 'checkout' => array( |
509 | 509 | 'url' => wc_get_checkout_url(), |
510 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
511 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
510 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
511 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
512 | 512 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
513 | 513 | ), |
514 | 514 | 'button' => array( |
515 | 515 | 'type' => $this->get_button_type(), |
516 | 516 | 'theme' => $this->get_button_theme(), |
517 | 517 | 'height' => $this->get_button_height(), |
518 | - 'locale' => apply_filters( 'wc_stripe_payment_request_button_locale', substr( get_locale(), 0, 2 ) ), // Default format is en_US. |
|
518 | + 'locale' => apply_filters('wc_stripe_payment_request_button_locale', substr(get_locale(), 0, 2)), // Default format is en_US. |
|
519 | 519 | ), |
520 | 520 | 'is_product_page' => is_product(), |
521 | 521 | 'product' => $this->get_product_data(), |
522 | 522 | ); |
523 | 523 | |
524 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
525 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
524 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
525 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
526 | 526 | |
527 | - wp_localize_script( 'wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters( 'wc_stripe_payment_request_params', $stripe_params ) ); |
|
527 | + wp_localize_script('wc_stripe_payment_request', 'wc_stripe_payment_request_params', apply_filters('wc_stripe_payment_request_params', $stripe_params)); |
|
528 | 528 | |
529 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
529 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | /** |
@@ -540,37 +540,37 @@ discard block |
||
540 | 540 | |
541 | 541 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
542 | 542 | |
543 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
543 | + if ( ! isset($gateways['stripe'])) { |
|
544 | 544 | return; |
545 | 545 | } |
546 | 546 | |
547 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
547 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
548 | 548 | return; |
549 | 549 | } |
550 | 550 | |
551 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
551 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
552 | 552 | return; |
553 | 553 | } |
554 | 554 | |
555 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
555 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
556 | 556 | return; |
557 | 557 | } |
558 | 558 | |
559 | - if ( is_product() ) { |
|
560 | - $product = wc_get_product( $post->ID ); |
|
559 | + if (is_product()) { |
|
560 | + $product = wc_get_product($post->ID); |
|
561 | 561 | |
562 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
562 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
563 | 563 | return; |
564 | 564 | } |
565 | 565 | |
566 | 566 | // Pre Orders charge upon release not supported. |
567 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
568 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
567 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
568 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
569 | 569 | return; |
570 | 570 | } |
571 | 571 | } else { |
572 | - if ( ! $this->allowed_items_in_cart() ) { |
|
573 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
572 | + if ( ! $this->allowed_items_in_cart()) { |
|
573 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
574 | 574 | return; |
575 | 575 | } |
576 | 576 | } |
@@ -594,42 +594,42 @@ discard block |
||
594 | 594 | |
595 | 595 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
596 | 596 | |
597 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
597 | + if ( ! isset($gateways['stripe'])) { |
|
598 | 598 | return; |
599 | 599 | } |
600 | 600 | |
601 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
601 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
602 | 602 | return; |
603 | 603 | } |
604 | 604 | |
605 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false, $post ) ) { |
|
605 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false, $post)) { |
|
606 | 606 | return; |
607 | 607 | } |
608 | 608 | |
609 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false, $post ) ) { |
|
609 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false, $post)) { |
|
610 | 610 | return; |
611 | 611 | } |
612 | 612 | |
613 | - if ( is_product() ) { |
|
614 | - $product = wc_get_product( $post->ID ); |
|
613 | + if (is_product()) { |
|
614 | + $product = wc_get_product($post->ID); |
|
615 | 615 | |
616 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
616 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
617 | 617 | return; |
618 | 618 | } |
619 | 619 | |
620 | 620 | // Pre Orders charge upon release not supported. |
621 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
622 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
621 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
622 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
623 | 623 | return; |
624 | 624 | } |
625 | 625 | } else { |
626 | - if ( ! $this->allowed_items_in_cart() ) { |
|
627 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
626 | + if ( ! $this->allowed_items_in_cart()) { |
|
627 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
628 | 628 | return; |
629 | 629 | } |
630 | 630 | } |
631 | 631 | ?> |
632 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> —</p> |
|
632 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> —</p> |
|
633 | 633 | <?php |
634 | 634 | } |
635 | 635 | |
@@ -640,11 +640,11 @@ discard block |
||
640 | 640 | * @version 4.0.0 |
641 | 641 | */ |
642 | 642 | public function ajax_log_errors() { |
643 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
643 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
644 | 644 | |
645 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
645 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
646 | 646 | |
647 | - WC_Stripe_Logger::log( $errors ); |
|
647 | + WC_Stripe_Logger::log($errors); |
|
648 | 648 | |
649 | 649 | exit; |
650 | 650 | } |
@@ -656,7 +656,7 @@ discard block |
||
656 | 656 | * @version 4.0.0 |
657 | 657 | */ |
658 | 658 | public function ajax_clear_cart() { |
659 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
659 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
660 | 660 | |
661 | 661 | WC()->cart->empty_cart(); |
662 | 662 | exit; |
@@ -666,10 +666,10 @@ discard block |
||
666 | 666 | * Get cart details. |
667 | 667 | */ |
668 | 668 | public function ajax_get_cart_details() { |
669 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
669 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
670 | 670 | |
671 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
672 | - define( 'WOOCOMMERCE_CART', true ); |
|
671 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
672 | + define('WOOCOMMERCE_CART', true); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | WC()->cart->calculate_totals(); |
@@ -680,14 +680,14 @@ discard block |
||
680 | 680 | $data = array( |
681 | 681 | 'shipping_required' => WC()->cart->needs_shipping(), |
682 | 682 | 'order_data' => array( |
683 | - 'currency' => strtolower( $currency ), |
|
684 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
683 | + 'currency' => strtolower($currency), |
|
684 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
685 | 685 | ), |
686 | 686 | ); |
687 | 687 | |
688 | 688 | $data['order_data'] += $this->build_display_items(); |
689 | 689 | |
690 | - wp_send_json( $data ); |
|
690 | + wp_send_json($data); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | /** |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | * @see WC_Shipping::get_packages(). |
699 | 699 | */ |
700 | 700 | public function ajax_get_shipping_options() { |
701 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
701 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
702 | 702 | |
703 | 703 | try { |
704 | 704 | // Set the shipping package. |
@@ -714,34 +714,34 @@ discard block |
||
714 | 714 | ) |
715 | 715 | ); |
716 | 716 | |
717 | - $this->calculate_shipping( apply_filters( 'wc_stripe_payment_request_shipping_posted_values', $posted ) ); |
|
717 | + $this->calculate_shipping(apply_filters('wc_stripe_payment_request_shipping_posted_values', $posted)); |
|
718 | 718 | |
719 | 719 | // Set the shipping options. |
720 | 720 | $data = array(); |
721 | 721 | $packages = WC()->shipping->get_packages(); |
722 | 722 | |
723 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
724 | - foreach ( $packages as $package_key => $package ) { |
|
725 | - if ( empty( $package['rates'] ) ) { |
|
726 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
723 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
724 | + foreach ($packages as $package_key => $package) { |
|
725 | + if (empty($package['rates'])) { |
|
726 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
727 | 727 | } |
728 | 728 | |
729 | - foreach ( $package['rates'] as $key => $rate ) { |
|
729 | + foreach ($package['rates'] as $key => $rate) { |
|
730 | 730 | $data['shipping_options'][] = array( |
731 | 731 | 'id' => $rate->id, |
732 | 732 | 'label' => $rate->label, |
733 | 733 | 'detail' => '', |
734 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
734 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
735 | 735 | ); |
736 | 736 | } |
737 | 737 | } |
738 | 738 | } else { |
739 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
739 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
740 | 740 | } |
741 | 741 | |
742 | - if ( isset( $data[0] ) ) { |
|
742 | + if (isset($data[0])) { |
|
743 | 743 | // Auto select the first shipping method. |
744 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
744 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | WC()->cart->calculate_totals(); |
@@ -749,12 +749,12 @@ discard block |
||
749 | 749 | $data += $this->build_display_items(); |
750 | 750 | $data['result'] = 'success'; |
751 | 751 | |
752 | - wp_send_json( $data ); |
|
753 | - } catch ( Exception $e ) { |
|
752 | + wp_send_json($data); |
|
753 | + } catch (Exception $e) { |
|
754 | 754 | $data += $this->build_display_items(); |
755 | 755 | $data['result'] = 'invalid_shipping_address'; |
756 | 756 | |
757 | - wp_send_json( $data ); |
|
757 | + wp_send_json($data); |
|
758 | 758 | } |
759 | 759 | } |
760 | 760 | |
@@ -762,22 +762,22 @@ discard block |
||
762 | 762 | * Update shipping method. |
763 | 763 | */ |
764 | 764 | public function ajax_update_shipping_method() { |
765 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
765 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
766 | 766 | |
767 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
768 | - define( 'WOOCOMMERCE_CART', true ); |
|
767 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
768 | + define('WOOCOMMERCE_CART', true); |
|
769 | 769 | } |
770 | 770 | |
771 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
772 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
771 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
772 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
773 | 773 | |
774 | - if ( is_array( $shipping_method ) ) { |
|
775 | - foreach ( $shipping_method as $i => $value ) { |
|
776 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
774 | + if (is_array($shipping_method)) { |
|
775 | + foreach ($shipping_method as $i => $value) { |
|
776 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
777 | 777 | } |
778 | 778 | } |
779 | 779 | |
780 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
780 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
781 | 781 | |
782 | 782 | WC()->cart->calculate_totals(); |
783 | 783 | |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | $data += $this->build_display_items(); |
786 | 786 | $data['result'] = 'success'; |
787 | 787 | |
788 | - wp_send_json( $data ); |
|
788 | + wp_send_json($data); |
|
789 | 789 | } |
790 | 790 | |
791 | 791 | /** |
@@ -796,42 +796,42 @@ discard block |
||
796 | 796 | * @return array $data |
797 | 797 | */ |
798 | 798 | public function ajax_get_selected_product_data() { |
799 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
799 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
800 | 800 | |
801 | 801 | try { |
802 | - $product_id = absint( $_POST['product_id'] ); |
|
803 | - $qty = ! isset( $_POST['qty'] ) ? 1 : apply_filters( 'woocommerce_add_to_cart_quantity', absint( $_POST['qty'] ), $product_id ); |
|
804 | - $product = wc_get_product( $product_id ); |
|
802 | + $product_id = absint($_POST['product_id']); |
|
803 | + $qty = ! isset($_POST['qty']) ? 1 : apply_filters('woocommerce_add_to_cart_quantity', absint($_POST['qty']), $product_id); |
|
804 | + $product = wc_get_product($product_id); |
|
805 | 805 | $variation_id = null; |
806 | 806 | |
807 | - if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
808 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
807 | + if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
808 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
809 | 809 | |
810 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
811 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
810 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
811 | + $variation_id = $product->get_matching_variation($attributes); |
|
812 | 812 | } else { |
813 | - $data_store = WC_Data_Store::load( 'product' ); |
|
814 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
813 | + $data_store = WC_Data_Store::load('product'); |
|
814 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
815 | 815 | } |
816 | 816 | |
817 | - if ( ! empty( $variation_id ) ) { |
|
818 | - $product = wc_get_product( $variation_id ); |
|
817 | + if ( ! empty($variation_id)) { |
|
818 | + $product = wc_get_product($variation_id); |
|
819 | 819 | } |
820 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) { |
|
821 | - $product = wc_get_product( $product_id ); |
|
820 | + } elseif ('simple' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) { |
|
821 | + $product = wc_get_product($product_id); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | // Force quantity to 1 if sold individually and check for existing item in cart. |
825 | - if ( $product->is_sold_individually() ) { |
|
826 | - $qty = apply_filters( 'wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id ); |
|
825 | + if ($product->is_sold_individually()) { |
|
826 | + $qty = apply_filters('wc_stripe_payment_request_add_to_cart_sold_individually_quantity', 1, $qty, $product_id, $variation_id); |
|
827 | 827 | } |
828 | 828 | |
829 | - if ( ! $product->has_enough_stock( $qty ) ) { |
|
829 | + if ( ! $product->has_enough_stock($qty)) { |
|
830 | 830 | /* translators: 1: product name 2: quantity in stock */ |
831 | - throw new Exception( sprintf( __( 'You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe' ), $product->get_name(), wc_format_stock_quantity_for_display( $product->get_stock_quantity(), $product ) ) ); |
|
831 | + throw new Exception(sprintf(__('You cannot add that amount of "%1$s"; to the cart because there is not enough stock (%2$s remaining).', 'woocommerce-gateway-stripe'), $product->get_name(), wc_format_stock_quantity_for_display($product->get_stock_quantity(), $product))); |
|
832 | 832 | } |
833 | 833 | |
834 | - $total = $qty * ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->price : $product->get_price() ); |
|
834 | + $total = $qty * (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->price : $product->get_price()); |
|
835 | 835 | |
836 | 836 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
837 | 837 | |
@@ -839,28 +839,28 @@ discard block |
||
839 | 839 | $items = array(); |
840 | 840 | |
841 | 841 | $items[] = array( |
842 | - 'label' => ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->name : $product->get_name() ) . $quantity_label, |
|
843 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
842 | + 'label' => (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->name : $product->get_name()) . $quantity_label, |
|
843 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
844 | 844 | ); |
845 | 845 | |
846 | - if ( wc_tax_enabled() ) { |
|
846 | + if (wc_tax_enabled()) { |
|
847 | 847 | $items[] = array( |
848 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
848 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
849 | 849 | 'amount' => 0, |
850 | 850 | 'pending' => true, |
851 | 851 | ); |
852 | 852 | } |
853 | 853 | |
854 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
854 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
855 | 855 | $items[] = array( |
856 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
856 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
857 | 857 | 'amount' => 0, |
858 | 858 | 'pending' => true, |
859 | 859 | ); |
860 | 860 | |
861 | 861 | $data['shippingOptions'] = array( |
862 | 862 | 'id' => 'pending', |
863 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
863 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
864 | 864 | 'detail' => '', |
865 | 865 | 'amount' => 0, |
866 | 866 | ); |
@@ -869,17 +869,17 @@ discard block |
||
869 | 869 | $data['displayItems'] = $items; |
870 | 870 | $data['total'] = array( |
871 | 871 | 'label' => $this->total_label, |
872 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
872 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
873 | 873 | 'pending' => true, |
874 | 874 | ); |
875 | 875 | |
876 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
877 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
878 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
876 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
877 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
878 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
879 | 879 | |
880 | - wp_send_json( $data ); |
|
881 | - } catch ( Exception $e ) { |
|
882 | - wp_send_json( array( 'error' => wp_strip_all_tags( $e->getMessage() ) ) ); |
|
880 | + wp_send_json($data); |
|
881 | + } catch (Exception $e) { |
|
882 | + wp_send_json(array('error' => wp_strip_all_tags($e->getMessage()))); |
|
883 | 883 | } |
884 | 884 | } |
885 | 885 | |
@@ -891,36 +891,36 @@ discard block |
||
891 | 891 | * @return array $data |
892 | 892 | */ |
893 | 893 | public function ajax_add_to_cart() { |
894 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
894 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
895 | 895 | |
896 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
897 | - define( 'WOOCOMMERCE_CART', true ); |
|
896 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
897 | + define('WOOCOMMERCE_CART', true); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | WC()->shipping->reset_shipping(); |
901 | 901 | |
902 | - $product_id = absint( $_POST['product_id'] ); |
|
903 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
904 | - $product = wc_get_product( $product_id ); |
|
902 | + $product_id = absint($_POST['product_id']); |
|
903 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
904 | + $product = wc_get_product($product_id); |
|
905 | 905 | |
906 | 906 | // First empty the cart to prevent wrong calculation. |
907 | 907 | WC()->cart->empty_cart(); |
908 | 908 | |
909 | - if ( 'variable' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
910 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
909 | + if ('variable' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
910 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
911 | 911 | |
912 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
913 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
912 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
913 | + $variation_id = $product->get_matching_variation($attributes); |
|
914 | 914 | } else { |
915 | - $data_store = WC_Data_Store::load( 'product' ); |
|
916 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
915 | + $data_store = WC_Data_Store::load('product'); |
|
916 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
917 | 917 | } |
918 | 918 | |
919 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
919 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
920 | 920 | } |
921 | 921 | |
922 | - if ( 'simple' === ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $product->product_type : $product->get_type() ) ) { |
|
923 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
922 | + if ('simple' === (WC_Stripe_Helper::is_wc_lt('3.0') ? $product->product_type : $product->get_type())) { |
|
923 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
924 | 924 | } |
925 | 925 | |
926 | 926 | WC()->cart->calculate_totals(); |
@@ -929,7 +929,7 @@ discard block |
||
929 | 929 | $data += $this->build_display_items(); |
930 | 930 | $data['result'] = 'success'; |
931 | 931 | |
932 | - wp_send_json( $data ); |
|
932 | + wp_send_json($data); |
|
933 | 933 | } |
934 | 934 | |
935 | 935 | /** |
@@ -942,31 +942,31 @@ discard block |
||
942 | 942 | * @version 4.0.0 |
943 | 943 | */ |
944 | 944 | public function normalize_state() { |
945 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
946 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
947 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
948 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
945 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
946 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
947 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
948 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
949 | 949 | |
950 | - if ( $billing_state && $billing_country ) { |
|
951 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
950 | + if ($billing_state && $billing_country) { |
|
951 | + $valid_states = WC()->countries->get_states($billing_country); |
|
952 | 952 | |
953 | 953 | // Valid states found for country. |
954 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
955 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
956 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
954 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
955 | + foreach ($valid_states as $state_abbr => $state) { |
|
956 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
957 | 957 | $_POST['billing_state'] = $state_abbr; |
958 | 958 | } |
959 | 959 | } |
960 | 960 | } |
961 | 961 | } |
962 | 962 | |
963 | - if ( $shipping_state && $shipping_country ) { |
|
964 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
963 | + if ($shipping_state && $shipping_country) { |
|
964 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
965 | 965 | |
966 | 966 | // Valid states found for country. |
967 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
968 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
969 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
967 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
968 | + foreach ($valid_states as $state_abbr => $state) { |
|
969 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
970 | 970 | $_POST['shipping_state'] = $state_abbr; |
971 | 971 | } |
972 | 972 | } |
@@ -981,19 +981,19 @@ discard block |
||
981 | 981 | * @version 4.0.0 |
982 | 982 | */ |
983 | 983 | public function ajax_create_order() { |
984 | - if ( WC()->cart->is_empty() ) { |
|
985 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
984 | + if (WC()->cart->is_empty()) { |
|
985 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
986 | 986 | } |
987 | 987 | |
988 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
989 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
988 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
989 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | $this->normalize_state(); |
993 | 993 | |
994 | 994 | WC()->checkout()->process_checkout(); |
995 | 995 | |
996 | - die( 0 ); |
|
996 | + die(0); |
|
997 | 997 | } |
998 | 998 | |
999 | 999 | /** |
@@ -1003,41 +1003,41 @@ discard block |
||
1003 | 1003 | * @version 4.0.0 |
1004 | 1004 | * @param array $address |
1005 | 1005 | */ |
1006 | - protected function calculate_shipping( $address = array() ) { |
|
1006 | + protected function calculate_shipping($address = array()) { |
|
1007 | 1007 | $country = $address['country']; |
1008 | 1008 | $state = $address['state']; |
1009 | 1009 | $postcode = $address['postcode']; |
1010 | 1010 | $city = $address['city']; |
1011 | 1011 | $address_1 = $address['address']; |
1012 | 1012 | $address_2 = $address['address_2']; |
1013 | - $wc_states = WC()->countries->get_states( $country ); |
|
1013 | + $wc_states = WC()->countries->get_states($country); |
|
1014 | 1014 | |
1015 | 1015 | /** |
1016 | 1016 | * In some versions of Chrome, state can be a full name. So we need |
1017 | 1017 | * to convert that to abbreviation as WC is expecting that. |
1018 | 1018 | */ |
1019 | - if ( 2 < strlen( $state ) && ! empty( $wc_states ) ) { |
|
1020 | - $state = array_search( ucwords( strtolower( $state ) ), $wc_states, true ); |
|
1019 | + if (2 < strlen($state) && ! empty($wc_states)) { |
|
1020 | + $state = array_search(ucwords(strtolower($state)), $wc_states, true); |
|
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | WC()->shipping->reset_shipping(); |
1024 | 1024 | |
1025 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
1026 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
1025 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
1026 | + $postcode = wc_format_postcode($postcode, $country); |
|
1027 | 1027 | } |
1028 | 1028 | |
1029 | - if ( $country ) { |
|
1030 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
1031 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
1029 | + if ($country) { |
|
1030 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
1031 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
1032 | 1032 | } else { |
1033 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
|
1034 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
|
1033 | + WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
|
1034 | + WC_Stripe_Helper::is_wc_lt('3.0') ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
|
1035 | 1035 | } |
1036 | 1036 | |
1037 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
1038 | - WC()->customer->calculated_shipping( true ); |
|
1037 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
1038 | + WC()->customer->calculated_shipping(true); |
|
1039 | 1039 | } else { |
1040 | - WC()->customer->set_calculated_shipping( true ); |
|
1040 | + WC()->customer->set_calculated_shipping(true); |
|
1041 | 1041 | WC()->customer->save(); |
1042 | 1042 | } |
1043 | 1043 | |
@@ -1054,17 +1054,17 @@ discard block |
||
1054 | 1054 | $packages[0]['destination']['address'] = $address_1; |
1055 | 1055 | $packages[0]['destination']['address_2'] = $address_2; |
1056 | 1056 | |
1057 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
1058 | - if ( $item['data']->needs_shipping() ) { |
|
1059 | - if ( isset( $item['line_total'] ) ) { |
|
1057 | + foreach (WC()->cart->get_cart() as $item) { |
|
1058 | + if ($item['data']->needs_shipping()) { |
|
1059 | + if (isset($item['line_total'])) { |
|
1060 | 1060 | $packages[0]['contents_cost'] += $item['line_total']; |
1061 | 1061 | } |
1062 | 1062 | } |
1063 | 1063 | } |
1064 | 1064 | |
1065 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
1065 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
1066 | 1066 | |
1067 | - WC()->shipping->calculate_shipping( $packages ); |
|
1067 | + WC()->shipping->calculate_shipping($packages); |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | /** |
@@ -1073,19 +1073,19 @@ discard block |
||
1073 | 1073 | * @since 3.1.0 |
1074 | 1074 | * @version 4.0.0 |
1075 | 1075 | */ |
1076 | - protected function build_shipping_methods( $shipping_methods ) { |
|
1077 | - if ( empty( $shipping_methods ) ) { |
|
1076 | + protected function build_shipping_methods($shipping_methods) { |
|
1077 | + if (empty($shipping_methods)) { |
|
1078 | 1078 | return array(); |
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | $shipping = array(); |
1082 | 1082 | |
1083 | - foreach ( $shipping_methods as $method ) { |
|
1083 | + foreach ($shipping_methods as $method) { |
|
1084 | 1084 | $shipping[] = array( |
1085 | 1085 | 'id' => $method['id'], |
1086 | 1086 | 'label' => $method['label'], |
1087 | 1087 | 'detail' => '', |
1088 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1088 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1089 | 1089 | ); |
1090 | 1090 | } |
1091 | 1091 | |
@@ -1099,8 +1099,8 @@ discard block |
||
1099 | 1099 | * @version 4.0.0 |
1100 | 1100 | */ |
1101 | 1101 | protected function build_display_items() { |
1102 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1103 | - define( 'WOOCOMMERCE_CART', true ); |
|
1102 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1103 | + define('WOOCOMMERCE_CART', true); |
|
1104 | 1104 | } |
1105 | 1105 | |
1106 | 1106 | $items = array(); |
@@ -1108,71 +1108,71 @@ discard block |
||
1108 | 1108 | $discounts = 0; |
1109 | 1109 | |
1110 | 1110 | // Default show only subtotal instead of itemization. |
1111 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1112 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1111 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1112 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1113 | 1113 | $amount = $cart_item['line_subtotal']; |
1114 | 1114 | $subtotal += $cart_item['line_subtotal']; |
1115 | 1115 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1116 | 1116 | |
1117 | - $product_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
1117 | + $product_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
|
1118 | 1118 | |
1119 | 1119 | $item = array( |
1120 | 1120 | 'label' => $product_name . $quantity_label, |
1121 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1121 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1122 | 1122 | ); |
1123 | 1123 | |
1124 | 1124 | $items[] = $item; |
1125 | 1125 | } |
1126 | 1126 | } |
1127 | 1127 | |
1128 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1129 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1128 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1129 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1130 | 1130 | } else { |
1131 | - $applied_coupons = array_values( WC()->cart->get_coupon_discount_totals() ); |
|
1131 | + $applied_coupons = array_values(WC()->cart->get_coupon_discount_totals()); |
|
1132 | 1132 | |
1133 | - foreach ( $applied_coupons as $amount ) { |
|
1133 | + foreach ($applied_coupons as $amount) { |
|
1134 | 1134 | $discounts += (float) $amount; |
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | |
1138 | - $discounts = wc_format_decimal( $discounts, WC()->cart->dp ); |
|
1139 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1140 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1141 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1142 | - $order_total = version_compare( WC_VERSION, '3.2', '<' ) ? wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ) : WC()->cart->get_total( false ); |
|
1138 | + $discounts = wc_format_decimal($discounts, WC()->cart->dp); |
|
1139 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1140 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1141 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1142 | + $order_total = version_compare(WC_VERSION, '3.2', '<') ? wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp) : WC()->cart->get_total(false); |
|
1143 | 1143 | |
1144 | - if ( wc_tax_enabled() ) { |
|
1144 | + if (wc_tax_enabled()) { |
|
1145 | 1145 | $items[] = array( |
1146 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1147 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1146 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1147 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1148 | 1148 | ); |
1149 | 1149 | } |
1150 | 1150 | |
1151 | - if ( WC()->cart->needs_shipping() ) { |
|
1151 | + if (WC()->cart->needs_shipping()) { |
|
1152 | 1152 | $items[] = array( |
1153 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1154 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1153 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1154 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1155 | 1155 | ); |
1156 | 1156 | } |
1157 | 1157 | |
1158 | - if ( WC()->cart->has_discount() ) { |
|
1158 | + if (WC()->cart->has_discount()) { |
|
1159 | 1159 | $items[] = array( |
1160 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1161 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1160 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1161 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1162 | 1162 | ); |
1163 | 1163 | } |
1164 | 1164 | |
1165 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1165 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1166 | 1166 | $cart_fees = WC()->cart->fees; |
1167 | 1167 | } else { |
1168 | 1168 | $cart_fees = WC()->cart->get_fees(); |
1169 | 1169 | } |
1170 | 1170 | |
1171 | 1171 | // Include fees and taxes as display items. |
1172 | - foreach ( $cart_fees as $key => $fee ) { |
|
1172 | + foreach ($cart_fees as $key => $fee) { |
|
1173 | 1173 | $items[] = array( |
1174 | 1174 | 'label' => $fee->name, |
1175 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1175 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1176 | 1176 | ); |
1177 | 1177 | } |
1178 | 1178 | |
@@ -1180,7 +1180,7 @@ discard block |
||
1180 | 1180 | 'displayItems' => $items, |
1181 | 1181 | 'total' => array( |
1182 | 1182 | 'label' => $this->total_label, |
1183 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1183 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1184 | 1184 | 'pending' => false, |
1185 | 1185 | ), |
1186 | 1186 | ); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * Displays the admin settings webhook description. |
16 | 16 | * |
17 | 17 | * @since 4.1.0 |
18 | - * @return mixed |
|
18 | + * @return string |
|
19 | 19 | */ |
20 | 20 | public function display_admin_settings_webhook_description() { |
21 | 21 | /* translators: 1) webhook url */ |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * Checks if card is 3DS. |
580 | 580 | * |
581 | 581 | * @since 4.0.4 |
582 | - * @param object $source_object |
|
582 | + * @param stdClass $source_object |
|
583 | 583 | * @return bool |
584 | 584 | */ |
585 | 585 | public function is_3ds_card( $source_object ) { |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | * |
603 | 603 | * @since 4.0.8 |
604 | 604 | * @param string $source_id |
605 | - * @return bool |
|
605 | + * @return integer |
|
606 | 606 | */ |
607 | 607 | public function is_type_legacy_card( $source_id ) { |
608 | 608 | return ( preg_match( '/^card_/', $source_id ) ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function display_admin_settings_webhook_description() { |
23 | 23 | /* translators: 1) webhook url */ |
24 | - return sprintf( __( 'You must add the following webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), WC_Stripe_Helper::get_webhook_url() ); |
|
24 | + return sprintf(__('You must add the following webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Stripe account settings</a>. This will enable you to receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), WC_Stripe_Helper::get_webhook_url()); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | <input id="wc-%1$s-new-payment-method" name="wc-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" /> |
36 | 36 | <label for="wc-%1$s-new-payment-method" style="display:inline;">%2$s</label> |
37 | 37 | </p>', |
38 | - esc_attr( $this->id ), |
|
39 | - esc_html( apply_filters( 'wc_stripe_save_to_account_text', __( 'Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe' ) ) ) |
|
38 | + esc_attr($this->id), |
|
39 | + esc_html(apply_filters('wc_stripe_save_to_account_text', __('Save payment information to my account for future purchases.', 'woocommerce-gateway-stripe'))) |
|
40 | 40 | ); |
41 | 41 | } |
42 | 42 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @since 4.0.5 |
48 | 48 | * @param array $error |
49 | 49 | */ |
50 | - public function is_retryable_error( $error ) { |
|
50 | + public function is_retryable_error($error) { |
|
51 | 51 | return ( |
52 | 52 | 'invalid_request_error' === $error->type || |
53 | 53 | 'idempotency_error' === $error->type || |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | * @since 4.1.0 |
65 | 65 | * @param array $error |
66 | 66 | */ |
67 | - public function is_same_idempotency_error( $error ) { |
|
67 | + public function is_same_idempotency_error($error) { |
|
68 | 68 | return ( |
69 | 69 | $error && |
70 | 70 | 'idempotency_error' === $error->type && |
71 | - preg_match( '/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message ) |
|
71 | + preg_match('/Keys for idempotent requests can only be used with the same parameters they were first used with./i', $error->message) |
|
72 | 72 | ); |
73 | 73 | } |
74 | 74 | |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | * @since 4.1.0 |
80 | 80 | * @param array $error |
81 | 81 | */ |
82 | - public function is_source_already_consumed_error( $error ) { |
|
82 | + public function is_source_already_consumed_error($error) { |
|
83 | 83 | return ( |
84 | 84 | $error && |
85 | 85 | 'invalid_request_error' === $error->type && |
86 | - preg_match( '/The reusable source you provided is consumed because it was previously charged without being attached to a customer or was detached from a customer. To charge a reusable source multiple time you must attach it to a customer first./i', $error->message ) |
|
86 | + preg_match('/The reusable source you provided is consumed because it was previously charged without being attached to a customer or was detached from a customer. To charge a reusable source multiple time you must attach it to a customer first./i', $error->message) |
|
87 | 87 | ); |
88 | 88 | } |
89 | 89 | |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | * @since 4.1.0 |
95 | 95 | * @param array $error |
96 | 96 | */ |
97 | - public function is_no_such_customer_error( $error ) { |
|
97 | + public function is_no_such_customer_error($error) { |
|
98 | 98 | return ( |
99 | 99 | $error && |
100 | 100 | 'invalid_request_error' === $error->type && |
101 | - preg_match( '/No such customer/i', $error->message ) |
|
101 | + preg_match('/No such customer/i', $error->message) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | * @since 4.1.0 |
110 | 110 | * @param array $error |
111 | 111 | */ |
112 | - public function is_no_such_token_error( $error ) { |
|
112 | + public function is_no_such_token_error($error) { |
|
113 | 113 | return ( |
114 | 114 | $error && |
115 | 115 | 'invalid_request_error' === $error->type && |
116 | - preg_match( '/No such token/i', $error->message ) |
|
116 | + preg_match('/No such token/i', $error->message) |
|
117 | 117 | ); |
118 | 118 | } |
119 | 119 | |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | * @since 4.1.0 |
125 | 125 | * @param array $error |
126 | 126 | */ |
127 | - public function is_no_such_source_error( $error ) { |
|
127 | + public function is_no_such_source_error($error) { |
|
128 | 128 | return ( |
129 | 129 | $error && |
130 | 130 | 'invalid_request_error' === $error->type && |
131 | - preg_match( '/No such source/i', $error->message ) |
|
131 | + preg_match('/No such source/i', $error->message) |
|
132 | 132 | ); |
133 | 133 | } |
134 | 134 | |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | * @since 4.1.0 |
140 | 140 | * @param array $error |
141 | 141 | */ |
142 | - public function is_no_linked_source_error( $error ) { |
|
142 | + public function is_no_linked_source_error($error) { |
|
143 | 143 | return ( |
144 | 144 | $error && |
145 | 145 | 'invalid_request_error' === $error->type && |
146 | - preg_match( '/does not have a linked source with ID/i', $error->message ) |
|
146 | + preg_match('/does not have a linked source with ID/i', $error->message) |
|
147 | 147 | ); |
148 | 148 | } |
149 | 149 | |
@@ -156,13 +156,13 @@ discard block |
||
156 | 156 | * @param object $error |
157 | 157 | * @return bool |
158 | 158 | */ |
159 | - public function need_update_idempotency_key( $source_object, $error ) { |
|
159 | + public function need_update_idempotency_key($source_object, $error) { |
|
160 | 160 | return ( |
161 | 161 | $error && |
162 | 162 | 1 < $this->retry_interval && |
163 | - ! empty( $source_object ) && |
|
163 | + ! empty($source_object) && |
|
164 | 164 | 'chargeable' === $source_object->status && |
165 | - self::is_same_idempotency_error( $error ) |
|
165 | + self::is_same_idempotency_error($error) |
|
166 | 166 | ); |
167 | 167 | } |
168 | 168 | |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * @since 4.1.3 |
173 | 173 | */ |
174 | 174 | public function is_available() { |
175 | - if ( 'yes' === $this->enabled ) { |
|
176 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
175 | + if ('yes' === $this->enabled) { |
|
176 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | return true; |
@@ -190,12 +190,12 @@ discard block |
||
190 | 190 | * @param int $order_id |
191 | 191 | * @return bool |
192 | 192 | */ |
193 | - public function maybe_process_pre_orders( $order_id ) { |
|
193 | + public function maybe_process_pre_orders($order_id) { |
|
194 | 194 | return ( |
195 | 195 | WC_Stripe_Helper::is_pre_orders_exists() && |
196 | - $this->pre_orders->is_pre_order( $order_id ) && |
|
197 | - WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) && |
|
198 | - ! is_wc_endpoint_url( 'order-pay' ) |
|
196 | + $this->pre_orders->is_pre_order($order_id) && |
|
197 | + WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id) && |
|
198 | + ! is_wc_endpoint_url('order-pay') |
|
199 | 199 | ); |
200 | 200 | } |
201 | 201 | |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | * @since 1.0.0 |
206 | 206 | * @version 4.0.0 |
207 | 207 | */ |
208 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
209 | - $this->notices[ $slug ] = array( |
|
208 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
209 | + $this->notices[$slug] = array( |
|
210 | 210 | 'class' => $class, |
211 | 211 | 'message' => $message, |
212 | 212 | 'dismissible' => $dismissible, |
@@ -253,10 +253,10 @@ discard block |
||
253 | 253 | * @version 4.0.0 |
254 | 254 | * @param object $order |
255 | 255 | */ |
256 | - public function validate_minimum_order_amount( $order ) { |
|
257 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
256 | + public function validate_minimum_order_amount($order) { |
|
257 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
258 | 258 | /* translators: 1) dollar amount */ |
259 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
259 | + throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | * @since 4.0.0 |
267 | 267 | * @version 4.0.0 |
268 | 268 | */ |
269 | - public function get_transaction_url( $order ) { |
|
270 | - if ( $this->testmode ) { |
|
269 | + public function get_transaction_url($order) { |
|
270 | + if ($this->testmode) { |
|
271 | 271 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
272 | 272 | } else { |
273 | 273 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
274 | 274 | } |
275 | 275 | |
276 | - return parent::get_transaction_url( $order ); |
|
276 | + return parent::get_transaction_url($order); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -282,15 +282,15 @@ discard block |
||
282 | 282 | * @since 4.0.0 |
283 | 283 | * @version 4.0.0 |
284 | 284 | */ |
285 | - public function get_stripe_customer_id( $order ) { |
|
286 | - $customer = get_user_meta( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
285 | + public function get_stripe_customer_id($order) { |
|
286 | + $customer = get_user_meta(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
287 | 287 | |
288 | - if ( empty( $customer ) ) { |
|
288 | + if (empty($customer)) { |
|
289 | 289 | // Try to get it via the order. |
290 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
291 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
290 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
291 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
292 | 292 | } else { |
293 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
293 | + return $order->get_meta('_stripe_customer_id', true); |
|
294 | 294 | } |
295 | 295 | } else { |
296 | 296 | return $customer; |
@@ -307,23 +307,23 @@ discard block |
||
307 | 307 | * @param object $order |
308 | 308 | * @param int $id Stripe session id. |
309 | 309 | */ |
310 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
311 | - if ( is_object( $order ) ) { |
|
312 | - if ( empty( $id ) ) { |
|
310 | + public function get_stripe_return_url($order = null, $id = null) { |
|
311 | + if (is_object($order)) { |
|
312 | + if (empty($id)) { |
|
313 | 313 | $id = uniqid(); |
314 | 314 | } |
315 | 315 | |
316 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
316 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
317 | 317 | |
318 | 318 | $args = array( |
319 | 319 | 'utm_nooverride' => '1', |
320 | 320 | 'order_id' => $order_id, |
321 | 321 | ); |
322 | 322 | |
323 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
323 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
324 | 324 | } |
325 | 325 | |
326 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
326 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -331,8 +331,8 @@ discard block |
||
331 | 331 | * @param int $order_id |
332 | 332 | * @return boolean |
333 | 333 | */ |
334 | - public function has_subscription( $order_id ) { |
|
335 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
334 | + public function has_subscription($order_id) { |
|
335 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -344,34 +344,33 @@ discard block |
||
344 | 344 | * @param object $prepared_source |
345 | 345 | * @return array() |
346 | 346 | */ |
347 | - public function generate_payment_request( $order, $prepared_source ) { |
|
348 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
349 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
350 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
347 | + public function generate_payment_request($order, $prepared_source) { |
|
348 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
349 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
350 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
351 | 351 | $post_data = array(); |
352 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
353 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
352 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()); |
|
353 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
354 | 354 | /* translators: 1) blog name 2) order number */ |
355 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
356 | - $billing_email = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email(); |
|
357 | - $billing_first_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
358 | - $billing_last_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
355 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
356 | + $billing_email = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email(); |
|
357 | + $billing_first_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
358 | + $billing_last_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
359 | 359 | |
360 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
360 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
361 | 361 | $post_data['receipt_email'] = $billing_email; |
362 | 362 | } |
363 | 363 | |
364 | - switch ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method() ) { |
|
365 | - case 'stripe': |
|
366 | - if ( ! empty( $statement_descriptor ) ) { |
|
367 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
364 | + switch (WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method()) { |
|
365 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
366 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
368 | 367 | } |
369 | 368 | |
370 | 369 | $post_data['capture'] = $capture ? 'true' : 'false'; |
371 | 370 | break; |
372 | 371 | case 'stripe_sepa': |
373 | - if ( ! empty( $statement_descriptor ) ) { |
|
374 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
372 | + if ( ! empty($statement_descriptor)) { |
|
373 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
375 | 374 | } |
376 | 375 | break; |
377 | 376 | } |
@@ -379,25 +378,25 @@ discard block |
||
379 | 378 | $post_data['expand[]'] = 'balance_transaction'; |
380 | 379 | |
381 | 380 | $metadata = array( |
382 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
383 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
381 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
382 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
384 | 383 | 'order_id' => $order->get_order_number(), |
385 | 384 | ); |
386 | 385 | |
387 | - if ( $this->has_subscription( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id() ) ) { |
|
386 | + if ($this->has_subscription(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id())) { |
|
388 | 387 | $metadata += array( |
389 | 388 | 'payment_type' => 'recurring', |
390 | - 'site_url' => esc_url( get_site_url() ), |
|
389 | + 'site_url' => esc_url(get_site_url()), |
|
391 | 390 | ); |
392 | 391 | } |
393 | 392 | |
394 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_source ); |
|
393 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $prepared_source); |
|
395 | 394 | |
396 | - if ( $prepared_source->customer ) { |
|
395 | + if ($prepared_source->customer) { |
|
397 | 396 | $post_data['customer'] = $prepared_source->customer; |
398 | 397 | } |
399 | 398 | |
400 | - if ( $prepared_source->source ) { |
|
399 | + if ($prepared_source->source) { |
|
401 | 400 | $post_data['source'] = $prepared_source->source; |
402 | 401 | } |
403 | 402 | |
@@ -409,83 +408,83 @@ discard block |
||
409 | 408 | * @param WC_Order $order |
410 | 409 | * @param object $source |
411 | 410 | */ |
412 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_source ); |
|
411 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $prepared_source); |
|
413 | 412 | } |
414 | 413 | |
415 | 414 | /** |
416 | 415 | * Store extra meta data for an order from a Stripe Response. |
417 | 416 | */ |
418 | - public function process_response( $response, $order ) { |
|
419 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
417 | + public function process_response($response, $order) { |
|
418 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
420 | 419 | |
421 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
420 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
422 | 421 | |
423 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
422 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
424 | 423 | |
425 | 424 | // Store charge data. |
426 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
425 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
427 | 426 | |
428 | 427 | // Store other data such as fees. |
429 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
428 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
430 | 429 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
431 | 430 | // values are in the local currency of the Stripe account, not from WC. |
432 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
433 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
434 | - WC_Stripe_Helper::update_stripe_fee( $order, $fee ); |
|
435 | - WC_Stripe_Helper::update_stripe_net( $order, $net ); |
|
431 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
432 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
433 | + WC_Stripe_Helper::update_stripe_fee($order, $fee); |
|
434 | + WC_Stripe_Helper::update_stripe_net($order, $net); |
|
436 | 435 | |
437 | 436 | // Store currency stripe. |
438 | - $currency = ! empty( $response->balance_transaction->currency ) ? strtoupper( $response->balance_transaction->currency ) : null; |
|
439 | - WC_Stripe_Helper::update_stripe_currency( $order, $currency ); |
|
437 | + $currency = ! empty($response->balance_transaction->currency) ? strtoupper($response->balance_transaction->currency) : null; |
|
438 | + WC_Stripe_Helper::update_stripe_currency($order, $currency); |
|
440 | 439 | } |
441 | 440 | |
442 | - if ( 'yes' === $captured ) { |
|
441 | + if ('yes' === $captured) { |
|
443 | 442 | /** |
444 | 443 | * Charge can be captured but in a pending state. Payment methods |
445 | 444 | * that are asynchronous may take couple days to clear. Webhook will |
446 | 445 | * take care of the status changes. |
447 | 446 | */ |
448 | - if ( 'pending' === $response->status ) { |
|
449 | - $order_stock_reduced = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_order_stock_reduced', true ) : $order->get_meta( '_order_stock_reduced', true ); |
|
447 | + if ('pending' === $response->status) { |
|
448 | + $order_stock_reduced = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_order_stock_reduced', true) : $order->get_meta('_order_stock_reduced', true); |
|
450 | 449 | |
451 | - if ( ! $order_stock_reduced ) { |
|
452 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
450 | + if ( ! $order_stock_reduced) { |
|
451 | + WC_Stripe_Helper::is_wc_lt('3.0') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
453 | 452 | } |
454 | 453 | |
455 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
454 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
456 | 455 | /* translators: transaction id */ |
457 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
456 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
458 | 457 | } |
459 | 458 | |
460 | - if ( 'succeeded' === $response->status ) { |
|
461 | - $order->payment_complete( $response->id ); |
|
459 | + if ('succeeded' === $response->status) { |
|
460 | + $order->payment_complete($response->id); |
|
462 | 461 | |
463 | 462 | /* translators: transaction id */ |
464 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
465 | - $order->add_order_note( $message ); |
|
463 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
464 | + $order->add_order_note($message); |
|
466 | 465 | } |
467 | 466 | |
468 | - if ( 'failed' === $response->status ) { |
|
469 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
470 | - $order->add_order_note( $localized_message ); |
|
471 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
467 | + if ('failed' === $response->status) { |
|
468 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
469 | + $order->add_order_note($localized_message); |
|
470 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
472 | 471 | } |
473 | 472 | } else { |
474 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
473 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
475 | 474 | |
476 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
477 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
475 | + if ($order->has_status(array('pending', 'failed'))) { |
|
476 | + WC_Stripe_Helper::is_wc_lt('3.0') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
478 | 477 | } |
479 | 478 | |
480 | 479 | /* translators: transaction id */ |
481 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
480 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
482 | 481 | } |
483 | 482 | |
484 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
483 | + if (is_callable(array($order, 'save'))) { |
|
485 | 484 | $order->save(); |
486 | 485 | } |
487 | 486 | |
488 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
487 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
489 | 488 | |
490 | 489 | return $response; |
491 | 490 | } |
@@ -498,10 +497,10 @@ discard block |
||
498 | 497 | * @param int $order_id |
499 | 498 | * @return null |
500 | 499 | */ |
501 | - public function send_failed_order_email( $order_id ) { |
|
500 | + public function send_failed_order_email($order_id) { |
|
502 | 501 | $emails = WC()->mailer()->get_emails(); |
503 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
504 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
502 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
503 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
505 | 504 | } |
506 | 505 | } |
507 | 506 | |
@@ -513,36 +512,36 @@ discard block |
||
513 | 512 | * @param object $order |
514 | 513 | * @return object $details |
515 | 514 | */ |
516 | - public function get_owner_details( $order ) { |
|
517 | - $billing_first_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
518 | - $billing_last_name = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
515 | + public function get_owner_details($order) { |
|
516 | + $billing_first_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
517 | + $billing_last_name = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
519 | 518 | |
520 | 519 | $details = array(); |
521 | 520 | |
522 | 521 | $name = $billing_first_name . ' ' . $billing_last_name; |
523 | - $email = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_email : $order->get_billing_email(); |
|
524 | - $phone = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_phone : $order->get_billing_phone(); |
|
522 | + $email = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_email : $order->get_billing_email(); |
|
523 | + $phone = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_phone : $order->get_billing_phone(); |
|
525 | 524 | |
526 | - if ( ! empty( $phone ) ) { |
|
525 | + if ( ! empty($phone)) { |
|
527 | 526 | $details['phone'] = $phone; |
528 | 527 | } |
529 | 528 | |
530 | - if ( ! empty( $name ) ) { |
|
529 | + if ( ! empty($name)) { |
|
531 | 530 | $details['name'] = $name; |
532 | 531 | } |
533 | 532 | |
534 | - if ( ! empty( $email ) ) { |
|
533 | + if ( ! empty($email)) { |
|
535 | 534 | $details['email'] = $email; |
536 | 535 | } |
537 | 536 | |
538 | - $details['address']['line1'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
539 | - $details['address']['line2'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
540 | - $details['address']['state'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_state : $order->get_billing_state(); |
|
541 | - $details['address']['city'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_city : $order->get_billing_city(); |
|
542 | - $details['address']['postal_code'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_postcode : $order->get_billing_postcode(); |
|
543 | - $details['address']['country'] = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_country : $order->get_billing_country(); |
|
537 | + $details['address']['line1'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
538 | + $details['address']['line2'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
539 | + $details['address']['state'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_state : $order->get_billing_state(); |
|
540 | + $details['address']['city'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_city : $order->get_billing_city(); |
|
541 | + $details['address']['postal_code'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_postcode : $order->get_billing_postcode(); |
|
542 | + $details['address']['country'] = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_country : $order->get_billing_country(); |
|
544 | 543 | |
545 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
544 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
546 | 545 | } |
547 | 546 | |
548 | 547 | /** |
@@ -551,15 +550,15 @@ discard block |
||
551 | 550 | * @since 4.0.3 |
552 | 551 | * @param string $source_id The source ID to get source object for. |
553 | 552 | */ |
554 | - public function get_source_object( $source_id = '' ) { |
|
555 | - if ( empty( $source_id ) ) { |
|
553 | + public function get_source_object($source_id = '') { |
|
554 | + if (empty($source_id)) { |
|
556 | 555 | return ''; |
557 | 556 | } |
558 | 557 | |
559 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
558 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
560 | 559 | |
561 | - if ( ! empty( $source_object->error ) ) { |
|
562 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
560 | + if ( ! empty($source_object->error)) { |
|
561 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
563 | 562 | } |
564 | 563 | |
565 | 564 | return $source_object; |
@@ -573,13 +572,13 @@ discard block |
||
573 | 572 | * @param object $source_object |
574 | 573 | * @return bool |
575 | 574 | */ |
576 | - public function is_3ds_required( $source_object ) { |
|
575 | + public function is_3ds_required($source_object) { |
|
577 | 576 | return apply_filters( |
578 | 577 | 'wc_stripe_require_3ds', |
579 | 578 | ( |
580 | - $source_object && ! empty( $source_object->card ) ) && |
|
581 | - ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
582 | - ( $this->three_d_secure && 'recommended' === $source_object->card->three_d_secure ) |
|
579 | + $source_object && ! empty($source_object->card) ) && |
|
580 | + ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
581 | + ($this->three_d_secure && 'recommended' === $source_object->card->three_d_secure) |
|
583 | 582 | ), |
584 | 583 | $source_object, |
585 | 584 | $this->three_d_secure |
@@ -593,8 +592,8 @@ discard block |
||
593 | 592 | * @param object $source_object |
594 | 593 | * @return bool |
595 | 594 | */ |
596 | - public function is_3ds_card( $source_object ) { |
|
597 | - return ( $source_object && 'three_d_secure' === $source_object->type ); |
|
595 | + public function is_3ds_card($source_object) { |
|
596 | + return ($source_object && 'three_d_secure' === $source_object->type); |
|
598 | 597 | } |
599 | 598 | |
600 | 599 | /** |
@@ -604,8 +603,8 @@ discard block |
||
604 | 603 | * @param object $source_object |
605 | 604 | * @return bool |
606 | 605 | */ |
607 | - public function is_prepaid_card( $source_object ) { |
|
608 | - return ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ); |
|
606 | + public function is_prepaid_card($source_object) { |
|
607 | + return ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding); |
|
609 | 608 | } |
610 | 609 | |
611 | 610 | /** |
@@ -615,8 +614,8 @@ discard block |
||
615 | 614 | * @param string $source_id |
616 | 615 | * @return bool |
617 | 616 | */ |
618 | - public function is_type_legacy_card( $source_id ) { |
|
619 | - return ( preg_match( '/^card_/', $source_id ) ); |
|
617 | + public function is_type_legacy_card($source_id) { |
|
618 | + return (preg_match('/^card_/', $source_id)); |
|
620 | 619 | } |
621 | 620 | |
622 | 621 | /** |
@@ -626,9 +625,9 @@ discard block |
||
626 | 625 | * @return bool |
627 | 626 | */ |
628 | 627 | public function is_using_saved_payment_method() { |
629 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
628 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
630 | 629 | |
631 | - return ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
630 | + return (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']); |
|
632 | 631 | } |
633 | 632 | |
634 | 633 | /** |
@@ -641,22 +640,22 @@ discard block |
||
641 | 640 | * @param string $return_url |
642 | 641 | * @return mixed |
643 | 642 | */ |
644 | - public function create_3ds_source( $order, $source_object, $return_url = '' ) { |
|
645 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
646 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
647 | - $return_url = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url; |
|
643 | + public function create_3ds_source($order, $source_object, $return_url = '') { |
|
644 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
645 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
646 | + $return_url = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url; |
|
648 | 647 | |
649 | 648 | $post_data = array(); |
650 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
651 | - $post_data['currency'] = strtolower( $currency ); |
|
649 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
650 | + $post_data['currency'] = strtolower($currency); |
|
652 | 651 | $post_data['type'] = 'three_d_secure'; |
653 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
654 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
655 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
652 | + $post_data['owner'] = $this->get_owner_details($order); |
|
653 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
654 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
656 | 655 | |
657 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' ); |
|
656 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source...'); |
|
658 | 657 | |
659 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' ); |
|
658 | + return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources'); |
|
660 | 659 | } |
661 | 660 | |
662 | 661 | /** |
@@ -672,61 +671,61 @@ discard block |
||
672 | 671 | * @throws Exception When card was not added or for and invalid card. |
673 | 672 | * @return object |
674 | 673 | */ |
675 | - public function prepare_source( $user_id, $force_save_source = false ) { |
|
676 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
674 | + public function prepare_source($user_id, $force_save_source = false) { |
|
675 | + $customer = new WC_Stripe_Customer($user_id); |
|
677 | 676 | $set_customer = true; |
678 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
677 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
679 | 678 | $source_object = ''; |
680 | 679 | $source_id = ''; |
681 | 680 | $wc_token_id = false; |
682 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
681 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
683 | 682 | $is_token = false; |
684 | 683 | |
685 | 684 | // New CC info was entered and we have a new source to process. |
686 | - if ( ! empty( $_POST['stripe_source'] ) ) { |
|
687 | - $source_object = self::get_source_object( wc_clean( $_POST['stripe_source'] ) ); |
|
685 | + if ( ! empty($_POST['stripe_source'])) { |
|
686 | + $source_object = self::get_source_object(wc_clean($_POST['stripe_source'])); |
|
688 | 687 | $source_id = $source_object->id; |
689 | 688 | |
690 | 689 | // This checks to see if customer opted to save the payment method to file. |
691 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
690 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
692 | 691 | |
693 | 692 | /** |
694 | 693 | * This is true if the user wants to store the card to their account. |
695 | 694 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
696 | 695 | * actually reusable. Either that or force_save_source is true. |
697 | 696 | */ |
698 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
699 | - $response = $customer->add_source( $source_object->id ); |
|
697 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
698 | + $response = $customer->add_source($source_object->id); |
|
700 | 699 | |
701 | - if ( ! empty( $response->error ) ) { |
|
702 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
700 | + if ( ! empty($response->error)) { |
|
701 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
703 | 702 | } |
704 | 703 | } |
705 | - } elseif ( $this->is_using_saved_payment_method() ) { |
|
704 | + } elseif ($this->is_using_saved_payment_method()) { |
|
706 | 705 | // Use an existing token, and then process the payment. |
707 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
708 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
706 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
707 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
709 | 708 | |
710 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
711 | - WC()->session->set( 'refresh_totals', true ); |
|
712 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
709 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
710 | + WC()->session->set('refresh_totals', true); |
|
711 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
713 | 712 | } |
714 | 713 | |
715 | 714 | $source_id = $wc_token->get_token(); |
716 | 715 | |
717 | - if ( $this->is_type_legacy_card( $source_id ) ) { |
|
716 | + if ($this->is_type_legacy_card($source_id)) { |
|
718 | 717 | $is_token = true; |
719 | 718 | } |
720 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
721 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
722 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
719 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
720 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
721 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
723 | 722 | |
724 | 723 | // This is true if the user wants to store the card to their account. |
725 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
726 | - $response = $customer->add_source( $stripe_token ); |
|
724 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
725 | + $response = $customer->add_source($stripe_token); |
|
727 | 726 | |
728 | - if ( ! empty( $response->error ) ) { |
|
729 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
727 | + if ( ! empty($response->error)) { |
|
728 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
730 | 729 | } |
731 | 730 | } else { |
732 | 731 | $set_customer = false; |
@@ -735,14 +734,14 @@ discard block |
||
735 | 734 | } |
736 | 735 | } |
737 | 736 | |
738 | - if ( ! $set_customer ) { |
|
737 | + if ( ! $set_customer) { |
|
739 | 738 | $customer_id = false; |
740 | 739 | } else { |
741 | 740 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
742 | 741 | } |
743 | 742 | |
744 | - if ( empty( $source_object ) && ! $is_token ) { |
|
745 | - $source_object = self::get_source_object( $source_id ); |
|
743 | + if (empty($source_object) && ! $is_token) { |
|
744 | + $source_object = self::get_source_object($source_id); |
|
746 | 745 | } |
747 | 746 | |
748 | 747 | return (object) array( |
@@ -766,39 +765,39 @@ discard block |
||
766 | 765 | * @param object $order |
767 | 766 | * @return object |
768 | 767 | */ |
769 | - public function prepare_order_source( $order = null ) { |
|
768 | + public function prepare_order_source($order = null) { |
|
770 | 769 | $stripe_customer = new WC_Stripe_Customer(); |
771 | 770 | $stripe_source = false; |
772 | 771 | $token_id = false; |
773 | 772 | $source_object = false; |
774 | 773 | |
775 | - if ( $order ) { |
|
776 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
774 | + if ($order) { |
|
775 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
777 | 776 | |
778 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
777 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
779 | 778 | |
780 | - if ( $stripe_customer_id ) { |
|
781 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
779 | + if ($stripe_customer_id) { |
|
780 | + $stripe_customer->set_id($stripe_customer_id); |
|
782 | 781 | } |
783 | 782 | |
784 | - $source_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
783 | + $source_id = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
785 | 784 | |
786 | 785 | // Since 4.0.0, we changed card to source so we need to account for that. |
787 | - if ( empty( $source_id ) ) { |
|
788 | - $source_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
786 | + if (empty($source_id)) { |
|
787 | + $source_id = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
789 | 788 | |
790 | 789 | // Take this opportunity to update the key name. |
791 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
790 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
792 | 791 | |
793 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
792 | + if (is_callable(array($order, 'save'))) { |
|
794 | 793 | $order->save(); |
795 | 794 | } |
796 | 795 | } |
797 | 796 | |
798 | - if ( $source_id ) { |
|
797 | + if ($source_id) { |
|
799 | 798 | $stripe_source = $source_id; |
800 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source_id ); |
|
801 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
799 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source_id); |
|
800 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
802 | 801 | /* |
803 | 802 | * We can attempt to charge the customer's default source |
804 | 803 | * by sending empty source id. |
@@ -823,27 +822,27 @@ discard block |
||
823 | 822 | * @param WC_Order $order For to which the source applies. |
824 | 823 | * @param stdClass $source Source information. |
825 | 824 | */ |
826 | - public function save_source_to_order( $order, $source ) { |
|
827 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
825 | + public function save_source_to_order($order, $source) { |
|
826 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
828 | 827 | |
829 | 828 | // Store source in the order. |
830 | - if ( $source->customer ) { |
|
831 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
832 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
829 | + if ($source->customer) { |
|
830 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
831 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
833 | 832 | } else { |
834 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
833 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
835 | 834 | } |
836 | 835 | } |
837 | 836 | |
838 | - if ( $source->source ) { |
|
839 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
840 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
837 | + if ($source->source) { |
|
838 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
839 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
841 | 840 | } else { |
842 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
841 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
843 | 842 | } |
844 | 843 | } |
845 | 844 | |
846 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
845 | + if (is_callable(array($order, 'save'))) { |
|
847 | 846 | $order->save(); |
848 | 847 | } |
849 | 848 | } |
@@ -857,38 +856,38 @@ discard block |
||
857 | 856 | * @param object $order The order object |
858 | 857 | * @param int $balance_transaction_id |
859 | 858 | */ |
860 | - public function update_fees( $order, $balance_transaction_id ) { |
|
861 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
859 | + public function update_fees($order, $balance_transaction_id) { |
|
860 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
862 | 861 | |
863 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
862 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
864 | 863 | |
865 | - if ( empty( $balance_transaction->error ) ) { |
|
866 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
864 | + if (empty($balance_transaction->error)) { |
|
865 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
867 | 866 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
868 | 867 | // values are in the local currency of the Stripe account, not from WC. |
869 | - $fee_refund = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
870 | - $net_refund = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
868 | + $fee_refund = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
869 | + $net_refund = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
871 | 870 | |
872 | 871 | // Current data fee & net. |
873 | - $fee_current = WC_Stripe_Helper::get_stripe_fee( $order ); |
|
874 | - $net_current = WC_Stripe_Helper::get_stripe_net( $order ); |
|
872 | + $fee_current = WC_Stripe_Helper::get_stripe_fee($order); |
|
873 | + $net_current = WC_Stripe_Helper::get_stripe_net($order); |
|
875 | 874 | |
876 | 875 | // Calculation. |
877 | 876 | $fee = (float) $fee_current + (float) $fee_refund; |
878 | 877 | $net = (float) $net_current + (float) $net_refund; |
879 | 878 | |
880 | - WC_Stripe_Helper::update_stripe_fee( $order, $fee ); |
|
881 | - WC_Stripe_Helper::update_stripe_net( $order, $net ); |
|
879 | + WC_Stripe_Helper::update_stripe_fee($order, $fee); |
|
880 | + WC_Stripe_Helper::update_stripe_net($order, $net); |
|
882 | 881 | |
883 | - $currency = ! empty( $balance_transaction->currency ) ? strtoupper( $balance_transaction->currency ) : null; |
|
884 | - WC_Stripe_Helper::update_stripe_currency( $order, $currency ); |
|
882 | + $currency = ! empty($balance_transaction->currency) ? strtoupper($balance_transaction->currency) : null; |
|
883 | + WC_Stripe_Helper::update_stripe_currency($order, $currency); |
|
885 | 884 | |
886 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
885 | + if (is_callable(array($order, 'save'))) { |
|
887 | 886 | $order->save(); |
888 | 887 | } |
889 | 888 | } |
890 | 889 | } else { |
891 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
890 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
892 | 891 | } |
893 | 892 | } |
894 | 893 | |
@@ -901,33 +900,33 @@ discard block |
||
901 | 900 | * @param float $amount |
902 | 901 | * @return bool |
903 | 902 | */ |
904 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
905 | - $order = wc_get_order( $order_id ); |
|
903 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
904 | + $order = wc_get_order($order_id); |
|
906 | 905 | |
907 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
906 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
908 | 907 | return false; |
909 | 908 | } |
910 | 909 | |
911 | 910 | $request = array(); |
912 | 911 | |
913 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
914 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
915 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
912 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
913 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
914 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
916 | 915 | } else { |
917 | 916 | $order_currency = $order->get_currency(); |
918 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
917 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
919 | 918 | } |
920 | 919 | |
921 | - if ( ! is_null( $amount ) ) { |
|
922 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
920 | + if ( ! is_null($amount)) { |
|
921 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
923 | 922 | } |
924 | 923 | |
925 | 924 | // If order is only authorized, don't pass amount. |
926 | - if ( 'yes' !== $captured ) { |
|
927 | - unset( $request['amount'] ); |
|
925 | + if ('yes' !== $captured) { |
|
926 | + unset($request['amount']); |
|
928 | 927 | } |
929 | 928 | |
930 | - if ( $reason ) { |
|
929 | + if ($reason) { |
|
931 | 930 | $request['metadata'] = array( |
932 | 931 | 'reason' => $reason, |
933 | 932 | ); |
@@ -935,35 +934,35 @@ discard block |
||
935 | 934 | |
936 | 935 | $request['charge'] = $order->get_transaction_id(); |
937 | 936 | |
938 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
937 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
939 | 938 | |
940 | - $request = apply_filters( 'wc_stripe_refund_request', $request, $order ); |
|
939 | + $request = apply_filters('wc_stripe_refund_request', $request, $order); |
|
941 | 940 | |
942 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
941 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
943 | 942 | |
944 | - if ( ! empty( $response->error ) ) { |
|
945 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
943 | + if ( ! empty($response->error)) { |
|
944 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
946 | 945 | |
947 | 946 | return $response; |
948 | 947 | |
949 | - } elseif ( ! empty( $response->id ) ) { |
|
950 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
948 | + } elseif ( ! empty($response->id)) { |
|
949 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
951 | 950 | |
952 | - $amount = wc_price( $response->amount / 100 ); |
|
951 | + $amount = wc_price($response->amount / 100); |
|
953 | 952 | |
954 | - if ( in_array( strtolower( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
955 | - $amount = wc_price( $response->amount ); |
|
953 | + if (in_array(strtolower(WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
954 | + $amount = wc_price($response->amount); |
|
956 | 955 | } |
957 | 956 | |
958 | - if ( isset( $response->balance_transaction ) ) { |
|
959 | - $this->update_fees( $order, $response->balance_transaction ); |
|
957 | + if (isset($response->balance_transaction)) { |
|
958 | + $this->update_fees($order, $response->balance_transaction); |
|
960 | 959 | } |
961 | 960 | |
962 | 961 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
963 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' ); |
|
962 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe'); |
|
964 | 963 | |
965 | - $order->add_order_note( $refund_message ); |
|
966 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( wp_strip_all_tags( $refund_message ) ) ); |
|
964 | + $order->add_order_note($refund_message); |
|
965 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(wp_strip_all_tags($refund_message))); |
|
967 | 966 | |
968 | 967 | return true; |
969 | 968 | } |
@@ -978,46 +977,46 @@ discard block |
||
978 | 977 | */ |
979 | 978 | public function add_payment_method() { |
980 | 979 | $error = false; |
981 | - $error_msg = __( 'There was a problem adding the payment method.', 'woocommerce-gateway-stripe' ); |
|
980 | + $error_msg = __('There was a problem adding the payment method.', 'woocommerce-gateway-stripe'); |
|
982 | 981 | $source_id = ''; |
983 | 982 | |
984 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
983 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
985 | 984 | $error = true; |
986 | 985 | } |
987 | 986 | |
988 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
987 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
989 | 988 | |
990 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
989 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
991 | 990 | |
992 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
991 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
993 | 992 | |
994 | - if ( isset( $source_object ) ) { |
|
995 | - if ( ! empty( $source_object->error ) ) { |
|
993 | + if (isset($source_object)) { |
|
994 | + if ( ! empty($source_object->error)) { |
|
996 | 995 | $error = true; |
997 | 996 | } |
998 | 997 | |
999 | 998 | $source_id = $source_object->id; |
1000 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
1001 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
999 | + } elseif (isset($_POST['stripe_token'])) { |
|
1000 | + $source_id = wc_clean($_POST['stripe_token']); |
|
1002 | 1001 | } |
1003 | 1002 | |
1004 | - $response = $stripe_customer->add_source( $source_id ); |
|
1003 | + $response = $stripe_customer->add_source($source_id); |
|
1005 | 1004 | |
1006 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
1005 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
1007 | 1006 | $error = true; |
1008 | 1007 | } |
1009 | 1008 | |
1010 | - if ( $error ) { |
|
1011 | - wc_add_notice( $error_msg, 'error' ); |
|
1012 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
1009 | + if ($error) { |
|
1010 | + wc_add_notice($error_msg, 'error'); |
|
1011 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
1013 | 1012 | return; |
1014 | 1013 | } |
1015 | 1014 | |
1016 | - do_action( 'wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object ); |
|
1015 | + do_action('wc_stripe_add_payment_method_' . $_POST['payment_method'] . '_success', $source_id, $source_object); |
|
1017 | 1016 | |
1018 | 1017 | return array( |
1019 | 1018 | 'result' => 'success', |
1020 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
1019 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
1021 | 1020 | ); |
1022 | 1021 | } |
1023 | 1022 | |
@@ -1034,10 +1033,10 @@ discard block |
||
1034 | 1033 | * Stripe expects Norwegian to only be passed NO. |
1035 | 1034 | * But WP has different dialects. |
1036 | 1035 | */ |
1037 | - if ( 'NO' === substr( $locale, 3, 2 ) ) { |
|
1036 | + if ('NO' === substr($locale, 3, 2)) { |
|
1038 | 1037 | $locale = 'no'; |
1039 | 1038 | } else { |
1040 | - $locale = substr( get_locale(), 0, 2 ); |
|
1039 | + $locale = substr(get_locale(), 0, 2); |
|
1041 | 1040 | } |
1042 | 1041 | |
1043 | 1042 | return $locale; |
@@ -1051,9 +1050,9 @@ discard block |
||
1051 | 1050 | * @param string $idempotency_key |
1052 | 1051 | * @param array $request |
1053 | 1052 | */ |
1054 | - public function change_idempotency_key( $idempotency_key, $request ) { |
|
1055 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
1056 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
1053 | + public function change_idempotency_key($idempotency_key, $request) { |
|
1054 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
1055 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
1057 | 1056 | $count = $this->retry_interval; |
1058 | 1057 | |
1059 | 1058 | return $request['metadata']['order_id'] . '-' . $count . '-' . $source; |
@@ -1067,8 +1066,8 @@ discard block |
||
1067 | 1066 | * @since 4.0.6 |
1068 | 1067 | * @param array $headers |
1069 | 1068 | */ |
1070 | - public function is_original_request( $headers ) { |
|
1071 | - if ( $headers['original-request'] === $headers['request-id'] ) { |
|
1069 | + public function is_original_request($headers) { |
|
1070 | + if ($headers['original-request'] === $headers['request-id']) { |
|
1072 | 1071 | return true; |
1073 | 1072 | } |
1074 | 1073 |
@@ -227,7 +227,7 @@ |
||
227 | 227 | /** |
228 | 228 | * List of currencies supported by Stripe that has no decimals. |
229 | 229 | * |
230 | - * @return array $currencies |
|
230 | + * @return string[] $currencies |
|
231 | 231 | */ |
232 | 232 | public static function no_decimal_currencies() { |
233 | 233 | 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 | |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | * @param object $order |
23 | 23 | * @return string $currency |
24 | 24 | */ |
25 | - public static function get_stripe_currency( $order = null ) { |
|
26 | - if ( is_null( $order ) ) { |
|
25 | + public static function get_stripe_currency($order = null) { |
|
26 | + if (is_null($order)) { |
|
27 | 27 | return false; |
28 | 28 | } |
29 | 29 | |
30 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
30 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
31 | 31 | |
32 | - return WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, self::META_NAME_STRIPE_CURRENCY, true ) : $order->get_meta( self::META_NAME_STRIPE_CURRENCY, true ); |
|
32 | + return WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, self::META_NAME_STRIPE_CURRENCY, true) : $order->get_meta(self::META_NAME_STRIPE_CURRENCY, true); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | * @param object $order |
40 | 40 | * @param string $currency |
41 | 41 | */ |
42 | - public static function update_stripe_currency( $order = null, $currency ) { |
|
43 | - if ( is_null( $order ) ) { |
|
42 | + public static function update_stripe_currency($order = null, $currency) { |
|
43 | + if (is_null($order)) { |
|
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | |
47 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
47 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
48 | 48 | |
49 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, self::META_NAME_STRIPE_CURRENCY, $currency ) : $order->update_meta_data( self::META_NAME_STRIPE_CURRENCY, $currency ); |
|
49 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, self::META_NAME_STRIPE_CURRENCY, $currency) : $order->update_meta_data(self::META_NAME_STRIPE_CURRENCY, $currency); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -56,22 +56,22 @@ discard block |
||
56 | 56 | * @param object $order |
57 | 57 | * @return string $amount |
58 | 58 | */ |
59 | - public static function get_stripe_fee( $order = null ) { |
|
60 | - if ( is_null( $order ) ) { |
|
59 | + public static function get_stripe_fee($order = null) { |
|
60 | + if (is_null($order)) { |
|
61 | 61 | return false; |
62 | 62 | } |
63 | 63 | |
64 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
64 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
65 | 65 | |
66 | - $amount = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, self::META_NAME_FEE, true ) : $order->get_meta( self::META_NAME_FEE, true ); |
|
66 | + $amount = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, self::META_NAME_FEE, true) : $order->get_meta(self::META_NAME_FEE, true); |
|
67 | 67 | |
68 | 68 | // If not found let's check for legacy name. |
69 | - if ( empty( $amount ) ) { |
|
70 | - $amount = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, self::LEGACY_META_NAME_FEE, true ) : $order->get_meta( self::LEGACY_META_NAME_FEE, true ); |
|
69 | + if (empty($amount)) { |
|
70 | + $amount = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, self::LEGACY_META_NAME_FEE, true) : $order->get_meta(self::LEGACY_META_NAME_FEE, true); |
|
71 | 71 | |
72 | 72 | // If found update to new name. |
73 | - if ( $amount ) { |
|
74 | - self::update_stripe_fee( $order, $amount ); |
|
73 | + if ($amount) { |
|
74 | + self::update_stripe_fee($order, $amount); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | * @param object $order |
86 | 86 | * @param float $amount |
87 | 87 | */ |
88 | - public static function update_stripe_fee( $order = null, $amount = 0.0 ) { |
|
89 | - if ( is_null( $order ) ) { |
|
88 | + public static function update_stripe_fee($order = null, $amount = 0.0) { |
|
89 | + if (is_null($order)) { |
|
90 | 90 | return false; |
91 | 91 | } |
92 | 92 | |
93 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
93 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
94 | 94 | |
95 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, self::META_NAME_FEE, $amount ) : $order->update_meta_data( self::META_NAME_FEE, $amount ); |
|
95 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, self::META_NAME_FEE, $amount) : $order->update_meta_data(self::META_NAME_FEE, $amount); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -101,15 +101,15 @@ discard block |
||
101 | 101 | * @since 4.1.0 |
102 | 102 | * @param object $order |
103 | 103 | */ |
104 | - public static function delete_stripe_fee( $order = null ) { |
|
105 | - if ( is_null( $order ) ) { |
|
104 | + public static function delete_stripe_fee($order = null) { |
|
105 | + if (is_null($order)) { |
|
106 | 106 | return false; |
107 | 107 | } |
108 | 108 | |
109 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
109 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
110 | 110 | |
111 | - delete_post_meta( $order_id, self::META_NAME_FEE ); |
|
112 | - delete_post_meta( $order_id, self::LEGACY_META_NAME_FEE ); |
|
111 | + delete_post_meta($order_id, self::META_NAME_FEE); |
|
112 | + delete_post_meta($order_id, self::LEGACY_META_NAME_FEE); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -119,22 +119,22 @@ discard block |
||
119 | 119 | * @param object $order |
120 | 120 | * @return string $amount |
121 | 121 | */ |
122 | - public static function get_stripe_net( $order = null ) { |
|
123 | - if ( is_null( $order ) ) { |
|
122 | + public static function get_stripe_net($order = null) { |
|
123 | + if (is_null($order)) { |
|
124 | 124 | return false; |
125 | 125 | } |
126 | 126 | |
127 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
127 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
128 | 128 | |
129 | - $amount = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, self::META_NAME_NET, true ) : $order->get_meta( self::META_NAME_NET, true ); |
|
129 | + $amount = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, self::META_NAME_NET, true) : $order->get_meta(self::META_NAME_NET, true); |
|
130 | 130 | |
131 | 131 | // If not found let's check for legacy name. |
132 | - if ( empty( $amount ) ) { |
|
133 | - $amount = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? get_post_meta( $order_id, self::LEGACY_META_NAME_NET, true ) : $order->get_meta( self::LEGACY_META_NAME_NET, true ); |
|
132 | + if (empty($amount)) { |
|
133 | + $amount = WC_Stripe_Helper::is_wc_lt('3.0') ? get_post_meta($order_id, self::LEGACY_META_NAME_NET, true) : $order->get_meta(self::LEGACY_META_NAME_NET, true); |
|
134 | 134 | |
135 | 135 | // If found update to new name. |
136 | - if ( $amount ) { |
|
137 | - self::update_stripe_net( $order, $amount ); |
|
136 | + if ($amount) { |
|
137 | + self::update_stripe_net($order, $amount); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | * @param object $order |
149 | 149 | * @param float $amount |
150 | 150 | */ |
151 | - public static function update_stripe_net( $order = null, $amount = 0.0 ) { |
|
152 | - if ( is_null( $order ) ) { |
|
151 | + public static function update_stripe_net($order = null, $amount = 0.0) { |
|
152 | + if (is_null($order)) { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | |
156 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
156 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
157 | 157 | |
158 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $order_id, self::META_NAME_NET, $amount ) : $order->update_meta_data( self::META_NAME_NET, $amount ); |
|
158 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($order_id, self::META_NAME_NET, $amount) : $order->update_meta_data(self::META_NAME_NET, $amount); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -164,15 +164,15 @@ discard block |
||
164 | 164 | * @since 4.1.0 |
165 | 165 | * @param object $order |
166 | 166 | */ |
167 | - public static function delete_stripe_net( $order = null ) { |
|
168 | - if ( is_null( $order ) ) { |
|
167 | + public static function delete_stripe_net($order = null) { |
|
168 | + if (is_null($order)) { |
|
169 | 169 | return false; |
170 | 170 | } |
171 | 171 | |
172 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
172 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
173 | 173 | |
174 | - delete_post_meta( $order_id, self::META_NAME_NET ); |
|
175 | - delete_post_meta( $order_id, self::LEGACY_META_NAME_NET ); |
|
174 | + delete_post_meta($order_id, self::META_NAME_NET); |
|
175 | + delete_post_meta($order_id, self::LEGACY_META_NAME_NET); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -183,15 +183,15 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return float|int |
185 | 185 | */ |
186 | - public static function get_stripe_amount( $total, $currency = '' ) { |
|
187 | - if ( ! $currency ) { |
|
186 | + public static function get_stripe_amount($total, $currency = '') { |
|
187 | + if ( ! $currency) { |
|
188 | 188 | $currency = get_woocommerce_currency(); |
189 | 189 | } |
190 | 190 | |
191 | - if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) { |
|
192 | - return absint( $total ); |
|
191 | + if (in_array(strtolower($currency), self::no_decimal_currencies())) { |
|
192 | + return absint($total); |
|
193 | 193 | } else { |
194 | - return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents. |
|
194 | + return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents. |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
@@ -206,23 +206,23 @@ discard block |
||
206 | 206 | return apply_filters( |
207 | 207 | 'wc_stripe_localized_messages', |
208 | 208 | array( |
209 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
210 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
211 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
212 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
213 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
214 | - 'incomplete_number' => __( 'The card number is incomplete.', 'woocommerce-gateway-stripe' ), |
|
215 | - 'incomplete_cvc' => __( 'The card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ), |
|
216 | - 'incomplete_expiry' => __( 'The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe' ), |
|
217 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
218 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
219 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
220 | - 'invalid_expiry_year_past' => __( 'The card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ), |
|
221 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
222 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
223 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
224 | - 'invalid_request_error' => __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ), |
|
225 | - 'invalid_sofort_country' => __( 'The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe' ), |
|
209 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
210 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
211 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
212 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
213 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
214 | + 'incomplete_number' => __('The card number is incomplete.', 'woocommerce-gateway-stripe'), |
|
215 | + 'incomplete_cvc' => __('The card\'s security code is incomplete.', 'woocommerce-gateway-stripe'), |
|
216 | + 'incomplete_expiry' => __('The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe'), |
|
217 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
218 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
219 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
220 | + 'invalid_expiry_year_past' => __('The card\'s expiration year is in the past', 'woocommerce-gateway-stripe'), |
|
221 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
222 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
223 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
224 | + 'invalid_request_error' => __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'), |
|
225 | + 'invalid_sofort_country' => __('The billing country is not accepted by SOFORT. Please try another country.', 'woocommerce-gateway-stripe'), |
|
226 | 226 | ) |
227 | 227 | ); |
228 | 228 | } |
@@ -261,24 +261,24 @@ discard block |
||
261 | 261 | * @param string $type Type of number to format |
262 | 262 | * @return string |
263 | 263 | */ |
264 | - public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
265 | - if ( ! is_object( $balance_transaction ) ) { |
|
264 | + public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
265 | + if ( ! is_object($balance_transaction)) { |
|
266 | 266 | return; |
267 | 267 | } |
268 | 268 | |
269 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
270 | - if ( 'fee' === $type ) { |
|
269 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
270 | + if ('fee' === $type) { |
|
271 | 271 | return $balance_transaction->fee; |
272 | 272 | } |
273 | 273 | |
274 | 274 | return $balance_transaction->net; |
275 | 275 | } |
276 | 276 | |
277 | - if ( 'fee' === $type ) { |
|
278 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
277 | + if ('fee' === $type) { |
|
278 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
279 | 279 | } |
280 | 280 | |
281 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
281 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | */ |
287 | 287 | public static function get_minimum_amount() { |
288 | 288 | // Check order amount |
289 | - switch ( get_woocommerce_currency() ) { |
|
289 | + switch (get_woocommerce_currency()) { |
|
290 | 290 | case 'USD': |
291 | 291 | case 'CAD': |
292 | 292 | case 'EUR': |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | * @param string $method The payment method to get the settings from. |
332 | 332 | * @param string $setting The name of the setting to get. |
333 | 333 | */ |
334 | - public static function get_settings( $method = null, $setting = null ) { |
|
335 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
334 | + public static function get_settings($method = null, $setting = null) { |
|
335 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
336 | 336 | |
337 | - if ( null === $setting ) { |
|
337 | + if (null === $setting) { |
|
338 | 338 | return $all_settings; |
339 | 339 | } |
340 | 340 | |
341 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
341 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | * @return bool |
349 | 349 | */ |
350 | 350 | public static function is_pre_orders_exists() { |
351 | - return class_exists( 'WC_Pre_Orders_Order' ); |
|
351 | + return class_exists('WC_Pre_Orders_Order'); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -360,9 +360,9 @@ discard block |
||
360 | 360 | * @return bool |
361 | 361 | */ |
362 | 362 | public static function is_pre_30() { |
363 | - error_log( 'is_pre_30() function has been deprecated since 4.1.11. Please use is_wc_lt( $version ) instead.' ); |
|
363 | + error_log('is_pre_30() function has been deprecated since 4.1.11. Please use is_wc_lt( $version ) instead.'); |
|
364 | 364 | |
365 | - return self::is_wc_lt( '3.0' ); |
|
365 | + return self::is_wc_lt('3.0'); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | * @param string $version Version to check against. |
373 | 373 | * @return bool |
374 | 374 | */ |
375 | - public static function is_wc_lt( $version ) { |
|
376 | - return version_compare( WC_VERSION, $version, '<' ); |
|
375 | + public static function is_wc_lt($version) { |
|
376 | + return version_compare(WC_VERSION, $version, '<'); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | * @return string |
387 | 387 | */ |
388 | 388 | public static function get_webhook_url() { |
389 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
389 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | /** |
@@ -396,13 +396,13 @@ discard block |
||
396 | 396 | * @version 4.0.0 |
397 | 397 | * @param string $source_id |
398 | 398 | */ |
399 | - public static function get_order_by_source_id( $source_id ) { |
|
399 | + public static function get_order_by_source_id($source_id) { |
|
400 | 400 | global $wpdb; |
401 | 401 | |
402 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $source_id, '_stripe_source_id' ) ); |
|
402 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $source_id, '_stripe_source_id')); |
|
403 | 403 | |
404 | - if ( ! empty( $order_id ) ) { |
|
405 | - return wc_get_order( $order_id ); |
|
404 | + if ( ! empty($order_id)) { |
|
405 | + return wc_get_order($order_id); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | return false; |
@@ -415,13 +415,13 @@ discard block |
||
415 | 415 | * @version 4.0.0 |
416 | 416 | * @param string $charge_id |
417 | 417 | */ |
418 | - public static function get_order_by_charge_id( $charge_id ) { |
|
418 | + public static function get_order_by_charge_id($charge_id) { |
|
419 | 419 | global $wpdb; |
420 | 420 | |
421 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $charge_id, '_transaction_id' ) ); |
|
421 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $charge_id, '_transaction_id')); |
|
422 | 422 | |
423 | - if ( ! empty( $order_id ) ) { |
|
424 | - return wc_get_order( $order_id ); |
|
423 | + if ( ! empty($order_id)) { |
|
424 | + return wc_get_order($order_id); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | return false; |
@@ -437,13 +437,13 @@ discard block |
||
437 | 437 | * @param string $statement_descriptor |
438 | 438 | * @return string $statement_descriptor Sanitized statement descriptor |
439 | 439 | */ |
440 | - public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
441 | - $disallowed_characters = array( '<', '>', '"', "'" ); |
|
440 | + public static function clean_statement_descriptor($statement_descriptor = '') { |
|
441 | + $disallowed_characters = array('<', '>', '"', "'"); |
|
442 | 442 | |
443 | 443 | // Remove special characters. |
444 | - $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
444 | + $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
445 | 445 | |
446 | - $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
446 | + $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
447 | 447 | |
448 | 448 | return $statement_descriptor; |
449 | 449 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @param float $amount |
139 | 139 | * @param mixed $renewal_order |
140 | 140 | * @param bool $retry Should we retry the process? |
141 | - * @param object $previous_error |
|
141 | + * @param boolean $previous_error |
|
142 | 142 | */ |
143 | 143 | public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
144 | 144 | try { |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | |
242 | 242 | /** |
243 | 243 | * Don't transfer Stripe fee/ID meta to renewal orders. |
244 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
244 | + * @param integer $renewal_order |
|
245 | 245 | */ |
246 | 246 | public function delete_renewal_meta( $renewal_order ) { |
247 | 247 | WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,21 +15,21 @@ discard block |
||
15 | 15 | public function __construct() { |
16 | 16 | parent::__construct(); |
17 | 17 | |
18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
23 | - add_action( 'wc_stripe_sepa_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) ); |
|
24 | - add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 ); |
|
18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
23 | + add_action('wc_stripe_sepa_payment_fields', array($this, 'display_update_subs_payment_checkout')); |
|
24 | + add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2); |
|
25 | 25 | |
26 | 26 | // Display the credit card used for a subscription in the "My Subscriptions" table. |
27 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
27 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
28 | 28 | |
29 | 29 | // Allow store managers to manually set Stripe as the payment method on a subscription. |
30 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
31 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
32 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
30 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
31 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
32 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | * @since 4.0.0 |
50 | 50 | * @version 4.0.0 |
51 | 51 | */ |
52 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
53 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
52 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
53 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @param int $order_id |
63 | 63 | * @return boolean |
64 | 64 | */ |
65 | - public function has_subscription( $order_id ) { |
|
66 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
65 | + public function has_subscription($order_id) { |
|
66 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @return bool |
74 | 74 | */ |
75 | 75 | public function is_subs_change_payment() { |
76 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
76 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function display_update_subs_payment_checkout() { |
86 | 86 | if ( |
87 | - apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) && |
|
88 | - wcs_user_has_subscription( get_current_user_id(), '', 'active' ) && |
|
87 | + apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) && |
|
88 | + wcs_user_has_subscription(get_current_user_id(), '', 'active') && |
|
89 | 89 | is_add_payment_method_page() |
90 | 90 | ) { |
91 | 91 | printf( |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | <input id="wc-%1$s-update-subs-payment-method-card" name="wc-%1$s-update-subs-payment-method-card" type="checkbox" value="true" style="width:auto;" /> |
94 | 94 | <label for="wc-%1$s-update-subs-payment-method-card" style="display:inline;">%2$s</label> |
95 | 95 | </p>', |
96 | - esc_attr( $this->id ), |
|
97 | - esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe' ) ) ) |
|
96 | + esc_attr($this->id), |
|
97 | + esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe'))) |
|
98 | 98 | ); |
99 | 99 | } |
100 | 100 | } |
@@ -106,16 +106,16 @@ discard block |
||
106 | 106 | * @param string $source_id |
107 | 107 | * @param object $source_object |
108 | 108 | */ |
109 | - public function handle_add_payment_method_success( $source_id, $source_object ) { |
|
110 | - if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) { |
|
109 | + public function handle_add_payment_method_success($source_id, $source_object) { |
|
110 | + if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) { |
|
111 | 111 | $all_subs = wcs_get_users_subscriptions(); |
112 | 112 | |
113 | - if ( ! empty( $all_subs ) ) { |
|
114 | - foreach ( $all_subs as $sub ) { |
|
115 | - if ( 'active' === $sub->get_status() ) { |
|
116 | - update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id ); |
|
117 | - update_post_meta( $sub->get_id(), '_payment_method', $this->id ); |
|
118 | - update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title ); |
|
113 | + if ( ! empty($all_subs)) { |
|
114 | + foreach ($all_subs as $sub) { |
|
115 | + if ('active' === $sub->get_status()) { |
|
116 | + update_post_meta($sub->get_id(), '_stripe_source_id', $source_id); |
|
117 | + update_post_meta($sub->get_id(), '_payment_method', $this->id); |
|
118 | + update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
@@ -128,24 +128,24 @@ discard block |
||
128 | 128 | * @since 3.1.0 |
129 | 129 | * @version 4.0.0 |
130 | 130 | */ |
131 | - public function save_source_to_order( $order, $source ) { |
|
132 | - parent::save_source_to_order( $order, $source ); |
|
131 | + public function save_source_to_order($order, $source) { |
|
132 | + parent::save_source_to_order($order, $source); |
|
133 | 133 | |
134 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
134 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
135 | 135 | |
136 | 136 | // Also store it on the subscriptions being purchased or paid for in the order. |
137 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
138 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
139 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
140 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
137 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
138 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
139 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
140 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
141 | 141 | } else { |
142 | 142 | $subscriptions = array(); |
143 | 143 | } |
144 | 144 | |
145 | - foreach ( $subscriptions as $subscription ) { |
|
146 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
147 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
148 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
145 | + foreach ($subscriptions as $subscription) { |
|
146 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
147 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
148 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -154,16 +154,16 @@ discard block |
||
154 | 154 | * @param int $order_id |
155 | 155 | * @return array |
156 | 156 | */ |
157 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
158 | - if ( $this->has_subscription( $order_id ) ) { |
|
159 | - if ( $this->is_subs_change_payment() ) { |
|
160 | - return $this->change_subs_payment_method( $order_id ); |
|
157 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
158 | + if ($this->has_subscription($order_id)) { |
|
159 | + if ($this->is_subs_change_payment()) { |
|
160 | + return $this->change_subs_payment_method($order_id); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | // Regular payment with force customer enabled |
164 | - return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
164 | + return parent::process_payment($order_id, $retry, true, $previous_error); |
|
165 | 165 | } else { |
166 | - return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
166 | + return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
167 | 167 | } |
168 | 168 | } |
169 | 169 | |
@@ -173,27 +173,27 @@ discard block |
||
173 | 173 | * @since 4.0.4 |
174 | 174 | * @param int $order_id |
175 | 175 | */ |
176 | - public function change_subs_payment_method( $order_id ) { |
|
176 | + public function change_subs_payment_method($order_id) { |
|
177 | 177 | try { |
178 | - $subscription = wc_get_order( $order_id ); |
|
179 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
178 | + $subscription = wc_get_order($order_id); |
|
179 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
180 | 180 | |
181 | - if ( empty( $prepared_source->source ) ) { |
|
182 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
183 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
181 | + if (empty($prepared_source->source)) { |
|
182 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
183 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
184 | 184 | } |
185 | 185 | |
186 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
186 | + $this->save_source_to_order($subscription, $prepared_source); |
|
187 | 187 | |
188 | - do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source ); |
|
188 | + do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source); |
|
189 | 189 | |
190 | 190 | return array( |
191 | 191 | 'result' => 'success', |
192 | - 'redirect' => $this->get_return_url( $subscription ), |
|
192 | + 'redirect' => $this->get_return_url($subscription), |
|
193 | 193 | ); |
194 | - } catch ( WC_Stripe_Exception $e ) { |
|
195 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
196 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
194 | + } catch (WC_Stripe_Exception $e) { |
|
195 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
196 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | * @param $amount_to_charge float The amount to charge. |
204 | 204 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
205 | 205 | */ |
206 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
207 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
206 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
207 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -218,86 +218,86 @@ discard block |
||
218 | 218 | * @param bool $retry Should we retry the process? |
219 | 219 | * @param object $previous_error |
220 | 220 | */ |
221 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
221 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
222 | 222 | try { |
223 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
223 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
224 | 224 | /* translators: minimum amount */ |
225 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
225 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
226 | 226 | } |
227 | 227 | |
228 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
228 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
229 | 229 | |
230 | 230 | // Get source from order |
231 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
231 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
232 | 232 | $source_object = $prepared_source->source_object; |
233 | 233 | |
234 | - if ( ! $prepared_source->customer ) { |
|
235 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
234 | + if ( ! $prepared_source->customer) { |
|
235 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
236 | 236 | } |
237 | 237 | |
238 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
238 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
239 | 239 | |
240 | 240 | /* If we're doing a retry and source is chargeable, we need to pass |
241 | 241 | * a different idempotency key and retry for success. |
242 | 242 | */ |
243 | - if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
244 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
243 | + if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
244 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
245 | 245 | } |
246 | 246 | |
247 | - if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
247 | + if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
248 | 248 | // Passing empty source will charge customer default. |
249 | 249 | $prepared_source->source = ''; |
250 | 250 | } |
251 | 251 | |
252 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
252 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
253 | 253 | $request['capture'] = 'true'; |
254 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
255 | - $response = WC_Stripe_API::request( $request ); |
|
254 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
255 | + $response = WC_Stripe_API::request($request); |
|
256 | 256 | |
257 | - if ( ! empty( $response->error ) ) { |
|
257 | + if ( ! empty($response->error)) { |
|
258 | 258 | // We want to retry. |
259 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
260 | - if ( $retry ) { |
|
259 | + if ($this->is_retryable_error($response->error)) { |
|
260 | + if ($retry) { |
|
261 | 261 | // Don't do anymore retries after this. |
262 | - if ( 5 <= $this->retry_interval ) { |
|
263 | - return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
262 | + if (5 <= $this->retry_interval) { |
|
263 | + return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
264 | 264 | } |
265 | 265 | |
266 | - sleep( $this->retry_interval ); |
|
266 | + sleep($this->retry_interval); |
|
267 | 267 | |
268 | 268 | $this->retry_interval++; |
269 | 269 | |
270 | - return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
270 | + return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
271 | 271 | } else { |
272 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
273 | - $renewal_order->add_order_note( $localized_message ); |
|
274 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
272 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
273 | + $renewal_order->add_order_note($localized_message); |
|
274 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | 278 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
279 | 279 | |
280 | - if ( 'card_error' === $response->error->type ) { |
|
281 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
280 | + if ('card_error' === $response->error->type) { |
|
281 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
282 | 282 | } else { |
283 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
283 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
284 | 284 | } |
285 | 285 | |
286 | - $renewal_order->add_order_note( $localized_message ); |
|
286 | + $renewal_order->add_order_note($localized_message); |
|
287 | 287 | |
288 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
288 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
289 | 289 | } |
290 | 290 | |
291 | - do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
291 | + do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
292 | 292 | |
293 | - $this->process_response( $response, $renewal_order ); |
|
294 | - } catch ( WC_Stripe_Exception $e ) { |
|
295 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
293 | + $this->process_response($response, $renewal_order); |
|
294 | + } catch (WC_Stripe_Exception $e) { |
|
295 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
296 | 296 | |
297 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
297 | + do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
298 | 298 | |
299 | 299 | /* translators: error message */ |
300 | - $renewal_order->update_status( 'failed' ); |
|
300 | + $renewal_order->update_status('failed'); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
@@ -305,21 +305,21 @@ discard block |
||
305 | 305 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
306 | 306 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
307 | 307 | */ |
308 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
309 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
310 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
308 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
309 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
310 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
311 | 311 | // For BW compat will remove in future |
312 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
313 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
312 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
313 | + $this->delete_renewal_meta($resubscribe_order); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
317 | 317 | * Don't transfer Stripe fee/ID meta to renewal orders. |
318 | 318 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
319 | 319 | */ |
320 | - public function delete_renewal_meta( $renewal_order ) { |
|
321 | - WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
322 | - WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
320 | + public function delete_renewal_meta($renewal_order) { |
|
321 | + WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
322 | + WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
323 | 323 | |
324 | 324 | return $renewal_order; |
325 | 325 | } |
@@ -333,14 +333,14 @@ discard block |
||
333 | 333 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
334 | 334 | * @return void |
335 | 335 | */ |
336 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
337 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
338 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
339 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
336 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
337 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
338 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
339 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
340 | 340 | |
341 | 341 | } else { |
342 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
343 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
342 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
343 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
@@ -353,21 +353,21 @@ discard block |
||
353 | 353 | * @param WC_Subscription $subscription An instance of a subscription object |
354 | 354 | * @return array |
355 | 355 | */ |
356 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
357 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
356 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
357 | + $source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
358 | 358 | |
359 | 359 | // For BW compat will remove in future. |
360 | - if ( empty( $source_id ) ) { |
|
361 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
360 | + if (empty($source_id)) { |
|
361 | + $source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
362 | 362 | |
363 | 363 | // Take this opportunity to update the key name. |
364 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
364 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
365 | 365 | } |
366 | 366 | |
367 | - $payment_meta[ $this->id ] = array( |
|
367 | + $payment_meta[$this->id] = array( |
|
368 | 368 | 'post_meta' => array( |
369 | 369 | '_stripe_customer_id' => array( |
370 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
370 | + 'value' => get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
371 | 371 | 'label' => 'Stripe Customer ID', |
372 | 372 | ), |
373 | 373 | '_stripe_source_id' => array( |
@@ -388,22 +388,22 @@ discard block |
||
388 | 388 | * @param array $payment_meta associative array of meta data required for automatic payments |
389 | 389 | * @return array |
390 | 390 | */ |
391 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
392 | - if ( $this->id === $payment_method_id ) { |
|
391 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
392 | + if ($this->id === $payment_method_id) { |
|
393 | 393 | |
394 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
395 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
396 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
397 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
394 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
395 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
396 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
397 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | if ( |
401 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
402 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
403 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
404 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
401 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
402 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
403 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
404 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
405 | 405 | |
406 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
406 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 | } |
@@ -416,67 +416,67 @@ discard block |
||
416 | 416 | * @param WC_Subscription $subscription the subscription details |
417 | 417 | * @return string the subscription payment method |
418 | 418 | */ |
419 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
420 | - $customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id(); |
|
419 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
420 | + $customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id(); |
|
421 | 421 | |
422 | 422 | // bail for other payment methods |
423 | - if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
423 | + if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
424 | 424 | return $payment_method_to_display; |
425 | 425 | } |
426 | 426 | |
427 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
427 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
428 | 428 | |
429 | 429 | // For BW compat will remove in future. |
430 | - if ( empty( $stripe_source_id ) ) { |
|
431 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
430 | + if (empty($stripe_source_id)) { |
|
431 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
432 | 432 | |
433 | 433 | // Take this opportunity to update the key name. |
434 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
434 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | $stripe_customer = new WC_Stripe_Customer(); |
438 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
438 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
439 | 439 | |
440 | 440 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
441 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
441 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
442 | 442 | $user_id = $customer_user; |
443 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
444 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
443 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
444 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
445 | 445 | |
446 | 446 | // For BW compat will remove in future. |
447 | - if ( empty( $stripe_source_id ) ) { |
|
448 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
447 | + if (empty($stripe_source_id)) { |
|
448 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
449 | 449 | |
450 | 450 | // Take this opportunity to update the key name. |
451 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
451 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
455 | 455 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
456 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
457 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
458 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
456 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
457 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
458 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
459 | 459 | |
460 | 460 | // For BW compat will remove in future. |
461 | - if ( empty( $stripe_source_id ) ) { |
|
462 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
461 | + if (empty($stripe_source_id)) { |
|
462 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
463 | 463 | |
464 | 464 | // Take this opportunity to update the key name. |
465 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
465 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
466 | 466 | } |
467 | 467 | } |
468 | 468 | |
469 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
469 | + $stripe_customer->set_id($stripe_customer_id); |
|
470 | 470 | |
471 | 471 | $sources = $stripe_customer->get_sources(); |
472 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
472 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
473 | 473 | |
474 | - if ( $sources ) { |
|
475 | - foreach ( $sources as $source ) { |
|
476 | - if ( $source->id === $stripe_source_id ) { |
|
477 | - if ( $source->sepa_debit ) { |
|
474 | + if ($sources) { |
|
475 | + foreach ($sources as $source) { |
|
476 | + if ($source->id === $stripe_source_id) { |
|
477 | + if ($source->sepa_debit) { |
|
478 | 478 | /* translators: 1) last 4 digits of SEPA Direct Debit */ |
479 | - $payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 ); |
|
479 | + $payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | break; |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
6 | 6 | // if uninstall not called from WordPress exit |
7 | -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
|
7 | +if ( ! defined('WP_UNINSTALL_PLUGIN')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | * wp-config.php. This is to prevent data loss when deleting the plugin from the backend |
14 | 14 | * and to ensure only the site owner can perform this action. |
15 | 15 | */ |
16 | -if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) { |
|
16 | +if (defined('WC_REMOVE_ALL_DATA') && true === WC_REMOVE_ALL_DATA) { |
|
17 | 17 | // Delete options. |
18 | - delete_option( 'woocommerce_stripe_settings' ); |
|
19 | - delete_option( 'wc_stripe_show_request_api_notice' ); |
|
20 | - delete_option( 'wc_stripe_show_apple_pay_notice' ); |
|
21 | - delete_option( 'wc_stripe_show_ssl_notice' ); |
|
22 | - delete_option( 'wc_stripe_show_keys_notice' ); |
|
23 | - delete_option( 'wc_stripe_show_alipay_notice' ); |
|
24 | - delete_option( 'wc_stripe_show_bancontact_notice' ); |
|
25 | - delete_option( 'wc_stripe_show_bitcoin_notice' ); |
|
26 | - delete_option( 'wc_stripe_show_eps_notice' ); |
|
27 | - delete_option( 'wc_stripe_show_giropay_notice' ); |
|
28 | - delete_option( 'wc_stripe_show_ideal_notice' ); |
|
29 | - delete_option( 'wc_stripe_show_multibanco_notice' ); |
|
30 | - delete_option( 'wc_stripe_show_p24_notice' ); |
|
31 | - delete_option( 'wc_stripe_show_sepa_notice' ); |
|
32 | - delete_option( 'wc_stripe_show_sofort_notice' ); |
|
33 | - delete_option( 'wc_stripe_version' ); |
|
34 | - delete_option( 'woocommerce_stripe_bancontact_settings' ); |
|
35 | - delete_option( 'woocommerce_stripe_alipay_settings' ); |
|
36 | - delete_option( 'woocommerce_stripe_bitcoin_settings' ); |
|
37 | - delete_option( 'woocommerce_stripe_ideal_settings' ); |
|
38 | - delete_option( 'woocommerce_stripe_p24_settings' ); |
|
39 | - delete_option( 'woocommerce_stripe_giropay_settings' ); |
|
40 | - delete_option( 'woocommerce_stripe_sepa_settings' ); |
|
41 | - delete_option( 'woocommerce_stripe_sofort_settings' ); |
|
18 | + delete_option('woocommerce_stripe_settings'); |
|
19 | + delete_option('wc_stripe_show_request_api_notice'); |
|
20 | + delete_option('wc_stripe_show_apple_pay_notice'); |
|
21 | + delete_option('wc_stripe_show_ssl_notice'); |
|
22 | + delete_option('wc_stripe_show_keys_notice'); |
|
23 | + delete_option('wc_stripe_show_alipay_notice'); |
|
24 | + delete_option('wc_stripe_show_bancontact_notice'); |
|
25 | + delete_option('wc_stripe_show_bitcoin_notice'); |
|
26 | + delete_option('wc_stripe_show_eps_notice'); |
|
27 | + delete_option('wc_stripe_show_giropay_notice'); |
|
28 | + delete_option('wc_stripe_show_ideal_notice'); |
|
29 | + delete_option('wc_stripe_show_multibanco_notice'); |
|
30 | + delete_option('wc_stripe_show_p24_notice'); |
|
31 | + delete_option('wc_stripe_show_sepa_notice'); |
|
32 | + delete_option('wc_stripe_show_sofort_notice'); |
|
33 | + delete_option('wc_stripe_version'); |
|
34 | + delete_option('woocommerce_stripe_bancontact_settings'); |
|
35 | + delete_option('woocommerce_stripe_alipay_settings'); |
|
36 | + delete_option('woocommerce_stripe_bitcoin_settings'); |
|
37 | + delete_option('woocommerce_stripe_ideal_settings'); |
|
38 | + delete_option('woocommerce_stripe_p24_settings'); |
|
39 | + delete_option('woocommerce_stripe_giropay_settings'); |
|
40 | + delete_option('woocommerce_stripe_sepa_settings'); |
|
41 | + delete_option('woocommerce_stripe_sofort_settings'); |
|
42 | 42 | } |