🐛 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.
*/
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 ) => {
cleanOptions.push( {
id: item.id,
label: item.label,
description: item.description,
} );
} );
// Ensure that the default option is valid.
let defaultOptionId = responseData.defaultSelectedOptionId;
if ( ! cleanOptions.some( ( item ) => item.id === defaultOptionId ) ) {
defaultOptionId = cleanOptions[ 0 ].id;
}
responseData.shippingOptions = cleanOptions;
return { ...responseData, shippingOptions: cleanOptions };
return {
defaultSelectedOptionId: defaultOptionId,
shippingOptions: cleanOptions,
};
}
/**