mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
♻️ Embed a function that’s only locally used
This commit is contained in:
parent
5a5074df8c
commit
12b5fe8082
1 changed files with 24 additions and 24 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue