Skip to content

Commit

Permalink
Merge branch 'develop' into update/9971-simplify-localization-csv-export
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagesh Pai committed Dec 20, 2024
2 parents 25ee905 + 34e3731 commit 4f92bcb
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 9 deletions.
4 changes: 4 additions & 0 deletions changelog/add-9973-enable-pms-from-capabilities
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Enable Payment Methods preselected by NOX after onboarding accounts
5 changes: 5 additions & 0 deletions changelog/add-beta-badge-woopay-theme
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: add
Comment: Adds a label to a gated feature.


4 changes: 4 additions & 0 deletions changelog/fix-9742-blank-overview-page-without-wc-features
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix blank Payments > Overview page when WC onboarding is disabled.
4 changes: 4 additions & 0 deletions changelog/fix-9896-postal-code-label
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Localize postal code check label based on country.
2 changes: 1 addition & 1 deletion client/onboarding/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const isPoEligible = async (
* @return {string | undefined} The MCC code for the selected industry. Will return undefined if no industry is selected.
*/
export const getMccFromIndustry = (): string | undefined => {
const industry = wcSettings.admin.onboarding.profile.industry?.[ 0 ];
const industry = wcSettings.admin?.onboarding?.profile?.industry?.[ 0 ];
if ( ! industry ) {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ exports[`Order details page should match the snapshot - Charge without payment i
<h4
class="payment-method-detail__label"
>
Zip check
Postal code check
</h4>
<p
class="payment-method-detail__value"
Expand Down
5 changes: 4 additions & 1 deletion client/payment-details/payment-method/card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ const CardDetails = ( { charge = {}, isLoading } ) => {

<Detail
isLoading={ isLoading }
label={ __( 'Zip check', 'woocommerce-payments' ) }
label={
/* translators: Label for results of a postal code (ZIP code, in US) check performed by a credit card issuer. */
__( 'Postal code check', 'woocommerce-payments' )
}
>
<Check checked={ postalCodeCheck } />
</Detail>
Expand Down
4 changes: 2 additions & 2 deletions client/payment-details/test/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ exports[`Payment details page should match the snapshot - Charge query param 1`]
aria-busy="true"
class="is-loadable-placeholder is-block"
>
Zip check
Postal code check
</span>
</h4>
<p
Expand Down Expand Up @@ -1144,7 +1144,7 @@ exports[`Payment details page should match the snapshot - Payment Intent query p
<h4
class="payment-method-detail__label"
>
Zip check
Postal code check
</h4>
<p
class="payment-method-detail__value"
Expand Down
12 changes: 12 additions & 0 deletions client/settings/express-checkout-settings/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@
}

.woopay-settings {
&__badge {
background-color: $studio-gray-5;
padding: 0 8px;
border-radius: 2px;
font-size: 12px;
line-height: 20px;
margin-left: 4px;
}
&__global-theme-label {
display: inline-flex;
align-items: center;
}
&__custom-message-wrapper {
position: relative;

Expand Down
15 changes: 11 additions & 4 deletions client/settings/express-checkout-settings/woopay-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,17 @@ const WooPaySettings = ( { section } ) => {
onChange={
updateIsWooPayGlobalThemeSupportEnabled
}
label={ __(
'Enable global theme support',
'woocommerce-payments'
) }
label={
<div className="woopay-settings__global-theme-label">
{ __(
'Enable global theme support',
'woocommerce-payments'
) }
<span className="woopay-settings__badge">
Beta
</span>
</div>
}
help={ interpolateComponents( {
mixedString: __(
'When enabled, WooPay checkout will be themed with your store’s brand colors and fonts. ' +
Expand Down
4 changes: 4 additions & 0 deletions client/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
font-weight: normal;
line-height: 20px;
padding: 4px 0;

@media screen and ( max-width: 470px ) {
flex: 0 0 40%;
}
}

&__value {
Expand Down
30 changes: 30 additions & 0 deletions includes/class-wc-payments-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,21 @@ private function init_stripe_onboarding( string $setup_mode, string $wcpay_conne
$gateway->update_option( 'enabled', 'yes' );
$gateway->update_option( 'test_mode', empty( $onboarding_data['is_live'] ) ? 'yes' : 'no' );

/**
* ==================
* Enforces the update of payment methods to 'enabled' based on the capabilities
* provided during the NOX onboarding process.
*
* @see WC_Payments_Onboarding_Service::update_enabled_payment_methods_ids
* ==================
*/
$capabilities = $this->onboarding_service->get_capabilities_from_request();

// Activate enabled Payment Methods IDs.
if ( ! empty( $capabilities ) ) {
$this->onboarding_service->update_enabled_payment_methods_ids( $gateway, $capabilities );
}

// Store a state after completing KYC for tracks. This is stored temporarily in option because
// user might not have agreed to TOS yet.
update_option( '_wcpay_onboarding_stripe_connected', [ 'is_existing_stripe_account' => true ] );
Expand Down Expand Up @@ -2161,6 +2176,20 @@ private function finalize_connection( string $state, string $mode, array $additi
$gateway->update_option( 'enabled', 'yes' );
$gateway->update_option( 'test_mode', 'live' !== $mode ? 'yes' : 'no' );

/**
* ==================
* Enforces the update of payment methods to 'enabled' based on the capabilities
* provided during the NOX onboarding process.
*
* @see WC_Payments_Onboarding_Service::update_enabled_payment_methods_ids
* ==================
*/
$capabilities = $this->onboarding_service->get_capabilities_from_request();
// Activate enabled Payment Methods IDs.
if ( ! empty( $capabilities ) ) {
$this->onboarding_service->update_enabled_payment_methods_ids( $gateway, $capabilities );
}

// Store a state after completing KYC for tracks. This is stored temporarily in option because
// user might not have agreed to TOS yet.
update_option( '_wcpay_onboarding_stripe_connected', [ 'is_existing_stripe_account' => false ] );
Expand Down Expand Up @@ -2570,6 +2599,7 @@ function (): array {
);
}


/**
* Send a Tracks event.
*
Expand Down
92 changes: 92 additions & 0 deletions includes/class-wc-payments-onboarding-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,22 @@ public function create_embedded_kyc_session( array $self_assessment_data, bool $
);
$actioned_notes = self::get_actioned_notes();

/**
* ==================
* Enforces the update of payment methods to 'enabled' based on the capabilities
* provided during the NOX onboarding process.
*
* @see self::update_enabled_payment_methods_ids
* ==================
*/
$capabilities = $this->get_capabilities_from_request();
$gateway = WC_Payments::get_gateway();

// Activate enabled Payment Methods IDs.
if ( ! empty( $capabilities ) ) {
$this->update_enabled_payment_methods_ids( $gateway, $capabilities );
}

try {
$account_session = $this->payments_api_client->initialize_onboarding_embedded_kyc(
'live' === $setup_mode,
Expand Down Expand Up @@ -1024,4 +1040,80 @@ public function maybe_add_test_drive_settings_to_new_account_request( array $arg

return $args;
}

/**
* Update payment methods to 'enabled' based on the capabilities
* provided during the NOX onboarding process. Merchants can preselect their preferred
* payment methods as part of this flow.
*
* The capabilities are provided in the following format:
*
* [
* 'card' => true,
* 'affirm' => true,
* ...
* ]
*
* @param WC_Payment_Gateway_WCPay $gateway Payment gateway instance.
* @param array $capabilities Provided capabilities.
*/
public function update_enabled_payment_methods_ids( $gateway, $capabilities = [] ): void {
$enabled_gateways = $gateway->get_upe_enabled_payment_method_ids();

$enabled_payment_methods = array_unique(
array_merge(
$enabled_gateways,
$this->exclude_placeholder_payment_methods( $capabilities )
)
);

// Update the gateway option.
$gateway->update_option( 'upe_enabled_payment_method_ids', $enabled_payment_methods );

/**
* Keeps the list of enabled payment method IDs synchronized between the default
* `woocommerce_woocommerce_payments_settings` and duplicates in individual gateway settings.
*/
foreach ( $enabled_payment_methods as $payment_method_id ) {
$payment_gateway = WC_Payments::get_payment_gateway_by_id( $payment_method_id );
if ( $payment_gateway ) {
$payment_gateway->enable();
$payment_gateway->update_option( 'upe_enabled_payment_method_ids', $enabled_payment_methods );
}
}

// If WooPay is enabled, update the gateway option.
if ( ! empty( $capabilities['woopay'] ) ) {
$gateway->update_is_woopay_enabled( true );
}

// If Apple Pay and Google Pay are disabled update the gateway option,
// otherwise they are enabled by default.
if ( empty( $capabilities['apple_google'] ) ) {
$gateway->update_option( 'payment_request', 'no' );
}
}

/**
* Excludes placeholder payment methods and removes duplicates.
*
* WooPay and Apple Pay & Google Pay are considered placeholder payment methods and are excluded.
*
* @param array $payment_methods Array of payment methods to process.
*
* @return array Filtered array of unique payment methods.
*/
private function exclude_placeholder_payment_methods( array $payment_methods ): array {
// Placeholder payment methods.
$excluded_methods = [ 'woopay', 'apple_google' ];

return array_filter(
array_unique(
array_keys( array_filter( $payment_methods ) )
),
function ( $payment_method ) use ( $excluded_methods ) {
return ! in_array( $payment_method, $excluded_methods, true );
}
);
}
}

0 comments on commit 4f92bcb

Please sign in to comment.