@@ -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 | } |
@@ -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 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_giropay'; |
60 | - $this->method_title = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
61 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
60 | + $this->method_title = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
61 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
62 | 62 | |
63 | 63 | // Load the form fields. |
64 | 64 | $this->init_form_fields(); |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | // Load the settings. |
67 | 67 | $this->init_settings(); |
68 | 68 | |
69 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
70 | - $this->title = $this->get_option( 'title' ); |
|
71 | - $this->description = $this->get_option( 'description' ); |
|
72 | - $this->enabled = $this->get_option( 'enabled' ); |
|
73 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
74 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
75 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
76 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
77 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
78 | - |
|
79 | - if ( $this->testmode ) { |
|
80 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
69 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
70 | + $this->title = $this->get_option('title'); |
|
71 | + $this->description = $this->get_option('description'); |
|
72 | + $this->enabled = $this->get_option('enabled'); |
|
73 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
74 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
75 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
76 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
77 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
78 | + |
|
79 | + if ($this->testmode) { |
|
80 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
82 | 82 | } |
83 | 83 | |
84 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
85 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
86 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
84 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
85 | + add_action('admin_notices', array($this, 'check_environment')); |
|
86 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | public function check_environment() { |
96 | 96 | $environment_warning = $this->get_environment_warning(); |
97 | 97 | |
98 | - if ( $environment_warning ) { |
|
99 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
98 | + if ($environment_warning) { |
|
99 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
100 | 100 | } |
101 | 101 | |
102 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
103 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
104 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
102 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
103 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
104 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
105 | 105 | echo '</p></div>'; |
106 | 106 | } |
107 | 107 | } |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @version 4.0.0 |
115 | 115 | */ |
116 | 116 | public function get_environment_warning() { |
117 | - if ( 'yes' === $this->enabled && 'EUR' !== get_woocommerce_currency() ) { |
|
118 | - $message = __( 'Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
117 | + if ('yes' === $this->enabled && 'EUR' !== get_woocommerce_currency()) { |
|
118 | + $message = __('Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
119 | 119 | |
120 | 120 | return $message; |
121 | 121 | } |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * @return array |
132 | 132 | */ |
133 | 133 | public function payment_icons() { |
134 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
134 | + return apply_filters('wc_stripe_payment_icons', array( |
|
135 | 135 | 'giropay' => '<i class="stripe-pf stripe-pf-giropay stripe-pf-right" alt="Giropay" aria-hidden="true"></i>', |
136 | - ) ); |
|
136 | + )); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | |
151 | 151 | $icons_str .= $icons['giropay']; |
152 | 152 | |
153 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
153 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -161,19 +161,19 @@ discard block |
||
161 | 161 | * @access public |
162 | 162 | */ |
163 | 163 | public function payment_scripts() { |
164 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
164 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | 167 | |
168 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
168 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
169 | 169 | |
170 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
170 | + wp_enqueue_style('stripe_paymentfonts'); |
|
171 | 171 | |
172 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
173 | - wp_enqueue_script( 'stripev3' ); |
|
174 | - wp_enqueue_script( 'woocommerce_stripe_elements' ); |
|
172 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
173 | + wp_enqueue_script('stripev3'); |
|
174 | + wp_enqueue_script('woocommerce_stripe_elements'); |
|
175 | 175 | } else { |
176 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
176 | + wp_enqueue_script('woocommerce_stripe'); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * Initialize Gateway Settings Form Fields. |
182 | 182 | */ |
183 | 183 | public function init_form_fields() { |
184 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' ); |
|
184 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php'); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -192,25 +192,25 @@ discard block |
||
192 | 192 | $total = WC()->cart->total; |
193 | 193 | |
194 | 194 | // If paying from order, we need to get total from order not cart. |
195 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
196 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
195 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
196 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
197 | 197 | $total = $order->get_total(); |
198 | 198 | } |
199 | 199 | |
200 | - if ( is_add_payment_method_page() ) { |
|
201 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
202 | - $total = ''; |
|
200 | + if (is_add_payment_method_page()) { |
|
201 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
202 | + $total = ''; |
|
203 | 203 | } else { |
204 | 204 | $pay_button_text = ''; |
205 | 205 | } |
206 | 206 | |
207 | 207 | echo '<div |
208 | 208 | id="stripe-giropay-payment-data" |
209 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
210 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
209 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
210 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
211 | 211 | |
212 | - if ( $this->description ) { |
|
213 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
212 | + if ($this->description) { |
|
213 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | echo '</div>'; |
@@ -224,26 +224,26 @@ discard block |
||
224 | 224 | * @param object $order |
225 | 225 | * @return mixed |
226 | 226 | */ |
227 | - public function create_source( $order ) { |
|
228 | - $currency = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency(); |
|
229 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
227 | + public function create_source($order) { |
|
228 | + $currency = version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency(); |
|
229 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
230 | 230 | $stripe_session_id = uniqid(); |
231 | 231 | |
232 | 232 | // Set the stripe session id in order meta to later match it for security purposes. |
233 | - update_post_meta( $order_id, '_stripe_session_id', $stripe_session_id ); |
|
234 | - $return_url = $this->get_stripe_return_url( $order, $stripe_session_id ); |
|
233 | + update_post_meta($order_id, '_stripe_session_id', $stripe_session_id); |
|
234 | + $return_url = $this->get_stripe_return_url($order, $stripe_session_id); |
|
235 | 235 | |
236 | 236 | $post_data = array(); |
237 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
238 | - $post_data['currency'] = strtolower( $currency ); |
|
237 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
238 | + $post_data['currency'] = strtolower($currency); |
|
239 | 239 | $post_data['type'] = 'giropay'; |
240 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
241 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
242 | - $post_data['giropay'] = array( 'statement_descriptor' => $this->statement_descriptor ); |
|
240 | + $post_data['owner'] = $this->get_owner_details($order); |
|
241 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
242 | + $post_data['giropay'] = array('statement_descriptor' => $this->statement_descriptor); |
|
243 | 243 | |
244 | - WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' ); |
|
244 | + WC_Stripe_Logger::log('Info: Begin creating Giropay source'); |
|
245 | 245 | |
246 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
246 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -257,45 +257,45 @@ discard block |
||
257 | 257 | * |
258 | 258 | * @return array|void |
259 | 259 | */ |
260 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
260 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
261 | 261 | try { |
262 | - $order = wc_get_order( $order_id ); |
|
262 | + $order = wc_get_order($order_id); |
|
263 | 263 | |
264 | 264 | // Handle payment. |
265 | - if ( $order->get_total() > 0 ) { |
|
265 | + if ($order->get_total() > 0) { |
|
266 | 266 | |
267 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
268 | - 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 ) ) ); |
|
267 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
268 | + 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))); |
|
269 | 269 | } |
270 | 270 | |
271 | - $response = $this->create_source( $order ); |
|
271 | + $response = $this->create_source($order); |
|
272 | 272 | |
273 | - if ( is_wp_error( $response ) ) { |
|
273 | + if (is_wp_error($response)) { |
|
274 | 274 | $message = $response->get_error_message(); |
275 | 275 | |
276 | - $order->add_order_note( $message ); |
|
276 | + $order->add_order_note($message); |
|
277 | 277 | |
278 | - throw new Exception( $message ); |
|
278 | + throw new Exception($message); |
|
279 | 279 | } |
280 | 280 | |
281 | - WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' ); |
|
281 | + WC_Stripe_Logger::log('Info: Redirecting to Giropay...'); |
|
282 | 282 | |
283 | 283 | return array( |
284 | 284 | 'result' => 'success', |
285 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
285 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
286 | 286 | ); |
287 | 287 | } else { |
288 | 288 | $order->payment_complete(); |
289 | 289 | } |
290 | - } catch ( Exception $e ) { |
|
291 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
292 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
290 | + } catch (Exception $e) { |
|
291 | + wc_add_notice($e->getMessage(), 'error'); |
|
292 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
293 | 293 | |
294 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
295 | - $this->send_failed_order_email( $order_id ); |
|
294 | + if ($order->has_status(array('pending', 'failed'))) { |
|
295 | + $this->send_failed_order_email($order_id); |
|
296 | 296 | } |
297 | 297 | |
298 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
298 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
299 | 299 | |
300 | 300 | return array( |
301 | 301 | 'result' => 'fail', |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_alipay'; |
60 | - $this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
61 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
60 | + $this->method_title = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
61 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
62 | 62 | |
63 | 63 | // Load the form fields. |
64 | 64 | $this->init_form_fields(); |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | // Load the settings. |
67 | 67 | $this->init_settings(); |
68 | 68 | |
69 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
70 | - $this->title = $this->get_option( 'title' ); |
|
71 | - $this->description = $this->get_option( 'description' ); |
|
72 | - $this->enabled = $this->get_option( 'enabled' ); |
|
73 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
74 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
75 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
76 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
77 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
78 | - |
|
79 | - if ( $this->testmode ) { |
|
80 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
69 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
70 | + $this->title = $this->get_option('title'); |
|
71 | + $this->description = $this->get_option('description'); |
|
72 | + $this->enabled = $this->get_option('enabled'); |
|
73 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
74 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
75 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
76 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
77 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
78 | + |
|
79 | + if ($this->testmode) { |
|
80 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
82 | 82 | } |
83 | 83 | |
84 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
85 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
86 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
84 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
85 | + add_action('admin_notices', array($this, 'check_environment')); |
|
86 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | public function check_environment() { |
96 | 96 | $environment_warning = $this->get_environment_warning(); |
97 | 97 | |
98 | - if ( $environment_warning ) { |
|
99 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
98 | + if ($environment_warning) { |
|
99 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
100 | 100 | } |
101 | 101 | |
102 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
103 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
104 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
102 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
103 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
104 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
105 | 105 | echo '</p></div>'; |
106 | 106 | } |
107 | 107 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | 'SGD' !== get_woocommerce_currency() && |
127 | 127 | 'USD' !== get_woocommerce_currency() |
128 | 128 | ) { |
129 | - $message = __( 'Alipay is enabled - it requires store currency to be set to USD, EUR, AUD, CAD, GBP, HKD, JPY, NZD or SGD.', 'woocommerce-gateway-stripe' ); |
|
129 | + $message = __('Alipay is enabled - it requires store currency to be set to USD, EUR, AUD, CAD, GBP, HKD, JPY, NZD or SGD.', 'woocommerce-gateway-stripe'); |
|
130 | 130 | |
131 | 131 | return $message; |
132 | 132 | } |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | * @return array |
143 | 143 | */ |
144 | 144 | public function payment_icons() { |
145 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
145 | + return apply_filters('wc_stripe_payment_icons', array( |
|
146 | 146 | 'alipay' => '<i class="stripe-pf stripe-pf-alipay stripe-pf-right" alt="Alipay" aria-hidden="true"></i>', |
147 | - ) ); |
|
147 | + )); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | $icons_str .= $icons['alipay']; |
163 | 163 | |
164 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
164 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | * @access public |
173 | 173 | */ |
174 | 174 | public function payment_scripts() { |
175 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
175 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
179 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
180 | 180 | |
181 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
181 | + wp_enqueue_style('stripe_paymentfonts'); |
|
182 | 182 | |
183 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
184 | - wp_enqueue_script( 'stripev3' ); |
|
185 | - wp_enqueue_script( 'woocommerce_stripe_elements' ); |
|
183 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
184 | + wp_enqueue_script('stripev3'); |
|
185 | + wp_enqueue_script('woocommerce_stripe_elements'); |
|
186 | 186 | } else { |
187 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
187 | + wp_enqueue_script('woocommerce_stripe'); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * Initialize Gateway Settings Form Fields. |
193 | 193 | */ |
194 | 194 | public function init_form_fields() { |
195 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' ); |
|
195 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php'); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -203,25 +203,25 @@ discard block |
||
203 | 203 | $total = WC()->cart->total; |
204 | 204 | |
205 | 205 | // If paying from order, we need to get total from order not cart. |
206 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
207 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
206 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
207 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
208 | 208 | $total = $order->get_total(); |
209 | 209 | } |
210 | 210 | |
211 | - if ( is_add_payment_method_page() ) { |
|
212 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
213 | - $total = ''; |
|
211 | + if (is_add_payment_method_page()) { |
|
212 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
213 | + $total = ''; |
|
214 | 214 | } else { |
215 | 215 | $pay_button_text = ''; |
216 | 216 | } |
217 | 217 | |
218 | 218 | echo '<div |
219 | 219 | id="stripe-alipay-payment-data" |
220 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
221 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
220 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
221 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
222 | 222 | |
223 | - if ( $this->description ) { |
|
224 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
223 | + if ($this->description) { |
|
224 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | echo '</div>'; |
@@ -235,26 +235,26 @@ discard block |
||
235 | 235 | * @param object $order |
236 | 236 | * @return mixed |
237 | 237 | */ |
238 | - public function create_source( $order ) { |
|
239 | - $currency = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->get_order_currency() : $order->get_currency(); |
|
240 | - $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id(); |
|
238 | + public function create_source($order) { |
|
239 | + $currency = version_compare(WC_VERSION, '3.0.0', '<') ? $order->get_order_currency() : $order->get_currency(); |
|
240 | + $order_id = version_compare(WC_VERSION, '3.0.0', '<') ? $order->id : $order->get_id(); |
|
241 | 241 | $stripe_session_id = uniqid(); |
242 | 242 | |
243 | 243 | // Set the stripe session id in order meta to later match it for security purposes. |
244 | - update_post_meta( $order_id, '_stripe_session_id', $stripe_session_id ); |
|
245 | - $return_url = $this->get_stripe_return_url( $order, $stripe_session_id ); |
|
244 | + update_post_meta($order_id, '_stripe_session_id', $stripe_session_id); |
|
245 | + $return_url = $this->get_stripe_return_url($order, $stripe_session_id); |
|
246 | 246 | |
247 | 247 | $post_data = array(); |
248 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
249 | - $post_data['currency'] = strtolower( $currency ); |
|
248 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
249 | + $post_data['currency'] = strtolower($currency); |
|
250 | 250 | $post_data['type'] = 'alipay'; |
251 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
252 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
253 | - $post_data['alipay'] = array( 'statement_descriptor' => $this->statement_descriptor ); |
|
251 | + $post_data['owner'] = $this->get_owner_details($order); |
|
252 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
253 | + $post_data['alipay'] = array('statement_descriptor' => $this->statement_descriptor); |
|
254 | 254 | |
255 | - WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' ); |
|
255 | + WC_Stripe_Logger::log('Info: Begin creating Alipay source'); |
|
256 | 256 | |
257 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
257 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -268,45 +268,45 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @return array|void |
270 | 270 | */ |
271 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
271 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
272 | 272 | try { |
273 | - $order = wc_get_order( $order_id ); |
|
273 | + $order = wc_get_order($order_id); |
|
274 | 274 | |
275 | 275 | // Handle payment. |
276 | - if ( $order->get_total() > 0 ) { |
|
276 | + if ($order->get_total() > 0) { |
|
277 | 277 | |
278 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
279 | - 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 ) ) ); |
|
278 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
279 | + 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))); |
|
280 | 280 | } |
281 | 281 | |
282 | - $response = $this->create_source( $order ); |
|
282 | + $response = $this->create_source($order); |
|
283 | 283 | |
284 | - if ( is_wp_error( $response ) ) { |
|
284 | + if (is_wp_error($response)) { |
|
285 | 285 | $message = $response->get_error_message(); |
286 | 286 | |
287 | - $order->add_order_note( $message ); |
|
287 | + $order->add_order_note($message); |
|
288 | 288 | |
289 | - throw new Exception( $message ); |
|
289 | + throw new Exception($message); |
|
290 | 290 | } |
291 | 291 | |
292 | - WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); |
|
292 | + WC_Stripe_Logger::log('Info: Redirecting to Alipay...'); |
|
293 | 293 | |
294 | 294 | return array( |
295 | 295 | 'result' => 'success', |
296 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
296 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
297 | 297 | ); |
298 | 298 | } else { |
299 | 299 | $order->payment_complete(); |
300 | 300 | } |
301 | - } catch ( Exception $e ) { |
|
302 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
303 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
301 | + } catch (Exception $e) { |
|
302 | + wc_add_notice($e->getMessage(), 'error'); |
|
303 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
304 | 304 | |
305 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
306 | - $this->send_failed_order_email( $order_id ); |
|
305 | + if ($order->has_status(array('pending', 'failed'))) { |
|
306 | + $this->send_failed_order_email($order_id); |
|
307 | 307 | } |
308 | 308 | |
309 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
309 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
310 | 310 | |
311 | 311 | return array( |
312 | 312 | 'result' => 'fail', |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_sepa'; |
60 | - $this->method_title = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
61 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
60 | + $this->method_title = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
61 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
62 | 62 | |
63 | 63 | // Load the form fields. |
64 | 64 | $this->init_form_fields(); |
@@ -66,27 +66,27 @@ discard block |
||
66 | 66 | // Load the settings. |
67 | 67 | $this->init_settings(); |
68 | 68 | |
69 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
70 | - $this->title = $this->get_option( 'title' ); |
|
71 | - $this->description = $this->get_option( 'description' ); |
|
72 | - $this->enabled = $this->get_option( 'enabled' ); |
|
73 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
74 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
75 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
76 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
77 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
78 | - |
|
79 | - if ( $this->testmode ) { |
|
80 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
82 | - |
|
83 | - $this->description .= ' ' . __( 'TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe' ); |
|
84 | - $this->description = trim( $this->description ); |
|
69 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
70 | + $this->title = $this->get_option('title'); |
|
71 | + $this->description = $this->get_option('description'); |
|
72 | + $this->enabled = $this->get_option('enabled'); |
|
73 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
74 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
75 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
76 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
77 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
78 | + |
|
79 | + if ($this->testmode) { |
|
80 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
82 | + |
|
83 | + $this->description .= ' ' . __('TEST MODE ENABLED. In test mode, you can use IBAN number DE89370400440532013000.', 'woocommerce-gateway-stripe'); |
|
84 | + $this->description = trim($this->description); |
|
85 | 85 | } |
86 | 86 | |
87 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
88 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
89 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
87 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
88 | + add_action('admin_notices', array($this, 'check_environment')); |
|
89 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | public function check_environment() { |
99 | 99 | $environment_warning = $this->get_environment_warning(); |
100 | 100 | |
101 | - if ( $environment_warning ) { |
|
102 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
101 | + if ($environment_warning) { |
|
102 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
103 | 103 | } |
104 | 104 | |
105 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
106 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
107 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
105 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
106 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
107 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
108 | 108 | echo '</p></div>'; |
109 | 109 | } |
110 | 110 | } |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | * @version 4.0.0 |
118 | 118 | */ |
119 | 119 | public function get_environment_warning() { |
120 | - if ( 'yes' === $this->enabled && 'EUR' !== get_woocommerce_currency() ) { |
|
121 | - $message = __( 'SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
120 | + if ('yes' === $this->enabled && 'EUR' !== get_woocommerce_currency()) { |
|
121 | + $message = __('SEPA is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
122 | 122 | |
123 | 123 | return $message; |
124 | 124 | } |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | * @return array |
135 | 135 | */ |
136 | 136 | public function payment_icons() { |
137 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
137 | + return apply_filters('wc_stripe_payment_icons', array( |
|
138 | 138 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
139 | - ) ); |
|
139 | + )); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | $icons_str .= $icons['sepa']; |
155 | 155 | |
156 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
156 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -164,19 +164,19 @@ discard block |
||
164 | 164 | * @access public |
165 | 165 | */ |
166 | 166 | public function payment_scripts() { |
167 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
167 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
168 | 168 | return; |
169 | 169 | } |
170 | 170 | |
171 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
171 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
172 | 172 | |
173 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
173 | + wp_enqueue_style('stripe_paymentfonts'); |
|
174 | 174 | |
175 | - if ( apply_filters( 'wc_stripe_use_elements_checkout_form', true ) ) { |
|
176 | - wp_enqueue_script( 'stripev3' ); |
|
177 | - wp_enqueue_script( 'woocommerce_stripe_elements' ); |
|
175 | + if (apply_filters('wc_stripe_use_elements_checkout_form', true)) { |
|
176 | + wp_enqueue_script('stripev3'); |
|
177 | + wp_enqueue_script('woocommerce_stripe_elements'); |
|
178 | 178 | } else { |
179 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
179 | + wp_enqueue_script('woocommerce_stripe'); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * Initialize Gateway Settings Form Fields. |
185 | 185 | */ |
186 | 186 | public function init_form_fields() { |
187 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php' ); |
|
187 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sepa-settings.php'); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @return string |
196 | 196 | */ |
197 | 197 | public function mandate_display() { |
198 | - printf( __( 'By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe' ), $this->statement_descriptor ); |
|
198 | + printf(__('By providing your IBAN and confirming this payment, you are authorizing %s and Stripe, our payment service provider, to send instructions to your bank to debit your account and your bank to debit your account in accordance with those instructions. You are entitled to a refund from your bank under the terms and conditions of your agreement with your bank. A refund must be claimed within 8 weeks starting from the date on which your account was debited.', 'woocommerce-gateway-stripe'), $this->statement_descriptor); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -206,18 +206,18 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function form() { |
208 | 208 | ?> |
209 | - <fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-form" class="wc-payment-form"> |
|
210 | - <?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
|
209 | + <fieldset id="wc-<?php echo esc_attr($this->id); ?>-form" class="wc-payment-form"> |
|
210 | + <?php do_action('woocommerce_credit_card_form_start', $this->id); ?> |
|
211 | 211 | <?php $this->mandate_display(); ?> |
212 | 212 | <p class="form-row form-row-wide validate-required"> |
213 | 213 | <label for="stripe-sepa-iban"> |
214 | - <?php esc_html_e( 'IBAN.', 'woocommerce-gateway-stripe' ); ?> |
|
214 | + <?php esc_html_e('IBAN.', 'woocommerce-gateway-stripe'); ?> |
|
215 | 215 | </label> |
216 | 216 | <input id="stripe-sepa-iban" name="stripe_sepa_iban" value="" /> |
217 | 217 | </p> |
218 | 218 | <!-- Used to display form errors --> |
219 | 219 | <div class="stripe-source-errors" role="alert"></div> |
220 | - <?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
|
220 | + <?php do_action('woocommerce_credit_card_form_end', $this->id); ?> |
|
221 | 221 | <div class="clear"></div> |
222 | 222 | </fieldset> |
223 | 223 | <?php |
@@ -231,25 +231,25 @@ discard block |
||
231 | 231 | $total = WC()->cart->total; |
232 | 232 | |
233 | 233 | // If paying from order, we need to get total from order not cart. |
234 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
235 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
234 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
235 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
236 | 236 | $total = $order->get_total(); |
237 | 237 | } |
238 | 238 | |
239 | - if ( is_add_payment_method_page() ) { |
|
240 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
241 | - $total = ''; |
|
239 | + if (is_add_payment_method_page()) { |
|
240 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
241 | + $total = ''; |
|
242 | 242 | } else { |
243 | 243 | $pay_button_text = ''; |
244 | 244 | } |
245 | 245 | |
246 | 246 | echo '<div |
247 | 247 | id="stripe-sepa_debit-payment-data" |
248 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
249 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
248 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
249 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
250 | 250 | |
251 | - if ( $this->description ) { |
|
252 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
251 | + if ($this->description) { |
|
252 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | $this->form(); |
@@ -268,66 +268,66 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @return array|void |
270 | 270 | */ |
271 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
271 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
272 | 272 | try { |
273 | - $order = wc_get_order( $order_id ); |
|
274 | - $source_object = ! empty( $_POST['stripe_source_object'] ) ? json_decode( stripslashes( $_POST['stripe_source_object'] ) ) : false; |
|
273 | + $order = wc_get_order($order_id); |
|
274 | + $source_object = ! empty($_POST['stripe_source_object']) ? json_decode(stripslashes($_POST['stripe_source_object'])) : false; |
|
275 | 275 | |
276 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
276 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
277 | 277 | |
278 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
279 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
280 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
281 | - throw new Exception( $error_msg ); |
|
278 | + if (empty($source->source) && empty($source->customer)) { |
|
279 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
280 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
281 | + throw new Exception($error_msg); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | // Store source to order meta. |
285 | - $this->save_source( $order, $source ); |
|
285 | + $this->save_source($order, $source); |
|
286 | 286 | |
287 | 287 | // Result from Stripe API request. |
288 | 288 | $response = null; |
289 | 289 | |
290 | 290 | // Handle payment. |
291 | - if ( $order->get_total() > 0 ) { |
|
291 | + if ($order->get_total() > 0) { |
|
292 | 292 | |
293 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
294 | - 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 ) ) ); |
|
293 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
294 | + 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))); |
|
295 | 295 | } |
296 | 296 | |
297 | - WC_Stripe_Logger::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
297 | + WC_Stripe_Logger::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
298 | 298 | |
299 | 299 | // Make the request. |
300 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
300 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
301 | 301 | |
302 | - if ( is_wp_error( $response ) ) { |
|
302 | + if (is_wp_error($response)) { |
|
303 | 303 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
304 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
305 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
306 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
307 | - } elseif ( preg_match( '/No such customer/i', $response->get_error_message() ) && $retry ) { |
|
308 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
304 | + if ('customer' === $response->get_error_code() && $retry) { |
|
305 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
306 | + return $this->process_payment($order_id, false, $force_customer); |
|
307 | + } elseif (preg_match('/No such customer/i', $response->get_error_message()) && $retry) { |
|
308 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
309 | 309 | |
310 | - return $this->process_redirect_payment( $order_id, false, $source ); |
|
310 | + return $this->process_redirect_payment($order_id, false, $source); |
|
311 | 311 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
312 | - } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
313 | - $token = WC_Payment_Tokens::get( $source->token_id ); |
|
312 | + } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
313 | + $token = WC_Payment_Tokens::get($source->token_id); |
|
314 | 314 | $token->delete(); |
315 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
316 | - $order->add_order_note( $message ); |
|
317 | - throw new Exception( $message ); |
|
315 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
316 | + $order->add_order_note($message); |
|
317 | + throw new Exception($message); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
321 | 321 | |
322 | - $message = isset( $localized_messages[ $response->get_error_code() ] ) ? $localized_messages[ $response->get_error_code() ] : $response->get_error_message(); |
|
322 | + $message = isset($localized_messages[$response->get_error_code()]) ? $localized_messages[$response->get_error_code()] : $response->get_error_message(); |
|
323 | 323 | |
324 | - $order->add_order_note( $message ); |
|
324 | + $order->add_order_note($message); |
|
325 | 325 | |
326 | - throw new Exception( $message ); |
|
326 | + throw new Exception($message); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // Process valid response. |
330 | - $this->process_response( $response, $order ); |
|
330 | + $this->process_response($response, $order); |
|
331 | 331 | } else { |
332 | 332 | $order->payment_complete(); |
333 | 333 | } |
@@ -335,23 +335,23 @@ discard block |
||
335 | 335 | // Remove cart. |
336 | 336 | WC()->cart->empty_cart(); |
337 | 337 | |
338 | - do_action( 'wc_gateway_stripe_process_payment', $response, $order ); |
|
338 | + do_action('wc_gateway_stripe_process_payment', $response, $order); |
|
339 | 339 | |
340 | 340 | // Return thank you page redirect. |
341 | 341 | return array( |
342 | 342 | 'result' => 'success', |
343 | - 'redirect' => $this->get_return_url( $order ), |
|
343 | + 'redirect' => $this->get_return_url($order), |
|
344 | 344 | ); |
345 | 345 | |
346 | - } catch ( Exception $e ) { |
|
347 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
348 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
346 | + } catch (Exception $e) { |
|
347 | + wc_add_notice($e->getMessage(), 'error'); |
|
348 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
349 | 349 | |
350 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
351 | - $this->send_failed_order_email( $order_id ); |
|
350 | + if ($order->has_status(array('pending', 'failed'))) { |
|
351 | + $this->send_failed_order_email($order_id); |
|
352 | 352 | } |
353 | 353 | |
354 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
354 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
355 | 355 | |
356 | 356 | return array( |
357 | 357 | 'result' => 'fail', |