@@ -96,7 +96,6 @@ discard block |
||
96 | 96 | * process_subscription_payment function. |
97 | 97 | * @param mixed $order |
98 | 98 | * @param int $amount (default: 0) |
99 | - * @param string $stripe_token (default: '') |
|
100 | 99 | * @param bool initial_payment |
101 | 100 | */ |
102 | 101 | public function process_subscription_payment( $order = '', $amount = 0 ) { |
@@ -139,6 +138,8 @@ discard block |
||
139 | 138 | /** |
140 | 139 | * Process the pre-order |
141 | 140 | * @param int $order_id |
141 | + * @param boolean $retry |
|
142 | + * @param boolean $force_customer |
|
142 | 143 | * @return array |
143 | 144 | */ |
144 | 145 | public function process_pre_order( $order_id, $retry, $force_customer ) { |
@@ -239,7 +240,7 @@ discard block |
||
239 | 240 | |
240 | 241 | /** |
241 | 242 | * Don't transfer Stripe fee/ID meta to renewal orders. |
242 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
243 | + * @param integer $renewal_order |
|
243 | 244 | */ |
244 | 245 | public function delete_renewal_meta( $renewal_order ) { |
245 | 246 | delete_post_meta( $renewal_order->id, 'Stripe Fee' ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -16,22 +16,22 @@ discard block |
||
16 | 16 | public function __construct() { |
17 | 17 | parent::__construct(); |
18 | 18 | |
19 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
20 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
21 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
22 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
23 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
19 | + if (class_exists('WC_Subscriptions_Order')) { |
|
20 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
21 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
22 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
23 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
24 | 24 | |
25 | 25 | // display the credit card used for a subscription in the "My Subscriptions" table |
26 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
26 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
27 | 27 | |
28 | 28 | // allow store managers to manually set Stripe as the payment method on a subscription |
29 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
30 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
29 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
30 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
31 | 31 | } |
32 | 32 | |
33 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
34 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
33 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
34 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | * @param int $order_id |
41 | 41 | * @return boolean |
42 | 42 | */ |
43 | - protected function is_subscription( $order_id ) { |
|
44 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
43 | + protected function is_subscription($order_id) { |
|
44 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | * @param int $order_id |
50 | 50 | * @return boolean |
51 | 51 | */ |
52 | - protected function is_pre_order( $order_id ) { |
|
53 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
52 | + protected function is_pre_order($order_id) { |
|
53 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -58,37 +58,37 @@ discard block |
||
58 | 58 | * @param int $order_id |
59 | 59 | * @return array |
60 | 60 | */ |
61 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
62 | - if ( $this->is_subscription( $order_id ) ) { |
|
61 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
62 | + if ($this->is_subscription($order_id)) { |
|
63 | 63 | // Regular payment with force customer enabled |
64 | - return parent::process_payment( $order_id, true, true ); |
|
64 | + return parent::process_payment($order_id, true, true); |
|
65 | 65 | |
66 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
67 | - return $this->process_pre_order( $order_id, $retry, $force_customer ); |
|
66 | + } elseif ($this->is_pre_order($order_id)) { |
|
67 | + return $this->process_pre_order($order_id, $retry, $force_customer); |
|
68 | 68 | |
69 | 69 | } else { |
70 | - return parent::process_payment( $order_id, $retry, $force_customer ); |
|
70 | + return parent::process_payment($order_id, $retry, $force_customer); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Updates other subscription sources. |
76 | 76 | */ |
77 | - protected function save_source( $order, $source ) { |
|
78 | - parent::save_source( $order, $source ); |
|
77 | + protected function save_source($order, $source) { |
|
78 | + parent::save_source($order, $source); |
|
79 | 79 | |
80 | 80 | // Also store it on the subscriptions being purchased or paid for in the order |
81 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order->id ) ) { |
|
82 | - $subscriptions = wcs_get_subscriptions_for_order( $order->id ); |
|
83 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order->id ) ) { |
|
84 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order->id ); |
|
81 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order->id)) { |
|
82 | + $subscriptions = wcs_get_subscriptions_for_order($order->id); |
|
83 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order->id)) { |
|
84 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order->id); |
|
85 | 85 | } else { |
86 | 86 | $subscriptions = array(); |
87 | 87 | } |
88 | 88 | |
89 | - foreach( $subscriptions as $subscription ) { |
|
90 | - update_post_meta( $subscription->id, '_stripe_customer_id', $source->customer ); |
|
91 | - update_post_meta( $subscription->id, '_stripe_card_id', $source->source ); |
|
89 | + foreach ($subscriptions as $subscription) { |
|
90 | + update_post_meta($subscription->id, '_stripe_customer_id', $source->customer); |
|
91 | + update_post_meta($subscription->id, '_stripe_card_id', $source->source); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
@@ -99,38 +99,38 @@ discard block |
||
99 | 99 | * @param string $stripe_token (default: '') |
100 | 100 | * @param bool initial_payment |
101 | 101 | */ |
102 | - public function process_subscription_payment( $order = '', $amount = 0 ) { |
|
103 | - if ( $amount * 100 < 50 ) { |
|
104 | - return new WP_Error( 'stripe_error', __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe' ) ); |
|
102 | + public function process_subscription_payment($order = '', $amount = 0) { |
|
103 | + if ($amount * 100 < 50) { |
|
104 | + return new WP_Error('stripe_error', __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe')); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | // Get source from order |
108 | - $source = $this->get_order_source( $order ); |
|
108 | + $source = $this->get_order_source($order); |
|
109 | 109 | |
110 | 110 | // If no order source was defined, use user source instead. |
111 | - if ( ! $source->customer ) { |
|
112 | - $source = $this->get_source( $order->customer_user ); |
|
111 | + if ( ! $source->customer) { |
|
112 | + $source = $this->get_source($order->customer_user); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | // Or fail :( |
116 | - if ( ! $source->customer ) { |
|
117 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
116 | + if ( ! $source->customer) { |
|
117 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
118 | 118 | } |
119 | 119 | |
120 | - WC_Stripe::log( "Info: Begin processing subscription payment for order {$order->id} for the amount of {$amount}" ); |
|
120 | + WC_Stripe::log("Info: Begin processing subscription payment for order {$order->id} for the amount of {$amount}"); |
|
121 | 121 | |
122 | 122 | // Make the request |
123 | - $request = $this->generate_payment_request( $order, $source ); |
|
123 | + $request = $this->generate_payment_request($order, $source); |
|
124 | 124 | $request['capture'] = 'true'; |
125 | - $request['amount'] = $this->get_stripe_amount( $amount, $request['currency'] ); |
|
125 | + $request['amount'] = $this->get_stripe_amount($amount, $request['currency']); |
|
126 | 126 | $request['metadata'] = array( |
127 | 127 | 'payment_type' => 'recurring' |
128 | 128 | ); |
129 | - $response = WC_Stripe_API::request( $request ); |
|
129 | + $response = WC_Stripe_API::request($request); |
|
130 | 130 | |
131 | 131 | // Process valid response |
132 | - if ( ! is_wp_error( $response ) ) { |
|
133 | - $this->process_response( $response, $order ); |
|
132 | + if ( ! is_wp_error($response)) { |
|
133 | + $this->process_response($response, $order); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | return $response; |
@@ -141,24 +141,24 @@ discard block |
||
141 | 141 | * @param int $order_id |
142 | 142 | * @return array |
143 | 143 | */ |
144 | - public function process_pre_order( $order_id, $retry, $force_customer ) { |
|
145 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
144 | + public function process_pre_order($order_id, $retry, $force_customer) { |
|
145 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
146 | 146 | try { |
147 | - $order = wc_get_order( $order_id ); |
|
147 | + $order = wc_get_order($order_id); |
|
148 | 148 | |
149 | - if ( $order->get_total() * 100 < 50 ) { |
|
150 | - throw new Exception( __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe' ) ); |
|
149 | + if ($order->get_total() * 100 < 50) { |
|
150 | + throw new Exception(__('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe')); |
|
151 | 151 | } |
152 | 152 | |
153 | - $source = $this->get_source( get_current_user_id(), true ); |
|
153 | + $source = $this->get_source(get_current_user_id(), true); |
|
154 | 154 | |
155 | 155 | // We need a source on file to continue. |
156 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
157 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
156 | + if (empty($source->customer) || empty($source->source)) { |
|
157 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // Store source to order meta |
161 | - $this->save_source( $order, $source ); |
|
161 | + $this->save_source($order, $source); |
|
162 | 162 | |
163 | 163 | // Reduce stock levels |
164 | 164 | $order->reduce_order_stock(); |
@@ -167,19 +167,19 @@ discard block |
||
167 | 167 | WC()->cart->empty_cart(); |
168 | 168 | |
169 | 169 | // Is pre ordered! |
170 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
170 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
171 | 171 | |
172 | 172 | // Return thank you page redirect |
173 | 173 | return array( |
174 | 174 | 'result' => 'success', |
175 | - 'redirect' => $this->get_return_url( $order ) |
|
175 | + 'redirect' => $this->get_return_url($order) |
|
176 | 176 | ); |
177 | - } catch ( Exception $e ) { |
|
178 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
177 | + } catch (Exception $e) { |
|
178 | + wc_add_notice($e->getMessage(), 'error'); |
|
179 | 179 | return; |
180 | 180 | } |
181 | 181 | } else { |
182 | - return parent::process_payment( $order_id, $retry, $force_customer ); |
|
182 | + return parent::process_payment($order_id, $retry, $force_customer); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @param WC_Order $order |
189 | 189 | * @return void |
190 | 190 | */ |
191 | - public function process_pre_order_release_payment( $order ) { |
|
191 | + public function process_pre_order_release_payment($order) { |
|
192 | 192 | try { |
193 | 193 | // Define some callbacks if the first attempt fails. |
194 | 194 | $retry_callbacks = array( |
@@ -196,33 +196,33 @@ discard block |
||
196 | 196 | 'remove_order_customer_before_retry', |
197 | 197 | ); |
198 | 198 | |
199 | - while ( 1 ) { |
|
200 | - $source = $this->get_order_source( $order ); |
|
201 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
199 | + while (1) { |
|
200 | + $source = $this->get_order_source($order); |
|
201 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
202 | 202 | |
203 | - if ( is_wp_error( $response ) ) { |
|
204 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
205 | - throw new Exception( $response->get_error_message() ); |
|
203 | + if (is_wp_error($response)) { |
|
204 | + if (0 === sizeof($retry_callbacks)) { |
|
205 | + throw new Exception($response->get_error_message()); |
|
206 | 206 | } else { |
207 | - $retry_callback = array_shift( $retry_callbacks ); |
|
208 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
207 | + $retry_callback = array_shift($retry_callbacks); |
|
208 | + call_user_func(array($this, $retry_callback), $order); |
|
209 | 209 | } |
210 | 210 | } else { |
211 | 211 | // Successful |
212 | - $this->process_response( $response, $order ); |
|
212 | + $this->process_response($response, $order); |
|
213 | 213 | break; |
214 | 214 | } |
215 | 215 | } |
216 | 216 | |
217 | - } catch ( Exception $e ) { |
|
218 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
217 | + } catch (Exception $e) { |
|
218 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
219 | 219 | |
220 | 220 | // Mark order as failed if not already set, |
221 | 221 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
222 | - if ( ! $order->has_status( 'failed' ) ) { |
|
223 | - $order->update_status( 'failed', $order_note ); |
|
222 | + if ( ! $order->has_status('failed')) { |
|
223 | + $order->update_status('failed', $order_note); |
|
224 | 224 | } else { |
225 | - $order->add_order_note( $order_note ); |
|
225 | + $order->add_order_note($order_note); |
|
226 | 226 | } |
227 | 227 | } |
228 | 228 | } |
@@ -231,20 +231,20 @@ discard block |
||
231 | 231 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
232 | 232 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
233 | 233 | */ |
234 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
235 | - delete_post_meta( $resubscribe_order->id, '_stripe_customer_id' ); |
|
236 | - delete_post_meta( $resubscribe_order->id, '_stripe_card_id' ); |
|
237 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
234 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
235 | + delete_post_meta($resubscribe_order->id, '_stripe_customer_id'); |
|
236 | + delete_post_meta($resubscribe_order->id, '_stripe_card_id'); |
|
237 | + $this->delete_renewal_meta($resubscribe_order); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
241 | 241 | * Don't transfer Stripe fee/ID meta to renewal orders. |
242 | 242 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
243 | 243 | */ |
244 | - public function delete_renewal_meta( $renewal_order ) { |
|
245 | - delete_post_meta( $renewal_order->id, 'Stripe Fee' ); |
|
246 | - delete_post_meta( $renewal_order->id, 'Net Revenue From Stripe' ); |
|
247 | - delete_post_meta( $renewal_order->id, 'Stripe Payment ID' ); |
|
244 | + public function delete_renewal_meta($renewal_order) { |
|
245 | + delete_post_meta($renewal_order->id, 'Stripe Fee'); |
|
246 | + delete_post_meta($renewal_order->id, 'Net Revenue From Stripe'); |
|
247 | + delete_post_meta($renewal_order->id, 'Stripe Payment ID'); |
|
248 | 248 | return $renewal_order; |
249 | 249 | } |
250 | 250 | |
@@ -254,11 +254,11 @@ discard block |
||
254 | 254 | * @param $amount_to_charge float The amount to charge. |
255 | 255 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
256 | 256 | */ |
257 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
258 | - $response = $this->process_subscription_payment( $renewal_order, $amount_to_charge ); |
|
257 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
258 | + $response = $this->process_subscription_payment($renewal_order, $amount_to_charge); |
|
259 | 259 | |
260 | - if ( is_wp_error( $response ) ) { |
|
261 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
260 | + if (is_wp_error($response)) { |
|
261 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
262 | 262 | } |
263 | 263 | } |
264 | 264 | |
@@ -266,16 +266,16 @@ discard block |
||
266 | 266 | * Remove order meta |
267 | 267 | * @param object $order |
268 | 268 | */ |
269 | - public function remove_order_source_before_retry( $order ) { |
|
270 | - delete_post_meta( $order->id, '_stripe_card_id' ); |
|
269 | + public function remove_order_source_before_retry($order) { |
|
270 | + delete_post_meta($order->id, '_stripe_card_id'); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
274 | 274 | * Remove order meta |
275 | 275 | * @param object $order |
276 | 276 | */ |
277 | - public function remove_order_customer_before_retry( $order ) { |
|
278 | - delete_post_meta( $order->id, '_stripe_customer_id' ); |
|
277 | + public function remove_order_customer_before_retry($order) { |
|
278 | + delete_post_meta($order->id, '_stripe_customer_id'); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
288 | 288 | * @return void |
289 | 289 | */ |
290 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
291 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
292 | - update_post_meta( $subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id ); |
|
290 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
291 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
292 | + update_post_meta($subscription->id, '_stripe_card_id', $renewal_order->stripe_card_id); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -301,15 +301,15 @@ discard block |
||
301 | 301 | * @param WC_Subscription $subscription An instance of a subscription object |
302 | 302 | * @return array |
303 | 303 | */ |
304 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
305 | - $payment_meta[ $this->id ] = array( |
|
304 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
305 | + $payment_meta[$this->id] = array( |
|
306 | 306 | 'post_meta' => array( |
307 | 307 | '_stripe_customer_id' => array( |
308 | - 'value' => get_post_meta( $subscription->id, '_stripe_customer_id', true ), |
|
308 | + 'value' => get_post_meta($subscription->id, '_stripe_customer_id', true), |
|
309 | 309 | 'label' => 'Stripe Customer ID', |
310 | 310 | ), |
311 | 311 | '_stripe_card_id' => array( |
312 | - 'value' => get_post_meta( $subscription->id, '_stripe_card_id', true ), |
|
312 | + 'value' => get_post_meta($subscription->id, '_stripe_card_id', true), |
|
313 | 313 | 'label' => 'Stripe Card ID', |
314 | 314 | ), |
315 | 315 | ), |
@@ -326,17 +326,17 @@ discard block |
||
326 | 326 | * @param array $payment_meta associative array of meta data required for automatic payments |
327 | 327 | * @return array |
328 | 328 | */ |
329 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
330 | - if ( $this->id === $payment_method_id ) { |
|
329 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
330 | + if ($this->id === $payment_method_id) { |
|
331 | 331 | |
332 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
333 | - throw new Exception( 'A "_stripe_customer_id" value is required.' ); |
|
334 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
335 | - throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' ); |
|
332 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
333 | + throw new Exception('A "_stripe_customer_id" value is required.'); |
|
334 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
335 | + throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".'); |
|
336 | 336 | } |
337 | 337 | |
338 | - if ( ! empty( $payment_meta['post_meta']['_stripe_card_id']['value'] ) && 0 !== strpos( $payment_meta['post_meta']['_stripe_card_id']['value'], 'card_' ) ) { |
|
339 | - throw new Exception( 'Invalid card ID. A valid "_stripe_card_id" must begin with "card_".' ); |
|
338 | + if ( ! empty($payment_meta['post_meta']['_stripe_card_id']['value']) && 0 !== strpos($payment_meta['post_meta']['_stripe_card_id']['value'], 'card_')) { |
|
339 | + throw new Exception('Invalid card ID. A valid "_stripe_card_id" must begin with "card_".'); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | } |
@@ -349,43 +349,43 @@ discard block |
||
349 | 349 | * @param WC_Subscription $subscription the subscription details |
350 | 350 | * @return string the subscription payment method |
351 | 351 | */ |
352 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
352 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
353 | 353 | // bail for other payment methods |
354 | - if ( $this->id !== $subscription->payment_method || ! $subscription->customer_user ) { |
|
354 | + if ($this->id !== $subscription->payment_method || ! $subscription->customer_user) { |
|
355 | 355 | return $payment_method_to_display; |
356 | 356 | } |
357 | 357 | |
358 | 358 | $stripe_customer = new WC_Stripe_Customer(); |
359 | - $stripe_customer_id = get_post_meta( $subscription->id, '_stripe_customer_id', true ); |
|
360 | - $stripe_card_id = get_post_meta( $subscription->id, '_stripe_card_id', true ); |
|
359 | + $stripe_customer_id = get_post_meta($subscription->id, '_stripe_customer_id', true); |
|
360 | + $stripe_card_id = get_post_meta($subscription->id, '_stripe_card_id', true); |
|
361 | 361 | |
362 | 362 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
363 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
363 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
364 | 364 | $user_id = $subscription->customer_user; |
365 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
366 | - $stripe_card_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
365 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
366 | + $stripe_card_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
370 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
371 | - $stripe_customer_id = get_post_meta( $subscription->order->id, '_stripe_customer_id', true ); |
|
372 | - $stripe_card_id = get_post_meta( $subscription->order->id, '_stripe_card_id', true ); |
|
370 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
371 | + $stripe_customer_id = get_post_meta($subscription->order->id, '_stripe_customer_id', true); |
|
372 | + $stripe_card_id = get_post_meta($subscription->order->id, '_stripe_card_id', true); |
|
373 | 373 | } |
374 | 374 | |
375 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
375 | + $stripe_customer->set_id($stripe_customer_id); |
|
376 | 376 | $cards = $stripe_customer->get_cards(); |
377 | 377 | |
378 | - if ( $cards ) { |
|
378 | + if ($cards) { |
|
379 | 379 | $found_card = false; |
380 | - foreach ( $cards as $card ) { |
|
381 | - if ( $card->id === $stripe_card_id ) { |
|
380 | + foreach ($cards as $card) { |
|
381 | + if ($card->id === $stripe_card_id) { |
|
382 | 382 | $found_card = true; |
383 | - $payment_method_to_display = sprintf( __( 'Via %s card ending in %s', 'woocommerce-gateway-stripe' ), ( isset( $card->type ) ? $card->type : $card->brand ), $card->last4 ); |
|
383 | + $payment_method_to_display = sprintf(__('Via %s card ending in %s', 'woocommerce-gateway-stripe'), (isset($card->type) ? $card->type : $card->brand), $card->last4); |
|
384 | 384 | break; |
385 | 385 | } |
386 | 386 | } |
387 | - if ( ! $found_card ) { |
|
388 | - $payment_method_to_display = sprintf( __( 'Via %s card ending in %s', 'woocommerce-gateway-stripe' ), ( isset( $cards[0]->type ) ? $cards[0]->type : $cards[0]->brand ), $cards[0]->last4 ); |
|
387 | + if ( ! $found_card) { |
|
388 | + $payment_method_to_display = sprintf(__('Via %s card ending in %s', 'woocommerce-gateway-stripe'), (isset($cards[0]->type) ? $cards[0]->type : $cards[0]->brand), $cards[0]->last4); |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 |
@@ -177,7 +177,7 @@ |
||
177 | 177 | * @param float $total Amount due. |
178 | 178 | * @param string $currency Accepted currency. |
179 | 179 | * |
180 | - * @return float|int |
|
180 | + * @return double |
|
181 | 181 | */ |
182 | 182 | public function get_stripe_amount( $total, $currency = '' ) { |
183 | 183 | if ( ! $currency ) { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function __construct() { |
87 | 87 | $this->id = 'stripe'; |
88 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
89 | - $this->method_description = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
88 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
89 | + $this->method_description = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
90 | 90 | $this->has_fields = true; |
91 | 91 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
92 | 92 | $this->supports = array( |
@@ -113,35 +113,35 @@ discard block |
||
113 | 113 | $this->init_settings(); |
114 | 114 | |
115 | 115 | // Get setting values. |
116 | - $this->title = $this->get_option( 'title' ); |
|
117 | - $this->description = $this->get_option( 'description' ); |
|
118 | - $this->enabled = $this->get_option( 'enabled' ); |
|
119 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
120 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
121 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
122 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
123 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
124 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
125 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
126 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
127 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
128 | - $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
116 | + $this->title = $this->get_option('title'); |
|
117 | + $this->description = $this->get_option('description'); |
|
118 | + $this->enabled = $this->get_option('enabled'); |
|
119 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
120 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
121 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
122 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
123 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
124 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
125 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
126 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
127 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
128 | + $this->logging = 'yes' === $this->get_option('logging'); |
|
129 | 129 | |
130 | - if ( $this->stripe_checkout ) { |
|
131 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
130 | + if ($this->stripe_checkout) { |
|
131 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
132 | 132 | } |
133 | 133 | |
134 | - if ( $this->testmode ) { |
|
135 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
136 | - $this->description = trim( $this->description ); |
|
134 | + if ($this->testmode) { |
|
135 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
136 | + $this->description = trim($this->description); |
|
137 | 137 | } |
138 | 138 | |
139 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
139 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
140 | 140 | |
141 | 141 | // Hooks. |
142 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
143 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
144 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
142 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
143 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
144 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -151,24 +151,24 @@ discard block |
||
151 | 151 | * @return string |
152 | 152 | */ |
153 | 153 | public function get_icon() { |
154 | - $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
155 | - $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
154 | + $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
155 | + $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
156 | 156 | |
157 | - $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
158 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
159 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
157 | + $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
158 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
159 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
160 | 160 | |
161 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
162 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
163 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
164 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
161 | + if ('USD' === get_woocommerce_currency()) { |
|
162 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
163 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
164 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
165 | 165 | } |
166 | 166 | |
167 | - if ( 'yes' === $this->bitcoin && 'yes' === $this->stripe_checkout ) { |
|
168 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
167 | + if ('yes' === $this->bitcoin && 'yes' === $this->stripe_checkout) { |
|
168 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
169 | 169 | } |
170 | 170 | |
171 | - return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
171 | + return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return float|int |
181 | 181 | */ |
182 | - public function get_stripe_amount( $total, $currency = '' ) { |
|
183 | - if ( ! $currency ) { |
|
182 | + public function get_stripe_amount($total, $currency = '') { |
|
183 | + if ( ! $currency) { |
|
184 | 184 | $currency = get_woocommerce_currency(); |
185 | 185 | } |
186 | - switch ( strtoupper( $currency ) ) { |
|
186 | + switch (strtoupper($currency)) { |
|
187 | 187 | // Zero decimal currencies. |
188 | 188 | case 'BIF' : |
189 | 189 | case 'CLP' : |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | case 'XAF' : |
201 | 201 | case 'XOF' : |
202 | 202 | case 'XPF' : |
203 | - $total = absint( $total ); |
|
203 | + $total = absint($total); |
|
204 | 204 | break; |
205 | 205 | default : |
206 | - $total = round( $total, 2 ) * 100; // In cents. |
|
206 | + $total = round($total, 2) * 100; // In cents. |
|
207 | 207 | break; |
208 | 208 | } |
209 | 209 | return $total; |
@@ -213,13 +213,13 @@ discard block |
||
213 | 213 | * Check if SSL is enabled and notify the user |
214 | 214 | */ |
215 | 215 | public function admin_notices() { |
216 | - if ( 'no' === $this->enabled ) { |
|
216 | + if ('no' === $this->enabled) { |
|
217 | 217 | return; |
218 | 218 | } |
219 | 219 | |
220 | 220 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected. |
221 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
222 | - echo '<div class="error stripe-ssl-message"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>'; |
|
221 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
222 | + echo '<div class="error stripe-ssl-message"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>'; |
|
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
@@ -227,11 +227,11 @@ discard block |
||
227 | 227 | * Check if this gateway is enabled |
228 | 228 | */ |
229 | 229 | public function is_available() { |
230 | - if ( 'yes' === $this->enabled ) { |
|
231 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
230 | + if ('yes' === $this->enabled) { |
|
231 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
234 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
235 | 235 | return false; |
236 | 236 | } |
237 | 237 | return true; |
@@ -243,9 +243,9 @@ discard block |
||
243 | 243 | * Initialise Gateway Settings Form Fields |
244 | 244 | */ |
245 | 245 | public function init_form_fields() { |
246 | - $this->form_fields = include( 'settings-stripe.php' ); |
|
246 | + $this->form_fields = include('settings-stripe.php'); |
|
247 | 247 | |
248 | - wc_enqueue_js( " |
|
248 | + wc_enqueue_js(" |
|
249 | 249 | jQuery( function( $ ) { |
250 | 250 | $( '#woocommerce_stripe_stripe_checkout' ).change(function(){ |
251 | 251 | if ( $( this ).is( ':checked' ) ) { |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | var value = $( this ).val(); |
260 | 260 | |
261 | 261 | if ( value.indexOf( '_test_' ) >= 0 ) { |
262 | - $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe' ) . "</span>' ); |
|
262 | + $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid live key. Live keys start with "sk_live_" and "pk_live_".', 'woocommerce-gateway-stripe') . "</span>' ); |
|
263 | 263 | } else { |
264 | 264 | $( this ).css( 'border-color', '' ); |
265 | 265 | $( '.stripe-error-description', $( this ).parent() ).remove(); |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | var value = $( this ).val(); |
271 | 271 | |
272 | 272 | if ( value.indexOf( '_live_' ) >= 0 ) { |
273 | - $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __( 'This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe' ) . "</span>' ); |
|
273 | + $( this ).css( 'border-color', 'red' ).after( '<span class=\"description stripe-error-description\" style=\"color:red; display:block;\">" . __('This is not a valid test key. Test keys start with "sk_test_" and "pk_test_".', 'woocommerce-gateway-stripe') . "</span>' ); |
|
274 | 274 | } else { |
275 | 275 | $( this ).css( 'border-color', '' ); |
276 | 276 | $( '.stripe-error-description', $( this ).parent() ).remove(); |
@@ -285,46 +285,46 @@ discard block |
||
285 | 285 | */ |
286 | 286 | public function payment_fields() { |
287 | 287 | $user = wp_get_current_user(); |
288 | - $display_tokenization = $this->supports( 'tokenization' ) && is_checkout() && $this->saved_cards; |
|
288 | + $display_tokenization = $this->supports('tokenization') && is_checkout() && $this->saved_cards; |
|
289 | 289 | |
290 | - if ( $user->ID ) { |
|
291 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
290 | + if ($user->ID) { |
|
291 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
292 | 292 | $user_email = $user_email ? $user_email : $user->user_email; |
293 | 293 | } else { |
294 | 294 | $user_email = ''; |
295 | 295 | } |
296 | 296 | |
297 | - if ( is_add_payment_method_page() ) { |
|
298 | - $pay_button_text = __( 'Add Card', 'woocommerce-gateway-stripe' ); |
|
297 | + if (is_add_payment_method_page()) { |
|
298 | + $pay_button_text = __('Add Card', 'woocommerce-gateway-stripe'); |
|
299 | 299 | } else { |
300 | 300 | $pay_button_text = ''; |
301 | 301 | } |
302 | 302 | |
303 | 303 | echo '<div |
304 | 304 | id="stripe-payment-data" |
305 | - data-panel-label="' . esc_attr( $pay_button_text ) . '" |
|
305 | + data-panel-label="' . esc_attr($pay_button_text) . '" |
|
306 | 306 | data-description="" |
307 | - data-email="' . esc_attr( $user_email ) . '" |
|
308 | - data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '" |
|
309 | - data-name="' . esc_attr( sprintf( __( '%s', 'woocommerce-gateway-stripe' ), get_bloginfo( 'name', 'display' ) ) ) . '" |
|
310 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
311 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
312 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
313 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">'; |
|
307 | + data-email="' . esc_attr($user_email) . '" |
|
308 | + data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '" |
|
309 | + data-name="' . esc_attr(sprintf(__('%s', 'woocommerce-gateway-stripe'), get_bloginfo('name', 'display'))) . '" |
|
310 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
311 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
312 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
313 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">'; |
|
314 | 314 | |
315 | - if ( $this->description ) { |
|
316 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
315 | + if ($this->description) { |
|
316 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
317 | 317 | } |
318 | 318 | |
319 | - if ( $display_tokenization ) { |
|
319 | + if ($display_tokenization) { |
|
320 | 320 | $this->tokenization_script(); |
321 | 321 | $this->saved_payment_methods(); |
322 | 322 | } |
323 | 323 | |
324 | - if ( ! $this->stripe_checkout ) { |
|
324 | + if ( ! $this->stripe_checkout) { |
|
325 | 325 | $this->form(); |
326 | 326 | |
327 | - if ( $display_tokenization ) { |
|
327 | + if ($display_tokenization) { |
|
328 | 328 | $this->save_payment_method_checkbox(); |
329 | 329 | } |
330 | 330 | } |
@@ -340,29 +340,29 @@ discard block |
||
340 | 340 | * @access public |
341 | 341 | */ |
342 | 342 | public function payment_scripts() { |
343 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
343 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
344 | 344 | |
345 | - if ( $this->stripe_checkout ) { |
|
346 | - wp_enqueue_script( 'stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true ); |
|
347 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
345 | + if ($this->stripe_checkout) { |
|
346 | + wp_enqueue_script('stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true); |
|
347 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
348 | 348 | } else { |
349 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
350 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
349 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
350 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe' . $suffix . '.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | $stripe_params = array( |
354 | 354 | 'key' => $this->publishable_key, |
355 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
356 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
355 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
356 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
357 | 357 | ); |
358 | 358 | |
359 | 359 | // If we're on the pay page we need to pass stripe.js the address of the order. |
360 | - if ( is_checkout_pay_page() && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) { |
|
361 | - $order_key = urldecode( $_GET['order'] ); |
|
362 | - $order_id = absint( $_GET['order_id'] ); |
|
363 | - $order = wc_get_order( $order_id ); |
|
360 | + if (is_checkout_pay_page() && isset($_GET['order']) && isset($_GET['order_id'])) { |
|
361 | + $order_key = urldecode($_GET['order']); |
|
362 | + $order_id = absint($_GET['order_id']); |
|
363 | + $order = wc_get_order($order_id); |
|
364 | 364 | |
365 | - if ( $order->id === $order_id && $order->order_key === $order_key ) { |
|
365 | + if ($order->id === $order_id && $order->order_key === $order_key) { |
|
366 | 366 | $stripe_params['billing_first_name'] = $order->billing_first_name; |
367 | 367 | $stripe_params['billing_last_name'] = $order->billing_last_name; |
368 | 368 | $stripe_params['billing_address_1'] = $order->billing_address_1; |
@@ -374,25 +374,25 @@ discard block |
||
374 | 374 | } |
375 | 375 | } |
376 | 376 | |
377 | - $stripe_params['no_prepaid_card_msg'] = __( 'Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe' ); |
|
378 | - $stripe_params['allow_prepaid_card'] = apply_filters( 'wc_stripe_allow_prepaid_card', true ) ? 'yes' : 'no'; |
|
379 | - $stripe_params['stripe_checkout_require_billing_address'] = apply_filters( 'wc_stripe_checkout_require_billing_address', false ) ? 'yes' : 'no'; |
|
377 | + $stripe_params['no_prepaid_card_msg'] = __('Sorry, we\'re not accepting prepaid cards at this time.', 'woocommerce-gateway-stripe'); |
|
378 | + $stripe_params['allow_prepaid_card'] = apply_filters('wc_stripe_allow_prepaid_card', true) ? 'yes' : 'no'; |
|
379 | + $stripe_params['stripe_checkout_require_billing_address'] = apply_filters('wc_stripe_checkout_require_billing_address', false) ? 'yes' : 'no'; |
|
380 | 380 | |
381 | 381 | // localize error messages from Stripe |
382 | - $stripe_params['invalid_number'] = __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ); |
|
383 | - $stripe_params['invalid_expiry_month'] = __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ); |
|
384 | - $stripe_params['invalid_expiry_year'] = __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ); |
|
385 | - $stripe_params['invalid_cvc'] = __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ); |
|
386 | - $stripe_params['incorrect_number'] = __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ); |
|
387 | - $stripe_params['expired_card'] = __( 'The card has expired.', 'woocommerce-gateway-stripe' ); |
|
388 | - $stripe_params['incorrect_cvc'] = __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ); |
|
389 | - $stripe_params['incorrect_zip'] = __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ); |
|
390 | - $stripe_params['card_declined'] = __( 'The card was declined.', 'woocommerce-gateway-stripe' ); |
|
391 | - $stripe_params['missing'] = __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ); |
|
392 | - $stripe_params['processing_error'] = __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ); |
|
393 | - $stripe_params['invalid_request_error'] = __( 'Could not find payment information.', 'woocommerce-gateway-stripe' ); |
|
394 | - |
|
395 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
382 | + $stripe_params['invalid_number'] = __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'); |
|
383 | + $stripe_params['invalid_expiry_month'] = __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'); |
|
384 | + $stripe_params['invalid_expiry_year'] = __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'); |
|
385 | + $stripe_params['invalid_cvc'] = __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'); |
|
386 | + $stripe_params['incorrect_number'] = __('The card number is incorrect.', 'woocommerce-gateway-stripe'); |
|
387 | + $stripe_params['expired_card'] = __('The card has expired.', 'woocommerce-gateway-stripe'); |
|
388 | + $stripe_params['incorrect_cvc'] = __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'); |
|
389 | + $stripe_params['incorrect_zip'] = __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'); |
|
390 | + $stripe_params['card_declined'] = __('The card was declined.', 'woocommerce-gateway-stripe'); |
|
391 | + $stripe_params['missing'] = __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'); |
|
392 | + $stripe_params['processing_error'] = __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'); |
|
393 | + $stripe_params['invalid_request_error'] = __('Could not find payment information.', 'woocommerce-gateway-stripe'); |
|
394 | + |
|
395 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -401,24 +401,24 @@ discard block |
||
401 | 401 | * @param object $source |
402 | 402 | * @return array() |
403 | 403 | */ |
404 | - protected function generate_payment_request( $order, $source ) { |
|
404 | + protected function generate_payment_request($order, $source) { |
|
405 | 405 | $post_data = array(); |
406 | - $post_data['currency'] = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() ); |
|
407 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
408 | - $post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
406 | + $post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency()); |
|
407 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
408 | + $post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
409 | 409 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
410 | 410 | |
411 | - if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
411 | + if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
412 | 412 | $post_data['receipt_email'] = $order->billing_email; |
413 | 413 | } |
414 | 414 | |
415 | - $post_data['expand[]'] = 'balance_transaction'; |
|
415 | + $post_data['expand[]'] = 'balance_transaction'; |
|
416 | 416 | |
417 | - if ( $source->customer ) { |
|
417 | + if ($source->customer) { |
|
418 | 418 | $post_data['customer'] = $source->customer; |
419 | 419 | } |
420 | 420 | |
421 | - if ( $source->source ) { |
|
421 | + if ($source->source) { |
|
422 | 422 | $post_data['source'] = $source->source; |
423 | 423 | } |
424 | 424 | |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | * @param WC_Order $order |
431 | 431 | * @param object $source |
432 | 432 | */ |
433 | - return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $source ); |
|
433 | + return apply_filters('wc_stripe_generate_payment_request', $post_data, $order, $source); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -442,22 +442,22 @@ discard block |
||
442 | 442 | * @throws Exception When card was not added or for and invalid card. |
443 | 443 | * @return object |
444 | 444 | */ |
445 | - protected function get_source( $user_id, $force_customer = false ) { |
|
446 | - $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
445 | + protected function get_source($user_id, $force_customer = false) { |
|
446 | + $stripe_customer = new WC_Stripe_Customer($user_id); |
|
447 | 447 | $stripe_source = false; |
448 | 448 | $token_id = false; |
449 | 449 | |
450 | 450 | // New CC info was entered and we have a new token to process |
451 | - if ( isset( $_POST['stripe_token'] ) ) { |
|
452 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
453 | - $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
451 | + if (isset($_POST['stripe_token'])) { |
|
452 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
453 | + $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
454 | 454 | |
455 | 455 | // This is true if the user wants to store the card to their account. |
456 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
457 | - $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
456 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
457 | + $stripe_source = $stripe_customer->add_card($stripe_token); |
|
458 | 458 | |
459 | - if ( is_wp_error( $stripe_source ) ) { |
|
460 | - throw new Exception( $stripe_source->get_error_message() ); |
|
459 | + if (is_wp_error($stripe_source)) { |
|
460 | + throw new Exception($stripe_source->get_error_message()); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | } else { |
@@ -468,13 +468,13 @@ discard block |
||
468 | 468 | } |
469 | 469 | |
470 | 470 | // Use an existing token, and then process the payment |
471 | - elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
472 | - $token_id = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
473 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
471 | + elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
472 | + $token_id = wc_clean($_POST['wc-stripe-payment-token']); |
|
473 | + $token = WC_Payment_Tokens::get($token_id); |
|
474 | 474 | |
475 | - if ( ! $token || $token->get_user_id() !== get_current_user_id() ) { |
|
476 | - WC()->session->set( 'refresh_totals', true ); |
|
477 | - throw new Exception( __( 'Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe' ) ); |
|
475 | + if ( ! $token || $token->get_user_id() !== get_current_user_id()) { |
|
476 | + WC()->session->set('refresh_totals', true); |
|
477 | + throw new Exception(__('Invalid payment method. Please input a new card number.', 'woocommerce-gateway-stripe')); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | $stripe_source = $token->get_token(); |
@@ -498,16 +498,16 @@ discard block |
||
498 | 498 | * @param object $order |
499 | 499 | * @return object |
500 | 500 | */ |
501 | - protected function get_order_source( $order = null ) { |
|
501 | + protected function get_order_source($order = null) { |
|
502 | 502 | $stripe_customer = new WC_Stripe_Customer(); |
503 | 503 | $stripe_source = false; |
504 | 504 | $token_id = false; |
505 | 505 | |
506 | - if ( $order ) { |
|
507 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) { |
|
508 | - $stripe_customer->set_id( $meta_value ); |
|
506 | + if ($order) { |
|
507 | + if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) { |
|
508 | + $stripe_customer->set_id($meta_value); |
|
509 | 509 | } |
510 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) { |
|
510 | + if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) { |
|
511 | 511 | $stripe_source = $meta_value; |
512 | 512 | } |
513 | 513 | } |
@@ -530,48 +530,48 @@ discard block |
||
530 | 530 | * |
531 | 531 | * @return array|void |
532 | 532 | */ |
533 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
533 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
534 | 534 | try { |
535 | - $order = wc_get_order( $order_id ); |
|
536 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
535 | + $order = wc_get_order($order_id); |
|
536 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
537 | 537 | |
538 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
539 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
540 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
541 | - throw new Exception( $error_msg ); |
|
538 | + if (empty($source->source) && empty($source->customer)) { |
|
539 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
540 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
541 | + throw new Exception($error_msg); |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | // Store source to order meta. |
545 | - $this->save_source( $order, $source ); |
|
545 | + $this->save_source($order, $source); |
|
546 | 546 | |
547 | 547 | // Handle payment. |
548 | - if ( $order->get_total() > 0 ) { |
|
548 | + if ($order->get_total() > 0) { |
|
549 | 549 | |
550 | - if ( $order->get_total() * 100 < 50 ) { |
|
551 | - throw new Exception( __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe' ) ); |
|
550 | + if ($order->get_total() * 100 < 50) { |
|
551 | + throw new Exception(__('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe')); |
|
552 | 552 | } |
553 | 553 | |
554 | - WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
554 | + WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
555 | 555 | |
556 | 556 | // Make the request. |
557 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
557 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
558 | 558 | |
559 | - if ( is_wp_error( $response ) ) { |
|
559 | + if (is_wp_error($response)) { |
|
560 | 560 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
561 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
562 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
563 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
561 | + if ('customer' === $response->get_error_code() && $retry) { |
|
562 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
563 | + return $this->process_payment($order_id, false, $force_customer); |
|
564 | 564 | // Source param wrong? The CARD may have been deleted on stripe's end. Remove token and show message. |
565 | - } elseif ( 'source' === $response->get_error_code() && $source->token_id ) { |
|
566 | - $token = WC_Payment_Tokens::get( $source->token_id ); |
|
565 | + } elseif ('source' === $response->get_error_code() && $source->token_id) { |
|
566 | + $token = WC_Payment_Tokens::get($source->token_id); |
|
567 | 567 | $token->delete(); |
568 | - throw new Exception( __( 'This card is no longer available and has been removed.', 'woocommerce-gateway-stripe' ) ); |
|
568 | + throw new Exception(__('This card is no longer available and has been removed.', 'woocommerce-gateway-stripe')); |
|
569 | 569 | } |
570 | - throw new Exception( $response->get_error_code() . ': ' . $response->get_error_message() ); |
|
570 | + throw new Exception($response->get_error_code() . ': ' . $response->get_error_message()); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | // Process valid response. |
574 | - $this->process_response( $response, $order ); |
|
574 | + $this->process_response($response, $order); |
|
575 | 575 | } else { |
576 | 576 | $order->payment_complete(); |
577 | 577 | } |
@@ -582,16 +582,16 @@ discard block |
||
582 | 582 | // Return thank you page redirect. |
583 | 583 | return array( |
584 | 584 | 'result' => 'success', |
585 | - 'redirect' => $this->get_return_url( $order ) |
|
585 | + 'redirect' => $this->get_return_url($order) |
|
586 | 586 | ); |
587 | 587 | |
588 | - } catch ( Exception $e ) { |
|
589 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
590 | - WC()->session->set( 'refresh_totals', true ); |
|
591 | - WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
588 | + } catch (Exception $e) { |
|
589 | + wc_add_notice($e->getMessage(), 'error'); |
|
590 | + WC()->session->set('refresh_totals', true); |
|
591 | + WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
592 | 592 | |
593 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
594 | - $this->send_failed_order_email( $order_id ); |
|
593 | + if ($order->has_status(array('pending', 'failed'))) { |
|
594 | + $this->send_failed_order_email($order_id); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | return; |
@@ -604,49 +604,49 @@ discard block |
||
604 | 604 | * @param WC_Order $order For to which the source applies. |
605 | 605 | * @param stdClass $source Source information. |
606 | 606 | */ |
607 | - protected function save_source( $order, $source ) { |
|
607 | + protected function save_source($order, $source) { |
|
608 | 608 | // Store source in the order. |
609 | - if ( $source->customer ) { |
|
610 | - update_post_meta( $order->id, '_stripe_customer_id', $source->customer ); |
|
609 | + if ($source->customer) { |
|
610 | + update_post_meta($order->id, '_stripe_customer_id', $source->customer); |
|
611 | 611 | } |
612 | - if ( $source->source ) { |
|
613 | - update_post_meta( $order->id, '_stripe_card_id', $source->source ); |
|
612 | + if ($source->source) { |
|
613 | + update_post_meta($order->id, '_stripe_card_id', $source->source); |
|
614 | 614 | } |
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
618 | 618 | * Store extra meta data for an order from a Stripe Response. |
619 | 619 | */ |
620 | - public function process_response( $response, $order ) { |
|
621 | - WC_Stripe::log( "Processing response: " . print_r( $response, true ) ); |
|
620 | + public function process_response($response, $order) { |
|
621 | + WC_Stripe::log("Processing response: " . print_r($response, true)); |
|
622 | 622 | |
623 | 623 | // Store charge data |
624 | - update_post_meta( $order->id, '_stripe_charge_id', $response->id ); |
|
625 | - update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
624 | + update_post_meta($order->id, '_stripe_charge_id', $response->id); |
|
625 | + update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
626 | 626 | |
627 | 627 | // Store other data such as fees |
628 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
629 | - $fee = number_format( $response->balance_transaction->fee / 100, 2, '.', '' ); |
|
630 | - update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
631 | - update_post_meta( $order->id, 'Net Revenue From Stripe', $order->get_total() - $fee ); |
|
628 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
629 | + $fee = number_format($response->balance_transaction->fee / 100, 2, '.', ''); |
|
630 | + update_post_meta($order->id, 'Stripe Fee', $fee); |
|
631 | + update_post_meta($order->id, 'Net Revenue From Stripe', $order->get_total() - $fee); |
|
632 | 632 | } |
633 | 633 | |
634 | - if ( $response->captured ) { |
|
635 | - $order->payment_complete( $response->id ); |
|
634 | + if ($response->captured) { |
|
635 | + $order->payment_complete($response->id); |
|
636 | 636 | |
637 | - $message = sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $response->id ); |
|
638 | - $order->add_order_note( $message ); |
|
639 | - WC_Stripe::log( 'Success: ' . $message ); |
|
637 | + $message = sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $response->id); |
|
638 | + $order->add_order_note($message); |
|
639 | + WC_Stripe::log('Success: ' . $message); |
|
640 | 640 | |
641 | 641 | } else { |
642 | - add_post_meta( $order->id, '_transaction_id', $response->id, true ); |
|
642 | + add_post_meta($order->id, '_transaction_id', $response->id, true); |
|
643 | 643 | |
644 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
644 | + if ($order->has_status(array('pending', 'failed'))) { |
|
645 | 645 | $order->reduce_order_stock(); |
646 | 646 | } |
647 | 647 | |
648 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
649 | - WC_Stripe::log( "Successful auth: $response->id" ); |
|
648 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
649 | + WC_Stripe::log("Successful auth: $response->id"); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | return $response; |
@@ -658,21 +658,21 @@ discard block |
||
658 | 658 | * @since 3.0.0 |
659 | 659 | */ |
660 | 660 | public function add_payment_method() { |
661 | - if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
662 | - wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
661 | + if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
662 | + wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
663 | 663 | return; |
664 | 664 | } |
665 | 665 | |
666 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
667 | - $card = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
666 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
667 | + $card = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
668 | 668 | |
669 | - if ( is_wp_error( $card ) ) { |
|
670 | - throw new Exception( $card->get_error_message() ); |
|
669 | + if (is_wp_error($card)) { |
|
670 | + throw new Exception($card->get_error_message()); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | return array( |
674 | 674 | 'result' => 'success', |
675 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
675 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
676 | 676 | ); |
677 | 677 | } |
678 | 678 | |
@@ -682,36 +682,36 @@ discard block |
||
682 | 682 | * @param float $amount |
683 | 683 | * @return bool |
684 | 684 | */ |
685 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
686 | - $order = wc_get_order( $order_id ); |
|
685 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
686 | + $order = wc_get_order($order_id); |
|
687 | 687 | |
688 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
688 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
689 | 689 | return false; |
690 | 690 | } |
691 | 691 | |
692 | 692 | $body = array(); |
693 | 693 | |
694 | - if ( ! is_null( $amount ) ) { |
|
695 | - $body['amount'] = $this->get_stripe_amount( $amount ); |
|
694 | + if ( ! is_null($amount)) { |
|
695 | + $body['amount'] = $this->get_stripe_amount($amount); |
|
696 | 696 | } |
697 | 697 | |
698 | - if ( $reason ) { |
|
698 | + if ($reason) { |
|
699 | 699 | $body['metadata'] = array( |
700 | 700 | 'reason' => $reason, |
701 | 701 | ); |
702 | 702 | } |
703 | 703 | |
704 | - WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
704 | + WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
705 | 705 | |
706 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
706 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
707 | 707 | |
708 | - if ( is_wp_error( $response ) ) { |
|
709 | - WC_Stripe::log( "Error: " . $response->get_error_message() ); |
|
708 | + if (is_wp_error($response)) { |
|
709 | + WC_Stripe::log("Error: " . $response->get_error_message()); |
|
710 | 710 | return $response; |
711 | - } elseif ( ! empty( $response->id ) ) { |
|
712 | - $refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
713 | - $order->add_order_note( $refund_message ); |
|
714 | - WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
711 | + } elseif ( ! empty($response->id)) { |
|
712 | + $refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
713 | + $order->add_order_note($refund_message); |
|
714 | + WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message))); |
|
715 | 715 | return true; |
716 | 716 | } |
717 | 717 | } |
@@ -724,10 +724,10 @@ discard block |
||
724 | 724 | * @param int $order_id |
725 | 725 | * @return null |
726 | 726 | */ |
727 | - public function send_failed_order_email( $order_id ) { |
|
727 | + public function send_failed_order_email($order_id) { |
|
728 | 728 | $emails = WC()->mailer()->get_emails(); |
729 | - if ( ! empty( $emails ) && ! empty( $order_id ) ) { |
|
730 | - $emails['WC_Email_Failed_Order']->trigger( $order_id ); |
|
729 | + if ( ! empty($emails) && ! empty($order_id)) { |
|
730 | + $emails['WC_Email_Failed_Order']->trigger($order_id); |
|
731 | 731 | } |
732 | 732 | } |
733 | 733 | } |
@@ -23,7 +23,6 @@ |
||
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Set secret API Key. |
26 | - * @param string $key |
|
27 | 26 | */ |
28 | 27 | public static function set_secret_key( $secret_key ) { |
29 | 28 | self::$secret_key = $secret_key; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * Set secret API Key. |
26 | 26 | * @param string $key |
27 | 27 | */ |
28 | - public static function set_secret_key( $secret_key ) { |
|
28 | + public static function set_secret_key($secret_key) { |
|
29 | 29 | self::$secret_key = $secret_key; |
30 | 30 | } |
31 | 31 | |
@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | * @return string |
35 | 35 | */ |
36 | 36 | public static function get_secret_key() { |
37 | - if ( ! self::$secret_key ) { |
|
38 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
37 | + if ( ! self::$secret_key) { |
|
38 | + $options = get_option('woocommerce_stripe_settings'); |
|
39 | 39 | |
40 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
41 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
40 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
41 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | return self::$secret_key; |
@@ -51,39 +51,39 @@ discard block |
||
51 | 51 | * @param string $api |
52 | 52 | * @return array|WP_Error |
53 | 53 | */ |
54 | - public static function request( $request, $api = 'charges', $method = 'POST' ) { |
|
55 | - WC_Stripe::log( "{$api} request: " . print_r( $request, true ) ); |
|
54 | + public static function request($request, $api = 'charges', $method = 'POST') { |
|
55 | + WC_Stripe::log("{$api} request: " . print_r($request, true)); |
|
56 | 56 | |
57 | 57 | $response = wp_safe_remote_post( |
58 | 58 | self::ENDPOINT . $api, |
59 | 59 | array( |
60 | 60 | 'method' => $method, |
61 | 61 | 'headers' => array( |
62 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key(). ':' ), |
|
62 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
63 | 63 | 'Stripe-Version' => '2016-03-07' |
64 | 64 | ), |
65 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
65 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
66 | 66 | 'timeout' => 70, |
67 | 67 | 'user-agent' => 'WooCommerce ' . WC()->version |
68 | 68 | ) |
69 | 69 | ); |
70 | 70 | |
71 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
72 | - WC_Stripe::log( "Error Response: " . print_r( $response, true ) ); |
|
73 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe' ) ); |
|
71 | + if (is_wp_error($response) || empty($response['body'])) { |
|
72 | + WC_Stripe::log("Error Response: " . print_r($response, true)); |
|
73 | + return new WP_Error('stripe_error', __('There was a problem connecting to the payment gateway.', 'woocommerce-gateway-stripe')); |
|
74 | 74 | } |
75 | 75 | |
76 | - $parsed_response = json_decode( $response['body'] ); |
|
76 | + $parsed_response = json_decode($response['body']); |
|
77 | 77 | // Handle response |
78 | - if ( ! empty( $parsed_response->error ) ) { |
|
79 | - if ( ! empty( $parsed_response->error->param ) ) { |
|
78 | + if ( ! empty($parsed_response->error)) { |
|
79 | + if ( ! empty($parsed_response->error->param)) { |
|
80 | 80 | $code = $parsed_response->error->param; |
81 | - } elseif ( ! empty( $parsed_response->error->code ) ) { |
|
81 | + } elseif ( ! empty($parsed_response->error->code)) { |
|
82 | 82 | $code = $parsed_response->error->code; |
83 | 83 | } else { |
84 | 84 | $code = 'stripe_error'; |
85 | 85 | } |
86 | - return new WP_Error( $code, $parsed_response->error->message ); |
|
86 | + return new WP_Error($code, $parsed_response->error->message); |
|
87 | 87 | } else { |
88 | 88 | return $parsed_response; |
89 | 89 | } |
@@ -210,7 +210,6 @@ |
||
210 | 210 | /** |
211 | 211 | * Get a customers saved cards using their Stripe ID. Cached. |
212 | 212 | * |
213 | - * @param string $customer_id |
|
214 | 213 | * @return array |
215 | 214 | */ |
216 | 215 | public function get_cards() { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | * Constructor |
33 | 33 | * @param integer $user_id |
34 | 34 | */ |
35 | - public function __construct( $user_id = 0 ) { |
|
36 | - if ( $user_id ) { |
|
37 | - $this->set_user_id( $user_id ); |
|
38 | - $this->set_id( get_user_meta( $user_id, '_stripe_customer_id', true ) ); |
|
35 | + public function __construct($user_id = 0) { |
|
36 | + if ($user_id) { |
|
37 | + $this->set_user_id($user_id); |
|
38 | + $this->set_id(get_user_meta($user_id, '_stripe_customer_id', true)); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * Set Stripe customer ID. |
52 | 52 | * @param [type] $id [description] |
53 | 53 | */ |
54 | - public function set_id( $id ) { |
|
55 | - $this->id = wc_clean( $id ); |
|
54 | + public function set_id($id) { |
|
55 | + $this->id = wc_clean($id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | * @return int |
61 | 61 | */ |
62 | 62 | public function get_user_id() { |
63 | - return absint( $this->user_id ); |
|
63 | + return absint($this->user_id); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Set User ID used by WordPress. |
68 | 68 | * @param int $user_id |
69 | 69 | */ |
70 | - public function set_user_id( $user_id ) { |
|
71 | - $this->user_id = absint( $user_id ); |
|
70 | + public function set_user_id($user_id) { |
|
71 | + $this->user_id = absint($user_id); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | * @return WP_User |
77 | 77 | */ |
78 | 78 | protected function get_user() { |
79 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
79 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Store data from the Stripe API about this customer |
84 | 84 | */ |
85 | - public function set_customer_data( $data ) { |
|
85 | + public function set_customer_data($data) { |
|
86 | 86 | $this->customer_data = $data; |
87 | 87 | } |
88 | 88 | |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | * Get data from the Stripe API about this customer |
91 | 91 | */ |
92 | 92 | public function get_customer_data() { |
93 | - if ( empty( $this->customer_data ) && $this->get_id() && false === ( $this->customer_data = get_transient( 'stripe_customer_' . $this->get_id() ) ) ) { |
|
94 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() ); |
|
93 | + if (empty($this->customer_data) && $this->get_id() && false === ($this->customer_data = get_transient('stripe_customer_' . $this->get_id()))) { |
|
94 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id()); |
|
95 | 95 | |
96 | - if ( ! is_wp_error( $response ) ) { |
|
97 | - $this->set_customer_data( $response ); |
|
98 | - set_transient( 'stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48 ); |
|
96 | + if ( ! is_wp_error($response)) { |
|
97 | + $this->set_customer_data($response); |
|
98 | + set_transient('stripe_customer_' . $this->get_id(), $response, HOUR_IN_SECONDS * 48); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | return $this->customer_data; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $data = $this->get_customer_data(); |
110 | 110 | $source = ''; |
111 | 111 | |
112 | - if ( $data ) { |
|
112 | + if ($data) { |
|
113 | 113 | $source = $data->default_source; |
114 | 114 | } |
115 | 115 | |
@@ -121,10 +121,10 @@ discard block |
||
121 | 121 | * @param array $args |
122 | 122 | * @return WP_Error|int |
123 | 123 | */ |
124 | - public function create_customer( $args = array() ) { |
|
125 | - if ( $user = $this->get_user() ) { |
|
126 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
127 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
124 | + public function create_customer($args = array()) { |
|
125 | + if ($user = $this->get_user()) { |
|
126 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
127 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
128 | 128 | |
129 | 129 | $defaults = array( |
130 | 130 | 'email' => $user->user_email, |
@@ -137,24 +137,24 @@ discard block |
||
137 | 137 | ); |
138 | 138 | } |
139 | 139 | |
140 | - $args = wp_parse_args( $args, $defaults ); |
|
141 | - $response = WC_Stripe_API::request( $args, 'customers' ); |
|
140 | + $args = wp_parse_args($args, $defaults); |
|
141 | + $response = WC_Stripe_API::request($args, 'customers'); |
|
142 | 142 | |
143 | - if ( is_wp_error( $response ) ) { |
|
143 | + if (is_wp_error($response)) { |
|
144 | 144 | return $response; |
145 | - } elseif ( empty( $response->id ) ) { |
|
146 | - return new WP_Error( 'stripe_error', __( 'Could not create Stripe customer.', 'woocommerce-gateway-stripe' ) ); |
|
145 | + } elseif (empty($response->id)) { |
|
146 | + return new WP_Error('stripe_error', __('Could not create Stripe customer.', 'woocommerce-gateway-stripe')); |
|
147 | 147 | } |
148 | 148 | |
149 | - $this->set_id( $response->id ); |
|
149 | + $this->set_id($response->id); |
|
150 | 150 | $this->clear_cache(); |
151 | - $this->set_customer_data( $response ); |
|
151 | + $this->set_customer_data($response); |
|
152 | 152 | |
153 | - if ( $this->get_user_id() ) { |
|
154 | - update_user_meta( $this->get_user_id(), '_stripe_customer_id', $response->id ); |
|
153 | + if ($this->get_user_id()) { |
|
154 | + update_user_meta($this->get_user_id(), '_stripe_customer_id', $response->id); |
|
155 | 155 | } |
156 | 156 | |
157 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
157 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
158 | 158 | |
159 | 159 | return $response->id; |
160 | 160 | } |
@@ -165,44 +165,44 @@ discard block |
||
165 | 165 | * @param bool $retry |
166 | 166 | * @return WP_Error|int |
167 | 167 | */ |
168 | - public function add_card( $token, $retry = true ) { |
|
169 | - if ( ! $this->get_id() ) { |
|
170 | - if ( ( $response = $this->create_customer() ) && is_wp_error( $response ) ) { |
|
168 | + public function add_card($token, $retry = true) { |
|
169 | + if ( ! $this->get_id()) { |
|
170 | + if (($response = $this->create_customer()) && is_wp_error($response)) { |
|
171 | 171 | return $response; |
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | - $response = WC_Stripe_API::request( array( |
|
175 | + $response = WC_Stripe_API::request(array( |
|
176 | 176 | 'source' => $token |
177 | - ), 'customers/' . $this->get_id() . '/sources' ); |
|
177 | + ), 'customers/' . $this->get_id() . '/sources'); |
|
178 | 178 | |
179 | - if ( is_wp_error( $response ) ) { |
|
180 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
179 | + if (is_wp_error($response)) { |
|
180 | + if ('customer' === $response->get_error_code() && $retry) { |
|
181 | 181 | $this->create_customer(); |
182 | - return $this->add_card( $token, false ); |
|
182 | + return $this->add_card($token, false); |
|
183 | 183 | } else { |
184 | 184 | return $response; |
185 | 185 | } |
186 | - } elseif ( empty( $response->id ) ) { |
|
187 | - return new WP_Error( 'error', __( 'Unable to add card', 'woocommerce-gateway-stripe' ) ); |
|
186 | + } elseif (empty($response->id)) { |
|
187 | + return new WP_Error('error', __('Unable to add card', 'woocommerce-gateway-stripe')); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | // Add token to WooCommerce |
191 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
191 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
192 | 192 | $token = new WC_Payment_Token_CC(); |
193 | - $token->set_token( $response->id ); |
|
194 | - $token->set_gateway_id( 'stripe' ); |
|
195 | - $token->set_card_type( strtolower( $response->brand ) ); |
|
196 | - $token->set_last4( $response->last4 ); |
|
197 | - $token->set_expiry_month( $response->exp_month ); |
|
198 | - $token->set_expiry_year( $response->exp_year ); |
|
199 | - $token->set_user_id( $this->get_user_id() ); |
|
193 | + $token->set_token($response->id); |
|
194 | + $token->set_gateway_id('stripe'); |
|
195 | + $token->set_card_type(strtolower($response->brand)); |
|
196 | + $token->set_last4($response->last4); |
|
197 | + $token->set_expiry_month($response->exp_month); |
|
198 | + $token->set_expiry_year($response->exp_year); |
|
199 | + $token->set_user_id($this->get_user_id()); |
|
200 | 200 | $token->save(); |
201 | 201 | } |
202 | 202 | |
203 | 203 | $this->clear_cache(); |
204 | 204 | |
205 | - do_action( 'woocommerce_stripe_add_card', $this->get_id(), $token, $response ); |
|
205 | + do_action('woocommerce_stripe_add_card', $this->get_id(), $token, $response); |
|
206 | 206 | |
207 | 207 | return $response->id; |
208 | 208 | } |
@@ -216,20 +216,20 @@ discard block |
||
216 | 216 | public function get_cards() { |
217 | 217 | $cards = array(); |
218 | 218 | |
219 | - if ( $this->get_id() && false === ( $cards = get_transient( 'stripe_cards_' . $this->get_id() ) ) ) { |
|
220 | - $response = WC_Stripe_API::request( array( |
|
219 | + if ($this->get_id() && false === ($cards = get_transient('stripe_cards_' . $this->get_id()))) { |
|
220 | + $response = WC_Stripe_API::request(array( |
|
221 | 221 | 'limit' => 100 |
222 | - ), 'customers/' . $this->get_id() . '/sources', 'GET' ); |
|
222 | + ), 'customers/' . $this->get_id() . '/sources', 'GET'); |
|
223 | 223 | |
224 | - if ( is_wp_error( $response ) ) { |
|
224 | + if (is_wp_error($response)) { |
|
225 | 225 | return array(); |
226 | 226 | } |
227 | 227 | |
228 | - if ( is_array( $response->data ) ) { |
|
228 | + if (is_array($response->data)) { |
|
229 | 229 | $cards = $response->data; |
230 | 230 | } |
231 | 231 | |
232 | - set_transient( 'stripe_cards_' . $this->get_id(), $cards, HOUR_IN_SECONDS * 48 ); |
|
232 | + set_transient('stripe_cards_' . $this->get_id(), $cards, HOUR_IN_SECONDS * 48); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | return $cards; |
@@ -239,13 +239,13 @@ discard block |
||
239 | 239 | * Delete a card from stripe. |
240 | 240 | * @param string $card_id |
241 | 241 | */ |
242 | - public function delete_card( $card_id ) { |
|
243 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $card_id ), 'DELETE' ); |
|
242 | + public function delete_card($card_id) { |
|
243 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($card_id), 'DELETE'); |
|
244 | 244 | |
245 | 245 | $this->clear_cache(); |
246 | 246 | |
247 | - if ( ! is_wp_error( $response ) ) { |
|
248 | - do_action( 'wc_stripe_delete_card', $this->get_id(), $response ); |
|
247 | + if ( ! is_wp_error($response)) { |
|
248 | + do_action('wc_stripe_delete_card', $this->get_id(), $response); |
|
249 | 249 | |
250 | 250 | return true; |
251 | 251 | } |
@@ -257,15 +257,15 @@ discard block |
||
257 | 257 | * Set default card in Stripe |
258 | 258 | * @param string $card_id |
259 | 259 | */ |
260 | - public function set_default_card( $card_id ) { |
|
261 | - $response = WC_Stripe_API::request( array( |
|
262 | - 'default_source' => sanitize_text_field( $card_id ), |
|
263 | - ), 'customers/' . $this->get_id(), 'POST' ); |
|
260 | + public function set_default_card($card_id) { |
|
261 | + $response = WC_Stripe_API::request(array( |
|
262 | + 'default_source' => sanitize_text_field($card_id), |
|
263 | + ), 'customers/' . $this->get_id(), 'POST'); |
|
264 | 264 | |
265 | 265 | $this->clear_cache(); |
266 | 266 | |
267 | - if ( ! is_wp_error( $response ) ) { |
|
268 | - do_action( 'wc_stripe_set_default_card', $this->get_id(), $response ); |
|
267 | + if ( ! is_wp_error($response)) { |
|
268 | + do_action('wc_stripe_set_default_card', $this->get_id(), $response); |
|
269 | 269 | |
270 | 270 | return true; |
271 | 271 | } |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | * Deletes caches for this users cards. |
278 | 278 | */ |
279 | 279 | public function clear_cache() { |
280 | - delete_transient( 'stripe_cards_' . $this->get_id() ); |
|
281 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
280 | + delete_transient('stripe_cards_' . $this->get_id()); |
|
281 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
282 | 282 | $this->customer_data = array(); |
283 | 283 | } |
284 | 284 | } |
@@ -139,6 +139,8 @@ |
||
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Allow this class and other classes to add slug keyed notices (to avoid duplication) |
142 | + * @param string $slug |
|
143 | + * @param string $class |
|
142 | 144 | */ |
143 | 145 | public function add_admin_notice( $slug, $class, $message ) { |
144 | 146 | $this->notices[ $slug ] = array( |
@@ -25,20 +25,20 @@ discard block |
||
25 | 25 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
26 | 26 | */ |
27 | 27 | |
28 | -if ( ! defined( 'ABSPATH' ) ) { |
|
28 | +if ( ! defined('ABSPATH')) { |
|
29 | 29 | exit; |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Required minimums and constants |
34 | 34 | */ |
35 | -define( 'WC_STRIPE_VERSION', '3.0.4' ); |
|
36 | -define( 'WC_STRIPE_MIN_PHP_VER', '5.3.0' ); |
|
37 | -define( 'WC_STRIPE_MIN_WC_VER', '2.5.0' ); |
|
38 | -define( 'WC_STRIPE_MAIN_FILE', __FILE__ ); |
|
39 | -define( 'WC_STRIPE_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); |
|
35 | +define('WC_STRIPE_VERSION', '3.0.4'); |
|
36 | +define('WC_STRIPE_MIN_PHP_VER', '5.3.0'); |
|
37 | +define('WC_STRIPE_MIN_WC_VER', '2.5.0'); |
|
38 | +define('WC_STRIPE_MAIN_FILE', __FILE__); |
|
39 | +define('WC_STRIPE_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)))); |
|
40 | 40 | |
41 | -if ( ! class_exists( 'WC_Stripe' ) ) { |
|
41 | +if ( ! class_exists('WC_Stripe')) { |
|
42 | 42 | |
43 | 43 | class WC_Stripe { |
44 | 44 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @return Singleton The *Singleton* instance. |
59 | 59 | */ |
60 | 60 | public static function get_instance() { |
61 | - if ( null === self::$instance ) { |
|
61 | + if (null === self::$instance) { |
|
62 | 62 | self::$instance = new self(); |
63 | 63 | } |
64 | 64 | return self::$instance; |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | * *Singleton* via the `new` operator from outside of this class. |
108 | 108 | */ |
109 | 109 | protected function __construct() { |
110 | - add_action( 'admin_init', array( $this, 'check_environment' ) ); |
|
111 | - add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); |
|
112 | - add_action( 'plugins_loaded', array( $this, 'init' ) ); |
|
110 | + add_action('admin_init', array($this, 'check_environment')); |
|
111 | + add_action('admin_notices', array($this, 'admin_notices'), 15); |
|
112 | + add_action('plugins_loaded', array($this, 'init')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,31 +117,31 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function init() { |
119 | 119 | // Don't hook anything else in the plugin if we're in an incompatible environment |
120 | - if ( self::get_environment_warning() ) { |
|
120 | + if (self::get_environment_warning()) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | - include_once( plugin_basename( 'includes/class-wc-stripe-api.php' ) ); |
|
125 | - include_once( plugin_basename( 'includes/class-wc-stripe-customer.php' ) ); |
|
124 | + include_once(plugin_basename('includes/class-wc-stripe-api.php')); |
|
125 | + include_once(plugin_basename('includes/class-wc-stripe-customer.php')); |
|
126 | 126 | |
127 | 127 | // Init the gateway itself |
128 | 128 | $this->init_gateways(); |
129 | 129 | |
130 | - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); |
|
131 | - add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) ); |
|
132 | - add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) ); |
|
133 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) ); |
|
134 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) ); |
|
135 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
136 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
137 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
130 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); |
|
131 | + add_action('woocommerce_order_status_on-hold_to_processing', array($this, 'capture_payment')); |
|
132 | + add_action('woocommerce_order_status_on-hold_to_completed', array($this, 'capture_payment')); |
|
133 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'cancel_payment')); |
|
134 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'cancel_payment')); |
|
135 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
136 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
137 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Allow this class and other classes to add slug keyed notices (to avoid duplication) |
142 | 142 | */ |
143 | - public function add_admin_notice( $slug, $class, $message ) { |
|
144 | - $this->notices[ $slug ] = array( |
|
143 | + public function add_admin_notice($slug, $class, $message) { |
|
144 | + $this->notices[$slug] = array( |
|
145 | 145 | 'class' => $class, |
146 | 146 | 'message' => $message |
147 | 147 | ); |
@@ -154,21 +154,21 @@ discard block |
||
154 | 154 | public function check_environment() { |
155 | 155 | $environment_warning = self::get_environment_warning(); |
156 | 156 | |
157 | - if ( $environment_warning && is_plugin_active( plugin_basename( __FILE__ ) ) ) { |
|
158 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
157 | + if ($environment_warning && is_plugin_active(plugin_basename(__FILE__))) { |
|
158 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | // Check if secret key present. Otherwise prompt, via notice, to go to |
162 | 162 | // setting. |
163 | - if ( ! class_exists( 'WC_Stripe_API' ) ) { |
|
164 | - include_once( plugin_basename( 'includes/class-wc-stripe-api.php' ) ); |
|
163 | + if ( ! class_exists('WC_Stripe_API')) { |
|
164 | + include_once(plugin_basename('includes/class-wc-stripe-api.php')); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | $secret = WC_Stripe_API::get_secret_key(); |
168 | 168 | |
169 | - if ( empty( $secret ) && ! ( isset( $_GET['page'], $_GET['section'] ) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'] ) ) { |
|
169 | + if (empty($secret) && ! (isset($_GET['page'], $_GET['section']) && 'wc-settings' === $_GET['page'] && 'stripe' === $_GET['section'])) { |
|
170 | 170 | $setting_link = $this->get_setting_link(); |
171 | - $this->add_admin_notice( 'prompt_connect', 'notice notice-warning', sprintf( __( 'Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe' ), $setting_link ) ); |
|
171 | + $this->add_admin_notice('prompt_connect', 'notice notice-warning', sprintf(__('Stripe is almost ready. To get started, <a href="%s">set your Stripe account keys</a>.', 'woocommerce-gateway-stripe'), $setting_link)); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
@@ -177,24 +177,24 @@ discard block |
||
177 | 177 | * found or false if the environment has no problems. |
178 | 178 | */ |
179 | 179 | static function get_environment_warning() { |
180 | - if ( version_compare( phpversion(), WC_STRIPE_MIN_PHP_VER, '<' ) ) { |
|
181 | - $message = __( 'WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe' ); |
|
180 | + if (version_compare(phpversion(), WC_STRIPE_MIN_PHP_VER, '<')) { |
|
181 | + $message = __('WooCommerce Stripe - The minimum PHP version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe'); |
|
182 | 182 | |
183 | - return sprintf( $message, WC_STRIPE_MIN_PHP_VER, phpversion() ); |
|
183 | + return sprintf($message, WC_STRIPE_MIN_PHP_VER, phpversion()); |
|
184 | 184 | } |
185 | 185 | |
186 | - if ( ! defined( 'WC_VERSION' ) ) { |
|
187 | - return __( 'WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe' ); |
|
186 | + if ( ! defined('WC_VERSION')) { |
|
187 | + return __('WooCommerce Stripe requires WooCommerce to be activated to work.', 'woocommerce-gateway-stripe'); |
|
188 | 188 | } |
189 | 189 | |
190 | - if ( version_compare( WC_VERSION, WC_STRIPE_MIN_WC_VER, '<' ) ) { |
|
191 | - $message = __( 'WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe' ); |
|
190 | + if (version_compare(WC_VERSION, WC_STRIPE_MIN_WC_VER, '<')) { |
|
191 | + $message = __('WooCommerce Stripe - The minimum WooCommerce version required for this plugin is %1$s. You are running %2$s.', 'woocommerce-gateway-stripe', 'woocommerce-gateway-stripe'); |
|
192 | 192 | |
193 | - return sprintf( $message, WC_STRIPE_MIN_WC_VER, WC_VERSION ); |
|
193 | + return sprintf($message, WC_STRIPE_MIN_WC_VER, WC_VERSION); |
|
194 | 194 | } |
195 | 195 | |
196 | - if ( ! function_exists( 'curl_init' ) ) { |
|
197 | - return __( 'WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe' ); |
|
196 | + if ( ! function_exists('curl_init')) { |
|
197 | + return __('WooCommerce Stripe - cURL is not installed.', 'woocommerce-gateway-stripe'); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | return false; |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @since 1.0.0 |
207 | 207 | */ |
208 | - public function plugin_action_links( $links ) { |
|
208 | + public function plugin_action_links($links) { |
|
209 | 209 | $setting_link = $this->get_setting_link(); |
210 | 210 | |
211 | 211 | $plugin_links = array( |
212 | - '<a href="' . $setting_link . '">' . __( 'Settings', 'woocommerce-gateway-stripe' ) . '</a>', |
|
213 | - '<a href="https://docs.woothemes.com/document/stripe/">' . __( 'Docs', 'woocommerce-gateway-stripe' ) . '</a>', |
|
214 | - '<a href="http://support.woothemes.com/">' . __( 'Support', 'woocommerce-gateway-stripe' ) . '</a>', |
|
212 | + '<a href="' . $setting_link . '">' . __('Settings', 'woocommerce-gateway-stripe') . '</a>', |
|
213 | + '<a href="https://docs.woothemes.com/document/stripe/">' . __('Docs', 'woocommerce-gateway-stripe') . '</a>', |
|
214 | + '<a href="http://support.woothemes.com/">' . __('Support', 'woocommerce-gateway-stripe') . '</a>', |
|
215 | 215 | ); |
216 | - return array_merge( $plugin_links, $links ); |
|
216 | + return array_merge($plugin_links, $links); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -224,20 +224,20 @@ discard block |
||
224 | 224 | * @return string Setting link |
225 | 225 | */ |
226 | 226 | public function get_setting_link() { |
227 | - $use_id_as_section = version_compare( WC()->version, '2.6', '>=' ); |
|
227 | + $use_id_as_section = version_compare(WC()->version, '2.6', '>='); |
|
228 | 228 | |
229 | - $section_slug = $use_id_as_section ? 'stripe' : strtolower( 'WC_Gateway_Stripe' ); |
|
229 | + $section_slug = $use_id_as_section ? 'stripe' : strtolower('WC_Gateway_Stripe'); |
|
230 | 230 | |
231 | - return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug ); |
|
231 | + return admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $section_slug); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
235 | 235 | * Display any notices we've collected thus far (e.g. for connection, disconnection) |
236 | 236 | */ |
237 | 237 | public function admin_notices() { |
238 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
239 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
240 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
238 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
239 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
240 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
241 | 241 | echo "</p></div>"; |
242 | 242 | } |
243 | 243 | } |
@@ -248,27 +248,27 @@ discard block |
||
248 | 248 | * @since 1.0.0 |
249 | 249 | */ |
250 | 250 | public function init_gateways() { |
251 | - if ( class_exists( 'WC_Subscriptions_Order' ) && function_exists( 'wcs_create_renewal_order' ) ) { |
|
251 | + if (class_exists('WC_Subscriptions_Order') && function_exists('wcs_create_renewal_order')) { |
|
252 | 252 | $this->subscription_support_enabled = true; |
253 | 253 | } |
254 | 254 | |
255 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
255 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
256 | 256 | $this->pre_order_enabled = true; |
257 | 257 | } |
258 | 258 | |
259 | - if ( ! class_exists( 'WC_Payment_Gateway' ) ) { |
|
259 | + if ( ! class_exists('WC_Payment_Gateway')) { |
|
260 | 260 | return; |
261 | 261 | } |
262 | 262 | |
263 | - if ( class_exists( 'WC_Payment_Gateway_CC' ) ) { |
|
264 | - include_once( plugin_basename( 'includes/class-wc-gateway-stripe.php' ) ); |
|
263 | + if (class_exists('WC_Payment_Gateway_CC')) { |
|
264 | + include_once(plugin_basename('includes/class-wc-gateway-stripe.php')); |
|
265 | 265 | } else { |
266 | - include_once( plugin_basename( 'includes/legacy/class-wc-gateway-stripe.php' ) ); |
|
267 | - include_once( plugin_basename( 'includes/legacy/class-wc-gateway-stripe-saved-cards.php' ) ); |
|
266 | + include_once(plugin_basename('includes/legacy/class-wc-gateway-stripe.php')); |
|
267 | + include_once(plugin_basename('includes/legacy/class-wc-gateway-stripe-saved-cards.php')); |
|
268 | 268 | } |
269 | 269 | |
270 | - load_plugin_textdomain( 'woocommerce-gateway-stripe', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); |
|
271 | - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateways' ) ); |
|
270 | + load_plugin_textdomain('woocommerce-gateway-stripe', false, plugin_basename(dirname(__FILE__)) . '/languages'); |
|
271 | + add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); |
|
272 | 272 | |
273 | 273 | $load_addons = ( |
274 | 274 | $this->subscription_support_enabled |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | $this->pre_order_enabled |
277 | 277 | ); |
278 | 278 | |
279 | - if ( $load_addons ) { |
|
280 | - require_once( plugin_basename( 'includes/class-wc-gateway-stripe-addons.php' ) ); |
|
279 | + if ($load_addons) { |
|
280 | + require_once(plugin_basename('includes/class-wc-gateway-stripe-addons.php')); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @since 1.0.0 |
288 | 288 | */ |
289 | - public function add_gateways( $methods ) { |
|
290 | - if ( $this->subscription_support_enabled || $this->pre_order_enabled ) { |
|
289 | + public function add_gateways($methods) { |
|
290 | + if ($this->subscription_support_enabled || $this->pre_order_enabled) { |
|
291 | 291 | $methods[] = 'WC_Gateway_Stripe_Addons'; |
292 | 292 | } else { |
293 | 293 | $methods[] = 'WC_Gateway_Stripe'; |
@@ -300,31 +300,31 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @param int $order_id |
302 | 302 | */ |
303 | - public function capture_payment( $order_id ) { |
|
304 | - $order = wc_get_order( $order_id ); |
|
303 | + public function capture_payment($order_id) { |
|
304 | + $order = wc_get_order($order_id); |
|
305 | 305 | |
306 | - if ( 'stripe' === $order->payment_method ) { |
|
307 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
308 | - $captured = get_post_meta( $order_id, '_stripe_charge_captured', true ); |
|
306 | + if ('stripe' === $order->payment_method) { |
|
307 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
308 | + $captured = get_post_meta($order_id, '_stripe_charge_captured', true); |
|
309 | 309 | |
310 | - if ( $charge && 'no' === $captured ) { |
|
311 | - $result = WC_Stripe_API::request( array( |
|
310 | + if ($charge && 'no' === $captured) { |
|
311 | + $result = WC_Stripe_API::request(array( |
|
312 | 312 | 'amount' => $order->get_total() * 100, |
313 | 313 | 'expand[]' => 'balance_transaction' |
314 | - ), 'charges/' . $charge . '/capture' ); |
|
314 | + ), 'charges/' . $charge . '/capture'); |
|
315 | 315 | |
316 | - if ( is_wp_error( $result ) ) { |
|
317 | - $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
316 | + if (is_wp_error($result)) { |
|
317 | + $order->add_order_note(__('Unable to capture charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
318 | 318 | } else { |
319 | - $order->add_order_note( sprintf( __( 'Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
320 | - update_post_meta( $order->id, '_stripe_charge_captured', 'yes' ); |
|
319 | + $order->add_order_note(sprintf(__('Stripe charge complete (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
320 | + update_post_meta($order->id, '_stripe_charge_captured', 'yes'); |
|
321 | 321 | |
322 | 322 | // Store other data such as fees |
323 | - update_post_meta( $order->id, 'Stripe Payment ID', $result->id ); |
|
323 | + update_post_meta($order->id, 'Stripe Payment ID', $result->id); |
|
324 | 324 | |
325 | - if ( isset( $result->balance_transaction ) && isset( $result->balance_transaction->fee ) ) { |
|
326 | - update_post_meta( $order->id, 'Stripe Fee', number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) ); |
|
327 | - update_post_meta( $order->id, 'Net Revenue From Stripe', ( $order->order_total - number_format( $result->balance_transaction->fee / 100, 2, '.', '' ) ) ); |
|
325 | + if (isset($result->balance_transaction) && isset($result->balance_transaction->fee)) { |
|
326 | + update_post_meta($order->id, 'Stripe Fee', number_format($result->balance_transaction->fee / 100, 2, '.', '')); |
|
327 | + update_post_meta($order->id, 'Net Revenue From Stripe', ($order->order_total - number_format($result->balance_transaction->fee / 100, 2, '.', ''))); |
|
328 | 328 | } |
329 | 329 | } |
330 | 330 | } |
@@ -336,23 +336,23 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @param int $order_id |
338 | 338 | */ |
339 | - public function cancel_payment( $order_id ) { |
|
340 | - $order = wc_get_order( $order_id ); |
|
339 | + public function cancel_payment($order_id) { |
|
340 | + $order = wc_get_order($order_id); |
|
341 | 341 | |
342 | - if ( 'stripe' === $order->payment_method ) { |
|
343 | - $charge = get_post_meta( $order_id, '_stripe_charge_id', true ); |
|
342 | + if ('stripe' === $order->payment_method) { |
|
343 | + $charge = get_post_meta($order_id, '_stripe_charge_id', true); |
|
344 | 344 | |
345 | - if ( $charge ) { |
|
346 | - $result = WC_Stripe_API::request( array( |
|
345 | + if ($charge) { |
|
346 | + $result = WC_Stripe_API::request(array( |
|
347 | 347 | 'amount' => $order->get_total() * 100, |
348 | - ), 'charges/' . $charge . '/refund' ); |
|
348 | + ), 'charges/' . $charge . '/refund'); |
|
349 | 349 | |
350 | - if ( is_wp_error( $result ) ) { |
|
351 | - $order->add_order_note( __( 'Unable to refund charge!', 'woocommerce-gateway-stripe' ) . ' ' . $result->get_error_message() ); |
|
350 | + if (is_wp_error($result)) { |
|
351 | + $order->add_order_note(__('Unable to refund charge!', 'woocommerce-gateway-stripe') . ' ' . $result->get_error_message()); |
|
352 | 352 | } else { |
353 | - $order->add_order_note( sprintf( __( 'Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe' ), $result->id ) ); |
|
354 | - delete_post_meta( $order->id, '_stripe_charge_captured' ); |
|
355 | - delete_post_meta( $order->id, '_stripe_charge_id' ); |
|
353 | + $order->add_order_note(sprintf(__('Stripe charge refunded (Charge ID: %s)', 'woocommerce-gateway-stripe'), $result->id)); |
|
354 | + delete_post_meta($order->id, '_stripe_charge_captured'); |
|
355 | + delete_post_meta($order->id, '_stripe_charge_id'); |
|
356 | 356 | } |
357 | 357 | } |
358 | 358 | } |
@@ -363,28 +363,28 @@ discard block |
||
363 | 363 | * @param array $tokens |
364 | 364 | * @return array |
365 | 365 | */ |
366 | - public function woocommerce_get_customer_payment_tokens( $tokens, $customer_id, $gateway_id ) { |
|
367 | - if ( is_user_logged_in() && 'stripe' === $gateway_id && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
368 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
366 | + public function woocommerce_get_customer_payment_tokens($tokens, $customer_id, $gateway_id) { |
|
367 | + if (is_user_logged_in() && 'stripe' === $gateway_id && class_exists('WC_Payment_Token_CC')) { |
|
368 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
369 | 369 | $stripe_cards = $stripe_customer->get_cards(); |
370 | 370 | $stored_tokens = array(); |
371 | 371 | |
372 | - foreach ( $tokens as $token ) { |
|
372 | + foreach ($tokens as $token) { |
|
373 | 373 | $stored_tokens[] = $token->get_token(); |
374 | 374 | } |
375 | 375 | |
376 | - foreach ( $stripe_cards as $card ) { |
|
377 | - if ( ! in_array( $card->id, $stored_tokens ) ) { |
|
376 | + foreach ($stripe_cards as $card) { |
|
377 | + if ( ! in_array($card->id, $stored_tokens)) { |
|
378 | 378 | $token = new WC_Payment_Token_CC(); |
379 | - $token->set_token( $card->id ); |
|
380 | - $token->set_gateway_id( 'stripe' ); |
|
381 | - $token->set_card_type( strtolower( $card->brand ) ); |
|
382 | - $token->set_last4( $card->last4 ); |
|
383 | - $token->set_expiry_month( $card->exp_month ); |
|
384 | - $token->set_expiry_year( $card->exp_year ); |
|
385 | - $token->set_user_id( $customer_id ); |
|
379 | + $token->set_token($card->id); |
|
380 | + $token->set_gateway_id('stripe'); |
|
381 | + $token->set_card_type(strtolower($card->brand)); |
|
382 | + $token->set_last4($card->last4); |
|
383 | + $token->set_expiry_month($card->exp_month); |
|
384 | + $token->set_expiry_year($card->exp_year); |
|
385 | + $token->set_user_id($customer_id); |
|
386 | 386 | $token->save(); |
387 | - $tokens[ $token->get_id() ] = $token; |
|
387 | + $tokens[$token->get_id()] = $token; |
|
388 | 388 | } |
389 | 389 | } |
390 | 390 | } |
@@ -394,21 +394,21 @@ discard block |
||
394 | 394 | /** |
395 | 395 | * Delete token from Stripe |
396 | 396 | */ |
397 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
398 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
399 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
400 | - $stripe_customer->delete_card( $token->get_token() ); |
|
397 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
398 | + if ('stripe' === $token->get_gateway_id()) { |
|
399 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
400 | + $stripe_customer->delete_card($token->get_token()); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
405 | 405 | * Set as default in Stripe |
406 | 406 | */ |
407 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
408 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
409 | - if ( 'stripe' === $token->get_gateway_id() ) { |
|
410 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
411 | - $stripe_customer->set_default_card( $token->get_token() ); |
|
407 | + public function woocommerce_payment_token_set_default($token_id) { |
|
408 | + $token = WC_Payment_Tokens::get($token_id); |
|
409 | + if ('stripe' === $token->get_gateway_id()) { |
|
410 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
411 | + $stripe_customer->set_default_card($token->get_token()); |
|
412 | 412 | } |
413 | 413 | } |
414 | 414 | |
@@ -420,15 +420,15 @@ discard block |
||
420 | 420 | * And fits on your back? |
421 | 421 | * It's log, log, log |
422 | 422 | */ |
423 | - public static function log( $message ) { |
|
424 | - if ( empty( self::$log ) ) { |
|
423 | + public static function log($message) { |
|
424 | + if (empty(self::$log)) { |
|
425 | 425 | self::$log = new WC_Logger(); |
426 | 426 | } |
427 | 427 | |
428 | - self::$log->add( 'woocommerce-gateway-stripe', $message ); |
|
428 | + self::$log->add('woocommerce-gateway-stripe', $message); |
|
429 | 429 | |
430 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
431 | - error_log( $message ); |
|
430 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
431 | + error_log($message); |
|
432 | 432 | } |
433 | 433 | } |
434 | 434 | } |
@@ -1,130 +1,130 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | -return apply_filters( 'wc_stripe_settings', |
|
6 | +return apply_filters('wc_stripe_settings', |
|
7 | 7 | array( |
8 | 8 | 'enabled' => array( |
9 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
10 | - 'label' => __( 'Enable Stripe', 'woocommerce-gateway-stripe' ), |
|
9 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
10 | + 'label' => __('Enable Stripe', 'woocommerce-gateway-stripe'), |
|
11 | 11 | 'type' => 'checkbox', |
12 | 12 | 'description' => '', |
13 | 13 | 'default' => 'no' |
14 | 14 | ), |
15 | 15 | 'title' => array( |
16 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
16 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
17 | 17 | 'type' => 'text', |
18 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
19 | - 'default' => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ), |
|
18 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
19 | + 'default' => __('Credit Card (Stripe)', 'woocommerce-gateway-stripe'), |
|
20 | 20 | 'desc_tip' => true, |
21 | 21 | ), |
22 | 22 | 'description' => array( |
23 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
23 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
24 | 24 | 'type' => 'text', |
25 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
26 | - 'default' => __( 'Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'), |
|
25 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
26 | + 'default' => __('Pay with your credit card via Stripe.', 'woocommerce-gateway-stripe'), |
|
27 | 27 | 'desc_tip' => true, |
28 | 28 | ), |
29 | 29 | 'testmode' => array( |
30 | - 'title' => __( 'Test mode', 'woocommerce-gateway-stripe' ), |
|
31 | - 'label' => __( 'Enable Test Mode', 'woocommerce-gateway-stripe' ), |
|
30 | + 'title' => __('Test mode', 'woocommerce-gateway-stripe'), |
|
31 | + 'label' => __('Enable Test Mode', 'woocommerce-gateway-stripe'), |
|
32 | 32 | 'type' => 'checkbox', |
33 | - 'description' => __( 'Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe' ), |
|
33 | + 'description' => __('Place the payment gateway in test mode using test API keys.', 'woocommerce-gateway-stripe'), |
|
34 | 34 | 'default' => 'yes', |
35 | 35 | 'desc_tip' => true, |
36 | 36 | ), |
37 | 37 | 'secret_key' => array( |
38 | - 'title' => __( 'Live Secret Key', 'woocommerce-gateway-stripe' ), |
|
38 | + 'title' => __('Live Secret Key', 'woocommerce-gateway-stripe'), |
|
39 | 39 | 'type' => 'text', |
40 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
40 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
41 | 41 | 'default' => '', |
42 | 42 | 'desc_tip' => true, |
43 | 43 | ), |
44 | 44 | 'publishable_key' => array( |
45 | - 'title' => __( 'Live Publishable Key', 'woocommerce-gateway-stripe' ), |
|
45 | + 'title' => __('Live Publishable Key', 'woocommerce-gateway-stripe'), |
|
46 | 46 | 'type' => 'text', |
47 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
47 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
48 | 48 | 'default' => '', |
49 | 49 | 'desc_tip' => true, |
50 | 50 | ), |
51 | 51 | 'test_secret_key' => array( |
52 | - 'title' => __( 'Test Secret Key', 'woocommerce-gateway-stripe' ), |
|
52 | + 'title' => __('Test Secret Key', 'woocommerce-gateway-stripe'), |
|
53 | 53 | 'type' => 'text', |
54 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
54 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
55 | 55 | 'default' => '', |
56 | 56 | 'desc_tip' => true, |
57 | 57 | ), |
58 | 58 | 'test_publishable_key' => array( |
59 | - 'title' => __( 'Test Publishable Key', 'woocommerce-gateway-stripe' ), |
|
59 | + 'title' => __('Test Publishable Key', 'woocommerce-gateway-stripe'), |
|
60 | 60 | 'type' => 'text', |
61 | - 'description' => __( 'Get your API keys from your stripe account.', 'woocommerce-gateway-stripe' ), |
|
61 | + 'description' => __('Get your API keys from your stripe account.', 'woocommerce-gateway-stripe'), |
|
62 | 62 | 'default' => '', |
63 | 63 | 'desc_tip' => true, |
64 | 64 | ), |
65 | 65 | 'capture' => array( |
66 | - 'title' => __( 'Capture', 'woocommerce-gateway-stripe' ), |
|
67 | - 'label' => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ), |
|
66 | + 'title' => __('Capture', 'woocommerce-gateway-stripe'), |
|
67 | + 'label' => __('Capture charge immediately', 'woocommerce-gateway-stripe'), |
|
68 | 68 | 'type' => 'checkbox', |
69 | - 'description' => __( 'Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe' ), |
|
69 | + 'description' => __('Whether or not to immediately capture the charge. When unchecked, the charge issues an authorization and will need to be captured later. Uncaptured charges expire in 7 days.', 'woocommerce-gateway-stripe'), |
|
70 | 70 | 'default' => 'yes', |
71 | 71 | 'desc_tip' => true, |
72 | 72 | ), |
73 | 73 | 'stripe_checkout' => array( |
74 | - 'title' => __( 'Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
75 | - 'label' => __( 'Enable Stripe Checkout', 'woocommerce-gateway-stripe' ), |
|
74 | + 'title' => __('Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
75 | + 'label' => __('Enable Stripe Checkout', 'woocommerce-gateway-stripe'), |
|
76 | 76 | 'type' => 'checkbox', |
77 | - 'description' => __( 'If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe' ), |
|
77 | + 'description' => __('If enabled, this option shows a "pay" button and modal credit card form on the checkout, instead of credit card fields directly on the page.', 'woocommerce-gateway-stripe'), |
|
78 | 78 | 'default' => 'no', |
79 | 79 | 'desc_tip' => true, |
80 | 80 | ), |
81 | 81 | 'stripe_checkout_locale' => array( |
82 | - 'title' => __( 'Stripe Checkout locale', 'woocommerce-gateway-stripe' ), |
|
82 | + 'title' => __('Stripe Checkout locale', 'woocommerce-gateway-stripe'), |
|
83 | 83 | 'type' => 'select', |
84 | 84 | 'class' => 'wc-enhanced-select', |
85 | - 'description' => __( 'Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe' ), |
|
85 | + 'description' => __('Language to display in Stripe Checkout modal. Specify Auto to display Checkout in the user\'s preferred language, if available. English will be used by default.', 'woocommerce-gateway-stripe'), |
|
86 | 86 | 'default' => 'en', |
87 | 87 | 'desc_tip' => true, |
88 | 88 | 'options' => array( |
89 | - 'auto' => __( 'Auto', 'woocommerce-gateway-stripe' ), |
|
90 | - 'zh' => __( 'Simplified Chinese', 'woocommerce-gateway-stripe' ), |
|
91 | - 'nl' => __( 'Dutch', 'woocommerce-gateway-stripe' ), |
|
92 | - 'en' => __( 'English', 'woocommerce-gateway-stripe' ), |
|
93 | - 'fr' => __( 'French', 'woocommerce-gateway-stripe' ), |
|
94 | - 'de' => __( 'German', 'woocommerce-gateway-stripe' ), |
|
95 | - 'it' => __( 'Italian', 'woocommerce-gateway-stripe' ), |
|
96 | - 'ja' => __( 'Japanese', 'woocommerce-gateway-stripe' ), |
|
97 | - 'es' => __( 'Spanish', 'woocommerce-gateway-stripe' ), |
|
89 | + 'auto' => __('Auto', 'woocommerce-gateway-stripe'), |
|
90 | + 'zh' => __('Simplified Chinese', 'woocommerce-gateway-stripe'), |
|
91 | + 'nl' => __('Dutch', 'woocommerce-gateway-stripe'), |
|
92 | + 'en' => __('English', 'woocommerce-gateway-stripe'), |
|
93 | + 'fr' => __('French', 'woocommerce-gateway-stripe'), |
|
94 | + 'de' => __('German', 'woocommerce-gateway-stripe'), |
|
95 | + 'it' => __('Italian', 'woocommerce-gateway-stripe'), |
|
96 | + 'ja' => __('Japanese', 'woocommerce-gateway-stripe'), |
|
97 | + 'es' => __('Spanish', 'woocommerce-gateway-stripe'), |
|
98 | 98 | ), |
99 | 99 | ), |
100 | 100 | 'stripe_bitcoin' => array( |
101 | - 'title' => __( 'Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
102 | - 'label' => __( 'Enable Bitcoin Currency', 'woocommerce-gateway-stripe' ), |
|
101 | + 'title' => __('Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
102 | + 'label' => __('Enable Bitcoin Currency', 'woocommerce-gateway-stripe'), |
|
103 | 103 | 'type' => 'checkbox', |
104 | - 'description' => __( 'If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe' ), |
|
104 | + 'description' => __('If enabled, an option to accept bitcoin will show on the checkout modal. Note: Stripe Checkout needs to be enabled and store currency must be set to USD.', 'woocommerce-gateway-stripe'), |
|
105 | 105 | 'default' => 'no', |
106 | 106 | 'desc_tip' => true, |
107 | 107 | ), |
108 | 108 | 'stripe_checkout_image' => array( |
109 | - 'title' => __( 'Stripe Checkout Image', 'woocommerce-gateway-stripe' ), |
|
110 | - 'description' => __( 'Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe' ), |
|
109 | + 'title' => __('Stripe Checkout Image', 'woocommerce-gateway-stripe'), |
|
110 | + 'description' => __('Optionally enter the URL to a 128x128px image of your brand or product. e.g. <code>https://yoursite.com/wp-content/uploads/2013/09/yourimage.jpg</code>', 'woocommerce-gateway-stripe'), |
|
111 | 111 | 'type' => 'text', |
112 | 112 | 'default' => '', |
113 | 113 | 'desc_tip' => true, |
114 | 114 | ), |
115 | 115 | 'saved_cards' => array( |
116 | - 'title' => __( 'Saved Cards', 'woocommerce-gateway-stripe' ), |
|
117 | - 'label' => __( 'Enable Payment via Saved Cards', 'woocommerce-gateway-stripe' ), |
|
116 | + 'title' => __('Saved Cards', 'woocommerce-gateway-stripe'), |
|
117 | + 'label' => __('Enable Payment via Saved Cards', 'woocommerce-gateway-stripe'), |
|
118 | 118 | 'type' => 'checkbox', |
119 | - 'description' => __( 'If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe' ), |
|
119 | + 'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Stripe servers, not on your store.', 'woocommerce-gateway-stripe'), |
|
120 | 120 | 'default' => 'no', |
121 | 121 | 'desc_tip' => true, |
122 | 122 | ), |
123 | 123 | 'logging' => array( |
124 | - 'title' => __( 'Logging', 'woocommerce-gateway-stripe' ), |
|
125 | - 'label' => __( 'Log debug messages', 'woocommerce-gateway-stripe' ), |
|
124 | + 'title' => __('Logging', 'woocommerce-gateway-stripe'), |
|
125 | + 'label' => __('Log debug messages', 'woocommerce-gateway-stripe'), |
|
126 | 126 | 'type' => 'checkbox', |
127 | - 'description' => __( 'Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe' ), |
|
127 | + 'description' => __('Save debug messages to the WooCommerce System Status log.', 'woocommerce-gateway-stripe'), |
|
128 | 128 | 'default' => 'no', |
129 | 129 | 'desc_tip' => true, |
130 | 130 | ), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -12,25 +12,25 @@ discard block |
||
12 | 12 | * Constructor |
13 | 13 | */ |
14 | 14 | public function __construct() { |
15 | - add_action( 'wp', array( $this, 'delete_card' ) ); |
|
16 | - add_action( 'woocommerce_after_my_account', array( $this, 'output' ) ); |
|
17 | - add_action( 'wp', array( $this, 'default_card' ) ); |
|
15 | + add_action('wp', array($this, 'delete_card')); |
|
16 | + add_action('woocommerce_after_my_account', array($this, 'output')); |
|
17 | + add_action('wp', array($this, 'default_card')); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Display saved cards |
22 | 22 | */ |
23 | 23 | public function output() { |
24 | - if ( ! is_user_logged_in() ) { |
|
24 | + if ( ! is_user_logged_in()) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | 27 | |
28 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
28 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
29 | 29 | $stripe_cards = $stripe_customer->get_cards(); |
30 | 30 | $default_card = $stripe_customer->get_default_card(); |
31 | 31 | |
32 | - if ( $stripe_cards ) { |
|
33 | - wc_get_template( 'saved-cards.php', array( 'cards' => $stripe_cards, 'default_card' => $default_card ), 'woocommerce-gateway-stripe/', untrailingslashit( plugin_dir_path( WC_STRIPE_MAIN_FILE ) ) . '/includes/legacy/templates/' ); |
|
32 | + if ($stripe_cards) { |
|
33 | + wc_get_template('saved-cards.php', array('cards' => $stripe_cards, 'default_card' => $default_card), 'woocommerce-gateway-stripe/', untrailingslashit(plugin_dir_path(WC_STRIPE_MAIN_FILE)) . '/includes/legacy/templates/'); |
|
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | * Delete a card |
39 | 39 | */ |
40 | 40 | public function delete_card() { |
41 | - if ( ! isset( $_POST['stripe_delete_card'] ) || ! is_account_page() ) { |
|
41 | + if ( ! isset($_POST['stripe_delete_card']) || ! is_account_page()) { |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
45 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
46 | 46 | $stripe_customer_id = $stripe_customer->get_id(); |
47 | - $delete_card = sanitize_text_field( $_POST['stripe_delete_card'] ); |
|
47 | + $delete_card = sanitize_text_field($_POST['stripe_delete_card']); |
|
48 | 48 | |
49 | - if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce( $_POST['_wpnonce'], "stripe_del_card" ) ) { |
|
50 | - wp_die( __( 'Unable to make default card, please try again', 'woocommerce-gateway-stripe' ) ); |
|
49 | + if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce($_POST['_wpnonce'], "stripe_del_card")) { |
|
50 | + wp_die(__('Unable to make default card, please try again', 'woocommerce-gateway-stripe')); |
|
51 | 51 | } |
52 | 52 | |
53 | - if ( ! $stripe_customer->delete_card( $delete_card ) ) { |
|
54 | - wc_add_notice( __( 'Unable to delete card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
53 | + if ( ! $stripe_customer->delete_card($delete_card)) { |
|
54 | + wc_add_notice(__('Unable to delete card.', 'woocommerce-gateway-stripe'), 'error'); |
|
55 | 55 | } else { |
56 | - wc_add_notice( __( 'Card deleted.', 'woocommerce-gateway-stripe' ), 'success' ); |
|
56 | + wc_add_notice(__('Card deleted.', 'woocommerce-gateway-stripe'), 'success'); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -61,22 +61,22 @@ discard block |
||
61 | 61 | * Make a card as default method |
62 | 62 | */ |
63 | 63 | public function default_card() { |
64 | - if ( ! isset( $_POST['stripe_default_card'] ) || ! is_account_page() ) { |
|
64 | + if ( ! isset($_POST['stripe_default_card']) || ! is_account_page()) { |
|
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
68 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
68 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
69 | 69 | $stripe_customer_id = $stripe_customer->get_id(); |
70 | - $default_source = sanitize_text_field( $_POST['stripe_default_card'] ); |
|
70 | + $default_source = sanitize_text_field($_POST['stripe_default_card']); |
|
71 | 71 | |
72 | - if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce( $_POST['_wpnonce'], "stripe_default_card" ) ) { |
|
73 | - wp_die( __( 'Unable to make default card, please try again', 'woocommerce-gateway-stripe' ) ); |
|
72 | + if ( ! is_user_logged_in() || ! $stripe_customer_id || ! wp_verify_nonce($_POST['_wpnonce'], "stripe_default_card")) { |
|
73 | + wp_die(__('Unable to make default card, please try again', 'woocommerce-gateway-stripe')); |
|
74 | 74 | } |
75 | 75 | |
76 | - if ( ! $stripe_customer->set_default_card( $default_source ) ) { |
|
77 | - wc_add_notice( __( 'Unable to update default card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
76 | + if ( ! $stripe_customer->set_default_card($default_source)) { |
|
77 | + wc_add_notice(__('Unable to update default card.', 'woocommerce-gateway-stripe'), 'error'); |
|
78 | 78 | } else { |
79 | - wc_add_notice( __( 'Default card updated.', 'woocommerce-gateway-stripe' ), 'success' ); |
|
79 | + wc_add_notice(__('Default card updated.', 'woocommerce-gateway-stripe'), 'success'); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | } |
@@ -1,37 +1,37 @@ |
||
1 | -<h2 id="saved-cards" style="margin-top:40px;"><?php _e( 'Saved cards', 'woocommerce-gateway-stripe' ); ?></h2> |
|
1 | +<h2 id="saved-cards" style="margin-top:40px;"><?php _e('Saved cards', 'woocommerce-gateway-stripe'); ?></h2> |
|
2 | 2 | <table class="shop_table"> |
3 | 3 | <thead> |
4 | 4 | <tr> |
5 | - <th><?php esc_html_e( 'Card', 'woocommerce-gateway-stripe' ); ?></th> |
|
6 | - <th><?php esc_html_e( 'Expires', 'woocommerce-gateway-stripe' ); ?></th> |
|
5 | + <th><?php esc_html_e('Card', 'woocommerce-gateway-stripe'); ?></th> |
|
6 | + <th><?php esc_html_e('Expires', 'woocommerce-gateway-stripe'); ?></th> |
|
7 | 7 | <th></th> |
8 | 8 | </tr> |
9 | 9 | </thead> |
10 | 10 | <tbody> |
11 | - <?php foreach ( $cards as $card ) : |
|
12 | - if ( 'card' !== $card->object ) { |
|
11 | + <?php foreach ($cards as $card) : |
|
12 | + if ('card' !== $card->object) { |
|
13 | 13 | continue; |
14 | 14 | } |
15 | 15 | |
16 | 16 | $is_default_card = $card->id === $default_card ? true : false; |
17 | 17 | ?> |
18 | 18 | <tr> |
19 | - <td><?php printf( __( '%s card ending in %s', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4 ); ?> |
|
20 | - <?php if ( $is_default_card ) echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' ); ?> |
|
19 | + <td><?php printf(__('%s card ending in %s', 'woocommerce-gateway-stripe'), $card->brand, $card->last4); ?> |
|
20 | + <?php if ($is_default_card) echo '<br />' . __('(Default)', 'woocommerce-gateway-stripe'); ?> |
|
21 | 21 | </td> |
22 | - <td><?php printf( __( 'Expires %s/%s', 'woocommerce-gateway-stripe' ), $card->exp_month, $card->exp_year ); ?></td> |
|
22 | + <td><?php printf(__('Expires %s/%s', 'woocommerce-gateway-stripe'), $card->exp_month, $card->exp_year); ?></td> |
|
23 | 23 | <td> |
24 | 24 | <form action="" method="POST"> |
25 | - <?php wp_nonce_field ( 'stripe_del_card' ); ?> |
|
26 | - <input type="hidden" name="stripe_delete_card" value="<?php echo esc_attr( $card->id ); ?>"> |
|
27 | - <input type="submit" class="button" value="<?php esc_attr_e( 'Delete card', 'woocommerce-gateway-stripe' ); ?>"> |
|
25 | + <?php wp_nonce_field('stripe_del_card'); ?> |
|
26 | + <input type="hidden" name="stripe_delete_card" value="<?php echo esc_attr($card->id); ?>"> |
|
27 | + <input type="submit" class="button" value="<?php esc_attr_e('Delete card', 'woocommerce-gateway-stripe'); ?>"> |
|
28 | 28 | </form> |
29 | 29 | |
30 | - <?php if ( ! $is_default_card ) { ?> |
|
30 | + <?php if ( ! $is_default_card) { ?> |
|
31 | 31 | <form action="" method="POST" style="margin-top:10px;"> |
32 | - <?php wp_nonce_field ( 'stripe_default_card' ); ?> |
|
33 | - <input type="hidden" name="stripe_default_card" value="<?php echo esc_attr( $card->id ); ?>"> |
|
34 | - <input type="submit" class="button" value="<?php esc_attr_e( 'Make Default', 'woocommerce-gateway-stripe' ); ?>"> |
|
32 | + <?php wp_nonce_field('stripe_default_card'); ?> |
|
33 | + <input type="hidden" name="stripe_default_card" value="<?php echo esc_attr($card->id); ?>"> |
|
34 | + <input type="submit" class="button" value="<?php esc_attr_e('Make Default', 'woocommerce-gateway-stripe'); ?>"> |
|
35 | 35 | </form> |
36 | 36 | <?php } ?> |
37 | 37 | </td> |
@@ -17,7 +17,10 @@ |
||
17 | 17 | ?> |
18 | 18 | <tr> |
19 | 19 | <td><?php printf( __( '%s card ending in %s', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4 ); ?> |
20 | - <?php if ( $is_default_card ) echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' ); ?> |
|
20 | + <?php if ( $is_default_card ) { |
|
21 | + echo '<br />' . __( '(Default)', 'woocommerce-gateway-stripe' ); |
|
22 | +} |
|
23 | +?> |
|
21 | 24 | </td> |
22 | 25 | <td><?php printf( __( 'Expires %s/%s', 'woocommerce-gateway-stripe' ), $card->exp_month, $card->exp_year ); ?></td> |
23 | 26 | <td> |
@@ -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,8 +15,8 @@ discard block |
||
15 | 15 | */ |
16 | 16 | public function __construct() { |
17 | 17 | $this->id = 'stripe'; |
18 | - $this->method_title = __( 'Stripe', 'woocommerce-gateway-stripe' ); |
|
19 | - $this->method_description = __( 'Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe' ); |
|
18 | + $this->method_title = __('Stripe', 'woocommerce-gateway-stripe'); |
|
19 | + $this->method_description = __('Stripe works by adding credit card fields on the checkout and then sending the details to Stripe for verification.', 'woocommerce-gateway-stripe'); |
|
20 | 20 | $this->has_fields = true; |
21 | 21 | $this->view_transaction_url = 'https://dashboard.stripe.com/payments/%s'; |
22 | 22 | $this->supports = array( |
@@ -42,35 +42,35 @@ discard block |
||
42 | 42 | $this->init_settings(); |
43 | 43 | |
44 | 44 | // Get setting values. |
45 | - $this->title = $this->get_option( 'title' ); |
|
46 | - $this->description = $this->get_option( 'description' ); |
|
47 | - $this->enabled = $this->get_option( 'enabled' ); |
|
48 | - $this->testmode = 'yes' === $this->get_option( 'testmode' ); |
|
49 | - $this->capture = 'yes' === $this->get_option( 'capture', 'yes' ); |
|
50 | - $this->stripe_checkout = 'yes' === $this->get_option( 'stripe_checkout' ); |
|
51 | - $this->stripe_checkout_locale = $this->get_option( 'stripe_checkout_locale' ); |
|
52 | - $this->stripe_checkout_image = $this->get_option( 'stripe_checkout_image', '' ); |
|
53 | - $this->saved_cards = 'yes' === $this->get_option( 'saved_cards' ); |
|
54 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
55 | - $this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' ); |
|
56 | - $this->bitcoin = 'USD' === strtoupper( get_woocommerce_currency() ) && 'yes' === $this->get_option( 'stripe_bitcoin' ); |
|
57 | - $this->logging = 'yes' === $this->get_option( 'logging' ); |
|
58 | - |
|
59 | - if ( $this->stripe_checkout ) { |
|
60 | - $this->order_button_text = __( 'Continue to payment', 'woocommerce-gateway-stripe' ); |
|
45 | + $this->title = $this->get_option('title'); |
|
46 | + $this->description = $this->get_option('description'); |
|
47 | + $this->enabled = $this->get_option('enabled'); |
|
48 | + $this->testmode = 'yes' === $this->get_option('testmode'); |
|
49 | + $this->capture = 'yes' === $this->get_option('capture', 'yes'); |
|
50 | + $this->stripe_checkout = 'yes' === $this->get_option('stripe_checkout'); |
|
51 | + $this->stripe_checkout_locale = $this->get_option('stripe_checkout_locale'); |
|
52 | + $this->stripe_checkout_image = $this->get_option('stripe_checkout_image', ''); |
|
53 | + $this->saved_cards = 'yes' === $this->get_option('saved_cards'); |
|
54 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
55 | + $this->publishable_key = $this->testmode ? $this->get_option('test_publishable_key') : $this->get_option('publishable_key'); |
|
56 | + $this->bitcoin = 'USD' === strtoupper(get_woocommerce_currency()) && 'yes' === $this->get_option('stripe_bitcoin'); |
|
57 | + $this->logging = 'yes' === $this->get_option('logging'); |
|
58 | + |
|
59 | + if ($this->stripe_checkout) { |
|
60 | + $this->order_button_text = __('Continue to payment', 'woocommerce-gateway-stripe'); |
|
61 | 61 | } |
62 | 62 | |
63 | - if ( $this->testmode ) { |
|
64 | - $this->description .= ' ' . sprintf( __( 'TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe' ), 'https://stripe.com/docs/testing' ); |
|
65 | - $this->description = trim( $this->description ); |
|
63 | + if ($this->testmode) { |
|
64 | + $this->description .= ' ' . sprintf(__('TEST MODE ENABLED. In test mode, you can use the card number 4242424242424242 with any CVC and a valid expiration date or check the documentation "<a href="%s">Testing Stripe</a>" for more card numbers.', 'woocommerce-gateway-stripe'), 'https://stripe.com/docs/testing'); |
|
65 | + $this->description = trim($this->description); |
|
66 | 66 | } |
67 | 67 | |
68 | - WC_Stripe_API::set_secret_key( $this->secret_key ); |
|
68 | + WC_Stripe_API::set_secret_key($this->secret_key); |
|
69 | 69 | |
70 | 70 | // Hooks |
71 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
72 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
73 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
71 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
72 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
73 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -80,35 +80,35 @@ discard block |
||
80 | 80 | * @return string |
81 | 81 | */ |
82 | 82 | public function get_icon() { |
83 | - $ext = version_compare( WC()->version, '2.6', '>=' ) ? '.svg' : '.png'; |
|
84 | - $style = version_compare( WC()->version, '2.6', '>=' ) ? 'style="margin-left: 0.3em"' : ''; |
|
83 | + $ext = version_compare(WC()->version, '2.6', '>=') ? '.svg' : '.png'; |
|
84 | + $style = version_compare(WC()->version, '2.6', '>=') ? 'style="margin-left: 0.3em"' : ''; |
|
85 | 85 | |
86 | - $icon = '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext ) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
87 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext ) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
88 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext ) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
86 | + $icon = '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/visa' . $ext) . '" alt="Visa" width="32" ' . $style . ' />'; |
|
87 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/mastercard' . $ext) . '" alt="Mastercard" width="32" ' . $style . ' />'; |
|
88 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/amex' . $ext) . '" alt="Amex" width="32" ' . $style . ' />'; |
|
89 | 89 | |
90 | - if ( 'USD' === get_woocommerce_currency() ) { |
|
91 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext ) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
92 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext ) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
93 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext ) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
90 | + if ('USD' === get_woocommerce_currency()) { |
|
91 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/discover' . $ext) . '" alt="Discover" width="32" ' . $style . ' />'; |
|
92 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/jcb' . $ext) . '" alt="JCB" width="32" ' . $style . ' />'; |
|
93 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(WC()->plugin_url() . '/assets/images/icons/credit-cards/diners' . $ext) . '" alt="Diners" width="32" ' . $style . ' />'; |
|
94 | 94 | } |
95 | 95 | |
96 | - if ( $this->bitcoin ) { |
|
97 | - $icon .= '<img src="' . WC_HTTPS::force_https_url( plugins_url( '/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE ) ) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
96 | + if ($this->bitcoin) { |
|
97 | + $icon .= '<img src="' . WC_HTTPS::force_https_url(plugins_url('/assets/images/bitcoin' . $ext, WC_STRIPE_MAIN_FILE)) . '" alt="Bitcoin" width="32" ' . $style . ' />'; |
|
98 | 98 | } |
99 | 99 | |
100 | - return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id ); |
|
100 | + return apply_filters('woocommerce_gateway_icon', $icon, $this->id); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Get Stripe amount to pay |
105 | 105 | * @return float |
106 | 106 | */ |
107 | - public function get_stripe_amount( $total, $currency = '' ) { |
|
108 | - if ( ! $currency ) { |
|
107 | + public function get_stripe_amount($total, $currency = '') { |
|
108 | + if ( ! $currency) { |
|
109 | 109 | $currency = get_woocommerce_currency(); |
110 | 110 | } |
111 | - switch ( strtoupper( $currency ) ) { |
|
111 | + switch (strtoupper($currency)) { |
|
112 | 112 | // Zero decimal currencies |
113 | 113 | case 'BIF' : |
114 | 114 | case 'CLP' : |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | case 'XAF' : |
126 | 126 | case 'XOF' : |
127 | 127 | case 'XPF' : |
128 | - $total = absint( $total ); |
|
128 | + $total = absint($total); |
|
129 | 129 | break; |
130 | 130 | default : |
131 | - $total = round( $total, 2 ) * 100; // In cents |
|
131 | + $total = round($total, 2) * 100; // In cents |
|
132 | 132 | break; |
133 | 133 | } |
134 | 134 | return $total; |
@@ -138,31 +138,31 @@ discard block |
||
138 | 138 | * Check if SSL is enabled and notify the user |
139 | 139 | */ |
140 | 140 | public function admin_notices() { |
141 | - if ( $this->enabled == 'no' ) { |
|
141 | + if ($this->enabled == 'no') { |
|
142 | 142 | return; |
143 | 143 | } |
144 | 144 | |
145 | - $addons = ( class_exists( 'WC_Subscriptions_Order' ) || class_exists( 'WC_Pre_Orders_Order' ) ) ? '_addons' : ''; |
|
145 | + $addons = (class_exists('WC_Subscriptions_Order') || class_exists('WC_Pre_Orders_Order')) ? '_addons' : ''; |
|
146 | 146 | |
147 | 147 | // Check required fields |
148 | - if ( ! $this->secret_key ) { |
|
149 | - echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons ) ) . '</p></div>'; |
|
148 | + if ( ! $this->secret_key) { |
|
149 | + echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your secret key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; |
|
150 | 150 | return; |
151 | 151 | |
152 | - } elseif ( ! $this->publishable_key ) { |
|
153 | - echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons ) ) . '</p></div>'; |
|
152 | + } elseif ( ! $this->publishable_key) { |
|
153 | + echo '<div class="error"><p>' . sprintf(__('Stripe error: Please enter your publishable key <a href="%s">here</a>', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; |
|
154 | 154 | return; |
155 | 155 | } |
156 | 156 | |
157 | 157 | // Simple check for duplicate keys |
158 | - if ( $this->secret_key == $this->publishable_key ) { |
|
159 | - echo '<div class="error"><p>' . sprintf( __( 'Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons ) ) . '</p></div>'; |
|
158 | + if ($this->secret_key == $this->publishable_key) { |
|
159 | + echo '<div class="error"><p>' . sprintf(__('Stripe error: Your secret and publishable keys match. Please check and re-enter.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_stripe' . $addons)) . '</p></div>'; |
|
160 | 160 | return; |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Show message if enabled and FORCE SSL is disabled and WordpressHTTPS plugin is not detected |
164 | - if ( ( function_exists( 'wc_site_is_https' ) && ! wc_site_is_https() ) && ( 'no' === get_option( 'woocommerce_force_ssl_checkout' ) && ! class_exists( 'WordPressHTTPS' ) ) ) { |
|
165 | - echo '<div class="error"><p>' . sprintf( __( 'Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout' ) ) . '</p></div>'; |
|
164 | + if ((function_exists('wc_site_is_https') && ! wc_site_is_https()) && ('no' === get_option('woocommerce_force_ssl_checkout') && ! class_exists('WordPressHTTPS'))) { |
|
165 | + echo '<div class="error"><p>' . sprintf(__('Stripe is enabled, but the <a href="%s">force SSL option</a> is disabled; your checkout may not be secure! Please enable SSL and ensure your server has a valid SSL certificate - Stripe will only work in test mode.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout')) . '</p></div>'; |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | * Check if this gateway is enabled |
171 | 171 | */ |
172 | 172 | public function is_available() { |
173 | - if ( 'yes' === $this->enabled ) { |
|
174 | - if ( ! $this->testmode && is_checkout() && ! is_ssl() ) { |
|
173 | + if ('yes' === $this->enabled) { |
|
174 | + if ( ! $this->testmode && is_checkout() && ! is_ssl()) { |
|
175 | 175 | return false; |
176 | 176 | } |
177 | - if ( ! $this->secret_key || ! $this->publishable_key ) { |
|
177 | + if ( ! $this->secret_key || ! $this->publishable_key) { |
|
178 | 178 | return false; |
179 | 179 | } |
180 | 180 | return true; |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | * Initialise Gateway Settings Form Fields |
187 | 187 | */ |
188 | 188 | public function init_form_fields() { |
189 | - $this->form_fields = include( untrailingslashit( plugin_dir_path( WC_STRIPE_MAIN_FILE ) ) . '/includes/settings-stripe.php' ); |
|
189 | + $this->form_fields = include(untrailingslashit(plugin_dir_path(WC_STRIPE_MAIN_FILE)) . '/includes/settings-stripe.php'); |
|
190 | 190 | |
191 | - wc_enqueue_js( " |
|
191 | + wc_enqueue_js(" |
|
192 | 192 | jQuery( function( $ ) { |
193 | 193 | $( '#woocommerce_stripe_stripe_checkout' ).change(function(){ |
194 | 194 | if ( $( this ).is( ':checked' ) ) { |
@@ -208,25 +208,25 @@ discard block |
||
208 | 208 | ?> |
209 | 209 | <fieldset class="stripe-legacy-payment-fields"> |
210 | 210 | <?php |
211 | - if ( $this->description ) { |
|
212 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
211 | + if ($this->description) { |
|
212 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
213 | 213 | } |
214 | - if ( $this->saved_cards && is_user_logged_in() ) { |
|
215 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
214 | + if ($this->saved_cards && is_user_logged_in()) { |
|
215 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
216 | 216 | ?> |
217 | 217 | <p class="form-row form-row-wide"> |
218 | - <a class="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_class', 'button' ); ?>" style="float:right;" href="<?php echo apply_filters( 'wc_stripe_manage_saved_cards_url', get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ); ?>#saved-cards"><?php esc_html_e( 'Manage cards', 'woocommerce-gateway-stripe' ); ?></a> |
|
218 | + <a class="<?php echo apply_filters('wc_stripe_manage_saved_cards_class', 'button'); ?>" style="float:right;" href="<?php echo apply_filters('wc_stripe_manage_saved_cards_url', get_permalink(get_option('woocommerce_myaccount_page_id'))); ?>#saved-cards"><?php esc_html_e('Manage cards', 'woocommerce-gateway-stripe'); ?></a> |
|
219 | 219 | <?php |
220 | - if ( $cards = $stripe_customer->get_cards() ) { |
|
220 | + if ($cards = $stripe_customer->get_cards()) { |
|
221 | 221 | $default_card = $cards[0]->id; |
222 | - foreach ( (array) $cards as $card ) { |
|
223 | - if ( 'card' !== $card->object ) { |
|
222 | + foreach ((array) $cards as $card) { |
|
223 | + if ('card' !== $card->object) { |
|
224 | 224 | continue; |
225 | 225 | } |
226 | 226 | ?> |
227 | - <label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr( strtolower( $card->brand ) ); ?>"> |
|
228 | - <input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked( $default_card, $card->id ) ?> /> |
|
229 | - <?php printf( __( '%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe' ), $card->brand, $card->last4, $card->exp_month, $card->exp_year ); ?> |
|
227 | + <label for="stripe_card_<?php echo $card->id; ?>" class="brand-<?php echo esc_attr(strtolower($card->brand)); ?>"> |
|
228 | + <input type="radio" id="stripe_card_<?php echo $card->id; ?>" name="wc-stripe-payment-token" value="<?php echo $card->id; ?>" <?php checked($default_card, $card->id) ?> /> |
|
229 | + <?php printf(__('%s card ending in %s (Expires %s/%s)', 'woocommerce-gateway-stripe'), $card->brand, $card->last4, $card->exp_month, $card->exp_year); ?> |
|
230 | 230 | </label> |
231 | 231 | <?php |
232 | 232 | } |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | ?> |
235 | 235 | <label for="new"> |
236 | 236 | <input type="radio" id="new" name="wc-stripe-payment-token" value="new" /> |
237 | - <?php _e( 'Use a new credit card', 'woocommerce-gateway-stripe' ); ?> |
|
237 | + <?php _e('Use a new credit card', 'woocommerce-gateway-stripe'); ?> |
|
238 | 238 | </label> |
239 | 239 | </p> |
240 | 240 | <?php |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | |
243 | 243 | $user = wp_get_current_user(); |
244 | 244 | |
245 | - if ( $user ) { |
|
246 | - $user_email = get_user_meta( $user->ID, 'billing_email', true ); |
|
245 | + if ($user) { |
|
246 | + $user_email = get_user_meta($user->ID, 'billing_email', true); |
|
247 | 247 | $user_email = $user_email ? $user_email : $user->user_email; |
248 | 248 | } else { |
249 | 249 | $user_email = ''; |
@@ -251,22 +251,22 @@ discard block |
||
251 | 251 | |
252 | 252 | $display = ''; |
253 | 253 | |
254 | - if ( $this->stripe_checkout || $this->saved_cards && ! empty( $cards ) ) { |
|
254 | + if ($this->stripe_checkout || $this->saved_cards && ! empty($cards)) { |
|
255 | 255 | $display = 'style="display:none;"'; |
256 | 256 | } |
257 | 257 | |
258 | 258 | echo '<div ' . $display . ' id="stripe-payment-data" |
259 | 259 | data-description="" |
260 | - data-email="' . esc_attr( $user_email ) . '" |
|
261 | - data-amount="' . esc_attr( $this->get_stripe_amount( WC()->cart->total ) ) . '" |
|
262 | - data-name="' . esc_attr( sprintf( __( '%s', 'woocommerce-gateway-stripe' ), get_bloginfo( 'name', 'display' ) ) ) . '" |
|
263 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '" |
|
264 | - data-image="' . esc_attr( $this->stripe_checkout_image ) . '" |
|
265 | - data-bitcoin="' . esc_attr( $this->bitcoin ? 'true' : 'false' ) . '" |
|
266 | - data-locale="' . esc_attr( $this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en' ) . '">'; |
|
267 | - |
|
268 | - if ( ! $this->stripe_checkout ) { |
|
269 | - $this->credit_card_form( array( 'fields_have_names' => false ) ); |
|
260 | + data-email="' . esc_attr($user_email) . '" |
|
261 | + data-amount="' . esc_attr($this->get_stripe_amount(WC()->cart->total)) . '" |
|
262 | + data-name="' . esc_attr(sprintf(__('%s', 'woocommerce-gateway-stripe'), get_bloginfo('name', 'display'))) . '" |
|
263 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '" |
|
264 | + data-image="' . esc_attr($this->stripe_checkout_image) . '" |
|
265 | + data-bitcoin="' . esc_attr($this->bitcoin ? 'true' : 'false') . '" |
|
266 | + data-locale="' . esc_attr($this->stripe_checkout_locale ? $this->stripe_checkout_locale : 'en') . '">'; |
|
267 | + |
|
268 | + if ( ! $this->stripe_checkout) { |
|
269 | + $this->credit_card_form(array('fields_have_names' => false)); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | echo '</div>'; |
@@ -283,27 +283,27 @@ discard block |
||
283 | 283 | * @access public |
284 | 284 | */ |
285 | 285 | public function payment_scripts() { |
286 | - if ( $this->stripe_checkout ) { |
|
287 | - wp_enqueue_script( 'stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true ); |
|
288 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe_checkout.js', WC_STRIPE_MAIN_FILE ), array( 'stripe' ), WC_STRIPE_VERSION, true ); |
|
286 | + if ($this->stripe_checkout) { |
|
287 | + wp_enqueue_script('stripe', 'https://checkout.stripe.com/v2/checkout.js', '', '2.0', true); |
|
288 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe_checkout.js', WC_STRIPE_MAIN_FILE), array('stripe'), WC_STRIPE_VERSION, true); |
|
289 | 289 | } else { |
290 | - wp_enqueue_script( 'stripe', 'https://js.stripe.com/v2/', '', '1.0', true ); |
|
291 | - wp_enqueue_script( 'woocommerce_stripe', plugins_url( 'assets/js/stripe.js', WC_STRIPE_MAIN_FILE ), array( 'jquery-payment', 'stripe' ), WC_STRIPE_VERSION, true ); |
|
290 | + wp_enqueue_script('stripe', 'https://js.stripe.com/v2/', '', '1.0', true); |
|
291 | + wp_enqueue_script('woocommerce_stripe', plugins_url('assets/js/stripe.js', WC_STRIPE_MAIN_FILE), array('jquery-payment', 'stripe'), WC_STRIPE_VERSION, true); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | $stripe_params = array( |
295 | 295 | 'key' => $this->publishable_key, |
296 | - 'i18n_terms' => __( 'Please accept the terms and conditions first', 'woocommerce-gateway-stripe' ), |
|
297 | - 'i18n_required_fields' => __( 'Please fill in required checkout fields first', 'woocommerce-gateway-stripe' ), |
|
296 | + 'i18n_terms' => __('Please accept the terms and conditions first', 'woocommerce-gateway-stripe'), |
|
297 | + 'i18n_required_fields' => __('Please fill in required checkout fields first', 'woocommerce-gateway-stripe'), |
|
298 | 298 | ); |
299 | 299 | |
300 | 300 | // If we're on the pay page we need to pass stripe.js the address of the order. |
301 | - if ( is_checkout_pay_page() && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) { |
|
302 | - $order_key = urldecode( $_GET['order'] ); |
|
303 | - $order_id = absint( $_GET['order_id'] ); |
|
304 | - $order = wc_get_order( $order_id ); |
|
301 | + if (is_checkout_pay_page() && isset($_GET['order']) && isset($_GET['order_id'])) { |
|
302 | + $order_key = urldecode($_GET['order']); |
|
303 | + $order_id = absint($_GET['order_id']); |
|
304 | + $order = wc_get_order($order_id); |
|
305 | 305 | |
306 | - if ( $order->id === $order_id && $order->order_key === $order_key ) { |
|
306 | + if ($order->id === $order_id && $order->order_key === $order_key) { |
|
307 | 307 | $stripe_params['billing_first_name'] = $order->billing_first_name; |
308 | 308 | $stripe_params['billing_last_name'] = $order->billing_last_name; |
309 | 309 | $stripe_params['billing_address_1'] = $order->billing_address_1; |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | } |
316 | 316 | } |
317 | 317 | |
318 | - wp_localize_script( 'woocommerce_stripe', 'wc_stripe_params', apply_filters( 'wc_stripe_params', $stripe_params ) ); |
|
318 | + wp_localize_script('woocommerce_stripe', 'wc_stripe_params', apply_filters('wc_stripe_params', $stripe_params)); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -324,24 +324,24 @@ discard block |
||
324 | 324 | * @param object $source |
325 | 325 | * @return array() |
326 | 326 | */ |
327 | - protected function generate_payment_request( $order, $source ) { |
|
327 | + protected function generate_payment_request($order, $source) { |
|
328 | 328 | $post_data = array(); |
329 | - $post_data['currency'] = strtolower( $order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency() ); |
|
330 | - $post_data['amount'] = $this->get_stripe_amount( $order->get_total(), $post_data['currency'] ); |
|
331 | - $post_data['description'] = sprintf( __( '%s - Order %s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() ); |
|
329 | + $post_data['currency'] = strtolower($order->get_order_currency() ? $order->get_order_currency() : get_woocommerce_currency()); |
|
330 | + $post_data['amount'] = $this->get_stripe_amount($order->get_total(), $post_data['currency']); |
|
331 | + $post_data['description'] = sprintf(__('%s - Order %s', 'woocommerce-gateway-stripe'), wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES), $order->get_order_number()); |
|
332 | 332 | $post_data['capture'] = $this->capture ? 'true' : 'false'; |
333 | 333 | |
334 | - if ( ! empty( $order->billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) { |
|
334 | + if ( ! empty($order->billing_email) && apply_filters('wc_stripe_send_stripe_receipt', false)) { |
|
335 | 335 | $post_data['receipt_email'] = $order->billing_email; |
336 | 336 | } |
337 | 337 | |
338 | - $post_data['expand[]'] = 'balance_transaction'; |
|
338 | + $post_data['expand[]'] = 'balance_transaction'; |
|
339 | 339 | |
340 | - if ( $source->customer ) { |
|
340 | + if ($source->customer) { |
|
341 | 341 | $post_data['customer'] = $source->customer; |
342 | 342 | } |
343 | 343 | |
344 | - if ( $source->source ) { |
|
344 | + if ($source->source) { |
|
345 | 345 | $post_data['source'] = $source->source; |
346 | 346 | } |
347 | 347 | |
@@ -353,22 +353,22 @@ discard block |
||
353 | 353 | * @param bool $force_customer Should we force customer creation? |
354 | 354 | * @return object |
355 | 355 | */ |
356 | - protected function get_source( $user_id, $force_customer = false ) { |
|
357 | - $stripe_customer = new WC_Stripe_Customer( $user_id ); |
|
356 | + protected function get_source($user_id, $force_customer = false) { |
|
357 | + $stripe_customer = new WC_Stripe_Customer($user_id); |
|
358 | 358 | $stripe_source = false; |
359 | 359 | $token_id = false; |
360 | 360 | |
361 | 361 | // New CC info was entered and we have a new token to process |
362 | - if ( isset( $_POST['stripe_token'] ) ) { |
|
363 | - $stripe_token = wc_clean( $_POST['stripe_token'] ); |
|
364 | - $maybe_saved_card = isset( $_POST['wc-stripe-new-payment-method'] ) && ! empty( $_POST['wc-stripe-new-payment-method'] ); |
|
362 | + if (isset($_POST['stripe_token'])) { |
|
363 | + $stripe_token = wc_clean($_POST['stripe_token']); |
|
364 | + $maybe_saved_card = isset($_POST['wc-stripe-new-payment-method']) && ! empty($_POST['wc-stripe-new-payment-method']); |
|
365 | 365 | |
366 | 366 | // This is true if the user wants to store the card to their account. |
367 | - if ( ( $user_id && $this->saved_cards && $maybe_saved_card ) || $force_customer ) { |
|
368 | - $stripe_source = $stripe_customer->add_card( $stripe_token ); |
|
367 | + if (($user_id && $this->saved_cards && $maybe_saved_card) || $force_customer) { |
|
368 | + $stripe_source = $stripe_customer->add_card($stripe_token); |
|
369 | 369 | |
370 | - if ( is_wp_error( $stripe_source ) ) { |
|
371 | - throw new Exception( $stripe_source->get_error_message() ); |
|
370 | + if (is_wp_error($stripe_source)) { |
|
371 | + throw new Exception($stripe_source->get_error_message()); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | } else { |
@@ -379,8 +379,8 @@ discard block |
||
379 | 379 | } |
380 | 380 | |
381 | 381 | // Use an existing token, and then process the payment |
382 | - elseif ( isset( $_POST['wc-stripe-payment-token'] ) && 'new' !== $_POST['wc-stripe-payment-token'] ) { |
|
383 | - $stripe_source = wc_clean( $_POST['wc-stripe-payment-token'] ); |
|
382 | + elseif (isset($_POST['wc-stripe-payment-token']) && 'new' !== $_POST['wc-stripe-payment-token']) { |
|
383 | + $stripe_source = wc_clean($_POST['wc-stripe-payment-token']); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | return (object) array( |
@@ -401,16 +401,16 @@ discard block |
||
401 | 401 | * @param object $order |
402 | 402 | * @return object |
403 | 403 | */ |
404 | - protected function get_order_source( $order = null ) { |
|
404 | + protected function get_order_source($order = null) { |
|
405 | 405 | $stripe_customer = new WC_Stripe_Customer(); |
406 | 406 | $stripe_source = false; |
407 | 407 | $token_id = false; |
408 | 408 | |
409 | - if ( $order ) { |
|
410 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_customer_id', true ) ) { |
|
411 | - $stripe_customer->set_id( $meta_value ); |
|
409 | + if ($order) { |
|
410 | + if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) { |
|
411 | + $stripe_customer->set_id($meta_value); |
|
412 | 412 | } |
413 | - if ( $meta_value = get_post_meta( $order->id, '_stripe_card_id', true ) ) { |
|
413 | + if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) { |
|
414 | 414 | $stripe_source = $meta_value; |
415 | 415 | } |
416 | 416 | } |
@@ -425,43 +425,43 @@ discard block |
||
425 | 425 | /** |
426 | 426 | * Process the payment |
427 | 427 | */ |
428 | - public function process_payment( $order_id, $retry = true, $force_customer = false ) { |
|
428 | + public function process_payment($order_id, $retry = true, $force_customer = false) { |
|
429 | 429 | try { |
430 | - $order = wc_get_order( $order_id ); |
|
431 | - $source = $this->get_source( get_current_user_id(), $force_customer ); |
|
430 | + $order = wc_get_order($order_id); |
|
431 | + $source = $this->get_source(get_current_user_id(), $force_customer); |
|
432 | 432 | |
433 | - if ( empty( $source->source ) && empty( $source->customer ) ) { |
|
434 | - $error_msg = __( 'Please enter your card details to make a payment.', 'woocommerce-gateway-stripe' ); |
|
435 | - $error_msg .= ' ' . __( 'Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe' ); |
|
436 | - throw new Exception( $error_msg ); |
|
433 | + if (empty($source->source) && empty($source->customer)) { |
|
434 | + $error_msg = __('Please enter your card details to make a payment.', 'woocommerce-gateway-stripe'); |
|
435 | + $error_msg .= ' ' . __('Developers: Please make sure that you are including jQuery and there are no JavaScript errors on the page.', 'woocommerce-gateway-stripe'); |
|
436 | + throw new Exception($error_msg); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | // Store source to order meta |
440 | - $this->save_source( $order, $source ); |
|
440 | + $this->save_source($order, $source); |
|
441 | 441 | |
442 | 442 | // Handle payment |
443 | - if ( $order->get_total() > 0 ) { |
|
443 | + if ($order->get_total() > 0) { |
|
444 | 444 | |
445 | - if ( $order->get_total() * 100 < 50 ) { |
|
446 | - throw new Exception( __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe' ) ); |
|
445 | + if ($order->get_total() * 100 < 50) { |
|
446 | + throw new Exception(__('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-gateway-stripe')); |
|
447 | 447 | } |
448 | 448 | |
449 | - WC_Stripe::log( "Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}" ); |
|
449 | + WC_Stripe::log("Info: Begin processing payment for order $order_id for the amount of {$order->get_total()}"); |
|
450 | 450 | |
451 | 451 | // Make the request |
452 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
452 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
453 | 453 | |
454 | - if ( is_wp_error( $response ) ) { |
|
454 | + if (is_wp_error($response)) { |
|
455 | 455 | // Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without. |
456 | - if ( 'customer' === $response->get_error_code() && $retry ) { |
|
457 | - delete_user_meta( get_current_user_id(), '_stripe_customer_id' ); |
|
458 | - return $this->process_payment( $order_id, false, $force_customer ); |
|
456 | + if ('customer' === $response->get_error_code() && $retry) { |
|
457 | + delete_user_meta(get_current_user_id(), '_stripe_customer_id'); |
|
458 | + return $this->process_payment($order_id, false, $force_customer); |
|
459 | 459 | } |
460 | - throw new Exception( $response->get_error_code() . ': ' . $response->get_error_message() ); |
|
460 | + throw new Exception($response->get_error_code() . ': ' . $response->get_error_message()); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | // Process valid response |
464 | - $this->process_response( $response, $order ); |
|
464 | + $this->process_response($response, $order); |
|
465 | 465 | } else { |
466 | 466 | $order->payment_complete(); |
467 | 467 | } |
@@ -472,13 +472,13 @@ discard block |
||
472 | 472 | // Return thank you page redirect |
473 | 473 | return array( |
474 | 474 | 'result' => 'success', |
475 | - 'redirect' => $this->get_return_url( $order ) |
|
475 | + 'redirect' => $this->get_return_url($order) |
|
476 | 476 | ); |
477 | 477 | |
478 | - } catch ( Exception $e ) { |
|
479 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
480 | - WC()->session->set( 'refresh_totals', true ); |
|
481 | - WC_Stripe::log( sprintf( __( 'Error: %s', 'woocommerce-gateway-stripe' ), $e->getMessage() ) ); |
|
478 | + } catch (Exception $e) { |
|
479 | + wc_add_notice($e->getMessage(), 'error'); |
|
480 | + WC()->session->set('refresh_totals', true); |
|
481 | + WC_Stripe::log(sprintf(__('Error: %s', 'woocommerce-gateway-stripe'), $e->getMessage())); |
|
482 | 482 | return; |
483 | 483 | } |
484 | 484 | } |
@@ -486,45 +486,45 @@ discard block |
||
486 | 486 | /** |
487 | 487 | * Save source to order. |
488 | 488 | */ |
489 | - protected function save_source( $order, $source ) { |
|
489 | + protected function save_source($order, $source) { |
|
490 | 490 | // Store source in the order |
491 | - if ( $source->customer ) { |
|
492 | - update_post_meta( $order->id, '_stripe_customer_id', $source->customer ); |
|
491 | + if ($source->customer) { |
|
492 | + update_post_meta($order->id, '_stripe_customer_id', $source->customer); |
|
493 | 493 | } |
494 | - if ( $source->source ) { |
|
495 | - update_post_meta( $order->id, '_stripe_card_id', $source->source->id ); |
|
494 | + if ($source->source) { |
|
495 | + update_post_meta($order->id, '_stripe_card_id', $source->source->id); |
|
496 | 496 | } |
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
500 | 500 | * Store extra meta data for an order from a Stripe Response. |
501 | 501 | */ |
502 | - public function process_response( $response, $order ) { |
|
503 | - WC_Stripe::log( "Processing response: " . print_r( $response, true ) ); |
|
502 | + public function process_response($response, $order) { |
|
503 | + WC_Stripe::log("Processing response: " . print_r($response, true)); |
|
504 | 504 | |
505 | 505 | // Store charge data |
506 | - update_post_meta( $order->id, '_stripe_charge_id', $response->id ); |
|
507 | - update_post_meta( $order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no' ); |
|
506 | + update_post_meta($order->id, '_stripe_charge_id', $response->id); |
|
507 | + update_post_meta($order->id, '_stripe_charge_captured', $response->captured ? 'yes' : 'no'); |
|
508 | 508 | |
509 | 509 | // Store other data such as fees |
510 | - if ( isset( $response->balance_transaction ) && isset( $response->balance_transaction->fee ) ) { |
|
511 | - $fee = number_format( $response->balance_transaction->fee / 100, 2, '.', '' ); |
|
512 | - update_post_meta( $order->id, 'Stripe Fee', $fee ); |
|
513 | - update_post_meta( $order->id, 'Net Revenue From Stripe', $order->get_total() - $fee ); |
|
510 | + if (isset($response->balance_transaction) && isset($response->balance_transaction->fee)) { |
|
511 | + $fee = number_format($response->balance_transaction->fee / 100, 2, '.', ''); |
|
512 | + update_post_meta($order->id, 'Stripe Fee', $fee); |
|
513 | + update_post_meta($order->id, 'Net Revenue From Stripe', $order->get_total() - $fee); |
|
514 | 514 | } |
515 | 515 | |
516 | - if ( $response->captured ) { |
|
517 | - $order->payment_complete( $response->id ); |
|
518 | - WC_Stripe::log( "Successful charge: $response->id" ); |
|
516 | + if ($response->captured) { |
|
517 | + $order->payment_complete($response->id); |
|
518 | + WC_Stripe::log("Successful charge: $response->id"); |
|
519 | 519 | } else { |
520 | - add_post_meta( $order->id, '_transaction_id', $response->id, true ); |
|
520 | + add_post_meta($order->id, '_transaction_id', $response->id, true); |
|
521 | 521 | |
522 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
522 | + if ($order->has_status(array('pending', 'failed'))) { |
|
523 | 523 | $order->reduce_order_stock(); |
524 | 524 | } |
525 | 525 | |
526 | - $order->update_status( 'on-hold', sprintf( __( 'Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe' ), $response->id ) ); |
|
527 | - WC_Stripe::log( "Successful auth: $response->id" ); |
|
526 | + $order->update_status('on-hold', sprintf(__('Stripe charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-stripe'), $response->id)); |
|
527 | + WC_Stripe::log("Successful auth: $response->id"); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | return $response; |
@@ -536,21 +536,21 @@ discard block |
||
536 | 536 | * @since 3.0.0 |
537 | 537 | */ |
538 | 538 | public function add_payment_method() { |
539 | - if ( empty( $_POST['stripe_token'] ) || ! is_user_logged_in() ) { |
|
540 | - wc_add_notice( __( 'There was a problem adding the card.', 'woocommerce-gateway-stripe' ), 'error' ); |
|
539 | + if (empty($_POST['stripe_token']) || ! is_user_logged_in()) { |
|
540 | + wc_add_notice(__('There was a problem adding the card.', 'woocommerce-gateway-stripe'), 'error'); |
|
541 | 541 | return; |
542 | 542 | } |
543 | 543 | |
544 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
545 | - $result = $stripe_customer->add_card( wc_clean( $_POST['stripe_token'] ) ); |
|
544 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
545 | + $result = $stripe_customer->add_card(wc_clean($_POST['stripe_token'])); |
|
546 | 546 | |
547 | - if ( is_wp_error( $result ) ) { |
|
548 | - throw new Exception( $result->get_error_message() ); |
|
547 | + if (is_wp_error($result)) { |
|
548 | + throw new Exception($result->get_error_message()); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | return array( |
552 | 552 | 'result' => 'success', |
553 | - 'redirect' => wc_get_endpoint_url( 'payment-methods' ), |
|
553 | + 'redirect' => wc_get_endpoint_url('payment-methods'), |
|
554 | 554 | ); |
555 | 555 | } |
556 | 556 | |
@@ -560,36 +560,36 @@ discard block |
||
560 | 560 | * @param float $amount |
561 | 561 | * @return bool |
562 | 562 | */ |
563 | - public function process_refund( $order_id, $amount = null, $reason = '' ) { |
|
564 | - $order = wc_get_order( $order_id ); |
|
563 | + public function process_refund($order_id, $amount = null, $reason = '') { |
|
564 | + $order = wc_get_order($order_id); |
|
565 | 565 | |
566 | - if ( ! $order || ! $order->get_transaction_id() ) { |
|
566 | + if ( ! $order || ! $order->get_transaction_id()) { |
|
567 | 567 | return false; |
568 | 568 | } |
569 | 569 | |
570 | 570 | $body = array(); |
571 | 571 | |
572 | - if ( ! is_null( $amount ) ) { |
|
573 | - $body['amount'] = $this->get_stripe_amount( $amount ); |
|
572 | + if ( ! is_null($amount)) { |
|
573 | + $body['amount'] = $this->get_stripe_amount($amount); |
|
574 | 574 | } |
575 | 575 | |
576 | - if ( $reason ) { |
|
576 | + if ($reason) { |
|
577 | 577 | $body['metadata'] = array( |
578 | 578 | 'reason' => $reason, |
579 | 579 | ); |
580 | 580 | } |
581 | 581 | |
582 | - WC_Stripe::log( "Info: Beginning refund for order $order_id for the amount of {$amount}" ); |
|
582 | + WC_Stripe::log("Info: Beginning refund for order $order_id for the amount of {$amount}"); |
|
583 | 583 | |
584 | - $response = WC_Stripe_API::request( $body, 'charges/' . $order->get_transaction_id() . '/refunds' ); |
|
584 | + $response = WC_Stripe_API::request($body, 'charges/' . $order->get_transaction_id() . '/refunds'); |
|
585 | 585 | |
586 | - if ( is_wp_error( $response ) ) { |
|
587 | - WC_Stripe::log( "Error: " . $response->get_error_message() ); |
|
586 | + if (is_wp_error($response)) { |
|
587 | + WC_Stripe::log("Error: " . $response->get_error_message()); |
|
588 | 588 | return $response; |
589 | - } elseif ( ! empty( $response->id ) ) { |
|
590 | - $refund_message = sprintf( __( 'Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe' ), wc_price( $response->amount / 100 ), $response->id, $reason ); |
|
591 | - $order->add_order_note( $refund_message ); |
|
592 | - WC_Stripe::log( "Success: " . html_entity_decode( strip_tags( $refund_message ) ) ); |
|
589 | + } elseif ( ! empty($response->id)) { |
|
590 | + $refund_message = sprintf(__('Refunded %s - Refund ID: %s - Reason: %s', 'woocommerce-gateway-stripe'), wc_price($response->amount / 100), $response->id, $reason); |
|
591 | + $order->add_order_note($refund_message); |
|
592 | + WC_Stripe::log("Success: " . html_entity_decode(strip_tags($refund_message))); |
|
593 | 593 | return true; |
594 | 594 | } |
595 | 595 | } |