From 3e2a1f347f849e8294c5c1cac34db659fbc42225 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 3 Mar 2025 17:25:55 +0100
Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Make=20the=20final=20serve?=
=?UTF-8?q?r-side=20approval=20conditional?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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
---
.../resources/js/GooglepayButton.js | 27 +++++++++++--------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/modules/ppcp-googlepay/resources/js/GooglepayButton.js b/modules/ppcp-googlepay/resources/js/GooglepayButton.js
index 432071843..8fd9db12c 100644
--- a/modules/ppcp-googlepay/resources/js/GooglepayButton.js
+++ b/modules/ppcp-googlepay/resources/js/GooglepayButton.js
@@ -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' );