Date: Thu, 28 Mar 2024 15:02:22 +0000
Subject: [PATCH 2/4] Fix fraud prevention data presentation.
---
.../src/Endpoint/CreateOrderEndpoint.php | 10 ++++++++--
.../ppcp-button/src/Helper/EarlyOrderHandler.php | 11 +++++++++--
.../ppcp-wc-gateway/src/Gateway/PayPalGateway.php | 5 +++++
.../CreditCardOrderInfoHandlingTrait.php | 15 ++++++++-------
.../src/Processor/OrderMetaTrait.php | 6 +++++-
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 2 +-
6 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
index 980e03770..1ef06c3be 100644
--- a/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
+++ b/modules/ppcp-button/src/Endpoint/CreateOrderEndpoint.php
@@ -330,8 +330,14 @@ class CreateOrderEndpoint implements EndpointInterface {
$wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $order->id() );
$wc_order->update_meta_data( PayPalGateway::INTENT_META_KEY, $order->intent() );
- $payer = $order->payer();
- if ( $payer ) {
+ $payment_source = $order->payment_source();
+ $payment_source_name = $payment_source ? $payment_source->name() : null;
+ $payer = $order->payer();
+ if (
+ $payer
+ && $payment_source_name
+ && in_array( $payment_source_name, PayPalGateway::PAYMENT_SOURCES_WITH_PAYER_EMAIL, true )
+ ) {
$payer_email = $payer->email_address();
if ( $payer_email ) {
$wc_order->update_meta_data( PayPalGateway::ORDER_PAYER_EMAIL_META_KEY, $payer_email );
diff --git a/modules/ppcp-button/src/Helper/EarlyOrderHandler.php b/modules/ppcp-button/src/Helper/EarlyOrderHandler.php
index adff6f56c..46b4ddf41 100644
--- a/modules/ppcp-button/src/Helper/EarlyOrderHandler.php
+++ b/modules/ppcp-button/src/Helper/EarlyOrderHandler.php
@@ -160,8 +160,15 @@ class EarlyOrderHandler {
$wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $order->id() );
$wc_order->update_meta_data( PayPalGateway::INTENT_META_KEY, $order->intent() );
- $payer = $order->payer();
- if ( $payer && $wc_order instanceof \WC_Order ) {
+ $payment_source = $order->payment_source();
+ $payment_source_name = $payment_source ? $payment_source->name() : null;
+ $payer = $order->payer();
+ if (
+ $payer
+ && $payment_source_name
+ && in_array( $payment_source_name, PayPalGateway::PAYMENT_SOURCES_WITH_PAYER_EMAIL, true )
+ && $wc_order instanceof \WC_Order
+ ) {
$payer_email = $payer->email_address();
if ( $payer_email ) {
$wc_order->update_meta_data( PayPalGateway::ORDER_PAYER_EMAIL_META_KEY, $payer_email );
diff --git a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
index 2a04aa478..19ebe9d08 100644
--- a/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
+++ b/modules/ppcp-wc-gateway/src/Gateway/PayPalGateway.php
@@ -55,6 +55,11 @@ class PayPalGateway extends \WC_Payment_Gateway {
const THREE_D_AUTH_RESULT_META_KEY = '_ppcp_paypal_3DS_auth_result';
const FRAUD_RESULT_META_KEY = '_ppcp_paypal_fraud_result';
+ /**
+ * List of payment sources wich we are expected to store the payer email in the WC Order metadata.
+ */
+ const PAYMENT_SOURCES_WITH_PAYER_EMAIL = array( 'paypal', 'paylater', 'venmo' );
+
/**
* The Settings Renderer.
*
diff --git a/modules/ppcp-wc-gateway/src/Processor/CreditCardOrderInfoHandlingTrait.php b/modules/ppcp-wc-gateway/src/Processor/CreditCardOrderInfoHandlingTrait.php
index 281045099..4cd9e07ed 100644
--- a/modules/ppcp-wc-gateway/src/Processor/CreditCardOrderInfoHandlingTrait.php
+++ b/modules/ppcp-wc-gateway/src/Processor/CreditCardOrderInfoHandlingTrait.php
@@ -52,7 +52,6 @@ trait CreditCardOrderInfoHandlingTrait {
%1$s
%2$s
%3$s
- %4$s
';
$three_d_response_order_note_result = sprintf(
$three_d_response_order_note_result_format,
@@ -61,9 +60,7 @@ trait CreditCardOrderInfoHandlingTrait {
/* translators: %s is enrollment status */
sprintf( __( 'Enrollment Status: %s', 'woocommerce-paypal-payments' ), esc_html( $result->enrollment_status() ) ),
/* translators: %s is authentication status */
- sprintf( __( 'Authentication Status: %s', 'woocommerce-paypal-payments' ), esc_html( $result->authentication_result() ) ),
- /* translators: %s card last digits */
- sprintf( __( 'Card Last Digits: %s', 'woocommerce-paypal-payments' ), esc_html( $payment_source->properties()->last_digits ?? '' ) )
+ sprintf( __( 'Authentication Status: %s', 'woocommerce-paypal-payments' ), esc_html( $result->authentication_result() ) )
);
$three_d_response_order_note = sprintf(
$three_d_response_order_note_format,
@@ -99,8 +96,9 @@ trait CreditCardOrderInfoHandlingTrait {
return;
}
- $fraud_responses = $fraud->to_array();
- $card_brand = $payment_source->properties()->brand ?? __( 'N/A', 'woocommerce-paypal-payments' );
+ $fraud_responses = $fraud->to_array();
+ $card_brand = $payment_source->properties()->brand ?? __( 'N/A', 'woocommerce-paypal-payments' );
+ $card_last_digits = $payment_source->properties()->last_digits ?? __( 'N/A', 'woocommerce-paypal-payments' );
$avs_response_order_note_title = __( 'Address Verification Result', 'woocommerce-paypal-payments' );
/* translators: %1$s is AVS order note title, %2$s is AVS order note result markup */
@@ -112,6 +110,7 @@ trait CreditCardOrderInfoHandlingTrait {
%3$s
%4$s
+ %5$s
';
$avs_response_order_note_result = sprintf(
$avs_response_order_note_result_format,
@@ -122,7 +121,9 @@ trait CreditCardOrderInfoHandlingTrait {
/* translators: %s is fraud AVS postal match */
sprintf( __( 'Postal Match: %s', 'woocommerce-paypal-payments' ), esc_html( $fraud_responses['postal_match'] ) ),
/* translators: %s is card brand */
- sprintf( __( 'Card Brand: %s', 'woocommerce-paypal-payments' ), esc_html( $card_brand ) )
+ sprintf( __( 'Card Brand: %s', 'woocommerce-paypal-payments' ), esc_html( $card_brand ) ),
+ /* translators: %s card last digits */
+ sprintf( __( 'Card Last Digits: %s', 'woocommerce-paypal-payments' ), esc_html( $card_last_digits ) )
);
$avs_response_order_note = sprintf(
$avs_response_order_note_format,
diff --git a/modules/ppcp-wc-gateway/src/Processor/OrderMetaTrait.php b/modules/ppcp-wc-gateway/src/Processor/OrderMetaTrait.php
index 1d9b87a2f..62a80456a 100644
--- a/modules/ppcp-wc-gateway/src/Processor/OrderMetaTrait.php
+++ b/modules/ppcp-wc-gateway/src/Processor/OrderMetaTrait.php
@@ -46,7 +46,11 @@ trait OrderMetaTrait {
}
$payer = $order->payer();
- if ( $payer ) {
+ if (
+ $payer
+ && $payment_source
+ && in_array( $payment_source, PayPalGateway::PAYMENT_SOURCES_WITH_PAYER_EMAIL, true )
+ ) {
$payer_email = $payer->email_address();
if ( $payer_email ) {
$wc_order->update_meta_data( PayPalGateway::ORDER_PAYER_EMAIL_META_KEY, $payer_email );
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 03241f555..7a8ef6d48 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -458,7 +458,7 @@ class WCGatewayModule implements ModuleInterface {
$email = $wc_order->get_meta( PayPalGateway::ORDER_PAYER_EMAIL_META_KEY ) ?: '';
if ( $email ) {
- echo '' . esc_html__( 'PayPal buyer account', 'woocommerce-paypal-payments' ) . ':
' . esc_attr( $email ) . '
';
+ echo '' . esc_html__( 'PayPal email address', 'woocommerce-paypal-payments' ) . ':
' . esc_attr( $email ) . '
';
}
}
);
From 585c4e76cf59e6dd7032ddc1b4c5d40d97db11fb Mon Sep 17 00:00:00 2001
From: Pedro Silva
Date: Mon, 1 Apr 2024 16:32:07 +0100
Subject: [PATCH 3/4] Refactor paypal email display in order detail.
---
.../ppcp-wc-gateway/src/WCGatewayModule.php | 37 +++++++++++++++----
1 file changed, 29 insertions(+), 8 deletions(-)
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index 7a8ef6d48..d0e57e5de 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -449,17 +449,38 @@ class WCGatewayModule implements ModuleInterface {
}
);
- add_action(
- 'woocommerce_admin_order_data_after_billing_address',
- function ( \WC_Order $wc_order ) {
- if ( ! apply_filters( 'woocommerce_paypal_payments_order_details_show_paypal_email', true ) ) {
- return;
+ /**
+ * Param types removed to avoid third-party issues.
+ *
+ * @psalm-suppress MissingClosureParamType
+ */
+ add_filter(
+ 'woocommerce_admin_billing_fields',
+ function ( $fields ) {
+ global $theorder;
+
+ if ( ! is_array( $fields ) ) {
+ return $fields;
}
- $email = $wc_order->get_meta( PayPalGateway::ORDER_PAYER_EMAIL_META_KEY ) ?: '';
- if ( $email ) {
- echo '' . esc_html__( 'PayPal email address', 'woocommerce-paypal-payments' ) . ':
' . esc_attr( $email ) . '
';
+ if ( ! $theorder instanceof WC_Order ) {
+ return $fields;
}
+
+ $email = $theorder->get_meta( PayPalGateway::ORDER_PAYER_EMAIL_META_KEY ) ?: '';
+
+ if ( ! $email ) {
+ return $fields;
+ }
+
+ $fields['paypal_email'] = array(
+ 'label' => __( 'PayPal email address', 'woocommerce-paypal-payments' ),
+ 'value' => $email,
+ 'wrapper_class' => 'form-field-wide',
+ 'custom_attributes' => array( 'disabled' => 'disabled' ),
+ );
+
+ return $fields;
}
);
}
From 48f9efbfd4bfcc22488fef7e191102773cda0b43 Mon Sep 17 00:00:00 2001
From: Pedro Silva
Date: Tue, 2 Apr 2024 11:19:00 +0100
Subject: [PATCH 4/4] Fix display of paypal email when funding source is not
paypal.
---
modules/ppcp-wc-gateway/src/WCGatewayModule.php | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
index d0e57e5de..4295b1b17 100644
--- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php
+++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php
@@ -473,6 +473,14 @@ class WCGatewayModule implements ModuleInterface {
return $fields;
}
+ // Is payment source is paypal exclude all non paypal funding sources.
+ $payment_source = $theorder->get_meta( PayPalGateway::ORDER_PAYMENT_SOURCE_META_KEY ) ?: '';
+ $is_paypal_funding_source = ( strpos( $theorder->get_payment_method_title(), '(via PayPal)' ) === false );
+
+ if ( $payment_source === 'paypal' && ! $is_paypal_funding_source ) {
+ return $fields;
+ }
+
$fields['paypal_email'] = array(
'label' => __( 'PayPal email address', 'woocommerce-paypal-payments' ),
'value' => $email,