@@ -134,7 +134,6 @@ discard block |
||
134 | 134 | * process_subscription_payment function. |
135 | 135 | * @param mixed $order |
136 | 136 | * @param int $amount (default: 0) |
137 | - * @param string $stripe_token (default: '') |
|
138 | 137 | * @param bool initial_payment |
139 | 138 | */ |
140 | 139 | public function process_subscription_payment( $order = '', $amount = 0 ) { |
@@ -186,7 +185,7 @@ discard block |
||
186 | 185 | |
187 | 186 | /** |
188 | 187 | * Don't transfer Stripe fee/ID meta to renewal orders. |
189 | - * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
|
188 | + * @param integer $renewal_order |
|
190 | 189 | */ |
191 | 190 | public function delete_renewal_meta( $renewal_order ) { |
192 | 191 | delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
@@ -406,6 +405,8 @@ discard block |
||
406 | 405 | /** |
407 | 406 | * Process the pre-order |
408 | 407 | * @param int $order_id |
408 | + * @param boolean $retry |
|
409 | + * @param boolean $force_save_source |
|
409 | 410 | * @return array |
410 | 411 | */ |
411 | 412 | public function process_pre_order( $order_id, $retry, $force_save_source ) { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -15,24 +15,24 @@ discard block |
||
15 | 15 | public function __construct() { |
16 | 16 | parent::__construct(); |
17 | 17 | |
18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
23 | 23 | |
24 | 24 | // display the credit card used for a subscription in the "My Subscriptions" table |
25 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
25 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
26 | 26 | |
27 | 27 | // allow store managers to manually set Stripe as the payment method on a subscription |
28 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
29 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
30 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
31 | - add_filter( 'wc_stripe_payment_metadata', array( $this, 'add_subscription_meta_data' ), 10, 2 ); |
|
28 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
29 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
30 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
31 | + add_filter('wc_stripe_payment_metadata', array($this, 'add_subscription_meta_data'), 10, 2); |
|
32 | 32 | } |
33 | 33 | |
34 | - if ( class_exists( 'WC_Pre_Orders_Order' ) ) { |
|
35 | - add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_release_payment' ) ); |
|
34 | + if (class_exists('WC_Pre_Orders_Order')) { |
|
35 | + add_action('wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array($this, 'process_pre_order_release_payment')); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * @since 4.0.0 |
44 | 44 | * @version 4.0.0 |
45 | 45 | */ |
46 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
47 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
46 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
47 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param int $order_id |
57 | 57 | * @return boolean |
58 | 58 | */ |
59 | - public function has_subscription( $order_id ) { |
|
60 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
59 | + public function has_subscription($order_id) { |
|
60 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @param int $order_id |
66 | 66 | * @return boolean |
67 | 67 | */ |
68 | - protected function is_pre_order( $order_id ) { |
|
69 | - return ( class_exists( 'WC_Pre_Orders_Order' ) && WC_Pre_Orders_Order::order_contains_pre_order( $order_id ) ); |
|
68 | + protected function is_pre_order($order_id) { |
|
69 | + return (class_exists('WC_Pre_Orders_Order') && WC_Pre_Orders_Order::order_contains_pre_order($order_id)); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * @param int $order_id |
75 | 75 | * @return array |
76 | 76 | */ |
77 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
78 | - if ( $this->has_subscription( $order_id ) ) { |
|
77 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
78 | + if ($this->has_subscription($order_id)) { |
|
79 | 79 | // Regular payment with force customer enabled |
80 | - return parent::process_payment( $order_id, true, true ); |
|
81 | - } elseif ( $this->is_pre_order( $order_id ) ) { |
|
82 | - return $this->process_pre_order( $order_id, $retry, $force_save_source ); |
|
80 | + return parent::process_payment($order_id, true, true); |
|
81 | + } elseif ($this->is_pre_order($order_id)) { |
|
82 | + return $this->process_pre_order($order_id, $retry, $force_save_source); |
|
83 | 83 | } else { |
84 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
84 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | * @param array $metadata |
93 | 93 | * @param object $order |
94 | 94 | */ |
95 | - public function add_subscription_meta_data( $metadata, $order ) { |
|
96 | - if ( ! $this->has_subscription( $order->get_id() ) ) { |
|
95 | + public function add_subscription_meta_data($metadata, $order) { |
|
96 | + if ( ! $this->has_subscription($order->get_id())) { |
|
97 | 97 | return $metadata; |
98 | 98 | } |
99 | 99 | |
100 | 100 | return $metadata += array( |
101 | 101 | 'payment_type' => 'recurring', |
102 | - 'site_url' => esc_url( get_site_url() ), |
|
102 | + 'site_url' => esc_url(get_site_url()), |
|
103 | 103 | ); |
104 | 104 | } |
105 | 105 | |
@@ -109,24 +109,24 @@ discard block |
||
109 | 109 | * @since 3.1.0 |
110 | 110 | * @version 4.0.0 |
111 | 111 | */ |
112 | - public function save_source( $order, $source ) { |
|
113 | - parent::save_source( $order, $source ); |
|
112 | + public function save_source($order, $source) { |
|
113 | + parent::save_source($order, $source); |
|
114 | 114 | |
115 | - $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
115 | + $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
|
116 | 116 | |
117 | 117 | // Also store it on the subscriptions being purchased or paid for in the order |
118 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
119 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
120 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
121 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
118 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
119 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
120 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
121 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
122 | 122 | } else { |
123 | 123 | $subscriptions = array(); |
124 | 124 | } |
125 | 125 | |
126 | - foreach ( $subscriptions as $subscription ) { |
|
126 | + foreach ($subscriptions as $subscription) { |
|
127 | 127 | $subscription_id = WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id(); |
128 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
129 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
128 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
129 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -137,37 +137,37 @@ discard block |
||
137 | 137 | * @param string $stripe_token (default: '') |
138 | 138 | * @param bool initial_payment |
139 | 139 | */ |
140 | - public function process_subscription_payment( $order = '', $amount = 0 ) { |
|
141 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
140 | + public function process_subscription_payment($order = '', $amount = 0) { |
|
141 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
142 | 142 | /* translators: minimum amount */ |
143 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
143 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | $customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
147 | 147 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
148 | 148 | |
149 | 149 | // Get source from order |
150 | - $prepared_source = $this->prepare_order_source( $order ); |
|
150 | + $prepared_source = $this->prepare_order_source($order); |
|
151 | 151 | |
152 | 152 | // Or fail :( |
153 | - if ( ! $prepared_source->customer ) { |
|
154 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
153 | + if ( ! $prepared_source->customer) { |
|
154 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
155 | 155 | } |
156 | 156 | |
157 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
157 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
158 | 158 | |
159 | 159 | // Make the request |
160 | - $request = $this->generate_payment_request( $order, $prepared_source ); |
|
160 | + $request = $this->generate_payment_request($order, $prepared_source); |
|
161 | 161 | $request['capture'] = 'true'; |
162 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
163 | - $response = WC_Stripe_API::request( $request ); |
|
162 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
163 | + $response = WC_Stripe_API::request($request); |
|
164 | 164 | |
165 | 165 | // Process valid response |
166 | - if ( ! empty( $response->error ) ) { |
|
166 | + if ( ! empty($response->error)) { |
|
167 | 167 | return $response; // Default catch all errors. |
168 | 168 | } |
169 | 169 | |
170 | - $this->process_response( $response, $order ); |
|
170 | + $this->process_response($response, $order); |
|
171 | 171 | |
172 | 172 | return $response; |
173 | 173 | } |
@@ -176,21 +176,21 @@ discard block |
||
176 | 176 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
177 | 177 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
178 | 178 | */ |
179 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
180 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
181 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
179 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
180 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
181 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
182 | 182 | // For BW compat will remove in future |
183 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
184 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
183 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
184 | + $this->delete_renewal_meta($resubscribe_order); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
188 | 188 | * Don't transfer Stripe fee/ID meta to renewal orders. |
189 | 189 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
190 | 190 | */ |
191 | - public function delete_renewal_meta( $renewal_order ) { |
|
192 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Stripe Fee' ); |
|
193 | - delete_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id() ), 'Net Revenue From Stripe' ); |
|
191 | + public function delete_renewal_meta($renewal_order) { |
|
192 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Stripe Fee'); |
|
193 | + delete_post_meta((WC_Stripe_Helper::is_pre_30() ? $renewal_order->id : $renewal_order->get_id()), 'Net Revenue From Stripe'); |
|
194 | 194 | return $renewal_order; |
195 | 195 | } |
196 | 196 | |
@@ -200,17 +200,17 @@ discard block |
||
200 | 200 | * @param $amount_to_charge float The amount to charge. |
201 | 201 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
202 | 202 | */ |
203 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
204 | - $response = $this->process_subscription_payment( $renewal_order, $amount_to_charge ); |
|
203 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
204 | + $response = $this->process_subscription_payment($renewal_order, $amount_to_charge); |
|
205 | 205 | |
206 | - if ( is_wp_error( $response ) ) { |
|
206 | + if (is_wp_error($response)) { |
|
207 | 207 | /* translators: error message */ |
208 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
208 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
209 | 209 | } |
210 | 210 | |
211 | - if ( ! empty( $response->error ) ) { |
|
211 | + if ( ! empty($response->error)) { |
|
212 | 212 | /* translators: error message */ |
213 | - $renewal_order->update_status( 'failed', sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $response->error->message ) ); |
|
213 | + $renewal_order->update_status('failed', sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $response->error->message)); |
|
214 | 214 | } |
215 | 215 | } |
216 | 216 | |
@@ -218,20 +218,20 @@ discard block |
||
218 | 218 | * Remove order meta |
219 | 219 | * @param object $order |
220 | 220 | */ |
221 | - public function remove_order_source_before_retry( $order ) { |
|
221 | + public function remove_order_source_before_retry($order) { |
|
222 | 222 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
223 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
223 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
224 | 224 | // For BW compat will remove in the future. |
225 | - delete_post_meta( $order_id, '_stripe_card_id' ); |
|
225 | + delete_post_meta($order_id, '_stripe_card_id'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
229 | 229 | * Remove order meta |
230 | 230 | * @param object $order |
231 | 231 | */ |
232 | - public function remove_order_customer_before_retry( $order ) { |
|
232 | + public function remove_order_customer_before_retry($order) { |
|
233 | 233 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
234 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
234 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -243,14 +243,14 @@ discard block |
||
243 | 243 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
244 | 244 | * @return void |
245 | 245 | */ |
246 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
247 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
248 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
249 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
246 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
247 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
248 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
249 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
250 | 250 | |
251 | 251 | } else { |
252 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
253 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
252 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
253 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
@@ -263,21 +263,21 @@ discard block |
||
263 | 263 | * @param WC_Subscription $subscription An instance of a subscription object |
264 | 264 | * @return array |
265 | 265 | */ |
266 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
267 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
266 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
267 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
268 | 268 | |
269 | 269 | // For BW compat will remove in future. |
270 | - if ( empty( $source_id ) ) { |
|
271 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
270 | + if (empty($source_id)) { |
|
271 | + $source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
272 | 272 | |
273 | 273 | // Take this opportunity to update the key name. |
274 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
274 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
275 | 275 | } |
276 | 276 | |
277 | - $payment_meta[ $this->id ] = array( |
|
277 | + $payment_meta[$this->id] = array( |
|
278 | 278 | 'post_meta' => array( |
279 | 279 | '_stripe_customer_id' => array( |
280 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
280 | + 'value' => get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
281 | 281 | 'label' => 'Stripe Customer ID', |
282 | 282 | ), |
283 | 283 | '_stripe_source_id' => array( |
@@ -299,17 +299,17 @@ discard block |
||
299 | 299 | * @param array $payment_meta associative array of meta data required for automatic payments |
300 | 300 | * @return array |
301 | 301 | */ |
302 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
303 | - if ( $this->id === $payment_method_id ) { |
|
302 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
303 | + if ($this->id === $payment_method_id) { |
|
304 | 304 | |
305 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
306 | - throw new Exception( 'A "_stripe_customer_id" value is required.' ); |
|
307 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
308 | - throw new Exception( 'Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".' ); |
|
305 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
306 | + throw new Exception('A "_stripe_customer_id" value is required.'); |
|
307 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
308 | + throw new Exception('Invalid customer ID. A valid "_stripe_customer_id" must begin with "cus_".'); |
|
309 | 309 | } |
310 | 310 | |
311 | - if ( ! isset( $payment_meta['post_meta']['_stripe_source_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) ) { |
|
312 | - throw new Exception( 'A "_stripe_source_id" value is required.' ); |
|
311 | + if ( ! isset($payment_meta['post_meta']['_stripe_source_id']['value']) || empty($payment_meta['post_meta']['_stripe_source_id']['value'])) { |
|
312 | + throw new Exception('A "_stripe_source_id" value is required.'); |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | } |
@@ -322,89 +322,89 @@ discard block |
||
322 | 322 | * @param WC_Subscription $subscription the subscription details |
323 | 323 | * @return string the subscription payment method |
324 | 324 | */ |
325 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
325 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
326 | 326 | $customer_user = WC_Stripe_Helper::is_pre_30() ? $subscription->customer_user : $subscription->get_customer_id(); |
327 | 327 | |
328 | 328 | // bail for other payment methods |
329 | - if ( ( WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
329 | + if ((WC_Stripe_Helper::is_pre_30() ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
330 | 330 | return $payment_method_to_display; |
331 | 331 | } |
332 | 332 | |
333 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
333 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
334 | 334 | |
335 | 335 | // For BW compat will remove in future. |
336 | - if ( empty( $stripe_source_id ) ) { |
|
337 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
336 | + if (empty($stripe_source_id)) { |
|
337 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
338 | 338 | |
339 | 339 | // Take this opportunity to update the key name. |
340 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
340 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | $stripe_customer = new WC_Stripe_Customer(); |
344 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
344 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
345 | 345 | |
346 | 346 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
347 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
347 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
348 | 348 | $user_id = $customer_user; |
349 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
350 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
349 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
350 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
351 | 351 | |
352 | 352 | // For BW compat will remove in future. |
353 | - if ( empty( $stripe_source_id ) ) { |
|
354 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
353 | + if (empty($stripe_source_id)) { |
|
354 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
355 | 355 | |
356 | 356 | // Take this opportunity to update the key name. |
357 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
357 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
358 | 358 | } |
359 | 359 | } |
360 | 360 | |
361 | 361 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
362 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
363 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
364 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
362 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
363 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
364 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
365 | 365 | |
366 | 366 | // For BW compat will remove in future. |
367 | - if ( empty( $stripe_source_id ) ) { |
|
368 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
367 | + if (empty($stripe_source_id)) { |
|
368 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_pre_30() ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
369 | 369 | |
370 | 370 | // Take this opportunity to update the key name. |
371 | - WC_Stripe_Helper::is_pre_30() ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
371 | + WC_Stripe_Helper::is_pre_30() ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
375 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
375 | + $stripe_customer->set_id($stripe_customer_id); |
|
376 | 376 | $sources = $stripe_customer->get_sources(); |
377 | 377 | |
378 | - if ( $sources ) { |
|
378 | + if ($sources) { |
|
379 | 379 | $found_source = false; |
380 | - foreach ( $sources as $source ) { |
|
381 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
380 | + foreach ($sources as $source) { |
|
381 | + if (isset($source->type) && 'card' === $source->type) { |
|
382 | 382 | $card = $source->card; |
383 | 383 | } |
384 | 384 | |
385 | - if ( $source->id === $stripe_source_id ) { |
|
385 | + if ($source->id === $stripe_source_id) { |
|
386 | 386 | $found_source = true; |
387 | 387 | |
388 | - if ( $card ) { |
|
388 | + if ($card) { |
|
389 | 389 | /* translators: 1) card brand 2) last 4 digits */ |
390 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
390 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
391 | 391 | } else { |
392 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
392 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
393 | 393 | } |
394 | 394 | break; |
395 | 395 | } |
396 | 396 | } |
397 | 397 | |
398 | - if ( ! $found_source ) { |
|
399 | - if ( 'card' === $sources[0]->type ) { |
|
398 | + if ( ! $found_source) { |
|
399 | + if ('card' === $sources[0]->type) { |
|
400 | 400 | $card = $sources[0]->card; |
401 | 401 | } |
402 | 402 | |
403 | - if ( $card ) { |
|
403 | + if ($card) { |
|
404 | 404 | /* translators: 1) card brand 2) last 4 digits */ |
405 | - $payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 ); |
|
405 | + $payment_method_to_display = sprintf(__('Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe'), (isset($card->brand) ? $card->brand : __('N/A', 'woocommerce-gateway-stripe')), $card->last4); |
|
406 | 406 | } else { |
407 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
407 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
408 | 408 | } |
409 | 409 | } |
410 | 410 | } |
@@ -417,43 +417,43 @@ discard block |
||
417 | 417 | * @param int $order_id |
418 | 418 | * @return array |
419 | 419 | */ |
420 | - public function process_pre_order( $order_id, $retry, $force_save_source ) { |
|
421 | - if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order_id ) ) { |
|
420 | + public function process_pre_order($order_id, $retry, $force_save_source) { |
|
421 | + if (WC_Pre_Orders_Order::order_requires_payment_tokenization($order_id)) { |
|
422 | 422 | try { |
423 | - $order = wc_get_order( $order_id ); |
|
423 | + $order = wc_get_order($order_id); |
|
424 | 424 | |
425 | - if ( $order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
425 | + if ($order->get_total() * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
426 | 426 | /* translators: minimum amount */ |
427 | - throw new Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
427 | + throw new Exception(sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
428 | 428 | } |
429 | 429 | |
430 | - $source = $this->prepare_source( $this->create_source_object(), get_current_user_id(), true ); |
|
430 | + $source = $this->prepare_source($this->create_source_object(), get_current_user_id(), true); |
|
431 | 431 | |
432 | 432 | // We need a source on file to continue. |
433 | - if ( empty( $source->customer ) || empty( $source->source ) ) { |
|
434 | - throw new Exception( __( 'Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe' ) ); |
|
433 | + if (empty($source->customer) || empty($source->source)) { |
|
434 | + throw new Exception(__('Unable to store payment details. Please try again.', 'woocommerce-gateway-stripe')); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | // Store source to order meta |
438 | - $this->save_source( $order, $source ); |
|
438 | + $this->save_source($order, $source); |
|
439 | 439 | |
440 | 440 | // Remove cart |
441 | 441 | WC()->cart->empty_cart(); |
442 | 442 | |
443 | 443 | // Is pre ordered! |
444 | - WC_Pre_Orders_Order::mark_order_as_pre_ordered( $order ); |
|
444 | + WC_Pre_Orders_Order::mark_order_as_pre_ordered($order); |
|
445 | 445 | |
446 | 446 | // Return thank you page redirect |
447 | 447 | return array( |
448 | 448 | 'result' => 'success', |
449 | - 'redirect' => $this->get_return_url( $order ), |
|
449 | + 'redirect' => $this->get_return_url($order), |
|
450 | 450 | ); |
451 | - } catch ( Exception $e ) { |
|
452 | - wc_add_notice( $e->getMessage(), 'error' ); |
|
451 | + } catch (Exception $e) { |
|
452 | + wc_add_notice($e->getMessage(), 'error'); |
|
453 | 453 | return; |
454 | 454 | } |
455 | 455 | } else { |
456 | - return parent::process_payment( $order_id, $retry, $force_save_source ); |
|
456 | + return parent::process_payment($order_id, $retry, $force_save_source); |
|
457 | 457 | } |
458 | 458 | } |
459 | 459 | |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | * @param WC_Order $order |
463 | 463 | * @return void |
464 | 464 | */ |
465 | - public function process_pre_order_release_payment( $order ) { |
|
465 | + public function process_pre_order_release_payment($order) { |
|
466 | 466 | try { |
467 | 467 | // Define some callbacks if the first attempt fails. |
468 | 468 | $retry_callbacks = array( |
@@ -470,33 +470,33 @@ discard block |
||
470 | 470 | 'remove_order_customer_before_retry', |
471 | 471 | ); |
472 | 472 | |
473 | - while ( 1 ) { |
|
474 | - $source = $this->prepare_order_source( $order ); |
|
475 | - $response = WC_Stripe_API::request( $this->generate_payment_request( $order, $source ) ); |
|
473 | + while (1) { |
|
474 | + $source = $this->prepare_order_source($order); |
|
475 | + $response = WC_Stripe_API::request($this->generate_payment_request($order, $source)); |
|
476 | 476 | |
477 | - if ( ! empty( $response->error ) ) { |
|
478 | - if ( 0 === sizeof( $retry_callbacks ) ) { |
|
479 | - throw new Exception( $response->error->message ); |
|
477 | + if ( ! empty($response->error)) { |
|
478 | + if (0 === sizeof($retry_callbacks)) { |
|
479 | + throw new Exception($response->error->message); |
|
480 | 480 | } else { |
481 | - $retry_callback = array_shift( $retry_callbacks ); |
|
482 | - call_user_func( array( $this, $retry_callback ), $order ); |
|
481 | + $retry_callback = array_shift($retry_callbacks); |
|
482 | + call_user_func(array($this, $retry_callback), $order); |
|
483 | 483 | } |
484 | 484 | } else { |
485 | 485 | // Successful |
486 | - $this->process_response( $response, $order ); |
|
486 | + $this->process_response($response, $order); |
|
487 | 487 | break; |
488 | 488 | } |
489 | 489 | } |
490 | - } catch ( Exception $e ) { |
|
490 | + } catch (Exception $e) { |
|
491 | 491 | /* translators: error message */ |
492 | - $order_note = sprintf( __( 'Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe' ), $e->getMessage() ); |
|
492 | + $order_note = sprintf(__('Stripe Transaction Failed (%s)', 'woocommerce-gateway-stripe'), $e->getMessage()); |
|
493 | 493 | |
494 | 494 | // Mark order as failed if not already set, |
495 | 495 | // otherwise, make sure we add the order note so we can detect when someone fails to check out multiple times |
496 | - if ( ! $order->has_status( 'failed' ) ) { |
|
497 | - $order->update_status( 'failed', $order_note ); |
|
496 | + if ( ! $order->has_status('failed')) { |
|
497 | + $order->update_status('failed', $order_note); |
|
498 | 498 | } else { |
499 | - $order->add_order_note( $order_note ); |
|
499 | + $order->add_order_note($order_note); |
|
500 | 500 | } |
501 | 501 | } |
502 | 502 | } |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
7 | 7 | * DEPRECATED DO NOT USE!! |
8 | 8 | */ |
9 | -if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) { |
|
9 | +if ( ! class_exists('WC_Stripe_Apple_Pay')) { |
|
10 | 10 | class WC_Stripe_Apple_Pay { |
11 | 11 | /** |
12 | 12 | * This Instance. |
@@ -20,15 +20,15 @@ discard block |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | public static function instance() { |
23 | - WC_Stripe_Logger::log( "DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance." ); |
|
23 | + WC_Stripe_Logger::log("DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance."); |
|
24 | 24 | return self::$_this; |
25 | 25 | } |
26 | 26 | |
27 | - public function __get( $var ) { |
|
27 | + public function __get($var) { |
|
28 | 28 | return null; |
29 | 29 | } |
30 | 30 | |
31 | - public function __call( $name, $arguments ) { |
|
31 | + public function __call($name, $arguments) { |
|
32 | 32 | return null; |
33 | 33 | } |
34 | 34 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @since 4.0.2 |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if ( ! defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | * @param string $error_message Full response |
24 | 24 | * @param string $localized_message user-friendly translated error message |
25 | 25 | */ |
26 | - public function __construct( $error_message = '', $localized_message = '' ) { |
|
26 | + public function __construct($error_message = '', $localized_message = '') { |
|
27 | 27 | $this->localized_message = $localized_message; |
28 | - parent::__construct( $error_message ); |
|
28 | + parent::__construct($error_message); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_ideal'; |
60 | - $this->method_title = __( 'Stripe iDeal', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe iDeal', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('iDeal is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_ideal_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_ideal_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['ideal']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-ideal-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-ideal-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,24 +241,24 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'ideal'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | 254 | |
255 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
256 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
255 | + if ( ! empty($this->statement_descriptor)) { |
|
256 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
257 | 257 | } |
258 | 258 | |
259 | - WC_Stripe_Logger::log( 'Info: Begin creating iDeal source' ); |
|
259 | + WC_Stripe_Logger::log('Info: Begin creating iDeal source'); |
|
260 | 260 | |
261 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
261 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return array|void |
274 | 274 | */ |
275 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
275 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
276 | 276 | try { |
277 | - $order = wc_get_order( $order_id ); |
|
277 | + $order = wc_get_order($order_id); |
|
278 | 278 | |
279 | 279 | // This will throw exception if not valid. |
280 | - $this->validate_minimum_order_amount( $order ); |
|
280 | + $this->validate_minimum_order_amount($order); |
|
281 | 281 | |
282 | 282 | // This comes from the create account checkbox in the checkout page. |
283 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
283 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
284 | 284 | |
285 | - if ( $create_account ) { |
|
285 | + if ($create_account) { |
|
286 | 286 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
287 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
287 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
288 | 288 | $new_stripe_customer->create_customer(); |
289 | 289 | } |
290 | 290 | |
291 | - $response = $this->create_source( $order ); |
|
291 | + $response = $this->create_source($order); |
|
292 | 292 | |
293 | - if ( ! empty( $response->error ) ) { |
|
294 | - $order->add_order_note( $response->error->message ); |
|
293 | + if ( ! empty($response->error)) { |
|
294 | + $order->add_order_note($response->error->message); |
|
295 | 295 | |
296 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
296 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
297 | 297 | } |
298 | 298 | |
299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
300 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
300 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
301 | 301 | } else { |
302 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
302 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
303 | 303 | $order->save(); |
304 | 304 | } |
305 | 305 | |
306 | - WC_Stripe_Logger::log( 'Info: Redirecting to iDeal...' ); |
|
306 | + WC_Stripe_Logger::log('Info: Redirecting to iDeal...'); |
|
307 | 307 | |
308 | 308 | return array( |
309 | 309 | 'result' => 'success', |
310 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
310 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
311 | 311 | ); |
312 | - } catch ( WC_Stripe_Exception $e ) { |
|
313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
312 | + } catch (WC_Stripe_Exception $e) { |
|
313 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
314 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
315 | 315 | |
316 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
316 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
317 | 317 | |
318 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
319 | - $this->send_failed_order_email( $order_id ); |
|
318 | + if ($order->has_status(array('pending', 'failed'))) { |
|
319 | + $this->send_failed_order_email($order_id); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_bancontact'; |
60 | - $this->method_title = __( 'Stripe Bancontact', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Bancontact', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('Bancontact is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_bancontact_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_bancontact_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['bancontact']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-bancontact-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-bancontact-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,24 +241,24 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'bancontact'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | 254 | |
255 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
256 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
255 | + if ( ! empty($this->statement_descriptor)) { |
|
256 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
257 | 257 | } |
258 | 258 | |
259 | - WC_Stripe_Logger::log( 'Info: Begin creating Bancontact source' ); |
|
259 | + WC_Stripe_Logger::log('Info: Begin creating Bancontact source'); |
|
260 | 260 | |
261 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
261 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return array|void |
274 | 274 | */ |
275 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
275 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
276 | 276 | try { |
277 | - $order = wc_get_order( $order_id ); |
|
277 | + $order = wc_get_order($order_id); |
|
278 | 278 | |
279 | 279 | // This will throw exception if not valid. |
280 | - $this->validate_minimum_order_amount( $order ); |
|
280 | + $this->validate_minimum_order_amount($order); |
|
281 | 281 | |
282 | 282 | // This comes from the create account checkbox in the checkout page. |
283 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
283 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
284 | 284 | |
285 | - if ( $create_account ) { |
|
285 | + if ($create_account) { |
|
286 | 286 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
287 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
287 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
288 | 288 | $new_stripe_customer->create_customer(); |
289 | 289 | } |
290 | 290 | |
291 | - $response = $this->create_source( $order ); |
|
291 | + $response = $this->create_source($order); |
|
292 | 292 | |
293 | - if ( ! empty( $response->error ) ) { |
|
294 | - $order->add_order_note( $response->error->message ); |
|
293 | + if ( ! empty($response->error)) { |
|
294 | + $order->add_order_note($response->error->message); |
|
295 | 295 | |
296 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
296 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
297 | 297 | } |
298 | 298 | |
299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
300 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
300 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
301 | 301 | } else { |
302 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
302 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
303 | 303 | $order->save(); |
304 | 304 | } |
305 | 305 | |
306 | - WC_Stripe_Logger::log( 'Info: Redirecting to Bancontact...' ); |
|
306 | + WC_Stripe_Logger::log('Info: Redirecting to Bancontact...'); |
|
307 | 307 | |
308 | 308 | return array( |
309 | 309 | 'result' => 'success', |
310 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
310 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
311 | 311 | ); |
312 | - } catch ( WC_Stripe_Exception $e ) { |
|
313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
312 | + } catch (WC_Stripe_Exception $e) { |
|
313 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
314 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
315 | 315 | |
316 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
316 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
317 | 317 | |
318 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
319 | - $this->send_failed_order_email( $order_id ); |
|
318 | + if ($order->has_status(array('pending', 'failed'))) { |
|
319 | + $this->send_failed_order_email($order_id); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_sofort'; |
60 | - $this->method_title = __( 'Stripe SOFORT', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe SOFORT', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('SOFORT is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_sofort_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_sofort_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['sofort']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-sofort-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-sofort-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,25 +241,25 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $bank_country = WC_Stripe_Helper::is_pre_30() ? $order->billing_country : $order->get_billing_country(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'sofort'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
254 | - $post_data['sofort'] = array( 'country' => $bank_country ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | + $post_data['sofort'] = array('country' => $bank_country); |
|
255 | 255 | |
256 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
257 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
256 | + if ( ! empty($this->statement_descriptor)) { |
|
257 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
258 | 258 | } |
259 | 259 | |
260 | - WC_Stripe_Logger::log( 'Info: Begin creating SOFORT source' ); |
|
260 | + WC_Stripe_Logger::log('Info: Begin creating SOFORT source'); |
|
261 | 261 | |
262 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
262 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -273,51 +273,51 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @return array|void |
275 | 275 | */ |
276 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
276 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
277 | 277 | try { |
278 | - $order = wc_get_order( $order_id ); |
|
278 | + $order = wc_get_order($order_id); |
|
279 | 279 | |
280 | 280 | // This will throw exception if not valid. |
281 | - $this->validate_minimum_order_amount( $order ); |
|
281 | + $this->validate_minimum_order_amount($order); |
|
282 | 282 | |
283 | 283 | // This comes from the create account checkbox in the checkout page. |
284 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
284 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
285 | 285 | |
286 | - if ( $create_account ) { |
|
286 | + if ($create_account) { |
|
287 | 287 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
288 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
288 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
289 | 289 | $new_stripe_customer->create_customer(); |
290 | 290 | } |
291 | 291 | |
292 | - $response = $this->create_source( $order ); |
|
292 | + $response = $this->create_source($order); |
|
293 | 293 | |
294 | - if ( ! empty( $response->error ) ) { |
|
295 | - $order->add_order_note( $response->error->message ); |
|
294 | + if ( ! empty($response->error)) { |
|
295 | + $order->add_order_note($response->error->message); |
|
296 | 296 | |
297 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
297 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
298 | 298 | } |
299 | 299 | |
300 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
301 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
300 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
301 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
302 | 302 | } else { |
303 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
303 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
304 | 304 | $order->save(); |
305 | 305 | } |
306 | 306 | |
307 | - WC_Stripe_Logger::log( 'Info: Redirecting to SOFORT...' ); |
|
307 | + WC_Stripe_Logger::log('Info: Redirecting to SOFORT...'); |
|
308 | 308 | |
309 | 309 | return array( |
310 | 310 | 'result' => 'success', |
311 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
311 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
312 | 312 | ); |
313 | - } catch ( WC_Stripe_Exception $e ) { |
|
314 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
315 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
313 | + } catch (WC_Stripe_Exception $e) { |
|
314 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
315 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
316 | 316 | |
317 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
317 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
318 | 318 | |
319 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
320 | - $this->send_failed_order_email( $order_id ); |
|
319 | + if ($order->has_status(array('pending', 'failed'))) { |
|
320 | + $this->send_failed_order_email($order_id); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_giropay'; |
60 | - $this->method_title = __( 'Stripe Giropay', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe Giropay', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('Giropay is enabled - it requires store currency to be set to Euros.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_giropay_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_giropay_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | - ) ); |
|
146 | + )); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return bool |
155 | 155 | */ |
156 | 156 | public function is_available() { |
157 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
157 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $icons_str .= $icons['giropay']; |
177 | 177 | |
178 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
178 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,19 +186,19 @@ discard block |
||
186 | 186 | * @access public |
187 | 187 | */ |
188 | 188 | public function payment_scripts() { |
189 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
189 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
194 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
193 | + wp_enqueue_style('stripe_paymentfonts'); |
|
194 | + wp_enqueue_script('woocommerce_stripe'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Initialize Gateway Settings Form Fields. |
199 | 199 | */ |
200 | 200 | public function init_form_fields() { |
201 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php' ); |
|
201 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-giropay-settings.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,25 +209,25 @@ discard block |
||
209 | 209 | $total = WC()->cart->total; |
210 | 210 | |
211 | 211 | // If paying from order, we need to get total from order not cart. |
212 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
213 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
212 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
213 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
214 | 214 | $total = $order->get_total(); |
215 | 215 | } |
216 | 216 | |
217 | - if ( is_add_payment_method_page() ) { |
|
218 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
219 | - $total = ''; |
|
217 | + if (is_add_payment_method_page()) { |
|
218 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
219 | + $total = ''; |
|
220 | 220 | } else { |
221 | 221 | $pay_button_text = ''; |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo '<div |
225 | 225 | id="stripe-giropay-payment-data" |
226 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
227 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
226 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
227 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
228 | 228 | |
229 | - if ( $this->description ) { |
|
230 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
229 | + if ($this->description) { |
|
230 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | echo '</div>'; |
@@ -241,24 +241,24 @@ discard block |
||
241 | 241 | * @param object $order |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function create_source( $order ) { |
|
244 | + public function create_source($order) { |
|
245 | 245 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
246 | 246 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
247 | - $return_url = $this->get_stripe_return_url( $order ); |
|
247 | + $return_url = $this->get_stripe_return_url($order); |
|
248 | 248 | $post_data = array(); |
249 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
250 | - $post_data['currency'] = strtolower( $currency ); |
|
249 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
250 | + $post_data['currency'] = strtolower($currency); |
|
251 | 251 | $post_data['type'] = 'giropay'; |
252 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
253 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
252 | + $post_data['owner'] = $this->get_owner_details($order); |
|
253 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
254 | 254 | |
255 | - if ( ! empty( $this->statement_descriptor ) ) { |
|
256 | - $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
255 | + if ( ! empty($this->statement_descriptor)) { |
|
256 | + $post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
257 | 257 | } |
258 | 258 | |
259 | - WC_Stripe_Logger::log( 'Info: Begin creating Giropay source' ); |
|
259 | + WC_Stripe_Logger::log('Info: Begin creating Giropay source'); |
|
260 | 260 | |
261 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
261 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -272,51 +272,51 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return array|void |
274 | 274 | */ |
275 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
275 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
276 | 276 | try { |
277 | - $order = wc_get_order( $order_id ); |
|
277 | + $order = wc_get_order($order_id); |
|
278 | 278 | |
279 | 279 | // This will throw exception if not valid. |
280 | - $this->validate_minimum_order_amount( $order ); |
|
280 | + $this->validate_minimum_order_amount($order); |
|
281 | 281 | |
282 | 282 | // This comes from the create account checkbox in the checkout page. |
283 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
283 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
284 | 284 | |
285 | - if ( $create_account ) { |
|
285 | + if ($create_account) { |
|
286 | 286 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
287 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
287 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
288 | 288 | $new_stripe_customer->create_customer(); |
289 | 289 | } |
290 | 290 | |
291 | - $response = $this->create_source( $order ); |
|
291 | + $response = $this->create_source($order); |
|
292 | 292 | |
293 | - if ( ! empty( $response->error ) ) { |
|
294 | - $order->add_order_note( $response->error->message ); |
|
293 | + if ( ! empty($response->error)) { |
|
294 | + $order->add_order_note($response->error->message); |
|
295 | 295 | |
296 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
296 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
297 | 297 | } |
298 | 298 | |
299 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
300 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
299 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
300 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
301 | 301 | } else { |
302 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
302 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
303 | 303 | $order->save(); |
304 | 304 | } |
305 | 305 | |
306 | - WC_Stripe_Logger::log( 'Info: Redirecting to Giropay...' ); |
|
306 | + WC_Stripe_Logger::log('Info: Redirecting to Giropay...'); |
|
307 | 307 | |
308 | 308 | return array( |
309 | 309 | 'result' => 'success', |
310 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
310 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
311 | 311 | ); |
312 | - } catch ( WC_Stripe_Exception $e ) { |
|
313 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
314 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
312 | + } catch (WC_Stripe_Exception $e) { |
|
313 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
314 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
315 | 315 | |
316 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
316 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
317 | 317 | |
318 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
319 | - $this->send_failed_order_email( $order_id ); |
|
318 | + if ($order->has_status(array('pending', 'failed'))) { |
|
319 | + $this->send_failed_order_email($order_id); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct() { |
59 | 59 | $this->id = 'stripe_p24'; |
60 | - $this->method_title = __( 'Stripe P24', 'woocommerce-gateway-stripe' ); |
|
60 | + $this->method_title = __('Stripe P24', 'woocommerce-gateway-stripe'); |
|
61 | 61 | /* translators: link */ |
62 | - $this->method_description = sprintf( __( 'All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe' ), admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=stripe' ) ); |
|
62 | + $this->method_description = sprintf(__('All other general Stripe settings can be adjusted <a href="%s">here</a>.', 'woocommerce-gateway-stripe'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=stripe')); |
|
63 | 63 | $this->supports = array( |
64 | 64 | 'products', |
65 | 65 | 'refunds', |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | // Load the settings. |
72 | 72 | $this->init_settings(); |
73 | 73 | |
74 | - $main_settings = get_option( 'woocommerce_stripe_settings' ); |
|
75 | - $this->title = $this->get_option( 'title' ); |
|
76 | - $this->description = $this->get_option( 'description' ); |
|
77 | - $this->enabled = $this->get_option( 'enabled' ); |
|
78 | - $this->testmode = ( ! empty( $main_settings['testmode'] ) && 'yes' === $main_settings['testmode'] ) ? true : false; |
|
79 | - $this->saved_cards = ( ! empty( $main_settings['saved_cards'] ) && 'yes' === $main_settings['saved_cards'] ) ? true : false; |
|
80 | - $this->publishable_key = ! empty( $main_settings['publishable_key'] ) ? $main_settings['publishable_key'] : ''; |
|
81 | - $this->secret_key = ! empty( $main_settings['secret_key'] ) ? $main_settings['secret_key'] : ''; |
|
82 | - $this->statement_descriptor = ! empty( $main_settings['statement_descriptor'] ) ? $main_settings['statement_descriptor'] : ''; |
|
83 | - |
|
84 | - if ( $this->testmode ) { |
|
85 | - $this->publishable_key = ! empty( $main_settings['test_publishable_key'] ) ? $main_settings['test_publishable_key'] : ''; |
|
86 | - $this->secret_key = ! empty( $main_settings['test_secret_key'] ) ? $main_settings['test_secret_key'] : ''; |
|
74 | + $main_settings = get_option('woocommerce_stripe_settings'); |
|
75 | + $this->title = $this->get_option('title'); |
|
76 | + $this->description = $this->get_option('description'); |
|
77 | + $this->enabled = $this->get_option('enabled'); |
|
78 | + $this->testmode = ( ! empty($main_settings['testmode']) && 'yes' === $main_settings['testmode']) ? true : false; |
|
79 | + $this->saved_cards = ( ! empty($main_settings['saved_cards']) && 'yes' === $main_settings['saved_cards']) ? true : false; |
|
80 | + $this->publishable_key = ! empty($main_settings['publishable_key']) ? $main_settings['publishable_key'] : ''; |
|
81 | + $this->secret_key = ! empty($main_settings['secret_key']) ? $main_settings['secret_key'] : ''; |
|
82 | + $this->statement_descriptor = ! empty($main_settings['statement_descriptor']) ? $main_settings['statement_descriptor'] : ''; |
|
83 | + |
|
84 | + if ($this->testmode) { |
|
85 | + $this->publishable_key = ! empty($main_settings['test_publishable_key']) ? $main_settings['test_publishable_key'] : ''; |
|
86 | + $this->secret_key = ! empty($main_settings['test_secret_key']) ? $main_settings['test_secret_key'] : ''; |
|
87 | 87 | } |
88 | 88 | |
89 | - add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); |
|
90 | - add_action( 'admin_notices', array( $this, 'check_environment' ) ); |
|
91 | - add_action( 'admin_head', array( $this, 'remove_admin_notice' ) ); |
|
92 | - add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) ); |
|
89 | + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); |
|
90 | + add_action('admin_notices', array($this, 'check_environment')); |
|
91 | + add_action('admin_head', array($this, 'remove_admin_notice')); |
|
92 | + add_action('wp_enqueue_scripts', array($this, 'payment_scripts')); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | * @version 4.0.0 |
100 | 100 | */ |
101 | 101 | public function check_environment() { |
102 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
102 | + if ( ! current_user_can('manage_woocommerce')) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $environment_warning = $this->get_environment_warning(); |
107 | 107 | |
108 | - if ( $environment_warning ) { |
|
109 | - $this->add_admin_notice( 'bad_environment', 'error', $environment_warning ); |
|
108 | + if ($environment_warning) { |
|
109 | + $this->add_admin_notice('bad_environment', 'error', $environment_warning); |
|
110 | 110 | } |
111 | 111 | |
112 | - foreach ( (array) $this->notices as $notice_key => $notice ) { |
|
113 | - echo "<div class='" . esc_attr( $notice['class'] ) . "'><p>"; |
|
114 | - echo wp_kses( $notice['message'], array( 'a' => array( 'href' => array() ) ) ); |
|
112 | + foreach ((array) $this->notices as $notice_key => $notice) { |
|
113 | + echo "<div class='" . esc_attr($notice['class']) . "'><p>"; |
|
114 | + echo wp_kses($notice['message'], array('a' => array('href' => array()))); |
|
115 | 115 | echo '</p></div>'; |
116 | 116 | } |
117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @version 4.0.0 |
125 | 125 | */ |
126 | 126 | public function get_environment_warning() { |
127 | - if ( 'yes' === $this->enabled && ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
128 | - $message = __( 'P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe' ); |
|
127 | + if ('yes' === $this->enabled && ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
128 | + $message = __('P24 is enabled - it requires store currency to be set to Euros or Polish Zloty.', 'woocommerce-gateway-stripe'); |
|
129 | 129 | |
130 | 130 | return $message; |
131 | 131 | } |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | * @return array |
142 | 142 | */ |
143 | 143 | public function get_supported_currency() { |
144 | - return apply_filters( 'wc_stripe_p24_supported_currencies', array( |
|
144 | + return apply_filters('wc_stripe_p24_supported_currencies', array( |
|
145 | 145 | 'EUR', |
146 | 146 | 'PLN', |
147 | - ) ); |
|
147 | + )); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @return bool |
156 | 156 | */ |
157 | 157 | public function is_available() { |
158 | - if ( ! in_array( get_woocommerce_currency(), $this->get_supported_currency() ) ) { |
|
158 | + if ( ! in_array(get_woocommerce_currency(), $this->get_supported_currency())) { |
|
159 | 159 | return false; |
160 | 160 | } |
161 | 161 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | $icons_str .= $icons['p24']; |
178 | 178 | |
179 | - return apply_filters( 'woocommerce_gateway_icon', $icons_str, $this->id ); |
|
179 | + return apply_filters('woocommerce_gateway_icon', $icons_str, $this->id); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -187,19 +187,19 @@ discard block |
||
187 | 187 | * @access public |
188 | 188 | */ |
189 | 189 | public function payment_scripts() { |
190 | - if ( ! is_cart() && ! is_checkout() && ! isset( $_GET['pay_for_order'] ) && ! is_add_payment_method_page() ) { |
|
190 | + if ( ! is_cart() && ! is_checkout() && ! isset($_GET['pay_for_order']) && ! is_add_payment_method_page()) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | |
194 | - wp_enqueue_style( 'stripe_paymentfonts' ); |
|
195 | - wp_enqueue_script( 'woocommerce_stripe' ); |
|
194 | + wp_enqueue_style('stripe_paymentfonts'); |
|
195 | + wp_enqueue_script('woocommerce_stripe'); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
199 | 199 | * Initialize Gateway Settings Form Fields. |
200 | 200 | */ |
201 | 201 | public function init_form_fields() { |
202 | - $this->form_fields = require( WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php' ); |
|
202 | + $this->form_fields = require(WC_STRIPE_PLUGIN_PATH . '/includes/admin/stripe-p24-settings.php'); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -210,25 +210,25 @@ discard block |
||
210 | 210 | $total = WC()->cart->total; |
211 | 211 | |
212 | 212 | // If paying from order, we need to get total from order not cart. |
213 | - if ( isset( $_GET['pay_for_order'] ) && ! empty( $_GET['key'] ) ) { |
|
214 | - $order = wc_get_order( wc_get_order_id_by_order_key( wc_clean( $_GET['key'] ) ) ); |
|
213 | + if (isset($_GET['pay_for_order']) && ! empty($_GET['key'])) { |
|
214 | + $order = wc_get_order(wc_get_order_id_by_order_key(wc_clean($_GET['key']))); |
|
215 | 215 | $total = $order->get_total(); |
216 | 216 | } |
217 | 217 | |
218 | - if ( is_add_payment_method_page() ) { |
|
219 | - $pay_button_text = __( 'Add Payment', 'woocommerce-gateway-stripe' ); |
|
220 | - $total = ''; |
|
218 | + if (is_add_payment_method_page()) { |
|
219 | + $pay_button_text = __('Add Payment', 'woocommerce-gateway-stripe'); |
|
220 | + $total = ''; |
|
221 | 221 | } else { |
222 | 222 | $pay_button_text = ''; |
223 | 223 | } |
224 | 224 | |
225 | 225 | echo '<div |
226 | 226 | id="stripe-p24-payment-data" |
227 | - data-amount="' . esc_attr( WC_Stripe_Helper::get_stripe_amount( $total ) ) . '" |
|
228 | - data-currency="' . esc_attr( strtolower( get_woocommerce_currency() ) ) . '">'; |
|
227 | + data-amount="' . esc_attr(WC_Stripe_Helper::get_stripe_amount($total)) . '" |
|
228 | + data-currency="' . esc_attr(strtolower(get_woocommerce_currency())) . '">'; |
|
229 | 229 | |
230 | - if ( $this->description ) { |
|
231 | - echo apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $this->description ) ) ); |
|
230 | + if ($this->description) { |
|
231 | + echo apply_filters('wc_stripe_description', wpautop(wp_kses_post($this->description))); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | echo '</div>'; |
@@ -242,20 +242,20 @@ discard block |
||
242 | 242 | * @param object $order |
243 | 243 | * @return mixed |
244 | 244 | */ |
245 | - public function create_source( $order ) { |
|
245 | + public function create_source($order) { |
|
246 | 246 | $currency = WC_Stripe_Helper::is_pre_30() ? $order->get_order_currency() : $order->get_currency(); |
247 | 247 | $order_id = WC_Stripe_Helper::is_pre_30() ? $order->id : $order->get_id(); |
248 | - $return_url = $this->get_stripe_return_url( $order ); |
|
248 | + $return_url = $this->get_stripe_return_url($order); |
|
249 | 249 | $post_data = array(); |
250 | - $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $currency ); |
|
251 | - $post_data['currency'] = strtolower( $currency ); |
|
250 | + $post_data['amount'] = WC_Stripe_Helper::get_stripe_amount($order->get_total(), $currency); |
|
251 | + $post_data['currency'] = strtolower($currency); |
|
252 | 252 | $post_data['type'] = 'p24'; |
253 | - $post_data['owner'] = $this->get_owner_details( $order ); |
|
254 | - $post_data['redirect'] = array( 'return_url' => $return_url ); |
|
253 | + $post_data['owner'] = $this->get_owner_details($order); |
|
254 | + $post_data['redirect'] = array('return_url' => $return_url); |
|
255 | 255 | |
256 | - WC_Stripe_Logger::log( 'Info: Begin creating P24 source' ); |
|
256 | + WC_Stripe_Logger::log('Info: Begin creating P24 source'); |
|
257 | 257 | |
258 | - return WC_Stripe_API::request( $post_data, 'sources' ); |
|
258 | + return WC_Stripe_API::request($post_data, 'sources'); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -269,51 +269,51 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @return array|void |
271 | 271 | */ |
272 | - public function process_payment( $order_id, $retry = true, $force_save_source = false ) { |
|
272 | + public function process_payment($order_id, $retry = true, $force_save_source = false) { |
|
273 | 273 | try { |
274 | - $order = wc_get_order( $order_id ); |
|
274 | + $order = wc_get_order($order_id); |
|
275 | 275 | |
276 | 276 | // This will throw exception if not valid. |
277 | - $this->validate_minimum_order_amount( $order ); |
|
277 | + $this->validate_minimum_order_amount($order); |
|
278 | 278 | |
279 | 279 | // This comes from the create account checkbox in the checkout page. |
280 | - $create_account = ! empty( $_POST['createaccount'] ) ? true : false; |
|
280 | + $create_account = ! empty($_POST['createaccount']) ? true : false; |
|
281 | 281 | |
282 | - if ( $create_account ) { |
|
282 | + if ($create_account) { |
|
283 | 283 | $new_customer_id = WC_Stripe_Helper::is_pre_30() ? $order->customer_user : $order->get_customer_id(); |
284 | - $new_stripe_customer = new WC_Stripe_Customer( $new_customer_id ); |
|
284 | + $new_stripe_customer = new WC_Stripe_Customer($new_customer_id); |
|
285 | 285 | $new_stripe_customer->create_customer(); |
286 | 286 | } |
287 | 287 | |
288 | - $response = $this->create_source( $order ); |
|
288 | + $response = $this->create_source($order); |
|
289 | 289 | |
290 | - if ( ! empty( $response->error ) ) { |
|
291 | - $order->add_order_note( $response->error->message ); |
|
290 | + if ( ! empty($response->error)) { |
|
291 | + $order->add_order_note($response->error->message); |
|
292 | 292 | |
293 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
293 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
294 | 294 | } |
295 | 295 | |
296 | - if ( WC_Stripe_Helper::is_pre_30() ) { |
|
297 | - update_post_meta( $order_id, '_stripe_source_id', $response->id ); |
|
296 | + if (WC_Stripe_Helper::is_pre_30()) { |
|
297 | + update_post_meta($order_id, '_stripe_source_id', $response->id); |
|
298 | 298 | } else { |
299 | - $order->update_meta_data( '_stripe_source_id', $response->id ); |
|
299 | + $order->update_meta_data('_stripe_source_id', $response->id); |
|
300 | 300 | $order->save(); |
301 | 301 | } |
302 | 302 | |
303 | - WC_Stripe_Logger::log( 'Info: Redirecting to P24...' ); |
|
303 | + WC_Stripe_Logger::log('Info: Redirecting to P24...'); |
|
304 | 304 | |
305 | 305 | return array( |
306 | 306 | 'result' => 'success', |
307 | - 'redirect' => esc_url_raw( $response->redirect->url ), |
|
307 | + 'redirect' => esc_url_raw($response->redirect->url), |
|
308 | 308 | ); |
309 | - } catch ( WC_Stripe_Exception $e ) { |
|
310 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
311 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
309 | + } catch (WC_Stripe_Exception $e) { |
|
310 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
311 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
312 | 312 | |
313 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $order ); |
|
313 | + do_action('wc_gateway_stripe_process_payment_error', $e, $order); |
|
314 | 314 | |
315 | - if ( $order->has_status( array( 'pending', 'failed' ) ) ) { |
|
316 | - $this->send_failed_order_email( $order_id ); |
|
315 | + if ($order->has_status(array('pending', 'failed'))) { |
|
316 | + $this->send_failed_order_email($order_id); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | return array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if ( ! defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -17,15 +17,15 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @return float|int |
19 | 19 | */ |
20 | - public static function get_stripe_amount( $total, $currency = '' ) { |
|
21 | - if ( ! $currency ) { |
|
20 | + public static function get_stripe_amount($total, $currency = '') { |
|
21 | + if ( ! $currency) { |
|
22 | 22 | $currency = get_woocommerce_currency(); |
23 | 23 | } |
24 | 24 | |
25 | - if ( in_array( strtolower( $currency ), self::no_decimal_currencies() ) ) { |
|
26 | - return absint( $total ); |
|
25 | + if (in_array(strtolower($currency), self::no_decimal_currencies())) { |
|
26 | + return absint($total); |
|
27 | 27 | } else { |
28 | - return absint( wc_format_decimal( ( (float) $total * 100 ), wc_get_price_decimals() ) ); // In cents. |
|
28 | + return absint(wc_format_decimal(((float) $total * 100), wc_get_price_decimals())); // In cents. |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | * @return array |
38 | 38 | */ |
39 | 39 | public static function get_localized_messages() { |
40 | - return apply_filters( 'wc_stripe_localized_messages', array( |
|
41 | - 'invalid_number' => __( 'The card number is not a valid credit card number.', 'woocommerce-gateway-stripe' ), |
|
42 | - 'invalid_expiry_month' => __( 'The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe' ), |
|
43 | - 'invalid_expiry_year' => __( 'The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe' ), |
|
44 | - 'invalid_cvc' => __( 'The card\'s security code is invalid.', 'woocommerce-gateway-stripe' ), |
|
45 | - 'incorrect_number' => __( 'The card number is incorrect.', 'woocommerce-gateway-stripe' ), |
|
46 | - 'incomplete_number' => __( 'The card number is incomplete.', 'woocommerce-gateway-stripe' ), |
|
47 | - 'incomplete_cvc' => __( 'The card\'s security code is incomplete.', 'woocommerce-gateway-stripe' ), |
|
48 | - 'incomplete_expiry' => __( 'The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe' ), |
|
49 | - 'expired_card' => __( 'The card has expired.', 'woocommerce-gateway-stripe' ), |
|
50 | - 'incorrect_cvc' => __( 'The card\'s security code is incorrect.', 'woocommerce-gateway-stripe' ), |
|
51 | - 'incorrect_zip' => __( 'The card\'s zip code failed validation.', 'woocommerce-gateway-stripe' ), |
|
52 | - 'invalid_expiry_year_past' => __( 'The card\'s expiration year is in the past', 'woocommerce-gateway-stripe' ), |
|
53 | - 'card_declined' => __( 'The card was declined.', 'woocommerce-gateway-stripe' ), |
|
54 | - 'missing' => __( 'There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe' ), |
|
55 | - 'processing_error' => __( 'An error occurred while processing the card.', 'woocommerce-gateway-stripe' ), |
|
56 | - 'invalid_request_error' => __( 'Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe' ), |
|
57 | - ) ); |
|
40 | + return apply_filters('wc_stripe_localized_messages', array( |
|
41 | + 'invalid_number' => __('The card number is not a valid credit card number.', 'woocommerce-gateway-stripe'), |
|
42 | + 'invalid_expiry_month' => __('The card\'s expiration month is invalid.', 'woocommerce-gateway-stripe'), |
|
43 | + 'invalid_expiry_year' => __('The card\'s expiration year is invalid.', 'woocommerce-gateway-stripe'), |
|
44 | + 'invalid_cvc' => __('The card\'s security code is invalid.', 'woocommerce-gateway-stripe'), |
|
45 | + 'incorrect_number' => __('The card number is incorrect.', 'woocommerce-gateway-stripe'), |
|
46 | + 'incomplete_number' => __('The card number is incomplete.', 'woocommerce-gateway-stripe'), |
|
47 | + 'incomplete_cvc' => __('The card\'s security code is incomplete.', 'woocommerce-gateway-stripe'), |
|
48 | + 'incomplete_expiry' => __('The card\'s expiration date is incomplete.', 'woocommerce-gateway-stripe'), |
|
49 | + 'expired_card' => __('The card has expired.', 'woocommerce-gateway-stripe'), |
|
50 | + 'incorrect_cvc' => __('The card\'s security code is incorrect.', 'woocommerce-gateway-stripe'), |
|
51 | + 'incorrect_zip' => __('The card\'s zip code failed validation.', 'woocommerce-gateway-stripe'), |
|
52 | + 'invalid_expiry_year_past' => __('The card\'s expiration year is in the past', 'woocommerce-gateway-stripe'), |
|
53 | + 'card_declined' => __('The card was declined.', 'woocommerce-gateway-stripe'), |
|
54 | + 'missing' => __('There is no card on a customer that is being charged.', 'woocommerce-gateway-stripe'), |
|
55 | + 'processing_error' => __('An error occurred while processing the card.', 'woocommerce-gateway-stripe'), |
|
56 | + 'invalid_request_error' => __('Unable to process this payment, please try again or use alternative method.', 'woocommerce-gateway-stripe'), |
|
57 | + )); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -91,24 +91,24 @@ discard block |
||
91 | 91 | * @param string $type Type of number to format |
92 | 92 | * @return string |
93 | 93 | */ |
94 | - public static function format_balance_fee( $balance_transaction, $type = 'fee' ) { |
|
95 | - if ( ! is_object( $balance_transaction ) ) { |
|
94 | + public static function format_balance_fee($balance_transaction, $type = 'fee') { |
|
95 | + if ( ! is_object($balance_transaction)) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | - if ( in_array( strtolower( $balance_transaction->currency ), self::no_decimal_currencies() ) ) { |
|
100 | - if ( 'fee' === $type ) { |
|
99 | + if (in_array(strtolower($balance_transaction->currency), self::no_decimal_currencies())) { |
|
100 | + if ('fee' === $type) { |
|
101 | 101 | return $balance_transaction->fee; |
102 | 102 | } |
103 | 103 | |
104 | 104 | return $balance_transaction->net; |
105 | 105 | } |
106 | 106 | |
107 | - if ( 'fee' === $type ) { |
|
108 | - return number_format( $balance_transaction->fee / 100, 2, '.', '' ); |
|
107 | + if ('fee' === $type) { |
|
108 | + return number_format($balance_transaction->fee / 100, 2, '.', ''); |
|
109 | 109 | } |
110 | 110 | |
111 | - return number_format( $balance_transaction->net / 100, 2, '.', '' ); |
|
111 | + return number_format($balance_transaction->net / 100, 2, '.', ''); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public static function get_minimum_amount() { |
118 | 118 | // Check order amount |
119 | - switch ( get_woocommerce_currency() ) { |
|
119 | + switch (get_woocommerce_currency()) { |
|
120 | 120 | case 'USD': |
121 | 121 | case 'CAD': |
122 | 122 | case 'EUR': |
@@ -161,14 +161,14 @@ discard block |
||
161 | 161 | * @param string $method The payment method to get the settings from. |
162 | 162 | * @param string $setting The name of the setting to get. |
163 | 163 | */ |
164 | - public static function get_settings( $method = null, $setting = null ) { |
|
165 | - $all_settings = null === $method ? get_option( 'woocommerce_stripe_settings', array() ) : get_option( 'woocommerce_stripe_' . $method . '_settings', array() ); |
|
164 | + public static function get_settings($method = null, $setting = null) { |
|
165 | + $all_settings = null === $method ? get_option('woocommerce_stripe_settings', array()) : get_option('woocommerce_stripe_' . $method . '_settings', array()); |
|
166 | 166 | |
167 | - if ( null === $setting ) { |
|
167 | + if (null === $setting) { |
|
168 | 168 | return $all_settings; |
169 | 169 | } |
170 | 170 | |
171 | - return isset( $all_settings[ $setting ] ) ? $all_settings[ $setting ] : ''; |
|
171 | + return isset($all_settings[$setting]) ? $all_settings[$setting] : ''; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @return bool |
180 | 180 | */ |
181 | 181 | public static function is_pre_30() { |
182 | - return version_compare( WC_VERSION, '3.0.0', '<' ); |
|
182 | + return version_compare(WC_VERSION, '3.0.0', '<'); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @return string |
193 | 193 | */ |
194 | 194 | public static function get_webhook_url() { |
195 | - return add_query_arg( 'wc-api', 'wc_stripe', trailingslashit( get_home_url() ) ); |
|
195 | + return add_query_arg('wc-api', 'wc_stripe', trailingslashit(get_home_url())); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | * @version 4.0.0 |
203 | 203 | * @param string $source_id |
204 | 204 | */ |
205 | - public static function get_order_by_source_id( $source_id ) { |
|
205 | + public static function get_order_by_source_id($source_id) { |
|
206 | 206 | global $wpdb; |
207 | 207 | |
208 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id ) ); |
|
208 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $source_id)); |
|
209 | 209 | |
210 | - if ( ! empty( $order_id ) ) { |
|
211 | - return wc_get_order( $order_id ); |
|
210 | + if ( ! empty($order_id)) { |
|
211 | + return wc_get_order($order_id); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | return false; |
@@ -221,13 +221,13 @@ discard block |
||
221 | 221 | * @version 4.0.0 |
222 | 222 | * @param string $charge_id |
223 | 223 | */ |
224 | - public static function get_order_by_charge_id( $charge_id ) { |
|
224 | + public static function get_order_by_charge_id($charge_id) { |
|
225 | 225 | global $wpdb; |
226 | 226 | |
227 | - $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id ) ); |
|
227 | + $order_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s", $charge_id)); |
|
228 | 228 | |
229 | - if ( ! empty( $order_id ) ) { |
|
230 | - return wc_get_order( $order_id ); |
|
229 | + if ( ! empty($order_id)) { |
|
230 | + return wc_get_order($order_id); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | return false; |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | * @param string $statement_descriptor |
244 | 244 | * @return string $statement_descriptor Sanitized statement descriptor |
245 | 245 | */ |
246 | - public static function clean_statement_descriptor( $statement_descriptor = '' ) { |
|
247 | - $disallowed_characters = array( '<', '>', '"', "'" ); |
|
246 | + public static function clean_statement_descriptor($statement_descriptor = '') { |
|
247 | + $disallowed_characters = array('<', '>', '"', "'"); |
|
248 | 248 | |
249 | 249 | // Remove special characters. |
250 | - $statement_descriptor = str_replace( $disallowed_characters, '', $statement_descriptor ); |
|
250 | + $statement_descriptor = str_replace($disallowed_characters, '', $statement_descriptor); |
|
251 | 251 | |
252 | - $statement_descriptor = substr( trim( $statement_descriptor ), 0, 22 ); |
|
252 | + $statement_descriptor = substr(trim($statement_descriptor), 0, 22); |
|
253 | 253 | |
254 | 254 | return $statement_descriptor; |
255 | 255 | } |