@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | |
315 | 315 | /** |
316 | 316 | * Don't transfer Stripe fee/ID meta to renewal orders. |
317 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
317 | + * @param integer $renewal_order |
|
318 | 318 | */ |
319 | 319 | public function delete_renewal_meta( $renewal_order ) { |
320 | 320 | delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
@@ -556,6 +556,8 @@ discard block |
||
556 | 556 | /** |
557 | 557 | * Process the pre-order |
558 | 558 | * @param int $order_id |
559 | + * @param boolean $retry |
|
560 | + * @param boolean $force_save_source |
|
559 | 561 | * @return array |
560 | 562 | */ |
561 | 563 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
@@ -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( WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id() ) ) { |
|
95 | + public function add_subscription_meta_data($metadata, $order) { |
|
96 | + if ( ! $this->has_subscription(WC_Stripe_Helper::is_pre_30() ? $order->id : $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,22 +313,22 @@ 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.', 'woocommerce-gateway-stripe' ) ); |
|
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_".', 'woocommerce-gateway-stripe' ) ); |
|
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.', 'woocommerce-gateway-stripe')); |
|
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_".', 'woocommerce-gateway-stripe')); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | if ( |
326 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
327 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
328 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
329 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
326 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
327 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
328 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
329 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
330 | 330 | |
331 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
331 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | } |
@@ -341,67 +341,67 @@ discard block |
||
341 | 341 | * @param WC_Subscription $subscription the subscription details |
342 | 342 | * @return string the subscription payment method |
343 | 343 | */ |
344 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
344 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
345 | 345 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
346 | 346 | |
347 | 347 | // bail for other payment methods |
348 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
348 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
349 | 349 | return $payment_method_to_display; |
350 | 350 | } |
351 | 351 | |
352 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
352 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
353 | 353 | |
354 | 354 | // For BW compat will remove in future. |
355 | - if ( empty( $stripe_source_id ) ) { |
|
356 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
355 | + if (empty($stripe_source_id)) { |
|
356 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
357 | 357 | |
358 | 358 | // Take this opportunity to update the key name. |
359 | - 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 ); |
|
359 | + 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); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | $stripe_customer = new WC_Stripe_Customer(); |
363 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
363 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
364 | 364 | |
365 | 365 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
366 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
366 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
367 | 367 | $user_id = $customer_user; |
368 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
369 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
368 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
369 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
370 | 370 | |
371 | 371 | // For BW compat will remove in future. |
372 | - if ( empty( $stripe_source_id ) ) { |
|
373 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
372 | + if (empty($stripe_source_id)) { |
|
373 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
374 | 374 | |
375 | 375 | // Take this opportunity to update the key name. |
376 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
376 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
377 | 377 | } |
378 | 378 | } |
379 | 379 | |
380 | 380 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
381 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
382 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
383 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
381 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
382 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
383 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
384 | 384 | |
385 | 385 | // For BW compat will remove in future. |
386 | - if ( empty( $stripe_source_id ) ) { |
|
387 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
386 | + if (empty($stripe_source_id)) { |
|
387 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
388 | 388 | |
389 | 389 | // Take this opportunity to update the key name. |
390 | - 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 ); |
|
390 | + 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); |
|
391 | 391 | } |
392 | 392 | } |
393 | 393 | |
394 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
394 | + $stripe_customer->set_id($stripe_customer_id); |
|
395 | 395 | $sources = $stripe_customer->get_sources(); |
396 | 396 | |
397 | - if ( $sources ) { |
|
398 | - foreach ( $sources as $source ) { |
|
399 | - if ( $source->id === $stripe_source_id ) { |
|
400 | - if ( $source->sepa_debit ) { |
|
397 | + if ($sources) { |
|
398 | + foreach ($sources as $source) { |
|
399 | + if ($source->id === $stripe_source_id) { |
|
400 | + if ($source->sepa_debit) { |
|
401 | 401 | /* translators: 1) last 4 digits of SEPA Direct Debit */ |
402 | - $payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 ); |
|
402 | + $payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4); |
|
403 | 403 | } else { |
404 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
404 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
405 | 405 | } |
406 | 406 | break; |
407 | 407 | } |
@@ -416,42 +416,42 @@ discard block |
||
416 | 416 | * @param int $order_id |
417 | 417 | * @return array |
418 | 418 | */ |
419 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
420 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
419 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
420 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
421 | 421 | try { |
422 | - $order = wc_get_order( $order_id ); |
|
422 | + $order = wc_get_order($order_id); |
|
423 | 423 | |
424 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
424 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
425 | 425 | /* translators: minimum amount */ |
426 | - 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 ) ) ); |
|
426 | + 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))); |
|
427 | 427 | } |
428 | 428 | |
429 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
429 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
430 | 430 | |
431 | 431 | // We need a source on file to continue. |
432 | - if ( empty( $prepared_source->customer ) || empty( $prepared_source->source ) ) { |
|
433 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
432 | + if (empty($prepared_source->customer) || empty($prepared_source->source)) { |
|
433 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
434 | 434 | } |
435 | 435 | |
436 | - $this->save_source_to_order( $order, $prepared_source ); |
|
436 | + $this->save_source_to_order($order, $prepared_source); |
|
437 | 437 | |
438 | 438 | // Remove cart |
439 | 439 | WC()->cart->empty_cart(); |
440 | 440 | |
441 | 441 | // Is pre ordered! |
442 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
442 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
443 | 443 | |
444 | 444 | // Return thank you page redirect |
445 | 445 | return array( |
446 | 446 | 'result' => 'success', |
447 | - 'redirect' => $this->get_return_url( $order ), |
|
447 | + 'redirect' => $this->get_return_url($order), |
|
448 | 448 | ); |
449 | - } catch ( Exception $e ) { |
|
450 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
449 | + } catch (Exception $e) { |
|
450 | + wc_add_notice($e->getMessage(), 'error'); |
|
451 | 451 | return; |
452 | 452 | } |
453 | 453 | } else { |
454 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
454 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
455 | 455 | } |
456 | 456 | } |
457 | 457 | |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | * @param WC_Order $order |
461 | 461 | * @return void |
462 | 462 | */ |
463 | - public function process_pre_order_release_payment( $order ) { |
|
463 | + public function process_pre_order_release_payment($order) { |
|
464 | 464 | try { |
465 | 465 | // Define some callbacks if the first attempt fails. |
466 | 466 | $retry_callbacks = array( |
@@ -468,33 +468,33 @@ discard block |
||
468 | 468 | 'remove_order_customer_before_retry', |
469 | 469 | ); |
470 | 470 | |
471 | - while ( 1 ) { |
|
472 | - $source = $this->prepare_order_source( $order ); |
|
473 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
471 | + while (1) { |
|
472 | + $source = $this->prepare_order_source($order); |
|
473 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
474 | 474 | |
475 | - if ( ! empty( $response->error ) ) { |
|
476 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
477 | - throw new Exception( $response->error->message ); |
|
475 | + if ( ! empty($response->error)) { |
|
476 | + if (0 === sizeof($retry_callbacks)) { |
|
477 | + throw new Exception($response->error->message); |
|
478 | 478 | } else { |
479 | - $retry_callback = array_shift( $retry_callbacks ); |
|
480 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
479 | + $retry_callback = array_shift($retry_callbacks); |
|
480 | + call_user_func(array($this, $retry_callback), $order); |
|
481 | 481 | } |
482 | 482 | } else { |
483 | 483 | // Successful |
484 | - $this->process_response( $response, $order ); |
|
484 | + $this->process_response($response, $order); |
|
485 | 485 | break; |
486 | 486 | } |
487 | 487 | } |
488 | - } catch ( Exception $e ) { |
|
488 | + } catch (Exception $e) { |
|
489 | 489 | /* translators: error message */ |
490 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
490 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
491 | 491 | |
492 | 492 | // Mark order as failed if not already set, |
493 | 493 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
494 | - if ( ! $order->has_status( 'failed' ) ) { |
|
495 | - $order->update_status( 'failed', $order_note ); |
|
494 | + if ( ! $order->has_status('failed')) { |
|
495 | + $order->update_status('failed', $order_note); |
|
496 | 496 | } else { |
497 | - $order->add_order_note( $order_note ); |
|
497 | + $order->add_order_note($order_note); |
|
498 | 498 | } |
499 | 499 | } |
500 | 500 | } |
@@ -213,7 +213,6 @@ |
||
213 | 213 | /** |
214 | 214 | * Get a customers saved sources using their Stripe ID. |
215 | 215 | * |
216 | - * @param string $customer_id |
|
217 | 216 | * @return array |
218 | 217 | */ |
219 | 218 | public function get_sources() { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * Constructor |
33 | 33 | * @param int $user_id The WP user ID |
34 | 34 | */ |
35 | - public function __construct( $user_id = 0 ) { |
|
36 | - if ( $user_id ) { |
|
37 | - $this->set_user_id( $user_id ); |
|
38 | - $this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
35 | + public function __construct($user_id = 0) { |
|
36 | + if ($user_id) { |
|
37 | + $this->set_user_id($user_id); |
|
38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * Set Stripe customer ID. |
52 | 52 | * @param [type] $id [description] |
53 | 53 | */ |
54 | - public function set_id( $id ) { |
|
55 | - $this->id = wc_clean( $id ); |
|
54 | + public function set_id($id) { |
|
55 | + $this->id = wc_clean($id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | * @return int |
61 | 61 | */ |
62 | 62 | public function get_user_id() { |
63 | - return absint( $this->user_id ); |
|
63 | + return absint($this->user_id); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Set User ID used by WordPress. |
68 | 68 | * @param int $user_id |
69 | 69 | */ |
70 | - public function set_user_id( $user_id ) { |
|
71 | - $this->user_id = absint( $user_id ); |
|
70 | + public function set_user_id($user_id) { |
|
71 | + $this->user_id = absint($user_id); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | * @return WP_User |
77 | 77 | */ |
78 | 78 | protected function get_user() { |
79 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
79 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Store data from the Stripe API about this customer |
84 | 84 | */ |
85 | - public function set_customer_data( $data ) { |
|
85 | + public function set_customer_data($data) { |
|
86 | 86 | $this->customer_data = $data; |
87 | 87 | } |
88 | 88 | |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | * @param array $args |
92 | 92 | * @return WP_Error|int |
93 | 93 | */ |
94 | - public function create_customer( $args = array() ) { |
|
95 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
94 | + public function create_customer($args = array()) { |
|
95 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
96 | 96 | $user = $this->get_user(); |
97 | 97 | |
98 | - if ( $user ) { |
|
99 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
100 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
98 | + if ($user) { |
|
99 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
100 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
101 | 101 | |
102 | 102 | $defaults = array( |
103 | 103 | 'email' => $user->user_email, |
@@ -112,24 +112,24 @@ discard block |
||
112 | 112 | |
113 | 113 | $metadata = array(); |
114 | 114 | |
115 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
115 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
116 | 116 | |
117 | - $args = wp_parse_args( $args, $defaults ); |
|
118 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
117 | + $args = wp_parse_args($args, $defaults); |
|
118 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
119 | 119 | |
120 | - if ( ! empty( $response->error ) ) { |
|
121 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
120 | + if ( ! empty($response->error)) { |
|
121 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
122 | 122 | } |
123 | 123 | |
124 | - $this->set_id( $response->id ); |
|
124 | + $this->set_id($response->id); |
|
125 | 125 | $this->clear_cache(); |
126 | - $this->set_customer_data( $response ); |
|
126 | + $this->set_customer_data($response); |
|
127 | 127 | |
128 | - if ( $this->get_user_id() ) { |
|
129 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
128 | + if ($this->get_user_id()) { |
|
129 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
130 | 130 | } |
131 | 131 | |
132 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
132 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
133 | 133 | |
134 | 134 | return $response->id; |
135 | 135 | } |
@@ -140,72 +140,72 @@ discard block |
||
140 | 140 | * @param bool $retry |
141 | 141 | * @return WP_Error|int |
142 | 142 | */ |
143 | - public function add_source( $source_id, $retry = true ) { |
|
144 | - if ( ! $this->get_id() ) { |
|
145 | - $this->set_id( $this->create_customer() ); |
|
143 | + public function add_source($source_id, $retry = true) { |
|
144 | + if ( ! $this->get_id()) { |
|
145 | + $this->set_id($this->create_customer()); |
|
146 | 146 | } |
147 | 147 | |
148 | - $response = WC_Stripe_API::request( array( |
|
148 | + $response = WC_Stripe_API::request(array( |
|
149 | 149 | 'source' => $source_id, |
150 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
150 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
151 | 151 | |
152 | - if ( ! empty( $response->error ) ) { |
|
152 | + if ( ! empty($response->error)) { |
|
153 | 153 | // It is possible the WC user once was linked to a customer on Stripe |
154 | 154 | // but no longer exists. Instead of failing, lets try to create a |
155 | 155 | // new customer. |
156 | - if ( preg_match( '/No such customer/i', $response->error->message ) ) { |
|
157 | - delete_user_meta( $this->get_user_id(), '_stripe_customer_id' ); |
|
156 | + if (preg_match('/No such customer/i', $response->error->message)) { |
|
157 | + delete_user_meta($this->get_user_id(), '_stripe_customer_id'); |
|
158 | 158 | $this->create_customer(); |
159 | - return $this->add_source( $source_id, false ); |
|
159 | + return $this->add_source($source_id, false); |
|
160 | 160 | } else { |
161 | 161 | return $response; |
162 | 162 | } |
163 | - } elseif ( empty( $response->id ) ) { |
|
164 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
163 | + } elseif (empty($response->id)) { |
|
164 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // Add token to WooCommerce. |
168 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
169 | - if ( ! empty( $response->type ) ) { |
|
170 | - switch ( $response->type ) { |
|
168 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
169 | + if ( ! empty($response->type)) { |
|
170 | + switch ($response->type) { |
|
171 | 171 | case 'alipay': |
172 | 172 | break; |
173 | 173 | case 'sepa_debit': |
174 | 174 | $wc_token = new WC_Payment_Token_SEPA(); |
175 | - $wc_token->set_token( $response->id ); |
|
176 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
177 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
175 | + $wc_token->set_token($response->id); |
|
176 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
177 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
178 | 178 | break; |
179 | 179 | default: |
180 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
180 | + if ('source' === $response->object && 'card' === $response->type) { |
|
181 | 181 | $wc_token = new WC_Payment_Token_CC(); |
182 | - $wc_token->set_token( $response->id ); |
|
183 | - $wc_token->set_gateway_id( 'stripe' ); |
|
184 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
185 | - $wc_token->set_last4( $response->card->last4 ); |
|
186 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
187 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
182 | + $wc_token->set_token($response->id); |
|
183 | + $wc_token->set_gateway_id('stripe'); |
|
184 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
185 | + $wc_token->set_last4($response->card->last4); |
|
186 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
187 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
188 | 188 | } |
189 | 189 | break; |
190 | 190 | } |
191 | 191 | } else { |
192 | 192 | // Legacy. |
193 | 193 | $wc_token = new WC_Payment_Token_CC(); |
194 | - $wc_token->set_token( $response->id ); |
|
195 | - $wc_token->set_gateway_id( 'stripe' ); |
|
196 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
197 | - $wc_token->set_last4( $response->last4 ); |
|
198 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
199 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
194 | + $wc_token->set_token($response->id); |
|
195 | + $wc_token->set_gateway_id('stripe'); |
|
196 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
197 | + $wc_token->set_last4($response->last4); |
|
198 | + $wc_token->set_expiry_month($response->exp_month); |
|
199 | + $wc_token->set_expiry_year($response->exp_year); |
|
200 | 200 | } |
201 | 201 | |
202 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
202 | + $wc_token->set_user_id($this->get_user_id()); |
|
203 | 203 | $wc_token->save(); |
204 | 204 | } |
205 | 205 | |
206 | 206 | $this->clear_cache(); |
207 | 207 | |
208 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
208 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
209 | 209 | |
210 | 210 | return $response->id; |
211 | 211 | } |
@@ -217,42 +217,42 @@ discard block |
||
217 | 217 | * @return array |
218 | 218 | */ |
219 | 219 | public function get_sources() { |
220 | - if ( ! $this->get_id() ) { |
|
220 | + if ( ! $this->get_id()) { |
|
221 | 221 | return array(); |
222 | 222 | } |
223 | 223 | |
224 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
224 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
225 | 225 | |
226 | - $response = WC_Stripe_API::request( array( |
|
226 | + $response = WC_Stripe_API::request(array( |
|
227 | 227 | 'limit' => 100, |
228 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
228 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
229 | 229 | |
230 | - if ( ! empty( $response->error ) ) { |
|
230 | + if ( ! empty($response->error)) { |
|
231 | 231 | return array(); |
232 | 232 | } |
233 | 233 | |
234 | - if ( is_array( $response->data ) ) { |
|
234 | + if (is_array($response->data)) { |
|
235 | 235 | $sources = $response->data; |
236 | 236 | } |
237 | 237 | |
238 | - return empty( $sources ) ? array() : $sources; |
|
238 | + return empty($sources) ? array() : $sources; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
242 | 242 | * Delete a source from stripe. |
243 | 243 | * @param string $source_id |
244 | 244 | */ |
245 | - public function delete_source( $source_id ) { |
|
246 | - if ( ! $this->get_id() ) { |
|
245 | + public function delete_source($source_id) { |
|
246 | + if ( ! $this->get_id()) { |
|
247 | 247 | return false; |
248 | 248 | } |
249 | 249 | |
250 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
250 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
251 | 251 | |
252 | 252 | $this->clear_cache(); |
253 | 253 | |
254 | - if ( empty( $response->error ) ) { |
|
255 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
254 | + if (empty($response->error)) { |
|
255 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
256 | 256 | |
257 | 257 | return true; |
258 | 258 | } |
@@ -264,15 +264,15 @@ discard block |
||
264 | 264 | * Set default source in Stripe |
265 | 265 | * @param string $source_id |
266 | 266 | */ |
267 | - public function set_default_source( $source_id ) { |
|
268 | - $response = WC_Stripe_API::request( array( |
|
269 | - 'default_source' => sanitize_text_field( $source_id ), |
|
270 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
267 | + public function set_default_source($source_id) { |
|
268 | + $response = WC_Stripe_API::request(array( |
|
269 | + 'default_source' => sanitize_text_field($source_id), |
|
270 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
271 | 271 | |
272 | 272 | $this->clear_cache(); |
273 | 273 | |
274 | - if ( empty( $response->error ) ) { |
|
275 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
274 | + if (empty($response->error)) { |
|
275 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
276 | 276 | |
277 | 277 | return true; |
278 | 278 | } |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * Deletes caches for this users cards. |
285 | 285 | */ |
286 | 286 | public function clear_cache() { |
287 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
288 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
287 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
288 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
289 | 289 | $this->customer_data = array(); |
290 | 290 | } |
291 | 291 | } |
@@ -2,12 +2,12 @@ discard block |
||
2 | 2 | |
3 | 3 | class WC_Stripe_Test extends WP_UnitTestCase { |
4 | 4 | public function test_constants_defined() { |
5 | - $this->assertTrue( defined( 'WC_STRIPE_VERSION' ) ); |
|
6 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) ); |
|
7 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) ); |
|
8 | - $this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) ); |
|
9 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) ); |
|
10 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) ); |
|
5 | + $this->assertTrue(defined('WC_STRIPE_VERSION')); |
|
6 | + $this->assertTrue(defined('WC_STRIPE_MIN_PHP_VER')); |
|
7 | + $this->assertTrue(defined('WC_STRIPE_MIN_WC_VER')); |
|
8 | + $this->assertTrue(defined('WC_STRIPE_MAIN_FILE')); |
|
9 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_URL')); |
|
10 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_PATH')); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | * This test will see if we're indeed converting the price correctly. |
16 | 16 | */ |
17 | 17 | public function test_price_conversion_before_send_to_stripe() { |
18 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
19 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) ); |
|
20 | - $this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) ); |
|
21 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) ); |
|
22 | - $this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
18 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
19 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(10050, 'JPY')); |
|
20 | + $this->assertEquals(100, WC_Stripe_Helper::get_stripe_amount(100.50, 'JPY')); |
|
21 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50)); |
|
22 | + $this->assertInternalType('int', WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -33,37 +33,37 @@ discard block |
||
33 | 33 | $balance_fee1->net = 10000; |
34 | 34 | $balance_fee1->currency = 'USD'; |
35 | 35 | |
36 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) ); |
|
36 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee1, 'fee')); |
|
37 | 37 | |
38 | 38 | $balance_fee2 = new stdClass(); |
39 | 39 | $balance_fee2->fee = 10500; |
40 | 40 | $balance_fee2->net = 10000; |
41 | 41 | $balance_fee2->currency = 'JPY'; |
42 | 42 | |
43 | - $this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) ); |
|
43 | + $this->assertEquals(10500, WC_Stripe_Helper::format_balance_fee($balance_fee2, 'fee')); |
|
44 | 44 | |
45 | 45 | $balance_fee3 = new stdClass(); |
46 | 46 | $balance_fee3->fee = 10500; |
47 | 47 | $balance_fee3->net = 10000; |
48 | 48 | $balance_fee3->currency = 'USD'; |
49 | 49 | |
50 | - $this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) ); |
|
50 | + $this->assertEquals(100.00, WC_Stripe_Helper::format_balance_fee($balance_fee3, 'net')); |
|
51 | 51 | |
52 | 52 | $balance_fee4 = new stdClass(); |
53 | 53 | $balance_fee4->fee = 10500; |
54 | 54 | $balance_fee4->net = 10000; |
55 | 55 | $balance_fee4->currency = 'JPY'; |
56 | 56 | |
57 | - $this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) ); |
|
57 | + $this->assertEquals(10000, WC_Stripe_Helper::format_balance_fee($balance_fee4, 'net')); |
|
58 | 58 | |
59 | 59 | $balance_fee5 = new stdClass(); |
60 | 60 | $balance_fee5->fee = 10500; |
61 | 61 | $balance_fee5->net = 10000; |
62 | 62 | $balance_fee5->currency = 'USD'; |
63 | 63 | |
64 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
64 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
65 | 65 | |
66 | - $this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
66 | + $this->assertInternalType('string', WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -76,28 +76,28 @@ discard block |
||
76 | 76 | 'expected' => 'Tests Store', |
77 | 77 | ); |
78 | 78 | |
79 | - $this->assertEquals( $statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor1['actual'] ) ); |
|
79 | + $this->assertEquals($statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor1['actual'])); |
|
80 | 80 | |
81 | 81 | $statement_descriptor2 = array( |
82 | 82 | 'actual' => 'Test\'s Store > Driving Course Range', |
83 | 83 | 'expected' => 'Tests Store Driving C', |
84 | 84 | ); |
85 | 85 | |
86 | - $this->assertEquals( $statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor2['actual'] ) ); |
|
86 | + $this->assertEquals($statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor2['actual'])); |
|
87 | 87 | |
88 | 88 | $statement_descriptor3 = array( |
89 | 89 | 'actual' => 'Test\'s Store < Driving Course Range', |
90 | 90 | 'expected' => 'Tests Store Driving C', |
91 | 91 | ); |
92 | 92 | |
93 | - $this->assertEquals( $statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor3['actual'] ) ); |
|
93 | + $this->assertEquals($statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor3['actual'])); |
|
94 | 94 | |
95 | 95 | $statement_descriptor4 = array( |
96 | 96 | 'actual' => 'Test\'s Store " Driving Course Range', |
97 | 97 | 'expected' => 'Tests Store Driving C', |
98 | 98 | ); |
99 | 99 | |
100 | - $this->assertEquals( $statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor4['actual'] ) ); |
|
100 | + $this->assertEquals($statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor4['actual'])); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | $source = new stdClass(); |
110 | 110 | $source->type = 'three_d_secure'; |
111 | 111 | |
112 | - $this->assertEquals( true, $stripe->is_3ds_card( $source ) ); |
|
112 | + $this->assertEquals(true, $stripe->is_3ds_card($source)); |
|
113 | 113 | |
114 | 114 | $source = new stdClass(); |
115 | 115 | $source->type = 'card'; |
116 | 116 | |
117 | - $this->assertEquals( false, $stripe->is_3ds_card( $source ) ); |
|
117 | + $this->assertEquals(false, $stripe->is_3ds_card($source)); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | $source->card = new stdClass(); |
129 | 129 | $source->card->three_d_secure = 'required'; |
130 | 130 | |
131 | - $this->assertEquals( true, $stripe->is_3ds_required( $source ) ); |
|
131 | + $this->assertEquals(true, $stripe->is_3ds_required($source)); |
|
132 | 132 | |
133 | 133 | $source = new stdClass(); |
134 | 134 | $source->type = 'card'; |
135 | 135 | $source->card = new stdClass(); |
136 | 136 | $source->card->three_d_secure = 'optional'; |
137 | 137 | |
138 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
138 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
139 | 139 | |
140 | 140 | $source = new stdClass(); |
141 | 141 | $source->type = 'card'; |
142 | 142 | $source->card = new stdClass(); |
143 | 143 | $source->card->three_d_secure = 'not_supported'; |
144 | 144 | |
145 | - $this->assertEquals( false, $stripe->is_3ds_required( $source ) ); |
|
145 | + $this->assertEquals(false, $stripe->is_3ds_required($source)); |
|
146 | 146 | } |
147 | 147 | } |
@@ -1,28 +1,28 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$_tests_dir = getenv( 'WP_TESTS_DIR' ); |
|
4 | -if ( ! $_tests_dir ) { |
|
3 | +$_tests_dir = getenv('WP_TESTS_DIR'); |
|
4 | +if ( ! $_tests_dir) { |
|
5 | 5 | $_tests_dir = '/tmp/wordpress-tests-lib'; |
6 | 6 | } |
7 | 7 | |
8 | 8 | require_once $_tests_dir . '/includes/functions.php'; |
9 | 9 | |
10 | 10 | function _manually_load_plugin() { |
11 | - $plugin_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/'; |
|
11 | + $plugin_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/'; |
|
12 | 12 | require $plugin_dir . 'woocommerce-gateway-stripe/woocommerce-gateway-stripe.php'; |
13 | 13 | require $plugin_dir . 'woocommerce/woocommerce.php'; |
14 | 14 | } |
15 | 15 | |
16 | -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); |
|
16 | +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); |
|
17 | 17 | |
18 | 18 | require $_tests_dir . '/includes/bootstrap.php'; |
19 | 19 | |
20 | -$wc_tests_framework_base_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/woocommerce/tests/framework/'; |
|
21 | -require_once( $wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php' ); |
|
22 | -require_once( $wc_tests_framework_base_dir . 'class-wc-unit-test-case.php' ); |
|
23 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php' ); |
|
24 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php' ); |
|
25 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php' ); |
|
26 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php' ); |
|
27 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php' ); |
|
28 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php' ); |
|
20 | +$wc_tests_framework_base_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/woocommerce/tests/framework/'; |
|
21 | +require_once($wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php'); |
|
22 | +require_once($wc_tests_framework_base_dir . 'class-wc-unit-test-case.php'); |
|
23 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php'); |
|
24 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php'); |
|
25 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php'); |
|
26 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php'); |
|
27 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php'); |
|
28 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php'); |
@@ -104,7 +104,7 @@ |
||
104 | 104 | * Get this instance. |
105 | 105 | * |
106 | 106 | * @since 4.0.6 |
107 | - * @return class |
|
107 | + * @return WC_Stripe_Payment_Request |
|
108 | 108 | */ |
109 | 109 | public static function instance() { |
110 | 110 | return self::$_this; |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 4.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if ( ! defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
@@ -71,36 +71,36 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function __construct() { |
73 | 73 | self::$_this = $this; |
74 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
75 | - $this->testmode = ( ! empty( $this->stripe_settings['testmode'] ) && 'yes' === $this->stripe_settings['testmode'] ) ? true : false; |
|
76 | - $this->publishable_key = ! empty( $this->stripe_settings['publishable_key'] ) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | - $this->secret_key = ! empty( $this->stripe_settings['secret_key'] ) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | - $this->stripe_checkout_enabled = isset( $this->stripe_settings['stripe_checkout'] ) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | - $this->total_label = ! empty( $this->stripe_settings['statement_descriptor'] ) ? WC_Stripe_Helper::clean_statement_descriptor( $this->stripe_settings['statement_descriptor'] ) : ''; |
|
74 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
75 | + $this->testmode = ( ! empty($this->stripe_settings['testmode']) && 'yes' === $this->stripe_settings['testmode']) ? true : false; |
|
76 | + $this->publishable_key = ! empty($this->stripe_settings['publishable_key']) ? $this->stripe_settings['publishable_key'] : ''; |
|
77 | + $this->secret_key = ! empty($this->stripe_settings['secret_key']) ? $this->stripe_settings['secret_key'] : ''; |
|
78 | + $this->stripe_checkout_enabled = isset($this->stripe_settings['stripe_checkout']) && 'yes' === $this->stripe_settings['stripe_checkout']; |
|
79 | + $this->total_label = ! empty($this->stripe_settings['statement_descriptor']) ? WC_Stripe_Helper::clean_statement_descriptor($this->stripe_settings['statement_descriptor']) : ''; |
|
80 | 80 | |
81 | - if ( $this->testmode ) { |
|
82 | - $this->publishable_key = ! empty( $this->stripe_settings['test_publishable_key'] ) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | - $this->secret_key = ! empty( $this->stripe_settings['test_secret_key'] ) ? $this->stripe_settings['test_secret_key'] : ''; |
|
81 | + if ($this->testmode) { |
|
82 | + $this->publishable_key = ! empty($this->stripe_settings['test_publishable_key']) ? $this->stripe_settings['test_publishable_key'] : ''; |
|
83 | + $this->secret_key = ! empty($this->stripe_settings['test_secret_key']) ? $this->stripe_settings['test_secret_key'] : ''; |
|
84 | 84 | } |
85 | 85 | |
86 | - $this->total_label = str_replace( "'", '', $this->total_label ) . apply_filters( 'wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)' ); |
|
86 | + $this->total_label = str_replace("'", '', $this->total_label) . apply_filters('wc_stripe_payment_request_total_label_suffix', ' (via WooCommerce)'); |
|
87 | 87 | |
88 | 88 | // Checks if Stripe Gateway is enabled. |
89 | - if ( empty( $this->stripe_settings ) || ( isset( $this->stripe_settings['enabled'] ) && 'yes' !== $this->stripe_settings['enabled'] ) ) { |
|
89 | + if (empty($this->stripe_settings) || (isset($this->stripe_settings['enabled']) && 'yes' !== $this->stripe_settings['enabled'])) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
93 | 93 | // Checks if Payment Request is enabled. |
94 | - if ( ! isset( $this->stripe_settings['payment_request'] ) || 'yes' !== $this->stripe_settings['payment_request'] ) { |
|
94 | + if ( ! isset($this->stripe_settings['payment_request']) || 'yes' !== $this->stripe_settings['payment_request']) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // Don't load for change payment method page. |
99 | - if ( isset( $_GET['change_payment_method'] ) ) { |
|
99 | + if (isset($_GET['change_payment_method'])) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | - add_action( 'template_redirect', array( $this, 'set_session' ) ); |
|
103 | + add_action('template_redirect', array($this, 'set_session')); |
|
104 | 104 | $this->init(); |
105 | 105 | } |
106 | 106 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return bool |
112 | 112 | */ |
113 | 113 | public function are_keys_set() { |
114 | - if ( empty( $this->secret_key ) || empty( $this->publishable_key ) ) { |
|
114 | + if (empty($this->secret_key) || empty($this->publishable_key)) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
@@ -135,18 +135,18 @@ discard block |
||
135 | 135 | * @since 4.0.0 |
136 | 136 | */ |
137 | 137 | public function set_session() { |
138 | - if ( ! is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) { |
|
138 | + if ( ! is_product() || (isset(WC()->session) && WC()->session->has_session())) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | - $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' ); |
|
142 | + $session_class = apply_filters('woocommerce_session_handler', 'WC_Session_Handler'); |
|
143 | 143 | $wc_session = new $session_class(); |
144 | 144 | |
145 | - if ( version_compare( WC_VERSION, '3.3', '>=' ) ) { |
|
145 | + if (version_compare(WC_VERSION, '3.3', '>=')) { |
|
146 | 146 | $wc_session->init(); |
147 | 147 | } |
148 | 148 | |
149 | - $wc_session->set_customer_session_cookie( true ); |
|
149 | + $wc_session->set_customer_session_cookie(true); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -156,40 +156,40 @@ discard block |
||
156 | 156 | * @version 4.0.0 |
157 | 157 | */ |
158 | 158 | public function init() { |
159 | - add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) ); |
|
159 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
160 | 160 | |
161 | 161 | /* |
162 | 162 | * In order to display the Payment Request button in the correct position, |
163 | 163 | * a new hook was added to WooCommerce 3.0. In older versions of WooCommerce, |
164 | 164 | * CSS is used to position the button. |
165 | 165 | */ |
166 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
167 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
168 | - add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
166 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
167 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_html'), 1); |
|
168 | + add_action('woocommerce_after_add_to_cart_button', array($this, 'display_payment_request_button_separator_html'), 2); |
|
169 | 169 | } else { |
170 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
171 | - add_action( 'woocommerce_after_add_to_cart_quantity', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
170 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_html'), 1); |
|
171 | + add_action('woocommerce_after_add_to_cart_quantity', array($this, 'display_payment_request_button_separator_html'), 2); |
|
172 | 172 | } |
173 | 173 | |
174 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
175 | - add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
174 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_html'), 1); |
|
175 | + add_action('woocommerce_proceed_to_checkout', array($this, 'display_payment_request_button_separator_html'), 2); |
|
176 | 176 | |
177 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_html' ), 1 ); |
|
178 | - add_action( 'woocommerce_checkout_before_customer_details', array( $this, 'display_payment_request_button_separator_html' ), 2 ); |
|
177 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_html'), 1); |
|
178 | + add_action('woocommerce_checkout_before_customer_details', array($this, 'display_payment_request_button_separator_html'), 2); |
|
179 | 179 | |
180 | - add_action( 'wc_ajax_wc_stripe_get_cart_details', array( $this, 'ajax_get_cart_details' ) ); |
|
181 | - add_action( 'wc_ajax_wc_stripe_get_shipping_options', array( $this, 'ajax_get_shipping_options' ) ); |
|
182 | - add_action( 'wc_ajax_wc_stripe_update_shipping_method', array( $this, 'ajax_update_shipping_method' ) ); |
|
183 | - add_action( 'wc_ajax_wc_stripe_create_order', array( $this, 'ajax_create_order' ) ); |
|
184 | - add_action( 'wc_ajax_wc_stripe_add_to_cart', array( $this, 'ajax_add_to_cart' ) ); |
|
185 | - add_action( 'wc_ajax_wc_stripe_get_selected_product_data', array( $this, 'ajax_get_selected_product_data' ) ); |
|
186 | - add_action( 'wc_ajax_wc_stripe_clear_cart', array( $this, 'ajax_clear_cart' ) ); |
|
187 | - add_action( 'wc_ajax_wc_stripe_log_errors', array( $this, 'ajax_log_errors' ) ); |
|
180 | + add_action('wc_ajax_wc_stripe_get_cart_details', array($this, 'ajax_get_cart_details')); |
|
181 | + add_action('wc_ajax_wc_stripe_get_shipping_options', array($this, 'ajax_get_shipping_options')); |
|
182 | + add_action('wc_ajax_wc_stripe_update_shipping_method', array($this, 'ajax_update_shipping_method')); |
|
183 | + add_action('wc_ajax_wc_stripe_create_order', array($this, 'ajax_create_order')); |
|
184 | + add_action('wc_ajax_wc_stripe_add_to_cart', array($this, 'ajax_add_to_cart')); |
|
185 | + add_action('wc_ajax_wc_stripe_get_selected_product_data', array($this, 'ajax_get_selected_product_data')); |
|
186 | + add_action('wc_ajax_wc_stripe_clear_cart', array($this, 'ajax_clear_cart')); |
|
187 | + add_action('wc_ajax_wc_stripe_log_errors', array($this, 'ajax_log_errors')); |
|
188 | 188 | |
189 | - add_filter( 'woocommerce_gateway_title', array( $this, 'filter_gateway_title' ), 10, 2 ); |
|
190 | - add_filter( 'woocommerce_validate_postcode', array( $this, 'postal_code_validation' ), 10, 3 ); |
|
189 | + add_filter('woocommerce_gateway_title', array($this, 'filter_gateway_title'), 10, 2); |
|
190 | + add_filter('woocommerce_validate_postcode', array($this, 'postal_code_validation'), 10, 3); |
|
191 | 191 | |
192 | - add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_order_meta' ), 10, 2 ); |
|
192 | + add_action('woocommerce_checkout_order_processed', array($this, 'add_order_meta'), 10, 2); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @return string |
201 | 201 | */ |
202 | 202 | public function get_button_type() { |
203 | - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
203 | + return isset($this->stripe_settings['payment_request_button_type']) ? $this->stripe_settings['payment_request_button_type'] : 'default'; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * @return string |
212 | 212 | */ |
213 | 213 | public function get_button_theme() { |
214 | - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
214 | + return isset($this->stripe_settings['payment_request_button_theme']) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * @return string |
223 | 223 | */ |
224 | 224 | public function get_button_height() { |
225 | - return isset( $this->stripe_settings['payment_request_button_height'] ) ? str_replace( 'px', '', $this->stripe_settings['payment_request_button_height'] ) : '64'; |
|
225 | + return isset($this->stripe_settings['payment_request_button_height']) ? str_replace('px', '', $this->stripe_settings['payment_request_button_height']) : '64'; |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -232,40 +232,40 @@ discard block |
||
232 | 232 | * @version 4.0.0 |
233 | 233 | */ |
234 | 234 | public function get_product_data() { |
235 | - if ( ! is_product() ) { |
|
235 | + if ( ! is_product()) { |
|
236 | 236 | return false; |
237 | 237 | } |
238 | 238 | |
239 | 239 | global $post; |
240 | 240 | |
241 | - $product = wc_get_product( $post->ID ); |
|
241 | + $product = wc_get_product($post->ID); |
|
242 | 242 | |
243 | 243 | $data = array(); |
244 | 244 | $items = array(); |
245 | 245 | |
246 | 246 | $items[] = array( |
247 | 247 | 'label' => WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name(), |
248 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
248 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
249 | 249 | ); |
250 | 250 | |
251 | - if ( wc_tax_enabled() ) { |
|
251 | + if (wc_tax_enabled()) { |
|
252 | 252 | $items[] = array( |
253 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
253 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
254 | 254 | 'amount' => 0, |
255 | 255 | 'pending' => true, |
256 | 256 | ); |
257 | 257 | } |
258 | 258 | |
259 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
259 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
260 | 260 | $items[] = array( |
261 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
261 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
262 | 262 | 'amount' => 0, |
263 | 263 | 'pending' => true, |
264 | 264 | ); |
265 | 265 | |
266 | - $data['shippingOptions'] = array( |
|
266 | + $data['shippingOptions'] = array( |
|
267 | 267 | 'id' => 'pending', |
268 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
268 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
269 | 269 | 'detail' => '', |
270 | 270 | 'amount' => 0, |
271 | 271 | ); |
@@ -273,41 +273,41 @@ discard block |
||
273 | 273 | |
274 | 274 | $data['displayItems'] = $items; |
275 | 275 | $data['total'] = array( |
276 | - 'label' => apply_filters( 'wc_stripe_payment_request_total_label', $this->total_label ), |
|
277 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ), |
|
276 | + 'label' => apply_filters('wc_stripe_payment_request_total_label', $this->total_label), |
|
277 | + 'amount' => WC_Stripe_Helper::get_stripe_amount(WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()), |
|
278 | 278 | 'pending' => true, |
279 | 279 | ); |
280 | 280 | |
281 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
282 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
283 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
281 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
282 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
283 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
284 | 284 | |
285 | - return apply_filters( 'wc_stripe_payment_request_product_data', $data, $product ); |
|
285 | + return apply_filters('wc_stripe_payment_request_product_data', $data, $product); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
289 | 289 | * Filters the gateway title to reflect Payment Request type |
290 | 290 | * |
291 | 291 | */ |
292 | - public function filter_gateway_title( $title, $id ) { |
|
292 | + public function filter_gateway_title($title, $id) { |
|
293 | 293 | global $post; |
294 | 294 | |
295 | - if ( ! is_object( $post ) ) { |
|
295 | + if ( ! is_object($post)) { |
|
296 | 296 | return $title; |
297 | 297 | } |
298 | 298 | |
299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
300 | - $method_title = get_post_meta( $post->ID, '_payment_method_title', true ); |
|
299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
300 | + $method_title = get_post_meta($post->ID, '_payment_method_title', true); |
|
301 | 301 | } else { |
302 | - $order = wc_get_order( $post->ID ); |
|
303 | - $method_title = is_object( $order ) ? $order->get_payment_method_title() : ''; |
|
302 | + $order = wc_get_order($post->ID); |
|
303 | + $method_title = is_object($order) ? $order->get_payment_method_title() : ''; |
|
304 | 304 | } |
305 | 305 | |
306 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Apple Pay (Stripe)' === $method_title ) { |
|
306 | + if ('stripe' === $id && ! empty($method_title) && 'Apple Pay (Stripe)' === $method_title) { |
|
307 | 307 | return $method_title; |
308 | 308 | } |
309 | 309 | |
310 | - if ( 'stripe' === $id && ! empty( $method_title ) && 'Chrome Payment Request (Stripe)' === $method_title ) { |
|
310 | + if ('stripe' === $id && ! empty($method_title) && 'Chrome Payment Request (Stripe)' === $method_title) { |
|
311 | 311 | return $method_title; |
312 | 312 | } |
313 | 313 | |
@@ -320,16 +320,16 @@ discard block |
||
320 | 320 | * @since 3.1.4 |
321 | 321 | * @version 4.0.0 |
322 | 322 | */ |
323 | - public function postal_code_validation( $valid, $postcode, $country ) { |
|
323 | + public function postal_code_validation($valid, $postcode, $country) { |
|
324 | 324 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
325 | 325 | |
326 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
326 | + if ( ! isset($gateways['stripe'])) { |
|
327 | 327 | return $valid; |
328 | 328 | } |
329 | 329 | |
330 | - $payment_request_type = isset( $_POST['payment_request_type'] ) ? wc_clean( $_POST['payment_request_type'] ) : ''; |
|
330 | + $payment_request_type = isset($_POST['payment_request_type']) ? wc_clean($_POST['payment_request_type']) : ''; |
|
331 | 331 | |
332 | - if ( 'apple_pay' !== $payment_request_type ) { |
|
332 | + if ('apple_pay' !== $payment_request_type) { |
|
333 | 333 | return $valid; |
334 | 334 | } |
335 | 335 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * the order and not let it go through. The remedy for now is just to remove this validation. |
340 | 340 | * Note that this only works with shipping providers that don't validate full postal codes. |
341 | 341 | */ |
342 | - if ( 'GB' === $country || 'CA' === $country ) { |
|
342 | + if ('GB' === $country || 'CA' === $country) { |
|
343 | 343 | return true; |
344 | 344 | } |
345 | 345 | |
@@ -354,29 +354,29 @@ discard block |
||
354 | 354 | * @param int $order_id |
355 | 355 | * @param array $posted_data The posted data from checkout form. |
356 | 356 | */ |
357 | - public function add_order_meta( $order_id, $posted_data ) { |
|
358 | - if ( empty( $_POST['payment_request_type'] ) ) { |
|
357 | + public function add_order_meta($order_id, $posted_data) { |
|
358 | + if (empty($_POST['payment_request_type'])) { |
|
359 | 359 | return; |
360 | 360 | } |
361 | 361 | |
362 | - $order = wc_get_order( $order_id ); |
|
362 | + $order = wc_get_order($order_id); |
|
363 | 363 | |
364 | - $payment_request_type = wc_clean( $_POST['payment_request_type'] ); |
|
364 | + $payment_request_type = wc_clean($_POST['payment_request_type']); |
|
365 | 365 | |
366 | - if ( 'apple_pay' === $payment_request_type ) { |
|
367 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
368 | - update_post_meta( $order_id, '_payment_method_title', 'Apple Pay (Stripe)' ); |
|
366 | + if ('apple_pay' === $payment_request_type) { |
|
367 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
368 | + update_post_meta($order_id, '_payment_method_title', 'Apple Pay (Stripe)'); |
|
369 | 369 | } else { |
370 | - $order->set_payment_method_title( 'Apple Pay (Stripe)' ); |
|
370 | + $order->set_payment_method_title('Apple Pay (Stripe)'); |
|
371 | 371 | $order->save(); |
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
375 | - if ( 'payment_request_api' === $payment_request_type ) { |
|
376 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
377 | - update_post_meta( $order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)' ); |
|
375 | + if ('payment_request_api' === $payment_request_type) { |
|
376 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
377 | + update_post_meta($order_id, '_payment_method_title', 'Chrome Payment Request (Stripe)'); |
|
378 | 378 | } else { |
379 | - $order->set_payment_method_title( 'Chrome Payment Request (Stripe)' ); |
|
379 | + $order->set_payment_method_title('Chrome Payment Request (Stripe)'); |
|
380 | 380 | $order->save(); |
381 | 381 | } |
382 | 382 | } |
@@ -390,11 +390,11 @@ discard block |
||
390 | 390 | * @return array |
391 | 391 | */ |
392 | 392 | public function supported_product_types() { |
393 | - return apply_filters( 'wc_stripe_payment_request_supported_types', array( |
|
393 | + return apply_filters('wc_stripe_payment_request_supported_types', array( |
|
394 | 394 | 'simple', |
395 | 395 | 'variable', |
396 | 396 | 'variation', |
397 | - ) ); |
|
397 | + )); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -405,15 +405,15 @@ discard block |
||
405 | 405 | * @return bool |
406 | 406 | */ |
407 | 407 | public function allowed_items_in_cart() { |
408 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
409 | - $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); |
|
408 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
409 | + $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); |
|
410 | 410 | |
411 | - if ( ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type() ), $this->supported_product_types() ) ) { |
|
411 | + if ( ! in_array((WC_Stripe_Helper::is_pre_30() ? $_product->product_type : $_product->get_type()), $this->supported_product_types())) { |
|
412 | 412 | return false; |
413 | 413 | } |
414 | 414 | |
415 | 415 | // Pre Orders compatbility where we don't support charge upon release. |
416 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release( WC_Pre_Orders_Cart::get_pre_order_product() ) ) { |
|
416 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product())) { |
|
417 | 417 | return false; |
418 | 418 | } |
419 | 419 | } |
@@ -429,82 +429,82 @@ discard block |
||
429 | 429 | */ |
430 | 430 | public function scripts() { |
431 | 431 | // If keys are not set bail. |
432 | - if ( ! $this->are_keys_set() ) { |
|
433 | - WC_Stripe_Logger::log( 'Keys are not set correctly.' ); |
|
432 | + if ( ! $this->are_keys_set()) { |
|
433 | + WC_Stripe_Logger::log('Keys are not set correctly.'); |
|
434 | 434 | return; |
435 | 435 | } |
436 | 436 | |
437 | 437 | // If no SSL bail. |
438 | - if ( ! $this->testmode && ! is_ssl() ) { |
|
439 | - WC_Stripe_Logger::log( 'Stripe requires SSL.' ); |
|
438 | + if ( ! $this->testmode && ! is_ssl()) { |
|
439 | + WC_Stripe_Logger::log('Stripe requires SSL.'); |
|
440 | 440 | return; |
441 | 441 | } |
442 | 442 | |
443 | - if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) ) { |
|
443 | + if ( ! is_product() && ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order'])) { |
|
444 | 444 | return; |
445 | 445 | } |
446 | 446 | |
447 | - if ( is_product() ) { |
|
447 | + if (is_product()) { |
|
448 | 448 | global $post; |
449 | 449 | |
450 | - $product = wc_get_product( $post->ID ); |
|
450 | + $product = wc_get_product($post->ID); |
|
451 | 451 | |
452 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
452 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
453 | 453 | return; |
454 | 454 | } |
455 | 455 | |
456 | - if ( apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
456 | + if (apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
457 | 457 | return; |
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
461 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
462 | 462 | |
463 | - wp_register_script( 'stripe', 'https://js.stripe.com/v3/', '', '3.0', true ); |
|
464 | - wp_register_script( 'wc_stripe_payment_request', plugins_url( 'assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
463 | + wp_register_script('stripe', 'https://js.stripe.com/v3/', '', '3.0', true); |
|
464 | + wp_register_script('wc_stripe_payment_request', plugins_url('assets/js/stripe-payment-request' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery', 'stripe'), WC_STRIPE_VERSION, true); |
|
465 | 465 | |
466 | 466 | wp_localize_script( |
467 | 467 | 'wc_stripe_payment_request', |
468 | 468 | 'wc_stripe_payment_request_params', |
469 | 469 | array( |
470 | - 'ajax_url' => WC_AJAX::get_endpoint( '%%endpoint%%' ), |
|
470 | + 'ajax_url' => WC_AJAX::get_endpoint('%%endpoint%%'), |
|
471 | 471 | 'stripe' => array( |
472 | 472 | 'key' => $this->publishable_key, |
473 | - 'allow_prepaid_card' => apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no', |
|
473 | + 'allow_prepaid_card' => apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no', |
|
474 | 474 | ), |
475 | 475 | 'nonce' => array( |
476 | - 'payment' => wp_create_nonce( 'wc-stripe-payment-request' ), |
|
477 | - 'shipping' => wp_create_nonce( 'wc-stripe-payment-request-shipping' ), |
|
478 | - 'update_shipping' => wp_create_nonce( 'wc-stripe-update-shipping-method' ), |
|
479 | - 'checkout' => wp_create_nonce( 'woocommerce-process_checkout' ), |
|
480 | - 'add_to_cart' => wp_create_nonce( 'wc-stripe-add-to-cart' ), |
|
481 | - 'get_selected_product_data' => wp_create_nonce( 'wc-stripe-get-selected-product-data' ), |
|
482 | - 'log_errors' => wp_create_nonce( 'wc-stripe-log-errors' ), |
|
483 | - 'clear_cart' => wp_create_nonce( 'wc-stripe-clear-cart' ), |
|
476 | + 'payment' => wp_create_nonce('wc-stripe-payment-request'), |
|
477 | + 'shipping' => wp_create_nonce('wc-stripe-payment-request-shipping'), |
|
478 | + 'update_shipping' => wp_create_nonce('wc-stripe-update-shipping-method'), |
|
479 | + 'checkout' => wp_create_nonce('woocommerce-process_checkout'), |
|
480 | + 'add_to_cart' => wp_create_nonce('wc-stripe-add-to-cart'), |
|
481 | + 'get_selected_product_data' => wp_create_nonce('wc-stripe-get-selected-product-data'), |
|
482 | + 'log_errors' => wp_create_nonce('wc-stripe-log-errors'), |
|
483 | + 'clear_cart' => wp_create_nonce('wc-stripe-clear-cart'), |
|
484 | 484 | ), |
485 | 485 | 'i18n' => array( |
486 | - 'no_prepaid_card' => __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ), |
|
486 | + 'no_prepaid_card' => __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'), |
|
487 | 487 | /* translators: Do not translate the [option] placeholder */ |
488 | - 'unknown_shipping' => __( 'Unknown shipping option "[option]".', 'woocommerce-gateway-stripe' ), |
|
488 | + 'unknown_shipping' => __('Unknown shipping option "[option]".', 'woocommerce-gateway-stripe'), |
|
489 | 489 | ), |
490 | 490 | 'checkout' => array( |
491 | 491 | 'url' => wc_get_checkout_url(), |
492 | - 'currency_code' => strtolower( get_woocommerce_currency() ), |
|
493 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
492 | + 'currency_code' => strtolower(get_woocommerce_currency()), |
|
493 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
494 | 494 | 'needs_shipping' => WC()->cart->needs_shipping() ? 'yes' : 'no', |
495 | 495 | ), |
496 | 496 | 'button' => array( |
497 | 497 | 'type' => $this->get_button_type(), |
498 | 498 | 'theme' => $this->get_button_theme(), |
499 | 499 | 'height' => $this->get_button_height(), |
500 | - 'locale' => substr( get_locale(), 0, 2 ), // Default format is en_US. |
|
500 | + 'locale' => substr(get_locale(), 0, 2), // Default format is en_US. |
|
501 | 501 | ), |
502 | 502 | 'is_product_page' => is_product(), |
503 | 503 | 'product' => $this->get_product_data(), |
504 | 504 | ) |
505 | 505 | ); |
506 | 506 | |
507 | - wp_enqueue_script( 'wc_stripe_payment_request' ); |
|
507 | + wp_enqueue_script('wc_stripe_payment_request'); |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | /** |
@@ -516,39 +516,39 @@ discard block |
||
516 | 516 | public function display_payment_request_button_html() { |
517 | 517 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
518 | 518 | |
519 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
519 | + if ( ! isset($gateways['stripe'])) { |
|
520 | 520 | return; |
521 | 521 | } |
522 | 522 | |
523 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
523 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
524 | 524 | return; |
525 | 525 | } |
526 | 526 | |
527 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
527 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
528 | 528 | return; |
529 | 529 | } |
530 | 530 | |
531 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
531 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
532 | 532 | return; |
533 | 533 | } |
534 | 534 | |
535 | - if ( is_product() ) { |
|
535 | + if (is_product()) { |
|
536 | 536 | global $post; |
537 | 537 | |
538 | - $product = wc_get_product( $post->ID ); |
|
538 | + $product = wc_get_product($post->ID); |
|
539 | 539 | |
540 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
540 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
541 | 541 | return; |
542 | 542 | } |
543 | 543 | |
544 | 544 | // Pre Orders charge upon release not supported. |
545 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
546 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
545 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
546 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
547 | 547 | return; |
548 | 548 | } |
549 | 549 | } else { |
550 | - if ( ! $this->allowed_items_in_cart() ) { |
|
551 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
550 | + if ( ! $this->allowed_items_in_cart()) { |
|
551 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
552 | 552 | return; |
553 | 553 | } |
554 | 554 | } |
@@ -570,44 +570,44 @@ discard block |
||
570 | 570 | public function display_payment_request_button_separator_html() { |
571 | 571 | $gateways = WC()->payment_gateways->get_available_payment_gateways(); |
572 | 572 | |
573 | - if ( ! isset( $gateways['stripe'] ) ) { |
|
573 | + if ( ! isset($gateways['stripe'])) { |
|
574 | 574 | return; |
575 | 575 | } |
576 | 576 | |
577 | - if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset( $_GET['pay_for_order'] ) ) { |
|
577 | + if ( ! is_cart() && ! is_checkout() && ! is_product() && ! isset($_GET['pay_for_order'])) { |
|
578 | 578 | return; |
579 | 579 | } |
580 | 580 | |
581 | - if ( is_product() && apply_filters( 'wc_stripe_hide_payment_request_on_product_page', false ) ) { |
|
581 | + if (is_product() && apply_filters('wc_stripe_hide_payment_request_on_product_page', false)) { |
|
582 | 582 | return; |
583 | 583 | } |
584 | 584 | |
585 | - if ( is_checkout() && ! apply_filters( 'wc_stripe_show_payment_request_on_checkout', false ) ) { |
|
585 | + if (is_checkout() && ! apply_filters('wc_stripe_show_payment_request_on_checkout', false)) { |
|
586 | 586 | return; |
587 | 587 | } |
588 | 588 | |
589 | - if ( is_product() ) { |
|
589 | + if (is_product()) { |
|
590 | 590 | global $post; |
591 | 591 | |
592 | - $product = wc_get_product( $post->ID ); |
|
592 | + $product = wc_get_product($post->ID); |
|
593 | 593 | |
594 | - if ( ! is_object( $product ) || ! in_array( ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) { |
|
594 | + if ( ! is_object($product) || ! in_array((WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()), $this->supported_product_types())) { |
|
595 | 595 | return; |
596 | 596 | } |
597 | 597 | |
598 | 598 | // Pre Orders charge upon release not supported. |
599 | - if ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Product::product_is_charged_upon_release( $product ) ) { |
|
600 | - WC_Stripe_Logger::log( 'Pre Order charge upon release is not supported. ( Payment Request button disabled )' ); |
|
599 | + if (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Product::product_is_charged_upon_release($product)) { |
|
600 | + WC_Stripe_Logger::log('Pre Order charge upon release is not supported. ( Payment Request button disabled )'); |
|
601 | 601 | return; |
602 | 602 | } |
603 | 603 | } else { |
604 | - if ( ! $this->allowed_items_in_cart() ) { |
|
605 | - WC_Stripe_Logger::log( 'Items in the cart has unsupported product type ( Payment Request button disabled )' ); |
|
604 | + if ( ! $this->allowed_items_in_cart()) { |
|
605 | + WC_Stripe_Logger::log('Items in the cart has unsupported product type ( Payment Request button disabled )'); |
|
606 | 606 | return; |
607 | 607 | } |
608 | 608 | } |
609 | 609 | ?> |
610 | - <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> —</p> |
|
610 | + <p id="wc-stripe-payment-request-button-separator" style="margin-top:1.5em;text-align:center;display:none;">— <?php esc_html_e('OR', 'woocommerce-gateway-stripe'); ?> —</p> |
|
611 | 611 | <?php |
612 | 612 | } |
613 | 613 | |
@@ -618,11 +618,11 @@ discard block |
||
618 | 618 | * @version 4.0.0 |
619 | 619 | */ |
620 | 620 | public function ajax_log_errors() { |
621 | - check_ajax_referer( 'wc-stripe-log-errors', 'security' ); |
|
621 | + check_ajax_referer('wc-stripe-log-errors', 'security'); |
|
622 | 622 | |
623 | - $errors = wc_clean( stripslashes( $_POST['errors'] ) ); |
|
623 | + $errors = wc_clean(stripslashes($_POST['errors'])); |
|
624 | 624 | |
625 | - WC_Stripe_Logger::log( $errors ); |
|
625 | + WC_Stripe_Logger::log($errors); |
|
626 | 626 | |
627 | 627 | exit; |
628 | 628 | } |
@@ -634,7 +634,7 @@ discard block |
||
634 | 634 | * @version 4.0.0 |
635 | 635 | */ |
636 | 636 | public function ajax_clear_cart() { |
637 | - check_ajax_referer( 'wc-stripe-clear-cart', 'security' ); |
|
637 | + check_ajax_referer('wc-stripe-clear-cart', 'security'); |
|
638 | 638 | |
639 | 639 | WC()->cart->empty_cart(); |
640 | 640 | exit; |
@@ -644,10 +644,10 @@ discard block |
||
644 | 644 | * Get cart details. |
645 | 645 | */ |
646 | 646 | public function ajax_get_cart_details() { |
647 | - check_ajax_referer( 'wc-stripe-payment-request', 'security' ); |
|
647 | + check_ajax_referer('wc-stripe-payment-request', 'security'); |
|
648 | 648 | |
649 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
650 | - define( 'WOOCOMMERCE_CART', true ); |
|
649 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
650 | + define('WOOCOMMERCE_CART', true); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | WC()->cart->calculate_totals(); |
@@ -658,14 +658,14 @@ discard block |
||
658 | 658 | $data = array( |
659 | 659 | 'shipping_required' => WC()->cart->needs_shipping(), |
660 | 660 | 'order_data' => array( |
661 | - 'currency' => strtolower( $currency ), |
|
662 | - 'country_code' => substr( get_option( 'woocommerce_default_country' ), 0, 2 ), |
|
661 | + 'currency' => strtolower($currency), |
|
662 | + 'country_code' => substr(get_option('woocommerce_default_country'), 0, 2), |
|
663 | 663 | ), |
664 | 664 | ); |
665 | 665 | |
666 | 666 | $data['order_data'] += $this->build_display_items(); |
667 | 667 | |
668 | - wp_send_json( $data ); |
|
668 | + wp_send_json($data); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | /** |
@@ -676,47 +676,47 @@ discard block |
||
676 | 676 | * @see WC_Shipping::get_packages(). |
677 | 677 | */ |
678 | 678 | public function ajax_get_shipping_options() { |
679 | - check_ajax_referer( 'wc-stripe-payment-request-shipping', 'security' ); |
|
679 | + check_ajax_referer('wc-stripe-payment-request-shipping', 'security'); |
|
680 | 680 | |
681 | 681 | try { |
682 | 682 | // Set the shipping package. |
683 | - $posted = filter_input_array( INPUT_POST, array( |
|
683 | + $posted = filter_input_array(INPUT_POST, array( |
|
684 | 684 | 'country' => FILTER_SANITIZE_STRING, |
685 | 685 | 'state' => FILTER_SANITIZE_STRING, |
686 | 686 | 'postcode' => FILTER_SANITIZE_STRING, |
687 | 687 | 'city' => FILTER_SANITIZE_STRING, |
688 | 688 | 'address' => FILTER_SANITIZE_STRING, |
689 | 689 | 'address_2' => FILTER_SANITIZE_STRING, |
690 | - ) ); |
|
690 | + )); |
|
691 | 691 | |
692 | - $this->calculate_shipping( $posted ); |
|
692 | + $this->calculate_shipping($posted); |
|
693 | 693 | |
694 | 694 | // Set the shipping options. |
695 | 695 | $data = array(); |
696 | 696 | $packages = WC()->shipping->get_packages(); |
697 | 697 | |
698 | - if ( ! empty( $packages ) && WC()->customer->has_calculated_shipping() ) { |
|
699 | - foreach ( $packages as $package_key => $package ) { |
|
700 | - if ( empty( $package['rates'] ) ) { |
|
701 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
698 | + if ( ! empty($packages) && WC()->customer->has_calculated_shipping()) { |
|
699 | + foreach ($packages as $package_key => $package) { |
|
700 | + if (empty($package['rates'])) { |
|
701 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
702 | 702 | } |
703 | 703 | |
704 | - foreach ( $package['rates'] as $key => $rate ) { |
|
704 | + foreach ($package['rates'] as $key => $rate) { |
|
705 | 705 | $data['shipping_options'][] = array( |
706 | 706 | 'id' => $rate->id, |
707 | 707 | 'label' => $rate->label, |
708 | 708 | 'detail' => '', |
709 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $rate->cost ), |
|
709 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($rate->cost), |
|
710 | 710 | ); |
711 | 711 | } |
712 | 712 | } |
713 | 713 | } else { |
714 | - throw new Exception( __( 'Unable to find shipping method for address.', 'woocommerce-gateway-stripe' ) ); |
|
714 | + throw new Exception(__('Unable to find shipping method for address.', 'woocommerce-gateway-stripe')); |
|
715 | 715 | } |
716 | 716 | |
717 | - if ( isset( $data[0] ) ) { |
|
717 | + if (isset($data[0])) { |
|
718 | 718 | // Auto select the first shipping method. |
719 | - WC()->session->set( 'chosen_shipping_methods', array( $data[0]['id'] ) ); |
|
719 | + WC()->session->set('chosen_shipping_methods', array($data[0]['id'])); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | WC()->cart->calculate_totals(); |
@@ -724,12 +724,12 @@ discard block |
||
724 | 724 | $data += $this->build_display_items(); |
725 | 725 | $data['result'] = 'success'; |
726 | 726 | |
727 | - wp_send_json( $data ); |
|
728 | - } catch ( Exception $e ) { |
|
727 | + wp_send_json($data); |
|
728 | + } catch (Exception $e) { |
|
729 | 729 | $data += $this->build_display_items(); |
730 | 730 | $data['result'] = 'invalid_shipping_address'; |
731 | 731 | |
732 | - wp_send_json( $data ); |
|
732 | + wp_send_json($data); |
|
733 | 733 | } |
734 | 734 | } |
735 | 735 | |
@@ -737,22 +737,22 @@ discard block |
||
737 | 737 | * Update shipping method. |
738 | 738 | */ |
739 | 739 | public function ajax_update_shipping_method() { |
740 | - check_ajax_referer( 'wc-stripe-update-shipping-method', 'security' ); |
|
740 | + check_ajax_referer('wc-stripe-update-shipping-method', 'security'); |
|
741 | 741 | |
742 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
743 | - define( 'WOOCOMMERCE_CART', true ); |
|
742 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
743 | + define('WOOCOMMERCE_CART', true); |
|
744 | 744 | } |
745 | 745 | |
746 | - $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); |
|
747 | - $shipping_method = filter_input( INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
746 | + $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); |
|
747 | + $shipping_method = filter_input(INPUT_POST, 'shipping_method', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
748 | 748 | |
749 | - if ( is_array( $shipping_method ) ) { |
|
750 | - foreach ( $shipping_method as $i => $value ) { |
|
751 | - $chosen_shipping_methods[ $i ] = wc_clean( $value ); |
|
749 | + if (is_array($shipping_method)) { |
|
750 | + foreach ($shipping_method as $i => $value) { |
|
751 | + $chosen_shipping_methods[$i] = wc_clean($value); |
|
752 | 752 | } |
753 | 753 | } |
754 | 754 | |
755 | - WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); |
|
755 | + WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); |
|
756 | 756 | |
757 | 757 | WC()->cart->calculate_totals(); |
758 | 758 | |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | $data += $this->build_display_items(); |
761 | 761 | $data['result'] = 'success'; |
762 | 762 | |
763 | - wp_send_json( $data ); |
|
763 | + wp_send_json($data); |
|
764 | 764 | } |
765 | 765 | |
766 | 766 | /** |
@@ -771,31 +771,31 @@ discard block |
||
771 | 771 | * @return array $data |
772 | 772 | */ |
773 | 773 | public function ajax_get_selected_product_data() { |
774 | - check_ajax_referer( 'wc-stripe-get-selected-product-data', 'security' ); |
|
774 | + check_ajax_referer('wc-stripe-get-selected-product-data', 'security'); |
|
775 | 775 | |
776 | - $product_id = absint( $_POST['product_id'] ); |
|
777 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
776 | + $product_id = absint($_POST['product_id']); |
|
777 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
778 | 778 | |
779 | - $product = wc_get_product( $product_id ); |
|
779 | + $product = wc_get_product($product_id); |
|
780 | 780 | |
781 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
782 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
781 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
782 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
783 | 783 | |
784 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
785 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
784 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
785 | + $variation_id = $product->get_matching_variation($attributes); |
|
786 | 786 | } else { |
787 | - $data_store = WC_Data_Store::load( 'product' ); |
|
788 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
787 | + $data_store = WC_Data_Store::load('product'); |
|
788 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
789 | 789 | } |
790 | 790 | |
791 | - if ( ! empty( $variation_id ) ) { |
|
792 | - $product = wc_get_product( $variation_id ); |
|
791 | + if ( ! empty($variation_id)) { |
|
792 | + $product = wc_get_product($variation_id); |
|
793 | 793 | } |
794 | - } elseif ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
795 | - $product = wc_get_product( $product_id ); |
|
794 | + } elseif ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
795 | + $product = wc_get_product($product_id); |
|
796 | 796 | } |
797 | 797 | |
798 | - $total = $qty * ( WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price() ); |
|
798 | + $total = $qty * (WC_Stripe_Helper::is_pre_30() ? $product->price : $product->get_price()); |
|
799 | 799 | |
800 | 800 | $quantity_label = 1 < $qty ? ' (x' . $qty . ')' : ''; |
801 | 801 | |
@@ -803,28 +803,28 @@ discard block |
||
803 | 803 | $items = array(); |
804 | 804 | |
805 | 805 | $items[] = array( |
806 | - 'label' => ( WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name() ) . $quantity_label, |
|
807 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
806 | + 'label' => (WC_Stripe_Helper::is_pre_30() ? $product->name : $product->get_name()) . $quantity_label, |
|
807 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
808 | 808 | ); |
809 | 809 | |
810 | - if ( wc_tax_enabled() ) { |
|
810 | + if (wc_tax_enabled()) { |
|
811 | 811 | $items[] = array( |
812 | - 'label' => __( 'Tax', 'woocommerce-gateway-stripe' ), |
|
812 | + 'label' => __('Tax', 'woocommerce-gateway-stripe'), |
|
813 | 813 | 'amount' => 0, |
814 | 814 | 'pending' => true, |
815 | 815 | ); |
816 | 816 | } |
817 | 817 | |
818 | - if ( wc_shipping_enabled() && $product->needs_shipping() ) { |
|
818 | + if (wc_shipping_enabled() && $product->needs_shipping()) { |
|
819 | 819 | $items[] = array( |
820 | - 'label' => __( 'Shipping', 'woocommerce-gateway-stripe' ), |
|
820 | + 'label' => __('Shipping', 'woocommerce-gateway-stripe'), |
|
821 | 821 | 'amount' => 0, |
822 | 822 | 'pending' => true, |
823 | 823 | ); |
824 | 824 | |
825 | - $data['shippingOptions'] = array( |
|
825 | + $data['shippingOptions'] = array( |
|
826 | 826 | 'id' => 'pending', |
827 | - 'label' => __( 'Pending', 'woocommerce-gateway-stripe' ), |
|
827 | + 'label' => __('Pending', 'woocommerce-gateway-stripe'), |
|
828 | 828 | 'detail' => '', |
829 | 829 | 'amount' => 0, |
830 | 830 | ); |
@@ -833,15 +833,15 @@ discard block |
||
833 | 833 | $data['displayItems'] = $items; |
834 | 834 | $data['total'] = array( |
835 | 835 | 'label' => $this->total_label, |
836 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $total ), |
|
836 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($total), |
|
837 | 837 | 'pending' => true, |
838 | 838 | ); |
839 | 839 | |
840 | - $data['requestShipping'] = ( wc_shipping_enabled() && $product->needs_shipping() ); |
|
841 | - $data['currency'] = strtolower( get_woocommerce_currency() ); |
|
842 | - $data['country_code'] = substr( get_option( 'woocommerce_default_country' ), 0, 2 ); |
|
840 | + $data['requestShipping'] = (wc_shipping_enabled() && $product->needs_shipping()); |
|
841 | + $data['currency'] = strtolower(get_woocommerce_currency()); |
|
842 | + $data['country_code'] = substr(get_option('woocommerce_default_country'), 0, 2); |
|
843 | 843 | |
844 | - wp_send_json( $data ); |
|
844 | + wp_send_json($data); |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | /** |
@@ -852,37 +852,37 @@ discard block |
||
852 | 852 | * @return array $data |
853 | 853 | */ |
854 | 854 | public function ajax_add_to_cart() { |
855 | - check_ajax_referer( 'wc-stripe-add-to-cart', 'security' ); |
|
855 | + check_ajax_referer('wc-stripe-add-to-cart', 'security'); |
|
856 | 856 | |
857 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
858 | - define( 'WOOCOMMERCE_CART', true ); |
|
857 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
858 | + define('WOOCOMMERCE_CART', true); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | WC()->shipping->reset_shipping(); |
862 | 862 | |
863 | - $product_id = absint( $_POST['product_id'] ); |
|
864 | - $qty = ! isset( $_POST['qty'] ) ? 1 : absint( $_POST['qty'] ); |
|
863 | + $product_id = absint($_POST['product_id']); |
|
864 | + $qty = ! isset($_POST['qty']) ? 1 : absint($_POST['qty']); |
|
865 | 865 | |
866 | - $product = wc_get_product( $product_id ); |
|
866 | + $product = wc_get_product($product_id); |
|
867 | 867 | |
868 | 868 | // First empty the cart to prevent wrong calculation. |
869 | 869 | WC()->cart->empty_cart(); |
870 | 870 | |
871 | - if ( 'variable' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) && isset( $_POST['attributes'] ) ) { |
|
872 | - $attributes = array_map( 'wc_clean', $_POST['attributes'] ); |
|
871 | + if ('variable' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type()) && isset($_POST['attributes'])) { |
|
872 | + $attributes = array_map('wc_clean', $_POST['attributes']); |
|
873 | 873 | |
874 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
875 | - $variation_id = $product->get_matching_variation( $attributes ); |
|
874 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
875 | + $variation_id = $product->get_matching_variation($attributes); |
|
876 | 876 | } else { |
877 | - $data_store = WC_Data_Store::load( 'product' ); |
|
878 | - $variation_id = $data_store->find_matching_product_variation( $product, $attributes ); |
|
877 | + $data_store = WC_Data_Store::load('product'); |
|
878 | + $variation_id = $data_store->find_matching_product_variation($product, $attributes); |
|
879 | 879 | } |
880 | 880 | |
881 | - WC()->cart->add_to_cart( $product->get_id(), $qty, $variation_id, $attributes ); |
|
881 | + WC()->cart->add_to_cart($product->get_id(), $qty, $variation_id, $attributes); |
|
882 | 882 | } |
883 | 883 | |
884 | - if ( 'simple' === ( WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type() ) ) { |
|
885 | - WC()->cart->add_to_cart( $product->get_id(), $qty ); |
|
884 | + if ('simple' === (WC_Stripe_Helper::is_pre_30() ? $product->product_type : $product->get_type())) { |
|
885 | + WC()->cart->add_to_cart($product->get_id(), $qty); |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | WC()->cart->calculate_totals(); |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | $data += $this->build_display_items(); |
892 | 892 | $data['result'] = 'success'; |
893 | 893 | |
894 | - wp_send_json( $data ); |
|
894 | + wp_send_json($data); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | /** |
@@ -904,31 +904,31 @@ discard block |
||
904 | 904 | * @version 4.0.0 |
905 | 905 | */ |
906 | 906 | public function normalize_state() { |
907 | - $billing_country = ! empty( $_POST['billing_country'] ) ? wc_clean( $_POST['billing_country'] ) : ''; |
|
908 | - $shipping_country = ! empty( $_POST['shipping_country'] ) ? wc_clean( $_POST['shipping_country'] ) : ''; |
|
909 | - $billing_state = ! empty( $_POST['billing_state'] ) ? wc_clean( $_POST['billing_state'] ) : ''; |
|
910 | - $shipping_state = ! empty( $_POST['shipping_state'] ) ? wc_clean( $_POST['shipping_state'] ) : ''; |
|
907 | + $billing_country = ! empty($_POST['billing_country']) ? wc_clean($_POST['billing_country']) : ''; |
|
908 | + $shipping_country = ! empty($_POST['shipping_country']) ? wc_clean($_POST['shipping_country']) : ''; |
|
909 | + $billing_state = ! empty($_POST['billing_state']) ? wc_clean($_POST['billing_state']) : ''; |
|
910 | + $shipping_state = ! empty($_POST['shipping_state']) ? wc_clean($_POST['shipping_state']) : ''; |
|
911 | 911 | |
912 | - if ( $billing_state && $billing_country ) { |
|
913 | - $valid_states = WC()->countries->get_states( $billing_country ); |
|
912 | + if ($billing_state && $billing_country) { |
|
913 | + $valid_states = WC()->countries->get_states($billing_country); |
|
914 | 914 | |
915 | 915 | // Valid states found for country. |
916 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
917 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
918 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $billing_state ) ) { |
|
916 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
917 | + foreach ($valid_states as $state_abbr => $state) { |
|
918 | + if (preg_match('/' . preg_quote($state) . '/i', $billing_state)) { |
|
919 | 919 | $_POST['billing_state'] = $state_abbr; |
920 | 920 | } |
921 | 921 | } |
922 | 922 | } |
923 | 923 | } |
924 | 924 | |
925 | - if ( $shipping_state && $shipping_country ) { |
|
926 | - $valid_states = WC()->countries->get_states( $shipping_country ); |
|
925 | + if ($shipping_state && $shipping_country) { |
|
926 | + $valid_states = WC()->countries->get_states($shipping_country); |
|
927 | 927 | |
928 | 928 | // Valid states found for country. |
929 | - if ( ! empty( $valid_states ) && is_array( $valid_states ) && sizeof( $valid_states ) > 0 ) { |
|
930 | - foreach ( $valid_states as $state_abbr => $state ) { |
|
931 | - if ( preg_match( '/' . preg_quote( $state ) . '/i', $shipping_state ) ) { |
|
929 | + if ( ! empty($valid_states) && is_array($valid_states) && sizeof($valid_states) > 0) { |
|
930 | + foreach ($valid_states as $state_abbr => $state) { |
|
931 | + if (preg_match('/' . preg_quote($state) . '/i', $shipping_state)) { |
|
932 | 932 | $_POST['shipping_state'] = $state_abbr; |
933 | 933 | } |
934 | 934 | } |
@@ -943,19 +943,19 @@ discard block |
||
943 | 943 | * @version 4.0.0 |
944 | 944 | */ |
945 | 945 | public function ajax_create_order() { |
946 | - if ( WC()->cart->is_empty() ) { |
|
947 | - wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) ); |
|
946 | + if (WC()->cart->is_empty()) { |
|
947 | + wp_send_json_error(__('Empty cart', 'woocommerce-gateway-stripe')); |
|
948 | 948 | } |
949 | 949 | |
950 | - if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) { |
|
951 | - define( 'WOOCOMMERCE_CHECKOUT', true ); |
|
950 | + if ( ! defined('WOOCOMMERCE_CHECKOUT')) { |
|
951 | + define('WOOCOMMERCE_CHECKOUT', true); |
|
952 | 952 | } |
953 | 953 | |
954 | 954 | $this->normalize_state(); |
955 | 955 | |
956 | 956 | WC()->checkout()->process_checkout(); |
957 | 957 | |
958 | - die( 0 ); |
|
958 | + die(0); |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | /** |
@@ -965,7 +965,7 @@ discard block |
||
965 | 965 | * @version 4.0.0 |
966 | 966 | * @param array $address |
967 | 967 | */ |
968 | - protected function calculate_shipping( $address = array() ) { |
|
968 | + protected function calculate_shipping($address = array()) { |
|
969 | 969 | global $states; |
970 | 970 | |
971 | 971 | $country = $address['country']; |
@@ -982,28 +982,28 @@ discard block |
||
982 | 982 | * In some versions of Chrome, state can be a full name. So we need |
983 | 983 | * to convert that to abbreviation as WC is expecting that. |
984 | 984 | */ |
985 | - if ( 2 < strlen( $state ) ) { |
|
986 | - $state = array_search( ucfirst( strtolower( $state ) ), $states[ $country ] ); |
|
985 | + if (2 < strlen($state)) { |
|
986 | + $state = array_search(ucfirst(strtolower($state)), $states[$country]); |
|
987 | 987 | } |
988 | 988 | |
989 | 989 | WC()->shipping->reset_shipping(); |
990 | 990 | |
991 | - if ( $postcode && WC_Validation::is_postcode( $postcode, $country ) ) { |
|
992 | - $postcode = wc_format_postcode( $postcode, $country ); |
|
991 | + if ($postcode && WC_Validation::is_postcode($postcode, $country)) { |
|
992 | + $postcode = wc_format_postcode($postcode, $country); |
|
993 | 993 | } |
994 | 994 | |
995 | - if ( $country ) { |
|
996 | - WC()->customer->set_location( $country, $state, $postcode, $city ); |
|
997 | - WC()->customer->set_shipping_location( $country, $state, $postcode, $city ); |
|
995 | + if ($country) { |
|
996 | + WC()->customer->set_location($country, $state, $postcode, $city); |
|
997 | + WC()->customer->set_shipping_location($country, $state, $postcode, $city); |
|
998 | 998 | } else { |
999 | 999 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_to_base() : WC()->customer->set_billing_address_to_base(); |
1000 | 1000 | WC_Stripe_Helper::is_pre_30() ? WC()->customer->set_shipping_to_base() : WC()->customer->set_shipping_address_to_base(); |
1001 | 1001 | } |
1002 | 1002 | |
1003 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
1004 | - WC()->customer->calculated_shipping( true ); |
|
1003 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
1004 | + WC()->customer->calculated_shipping(true); |
|
1005 | 1005 | } else { |
1006 | - WC()->customer->set_calculated_shipping( true ); |
|
1006 | + WC()->customer->set_calculated_shipping(true); |
|
1007 | 1007 | WC()->customer->save(); |
1008 | 1008 | } |
1009 | 1009 | |
@@ -1020,17 +1020,17 @@ discard block |
||
1020 | 1020 | $packages[0]['destination']['address'] = $address_1; |
1021 | 1021 | $packages[0]['destination']['address_2'] = $address_2; |
1022 | 1022 | |
1023 | - foreach ( WC()->cart->get_cart() as $item ) { |
|
1024 | - if ( $item['data']->needs_shipping() ) { |
|
1025 | - if ( isset( $item['line_total'] ) ) { |
|
1023 | + foreach (WC()->cart->get_cart() as $item) { |
|
1024 | + if ($item['data']->needs_shipping()) { |
|
1025 | + if (isset($item['line_total'])) { |
|
1026 | 1026 | $packages[0]['contents_cost'] += $item['line_total']; |
1027 | 1027 | } |
1028 | 1028 | } |
1029 | 1029 | } |
1030 | 1030 | |
1031 | - $packages = apply_filters( 'woocommerce_cart_shipping_packages', $packages ); |
|
1031 | + $packages = apply_filters('woocommerce_cart_shipping_packages', $packages); |
|
1032 | 1032 | |
1033 | - WC()->shipping->calculate_shipping( $packages ); |
|
1033 | + WC()->shipping->calculate_shipping($packages); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | /** |
@@ -1039,19 +1039,19 @@ discard block |
||
1039 | 1039 | * @since 3.1.0 |
1040 | 1040 | * @version 4.0.0 |
1041 | 1041 | */ |
1042 | - protected function build_shipping_methods( $shipping_methods ) { |
|
1043 | - if ( empty( $shipping_methods ) ) { |
|
1042 | + protected function build_shipping_methods($shipping_methods) { |
|
1043 | + if (empty($shipping_methods)) { |
|
1044 | 1044 | return array(); |
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | $shipping = array(); |
1048 | 1048 | |
1049 | - foreach ( $shipping_methods as $method ) { |
|
1049 | + foreach ($shipping_methods as $method) { |
|
1050 | 1050 | $shipping[] = array( |
1051 | 1051 | 'id' => $method['id'], |
1052 | 1052 | 'label' => $method['label'], |
1053 | 1053 | 'detail' => '', |
1054 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $method['amount']['value'] ), |
|
1054 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($method['amount']['value']), |
|
1055 | 1055 | ); |
1056 | 1056 | } |
1057 | 1057 | |
@@ -1065,69 +1065,69 @@ discard block |
||
1065 | 1065 | * @version 4.0.0 |
1066 | 1066 | */ |
1067 | 1067 | protected function build_display_items() { |
1068 | - if ( ! defined( 'WOOCOMMERCE_CART' ) ) { |
|
1069 | - define( 'WOOCOMMERCE_CART', true ); |
|
1068 | + if ( ! defined('WOOCOMMERCE_CART')) { |
|
1069 | + define('WOOCOMMERCE_CART', true); |
|
1070 | 1070 | } |
1071 | 1071 | |
1072 | 1072 | $items = array(); |
1073 | 1073 | $subtotal = 0; |
1074 | 1074 | |
1075 | 1075 | // Default show only subtotal instead of itemization. |
1076 | - if ( ! apply_filters( 'wc_stripe_payment_request_hide_itemization', true ) ) { |
|
1077 | - foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
|
1076 | + if ( ! apply_filters('wc_stripe_payment_request_hide_itemization', true)) { |
|
1077 | + foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { |
|
1078 | 1078 | $amount = $cart_item['line_subtotal']; |
1079 | - $subtotal += $cart_item['line_subtotal']; |
|
1079 | + $subtotal += $cart_item['line_subtotal']; |
|
1080 | 1080 | $quantity_label = 1 < $cart_item['quantity'] ? ' (x' . $cart_item['quantity'] . ')' : ''; |
1081 | 1081 | |
1082 | 1082 | $product_name = WC_Stripe_Helper::is_pre_30() ? $cart_item['data']->post->post_title : $cart_item['data']->get_name(); |
1083 | 1083 | |
1084 | 1084 | $item = array( |
1085 | 1085 | 'label' => $product_name . $quantity_label, |
1086 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $amount ), |
|
1086 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($amount), |
|
1087 | 1087 | ); |
1088 | 1088 | |
1089 | 1089 | $items[] = $item; |
1090 | 1090 | } |
1091 | 1091 | } |
1092 | 1092 | |
1093 | - $discounts = wc_format_decimal( WC()->cart->get_cart_discount_total(), WC()->cart->dp ); |
|
1094 | - $tax = wc_format_decimal( WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp ); |
|
1095 | - $shipping = wc_format_decimal( WC()->cart->shipping_total, WC()->cart->dp ); |
|
1096 | - $items_total = wc_format_decimal( WC()->cart->cart_contents_total, WC()->cart->dp ) + $discounts; |
|
1097 | - $order_total = wc_format_decimal( $items_total + $tax + $shipping - $discounts, WC()->cart->dp ); |
|
1093 | + $discounts = wc_format_decimal(WC()->cart->get_cart_discount_total(), WC()->cart->dp); |
|
1094 | + $tax = wc_format_decimal(WC()->cart->tax_total + WC()->cart->shipping_tax_total, WC()->cart->dp); |
|
1095 | + $shipping = wc_format_decimal(WC()->cart->shipping_total, WC()->cart->dp); |
|
1096 | + $items_total = wc_format_decimal(WC()->cart->cart_contents_total, WC()->cart->dp) + $discounts; |
|
1097 | + $order_total = wc_format_decimal($items_total + $tax + $shipping - $discounts, WC()->cart->dp); |
|
1098 | 1098 | |
1099 | - if ( wc_tax_enabled() ) { |
|
1099 | + if (wc_tax_enabled()) { |
|
1100 | 1100 | $items[] = array( |
1101 | - 'label' => esc_html( __( 'Tax', 'woocommerce-gateway-stripe' ) ), |
|
1102 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $tax ), |
|
1101 | + 'label' => esc_html(__('Tax', 'woocommerce-gateway-stripe')), |
|
1102 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($tax), |
|
1103 | 1103 | ); |
1104 | 1104 | } |
1105 | 1105 | |
1106 | - if ( WC()->cart->needs_shipping() ) { |
|
1106 | + if (WC()->cart->needs_shipping()) { |
|
1107 | 1107 | $items[] = array( |
1108 | - 'label' => esc_html( __( 'Shipping', 'woocommerce-gateway-stripe' ) ), |
|
1109 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $shipping ), |
|
1108 | + 'label' => esc_html(__('Shipping', 'woocommerce-gateway-stripe')), |
|
1109 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($shipping), |
|
1110 | 1110 | ); |
1111 | 1111 | } |
1112 | 1112 | |
1113 | - if ( WC()->cart->has_discount() ) { |
|
1113 | + if (WC()->cart->has_discount()) { |
|
1114 | 1114 | $items[] = array( |
1115 | - 'label' => esc_html( __( 'Discount', 'woocommerce-gateway-stripe' ) ), |
|
1116 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $discounts ), |
|
1115 | + 'label' => esc_html(__('Discount', 'woocommerce-gateway-stripe')), |
|
1116 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($discounts), |
|
1117 | 1117 | ); |
1118 | 1118 | } |
1119 | 1119 | |
1120 | - if ( version_compare( WC_VERSION, '3.2', '<' ) ) { |
|
1120 | + if (version_compare(WC_VERSION, '3.2', '<')) { |
|
1121 | 1121 | $cart_fees = WC()->cart->fees; |
1122 | 1122 | } else { |
1123 | 1123 | $cart_fees = WC()->cart->get_fees(); |
1124 | 1124 | } |
1125 | 1125 | |
1126 | 1126 | // Include fees and taxes as display items. |
1127 | - foreach ( $cart_fees as $key => $fee ) { |
|
1127 | + foreach ($cart_fees as $key => $fee) { |
|
1128 | 1128 | $items[] = array( |
1129 | 1129 | 'label' => $fee->name, |
1130 | - 'amount' => WC_Stripe_Helper::get_stripe_amount( $fee->amount ), |
|
1130 | + 'amount' => WC_Stripe_Helper::get_stripe_amount($fee->amount), |
|
1131 | 1131 | ); |
1132 | 1132 | } |
1133 | 1133 | |
@@ -1135,7 +1135,7 @@ discard block |
||
1135 | 1135 | 'displayItems' => $items, |
1136 | 1136 | 'total' => array( |
1137 | 1137 | 'label' => $this->total_label, |
1138 | - 'amount' => max( 0, apply_filters( 'woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount( $order_total ), $order_total, WC()->cart ) ), |
|
1138 | + 'amount' => max(0, apply_filters('woocommerce_stripe_calculated_total', WC_Stripe_Helper::get_stripe_amount($order_total), $order_total, WC()->cart)), |
|
1139 | 1139 | 'pending' => false, |
1140 | 1140 | ), |
1141 | 1141 | ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_sofort'; |
60 | - $this->method_title = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_sofort_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_sofort_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['sofort']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-sofort-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,28 +241,28 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $bank_country = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'sofort'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | 254 | $post_data['sofort'] = array( |
255 | 255 | 'country' => $bank_country, |
256 | 256 | 'preferred_language' => $this->get_locale(), |
257 | 257 | ); |
258 | 258 | |
259 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
260 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
259 | + if ( ! empty($this->statement_descriptor)) { |
|
260 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
261 | 261 | } |
262 | 262 | |
263 | - WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' ); |
|
263 | + WC_Stripe_Logger::log('Info: Begin creating SOFORT source'); |
|
264 | 264 | |
265 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_sofort_source', $post_data, $order ), 'sources' ); |
|
265 | + return WC_Stripe_API::request(apply_filters('wc_stripe_sofort_source', $post_data, $order), 'sources'); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -276,59 +276,59 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return array|void |
278 | 278 | */ |
279 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
279 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
280 | 280 | try { |
281 | - $order = wc_get_order( $order_id ); |
|
281 | + $order = wc_get_order($order_id); |
|
282 | 282 | |
283 | 283 | // This will throw exception if not valid. |
284 | - $this->validate_minimum_order_amount( $order ); |
|
284 | + $this->validate_minimum_order_amount($order); |
|
285 | 285 | |
286 | 286 | // This comes from the create account checkbox in the checkout page. |
287 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
287 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
288 | 288 | |
289 | - if ( $create_account ) { |
|
289 | + if ($create_account) { |
|
290 | 290 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
291 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
291 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
292 | 292 | $new_stripe_customer->create_customer(); |
293 | 293 | } |
294 | 294 | |
295 | - $response = $this->create_source( $order ); |
|
295 | + $response = $this->create_source($order); |
|
296 | 296 | |
297 | - if ( ! empty( $response->error ) ) { |
|
298 | - $order->add_order_note( $response->error->message ); |
|
297 | + if ( ! empty($response->error)) { |
|
298 | + $order->add_order_note($response->error->message); |
|
299 | 299 | |
300 | 300 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
301 | 301 | |
302 | - if ( 'invalid_sofort_country' === $response->error->code ) { |
|
303 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
302 | + if ('invalid_sofort_country' === $response->error->code) { |
|
303 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
304 | 304 | } else { |
305 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
305 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
306 | 306 | } |
307 | 307 | |
308 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
308 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
309 | 309 | } |
310 | 310 | |
311 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
312 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
311 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
312 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
313 | 313 | } else { |
314 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
314 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
315 | 315 | $order->save(); |
316 | 316 | } |
317 | 317 | |
318 | - WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' ); |
|
318 | + WC_Stripe_Logger::log('Info: Redirecting to SOFORT...'); |
|
319 | 319 | |
320 | 320 | return array( |
321 | 321 | 'result' => 'success', |
322 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
322 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
323 | 323 | ); |
324 | - } catch ( WC_Stripe_Exception $e ) { |
|
325 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
326 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
324 | + } catch (WC_Stripe_Exception $e) { |
|
325 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
326 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
327 | 327 | |
328 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
328 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
329 | 329 | |
330 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
331 | - $this->send_failed_order_email( $order_id ); |
|
330 | + if ($order->has_status(array('pending', 'failed'))) { |
|
331 | + $this->send_failed_order_email($order_id); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_bancontact'; |
60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_bancontact_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_bancontact_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['bancontact']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-bancontact-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,25 +241,25 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'bancontact'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
254 | - $post_data['bancontact'] = array( 'preferred_language' => $this->get_locale() ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | + $post_data['bancontact'] = array('preferred_language' => $this->get_locale()); |
|
255 | 255 | |
256 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
257 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
256 | + if ( ! empty($this->statement_descriptor)) { |
|
257 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
258 | 258 | } |
259 | 259 | |
260 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
260 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
261 | 261 | |
262 | - return WC_Stripe_API::request( apply_filters( 'wc_stripe_bancontact_source', $post_data, $order ), 'sources' ); |
|
262 | + return WC_Stripe_API::request(apply_filters('wc_stripe_bancontact_source', $post_data, $order), 'sources'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -273,51 +273,51 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return array|void |
275 | 275 | */ |
276 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
276 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
277 | 277 | try { |
278 | - $order = wc_get_order( $order_id ); |
|
278 | + $order = wc_get_order($order_id); |
|
279 | 279 | |
280 | 280 | // This will throw exception if not valid. |
281 | - $this->validate_minimum_order_amount( $order ); |
|
281 | + $this->validate_minimum_order_amount($order); |
|
282 | 282 | |
283 | 283 | // This comes from the create account checkbox in the checkout page. |
284 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
284 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
285 | 285 | |
286 | - if ( $create_account ) { |
|
286 | + if ($create_account) { |
|
287 | 287 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
288 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
288 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
289 | 289 | $new_stripe_customer->create_customer(); |
290 | 290 | } |
291 | 291 | |
292 | - $response = $this->create_source( $order ); |
|
292 | + $response = $this->create_source($order); |
|
293 | 293 | |
294 | - if ( ! empty( $response->error ) ) { |
|
295 | - $order->add_order_note( $response->error->message ); |
|
294 | + if ( ! empty($response->error)) { |
|
295 | + $order->add_order_note($response->error->message); |
|
296 | 296 | |
297 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
297 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
298 | 298 | } |
299 | 299 | |
300 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
301 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
300 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
301 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
302 | 302 | } else { |
303 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
303 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
304 | 304 | $order->save(); |
305 | 305 | } |
306 | 306 | |
307 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
307 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
308 | 308 | |
309 | 309 | return array( |
310 | 310 | 'result' => 'success', |
311 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
311 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
312 | 312 | ); |
313 | - } catch ( WC_Stripe_Exception $e ) { |
|
314 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
315 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
313 | + } catch (WC_Stripe_Exception $e) { |
|
314 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
315 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
316 | 316 | |
317 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
317 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
318 | 318 | |
319 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
320 | - $this->send_failed_order_email( $order_id ); |
|
319 | + if ($order->has_status(array('pending', 'failed'))) { |
|
320 | + $this->send_failed_order_email($order_id); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | return array( |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
7 | 7 | * DEPRECATED DO NOT USE!! |
8 | 8 | */ |
9 | -if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) { |
|
9 | +if ( ! class_exists('WC_Stripe_Apple_Pay')) { |
|
10 | 10 | class WC_Stripe_Apple_Pay { |
11 | 11 | /** |
12 | 12 | * This Instance. |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function instance() { |
23 | - WC_Stripe_Logger::log( 'DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0' ); |
|
23 | + WC_Stripe_Logger::log('DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 5.0'); |
|
24 | 24 | return self::$_this; |
25 | 25 | } |
26 | 26 | |
27 | - public function __get( $var ) { |
|
27 | + public function __get($var) { |
|
28 | 28 | return null; |
29 | 29 | } |
30 | 30 | |
31 | - public function __call( $name, $arguments ) { |
|
31 | + public function __call($name, $arguments) { |
|
32 | 32 | return null; |
33 | 33 | } |
34 | 34 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function __construct() { |
66 | 66 | $this->id = 'stripe_bitcoin'; |
67 | - $this->method_title = __( 'Stripe Bitcoin', 'woocommerce-gateway-stripe' ); |
|
67 | + $this->method_title = __('Stripe Bitcoin', 'woocommerce-gateway-stripe'); |
|
68 | 68 | /* translators: link */ |
69 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
69 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
70 | 70 | $this->supports = array( |
71 | 71 | 'products', |
72 | 72 | 'refunds', |
@@ -78,29 +78,29 @@ discard block |
||
78 | 78 | // Load the settings. |
79 | 79 | $this->init_settings(); |
80 | 80 | |
81 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
82 | - $this->title = $this->get_option( 'title' ); |
|
83 | - $this->description = $this->get_option( 'description' ); |
|
84 | - $this->enabled = $this->get_option( 'enabled' ); |
|
85 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
86 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
87 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
88 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
89 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
90 | - |
|
91 | - if ( $this->testmode ) { |
|
92 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
93 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
81 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
82 | + $this->title = $this->get_option('title'); |
|
83 | + $this->description = $this->get_option('description'); |
|
84 | + $this->enabled = $this->get_option('enabled'); |
|
85 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
86 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
87 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
88 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
89 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
90 | + |
|
91 | + if ($this->testmode) { |
|
92 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
93 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
94 | 94 | } |
95 | 95 | |
96 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
97 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
98 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
99 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
100 | - add_action( 'woocommerce_thankyou_stripe_bitcoin', array( $this, 'thankyou_page' ) ); |
|
96 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
97 | + add_action('admin_notices', array($this, 'check_environment')); |
|
98 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
99 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
100 | + add_action('woocommerce_thankyou_stripe_bitcoin', array($this, 'thankyou_page')); |
|
101 | 101 | |
102 | 102 | // Customer Emails. |
103 | - add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); |
|
103 | + add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,19 +110,19 @@ discard block |
||
110 | 110 | * @version 4.0.0 |
111 | 111 | */ |
112 | 112 | public function check_environment() { |
113 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
113 | + if ( ! current_user_can('manage_woocommerce')) { |
|
114 | 114 | return; |
115 | 115 | } |
116 | 116 | |
117 | 117 | $environment_warning = $this->get_environment_warning(); |
118 | 118 | |
119 | - if ( $environment_warning ) { |
|
120 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
119 | + if ($environment_warning) { |
|
120 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
121 | 121 | } |
122 | 122 | |
123 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
124 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
125 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
123 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
124 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
125 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
126 | 126 | echo '</p></div>'; |
127 | 127 | } |
128 | 128 | } |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function get_environment_warning() { |
138 | 138 | // Add deprecated notice to logs. |
139 | - if ( 'yes' === $this->enabled ) { |
|
140 | - WC_Stripe_Logger::log( 'DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.' ); |
|
139 | + if ('yes' === $this->enabled) { |
|
140 | + WC_Stripe_Logger::log('DEPRECATED! Stripe will no longer support Bitcoin and will cease to function on April 23, 2018. Please plan accordingly.'); |
|
141 | 141 | } |
142 | 142 | |
143 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
144 | - $message = __( 'Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe' ); |
|
143 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
144 | + $message = __('Bitcoin is enabled - it requires store currency to be set to USD.', 'woocommerce-gateway-stripe'); |
|
145 | 145 | |
146 | 146 | return $message; |
147 | 147 | } |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * @return array |
158 | 158 | */ |
159 | 159 | public function get_supported_currency() { |
160 | - return apply_filters( 'wc_stripe_bitcoin_supported_currencies', array( |
|
160 | + return apply_filters('wc_stripe_bitcoin_supported_currencies', array( |
|
161 | 161 | 'USD', |
162 | - ) ); |
|
162 | + )); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @return bool |
171 | 171 | */ |
172 | 172 | public function is_available() { |
173 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
173 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
174 | 174 | return false; |
175 | 175 | } |
176 | 176 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | $icons_str .= $icons['bitcoin']; |
193 | 193 | |
194 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
194 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -202,19 +202,19 @@ discard block |
||
202 | 202 | * @access public |
203 | 203 | */ |
204 | 204 | public function payment_scripts() { |
205 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
205 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
206 | 206 | return; |
207 | 207 | } |
208 | 208 | |
209 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
210 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
209 | + wp_enqueue_style('stripe_paymentfonts'); |
|
210 | + wp_enqueue_script('woocommerce_stripe'); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | 214 | * Initialize Gateway Settings Form Fields. |
215 | 215 | */ |
216 | 216 | public function init_form_fields() { |
217 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php' ); |
|
217 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bitcoin-settings.php'); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -225,25 +225,25 @@ discard block |
||
225 | 225 | $total = WC()->cart->total; |
226 | 226 | |
227 | 227 | // If paying from order, we need to get total from order not cart. |
228 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
229 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
228 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
229 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
230 | 230 | $total = $order->get_total(); |
231 | 231 | } |
232 | 232 | |
233 | - if ( is_add_payment_method_page() ) { |
|
234 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
235 | - $total = ''; |
|
233 | + if (is_add_payment_method_page()) { |
|
234 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
235 | + $total = ''; |
|
236 | 236 | } else { |
237 | 237 | $pay_button_text = ''; |
238 | 238 | } |
239 | 239 | |
240 | 240 | echo '<div |
241 | 241 | id="stripe-bitcoin-payment-data" |
242 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
243 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
242 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
243 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
244 | 244 | |
245 | - if ( $this->description ) { |
|
246 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
245 | + if ($this->description) { |
|
246 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | echo '</div>'; |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @param int $order_id |
256 | 256 | */ |
257 | - public function thankyou_page( $order_id ) { |
|
258 | - $this->get_instructions( $order_id ); |
|
257 | + public function thankyou_page($order_id) { |
|
258 | + $this->get_instructions($order_id); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -267,13 +267,13 @@ discard block |
||
267 | 267 | * @param bool $sent_to_admin |
268 | 268 | * @param bool $plain_text |
269 | 269 | */ |
270 | - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { |
|
270 | + public function email_instructions($order, $sent_to_admin, $plain_text = false) { |
|
271 | 271 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
272 | 272 | |
273 | 273 | $payment_method = WC_Stripe_Helper::is_pre_30() ? $order->payment_method : $order->get_payment_method(); |
274 | 274 | |
275 | - if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status( 'on-hold' ) ) { |
|
276 | - $this->get_instructions( $order_id, $plain_text ); |
|
275 | + if ( ! $sent_to_admin && 'stripe_bitcoin' === $payment_method && $order->has_status('on-hold')) { |
|
276 | + $this->get_instructions($order_id, $plain_text); |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
@@ -284,38 +284,38 @@ discard block |
||
284 | 284 | * @version 4.0.0 |
285 | 285 | * @param int $order_id |
286 | 286 | */ |
287 | - public function get_instructions( $order_id, $plain_text = false ) { |
|
288 | - $data = get_post_meta( $order_id, '_stripe_bitcoin', true ); |
|
287 | + public function get_instructions($order_id, $plain_text = false) { |
|
288 | + $data = get_post_meta($order_id, '_stripe_bitcoin', true); |
|
289 | 289 | |
290 | - if ( $plain_text ) { |
|
291 | - esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
290 | + if ($plain_text) { |
|
291 | + esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
292 | 292 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
293 | - esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
293 | + esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
294 | 294 | echo $data['amount'] . "\n\n"; |
295 | 295 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
296 | - esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
296 | + esc_html_e('Receiver:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
297 | 297 | echo $data['address'] . "\n\n"; |
298 | 298 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
299 | - esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ) . "\n\n"; |
|
299 | + esc_html_e('URI:', 'woocommerce-gateway-stripe') . "\n\n"; |
|
300 | 300 | echo $data['uri'] . "\n\n"; |
301 | 301 | } else { |
302 | 302 | ?> |
303 | - <h3><?php esc_html_e( 'Please pay the following:', 'woocommerce-gateway-stripe' ); ?></h3> |
|
303 | + <h3><?php esc_html_e('Please pay the following:', 'woocommerce-gateway-stripe'); ?></h3> |
|
304 | 304 | <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"> |
305 | 305 | <li class="woocommerce-order-overview__order order"> |
306 | - <?php esc_html_e( 'Bitcoin Amount:', 'woocommerce-gateway-stripe' ); ?> |
|
306 | + <?php esc_html_e('Bitcoin Amount:', 'woocommerce-gateway-stripe'); ?> |
|
307 | 307 | <strong><?php echo $data['amount']; ?></strong> |
308 | 308 | </li> |
309 | 309 | <li class="woocommerce-order-overview__order order"> |
310 | - <?php esc_html_e( 'Receiver:', 'woocommerce-gateway-stripe' ); ?> |
|
310 | + <?php esc_html_e('Receiver:', 'woocommerce-gateway-stripe'); ?> |
|
311 | 311 | <strong><?php echo $data['address']; ?></strong> |
312 | 312 | </li> |
313 | 313 | <li class="woocommerce-order-overview__order order"> |
314 | - <?php esc_html_e( 'URI:', 'woocommerce-gateway-stripe' ); ?> |
|
314 | + <?php esc_html_e('URI:', 'woocommerce-gateway-stripe'); ?> |
|
315 | 315 | <strong> |
316 | 316 | <?php |
317 | 317 | /* translators: link */ |
318 | - printf( __( '<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe' ), $data['uri'] ); |
|
318 | + printf(__('<a href="%s">Pay Bitcoin</a>', 'woocommerce-gateway-stripe'), $data['uri']); |
|
319 | 319 | ?> |
320 | 320 | </strong> |
321 | 321 | </li> |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | * @param object $order |
333 | 333 | * @param object $source_object |
334 | 334 | */ |
335 | - public function save_instructions( $order, $source_object ) { |
|
335 | + public function save_instructions($order, $source_object) { |
|
336 | 336 | $data = array( |
337 | 337 | 'amount' => $source_object->bitcoin->amount, |
338 | 338 | 'address' => $source_object->bitcoin->address, |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | |
342 | 342 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
343 | 343 | |
344 | - update_post_meta( $order_id, '_stripe_bitcoin', $data ); |
|
344 | + update_post_meta($order_id, '_stripe_bitcoin', $data); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -355,37 +355,37 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @return array|void |
357 | 357 | */ |
358 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
358 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
359 | 359 | try { |
360 | - $order = wc_get_order( $order_id ); |
|
360 | + $order = wc_get_order($order_id); |
|
361 | 361 | |
362 | 362 | // This comes from the create account checkbox in the checkout page. |
363 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
363 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
364 | 364 | |
365 | - if ( $create_account ) { |
|
365 | + if ($create_account) { |
|
366 | 366 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
367 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
367 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
368 | 368 | $new_stripe_customer->create_customer(); |
369 | 369 | } |
370 | 370 | |
371 | - $prepared_source = $this->prepare_source( get_current_user_id(), $force_save_source ); |
|
371 | + $prepared_source = $this->prepare_source(get_current_user_id(), $force_save_source); |
|
372 | 372 | |
373 | - if ( empty( $prepared_source->source ) ) { |
|
374 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
375 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
373 | + if (empty($prepared_source->source)) { |
|
374 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
375 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
376 | 376 | } |
377 | 377 | |
378 | - $this->save_source_to_order( $order, $prepared_source ); |
|
378 | + $this->save_source_to_order($order, $prepared_source); |
|
379 | 379 | |
380 | 380 | // This will throw exception if not valid. |
381 | - $this->validate_minimum_order_amount( $order ); |
|
381 | + $this->validate_minimum_order_amount($order); |
|
382 | 382 | |
383 | - $this->save_instructions( $order, $this->get_source_object( $prepared_source->source ) ); |
|
383 | + $this->save_instructions($order, $this->get_source_object($prepared_source->source)); |
|
384 | 384 | |
385 | 385 | // Mark as on-hold (we're awaiting the payment). |
386 | - $order->update_status( 'on-hold', __( 'Awaiting Bitcoin payment', 'woocommerce-gateway-stripe' ) ); |
|
386 | + $order->update_status('on-hold', __('Awaiting Bitcoin payment', 'woocommerce-gateway-stripe')); |
|
387 | 387 | |
388 | - wc_reduce_stock_levels( $order_id ); |
|
388 | + wc_reduce_stock_levels($order_id); |
|
389 | 389 | |
390 | 390 | // Remove cart. |
391 | 391 | WC()->cart->empty_cart(); |
@@ -393,16 +393,16 @@ discard block |
||
393 | 393 | // Return thankyou redirect. |
394 | 394 | return array( |
395 | 395 | 'result' => 'success', |
396 | - 'redirect' => $this->get_return_url( $order ), |
|
396 | + 'redirect' => $this->get_return_url($order), |
|
397 | 397 | ); |
398 | - } catch ( WC_Stripe_Exception $e ) { |
|
399 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
400 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
398 | + } catch (WC_Stripe_Exception $e) { |
|
399 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
400 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
401 | 401 | |
402 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
402 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
403 | 403 | |
404 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
405 | - $this->send_failed_order_email( $order_id ); |
|
404 | + if ($order->has_status(array('pending', 'failed'))) { |
|
405 | + $this->send_failed_order_email($order_id); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | return array( |