@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,21 +15,21 @@ discard block |
||
15 | 15 | public function __construct() { |
16 | 16 | parent::__construct(); |
17 | 17 | |
18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
23 | - add_action( 'wc_stripe_cards_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) ); |
|
24 | - add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 ); |
|
18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
23 | + add_action('wc_stripe_cards_payment_fields', array($this, 'display_update_subs_payment_checkout')); |
|
24 | + add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2); |
|
25 | 25 | |
26 | 26 | // display the credit card used for a subscription in the "My Subscriptions" table |
27 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
27 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
28 | 28 | |
29 | 29 | // allow store managers to manually set Stripe as the payment method on a subscription |
30 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
31 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
32 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
30 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
31 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
32 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | * @since 4.0.0 |
50 | 50 | * @version 4.0.0 |
51 | 51 | */ |
52 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
53 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
52 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
53 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @param int $order_id |
63 | 63 | * @return boolean |
64 | 64 | */ |
65 | - public function has_subscription( $order_id ) { |
|
66 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
65 | + public function has_subscription($order_id) { |
|
66 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @return bool |
74 | 74 | */ |
75 | 75 | public function is_subs_change_payment() { |
76 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
76 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function display_update_subs_payment_checkout() { |
86 | 86 | if ( |
87 | - apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) && |
|
88 | - wcs_user_has_subscription( get_current_user_id(), '', 'active' ) && |
|
87 | + apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) && |
|
88 | + wcs_user_has_subscription(get_current_user_id(), '', 'active') && |
|
89 | 89 | is_add_payment_method_page() |
90 | 90 | ) { |
91 | 91 | printf( |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | <input id="wc-%1$s-update-subs-payment-method-card" name="wc-%1$s-update-subs-payment-method-card" type="checkbox" value="true" style="width:auto;" /> |
94 | 94 | <label for="wc-%1$s-update-subs-payment-method-card" style="display:inline;">%2$s</label> |
95 | 95 | </p>', |
96 | - esc_attr( $this->id ), |
|
97 | - esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe' ) ) ) |
|
96 | + esc_attr($this->id), |
|
97 | + esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe'))) |
|
98 | 98 | ); |
99 | 99 | } |
100 | 100 | } |
@@ -106,16 +106,16 @@ discard block |
||
106 | 106 | * @param string $source_id |
107 | 107 | * @param object $source_object |
108 | 108 | */ |
109 | - public function handle_add_payment_method_success( $source_id, $source_object ) { |
|
110 | - if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) { |
|
109 | + public function handle_add_payment_method_success($source_id, $source_object) { |
|
110 | + if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) { |
|
111 | 111 | $all_subs = wcs_get_users_subscriptions(); |
112 | 112 | |
113 | - if ( ! empty( $all_subs ) ) { |
|
114 | - foreach ( $all_subs as $sub ) { |
|
115 | - if ( 'active' === $sub->get_status() ) { |
|
116 | - update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id ); |
|
117 | - update_post_meta( $sub->get_id(), '_payment_method', $this->id ); |
|
118 | - update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title ); |
|
113 | + if ( ! empty($all_subs)) { |
|
114 | + foreach ($all_subs as $sub) { |
|
115 | + if ('active' === $sub->get_status()) { |
|
116 | + update_post_meta($sub->get_id(), '_stripe_source_id', $source_id); |
|
117 | + update_post_meta($sub->get_id(), '_payment_method', $this->id); |
|
118 | + update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
@@ -129,34 +129,34 @@ discard block |
||
129 | 129 | * @since 4.1.11 Remove 3DS check as it is not needed. |
130 | 130 | * @param int $order_id |
131 | 131 | */ |
132 | - public function change_subs_payment_method( $order_id ) { |
|
132 | + public function change_subs_payment_method($order_id) { |
|
133 | 133 | try { |
134 | - $subscription = wc_get_order( $order_id ); |
|
135 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
134 | + $subscription = wc_get_order($order_id); |
|
135 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
136 | 136 | $source_object = $prepared_source->source_object; |
137 | 137 | |
138 | 138 | // Check if we don't allow prepaid credit cards. |
139 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) && $this->is_prepaid_card( $source_object ) ) { |
|
140 | - $localized_message = __( 'Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe' ); |
|
141 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
139 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true) && $this->is_prepaid_card($source_object)) { |
|
140 | + $localized_message = __('Sorry, we\'re not accepting prepaid cards at this time. Your credit card has not been charge. Please try with alternative payment method.', 'woocommerce-gateway-stripe'); |
|
141 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
142 | 142 | } |
143 | 143 | |
144 | - if ( empty( $prepared_source->source ) ) { |
|
145 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
146 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
144 | + if (empty($prepared_source->source)) { |
|
145 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
146 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
147 | 147 | } |
148 | 148 | |
149 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
149 | + $this->save_source_to_order($subscription, $prepared_source); |
|
150 | 150 | |
151 | - do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source ); |
|
151 | + do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source); |
|
152 | 152 | |
153 | 153 | return array( |
154 | 154 | 'result' => 'success', |
155 | - 'redirect' => $this->get_return_url( $subscription ), |
|
155 | + 'redirect' => $this->get_return_url($subscription), |
|
156 | 156 | ); |
157 | - } catch ( WC_Stripe_Exception $e ) { |
|
158 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
159 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
157 | + } catch (WC_Stripe_Exception $e) { |
|
158 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
159 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -165,16 +165,16 @@ discard block |
||
165 | 165 | * @param int $order_id |
166 | 166 | * @return array |
167 | 167 | */ |
168 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
169 | - if ( $this->has_subscription( $order_id ) ) { |
|
170 | - if ( $this->is_subs_change_payment() ) { |
|
171 | - return $this->change_subs_payment_method( $order_id ); |
|
168 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
169 | + if ($this->has_subscription($order_id)) { |
|
170 | + if ($this->is_subs_change_payment()) { |
|
171 | + return $this->change_subs_payment_method($order_id); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // Regular payment with force customer enabled |
175 | - return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
175 | + return parent::process_payment($order_id, $retry, true, $previous_error); |
|
176 | 176 | } else { |
177 | - return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
177 | + return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @param $amount_to_charge float The amount to charge. |
185 | 185 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
186 | 186 | */ |
187 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
188 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
187 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
188 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -199,86 +199,86 @@ discard block |
||
199 | 199 | * @param bool $retry Should we retry the process? |
200 | 200 | * @param object $previous_error |
201 | 201 | */ |
202 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
202 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
203 | 203 | try { |
204 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
204 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
205 | 205 | /* translators: minimum amount */ |
206 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
206 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
207 | 207 | } |
208 | 208 | |
209 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
209 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
210 | 210 | |
211 | 211 | // Get source from order |
212 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
212 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
213 | 213 | $source_object = $prepared_source->source_object; |
214 | 214 | |
215 | - if ( ! $prepared_source->customer ) { |
|
216 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
215 | + if ( ! $prepared_source->customer) { |
|
216 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
217 | 217 | } |
218 | 218 | |
219 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
219 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
220 | 220 | |
221 | 221 | /* If we're doing a retry and source is chargeable, we need to pass |
222 | 222 | * a different idempotency key and retry for success. |
223 | 223 | */ |
224 | - if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
225 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
224 | + if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
225 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
226 | 226 | } |
227 | 227 | |
228 | - if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
228 | + if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
229 | 229 | // Passing empty source will charge customer default. |
230 | 230 | $prepared_source->source = ''; |
231 | 231 | } |
232 | 232 | |
233 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
233 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
234 | 234 | $request['capture'] = 'true'; |
235 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
236 | - $response = WC_Stripe_API::request( $request ); |
|
235 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
236 | + $response = WC_Stripe_API::request($request); |
|
237 | 237 | |
238 | - if ( ! empty( $response->error ) ) { |
|
238 | + if ( ! empty($response->error)) { |
|
239 | 239 | // We want to retry. |
240 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
241 | - if ( $retry ) { |
|
240 | + if ($this->is_retryable_error($response->error)) { |
|
241 | + if ($retry) { |
|
242 | 242 | // Don't do anymore retries after this. |
243 | - if ( 5 <= $this->retry_interval ) { |
|
244 | - return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
243 | + if (5 <= $this->retry_interval) { |
|
244 | + return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
245 | 245 | } |
246 | 246 | |
247 | - sleep( $this->retry_interval ); |
|
247 | + sleep($this->retry_interval); |
|
248 | 248 | |
249 | 249 | $this->retry_interval++; |
250 | 250 | |
251 | - return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
251 | + return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
252 | 252 | } else { |
253 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
254 | - $renewal_order->add_order_note( $localized_message ); |
|
255 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
253 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
254 | + $renewal_order->add_order_note($localized_message); |
|
255 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
259 | 259 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
260 | 260 | |
261 | - if ( 'card_error' === $response->error->type ) { |
|
262 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
261 | + if ('card_error' === $response->error->type) { |
|
262 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
263 | 263 | } else { |
264 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
264 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
265 | 265 | } |
266 | 266 | |
267 | - $renewal_order->add_order_note( $localized_message ); |
|
267 | + $renewal_order->add_order_note($localized_message); |
|
268 | 268 | |
269 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
269 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
270 | 270 | } |
271 | 271 | |
272 | - do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
272 | + do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
273 | 273 | |
274 | - $this->process_response( $response, $renewal_order ); |
|
275 | - } catch ( WC_Stripe_Exception $e ) { |
|
276 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
274 | + $this->process_response($response, $renewal_order); |
|
275 | + } catch (WC_Stripe_Exception $e) { |
|
276 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
277 | 277 | |
278 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
278 | + do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
279 | 279 | |
280 | 280 | /* translators: error message */ |
281 | - $renewal_order->update_status( 'failed' ); |
|
281 | + $renewal_order->update_status('failed'); |
|
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
@@ -288,24 +288,24 @@ discard block |
||
288 | 288 | * @since 3.1.0 |
289 | 289 | * @version 4.0.0 |
290 | 290 | */ |
291 | - public function save_source_to_order( $order, $source ) { |
|
292 | - parent::save_source_to_order( $order, $source ); |
|
291 | + public function save_source_to_order($order, $source) { |
|
292 | + parent::save_source_to_order($order, $source); |
|
293 | 293 | |
294 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
294 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
295 | 295 | |
296 | 296 | // Also store it on the subscriptions being purchased or paid for in the order |
297 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
298 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
299 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
300 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
297 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
298 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
299 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
300 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
301 | 301 | } else { |
302 | 302 | $subscriptions = array(); |
303 | 303 | } |
304 | 304 | |
305 | - foreach ( $subscriptions as $subscription ) { |
|
306 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
307 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
308 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
305 | + foreach ($subscriptions as $subscription) { |
|
306 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
307 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
308 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
309 | 309 | } |
310 | 310 | } |
311 | 311 | |
@@ -313,21 +313,21 @@ discard block |
||
313 | 313 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
314 | 314 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
315 | 315 | */ |
316 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
317 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
318 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
316 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
317 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
318 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
319 | 319 | // For BW compat will remove in future |
320 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
321 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
320 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
321 | + $this->delete_renewal_meta($resubscribe_order); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
325 | 325 | * Don't transfer Stripe fee/ID meta to renewal orders. |
326 | 326 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
327 | 327 | */ |
328 | - public function delete_renewal_meta( $renewal_order ) { |
|
329 | - WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
330 | - WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
328 | + public function delete_renewal_meta($renewal_order) { |
|
329 | + WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
330 | + WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
331 | 331 | |
332 | 332 | return $renewal_order; |
333 | 333 | } |
@@ -341,14 +341,14 @@ discard block |
||
341 | 341 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
342 | 342 | * @return void |
343 | 343 | */ |
344 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
345 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
346 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
347 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
344 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
345 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
346 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
347 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
348 | 348 | |
349 | 349 | } else { |
350 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
351 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
350 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
351 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
@@ -361,23 +361,23 @@ discard block |
||
361 | 361 | * @param WC_Subscription $subscription An instance of a subscription object |
362 | 362 | * @return array |
363 | 363 | */ |
364 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
365 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
366 | - $source_id = get_post_meta( $subscription_id, '_stripe_source_id', true ); |
|
364 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
365 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
366 | + $source_id = get_post_meta($subscription_id, '_stripe_source_id', true); |
|
367 | 367 | |
368 | 368 | // For BW compat will remove in future. |
369 | - if ( empty( $source_id ) ) { |
|
370 | - $source_id = get_post_meta( $subscription_id, '_stripe_card_id', true ); |
|
369 | + if (empty($source_id)) { |
|
370 | + $source_id = get_post_meta($subscription_id, '_stripe_card_id', true); |
|
371 | 371 | |
372 | 372 | // Take this opportunity to update the key name. |
373 | - update_post_meta( $subscription_id, '_stripe_source_id', $source_id ); |
|
374 | - delete_post_meta( $subscription_id, '_stripe_card_id', $source_id ); |
|
373 | + update_post_meta($subscription_id, '_stripe_source_id', $source_id); |
|
374 | + delete_post_meta($subscription_id, '_stripe_card_id', $source_id); |
|
375 | 375 | } |
376 | 376 | |
377 | - $payment_meta[ $this->id ] = array( |
|
377 | + $payment_meta[$this->id] = array( |
|
378 | 378 | 'post_meta' => array( |
379 | 379 | '_stripe_customer_id' => array( |
380 | - 'value' => get_post_meta( $subscription_id, '_stripe_customer_id', true ), |
|
380 | + 'value' => get_post_meta($subscription_id, '_stripe_customer_id', true), |
|
381 | 381 | 'label' => 'Stripe Customer ID', |
382 | 382 | ), |
383 | 383 | '_stripe_source_id' => array( |
@@ -400,22 +400,22 @@ discard block |
||
400 | 400 | * @param array $payment_meta associative array of meta data required for automatic payments |
401 | 401 | * @return array |
402 | 402 | */ |
403 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
404 | - if ( $this->id === $payment_method_id ) { |
|
403 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
404 | + if ($this->id === $payment_method_id) { |
|
405 | 405 | |
406 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
407 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
408 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
409 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
406 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
407 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
408 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
409 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | if ( |
413 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
414 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
415 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
416 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
413 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
414 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
415 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
416 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
417 | 417 | |
418 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
418 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
419 | 419 | } |
420 | 420 | } |
421 | 421 | } |
@@ -428,75 +428,75 @@ discard block |
||
428 | 428 | * @param WC_Subscription $subscription the subscription details |
429 | 429 | * @return string the subscription payment method |
430 | 430 | */ |
431 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
432 | - $customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id(); |
|
431 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
432 | + $customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id(); |
|
433 | 433 | |
434 | 434 | // bail for other payment methods |
435 | - if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
435 | + if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
436 | 436 | return $payment_method_to_display; |
437 | 437 | } |
438 | 438 | |
439 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
439 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
440 | 440 | |
441 | 441 | // For BW compat will remove in future. |
442 | - if ( empty( $stripe_source_id ) ) { |
|
443 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
442 | + if (empty($stripe_source_id)) { |
|
443 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
444 | 444 | |
445 | 445 | // Take this opportunity to update the key name. |
446 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
446 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | $stripe_customer = new WC_Stripe_Customer(); |
450 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
450 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
451 | 451 | |
452 | 452 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
453 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
453 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
454 | 454 | $user_id = $customer_user; |
455 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
456 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
455 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
456 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
457 | 457 | |
458 | 458 | // For BW compat will remove in future. |
459 | - if ( empty( $stripe_source_id ) ) { |
|
460 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
459 | + if (empty($stripe_source_id)) { |
|
460 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
461 | 461 | |
462 | 462 | // Take this opportunity to update the key name. |
463 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
463 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
464 | 464 | } |
465 | 465 | } |
466 | 466 | |
467 | 467 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
468 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
469 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
470 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
468 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
469 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
470 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
471 | 471 | |
472 | 472 | // For BW compat will remove in future. |
473 | - if ( empty( $stripe_source_id ) ) { |
|
474 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
473 | + if (empty($stripe_source_id)) { |
|
474 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
475 | 475 | |
476 | 476 | // Take this opportunity to update the key name. |
477 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
477 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
478 | 478 | } |
479 | 479 | } |
480 | 480 | |
481 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
481 | + $stripe_customer->set_id($stripe_customer_id); |
|
482 | 482 | |
483 | 483 | $sources = $stripe_customer->get_sources(); |
484 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
484 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
485 | 485 | |
486 | - if ( $sources ) { |
|
486 | + if ($sources) { |
|
487 | 487 | $card = false; |
488 | 488 | |
489 | - foreach ( $sources as $source ) { |
|
490 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
489 | + foreach ($sources as $source) { |
|
490 | + if (isset($source->type) && 'card' === $source->type) { |
|
491 | 491 | $card = $source->card; |
492 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
492 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
493 | 493 | $card = $source; |
494 | 494 | } |
495 | 495 | |
496 | - if ( $source->id === $stripe_source_id ) { |
|
497 | - if ( $card ) { |
|
496 | + if ($source->id === $stripe_source_id) { |
|
497 | + if ($card) { |
|
498 | 498 | /* translators: 1) card brand 2) last 4 digits */ |
499 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
499 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | break; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,21 +15,21 @@ discard block |
||
15 | 15 | public function __construct() { |
16 | 16 | parent::__construct(); |
17 | 17 | |
18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
23 | - add_action( 'wc_stripe_sepa_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) ); |
|
24 | - add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 ); |
|
18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
23 | + add_action('wc_stripe_sepa_payment_fields', array($this, 'display_update_subs_payment_checkout')); |
|
24 | + add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2); |
|
25 | 25 | |
26 | 26 | // Display the credit card used for a subscription in the "My Subscriptions" table. |
27 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
27 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
28 | 28 | |
29 | 29 | // Allow store managers to manually set Stripe as the payment method on a subscription. |
30 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
31 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
32 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
30 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
31 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
32 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | * @since 4.0.0 |
50 | 50 | * @version 4.0.0 |
51 | 51 | */ |
52 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
53 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
52 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
53 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @param int $order_id |
63 | 63 | * @return boolean |
64 | 64 | */ |
65 | - public function has_subscription( $order_id ) { |
|
66 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
65 | + public function has_subscription($order_id) { |
|
66 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @return bool |
74 | 74 | */ |
75 | 75 | public function is_subs_change_payment() { |
76 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
76 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function display_update_subs_payment_checkout() { |
86 | 86 | if ( |
87 | - apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) && |
|
88 | - wcs_user_has_subscription( get_current_user_id(), '', 'active' ) && |
|
87 | + apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) && |
|
88 | + wcs_user_has_subscription(get_current_user_id(), '', 'active') && |
|
89 | 89 | is_add_payment_method_page() |
90 | 90 | ) { |
91 | 91 | printf( |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | <input id="wc-%1$s-update-subs-payment-method-card" name="wc-%1$s-update-subs-payment-method-card" type="checkbox" value="true" style="width:auto;" /> |
94 | 94 | <label for="wc-%1$s-update-subs-payment-method-card" style="display:inline;">%2$s</label> |
95 | 95 | </p>', |
96 | - esc_attr( $this->id ), |
|
97 | - esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe' ) ) ) |
|
96 | + esc_attr($this->id), |
|
97 | + esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe'))) |
|
98 | 98 | ); |
99 | 99 | } |
100 | 100 | } |
@@ -106,16 +106,16 @@ discard block |
||
106 | 106 | * @param string $source_id |
107 | 107 | * @param object $source_object |
108 | 108 | */ |
109 | - public function handle_add_payment_method_success( $source_id, $source_object ) { |
|
110 | - if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) { |
|
109 | + public function handle_add_payment_method_success($source_id, $source_object) { |
|
110 | + if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) { |
|
111 | 111 | $all_subs = wcs_get_users_subscriptions(); |
112 | 112 | |
113 | - if ( ! empty( $all_subs ) ) { |
|
114 | - foreach ( $all_subs as $sub ) { |
|
115 | - if ( 'active' === $sub->get_status() ) { |
|
116 | - update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id ); |
|
117 | - update_post_meta( $sub->get_id(), '_payment_method', $this->id ); |
|
118 | - update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title ); |
|
113 | + if ( ! empty($all_subs)) { |
|
114 | + foreach ($all_subs as $sub) { |
|
115 | + if ('active' === $sub->get_status()) { |
|
116 | + update_post_meta($sub->get_id(), '_stripe_source_id', $source_id); |
|
117 | + update_post_meta($sub->get_id(), '_payment_method', $this->id); |
|
118 | + update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
@@ -128,24 +128,24 @@ discard block |
||
128 | 128 | * @since 3.1.0 |
129 | 129 | * @version 4.0.0 |
130 | 130 | */ |
131 | - public function save_source_to_order( $order, $source ) { |
|
132 | - parent::save_source_to_order( $order, $source ); |
|
131 | + public function save_source_to_order($order, $source) { |
|
132 | + parent::save_source_to_order($order, $source); |
|
133 | 133 | |
134 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
134 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
135 | 135 | |
136 | 136 | // Also store it on the subscriptions being purchased or paid for in the order. |
137 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
138 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
139 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
140 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
137 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
138 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
139 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
140 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
141 | 141 | } else { |
142 | 142 | $subscriptions = array(); |
143 | 143 | } |
144 | 144 | |
145 | - foreach ( $subscriptions as $subscription ) { |
|
146 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
147 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
148 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
145 | + foreach ($subscriptions as $subscription) { |
|
146 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
147 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
148 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -154,16 +154,16 @@ discard block |
||
154 | 154 | * @param int $order_id |
155 | 155 | * @return array |
156 | 156 | */ |
157 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
158 | - if ( $this->has_subscription( $order_id ) ) { |
|
159 | - if ( $this->is_subs_change_payment() ) { |
|
160 | - return $this->change_subs_payment_method( $order_id ); |
|
157 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
158 | + if ($this->has_subscription($order_id)) { |
|
159 | + if ($this->is_subs_change_payment()) { |
|
160 | + return $this->change_subs_payment_method($order_id); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | // Regular payment with force customer enabled |
164 | - return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
164 | + return parent::process_payment($order_id, $retry, true, $previous_error); |
|
165 | 165 | } else { |
166 | - return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
166 | + return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
167 | 167 | } |
168 | 168 | } |
169 | 169 | |
@@ -173,27 +173,27 @@ discard block |
||
173 | 173 | * @since 4.0.4 |
174 | 174 | * @param int $order_id |
175 | 175 | */ |
176 | - public function change_subs_payment_method( $order_id ) { |
|
176 | + public function change_subs_payment_method($order_id) { |
|
177 | 177 | try { |
178 | - $subscription = wc_get_order( $order_id ); |
|
179 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
178 | + $subscription = wc_get_order($order_id); |
|
179 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
180 | 180 | |
181 | - if ( empty( $prepared_source->source ) ) { |
|
182 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
183 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
181 | + if (empty($prepared_source->source)) { |
|
182 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
183 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
184 | 184 | } |
185 | 185 | |
186 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
186 | + $this->save_source_to_order($subscription, $prepared_source); |
|
187 | 187 | |
188 | - do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source ); |
|
188 | + do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source); |
|
189 | 189 | |
190 | 190 | return array( |
191 | 191 | 'result' => 'success', |
192 | - 'redirect' => $this->get_return_url( $subscription ), |
|
192 | + 'redirect' => $this->get_return_url($subscription), |
|
193 | 193 | ); |
194 | - } catch ( WC_Stripe_Exception $e ) { |
|
195 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
196 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
194 | + } catch (WC_Stripe_Exception $e) { |
|
195 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
196 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | * @param $amount_to_charge float The amount to charge. |
204 | 204 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
205 | 205 | */ |
206 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
207 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
206 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
207 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -218,86 +218,86 @@ discard block |
||
218 | 218 | * @param bool $retry Should we retry the process? |
219 | 219 | * @param object $previous_error |
220 | 220 | */ |
221 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
221 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
222 | 222 | try { |
223 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
223 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
224 | 224 | /* translators: minimum amount */ |
225 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
225 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
226 | 226 | } |
227 | 227 | |
228 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
228 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
229 | 229 | |
230 | 230 | // Get source from order |
231 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
231 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
232 | 232 | $source_object = $prepared_source->source_object; |
233 | 233 | |
234 | - if ( ! $prepared_source->customer ) { |
|
235 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
234 | + if ( ! $prepared_source->customer) { |
|
235 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
236 | 236 | } |
237 | 237 | |
238 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
238 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
239 | 239 | |
240 | 240 | /* If we're doing a retry and source is chargeable, we need to pass |
241 | 241 | * a different idempotency key and retry for success. |
242 | 242 | */ |
243 | - if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
244 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
243 | + if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
244 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
245 | 245 | } |
246 | 246 | |
247 | - if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
247 | + if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
248 | 248 | // Passing empty source will charge customer default. |
249 | 249 | $prepared_source->source = ''; |
250 | 250 | } |
251 | 251 | |
252 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
252 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
253 | 253 | $request['capture'] = 'true'; |
254 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
255 | - $response = WC_Stripe_API::request( $request ); |
|
254 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
255 | + $response = WC_Stripe_API::request($request); |
|
256 | 256 | |
257 | - if ( ! empty( $response->error ) ) { |
|
257 | + if ( ! empty($response->error)) { |
|
258 | 258 | // We want to retry. |
259 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
260 | - if ( $retry ) { |
|
259 | + if ($this->is_retryable_error($response->error)) { |
|
260 | + if ($retry) { |
|
261 | 261 | // Don't do anymore retries after this. |
262 | - if ( 5 <= $this->retry_interval ) { |
|
263 | - return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
262 | + if (5 <= $this->retry_interval) { |
|
263 | + return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
264 | 264 | } |
265 | 265 | |
266 | - sleep( $this->retry_interval ); |
|
266 | + sleep($this->retry_interval); |
|
267 | 267 | |
268 | 268 | $this->retry_interval++; |
269 | 269 | |
270 | - return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
270 | + return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
271 | 271 | } else { |
272 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
273 | - $renewal_order->add_order_note( $localized_message ); |
|
274 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
272 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
273 | + $renewal_order->add_order_note($localized_message); |
|
274 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | 278 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
279 | 279 | |
280 | - if ( 'card_error' === $response->error->type ) { |
|
281 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
280 | + if ('card_error' === $response->error->type) { |
|
281 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
282 | 282 | } else { |
283 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
283 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
284 | 284 | } |
285 | 285 | |
286 | - $renewal_order->add_order_note( $localized_message ); |
|
286 | + $renewal_order->add_order_note($localized_message); |
|
287 | 287 | |
288 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
288 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
289 | 289 | } |
290 | 290 | |
291 | - do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
291 | + do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
292 | 292 | |
293 | - $this->process_response( $response, $renewal_order ); |
|
294 | - } catch ( WC_Stripe_Exception $e ) { |
|
295 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
293 | + $this->process_response($response, $renewal_order); |
|
294 | + } catch (WC_Stripe_Exception $e) { |
|
295 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
296 | 296 | |
297 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
297 | + do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
298 | 298 | |
299 | 299 | /* translators: error message */ |
300 | - $renewal_order->update_status( 'failed' ); |
|
300 | + $renewal_order->update_status('failed'); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
@@ -305,21 +305,21 @@ discard block |
||
305 | 305 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
306 | 306 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
307 | 307 | */ |
308 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
309 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
310 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
308 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
309 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
310 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
311 | 311 | // For BW compat will remove in future |
312 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
313 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
312 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
313 | + $this->delete_renewal_meta($resubscribe_order); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
317 | 317 | * Don't transfer Stripe fee/ID meta to renewal orders. |
318 | 318 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
319 | 319 | */ |
320 | - public function delete_renewal_meta( $renewal_order ) { |
|
321 | - WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
322 | - WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
320 | + public function delete_renewal_meta($renewal_order) { |
|
321 | + WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
322 | + WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
323 | 323 | |
324 | 324 | return $renewal_order; |
325 | 325 | } |
@@ -333,14 +333,14 @@ discard block |
||
333 | 333 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
334 | 334 | * @return void |
335 | 335 | */ |
336 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
337 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
338 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
339 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
336 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
337 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
338 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
339 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
340 | 340 | |
341 | 341 | } else { |
342 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
343 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
342 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
343 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
@@ -353,21 +353,21 @@ discard block |
||
353 | 353 | * @param WC_Subscription $subscription An instance of a subscription object |
354 | 354 | * @return array |
355 | 355 | */ |
356 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
357 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
356 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
357 | + $source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
358 | 358 | |
359 | 359 | // For BW compat will remove in future. |
360 | - if ( empty( $source_id ) ) { |
|
361 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
360 | + if (empty($source_id)) { |
|
361 | + $source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
362 | 362 | |
363 | 363 | // Take this opportunity to update the key name. |
364 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
364 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
365 | 365 | } |
366 | 366 | |
367 | - $payment_meta[ $this->id ] = array( |
|
367 | + $payment_meta[$this->id] = array( |
|
368 | 368 | 'post_meta' => array( |
369 | 369 | '_stripe_customer_id' => array( |
370 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
370 | + 'value' => get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
371 | 371 | 'label' => 'Stripe Customer ID', |
372 | 372 | ), |
373 | 373 | '_stripe_source_id' => array( |
@@ -388,22 +388,22 @@ discard block |
||
388 | 388 | * @param array $payment_meta associative array of meta data required for automatic payments |
389 | 389 | * @return array |
390 | 390 | */ |
391 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
392 | - if ( $this->id === $payment_method_id ) { |
|
391 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
392 | + if ($this->id === $payment_method_id) { |
|
393 | 393 | |
394 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
395 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
396 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
397 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
394 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
395 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
396 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
397 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | if ( |
401 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
402 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
403 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
404 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
401 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
402 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
403 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
404 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
405 | 405 | |
406 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
406 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 | } |
@@ -416,67 +416,67 @@ discard block |
||
416 | 416 | * @param WC_Subscription $subscription the subscription details |
417 | 417 | * @return string the subscription payment method |
418 | 418 | */ |
419 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
420 | - $customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id(); |
|
419 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
420 | + $customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id(); |
|
421 | 421 | |
422 | 422 | // bail for other payment methods |
423 | - if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
423 | + if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
424 | 424 | return $payment_method_to_display; |
425 | 425 | } |
426 | 426 | |
427 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
427 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
428 | 428 | |
429 | 429 | // For BW compat will remove in future. |
430 | - if ( empty( $stripe_source_id ) ) { |
|
431 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
430 | + if (empty($stripe_source_id)) { |
|
431 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
432 | 432 | |
433 | 433 | // Take this opportunity to update the key name. |
434 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
434 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | $stripe_customer = new WC_Stripe_Customer(); |
438 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
438 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
439 | 439 | |
440 | 440 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
441 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
441 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
442 | 442 | $user_id = $customer_user; |
443 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
444 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
443 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
444 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
445 | 445 | |
446 | 446 | // For BW compat will remove in future. |
447 | - if ( empty( $stripe_source_id ) ) { |
|
448 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
447 | + if (empty($stripe_source_id)) { |
|
448 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
449 | 449 | |
450 | 450 | // Take this opportunity to update the key name. |
451 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
451 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
455 | 455 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
456 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
457 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
458 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
456 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
457 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
458 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
459 | 459 | |
460 | 460 | // For BW compat will remove in future. |
461 | - if ( empty( $stripe_source_id ) ) { |
|
462 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
461 | + if (empty($stripe_source_id)) { |
|
462 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
463 | 463 | |
464 | 464 | // Take this opportunity to update the key name. |
465 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
465 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
466 | 466 | } |
467 | 467 | } |
468 | 468 | |
469 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
469 | + $stripe_customer->set_id($stripe_customer_id); |
|
470 | 470 | |
471 | 471 | $sources = $stripe_customer->get_sources(); |
472 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
472 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
473 | 473 | |
474 | - if ( $sources ) { |
|
475 | - foreach ( $sources as $source ) { |
|
476 | - if ( $source->id === $stripe_source_id ) { |
|
477 | - if ( $source->sepa_debit ) { |
|
474 | + if ($sources) { |
|
475 | + foreach ($sources as $source) { |
|
476 | + if ($source->id === $stripe_source_id) { |
|
477 | + if ($source->sepa_debit) { |
|
478 | 478 | /* translators: 1) last 4 digits of SEPA Direct Debit */ |
479 | - $payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 ); |
|
479 | + $payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | break; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_multibanco'; |
60 | - $this->method_title = __( 'Stripe Multibanco', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Multibanco', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,27 +71,27 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
91 | - add_action( 'woocommerce_thankyou_stripe_multibanco', array( $this, 'thankyou_page' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | + add_action('woocommerce_thankyou_stripe_multibanco', array($this, 'thankyou_page')); |
|
92 | 92 | |
93 | 93 | // Customer Emails |
94 | - add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); |
|
94 | + add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @return bool |
119 | 119 | */ |
120 | 120 | public function is_available() { |
121 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
121 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | $icons_str .= $icons['multibanco']; |
141 | 141 | |
142 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
142 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -150,19 +150,19 @@ discard block |
||
150 | 150 | * @access public |
151 | 151 | */ |
152 | 152 | public function payment_scripts() { |
153 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
153 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
154 | 154 | return; |
155 | 155 | } |
156 | 156 | |
157 | - wp_enqueue_style( 'stripe_styles' ); |
|
158 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
157 | + wp_enqueue_style('stripe_styles'); |
|
158 | + wp_enqueue_script('woocommerce_stripe'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * Initialize Gateway Settings Form Fields. |
163 | 163 | */ |
164 | 164 | public function init_form_fields() { |
165 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-multibanco-settings.php' ); |
|
165 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-multibanco-settings.php'); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | $description = $this->get_description(); |
175 | 175 | |
176 | 176 | // If paying from order, we need to get total from order not cart. |
177 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
178 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
177 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
178 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
179 | 179 | $total = $order->get_total(); |
180 | 180 | } |
181 | 181 | |
182 | - if ( is_add_payment_method_page() ) { |
|
183 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
182 | + if (is_add_payment_method_page()) { |
|
183 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
184 | 184 | $total = ''; |
185 | 185 | } else { |
186 | 186 | $pay_button_text = ''; |
@@ -188,11 +188,11 @@ discard block |
||
188 | 188 | |
189 | 189 | echo '<div |
190 | 190 | id="stripe-multibanco-payment-data" |
191 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
192 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
191 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
192 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
193 | 193 | |
194 | - if ( $description ) { |
|
195 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
194 | + if ($description) { |
|
195 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | echo '</div>'; |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @param int $order_id |
205 | 205 | */ |
206 | - public function thankyou_page( $order_id ) { |
|
207 | - $this->get_instructions( $order_id ); |
|
206 | + public function thankyou_page($order_id) { |
|
207 | + $this->get_instructions($order_id); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -216,15 +216,15 @@ discard block |
||
216 | 216 | * @param bool $sent_to_admin |
217 | 217 | * @param bool $plain_text |
218 | 218 | */ |
219 | - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { |
|
220 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
219 | + public function email_instructions($order, $sent_to_admin, $plain_text = false) { |
|
220 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
221 | 221 | |
222 | - $payment_method = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->payment_method : $order->get_payment_method(); |
|
222 | + $payment_method = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->payment_method : $order->get_payment_method(); |
|
223 | 223 | |
224 | - if ( ! $sent_to_admin && 'stripe_multibanco' === $payment_method && $order->has_status( 'on-hold' ) ) { |
|
225 | - WC_Stripe_Logger::log( 'Sending multibanco email for order #' . $order_id ); |
|
224 | + if ( ! $sent_to_admin && 'stripe_multibanco' === $payment_method && $order->has_status('on-hold')) { |
|
225 | + WC_Stripe_Logger::log('Sending multibanco email for order #' . $order_id); |
|
226 | 226 | |
227 | - $this->get_instructions( $order_id, $plain_text ); |
|
227 | + $this->get_instructions($order_id, $plain_text); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
@@ -235,34 +235,34 @@ discard block |
||
235 | 235 | * @version 4.1.0 |
236 | 236 | * @param int $order_id |
237 | 237 | */ |
238 | - public function get_instructions( $order_id, $plain_text = false ) { |
|
239 | - $data = get_post_meta( $order_id, '_stripe_multibanco', true ); |
|
238 | + public function get_instructions($order_id, $plain_text = false) { |
|
239 | + $data = get_post_meta($order_id, '_stripe_multibanco', true); |
|
240 | 240 | |
241 | - if ( $plain_text ) { |
|
242 | - esc_html_e( 'MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
241 | + if ($plain_text) { |
|
242 | + esc_html_e('MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
243 | 243 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
244 | - esc_html_e( 'Montante:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
244 | + esc_html_e('Montante:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
245 | 245 | echo $data['amount'] . "\n\n"; |
246 | 246 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
247 | - esc_html_e( 'Entidade:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
247 | + esc_html_e('Entidade:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
248 | 248 | echo $data['entity'] . "\n\n"; |
249 | 249 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
250 | - esc_html_e( 'Referencia:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
250 | + esc_html_e('Referencia:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
251 | 251 | echo $data['reference'] . "\n\n"; |
252 | 252 | } else { |
253 | 253 | ?> |
254 | - <h3><?php esc_html_e( 'MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe' ); ?></h3> |
|
254 | + <h3><?php esc_html_e('MULTIBANCO INFORMAÇÕES DE ENCOMENDA:', 'woocommerce-gateway-stripe'); ?></h3> |
|
255 | 255 | <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
256 | 256 | <li class="woocommerce-order-overview__order order"> |
257 | - <?php esc_html_e( 'Montante:', 'woocommerce-gateway-stripe' ); ?> |
|
257 | + <?php esc_html_e('Montante:', 'woocommerce-gateway-stripe'); ?> |
|
258 | 258 | <strong><?php echo $data['amount']; ?></strong> |
259 | 259 | </li> |
260 | 260 | <li class="woocommerce-order-overview__order order"> |
261 | - <?php esc_html_e( 'Entidade:', 'woocommerce-gateway-stripe' ); ?> |
|
261 | + <?php esc_html_e('Entidade:', 'woocommerce-gateway-stripe'); ?> |
|
262 | 262 | <strong><?php echo $data['entity']; ?></strong> |
263 | 263 | </li> |
264 | 264 | <li class="woocommerce-order-overview__order order"> |
265 | - <?php esc_html_e( 'Referencia:', 'woocommerce-gateway-stripe' ); ?> |
|
265 | + <?php esc_html_e('Referencia:', 'woocommerce-gateway-stripe'); ?> |
|
266 | 266 | <strong><?php echo $data['reference']; ?></strong> |
267 | 267 | </li> |
268 | 268 | </ul> |
@@ -278,16 +278,16 @@ discard block |
||
278 | 278 | * @param object $order |
279 | 279 | * @param object $source_object |
280 | 280 | */ |
281 | - public function save_instructions( $order, $source_object ) { |
|
281 | + public function save_instructions($order, $source_object) { |
|
282 | 282 | $data = array( |
283 | 283 | 'amount' => $order->get_formatted_order_total(), |
284 | 284 | 'entity' => $source_object->multibanco->entity, |
285 | 285 | 'reference' => $source_object->multibanco->reference, |
286 | 286 | ); |
287 | 287 | |
288 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
288 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
289 | 289 | |
290 | - update_post_meta( $order_id, '_stripe_multibanco', $data ); |
|
290 | + update_post_meta($order_id, '_stripe_multibanco', $data); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -298,24 +298,24 @@ discard block |
||
298 | 298 | * @param object $order |
299 | 299 | * @return mixed |
300 | 300 | */ |
301 | - public function create_source( $order ) { |
|
302 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
303 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
304 | - $return_url = $this->get_stripe_return_url( $order ); |
|
301 | + public function create_source($order) { |
|
302 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
303 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
304 | + $return_url = $this->get_stripe_return_url($order); |
|
305 | 305 | $post_data = array(); |
306 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
307 | - $post_data['currency'] = strtolower( $currency ); |
|
306 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
307 | + $post_data['currency'] = strtolower($currency); |
|
308 | 308 | $post_data['type'] = 'multibanco'; |
309 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
310 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
309 | + $post_data['owner'] = $this->get_owner_details($order); |
|
310 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
311 | 311 | |
312 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
313 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
312 | + if ( ! empty($this->statement_descriptor)) { |
|
313 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
314 | 314 | } |
315 | 315 | |
316 | - WC_Stripe_Logger::log( 'Info: Begin creating Multibanco source' ); |
|
316 | + WC_Stripe_Logger::log('Info: Begin creating Multibanco source'); |
|
317 | 317 | |
318 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
318 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -329,62 +329,62 @@ discard block |
||
329 | 329 | * |
330 | 330 | * @return array|void |
331 | 331 | */ |
332 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
332 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
333 | 333 | try { |
334 | - $order = wc_get_order( $order_id ); |
|
334 | + $order = wc_get_order($order_id); |
|
335 | 335 | |
336 | 336 | // This will throw exception if not valid. |
337 | - $this->validate_minimum_order_amount( $order ); |
|
337 | + $this->validate_minimum_order_amount($order); |
|
338 | 338 | |
339 | 339 | // This comes from the create account checkbox in the checkout page. |
340 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
340 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
341 | 341 | |
342 | - if ( $create_account ) { |
|
343 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
344 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
342 | + if ($create_account) { |
|
343 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
344 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
345 | 345 | $new_stripe_customer->create_customer(); |
346 | 346 | } |
347 | 347 | |
348 | - $response = $this->create_source( $order ); |
|
348 | + $response = $this->create_source($order); |
|
349 | 349 | |
350 | - if ( ! empty( $response->error ) ) { |
|
351 | - $order->add_order_note( $response->error->message ); |
|
350 | + if ( ! empty($response->error)) { |
|
351 | + $order->add_order_note($response->error->message); |
|
352 | 352 | |
353 | - throw new Exception( $response->error->message ); |
|
353 | + throw new Exception($response->error->message); |
|
354 | 354 | } |
355 | 355 | |
356 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
357 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
356 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
357 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
358 | 358 | } else { |
359 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
359 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
360 | 360 | $order->save(); |
361 | 361 | } |
362 | 362 | |
363 | - $this->save_instructions( $order, $response ); |
|
363 | + $this->save_instructions($order, $response); |
|
364 | 364 | |
365 | 365 | // Mark as on-hold (we're awaiting the payment) |
366 | - $order->update_status( 'on-hold', __( 'Awaiting Multibanco payment', 'woocommerce-gateway-stripe' ) ); |
|
366 | + $order->update_status('on-hold', __('Awaiting Multibanco payment', 'woocommerce-gateway-stripe')); |
|
367 | 367 | |
368 | 368 | // Reduce stock levels |
369 | - wc_reduce_stock_levels( $order_id ); |
|
369 | + wc_reduce_stock_levels($order_id); |
|
370 | 370 | |
371 | 371 | // Remove cart |
372 | 372 | WC()->cart->empty_cart(); |
373 | 373 | |
374 | - WC_Stripe_Logger::log( 'Info: Redirecting to Multibanco...' ); |
|
374 | + WC_Stripe_Logger::log('Info: Redirecting to Multibanco...'); |
|
375 | 375 | |
376 | 376 | return array( |
377 | 377 | 'result' => 'success', |
378 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
378 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
379 | 379 | ); |
380 | - } catch ( Exception $e ) { |
|
381 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
382 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
380 | + } catch (Exception $e) { |
|
381 | + wc_add_notice($e->getMessage(), 'error'); |
|
382 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
383 | 383 | |
384 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
384 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
385 | 385 | |
386 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
387 | - $this->send_failed_order_email( $order_id ); |
|
386 | + if ($order->has_status(array('pending', 'failed'))) { |
|
387 | + $this->send_failed_order_email($order_id); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_ideal'; |
60 | - $this->method_title = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @return bool |
115 | 115 | */ |
116 | 116 | public function is_available() { |
117 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
117 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | |
136 | 136 | $icons_str .= $icons['ideal']; |
137 | 137 | |
138 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
138 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -146,19 +146,19 @@ discard block |
||
146 | 146 | * @access public |
147 | 147 | */ |
148 | 148 | public function payment_scripts() { |
149 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
149 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | - wp_enqueue_style( 'stripe_styles' ); |
|
154 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
153 | + wp_enqueue_style('stripe_styles'); |
|
154 | + wp_enqueue_script('woocommerce_stripe'); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | 158 | * Initialize Gateway Settings Form Fields. |
159 | 159 | */ |
160 | 160 | public function init_form_fields() { |
161 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' ); |
|
161 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | $description = $this->get_description(); |
171 | 171 | |
172 | 172 | // If paying from order, we need to get total from order not cart. |
173 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
174 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
173 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
174 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
175 | 175 | $total = $order->get_total(); |
176 | 176 | } |
177 | 177 | |
178 | - if ( is_add_payment_method_page() ) { |
|
179 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
178 | + if (is_add_payment_method_page()) { |
|
179 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
180 | 180 | $total = ''; |
181 | 181 | } else { |
182 | 182 | $pay_button_text = ''; |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | |
185 | 185 | echo '<div |
186 | 186 | id="stripe-ideal-payment-data" |
187 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
188 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
187 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
188 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
189 | 189 | |
190 | - if ( $description ) { |
|
191 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
190 | + if ($description) { |
|
191 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | echo '</div>'; |
@@ -202,24 +202,24 @@ discard block |
||
202 | 202 | * @param object $order |
203 | 203 | * @return mixed |
204 | 204 | */ |
205 | - public function create_source( $order ) { |
|
206 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
207 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
208 | - $return_url = $this->get_stripe_return_url( $order ); |
|
205 | + public function create_source($order) { |
|
206 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
207 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
208 | + $return_url = $this->get_stripe_return_url($order); |
|
209 | 209 | $post_data = array(); |
210 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
211 | - $post_data['currency'] = strtolower( $currency ); |
|
210 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
211 | + $post_data['currency'] = strtolower($currency); |
|
212 | 212 | $post_data['type'] = 'ideal'; |
213 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
214 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
213 | + $post_data['owner'] = $this->get_owner_details($order); |
|
214 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
215 | 215 | |
216 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
217 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
216 | + if ( ! empty($this->statement_descriptor)) { |
|
217 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
218 | 218 | } |
219 | 219 | |
220 | - WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' ); |
|
220 | + WC_Stripe_Logger::log('Info: Begin creating iDeal source'); |
|
221 | 221 | |
222 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_ideal_source', $post_data, $order ), 'sources' ); |
|
222 | + return WC_Stripe_API::request(apply_filters('wc_stripe_ideal_source', $post_data, $order), 'sources'); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -233,51 +233,51 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @return array|void |
235 | 235 | */ |
236 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
236 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
237 | 237 | try { |
238 | - $order = wc_get_order( $order_id ); |
|
238 | + $order = wc_get_order($order_id); |
|
239 | 239 | |
240 | 240 | // This will throw exception if not valid. |
241 | - $this->validate_minimum_order_amount( $order ); |
|
241 | + $this->validate_minimum_order_amount($order); |
|
242 | 242 | |
243 | 243 | // This comes from the create account checkbox in the checkout page. |
244 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
244 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
245 | 245 | |
246 | - if ( $create_account ) { |
|
247 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
248 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
246 | + if ($create_account) { |
|
247 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
248 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
249 | 249 | $new_stripe_customer->create_customer(); |
250 | 250 | } |
251 | 251 | |
252 | - $response = $this->create_source( $order ); |
|
252 | + $response = $this->create_source($order); |
|
253 | 253 | |
254 | - if ( ! empty( $response->error ) ) { |
|
255 | - $order->add_order_note( $response->error->message ); |
|
254 | + if ( ! empty($response->error)) { |
|
255 | + $order->add_order_note($response->error->message); |
|
256 | 256 | |
257 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
257 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
258 | 258 | } |
259 | 259 | |
260 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
261 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
260 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
261 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
262 | 262 | } else { |
263 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
263 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
264 | 264 | $order->save(); |
265 | 265 | } |
266 | 266 | |
267 | - WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' ); |
|
267 | + WC_Stripe_Logger::log('Info: Redirecting to iDeal...'); |
|
268 | 268 | |
269 | 269 | return array( |
270 | 270 | 'result' => 'success', |
271 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
271 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
272 | 272 | ); |
273 | - } catch ( WC_Stripe_Exception $e ) { |
|
274 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
275 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
273 | + } catch (WC_Stripe_Exception $e) { |
|
274 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
275 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
276 | 276 | |
277 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
277 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
278 | 278 | |
279 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
280 | - $this->send_failed_order_email( $order_id ); |
|
279 | + if ($order->has_status(array('pending', 'failed'))) { |
|
280 | + $this->send_failed_order_email($order_id); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_sofort'; |
60 | - $this->method_title = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @return bool |
115 | 115 | */ |
116 | 116 | public function is_available() { |
117 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
117 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | |
136 | 136 | $icons_str .= $icons['sofort']; |
137 | 137 | |
138 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
138 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -146,19 +146,19 @@ discard block |
||
146 | 146 | * @access public |
147 | 147 | */ |
148 | 148 | public function payment_scripts() { |
149 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
149 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | - wp_enqueue_style( 'stripe_styles' ); |
|
154 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
153 | + wp_enqueue_style('stripe_styles'); |
|
154 | + wp_enqueue_script('woocommerce_stripe'); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | 158 | * Initialize Gateway Settings Form Fields. |
159 | 159 | */ |
160 | 160 | public function init_form_fields() { |
161 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
161 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | $description = $this->get_description(); |
171 | 171 | |
172 | 172 | // If paying from order, we need to get total from order not cart. |
173 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
174 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
173 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
174 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
175 | 175 | $total = $order->get_total(); |
176 | 176 | } |
177 | 177 | |
178 | - if ( is_add_payment_method_page() ) { |
|
179 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
178 | + if (is_add_payment_method_page()) { |
|
179 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
180 | 180 | $total = ''; |
181 | 181 | } else { |
182 | 182 | $pay_button_text = ''; |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | |
185 | 185 | echo '<div |
186 | 186 | id="stripe-sofort-payment-data" |
187 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
188 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
187 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
188 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
189 | 189 | |
190 | - if ( $description ) { |
|
191 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
190 | + if ($description) { |
|
191 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | echo '</div>'; |
@@ -202,28 +202,28 @@ discard block |
||
202 | 202 | * @param object $order |
203 | 203 | * @return mixed |
204 | 204 | */ |
205 | - public function create_source( $order ) { |
|
206 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
207 | - $bank_country = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->billing_country : $order->get_billing_country(); |
|
208 | - $return_url = $this->get_stripe_return_url( $order ); |
|
205 | + public function create_source($order) { |
|
206 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
207 | + $bank_country = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->billing_country : $order->get_billing_country(); |
|
208 | + $return_url = $this->get_stripe_return_url($order); |
|
209 | 209 | $post_data = array(); |
210 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
211 | - $post_data['currency'] = strtolower( $currency ); |
|
210 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
211 | + $post_data['currency'] = strtolower($currency); |
|
212 | 212 | $post_data['type'] = 'sofort'; |
213 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
214 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
213 | + $post_data['owner'] = $this->get_owner_details($order); |
|
214 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
215 | 215 | $post_data['sofort'] = array( |
216 | 216 | 'country' => $bank_country, |
217 | 217 | 'preferred_language' => $this->get_locale(), |
218 | 218 | ); |
219 | 219 | |
220 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
221 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
220 | + if ( ! empty($this->statement_descriptor)) { |
|
221 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
222 | 222 | } |
223 | 223 | |
224 | - WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' ); |
|
224 | + WC_Stripe_Logger::log('Info: Begin creating SOFORT source'); |
|
225 | 225 | |
226 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_sofort_source', $post_data, $order ), 'sources' ); |
|
226 | + return WC_Stripe_API::request(apply_filters('wc_stripe_sofort_source', $post_data, $order), 'sources'); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -237,59 +237,59 @@ discard block |
||
237 | 237 | * |
238 | 238 | * @return array|void |
239 | 239 | */ |
240 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
240 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
241 | 241 | try { |
242 | - $order = wc_get_order( $order_id ); |
|
242 | + $order = wc_get_order($order_id); |
|
243 | 243 | |
244 | 244 | // This will throw exception if not valid. |
245 | - $this->validate_minimum_order_amount( $order ); |
|
245 | + $this->validate_minimum_order_amount($order); |
|
246 | 246 | |
247 | 247 | // This comes from the create account checkbox in the checkout page. |
248 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
248 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
249 | 249 | |
250 | - if ( $create_account ) { |
|
251 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
252 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
250 | + if ($create_account) { |
|
251 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
252 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
253 | 253 | $new_stripe_customer->create_customer(); |
254 | 254 | } |
255 | 255 | |
256 | - $response = $this->create_source( $order ); |
|
256 | + $response = $this->create_source($order); |
|
257 | 257 | |
258 | - if ( ! empty( $response->error ) ) { |
|
259 | - $order->add_order_note( $response->error->message ); |
|
258 | + if ( ! empty($response->error)) { |
|
259 | + $order->add_order_note($response->error->message); |
|
260 | 260 | |
261 | 261 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
262 | 262 | |
263 | - if ( 'invalid_sofort_country' === $response->error->code ) { |
|
264 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
263 | + if ('invalid_sofort_country' === $response->error->code) { |
|
264 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
265 | 265 | } else { |
266 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
266 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
267 | 267 | } |
268 | 268 | |
269 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
269 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
270 | 270 | } |
271 | 271 | |
272 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
273 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
272 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
273 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
274 | 274 | } else { |
275 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
275 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
276 | 276 | $order->save(); |
277 | 277 | } |
278 | 278 | |
279 | - WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' ); |
|
279 | + WC_Stripe_Logger::log('Info: Redirecting to SOFORT...'); |
|
280 | 280 | |
281 | 281 | return array( |
282 | 282 | 'result' => 'success', |
283 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
283 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
284 | 284 | ); |
285 | - } catch ( WC_Stripe_Exception $e ) { |
|
286 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
287 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
285 | + } catch (WC_Stripe_Exception $e) { |
|
286 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
287 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
288 | 288 | |
289 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
289 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
290 | 290 | |
291 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
292 | - $this->send_failed_order_email( $order_id ); |
|
291 | + if ($order->has_status(array('pending', 'failed'))) { |
|
292 | + $this->send_failed_order_email($order_id); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_giropay'; |
60 | - $this->method_title = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @return bool |
115 | 115 | */ |
116 | 116 | public function is_available() { |
117 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
117 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | |
136 | 136 | $icons_str .= $icons['giropay']; |
137 | 137 | |
138 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
138 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -146,19 +146,19 @@ discard block |
||
146 | 146 | * @access public |
147 | 147 | */ |
148 | 148 | public function payment_scripts() { |
149 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
149 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | - wp_enqueue_style( 'stripe_styles' ); |
|
154 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
153 | + wp_enqueue_style('stripe_styles'); |
|
154 | + wp_enqueue_script('woocommerce_stripe'); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | 158 | * Initialize Gateway Settings Form Fields. |
159 | 159 | */ |
160 | 160 | public function init_form_fields() { |
161 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' ); |
|
161 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | $description = $this->get_description(); |
171 | 171 | |
172 | 172 | // If paying from order, we need to get total from order not cart. |
173 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
174 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
173 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
174 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
175 | 175 | $total = $order->get_total(); |
176 | 176 | } |
177 | 177 | |
178 | - if ( is_add_payment_method_page() ) { |
|
179 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
178 | + if (is_add_payment_method_page()) { |
|
179 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
180 | 180 | $total = ''; |
181 | 181 | } else { |
182 | 182 | $pay_button_text = ''; |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | |
185 | 185 | echo '<div |
186 | 186 | id="stripe-giropay-payment-data" |
187 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
188 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
187 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
188 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
189 | 189 | |
190 | - if ( $description ) { |
|
191 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
190 | + if ($description) { |
|
191 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | echo '</div>'; |
@@ -202,24 +202,24 @@ discard block |
||
202 | 202 | * @param object $order |
203 | 203 | * @return mixed |
204 | 204 | */ |
205 | - public function create_source( $order ) { |
|
206 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
207 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
208 | - $return_url = $this->get_stripe_return_url( $order ); |
|
205 | + public function create_source($order) { |
|
206 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
207 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
208 | + $return_url = $this->get_stripe_return_url($order); |
|
209 | 209 | $post_data = array(); |
210 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
211 | - $post_data['currency'] = strtolower( $currency ); |
|
210 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
211 | + $post_data['currency'] = strtolower($currency); |
|
212 | 212 | $post_data['type'] = 'giropay'; |
213 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
214 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
213 | + $post_data['owner'] = $this->get_owner_details($order); |
|
214 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
215 | 215 | |
216 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
217 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
216 | + if ( ! empty($this->statement_descriptor)) { |
|
217 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
218 | 218 | } |
219 | 219 | |
220 | - WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' ); |
|
220 | + WC_Stripe_Logger::log('Info: Begin creating Giropay source'); |
|
221 | 221 | |
222 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_giropay_source', $post_data, $order ), 'sources' ); |
|
222 | + return WC_Stripe_API::request(apply_filters('wc_stripe_giropay_source', $post_data, $order), 'sources'); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -233,51 +233,51 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @return array|void |
235 | 235 | */ |
236 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
236 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
237 | 237 | try { |
238 | - $order = wc_get_order( $order_id ); |
|
238 | + $order = wc_get_order($order_id); |
|
239 | 239 | |
240 | 240 | // This will throw exception if not valid. |
241 | - $this->validate_minimum_order_amount( $order ); |
|
241 | + $this->validate_minimum_order_amount($order); |
|
242 | 242 | |
243 | 243 | // This comes from the create account checkbox in the checkout page. |
244 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
244 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
245 | 245 | |
246 | - if ( $create_account ) { |
|
247 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
248 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
246 | + if ($create_account) { |
|
247 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
248 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
249 | 249 | $new_stripe_customer->create_customer(); |
250 | 250 | } |
251 | 251 | |
252 | - $response = $this->create_source( $order ); |
|
252 | + $response = $this->create_source($order); |
|
253 | 253 | |
254 | - if ( ! empty( $response->error ) ) { |
|
255 | - $order->add_order_note( $response->error->message ); |
|
254 | + if ( ! empty($response->error)) { |
|
255 | + $order->add_order_note($response->error->message); |
|
256 | 256 | |
257 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
257 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
258 | 258 | } |
259 | 259 | |
260 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
261 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
260 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
261 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
262 | 262 | } else { |
263 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
263 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
264 | 264 | $order->save(); |
265 | 265 | } |
266 | 266 | |
267 | - WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' ); |
|
267 | + WC_Stripe_Logger::log('Info: Redirecting to Giropay...'); |
|
268 | 268 | |
269 | 269 | return array( |
270 | 270 | 'result' => 'success', |
271 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
271 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
272 | 272 | ); |
273 | - } catch ( WC_Stripe_Exception $e ) { |
|
274 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
275 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
273 | + } catch (WC_Stripe_Exception $e) { |
|
274 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
275 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
276 | 276 | |
277 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
277 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
278 | 278 | |
279 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
280 | - $this->send_failed_order_email( $order_id ); |
|
279 | + if ($order->has_status(array('pending', 'failed'))) { |
|
280 | + $this->send_failed_order_email($order_id); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_alipay'; |
60 | - $this->method_title = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @return bool |
123 | 123 | */ |
124 | 124 | public function is_available() { |
125 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
125 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
126 | 126 | return false; |
127 | 127 | } |
128 | 128 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $icons_str .= $icons['alipay']; |
145 | 145 | |
146 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
146 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -153,19 +153,19 @@ discard block |
||
153 | 153 | * @version 4.0.0 |
154 | 154 | */ |
155 | 155 | public function payment_scripts() { |
156 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
156 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
157 | 157 | return; |
158 | 158 | } |
159 | 159 | |
160 | - wp_enqueue_style( 'stripe_styles' ); |
|
161 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
160 | + wp_enqueue_style('stripe_styles'); |
|
161 | + wp_enqueue_script('woocommerce_stripe'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * Initialize Gateway Settings Form Fields. |
166 | 166 | */ |
167 | 167 | public function init_form_fields() { |
168 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php' ); |
|
168 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-alipay-settings.php'); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -177,13 +177,13 @@ discard block |
||
177 | 177 | $description = $this->get_description(); |
178 | 178 | |
179 | 179 | // If paying from order, we need to get total from order not cart. |
180 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
181 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
180 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
181 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
182 | 182 | $total = $order->get_total(); |
183 | 183 | } |
184 | 184 | |
185 | - if ( is_add_payment_method_page() ) { |
|
186 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
185 | + if (is_add_payment_method_page()) { |
|
186 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
187 | 187 | $total = ''; |
188 | 188 | } else { |
189 | 189 | $pay_button_text = ''; |
@@ -191,11 +191,11 @@ discard block |
||
191 | 191 | |
192 | 192 | echo '<div |
193 | 193 | id="stripe-alipay-payment-data" |
194 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
195 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
194 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
195 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
196 | 196 | |
197 | - if ( $description ) { |
|
198 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
197 | + if ($description) { |
|
198 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | echo '</div>'; |
@@ -209,24 +209,24 @@ discard block |
||
209 | 209 | * @param object $order |
210 | 210 | * @return mixed |
211 | 211 | */ |
212 | - public function create_source( $order ) { |
|
213 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
214 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
215 | - $return_url = $this->get_stripe_return_url( $order ); |
|
212 | + public function create_source($order) { |
|
213 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
214 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
215 | + $return_url = $this->get_stripe_return_url($order); |
|
216 | 216 | $post_data = array(); |
217 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
218 | - $post_data['currency'] = strtolower( $currency ); |
|
217 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
218 | + $post_data['currency'] = strtolower($currency); |
|
219 | 219 | $post_data['type'] = 'alipay'; |
220 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
221 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
220 | + $post_data['owner'] = $this->get_owner_details($order); |
|
221 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
222 | 222 | |
223 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
224 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
223 | + if ( ! empty($this->statement_descriptor)) { |
|
224 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
225 | 225 | } |
226 | 226 | |
227 | - WC_Stripe_Logger::log( 'Info: Begin creating Alipay source' ); |
|
227 | + WC_Stripe_Logger::log('Info: Begin creating Alipay source'); |
|
228 | 228 | |
229 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_alipay_source', $post_data, $order ), 'sources' ); |
|
229 | + return WC_Stripe_API::request(apply_filters('wc_stripe_alipay_source', $post_data, $order), 'sources'); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -240,53 +240,53 @@ discard block |
||
240 | 240 | * |
241 | 241 | * @return array|void |
242 | 242 | */ |
243 | - public function process_payment( $order_id, $retry = true, $force_save_save = false ) { |
|
243 | + public function process_payment($order_id, $retry = true, $force_save_save = false) { |
|
244 | 244 | try { |
245 | - $order = wc_get_order( $order_id ); |
|
245 | + $order = wc_get_order($order_id); |
|
246 | 246 | |
247 | 247 | // This will throw exception if not valid. |
248 | - $this->validate_minimum_order_amount( $order ); |
|
248 | + $this->validate_minimum_order_amount($order); |
|
249 | 249 | |
250 | 250 | // This comes from the create account checkbox in the checkout page. |
251 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
251 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
252 | 252 | |
253 | - if ( $create_account ) { |
|
254 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
255 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
253 | + if ($create_account) { |
|
254 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
255 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
256 | 256 | $new_stripe_customer->create_customer(); |
257 | 257 | } |
258 | 258 | |
259 | - $response = $this->create_source( $order ); |
|
259 | + $response = $this->create_source($order); |
|
260 | 260 | |
261 | - if ( ! empty( $response->error ) ) { |
|
262 | - $order->add_order_note( $response->error->message ); |
|
261 | + if ( ! empty($response->error)) { |
|
262 | + $order->add_order_note($response->error->message); |
|
263 | 263 | |
264 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
264 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
265 | 265 | } |
266 | 266 | |
267 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
268 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
267 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
268 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
269 | 269 | } else { |
270 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
270 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
271 | 271 | $order->save(); |
272 | 272 | } |
273 | 273 | |
274 | - WC_Stripe_Logger::log( 'Info: Redirecting to Alipay...' ); |
|
274 | + WC_Stripe_Logger::log('Info: Redirecting to Alipay...'); |
|
275 | 275 | |
276 | 276 | return array( |
277 | 277 | 'result' => 'success', |
278 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
278 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
279 | 279 | ); |
280 | - } catch ( WC_Stripe_Exception $e ) { |
|
281 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
282 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
280 | + } catch (WC_Stripe_Exception $e) { |
|
281 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
282 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
283 | 283 | |
284 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
284 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
285 | 285 | |
286 | - $statuses = array( 'pending', 'failed' ); |
|
286 | + $statuses = array('pending', 'failed'); |
|
287 | 287 | |
288 | - if ( $order->has_status( $statuses ) ) { |
|
289 | - $this->send_failed_order_email( $order_id ); |
|
288 | + if ($order->has_status($statuses)) { |
|
289 | + $this->send_failed_order_email($order_id); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_eps'; |
60 | - $this->method_title = __( 'Stripe EPS', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe EPS', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @return bool |
115 | 115 | */ |
116 | 116 | public function is_available() { |
117 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
117 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | |
136 | 136 | $icons_str .= $icons['eps']; |
137 | 137 | |
138 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
138 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -146,19 +146,19 @@ discard block |
||
146 | 146 | * @access public |
147 | 147 | */ |
148 | 148 | public function payment_scripts() { |
149 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
149 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | - wp_enqueue_style( 'stripe_styles' ); |
|
154 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
153 | + wp_enqueue_style('stripe_styles'); |
|
154 | + wp_enqueue_script('woocommerce_stripe'); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | 158 | * Initialize Gateway Settings Form Fields. |
159 | 159 | */ |
160 | 160 | public function init_form_fields() { |
161 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-eps-settings.php' ); |
|
161 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-eps-settings.php'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | $description = $this->get_description(); |
171 | 171 | |
172 | 172 | // If paying from order, we need to get total from order not cart. |
173 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
174 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
173 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
174 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
175 | 175 | $total = $order->get_total(); |
176 | 176 | } |
177 | 177 | |
178 | - if ( is_add_payment_method_page() ) { |
|
179 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
178 | + if (is_add_payment_method_page()) { |
|
179 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
180 | 180 | $total = ''; |
181 | 181 | } else { |
182 | 182 | $pay_button_text = ''; |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | |
185 | 185 | echo '<div |
186 | 186 | id="stripe-eps-payment-data" |
187 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
188 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
187 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
188 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
189 | 189 | |
190 | - if ( $description ) { |
|
191 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
190 | + if ($description) { |
|
191 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | echo '</div>'; |
@@ -202,24 +202,24 @@ discard block |
||
202 | 202 | * @param object $order |
203 | 203 | * @return mixed |
204 | 204 | */ |
205 | - public function create_source( $order ) { |
|
206 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
207 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
208 | - $return_url = $this->get_stripe_return_url( $order ); |
|
205 | + public function create_source($order) { |
|
206 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
207 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
208 | + $return_url = $this->get_stripe_return_url($order); |
|
209 | 209 | $post_data = array(); |
210 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
211 | - $post_data['currency'] = strtolower( $currency ); |
|
210 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
211 | + $post_data['currency'] = strtolower($currency); |
|
212 | 212 | $post_data['type'] = 'eps'; |
213 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
214 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
213 | + $post_data['owner'] = $this->get_owner_details($order); |
|
214 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
215 | 215 | |
216 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
217 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
216 | + if ( ! empty($this->statement_descriptor)) { |
|
217 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
218 | 218 | } |
219 | 219 | |
220 | - WC_Stripe_Logger::log( 'Info: Begin creating EPS source' ); |
|
220 | + WC_Stripe_Logger::log('Info: Begin creating EPS source'); |
|
221 | 221 | |
222 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
222 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -233,51 +233,51 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @return array|void |
235 | 235 | */ |
236 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
236 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
237 | 237 | try { |
238 | - $order = wc_get_order( $order_id ); |
|
238 | + $order = wc_get_order($order_id); |
|
239 | 239 | |
240 | 240 | // This will throw exception if not valid. |
241 | - $this->validate_minimum_order_amount( $order ); |
|
241 | + $this->validate_minimum_order_amount($order); |
|
242 | 242 | |
243 | 243 | // This comes from the create account checkbox in the checkout page. |
244 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
244 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
245 | 245 | |
246 | - if ( $create_account ) { |
|
247 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
248 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
246 | + if ($create_account) { |
|
247 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
248 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
249 | 249 | $new_stripe_customer->create_customer(); |
250 | 250 | } |
251 | 251 | |
252 | - $response = $this->create_source( $order ); |
|
252 | + $response = $this->create_source($order); |
|
253 | 253 | |
254 | - if ( ! empty( $response->error ) ) { |
|
255 | - $order->add_order_note( $response->error->message ); |
|
254 | + if ( ! empty($response->error)) { |
|
255 | + $order->add_order_note($response->error->message); |
|
256 | 256 | |
257 | - throw new Exception( $response->error->message ); |
|
257 | + throw new Exception($response->error->message); |
|
258 | 258 | } |
259 | 259 | |
260 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
261 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
260 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
261 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
262 | 262 | } else { |
263 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
263 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
264 | 264 | $order->save(); |
265 | 265 | } |
266 | 266 | |
267 | - WC_Stripe_Logger::log( 'Info: Redirecting to EPS...' ); |
|
267 | + WC_Stripe_Logger::log('Info: Redirecting to EPS...'); |
|
268 | 268 | |
269 | 269 | return array( |
270 | 270 | 'result' => 'success', |
271 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
271 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
272 | 272 | ); |
273 | - } catch ( Exception $e ) { |
|
274 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
275 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
273 | + } catch (Exception $e) { |
|
274 | + wc_add_notice($e->getMessage(), 'error'); |
|
275 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
276 | 276 | |
277 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
277 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
278 | 278 | |
279 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
280 | - $this->send_failed_order_email( $order_id ); |
|
279 | + if ($order->has_status(array('pending', 'failed'))) { |
|
280 | + $this->send_failed_order_email($order_id); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_bancontact'; |
60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,23 +71,23 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @return bool |
115 | 115 | */ |
116 | 116 | public function is_available() { |
117 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
117 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | |
136 | 136 | $icons_str .= $icons['bancontact']; |
137 | 137 | |
138 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
138 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -146,19 +146,19 @@ discard block |
||
146 | 146 | * @access public |
147 | 147 | */ |
148 | 148 | public function payment_scripts() { |
149 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
149 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | - wp_enqueue_style( 'stripe_styles' ); |
|
154 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
153 | + wp_enqueue_style('stripe_styles'); |
|
154 | + wp_enqueue_script('woocommerce_stripe'); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | 158 | * Initialize Gateway Settings Form Fields. |
159 | 159 | */ |
160 | 160 | public function init_form_fields() { |
161 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
161 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | $description = $this->get_description(); |
171 | 171 | |
172 | 172 | // If paying from order, we need to get total from order not cart. |
173 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
174 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
173 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
174 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
175 | 175 | $total = $order->get_total(); |
176 | 176 | } |
177 | 177 | |
178 | - if ( is_add_payment_method_page() ) { |
|
179 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
178 | + if (is_add_payment_method_page()) { |
|
179 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
180 | 180 | $total = ''; |
181 | 181 | } else { |
182 | 182 | $pay_button_text = ''; |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | |
185 | 185 | echo '<div |
186 | 186 | id="stripe-bancontact-payment-data" |
187 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
188 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
187 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
188 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
189 | 189 | |
190 | - if ( $description ) { |
|
191 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id ); |
|
190 | + if ($description) { |
|
191 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($description)), $this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | echo '</div>'; |
@@ -202,25 +202,25 @@ discard block |
||
202 | 202 | * @param object $order |
203 | 203 | * @return mixed |
204 | 204 | */ |
205 | - public function create_source( $order ) { |
|
206 | - $currency = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->get_order_currency() : $order->get_currency(); |
|
207 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
208 | - $return_url = $this->get_stripe_return_url( $order ); |
|
205 | + public function create_source($order) { |
|
206 | + $currency = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->get_order_currency() : $order->get_currency(); |
|
207 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
208 | + $return_url = $this->get_stripe_return_url($order); |
|
209 | 209 | $post_data = array(); |
210 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
211 | - $post_data['currency'] = strtolower( $currency ); |
|
210 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
211 | + $post_data['currency'] = strtolower($currency); |
|
212 | 212 | $post_data['type'] = 'bancontact'; |
213 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
214 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
215 | - $post_data['bancontact'] = array( 'preferred_language' => $this->get_locale() ); |
|
213 | + $post_data['owner'] = $this->get_owner_details($order); |
|
214 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
215 | + $post_data['bancontact'] = array('preferred_language' => $this->get_locale()); |
|
216 | 216 | |
217 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
218 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
217 | + if ( ! empty($this->statement_descriptor)) { |
|
218 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
219 | 219 | } |
220 | 220 | |
221 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
221 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
222 | 222 | |
223 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' ); |
|
223 | + return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -234,51 +234,51 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @return array|void |
236 | 236 | */ |
237 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
237 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
238 | 238 | try { |
239 | - $order = wc_get_order( $order_id ); |
|
239 | + $order = wc_get_order($order_id); |
|
240 | 240 | |
241 | 241 | // This will throw exception if not valid. |
242 | - $this->validate_minimum_order_amount( $order ); |
|
242 | + $this->validate_minimum_order_amount($order); |
|
243 | 243 | |
244 | 244 | // This comes from the create account checkbox in the checkout page. |
245 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
245 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
246 | 246 | |
247 | - if ( $create_account ) { |
|
248 | - $new_customer_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->customer_user : $order->get_customer_id(); |
|
249 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
247 | + if ($create_account) { |
|
248 | + $new_customer_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->customer_user : $order->get_customer_id(); |
|
249 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
250 | 250 | $new_stripe_customer->create_customer(); |
251 | 251 | } |
252 | 252 | |
253 | - $response = $this->create_source( $order ); |
|
253 | + $response = $this->create_source($order); |
|
254 | 254 | |
255 | - if ( ! empty( $response->error ) ) { |
|
256 | - $order->add_order_note( $response->error->message ); |
|
255 | + if ( ! empty($response->error)) { |
|
256 | + $order->add_order_note($response->error->message); |
|
257 | 257 | |
258 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
258 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
259 | 259 | } |
260 | 260 | |
261 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
262 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
261 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
262 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
263 | 263 | } else { |
264 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
264 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
265 | 265 | $order->save(); |
266 | 266 | } |
267 | 267 | |
268 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
268 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
269 | 269 | |
270 | 270 | return array( |
271 | 271 | 'result' => 'success', |
272 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
272 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
273 | 273 | ); |
274 | - } catch ( WC_Stripe_Exception $e ) { |
|
275 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
276 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
274 | + } catch (WC_Stripe_Exception $e) { |
|
275 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
276 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
277 | 277 | |
278 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
278 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
279 | 279 | |
280 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
281 | - $this->send_failed_order_email( $order_id ); |
|
280 | + if ($order->has_status(array('pending', 'failed'))) { |
|
281 | + $this->send_failed_order_email($order_id); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | return array( |