mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-08 21:52:55 +08:00
🐛 Fix bug with defaultShippingId
This commit is contained in:
parent
d370f70d86
commit
b3a05ae3d8
1 changed files with 15 additions and 11 deletions
|
@ -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,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue