Skip to content

Commit 2f01e06

Browse files
daledupreezmalithsen
authored andcommitted
Update payment_button_request_size upgrade checks (#4307)
* Update payment_button_request_size upgrade checks * Changelog * Remove error_log() debugging * Update and expand existing unit tests * Remove unnecessary tests
1 parent c7fe7c5 commit 2f01e06

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
= 9.5.3 - xxxx-xx-xx =
44
* Fix - Reimplement mapping of Express Checkout state values to align with WooCommerce's expected state formats
55
* Tweak - Track charge completed via webhooks in order notes
6+
* Fix - Ensure that we migrate payment_request_button_size=medium on upgrade
67

78
= 9.5.2 - 2025-05-22 =
89
* Add - Implement custom database cache for persistent caching with in-memory optimization.

includes/payment-methods/class-wc-stripe-payment-request.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,13 +2046,19 @@ private function is_payment_request_enabled() {
20462046
public function migrate_button_size() {
20472047
$previous_version = get_option( 'wc_stripe_version' );
20482048

2049-
// Exit if it's a new install or the previous version is already 7.8.0 or greater.
2050-
if ( ! $previous_version || version_compare( $previous_version, '7.8.0', '>=' ) ) {
2049+
// Exit if it's a new install, or if we don't have a stored button size.
2050+
if ( ! $previous_version || ! isset( $this->stripe_settings['payment_request_button_size'] ) ) {
20512051
return;
20522052
}
20532053

2054-
if ( ! isset( $this->stripe_settings['payment_request_button_size'] ) ) {
2055-
return;
2054+
$button_size = $this->stripe_settings['payment_request_button_size'];
2055+
2056+
// If the previous version is already 7.8.0 or greater, exit unless we have 'medium' as the value.
2057+
if ( version_compare( $previous_version, '7.8.0', '>=' ) ) {
2058+
if ( 'medium' !== $button_size ) {
2059+
return;
2060+
}
2061+
// If we have 'medium' as the value, we need to migrate it below.
20562062
}
20572063

20582064
$gateway = woocommerce_gateway_stripe()->get_main_stripe_gateway();
@@ -2061,8 +2067,6 @@ public function migrate_button_size() {
20612067
return;
20622068
}
20632069

2064-
$button_size = $this->stripe_settings['payment_request_button_size'];
2065-
20662070
// If the button was set to the default, it is now the small size (40px). If it was set to medium, it is now the default size (48px).
20672071
if ( 'default' === $button_size ) {
20682072
$this->stripe_settings['payment_request_button_size'] = 'small';

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
114114

115115
* Fix - Reimplement mapping of Express Checkout state values to align with WooCommerce's expected state formats
116116
* Tweak - Track charge completed via webhooks in order notes
117+
* Fix - Ensure that we migrate payment_request_button_size=medium on upgrade
117118

118119
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

tests/phpunit/payment-methods/test-wc-stripe-payment-request.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* These teste make assertions against class WC_Stripe_Payment_Request.
3+
* These tests make assertions against class WC_Stripe_Payment_Request.
44
*
55
* @package WooCommerce_Stripe/Tests/Payment_Request
66
*/
@@ -208,7 +208,8 @@ public function test_migrate_button_size() {
208208
/**
209209
* Migration tests.
210210
*
211-
* Migrating the button size only happens when the plugin is updated from a version pre 7.8.0.
211+
* Migrating the button size only happens when the plugin is updated from a version pre 7.8.0,
212+
* or when the button size is set to 'medium'.
212213
*/
213214
update_option( 'wc_stripe_version', '7.6.0' );
214215

@@ -242,10 +243,46 @@ public function test_migrate_button_size() {
242243
$this->pr->migrate_button_size();
243244
$this->assertEquals( 'large', $this->pr->stripe_settings['payment_request_button_size'] );
244245

245-
// Medium => Medium.
246+
// Medium => default.
247+
$this->pr->stripe_settings = [ 'payment_request_button_size' => 'medium' ];
248+
$this->pr->migrate_button_size();
249+
$this->assertEquals( 'default', $this->pr->stripe_settings['payment_request_button_size'] );
250+
251+
// Small => small.
252+
$this->pr->stripe_settings = [ 'payment_request_button_size' => 'small' ];
253+
$this->pr->migrate_button_size();
254+
$this->assertEquals( 'small', $this->pr->stripe_settings['payment_request_button_size'] );
255+
256+
// Button size not set.
257+
$this->pr->stripe_settings = [];
258+
$this->pr->migrate_button_size();
259+
$this->assertArrayNotHasKey( 'payment_request_button_size', $this->pr->stripe_settings );
260+
$this->assertEmpty( $this->pr->stripe_settings );
261+
262+
/**
263+
* Post-migration tests.
264+
*/
265+
update_option( 'wc_stripe_version', '9.0.0' );
266+
267+
// Default => default.
268+
$this->pr->stripe_settings = [ 'payment_request_button_size' => 'default' ];
269+
$this->pr->migrate_button_size();
270+
$this->assertEquals( 'default', $this->pr->stripe_settings['payment_request_button_size'] );
271+
272+
// Large => large.
273+
$this->pr->stripe_settings = [ 'payment_request_button_size' => 'large' ];
274+
$this->pr->migrate_button_size();
275+
$this->assertEquals( 'large', $this->pr->stripe_settings['payment_request_button_size'] );
276+
277+
// Medium => default.
246278
$this->pr->stripe_settings = [ 'payment_request_button_size' => 'medium' ];
247279
$this->pr->migrate_button_size();
248-
$this->assertEquals( 'medium', $this->pr->stripe_settings['payment_request_button_size'] );
280+
$this->assertEquals( 'default', $this->pr->stripe_settings['payment_request_button_size'] );
281+
282+
// Small => small.
283+
$this->pr->stripe_settings = [ 'payment_request_button_size' => 'small' ];
284+
$this->pr->migrate_button_size();
285+
$this->assertEquals( 'small', $this->pr->stripe_settings['payment_request_button_size'] );
249286

250287
// Button size not set.
251288
$this->pr->stripe_settings = [];

0 commit comments

Comments
 (0)