Skip to content

Commit

Permalink
Merge branch 'develop' into fix/optimise-capture-charge-calls
Browse files Browse the repository at this point in the history
  • Loading branch information
anu-rock authored Sep 28, 2023
2 parents 19184ee + 07dc42b commit 77ca53d
Show file tree
Hide file tree
Showing 36 changed files with 757 additions and 188 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*** WooPayments Changelog ***

= 6.5.1 - 2023-09-26 =
* Fix - fix incorrect payment method title for non-WooPayments gateways

= 6.5.0 - 2023-09-21 =
* Add - Add a new task prompt to set up APMs after onboarding. Fixed an issue where a notice would show up in some unintended circumstances on the APM setup.
* Add - Add an option on the Settings screen to enable merchants to migrate their Stripe Billing subscriptions to on-site billing.
Expand Down
4 changes: 4 additions & 0 deletions changelog/add-feature-flag-check-for-pay-for-order-flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: add

Add the feature flag check for pay-for-order flow
5 changes: 5 additions & 0 deletions changelog/fix-7191-dispute-resolution-footer-inquiries
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: add
Comment: Behind feature flag: Show dispute resolution footer for inquiries under review or closed.


Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Comment: Behind a feature flag: Update documentation links (new/changed docs content) when notifying merchant that a dispute needs response.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix WooPay express checkout button with product bundles on product page.
4 changes: 4 additions & 0 deletions changelog/fix-init-woopay-error
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix init WooPay and empty cart error
4 changes: 4 additions & 0 deletions changelog/fix-woopay-billing-phone-fallback
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

WooPay save my info phone number fallback for virtual products
4 changes: 4 additions & 0 deletions changelog/fix-woopay-multiple-redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Prevent WooPay multiple redirect requests.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: update

Adapt the PO congratulations card copy for pending account status.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: update
Comment: Behind feature flag: show transaction details dispute amount in store's currency


23 changes: 16 additions & 7 deletions client/checkout/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class WCPayAPI {
this.stripe = null;
this.stripePlatform = null;
this.request = request;
this.isWooPayRequesting = false;
}

createStripe( publishableKey, locale, accountId = '', betas = [] ) {
Expand Down Expand Up @@ -688,13 +689,21 @@ export default class WCPayAPI {
}

initWooPay( userEmail, woopayUserSession ) {
const wcAjaxUrl = getConfig( 'wcAjaxUrl' );
const nonce = getConfig( 'initWooPayNonce' );
return this.request( buildAjaxURL( wcAjaxUrl, 'init_woopay' ), {
_wpnonce: nonce,
email: userEmail,
user_session: woopayUserSession,
} );
if ( ! this.isWooPayRequesting ) {
this.isWooPayRequesting = true;
const wcAjaxUrl = getConfig( 'wcAjaxUrl' );
const nonce = getConfig( 'initWooPayNonce' );
return this.request( buildAjaxURL( wcAjaxUrl, 'init_woopay' ), {
_wpnonce: nonce,
email: userEmail,
user_session: woopayUserSession,
order_id: getConfig( 'order_id' ),
key: getConfig( 'key' ),
billing_email: getConfig( 'billing_email' ),
} ).finally( () => {
this.isWooPayRequesting = false;
} );
}
}

expressCheckoutAddToCart( productData ) {
Expand Down
42 changes: 38 additions & 4 deletions client/checkout/api/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import request from 'wcpay/checkout/utils/request';
import { buildAjaxURL } from 'wcpay/payment-request/utils';
import { getConfig } from 'wcpay/utils/checkout';

jest.mock( 'wcpay/checkout/utils/request', () => jest.fn() );
jest.mock( 'wcpay/checkout/utils/request', () =>
jest.fn( () => Promise.resolve( {} ).finally( () => {} ) )
);
jest.mock( 'wcpay/payment-request/utils', () => ( {
buildAjaxURL: jest.fn(),
} ) );
Expand All @@ -15,17 +17,49 @@ jest.mock( 'wcpay/utils/checkout', () => ( {
} ) );

describe( 'WCPayAPI', () => {
test( 'initializes woopay using config params', () => {
test( 'does not initialize woopay if already requesting', async () => {
buildAjaxURL.mockReturnValue( 'https://example.org/' );
getConfig.mockReturnValue( 'foo' );
getConfig.mockImplementation( ( key ) => {
const mockProperties = {
initWooPayNonce: 'foo',
order_id: 1,
key: 'testkey',
billing_email: '[email protected]',
};
return mockProperties[ key ];
} );

const api = new WCPayAPI( {}, request );
api.isWooPayRequesting = true;
await api.initWooPay( '[email protected]', 'qwerty123' );

expect( request ).not.toHaveBeenCalled();
expect( api.isWooPayRequesting ).toBe( true );
} );

test( 'initializes woopay using config params', async () => {
buildAjaxURL.mockReturnValue( 'https://example.org/' );
getConfig.mockImplementation( ( key ) => {
const mockProperties = {
initWooPayNonce: 'foo',
order_id: 1,
key: 'testkey',
billing_email: '[email protected]',
};
return mockProperties[ key ];
} );

const api = new WCPayAPI( {}, request );
api.initWooPay( '[email protected]', 'qwerty123' );
await api.initWooPay( '[email protected]', 'qwerty123' );

expect( request ).toHaveBeenLastCalledWith( 'https://example.org/', {
_wpnonce: 'foo',
email: '[email protected]',
user_session: 'qwerty123',
order_id: 1,
key: 'testkey',
billing_email: '[email protected]',
} );
expect( api.isWooPayRequesting ).toBe( false );
} );
} );
3 changes: 3 additions & 0 deletions client/checkout/woopay/email-input-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ export const handleWooPayEmailInput = async (
buildAjaxURL( getConfig( 'wcAjaxUrl' ), 'get_woopay_session' ),
{
_ajax_nonce: getConfig( 'woopaySessionNonce' ),
order_id: getConfig( 'order_id' ),
key: getConfig( 'key' ),
billing_email: getConfig( 'billing_email' ),
}
).then( ( response ) => {
if ( response?.data?.session ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export const expressCheckoutIframe = async ( api, context, emailSelector ) => {
buildAjaxURL( getConfig( 'wcAjaxUrl' ), 'get_woopay_session' ),
{
_ajax_nonce: getConfig( 'woopaySessionNonce' ),
order_id: getConfig( 'order_id' ),
key: getConfig( 'key' ),
billing_email: getConfig( 'billing_email' ),
}
).then( ( response ) => {
if ( response?.data?.session ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ jest.mock( 'tracks', () => ( {

jest.mock( '../use-express-checkout-product-handler', () => jest.fn() );

jest.spyOn( window, 'alert' ).mockImplementation( () => {} );

global.window.wc_add_to_cart_variation_params = {
i18n_make_a_selection_text: 'Mock text',
};

describe( 'WoopayExpressCheckoutButton', () => {
const buttonSettings = {
type: 'default',
Expand Down Expand Up @@ -116,24 +122,7 @@ describe( 'WoopayExpressCheckoutButton', () => {
} );

describe( 'Product Page', () => {
test( 'should enable the button when add to cart button is enabled', () => {
render(
<WoopayExpressCheckoutButton
isPreview={ false }
buttonSettings={ buttonSettings }
api={ api }
isProductPage={ true }
emailSelector="#email"
/>
);

const expressButton = screen.queryByRole( 'button', {
name: 'WooPay',
} );
expect( expressButton ).toBeEnabled();
} );

test( 'should disable the button when add to cart button is disabled', () => {
test( 'should shown an alert when clicking the button when add to cart button is disabled', () => {
useExpressCheckoutProductHandler.mockImplementation( () => ( {
addToCart: mockAddToCart,
isAddToCartDisabled: true,
Expand All @@ -152,7 +141,13 @@ describe( 'WoopayExpressCheckoutButton', () => {
const expressButton = screen.queryByRole( 'button', {
name: 'WooPay',
} );
expect( expressButton ).toBeDisabled();

userEvent.click( expressButton );

expect( window.alert ).toBeCalledWith(
window.wc_add_to_cart_variation_params
.i18n_make_a_selection_text
);
} );

test( 'call `addToCart` and `expressCheckoutIframe` on express button click on product page', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,48 @@ const useExpressCheckoutProductHandler = ( api, isProductPage = false ) => {
};

const getProductData = () => {
let productId = document.querySelector( '.single_add_to_cart_button' )
const productId = document.querySelector( '.single_add_to_cart_button' )
.value;

// Check if product is a bundle product.
const bundleForm = document.querySelector( '.bundle_form' );
// Check if product is a variable product.
const variation = document.querySelector( '.single_variation_wrap' );
if ( variation ) {
productId = variation.querySelector( 'input[name="product_id"]' )
.value;
}

const data = {
let data = {
product_id: productId,
qty: document.querySelector( '.quantity .qty' ).value,
attributes: document.querySelector( '.variations_form' )
? getAttributes()
: [],
};

if ( variation && ! bundleForm ) {
data.product_id = variation.querySelector(
'input[name="product_id"]'
).value;
data.attributes = document.querySelector( '.variations_form' )
? getAttributes()
: [];
} else {
const formData = new FormData(
document.querySelector( 'form.cart' )
);

// Remove add-to-cart attribute to prevent redirection
// when "Redirect to the cart page after successful addition"
// option is enabled.
formData.delete( 'add-to-cart' );

const attributes = {};

for ( const fields of formData.entries() ) {
attributes[ fields[ 0 ] ] = fields[ 1 ];
}

data = {
...data,
...attributes,
};
}

const addOnForm = document.querySelector( 'form.cart' );

if ( addOnForm ) {
Expand Down Expand Up @@ -133,31 +157,60 @@ const useExpressCheckoutProductHandler = ( api, isProductPage = false ) => {
addToCartButton.classList.contains( 'disabled' )
);
};

setIsAddToCartDisabled( getIsAddToCartDisabled() );

const onVariationChange = () =>
setIsAddToCartDisabled( getIsAddToCartDisabled() );
const enableAddToCartButton = () => {
setIsAddToCartDisabled( false );
};

const disableAddToCartButton = () => {
setIsAddToCartDisabled( true );
};

const variationList = document.querySelector( '.variations_form' );
const bundleForm = document.querySelector( '.bundle_form' );
const variationForm = document.querySelector( '.variations_form' );

if ( variationList ) {
variationList.addEventListener( 'change', onVariationChange );
if ( bundleForm ) {
// eslint-disable-next-line no-undef
jQuery( bundleForm )
.on( 'woocommerce-product-bundle-show', enableAddToCartButton )
.on(
'woocommerce-product-bundle-hide',
disableAddToCartButton
);
} else if ( variationForm ) {
// eslint-disable-next-line no-undef
jQuery( variationForm )
.on( 'show_variation', enableAddToCartButton )
.on( 'hide_variation', disableAddToCartButton );
}

return () => {
if ( variationList ) {
variationList.removeEventListener(
'change',
onVariationChange
);
if ( bundleForm ) {
// eslint-disable-next-line no-undef
jQuery( bundleForm )
.off(
'woocommerce-product-bundle-show',
enableAddToCartButton
)
.off(
'woocommerce-product-bundle-hide',
disableAddToCartButton
);
} else if ( variationForm ) {
// eslint-disable-next-line no-undef
jQuery( variationForm )
.off( 'show_variation', enableAddToCartButton )
.off( 'hide_variation', disableAddToCartButton );
}
};
}, [ isProductPage, setIsAddToCartDisabled ] );

return {
addToCart: addToCart,
getProductData: getProductData,
isAddToCartDisabled: isAddToCartDisabled,
addToCart,
getProductData,
isAddToCartDisabled,
};
};

Expand Down
Loading

0 comments on commit 77ca53d

Please sign in to comment.