@@ -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,24 +15,24 @@ 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 ); |
|
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 | 23 | |
24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
26 | 26 | |
27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
32 | 32 | } |
33 | 33 | |
34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * @since 4.0.0 |
44 | 44 | * @version 4.0.0 |
45 | 45 | */ |
46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param int $order_id |
57 | 57 | * @return boolean |
58 | 58 | */ |
59 | - public function has_subscription( $order_id ) { |
|
60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
59 | + public function has_subscription($order_id) { |
|
60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @param int $order_id |
66 | 66 | * @return boolean |
67 | 67 | */ |
68 | - protected function is_pre_order( $order_id ) { |
|
69 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
68 | + protected function is_pre_order($order_id) { |
|
69 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * @param int $order_id |
75 | 75 | * @return array |
76 | 76 | */ |
77 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
78 | - if ( $this->has_subscription( $order_id ) ) { |
|
77 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
78 | + if ($this->has_subscription($order_id)) { |
|
79 | 79 | // Regular payment with force customer enabled |
80 | - return parent::process_payment( $order_id, true, true ); |
|
81 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
82 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
80 | + return parent::process_payment($order_id, true, true); |
|
81 | + } elseif ($this->is_pre_order($order_id)) { |
|
82 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
83 | 83 | } else { |
84 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
84 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | * @param array $metadata |
93 | 93 | * @param object $order |
94 | 94 | */ |
95 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
96 | - if ( ! $this->has_subscription( $order->get_id() ) ) { |
|
95 | + public function add_subscription_meta_data($metadata, $order) { |
|
96 | + if ( ! $this->has_subscription($order->get_id())) { |
|
97 | 97 | return $metadata; |
98 | 98 | } |
99 | 99 | |
100 | 100 | return $metadata += array( |
101 | 101 | 'payment_type' => 'recurring', |
102 | - 'site_url' => esc_url( get_site_url() ), |
|
102 | + 'site_url' => esc_url(get_site_url()), |
|
103 | 103 | ); |
104 | 104 | } |
105 | 105 | |
@@ -109,24 +109,24 @@ discard block |
||
109 | 109 | * @since 3.1.0 |
110 | 110 | * @version 4.0.0 |
111 | 111 | */ |
112 | - public function save_source_to_order( $order, $source ) { |
|
113 | - parent::save_source_to_order( $order, $source ); |
|
112 | + public function save_source_to_order($order, $source) { |
|
113 | + parent::save_source_to_order($order, $source); |
|
114 | 114 | |
115 | - $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
115 | + $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
116 | 116 | |
117 | 117 | // Also store it on the subscriptions being purchased or paid for in the order |
118 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
119 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
120 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
121 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
118 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
119 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
120 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
121 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
122 | 122 | } else { |
123 | 123 | $subscriptions = array(); |
124 | 124 | } |
125 | 125 | |
126 | - foreach ( $subscriptions as $subscription ) { |
|
126 | + foreach ($subscriptions as $subscription) { |
|
127 | 127 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
128 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
129 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
128 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
129 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -139,45 +139,45 @@ discard block |
||
139 | 139 | * @param mixed $renewal_order |
140 | 140 | * @param bool $is_retry Is this a retry process. |
141 | 141 | */ |
142 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
143 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
142 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) { |
|
143 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
144 | 144 | /* translators: minimum amount */ |
145 | - 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 ) ) ); |
|
145 | + 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))); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
149 | 149 | |
150 | 150 | // Get source from order |
151 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
151 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
152 | 152 | |
153 | - if ( ! $prepared_source->customer ) { |
|
154 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
153 | + if ( ! $prepared_source->customer) { |
|
154 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
155 | 155 | } |
156 | 156 | |
157 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
157 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
158 | 158 | |
159 | - if ( $is_retry ) { |
|
159 | + if ($is_retry) { |
|
160 | 160 | // Passing empty source with charge customer default. |
161 | 161 | $prepared_source->source = ''; |
162 | 162 | } |
163 | 163 | |
164 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
164 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
165 | 165 | $request['capture'] = 'true'; |
166 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
167 | - $response = WC_Stripe_API::request( $request ); |
|
166 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
167 | + $response = WC_Stripe_API::request($request); |
|
168 | 168 | |
169 | - if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
170 | - if ( $is_retry ) { |
|
169 | + if ( ! empty($response->error) || is_wp_error($response)) { |
|
170 | + if ($is_retry) { |
|
171 | 171 | /* translators: error message */ |
172 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
172 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | return $response; // Default catch all errors. |
176 | 176 | } |
177 | 177 | |
178 | - $this->process_response( $response, $renewal_order ); |
|
178 | + $this->process_response($response, $renewal_order); |
|
179 | 179 | |
180 | - if ( ! $is_retry ) { |
|
180 | + if ( ! $is_retry) { |
|
181 | 181 | return $response; |
182 | 182 | } |
183 | 183 | } |
@@ -186,21 +186,21 @@ discard block |
||
186 | 186 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
187 | 187 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
188 | 188 | */ |
189 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
190 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
191 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
189 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
190 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
191 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
192 | 192 | // For BW compat will remove in future |
193 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
194 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
193 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
194 | + $this->delete_renewal_meta($resubscribe_order); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Don't transfer Stripe fee/ID meta to renewal orders. |
199 | 199 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
200 | 200 | */ |
201 | - public function delete_renewal_meta( $renewal_order ) { |
|
202 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
203 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
201 | + public function delete_renewal_meta($renewal_order) { |
|
202 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
203 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
204 | 204 | return $renewal_order; |
205 | 205 | } |
206 | 206 | |
@@ -210,21 +210,21 @@ discard block |
||
210 | 210 | * @param $amount_to_charge float The amount to charge. |
211 | 211 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
212 | 212 | */ |
213 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
214 | - $response = $this->process_subscription_payment( $amount_to_charge, $renewal_order ); |
|
213 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
214 | + $response = $this->process_subscription_payment($amount_to_charge, $renewal_order); |
|
215 | 215 | |
216 | - if ( is_wp_error( $response ) ) { |
|
216 | + if (is_wp_error($response)) { |
|
217 | 217 | /* translators: error message */ |
218 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
218 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
219 | 219 | } |
220 | 220 | |
221 | - if ( ! empty( $response->error ) ) { |
|
221 | + if ( ! empty($response->error)) { |
|
222 | 222 | // This is a very generic error to listen for but worth a retry before total fail. |
223 | - if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
224 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true ); |
|
223 | + if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
224 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true); |
|
225 | 225 | } else { |
226 | 226 | /* translators: error message */ |
227 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
227 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | } |
@@ -233,20 +233,20 @@ discard block |
||
233 | 233 | * Remove order meta |
234 | 234 | * @param object $order |
235 | 235 | */ |
236 | - public function remove_order_source_before_retry( $order ) { |
|
236 | + public function remove_order_source_before_retry($order) { |
|
237 | 237 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
238 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
238 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
239 | 239 | // For BW compat will remove in the future. |
240 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
240 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
244 | 244 | * Remove order meta |
245 | 245 | * @param object $order |
246 | 246 | */ |
247 | - public function remove_order_customer_before_retry( $order ) { |
|
247 | + public function remove_order_customer_before_retry($order) { |
|
248 | 248 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
249 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
249 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -258,14 +258,14 @@ discard block |
||
258 | 258 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
259 | 259 | * @return void |
260 | 260 | */ |
261 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
262 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
263 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
264 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
261 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
262 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
263 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
264 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
265 | 265 | |
266 | 266 | } else { |
267 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
268 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
267 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
268 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
@@ -278,21 +278,21 @@ discard block |
||
278 | 278 | * @param WC_Subscription $subscription An instance of a subscription object |
279 | 279 | * @return array |
280 | 280 | */ |
281 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
282 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
281 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
282 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
283 | 283 | |
284 | 284 | // For BW compat will remove in future. |
285 | - if ( empty( $source_id ) ) { |
|
286 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
285 | + if (empty($source_id)) { |
|
286 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
287 | 287 | |
288 | 288 | // Take this opportunity to update the key name. |
289 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
289 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
290 | 290 | } |
291 | 291 | |
292 | - $payment_meta[ $this->id ] = array( |
|
292 | + $payment_meta[$this->id] = array( |
|
293 | 293 | 'post_meta' => array( |
294 | 294 | '_stripe_customer_id' => array( |
295 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
295 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
296 | 296 | 'label' => 'Stripe Customer ID', |
297 | 297 | ), |
298 | 298 | '_stripe_source_id' => array( |
@@ -313,17 +313,17 @@ discard block |
||
313 | 313 | * @param array $payment_meta associative array of meta data required for automatic payments |
314 | 314 | * @return array |
315 | 315 | */ |
316 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
317 | - if ( $this->id === $payment_method_id ) { |
|
316 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
317 | + if ($this->id === $payment_method_id) { |
|
318 | 318 | |
319 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
320 | - throw new Exception( 'A "_stripe_customer_id" value is required.' ); |
|
321 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
322 | - throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' ); |
|
319 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
320 | + throw new Exception('A "_stripe_customer_id" value is required.'); |
|
321 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
322 | + throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".'); |
|
323 | 323 | } |
324 | 324 | |
325 | - if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) { |
|
326 | - throw new Exception( 'A "_stripe_source_id" value is required.' ); |
|
325 | + if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) { |
|
326 | + throw new Exception('A "_stripe_source_id" value is required.'); |
|
327 | 327 | } |
328 | 328 | } |
329 | 329 | } |
@@ -336,89 +336,89 @@ discard block |
||
336 | 336 | * @param WC_Subscription $subscription the subscription details |
337 | 337 | * @return string the subscription payment method |
338 | 338 | */ |
339 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
339 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
340 | 340 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
341 | 341 | |
342 | 342 | // bail for other payment methods |
343 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
343 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
344 | 344 | return $payment_method_to_display; |
345 | 345 | } |
346 | 346 | |
347 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
347 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
348 | 348 | |
349 | 349 | // For BW compat will remove in future. |
350 | - if ( empty( $stripe_source_id ) ) { |
|
351 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
350 | + if (empty($stripe_source_id)) { |
|
351 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
352 | 352 | |
353 | 353 | // Take this opportunity to update the key name. |
354 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
354 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | $stripe_customer = new WC_Stripe_Customer(); |
358 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
358 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
359 | 359 | |
360 | 360 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
361 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
361 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
362 | 362 | $user_id = $customer_user; |
363 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
364 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
363 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
364 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
365 | 365 | |
366 | 366 | // For BW compat will remove in future. |
367 | - if ( empty( $stripe_source_id ) ) { |
|
368 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
367 | + if (empty($stripe_source_id)) { |
|
368 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
369 | 369 | |
370 | 370 | // Take this opportunity to update the key name. |
371 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
371 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
375 | 375 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
376 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
377 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
378 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
376 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
377 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
378 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
379 | 379 | |
380 | 380 | // For BW compat will remove in future. |
381 | - if ( empty( $stripe_source_id ) ) { |
|
382 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
381 | + if (empty($stripe_source_id)) { |
|
382 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
383 | 383 | |
384 | 384 | // Take this opportunity to update the key name. |
385 | - WC_Stripe_Helper::is_pre_30() ? 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 ); |
|
385 | + WC_Stripe_Helper::is_pre_30() ? 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); |
|
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
389 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
389 | + $stripe_customer->set_id($stripe_customer_id); |
|
390 | 390 | $sources = $stripe_customer->get_sources(); |
391 | 391 | |
392 | - if ( $sources ) { |
|
392 | + if ($sources) { |
|
393 | 393 | $found_source = false; |
394 | - foreach ( $sources as $source ) { |
|
395 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
394 | + foreach ($sources as $source) { |
|
395 | + if (isset($source->type) && 'card' === $source->type) { |
|
396 | 396 | $card = $source->card; |
397 | 397 | } |
398 | 398 | |
399 | - if ( $source->id === $stripe_source_id ) { |
|
399 | + if ($source->id === $stripe_source_id) { |
|
400 | 400 | $found_source = true; |
401 | 401 | |
402 | - if ( $card ) { |
|
402 | + if ($card) { |
|
403 | 403 | /* translators: 1) card brand 2) last 4 digits */ |
404 | - $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 ); |
|
404 | + $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); |
|
405 | 405 | } else { |
406 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
406 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
407 | 407 | } |
408 | 408 | break; |
409 | 409 | } |
410 | 410 | } |
411 | 411 | |
412 | - if ( ! $found_source ) { |
|
413 | - if ( 'card' === $sources[0]->type ) { |
|
412 | + if ( ! $found_source) { |
|
413 | + if ('card' === $sources[0]->type) { |
|
414 | 414 | $card = $sources[0]->card; |
415 | 415 | } |
416 | 416 | |
417 | - if ( $card ) { |
|
417 | + if ($card) { |
|
418 | 418 | /* translators: 1) card brand 2) last 4 digits */ |
419 | - $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 ); |
|
419 | + $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); |
|
420 | 420 | } else { |
421 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
421 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | } |
@@ -431,42 +431,42 @@ discard block |
||
431 | 431 | * @param int $order_id |
432 | 432 | * @return array |
433 | 433 | */ |
434 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
435 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
434 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
435 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
436 | 436 | try { |
437 | - $order = wc_get_order( $order_id ); |
|
437 | + $order = wc_get_order($order_id); |
|
438 | 438 | |
439 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
439 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
440 | 440 | /* translators: minimum amount */ |
441 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
441 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
442 | 442 | } |
443 | 443 | |
444 | - $source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true ); |
|
444 | + $source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true); |
|
445 | 445 | |
446 | 446 | // We need a source on file to continue. |
447 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
448 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
447 | + if (empty($source->customer) || empty($source->source)) { |
|
448 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
449 | 449 | } |
450 | 450 | |
451 | - $this->save_source_to_order( $order, $source ); |
|
451 | + $this->save_source_to_order($order, $source); |
|
452 | 452 | |
453 | 453 | // Remove cart |
454 | 454 | WC()->cart->empty_cart(); |
455 | 455 | |
456 | 456 | // Is pre ordered! |
457 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
457 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
458 | 458 | |
459 | 459 | // Return thank you page redirect |
460 | 460 | return array( |
461 | 461 | 'result' => 'success', |
462 | - 'redirect' => $this->get_return_url( $order ), |
|
462 | + 'redirect' => $this->get_return_url($order), |
|
463 | 463 | ); |
464 | - } catch ( Exception $e ) { |
|
465 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
464 | + } catch (Exception $e) { |
|
465 | + wc_add_notice($e->getMessage(), 'error'); |
|
466 | 466 | return; |
467 | 467 | } |
468 | 468 | } else { |
469 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
469 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
470 | 470 | } |
471 | 471 | } |
472 | 472 | |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | * @param WC_Order $order |
476 | 476 | * @return void |
477 | 477 | */ |
478 | - public function process_pre_order_release_payment( $order ) { |
|
478 | + public function process_pre_order_release_payment($order) { |
|
479 | 479 | try { |
480 | 480 | // Define some callbacks if the first attempt fails. |
481 | 481 | $retry_callbacks = array( |
@@ -483,33 +483,33 @@ discard block |
||
483 | 483 | 'remove_order_customer_before_retry', |
484 | 484 | ); |
485 | 485 | |
486 | - while ( 1 ) { |
|
487 | - $source = $this->prepare_order_source( $order ); |
|
488 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
486 | + while (1) { |
|
487 | + $source = $this->prepare_order_source($order); |
|
488 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
489 | 489 | |
490 | - if ( ! empty( $response->error ) ) { |
|
491 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
492 | - throw new Exception( $response->error->message ); |
|
490 | + if ( ! empty($response->error)) { |
|
491 | + if (0 === sizeof($retry_callbacks)) { |
|
492 | + throw new Exception($response->error->message); |
|
493 | 493 | } else { |
494 | - $retry_callback = array_shift( $retry_callbacks ); |
|
495 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
494 | + $retry_callback = array_shift($retry_callbacks); |
|
495 | + call_user_func(array($this, $retry_callback), $order); |
|
496 | 496 | } |
497 | 497 | } else { |
498 | 498 | // Successful |
499 | - $this->process_response( $response, $order ); |
|
499 | + $this->process_response($response, $order); |
|
500 | 500 | break; |
501 | 501 | } |
502 | 502 | } |
503 | - } catch ( Exception $e ) { |
|
503 | + } catch (Exception $e) { |
|
504 | 504 | /* translators: error message */ |
505 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
505 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
506 | 506 | |
507 | 507 | // Mark order as failed if not already set, |
508 | 508 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
509 | - if ( ! $order->has_status( 'failed' ) ) { |
|
510 | - $order->update_status( 'failed', $order_note ); |
|
509 | + if ( ! $order->has_status('failed')) { |
|
510 | + $order->update_status('failed', $order_note); |
|
511 | 511 | } else { |
512 | - $order->add_order_note( $order_note ); |
|
512 | + $order->add_order_note($order_note); |
|
513 | 513 | } |
514 | 514 | } |
515 | 515 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | public function __construct() { |
21 | 21 | self::$_this = $this; |
22 | 22 | |
23 | - add_action( 'wp', array( $this, 'maybe_process_redirect_order' ) ); |
|
24 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
25 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
26 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
27 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
28 | - add_action( 'wc_ajax_wc_stripe_validate_checkout', array( $this, 'validate_checkout' ) ); |
|
23 | + add_action('wp', array($this, 'maybe_process_redirect_order')); |
|
24 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
25 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
26 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
27 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
28 | + add_action('wc_ajax_wc_stripe_validate_checkout', array($this, 'validate_checkout')); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -46,25 +46,25 @@ discard block |
||
46 | 46 | * @since 4.0.0 |
47 | 47 | * @version 4.0.0 |
48 | 48 | */ |
49 | - public function process_redirect_payment( $order_id, $retry = true ) { |
|
49 | + public function process_redirect_payment($order_id, $retry = true) { |
|
50 | 50 | try { |
51 | - $source = wc_clean( $_GET['source'] ); |
|
51 | + $source = wc_clean($_GET['source']); |
|
52 | 52 | |
53 | - if ( empty( $source ) ) { |
|
53 | + if (empty($source)) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | - if ( empty( $order_id ) ) { |
|
57 | + if (empty($order_id)) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | 60 | |
61 | - $order = wc_get_order( $order_id ); |
|
61 | + $order = wc_get_order($order_id); |
|
62 | 62 | |
63 | - if ( ! is_object( $order ) ) { |
|
63 | + if ( ! is_object($order)) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status() ) { |
|
67 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status() || 'on-hold' === $order->get_status()) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
@@ -72,108 +72,108 @@ discard block |
||
72 | 72 | $response = null; |
73 | 73 | |
74 | 74 | // This will throw exception if not valid. |
75 | - $this->validate_minimum_order_amount( $order ); |
|
75 | + $this->validate_minimum_order_amount($order); |
|
76 | 76 | |
77 | - WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
77 | + WC_Stripe_Logger::log("Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
78 | 78 | |
79 | 79 | /** |
80 | 80 | * First check if the source is chargeable at this time. If not, |
81 | 81 | * webhook will take care of it later. |
82 | 82 | */ |
83 | - $source_info = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
83 | + $source_info = WC_Stripe_API::retrieve('sources/' . $source); |
|
84 | 84 | |
85 | - if ( ! empty( $source_info->error ) ) { |
|
86 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), $source_info->error->message ); |
|
85 | + if ( ! empty($source_info->error)) { |
|
86 | + throw new WC_Stripe_Exception(print_r($source_info, true), $source_info->error->message); |
|
87 | 87 | } |
88 | 88 | |
89 | - if ( 'failed' === $source_info->status || 'canceled' === $source_info->status ) { |
|
90 | - throw new WC_Stripe_Exception( print_r( $source_info, true ), __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ) ); |
|
89 | + if ('failed' === $source_info->status || 'canceled' === $source_info->status) { |
|
90 | + throw new WC_Stripe_Exception(print_r($source_info, true), __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe')); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // If already consumed, then ignore request. |
94 | - if ( 'consumed' === $source_info->status ) { |
|
94 | + if ('consumed' === $source_info->status) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // If not chargeable, then ignore request. |
99 | - if ( 'chargeable' !== $source_info->status ) { |
|
99 | + if ('chargeable' !== $source_info->status) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | 103 | // Prep source object. |
104 | 104 | $source_object = new stdClass(); |
105 | 105 | $source_object->token_id = ''; |
106 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
106 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
107 | 107 | $source_object->source = $source_info->id; |
108 | 108 | |
109 | 109 | // Make the request. |
110 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
110 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
111 | 111 | |
112 | - if ( ! empty( $response->error ) ) { |
|
112 | + if ( ! empty($response->error)) { |
|
113 | 113 | // If it is an API error such connection or server, let's retry. |
114 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
115 | - if ( $retry ) { |
|
116 | - sleep( 5 ); |
|
117 | - return $this->process_redirect_payment( $order_id, false ); |
|
114 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
115 | + if ($retry) { |
|
116 | + sleep(5); |
|
117 | + return $this->process_redirect_payment($order_id, false); |
|
118 | 118 | } else { |
119 | 119 | $message = 'API connection error and retries exhausted.'; |
120 | - $order->add_order_note( $message ); |
|
121 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
120 | + $order->add_order_note($message); |
|
121 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | 125 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
126 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
127 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
128 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
129 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
126 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
127 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
128 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
129 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
130 | 130 | } else { |
131 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
132 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
131 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
132 | + $order->delete_meta_data('_stripe_customer_id'); |
|
133 | 133 | $order->save(); |
134 | 134 | } |
135 | 135 | |
136 | - return $this->process_redirect_payment( $order_id, false ); |
|
136 | + return $this->process_redirect_payment($order_id, false); |
|
137 | 137 | |
138 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
138 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
139 | 139 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
140 | 140 | |
141 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
141 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
142 | 142 | $wc_token->delete(); |
143 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
144 | - $order->add_order_note( $message ); |
|
145 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
143 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
144 | + $order->add_order_note($message); |
|
145 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
149 | 149 | |
150 | - if ( 'card_error' === $response->error->type ) { |
|
151 | - $message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
150 | + if ('card_error' === $response->error->type) { |
|
151 | + $message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
152 | 152 | } else { |
153 | - $message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
153 | + $message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
154 | 154 | } |
155 | 155 | |
156 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
156 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
157 | 157 | } |
158 | 158 | |
159 | - do_action( 'wc_gateway_stripe_process_redirect_payment', $response, $order ); |
|
159 | + do_action('wc_gateway_stripe_process_redirect_payment', $response, $order); |
|
160 | 160 | |
161 | - $this->process_response( $response, $order ); |
|
161 | + $this->process_response($response, $order); |
|
162 | 162 | |
163 | - } catch ( WC_Stripe_Exception $e ) { |
|
164 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
163 | + } catch (WC_Stripe_Exception $e) { |
|
164 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
165 | 165 | |
166 | - do_action( 'wc_gateway_stripe_process_redirect_payment_error', $e, $order ); |
|
166 | + do_action('wc_gateway_stripe_process_redirect_payment_error', $e, $order); |
|
167 | 167 | |
168 | 168 | /* translators: error message */ |
169 | - $order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) ); |
|
169 | + $order->update_status('failed', sprintf(__('Stripe payment failed: %s', 'woocommerce-gateway-stripe'), $e->getLocalizedMessage())); |
|
170 | 170 | |
171 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
172 | - $this->send_failed_order_email( $order_id ); |
|
171 | + if ($order->has_status(array('pending', 'failed'))) { |
|
172 | + $this->send_failed_order_email($order_id); |
|
173 | 173 | } |
174 | 174 | |
175 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
176 | - wp_safe_redirect( wc_get_checkout_url() ); |
|
175 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
176 | + wp_safe_redirect(wc_get_checkout_url()); |
|
177 | 177 | exit; |
178 | 178 | } |
179 | 179 | } |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | * @version 4.0.0 |
186 | 186 | */ |
187 | 187 | public function maybe_process_redirect_order() { |
188 | - if ( ! is_order_received_page() || empty( $_GET['client_secret'] ) || empty( $_GET['source'] ) ) { |
|
188 | + if ( ! is_order_received_page() || empty($_GET['client_secret']) || empty($_GET['source'])) { |
|
189 | 189 | return; |
190 | 190 | } |
191 | 191 | |
192 | - $order_id = wc_clean( $_GET['order_id'] ); |
|
192 | + $order_id = wc_clean($_GET['order_id']); |
|
193 | 193 | |
194 | - $this->process_redirect_payment( $order_id ); |
|
194 | + $this->process_redirect_payment($order_id); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -201,52 +201,52 @@ discard block |
||
201 | 201 | * @version 4.0.0 |
202 | 202 | * @param int $order_id |
203 | 203 | */ |
204 | - public function capture_payment( $order_id ) { |
|
205 | - $order = wc_get_order( $order_id ); |
|
204 | + public function capture_payment($order_id) { |
|
205 | + $order = wc_get_order($order_id); |
|
206 | 206 | |
207 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
208 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
209 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
207 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
208 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
209 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
210 | 210 | |
211 | - if ( $charge && 'no' === $captured ) { |
|
211 | + if ($charge && 'no' === $captured) { |
|
212 | 212 | $order_total = $order->get_total(); |
213 | 213 | |
214 | - if ( 0 < $order->get_total_refunded() ) { |
|
214 | + if (0 < $order->get_total_refunded()) { |
|
215 | 215 | $order_total = $order_total - $order->get_total_refunded(); |
216 | 216 | } |
217 | 217 | |
218 | - $result = WC_Stripe_API::request( array( |
|
219 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $order_total ), |
|
218 | + $result = WC_Stripe_API::request(array( |
|
219 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($order_total), |
|
220 | 220 | 'expand[]' => 'balance_transaction', |
221 | - ), 'charges/' . $charge . '/capture' ); |
|
221 | + ), 'charges/' . $charge . '/capture'); |
|
222 | 222 | |
223 | - if ( ! empty( $result->error ) ) { |
|
223 | + if ( ! empty($result->error)) { |
|
224 | 224 | /* translators: error message */ |
225 | - $order->update_status( 'failed', sprintf( __( 'Unable to capture charge! %s', 'woocommerce-gateway-stripe' ), $result->error->message ) ); |
|
225 | + $order->update_status('failed', sprintf(__('Unable to capture charge! %s', 'woocommerce-gateway-stripe'), $result->error->message)); |
|
226 | 226 | } else { |
227 | 227 | /* translators: transaction id */ |
228 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
229 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
228 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
229 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
230 | 230 | |
231 | 231 | // Store other data such as fees |
232 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $result->id ) : $order->set_transaction_id( $result->id ); |
|
232 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $result->id) : $order->set_transaction_id($result->id); |
|
233 | 233 | |
234 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
234 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
235 | 235 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
236 | 236 | // values are in the local currency of the Stripe account, not from WC. |
237 | - $fee = ! empty( $result->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'fee' ) : 0; |
|
238 | - $net = ! empty( $result->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $result->balance_transaction, 'net' ) : 0; |
|
239 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_FEE, $fee ) : $order->update_meta_data( parent::META_NAME_FEE, $fee ); |
|
240 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, parent::META_NAME_NET, $net ) : $order->update_meta_data( parent::META_NAME_NET, $net ); |
|
237 | + $fee = ! empty($result->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'fee') : 0; |
|
238 | + $net = ! empty($result->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($result->balance_transaction, 'net') : 0; |
|
239 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_FEE, $fee) : $order->update_meta_data(parent::META_NAME_FEE, $fee); |
|
240 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, parent::META_NAME_NET, $net) : $order->update_meta_data(parent::META_NAME_NET, $net); |
|
241 | 241 | } |
242 | 242 | |
243 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
243 | + if (is_callable(array($order, 'save'))) { |
|
244 | 244 | $order->save(); |
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | 248 | // This hook fires when admin manually changes order status to processing or completed. |
249 | - do_action( 'woocommerce_stripe_process_manual_capture', $order, $result ); |
|
249 | + do_action('woocommerce_stripe_process_manual_capture', $order, $result); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | } |
@@ -258,14 +258,14 @@ discard block |
||
258 | 258 | * @version 4.0.0 |
259 | 259 | * @param int $order_id |
260 | 260 | */ |
261 | - public function cancel_payment( $order_id ) { |
|
262 | - $order = wc_get_order( $order_id ); |
|
261 | + public function cancel_payment($order_id) { |
|
262 | + $order = wc_get_order($order_id); |
|
263 | 263 | |
264 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
265 | - $this->process_refund( $order_id ); |
|
264 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
265 | + $this->process_refund($order_id); |
|
266 | 266 | |
267 | 267 | // This hook fires when admin manually changes order status to cancel. |
268 | - do_action( 'woocommerce_stripe_process_manual_cancel', $order ); |
|
268 | + do_action('woocommerce_stripe_process_manual_cancel', $order); |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
@@ -277,21 +277,21 @@ discard block |
||
277 | 277 | * @param string $field |
278 | 278 | * @return string $error_field |
279 | 279 | */ |
280 | - public function normalize_field( $field ) { |
|
280 | + public function normalize_field($field) { |
|
281 | 281 | $checkout_fields = WC()->checkout->get_checkout_fields(); |
282 | 282 | $org_str = array(); |
283 | 283 | $replace_str = array(); |
284 | 284 | |
285 | - if ( array_key_exists( $field, $checkout_fields['billing'] ) ) { |
|
286 | - $error_field = __( 'Billing', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['billing'][ $field ]['label']; |
|
287 | - } elseif ( array_key_exists( $field, $checkout_fields['shipping'] ) ) { |
|
288 | - $error_field = __( 'Shipping', 'woocommerce-gateway-stripe' ) . ' ' . $checkout_fields['shipping'][ $field ]['label']; |
|
289 | - } elseif ( array_key_exists( $field, $checkout_fields['order'] ) ) { |
|
290 | - $error_field = $checkout_fields['order'][ $field ]['label']; |
|
291 | - } elseif ( array_key_exists( $field, $checkout_fields['account'] ) ) { |
|
292 | - $error_field = $checkout_fields['account'][ $field ]['label']; |
|
285 | + if (array_key_exists($field, $checkout_fields['billing'])) { |
|
286 | + $error_field = __('Billing', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['billing'][$field]['label']; |
|
287 | + } elseif (array_key_exists($field, $checkout_fields['shipping'])) { |
|
288 | + $error_field = __('Shipping', 'woocommerce-gateway-stripe') . ' ' . $checkout_fields['shipping'][$field]['label']; |
|
289 | + } elseif (array_key_exists($field, $checkout_fields['order'])) { |
|
290 | + $error_field = $checkout_fields['order'][$field]['label']; |
|
291 | + } elseif (array_key_exists($field, $checkout_fields['account'])) { |
|
292 | + $error_field = $checkout_fields['account'][$field]['label']; |
|
293 | 293 | } else { |
294 | - $error_field = str_replace( '_', ' ', $field ); |
|
294 | + $error_field = str_replace('_', ' ', $field); |
|
295 | 295 | |
296 | 296 | $org_str[] = 'stripe'; |
297 | 297 | $replace_str[] = ''; |
@@ -306,9 +306,9 @@ discard block |
||
306 | 306 | $replace_str[] = 'SOFORT'; |
307 | 307 | |
308 | 308 | $org_str[] = 'owner'; |
309 | - $replace_str[] = __( 'Owner', 'woocommerce-gateway-stripe' ); |
|
309 | + $replace_str[] = __('Owner', 'woocommerce-gateway-stripe'); |
|
310 | 310 | |
311 | - $error_field = str_replace( $org_str, $replace_str, $error_field ); |
|
311 | + $error_field = str_replace($org_str, $replace_str, $error_field); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | return $error_field; |
@@ -321,138 +321,138 @@ discard block |
||
321 | 321 | * @version 4.0.0 |
322 | 322 | */ |
323 | 323 | public function validate_checkout() { |
324 | - if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_stripe_nonce' ) ) { |
|
325 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
324 | + if ( ! wp_verify_nonce($_POST['nonce'], '_wc_stripe_nonce')) { |
|
325 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | $errors = new WP_Error(); |
329 | - parse_str( $_POST['required_fields'], $required_fields ); |
|
330 | - parse_str( $_POST['all_fields'], $all_fields ); |
|
331 | - $source_type = isset( $_POST['source_type'] ) ? wc_clean( $_POST['source_type'] ) : ''; |
|
329 | + parse_str($_POST['required_fields'], $required_fields); |
|
330 | + parse_str($_POST['all_fields'], $all_fields); |
|
331 | + $source_type = isset($_POST['source_type']) ? wc_clean($_POST['source_type']) : ''; |
|
332 | 332 | $validate_shipping_fields = false; |
333 | 333 | $create_account = false; |
334 | 334 | |
335 | - $all_fields = apply_filters( 'wc_stripe_validate_checkout_all_fields', $all_fields ); |
|
336 | - $required_fields = apply_filters( 'wc_stripe_validate_checkout_required_fields', $required_fields ); |
|
335 | + $all_fields = apply_filters('wc_stripe_validate_checkout_all_fields', $all_fields); |
|
336 | + $required_fields = apply_filters('wc_stripe_validate_checkout_required_fields', $required_fields); |
|
337 | 337 | |
338 | - array_walk_recursive( $required_fields, 'wc_clean' ); |
|
339 | - array_walk_recursive( $all_fields, 'wc_clean' ); |
|
338 | + array_walk_recursive($required_fields, 'wc_clean'); |
|
339 | + array_walk_recursive($all_fields, 'wc_clean'); |
|
340 | 340 | |
341 | 341 | /** |
342 | 342 | * If ship to different address checkbox is checked then we need |
343 | 343 | * to validate shipping fields too. |
344 | 344 | */ |
345 | - if ( isset( $all_fields['ship_to_different_address'] ) ) { |
|
345 | + if (isset($all_fields['ship_to_different_address'])) { |
|
346 | 346 | $validate_shipping_fields = true; |
347 | 347 | } |
348 | 348 | |
349 | 349 | // Check if createaccount is checked. |
350 | - if ( isset( $all_fields['createaccount'] ) ) { |
|
350 | + if (isset($all_fields['createaccount'])) { |
|
351 | 351 | $create_account = true; |
352 | 352 | } |
353 | 353 | |
354 | 354 | // Check if required fields are empty. |
355 | - foreach ( $required_fields as $field => $field_value ) { |
|
355 | + foreach ($required_fields as $field => $field_value) { |
|
356 | 356 | // Check for shipping field. |
357 | - if ( preg_match( '/^shipping_/', $field ) && ! $validate_shipping_fields ) { |
|
357 | + if (preg_match('/^shipping_/', $field) && ! $validate_shipping_fields) { |
|
358 | 358 | continue; |
359 | 359 | } |
360 | 360 | |
361 | 361 | // Check create account name. |
362 | - if ( 'account_username' === $field && ! $create_account ) { |
|
362 | + if ('account_username' === $field && ! $create_account) { |
|
363 | 363 | continue; |
364 | 364 | } |
365 | 365 | |
366 | 366 | // Check create account password. |
367 | - if ( 'account_password' === $field && ! $create_account ) { |
|
367 | + if ('account_password' === $field && ! $create_account) { |
|
368 | 368 | continue; |
369 | 369 | } |
370 | 370 | |
371 | - if ( empty( $field_value ) || '-1' === $field_value ) { |
|
372 | - $error_field = $this->normalize_field( $field ); |
|
371 | + if (empty($field_value) || '-1' === $field_value) { |
|
372 | + $error_field = $this->normalize_field($field); |
|
373 | 373 | /* translators: error field name */ |
374 | - $errors->add( 'validation', sprintf( __( '<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe' ), $error_field ) ); |
|
374 | + $errors->add('validation', sprintf(__('<strong>%s</strong> cannot be empty', 'woocommerce-gateway-stripe'), $error_field)); |
|
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
378 | 378 | // Check if email is valid format. |
379 | - if ( ! empty( $required_fields['billing_email'] ) && ! is_email( $required_fields['billing_email'] ) ) { |
|
380 | - $errors->add( 'validation', __( 'Email is not valid', 'woocommerce-gateway-stripe' ) ); |
|
379 | + if ( ! empty($required_fields['billing_email']) && ! is_email($required_fields['billing_email'])) { |
|
380 | + $errors->add('validation', __('Email is not valid', 'woocommerce-gateway-stripe')); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | // Check if phone number is valid format. |
384 | - if ( ! empty( $required_fields['billing_phone'] ) ) { |
|
385 | - $phone = wc_format_phone_number( $required_fields['billing_phone'] ); |
|
384 | + if ( ! empty($required_fields['billing_phone'])) { |
|
385 | + $phone = wc_format_phone_number($required_fields['billing_phone']); |
|
386 | 386 | |
387 | - if ( '' !== $phone && ! WC_Validation::is_phone( $phone ) ) { |
|
387 | + if ('' !== $phone && ! WC_Validation::is_phone($phone)) { |
|
388 | 388 | /* translators: %s: phone number */ |
389 | - $errors->add( 'validation', __( 'Please enter a valid phone number.', 'woocommerce-gateway-stripe' ) ); |
|
389 | + $errors->add('validation', __('Please enter a valid phone number.', 'woocommerce-gateway-stripe')); |
|
390 | 390 | } |
391 | 391 | } |
392 | 392 | |
393 | 393 | // Check if postal code is valid format. |
394 | - if ( ! empty( $required_fields['billing_postcode'] ) ) { |
|
395 | - $country = isset( $required_fields['billing_country'] ) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
396 | - $postcode = wc_format_postcode( $required_fields['billing_postcode'], $country ); |
|
394 | + if ( ! empty($required_fields['billing_postcode'])) { |
|
395 | + $country = isset($required_fields['billing_country']) ? $required_fields['billing_country'] : WC()->customer->get_billing_country(); |
|
396 | + $postcode = wc_format_postcode($required_fields['billing_postcode'], $country); |
|
397 | 397 | |
398 | - if ( '' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
399 | - $errors->add( 'validation', __( 'Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
398 | + if ('' !== $required_fields['billing_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
399 | + $errors->add('validation', __('Please enter a valid billing postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
403 | 403 | // Don't check this on add payment method page. |
404 | - if ( ( isset( $_POST['is_add_payment_page'] ) && 'no' === $_POST['is_add_payment_page'] ) ) { |
|
405 | - if ( empty( $all_fields['woocommerce_checkout_update_totals'] ) && empty( $all_fields['terms'] ) && apply_filters( 'woocommerce_checkout_show_terms', wc_get_page_id( 'terms' ) > 0 ) ) { |
|
406 | - $errors->add( 'terms', __( 'You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe' ) ); |
|
404 | + if ((isset($_POST['is_add_payment_page']) && 'no' === $_POST['is_add_payment_page'])) { |
|
405 | + if (empty($all_fields['woocommerce_checkout_update_totals']) && empty($all_fields['terms']) && apply_filters('woocommerce_checkout_show_terms', wc_get_page_id('terms') > 0)) { |
|
406 | + $errors->add('terms', __('You must accept our Terms & Conditions.', 'woocommerce-gateway-stripe')); |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | - if ( WC()->cart->needs_shipping() && $validate_shipping_fields ) { |
|
410 | + if (WC()->cart->needs_shipping() && $validate_shipping_fields) { |
|
411 | 411 | // Check if postal code is valid format. |
412 | - if ( ! empty( $required_fields['shipping_postcode'] ) ) { |
|
413 | - $country = isset( $required_fields['shipping_country'] ) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
414 | - $postcode = wc_format_postcode( $required_fields['shipping_postcode'], $country ); |
|
412 | + if ( ! empty($required_fields['shipping_postcode'])) { |
|
413 | + $country = isset($required_fields['shipping_country']) ? $required_fields['shipping_country'] : WC()->customer->get_shipping_country(); |
|
414 | + $postcode = wc_format_postcode($required_fields['shipping_postcode'], $country); |
|
415 | 415 | |
416 | - if ( '' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode( $postcode, $country ) ) { |
|
417 | - $errors->add( 'validation', __( 'Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe' ) ); |
|
416 | + if ('' !== $required_fields['shipping_postcode'] && ! WC_Validation::is_postcode($postcode, $country)) { |
|
417 | + $errors->add('validation', __('Please enter a valid shipping postcode / ZIP.', 'woocommerce-gateway-stripe')); |
|
418 | 418 | } |
419 | 419 | } |
420 | 420 | } |
421 | 421 | |
422 | - if ( WC()->cart->needs_shipping() ) { |
|
422 | + if (WC()->cart->needs_shipping()) { |
|
423 | 423 | $shipping_country = WC()->customer->get_shipping_country(); |
424 | 424 | |
425 | - if ( empty( $shipping_country ) ) { |
|
426 | - $errors->add( 'shipping', __( 'Please enter an address to continue.', 'woocommerce-gateway-stripe' ) ); |
|
427 | - } elseif ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) ) { |
|
425 | + if (empty($shipping_country)) { |
|
426 | + $errors->add('shipping', __('Please enter an address to continue.', 'woocommerce-gateway-stripe')); |
|
427 | + } elseif ( ! in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) { |
|
428 | 428 | /* translators: country name */ |
429 | - $errors->add( 'shipping', sprintf( __( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) ); |
|
429 | + $errors->add('shipping', sprintf(__('Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.', 'woocommerce-gateway-stripe'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country())); |
|
430 | 430 | } else { |
431 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
431 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
432 | 432 | |
433 | - foreach ( WC()->shipping->get_packages() as $i => $package ) { |
|
434 | - if ( ! isset( $chosen_shipping_methods[ $i ], $package['rates'][ $chosen_shipping_methods[ $i ] ] ) ) { |
|
435 | - $errors->add( 'shipping', __( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe' ) ); |
|
433 | + foreach (WC()->shipping->get_packages() as $i => $package) { |
|
434 | + if ( ! isset($chosen_shipping_methods[$i], $package['rates'][$chosen_shipping_methods[$i]])) { |
|
435 | + $errors->add('shipping', __('No shipping method has been selected. Please double check your address, or contact us if you need any help.', 'woocommerce-gateway-stripe')); |
|
436 | 436 | } |
437 | 437 | } |
438 | 438 | } |
439 | 439 | } |
440 | 440 | |
441 | - if ( WC()->cart->needs_payment() ) { |
|
441 | + if (WC()->cart->needs_payment()) { |
|
442 | 442 | $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); |
443 | 443 | |
444 | - if ( ! isset( $available_gateways[ $all_fields['payment_method'] ] ) ) { |
|
445 | - $errors->add( 'payment', __( 'Invalid payment method.', 'woocommerce-gateway-stripe' ) ); |
|
444 | + if ( ! isset($available_gateways[$all_fields['payment_method']])) { |
|
445 | + $errors->add('payment', __('Invalid payment method.', 'woocommerce-gateway-stripe')); |
|
446 | 446 | } else { |
447 | - $available_gateways[ $all_fields['payment_method'] ]->validate_fields(); |
|
447 | + $available_gateways[$all_fields['payment_method']]->validate_fields(); |
|
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | - if ( 0 === count( $errors->errors ) ) { |
|
452 | - wp_send_json( 'success' ); |
|
451 | + if (0 === count($errors->errors)) { |
|
452 | + wp_send_json('success'); |
|
453 | 453 | } else { |
454 | - foreach ( $errors->get_error_messages() as $message ) { |
|
455 | - wc_add_notice( $message, 'error' ); |
|
454 | + foreach ($errors->get_error_messages() as $message) { |
|
455 | + wc_add_notice($message, 'error'); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | $this->send_ajax_failure_response(); |
@@ -466,9 +466,9 @@ discard block |
||
466 | 466 | * @version 4.0.0 |
467 | 467 | */ |
468 | 468 | public function send_ajax_failure_response() { |
469 | - if ( is_ajax() ) { |
|
469 | + if (is_ajax()) { |
|
470 | 470 | // only print notices if not reloading the checkout, otherwise they're lost in the page reload. |
471 | - if ( ! isset( WC()->session->reload_checkout ) ) { |
|
471 | + if ( ! isset(WC()->session->reload_checkout)) { |
|
472 | 472 | ob_start(); |
473 | 473 | wc_print_notices(); |
474 | 474 | $messages = ob_get_clean(); |
@@ -476,14 +476,14 @@ discard block |
||
476 | 476 | |
477 | 477 | $response = array( |
478 | 478 | 'result' => 'failure', |
479 | - 'messages' => isset( $messages ) ? $messages : '', |
|
480 | - 'refresh' => isset( WC()->session->refresh_totals ), |
|
481 | - 'reload' => isset( WC()->session->reload_checkout ), |
|
479 | + 'messages' => isset($messages) ? $messages : '', |
|
480 | + 'refresh' => isset(WC()->session->refresh_totals), |
|
481 | + 'reload' => isset(WC()->session->reload_checkout), |
|
482 | 482 | ); |
483 | 483 | |
484 | - unset( WC()->session->refresh_totals, WC()->session->reload_checkout ); |
|
484 | + unset(WC()->session->refresh_totals, WC()->session->reload_checkout); |
|
485 | 485 | |
486 | - wp_send_json( $response ); |
|
486 | + wp_send_json($response); |
|
487 | 487 | } |
488 | 488 | } |
489 | 489 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @version 4.0.0 |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'woocommerce_api_wc_stripe', array( $this, 'check_for_webhook' ) ); |
|
20 | + add_action('woocommerce_api_wc_stripe', array($this, 'check_for_webhook')); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -27,24 +27,24 @@ discard block |
||
27 | 27 | * @version 4.0.0 |
28 | 28 | */ |
29 | 29 | public function check_for_webhook() { |
30 | - if ( ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) |
|
31 | - || ! isset( $_GET['wc-api'] ) |
|
32 | - || ( 'wc_stripe' !== $_GET['wc-api'] ) |
|
30 | + if (('POST' !== $_SERVER['REQUEST_METHOD']) |
|
31 | + || ! isset($_GET['wc-api']) |
|
32 | + || ('wc_stripe' !== $_GET['wc-api']) |
|
33 | 33 | ) { |
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | - $request_body = file_get_contents( 'php://input' ); |
|
38 | - $request_headers = array_change_key_case( $this->get_request_headers(), CASE_UPPER ); |
|
37 | + $request_body = file_get_contents('php://input'); |
|
38 | + $request_headers = array_change_key_case($this->get_request_headers(), CASE_UPPER); |
|
39 | 39 | |
40 | 40 | // Validate it to make sure it is legit. |
41 | - if ( $this->is_valid_request( $request_headers, $request_body ) ) { |
|
42 | - $this->process_webhook( $request_body ); |
|
43 | - status_header( 200 ); |
|
41 | + if ($this->is_valid_request($request_headers, $request_body)) { |
|
42 | + $this->process_webhook($request_body); |
|
43 | + status_header(200); |
|
44 | 44 | exit; |
45 | 45 | } else { |
46 | - WC_Stripe_Logger::log( 'Incoming webhook failed validation: ' . print_r( $request_body, true ) ); |
|
47 | - status_header( 400 ); |
|
46 | + WC_Stripe_Logger::log('Incoming webhook failed validation: ' . print_r($request_body, true)); |
|
47 | + status_header(400); |
|
48 | 48 | exit; |
49 | 49 | } |
50 | 50 | } |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | * @param string $request_body The request body from Stripe. |
60 | 60 | * @return bool |
61 | 61 | */ |
62 | - public function is_valid_request( $request_headers = null, $request_body = null ) { |
|
63 | - if ( null === $request_headers || null === $request_body ) { |
|
62 | + public function is_valid_request($request_headers = null, $request_body = null) { |
|
63 | + if (null === $request_headers || null === $request_body) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | |
67 | - if ( ! empty( $request_headers['USER-AGENT'] ) && ! preg_match( '/Stripe/', $request_headers['USER-AGENT'] ) ) { |
|
67 | + if ( ! empty($request_headers['USER-AGENT']) && ! preg_match('/Stripe/', $request_headers['USER-AGENT'])) { |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | * @version 4.0.0 |
81 | 81 | */ |
82 | 82 | public function get_request_headers() { |
83 | - if ( ! function_exists( 'getallheaders' ) ) { |
|
83 | + if ( ! function_exists('getallheaders')) { |
|
84 | 84 | $headers = []; |
85 | - foreach ( $_SERVER as $name => $value ) { |
|
86 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
87 | - $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
85 | + foreach ($_SERVER as $name => $value) { |
|
86 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
87 | + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -103,30 +103,30 @@ discard block |
||
103 | 103 | * @param object $notification |
104 | 104 | * @param bool $retry |
105 | 105 | */ |
106 | - public function process_webhook_payment( $notification, $retry = true ) { |
|
106 | + public function process_webhook_payment($notification, $retry = true) { |
|
107 | 107 | // The following 2 payment methods are synchronous so does not need to be handle via webhook. |
108 | - if ( 'card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type ) { |
|
108 | + if ('card' === $notification->data->object->type || 'sepa_debit' === $notification->data->object->type) { |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
112 | - $order = WC_Stripe_Helper::get_order_by_source_id( $notification->data->object->id ); |
|
112 | + $order = WC_Stripe_Helper::get_order_by_source_id($notification->data->object->id); |
|
113 | 113 | |
114 | - if ( ! $order ) { |
|
115 | - WC_Stripe_Logger::log( 'Could not find order via source ID: ' . $notification->data->object->id ); |
|
114 | + if ( ! $order) { |
|
115 | + WC_Stripe_Logger::log('Could not find order via source ID: ' . $notification->data->object->id); |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | 119 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
120 | 120 | $source_id = $notification->data->object->id; |
121 | 121 | |
122 | - $is_pending_receiver = ( 'receiver' === $notification->data->object->flow ); |
|
122 | + $is_pending_receiver = ('receiver' === $notification->data->object->flow); |
|
123 | 123 | |
124 | 124 | try { |
125 | - if ( 'processing' === $order->get_status() || 'completed' === $order->get_status() ) { |
|
125 | + if ('processing' === $order->get_status() || 'completed' === $order->get_status()) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | - if ( 'on-hold' === $order->get_status() && ! $is_pending_receiver ) { |
|
129 | + if ('on-hold' === $order->get_status() && ! $is_pending_receiver) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
@@ -134,80 +134,80 @@ discard block |
||
134 | 134 | $response = null; |
135 | 135 | |
136 | 136 | // This will throw exception if not valid. |
137 | - $this->validate_minimum_order_amount( $order ); |
|
137 | + $this->validate_minimum_order_amount($order); |
|
138 | 138 | |
139 | - WC_Stripe_Logger::log( "Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
139 | + WC_Stripe_Logger::log("Info: (Webhook) Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
140 | 140 | |
141 | 141 | // Prep source object. |
142 | 142 | $source_object = new stdClass(); |
143 | 143 | $source_object->token_id = ''; |
144 | - $source_object->customer = $this->get_stripe_customer_id( $order ); |
|
144 | + $source_object->customer = $this->get_stripe_customer_id($order); |
|
145 | 145 | $source_object->source = $source_id; |
146 | 146 | |
147 | 147 | // Make the request. |
148 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source_object ) ); |
|
148 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source_object)); |
|
149 | 149 | |
150 | - if ( ! empty( $response->error ) ) { |
|
150 | + if ( ! empty($response->error)) { |
|
151 | 151 | // If it is an API error such connection or server, let's retry. |
152 | - if ( 'api_connection_error' === $response->error->type || 'api_error' === $response->error->type ) { |
|
153 | - if ( $retry ) { |
|
154 | - sleep( 5 ); |
|
155 | - return $this->process_payment( $order_id, false ); |
|
152 | + if ('api_connection_error' === $response->error->type || 'api_error' === $response->error->type) { |
|
153 | + if ($retry) { |
|
154 | + sleep(5); |
|
155 | + return $this->process_payment($order_id, false); |
|
156 | 156 | } else { |
157 | 157 | $localized_message = 'API connection error and retries exhausted.'; |
158 | - $order->add_order_note( $localized_message ); |
|
159 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
158 | + $order->add_order_note($localized_message); |
|
159 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
164 | - if ( preg_match( '/No such customer/i', $response->error->message ) && $retry ) { |
|
165 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
166 | - delete_user_meta( $order->customer_user, '_stripe_customer_id' ); |
|
167 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
164 | + if (preg_match('/No such customer/i', $response->error->message) && $retry) { |
|
165 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
166 | + delete_user_meta($order->customer_user, '_stripe_customer_id'); |
|
167 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
168 | 168 | } else { |
169 | - delete_user_meta( $order->get_customer_id(), '_stripe_customer_id' ); |
|
170 | - $order->delete_meta_data( '_stripe_customer_id' ); |
|
169 | + delete_user_meta($order->get_customer_id(), '_stripe_customer_id'); |
|
170 | + $order->delete_meta_data('_stripe_customer_id'); |
|
171 | 171 | $order->save(); |
172 | 172 | } |
173 | 173 | |
174 | - return $this->process_payment( $order_id, false ); |
|
174 | + return $this->process_payment($order_id, false); |
|
175 | 175 | |
176 | - } elseif ( preg_match( '/No such token/i', $response->error->message ) && $source_object->token_id ) { |
|
176 | + } elseif (preg_match('/No such token/i', $response->error->message) && $source_object->token_id) { |
|
177 | 177 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
178 | - $wc_token = WC_Payment_Tokens::get( $source_object->token_id ); |
|
178 | + $wc_token = WC_Payment_Tokens::get($source_object->token_id); |
|
179 | 179 | $wc_token->delete(); |
180 | - $message = __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ); |
|
181 | - $order->add_order_note( $message ); |
|
182 | - throw new WC_Stripe_Exception( print_r( $response, true ), $message ); |
|
180 | + $message = __('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe'); |
|
181 | + $order->add_order_note($message); |
|
182 | + throw new WC_Stripe_Exception(print_r($response, true), $message); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
186 | 186 | |
187 | - if ( 'card_error' === $response->error->type ) { |
|
188 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
187 | + if ('card_error' === $response->error->type) { |
|
188 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
189 | 189 | } else { |
190 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
190 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
191 | 191 | } |
192 | 192 | |
193 | - $order->add_order_note( $localized_message ); |
|
193 | + $order->add_order_note($localized_message); |
|
194 | 194 | |
195 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
195 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
196 | 196 | } |
197 | 197 | |
198 | - do_action( 'wc_gateway_stripe_process_webhook_payment', $response, $order ); |
|
198 | + do_action('wc_gateway_stripe_process_webhook_payment', $response, $order); |
|
199 | 199 | |
200 | - $this->process_response( $response, $order ); |
|
200 | + $this->process_response($response, $order); |
|
201 | 201 | |
202 | - } catch ( WC_Stripe_Exception $e ) { |
|
203 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
202 | + } catch (WC_Stripe_Exception $e) { |
|
203 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
204 | 204 | |
205 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $e, $order ); |
|
205 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $e, $order); |
|
206 | 206 | |
207 | - $statuses = array( 'pending', 'failed' ); |
|
207 | + $statuses = array('pending', 'failed'); |
|
208 | 208 | |
209 | - if ( $order->has_status( $statuses ) ) { |
|
210 | - $this->send_failed_order_email( $order_id ); |
|
209 | + if ($order->has_status($statuses)) { |
|
210 | + $this->send_failed_order_email($order_id); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | } |
@@ -220,20 +220,20 @@ discard block |
||
220 | 220 | * @since 4.0.0 |
221 | 221 | * @param object $notification |
222 | 222 | */ |
223 | - public function process_webhook_dispute( $notification ) { |
|
224 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->charge ); |
|
223 | + public function process_webhook_dispute($notification) { |
|
224 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->charge); |
|
225 | 225 | |
226 | - if ( ! $order ) { |
|
227 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->charge ); |
|
226 | + if ( ! $order) { |
|
227 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->charge); |
|
228 | 228 | return; |
229 | 229 | } |
230 | 230 | |
231 | - $order->update_status( 'on-hold', __( 'A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe' ) ); |
|
231 | + $order->update_status('on-hold', __('A dispute was created for this order. Response is needed. Please go to your Stripe Dashboard to review this dispute.', 'woocommerce-gateway-stripe')); |
|
232 | 232 | |
233 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
233 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
234 | 234 | |
235 | 235 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
236 | - $this->send_failed_order_email( $order_id ); |
|
236 | + $this->send_failed_order_email($order_id); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -244,41 +244,41 @@ discard block |
||
244 | 244 | * @version 4.0.0 |
245 | 245 | * @param object $notification |
246 | 246 | */ |
247 | - public function process_webhook_capture( $notification ) { |
|
248 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
247 | + public function process_webhook_capture($notification) { |
|
248 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
249 | 249 | |
250 | - if ( ! $order ) { |
|
251 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
250 | + if ( ! $order) { |
|
251 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | 255 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
256 | 256 | |
257 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
258 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
259 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
257 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
258 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
259 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
260 | 260 | |
261 | - if ( $charge && 'no' === $captured ) { |
|
262 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', 'yes' ) : $order->update_meta_data( '_stripe_charge_captured', 'yes' ); |
|
261 | + if ($charge && 'no' === $captured) { |
|
262 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', 'yes') : $order->update_meta_data('_stripe_charge_captured', 'yes'); |
|
263 | 263 | |
264 | 264 | // Store other data such as fees |
265 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
265 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
266 | 266 | |
267 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
268 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
267 | + if (isset($notification->data->object->balance_transaction)) { |
|
268 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
269 | 269 | } |
270 | 270 | |
271 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
271 | + if (is_callable(array($order, 'save'))) { |
|
272 | 272 | $order->save(); |
273 | 273 | } |
274 | 274 | |
275 | 275 | /* translators: transaction id */ |
276 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
276 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
277 | 277 | |
278 | 278 | // Check and see if capture is partial. |
279 | - if ( $this->is_partial_capture( $notification ) ) { |
|
280 | - $order->set_total( $this->get_partial_amount_to_charge( $notification ) ); |
|
281 | - $order->add_note( __( 'This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe' ) ); |
|
279 | + if ($this->is_partial_capture($notification)) { |
|
280 | + $order->set_total($this->get_partial_amount_to_charge($notification)); |
|
281 | + $order->add_note(__('This charge was partially captured via Stripe Dashboard', 'woocommerce-gateway-stripe')); |
|
282 | 282 | $order->save(); |
283 | 283 | } |
284 | 284 | } |
@@ -293,38 +293,38 @@ discard block |
||
293 | 293 | * @version 4.0.0 |
294 | 294 | * @param object $notification |
295 | 295 | */ |
296 | - public function process_webhook_charge_succeeded( $notification ) { |
|
296 | + public function process_webhook_charge_succeeded($notification) { |
|
297 | 297 | // The following payment methods are synchronous so does not need to be handle via webhook. |
298 | - if ( ( isset( $notification->data->object->source->type ) && 'card' === $notification->data->object->source->type ) || ( isset( $notification->data->object->source->type ) && 'three_d_secure' === $notification->data->object->source->type ) ) { |
|
298 | + if ((isset($notification->data->object->source->type) && 'card' === $notification->data->object->source->type) || (isset($notification->data->object->source->type) && 'three_d_secure' === $notification->data->object->source->type)) { |
|
299 | 299 | return; |
300 | 300 | } |
301 | 301 | |
302 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
302 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
303 | 303 | |
304 | - if ( ! $order ) { |
|
305 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
304 | + if ( ! $order) { |
|
305 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
306 | 306 | return; |
307 | 307 | } |
308 | 308 | |
309 | 309 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
310 | 310 | |
311 | - if ( 'on-hold' !== $order->get_status() ) { |
|
311 | + if ('on-hold' !== $order->get_status()) { |
|
312 | 312 | return; |
313 | 313 | } |
314 | 314 | |
315 | 315 | // Store other data such as fees |
316 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $notification->data->object->id ) : $order->set_transaction_id( $notification->data->object->id ); |
|
316 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $notification->data->object->id) : $order->set_transaction_id($notification->data->object->id); |
|
317 | 317 | |
318 | - if ( isset( $notification->data->object->balance_transaction ) ) { |
|
319 | - $this->update_fees( $order, $notification->data->object->balance_transaction ); |
|
318 | + if (isset($notification->data->object->balance_transaction)) { |
|
319 | + $this->update_fees($order, $notification->data->object->balance_transaction); |
|
320 | 320 | } |
321 | 321 | |
322 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
322 | + if (is_callable(array($order, 'save'))) { |
|
323 | 323 | $order->save(); |
324 | 324 | } |
325 | 325 | |
326 | 326 | /* translators: transaction id */ |
327 | - $order->update_status( $order->needs_processing() ? 'processing' : 'completed', sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $notification->data->object->id ) ); |
|
327 | + $order->update_status($order->needs_processing() ? 'processing' : 'completed', sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $notification->data->object->id)); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -335,23 +335,23 @@ discard block |
||
335 | 335 | * @version 4.0.0 |
336 | 336 | * @param object $notification |
337 | 337 | */ |
338 | - public function process_webhook_charge_failed( $notification ) { |
|
339 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
338 | + public function process_webhook_charge_failed($notification) { |
|
339 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
340 | 340 | |
341 | - if ( ! $order ) { |
|
342 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
341 | + if ( ! $order) { |
|
342 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
343 | 343 | return; |
344 | 344 | } |
345 | 345 | |
346 | 346 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
347 | 347 | |
348 | - if ( 'on-hold' !== $order->get_status() ) { |
|
348 | + if ('on-hold' !== $order->get_status()) { |
|
349 | 349 | return; |
350 | 350 | } |
351 | 351 | |
352 | - $order->update_status( 'failed', __( 'This payment failed to clear.', 'woocommerce-gateway-stripe' ) ); |
|
352 | + $order->update_status('failed', __('This payment failed to clear.', 'woocommerce-gateway-stripe')); |
|
353 | 353 | |
354 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
354 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -362,23 +362,23 @@ discard block |
||
362 | 362 | * @version 4.0.0 |
363 | 363 | * @param object $notification |
364 | 364 | */ |
365 | - public function process_webhook_source_canceled( $notification ) { |
|
366 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
365 | + public function process_webhook_source_canceled($notification) { |
|
366 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
367 | 367 | |
368 | - if ( ! $order ) { |
|
369 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
368 | + if ( ! $order) { |
|
369 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
370 | 370 | return; |
371 | 371 | } |
372 | 372 | |
373 | 373 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
374 | 374 | |
375 | - if ( 'on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status() ) { |
|
375 | + if ('on-hold' !== $order->get_status() || 'cancelled' !== $order->get_status()) { |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | |
379 | - $order->update_status( 'cancelled', __( 'This payment has cancelled.', 'woocommerce-gateway-stripe' ) ); |
|
379 | + $order->update_status('cancelled', __('This payment has cancelled.', 'woocommerce-gateway-stripe')); |
|
380 | 380 | |
381 | - do_action( 'wc_gateway_stripe_process_webhook_payment_error', $order, $notification ); |
|
381 | + do_action('wc_gateway_stripe_process_webhook_payment_error', $order, $notification); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -389,42 +389,42 @@ discard block |
||
389 | 389 | * @version 4.0.0 |
390 | 390 | * @param object $notification |
391 | 391 | */ |
392 | - public function process_webhook_refund( $notification ) { |
|
393 | - $order = WC_Stripe_Helper::get_order_by_charge_id( $notification->data->object->id ); |
|
392 | + public function process_webhook_refund($notification) { |
|
393 | + $order = WC_Stripe_Helper::get_order_by_charge_id($notification->data->object->id); |
|
394 | 394 | |
395 | - if ( ! $order ) { |
|
396 | - WC_Stripe_Logger::log( 'Could not find order via charge ID: ' . $notification->data->object->id ); |
|
395 | + if ( ! $order) { |
|
396 | + WC_Stripe_Logger::log('Could not find order via charge ID: ' . $notification->data->object->id); |
|
397 | 397 | return; |
398 | 398 | } |
399 | 399 | |
400 | 400 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
401 | 401 | |
402 | - if ( 'stripe' === ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) ) { |
|
403 | - $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_transaction_id', true ) : $order->get_transaction_id(); |
|
404 | - $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_charge_captured', true ) : $order->get_meta( '_stripe_charge_captured', true ); |
|
405 | - $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_refund_id', true ) : $order->get_meta( '_stripe_refund_id', true ); |
|
402 | + if ('stripe' === (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method())) { |
|
403 | + $charge = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_transaction_id', true) : $order->get_transaction_id(); |
|
404 | + $captured = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_charge_captured', true) : $order->get_meta('_stripe_charge_captured', true); |
|
405 | + $refund_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_refund_id', true) : $order->get_meta('_stripe_refund_id', true); |
|
406 | 406 | |
407 | 407 | // If the refund ID matches, don't continue to prevent double refunding. |
408 | - if ( $notification->data->object->refunds->data[0]->id === $refund_id ) { |
|
408 | + if ($notification->data->object->refunds->data[0]->id === $refund_id) { |
|
409 | 409 | return; |
410 | 410 | } |
411 | 411 | |
412 | 412 | // Only refund captured charge. |
413 | - if ( $charge ) { |
|
414 | - $reason = ( isset( $captured ) && 'yes' === $captured ) ? __( 'Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe' ) : __( 'Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe' ); |
|
413 | + if ($charge) { |
|
414 | + $reason = (isset($captured) && 'yes' === $captured) ? __('Refunded via Stripe Dashboard', 'woocommerce-gateway-stripe') : __('Pre-Authorization Released via Stripe Dashboard', 'woocommerce-gateway-stripe'); |
|
415 | 415 | |
416 | 416 | // Create the refund. |
417 | - $refund = wc_create_refund( array( |
|
417 | + $refund = wc_create_refund(array( |
|
418 | 418 | 'order_id' => $order_id, |
419 | - 'amount' => $this->get_refund_amount( $notification ), |
|
419 | + 'amount' => $this->get_refund_amount($notification), |
|
420 | 420 | 'reason' => $reason, |
421 | - ) ); |
|
421 | + )); |
|
422 | 422 | |
423 | - if ( is_wp_error( $refund ) ) { |
|
424 | - WC_Stripe_Logger::log( $refund->get_error_message() ); |
|
423 | + if (is_wp_error($refund)) { |
|
424 | + WC_Stripe_Logger::log($refund->get_error_message()); |
|
425 | 425 | } |
426 | 426 | |
427 | - $order->add_order_note( $reason ); |
|
427 | + $order->add_order_note($reason); |
|
428 | 428 | } |
429 | 429 | } |
430 | 430 | } |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * @version 4.0.0 |
437 | 437 | * @param object $notification |
438 | 438 | */ |
439 | - public function is_partial_capture( $notification ) { |
|
439 | + public function is_partial_capture($notification) { |
|
440 | 440 | return 0 < $notification->data->object->amount_refunded; |
441 | 441 | } |
442 | 442 | |
@@ -447,11 +447,11 @@ discard block |
||
447 | 447 | * @version 4.0.0 |
448 | 448 | * @param object $notification |
449 | 449 | */ |
450 | - public function get_refund_amount( $notification ) { |
|
451 | - if ( $this->is_partial_capture( $notification ) ) { |
|
450 | + public function get_refund_amount($notification) { |
|
451 | + if ($this->is_partial_capture($notification)) { |
|
452 | 452 | $amount = $notification->data->object->amount_refunded / 100; |
453 | 453 | |
454 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
454 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
455 | 455 | $amount = $notification->data->object->amount_refunded; |
456 | 456 | } |
457 | 457 | |
@@ -468,12 +468,12 @@ discard block |
||
468 | 468 | * @version 4.0.0 |
469 | 469 | * @param object $notification |
470 | 470 | */ |
471 | - public function get_partial_amount_to_charge( $notification ) { |
|
472 | - if ( $this->is_partial_capture( $notification ) ) { |
|
473 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ) / 100; |
|
471 | + public function get_partial_amount_to_charge($notification) { |
|
472 | + if ($this->is_partial_capture($notification)) { |
|
473 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded) / 100; |
|
474 | 474 | |
475 | - if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
476 | - $amount = ( $notification->data->object->amount - $notification->data->object->amount_refunded ); |
|
475 | + if (in_array(strtolower($notification->data->object->currency), WC_Stripe_Helper::no_decimal_currencies())) { |
|
476 | + $amount = ($notification->data->object->amount - $notification->data->object->amount_refunded); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | return $amount; |
@@ -489,43 +489,43 @@ discard block |
||
489 | 489 | * @version 4.0.0 |
490 | 490 | * @param string $request_body |
491 | 491 | */ |
492 | - public function process_webhook( $request_body ) { |
|
493 | - $notification = json_decode( $request_body ); |
|
492 | + public function process_webhook($request_body) { |
|
493 | + $notification = json_decode($request_body); |
|
494 | 494 | |
495 | 495 | /* |
496 | 496 | * Hacky way to possibly prevent duplicate requests due to |
497 | 497 | * frontend request and webhook payment firing at the same |
498 | 498 | * time. |
499 | 499 | */ |
500 | - sleep( 10 ); |
|
500 | + sleep(10); |
|
501 | 501 | |
502 | - switch ( $notification->type ) { |
|
502 | + switch ($notification->type) { |
|
503 | 503 | case 'source.chargeable': |
504 | - $this->process_webhook_payment( $notification ); |
|
504 | + $this->process_webhook_payment($notification); |
|
505 | 505 | break; |
506 | 506 | |
507 | 507 | case 'source.canceled': |
508 | - $this->process_webhook_source_canceled( $notification ); |
|
508 | + $this->process_webhook_source_canceled($notification); |
|
509 | 509 | break; |
510 | 510 | |
511 | 511 | case 'charge.succeeded': |
512 | - $this->process_webhook_charge_succeeded( $notification ); |
|
512 | + $this->process_webhook_charge_succeeded($notification); |
|
513 | 513 | break; |
514 | 514 | |
515 | 515 | case 'charge.failed': |
516 | - $this->process_webhook_charge_failed( $notification ); |
|
516 | + $this->process_webhook_charge_failed($notification); |
|
517 | 517 | break; |
518 | 518 | |
519 | 519 | case 'charge.captured': |
520 | - $this->process_webhook_capture( $notification ); |
|
520 | + $this->process_webhook_capture($notification); |
|
521 | 521 | break; |
522 | 522 | |
523 | 523 | case 'charge.dispute.created': |
524 | - $this->process_webhook_dispute( $notification ); |
|
524 | + $this->process_webhook_dispute($notification); |
|
525 | 525 | break; |
526 | 526 | |
527 | 527 | case 'charge.refunded': |
528 | - $this->process_webhook_refund( $notification ); |
|
528 | + $this->process_webhook_refund($notification); |
|
529 | 529 | break; |
530 | 530 | |
531 | 531 | } |
@@ -14,20 +14,20 @@ discard block |
||
14 | 14 | * |
15 | 15 | */ |
16 | 16 | |
17 | -if ( ! defined( 'ABSPATH' ) ) { |
|
17 | +if ( ! defined('ABSPATH')) { |
|
18 | 18 | exit; |
19 | 19 | } |
20 | 20 | |
21 | -if ( ! class_exists( 'WC_Stripe' ) ) : |
|
21 | +if ( ! class_exists('WC_Stripe')) : |
|
22 | 22 | /** |
23 | 23 | * Required minimums and constants |
24 | 24 | */ |
25 | - define( 'WC_STRIPE_VERSION', '4.0.4' ); |
|
26 | - define( 'WC_STRIPE_MIN_PHP_VER', '5.6.0' ); |
|
27 | - define( 'WC_STRIPE_MIN_WC_VER', '2.6.0' ); |
|
28 | - define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
29 | - define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
30 | - define( 'WC_STRIPE_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); |
|
25 | + define('WC_STRIPE_VERSION', '4.0.4'); |
|
26 | + define('WC_STRIPE_MIN_PHP_VER', '5.6.0'); |
|
27 | + define('WC_STRIPE_MIN_WC_VER', '2.6.0'); |
|
28 | + define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
29 | + define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
30 | + define('WC_STRIPE_PLUGIN_PATH', untrailingslashit(plugin_dir_path(__FILE__))); |
|
31 | 31 | |
32 | 32 | class WC_Stripe { |
33 | 33 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return Singleton The *Singleton* instance. |
48 | 48 | */ |
49 | 49 | public static function get_instance() { |
50 | - if ( null === self::$instance ) { |
|
50 | + if (null === self::$instance) { |
|
51 | 51 | self::$instance = new self(); |
52 | 52 | } |
53 | 53 | return self::$instance; |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | * *Singleton* via the `new` operator from outside of this class. |
81 | 81 | */ |
82 | 82 | private function __construct() { |
83 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
84 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
85 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
86 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
83 | + add_action('admin_init', array($this, 'check_environment')); |
|
84 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
85 | + add_action('plugins_loaded', array($this, 'init')); |
|
86 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -93,43 +93,43 @@ discard block |
||
93 | 93 | * @version 4.0.0 |
94 | 94 | */ |
95 | 95 | public function init() { |
96 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-exception.php' ); |
|
97 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-logger.php' ); |
|
98 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-helper.php' ); |
|
99 | - include_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-api.php' ); |
|
96 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-exception.php'); |
|
97 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-logger.php'); |
|
98 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-helper.php'); |
|
99 | + include_once(dirname(__FILE__) . '/includes/class-wc-stripe-api.php'); |
|
100 | 100 | |
101 | 101 | // Don't hook anything else in the plugin if we're in an incompatible environment |
102 | - if ( self::get_environment_warning() ) { |
|
102 | + if (self::get_environment_warning()) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
107 | - |
|
108 | - require_once( dirname( __FILE__ ) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php' ); |
|
109 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-webhook-handler.php' ); |
|
110 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-sepa-payment-token.php' ); |
|
111 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-gateway-stripe.php' ); |
|
112 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php' ); |
|
113 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php' ); |
|
114 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php' ); |
|
115 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php' ); |
|
116 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php' ); |
|
117 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php' ); |
|
118 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php' ); |
|
119 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php' ); |
|
120 | - require_once( dirname( __FILE__ ) . '/includes/payment-methods/class-wc-stripe-payment-request.php' ); |
|
121 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-compat.php' ); |
|
122 | - require_once( dirname( __FILE__ ) . '/includes/compat/class-wc-stripe-sepa-compat.php' ); |
|
123 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-order-handler.php' ); |
|
124 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-payment-tokens.php' ); |
|
125 | - require_once( dirname( __FILE__ ) . '/includes/class-wc-stripe-customer.php' ); |
|
106 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
107 | + |
|
108 | + require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-stripe-payment-gateway.php'); |
|
109 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-webhook-handler.php'); |
|
110 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-sepa-payment-token.php'); |
|
111 | + require_once(dirname(__FILE__) . '/includes/class-wc-gateway-stripe.php'); |
|
112 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'); |
|
113 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'); |
|
114 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'); |
|
115 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-ideal.php'); |
|
116 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-p24.php'); |
|
117 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-alipay.php'); |
|
118 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-sepa.php'); |
|
119 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-gateway-stripe-bitcoin.php'); |
|
120 | + require_once(dirname(__FILE__) . '/includes/payment-methods/class-wc-stripe-payment-request.php'); |
|
121 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-compat.php'); |
|
122 | + require_once(dirname(__FILE__) . '/includes/compat/class-wc-stripe-sepa-compat.php'); |
|
123 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-order-handler.php'); |
|
124 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-payment-tokens.php'); |
|
125 | + require_once(dirname(__FILE__) . '/includes/class-wc-stripe-customer.php'); |
|
126 | 126 | |
127 | 127 | // REMOVE IN THE FUTURE. |
128 | - require_once( dirname( __FILE__ ) . '/includes/deprecated/class-wc-stripe-apple-pay.php' ); |
|
128 | + require_once(dirname(__FILE__) . '/includes/deprecated/class-wc-stripe-apple-pay.php'); |
|
129 | 129 | |
130 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
131 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
132 | - add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_gateway_order_admin' ) ); |
|
130 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
131 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
132 | + add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,23 +139,23 @@ discard block |
||
139 | 139 | * @version 4.0.0 |
140 | 140 | */ |
141 | 141 | public function hide_notices() { |
142 | - if ( isset( $_GET['wc-stripe-hide-notice'] ) && isset( $_GET['_wc_stripe_notice_nonce'] ) ) { |
|
143 | - if ( ! wp_verify_nonce( $_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce' ) ) { |
|
144 | - wp_die( __( 'Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe' ) ); |
|
142 | + if (isset($_GET['wc-stripe-hide-notice']) && isset($_GET['_wc_stripe_notice_nonce'])) { |
|
143 | + if ( ! wp_verify_nonce($_GET['_wc_stripe_notice_nonce'], 'wc_stripe_hide_notices_nonce')) { |
|
144 | + wp_die(__('Action failed. Please refresh the page and retry.', 'woocommerce-gateway-stripe')); |
|
145 | 145 | } |
146 | 146 | |
147 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
148 | - wp_die( __( 'Cheatin’ huh?', 'woocommerce-gateway-stripe' ) ); |
|
147 | + if ( ! current_user_can('manage_woocommerce')) { |
|
148 | + wp_die(__('Cheatin’ huh?', 'woocommerce-gateway-stripe')); |
|
149 | 149 | } |
150 | 150 | |
151 | - $notice = wc_clean( $_GET['wc-stripe-hide-notice'] ); |
|
151 | + $notice = wc_clean($_GET['wc-stripe-hide-notice']); |
|
152 | 152 | |
153 | - switch ( $notice ) { |
|
153 | + switch ($notice) { |
|
154 | 154 | case 'ssl': |
155 | - update_option( 'wc_stripe_show_ssl_notice', 'no' ); |
|
155 | + update_option('wc_stripe_show_ssl_notice', 'no'); |
|
156 | 156 | break; |
157 | 157 | case 'keys': |
158 | - update_option( 'wc_stripe_show_keys_notice', 'no' ); |
|
158 | + update_option('wc_stripe_show_keys_notice', 'no'); |
|
159 | 159 | break; |
160 | 160 | } |
161 | 161 | } |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * @since 1.0.0 |
168 | 168 | * @version 4.0.0 |
169 | 169 | */ |
170 | - public function add_admin_notice( $slug, $class, $message, $dismissible = false ) { |
|
171 | - $this->notices[ $slug ] = array( |
|
170 | + public function add_admin_notice($slug, $class, $message, $dismissible = false) { |
|
171 | + $this->notices[$slug] = array( |
|
172 | 172 | 'class' => $class, |
173 | 173 | 'message' => $message, |
174 | 174 | 'dismissible' => $dismissible, |
@@ -182,21 +182,21 @@ discard block |
||
182 | 182 | * @version 4.0.0 |
183 | 183 | */ |
184 | 184 | public function admin_notices() { |
185 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
185 | + if ( ! current_user_can('manage_woocommerce')) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
189 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
190 | - echo '<div class="' . esc_attr( $notice['class'] ) . '" style="position:relative;">'; |
|
189 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
190 | + echo '<div class="' . esc_attr($notice['class']) . '" style="position:relative;">'; |
|
191 | 191 | |
192 | - if ( $notice['dismissible'] ) { |
|
192 | + if ($notice['dismissible']) { |
|
193 | 193 | ?> |
194 | - <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-stripe-hide-notice', $notice_key ), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce' ) ); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
194 | + <a href="<?php echo esc_url(wp_nonce_url(add_query_arg('wc-stripe-hide-notice', $notice_key), 'wc_stripe_hide_notices_nonce', '_wc_stripe_notice_nonce')); ?>" class="woocommerce-message-close notice-dismiss" style="position:absolute;right:1px;padding:9px;text-decoration:none;"></a> |
|
195 | 195 | <?php |
196 | 196 | } |
197 | 197 | |
198 | 198 | echo '<p>'; |
199 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
199 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
200 | 200 | echo '</p></div>'; |
201 | 201 | } |
202 | 202 | } |
@@ -209,26 +209,26 @@ discard block |
||
209 | 209 | * @version 4.0.0 |
210 | 210 | */ |
211 | 211 | public function get_environment_warning() { |
212 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
212 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
213 | 213 | /* translators: 1) int version 2) int version */ |
214 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
214 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
215 | 215 | |
216 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
216 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
217 | 217 | } |
218 | 218 | |
219 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
220 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
219 | + if ( ! defined('WC_VERSION')) { |
|
220 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
221 | 221 | } |
222 | 222 | |
223 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
223 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
224 | 224 | /* translators: 1) int version 2) int version */ |
225 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe' ); |
|
225 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe'); |
|
226 | 226 | |
227 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
227 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
228 | 228 | } |
229 | 229 | |
230 | - if ( ! function_exists( 'curl_init' ) ) { |
|
231 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
230 | + if ( ! function_exists('curl_init')) { |
|
231 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | return false; |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | * @return string Setting link |
243 | 243 | */ |
244 | 244 | public function get_setting_link() { |
245 | - $use_id_as_section = function_exists( 'WC' ) ? version_compare( WC()->version, '2.6', '>=' ) : false; |
|
245 | + $use_id_as_section = function_exists('WC') ? version_compare(WC()->version, '2.6', '>=') : false; |
|
246 | 246 | |
247 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
247 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
248 | 248 | |
249 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
249 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -257,65 +257,65 @@ discard block |
||
257 | 257 | * @version 4.0.0 |
258 | 258 | */ |
259 | 259 | public function check_environment() { |
260 | - if ( ! defined( 'IFRAME_REQUEST' ) && ( WC_STRIPE_VERSION !== get_option( 'wc_stripe_version' ) ) ) { |
|
260 | + if ( ! defined('IFRAME_REQUEST') && (WC_STRIPE_VERSION !== get_option('wc_stripe_version'))) { |
|
261 | 261 | $this->install(); |
262 | 262 | |
263 | - do_action( 'woocommerce_stripe_updated' ); |
|
263 | + do_action('woocommerce_stripe_updated'); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | $environment_warning = $this->get_environment_warning(); |
267 | 267 | |
268 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
269 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
268 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
269 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
270 | 270 | } |
271 | 271 | |
272 | - $show_ssl_notice = get_option( 'wc_stripe_show_ssl_notice' ); |
|
273 | - $show_keys_notice = get_option( 'wc_stripe_show_keys_notice' ); |
|
274 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
275 | - $testmode = ( isset( $options['testmode'] ) && 'yes' === $options['testmode'] ) ? true : false; |
|
276 | - $test_pub_key = isset( $options['test_publishable_key'] ) ? $options['test_publishable_key'] : ''; |
|
277 | - $test_secret_key = isset( $options['test_secret_key'] ) ? $options['test_secret_key'] : ''; |
|
278 | - $live_pub_key = isset( $options['publishable_key'] ) ? $options['publishable_key'] : ''; |
|
279 | - $live_secret_key = isset( $options['secret_key'] ) ? $options['secret_key'] : ''; |
|
272 | + $show_ssl_notice = get_option('wc_stripe_show_ssl_notice'); |
|
273 | + $show_keys_notice = get_option('wc_stripe_show_keys_notice'); |
|
274 | + $options = get_option('woocommerce_stripe_settings'); |
|
275 | + $testmode = (isset($options['testmode']) && 'yes' === $options['testmode']) ? true : false; |
|
276 | + $test_pub_key = isset($options['test_publishable_key']) ? $options['test_publishable_key'] : ''; |
|
277 | + $test_secret_key = isset($options['test_secret_key']) ? $options['test_secret_key'] : ''; |
|
278 | + $live_pub_key = isset($options['publishable_key']) ? $options['publishable_key'] : ''; |
|
279 | + $live_secret_key = isset($options['secret_key']) ? $options['secret_key'] : ''; |
|
280 | 280 | |
281 | - if ( isset( $options['enabled'] ) && 'yes' === $options['enabled'] && empty( $show_keys_notice ) ) { |
|
282 | - $secret = WC_Stripe_API::get_secret_key(); |
|
281 | + if (isset($options['enabled']) && 'yes' === $options['enabled'] && empty($show_keys_notice)) { |
|
282 | + $secret = WC_Stripe_API::get_secret_key(); |
|
283 | 283 | |
284 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
284 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
285 | 285 | $setting_link = $this->get_setting_link(); |
286 | 286 | /* translators: 1) link */ |
287 | - $this->add_admin_notice( 'keys', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
287 | + $this->add_admin_notice('keys', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | // Check if keys are entered properly per live/test mode. |
291 | - if ( $testmode ) { |
|
291 | + if ($testmode) { |
|
292 | 292 | if ( |
293 | - ! empty( $test_pub_key ) && ! preg_match( '/^pk_test_/', $test_pub_key ) |
|
294 | - || ( ! empty( $test_secret_key ) && ! preg_match( '/^sk_test_/', $test_secret_key ) |
|
295 | - && ! empty( $test_secret_key ) && ! preg_match( '/^rk_test_/', $test_secret_key ) ) ) |
|
293 | + ! empty($test_pub_key) && ! preg_match('/^pk_test_/', $test_pub_key) |
|
294 | + || ( ! empty($test_secret_key) && ! preg_match('/^sk_test_/', $test_secret_key) |
|
295 | + && ! empty($test_secret_key) && ! preg_match('/^rk_test_/', $test_secret_key)) ) |
|
296 | 296 | { |
297 | 297 | $setting_link = $this->get_setting_link(); |
298 | 298 | /* translators: 1) link */ |
299 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
299 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in test mode however your test keys may not be valid. Test keys start with pk_test and sk_test or rk_test. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
300 | 300 | } |
301 | 301 | } else { |
302 | 302 | if ( |
303 | - ! empty( $live_pub_key ) && ! preg_match( '/^pk_live_/', $live_pub_key ) |
|
304 | - || ( ! empty( $live_secret_key ) && ! preg_match( '/^sk_live_/', $live_secret_key ) |
|
305 | - && ! empty( $live_secret_key ) && ! preg_match( '/^rk_live_/', $live_secret_key ) ) ) |
|
303 | + ! empty($live_pub_key) && ! preg_match('/^pk_live_/', $live_pub_key) |
|
304 | + || ( ! empty($live_secret_key) && ! preg_match('/^sk_live_/', $live_secret_key) |
|
305 | + && ! empty($live_secret_key) && ! preg_match('/^rk_live_/', $live_secret_key)) ) |
|
306 | 306 | { |
307 | 307 | $setting_link = $this->get_setting_link(); |
308 | 308 | /* translators: 1) link */ |
309 | - $this->add_admin_notice( 'keys', 'notice notice-error', sprintf( __( 'Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ), true ); |
|
309 | + $this->add_admin_notice('keys', 'notice notice-error', sprintf(__('Stripe is in live mode however your test keys may not be valid. Live keys start with pk_live and sk_live or rk_live. Please go to your settings and, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link), true); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | } |
313 | 313 | |
314 | - if ( empty( $show_ssl_notice ) && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) { |
|
314 | + if (empty($show_ssl_notice) && isset($options['enabled']) && 'yes' === $options['enabled']) { |
|
315 | 315 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
316 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
316 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
317 | 317 | /* translators: 1) link 2) link */ |
318 | - $this->add_admin_notice( 'ssl', 'notice notice-warning', sprintf( __( 'Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ), 'https://en.wikipedia.org/wiki/Transport_Layer_Security' ), true ); |
|
318 | + $this->add_admin_notice('ssl', 'notice notice-warning', sprintf(__('Stripe is enabled, but the <a href="%1$s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid <a href="%2$s" target="_blank">SSL certificate</a> - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout'), 'https://en.wikipedia.org/wiki/Transport_Layer_Security'), true); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | } |
@@ -327,8 +327,8 @@ discard block |
||
327 | 327 | * @version 4.0.0 |
328 | 328 | */ |
329 | 329 | public function update_plugin_version() { |
330 | - delete_option( 'wc_stripe_version' ); |
|
331 | - update_option( 'wc_stripe_version', WC_STRIPE_VERSION ); |
|
330 | + delete_option('wc_stripe_version'); |
|
331 | + update_option('wc_stripe_version', WC_STRIPE_VERSION); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | * @version 3.1.0 |
339 | 339 | */ |
340 | 340 | public function install() { |
341 | - if ( ! defined( 'WC_STRIPE_INSTALLING' ) ) { |
|
342 | - define( 'WC_STRIPE_INSTALLING', true ); |
|
341 | + if ( ! defined('WC_STRIPE_INSTALLING')) { |
|
342 | + define('WC_STRIPE_INSTALLING', true); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | $this->update_plugin_version(); |
@@ -351,13 +351,13 @@ discard block |
||
351 | 351 | * @since 1.0.0 |
352 | 352 | * @version 4.0.0 |
353 | 353 | */ |
354 | - public function plugin_action_links( $links ) { |
|
354 | + public function plugin_action_links($links) { |
|
355 | 355 | $plugin_links = array( |
356 | - '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
357 | - '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
358 | - '<a href="https://woocommerce.com/contact-us/">' . esc_html__( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
356 | + '<a href="admin.php?page=wc-settings&tab=checkout§ion=stripe">' . esc_html__('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
357 | + '<a href="https://docs.woocommerce.com/document/stripe/">' . esc_html__('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
358 | + '<a href="https://woocommerce.com/contact-us/">' . esc_html__('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
359 | 359 | ); |
360 | - return array_merge( $plugin_links, $links ); |
|
360 | + return array_merge($plugin_links, $links); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -366,8 +366,8 @@ discard block |
||
366 | 366 | * @since 1.0.0 |
367 | 367 | * @version 4.0.0 |
368 | 368 | */ |
369 | - public function add_gateways( $methods ) { |
|
370 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
369 | + public function add_gateways($methods) { |
|
370 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order') || class_exists('WC_Pre_Orders_Order')) { |
|
371 | 371 | $methods[] = 'WC_Stripe_Compat'; |
372 | 372 | $methods[] = 'WC_Stripe_Sepa_Compat'; |
373 | 373 | } else { |
@@ -392,26 +392,26 @@ discard block |
||
392 | 392 | * @since 4.0.0 |
393 | 393 | * @version 4.0.0 |
394 | 394 | */ |
395 | - public function filter_gateway_order_admin( $sections ) { |
|
396 | - unset( $sections['stripe'] ); |
|
397 | - unset( $sections['stripe_bancontact'] ); |
|
398 | - unset( $sections['stripe_sofort'] ); |
|
399 | - unset( $sections['stripe_giropay'] ); |
|
400 | - unset( $sections['stripe_ideal'] ); |
|
401 | - unset( $sections['stripe_p24'] ); |
|
402 | - unset( $sections['stripe_alipay'] ); |
|
403 | - unset( $sections['stripe_sepa'] ); |
|
404 | - unset( $sections['stripe_bitcoin'] ); |
|
395 | + public function filter_gateway_order_admin($sections) { |
|
396 | + unset($sections['stripe']); |
|
397 | + unset($sections['stripe_bancontact']); |
|
398 | + unset($sections['stripe_sofort']); |
|
399 | + unset($sections['stripe_giropay']); |
|
400 | + unset($sections['stripe_ideal']); |
|
401 | + unset($sections['stripe_p24']); |
|
402 | + unset($sections['stripe_alipay']); |
|
403 | + unset($sections['stripe_sepa']); |
|
404 | + unset($sections['stripe_bitcoin']); |
|
405 | 405 | |
406 | 406 | $sections['stripe'] = 'Stripe'; |
407 | - $sections['stripe_bancontact'] = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
408 | - $sections['stripe_sofort'] = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
409 | - $sections['stripe_giropay'] = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
410 | - $sections['stripe_ideal'] = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
411 | - $sections['stripe_p24'] = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
412 | - $sections['stripe_alipay'] = __( 'Stripe Alipay', 'woocommerce-gateway-stripe' ); |
|
413 | - $sections['stripe_sepa'] = __( 'Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe' ); |
|
414 | - $sections['stripe_bitcoin'] = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
407 | + $sections['stripe_bancontact'] = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
408 | + $sections['stripe_sofort'] = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
409 | + $sections['stripe_giropay'] = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
410 | + $sections['stripe_ideal'] = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
411 | + $sections['stripe_p24'] = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
412 | + $sections['stripe_alipay'] = __('Stripe Alipay', 'woocommerce-gateway-stripe'); |
|
413 | + $sections['stripe_sepa'] = __('Stripe SEPA Direct Debit', 'woocommerce-gateway-stripe'); |
|
414 | + $sections['stripe_bitcoin'] = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
415 | 415 | |
416 | 416 | return $sections; |
417 | 417 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,24 +15,24 @@ 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 ); |
|
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 | 23 | |
24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
26 | 26 | |
27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
32 | 32 | } |
33 | 33 | |
34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * @since 4.0.0 |
44 | 44 | * @version 4.0.0 |
45 | 45 | */ |
46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param int $order_id |
57 | 57 | * @return boolean |
58 | 58 | */ |
59 | - public function has_subscription( $order_id ) { |
|
60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
59 | + public function has_subscription($order_id) { |
|
60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @return bool |
68 | 68 | */ |
69 | 69 | public function is_subs_change_payment() { |
70 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
70 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | * @param int $order_id |
76 | 76 | * @return boolean |
77 | 77 | */ |
78 | - public function is_pre_order( $order_id ) { |
|
79 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
78 | + public function is_pre_order($order_id) { |
|
79 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -85,26 +85,26 @@ discard block |
||
85 | 85 | * @since 4.0.4 |
86 | 86 | * @param int $order_id |
87 | 87 | */ |
88 | - public function change_subs_payment_method( $order_id ) { |
|
88 | + public function change_subs_payment_method($order_id) { |
|
89 | 89 | try { |
90 | - $subscription = wc_get_order( $order_id ); |
|
90 | + $subscription = wc_get_order($order_id); |
|
91 | 91 | $source_object = $this->get_source_object(); |
92 | - $prepared_source = $this->prepare_source( $source_object, get_current_user_id(), true ); |
|
92 | + $prepared_source = $this->prepare_source($source_object, get_current_user_id(), true); |
|
93 | 93 | |
94 | 94 | // Check if we don't allow prepaid credit cards. |
95 | - if ( ! apply_filters( 'wc_stripe_allow_prepaid_card', true ) ) { |
|
96 | - if ( $source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding ) { |
|
97 | - $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' ); |
|
98 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $localized_message ); |
|
95 | + if ( ! apply_filters('wc_stripe_allow_prepaid_card', true)) { |
|
96 | + if ($source_object && 'token' === $source_object->object && 'prepaid' === $source_object->card->funding) { |
|
97 | + $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'); |
|
98 | + throw new WC_Stripe_Exception(print_r($source_object, true), $localized_message); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - if ( empty( $prepared_source->source ) ) { |
|
103 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
104 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
102 | + if (empty($prepared_source->source)) { |
|
103 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
104 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
105 | 105 | } |
106 | 106 | |
107 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
107 | + $this->save_source_to_order($subscription, $prepared_source); |
|
108 | 108 | |
109 | 109 | /* |
110 | 110 | * Check if card 3DS is required or optional with 3DS setting. |
@@ -113,41 +113,41 @@ discard block |
||
113 | 113 | * Note that if we need to save source, the original source must be first |
114 | 114 | * attached to a customer in Stripe before it can be charged. |
115 | 115 | */ |
116 | - if ( $this->is_3ds_required( $source_object ) ) { |
|
116 | + if ($this->is_3ds_required($source_object)) { |
|
117 | 117 | $order = $subscription->get_parent(); |
118 | - $response = $this->create_3ds_source( $order, $source_object, $subscription->get_view_order_url() ); |
|
118 | + $response = $this->create_3ds_source($order, $source_object, $subscription->get_view_order_url()); |
|
119 | 119 | |
120 | - if ( ! empty( $response->error ) ) { |
|
120 | + if ( ! empty($response->error)) { |
|
121 | 121 | $localized_message = $response->error->message; |
122 | 122 | |
123 | - $order->add_order_note( $localized_message ); |
|
123 | + $order->add_order_note($localized_message); |
|
124 | 124 | |
125 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
125 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | // Update order meta with 3DS source. |
129 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
130 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
129 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
130 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
131 | 131 | } else { |
132 | - $subscription->update_meta_data( '_stripe_source_id', $response->id ); |
|
132 | + $subscription->update_meta_data('_stripe_source_id', $response->id); |
|
133 | 133 | $subscription->save(); |
134 | 134 | } |
135 | 135 | |
136 | - WC_Stripe_Logger::log( 'Info: Redirecting to 3DS...' ); |
|
136 | + WC_Stripe_Logger::log('Info: Redirecting to 3DS...'); |
|
137 | 137 | |
138 | 138 | return array( |
139 | 139 | 'result' => 'success', |
140 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
140 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
141 | 141 | ); |
142 | 142 | } |
143 | 143 | |
144 | 144 | return array( |
145 | 145 | 'result' => 'success', |
146 | - 'redirect' => $this->get_return_url( $subscription ), |
|
146 | + 'redirect' => $this->get_return_url($subscription), |
|
147 | 147 | ); |
148 | - } catch ( WC_Stripe_Exception $e ) { |
|
149 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
150 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
148 | + } catch (WC_Stripe_Exception $e) { |
|
149 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
150 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | |
@@ -156,18 +156,18 @@ discard block |
||
156 | 156 | * @param int $order_id |
157 | 157 | * @return array |
158 | 158 | */ |
159 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
160 | - if ( $this->has_subscription( $order_id ) ) { |
|
161 | - if ( $this->is_subs_change_payment() ) { |
|
162 | - return $this->change_subs_payment_method( $order_id ); |
|
159 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
160 | + if ($this->has_subscription($order_id)) { |
|
161 | + if ($this->is_subs_change_payment()) { |
|
162 | + return $this->change_subs_payment_method($order_id); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | // Regular payment with force customer enabled |
166 | - return parent::process_payment( $order_id, true, true ); |
|
167 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
168 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
166 | + return parent::process_payment($order_id, true, true); |
|
167 | + } elseif ($this->is_pre_order($order_id)) { |
|
168 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
169 | 169 | } else { |
170 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
170 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
@@ -178,14 +178,14 @@ discard block |
||
178 | 178 | * @param array $metadata |
179 | 179 | * @param object $order |
180 | 180 | */ |
181 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
182 | - if ( ! $this->has_subscription( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
181 | + public function add_subscription_meta_data($metadata, $order) { |
|
182 | + if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id())) { |
|
183 | 183 | return $metadata; |
184 | 184 | } |
185 | 185 | |
186 | 186 | return $metadata += array( |
187 | 187 | 'payment_type' => 'recurring', |
188 | - 'site_url' => esc_url( get_site_url() ), |
|
188 | + 'site_url' => esc_url(get_site_url()), |
|
189 | 189 | ); |
190 | 190 | } |
191 | 191 | |
@@ -195,24 +195,24 @@ discard block |
||
195 | 195 | * @since 3.1.0 |
196 | 196 | * @version 4.0.0 |
197 | 197 | */ |
198 | - public function save_source_to_order( $order, $source ) { |
|
199 | - parent::save_source_to_order( $order, $source ); |
|
198 | + public function save_source_to_order($order, $source) { |
|
199 | + parent::save_source_to_order($order, $source); |
|
200 | 200 | |
201 | 201 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
202 | 202 | |
203 | 203 | // Also store it on the subscriptions being purchased or paid for in the order |
204 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
205 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
206 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
207 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
204 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
205 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
206 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
207 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
208 | 208 | } else { |
209 | 209 | $subscriptions = array(); |
210 | 210 | } |
211 | 211 | |
212 | - foreach ( $subscriptions as $subscription ) { |
|
212 | + foreach ($subscriptions as $subscription) { |
|
213 | 213 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
214 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
215 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
214 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
215 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
@@ -225,45 +225,45 @@ discard block |
||
225 | 225 | * @param mixed $renewal_order |
226 | 226 | * @param bool $is_retry Is this a retry process. |
227 | 227 | */ |
228 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $is_retry = false ) { |
|
229 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
228 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $is_retry = false) { |
|
229 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
230 | 230 | /* translators: minimum amount */ |
231 | - 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 ) ) ); |
|
231 | + 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))); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | $order_id = WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id(); |
235 | 235 | |
236 | 236 | // Get source from order |
237 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
237 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
238 | 238 | |
239 | - if ( ! $prepared_source->customer ) { |
|
240 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
239 | + if ( ! $prepared_source->customer) { |
|
240 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
241 | 241 | } |
242 | 242 | |
243 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
243 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
244 | 244 | |
245 | - if ( $is_retry ) { |
|
245 | + if ($is_retry) { |
|
246 | 246 | // Passing empty source with charge customer default. |
247 | 247 | $prepared_source->source = ''; |
248 | 248 | } |
249 | 249 | |
250 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
250 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
251 | 251 | $request['capture'] = 'true'; |
252 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
253 | - $response = WC_Stripe_API::request( $request ); |
|
252 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
253 | + $response = WC_Stripe_API::request($request); |
|
254 | 254 | |
255 | - if ( ! empty( $response->error ) || is_wp_error( $response ) ) { |
|
256 | - if ( $is_retry ) { |
|
255 | + if ( ! empty($response->error) || is_wp_error($response)) { |
|
256 | + if ($is_retry) { |
|
257 | 257 | /* translators: error message */ |
258 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
258 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | return $response; // Default catch all errors. |
262 | 262 | } |
263 | 263 | |
264 | - $this->process_response( $response, $renewal_order ); |
|
264 | + $this->process_response($response, $renewal_order); |
|
265 | 265 | |
266 | - if ( ! $is_retry ) { |
|
266 | + if ( ! $is_retry) { |
|
267 | 267 | return $response; |
268 | 268 | } |
269 | 269 | } |
@@ -272,21 +272,21 @@ discard block |
||
272 | 272 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
273 | 273 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
274 | 274 | */ |
275 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
276 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
277 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
275 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
276 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
277 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
278 | 278 | // For BW compat will remove in future |
279 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
280 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
279 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
280 | + $this->delete_renewal_meta($resubscribe_order); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
284 | 284 | * Don't transfer Stripe fee/ID meta to renewal orders. |
285 | 285 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
286 | 286 | */ |
287 | - public function delete_renewal_meta( $renewal_order ) { |
|
288 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
289 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
287 | + public function delete_renewal_meta($renewal_order) { |
|
288 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
289 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
290 | 290 | return $renewal_order; |
291 | 291 | } |
292 | 292 | |
@@ -296,21 +296,21 @@ discard block |
||
296 | 296 | * @param $amount_to_charge float The amount to charge. |
297 | 297 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
298 | 298 | */ |
299 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
300 | - $response = $this->process_subscription_payment( $amount_to_charge, $renewal_order ); |
|
299 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
300 | + $response = $this->process_subscription_payment($amount_to_charge, $renewal_order); |
|
301 | 301 | |
302 | - if ( is_wp_error( $response ) ) { |
|
302 | + if (is_wp_error($response)) { |
|
303 | 303 | /* translators: error message */ |
304 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
304 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
305 | 305 | } |
306 | 306 | |
307 | - if ( ! empty( $response->error ) ) { |
|
307 | + if ( ! empty($response->error)) { |
|
308 | 308 | // This is a very generic error to listen for but worth a retry before total fail. |
309 | - if ( isset( $response->error->type ) && 'invalid_request_error' === $response->error->type && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
310 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true ); |
|
309 | + if (isset($response->error->type) && 'invalid_request_error' === $response->error->type && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
310 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true); |
|
311 | 311 | } else { |
312 | 312 | /* translators: error message */ |
313 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
313 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | } |
@@ -319,20 +319,20 @@ discard block |
||
319 | 319 | * Remove order meta |
320 | 320 | * @param object $order |
321 | 321 | */ |
322 | - public function remove_order_source_before_retry( $order ) { |
|
322 | + public function remove_order_source_before_retry($order) { |
|
323 | 323 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
324 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
324 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
325 | 325 | // For BW compat will remove in the future. |
326 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
326 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
330 | 330 | * Remove order meta |
331 | 331 | * @param object $order |
332 | 332 | */ |
333 | - public function remove_order_customer_before_retry( $order ) { |
|
333 | + public function remove_order_customer_before_retry($order) { |
|
334 | 334 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
335 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
335 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -344,14 +344,14 @@ discard block |
||
344 | 344 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
345 | 345 | * @return void |
346 | 346 | */ |
347 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
348 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
349 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
350 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
347 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
348 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
349 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
350 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
351 | 351 | |
352 | 352 | } else { |
353 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
354 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
353 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
354 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
@@ -364,21 +364,21 @@ discard block |
||
364 | 364 | * @param WC_Subscription $subscription An instance of a subscription object |
365 | 365 | * @return array |
366 | 366 | */ |
367 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
368 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
367 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
368 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
369 | 369 | |
370 | 370 | // For BW compat will remove in future. |
371 | - if ( empty( $source_id ) ) { |
|
372 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
371 | + if (empty($source_id)) { |
|
372 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
373 | 373 | |
374 | 374 | // Take this opportunity to update the key name. |
375 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
375 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
376 | 376 | } |
377 | 377 | |
378 | - $payment_meta[ $this->id ] = array( |
|
378 | + $payment_meta[$this->id] = array( |
|
379 | 379 | 'post_meta' => array( |
380 | 380 | '_stripe_customer_id' => array( |
381 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
381 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
382 | 382 | 'label' => 'Stripe Customer ID', |
383 | 383 | ), |
384 | 384 | '_stripe_source_id' => array( |
@@ -401,22 +401,22 @@ discard block |
||
401 | 401 | * @param array $payment_meta associative array of meta data required for automatic payments |
402 | 402 | * @return array |
403 | 403 | */ |
404 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
405 | - if ( $this->id === $payment_method_id ) { |
|
404 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
405 | + if ($this->id === $payment_method_id) { |
|
406 | 406 | |
407 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
408 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
409 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
410 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
407 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
408 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
409 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
410 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | if ( |
414 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
415 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
416 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
417 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
414 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
415 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
416 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
417 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
418 | 418 | |
419 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
419 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
420 | 420 | } |
421 | 421 | } |
422 | 422 | } |
@@ -429,91 +429,91 @@ discard block |
||
429 | 429 | * @param WC_Subscription $subscription the subscription details |
430 | 430 | * @return string the subscription payment method |
431 | 431 | */ |
432 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
432 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
433 | 433 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
434 | 434 | |
435 | 435 | // bail for other payment methods |
436 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
436 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
437 | 437 | return $payment_method_to_display; |
438 | 438 | } |
439 | 439 | |
440 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
440 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
441 | 441 | |
442 | 442 | // For BW compat will remove in future. |
443 | - if ( empty( $stripe_source_id ) ) { |
|
444 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
443 | + if (empty($stripe_source_id)) { |
|
444 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
445 | 445 | |
446 | 446 | // Take this opportunity to update the key name. |
447 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
447 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | $stripe_customer = new WC_Stripe_Customer(); |
451 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
451 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
452 | 452 | |
453 | 453 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
454 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
454 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
455 | 455 | $user_id = $customer_user; |
456 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
457 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
456 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
457 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
458 | 458 | |
459 | 459 | // For BW compat will remove in future. |
460 | - if ( empty( $stripe_source_id ) ) { |
|
461 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
460 | + if (empty($stripe_source_id)) { |
|
461 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
462 | 462 | |
463 | 463 | // Take this opportunity to update the key name. |
464 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
464 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
468 | 468 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
469 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
470 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
471 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
469 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
470 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
471 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
472 | 472 | |
473 | 473 | // For BW compat will remove in future. |
474 | - if ( empty( $stripe_source_id ) ) { |
|
475 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
474 | + if (empty($stripe_source_id)) { |
|
475 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
476 | 476 | |
477 | 477 | // Take this opportunity to update the key name. |
478 | - WC_Stripe_Helper::is_pre_30() ? 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 | + WC_Stripe_Helper::is_pre_30() ? 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); |
|
479 | 479 | } |
480 | 480 | } |
481 | 481 | |
482 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
482 | + $stripe_customer->set_id($stripe_customer_id); |
|
483 | 483 | $sources = $stripe_customer->get_sources(); |
484 | 484 | |
485 | - if ( $sources ) { |
|
485 | + if ($sources) { |
|
486 | 486 | $found_source = false; |
487 | - foreach ( $sources as $source ) { |
|
488 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
487 | + foreach ($sources as $source) { |
|
488 | + if (isset($source->type) && 'card' === $source->type) { |
|
489 | 489 | $card = $source->card; |
490 | - } elseif ( isset( $source->object ) && 'card' === $source->object ) { |
|
490 | + } elseif (isset($source->object) && 'card' === $source->object) { |
|
491 | 491 | $card = $source; |
492 | 492 | } |
493 | 493 | |
494 | - if ( $source->id === $stripe_source_id ) { |
|
494 | + if ($source->id === $stripe_source_id) { |
|
495 | 495 | $found_source = true; |
496 | 496 | |
497 | - if ( $card ) { |
|
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 | } else { |
501 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
501 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
502 | 502 | } |
503 | 503 | break; |
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
507 | - if ( ! $found_source ) { |
|
508 | - if ( 'card' === $sources[0]->type ) { |
|
507 | + if ( ! $found_source) { |
|
508 | + if ('card' === $sources[0]->type) { |
|
509 | 509 | $card = $sources[0]->card; |
510 | 510 | } |
511 | 511 | |
512 | - if ( $card ) { |
|
512 | + if ($card) { |
|
513 | 513 | /* translators: 1) card brand 2) last 4 digits */ |
514 | - $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 ); |
|
514 | + $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); |
|
515 | 515 | } else { |
516 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
516 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
517 | 517 | } |
518 | 518 | } |
519 | 519 | } |
@@ -526,42 +526,42 @@ discard block |
||
526 | 526 | * @param int $order_id |
527 | 527 | * @return array |
528 | 528 | */ |
529 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
530 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
529 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
530 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
531 | 531 | try { |
532 | - $order = wc_get_order( $order_id ); |
|
532 | + $order = wc_get_order($order_id); |
|
533 | 533 | |
534 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
534 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
535 | 535 | /* translators: minimum amount */ |
536 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
536 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
537 | 537 | } |
538 | 538 | |
539 | - $source = $this->prepare_source( $this->get_source_object(), get_current_user_id(), true ); |
|
539 | + $source = $this->prepare_source($this->get_source_object(), get_current_user_id(), true); |
|
540 | 540 | |
541 | 541 | // We need a source on file to continue. |
542 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
543 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
542 | + if (empty($source->customer) || empty($source->source)) { |
|
543 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
544 | 544 | } |
545 | 545 | |
546 | - $this->save_source_to_order( $order, $source ); |
|
546 | + $this->save_source_to_order($order, $source); |
|
547 | 547 | |
548 | 548 | // Remove cart |
549 | 549 | WC()->cart->empty_cart(); |
550 | 550 | |
551 | 551 | // Is pre ordered! |
552 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
552 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
553 | 553 | |
554 | 554 | // Return thank you page redirect |
555 | 555 | return array( |
556 | 556 | 'result' => 'success', |
557 | - 'redirect' => $this->get_return_url( $order ), |
|
557 | + 'redirect' => $this->get_return_url($order), |
|
558 | 558 | ); |
559 | - } catch ( Exception $e ) { |
|
560 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
559 | + } catch (Exception $e) { |
|
560 | + wc_add_notice($e->getMessage(), 'error'); |
|
561 | 561 | return; |
562 | 562 | } |
563 | 563 | } else { |
564 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
564 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | * @param WC_Order $order |
571 | 571 | * @return void |
572 | 572 | */ |
573 | - public function process_pre_order_release_payment( $order ) { |
|
573 | + public function process_pre_order_release_payment($order) { |
|
574 | 574 | try { |
575 | 575 | // Define some callbacks if the first attempt fails. |
576 | 576 | $retry_callbacks = array( |
@@ -578,33 +578,33 @@ discard block |
||
578 | 578 | 'remove_order_customer_before_retry', |
579 | 579 | ); |
580 | 580 | |
581 | - while ( 1 ) { |
|
582 | - $source = $this->prepare_order_source( $order ); |
|
583 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
581 | + while (1) { |
|
582 | + $source = $this->prepare_order_source($order); |
|
583 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
584 | 584 | |
585 | - if ( ! empty( $response->error ) ) { |
|
586 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
587 | - throw new Exception( $response->error->message ); |
|
585 | + if ( ! empty($response->error)) { |
|
586 | + if (0 === sizeof($retry_callbacks)) { |
|
587 | + throw new Exception($response->error->message); |
|
588 | 588 | } else { |
589 | - $retry_callback = array_shift( $retry_callbacks ); |
|
590 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
589 | + $retry_callback = array_shift($retry_callbacks); |
|
590 | + call_user_func(array($this, $retry_callback), $order); |
|
591 | 591 | } |
592 | 592 | } else { |
593 | 593 | // Successful |
594 | - $this->process_response( $response, $order ); |
|
594 | + $this->process_response($response, $order); |
|
595 | 595 | break; |
596 | 596 | } |
597 | 597 | } |
598 | - } catch ( Exception $e ) { |
|
598 | + } catch (Exception $e) { |
|
599 | 599 | /* translators: error message */ |
600 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
600 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
601 | 601 | |
602 | 602 | // Mark order as failed if not already set, |
603 | 603 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
604 | - if ( ! $order->has_status( 'failed' ) ) { |
|
605 | - $order->update_status( 'failed', $order_note ); |
|
604 | + if ( ! $order->has_status('failed')) { |
|
605 | + $order->update_status('failed', $order_note); |
|
606 | 606 | } else { |
607 | - $order->add_order_note( $order_note ); |
|
607 | + $order->add_order_note($order_note); |
|
608 | 608 | } |
609 | 609 | } |
610 | 610 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | * Check if this gateway is enabled |
19 | 19 | */ |
20 | 20 | public function is_available() { |
21 | - if ( 'yes' === $this->enabled ) { |
|
22 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
21 | + if ('yes' === $this->enabled) { |
|
22 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
23 | 23 | return false; |
24 | 24 | } |
25 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
25 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | 28 | return true; |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * @since 4.0.0 |
38 | 38 | * @version 4.0.0 |
39 | 39 | */ |
40 | - public function add_admin_notice( $slug, $class, $message ) { |
|
41 | - $this->notices[ $slug ] = array( |
|
40 | + public function add_admin_notice($slug, $class, $message) { |
|
41 | + $this->notices[$slug] = array( |
|
42 | 42 | 'class' => $class, |
43 | 43 | 'message' => $message, |
44 | 44 | ); |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @version 4.0.0 |
52 | 52 | */ |
53 | 53 | public function remove_admin_notice() { |
54 | - if ( did_action( 'woocommerce_update_options' ) ) { |
|
55 | - remove_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
54 | + if (did_action('woocommerce_update_options')) { |
|
55 | + remove_action('admin_notices', array($this, 'check_environment')); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return array |
65 | 65 | */ |
66 | 66 | public function payment_icons() { |
67 | - return apply_filters( 'wc_stripe_payment_icons', array( |
|
67 | + return apply_filters('wc_stripe_payment_icons', array( |
|
68 | 68 | 'visa' => '<i class="stripe-pf stripe-pf-visa stripe-pf-right" alt="Visa" aria-hidden="true"></i>', |
69 | 69 | 'amex' => '<i class="stripe-pf stripe-pf-american-express stripe-pf-right" alt="Amex" aria-hidden="true"></i>', |
70 | 70 | 'mastercard' => '<i class="stripe-pf stripe-pf-mastercard stripe-pf-right" alt="Mastercard" aria-hidden="true"></i>', |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | 'eps' => '<i class="stripe-pf stripe-pf-eps stripe-pf-right" alt="EPS" aria-hidden="true"></i>', |
82 | 82 | 'sofort' => '<i class="stripe-pf stripe-pf-sofort stripe-pf-right" alt="SOFORT" aria-hidden="true"></i>', |
83 | 83 | 'sepa' => '<i class="stripe-pf stripe-pf-sepa stripe-pf-right" alt="SEPA" aria-hidden="true"></i>', |
84 | - ) ); |
|
84 | + )); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -92,10 +92,10 @@ discard block |
||
92 | 92 | * @version 4.0.0 |
93 | 93 | * @param object $order |
94 | 94 | */ |
95 | - public function validate_minimum_order_amount( $order ) { |
|
96 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
95 | + public function validate_minimum_order_amount($order) { |
|
96 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
97 | 97 | /* translators: 1) dollar amount */ |
98 | - throw new WC_Stripe_Exception( 'Did not meet minimum amount', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
98 | + throw new WC_Stripe_Exception('Did not meet minimum amount', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | * @since 4.0.0 |
106 | 106 | * @version 4.0.0 |
107 | 107 | */ |
108 | - public function get_transaction_url( $order ) { |
|
109 | - if ( $this->testmode ) { |
|
108 | + public function get_transaction_url($order) { |
|
109 | + if ($this->testmode) { |
|
110 | 110 | $this->view_transaction_url = 'https://dashboard.stripe.com/test/payments/%s'; |
111 | 111 | } else { |
112 | 112 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
113 | 113 | } |
114 | 114 | |
115 | - return parent::get_transaction_url( $order ); |
|
115 | + return parent::get_transaction_url($order); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -121,15 +121,15 @@ discard block |
||
121 | 121 | * @since 4.0.0 |
122 | 122 | * @version 4.0.0 |
123 | 123 | */ |
124 | - public function get_stripe_customer_id( $order ) { |
|
125 | - $customer = get_user_meta( WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true ); |
|
124 | + public function get_stripe_customer_id($order) { |
|
125 | + $customer = get_user_meta(WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(), '_stripe_customer_id', true); |
|
126 | 126 | |
127 | - if ( empty( $customer ) ) { |
|
127 | + if (empty($customer)) { |
|
128 | 128 | // Try to get it via the order. |
129 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
130 | - return get_post_meta( $order->id, '_stripe_customer_id', true ); |
|
129 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
130 | + return get_post_meta($order->id, '_stripe_customer_id', true); |
|
131 | 131 | } else { |
132 | - return $order->get_meta( '_stripe_customer_id', true ); |
|
132 | + return $order->get_meta('_stripe_customer_id', true); |
|
133 | 133 | } |
134 | 134 | } else { |
135 | 135 | return $customer; |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | * @param object $order |
147 | 147 | * @param int $id Stripe session id. |
148 | 148 | */ |
149 | - public function get_stripe_return_url( $order = null, $id = null ) { |
|
150 | - if ( is_object( $order ) ) { |
|
151 | - if ( empty( $id ) ) { |
|
149 | + public function get_stripe_return_url($order = null, $id = null) { |
|
150 | + if (is_object($order)) { |
|
151 | + if (empty($id)) { |
|
152 | 152 | $id = uniqid(); |
153 | 153 | } |
154 | 154 | |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | 'order_id' => $order_id, |
160 | 160 | ); |
161 | 161 | |
162 | - return esc_url_raw( add_query_arg( $args, $this->get_return_url( $order ) ) ); |
|
162 | + return esc_url_raw(add_query_arg($args, $this->get_return_url($order))); |
|
163 | 163 | } |
164 | 164 | |
165 | - return esc_url_raw( add_query_arg( array( 'utm_nooverride' => '1' ), $this->get_return_url() ) ); |
|
165 | + return esc_url_raw(add_query_arg(array('utm_nooverride' => '1'), $this->get_return_url())); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -174,34 +174,33 @@ discard block |
||
174 | 174 | * @param object $source |
175 | 175 | * @return array() |
176 | 176 | */ |
177 | - public function generate_payment_request( $order, $source ) { |
|
178 | - $settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
179 | - $statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : ''; |
|
180 | - $capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false; |
|
177 | + public function generate_payment_request($order, $source) { |
|
178 | + $settings = get_option('woocommerce_stripe_settings', array()); |
|
179 | + $statement_descriptor = ! empty($settings['statement_descriptor']) ? str_replace("'", '', $settings['statement_descriptor']) : ''; |
|
180 | + $capture = ! empty($settings['capture']) && 'yes' === $settings['capture'] ? true : false; |
|
181 | 181 | $post_data = array(); |
182 | - $post_data['currency'] = strtolower( WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency() ); |
|
183 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
182 | + $post_data['currency'] = strtolower(WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency()); |
|
183 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $post_data['currency']); |
|
184 | 184 | /* translators: 1) blog name 2) order number */ |
185 | - $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
185 | + $post_data['description'] = sprintf(__('%1$s - Order %2$s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
186 | 186 | $billing_email = WC_Stripe_Helper::is_pre_30() ? $order->billing_email : $order->get_billing_email(); |
187 | 187 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
188 | 188 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
189 | 189 | |
190 | - if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
190 | + if ( ! empty($billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
191 | 191 | $post_data['receipt_email'] = $billing_email; |
192 | 192 | } |
193 | 193 | |
194 | - switch ( WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method() ) { |
|
195 | - case 'stripe': |
|
196 | - if ( ! empty( $statement_descriptor ) ) { |
|
197 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
194 | + switch (WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method()) { |
|
195 | + case 'stripe' : if ( ! empty($statement_descriptor)) { |
|
196 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
198 | 197 | } |
199 | 198 | |
200 | 199 | $post_data['capture'] = $capture ? 'true' : 'false'; |
201 | 200 | break; |
202 | 201 | case 'stripe_sepa': |
203 | - if ( ! empty( $statement_descriptor ) ) { |
|
204 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor ); |
|
202 | + if ( ! empty($statement_descriptor)) { |
|
203 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor); |
|
205 | 204 | } |
206 | 205 | break; |
207 | 206 | } |
@@ -209,18 +208,18 @@ discard block |
||
209 | 208 | $post_data['expand[]'] = 'balance_transaction'; |
210 | 209 | |
211 | 210 | $metadata = array( |
212 | - __( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ), |
|
213 | - __( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ), |
|
211 | + __('customer_name', 'woocommerce-gateway-stripe') => sanitize_text_field($billing_first_name) . ' ' . sanitize_text_field($billing_last_name), |
|
212 | + __('customer_email', 'woocommerce-gateway-stripe') => sanitize_email($billing_email), |
|
214 | 213 | 'order_id' => WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(), |
215 | 214 | ); |
216 | 215 | |
217 | - $post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $source ); |
|
216 | + $post_data['metadata'] = apply_filters('wc_stripe_payment_metadata', $metadata, $order, $source); |
|
218 | 217 | |
219 | - if ( $source->customer ) { |
|
218 | + if ($source->customer) { |
|
220 | 219 | $post_data['customer'] = $source->customer; |
221 | 220 | } |
222 | 221 | |
223 | - if ( $source->source ) { |
|
222 | + if ($source->source) { |
|
224 | 223 | $post_data['source'] = $source->source; |
225 | 224 | } |
226 | 225 | |
@@ -232,77 +231,77 @@ discard block |
||
232 | 231 | * @param WC_Order $order |
233 | 232 | * @param object $source |
234 | 233 | */ |
235 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
234 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
236 | 235 | } |
237 | 236 | |
238 | 237 | /** |
239 | 238 | * Store extra meta data for an order from a Stripe Response. |
240 | 239 | */ |
241 | - public function process_response( $response, $order ) { |
|
242 | - WC_Stripe_Logger::log( 'Processing response: ' . print_r( $response, true ) ); |
|
240 | + public function process_response($response, $order) { |
|
241 | + WC_Stripe_Logger::log('Processing response: ' . print_r($response, true)); |
|
243 | 242 | |
244 | 243 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
245 | 244 | |
246 | - $captured = ( isset( $response->captured ) && $response->captured ) ? 'yes' : 'no'; |
|
245 | + $captured = (isset($response->captured) && $response->captured) ? 'yes' : 'no'; |
|
247 | 246 | |
248 | 247 | // Store charge data |
249 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_charge_captured', $captured ) : $order->update_meta_data( '_stripe_charge_captured', $captured ); |
|
248 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_charge_captured', $captured) : $order->update_meta_data('_stripe_charge_captured', $captured); |
|
250 | 249 | |
251 | 250 | // Store other data such as fees |
252 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
251 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
253 | 252 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
254 | 253 | // values are in the local currency of the Stripe account, not from WC. |
255 | - $fee = ! empty( $response->balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'fee' ) : 0; |
|
256 | - $net = ! empty( $response->balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $response->balance_transaction, 'net' ) : 0; |
|
257 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
258 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
254 | + $fee = ! empty($response->balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'fee') : 0; |
|
255 | + $net = ! empty($response->balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($response->balance_transaction, 'net') : 0; |
|
256 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
257 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
259 | 258 | } |
260 | 259 | |
261 | - if ( 'yes' === $captured ) { |
|
260 | + if ('yes' === $captured) { |
|
262 | 261 | /** |
263 | 262 | * Charge can be captured but in a pending state. Payment methods |
264 | 263 | * that are asynchronous may take couple days to clear. Webhook will |
265 | 264 | * take care of the status changes. |
266 | 265 | */ |
267 | - if ( 'pending' === $response->status ) { |
|
268 | - if ( ! wc_string_to_bool( get_post_meta( $order_id, '_order_stock_reduced', true ) ) ) { |
|
269 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
266 | + if ('pending' === $response->status) { |
|
267 | + if ( ! wc_string_to_bool(get_post_meta($order_id, '_order_stock_reduced', true))) { |
|
268 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
270 | 269 | } |
271 | 270 | |
272 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
271 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
273 | 272 | /* translators: transaction id */ |
274 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
273 | + $order->update_status('on-hold', sprintf(__('Stripe charge awaiting payment: %s.', 'woocommerce-gateway-stripe'), $response->id)); |
|
275 | 274 | } |
276 | 275 | |
277 | - if ( 'succeeded' === $response->status ) { |
|
278 | - $order->payment_complete( $response->id ); |
|
276 | + if ('succeeded' === $response->status) { |
|
277 | + $order->payment_complete($response->id); |
|
279 | 278 | |
280 | 279 | /* translators: transaction id */ |
281 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
282 | - $order->add_order_note( $message ); |
|
280 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
281 | + $order->add_order_note($message); |
|
283 | 282 | } |
284 | 283 | |
285 | - if ( 'failed' === $response->status ) { |
|
286 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
287 | - $order->add_order_note( $localized_message ); |
|
288 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
284 | + if ('failed' === $response->status) { |
|
285 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
286 | + $order->add_order_note($localized_message); |
|
287 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
289 | 288 | } |
290 | 289 | } else { |
291 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_transaction_id', $response->id ) : $order->set_transaction_id( $response->id ); |
|
290 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_transaction_id', $response->id) : $order->set_transaction_id($response->id); |
|
292 | 291 | |
293 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
294 | - WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels( $order_id ); |
|
292 | + if ($order->has_status(array('pending', 'failed'))) { |
|
293 | + WC_Stripe_Helper::is_pre_30() ? $order->reduce_order_stock() : wc_reduce_stock_levels($order_id); |
|
295 | 294 | } |
296 | 295 | |
297 | 296 | /* translators: transaction id */ |
298 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
297 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
299 | 298 | } |
300 | 299 | |
301 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
300 | + if (is_callable(array($order, 'save'))) { |
|
302 | 301 | $order->save(); |
303 | 302 | } |
304 | 303 | |
305 | - do_action( 'wc_gateway_stripe_process_response', $response, $order ); |
|
304 | + do_action('wc_gateway_stripe_process_response', $response, $order); |
|
306 | 305 | |
307 | 306 | return $response; |
308 | 307 | } |
@@ -315,10 +314,10 @@ discard block |
||
315 | 314 | * @param int $order_id |
316 | 315 | * @return null |
317 | 316 | */ |
318 | - public function send_failed_order_email( $order_id ) { |
|
317 | + public function send_failed_order_email($order_id) { |
|
319 | 318 | $emails = WC()->mailer()->get_emails(); |
320 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
321 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
319 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
320 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
322 | 321 | } |
323 | 322 | } |
324 | 323 | |
@@ -330,7 +329,7 @@ discard block |
||
330 | 329 | * @param object $order |
331 | 330 | * @return object $details |
332 | 331 | */ |
333 | - public function get_owner_details( $order ) { |
|
332 | + public function get_owner_details($order) { |
|
334 | 333 | $billing_first_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_first_name : $order->get_billing_first_name(); |
335 | 334 | $billing_last_name = WC_Stripe_Helper::is_pre_30() ? $order->billing_last_name : $order->get_billing_last_name(); |
336 | 335 | |
@@ -341,8 +340,8 @@ discard block |
||
341 | 340 | |
342 | 341 | $phone = WC_Stripe_Helper::is_pre_30() ? $order->billing_phone : $order->get_billing_phone(); |
343 | 342 | |
344 | - if ( ! empty( $phone ) ) { |
|
345 | - $details['phone'] = $phone; |
|
343 | + if ( ! empty($phone)) { |
|
344 | + $details['phone'] = $phone; |
|
346 | 345 | } |
347 | 346 | |
348 | 347 | $details['address']['line1'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_address_1 : $order->get_billing_address_1(); |
@@ -352,7 +351,7 @@ discard block |
||
352 | 351 | $details['address']['postal_code'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_postcode : $order->get_billing_postcode(); |
353 | 352 | $details['address']['country'] = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
354 | 353 | |
355 | - return (object) apply_filters( 'wc_stripe_owner_details', $details, $order ); |
|
354 | + return (object) apply_filters('wc_stripe_owner_details', $details, $order); |
|
356 | 355 | } |
357 | 356 | |
358 | 357 | /** |
@@ -361,16 +360,16 @@ discard block |
||
361 | 360 | * @since 4.0.3 |
362 | 361 | */ |
363 | 362 | public function get_source_object() { |
364 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
363 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
365 | 364 | |
366 | - if ( empty( $source ) ) { |
|
365 | + if (empty($source)) { |
|
367 | 366 | return ''; |
368 | 367 | } |
369 | 368 | |
370 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
369 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
371 | 370 | |
372 | - if ( ! empty( $source_object->error ) ) { |
|
373 | - throw new WC_Stripe_Exception( print_r( $source_object, true ), $source_object->error->message ); |
|
371 | + if ( ! empty($source_object->error)) { |
|
372 | + throw new WC_Stripe_Exception(print_r($source_object, true), $source_object->error->message); |
|
374 | 373 | } |
375 | 374 | |
376 | 375 | return $source_object; |
@@ -383,11 +382,11 @@ discard block |
||
383 | 382 | * @param object $source_object |
384 | 383 | * @return bool |
385 | 384 | */ |
386 | - public function is_3ds_required( $source_object ) { |
|
385 | + public function is_3ds_required($source_object) { |
|
387 | 386 | return ( |
388 | - $source_object && ! empty( $source_object->card ) ) && |
|
389 | - ( 'card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
390 | - ( $this->three_d_secure && 'optional' === $source_object->card->three_d_secure ) |
|
387 | + $source_object && ! empty($source_object->card) ) && |
|
388 | + ('card' === $source_object->type && 'required' === $source_object->card->three_d_secure || |
|
389 | + ($this->three_d_secure && 'optional' === $source_object->card->three_d_secure) |
|
391 | 390 | ); |
392 | 391 | } |
393 | 392 | |
@@ -398,8 +397,8 @@ discard block |
||
398 | 397 | * @param object $source_object |
399 | 398 | * @return bool |
400 | 399 | */ |
401 | - public function is_3ds_card( $source_object ) { |
|
402 | - return ( $source_object && 'three_d_secure' === $source_object->type ); |
|
400 | + public function is_3ds_card($source_object) { |
|
401 | + return ($source_object && 'three_d_secure' === $source_object->type); |
|
403 | 402 | } |
404 | 403 | |
405 | 404 | /** |
@@ -412,22 +411,22 @@ discard block |
||
412 | 411 | * @param string $return_url |
413 | 412 | * @return mixed |
414 | 413 | */ |
415 | - public function create_3ds_source( $order, $source_object, $return_url = '' ) { |
|
414 | + public function create_3ds_source($order, $source_object, $return_url = '') { |
|
416 | 415 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
417 | 416 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
418 | - $return_url = empty( $return_url ) ? $this->get_stripe_return_url( $order ) : $return_url; |
|
417 | + $return_url = empty($return_url) ? $this->get_stripe_return_url($order) : $return_url; |
|
419 | 418 | |
420 | 419 | $post_data = array(); |
421 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
422 | - $post_data['currency'] = strtolower( $currency ); |
|
420 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
421 | + $post_data['currency'] = strtolower($currency); |
|
423 | 422 | $post_data['type'] = 'three_d_secure'; |
424 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
425 | - $post_data['three_d_secure'] = array( 'card' => $source_object->id ); |
|
426 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
423 | + $post_data['owner'] = $this->get_owner_details($order); |
|
424 | + $post_data['three_d_secure'] = array('card' => $source_object->id); |
|
425 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
427 | 426 | |
428 | - WC_Stripe_Logger::log( 'Info: Begin creating 3DS source...' ); |
|
427 | + WC_Stripe_Logger::log('Info: Begin creating 3DS source...'); |
|
429 | 428 | |
430 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_3ds_source', $post_data, $order ), 'sources' ); |
|
429 | + return WC_Stripe_API::request(apply_filters('wc_stripe_3ds_source', $post_data, $order), 'sources'); |
|
431 | 430 | } |
432 | 431 | |
433 | 432 | /** |
@@ -444,54 +443,54 @@ discard block |
||
444 | 443 | * @throws Exception When card was not added or for and invalid card. |
445 | 444 | * @return object |
446 | 445 | */ |
447 | - public function prepare_source( $source_object = '', $user_id, $force_save_source = false ) { |
|
448 | - $customer = new WC_Stripe_Customer( $user_id ); |
|
446 | + public function prepare_source($source_object = '', $user_id, $force_save_source = false) { |
|
447 | + $customer = new WC_Stripe_Customer($user_id); |
|
449 | 448 | $set_customer = true; |
450 | - $force_save_source = apply_filters( 'wc_stripe_force_save_source', $force_save_source, $customer ); |
|
449 | + $force_save_source = apply_filters('wc_stripe_force_save_source', $force_save_source, $customer); |
|
451 | 450 | $source_id = ''; |
452 | 451 | $wc_token_id = false; |
453 | - $payment_method = isset( $_POST['payment_method'] ) ? wc_clean( $_POST['payment_method'] ) : 'stripe'; |
|
452 | + $payment_method = isset($_POST['payment_method']) ? wc_clean($_POST['payment_method']) : 'stripe'; |
|
454 | 453 | |
455 | 454 | // New CC info was entered and we have a new source to process. |
456 | - if ( ! empty( $source_object ) ) { |
|
455 | + if ( ! empty($source_object)) { |
|
457 | 456 | $source_id = $source_object->id; |
458 | 457 | |
459 | 458 | // This checks to see if customer opted to save the payment method to file. |
460 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
459 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
461 | 460 | |
462 | 461 | /** |
463 | 462 | * This is true if the user wants to store the card to their account. |
464 | 463 | * Criteria to save to file is they are logged in, they opted to save or product requirements and the source is |
465 | 464 | * actually reusable. Either that or force_save_source is true. |
466 | 465 | */ |
467 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage ) || $force_save_source ) { |
|
468 | - $response = $customer->add_source( $source_object->id ); |
|
466 | + if (($user_id && $this->saved_cards && $maybe_saved_card && 'reusable' === $source_object->usage) || $force_save_source) { |
|
467 | + $response = $customer->add_source($source_object->id); |
|
469 | 468 | |
470 | - if ( ! empty( $response->error ) ) { |
|
471 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
469 | + if ( ! empty($response->error)) { |
|
470 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
472 | 471 | } |
473 | 472 | } |
474 | - } elseif ( isset( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) && 'new' !== $_POST[ 'wc-' . $payment_method . '-payment-token' ] ) { |
|
473 | + } elseif (isset($_POST['wc-' . $payment_method . '-payment-token']) && 'new' !== $_POST['wc-' . $payment_method . '-payment-token']) { |
|
475 | 474 | // Use an existing token, and then process the payment |
476 | - $wc_token_id = wc_clean( $_POST[ 'wc-' . $payment_method . '-payment-token' ] ); |
|
477 | - $wc_token = WC_Payment_Tokens::get( $wc_token_id ); |
|
475 | + $wc_token_id = wc_clean($_POST['wc-' . $payment_method . '-payment-token']); |
|
476 | + $wc_token = WC_Payment_Tokens::get($wc_token_id); |
|
478 | 477 | |
479 | - if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id() ) { |
|
480 | - WC()->session->set( 'refresh_totals', true ); |
|
481 | - throw new WC_Stripe_Exception( 'Invalid payment method', __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
478 | + if ( ! $wc_token || $wc_token->get_user_id() !== get_current_user_id()) { |
|
479 | + WC()->session->set('refresh_totals', true); |
|
480 | + throw new WC_Stripe_Exception('Invalid payment method', __('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
482 | 481 | } |
483 | 482 | |
484 | 483 | $source_id = $wc_token->get_token(); |
485 | - } elseif ( isset( $_POST['stripe_token'] ) && 'new' !== $_POST['stripe_token'] ) { |
|
486 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
487 | - $maybe_saved_card = isset( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ) && ! empty( $_POST[ 'wc-' . $payment_method . '-new-payment-method' ] ); |
|
484 | + } elseif (isset($_POST['stripe_token']) && 'new' !== $_POST['stripe_token']) { |
|
485 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
486 | + $maybe_saved_card = isset($_POST['wc-' . $payment_method . '-new-payment-method']) && ! empty($_POST['wc-' . $payment_method . '-new-payment-method']); |
|
488 | 487 | |
489 | 488 | // This is true if the user wants to store the card to their account. |
490 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_save_source ) { |
|
491 | - $response = $customer->add_source( $stripe_token ); |
|
489 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_save_source) { |
|
490 | + $response = $customer->add_source($stripe_token); |
|
492 | 491 | |
493 | - if ( ! empty( $response->error ) ) { |
|
494 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
492 | + if ( ! empty($response->error)) { |
|
493 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
495 | 494 | } |
496 | 495 | } else { |
497 | 496 | $set_customer = false; |
@@ -499,7 +498,7 @@ discard block |
||
499 | 498 | } |
500 | 499 | } |
501 | 500 | |
502 | - if ( ! $set_customer ) { |
|
501 | + if ( ! $set_customer) { |
|
503 | 502 | $customer_id = false; |
504 | 503 | } else { |
505 | 504 | $customer_id = $customer->get_id() ? $customer->get_id() : false; |
@@ -525,37 +524,37 @@ discard block |
||
525 | 524 | * @param object $order |
526 | 525 | * @return object |
527 | 526 | */ |
528 | - public function prepare_order_source( $order = null ) { |
|
527 | + public function prepare_order_source($order = null) { |
|
529 | 528 | $stripe_customer = new WC_Stripe_Customer(); |
530 | 529 | $stripe_source = false; |
531 | 530 | $token_id = false; |
532 | 531 | |
533 | - if ( $order ) { |
|
532 | + if ($order) { |
|
534 | 533 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
535 | 534 | |
536 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
535 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
537 | 536 | |
538 | - if ( $stripe_customer_id ) { |
|
539 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
537 | + if ($stripe_customer_id) { |
|
538 | + $stripe_customer->set_id($stripe_customer_id); |
|
540 | 539 | } |
541 | 540 | |
542 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_source_id', true ) : $order->get_meta( '_stripe_source_id', true ); |
|
541 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_source_id', true) : $order->get_meta('_stripe_source_id', true); |
|
543 | 542 | |
544 | 543 | // Since 4.0.0, we changed card to source so we need to account for that. |
545 | - if ( empty( $source_id ) ) { |
|
546 | - $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta( $order_id, '_stripe_card_id', true ) : $order->get_meta( '_stripe_card_id', true ); |
|
544 | + if (empty($source_id)) { |
|
545 | + $source_id = WC_Stripe_Helper::is_pre_30() ? get_post_meta($order_id, '_stripe_card_id', true) : $order->get_meta('_stripe_card_id', true); |
|
547 | 546 | |
548 | 547 | // Take this opportunity to update the key name. |
549 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_source_id', $source_id ) : $order->update_meta_data( '_stripe_source_id', $source_id ); |
|
548 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_source_id', $source_id) : $order->update_meta_data('_stripe_source_id', $source_id); |
|
550 | 549 | |
551 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
550 | + if (is_callable(array($order, 'save'))) { |
|
552 | 551 | $order->save(); |
553 | 552 | } |
554 | 553 | } |
555 | 554 | |
556 | - if ( $source_id ) { |
|
555 | + if ($source_id) { |
|
557 | 556 | $stripe_source = $source_id; |
558 | - } elseif ( apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
557 | + } elseif (apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
559 | 558 | /* |
560 | 559 | * We can attempt to charge the customer's default source |
561 | 560 | * by sending empty source id. |
@@ -579,27 +578,27 @@ discard block |
||
579 | 578 | * @param WC_Order $order For to which the source applies. |
580 | 579 | * @param stdClass $source Source information. |
581 | 580 | */ |
582 | - public function save_source_to_order( $order, $source ) { |
|
581 | + public function save_source_to_order($order, $source) { |
|
583 | 582 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
584 | 583 | |
585 | 584 | // Store source in the order. |
586 | - if ( $source->customer ) { |
|
587 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
588 | - update_post_meta( $order_id, '_stripe_customer_id', $source->customer ); |
|
585 | + if ($source->customer) { |
|
586 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
587 | + update_post_meta($order_id, '_stripe_customer_id', $source->customer); |
|
589 | 588 | } else { |
590 | - $order->update_meta_data( '_stripe_customer_id', $source->customer ); |
|
589 | + $order->update_meta_data('_stripe_customer_id', $source->customer); |
|
591 | 590 | } |
592 | 591 | } |
593 | 592 | |
594 | - if ( $source->source ) { |
|
595 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
596 | - update_post_meta( $order_id, '_stripe_source_id', $source->source ); |
|
593 | + if ($source->source) { |
|
594 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
595 | + update_post_meta($order_id, '_stripe_source_id', $source->source); |
|
597 | 596 | } else { |
598 | - $order->update_meta_data( '_stripe_source_id', $source->source ); |
|
597 | + $order->update_meta_data('_stripe_source_id', $source->source); |
|
599 | 598 | } |
600 | 599 | } |
601 | 600 | |
602 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
601 | + if (is_callable(array($order, 'save'))) { |
|
603 | 602 | $order->save(); |
604 | 603 | } |
605 | 604 | } |
@@ -613,27 +612,27 @@ discard block |
||
613 | 612 | * @param object $order The order object |
614 | 613 | * @param int $balance_transaction_id |
615 | 614 | */ |
616 | - public function update_fees( $order, $balance_transaction_id ) { |
|
615 | + public function update_fees($order, $balance_transaction_id) { |
|
617 | 616 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
618 | 617 | |
619 | - $balance_transaction = WC_Stripe_API::retrieve( 'balance/history/' . $balance_transaction_id ); |
|
618 | + $balance_transaction = WC_Stripe_API::retrieve('balance/history/' . $balance_transaction_id); |
|
620 | 619 | |
621 | - if ( empty( $balance_transaction->error ) ) { |
|
622 | - if ( isset( $balance_transaction ) && isset( $balance_transaction->fee ) ) { |
|
620 | + if (empty($balance_transaction->error)) { |
|
621 | + if (isset($balance_transaction) && isset($balance_transaction->fee)) { |
|
623 | 622 | // Fees and Net needs to both come from Stripe to be accurate as the returned |
624 | 623 | // values are in the local currency of the Stripe account, not from WC. |
625 | - $fee = ! empty( $balance_transaction->fee ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'fee' ) : 0; |
|
626 | - $net = ! empty( $balance_transaction->net ) ? WC_Stripe_Helper::format_balance_fee( $balance_transaction, 'net' ) : 0; |
|
624 | + $fee = ! empty($balance_transaction->fee) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'fee') : 0; |
|
625 | + $net = ! empty($balance_transaction->net) ? WC_Stripe_Helper::format_balance_fee($balance_transaction, 'net') : 0; |
|
627 | 626 | |
628 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_FEE, $fee ) : $order->update_meta_data( self::META_NAME_FEE, $fee ); |
|
629 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, self::META_NAME_NET, $net ) : $order->update_meta_data( self::META_NAME_NET, $net ); |
|
627 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_FEE, $fee) : $order->update_meta_data(self::META_NAME_FEE, $fee); |
|
628 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, self::META_NAME_NET, $net) : $order->update_meta_data(self::META_NAME_NET, $net); |
|
630 | 629 | |
631 | - if ( is_callable( array( $order, 'save' ) ) ) { |
|
630 | + if (is_callable(array($order, 'save'))) { |
|
632 | 631 | $order->save(); |
633 | 632 | } |
634 | 633 | } |
635 | 634 | } else { |
636 | - WC_Stripe_Logger::log( "Unable to update fees/net meta for order: {$order_id}" ); |
|
635 | + WC_Stripe_Logger::log("Unable to update fees/net meta for order: {$order_id}"); |
|
637 | 636 | } |
638 | 637 | } |
639 | 638 | |
@@ -646,33 +645,33 @@ discard block |
||
646 | 645 | * @param float $amount |
647 | 646 | * @return bool |
648 | 647 | */ |
649 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
650 | - $order = wc_get_order( $order_id ); |
|
648 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
649 | + $order = wc_get_order($order_id); |
|
651 | 650 | |
652 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
651 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
653 | 652 | return false; |
654 | 653 | } |
655 | 654 | |
656 | 655 | $request = array(); |
657 | 656 | |
658 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
659 | - $order_currency = get_post_meta( $order_id, '_order_currency', true ); |
|
660 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
657 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
658 | + $order_currency = get_post_meta($order_id, '_order_currency', true); |
|
659 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
661 | 660 | } else { |
662 | 661 | $order_currency = $order->get_currency(); |
663 | - $captured = $order->get_meta( '_stripe_charge_captured', true ); |
|
662 | + $captured = $order->get_meta('_stripe_charge_captured', true); |
|
664 | 663 | } |
665 | 664 | |
666 | - if ( ! is_null( $amount ) ) { |
|
667 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $order_currency ); |
|
665 | + if ( ! is_null($amount)) { |
|
666 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $order_currency); |
|
668 | 667 | } |
669 | 668 | |
670 | 669 | // If order is only authorized, don't pass amount. |
671 | - if ( 'yes' !== $captured ) { |
|
672 | - unset( $request['amount'] ); |
|
670 | + if ('yes' !== $captured) { |
|
671 | + unset($request['amount']); |
|
673 | 672 | } |
674 | 673 | |
675 | - if ( $reason ) { |
|
674 | + if ($reason) { |
|
676 | 675 | $request['metadata'] = array( |
677 | 676 | 'reason' => $reason, |
678 | 677 | ); |
@@ -680,33 +679,33 @@ discard block |
||
680 | 679 | |
681 | 680 | $request['charge'] = $order->get_transaction_id(); |
682 | 681 | |
683 | - WC_Stripe_Logger::log( "Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}" ); |
|
682 | + WC_Stripe_Logger::log("Info: Beginning refund for order {$order->get_transaction_id()} for the amount of {$amount}"); |
|
684 | 683 | |
685 | - $response = WC_Stripe_API::request( $request, 'refunds' ); |
|
684 | + $response = WC_Stripe_API::request($request, 'refunds'); |
|
686 | 685 | |
687 | - if ( ! empty( $response->error ) ) { |
|
688 | - WC_Stripe_Logger::log( 'Error: ' . $response->error->message ); |
|
686 | + if ( ! empty($response->error)) { |
|
687 | + WC_Stripe_Logger::log('Error: ' . $response->error->message); |
|
689 | 688 | |
690 | 689 | return $response; |
691 | 690 | |
692 | - } elseif ( ! empty( $response->id ) ) { |
|
693 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $order_id, '_stripe_refund_id', $response->id ) : $order->update_meta_data( '_stripe_refund_id', $response->id ); |
|
691 | + } elseif ( ! empty($response->id)) { |
|
692 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($order_id, '_stripe_refund_id', $response->id) : $order->update_meta_data('_stripe_refund_id', $response->id); |
|
694 | 693 | |
695 | - $amount = wc_price( $response->amount / 100 ); |
|
694 | + $amount = wc_price($response->amount / 100); |
|
696 | 695 | |
697 | - if ( in_array( strtolower( $order->get_currency() ), WC_Stripe_Helper::no_decimal_currencies() ) ) { |
|
698 | - $amount = wc_price( $response->amount ); |
|
696 | + if (in_array(strtolower($order->get_currency()), WC_Stripe_Helper::no_decimal_currencies())) { |
|
697 | + $amount = wc_price($response->amount); |
|
699 | 698 | } |
700 | 699 | |
701 | - if ( isset( $response->balance_transaction ) ) { |
|
702 | - $this->update_fees( $order, $response->balance_transaction ); |
|
700 | + if (isset($response->balance_transaction)) { |
|
701 | + $this->update_fees($order, $response->balance_transaction); |
|
703 | 702 | } |
704 | 703 | |
705 | 704 | /* translators: 1) dollar amount 2) transaction id 3) refund message */ |
706 | - $refund_message = ( isset( $captured ) && 'yes' === $captured ) ? sprintf( __( 'Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe' ), $amount, $response->id, $reason ) : __( 'Pre-Authorization Released', 'woocommerce-gateway-stripe' ); |
|
705 | + $refund_message = (isset($captured) && 'yes' === $captured) ? sprintf(__('Refunded %1$s - Refund ID: %2$s - Reason: %3$s', 'woocommerce-gateway-stripe'), $amount, $response->id, $reason) : __('Pre-Authorization Released', 'woocommerce-gateway-stripe'); |
|
707 | 706 | |
708 | - $order->add_order_note( $refund_message ); |
|
709 | - WC_Stripe_Logger::log( 'Success: ' . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
707 | + $order->add_order_note($refund_message); |
|
708 | + WC_Stripe_Logger::log('Success: ' . html_entity_decode(strip_tags($refund_message))); |
|
710 | 709 | |
711 | 710 | return true; |
712 | 711 | } |
@@ -721,44 +720,44 @@ discard block |
||
721 | 720 | */ |
722 | 721 | public function add_payment_method() { |
723 | 722 | $error = false; |
724 | - $error_msg = __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ); |
|
723 | + $error_msg = __('There was a problem adding the card.', 'woocommerce-gateway-stripe'); |
|
725 | 724 | $source_id = ''; |
726 | 725 | |
727 | - if ( empty( $_POST['stripe_source'] ) && empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
726 | + if (empty($_POST['stripe_source']) && empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
728 | 727 | $error = true; |
729 | 728 | } |
730 | 729 | |
731 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
730 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
732 | 731 | |
733 | - $source = ! empty( $_POST['stripe_source'] ) ? wc_clean( $_POST['stripe_source'] ) : ''; |
|
732 | + $source = ! empty($_POST['stripe_source']) ? wc_clean($_POST['stripe_source']) : ''; |
|
734 | 733 | |
735 | - $source_object = WC_Stripe_API::retrieve( 'sources/' . $source ); |
|
734 | + $source_object = WC_Stripe_API::retrieve('sources/' . $source); |
|
736 | 735 | |
737 | - if ( isset( $source_object ) ) { |
|
738 | - if ( ! empty( $source_object->error ) ) { |
|
736 | + if (isset($source_object)) { |
|
737 | + if ( ! empty($source_object->error)) { |
|
739 | 738 | $error = true; |
740 | 739 | } |
741 | 740 | |
742 | 741 | $source_id = $source_object->id; |
743 | - } elseif ( isset( $_POST['stripe_token'] ) ) { |
|
744 | - $source_id = wc_clean( $_POST['stripe_token'] ); |
|
742 | + } elseif (isset($_POST['stripe_token'])) { |
|
743 | + $source_id = wc_clean($_POST['stripe_token']); |
|
745 | 744 | } |
746 | 745 | |
747 | - $response = $stripe_customer->add_source( $source_id ); |
|
746 | + $response = $stripe_customer->add_source($source_id); |
|
748 | 747 | |
749 | - if ( ! $response || is_wp_error( $response ) || ! empty( $response->error ) ) { |
|
748 | + if ( ! $response || is_wp_error($response) || ! empty($response->error)) { |
|
750 | 749 | $error = true; |
751 | 750 | } |
752 | 751 | |
753 | - if ( $error ) { |
|
754 | - wc_add_notice( $error_msg, 'error' ); |
|
755 | - WC_Stripe_Logger::log( 'Add payment method Error: ' . $error_msg ); |
|
752 | + if ($error) { |
|
753 | + wc_add_notice($error_msg, 'error'); |
|
754 | + WC_Stripe_Logger::log('Add payment method Error: ' . $error_msg); |
|
756 | 755 | return; |
757 | 756 | } |
758 | 757 | |
759 | 758 | return array( |
760 | 759 | 'result' => 'success', |
761 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
760 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
762 | 761 | ); |
763 | 762 | } |
764 | 763 | } |