@@ -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; |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | $user_agent = self::get_user_agent(); |
79 | 79 | $app_info = $user_agent['application']; |
80 | 80 | |
81 | - return apply_filters( 'woocommerce_stripe_request_headers', array( |
|
82 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
81 | + return apply_filters('woocommerce_stripe_request_headers', array( |
|
82 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
83 | 83 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
84 | 84 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
85 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
86 | - ) ); |
|
85 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
86 | + )); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | * @param string $api |
96 | 96 | * @return array|WP_Error |
97 | 97 | */ |
98 | - public static function request( $request, $api = 'charges', $method = 'POST' ) { |
|
99 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
98 | + public static function request($request, $api = 'charges', $method = 'POST') { |
|
99 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
100 | 100 | |
101 | 101 | $headers = self::get_headers(); |
102 | 102 | |
103 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
104 | - $headers['Idempotency-Key'] = uniqid( 'stripe_' ); |
|
103 | + if ('charges' === $api && 'POST' === $method) { |
|
104 | + $headers['Idempotency-Key'] = uniqid('stripe_'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | $response = wp_safe_remote_post( |
@@ -109,17 +109,17 @@ discard block |
||
109 | 109 | array( |
110 | 110 | 'method' => $method, |
111 | 111 | 'headers' => $headers, |
112 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
112 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
113 | 113 | 'timeout' => 70, |
114 | 114 | ) |
115 | 115 | ); |
116 | 116 | |
117 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
118 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
119 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
117 | + if (is_wp_error($response) || empty($response['body'])) { |
|
118 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
119 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
120 | 120 | } |
121 | 121 | |
122 | - return json_decode( $response['body'] ); |
|
122 | + return json_decode($response['body']); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * @version 4.0.0 |
130 | 130 | * @param string $api |
131 | 131 | */ |
132 | - public static function retrieve( $api ) { |
|
133 | - WC_Stripe_Logger::log( "{$api}" ); |
|
132 | + public static function retrieve($api) { |
|
133 | + WC_Stripe_Logger::log("{$api}"); |
|
134 | 134 | |
135 | 135 | $response = wp_safe_remote_get( |
136 | 136 | self::ENDPOINT . $api, |
@@ -141,11 +141,11 @@ discard block |
||
141 | 141 | ) |
142 | 142 | ); |
143 | 143 | |
144 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
145 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
146 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
144 | + if (is_wp_error($response) || empty($response['body'])) { |
|
145 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
146 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
147 | 147 | } |
148 | 148 | |
149 | - return json_decode( $response['body'] ); |
|
149 | + return json_decode($response['body']); |
|
150 | 150 | } |
151 | 151 | } |
@@ -32,6 +32,8 @@ |
||
32 | 32 | * |
33 | 33 | * @since 4.0.0 |
34 | 34 | * @version 4.0.0 |
35 | + * @param string $slug |
|
36 | + * @param string $class |
|
35 | 37 | */ |
36 | 38 | public function add_admin_notice( $slug, $class, $message ) { |
37 | 39 | $this->notices[ $slug ] = 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 | |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | * Check if this gateway is enabled |
19 | 19 | */ |
20 | 20 | public function is_available() { |
21 | - if ( 'yes' === $this->enabled ) { |
|
22 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
21 | + if ('yes' === $this->enabled) { |
|
22 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
23 | 23 | return false; |
24 | 24 | } |
25 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
25 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | 28 | return true; |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * @since 4.0.0 |
38 | 38 | * @version 4.0.0 |
39 | 39 | */ |
40 | - public function add_admin_notice( $slug, $class, $message ) { |
|
41 | - $this->notices[ $slug ] = array( |
|
40 | + public function add_admin_notice($slug, $class, $message) { |
|
41 | + $this->notices[$slug] = array( |
|
42 | 42 | 'class' => $class, |
43 | 43 | 'message' => $message, |
44 | 44 | ); |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @version 4.0.0 |
52 | 52 | */ |
53 | 53 | public function remove_admin_notice() { |
54 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
55 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
54 | + if (did_action('woocommerce_update_options')) { |
|
55 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return array |
65 | 65 | */ |
66 | 66 | public function payment_icons() { |
67 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
67 | + return apply_filters('wc_stripe_payment_icons', array( |
|
68 | 68 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
69 | 69 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
70 | 70 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
82 | 82 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
83 | 83 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
84 | - ) ); |
|
84 | + )); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -92,10 +92,10 @@ discard block |
||
92 | 92 | * @version 4.0.0 |
93 | 93 | * @param object $order |
94 | 94 | */ |
95 | - public function validate_minimum_order_amount( $order ) { |
|
96 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
95 | + public function validate_minimum_order_amount($order) { |
|
96 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
97 | 97 | /* translators: 1) dollar amount */ |
98 | - 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 ) ) ); |
|
98 | + 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))); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | * @since 4.0.0 |
106 | 106 | * @version 4.0.0 |
107 | 107 | */ |
108 | - public function get_transaction_url( $order ) { |
|
109 | - if ( $this->testmode ) { |
|
108 | + public function get_transaction_url($order) { |
|
109 | + if ($this->testmode) { |
|
110 | 110 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
111 | 111 | } else { |
112 | 112 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
113 | 113 | } |
114 | 114 | |
115 | - return parent::get_transaction_url( $order ); |
|
115 | + return parent::get_transaction_url($order); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -121,15 +121,15 @@ discard block |
||
121 | 121 | * @since 4.0.0 |
122 | 122 | * @version 4.0.0 |
123 | 123 | */ |
124 | - public function get_stripe_customer_id( $order ) { |
|
125 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
124 | + public function get_stripe_customer_id($order) { |
|
125 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
126 | 126 | |
127 | - if ( empty( $customer ) ) { |
|
127 | + if (empty($customer)) { |
|
128 | 128 | // Try to get it via the order. |
129 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
130 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
129 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
130 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
131 | 131 | } else { |
132 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
132 | + return $order->get_meta('_stripe_customer_id', true); |
|
133 | 133 | } |
134 | 134 | } else { |
135 | 135 | return $customer; |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | * @param object $order |
147 | 147 | * @param int $id Stripe session id. |
148 | 148 | */ |
149 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
150 | - if ( is_object( $order ) ) { |
|
151 | - if ( empty( $id ) ) { |
|
149 | + public function get_stripe_return_url($order = null, $id = null) { |
|
150 | + if (is_object($order)) { |
|
151 | + if (empty($id)) { |
|
152 | 152 | $id = uniqid(); |
153 | 153 | } |
154 | 154 | |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | 'order_id' => $order_id, |
160 | 160 | ); |
161 | 161 | |
162 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
162 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
163 | 163 | } |
164 | 164 | |
165 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
165 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -174,27 +174,26 @@ discard block |
||
174 | 174 | * @param object $source |
175 | 175 | * @return array() |
176 | 176 | */ |
177 | - public function generate_payment_request( $order, $source ) { |
|
178 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
179 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
180 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
177 | + public function generate_payment_request($order, $source) { |
|
178 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
179 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
180 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
181 | 181 | $post_data = array(); |
182 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
183 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
182 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
183 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
184 | 184 | /* translators: 1) blog name 2) order number */ |
185 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
185 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
186 | 186 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
187 | 187 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
188 | 188 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
189 | 189 | |
190 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
190 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
191 | 191 | $post_data['receipt_email'] = $billing_email; |
192 | 192 | } |
193 | 193 | |
194 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
195 | - case 'stripe': |
|
196 | - if ( ! empty( $statement_descriptor ) ) { |
|
197 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
194 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
195 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
196 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
198 | 197 | } |
199 | 198 | |
200 | 199 | $post_data['capture'] = $capture ? 'true' : 'false'; |
@@ -204,18 +203,18 @@ discard block |
||
204 | 203 | $post_data['expand[]'] = 'balance_transaction'; |
205 | 204 | |
206 | 205 | $metadata = array( |
207 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
208 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
206 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
207 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
209 | 208 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
210 | 209 | ); |
211 | 210 | |
212 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
211 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
213 | 212 | |
214 | - if ( $source->customer ) { |
|
213 | + if ($source->customer) { |
|
215 | 214 | $post_data['customer'] = $source->customer; |
216 | 215 | } |
217 | 216 | |
218 | - if ( $source->source ) { |
|
217 | + if ($source->source) { |
|
219 | 218 | $post_data['source'] = $source->source; |
220 | 219 | } |
221 | 220 | |
@@ -227,77 +226,77 @@ discard block |
||
227 | 226 | * @param WC_Order $order |
228 | 227 | * @param object $source |
229 | 228 | */ |
230 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
229 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
231 | 230 | } |
232 | 231 | |
233 | 232 | /** |
234 | 233 | * Store extra meta data for an order from a Stripe Response. |
235 | 234 | */ |
236 | - public function process_response( $response, $order ) { |
|
237 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
235 | + public function process_response($response, $order) { |
|
236 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
238 | 237 | |
239 | 238 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
240 | 239 | |
241 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
240 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
242 | 241 | |
243 | 242 | // Store charge data |
244 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
243 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
245 | 244 | |
246 | 245 | // Store other data such as fees |
247 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
246 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
248 | 247 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
249 | 248 | // values are in the local currency of the Stripe account, not from WC. |
250 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
251 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
252 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
253 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
249 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
250 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
251 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
252 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
254 | 253 | } |
255 | 254 | |
256 | - if ( 'yes' === $captured ) { |
|
255 | + if ('yes' === $captured) { |
|
257 | 256 | /** |
258 | 257 | * Charge can be captured but in a pending state. Payment methods |
259 | 258 | * that are asynchronous may take couple days to clear. Webhook will |
260 | 259 | * take care of the status changes. |
261 | 260 | */ |
262 | - if ( 'pending' === $response->status ) { |
|
263 | - if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) { |
|
264 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
261 | + if ('pending' === $response->status) { |
|
262 | + if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) { |
|
263 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
265 | 264 | } |
266 | 265 | |
267 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
266 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
268 | 267 | /* translators: transaction id */ |
269 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
268 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
270 | 269 | } |
271 | 270 | |
272 | - if ( 'succeeded' === $response->status ) { |
|
273 | - $order->payment_complete( $response->id ); |
|
271 | + if ('succeeded' === $response->status) { |
|
272 | + $order->payment_complete($response->id); |
|
274 | 273 | |
275 | 274 | /* translators: transaction id */ |
276 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
277 | - $order->add_order_note( $message ); |
|
275 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
276 | + $order->add_order_note($message); |
|
278 | 277 | } |
279 | 278 | |
280 | - if ( 'failed' === $response->status ) { |
|
281 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
282 | - $order->add_order_note( $localized_message ); |
|
283 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
279 | + if ('failed' === $response->status) { |
|
280 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
281 | + $order->add_order_note($localized_message); |
|
282 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
284 | 283 | } |
285 | 284 | } else { |
286 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
285 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
287 | 286 | |
288 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
289 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
287 | + if ($order->has_status(array('pending', 'failed'))) { |
|
288 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
290 | 289 | } |
291 | 290 | |
292 | 291 | /* translators: transaction id */ |
293 | - $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 ) ); |
|
292 | + $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)); |
|
294 | 293 | } |
295 | 294 | |
296 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
295 | + if (is_callable(array($order, 'save'))) { |
|
297 | 296 | $order->save(); |
298 | 297 | } |
299 | 298 | |
300 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
299 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
301 | 300 | |
302 | 301 | return $response; |
303 | 302 | } |
@@ -310,10 +309,10 @@ discard block |
||
310 | 309 | * @param int $order_id |
311 | 310 | * @return null |
312 | 311 | */ |
313 | - public function send_failed_order_email( $order_id ) { |
|
312 | + public function send_failed_order_email($order_id) { |
|
314 | 313 | $emails = WC()->mailer()->get_emails(); |
315 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
316 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
314 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
315 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
317 | 316 | } |
318 | 317 | } |
319 | 318 | |
@@ -325,7 +324,7 @@ discard block |
||
325 | 324 | * @param object $order |
326 | 325 | * @return object $details |
327 | 326 | */ |
328 | - public function get_owner_details( $order ) { |
|
327 | + public function get_owner_details($order) { |
|
329 | 328 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
330 | 329 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
331 | 330 | |
@@ -336,8 +335,8 @@ discard block |
||
336 | 335 | |
337 | 336 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
338 | 337 | |
339 | - if ( ! empty( $phone ) ) { |
|
340 | - $details['phone'] = $phone; |
|
338 | + if ( ! empty($phone)) { |
|
339 | + $details['phone'] = $phone; |
|
341 | 340 | } |
342 | 341 | |
343 | 342 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -347,7 +346,7 @@ discard block |
||
347 | 346 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
348 | 347 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
349 | 348 | |
350 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
349 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
351 | 350 | } |
352 | 351 | |
353 | 352 | /** |
@@ -356,16 +355,16 @@ discard block |
||
356 | 355 | * @since 4.0.3 |
357 | 356 | */ |
358 | 357 | public function get_source_object() { |
359 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
358 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
360 | 359 | |
361 | - if ( empty( $source ) ) { |
|
360 | + if (empty($source)) { |
|
362 | 361 | return ''; |
363 | 362 | } |
364 | 363 | |
365 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
364 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
366 | 365 | |
367 | - if ( ! empty( $source_object->error ) ) { |
|
368 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
366 | + if ( ! empty($source_object->error)) { |
|
367 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
369 | 368 | } |
370 | 369 | |
371 | 370 | return $source_object; |
@@ -378,11 +377,11 @@ discard block |
||
378 | 377 | * @param object $source_object |
379 | 378 | * @return bool |
380 | 379 | */ |
381 | - public function is_3ds_required( $source_object ) { |
|
380 | + public function is_3ds_required($source_object) { |
|
382 | 381 | return ( |
383 | - $source_object && ! empty( $source_object->card ) ) && |
|
384 | - ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
385 | - ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) |
|
382 | + $source_object && ! empty($source_object->card) ) && |
|
383 | + ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
384 | + ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure) |
|
386 | 385 | ); |
387 | 386 | } |
388 | 387 | |
@@ -393,8 +392,8 @@ discard block |
||
393 | 392 | * @param object $source_object |
394 | 393 | * @return bool |
395 | 394 | */ |
396 | - public function is_3ds_card( $source_object ) { |
|
397 | - return ( $source_object && 'three_d_secure' === $source_object->type ); |
|
395 | + public function is_3ds_card($source_object) { |
|
396 | + return ($source_object && 'three_d_secure' === $source_object->type); |
|
398 | 397 | } |
399 | 398 | |
400 | 399 | /** |
@@ -407,22 +406,22 @@ discard block |
||
407 | 406 | * @param string $return_url |
408 | 407 | * @return mixed |
409 | 408 | */ |
410 | - public function create_3ds_source( $order, $source_object, $return_url = '' ) { |
|
409 | + public function create_3ds_source($order, $source_object, $return_url = '') { |
|
411 | 410 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
412 | 411 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
413 | - $return_url = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url; |
|
412 | + $return_url = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url; |
|
414 | 413 | |
415 | 414 | $post_data = array(); |
416 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
417 | - $post_data['currency'] = strtolower( $currency ); |
|
415 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
416 | + $post_data['currency'] = strtolower($currency); |
|
418 | 417 | $post_data['type'] = 'three_d_secure'; |
419 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
420 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
421 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
418 | + $post_data['owner'] = $this->get_owner_details($order); |
|
419 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
420 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
422 | 421 | |
423 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' ); |
|
422 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source...'); |
|
424 | 423 | |
425 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' ); |
|
424 | + return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources'); |
|
426 | 425 | } |
427 | 426 | |
428 | 427 | /** |
@@ -439,54 +438,54 @@ discard block |
||
439 | 438 | * @throws Exception When card was not added or for and invalid card. |
440 | 439 | * @return object |
441 | 440 | */ |
442 | - public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) { |
|
443 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
441 | + public function prepare_source($source_object = '', $user_id, $force_save_source = false) { |
|
442 | + $customer = new WC_Stripe_Customer($user_id); |
|
444 | 443 | $set_customer = true; |
445 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
444 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
446 | 445 | $source_id = ''; |
447 | 446 | $wc_token_id = false; |
448 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
447 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
449 | 448 | |
450 | 449 | // New CC info was entered and we have a new source to process. |
451 | - if ( ! empty( $source_object ) ) { |
|
450 | + if ( ! empty($source_object)) { |
|
452 | 451 | $source_id = $source_object->id; |
453 | 452 | |
454 | 453 | // This checks to see if customer opted to save the payment method to file. |
455 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
454 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
456 | 455 | |
457 | 456 | /** |
458 | 457 | * This is true if the user wants to store the card to their account. |
459 | 458 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
460 | 459 | * actually reusable. Either that or force_save_source is true. |
461 | 460 | */ |
462 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
463 | - $response = $customer->add_source( $source_object->id ); |
|
461 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
462 | + $response = $customer->add_source($source_object->id); |
|
464 | 463 | |
465 | - if ( ! empty( $response->error ) ) { |
|
466 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
464 | + if ( ! empty($response->error)) { |
|
465 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
467 | 466 | } |
468 | 467 | } |
469 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
468 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
470 | 469 | // Use an existing token, and then process the payment |
471 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
472 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
470 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
471 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
473 | 472 | |
474 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
475 | - WC()->session->set( 'refresh_totals', true ); |
|
476 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
473 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
474 | + WC()->session->set('refresh_totals', true); |
|
475 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
477 | 476 | } |
478 | 477 | |
479 | 478 | $source_id = $wc_token->get_token(); |
480 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
481 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
482 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
479 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
480 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
481 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
483 | 482 | |
484 | 483 | // This is true if the user wants to store the card to their account. |
485 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
486 | - $response = $customer->add_source( $stripe_token ); |
|
484 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
485 | + $response = $customer->add_source($stripe_token); |
|
487 | 486 | |
488 | - if ( ! empty( $response->error ) ) { |
|
489 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
487 | + if ( ! empty($response->error)) { |
|
488 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
490 | 489 | } |
491 | 490 | } else { |
492 | 491 | $set_customer = false; |
@@ -494,7 +493,7 @@ discard block |
||
494 | 493 | } |
495 | 494 | } |
496 | 495 | |
497 | - if ( ! $set_customer ) { |
|
496 | + if ( ! $set_customer) { |
|
498 | 497 | $customer_id = false; |
499 | 498 | } else { |
500 | 499 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
@@ -520,37 +519,37 @@ discard block |
||
520 | 519 | * @param object $order |
521 | 520 | * @return object |
522 | 521 | */ |
523 | - public function prepare_order_source( $order = null ) { |
|
522 | + public function prepare_order_source($order = null) { |
|
524 | 523 | $stripe_customer = new WC_Stripe_Customer(); |
525 | 524 | $stripe_source = false; |
526 | 525 | $token_id = false; |
527 | 526 | |
528 | - if ( $order ) { |
|
527 | + if ($order) { |
|
529 | 528 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
530 | 529 | |
531 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
530 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
532 | 531 | |
533 | - if ( $stripe_customer_id ) { |
|
534 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
532 | + if ($stripe_customer_id) { |
|
533 | + $stripe_customer->set_id($stripe_customer_id); |
|
535 | 534 | } |
536 | 535 | |
537 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
536 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
538 | 537 | |
539 | 538 | // Since 4.0.0, we changed card to source so we need to account for that. |
540 | - if ( empty( $source_id ) ) { |
|
541 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
539 | + if (empty($source_id)) { |
|
540 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
542 | 541 | |
543 | 542 | // Take this opportunity to update the key name. |
544 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
543 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
545 | 544 | |
546 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
545 | + if (is_callable(array($order, 'save'))) { |
|
547 | 546 | $order->save(); |
548 | 547 | } |
549 | 548 | } |
550 | 549 | |
551 | - if ( $source_id ) { |
|
550 | + if ($source_id) { |
|
552 | 551 | $stripe_source = $source_id; |
553 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
552 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
554 | 553 | /* |
555 | 554 | * We can attempt to charge the customer's default source |
556 | 555 | * by sending empty source id. |
@@ -574,27 +573,27 @@ discard block |
||
574 | 573 | * @param WC_Order $order For to which the source applies. |
575 | 574 | * @param stdClass $source Source information. |
576 | 575 | */ |
577 | - public function save_source_to_order( $order, $source ) { |
|
576 | + public function save_source_to_order($order, $source) { |
|
578 | 577 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
579 | 578 | |
580 | 579 | // Store source in the order. |
581 | - if ( $source->customer ) { |
|
582 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
583 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
580 | + if ($source->customer) { |
|
581 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
582 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
584 | 583 | } else { |
585 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
584 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
586 | 585 | } |
587 | 586 | } |
588 | 587 | |
589 | - if ( $source->source ) { |
|
590 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
591 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
588 | + if ($source->source) { |
|
589 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
590 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
592 | 591 | } else { |
593 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
592 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
594 | 593 | } |
595 | 594 | } |
596 | 595 | |
597 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
596 | + if (is_callable(array($order, 'save'))) { |
|
598 | 597 | $order->save(); |
599 | 598 | } |
600 | 599 | } |
@@ -608,27 +607,27 @@ discard block |
||
608 | 607 | * @param object $order The order object |
609 | 608 | * @param int $balance_transaction_id |
610 | 609 | */ |
611 | - public function update_fees( $order, $balance_transaction_id ) { |
|
610 | + public function update_fees($order, $balance_transaction_id) { |
|
612 | 611 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
613 | 612 | |
614 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
613 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
615 | 614 | |
616 | - if ( empty( $balance_transaction->error ) ) { |
|
617 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
615 | + if (empty($balance_transaction->error)) { |
|
616 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
618 | 617 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
619 | 618 | // values are in the local currency of the Stripe account, not from WC. |
620 | - $fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
621 | - $net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
619 | + $fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
620 | + $net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
622 | 621 | |
623 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
624 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
622 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
623 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
625 | 624 | |
626 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
625 | + if (is_callable(array($order, 'save'))) { |
|
627 | 626 | $order->save(); |
628 | 627 | } |
629 | 628 | } |
630 | 629 | } else { |
631 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
630 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
632 | 631 | } |
633 | 632 | } |
634 | 633 | |
@@ -641,33 +640,33 @@ discard block |
||
641 | 640 | * @param float $amount |
642 | 641 | * @return bool |
643 | 642 | */ |
644 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
645 | - $order = wc_get_order( $order_id ); |
|
643 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
644 | + $order = wc_get_order($order_id); |
|
646 | 645 | |
647 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
646 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
648 | 647 | return false; |
649 | 648 | } |
650 | 649 | |
651 | 650 | $request = array(); |
652 | 651 | |
653 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
654 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
655 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
652 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
653 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
654 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
656 | 655 | } else { |
657 | 656 | $order_currency = $order->get_currency(); |
658 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
657 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
659 | 658 | } |
660 | 659 | |
661 | - if ( ! is_null( $amount ) ) { |
|
662 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
660 | + if ( ! is_null($amount)) { |
|
661 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
663 | 662 | } |
664 | 663 | |
665 | 664 | // If order is only authorized, don't pass amount. |
666 | - if ( 'yes' !== $captured ) { |
|
667 | - unset( $request['amount'] ); |
|
665 | + if ('yes' !== $captured) { |
|
666 | + unset($request['amount']); |
|
668 | 667 | } |
669 | 668 | |
670 | - if ( $reason ) { |
|
669 | + if ($reason) { |
|
671 | 670 | $request['metadata'] = array( |
672 | 671 | 'reason' => $reason, |
673 | 672 | ); |
@@ -675,33 +674,33 @@ discard block |
||
675 | 674 | |
676 | 675 | $request['charge'] = $order->get_transaction_id(); |
677 | 676 | |
678 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
677 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
679 | 678 | |
680 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
679 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
681 | 680 | |
682 | - if ( ! empty( $response->error ) ) { |
|
683 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
681 | + if ( ! empty($response->error)) { |
|
682 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
684 | 683 | |
685 | 684 | return $response; |
686 | 685 | |
687 | - } elseif ( ! empty( $response->id ) ) { |
|
688 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
686 | + } elseif ( ! empty($response->id)) { |
|
687 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
689 | 688 | |
690 | - $amount = wc_price( $response->amount / 100 ); |
|
689 | + $amount = wc_price($response->amount / 100); |
|
691 | 690 | |
692 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
693 | - $amount = wc_price( $response->amount ); |
|
691 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
692 | + $amount = wc_price($response->amount); |
|
694 | 693 | } |
695 | 694 | |
696 | - if ( isset( $response->balance_transaction ) ) { |
|
697 | - $this->update_fees( $order, $response->balance_transaction ); |
|
695 | + if (isset($response->balance_transaction)) { |
|
696 | + $this->update_fees($order, $response->balance_transaction); |
|
698 | 697 | } |
699 | 698 | |
700 | 699 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
701 | - $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' ); |
|
700 | + $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'); |
|
702 | 701 | |
703 | - $order->add_order_note( $refund_message ); |
|
704 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
702 | + $order->add_order_note($refund_message); |
|
703 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
705 | 704 | |
706 | 705 | return true; |
707 | 706 | } |
@@ -716,44 +715,44 @@ discard block |
||
716 | 715 | */ |
717 | 716 | public function add_payment_method() { |
718 | 717 | $error = false; |
719 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
718 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
720 | 719 | $source_id = ''; |
721 | 720 | |
722 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
721 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
723 | 722 | $error = true; |
724 | 723 | } |
725 | 724 | |
726 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
725 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
727 | 726 | |
728 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
727 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
729 | 728 | |
730 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
729 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
731 | 730 | |
732 | - if ( isset( $source_object ) ) { |
|
733 | - if ( ! empty( $source_object->error ) ) { |
|
731 | + if (isset($source_object)) { |
|
732 | + if ( ! empty($source_object->error)) { |
|
734 | 733 | $error = true; |
735 | 734 | } |
736 | 735 | |
737 | 736 | $source_id = $source_object->id; |
738 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
739 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
737 | + } elseif (isset($_POST['stripe_token'])) { |
|
738 | + $source_id = wc_clean($_POST['stripe_token']); |
|
740 | 739 | } |
741 | 740 | |
742 | - $response = $stripe_customer->add_source( $source_id ); |
|
741 | + $response = $stripe_customer->add_source($source_id); |
|
743 | 742 | |
744 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
743 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
745 | 744 | $error = true; |
746 | 745 | } |
747 | 746 | |
748 | - if ( $error ) { |
|
749 | - wc_add_notice( $error_msg, 'error' ); |
|
750 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
747 | + if ($error) { |
|
748 | + wc_add_notice($error_msg, 'error'); |
|
749 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
751 | 750 | return; |
752 | 751 | } |
753 | 752 | |
754 | 753 | return array( |
755 | 754 | 'result' => 'success', |
756 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
755 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
757 | 756 | ); |
758 | 757 | } |
759 | 758 | } |
@@ -233,7 +233,6 @@ |
||
233 | 233 | /** |
234 | 234 | * Get a customers saved sources using their Stripe ID. Cached. |
235 | 235 | * |
236 | - * @param string $customer_id |
|
237 | 236 | * @return array |
238 | 237 | */ |
239 | 238 | 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,8 +51,8 @@ discard block |
||
51 | 51 | * Set Stripe customer ID. |
52 | 52 | * @param [type] $id [description] |
53 | 53 | */ |
54 | - public function set_id( $id ) { |
|
55 | - $this->id = wc_clean( $id ); |
|
54 | + public function set_id($id) { |
|
55 | + $this->id = wc_clean($id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | * @return int |
61 | 61 | */ |
62 | 62 | public function get_user_id() { |
63 | - return absint( $this->user_id ); |
|
63 | + return absint($this->user_id); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Set User ID used by WordPress. |
68 | 68 | * @param int $user_id |
69 | 69 | */ |
70 | - public function set_user_id( $user_id ) { |
|
71 | - $this->user_id = absint( $user_id ); |
|
70 | + public function set_user_id($user_id) { |
|
71 | + $this->user_id = absint($user_id); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | * @return WP_User |
77 | 77 | */ |
78 | 78 | protected function get_user() { |
79 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
79 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Store data from the Stripe API about this customer |
84 | 84 | */ |
85 | - public function set_customer_data( $data ) { |
|
85 | + public function set_customer_data($data) { |
|
86 | 86 | $this->customer_data = $data; |
87 | 87 | } |
88 | 88 | |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | * Get data from the Stripe API about this customer |
91 | 91 | */ |
92 | 92 | public function get_customer_data() { |
93 | - $this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() ); |
|
93 | + $this->customer_data = get_transient('stripe_customer_' . $this->get_id()); |
|
94 | 94 | |
95 | - if ( empty( $this->customer_data ) && $this->get_id() && false === $this->customer_data ) { |
|
96 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() ); |
|
95 | + if (empty($this->customer_data) && $this->get_id() && false === $this->customer_data) { |
|
96 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id()); |
|
97 | 97 | |
98 | - if ( empty( $response->error ) ) { |
|
99 | - $this->set_customer_data( $response ); |
|
100 | - set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 ); |
|
98 | + if (empty($response->error)) { |
|
99 | + $this->set_customer_data($response); |
|
100 | + set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $data = $this->get_customer_data(); |
113 | 113 | $source = ''; |
114 | 114 | |
115 | - if ( $data ) { |
|
115 | + if ($data) { |
|
116 | 116 | $source = $data->default_source; |
117 | 117 | } |
118 | 118 | |
@@ -124,13 +124,13 @@ discard block |
||
124 | 124 | * @param array $args |
125 | 125 | * @return WP_Error|int |
126 | 126 | */ |
127 | - public function create_customer( $args = array() ) { |
|
128 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
127 | + public function create_customer($args = array()) { |
|
128 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
129 | 129 | $user = $this->get_user(); |
130 | 130 | |
131 | - if ( $user ) { |
|
132 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
133 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
131 | + if ($user) { |
|
132 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
133 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
134 | 134 | |
135 | 135 | $defaults = array( |
136 | 136 | 'email' => $user->user_email, |
@@ -145,24 +145,24 @@ discard block |
||
145 | 145 | |
146 | 146 | $metadata = array(); |
147 | 147 | |
148 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
148 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
149 | 149 | |
150 | - $args = wp_parse_args( $args, $defaults ); |
|
151 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
150 | + $args = wp_parse_args($args, $defaults); |
|
151 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
152 | 152 | |
153 | - if ( ! empty( $response->error ) ) { |
|
154 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
153 | + if ( ! empty($response->error)) { |
|
154 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
155 | 155 | } |
156 | 156 | |
157 | - $this->set_id( $response->id ); |
|
157 | + $this->set_id($response->id); |
|
158 | 158 | $this->clear_cache(); |
159 | - $this->set_customer_data( $response ); |
|
159 | + $this->set_customer_data($response); |
|
160 | 160 | |
161 | - if ( $this->get_user_id() ) { |
|
162 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
161 | + if ($this->get_user_id()) { |
|
162 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
163 | 163 | } |
164 | 164 | |
165 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
165 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
166 | 166 | |
167 | 167 | return $response->id; |
168 | 168 | } |
@@ -173,72 +173,72 @@ discard block |
||
173 | 173 | * @param bool $retry |
174 | 174 | * @return WP_Error|int |
175 | 175 | */ |
176 | - public function add_source( $source_id, $retry = true ) { |
|
177 | - if ( ! $this->get_id() ) { |
|
178 | - $this->set_id( $this->create_customer() ); |
|
176 | + public function add_source($source_id, $retry = true) { |
|
177 | + if ( ! $this->get_id()) { |
|
178 | + $this->set_id($this->create_customer()); |
|
179 | 179 | } |
180 | 180 | |
181 | - $response = WC_Stripe_API::request( array( |
|
181 | + $response = WC_Stripe_API::request(array( |
|
182 | 182 | 'source' => $source_id, |
183 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
183 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
184 | 184 | |
185 | - if ( ! empty( $response->error ) ) { |
|
185 | + if ( ! empty($response->error)) { |
|
186 | 186 | // It is possible the WC user once was linked to a customer on Stripe |
187 | 187 | // but no longer exists. Instead of failing, lets try to create a |
188 | 188 | // new customer. |
189 | - if ( preg_match( '/No such customer/i', $response->error->message ) ) { |
|
190 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
189 | + if (preg_match('/No such customer/i', $response->error->message)) { |
|
190 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
191 | 191 | $this->create_customer(); |
192 | - return $this->add_source( $source_id, false ); |
|
192 | + return $this->add_source($source_id, false); |
|
193 | 193 | } else { |
194 | 194 | return $response; |
195 | 195 | } |
196 | - } elseif ( empty( $response->id ) ) { |
|
197 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
196 | + } elseif (empty($response->id)) { |
|
197 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | // Add token to WooCommerce. |
201 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
202 | - if ( ! empty( $response->type ) ) { |
|
203 | - switch ( $response->type ) { |
|
201 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
202 | + if ( ! empty($response->type)) { |
|
203 | + switch ($response->type) { |
|
204 | 204 | case 'alipay': |
205 | 205 | break; |
206 | 206 | case 'sepa_debit': |
207 | 207 | $wc_token = new WC_Payment_Token_SEPA(); |
208 | - $wc_token->set_token( $response->id ); |
|
209 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
210 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
208 | + $wc_token->set_token($response->id); |
|
209 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
210 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
211 | 211 | break; |
212 | 212 | default: |
213 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
213 | + if ('source' === $response->object && 'card' === $response->type) { |
|
214 | 214 | $wc_token = new WC_Payment_Token_CC(); |
215 | - $wc_token->set_token( $response->id ); |
|
216 | - $wc_token->set_gateway_id( 'stripe' ); |
|
217 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
218 | - $wc_token->set_last4( $response->card->last4 ); |
|
219 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
220 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
215 | + $wc_token->set_token($response->id); |
|
216 | + $wc_token->set_gateway_id('stripe'); |
|
217 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
218 | + $wc_token->set_last4($response->card->last4); |
|
219 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
220 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
221 | 221 | } |
222 | 222 | break; |
223 | 223 | } |
224 | 224 | } else { |
225 | 225 | // Legacy. |
226 | 226 | $wc_token = new WC_Payment_Token_CC(); |
227 | - $wc_token->set_token( $response->id ); |
|
228 | - $wc_token->set_gateway_id( 'stripe' ); |
|
229 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
230 | - $wc_token->set_last4( $response->last4 ); |
|
231 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
232 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
227 | + $wc_token->set_token($response->id); |
|
228 | + $wc_token->set_gateway_id('stripe'); |
|
229 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
230 | + $wc_token->set_last4($response->last4); |
|
231 | + $wc_token->set_expiry_month($response->exp_month); |
|
232 | + $wc_token->set_expiry_year($response->exp_year); |
|
233 | 233 | } |
234 | 234 | |
235 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
235 | + $wc_token->set_user_id($this->get_user_id()); |
|
236 | 236 | $wc_token->save(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $this->clear_cache(); |
240 | 240 | |
241 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
241 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
242 | 242 | |
243 | 243 | return $response->id; |
244 | 244 | } |
@@ -250,42 +250,42 @@ discard block |
||
250 | 250 | * @return array |
251 | 251 | */ |
252 | 252 | public function get_sources() { |
253 | - if ( ! $this->get_id() ) { |
|
253 | + if ( ! $this->get_id()) { |
|
254 | 254 | return array(); |
255 | 255 | } |
256 | 256 | |
257 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
257 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
258 | 258 | |
259 | - $response = WC_Stripe_API::request( array( |
|
259 | + $response = WC_Stripe_API::request(array( |
|
260 | 260 | 'limit' => 100, |
261 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
261 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
262 | 262 | |
263 | - if ( ! empty( $response->error ) ) { |
|
263 | + if ( ! empty($response->error)) { |
|
264 | 264 | return array(); |
265 | 265 | } |
266 | 266 | |
267 | - if ( is_array( $response->data ) ) { |
|
267 | + if (is_array($response->data)) { |
|
268 | 268 | $sources = $response->data; |
269 | 269 | } |
270 | 270 | |
271 | - return empty( $sources ) ? array() : $sources; |
|
271 | + return empty($sources) ? array() : $sources; |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | 275 | * Delete a source from stripe. |
276 | 276 | * @param string $source_id |
277 | 277 | */ |
278 | - public function delete_source( $source_id ) { |
|
279 | - if ( ! $this->get_id() ) { |
|
278 | + public function delete_source($source_id) { |
|
279 | + if ( ! $this->get_id()) { |
|
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
283 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
283 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
284 | 284 | |
285 | 285 | $this->clear_cache(); |
286 | 286 | |
287 | - if ( empty( $response->error ) ) { |
|
288 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
287 | + if (empty($response->error)) { |
|
288 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
289 | 289 | |
290 | 290 | return true; |
291 | 291 | } |
@@ -297,15 +297,15 @@ discard block |
||
297 | 297 | * Set default source in Stripe |
298 | 298 | * @param string $source_id |
299 | 299 | */ |
300 | - public function set_default_source( $source_id ) { |
|
301 | - $response = WC_Stripe_API::request( array( |
|
302 | - 'default_source' => sanitize_text_field( $source_id ), |
|
303 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
300 | + public function set_default_source($source_id) { |
|
301 | + $response = WC_Stripe_API::request(array( |
|
302 | + 'default_source' => sanitize_text_field($source_id), |
|
303 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
304 | 304 | |
305 | 305 | $this->clear_cache(); |
306 | 306 | |
307 | - if ( empty( $response->error ) ) { |
|
308 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
307 | + if (empty($response->error)) { |
|
308 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
309 | 309 | |
310 | 310 | return true; |
311 | 311 | } |
@@ -317,8 +317,8 @@ discard block |
||
317 | 317 | * Deletes caches for this users cards. |
318 | 318 | */ |
319 | 319 | public function clear_cache() { |
320 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
321 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
320 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
321 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
322 | 322 | $this->customer_data = array(); |
323 | 323 | } |
324 | 324 | } |
@@ -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,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | 127 | if ( |
128 | - 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) |
|
128 | + 'yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency()) |
|
129 | 129 | ) { |
130 | 130 | /* translators: supported currency list */ |
131 | - $message = sprintf( __( 'Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe' ), implode( ', ', $this->get_supported_currency() ) ); |
|
131 | + $message = sprintf(__('Alipay is enabled - it requires store currency to be set to %s', 'woocommerce-gateway-stripe'), implode(', ', $this->get_supported_currency())); |
|
132 | 132 | |
133 | 133 | return $message; |
134 | 134 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return array |
145 | 145 | */ |
146 | 146 | public function get_supported_currency() { |
147 | - return apply_filters( 'wc_stripe_alipay_supported_currencies', array( |
|
147 | + return apply_filters('wc_stripe_alipay_supported_currencies', array( |
|
148 | 148 | 'EUR', |
149 | 149 | 'AUD', |
150 | 150 | 'CAD', |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | 'NZD', |
155 | 155 | 'SGD', |
156 | 156 | 'USD', |
157 | - ) ); |
|
157 | + )); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @return bool |
166 | 166 | */ |
167 | 167 | public function is_available() { |
168 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
168 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
169 | 169 | return false; |
170 | 170 | } |
171 | 171 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | $icons_str .= $icons['alipay']; |
188 | 188 | |
189 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
189 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,19 +196,19 @@ discard block |
||
196 | 196 | * @version 4.0.0 |
197 | 197 | */ |
198 | 198 | public function payment_scripts() { |
199 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
199 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
200 | 200 | return; |
201 | 201 | } |
202 | 202 | |
203 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
204 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
203 | + wp_enqueue_style('stripe_paymentfonts'); |
|
204 | + wp_enqueue_script('woocommerce_stripe'); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
208 | 208 | * Initialize Gateway Settings Form Fields. |
209 | 209 | */ |
210 | 210 | public function init_form_fields() { |
211 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' ); |
|
211 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php'); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -219,25 +219,25 @@ discard block |
||
219 | 219 | $total = WC()->cart->total; |
220 | 220 | |
221 | 221 | // If paying from order, we need to get total from order not cart. |
222 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
223 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
222 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
223 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
224 | 224 | $total = $order->get_total(); |
225 | 225 | } |
226 | 226 | |
227 | - if ( is_add_payment_method_page() ) { |
|
228 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
229 | - $total = ''; |
|
227 | + if (is_add_payment_method_page()) { |
|
228 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
229 | + $total = ''; |
|
230 | 230 | } else { |
231 | 231 | $pay_button_text = ''; |
232 | 232 | } |
233 | 233 | |
234 | 234 | echo '<div |
235 | 235 | id="stripe-alipay-payment-data" |
236 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
237 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
236 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
237 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
238 | 238 | |
239 | - if ( $this->description ) { |
|
240 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
239 | + if ($this->description) { |
|
240 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | echo '</div>'; |
@@ -251,24 +251,24 @@ discard block |
||
251 | 251 | * @param object $order |
252 | 252 | * @return mixed |
253 | 253 | */ |
254 | - public function create_source( $order ) { |
|
254 | + public function create_source($order) { |
|
255 | 255 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
256 | 256 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
257 | - $return_url = $this->get_stripe_return_url( $order ); |
|
257 | + $return_url = $this->get_stripe_return_url($order); |
|
258 | 258 | $post_data = array(); |
259 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
260 | - $post_data['currency'] = strtolower( $currency ); |
|
259 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
260 | + $post_data['currency'] = strtolower($currency); |
|
261 | 261 | $post_data['type'] = 'alipay'; |
262 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
263 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
262 | + $post_data['owner'] = $this->get_owner_details($order); |
|
263 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
264 | 264 | |
265 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
266 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
265 | + if ( ! empty($this->statement_descriptor)) { |
|
266 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
267 | 267 | } |
268 | 268 | |
269 | - WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' ); |
|
269 | + WC_Stripe_Logger::log('Info: Begin creating Alipay source'); |
|
270 | 270 | |
271 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_alipay_source', $post_data, $order ), 'sources' ); |
|
271 | + return WC_Stripe_API::request(apply_filters('wc_stripe_alipay_source', $post_data, $order), 'sources'); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -282,53 +282,53 @@ discard block |
||
282 | 282 | * |
283 | 283 | * @return array|void |
284 | 284 | */ |
285 | - public function process_payment( $order_id, $retry = true, $force_save_save = false ) { |
|
285 | + public function process_payment($order_id, $retry = true, $force_save_save = false) { |
|
286 | 286 | try { |
287 | - $order = wc_get_order( $order_id ); |
|
287 | + $order = wc_get_order($order_id); |
|
288 | 288 | |
289 | 289 | // This will throw exception if not valid. |
290 | - $this->validate_minimum_order_amount( $order ); |
|
290 | + $this->validate_minimum_order_amount($order); |
|
291 | 291 | |
292 | 292 | // This comes from the create account checkbox in the checkout page. |
293 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
293 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
294 | 294 | |
295 | - if ( $create_account ) { |
|
295 | + if ($create_account) { |
|
296 | 296 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
297 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
297 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
298 | 298 | $new_stripe_customer->create_customer(); |
299 | 299 | } |
300 | 300 | |
301 | - $response = $this->create_source( $order ); |
|
301 | + $response = $this->create_source($order); |
|
302 | 302 | |
303 | - if ( ! empty( $response->error ) ) { |
|
304 | - $order->add_order_note( $response->error->message ); |
|
303 | + if ( ! empty($response->error)) { |
|
304 | + $order->add_order_note($response->error->message); |
|
305 | 305 | |
306 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
306 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
310 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
309 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
310 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
311 | 311 | } else { |
312 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
312 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
313 | 313 | $order->save(); |
314 | 314 | } |
315 | 315 | |
316 | - WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); |
|
316 | + WC_Stripe_Logger::log('Info: Redirecting to Alipay...'); |
|
317 | 317 | |
318 | 318 | return array( |
319 | 319 | 'result' => 'success', |
320 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
320 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
321 | 321 | ); |
322 | - } catch ( WC_Stripe_Exception $e ) { |
|
323 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
324 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
322 | + } catch (WC_Stripe_Exception $e) { |
|
323 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
324 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
325 | 325 | |
326 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
326 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
327 | 327 | |
328 | - $statuses = array( 'pending', 'failed' ); |
|
328 | + $statuses = array('pending', 'failed'); |
|
329 | 329 | |
330 | - if ( $order->has_status( $statuses ) ) { |
|
331 | - $this->send_failed_order_email( $order_id ); |
|
330 | + if ($order->has_status($statuses)) { |
|
331 | + $this->send_failed_order_email($order_id); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | return array( |
@@ -162,6 +162,8 @@ |
||
162 | 162 | * |
163 | 163 | * @since 1.0.0 |
164 | 164 | * @version 4.0.0 |
165 | + * @param string $slug |
|
166 | + * @param string $class |
|
165 | 167 | */ |
166 | 168 | public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
167 | 169 | $this->notices[ $slug ] = array( |
@@ -14,20 +14,20 @@ discard block |
||
14 | 14 | * |
15 | 15 | */ |
16 | 16 | |
17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
17 | +if ( ! defined('ABSPATH')) { |
|
18 | 18 | exit; |
19 | 19 | } |
20 | 20 | |
21 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
21 | +if ( ! class_exists('WC_Stripe')) : |
|
22 | 22 | /** |
23 | 23 | * Required minimums and constants |
24 | 24 | */ |
25 | - define( 'WC_STRIPE_VERSION', '4.0.4' ); |
|
26 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
27 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
28 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
29 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
30 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
25 | + define('WC_STRIPE_VERSION', '4.0.4'); |
|
26 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
27 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
28 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
29 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
30 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
31 | 31 | |
32 | 32 | class WC_Stripe { |
33 | 33 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return Singleton The *Singleton* instance. |
48 | 48 | */ |
49 | 49 | public static function get_instance() { |
50 | - if ( null === self::$instance ) { |
|
50 | + if (null === self::$instance) { |
|
51 | 51 | self::$instance = new self(); |
52 | 52 | } |
53 | 53 | return self::$instance; |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | * *Singleton* via the `new` operator from outside of this class. |
81 | 81 | */ |
82 | 82 | private function __construct() { |
83 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
84 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
85 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
86 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
83 | + add_action('admin_init', array($this, 'check_environment')); |
|
84 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
85 | + add_action('plugins_loaded', array($this, 'init')); |
|
86 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -93,43 +93,43 @@ discard block |
||
93 | 93 | * @version 4.0.0 |
94 | 94 | */ |
95 | 95 | public function init() { |
96 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' ); |
|
97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
98 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
99 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
96 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'); |
|
97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
98 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
99 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
100 | 100 | |
101 | 101 | // Don't hook anything else in the plugin if we're in an incompatible environment |
102 | - if ( self::get_environment_warning() ) { |
|
102 | + if (self::get_environment_warning()) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
107 | - |
|
108 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
109 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
111 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
112 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
113 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
123 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
124 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
125 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
106 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
107 | + |
|
108 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
109 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
110 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
111 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
112 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
113 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
123 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
124 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
125 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
126 | 126 | |
127 | 127 | // REMOVE IN THE FUTURE. |
128 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
128 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
129 | 129 | |
130 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
131 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
132 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
130 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
131 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
132 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,23 +139,23 @@ discard block |
||
139 | 139 | * @version 4.0.0 |
140 | 140 | */ |
141 | 141 | public function hide_notices() { |
142 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
143 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
144 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
142 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
143 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
144 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
145 | 145 | } |
146 | 146 | |
147 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
148 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
147 | + if ( ! current_user_can('manage_woocommerce')) { |
|
148 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
149 | 149 | } |
150 | 150 | |
151 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
151 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
152 | 152 | |
153 | - switch ( $notice ) { |
|
153 | + switch ($notice) { |
|
154 | 154 | case 'ssl': |
155 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
155 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
156 | 156 | break; |
157 | 157 | case 'keys': |
158 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
158 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
159 | 159 | break; |
160 | 160 | } |
161 | 161 | } |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * @since 1.0.0 |
168 | 168 | * @version 4.0.0 |
169 | 169 | */ |
170 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
171 | - $this->notices[ $slug ] = array( |
|
170 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
171 | + $this->notices[$slug] = array( |
|
172 | 172 | 'class' => $class, |
173 | 173 | 'message' => $message, |
174 | 174 | 'dismissible' => $dismissible, |
@@ -182,21 +182,21 @@ discard block |
||
182 | 182 | * @version 4.0.0 |
183 | 183 | */ |
184 | 184 | public function admin_notices() { |
185 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
185 | + if ( ! current_user_can('manage_woocommerce')) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
189 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
190 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
189 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
190 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
191 | 191 | |
192 | - if ( $notice['dismissible'] ) { |
|
192 | + if ($notice['dismissible']) { |
|
193 | 193 | ?> |
194 | - <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
194 | + <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
195 | 195 | <?php |
196 | 196 | } |
197 | 197 | |
198 | 198 | echo '<p>'; |
199 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
199 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
200 | 200 | echo '</p></div>'; |
201 | 201 | } |
202 | 202 | } |
@@ -209,26 +209,26 @@ discard block |
||
209 | 209 | * @version 4.0.0 |
210 | 210 | */ |
211 | 211 | public function get_environment_warning() { |
212 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
212 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
213 | 213 | /* translators: 1) int version 2) int version */ |
214 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
214 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
215 | 215 | |
216 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
216 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
217 | 217 | } |
218 | 218 | |
219 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
220 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
219 | + if ( ! defined('WC_VERSION')) { |
|
220 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
221 | 221 | } |
222 | 222 | |
223 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
223 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
224 | 224 | /* translators: 1) int version 2) int version */ |
225 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
225 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
226 | 226 | |
227 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
227 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
228 | 228 | } |
229 | 229 | |
230 | - if ( ! function_exists( 'curl_init' ) ) { |
|
231 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
230 | + if ( ! function_exists('curl_init')) { |
|
231 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | return false; |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | * @return string Setting link |
243 | 243 | */ |
244 | 244 | public function get_setting_link() { |
245 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
245 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
246 | 246 | |
247 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
247 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
248 | 248 | |
249 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
249 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -257,65 +257,65 @@ discard block |
||
257 | 257 | * @version 4.0.0 |
258 | 258 | */ |
259 | 259 | public function check_environment() { |
260 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
260 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
261 | 261 | $this->install(); |
262 | 262 | |
263 | - do_action( 'woocommerce_stripe_updated' ); |
|
263 | + do_action('woocommerce_stripe_updated'); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | $environment_warning = $this->get_environment_warning(); |
267 | 267 | |
268 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
269 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
268 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
269 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
270 | 270 | } |
271 | 271 | |
272 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
273 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
274 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
275 | - $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
|
276 | - $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
|
277 | - $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
|
278 | - $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
|
279 | - $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
|
272 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
273 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
274 | + $options = get_option('woocommerce_stripe_settings'); |
|
275 | + $testmode = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false; |
|
276 | + $test_pub_key = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : ''; |
|
277 | + $test_secret_key = isset($options['test_secret_key']) ? $options['test_secret_key'] : ''; |
|
278 | + $live_pub_key = isset($options['publishable_key']) ? $options['publishable_key'] : ''; |
|
279 | + $live_secret_key = isset($options['secret_key']) ? $options['secret_key'] : ''; |
|
280 | 280 | |
281 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
282 | - $secret = WC_Stripe_API::get_secret_key(); |
|
281 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
282 | + $secret = WC_Stripe_API::get_secret_key(); |
|
283 | 283 | |
284 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
284 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
285 | 285 | $setting_link = $this->get_setting_link(); |
286 | 286 | /* translators: 1) link */ |
287 | - $this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
287 | + $this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | // Check if keys are entered properly per live/test mode. |
291 | - if ( $testmode ) { |
|
291 | + if ($testmode) { |
|
292 | 292 | if ( |
293 | - ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
|
294 | - || ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) |
|
295 | - && ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) |
|
293 | + ! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key) |
|
294 | + || ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key) |
|
295 | + && ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) |
|
296 | 296 | { |
297 | 297 | $setting_link = $this->get_setting_link(); |
298 | 298 | /* translators: 1) link */ |
299 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
299 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
300 | 300 | } |
301 | 301 | } else { |
302 | 302 | if ( |
303 | - ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
|
304 | - || ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) |
|
305 | - && ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) |
|
303 | + ! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key) |
|
304 | + || ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key) |
|
305 | + && ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) |
|
306 | 306 | { |
307 | 307 | $setting_link = $this->get_setting_link(); |
308 | 308 | /* translators: 1) link */ |
309 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
309 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | } |
313 | 313 | |
314 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
314 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
315 | 315 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
316 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
316 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
317 | 317 | /* translators: 1) link 2) link */ |
318 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
|
318 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | } |
@@ -327,8 +327,8 @@ discard block |
||
327 | 327 | * @version 4.0.0 |
328 | 328 | */ |
329 | 329 | public function update_plugin_version() { |
330 | - delete_option( 'wc_stripe_version' ); |
|
331 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
330 | + delete_option('wc_stripe_version'); |
|
331 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | * @version 3.1.0 |
339 | 339 | */ |
340 | 340 | public function install() { |
341 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
342 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
341 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
342 | + define('WC_STRIPE_INSTALLING', true); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | $this->update_plugin_version(); |
@@ -351,13 +351,13 @@ discard block |
||
351 | 351 | * @since 1.0.0 |
352 | 352 | * @version 4.0.0 |
353 | 353 | */ |
354 | - public function plugin_action_links( $links ) { |
|
354 | + public function plugin_action_links($links) { |
|
355 | 355 | $plugin_links = array( |
356 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
357 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
358 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
356 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
357 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
358 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
359 | 359 | ); |
360 | - return array_merge( $plugin_links, $links ); |
|
360 | + return array_merge($plugin_links, $links); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -366,8 +366,8 @@ discard block |
||
366 | 366 | * @since 1.0.0 |
367 | 367 | * @version 4.0.0 |
368 | 368 | */ |
369 | - public function add_gateways( $methods ) { |
|
370 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
369 | + public function add_gateways($methods) { |
|
370 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
371 | 371 | $methods[] = 'WC_Stripe_Compat'; |
372 | 372 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
373 | 373 | } else { |
@@ -392,26 +392,26 @@ discard block |
||
392 | 392 | * @since 4.0.0 |
393 | 393 | * @version 4.0.0 |
394 | 394 | */ |
395 | - public function filter_gateway_order_admin( $sections ) { |
|
396 | - unset( $sections['stripe'] ); |
|
397 | - unset( $sections['stripe_bancontact'] ); |
|
398 | - unset( $sections['stripe_sofort'] ); |
|
399 | - unset( $sections['stripe_giropay'] ); |
|
400 | - unset( $sections['stripe_ideal'] ); |
|
401 | - unset( $sections['stripe_p24'] ); |
|
402 | - unset( $sections['stripe_alipay'] ); |
|
403 | - unset( $sections['stripe_sepa'] ); |
|
404 | - unset( $sections['stripe_bitcoin'] ); |
|
395 | + public function filter_gateway_order_admin($sections) { |
|
396 | + unset($sections['stripe']); |
|
397 | + unset($sections['stripe_bancontact']); |
|
398 | + unset($sections['stripe_sofort']); |
|
399 | + unset($sections['stripe_giropay']); |
|
400 | + unset($sections['stripe_ideal']); |
|
401 | + unset($sections['stripe_p24']); |
|
402 | + unset($sections['stripe_alipay']); |
|
403 | + unset($sections['stripe_sepa']); |
|
404 | + unset($sections['stripe_bitcoin']); |
|
405 | 405 | |
406 | 406 | $sections['stripe'] = 'Stripe'; |
407 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
408 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
409 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
410 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
411 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
412 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
413 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
414 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
407 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
408 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
409 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
410 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
411 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
412 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
413 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
414 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
415 | 415 | |
416 | 416 | return $sections; |
417 | 417 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if ( ! defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * @param string $deprecated Deprecated since WooCommerce 3.0 |
36 | 36 | * @return string |
37 | 37 | */ |
38 | - public function get_display_name( $deprecated = '' ) { |
|
38 | + public function get_display_name($deprecated = '') { |
|
39 | 39 | $display = sprintf( |
40 | 40 | /* translators: last 4 digits of IBAN account */ |
41 | - __( 'SEPA IBAN ending in %s', 'woocommerce-gateway-stripe' ), |
|
41 | + __('SEPA IBAN ending in %s', 'woocommerce-gateway-stripe'), |
|
42 | 42 | $this->get_last4() |
43 | 43 | ); |
44 | 44 | |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | * @return boolean True if the passed data is valid |
67 | 67 | */ |
68 | 68 | public function validate() { |
69 | - if ( false === parent::validate() ) { |
|
69 | + if (false === parent::validate()) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | - if ( ! $this->get_last4( 'edit' ) ) { |
|
73 | + if ( ! $this->get_last4('edit')) { |
|
74 | 74 | return false; |
75 | 75 | } |
76 | 76 | |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * @param string $context |
86 | 86 | * @return string Last 4 digits |
87 | 87 | */ |
88 | - public function get_last4( $context = 'view' ) { |
|
89 | - return $this->get_prop( 'last4', $context ); |
|
88 | + public function get_last4($context = 'view') { |
|
89 | + return $this->get_prop('last4', $context); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @version 4.0.0 |
96 | 96 | * @param string $last4 |
97 | 97 | */ |
98 | - public function set_last4( $last4 ) { |
|
99 | - $this->set_prop( 'last4', $last4 ); |
|
98 | + public function set_last4($last4) { |
|
99 | + $this->set_prop('last4', $last4); |
|
100 | 100 | } |
101 | 101 | } |
@@ -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,11 +21,11 @@ discard block |
||
21 | 21 | public function __construct() { |
22 | 22 | self::$_this = $this; |
23 | 23 | |
24 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
25 | - add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'get_account_saved_payment_methods_list_item_sepa' ), 10, 2 ); |
|
26 | - add_filter( 'woocommerce_get_credit_card_type_label', array( $this, 'normalize_sepa_label' ) ); |
|
27 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
28 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
24 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
25 | + add_filter('woocommerce_payment_methods_list_item', array($this, 'get_account_saved_payment_methods_list_item_sepa'), 10, 2); |
|
26 | + add_filter('woocommerce_get_credit_card_type_label', array($this, 'normalize_sepa_label')); |
|
27 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
28 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | * @param string $label |
47 | 47 | * @return string $label |
48 | 48 | */ |
49 | - public function normalize_sepa_label( $label ) { |
|
50 | - if ( 'sepa iban' === strtolower( $label ) ) { |
|
49 | + public function normalize_sepa_label($label) { |
|
50 | + if ('sepa iban' === strtolower($label)) { |
|
51 | 51 | return 'SEPA IBAN'; |
52 | 52 | } |
53 | 53 | |
@@ -62,67 +62,67 @@ discard block |
||
62 | 62 | * @param array $tokens |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) { |
|
66 | - if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
65 | + public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) { |
|
66 | + if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) { |
|
67 | 67 | $stored_tokens = array(); |
68 | 68 | |
69 | - foreach ( $tokens as $token ) { |
|
69 | + foreach ($tokens as $token) { |
|
70 | 70 | $stored_tokens[] = $token->get_token(); |
71 | 71 | } |
72 | 72 | |
73 | - if ( 'stripe' === $gateway_id ) { |
|
74 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
73 | + if ('stripe' === $gateway_id) { |
|
74 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
75 | 75 | $stripe_sources = $stripe_customer->get_sources(); |
76 | 76 | |
77 | - foreach ( $stripe_sources as $source ) { |
|
78 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
79 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
77 | + foreach ($stripe_sources as $source) { |
|
78 | + if (isset($source->type) && 'card' === $source->type) { |
|
79 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
80 | 80 | $token = new WC_Payment_Token_CC(); |
81 | - $token->set_token( $source->id ); |
|
82 | - $token->set_gateway_id( 'stripe' ); |
|
83 | - |
|
84 | - if ( 'source' === $source->object && 'card' === $source->type ) { |
|
85 | - $token->set_card_type( strtolower( $source->card->brand ) ); |
|
86 | - $token->set_last4( $source->card->last4 ); |
|
87 | - $token->set_expiry_month( $source->card->exp_month ); |
|
88 | - $token->set_expiry_year( $source->card->exp_year ); |
|
81 | + $token->set_token($source->id); |
|
82 | + $token->set_gateway_id('stripe'); |
|
83 | + |
|
84 | + if ('source' === $source->object && 'card' === $source->type) { |
|
85 | + $token->set_card_type(strtolower($source->card->brand)); |
|
86 | + $token->set_last4($source->card->last4); |
|
87 | + $token->set_expiry_month($source->card->exp_month); |
|
88 | + $token->set_expiry_year($source->card->exp_year); |
|
89 | 89 | } |
90 | 90 | |
91 | - $token->set_user_id( $customer_id ); |
|
91 | + $token->set_user_id($customer_id); |
|
92 | 92 | $token->save(); |
93 | - $tokens[ $token->get_id() ] = $token; |
|
93 | + $tokens[$token->get_id()] = $token; |
|
94 | 94 | } |
95 | 95 | } else { |
96 | - if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) { |
|
96 | + if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) { |
|
97 | 97 | $token = new WC_Payment_Token_CC(); |
98 | - $token->set_token( $source->id ); |
|
99 | - $token->set_gateway_id( 'stripe' ); |
|
100 | - $token->set_card_type( strtolower( $source->brand ) ); |
|
101 | - $token->set_last4( $source->last4 ); |
|
102 | - $token->set_expiry_month( $source->exp_month ); |
|
103 | - $token->set_expiry_year( $source->exp_year ); |
|
104 | - $token->set_user_id( $customer_id ); |
|
98 | + $token->set_token($source->id); |
|
99 | + $token->set_gateway_id('stripe'); |
|
100 | + $token->set_card_type(strtolower($source->brand)); |
|
101 | + $token->set_last4($source->last4); |
|
102 | + $token->set_expiry_month($source->exp_month); |
|
103 | + $token->set_expiry_year($source->exp_year); |
|
104 | + $token->set_user_id($customer_id); |
|
105 | 105 | $token->save(); |
106 | - $tokens[ $token->get_id() ] = $token; |
|
106 | + $tokens[$token->get_id()] = $token; |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | - if ( 'stripe_sepa' === $gateway_id ) { |
|
113 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
112 | + if ('stripe_sepa' === $gateway_id) { |
|
113 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
114 | 114 | $stripe_sources = $stripe_customer->get_sources(); |
115 | 115 | |
116 | - foreach ( $stripe_sources as $source ) { |
|
117 | - if ( isset( $source->type ) && 'sepa_debit' === $source->type ) { |
|
118 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
116 | + foreach ($stripe_sources as $source) { |
|
117 | + if (isset($source->type) && 'sepa_debit' === $source->type) { |
|
118 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
119 | 119 | $token = new WC_Payment_Token_SEPA(); |
120 | - $token->set_token( $source->id ); |
|
121 | - $token->set_gateway_id( 'stripe_sepa' ); |
|
122 | - $token->set_last4( $source->sepa_debit->last4 ); |
|
123 | - $token->set_user_id( $customer_id ); |
|
120 | + $token->set_token($source->id); |
|
121 | + $token->set_gateway_id('stripe_sepa'); |
|
122 | + $token->set_last4($source->sepa_debit->last4); |
|
123 | + $token->set_user_id($customer_id); |
|
124 | 124 | $token->save(); |
125 | - $tokens[ $token->get_id() ] = $token; |
|
125 | + $tokens[$token->get_id()] = $token; |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | * @param WC_Payment_Token $payment_token The payment token associated with this method entry |
142 | 142 | * @return array Filtered item |
143 | 143 | */ |
144 | - public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) { |
|
145 | - if ( 'sepa' !== strtolower( $payment_token->get_type() ) ) { |
|
144 | + public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) { |
|
145 | + if ('sepa' !== strtolower($payment_token->get_type())) { |
|
146 | 146 | return $item; |
147 | 147 | } |
148 | 148 | |
149 | 149 | $item['method']['last4'] = $payment_token->get_last4(); |
150 | - $item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' ); |
|
150 | + $item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe'); |
|
151 | 151 | |
152 | 152 | return $item; |
153 | 153 | } |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | * @since 3.1.0 |
159 | 159 | * @version 4.0.0 |
160 | 160 | */ |
161 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
162 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
163 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
164 | - $stripe_customer->delete_source( $token->get_token() ); |
|
161 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
162 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
163 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
164 | + $stripe_customer->delete_source($token->get_token()); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -171,12 +171,12 @@ discard block |
||
171 | 171 | * @since 3.1.0 |
172 | 172 | * @version 4.0.0 |
173 | 173 | */ |
174 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
175 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
174 | + public function woocommerce_payment_token_set_default($token_id) { |
|
175 | + $token = WC_Payment_Tokens::get($token_id); |
|
176 | 176 | |
177 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
178 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
179 | - $stripe_customer->set_default_source( $token->get_token() ); |
|
177 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
178 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
179 | + $stripe_customer->set_default_source($token->get_token()); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -20,23 +20,23 @@ discard block |
||
20 | 20 | * @since 4.0.0 |
21 | 21 | * @version 4.0.0 |
22 | 22 | */ |
23 | - public static function log( $message, $start_time = null, $end_time = null ) { |
|
24 | - if ( empty( self::$logger ) ) { |
|
23 | + public static function log($message, $start_time = null, $end_time = null) { |
|
24 | + if (empty(self::$logger)) { |
|
25 | 25 | self::$logger = new WC_Logger(); |
26 | 26 | } |
27 | 27 | |
28 | - $settings = get_option( 'woocommerce_stripe_settings' ); |
|
28 | + $settings = get_option('woocommerce_stripe_settings'); |
|
29 | 29 | |
30 | - if ( empty( $settings ) || isset( $settings['logging'] ) && 'yes' !== $settings['logging'] ) { |
|
30 | + if (empty($settings) || isset($settings['logging']) && 'yes' !== $settings['logging']) { |
|
31 | 31 | return; |
32 | 32 | } |
33 | 33 | |
34 | - if ( ! is_null( $start_time ) ) { |
|
34 | + if ( ! is_null($start_time)) { |
|
35 | 35 | |
36 | - $formatted_start_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $start_time ); |
|
37 | - $end_time = is_null( $end_time ) ? current_time( 'timestamp' ) : $end_time; |
|
38 | - $formatted_end_time = date_i18n( get_option( 'date_format' ) . ' g:ia', $end_time ); |
|
39 | - $elapsed_time = round( abs( $end_time - $start_time ) / 60, 2 ); |
|
36 | + $formatted_start_time = date_i18n(get_option('date_format') . ' g:ia', $start_time); |
|
37 | + $end_time = is_null($end_time) ? current_time('timestamp') : $end_time; |
|
38 | + $formatted_end_time = date_i18n(get_option('date_format') . ' g:ia', $end_time); |
|
39 | + $elapsed_time = round(abs($end_time - $start_time) / 60, 2); |
|
40 | 40 | |
41 | 41 | $log_entry = '====Start Log ' . $formatted_start_time . '====' . "\n" . $message . "\n"; |
42 | 42 | $log_entry .= '====End Log ' . $formatted_end_time . ' (' . $elapsed_time . ')====' . "\n\n"; |
@@ -47,6 +47,6 @@ discard block |
||
47 | 47 | |
48 | 48 | } |
49 | 49 | |
50 | - self::$logger->add( self::WC_LOG_FILENAME, $log_entry ); |
|
50 | + self::$logger->add(self::WC_LOG_FILENAME, $log_entry); |
|
51 | 51 | } |
52 | 52 | } |
@@ -1,50 +1,50 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | $webhook_url = WC_Stripe_Helper::get_webhook_url(); |
7 | 7 | |
8 | -return apply_filters( 'wc_stripe_bitcoin_settings', |
|
8 | +return apply_filters('wc_stripe_bitcoin_settings', |
|
9 | 9 | array( |
10 | 10 | 'geo_target' => array( |
11 | - 'description' => __( 'Relevant Payer Geography: Global', 'woocommerce-gateway-stripe' ), |
|
11 | + 'description' => __('Relevant Payer Geography: Global', 'woocommerce-gateway-stripe'), |
|
12 | 12 | 'type' => 'title', |
13 | 13 | ), |
14 | 14 | 'guide' => array( |
15 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#bitcoin" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
15 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#bitcoin" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
16 | 16 | 'type' => 'title', |
17 | 17 | ), |
18 | 18 | 'activation' => array( |
19 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
19 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'type' => 'title', |
21 | 21 | ), |
22 | 22 | 'enabled' => array( |
23 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
24 | - 'label' => __( 'Enable Stripe Bitcoin', 'woocommerce-gateway-stripe' ), |
|
23 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
24 | + 'label' => __('Enable Stripe Bitcoin', 'woocommerce-gateway-stripe'), |
|
25 | 25 | 'type' => 'checkbox', |
26 | 26 | 'description' => '', |
27 | 27 | 'default' => 'no', |
28 | 28 | ), |
29 | 29 | 'title' => array( |
30 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
30 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
31 | 31 | 'type' => 'text', |
32 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
33 | - 'default' => __( 'Bitcoin', 'woocommerce-gateway-stripe' ), |
|
32 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
33 | + 'default' => __('Bitcoin', 'woocommerce-gateway-stripe'), |
|
34 | 34 | 'desc_tip' => true, |
35 | 35 | ), |
36 | 36 | 'description' => array( |
37 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
37 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
38 | 38 | 'type' => 'text', |
39 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
40 | - 'default' => __( 'Bitcoin payment information will be provided when you place the order.', 'woocommerce-gateway-stripe' ), |
|
39 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
40 | + 'default' => __('Bitcoin payment information will be provided when you place the order.', 'woocommerce-gateway-stripe'), |
|
41 | 41 | 'desc_tip' => true, |
42 | 42 | ), |
43 | 43 | 'webhook' => array( |
44 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
44 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
45 | 45 | 'type' => 'title', |
46 | 46 | /* translators: webhook URL */ |
47 | - 'description' => sprintf( __( 'You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe' ), $webhook_url ), |
|
47 | + 'description' => sprintf(__('You must add the webhook endpoint <strong style="background-color:#ddd;"> %s </strong> to your Stripe Account Settings <a href="https://dashboard.stripe.com/account/webhooks" target="_blank">Here</a> so you can receive notifications on the charge statuses.', 'woocommerce-gateway-stripe'), $webhook_url), |
|
48 | 48 | ), |
49 | 49 | ) |
50 | 50 | ); |