♻️ Simplify control flow by removing a Promise

This commit is contained in:
Philipp Stracker 2025-02-26 17:59:35 +01:00
parent d6e66fd55c
commit 672641ba82
No known key found for this signature in database

View file

@ -870,42 +870,38 @@ class GooglepayButton extends PaymentButton {
return isApproved;
};
const processPaymentPromise = async ( resolve, id ) => {
const processPaymentPromise = async ( id ) => {
const isApprovedByPayPal = await checkPayPalApproval( id );
if ( ! isApprovedByPayPal ) {
resolve( paymentError( 'TRANSACTION FAILED' ) );
return;
return paymentError( 'TRANSACTION FAILED' );
}
// This must be the last step in the process, as it initiates a redirect.
const success = await approveOrderServerSide( id );
if ( success ) {
resolve( this.processPaymentResponse( 'SUCCESS' ) );
} else {
resolve( paymentError( 'FAILED TO APPROVE' ) );
return this.processPaymentResponse( 'SUCCESS' );
}
return paymentError( 'FAILED TO APPROVE' );
};
// Add billing data to session.
moduleStorage.setPayer( payer );
setPayerData( payer );
return new Promise( async ( resolve ) => {
// Add billing data to session.
moduleStorage.setPayer( payer );
setPayerData( payer );
try {
const orderId = await this.contextHandler.createOrder();
this.log( 'createOrder', orderId );
try {
const orderId = await this.contextHandler.createOrder();
this.log( 'createOrder', orderId );
result = await processPaymentPromise( orderId );
} catch ( err ) {
result = paymentError( err.message );
}
await processPaymentPromise( resolve, orderId );
} catch ( err ) {
resolve( paymentError( err.message ) );
}
this.logGroup();
this.logGroup();
} );
return result;
}
processPaymentResponse( state, intent = null, message = null ) {