♻️ Embed a function that’s only locally used

This commit is contained in:
Philipp Stracker 2025-02-26 18:09:20 +01:00
parent 5a5074df8c
commit 12b5fe8082
No known key found for this signature in database

View file

@ -812,14 +812,27 @@ class GooglepayButton extends PaymentButton {
const payer = payerDataFromPaymentResponse( paymentData );
const paymentResponse = ( state, intent = null, message = null ) => {
const response = {
transactionState: state,
};
if ( intent || message ) {
response.error = {
intent,
message,
};
}
this.log( 'processPaymentResponse', response );
return response;
};
const paymentError = ( reason ) => {
this.error( reason );
return this.processPaymentResponse(
'ERROR',
'PAYMENT_AUTHORIZATION',
reason
);
return paymentResponse( 'ERROR', 'PAYMENT_AUTHORIZATION', reason );
};
const checkPayPalApproval = async ( orderId ) => {
@ -840,9 +853,13 @@ class GooglepayButton extends PaymentButton {
/**
* This approval mainly confirms that the orderID is valid.
*
* It's still needed because this handler redirects to the checkout page if the server-side
* It's still needed because this handler REDIRECTS to the checkout page if the server-side
* approval was successful.
*
* I.e. on success, the approveOrder handler initiates a browser navigation; this means
* it should be the last action that happens in the payment process.
*
* @see onApproveForContinue.js
* @param {string} orderID
*/
const approveOrderServerSide = async ( orderID ) => {
@ -886,7 +903,7 @@ class GooglepayButton extends PaymentButton {
const success = await approveOrderServerSide( orderId );
if ( success ) {
result = this.processPaymentResponse( 'SUCCESS' );
result = paymentResponse( 'SUCCESS' );
} else {
result = paymentError( 'FAILED TO APPROVE' );
}
@ -900,23 +917,6 @@ class GooglepayButton extends PaymentButton {
return result;
}
processPaymentResponse( state, intent = null, message = null ) {
const response = {
transactionState: state,
};
if ( intent || message ) {
response.error = {
intent,
message,
};
}
this.log( 'processPaymentResponse', response );
return response;
}
/**
* Updates the shipping option in the checkout form, if a form with shipping options is
* detected.