♻️ Make the final server-side approval conditional

With 3DS the final approval should only fire when the 3DS process was successful. Note that we still need to implement a check to confirm the verification via API
This commit is contained in:
Philipp Stracker 2025-03-03 17:25:55 +01:00
parent 7b579bfc9b
commit 3e2a1f347f
No known key found for this signature in database

View file

@ -857,6 +857,7 @@ class GooglepayButton extends PaymentButton {
return false;
}
};
/**
* Initiates payer action and handles the 3DS contingency.
*
@ -865,14 +866,13 @@ class GooglepayButton extends PaymentButton {
const initiatePayerAction = async ( orderID ) => {
this.log( 'initiatePayerAction', orderID );
this.log(
'==== Confirm Payment Completed Payer Action Required ====='
);
await widgetBuilder.paypal
.Googlepay()
.initiatePayerAction( { orderId: orderID } );
this.log( '===== Payer Action Completed =====' );
// TODO: We need to make a server-side request to check if the 3DS process was successful.
return true;
};
/**
@ -947,14 +947,19 @@ class GooglepayButton extends PaymentButton {
if ( ! isApprovedByPayPal ) {
result = paymentError( 'TRANSACTION FAILED' );
} else {
/**
* This payment requires a 3DS verification before we can process the order.
*/
if ( isApprovedByPayPal === 'action_required' ) {
await initiatePayerAction( orderId );
}
let success = false;
const success = await approveOrderServerSide( orderId );
// This payment requires a 3DS verification before we can process the order.
if ( isApprovedByPayPal === 'action_required' ) {
const approved = await initiatePayerAction( orderId );
// Only approve on server-side when 3DS was successful.
if ( approved ) {
success = await approveOrderServerSide( orderId );
}
} else {
success = await approveOrderServerSide( orderId );
}
if ( success ) {
result = paymentResponse( 'SUCCESS' );