Skip to content

Commit

Permalink
Merge branch 'develop' into fix/remove-unused-file
Browse files Browse the repository at this point in the history
  • Loading branch information
alefesouza authored Mar 22, 2024
2 parents dc8fab6 + c363808 commit 8ca8453
Show file tree
Hide file tree
Showing 21 changed files with 401 additions and 53 deletions.
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATE/e2e_test_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: e2e test report
about: Report an e2e test failure.
title: ''
labels: ['category: e2e', 'needs triage']
assignees: ''

---

### Description
<!-- Before reporting an issue, are you sure this e2e test is failing consistently? -->
<!-- Add a clear and concise description of what the issue is. Please, be as descriptive as possible. -->
<!-- Make sure you include relevant details such as what test/spec is failing and the link of the job where it started failing. -->

**Output from the test failure**:
<!-- Chunk of the output from the test failure. It doesn't need to be the entire output, just the relevant part. e.g.
TimeoutError: waiting for selector "..." failed: timeout 100000ms exceeded
336 | );
> 337 | const selector = await page.waitForSelector(
| ^
339 | 'selector'
-->

### Additional context
<!-- Any additional context or details you think might be helpful. -->
<!-- Ticket numbers/links, plugin versions, system statuses etc. -->

### Priority
<!-- Add a priority label based on your best judgement (quick is fine). -->
<!-- Optional: add comments here to explain your decision or highlight any questions/potential risks. -->

### Reason why this e2e test is broken
<!-- Add one of the "e2e: broken flow/test/environment" labels based on your best judgement (quick is fine). -->
<!-- Optional: add comments here to explain your decision. -->

> [!Important]
> Please, ensure when closing this issue (PR fix) that only one `e2e: broken` label is added and it is accurate.
> - [ ] I confirmed there's only one `e2e: broken` label in this issue and it is accurate.
<!-- Leave the above for who's fixing this issue. -->
4 changes: 4 additions & 0 deletions changelog/add-account-reset-for-sandboxes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add account reset for sandboxes
4 changes: 4 additions & 0 deletions changelog/add-woopay-merchant-request
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Allow WooPay to request full session data from store.
5 changes: 5 additions & 0 deletions changelog/chore-e2e-test-report-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Create e2e test report issue template.


4 changes: 0 additions & 4 deletions changelog/dev-4710-remove-deposit-status

This file was deleted.

4 changes: 4 additions & 0 deletions changelog/fix-cursor-pointer-for-disabled-logging
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Fix the cursor pointer when hovering over disabled checkboxes in Advanced Settings
5 changes: 5 additions & 0 deletions changelog/revert-8376-removed-depositsstatus
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Reverting https://github.com/Automattic/woocommerce-payments/pull/8376 that removes depositsStatus key from account response.


6 changes: 3 additions & 3 deletions client/checkout/woopay/direct-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ window.addEventListener( 'load', async () => {
if ( isThirdPartyCookieEnabled ) {
if ( await WooPayDirectCheckout.isUserLoggedIn() ) {
WooPayDirectCheckout.maybePrefetchEncryptedSessionData();
WooPayDirectCheckout.redirectToWooPay( checkoutElements );
WooPayDirectCheckout.redirectToWooPay( checkoutElements, true );
}

return;
}

// Pass true to append '&checkout_redirect=1' and let WooPay decide the checkout flow.
WooPayDirectCheckout.redirectToWooPay( checkoutElements, true );
// Pass false to indicate we are not sure if the user is logged in or not.
WooPayDirectCheckout.redirectToWooPay( checkoutElements, false );
} );

jQuery( ( $ ) => {
Expand Down
112 changes: 106 additions & 6 deletions client/checkout/woopay/direct-checkout/woopay-direct-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import request from 'wcpay/checkout/utils/request';
import { buildAjaxURL } from 'wcpay/payment-request/utils';
import UserConnect from 'wcpay/checkout/woopay/connect/user-connect';
import SessionConnect from 'wcpay/checkout/woopay/connect/session-connect';
import { getTracksIdentity } from 'tracks';

/**
* The WooPayDirectCheckout class is responsible for injecting the WooPayConnectIframe into the
Expand Down Expand Up @@ -94,11 +95,12 @@ class WooPayDirectCheckout {

/**
* Resolves the redirect URL to the WooPay checkout page or throws an error if the request fails.
* This function should only be called when we have determined the shopper is already logged in to WooPay.
*
* @return {string} The redirect URL.
* @throws {Error} If the session data could not be sent to WooPay.
*/
static async resolveWooPayRedirectUrl() {
static async getWooPayCheckoutUrl() {
// We're intentionally adding a try-catch block to catch any errors
// that might occur other than the known validation errors.
try {
Expand All @@ -121,6 +123,16 @@ class WooPayDirectCheckout {
throw new Error( 'Could not retrieve WooPay checkout URL.' );
}

const { redirect_url: redirectUrl } = woopaySessionData;
if (
! this.validateRedirectUrl(
redirectUrl,
'platform_checkout_key'
)
) {
throw new Error( 'Invalid WooPay session URL: ' + redirectUrl );
}

return woopaySessionData.redirect_url;
} catch ( error ) {
throw new Error( error.message );
Expand All @@ -143,6 +155,46 @@ class WooPayDirectCheckout {
);
}

/**
* Gets the necessary merchant data to create session from WooPay request or throws an error if the request fails.
* This function should only be called if we still need to determine if the shopper is logged into WooPay or not.
*
* @return {string} WooPay redirect URL with parameters.
*/
static async getWooPayMinimumSessionUrl() {
const redirectData = await this.getWooPayMinimumSesssionDataFromMerchant();
if ( redirectData?.success === false ) {
throw new Error(
'Could not retrieve redirect data from merchant.'
);
}

if ( ! this.isValidEncryptedSessionData( redirectData ) ) {
throw new Error( 'Invalid encrypted session data.' );
}

const testMode = getConfig( 'testMode' );
const redirectParams = new URLSearchParams( {
checkout_redirect: 1,
blog_id: redirectData.blog_id,
session: redirectData.data.session,
iv: redirectData.data.iv,
hash: redirectData.data.hash,
testMode,
source_url: window.location.href,
} );

const tracksUserId = await getTracksIdentity();
if ( tracksUserId ) {
redirectParams.append( 'tracksUserIdentity', tracksUserId );
}

const redirectUrl =
getConfig( 'woopayHost' ) + '/woopay/?' + redirectParams.toString();

return redirectUrl;
}

/**
* Gets the checkout redirect elements.
*
Expand Down Expand Up @@ -183,9 +235,9 @@ class WooPayDirectCheckout {
* Adds a click-event listener to the given elements that redirects to the WooPay checkout page.
*
* @param {*[]} elements The elements to add a click-event listener to.
* @param {boolean} useCheckoutRedirect Whether to use the `checkout_redirect` flag to let WooPay handle the checkout flow.
* @param {boolean} userIsLoggedIn True if we determined the user is already logged in, false otherwise.
*/
static redirectToWooPay( elements, useCheckoutRedirect = false ) {
static redirectToWooPay( elements, userIsLoggedIn = false ) {
/**
* Adds a loading spinner to the given element.
*
Expand Down Expand Up @@ -258,9 +310,11 @@ class WooPayDirectCheckout {
event.preventDefault();

try {
let woopayRedirectUrl = await this.resolveWooPayRedirectUrl();
if ( useCheckoutRedirect ) {
woopayRedirectUrl += '&checkout_redirect=1';
let woopayRedirectUrl = '';
if ( userIsLoggedIn ) {
woopayRedirectUrl = await this.getWooPayCheckoutUrl();
} else {
woopayRedirectUrl = await this.getWooPayMinimumSessionUrl();
}

this.teardown();
Expand Down Expand Up @@ -291,6 +345,52 @@ class WooPayDirectCheckout {
);
}

/**
* Gets the WooPay redirect data.
*
* @return {Promise<Promise<*>|*>} Resolves to the WooPay redirect response.
*/
static async getWooPayMinimumSesssionDataFromMerchant() {
// This should always be defined, but fallback to a request in case of the unexpected.
if ( getConfig( 'woopayMinimumSessionData' ) ) {
return getConfig( 'woopayMinimumSessionData' );
}

return request(
buildAjaxURL(
getConfig( 'wcAjaxUrl' ),
'get_woopay_minimum_session_data'
),
{
_ajax_nonce: getConfig( 'woopaySessionNonce' ),
}
);
}

/**
* Validates a WooPay redirect URL.
*
* @param {string} redirectUrl The URL to validate.
* @param {string} requiredParam The URL parameter that is required in the URL.
*
* @return {boolean} True if URL is valid, false otherwise.
*/
static validateRedirectUrl( redirectUrl, requiredParam ) {
try {
const parsedUrl = new URL( redirectUrl );
if (
parsedUrl.origin !== getConfig( 'woopayHost' ) ||
! parsedUrl.searchParams.has( requiredParam )
) {
return false;
}

return true;
} catch ( error ) {
return false;
}
}

/**
* Prefetches the encrypted session data if not on the product page.
*/
Expand Down
3 changes: 0 additions & 3 deletions client/components/account-status/account-tools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { addQueryArgs } from '@wordpress/url';
* Internal dependencies
*/
import strings from './strings';
import { isInDevMode } from 'utils';
import './styles.scss';
import ResetAccountModal from 'wcpay/overview/modal/reset-account';
import { trackAccountReset } from 'wcpay/onboarding/tracking';
Expand All @@ -31,8 +30,6 @@ export const AccountTools: React.FC< Props > = ( props: Props ) => {
const accountLink = props.accountLink;
const [ modalVisible, setModalVisible ] = useState( false );

if ( isInDevMode() ) return null;

return (
<>
<div className="account-tools">
Expand Down
18 changes: 14 additions & 4 deletions client/components/account-status/account-tools/strings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { isInDevMode } from 'utils';

export default {
title: __( 'Account Tools', 'woocommerce-payments' ),
description: __(
'Payments and deposits are disabled until account setup is completed. If you are experiencing problems completing account setup, or need to change the email/country associated with your account, you can reset your account and start from the beginning.',
'woocommerce-payments'
),
description: isInDevMode()
? __(
'Your account is in sandbox mode. If you are experiencing problems completing account setup, or wish to test with a different email/country associated with your account, you can reset your account and start from the beginning.',
'woocommerce-payments'
)
: __(
'Payments and deposits are disabled until account setup is completed. If you are experiencing problems completing account setup, or need to change the email/country associated with your account, you can reset your account and start from the beginning.',
'woocommerce-payments'
),
finish: __( 'Finish setup', 'woocommerce-payments' ),
reset: __( 'Reset account', 'woocommerce-payments' ),
};
3 changes: 2 additions & 1 deletion client/components/account-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import StatusChip from './status-chip';
import './style.scss';
import './shared.scss';
import { AccountTools } from './account-tools';
import { isInDevMode } from 'wcpay/utils';

const AccountStatusCard = ( props ) => {
const { title, children, value } = props;
Expand Down Expand Up @@ -103,7 +104,7 @@ const AccountStatusDetails = ( props ) => {
}
/>
</AccountStatusItem>
{ ! accountStatus.detailsSubmitted && (
{ ( ! accountStatus.detailsSubmitted || isInDevMode() ) && (
<AccountTools accountLink={ accountStatus.accountLink } />
) }
{ accountFees.length > 0 && (
Expand Down
1 change: 1 addition & 0 deletions client/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ declare global {
minimum_manual_deposit_amounts: Record< string, number >;
minimum_scheduled_deposit_amounts: Record< string, number >;
};
depositsStatus?: string;
currentDeadline?: bigint;
detailsSubmitted?: boolean;
pastDue?: boolean;
Expand Down
18 changes: 14 additions & 4 deletions client/overview/modal/reset-account/strings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
*/
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { isInDevMode } from 'utils';

export default {
title: __( 'Reset account', 'woocommerce-payments' ),
description: __(
'If you are experiencing problems completing account setup, or need to change the email/country associated with your account, you can reset your account and start from the beginning.',
'woocommerce-payments'
),
description: isInDevMode()
? __(
'In sandbox mode, you can reset your account and onboard again at any time. Please note that all current WooPayments account details, test transactions, and deposits history will be lost.',
'woocommerce-payments'
)
: __(
'If you are experiencing problems completing account setup, or need to change the email/country associated with your account, you can reset your account and start from the beginning.',
'woocommerce-payments'
),
beforeContinue: __( 'Before you continue', 'woocommerce-payments' ),
step1: sprintf(
/* translators: %s: WooPayments. */
Expand Down
8 changes: 8 additions & 0 deletions client/settings/advanced-settings/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@
margin-bottom: 1em;
}
}

.settings-section__controls {
input[type='checkbox'] {
&:disabled {
cursor: not-allowed;
}
}
}
Loading

0 comments on commit 8ca8453

Please sign in to comment.