🔥 Minor clean-up

This commit is contained in:
Philipp Stracker 2024-08-13 19:34:13 +02:00
parent 3b92eaac81
commit 179c1d6831
No known key found for this signature in database

View file

@ -386,7 +386,6 @@ class GooglepayButton {
updatedData.country_code = transactionInfo.countryCode; updatedData.country_code = transactionInfo.countryCode;
updatedData.currency_code = transactionInfo.currencyCode; updatedData.currency_code = transactionInfo.currencyCode;
updatedData.total_str = transactionInfo.totalPrice;
// Handle unserviceable address. // Handle unserviceable address.
if ( ! updatedData.shipping_options?.shippingOptions?.length ) { if ( ! updatedData.shipping_options?.shippingOptions?.length ) {
@ -425,7 +424,8 @@ class GooglepayButton {
* TODO - Move this to the PaymentButton base class * TODO - Move this to the PaymentButton base class
* *
* @param {string} shippingId - The shipping method ID. * @param {string} shippingId - The shipping method ID.
* @param {Object} shippingData - The PaymentDataRequest object that contains shipping options. * @param {Object} shippingData - The PaymentDataRequest object that
* contains shipping options.
* @param {Array} shippingData.shippingOptions * @param {Array} shippingData.shippingOptions
* @param {string} shippingData.defaultSelectedOptionId * @param {string} shippingData.defaultSelectedOptionId
* *
@ -460,27 +460,6 @@ class GooglepayButton {
return currentOption?.cost ? this.toAmount( currentOption.cost ) : 0; return currentOption?.cost ? this.toAmount( currentOption.cost ) : 0;
} }
/**
* Converts the provided value to a number with configurable precision.
*
* TODO - Move this to the PaymentButton base class
*
* @param {any} value - The value to convert.
* @param {number} [precision=2] - The number of decimal places.
* @return {number} Always a numeric value with the specified precision.
*/
toAmount( value, precision = 2 ) {
const number = Number( value );
if ( isNaN( number ) ) {
return 0;
}
const multiplier = Math.pow( 10, precision );
return Math.round( number * multiplier ) / multiplier;
}
unserviceableShippingAddressError() { unserviceableShippingAddressError() {
return { return {
reason: 'SHIPPING_ADDRESS_UNSERVICEABLE', reason: 'SHIPPING_ADDRESS_UNSERVICEABLE',