Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into add/7245-transaction-details-inquiry-step…
Browse files Browse the repository at this point in the history
…s-to-resolve
Jinksi authored Oct 3, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents cbdad3e + 1eadff7 commit 748f5c7
Showing 150 changed files with 1,799 additions and 583 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.
4 changes: 4 additions & 0 deletions changelog/add-2094-pass-checkout-data-before-auth
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add functionality to enable WooPay first party auth behind feature flag.
4 changes: 4 additions & 0 deletions changelog/add-constructor-hooks-sniffer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Migrate away from hooking into actions in certain classes
4 changes: 4 additions & 0 deletions changelog/add-documentation-for-cancel-authorization-endpoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: add

Added docs for cancel_authorization endpoint
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Move fraud related service hooks out of class constructors and into new init_hooks methods.
4 changes: 4 additions & 0 deletions changelog/fix-5945-add-default-cc-enabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix Apple Pay and Google Pay if card payments are disabled.
4 changes: 4 additions & 0 deletions changelog/fix-6819-payment-method-messaging-invalid-value
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Improved product details script with enhanced price calculation, and fallbacks for potential undefined values.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Refactored request class send() method
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.
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-optimise-capture-charge-calls
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Speed up capturing terminal and authorized payments.
4 changes: 4 additions & 0 deletions changelog/fix-tracking-conditions
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Tracking conditions
5 changes: 5 additions & 0 deletions changelog/rpp-container-exceptions
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Adding proper exceptions to the depenedency container.


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.
4 changes: 4 additions & 0 deletions changelog/update-7000-improve-analytics-call-performance
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Store customer currencies as an option to avoid expensive calculation.
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


3 changes: 3 additions & 0 deletions client/checkout/api/index.js
Original file line number Diff line number Diff line change
@@ -697,6 +697,9 @@ export default class WCPayAPI {
_wpnonce: nonce,
email: userEmail,
user_session: woopayUserSession,
order_id: getConfig( 'order_id' ),
key: getConfig( 'key' ),
billing_email: getConfig( 'billing_email' ),
} ).finally( () => {
this.isWooPayRequesting = false;
} );
23 changes: 21 additions & 2 deletions client/checkout/api/test/index.test.js
Original file line number Diff line number Diff line change
@@ -19,7 +19,15 @@ jest.mock( 'wcpay/utils/checkout', () => ( {
describe( 'WCPayAPI', () => {
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: 'test@example.com',
};
return mockProperties[ key ];
} );

const api = new WCPayAPI( {}, request );
api.isWooPayRequesting = true;
@@ -31,7 +39,15 @@ describe( 'WCPayAPI', () => {

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

const api = new WCPayAPI( {}, request );
await api.initWooPay( 'foo@bar.com', 'qwerty123' );
@@ -40,6 +56,9 @@ describe( 'WCPayAPI', () => {
_wpnonce: 'foo',
email: 'foo@bar.com',
user_session: 'qwerty123',
order_id: 1,
key: 'testkey',
billing_email: 'test@example.com',
} );
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
@@ -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 ) {
61 changes: 14 additions & 47 deletions client/checkout/woopay/express-button/express-checkout-iframe.js
Original file line number Diff line number Diff line change
@@ -2,8 +2,13 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { getConfig } from 'utils/checkout';
import request from 'wcpay/checkout/utils/request';
import { showErrorMessage } from 'wcpay/checkout/woopay/express-button/utils';
import { buildAjaxURL } from 'wcpay/payment-request/utils';
import {
getTargetElement,
@@ -96,6 +101,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 ) {
@@ -126,52 +134,6 @@ export const expressCheckoutIframe = async ( api, context, emailSelector ) => {
// Add the iframe to the wrapper.
iframeWrapper.insertBefore( iframe, null );

const showErrorMessage = () => {
// Set the notice text.
const errorMessage = __(
'WooPay is unavailable at this time. Sorry for the inconvenience.',
'woocommerce-payments'
);

// Handle Blocks Cart and Checkout notices.
if ( wcSettings.wcBlocksConfig && context !== 'product' ) {
// This handles adding the error notice to the cart page.
wp.data
.dispatch( 'core/notices' )
?.createNotice( 'error', errorMessage, {
context: `wc/${ context }`,
} );
} else {
// We're either on a shortcode cart/checkout or single product page.
fetch( getConfig( 'ajaxUrl' ), {
method: 'POST',
body: new URLSearchParams( {
action: 'woopay_express_checkout_button_show_error_notice',
_ajax_nonce: getConfig( 'woopayButtonNonce' ),
context,
message: errorMessage,
} ),
} )
.then( ( response ) => response.json() )
.then( ( response ) => {
if ( response.success ) {
// We need to manually add the notice to the page.
const noticesWrapper = document.querySelector(
'.woocommerce-notices-wrapper'
);
const wrapper = document.createElement( 'div' );
wrapper.innerHTML = response.data.notice;
noticesWrapper.insertBefore( wrapper, null );

noticesWrapper.scrollIntoView( {
behavior: 'smooth',
block: 'center',
} );
}
} );
}
};

const closeIframe = () => {
window.removeEventListener( 'resize', getWindowSize );
window.removeEventListener( 'resize', setPopoverPosition );
@@ -279,7 +241,12 @@ export const expressCheckoutIframe = async ( api, context, emailSelector ) => {
response.url
);
} else {
showErrorMessage();
// Set the notice text.
const errorMessage = __(
'WooPay is unavailable at this time. Sorry for the inconvenience.',
'woocommerce-payments'
);
showErrorMessage( context, errorMessage );
closeIframe( false );
}
} );
42 changes: 37 additions & 5 deletions client/checkout/woopay/express-button/index.js
Original file line number Diff line number Diff line change
@@ -13,7 +13,9 @@ import WCPayAPI from '../../api';
import request from '../../utils/request';
import '../../express-checkout-buttons.scss';

const renderWooPayExpressCheckoutButton = () => {
const oldWoopayContainers = [];

const renderWooPayExpressCheckoutButton = ( listenForCartChanges = {} ) => {
// Create an API object, which will be used throughout the checkout.
const api = new WCPayAPI(
{
@@ -28,8 +30,17 @@ const renderWooPayExpressCheckoutButton = () => {
const woopayContainer = document.getElementById( 'wcpay-woopay-button' );

if ( woopayContainer ) {
while ( oldWoopayContainers.length > 0 ) {
// Ensure previous buttons are unmounted and cleaned up.
const oldWoopayContainer = oldWoopayContainers.pop();
ReactDOM.unmountComponentAtNode( oldWoopayContainer );
}

oldWoopayContainers.push( woopayContainer );

ReactDOM.render(
<WoopayExpressCheckoutButton
listenForCartChanges={ listenForCartChanges }
buttonSettings={ getConfig( 'woopayButton' ) }
api={ api }
isProductPage={
@@ -42,10 +53,31 @@ const renderWooPayExpressCheckoutButton = () => {
}
};

window.addEventListener( 'load', renderWooPayExpressCheckoutButton );
let listenForCartChanges = null;
const renderWooPayExpressCheckoutButtonWithCallbacks = () => {
renderWooPayExpressCheckoutButton( listenForCartChanges );
};

jQuery( ( $ ) => {
$( document.body ).on( 'updated_cart_totals', () => {
renderWooPayExpressCheckoutButton();
} );
listenForCartChanges = {
start: () => {
$( document.body ).on(
'updated_cart_totals',
renderWooPayExpressCheckoutButtonWithCallbacks
);
},
stop: () => {
$( document.body ).off(
'updated_cart_totals',
renderWooPayExpressCheckoutButtonWithCallbacks
);
},
};

listenForCartChanges.start();
} );

window.addEventListener(
'load',
renderWooPayExpressCheckoutButtonWithCallbacks
);
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ jest.mock( '../use-express-checkout-product-handler', () => jest.fn() );

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

global.fetch = jest.fn( () => Promise.resolve( { json: () => ( {} ) } ) );
global.window.wc_add_to_cart_variation_params = {
i18n_make_a_selection_text: 'Mock text',
};
@@ -80,6 +81,9 @@ describe( 'WoopayExpressCheckoutButton', () => {
} );

test( 'call `expressCheckoutIframe` on button click when `isPreview` is false', () => {
getConfig.mockImplementation( ( v ) => {
return v === 'isWoopayFirstPartyAuthEnabled' ? false : 'foo';
} );
render(
<WoopayExpressCheckoutButton
isPreview={ false }
@@ -123,6 +127,9 @@ describe( 'WoopayExpressCheckoutButton', () => {

describe( 'Product Page', () => {
test( 'should shown an alert when clicking the button when add to cart button is disabled', () => {
getConfig.mockImplementation( ( v ) => {
return v === 'isWoopayFirstPartyAuthEnabled' ? false : 'foo';
} );
useExpressCheckoutProductHandler.mockImplementation( () => ( {
addToCart: mockAddToCart,
isAddToCartDisabled: true,
@@ -151,6 +158,9 @@ describe( 'WoopayExpressCheckoutButton', () => {
} );

test( 'call `addToCart` and `expressCheckoutIframe` on express button click on product page', async () => {
getConfig.mockImplementation( ( v ) => {
return v === 'isWoopayFirstPartyAuthEnabled' ? false : 'foo';
} );
useExpressCheckoutProductHandler.mockImplementation( () => ( {
addToCart: mockAddToCart,
getProductData: jest.fn().mockReturnValue( {} ),
@@ -184,6 +194,9 @@ describe( 'WoopayExpressCheckoutButton', () => {
} );

test( 'do not call `addToCart` on express button click on product page when validation fails', async () => {
getConfig.mockImplementation( ( v ) => {
return v === 'isWoopayFirstPartyAuthEnabled' ? false : 'foo';
} );
useExpressCheckoutProductHandler.mockImplementation( () => ( {
addToCart: mockAddToCart,
getProductData: jest.fn().mockReturnValue( false ),
Loading

0 comments on commit 748f5c7

Please sign in to comment.