@@ -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; |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public static function get_headers() { |
70 | 70 | return array( |
71 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
71 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
72 | 72 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
73 | 73 | 'Idempotency-Key' => uniqid(), |
74 | - 'X-Stripe-Client-User-Agent' => json_encode( self::get_user_agent() ), |
|
74 | + 'X-Stripe-Client-User-Agent' => json_encode(self::get_user_agent()), |
|
75 | 75 | ); |
76 | 76 | } |
77 | 77 | |
@@ -82,35 +82,35 @@ discard block |
||
82 | 82 | * @param string $api |
83 | 83 | * @return array|WP_Error |
84 | 84 | */ |
85 | - public static function request( $request, $api = 'charges', $method = 'POST' ) { |
|
86 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
85 | + public static function request($request, $api = 'charges', $method = 'POST') { |
|
86 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
87 | 87 | |
88 | 88 | $response = wp_safe_remote_post( |
89 | 89 | self::ENDPOINT . $api, |
90 | 90 | array( |
91 | 91 | 'method' => $method, |
92 | 92 | 'headers' => self::get_headers(), |
93 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
93 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
94 | 94 | 'timeout' => 70, |
95 | 95 | 'user-agent' => 'WooCommerce ' . WC()->version, |
96 | 96 | ) |
97 | 97 | ); |
98 | 98 | |
99 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
100 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
101 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
99 | + if (is_wp_error($response) || empty($response['body'])) { |
|
100 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
101 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
102 | 102 | } |
103 | 103 | |
104 | - $parsed_response = json_decode( $response['body'] ); |
|
104 | + $parsed_response = json_decode($response['body']); |
|
105 | 105 | |
106 | 106 | // Handle response |
107 | - if ( ! empty( $parsed_response->error ) ) { |
|
108 | - if ( ! empty( $parsed_response->error->code ) ) { |
|
107 | + if ( ! empty($parsed_response->error)) { |
|
108 | + if ( ! empty($parsed_response->error->code)) { |
|
109 | 109 | $code = $parsed_response->error->code; |
110 | 110 | } else { |
111 | 111 | $code = 'stripe_error'; |
112 | 112 | } |
113 | - return new WP_Error( $code, $parsed_response->error->message ); |
|
113 | + return new WP_Error($code, $parsed_response->error->message); |
|
114 | 114 | } else { |
115 | 115 | return $parsed_response; |
116 | 116 | } |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | * @version 4.0.0 |
124 | 124 | * @param string $api |
125 | 125 | */ |
126 | - public static function retrieve( $api ) { |
|
127 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
126 | + public static function retrieve($api) { |
|
127 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
128 | 128 | |
129 | 129 | $ua = self::get_user_agent(); |
130 | 130 | |
@@ -138,21 +138,21 @@ discard block |
||
138 | 138 | ) |
139 | 139 | ); |
140 | 140 | |
141 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
142 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
143 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
141 | + if (is_wp_error($response) || empty($response['body'])) { |
|
142 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
143 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
144 | 144 | } |
145 | 145 | |
146 | - $parsed_response = json_decode( $response['body'] ); |
|
146 | + $parsed_response = json_decode($response['body']); |
|
147 | 147 | |
148 | 148 | // Handle response |
149 | - if ( ! empty( $parsed_response->error ) ) { |
|
150 | - if ( ! empty( $parsed_response->error->code ) ) { |
|
149 | + if ( ! empty($parsed_response->error)) { |
|
150 | + if ( ! empty($parsed_response->error->code)) { |
|
151 | 151 | $code = $parsed_response->error->code; |
152 | 152 | } else { |
153 | 153 | $code = 'stripe_error'; |
154 | 154 | } |
155 | - return new WP_Error( $code, $parsed_response->error->message ); |
|
155 | + return new WP_Error($code, $parsed_response->error->message); |
|
156 | 156 | } else { |
157 | 157 | return $parsed_response; |
158 | 158 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @version 3.1.0 |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if ( ! defined('ABSPATH')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | * Initialize class actions. |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
23 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
24 | 24 | |
25 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
26 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
27 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
28 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
25 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
26 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
27 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
28 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | * @return bool |
35 | 35 | */ |
36 | 36 | protected function is_activated() { |
37 | - $options = get_option( 'woocommerce_stripe_settings', array() ); |
|
38 | - $enabled = isset( $options['enabled'] ) && 'yes' === $options['enabled']; |
|
39 | - $stripe_checkout = isset( $options['stripe_checkout'] ) && 'yes' !== $options['stripe_checkout']; |
|
40 | - $request_payment_api = isset( $options['request_payment_api'] ) && 'yes' === $options['request_payment_api']; |
|
37 | + $options = get_option('woocommerce_stripe_settings', array()); |
|
38 | + $enabled = isset($options['enabled']) && 'yes' === $options['enabled']; |
|
39 | + $stripe_checkout = isset($options['stripe_checkout']) && 'yes' !== $options['stripe_checkout']; |
|
40 | + $request_payment_api = isset($options['request_payment_api']) && 'yes' === $options['request_payment_api']; |
|
41 | 41 | |
42 | 42 | return $enabled && $stripe_checkout && $request_payment_api && is_ssl(); |
43 | 43 | } |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | * @return string |
49 | 49 | */ |
50 | 50 | protected function get_publishable_key() { |
51 | - $options = get_option( 'woocommerce_stripe_settings', array() ); |
|
51 | + $options = get_option('woocommerce_stripe_settings', array()); |
|
52 | 52 | |
53 | - if ( empty( $options ) ) { |
|
53 | + if (empty($options)) { |
|
54 | 54 | return ''; |
55 | 55 | } |
56 | 56 | |
@@ -62,39 +62,39 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function scripts() { |
64 | 64 | // Load PaymentRequest only on cart for now. |
65 | - if ( ! is_cart() ) { |
|
65 | + if ( ! is_cart()) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | - if ( ! $this->is_activated() ) { |
|
69 | + if ( ! $this->is_activated()) { |
|
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
73 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
74 | 74 | |
75 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
76 | - wp_enqueue_script( 'google-payment-request-shim', 'https://storage.googleapis.com/prshim/v1/payment-shim.js', '', '1.0', false ); |
|
77 | - wp_enqueue_script( 'wc-stripe-payment-request', plugins_url( 'assets/js/payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
75 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
76 | + wp_enqueue_script('google-payment-request-shim', 'https://storage.googleapis.com/prshim/v1/payment-shim.js', '', '1.0', false); |
|
77 | + wp_enqueue_script('wc-stripe-payment-request', plugins_url('assets/js/payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
78 | 78 | |
79 | 79 | wp_localize_script( |
80 | 80 | 'wc-stripe-payment-request', |
81 | 81 | 'wcStripePaymentRequestParams', |
82 | 82 | array( |
83 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
83 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
84 | 84 | 'stripe' => array( |
85 | 85 | 'key' => $this->get_publishable_key(), |
86 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
86 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
87 | 87 | ), |
88 | 88 | 'nonce' => array( |
89 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
90 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
91 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
92 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
89 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
90 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
91 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
92 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
93 | 93 | ), |
94 | 94 | 'i18n' => array( |
95 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
95 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
96 | 96 | /* translators: Do not translate the [option] placeholder */ |
97 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
97 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
98 | 98 | ), |
99 | 99 | ) |
100 | 100 | ); |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | * Get cart details. |
105 | 105 | */ |
106 | 106 | public function ajax_get_cart_details() { |
107 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
107 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
108 | 108 | |
109 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
110 | - define( 'WOOCOMMERCE_CART', true ); |
|
109 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
110 | + define('WOOCOMMERCE_CART', true); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | WC()->cart->calculate_totals(); |
@@ -119,18 +119,18 @@ discard block |
||
119 | 119 | 'shipping_required' => WC()->cart->needs_shipping(), |
120 | 120 | 'order_data' => array( |
121 | 121 | 'total' => array( |
122 | - 'label' => __( 'Total', 'woocommerce-gateway-stripe' ), |
|
122 | + 'label' => __('Total', 'woocommerce-gateway-stripe'), |
|
123 | 123 | 'amount' => array( |
124 | - 'value' => max( 0, apply_filters( 'woocommerce_calculated_total', round( WC()->cart->cart_contents_total + WC()->cart->fee_total + WC()->cart->tax_total, WC()->cart->dp ), WC()->cart ) ), |
|
124 | + 'value' => max(0, apply_filters('woocommerce_calculated_total', round(WC()->cart->cart_contents_total + WC()->cart->fee_total + WC()->cart->tax_total, WC()->cart->dp), WC()->cart)), |
|
125 | 125 | 'currency' => $currency, |
126 | 126 | ), |
127 | 127 | ), |
128 | 128 | // Include line items such as subtotal, fees and taxes. No shipping option is provided here because it is not chosen yet. |
129 | - 'displayItems' => $this->compute_display_items( null ), |
|
129 | + 'displayItems' => $this->compute_display_items(null), |
|
130 | 130 | ), |
131 | 131 | ); |
132 | 132 | |
133 | - wp_send_json( $data ); |
|
133 | + wp_send_json($data); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @version 3.2.0 |
141 | 141 | * @param array $address |
142 | 142 | */ |
143 | - public function calculate_shipping( $address = array() ) { |
|
143 | + public function calculate_shipping($address = array()) { |
|
144 | 144 | global $states; |
145 | 145 | |
146 | 146 | $country = $address['country']; |
@@ -157,28 +157,28 @@ discard block |
||
157 | 157 | * In some versions of Chrome, state can be a full name. So we need |
158 | 158 | * to convert that to abbreviation as WC is expecting that. |
159 | 159 | */ |
160 | - if ( 2 < strlen( $state ) ) { |
|
161 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
160 | + if (2 < strlen($state)) { |
|
161 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | WC()->shipping->reset_shipping(); |
165 | 165 | |
166 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
167 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
166 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
167 | + $postcode = wc_format_postcode($postcode, $country); |
|
168 | 168 | } |
169 | 169 | |
170 | - if ( $country ) { |
|
171 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
172 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
170 | + if ($country) { |
|
171 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
172 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
173 | 173 | } else { |
174 | 174 | WC()->customer->set_to_base(); |
175 | 175 | WC()->customer->set_shipping_to_base(); |
176 | 176 | } |
177 | 177 | |
178 | - if ( version_compare( WC_VERSION, '3.0', '<' ) ) { |
|
179 | - WC()->customer->calculated_shipping( true ); |
|
178 | + if (version_compare(WC_VERSION, '3.0', '<')) { |
|
179 | + WC()->customer->calculated_shipping(true); |
|
180 | 180 | } else { |
181 | - WC()->customer->set_calculated_shipping( true ); |
|
181 | + WC()->customer->set_calculated_shipping(true); |
|
182 | 182 | WC()->customer->save(); |
183 | 183 | } |
184 | 184 | |
@@ -195,17 +195,17 @@ discard block |
||
195 | 195 | $packages[0]['destination']['address'] = $address_1; |
196 | 196 | $packages[0]['destination']['address_2'] = $address_2; |
197 | 197 | |
198 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
199 | - if ( $item['data']->needs_shipping() ) { |
|
200 | - if ( isset( $item['line_total'] ) ) { |
|
198 | + foreach (WC()->cart->get_cart() as $item) { |
|
199 | + if ($item['data']->needs_shipping()) { |
|
200 | + if (isset($item['line_total'])) { |
|
201 | 201 | $packages[0]['contents_cost'] += $item['line_total']; |
202 | 202 | } |
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
206 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
207 | 207 | |
208 | - WC()->shipping->calculate_shipping( $packages ); |
|
208 | + WC()->shipping->calculate_shipping($packages); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -216,19 +216,19 @@ discard block |
||
216 | 216 | * @see WC_Shipping::get_packages(). |
217 | 217 | */ |
218 | 218 | public function ajax_get_shipping_options() { |
219 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
219 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
220 | 220 | |
221 | 221 | // Set the shipping package. |
222 | - $posted = filter_input_array( INPUT_POST, array( |
|
222 | + $posted = filter_input_array(INPUT_POST, array( |
|
223 | 223 | 'country' => FILTER_SANITIZE_STRING, |
224 | 224 | 'state' => FILTER_SANITIZE_STRING, |
225 | 225 | 'postcode' => FILTER_SANITIZE_STRING, |
226 | 226 | 'city' => FILTER_SANITIZE_STRING, |
227 | 227 | 'address' => FILTER_SANITIZE_STRING, |
228 | 228 | 'address_2' => FILTER_SANITIZE_STRING, |
229 | - ) ); |
|
229 | + )); |
|
230 | 230 | |
231 | - $this->calculate_shipping( $posted ); |
|
231 | + $this->calculate_shipping($posted); |
|
232 | 232 | |
233 | 233 | // Set the shipping options. |
234 | 234 | $currency = get_woocommerce_currency(); |
@@ -236,13 +236,13 @@ discard block |
||
236 | 236 | |
237 | 237 | $packages = WC()->shipping->get_packages(); |
238 | 238 | |
239 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
240 | - foreach ( $packages as $package_key => $package ) { |
|
241 | - if ( empty( $package['rates'] ) ) { |
|
239 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
240 | + foreach ($packages as $package_key => $package) { |
|
241 | + if (empty($package['rates'])) { |
|
242 | 242 | break; |
243 | 243 | } |
244 | 244 | |
245 | - foreach ( $package['rates'] as $key => $rate ) { |
|
245 | + foreach ($package['rates'] as $key => $rate) { |
|
246 | 246 | $data[] = array( |
247 | 247 | 'id' => $rate->id, |
248 | 248 | 'label' => $rate->label, |
@@ -257,55 +257,55 @@ discard block |
||
257 | 257 | } |
258 | 258 | |
259 | 259 | // Auto select when have only one shipping method available. |
260 | - if ( 1 === count( $data ) ) { |
|
260 | + if (1 === count($data)) { |
|
261 | 261 | $data[0]['selected'] = true; |
262 | 262 | } |
263 | 263 | |
264 | - wp_send_json( $data ); |
|
264 | + wp_send_json($data); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
268 | 268 | * Update shipping method. |
269 | 269 | */ |
270 | 270 | public function ajax_update_shipping_method() { |
271 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
271 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
272 | 272 | |
273 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
274 | - define( 'WOOCOMMERCE_CART', true ); |
|
273 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
274 | + define('WOOCOMMERCE_CART', true); |
|
275 | 275 | } |
276 | 276 | |
277 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
278 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
277 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
278 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
279 | 279 | |
280 | - if ( is_array( $shipping_method ) ) { |
|
281 | - foreach ( $shipping_method as $i => $value ) { |
|
282 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
280 | + if (is_array($shipping_method)) { |
|
281 | + foreach ($shipping_method as $i => $value) { |
|
282 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
286 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
287 | 287 | |
288 | 288 | WC()->cart->calculate_totals(); |
289 | 289 | |
290 | 290 | // Send back the new cart total and line items to be displayed, such as subtotal, shipping rate(s), fees and taxes. |
291 | - $data = array( |
|
291 | + $data = array( |
|
292 | 292 | 'total' => WC()->cart->total, |
293 | - 'items' => $this->compute_display_items( $shipping_method[0] ), |
|
293 | + 'items' => $this->compute_display_items($shipping_method[0]), |
|
294 | 294 | ); |
295 | 295 | |
296 | - wp_send_json( $data ); |
|
296 | + wp_send_json($data); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
300 | 300 | * Create order. |
301 | 301 | */ |
302 | 302 | public function ajax_create_order() { |
303 | - if ( WC()->cart->is_empty() ) { |
|
304 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
303 | + if (WC()->cart->is_empty()) { |
|
304 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
305 | 305 | } |
306 | 306 | |
307 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
308 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
307 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
308 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | $_POST['terms'] = 1; |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | |
314 | 314 | WC()->checkout()->process_checkout(); |
315 | 315 | |
316 | - die( 0 ); |
|
316 | + die(0); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -321,26 +321,26 @@ discard block |
||
321 | 321 | * |
322 | 322 | * @param string shipping_method_id If shipping method ID is provided, will include display items about shipping. |
323 | 323 | */ |
324 | - protected function compute_display_items( $shipping_method_id ) { |
|
324 | + protected function compute_display_items($shipping_method_id) { |
|
325 | 325 | $currency = get_woocommerce_currency(); |
326 | 326 | $items = array( |
327 | 327 | // Subtotal excluding tax, because taxes is a separate item, below. |
328 | 328 | array( |
329 | - 'label' => __( 'Subtotal', 'woocommerce-gateway-stripe' ), |
|
329 | + 'label' => __('Subtotal', 'woocommerce-gateway-stripe'), |
|
330 | 330 | 'amount' => array( |
331 | - 'value' => max( 0, round( WC()->cart->subtotal_ex_tax, WC()->cart->dp ) ), |
|
331 | + 'value' => max(0, round(WC()->cart->subtotal_ex_tax, WC()->cart->dp)), |
|
332 | 332 | 'currency' => $currency, |
333 | 333 | ), |
334 | 334 | ), |
335 | 335 | ); |
336 | 336 | // If a chosen shipping option was provided, add line item(s) for it and include the shipping tax. |
337 | - $tax_total = max( 0, round( WC()->cart->tax_total, WC()->cart->dp ) ); |
|
338 | - if ( $shipping_method_id ) { |
|
339 | - $tax_total = max( 0, round( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ) ); |
|
337 | + $tax_total = max(0, round(WC()->cart->tax_total, WC()->cart->dp)); |
|
338 | + if ($shipping_method_id) { |
|
339 | + $tax_total = max(0, round(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp)); |
|
340 | 340 | // Look through the package rates for $shipping_method_id, and when found, add a line item. |
341 | - foreach ( WC()->shipping->get_packages() as $package_key => $package ) { |
|
342 | - foreach ( $package['rates'] as $key => $rate ) { |
|
343 | - if ( $rate->id == $shipping_method_id ) { |
|
341 | + foreach (WC()->shipping->get_packages() as $package_key => $package) { |
|
342 | + foreach ($package['rates'] as $key => $rate) { |
|
343 | + if ($rate->id == $shipping_method_id) { |
|
344 | 344 | $items[] = array( |
345 | 345 | 'label' => $rate->label, |
346 | 346 | 'amount' => array( |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | } |
355 | 355 | } |
356 | 356 | // Include fees and taxes as display items. |
357 | - foreach ( WC()->cart->fees as $key => $fee ) { |
|
357 | + foreach (WC()->cart->fees as $key => $fee) { |
|
358 | 358 | $items[] = array( |
359 | 359 | 'label' => $fee->name, |
360 | 360 | 'amount' => array( |
@@ -364,9 +364,9 @@ discard block |
||
364 | 364 | ); |
365 | 365 | } |
366 | 366 | // The tax total may include the shipping taxes if a shipping option is provided. |
367 | - if ( 0 < $tax_total ) { |
|
367 | + if (0 < $tax_total) { |
|
368 | 368 | $items[] = array( |
369 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
369 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
370 | 370 | 'amount' => array( |
371 | 371 | 'currency' => $currency, |
372 | 372 | 'value' => $tax_total, |
@@ -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 | |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * Check if this gateway is enabled |
16 | 16 | */ |
17 | 17 | public function is_available() { |
18 | - if ( 'yes' === $this->enabled ) { |
|
19 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
18 | + if ('yes' === $this->enabled) { |
|
19 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
20 | 20 | return false; |
21 | 21 | } |
22 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
22 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
23 | 23 | return false; |
24 | 24 | } |
25 | 25 | return true; |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | * @since 4.0.0 |
34 | 34 | * @version 4.0.0 |
35 | 35 | */ |
36 | - public function add_admin_notice( $slug, $class, $message ) { |
|
37 | - $this->notices[ $slug ] = array( |
|
36 | + public function add_admin_notice($slug, $class, $message) { |
|
37 | + $this->notices[$slug] = array( |
|
38 | 38 | 'class' => $class, |
39 | 39 | 'message' => $message, |
40 | 40 | ); |
@@ -46,14 +46,14 @@ discard block |
||
46 | 46 | * @since 4.0.0 |
47 | 47 | * @version 4.0.0 |
48 | 48 | */ |
49 | - public function get_transaction_url( $order ) { |
|
50 | - if ( $this->testmode ) { |
|
49 | + public function get_transaction_url($order) { |
|
50 | + if ($this->testmode) { |
|
51 | 51 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
52 | 52 | } else { |
53 | 53 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
54 | 54 | } |
55 | 55 | |
56 | - return parent::get_transaction_url( $order ); |
|
56 | + return parent::get_transaction_url($order); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | * @param object $order |
65 | 65 | * @param int $id Stripe session id. |
66 | 66 | */ |
67 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
68 | - if ( is_object( $order ) ) { |
|
69 | - if ( empty( $id ) ) { |
|
67 | + public function get_stripe_return_url($order = null, $id = null) { |
|
68 | + if (is_object($order)) { |
|
69 | + if (empty($id)) { |
|
70 | 70 | $id = uniqid(); |
71 | 71 | } |
72 | 72 | |
73 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
73 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
74 | 74 | |
75 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1', 'stripe_session_id' => $id, 'order_id' => $order_id ), $this->get_return_url( $order ) ) ); |
|
75 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1', 'stripe_session_id' => $id, 'order_id' => $order_id), $this->get_return_url($order))); |
|
76 | 76 | } |
77 | 77 | |
78 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
78 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -87,44 +87,44 @@ discard block |
||
87 | 87 | * @param object $source |
88 | 88 | * @return array() |
89 | 89 | */ |
90 | - public function generate_payment_request( $order, $source ) { |
|
91 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
92 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? $settings['statement_descriptor'] : ''; |
|
93 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
90 | + public function generate_payment_request($order, $source) { |
|
91 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
92 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? $settings['statement_descriptor'] : ''; |
|
93 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
94 | 94 | $post_data = array(); |
95 | - $post_data['currency'] = strtolower( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ); |
|
96 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
97 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), $statement_descriptor, $order->get_order_number() ); |
|
95 | + $post_data['currency'] = strtolower(version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency()); |
|
96 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
97 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), $statement_descriptor, $order->get_order_number()); |
|
98 | 98 | $post_data['capture'] = $capture ? 'true' : 'false'; |
99 | 99 | |
100 | - $billing_email = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
101 | - $billing_first_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
102 | - $billing_last_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
100 | + $billing_email = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
101 | + $billing_first_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
102 | + $billing_last_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
103 | 103 | |
104 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
104 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
105 | 105 | $post_data['receipt_email'] = $billing_email; |
106 | 106 | } |
107 | 107 | |
108 | - switch ( $order->get_payment_method() ) { |
|
108 | + switch ($order->get_payment_method()) { |
|
109 | 109 | case 'stripe': |
110 | - $post_data['statement_descriptor'] = substr( str_replace( "'", '', $statement_descriptor ), 0, 22 ); |
|
110 | + $post_data['statement_descriptor'] = substr(str_replace("'", '', $statement_descriptor), 0, 22); |
|
111 | 111 | break; |
112 | 112 | } |
113 | 113 | |
114 | 114 | $post_data['expand[]'] = 'balance_transaction'; |
115 | 115 | |
116 | 116 | $metadata = array( |
117 | - __( 'Customer Name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
118 | - __( 'Customer Email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
117 | + __('Customer Name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
118 | + __('Customer Email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
119 | 119 | ); |
120 | 120 | |
121 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
121 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
122 | 122 | |
123 | - if ( $source->customer ) { |
|
123 | + if ($source->customer) { |
|
124 | 124 | $post_data['customer'] = $source->customer; |
125 | 125 | } |
126 | 126 | |
127 | - if ( $source->source ) { |
|
127 | + if ($source->source) { |
|
128 | 128 | $post_data['source'] = $source->source; |
129 | 129 | } |
130 | 130 | |
@@ -136,50 +136,50 @@ discard block |
||
136 | 136 | * @param WC_Order $order |
137 | 137 | * @param object $source |
138 | 138 | */ |
139 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
139 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | 143 | * Store extra meta data for an order from a Stripe Response. |
144 | 144 | */ |
145 | - public function process_response( $response, $order ) { |
|
146 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
145 | + public function process_response($response, $order) { |
|
146 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
147 | 147 | |
148 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
148 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
149 | 149 | |
150 | 150 | // Store charge data |
151 | - update_post_meta( $order_id, '_stripe_charge_id', $response->id ); |
|
152 | - update_post_meta( $order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
151 | + update_post_meta($order_id, '_stripe_charge_id', $response->id); |
|
152 | + update_post_meta($order_id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
153 | 153 | |
154 | 154 | // Store other data such as fees |
155 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
155 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
156 | 156 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
157 | 157 | // values are in the local currency of the Stripe account, not from WC. |
158 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_number( $response->balance_transaction, 'fee' ) : 0; |
|
159 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_number( $response->balance_transaction, 'net' ) : 0; |
|
160 | - update_post_meta( $order_id, 'Stripe Fee', $fee ); |
|
161 | - update_post_meta( $order_id, 'Net Revenue From Stripe', $net ); |
|
158 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_number($response->balance_transaction, 'fee') : 0; |
|
159 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_number($response->balance_transaction, 'net') : 0; |
|
160 | + update_post_meta($order_id, 'Stripe Fee', $fee); |
|
161 | + update_post_meta($order_id, 'Net Revenue From Stripe', $net); |
|
162 | 162 | } |
163 | 163 | |
164 | - if ( $response->captured ) { |
|
165 | - $order->payment_complete( $response->id ); |
|
164 | + if ($response->captured) { |
|
165 | + $order->payment_complete($response->id); |
|
166 | 166 | |
167 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
168 | - $order->add_order_note( $message ); |
|
169 | - WC_Stripe_Logger::log( 'Success: ' . $message ); |
|
167 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
168 | + $order->add_order_note($message); |
|
169 | + WC_Stripe_Logger::log('Success: ' . $message); |
|
170 | 170 | |
171 | 171 | } else { |
172 | - update_post_meta( $order_id, '_transaction_id', $response->id, true ); |
|
172 | + update_post_meta($order_id, '_transaction_id', $response->id, true); |
|
173 | 173 | |
174 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
175 | - version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
174 | + if ($order->has_status(array('pending', 'failed'))) { |
|
175 | + version_compare(WC_VERSION, '3.0.0', '<') ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
176 | 176 | } |
177 | 177 | |
178 | - $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 ) ); |
|
179 | - WC_Stripe_Logger::log( "Successful auth: $response->id" ); |
|
178 | + $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)); |
|
179 | + WC_Stripe_Logger::log("Successful auth: $response->id"); |
|
180 | 180 | } |
181 | 181 | |
182 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
182 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
183 | 183 | |
184 | 184 | return $response; |
185 | 185 | } |
@@ -192,10 +192,10 @@ discard block |
||
192 | 192 | * @param int $order_id |
193 | 193 | * @return null |
194 | 194 | */ |
195 | - public function send_failed_order_email( $order_id ) { |
|
195 | + public function send_failed_order_email($order_id) { |
|
196 | 196 | $emails = WC()->mailer()->get_emails(); |
197 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
198 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
197 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
198 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
@@ -207,21 +207,21 @@ discard block |
||
207 | 207 | * @param object $order |
208 | 208 | * @return object $details |
209 | 209 | */ |
210 | - public function get_owner_details( $order ) { |
|
211 | - $billing_first_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_first_name : $order->get_billing_first_name(); |
|
212 | - $billing_last_name = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_last_name : $order->get_billing_last_name(); |
|
210 | + public function get_owner_details($order) { |
|
211 | + $billing_first_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_first_name : $order->get_billing_first_name(); |
|
212 | + $billing_last_name = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_last_name : $order->get_billing_last_name(); |
|
213 | 213 | |
214 | 214 | $details = array(); |
215 | 215 | |
216 | 216 | $details['name'] = $billing_first_name . ' ' . $billing_last_name; |
217 | - $details['email'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_email : $order->get_billing_email(); |
|
218 | - $details['phone'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_phone : $order->get_billing_phone(); |
|
219 | - $details['address']['line1'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
220 | - $details['address']['line2'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
221 | - $details['address']['state'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_state : $order->get_billing_state(); |
|
222 | - $details['address']['city'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_city : $order->get_billing_city(); |
|
223 | - $details['address']['postal_code'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_postcode : $order->get_billing_postcode(); |
|
224 | - $details['address']['country'] = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->billing_country : $order->get_billing_country(); |
|
217 | + $details['email'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_email : $order->get_billing_email(); |
|
218 | + $details['phone'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_phone : $order->get_billing_phone(); |
|
219 | + $details['address']['line1'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_1 : $order->get_billing_address_1(); |
|
220 | + $details['address']['line2'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_address_2 : $order->get_billing_address_2(); |
|
221 | + $details['address']['state'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_state : $order->get_billing_state(); |
|
222 | + $details['address']['city'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_city : $order->get_billing_city(); |
|
223 | + $details['address']['postal_code'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_postcode : $order->get_billing_postcode(); |
|
224 | + $details['address']['country'] = version_compare(WC_VERSION, '3.0.0', '<') ? $order->billing_country : $order->get_billing_country(); |
|
225 | 225 | |
226 | 226 | return (object) $details; |
227 | 227 | } |
@@ -235,38 +235,38 @@ discard block |
||
235 | 235 | * @throws Exception When card was not added or for and invalid card. |
236 | 236 | * @return object |
237 | 237 | */ |
238 | - public function get_source( $user_id, $force_customer = false ) { |
|
239 | - $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
240 | - $force_customer = apply_filters( 'wc_stripe_force_customer_creation', $force_customer, $stripe_customer ); |
|
238 | + public function get_source($user_id, $force_customer = false) { |
|
239 | + $stripe_customer = new WC_Stripe_Customer($user_id); |
|
240 | + $force_customer = apply_filters('wc_stripe_force_customer_creation', $force_customer, $stripe_customer); |
|
241 | 241 | $stripe_source = false; |
242 | 242 | $token_id = false; |
243 | 243 | |
244 | 244 | // New CC info was entered and we have a new token to process |
245 | - if ( isset( $_POST['stripe_source'] ) ) { |
|
246 | - $stripe_source = wc_clean( $_POST['stripe_source'] ); |
|
247 | - $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
245 | + if (isset($_POST['stripe_source'])) { |
|
246 | + $stripe_source = wc_clean($_POST['stripe_source']); |
|
247 | + $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
248 | 248 | |
249 | 249 | // This is true if the user wants to store the card to their account. |
250 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
251 | - $stripe_source = $stripe_customer->add_source( $stripe_source ); |
|
250 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
251 | + $stripe_source = $stripe_customer->add_source($stripe_source); |
|
252 | 252 | |
253 | - if ( is_wp_error( $stripe_source ) ) { |
|
254 | - throw new Exception( $stripe_source->get_error_message() ); |
|
253 | + if (is_wp_error($stripe_source)) { |
|
254 | + throw new Exception($stripe_source->get_error_message()); |
|
255 | 255 | } |
256 | 256 | } else { |
257 | 257 | // Not saving token, so don't define customer either. |
258 | 258 | $stripe_source = $stripe_source; |
259 | 259 | $stripe_customer = false; |
260 | 260 | } |
261 | - } elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
261 | + } elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
262 | 262 | // Use an existing token, and then process the payment |
263 | 263 | |
264 | - $token_id = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
265 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
264 | + $token_id = wc_clean($_POST['wc-stripe-payment-token']); |
|
265 | + $token = WC_Payment_Tokens::get($token_id); |
|
266 | 266 | |
267 | - if ( ! $token || $token->get_user_id() !== get_current_user_id() ) { |
|
268 | - WC()->session->set( 'refresh_totals', true ); |
|
269 | - throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
267 | + if ( ! $token || $token->get_user_id() !== get_current_user_id()) { |
|
268 | + WC()->session->set('refresh_totals', true); |
|
269 | + throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | $stripe_source = $token->get_token(); |
@@ -287,18 +287,18 @@ discard block |
||
287 | 287 | * @param WC_Order $order For to which the source applies. |
288 | 288 | * @param stdClass $source Source information. |
289 | 289 | */ |
290 | - public function save_source( $order, $source ) { |
|
291 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
290 | + public function save_source($order, $source) { |
|
291 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
292 | 292 | |
293 | 293 | // Store source in the order. |
294 | - if ( $source->customer ) { |
|
295 | - version_compare( WC_VERSION, '3.0.0', '<' ) ? update_post_meta( $order_id, '_stripe_customer_id', $source->customer ) : $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
294 | + if ($source->customer) { |
|
295 | + version_compare(WC_VERSION, '3.0.0', '<') ? update_post_meta($order_id, '_stripe_customer_id', $source->customer) : $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
296 | 296 | } |
297 | - if ( $source->source ) { |
|
298 | - version_compare( WC_VERSION, '3.0.0', '<' ) ? update_post_meta( $order_id, '_stripe_card_id', $source->source ) : $order->update_meta_data( '_stripe_card_id', $source->source ); |
|
297 | + if ($source->source) { |
|
298 | + version_compare(WC_VERSION, '3.0.0', '<') ? update_post_meta($order_id, '_stripe_card_id', $source->source) : $order->update_meta_data('_stripe_card_id', $source->source); |
|
299 | 299 | } |
300 | 300 | |
301 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
301 | + if (is_callable(array($order, 'save'))) { |
|
302 | 302 | $order->save(); |
303 | 303 | } |
304 | 304 | } |
@@ -316,19 +316,19 @@ discard block |
||
316 | 316 | * @param object $order |
317 | 317 | * @return object |
318 | 318 | */ |
319 | - public function get_order_source( $order = null ) { |
|
319 | + public function get_order_source($order = null) { |
|
320 | 320 | $stripe_customer = new WC_Stripe_Customer(); |
321 | 321 | $stripe_source = false; |
322 | 322 | $token_id = false; |
323 | 323 | |
324 | - if ( $order ) { |
|
325 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
324 | + if ($order) { |
|
325 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
326 | 326 | |
327 | - if ( $meta_value = get_post_meta( $order_id, '_stripe_customer_id', true ) ) { |
|
328 | - $stripe_customer->set_id( $meta_value ); |
|
327 | + if ($meta_value = get_post_meta($order_id, '_stripe_customer_id', true)) { |
|
328 | + $stripe_customer->set_id($meta_value); |
|
329 | 329 | } |
330 | 330 | |
331 | - if ( $meta_value = get_post_meta( $order_id, '_stripe_card_id', true ) ) { |
|
331 | + if ($meta_value = get_post_meta($order_id, '_stripe_card_id', true)) { |
|
332 | 332 | $stripe_source = $meta_value; |
333 | 333 | } |
334 | 334 | } |
@@ -349,36 +349,36 @@ discard block |
||
349 | 349 | * @param float $amount |
350 | 350 | * @return bool |
351 | 351 | */ |
352 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
353 | - $order = wc_get_order( $order_id ); |
|
352 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
353 | + $order = wc_get_order($order_id); |
|
354 | 354 | |
355 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
355 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
356 | 356 | return false; |
357 | 357 | } |
358 | 358 | |
359 | 359 | $body = array(); |
360 | 360 | |
361 | - if ( ! is_null( $amount ) ) { |
|
362 | - $body['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount ); |
|
361 | + if ( ! is_null($amount)) { |
|
362 | + $body['amount'] = WC_Stripe_Helper::get_stripe_amount($amount); |
|
363 | 363 | } |
364 | 364 | |
365 | - if ( $reason ) { |
|
365 | + if ($reason) { |
|
366 | 366 | $body['metadata'] = array( |
367 | 367 | 'reason' => $reason, |
368 | 368 | ); |
369 | 369 | } |
370 | 370 | |
371 | - WC_Stripe_Logger::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
371 | + WC_Stripe_Logger::log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
372 | 372 | |
373 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
373 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
374 | 374 | |
375 | - if ( is_wp_error( $response ) ) { |
|
376 | - WC_Stripe_Logger::log( 'Error: ' . $response->get_error_message() ); |
|
375 | + if (is_wp_error($response)) { |
|
376 | + WC_Stripe_Logger::log('Error: ' . $response->get_error_message()); |
|
377 | 377 | return $response; |
378 | - } elseif ( ! empty( $response->id ) ) { |
|
379 | - $refund_message = sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
380 | - $order->add_order_note( $refund_message ); |
|
381 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
378 | + } elseif ( ! empty($response->id)) { |
|
379 | + $refund_message = sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
380 | + $order->add_order_note($refund_message); |
|
381 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
382 | 382 | return true; |
383 | 383 | } |
384 | 384 | } |
@@ -391,32 +391,32 @@ discard block |
||
391 | 391 | * @version 4.0.0 |
392 | 392 | */ |
393 | 393 | public function add_payment_method() { |
394 | - if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
395 | - wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
394 | + if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
395 | + wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
396 | 396 | return; |
397 | 397 | } |
398 | 398 | |
399 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
400 | - $card = $stripe_customer->add_source( wc_clean( $_POST['stripe_token'] ) ); |
|
399 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
400 | + $card = $stripe_customer->add_source(wc_clean($_POST['stripe_token'])); |
|
401 | 401 | |
402 | - if ( is_wp_error( $card ) ) { |
|
402 | + if (is_wp_error($card)) { |
|
403 | 403 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
404 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
404 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
405 | 405 | |
406 | 406 | // loop through the errors to find matching localized message |
407 | - foreach ( $card->errors as $error => $msg ) { |
|
408 | - if ( isset( $localized_messages[ $error ] ) ) { |
|
409 | - $error_msg = $localized_messages[ $error ]; |
|
407 | + foreach ($card->errors as $error => $msg) { |
|
408 | + if (isset($localized_messages[$error])) { |
|
409 | + $error_msg = $localized_messages[$error]; |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | |
413 | - wc_add_notice( $error_msg, 'error' ); |
|
413 | + wc_add_notice($error_msg, 'error'); |
|
414 | 414 | return; |
415 | 415 | } |
416 | 416 | |
417 | 417 | return array( |
418 | 418 | 'result' => 'success', |
419 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
419 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
420 | 420 | ); |
421 | 421 | } |
422 | 422 | } |
@@ -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 integer $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,12 +90,12 @@ discard block |
||
90 | 90 | * Get data from the Stripe API about this customer |
91 | 91 | */ |
92 | 92 | public function get_customer_data() { |
93 | - if ( empty( $this->customer_data ) && $this->get_id() && false === ( $this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() ) ) ) { |
|
94 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() ); |
|
93 | + if (empty($this->customer_data) && $this->get_id() && false === ($this->customer_data = get_transient('stripe_customer_' . $this->get_id()))) { |
|
94 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id()); |
|
95 | 95 | |
96 | - if ( ! is_wp_error( $response ) ) { |
|
97 | - $this->set_customer_data( $response ); |
|
98 | - set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 ); |
|
96 | + if ( ! is_wp_error($response)) { |
|
97 | + $this->set_customer_data($response); |
|
98 | + set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | return $this->customer_data; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $data = $this->get_customer_data(); |
110 | 110 | $source = ''; |
111 | 111 | |
112 | - if ( $data ) { |
|
112 | + if ($data) { |
|
113 | 113 | $source = $data->default_source; |
114 | 114 | } |
115 | 115 | |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | * @param array $args |
122 | 122 | * @return WP_Error|int |
123 | 123 | */ |
124 | - public function create_customer( $args = array() ) { |
|
125 | - $billing_email = filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ); |
|
124 | + public function create_customer($args = array()) { |
|
125 | + $billing_email = filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL); |
|
126 | 126 | |
127 | - if ( $user = $this->get_user() ) { |
|
128 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
129 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
127 | + if ($user = $this->get_user()) { |
|
128 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
129 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
130 | 130 | |
131 | 131 | $defaults = array( |
132 | 132 | 'email' => $user->user_email, |
@@ -134,33 +134,33 @@ discard block |
||
134 | 134 | ); |
135 | 135 | } else { |
136 | 136 | $defaults = array( |
137 | - 'email' => ! empty( $billing_email ) ? $billing_email : '', |
|
137 | + 'email' => ! empty($billing_email) ? $billing_email : '', |
|
138 | 138 | 'description' => '', |
139 | 139 | ); |
140 | 140 | } |
141 | 141 | |
142 | 142 | $metadata = array(); |
143 | 143 | |
144 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
144 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
145 | 145 | |
146 | - $args = wp_parse_args( $args, $defaults ); |
|
147 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
146 | + $args = wp_parse_args($args, $defaults); |
|
147 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
148 | 148 | |
149 | - if ( is_wp_error( $response ) ) { |
|
149 | + if (is_wp_error($response)) { |
|
150 | 150 | return $response; |
151 | - } elseif ( empty( $response->id ) ) { |
|
152 | - return new WP_Error( 'stripe_error', __( 'Could not create Stripe customer.', 'woocommerce-gateway-stripe' ) ); |
|
151 | + } elseif (empty($response->id)) { |
|
152 | + return new WP_Error('stripe_error', __('Could not create Stripe customer.', 'woocommerce-gateway-stripe')); |
|
153 | 153 | } |
154 | 154 | |
155 | - $this->set_id( $response->id ); |
|
155 | + $this->set_id($response->id); |
|
156 | 156 | $this->clear_cache(); |
157 | - $this->set_customer_data( $response ); |
|
157 | + $this->set_customer_data($response); |
|
158 | 158 | |
159 | - if ( $this->get_user_id() ) { |
|
160 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
159 | + if ($this->get_user_id()) { |
|
160 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
161 | 161 | } |
162 | 162 | |
163 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
163 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
164 | 164 | |
165 | 165 | return $response->id; |
166 | 166 | } |
@@ -171,61 +171,61 @@ discard block |
||
171 | 171 | * @param bool $retry |
172 | 172 | * @return WP_Error|int |
173 | 173 | */ |
174 | - public function add_source( $token, $retry = true ) { |
|
175 | - if ( ! $this->get_id() ) { |
|
176 | - if ( ( $response = $this->create_customer() ) && is_wp_error( $response ) ) { |
|
174 | + public function add_source($token, $retry = true) { |
|
175 | + if ( ! $this->get_id()) { |
|
176 | + if (($response = $this->create_customer()) && is_wp_error($response)) { |
|
177 | 177 | return $response; |
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - $response = WC_Stripe_API::request( array( |
|
181 | + $response = WC_Stripe_API::request(array( |
|
182 | 182 | 'source' => $token, |
183 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
183 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
184 | 184 | |
185 | - if ( is_wp_error( $response ) ) { |
|
185 | + if (is_wp_error($response)) { |
|
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:/', $response->get_error_message() ) ) { |
|
190 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
189 | + if (preg_match('/No such customer:/', $response->get_error_message())) { |
|
190 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
191 | 191 | $this->create_customer(); |
192 | - return $this->add_source( $token, false ); |
|
193 | - } elseif ( 'customer' === $response->get_error_code() && $retry ) { |
|
192 | + return $this->add_source($token, false); |
|
193 | + } elseif ('customer' === $response->get_error_code() && $retry) { |
|
194 | 194 | $this->create_customer(); |
195 | - return $this->add_source( $token, false ); |
|
195 | + return $this->add_source($token, false); |
|
196 | 196 | } else { |
197 | 197 | return $response; |
198 | 198 | } |
199 | - } elseif ( empty( $response->id ) ) { |
|
200 | - return new WP_Error( 'error', __( 'Unable to add card', 'woocommerce-gateway-stripe' ) ); |
|
199 | + } elseif (empty($response->id)) { |
|
200 | + return new WP_Error('error', __('Unable to add card', 'woocommerce-gateway-stripe')); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | // Add token to WooCommerce |
204 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
204 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
205 | 205 | $token = new WC_Payment_Token_CC(); |
206 | - $token->set_token( $response->id ); |
|
207 | - $token->set_gateway_id( 'stripe' ); |
|
206 | + $token->set_token($response->id); |
|
207 | + $token->set_gateway_id('stripe'); |
|
208 | 208 | |
209 | - if ( 'source' === $response->object ) { |
|
209 | + if ('source' === $response->object) { |
|
210 | 210 | // Check if it is a 3d secure source. |
211 | - if ( 'three_d_secure' === $response->type ) { |
|
211 | + if ('three_d_secure' === $response->type) { |
|
212 | 212 | $card = $response->three_d_secure->card; |
213 | 213 | } else { |
214 | 214 | $card = $response->card; |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | - $token->set_card_type( strtolower( $card->brand ) ); |
|
219 | - $token->set_last4( $card->last4 ); |
|
220 | - $token->set_expiry_month( $card->exp_month ); |
|
221 | - $token->set_expiry_year( $card->exp_year ); |
|
222 | - $token->set_user_id( $this->get_user_id() ); |
|
218 | + $token->set_card_type(strtolower($card->brand)); |
|
219 | + $token->set_last4($card->last4); |
|
220 | + $token->set_expiry_month($card->exp_month); |
|
221 | + $token->set_expiry_year($card->exp_year); |
|
222 | + $token->set_user_id($this->get_user_id()); |
|
223 | 223 | $token->save(); |
224 | 224 | } |
225 | 225 | |
226 | 226 | $this->clear_cache(); |
227 | 227 | |
228 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $token, $response ); |
|
228 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $token, $response); |
|
229 | 229 | |
230 | 230 | return $response->id; |
231 | 231 | } |
@@ -239,20 +239,20 @@ discard block |
||
239 | 239 | public function get_sources() { |
240 | 240 | $sources = array(); |
241 | 241 | |
242 | - if ( $this->get_id() && false === ( $sources = get_transient( 'stripe_sources_' . $this->get_id() ) ) ) { |
|
243 | - $response = WC_Stripe_API::request( array( |
|
242 | + if ($this->get_id() && false === ($sources = get_transient('stripe_sources_' . $this->get_id()))) { |
|
243 | + $response = WC_Stripe_API::request(array( |
|
244 | 244 | 'limit' => 100, |
245 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
245 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
246 | 246 | |
247 | - if ( is_wp_error( $response ) ) { |
|
247 | + if (is_wp_error($response)) { |
|
248 | 248 | return array(); |
249 | 249 | } |
250 | 250 | |
251 | - if ( is_array( $response->data ) ) { |
|
251 | + if (is_array($response->data)) { |
|
252 | 252 | $sources = $response->data; |
253 | 253 | } |
254 | 254 | |
255 | - set_transient( 'stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 48 ); |
|
255 | + set_transient('stripe_sources_' . $this->get_id(), $sources, HOUR_IN_SECONDS * 48); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | return $sources; |
@@ -262,13 +262,13 @@ discard block |
||
262 | 262 | * Delete a source from stripe. |
263 | 263 | * @param string $source_id |
264 | 264 | */ |
265 | - public function delete_source( $source_id ) { |
|
266 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
265 | + public function delete_source($source_id) { |
|
266 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
267 | 267 | |
268 | 268 | $this->clear_cache(); |
269 | 269 | |
270 | - if ( ! is_wp_error( $response ) ) { |
|
271 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
270 | + if ( ! is_wp_error($response)) { |
|
271 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
272 | 272 | |
273 | 273 | return true; |
274 | 274 | } |
@@ -280,15 +280,15 @@ discard block |
||
280 | 280 | * Set default source in Stripe |
281 | 281 | * @param string $source_id |
282 | 282 | */ |
283 | - public function set_default_source( $source_id ) { |
|
284 | - $response = WC_Stripe_API::request( array( |
|
285 | - 'default_source' => sanitize_text_field( $source_id ), |
|
286 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
283 | + public function set_default_source($source_id) { |
|
284 | + $response = WC_Stripe_API::request(array( |
|
285 | + 'default_source' => sanitize_text_field($source_id), |
|
286 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
287 | 287 | |
288 | 288 | $this->clear_cache(); |
289 | 289 | |
290 | - if ( ! is_wp_error( $response ) ) { |
|
291 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
290 | + if ( ! is_wp_error($response)) { |
|
291 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
292 | 292 | |
293 | 293 | return true; |
294 | 294 | } |
@@ -300,8 +300,8 @@ discard block |
||
300 | 300 | * Deletes caches for this users cards. |
301 | 301 | */ |
302 | 302 | public function clear_cache() { |
303 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
304 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
303 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
304 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
305 | 305 | $this->customer_data = array(); |
306 | 306 | } |
307 | 307 | } |
@@ -103,7 +103,6 @@ discard block |
||
103 | 103 | * process_subscription_payment function. |
104 | 104 | * @param mixed $order |
105 | 105 | * @param int $amount (default: 0) |
106 | - * @param string $stripe_token (default: '') |
|
107 | 106 | * @param bool initial_payment |
108 | 107 | */ |
109 | 108 | public function process_subscription_payment( $order = '', $amount = 0 ) { |
@@ -160,6 +159,8 @@ discard block |
||
160 | 159 | /** |
161 | 160 | * Process the pre-order |
162 | 161 | * @param int $order_id |
162 | + * @param boolean $retry |
|
163 | + * @param boolean $force_customer |
|
163 | 164 | * @return array |
164 | 165 | */ |
165 | 166 | public function process_pre_order( $order_id, $retry, $force_customer ) { |
@@ -256,7 +257,7 @@ discard block |
||
256 | 257 | |
257 | 258 | /** |
258 | 259 | * Don't transfer Stripe fee/ID meta to renewal orders. |
259 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
260 | + * @param integer $renewal_order |
|
260 | 261 | */ |
261 | 262 | public function delete_renewal_meta( $renewal_order ) { |
262 | 263 | delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -18,25 +18,25 @@ discard block |
||
18 | 18 | public function __construct() { |
19 | 19 | parent::__construct(); |
20 | 20 | |
21 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
22 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
23 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
24 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
25 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
21 | + if (class_exists('WC_Subscriptions_Order')) { |
|
22 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
23 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
24 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
25 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
26 | 26 | |
27 | 27 | // display the credit card used for a subscription in the "My Subscriptions" table |
28 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
28 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
29 | 29 | |
30 | 30 | // allow store managers to manually set Stripe as the payment method on a subscription |
31 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
32 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
31 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
32 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
33 | 33 | } |
34 | 34 | |
35 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
36 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
35 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
36 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
37 | 37 | } |
38 | 38 | |
39 | - $this->wc_pre_30 = version_compare( WC_VERSION, '3.0.0', '<' ); |
|
39 | + $this->wc_pre_30 = version_compare(WC_VERSION, '3.0.0', '<'); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | * @param int $order_id |
45 | 45 | * @return boolean |
46 | 46 | */ |
47 | - protected function is_subscription( $order_id ) { |
|
48 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
47 | + protected function is_subscription($order_id) { |
|
48 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | * @param int $order_id |
54 | 54 | * @return boolean |
55 | 55 | */ |
56 | - protected function is_pre_order( $order_id ) { |
|
57 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
56 | + protected function is_pre_order($order_id) { |
|
57 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -62,40 +62,40 @@ discard block |
||
62 | 62 | * @param int $order_id |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
66 | - if ( $this->is_subscription( $order_id ) ) { |
|
65 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
66 | + if ($this->is_subscription($order_id)) { |
|
67 | 67 | // Regular payment with force customer enabled |
68 | - return parent::process_payment( $order_id, true, true ); |
|
68 | + return parent::process_payment($order_id, true, true); |
|
69 | 69 | |
70 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
71 | - return $this->process_pre_order( $order_id, $retry, $force_customer ); |
|
70 | + } elseif ($this->is_pre_order($order_id)) { |
|
71 | + return $this->process_pre_order($order_id, $retry, $force_customer); |
|
72 | 72 | |
73 | 73 | } else { |
74 | - return parent::process_payment( $order_id, $retry, $force_customer ); |
|
74 | + return parent::process_payment($order_id, $retry, $force_customer); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Updates other subscription sources. |
80 | 80 | */ |
81 | - protected function save_source( $order, $source ) { |
|
82 | - parent::save_source( $order, $source ); |
|
81 | + protected function save_source($order, $source) { |
|
82 | + parent::save_source($order, $source); |
|
83 | 83 | |
84 | - $order_id = $this->wc_pre_30 ? $order->id : $order->get_id(); |
|
84 | + $order_id = $this->wc_pre_30 ? $order->id : $order->get_id(); |
|
85 | 85 | |
86 | 86 | // Also store it on the subscriptions being purchased or paid for in the order |
87 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
88 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
89 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
90 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
87 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
88 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
89 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
90 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
91 | 91 | } else { |
92 | 92 | $subscriptions = array(); |
93 | 93 | } |
94 | 94 | |
95 | - foreach ( $subscriptions as $subscription ) { |
|
95 | + foreach ($subscriptions as $subscription) { |
|
96 | 96 | $subscription_id = $this->wc_pre_30 ? $subscription->id : $subscription->get_id(); |
97 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
98 | - update_post_meta( $subscription_id, '_stripe_card_id', $source->source ); |
|
97 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
98 | + update_post_meta($subscription_id, '_stripe_card_id', $source->source); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -106,55 +106,55 @@ discard block |
||
106 | 106 | * @param string $stripe_token (default: '') |
107 | 107 | * @param bool initial_payment |
108 | 108 | */ |
109 | - public function process_subscription_payment( $order = '', $amount = 0 ) { |
|
110 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
111 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
109 | + public function process_subscription_payment($order = '', $amount = 0) { |
|
110 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
111 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | // Get source from order |
115 | - $source = $this->get_order_source( $order ); |
|
115 | + $source = $this->get_order_source($order); |
|
116 | 116 | |
117 | 117 | // If no order source was defined, use user source instead. |
118 | - if ( ! $source->customer ) { |
|
119 | - $source = $this->get_source( ( $this->wc_pre_30 ? $order->customer_user : $order->get_customer_id() ) ); |
|
118 | + if ( ! $source->customer) { |
|
119 | + $source = $this->get_source(($this->wc_pre_30 ? $order->customer_user : $order->get_customer_id())); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | // Or fail :( |
123 | - if ( ! $source->customer ) { |
|
124 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
123 | + if ( ! $source->customer) { |
|
124 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | $order_id = $this->wc_pre_30 ? $order->id : $order->get_id(); |
128 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
128 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
129 | 129 | |
130 | 130 | // Make the request |
131 | - $request = $this->generate_payment_request( $order, $source ); |
|
131 | + $request = $this->generate_payment_request($order, $source); |
|
132 | 132 | $request['capture'] = 'true'; |
133 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
133 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
134 | 134 | $request['metadata'] = array( |
135 | 135 | 'payment_type' => 'recurring', |
136 | - 'site_url' => esc_url( get_site_url() ), |
|
136 | + 'site_url' => esc_url(get_site_url()), |
|
137 | 137 | ); |
138 | - $response = WC_Stripe_API::request( $request ); |
|
138 | + $response = WC_Stripe_API::request($request); |
|
139 | 139 | |
140 | 140 | // Process valid response |
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - if ( 'missing' === $response->get_error_code() ) { |
|
141 | + if (is_wp_error($response)) { |
|
142 | + if ('missing' === $response->get_error_code()) { |
|
143 | 143 | // If we can't link customer to a card, we try to charge by customer ID. |
144 | - $request = $this->generate_payment_request( $order, $this->get_source( ( $this->wc_pre_30 ? $order->customer_user : $order->get_customer_id() ) ) ); |
|
144 | + $request = $this->generate_payment_request($order, $this->get_source(($this->wc_pre_30 ? $order->customer_user : $order->get_customer_id()))); |
|
145 | 145 | $request['capture'] = 'true'; |
146 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
146 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
147 | 147 | $request['metadata'] = array( |
148 | 148 | 'payment_type' => 'recurring', |
149 | - 'site_url' => esc_url( get_site_url() ), |
|
149 | + 'site_url' => esc_url(get_site_url()), |
|
150 | 150 | ); |
151 | - $response = WC_Stripe_API::request( $request ); |
|
151 | + $response = WC_Stripe_API::request($request); |
|
152 | 152 | } else { |
153 | 153 | return $response; // Default catch all errors. |
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - $this->process_response( $response, $order ); |
|
157 | + $this->process_response($response, $order); |
|
158 | 158 | |
159 | 159 | return $response; |
160 | 160 | } |
@@ -164,42 +164,42 @@ discard block |
||
164 | 164 | * @param int $order_id |
165 | 165 | * @return array |
166 | 166 | */ |
167 | - public function process_pre_order( $order_id, $retry, $force_customer ) { |
|
168 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
167 | + public function process_pre_order($order_id, $retry, $force_customer) { |
|
168 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
169 | 169 | try { |
170 | - $order = wc_get_order( $order_id ); |
|
170 | + $order = wc_get_order($order_id); |
|
171 | 171 | |
172 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
173 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
172 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
173 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
174 | 174 | } |
175 | 175 | |
176 | - $source = $this->get_source( get_current_user_id(), true ); |
|
176 | + $source = $this->get_source(get_current_user_id(), true); |
|
177 | 177 | |
178 | 178 | // We need a source on file to continue. |
179 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
180 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
179 | + if (empty($source->customer) || empty($source->source)) { |
|
180 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | // Store source to order meta |
184 | - $this->save_source( $order, $source ); |
|
184 | + $this->save_source($order, $source); |
|
185 | 185 | |
186 | 186 | // Remove cart |
187 | 187 | WC()->cart->empty_cart(); |
188 | 188 | |
189 | 189 | // Is pre ordered! |
190 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
190 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
191 | 191 | |
192 | 192 | // Return thank you page redirect |
193 | 193 | return array( |
194 | 194 | 'result' => 'success', |
195 | - 'redirect' => $this->get_return_url( $order ), |
|
195 | + 'redirect' => $this->get_return_url($order), |
|
196 | 196 | ); |
197 | - } catch ( Exception $e ) { |
|
198 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
197 | + } catch (Exception $e) { |
|
198 | + wc_add_notice($e->getMessage(), 'error'); |
|
199 | 199 | return; |
200 | 200 | } |
201 | 201 | } else { |
202 | - return parent::process_payment( $order_id, $retry, $force_customer ); |
|
202 | + return parent::process_payment($order_id, $retry, $force_customer); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @param WC_Order $order |
209 | 209 | * @return void |
210 | 210 | */ |
211 | - public function process_pre_order_release_payment( $order ) { |
|
211 | + public function process_pre_order_release_payment($order) { |
|
212 | 212 | try { |
213 | 213 | // Define some callbacks if the first attempt fails. |
214 | 214 | $retry_callbacks = array( |
@@ -216,32 +216,32 @@ discard block |
||
216 | 216 | 'remove_order_customer_before_retry', |
217 | 217 | ); |
218 | 218 | |
219 | - while ( 1 ) { |
|
220 | - $source = $this->get_order_source( $order ); |
|
221 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
219 | + while (1) { |
|
220 | + $source = $this->get_order_source($order); |
|
221 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
222 | 222 | |
223 | - if ( is_wp_error( $response ) ) { |
|
224 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
225 | - throw new Exception( $response->get_error_message() ); |
|
223 | + if (is_wp_error($response)) { |
|
224 | + if (0 === sizeof($retry_callbacks)) { |
|
225 | + throw new Exception($response->get_error_message()); |
|
226 | 226 | } else { |
227 | - $retry_callback = array_shift( $retry_callbacks ); |
|
228 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
227 | + $retry_callback = array_shift($retry_callbacks); |
|
228 | + call_user_func(array($this, $retry_callback), $order); |
|
229 | 229 | } |
230 | 230 | } else { |
231 | 231 | // Successful |
232 | - $this->process_response( $response, $order ); |
|
232 | + $this->process_response($response, $order); |
|
233 | 233 | break; |
234 | 234 | } |
235 | 235 | } |
236 | - } catch ( Exception $e ) { |
|
237 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
236 | + } catch (Exception $e) { |
|
237 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
238 | 238 | |
239 | 239 | // Mark order as failed if not already set, |
240 | 240 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
241 | - if ( ! $order->has_status( 'failed' ) ) { |
|
242 | - $order->update_status( 'failed', $order_note ); |
|
241 | + if ( ! $order->has_status('failed')) { |
|
242 | + $order->update_status('failed', $order_note); |
|
243 | 243 | } else { |
244 | - $order->add_order_note( $order_note ); |
|
244 | + $order->add_order_note($order_note); |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | } |
@@ -250,20 +250,20 @@ discard block |
||
250 | 250 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
251 | 251 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
252 | 252 | */ |
253 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
254 | - delete_post_meta( ( $this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
255 | - delete_post_meta( ( $this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
256 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
253 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
254 | + delete_post_meta(($this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
255 | + delete_post_meta(($this->wc_pre_30 ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
256 | + $this->delete_renewal_meta($resubscribe_order); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | 260 | * Don't transfer Stripe fee/ID meta to renewal orders. |
261 | 261 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
262 | 262 | */ |
263 | - public function delete_renewal_meta( $renewal_order ) { |
|
264 | - delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
265 | - delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
266 | - delete_post_meta( ( $this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Payment ID' ); |
|
263 | + public function delete_renewal_meta($renewal_order) { |
|
264 | + delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
265 | + delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
266 | + delete_post_meta(($this->wc_pre_30 ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Payment ID'); |
|
267 | 267 | return $renewal_order; |
268 | 268 | } |
269 | 269 | |
@@ -273,11 +273,11 @@ discard block |
||
273 | 273 | * @param $amount_to_charge float The amount to charge. |
274 | 274 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
275 | 275 | */ |
276 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
277 | - $response = $this->process_subscription_payment( $renewal_order, $amount_to_charge ); |
|
276 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
277 | + $response = $this->process_subscription_payment($renewal_order, $amount_to_charge); |
|
278 | 278 | |
279 | - if ( is_wp_error( $response ) ) { |
|
280 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
279 | + if (is_wp_error($response)) { |
|
280 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
@@ -285,18 +285,18 @@ discard block |
||
285 | 285 | * Remove order meta |
286 | 286 | * @param object $order |
287 | 287 | */ |
288 | - public function remove_order_source_before_retry( $order ) { |
|
288 | + public function remove_order_source_before_retry($order) { |
|
289 | 289 | $order_id = $this->wc_pre_30 ? $order->id : $order->get_id(); |
290 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
290 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | 294 | * Remove order meta |
295 | 295 | * @param object $order |
296 | 296 | */ |
297 | - public function remove_order_customer_before_retry( $order ) { |
|
297 | + public function remove_order_customer_before_retry($order) { |
|
298 | 298 | $order_id = $this->wc_pre_30 ? $order->id : $order->get_id(); |
299 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
299 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -308,13 +308,13 @@ discard block |
||
308 | 308 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
309 | 309 | * @return void |
310 | 310 | */ |
311 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
312 | - if ( $this->wc_pre_30 ) { |
|
313 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
314 | - update_post_meta( $subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id ); |
|
311 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
312 | + if ($this->wc_pre_30) { |
|
313 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
314 | + update_post_meta($subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id); |
|
315 | 315 | } else { |
316 | - $subscription->update_meta_data( '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
317 | - $subscription->update_meta_data( '_stripe_card_id', $renewal_order->get_meta( '_stripe_card_id', true ) ); |
|
316 | + $subscription->update_meta_data('_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
317 | + $subscription->update_meta_data('_stripe_card_id', $renewal_order->get_meta('_stripe_card_id', true)); |
|
318 | 318 | } |
319 | 319 | } |
320 | 320 | |
@@ -327,15 +327,15 @@ discard block |
||
327 | 327 | * @param WC_Subscription $subscription An instance of a subscription object |
328 | 328 | * @return array |
329 | 329 | */ |
330 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
331 | - $payment_meta[ $this->id ] = array( |
|
330 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
331 | + $payment_meta[$this->id] = array( |
|
332 | 332 | 'post_meta' => array( |
333 | 333 | '_stripe_customer_id' => array( |
334 | - 'value' => get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
334 | + 'value' => get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
335 | 335 | 'label' => 'Stripe Customer ID', |
336 | 336 | ), |
337 | 337 | '_stripe_card_id' => array( |
338 | - 'value' => get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ), |
|
338 | + 'value' => get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true), |
|
339 | 339 | 'label' => 'Stripe Card ID', |
340 | 340 | ), |
341 | 341 | ), |
@@ -352,17 +352,17 @@ discard block |
||
352 | 352 | * @param array $payment_meta associative array of meta data required for automatic payments |
353 | 353 | * @return array |
354 | 354 | */ |
355 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
356 | - if ( $this->id === $payment_method_id ) { |
|
355 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
356 | + if ($this->id === $payment_method_id) { |
|
357 | 357 | |
358 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
359 | - throw new Exception( 'A "_stripe_customer_id" value is required.' ); |
|
360 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
361 | - throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' ); |
|
358 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
359 | + throw new Exception('A "_stripe_customer_id" value is required.'); |
|
360 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
361 | + throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".'); |
|
362 | 362 | } |
363 | 363 | |
364 | - if ( ! empty( $payment_meta['post_meta']['_stripe_card_id']['value'] ) && 0 !== strpos( $payment_meta['post_meta']['_stripe_card_id']['value'], 'card_' ) ) { |
|
365 | - throw new Exception( 'Invalid card ID. A valid "_stripe_card_id" must begin with "card_".' ); |
|
364 | + if ( ! empty($payment_meta['post_meta']['_stripe_card_id']['value']) && 0 !== strpos($payment_meta['post_meta']['_stripe_card_id']['value'], 'card_')) { |
|
365 | + throw new Exception('Invalid card ID. A valid "_stripe_card_id" must begin with "card_".'); |
|
366 | 366 | } |
367 | 367 | } |
368 | 368 | } |
@@ -375,45 +375,45 @@ discard block |
||
375 | 375 | * @param WC_Subscription $subscription the subscription details |
376 | 376 | * @return string the subscription payment method |
377 | 377 | */ |
378 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
378 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
379 | 379 | $customer_user = $this->wc_pre_30 ? $subscription->customer_user : $subscription->get_customer_id(); |
380 | 380 | |
381 | 381 | // bail for other payment methods |
382 | - if ( $this->id !== ( $this->wc_pre_30 ? $subscription->payment_method : $subscription->get_payment_method() ) || ! $customer_user ) { |
|
382 | + if ($this->id !== ($this->wc_pre_30 ? $subscription->payment_method : $subscription->get_payment_method()) || ! $customer_user) { |
|
383 | 383 | return $payment_method_to_display; |
384 | 384 | } |
385 | 385 | |
386 | 386 | $stripe_customer = new WC_Stripe_Customer(); |
387 | - $stripe_customer_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
388 | - $stripe_card_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
387 | + $stripe_customer_id = get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
388 | + $stripe_card_id = get_post_meta(($this->wc_pre_30 ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
389 | 389 | |
390 | 390 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
391 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
391 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
392 | 392 | $user_id = $customer_user; |
393 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
394 | - $stripe_card_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
393 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
394 | + $stripe_card_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
398 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
399 | - $stripe_customer_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
400 | - $stripe_card_id = get_post_meta( ( $this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
398 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
399 | + $stripe_customer_id = get_post_meta(($this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
400 | + $stripe_card_id = get_post_meta(($this->wc_pre_30 ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
401 | 401 | } |
402 | 402 | |
403 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
403 | + $stripe_customer->set_id($stripe_customer_id); |
|
404 | 404 | $cards = $stripe_customer->get_sources(); |
405 | 405 | |
406 | - if ( $cards ) { |
|
406 | + if ($cards) { |
|
407 | 407 | $found_card = false; |
408 | - foreach ( $cards as $card ) { |
|
409 | - if ( $card->id === $stripe_card_id ) { |
|
408 | + foreach ($cards as $card) { |
|
409 | + if ($card->id === $stripe_card_id) { |
|
410 | 410 | $found_card = true; |
411 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->type ) ? $card->type : $card->brand ), $card->last4 ); |
|
411 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->type) ? $card->type : $card->brand), $card->last4); |
|
412 | 412 | break; |
413 | 413 | } |
414 | 414 | } |
415 | - if ( ! $found_card ) { |
|
416 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $cards[0]->type ) ? $cards[0]->type : $cards[0]->brand ), $cards[0]->last4 ); |
|
415 | + if ( ! $found_card) { |
|
416 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($cards[0]->type) ? $cards[0]->type : $cards[0]->brand), $cards[0]->last4); |
|
417 | 417 | } |
418 | 418 | } |
419 | 419 |
@@ -144,6 +144,8 @@ |
||
144 | 144 | * |
145 | 145 | * @since 1.0.0 |
146 | 146 | * @version 1.0.0 |
147 | + * @param string $slug |
|
148 | + * @param string $class |
|
147 | 149 | */ |
148 | 150 | public function add_admin_notice( $slug, $class, $message ) { |
149 | 151 | $this->notices[ $slug ] = array( |
@@ -11,20 +11,20 @@ discard block |
||
11 | 11 | * |
12 | 12 | */ |
13 | 13 | |
14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
14 | +if ( ! defined('ABSPATH')) { |
|
15 | 15 | exit; |
16 | 16 | } |
17 | 17 | |
18 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
18 | +if ( ! class_exists('WC_Stripe')) : |
|
19 | 19 | /** |
20 | 20 | * Required minimums and constants |
21 | 21 | */ |
22 | - define( 'WC_STRIPE_VERSION', '3.2.2' ); |
|
23 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
24 | - define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' ); |
|
25 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
26 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
27 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
22 | + define('WC_STRIPE_VERSION', '3.2.2'); |
|
23 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
24 | + define('WC_STRIPE_MIN_WC_VER', '2.5.0'); |
|
25 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
26 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
27 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
28 | 28 | |
29 | 29 | class WC_Stripe { |
30 | 30 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @return Singleton The *Singleton* instance. |
45 | 45 | */ |
46 | 46 | public static function get_instance() { |
47 | - if ( null === self::$instance ) { |
|
47 | + if (null === self::$instance) { |
|
48 | 48 | self::$instance = new self(); |
49 | 49 | } |
50 | 50 | return self::$instance; |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | * *Singleton* via the `new` operator from outside of this class. |
94 | 94 | */ |
95 | 95 | private function __construct() { |
96 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
97 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
98 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
96 | + add_action('admin_init', array($this, 'check_environment')); |
|
97 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
98 | + add_action('plugins_loaded', array($this, 'init')); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -105,38 +105,38 @@ discard block |
||
105 | 105 | * @version 4.0.0 |
106 | 106 | */ |
107 | 107 | public function init() { |
108 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
108 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
109 | 109 | |
110 | 110 | // Don't hook anything else in the plugin if we're in an incompatible environment |
111 | - if ( self::get_environment_warning() ) { |
|
111 | + if (self::get_environment_warning()) { |
|
112 | 112 | return; |
113 | 113 | } |
114 | 114 | |
115 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
123 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
124 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
125 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
126 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
127 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
128 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
129 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
115 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
123 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
124 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
125 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
126 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
127 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
128 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
129 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
130 | 130 | |
131 | 131 | // Init the gateway itself |
132 | 132 | $this->init_gateways(); |
133 | 133 | |
134 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
135 | - add_action( 'wp_ajax_stripe_dismiss_request_api_notice', array( $this, 'dismiss_request_api_notice' ) ); |
|
136 | - add_action( 'wp_ajax_stripe_dismiss_apple_pay_notice', array( $this, 'dismiss_apple_pay_notice' ) ); |
|
137 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
134 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
135 | + add_action('wp_ajax_stripe_dismiss_request_api_notice', array($this, 'dismiss_request_api_notice')); |
|
136 | + add_action('wp_ajax_stripe_dismiss_apple_pay_notice', array($this, 'dismiss_apple_pay_notice')); |
|
137 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
138 | 138 | |
139 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-request.php' ); |
|
139 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-request.php'); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | * @since 1.0.0 |
146 | 146 | * @version 1.0.0 |
147 | 147 | */ |
148 | - public function add_admin_notice( $slug, $class, $message ) { |
|
149 | - $this->notices[ $slug ] = array( |
|
148 | + public function add_admin_notice($slug, $class, $message) { |
|
149 | + $this->notices[$slug] = array( |
|
150 | 150 | 'class' => $class, |
151 | 151 | 'message' => $message, |
152 | 152 | ); |
@@ -160,23 +160,23 @@ discard block |
||
160 | 160 | * @version 4.0.0 |
161 | 161 | */ |
162 | 162 | public function check_environment() { |
163 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
163 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
164 | 164 | $this->install(); |
165 | 165 | |
166 | - do_action( 'woocommerce_stripe_updated' ); |
|
166 | + do_action('woocommerce_stripe_updated'); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | $environment_warning = self::get_environment_warning(); |
170 | 170 | |
171 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
172 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
171 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
172 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | $secret = WC_Stripe_API::get_secret_key(); |
176 | 176 | |
177 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
177 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
178 | 178 | $setting_link = $this->get_setting_link(); |
179 | - $this->add_admin_notice( 'prompt_connect', '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 ) ); |
|
179 | + $this->add_admin_notice('prompt_connect', '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)); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | * @return bool |
189 | 189 | */ |
190 | 190 | private static function _update_plugin_version() { |
191 | - delete_option( 'wc_stripe_version' ); |
|
192 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
191 | + delete_option('wc_stripe_version'); |
|
192 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
193 | 193 | |
194 | 194 | return true; |
195 | 195 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @version 3.1.0 |
202 | 202 | */ |
203 | 203 | public function dismiss_request_api_notice() { |
204 | - update_option( 'wc_stripe_show_request_api_notice', 'no' ); |
|
204 | + update_option('wc_stripe_show_request_api_notice', 'no'); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * @version 3.1.0 |
212 | 212 | */ |
213 | 213 | public function dismiss_apple_pay_notice() { |
214 | - update_option( 'wc_stripe_show_apple_pay_notice', 'no' ); |
|
214 | + update_option('wc_stripe_show_apple_pay_notice', 'no'); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | * @version 3.1.0 |
222 | 222 | */ |
223 | 223 | public function install() { |
224 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
225 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
224 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
225 | + define('WC_STRIPE_INSTALLING', true); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | $this->_update_plugin_version(); |
@@ -236,24 +236,24 @@ discard block |
||
236 | 236 | * @version 3.1.0 |
237 | 237 | */ |
238 | 238 | public static function get_environment_warning() { |
239 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
240 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
239 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
240 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
241 | 241 | |
242 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
242 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
243 | 243 | } |
244 | 244 | |
245 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
246 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
245 | + if ( ! defined('WC_VERSION')) { |
|
246 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
247 | 247 | } |
248 | 248 | |
249 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
250 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
249 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
250 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
251 | 251 | |
252 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
252 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
253 | 253 | } |
254 | 254 | |
255 | - if ( ! function_exists( 'curl_init' ) ) { |
|
256 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
255 | + if ( ! function_exists('curl_init')) { |
|
256 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | return false; |
@@ -264,15 +264,15 @@ discard block |
||
264 | 264 | * |
265 | 265 | * @since 1.0.0 |
266 | 266 | */ |
267 | - public function plugin_action_links( $links ) { |
|
267 | + public function plugin_action_links($links) { |
|
268 | 268 | $setting_link = $this->get_setting_link(); |
269 | 269 | |
270 | 270 | $plugin_links = array( |
271 | - '<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
272 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
273 | - '<a href="https://woocommerce.com/contact-us/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
271 | + '<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
272 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
273 | + '<a href="https://woocommerce.com/contact-us/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
274 | 274 | ); |
275 | - return array_merge( $plugin_links, $links ); |
|
275 | + return array_merge($plugin_links, $links); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -283,24 +283,24 @@ discard block |
||
283 | 283 | * @return string Setting link |
284 | 284 | */ |
285 | 285 | public function get_setting_link() { |
286 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
286 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
287 | 287 | |
288 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
288 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
289 | 289 | |
290 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
290 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | 294 | * Display any notices we've collected thus far (e.g. for connection, disconnection) |
295 | 295 | */ |
296 | 296 | public function admin_notices() { |
297 | - $show_request_api_notice = get_option( 'wc_stripe_show_request_api_notice' ); |
|
298 | - $show_apple_pay_notice = get_option( 'wc_stripe_show_apple_pay_notice' ); |
|
297 | + $show_request_api_notice = get_option('wc_stripe_show_request_api_notice'); |
|
298 | + $show_apple_pay_notice = get_option('wc_stripe_show_apple_pay_notice'); |
|
299 | 299 | |
300 | - if ( empty( $show_apple_pay_notice ) ) { |
|
300 | + if (empty($show_apple_pay_notice)) { |
|
301 | 301 | // @TODO remove this notice in the future. |
302 | 302 | ?> |
303 | - <div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php echo sprintf( esc_html__( 'New Feature! Stripe now supports %s. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe' ), '<a href="https://woocommerce.com/apple-pay/">Apple Pay</a>'); ?></p></div> |
|
303 | + <div class="notice notice-warning wc-stripe-apple-pay-notice is-dismissible"><p><?php echo sprintf(esc_html__('New Feature! Stripe now supports %s. Your customers can now purchase your products even faster. Apple Pay has been enabled by default.', 'woocommerce-gateway-stripe'), '<a href="https://woocommerce.com/apple-pay/">Apple Pay</a>'); ?></p></div> |
|
304 | 304 | |
305 | 305 | <script type="application/javascript"> |
306 | 306 | jQuery( '.wc-stripe-apple-pay-notice' ).on( 'click', '.notice-dismiss', function() { |
@@ -308,17 +308,17 @@ discard block |
||
308 | 308 | action: 'stripe_dismiss_apple_pay_notice' |
309 | 309 | }; |
310 | 310 | |
311 | - jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data ); |
|
311 | + jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data ); |
|
312 | 312 | }); |
313 | 313 | </script> |
314 | 314 | |
315 | 315 | <?php |
316 | 316 | } |
317 | 317 | |
318 | - if ( empty( $show_request_api_notice ) ) { |
|
318 | + if (empty($show_request_api_notice)) { |
|
319 | 319 | // @TODO remove this notice in the future. |
320 | 320 | ?> |
321 | - <div class="notice notice-warning wc-stripe-request-api-notice is-dismissible"><p><?php esc_html_e( 'New Feature! Stripe now supports Google Payment Request. Your customers can now use mobile phones with supported browsers such as Chrome to make purchases easier and faster.', 'woocommerce-gateway-stripe' ); ?></p></div> |
|
321 | + <div class="notice notice-warning wc-stripe-request-api-notice is-dismissible"><p><?php esc_html_e('New Feature! Stripe now supports Google Payment Request. Your customers can now use mobile phones with supported browsers such as Chrome to make purchases easier and faster.', 'woocommerce-gateway-stripe'); ?></p></div> |
|
322 | 322 | |
323 | 323 | <script type="application/javascript"> |
324 | 324 | jQuery( '.wc-stripe-request-api-notice' ).on( 'click', '.notice-dismiss', function() { |
@@ -326,16 +326,16 @@ discard block |
||
326 | 326 | action: 'stripe_dismiss_request_api_notice' |
327 | 327 | }; |
328 | 328 | |
329 | - jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', data ); |
|
329 | + jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data ); |
|
330 | 330 | }); |
331 | 331 | </script> |
332 | 332 | |
333 | 333 | <?php |
334 | 334 | } |
335 | 335 | |
336 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
337 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
338 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
336 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
337 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
338 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
339 | 339 | echo '</p></div>'; |
340 | 340 | } |
341 | 341 | } |
@@ -347,22 +347,22 @@ discard block |
||
347 | 347 | * @version 4.0.0 |
348 | 348 | */ |
349 | 349 | public function init_gateways() { |
350 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
350 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
351 | 351 | $this->subscription_support_enabled = true; |
352 | 352 | } |
353 | 353 | |
354 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
354 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
355 | 355 | $this->pre_order_enabled = true; |
356 | 356 | } |
357 | 357 | |
358 | - if ( ! class_exists( 'WC_Payment_Gateway' ) ) { |
|
358 | + if ( ! class_exists('WC_Payment_Gateway')) { |
|
359 | 359 | return; |
360 | 360 | } |
361 | 361 | |
362 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-apple-pay.php' ); |
|
362 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-apple-pay.php'); |
|
363 | 363 | |
364 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
365 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
364 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
365 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
366 | 366 | |
367 | 367 | $load_addons = ( |
368 | 368 | $this->subscription_support_enabled |
@@ -370,8 +370,8 @@ discard block |
||
370 | 370 | $this->pre_order_enabled |
371 | 371 | ); |
372 | 372 | |
373 | - if ( $load_addons ) { |
|
374 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-gateway-stripe-addons.php' ); |
|
373 | + if ($load_addons) { |
|
374 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-gateway-stripe-addons.php'); |
|
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
@@ -381,8 +381,8 @@ discard block |
||
381 | 381 | * @since 1.0.0 |
382 | 382 | * @version 4.0.0 |
383 | 383 | */ |
384 | - public function add_gateways( $methods ) { |
|
385 | - if ( $this->subscription_support_enabled || $this->pre_order_enabled ) { |
|
384 | + public function add_gateways($methods) { |
|
385 | + if ($this->subscription_support_enabled || $this->pre_order_enabled) { |
|
386 | 386 | $methods[] = 'WC_Gateway_Stripe_Addons'; |
387 | 387 | } else { |
388 | 388 | $methods[] = 'WC_Gateway_Stripe'; |
@@ -403,15 +403,15 @@ discard block |
||
403 | 403 | * @since 4.0.0 |
404 | 404 | * @version 4.0.0 |
405 | 405 | */ |
406 | - public function filter_gateway_order_admin( $sections ) { |
|
407 | - unset( $sections['stripe'] ); |
|
408 | - unset( $sections['stripe_bancontact'] ); |
|
409 | - unset( $sections['stripe_sofort'] ); |
|
410 | - unset( $sections['stripe_giropay'] ); |
|
411 | - unset( $sections['stripe_ideal'] ); |
|
412 | - unset( $sections['stripe_alipay'] ); |
|
413 | - unset( $sections['stripe_sepa'] ); |
|
414 | - unset( $sections['stripe_bitcoin'] ); |
|
406 | + public function filter_gateway_order_admin($sections) { |
|
407 | + unset($sections['stripe']); |
|
408 | + unset($sections['stripe_bancontact']); |
|
409 | + unset($sections['stripe_sofort']); |
|
410 | + unset($sections['stripe_giropay']); |
|
411 | + unset($sections['stripe_ideal']); |
|
412 | + unset($sections['stripe_alipay']); |
|
413 | + unset($sections['stripe_sepa']); |
|
414 | + unset($sections['stripe_bitcoin']); |
|
415 | 415 | |
416 | 416 | $sections['stripe'] = 'Stripe'; |
417 | 417 | $sections['stripe_bancontact'] = 'Stripe Bancontact'; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | public function __construct() { |
21 | 21 | self::$_this = $this; |
22 | 22 | |
23 | - add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) ); |
|
24 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
25 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
26 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
27 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
28 | - add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) ); |
|
23 | + add_action('wp', array($this, 'maybe_process_redirect_order')); |
|
24 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
25 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
26 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
27 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
28 | + add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | * @since 4.0.0 |
45 | 45 | * @version 4.0.0 |
46 | 46 | */ |
47 | - public function get_stripe_customer_id( $order ) { |
|
48 | - return get_user_meta( $order->get_customer_id(), '_stripe_customer_id', true ); |
|
47 | + public function get_stripe_customer_id($order) { |
|
48 | + return get_user_meta($order->get_customer_id(), '_stripe_customer_id', true); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | * @since 4.0.0 |
57 | 57 | * @version 4.0.0 |
58 | 58 | */ |
59 | - public function process_redirect_payment( $order_id, $retry = true, $source ) { |
|
59 | + public function process_redirect_payment($order_id, $retry = true, $source) { |
|
60 | 60 | try { |
61 | - $order = wc_get_order( $order_id ); |
|
61 | + $order = wc_get_order($order_id); |
|
62 | 62 | |
63 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) { |
|
63 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
@@ -68,73 +68,73 @@ discard block |
||
68 | 68 | $response = null; |
69 | 69 | |
70 | 70 | // Handle payment. |
71 | - if ( $order->get_total() > 0 ) { |
|
71 | + if ($order->get_total() > 0) { |
|
72 | 72 | |
73 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
74 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
73 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
74 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
75 | 75 | } |
76 | 76 | |
77 | - WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
77 | + WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
78 | 78 | |
79 | 79 | // Prep source object. |
80 | 80 | $source_object = new stdClass(); |
81 | 81 | $source_object->token_id = ''; |
82 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
82 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
83 | 83 | $source_object->source = $source; |
84 | 84 | |
85 | 85 | // Make the request. |
86 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
86 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
87 | 87 | |
88 | - if ( is_wp_error( $response ) ) { |
|
89 | - $this->delete_stripe_session_id( $order_id ); |
|
88 | + if (is_wp_error($response)) { |
|
89 | + $this->delete_stripe_session_id($order_id); |
|
90 | 90 | |
91 | 91 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
92 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
93 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
92 | + if ('customer' === $response->get_error_code() && $retry) { |
|
93 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
94 | 94 | |
95 | - return $this->process_redirect_payment( $order_id, false, $source ); |
|
96 | - } elseif ( preg_match( '/No such customer/i', $response->get_error_message() ) && $retry ) { |
|
97 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
95 | + return $this->process_redirect_payment($order_id, false, $source); |
|
96 | + } elseif (preg_match('/No such customer/i', $response->get_error_message()) && $retry) { |
|
97 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
98 | 98 | |
99 | - return $this->process_redirect_payment( $order_id, false, $source ); |
|
99 | + return $this->process_redirect_payment($order_id, false, $source); |
|
100 | 100 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
101 | - } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
102 | - $token = WC_Payment_Tokens::get( $source->token_id ); |
|
101 | + } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
102 | + $token = WC_Payment_Tokens::get($source->token_id); |
|
103 | 103 | $token->delete(); |
104 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
105 | - $order->add_order_note( $message ); |
|
104 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
105 | + $order->add_order_note($message); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
109 | 109 | |
110 | - $message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message(); |
|
110 | + $message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message(); |
|
111 | 111 | |
112 | - $order->add_order_note( $message ); |
|
112 | + $order->add_order_note($message); |
|
113 | 113 | |
114 | - wc_add_notice( __( 'Payment failed, please try another payment method.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
114 | + wc_add_notice(__('Payment failed, please try another payment method.', 'woocommerce-gateway-stripe'), 'error'); |
|
115 | 115 | // Everything failed so send customer back to checkout page to pay via another source. |
116 | - wp_safe_redirect( wc_get_checkout_url() ); |
|
116 | + wp_safe_redirect(wc_get_checkout_url()); |
|
117 | 117 | exit; |
118 | 118 | } |
119 | 119 | |
120 | - $this->process_response( $response, $order ); |
|
120 | + $this->process_response($response, $order); |
|
121 | 121 | |
122 | 122 | } else { |
123 | 123 | $order->payment_complete(); |
124 | 124 | } |
125 | 125 | |
126 | - $this->delete_stripe_session_id( $order_id ); |
|
127 | - do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
126 | + $this->delete_stripe_session_id($order_id); |
|
127 | + do_action('wc_gateway_stripe_process_redirect_payment', $response, $order); |
|
128 | 128 | |
129 | - } catch ( Exception $e ) { |
|
130 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
129 | + } catch (Exception $e) { |
|
130 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
131 | 131 | |
132 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
133 | - $this->send_failed_order_email( $order_id ); |
|
132 | + if ($order->has_status(array('pending', 'failed'))) { |
|
133 | + $this->send_failed_order_email($order_id); |
|
134 | 134 | } |
135 | 135 | |
136 | - $this->delete_stripe_session_id( $order_id ); |
|
137 | - do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order ); |
|
136 | + $this->delete_stripe_session_id($order_id); |
|
137 | + do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | * @version 4.0.0 |
146 | 146 | * @param int $order_id |
147 | 147 | */ |
148 | - public function delete_stripe_session_id( $order_id ) { |
|
149 | - delete_post_meta( $order_id, '_stripe_session_id' ); |
|
148 | + public function delete_stripe_session_id($order_id) { |
|
149 | + delete_post_meta($order_id, '_stripe_session_id'); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -156,19 +156,19 @@ discard block |
||
156 | 156 | * @version 4.0.0 |
157 | 157 | */ |
158 | 158 | public function maybe_process_redirect_order() { |
159 | - if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) || empty( $_GET['stripe_session_id'] ) ) { |
|
159 | + if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source']) || empty($_GET['stripe_session_id'])) { |
|
160 | 160 | return; |
161 | 161 | } |
162 | 162 | |
163 | - $source = wc_clean( $_GET['source'] ); |
|
164 | - $stripe_session_id = wc_clean( $_GET['stripe_session_id'] ); |
|
165 | - $order_id = wc_clean( $_GET['order_id'] ); |
|
163 | + $source = wc_clean($_GET['source']); |
|
164 | + $stripe_session_id = wc_clean($_GET['stripe_session_id']); |
|
165 | + $order_id = wc_clean($_GET['order_id']); |
|
166 | 166 | |
167 | - if ( $stripe_session_id !== get_post_meta( $order_id, '_stripe_session_id', true ) ) { |
|
167 | + if ($stripe_session_id !== get_post_meta($order_id, '_stripe_session_id', true)) { |
|
168 | 168 | return; |
169 | 169 | } |
170 | 170 | |
171 | - $this->process_redirect_payment( $order_id, true, $source ); |
|
171 | + $this->process_redirect_payment($order_id, true, $source); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -178,36 +178,36 @@ discard block |
||
178 | 178 | * @version 4.0.0 |
179 | 179 | * @param int $order_id |
180 | 180 | */ |
181 | - public function capture_payment( $order_id ) { |
|
182 | - $order = wc_get_order( $order_id ); |
|
181 | + public function capture_payment($order_id) { |
|
182 | + $order = wc_get_order($order_id); |
|
183 | 183 | |
184 | - if ( 'stripe' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
185 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
186 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
184 | + if ('stripe' === (version_compare(WC_VERSION, '3.0.0', '<') ? $order->payment_method : $order->get_payment_method())) { |
|
185 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
186 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
187 | 187 | |
188 | - if ( $charge && 'no' === $captured ) { |
|
189 | - $result = WC_Stripe_API::request( array( |
|
188 | + if ($charge && 'no' === $captured) { |
|
189 | + $result = WC_Stripe_API::request(array( |
|
190 | 190 | 'amount' => $order->get_total() * 100, |
191 | 191 | 'expand[]' => 'balance_transaction', |
192 | - ), 'charges/' . $charge . '/capture' ); |
|
192 | + ), 'charges/' . $charge . '/capture'); |
|
193 | 193 | |
194 | - if ( is_wp_error( $result ) ) { |
|
195 | - $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
194 | + if (is_wp_error($result)) { |
|
195 | + $order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
196 | 196 | } else { |
197 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
198 | - update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ); |
|
197 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
198 | + update_post_meta($order_id, '_stripe_charge_captured', 'yes'); |
|
199 | 199 | |
200 | 200 | // Store other data such as fees |
201 | - update_post_meta( $order_id, 'Stripe Payment ID', $result->id ); |
|
202 | - update_post_meta( $order_id, '_transaction_id', $result->id ); |
|
201 | + update_post_meta($order_id, 'Stripe Payment ID', $result->id); |
|
202 | + update_post_meta($order_id, '_transaction_id', $result->id); |
|
203 | 203 | |
204 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
204 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
205 | 205 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
206 | 206 | // values are in the local currency of the Stripe account, not from WC. |
207 | - $fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_number( $result->balance_transaction, 'fee' ) : 0; |
|
208 | - $net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_number( $result->balance_transaction, 'net' ) : 0; |
|
209 | - update_post_meta( $order_id, 'Stripe Fee', $fee ); |
|
210 | - update_post_meta( $order_id, 'Net Revenue From Stripe', $net ); |
|
207 | + $fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_number($result->balance_transaction, 'fee') : 0; |
|
208 | + $net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_number($result->balance_transaction, 'net') : 0; |
|
209 | + update_post_meta($order_id, 'Stripe Fee', $fee); |
|
210 | + update_post_meta($order_id, 'Net Revenue From Stripe', $net); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | } |
@@ -221,23 +221,23 @@ discard block |
||
221 | 221 | * @version 4.0.0 |
222 | 222 | * @param int $order_id |
223 | 223 | */ |
224 | - public function cancel_payment( $order_id ) { |
|
225 | - $order = wc_get_order( $order_id ); |
|
224 | + public function cancel_payment($order_id) { |
|
225 | + $order = wc_get_order($order_id); |
|
226 | 226 | |
227 | - if ( 'stripe' === ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->payment_method : $order->get_payment_method() ) ) { |
|
228 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
227 | + if ('stripe' === (version_compare(WC_VERSION, '3.0.0', '<') ? $order->payment_method : $order->get_payment_method())) { |
|
228 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
229 | 229 | |
230 | - if ( $charge ) { |
|
231 | - $result = WC_Stripe_API::request( array( |
|
230 | + if ($charge) { |
|
231 | + $result = WC_Stripe_API::request(array( |
|
232 | 232 | 'amount' => $order->get_total() * 100, |
233 | - ), 'charges/' . $charge . '/refund' ); |
|
233 | + ), 'charges/' . $charge . '/refund'); |
|
234 | 234 | |
235 | - if ( is_wp_error( $result ) ) { |
|
236 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
235 | + if (is_wp_error($result)) { |
|
236 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
237 | 237 | } else { |
238 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
239 | - delete_post_meta( $order_id, '_stripe_charge_captured' ); |
|
240 | - delete_post_meta( $order_id, '_stripe_charge_id' ); |
|
238 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
239 | + delete_post_meta($order_id, '_stripe_charge_captured'); |
|
240 | + delete_post_meta($order_id, '_stripe_charge_id'); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | } |
@@ -250,14 +250,14 @@ discard block |
||
250 | 250 | * @version 4.0.0 |
251 | 251 | */ |
252 | 252 | public function validate_checkout() { |
253 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) { |
|
254 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
253 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) { |
|
254 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | $errors = new WP_Error(); |
258 | - parse_str( $_POST['required_fields'], $required_fields ); |
|
259 | - parse_str( $_POST['all_fields'], $all_fields ); |
|
260 | - $source_type = wc_clean( $_POST['source_type'] ); |
|
258 | + parse_str($_POST['required_fields'], $required_fields); |
|
259 | + parse_str($_POST['all_fields'], $all_fields); |
|
260 | + $source_type = wc_clean($_POST['source_type']); |
|
261 | 261 | $validate_shipping_fields = false; |
262 | 262 | $create_account = false; |
263 | 263 | |
@@ -265,89 +265,89 @@ discard block |
||
265 | 265 | * If ship to different address checkbox is checked then we need |
266 | 266 | * to validate shipping fields too. |
267 | 267 | */ |
268 | - if ( isset( $all_fields['ship_to_different_address'] ) ) { |
|
268 | + if (isset($all_fields['ship_to_different_address'])) { |
|
269 | 269 | $validate_shipping_fields = true; |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Check if createaccount is checked. |
273 | - if ( isset( $all_fields['createaccount'] ) ) { |
|
273 | + if (isset($all_fields['createaccount'])) { |
|
274 | 274 | $create_account = true; |
275 | 275 | } |
276 | 276 | |
277 | 277 | // Check if required fields are empty. |
278 | - foreach ( $required_fields as $field => $field_value ) { |
|
278 | + foreach ($required_fields as $field => $field_value) { |
|
279 | 279 | // Check for shipping field. |
280 | - if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) { |
|
280 | + if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) { |
|
281 | 281 | continue; |
282 | 282 | } |
283 | 283 | |
284 | 284 | // Check create account name. |
285 | - if ( 'account_username' === $field && ! $create_account ) { |
|
285 | + if ('account_username' === $field && ! $create_account) { |
|
286 | 286 | continue; |
287 | 287 | } |
288 | 288 | |
289 | 289 | // Check create account password. |
290 | - if ( 'account_password' === $field && ! $create_account ) { |
|
290 | + if ('account_password' === $field && ! $create_account) { |
|
291 | 291 | continue; |
292 | 292 | } |
293 | 293 | |
294 | 294 | // Check if is SEPA. |
295 | - if ( empty( $field_value ) && 'stripe_sepa' !== $source_type ) { |
|
295 | + if (empty($field_value) && 'stripe_sepa' !== $source_type) { |
|
296 | 296 | continue; |
297 | 297 | } |
298 | 298 | |
299 | 299 | // Check if is Sofort. |
300 | - if ( '-1' === $field_value && 'stripe_sofort' === $source_type ) { |
|
301 | - $errors->add( 'validation', sprintf( __( '%s cannot be empty', 'woocommerce-gateway-stripe' ), ucfirst( str_replace( '_', ' ', $field ) ) ) ); |
|
300 | + if ('-1' === $field_value && 'stripe_sofort' === $source_type) { |
|
301 | + $errors->add('validation', sprintf(__('%s cannot be empty', 'woocommerce-gateway-stripe'), ucfirst(str_replace('_', ' ', $field)))); |
|
302 | 302 | } |
303 | 303 | |
304 | - if ( empty( $field_value ) ) { |
|
305 | - $errors->add( 'validation', sprintf( __( '%s cannot be empty', 'woocommerce-gateway-stripe' ), ucfirst( str_replace( '_', ' ', $field ) ) ) ); |
|
304 | + if (empty($field_value)) { |
|
305 | + $errors->add('validation', sprintf(__('%s cannot be empty', 'woocommerce-gateway-stripe'), ucfirst(str_replace('_', ' ', $field)))); |
|
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | 309 | // Check if email is valid format. |
310 | - if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) { |
|
311 | - $errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) ); |
|
310 | + if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) { |
|
311 | + $errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe')); |
|
312 | 312 | } |
313 | 313 | |
314 | - if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) { |
|
315 | - $errors->add( 'terms', __( 'You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe' ) ); |
|
314 | + if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) { |
|
315 | + $errors->add('terms', __('You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe')); |
|
316 | 316 | } |
317 | 317 | |
318 | - if ( WC()->cart->needs_shipping() ) { |
|
318 | + if (WC()->cart->needs_shipping()) { |
|
319 | 319 | $shipping_country = WC()->customer->get_shipping_country(); |
320 | 320 | |
321 | - if ( empty( $shipping_country ) ) { |
|
322 | - $errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) ); |
|
323 | - } elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) { |
|
324 | - $errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) ); |
|
321 | + if (empty($shipping_country)) { |
|
322 | + $errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe')); |
|
323 | + } elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) { |
|
324 | + $errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country())); |
|
325 | 325 | } else { |
326 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
326 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
327 | 327 | |
328 | - foreach ( WC()->shipping->get_packages() as $i => $package ) { |
|
329 | - if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) { |
|
330 | - $errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) ); |
|
328 | + foreach (WC()->shipping->get_packages() as $i => $package) { |
|
329 | + if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) { |
|
330 | + $errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe')); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | } |
334 | 334 | } |
335 | 335 | |
336 | - if ( WC()->cart->needs_payment() ) { |
|
336 | + if (WC()->cart->needs_payment()) { |
|
337 | 337 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
338 | 338 | |
339 | - if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) { |
|
340 | - $errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) ); |
|
339 | + if ( ! isset($available_gateways[$all_fields['payment_method']])) { |
|
340 | + $errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe')); |
|
341 | 341 | } else { |
342 | - $available_gateways[ $all_fields['payment_method'] ]->validate_fields(); |
|
342 | + $available_gateways[$all_fields['payment_method']]->validate_fields(); |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
346 | - if ( 0 === count( $errors->errors ) ) { |
|
347 | - wp_send_json( 'success' ); |
|
346 | + if (0 === count($errors->errors)) { |
|
347 | + wp_send_json('success'); |
|
348 | 348 | } else { |
349 | - foreach ( $errors->get_error_messages() as $message ) { |
|
350 | - wc_add_notice( $message, 'error' ); |
|
349 | + foreach ($errors->get_error_messages() as $message) { |
|
350 | + wc_add_notice($message, 'error'); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | $this->send_ajax_failure_response(); |
@@ -361,9 +361,9 @@ discard block |
||
361 | 361 | * @version 4.0.0 |
362 | 362 | */ |
363 | 363 | public function send_ajax_failure_response() { |
364 | - if ( is_ajax() ) { |
|
364 | + if (is_ajax()) { |
|
365 | 365 | // only print notices if not reloading the checkout, otherwise they're lost in the page reload. |
366 | - if ( ! isset( WC()->session->reload_checkout ) ) { |
|
366 | + if ( ! isset(WC()->session->reload_checkout)) { |
|
367 | 367 | ob_start(); |
368 | 368 | wc_print_notices(); |
369 | 369 | $messages = ob_get_clean(); |
@@ -371,14 +371,14 @@ discard block |
||
371 | 371 | |
372 | 372 | $response = array( |
373 | 373 | 'result' => 'failure', |
374 | - 'messages' => isset( $messages ) ? $messages : '', |
|
375 | - 'refresh' => isset( WC()->session->refresh_totals ), |
|
376 | - 'reload' => isset( WC()->session->reload_checkout ), |
|
374 | + 'messages' => isset($messages) ? $messages : '', |
|
375 | + 'refresh' => isset(WC()->session->refresh_totals), |
|
376 | + 'reload' => isset(WC()->session->reload_checkout), |
|
377 | 377 | ); |
378 | 378 | |
379 | - unset( WC()->session->refresh_totals, WC()->session->reload_checkout ); |
|
379 | + unset(WC()->session->refresh_totals, WC()->session->reload_checkout); |
|
380 | 380 | |
381 | - wp_send_json( $response ); |
|
381 | + wp_send_json($response); |
|
382 | 382 | } |
383 | 383 | } |
384 | 384 | } |
@@ -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,9 +21,9 @@ 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_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
26 | - 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_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
26 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -44,37 +44,37 @@ discard block |
||
44 | 44 | * @param array $tokens |
45 | 45 | * @return array |
46 | 46 | */ |
47 | - public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) { |
|
48 | - if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
49 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
47 | + public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) { |
|
48 | + if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) { |
|
49 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
50 | 50 | $stripe_cards = $stripe_customer->get_sources(); |
51 | 51 | $stored_tokens = array(); |
52 | 52 | |
53 | - foreach ( $tokens as $token ) { |
|
53 | + foreach ($tokens as $token) { |
|
54 | 54 | $stored_tokens[] = $token->get_token(); |
55 | 55 | } |
56 | 56 | |
57 | - foreach ( $stripe_cards as $card ) { |
|
58 | - if ( ! in_array( $card->id, $stored_tokens ) ) { |
|
57 | + foreach ($stripe_cards as $card) { |
|
58 | + if ( ! in_array($card->id, $stored_tokens)) { |
|
59 | 59 | $token = new WC_Payment_Token_CC(); |
60 | - $token->set_token( $card->id ); |
|
61 | - $token->set_gateway_id( 'stripe' ); |
|
60 | + $token->set_token($card->id); |
|
61 | + $token->set_gateway_id('stripe'); |
|
62 | 62 | |
63 | - if ( 'three_d_secure' === $card->type ) { |
|
63 | + if ('three_d_secure' === $card->type) { |
|
64 | 64 | continue; |
65 | 65 | } |
66 | 66 | |
67 | - if ( 'source' === $card->object ) { |
|
67 | + if ('source' === $card->object) { |
|
68 | 68 | $card = $card->card; |
69 | 69 | } |
70 | 70 | |
71 | - $token->set_card_type( strtolower( $card->brand ) ); |
|
72 | - $token->set_last4( $card->last4 ); |
|
73 | - $token->set_expiry_month( $card->exp_month ); |
|
74 | - $token->set_expiry_year( $card->exp_year ); |
|
75 | - $token->set_user_id( $customer_id ); |
|
71 | + $token->set_card_type(strtolower($card->brand)); |
|
72 | + $token->set_last4($card->last4); |
|
73 | + $token->set_expiry_month($card->exp_month); |
|
74 | + $token->set_expiry_year($card->exp_year); |
|
75 | + $token->set_user_id($customer_id); |
|
76 | 76 | $token->save(); |
77 | - $tokens[ $token->get_id() ] = $token; |
|
77 | + $tokens[$token->get_id()] = $token; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | } |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | * @since 3.1.0 |
89 | 89 | * @version 4.0.0 |
90 | 90 | */ |
91 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
92 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
93 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
94 | - $stripe_customer->delete_source( $token->get_token() ); |
|
91 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
92 | + if ('stripe' === $token->get_gateway_id()) { |
|
93 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
94 | + $stripe_customer->delete_source($token->get_token()); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | * @since 3.1.0 |
102 | 102 | * @version 4.0.0 |
103 | 103 | */ |
104 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
105 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
106 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
107 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
108 | - $stripe_customer->set_default_source( $token->get_token() ); |
|
104 | + public function woocommerce_payment_token_set_default($token_id) { |
|
105 | + $token = WC_Payment_Tokens::get($token_id); |
|
106 | + if ('stripe' === $token->get_gateway_id()) { |
|
107 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
108 | + $stripe_customer->set_default_source($token->get_token()); |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | } |
@@ -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 ) || 'yes' !== $settings['logging'] ) { |
|
30 | + if (empty($settings) || '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 | } |