🐛 Fix critical Google Pay error

This commit is contained in:
Philipp Stracker 2024-08-23 11:52:00 +02:00
parent fe39793e9a
commit b4cd6bb121
No known key found for this signature in database

View file

@ -515,7 +515,9 @@ class GooglepayButton extends PaymentButton {
)
) {
paymentDataRequestUpdate.newShippingOptionParameters =
updatedData.shipping_options;
this.sanitizeShippingOptions(
updatedData.shipping_options
);
}
if ( updatedData.total && hasRealCart ) {
@ -541,6 +543,30 @@ class GooglepayButton extends PaymentButton {
} );
}
/**
* Google Pay throws an error, when the shippingOptions entries contain
* custom properties. This function strips unsupported properties from the
* provided ajax response.
*
* @param {Object} responseData Data returned from the ajax endpoint.
* @return {Object} Sanitized object.
*/
sanitizeShippingOptions( responseData ) {
const cleanOptions = [];
responseData.shippingOptions.forEach( ( item ) => {
cleanOptions.push( {
id: item.id,
label: item.label,
description: item.description,
} );
} );
responseData.shippingOptions = cleanOptions;
return { ...responseData, shippingOptions: cleanOptions };
}
/**
* Returns the shipping costs as numeric value.
*