mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
♻️ Flatten processPayment to functon body
This makes the flow easier to understand and debug
This commit is contained in:
parent
672641ba82
commit
5a5074df8c
1 changed files with 13 additions and 17 deletions
|
@ -870,22 +870,6 @@ class GooglepayButton extends PaymentButton {
|
|||
return isApproved;
|
||||
};
|
||||
|
||||
const processPaymentPromise = async ( id ) => {
|
||||
const isApprovedByPayPal = await checkPayPalApproval( id );
|
||||
|
||||
if ( ! isApprovedByPayPal ) {
|
||||
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 ) {
|
||||
return this.processPaymentResponse( 'SUCCESS' );
|
||||
}
|
||||
return paymentError( 'FAILED TO APPROVE' );
|
||||
};
|
||||
|
||||
// Add billing data to session.
|
||||
moduleStorage.setPayer( payer );
|
||||
setPayerData( payer );
|
||||
|
@ -894,7 +878,19 @@ class GooglepayButton extends PaymentButton {
|
|||
const orderId = await this.contextHandler.createOrder();
|
||||
this.log( 'createOrder', orderId );
|
||||
|
||||
result = await processPaymentPromise( orderId );
|
||||
const isApprovedByPayPal = await checkPayPalApproval( orderId );
|
||||
|
||||
if ( ! isApprovedByPayPal ) {
|
||||
result = paymentError( 'TRANSACTION FAILED' );
|
||||
} else {
|
||||
const success = await approveOrderServerSide( orderId );
|
||||
|
||||
if ( success ) {
|
||||
result = this.processPaymentResponse( 'SUCCESS' );
|
||||
} else {
|
||||
result = paymentError( 'FAILED TO APPROVE' );
|
||||
}
|
||||
}
|
||||
} catch ( err ) {
|
||||
result = paymentError( err.message );
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue