Skip to content

Commit 9339c2f

Browse files
committed
Merge remote-tracking branch 'origin/release/6.4.2' into trunk
2 parents c4e1fca + a979623 commit 9339c2f

10 files changed

+102
-33
lines changed

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
*** Changelog ***
22

3+
= 6.4.2 - 2022-06-29 =
4+
* Fix - Fix terminal location creation if site title is missing.
5+
* Fix - Add compatibility with WooCommerce 6.6.
6+
37
= 6.4.1 - 2022-06-01 =
48
* Fix - Ensure proper URL formatting.
59

includes/admin/class-wc-rest-stripe-locations-controller.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ public function get_location( $request ) {
178178
* @param WP_REST_Request $request Full data about the request.
179179
*/
180180
public function get_store_location( $request ) {
181-
$name = get_bloginfo();
181+
// Originally `get_bloginfo` was used for location name, later switched to `site_url` as the former may be blank.
182+
$store_hostname = str_replace( [ 'https://', 'http://' ], '', get_site_url() );
183+
$possible_names = [ get_bloginfo(), $store_hostname ];
182184
$store_address = WC()->countries;
183185
$address = array_filter(
184186
[
@@ -213,7 +215,7 @@ public function get_store_location( $request ) {
213215
try {
214216
foreach ( $this->fetch_locations() as $location ) {
215217
if (
216-
$location->display_name === $name
218+
in_array( $location->display_name, $possible_names, true )
217219
&& count( array_intersect( (array) $location->address, $address ) ) === count( $address )
218220
) {
219221
return rest_ensure_response( $location );
@@ -223,7 +225,7 @@ public function get_store_location( $request ) {
223225
// Create new location if no location matches display name and address.
224226
$response = WC_Stripe_API::request(
225227
[
226-
'display_name' => $name,
228+
'display_name' => $store_hostname,
227229
'address' => $address,
228230
],
229231
'terminal/locations'

includes/admin/class-wc-rest-stripe-settings-controller.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,28 +240,28 @@ public function get_settings() {
240240
/* Settings > General */
241241
'is_stripe_enabled' => $this->gateway->is_enabled(),
242242
'is_test_mode_enabled' => $this->gateway->is_in_test_mode(),
243-
'title' => $this->gateway->get_option( 'title' ),
244-
'title_upe' => $this->gateway->get_option( 'title_upe' ),
245-
'description' => $this->gateway->get_option( 'description' ),
243+
'title' => $this->gateway->get_validated_option( 'title' ),
244+
'title_upe' => $this->gateway->get_validated_option( 'title_upe' ),
245+
'description' => $this->gateway->get_validated_option( 'description' ),
246246

247247
/* Settings > Payments accepted on checkout */
248248
'enabled_payment_method_ids' => $this->gateway->get_upe_enabled_payment_method_ids(),
249249
'available_payment_method_ids' => $this->gateway->get_upe_available_payment_methods(),
250250

251251
/* Settings > Express checkouts */
252252
'is_payment_request_enabled' => 'yes' === $this->gateway->get_option( 'payment_request' ),
253-
'payment_request_button_type' => $this->gateway->get_option( 'payment_request_button_type' ),
254-
'payment_request_button_theme' => $this->gateway->get_option( 'payment_request_button_theme' ),
255-
'payment_request_button_size' => $this->gateway->get_option( 'payment_request_button_size' ),
256-
'payment_request_button_locations' => $this->gateway->get_option( 'payment_request_button_locations' ),
253+
'payment_request_button_type' => $this->gateway->get_validated_option( 'payment_request_button_type' ),
254+
'payment_request_button_theme' => $this->gateway->get_validated_option( 'payment_request_button_theme' ),
255+
'payment_request_button_size' => $this->gateway->get_validated_option( 'payment_request_button_size' ),
256+
'payment_request_button_locations' => $this->gateway->get_validated_option( 'payment_request_button_locations' ),
257257

258258
/* Settings > Payments & transactions */
259259
'is_manual_capture_enabled' => ! $this->gateway->is_automatic_capture_enabled(),
260260
'is_saved_cards_enabled' => 'yes' === $this->gateway->get_option( 'saved_cards' ),
261261
'is_separate_card_form_enabled' => 'no' === $this->gateway->get_option( 'inline_cc_form' ),
262-
'statement_descriptor' => $this->gateway->get_option( 'statement_descriptor' ),
262+
'statement_descriptor' => $this->gateway->get_validated_option( 'statement_descriptor' ),
263263
'is_short_statement_descriptor_enabled' => 'yes' === $this->gateway->get_option( 'is_short_statement_descriptor_enabled' ),
264-
'short_statement_descriptor' => $this->gateway->get_option( 'short_statement_descriptor' ),
264+
'short_statement_descriptor' => $this->gateway->get_validated_option( 'short_statement_descriptor' ),
265265

266266
/* Settings > Advanced settings */
267267
'is_debug_log_enabled' => 'yes' === $this->gateway->get_option( 'logging' ),
@@ -336,7 +336,7 @@ private function update_title( WP_REST_Request $request ) {
336336
return;
337337
}
338338

339-
$this->gateway->update_option( 'title', $title );
339+
$this->gateway->update_validated_option( 'title', $title );
340340
}
341341

342342
/**
@@ -351,7 +351,7 @@ private function update_title_upe( WP_REST_Request $request ) {
351351
return;
352352
}
353353

354-
$this->gateway->update_option( 'title_upe', $title_upe );
354+
$this->gateway->update_validated_option( 'title_upe', $title_upe );
355355
}
356356

357357
/**
@@ -366,7 +366,7 @@ private function update_description( WP_REST_Request $request ) {
366366
return;
367367
}
368368

369-
$this->gateway->update_option( 'description', $description );
369+
$this->gateway->update_validated_option( 'description', $description );
370370
}
371371

372372
/**
@@ -456,7 +456,7 @@ private function update_account_statement_descriptor( WP_REST_Request $request )
456456
return;
457457
}
458458

459-
$this->gateway->update_option( 'statement_descriptor', $account_statement_descriptor );
459+
$this->gateway->update_validated_option( 'statement_descriptor', $account_statement_descriptor );
460460
}
461461

462462
/**
@@ -492,7 +492,7 @@ private function update_short_account_statement_descriptor( WP_REST_Request $req
492492
return;
493493
}
494494

495-
$this->gateway->update_option( 'short_statement_descriptor', $short_account_statement_descriptor );
495+
$this->gateway->update_validated_option( 'short_statement_descriptor', $short_account_statement_descriptor );
496496
}
497497

498498
/**
@@ -553,7 +553,7 @@ private function update_payment_request_settings( WP_REST_Request $request ) {
553553
}
554554

555555
$value = $request->get_param( $request_key );
556-
$this->gateway->update_option( $attribute, $value );
556+
$this->gateway->update_validated_option( $attribute, $value );
557557
}
558558
}
559559

includes/admin/stripe-settings.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
exit;
44
}
55

6+
$is_gte_wc6_6 = defined( WC_VERSION ) && version_compare( WC_VERSION, '6.6', '>=' );
7+
68
$stripe_settings = apply_filters(
79
'wc_stripe_settings',
810
[
@@ -15,14 +17,14 @@
1517
],
1618
'title' => [
1719
'title' => __( 'Title', 'woocommerce-gateway-stripe' ),
18-
'type' => 'text',
20+
'type' => $is_gte_wc6_6 ? 'safe_text' : 'text',
1921
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ),
2022
'default' => __( 'Credit Card (Stripe)', 'woocommerce-gateway-stripe' ),
2123
'desc_tip' => true,
2224
],
2325
'title_upe' => [
2426
'title' => __( 'Title', 'woocommerce-gateway-stripe' ),
25-
'type' => 'text',
27+
'type' => $is_gte_wc6_6 ? 'safe_text' : 'text',
2628
'description' => __( 'This controls the title which the user sees during checkout when multiple payment methods are enabled.', 'woocommerce-gateway-stripe' ),
2729
'default' => __( 'Popular payment methods', 'woocommerce-gateway-stripe' ),
2830
'desc_tip' => true,
@@ -107,6 +109,13 @@
107109
'default' => '',
108110
'desc_tip' => true,
109111
],
112+
'short_statement_descriptor' => [
113+
'title' => __( 'Short Statement Descriptor', 'woocommerce-gateway-stripe' ),
114+
'type' => 'text',
115+
'description' => __( 'Shortened version of the statement descriptor in combination with the customer order number.', 'woocommerce-gateway-stripe' ),
116+
'default' => '',
117+
'desc_tip' => true,
118+
],
110119
'capture' => [
111120
'title' => __( 'Capture', 'woocommerce-gateway-stripe' ),
112121
'label' => __( 'Capture charge immediately', 'woocommerce-gateway-stripe' ),

includes/class-wc-gateway-stripe.php

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ public function __construct() {
9797
$this->maybe_init_pre_orders();
9898

9999
// Get setting values.
100-
$this->title = $this->get_option( 'title' );
101-
$this->description = $this->get_option( 'description' );
100+
$this->title = $this->get_validated_option( 'title' );
101+
$this->description = $this->get_validated_option( 'description' );
102102
$this->enabled = $this->get_option( 'enabled' );
103103
$this->testmode = 'yes' === $this->get_option( 'testmode' );
104104
$this->inline_cc_form = 'yes' === $this->get_option( 'inline_cc_form' );
105105
$this->capture = 'yes' === $this->get_option( 'capture', 'yes' );
106-
$this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_option( 'statement_descriptor' ) );
106+
$this->statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->get_validated_option( 'statement_descriptor' ) );
107107
$this->saved_cards = 'yes' === $this->get_option( 'saved_cards' );
108-
$this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' );
109-
$this->publishable_key = $this->testmode ? $this->get_option( 'test_publishable_key' ) : $this->get_option( 'publishable_key' );
108+
$this->secret_key = $this->testmode ? $this->get_validated_option( 'test_secret_key' ) : $this->get_validated_option( 'secret_key' );
109+
$this->publishable_key = $this->testmode ? $this->get_validated_option( 'test_publishable_key' ) : $this->get_validated_option( 'publishable_key' );
110110
$this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' );
111111

112112
WC_Stripe_API::set_secret_key( $this->secret_key );
@@ -1247,4 +1247,57 @@ public function update_onboarding_settings( $settings ) {
12471247

12481248
return $settings;
12491249
}
1250+
1251+
/**
1252+
* Validates a field value before updating.
1253+
*
1254+
* @param string $field_key the form field key.
1255+
* @param string $field_value the form field value.
1256+
*
1257+
* @return bool True if the value was updated, false otherwise.
1258+
*/
1259+
public function update_validated_option( $field_key, $field_value ) {
1260+
$validated_field_value = $this->validate_field( $field_key, $field_value );
1261+
return $this->update_option( $field_key, $validated_field_value );
1262+
}
1263+
1264+
/**
1265+
* Retrieves validated field value.
1266+
*
1267+
* @param string $field_key the form field key.
1268+
* @param mixed $empty_value fallback value.
1269+
*
1270+
* @return string validated field value.
1271+
*/
1272+
public function get_validated_option( $field_key, $empty_value = null ) {
1273+
$value = parent::get_option( $field_key, $empty_value );
1274+
return $this->validate_field( $field_key, $value );
1275+
}
1276+
1277+
/**
1278+
* Ensures validated field values.
1279+
*
1280+
* @param string $field_key the form field key.
1281+
* @param string $field_value the form field value.
1282+
*
1283+
* @return string validated field value.
1284+
*/
1285+
private function validate_field( $field_key, $field_value ) {
1286+
if ( is_callable( [ $this, 'validate_' . $field_key . '_field' ] ) ) {
1287+
return $this->{'validate_' . $field_key . '_field'}( $field_key, $field_value );
1288+
}
1289+
1290+
if ( empty( $this->form_fields ) ) {
1291+
$this->init_form_fields();
1292+
}
1293+
if ( key_exists( $field_key, $this->form_fields ) ) {
1294+
$field_type = $this->form_fields[ $field_key ]['type'];
1295+
1296+
if ( is_callable( [ $this, 'validate_' . $field_type . '_field' ] ) ) {
1297+
return $this->{'validate_' . $field_type . '_field'}( $field_key, $field_value );
1298+
}
1299+
}
1300+
1301+
return $this->validate_text_field( $field_key, $field_value );
1302+
}
12501303
}

includes/class-wc-stripe-order-handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function process_redirect_payment( $order_id, $retry = true, $previous_er
191191
}
192192

193193
/**
194-
* Processses the orders that are redirected.
194+
* Processes the orders that are redirected.
195195
*
196196
* @since 4.0.0
197197
* @version 4.0.0

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "woocommerce-gateway-stripe",
33
"title": "WooCommerce Gateway Stripe",
4-
"version": "6.4.1",
4+
"version": "6.4.2",
55
"license": "GPL-3.0",
66
"homepage": "http://wordpress.org/plugins/woocommerce-gateway-stripe/",
77
"repository": {

readme.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: credit card, stripe, apple pay, payment request, google pay, sepa, sofort,
44
Requires at least: 5.7
55
Tested up to: 5.9
66
Requires PHP: 7.0
7-
Stable tag: 6.4.1
7+
Stable tag: 6.4.2
88
License: GPLv3
99
License URI: https://www.gnu.org/licenses/gpl-3.0.html
1010
Attributions: thorsten-stripe
@@ -128,7 +128,8 @@ If you get stuck, you can ask for help in the Plugin Forum.
128128

129129
== Changelog ==
130130

131-
= 6.4.1 - 2022-06-01 =
132-
* Fix - Ensure proper URL formatting.
131+
= 6.4.2 - 2022-06-29 =
132+
* Fix - Fix terminal location creation if site title is missing.
133+
* Fix - Add compatibility with WooCommerce 6.6.
133134

134135
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

woocommerce-gateway-stripe.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Take credit card payments on your store using Stripe.
66
* Author: WooCommerce
77
* Author URI: https://woocommerce.com/
8-
* Version: 6.4.1
8+
* Version: 6.4.2
99
* Requires at least: 5.7
1010
* Tested up to: 5.9
1111
* WC requires at least: 6.2
@@ -21,7 +21,7 @@
2121
/**
2222
* Required minimums and constants
2323
*/
24-
define( 'WC_STRIPE_VERSION', '6.4.1' ); // WRCS: DEFINED_VERSION.
24+
define( 'WC_STRIPE_VERSION', '6.4.2' ); // WRCS: DEFINED_VERSION.
2525
define( 'WC_STRIPE_MIN_PHP_VER', '7.0.0' );
2626
define( 'WC_STRIPE_MIN_WC_VER', '6.2' );
2727
define( 'WC_STRIPE_FUTURE_MIN_WC_VER', '6.3' );

0 commit comments

Comments
 (0)