Skip to content

Commit

Permalink
Merge release/8.3.1 into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarcosta99 committed Oct 16, 2024
2 parents 45cfbd1 + 4fdf943 commit d3cac61
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 22 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
*** WooPayments Changelog ***

= 8.3.1 - 2024-10-16 =
* Fix - Auto-enabled WooPay for new accounts.
* Fix - Load Stripe with merchant account's key when checking payment method availability.

= 8.3.0 - 2024-10-03 =
* Add - Add compatibility with the buttonAttributes API from Woo Blocks
* Add - Add rate limiter to compatibility data updates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const checkPaymentMethodIsAvailable = memoize(

root.render(
<Elements
stripe={ api.loadStripe() }
stripe={ api.loadStripe( true ) }
options={ {
mode: 'payment',
paymentMethodCreation: 'manual',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@ public function get_embedded_kyc_session( WP_REST_Request $request ) {
$account_session['locale'] = get_user_locale();
}

// Set the onboarding in progress option.
$this->onboarding_service->set_embedded_kyc_in_progress();

return rest_ensure_response( $account_session );
}

Expand Down
12 changes: 7 additions & 5 deletions includes/class-wc-payments-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WC_Payments_Account {
const ONBOARDING_DISABLED_TRANSIENT = 'wcpay_on_boarding_disabled';
const ONBOARDING_STARTED_TRANSIENT = 'wcpay_on_boarding_started';
const ONBOARDING_STATE_TRANSIENT = 'wcpay_stripe_onboarding_state';
const WOOPAY_ENABLED_BY_DEFAULT_TRANSIENT = 'woopay_enabled_by_default';
const EMBEDDED_KYC_IN_PROGRESS_OPTION = 'wcpay_onboarding_embedded_kyc_in_progress';
const ERROR_MESSAGE_TRANSIENT = 'wcpay_error_message';
const INSTANT_DEPOSITS_REMINDER_ACTION = 'wcpay_instant_deposit_reminder';
Expand Down Expand Up @@ -1618,7 +1619,7 @@ private function cleanup_on_account_reset() {
delete_transient( self::ONBOARDING_STATE_TRANSIENT );
delete_transient( self::ONBOARDING_STARTED_TRANSIENT );
delete_option( self::EMBEDDED_KYC_IN_PROGRESS_OPTION );
delete_transient( 'woopay_enabled_by_default' );
delete_transient( self::WOOPAY_ENABLED_BY_DEFAULT_TRANSIENT );

// Clear the cache to avoid stale data.
$this->clear_cache();
Expand Down Expand Up @@ -1910,7 +1911,8 @@ private function init_stripe_onboarding( string $setup_mode, string $wcpay_conne

// Clean up any existing onboarding state.
delete_transient( self::ONBOARDING_STATE_TRANSIENT );
delete_option( self::EMBEDDED_KYC_IN_PROGRESS_OPTION );
// Clear the embedded KYC in progress option, since the onboarding flow is now complete.
$this->onboarding_service->clear_embedded_kyc_in_progress();

return add_query_arg(
[ 'wcpay-connection-success' => '1' ],
Expand All @@ -1920,7 +1922,7 @@ private function init_stripe_onboarding( string $setup_mode, string $wcpay_conne

// We have an account that needs to be verified (has a URL to redirect the merchant to).
// Store the relevant onboarding data.
set_transient( 'woopay_enabled_by_default', isset( $onboarding_data['woopay_enabled_by_default'] ) ?? false, DAY_IN_SECONDS );
set_transient( self::WOOPAY_ENABLED_BY_DEFAULT_TRANSIENT, filter_var( $onboarding_data['woopay_enabled_by_default'] ?? false, FILTER_VALIDATE_BOOLEAN ), DAY_IN_SECONDS );
// Save the onboarding state for a day.
// This is used to verify the state when finalizing the onboarding and connecting the account.
// On finalizing the onboarding, the transient gets deleted.
Expand All @@ -1937,9 +1939,9 @@ public function maybe_activate_woopay() {
return;
}

if ( get_transient( 'woopay_enabled_by_default' ) ) {
if ( get_transient( self::WOOPAY_ENABLED_BY_DEFAULT_TRANSIENT ) ) {
WC_Payments::get_gateway()->update_is_woopay_enabled( true );
delete_transient( 'woopay_enabled_by_default' );
delete_transient( self::WOOPAY_ENABLED_BY_DEFAULT_TRANSIENT );
}
}

Expand Down
19 changes: 15 additions & 4 deletions includes/class-wc-payments-onboarding-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ function () use ( $locale ) {
*
* @return array Session data.
*
* @throws API_Exception
* @throws API_Exception|Exception
*/
public function create_embedded_kyc_session( array $self_assessment_data, bool $progressive = false ): array {
if ( ! $this->payments_api_client->is_server_connected() ) {
return [];
}

$setup_mode = WC_Payments::mode()->is_live() ? 'live' : 'test';

// Make sure the onboarding test mode DB flag is set.
Expand Down Expand Up @@ -193,6 +194,16 @@ public function create_embedded_kyc_session( array $self_assessment_data, bool $
return [];
}

// Set the embedded KYC in progress flag.
$this->set_embedded_kyc_in_progress();

// Remember if we should enable WooPay by default.
set_transient(
WC_Payments_Account::WOOPAY_ENABLED_BY_DEFAULT_TRANSIENT,
filter_var( $account_session['woopay_enabled_by_default'] ?? false, FILTER_VALIDATE_BOOLEAN ),
DAY_IN_SECONDS
);

return [
'clientSecret' => $account_session['client_secret'] ?? '',
'expiresAt' => $account_session['expires_at'] ?? 0,
Expand Down Expand Up @@ -230,7 +241,7 @@ public function finalize_embedded_kyc( string $locale, string $source, array $ac
throw new API_Exception( __( 'Failed to finalize onboarding session.', 'woocommerce-payments' ), 'wcpay-onboarding-finalize-error', 400 );
}

// Clear the onboarding in progress option, since the onboarding flow is now complete.
// Clear the embedded KYC in progress option, since the onboarding flow is now complete.
$this->clear_embedded_kyc_in_progress();

return [
Expand Down Expand Up @@ -322,7 +333,7 @@ public function add_admin_body_classes( string $classes = '' ): string {
}

/**
* Get account data for onboarding from self assestment data.
* Get account data for onboarding from self assessment data.
*
* @param string $setup_mode Setup mode.
* @param array $self_assessment_data Self assessment data.
Expand Down Expand Up @@ -424,7 +435,7 @@ public function get_onboarding_user_data(): array {
* @return bool True if embedded KYC is in progress, false otherwise.
*/
public function is_embedded_kyc_in_progress(): bool {
return in_array( get_option( WC_Payments_Account::EMBEDDED_KYC_IN_PROGRESS_OPTION, 'no' ), [ 'yes', '1' ], true );
return filter_var( get_option( WC_Payments_Account::EMBEDDED_KYC_IN_PROGRESS_OPTION, 'no' ), FILTER_VALIDATE_BOOLEAN );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "woocommerce-payments",
"version": "8.3.0",
"version": "8.3.1",
"main": "webpack.config.js",
"author": "Automattic",
"license": "GPL-3.0-or-later",
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: woocommerce payments, apple pay, credit card, google pay, payment, payment
Requires at least: 6.0
Tested up to: 6.6
Requires PHP: 7.3
Stable tag: 8.3.0
Stable tag: 8.3.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -94,6 +94,11 @@ Please note that our support for the checkout block is still experimental and th

== Changelog ==

= 8.3.1 - 2024-10-16 =
* Fix - Auto-enabled WooPay for new accounts.
* Fix - Load Stripe with merchant account's key when checking payment method availability.


= 8.3.0 - 2024-10-03 =
* Add - Add compatibility with the buttonAttributes API from Woo Blocks
* Add - Add rate limiter to compatibility data updates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,6 @@ public function test_get_embedded_kyc_session() {
$kyc_session
);

$this->mock_onboarding_service
->expects( $this->once() )
->method( 'set_embedded_kyc_in_progress' );

$request = new WP_REST_Request( 'GET' );
$request->set_query_params(
[
Expand Down
116 changes: 116 additions & 0 deletions tests/unit/test-class-wc-payments-onboarding-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPUnit\Framework\MockObject\MockObject;
use WCPay\Constants\Country_Code;
use WCPay\Database_Cache;
use WCPay\Exceptions\API_Exception;

/**
* WC_Payments_Onboarding_Service unit tests.
Expand Down Expand Up @@ -148,6 +149,121 @@ public function test_filters_registered_properly() {
$this->assertNotFalse( has_filter( 'admin_body_class', [ $this->onboarding_service, 'add_admin_body_classes' ] ) );
}

public function test_create_embedded_kyc_session() {
// Arrange.
$this->mock_api_client
->method( 'is_server_connected' )
->willReturn( true );

$expected_account_session = [
'client_secret' => 'secret',
'expires_at' => time() + 3600,
'account_id' => 'acc_123',
'is_live' => true,
'account_created' => true,
'publishable_key' => 'pk_test_123',
'woopay_enabled_by_default' => true,
];

$this->mock_api_client
->method( 'initialize_onboarding_embedded_kyc' )
->willReturn( $expected_account_session );

$this->onboarding_service->clear_embedded_kyc_in_progress();

delete_transient( WC_Payments_Account::WOOPAY_ENABLED_BY_DEFAULT_TRANSIENT );

// Act.
$result = $this->onboarding_service->create_embedded_kyc_session( [], false );

// Assert.
$this->assertEquals( $expected_account_session['client_secret'], $result['clientSecret'] );
$this->assertEquals( $expected_account_session['expires_at'], $result['expiresAt'] );
$this->assertEquals( $expected_account_session['account_id'], $result['accountId'] );
$this->assertEquals( $expected_account_session['is_live'], $result['isLive'] );
$this->assertEquals( $expected_account_session['account_created'], $result['accountCreated'] );
$this->assertEquals( $expected_account_session['publishable_key'], $result['publishableKey'] );

$this->assertTrue( $this->onboarding_service->is_embedded_kyc_in_progress() );
$this->assertTrue( get_transient( WC_Payments_Account::WOOPAY_ENABLED_BY_DEFAULT_TRANSIENT ) );
}

public function test_create_embedded_kyc_session_no_wpcom_connection() {
// Arrange.
$this->mock_api_client
->method( 'is_server_connected' )
->willReturn( false );

// Act.
$result = $this->onboarding_service->create_embedded_kyc_session( [], false );

// Assert.
$this->assertEmpty( $result );
}

public function test_finalize_embedded_kyc() {
// Arrange.
$this->mock_api_client
->method( 'is_server_connected' )
->willReturn( true );

$expected_result = [
'success' => true,
'account_id' => 'acc_id',
'details_submitted' => true,
'mode' => 'test',
'promotion_id' => 'promotion_id',
];
$this->mock_api_client
->method( 'finalize_onboarding_embedded_kyc' )
->willReturn( $expected_result );

$this->onboarding_service->set_embedded_kyc_in_progress();

// Act.
$result = $this->onboarding_service->finalize_embedded_kyc( 'en_US', 'source', [] );

// Assert.
$this->assertEquals( $expected_result['success'], $result['success'] );
$this->assertEquals( $expected_result['account_id'], $result['account_id'] );
$this->assertEquals( $expected_result['details_submitted'], $result['details_submitted'] );
$this->assertEquals( $expected_result['mode'], $result['mode'] );
$this->assertEquals( $expected_result['promotion_id'], $result['promotion_id'] );

$this->assertFalse( $this->onboarding_service->is_embedded_kyc_in_progress() );
}

public function test_finalize_embedded_kyc_no_wpcom_connection() {
// Arrange.
$this->mock_api_client
->method( 'is_server_connected' )
->willReturn( false );

// Act.
$result = $this->onboarding_service->finalize_embedded_kyc( 'en_US', 'source', [] );

// Assert.
$this->assertEquals( [ 'success' => false ], $result );
}

public function test_finalize_embedded_kyc_no_success() {
// Arrange.
$this->mock_api_client
->method( 'is_server_connected' )
->willReturn( true );

$this->mock_api_client
->method( 'finalize_onboarding_embedded_kyc' )
->willReturn( [ 'success' => false ] );

// Assert.
$this->expectException( API_Exception::class );
$this->expectExceptionMessage( 'Failed to finalize onboarding session.' );

// Act.
$this->onboarding_service->finalize_embedded_kyc( 'en_US', 'source', [] );
}

public function test_get_cached_business_types_with_no_server_connection() {
$this->mock_api_client
->expects( $this->once() )
Expand Down
2 changes: 1 addition & 1 deletion woocommerce-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* WC tested up to: 9.3.1
* Requires at least: 6.0
* Requires PHP: 7.3
* Version: 8.3.0
* Version: 8.3.1
* Requires Plugins: woocommerce
*
* @package WooCommerce\Payments
Expand Down

0 comments on commit d3cac61

Please sign in to comment.