🐛 Fix bug with defaultShippingId

This commit is contained in:
Philipp Stracker 2024-09-04 12:02:23 +02:00
parent d370f70d86
commit b3a05ae3d8
No known key found for this signature in database

View file

@ -557,19 +557,23 @@ class GooglepayButton extends PaymentButton {
* @return {Object} Sanitized object. * @return {Object} Sanitized object.
*/ */
sanitizeShippingOptions( responseData ) { sanitizeShippingOptions( responseData ) {
const cleanOptions = []; // Sanitize the shipping options.
const cleanOptions = responseData.shippingOptions.map( ( item ) => ( {
id: item.id,
label: item.label,
description: item.description,
} ) );
responseData.shippingOptions.forEach( ( item ) => { // Ensure that the default option is valid.
cleanOptions.push( { let defaultOptionId = responseData.defaultSelectedOptionId;
id: item.id, if ( ! cleanOptions.some( ( item ) => item.id === defaultOptionId ) ) {
label: item.label, defaultOptionId = cleanOptions[ 0 ].id;
description: item.description, }
} );
} );
responseData.shippingOptions = cleanOptions; return {
defaultSelectedOptionId: defaultOptionId,
return { ...responseData, shippingOptions: cleanOptions }; shippingOptions: cleanOptions,
};
} }
/** /**