get_meta( 'last4' ) ) {
@@ -73,6 +114,35 @@ public function show_woopay_payment_method_name( $payment_method_title, $abstrac
return ob_get_clean();
}
+ /**
+ * Add the BNPL logo to the payment method name on the order received page.
+ *
+ * @param WC_Payment_Gateway_WCPay $gateway the gateway being shown.
+ * @param WCPay\Payment_Methods\UPE_Payment_Method $payment_method the payment method being shown.
+ *
+ * @return string|false
+ */
+ public function show_bnpl_payment_method_name( $gateway, $payment_method ) {
+ $method_logo_url = apply_filters(
+ 'wc_payments_thank_you_page_bnpl_payment_method_logo_url',
+ $payment_method->get_payment_method_icon_for_location( 'checkout', false, $gateway->get_account_country() ),
+ $payment_method->get_id()
+ );
+
+ // If we don't have a logo URL here for some reason, bail.
+ if ( ! $method_logo_url ) {
+ return false;
+ }
+
+ ob_start();
+ ?>
+
+
+
+ $contexts ) {
+ // We don't need to check the same location again.
+ if ( $location_const === $location ) {
+ continue;
+ }
+
+ foreach ( $contexts as $context => $transient ) {
+ $active_theme = get_transient( $transient );
+ if ( $active_theme ) {
+ break 2; // This will break both loops.
+ }
+ }
+ }
+ }
+
+ // If $active_theme is still false, we don't have any theme set in the transients, so we fallback to 'stripe'.
+ if ( $active_theme ) {
+ return $active_theme;
+ }
+
+ // Fallback to 'stripe' if no transients are set.
+ return 'stripe';
+ }
}
diff --git a/includes/class-wc-payments.php b/includes/class-wc-payments.php
index 7a6a3aeab4e..72c90d3a635 100644
--- a/includes/class-wc-payments.php
+++ b/includes/class-wc-payments.php
@@ -538,7 +538,7 @@ public static function init() {
foreach ( $payment_methods as $payment_method ) {
self::$payment_method_map[ $payment_method->get_id() ] = $payment_method;
- $split_gateway = new WC_Payment_Gateway_WCPay( self::$api_client, self::$account, self::$customer_service, self::$token_service, self::$action_scheduler_service, $payment_method, $payment_methods, self::$failed_transaction_rate_limiter, self::$order_service, self::$duplicate_payment_prevention_service, self::$localization_service, self::$fraud_service );
+ $split_gateway = new WC_Payment_Gateway_WCPay( self::$api_client, self::$account, self::$customer_service, self::$token_service, self::$action_scheduler_service, $payment_method, $payment_methods, self::$failed_transaction_rate_limiter, self::$order_service, self::$duplicate_payment_prevention_service, self::$localization_service, self::$fraud_service, self::$duplicates_detection_service );
// Card gateway hooks are registered once below.
if ( 'card' !== $payment_method->get_id() ) {
@@ -1020,7 +1020,7 @@ public static function init_rest_api() {
$reporting_controller->register_routes();
include_once WCPAY_ABSPATH . 'includes/admin/class-wc-rest-payments-settings-controller.php';
- $settings_controller = new WC_REST_Payments_Settings_Controller( self::$api_client, self::get_gateway(), self::$account, self::$duplicates_detection_service );
+ $settings_controller = new WC_REST_Payments_Settings_Controller( self::$api_client, self::get_gateway(), self::$account );
$settings_controller->register_routes();
include_once WCPAY_ABSPATH . 'includes/admin/class-wc-rest-payments-reader-controller.php';
diff --git a/includes/class-woopay-tracker.php b/includes/class-woopay-tracker.php
index 04312026ebc..511aeafc5cd 100644
--- a/includes/class-woopay-tracker.php
+++ b/includes/class-woopay-tracker.php
@@ -13,6 +13,7 @@
use WC_Payments_Features;
use WCPay\Constants\Country_Code;
use WP_Error;
+use Exception;
defined( 'ABSPATH' ) || exit; // block direct access.
@@ -42,6 +43,13 @@ class WooPay_Tracker extends Jetpack_Tracks_Client {
*/
private $http;
+ /**
+ * Base URL for stats counter.
+ *
+ * @var string
+ */
+ private static $pixel_base_url = 'https://pixel.wp.com/g.gif';
+
/**
* Constructor.
@@ -63,8 +71,8 @@ public function __construct( $http ) {
add_action( 'woocommerce_after_single_product', [ $this, 'classic_product_page_view' ] );
add_action( 'woocommerce_blocks_enqueue_checkout_block_scripts_after', [ $this, 'blocks_checkout_start' ] );
add_action( 'woocommerce_blocks_enqueue_cart_block_scripts_after', [ $this, 'blocks_cart_page_view' ] );
- add_action( 'woocommerce_checkout_order_processed', [ $this, 'checkout_order_processed' ] );
- add_action( 'woocommerce_blocks_checkout_order_processed', [ $this, 'checkout_order_processed' ] );
+ add_action( 'woocommerce_checkout_order_processed', [ $this, 'checkout_order_processed' ], 10, 2 );
+ add_action( 'woocommerce_blocks_checkout_order_processed', [ $this, 'checkout_order_processed' ], 10, 2 );
add_action( 'woocommerce_payments_save_user_in_woopay', [ $this, 'must_save_payment_method_to_platform' ] );
add_action( 'before_woocommerce_pay_form', [ $this, 'pay_for_order_page_view' ] );
add_action( 'woocommerce_thankyou', [ $this, 'thank_you_page_view' ] );
@@ -370,7 +378,6 @@ public function tracks_get_identity() {
];
}
-
/**
* Record a Tracks event that the classic checkout page has loaded.
*/
@@ -445,13 +452,56 @@ public function pay_for_order_page_view() {
}
/**
- * Record a Tracks event that the order has been processed.
+ * Bump a counter. No user identifiable information is sent.
+ *
+ * @param string $group The group to bump the stat in.
+ * @param string $stat_name The name of the stat to bump.
+ *
+ * @return bool
+ */
+ public function bump_stats( $group, $stat_name ) {
+ $pixel_url = sprintf(
+ self::$pixel_base_url . '?v=wpcom-no-pv&x_%s=%s',
+ $group,
+ $stat_name
+ );
+
+ $response = wp_remote_get( esc_url_raw( $pixel_url ) );
+
+ if ( is_wp_error( $response ) ) {
+ return false;
+ }
+
+ if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Record that the order has been processed.
*/
- public function checkout_order_processed() {
- $is_woopay_order = ( isset( $_SERVER['HTTP_USER_AGENT'] ) && 'WooPay' === $_SERVER['HTTP_USER_AGENT'] );
- // Don't track WooPay orders. They will be tracked on WooPay side with more flow specific details.
- if ( ! $is_woopay_order ) {
- $this->maybe_record_wcpay_shopper_event( 'checkout_order_placed' );
+ public function checkout_order_processed( $order_id ) {
+
+ $payment_gateway = wc_get_payment_gateway_by_order( $order_id );
+ $properties = [ 'payment_title' => 'other' ];
+
+ // If the order was placed using WooCommerce Payments, record the payment title using Tracks.
+ if (strpos( $payment_gateway->id, 'woocommerce_payments') === 0 ) {
+ $order = wc_get_order( $order_id );
+ $payment_title = $order->get_payment_method_title();
+ $properties = [ 'payment_title' => $payment_title ];
+
+ $is_woopay_order = ( isset( $_SERVER['HTTP_USER_AGENT'] ) && 'WooPay' === $_SERVER['HTTP_USER_AGENT'] );
+
+ // Don't track WooPay orders. They will be tracked on WooPay side with more details.
+ if ( ! $is_woopay_order ) {
+ $this->maybe_record_wcpay_shopper_event( 'checkout_order_placed', $properties );
+ }
+ // If the order was placed using a different payment gateway, just increment a counter.
+ } else {
+ $this->bump_stats( 'wcpay_order_completed_gateway', 'other' );
}
}
diff --git a/includes/core/server/request/class-list-fraud-outcome-transactions.php b/includes/core/server/request/class-list-fraud-outcome-transactions.php
index d7d3770c7c5..4d01cff2666 100644
--- a/includes/core/server/request/class-list-fraud-outcome-transactions.php
+++ b/includes/core/server/request/class-list-fraud-outcome-transactions.php
@@ -11,6 +11,7 @@
use WC_Payments_Utils;
use WC_Payments_API_Client;
use WCPay\Constants\Fraud_Meta_Box_Type;
+use WCPay\Fraud_Prevention\Models\Rule;
/**
* Request class for getting intents.
@@ -37,6 +38,10 @@ class List_Fraud_Outcome_Transactions extends Paginated {
* @throws Invalid_Request_Parameter_Exception
*/
public function get_api(): string {
+ $status = $this->status ?? 'null';
+ if ( ! Rule::is_valid_fraud_outcome_status( $status ) ) {
+ throw new Invalid_Request_Parameter_Exception( "Invalid fraud outcome status provided: $status", 'invalid_fraud_outcome_status' );
+ }
return WC_Payments_API_Client::FRAUD_OUTCOMES_API . '/status/' . $this->status;
}
diff --git a/includes/multi-currency/MultiCurrency.php b/includes/multi-currency/MultiCurrency.php
index cc279200108..c0698eddf1c 100644
--- a/includes/multi-currency/MultiCurrency.php
+++ b/includes/multi-currency/MultiCurrency.php
@@ -316,8 +316,6 @@ public function init() {
// Update the customer currencies option after an order status change.
add_action( 'woocommerce_order_status_changed', [ $this, 'maybe_update_customer_currencies_option' ] );
- $this->maybe_add_cache_cookie();
-
static::$is_initialized = true;
}
@@ -830,8 +828,6 @@ public function update_selected_currency( string $currency_code, bool $persist_c
} else {
add_action( 'wp_loaded', [ $this, 'recalculate_cart' ] );
}
-
- $this->maybe_add_cache_cookie();
}
/**
@@ -1657,17 +1653,4 @@ private function log_and_throw_invalid_currency_exception( $method, $currency_co
private function is_customer_currencies_data_valid( $currencies ) {
return ! empty( $currencies ) && is_array( $currencies );
}
-
- /**
- * Sets the cache cookie for currency code and exchange rate.
- *
- * This private method sets the 'wcpay_currency' cookie if HTTP headers
- * have not been sent. This cookie stores the selected currency's code and its exchange rate,
- * and is intended exclusively for caching purposes, not for application logic.
- */
- private function maybe_add_cache_cookie() {
- if ( ! headers_sent() && ! is_admin() && ! defined( 'DOING_CRON' ) && ! Utils::is_admin_api_request() ) {
- wc_setcookie( 'wcpay_currency', sprintf( '%s_%s', $this->get_selected_currency()->get_code(), $this->get_selected_currency()->get_rate() ), time() + HOUR_IN_SECONDS );
- }
- }
}
diff --git a/includes/payment-methods/class-affirm-payment-method.php b/includes/payment-methods/class-affirm-payment-method.php
index a51967ef3bb..f65794e555d 100644
--- a/includes/payment-methods/class-affirm-payment-method.php
+++ b/includes/payment-methods/class-affirm-payment-method.php
@@ -30,6 +30,7 @@ public function __construct( $token_service ) {
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = __( 'Affirm', 'woocommerce-payments' );
$this->is_reusable = false;
+ $this->is_bnpl = true;
$this->icon_url = plugins_url( 'assets/images/payment-methods/affirm-logo.svg', WCPAY_PLUGIN_FILE );
$this->dark_icon_url = plugins_url( 'assets/images/payment-methods/affirm-logo-dark.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::CANADIAN_DOLLAR ];
diff --git a/includes/payment-methods/class-afterpay-payment-method.php b/includes/payment-methods/class-afterpay-payment-method.php
index 6df0697c473..01690b64f1b 100644
--- a/includes/payment-methods/class-afterpay-payment-method.php
+++ b/includes/payment-methods/class-afterpay-payment-method.php
@@ -29,6 +29,7 @@ public function __construct( $token_service ) {
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = __( 'Afterpay', 'woocommerce-payments' );
$this->is_reusable = false;
+ $this->is_bnpl = true;
$this->icon_url = plugins_url( 'assets/images/payment-methods/afterpay-logo.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::CANADIAN_DOLLAR, Currency_Code::AUSTRALIAN_DOLLAR, Currency_Code::NEW_ZEALAND_DOLLAR, Currency_Code::POUND_STERLING ];
$this->countries = [ Country_Code::UNITED_STATES, Country_Code::CANADA, Country_Code::AUSTRALIA, Country_Code::NEW_ZEALAND, Country_Code::UNITED_KINGDOM ];
diff --git a/includes/payment-methods/class-klarna-payment-method.php b/includes/payment-methods/class-klarna-payment-method.php
index 2e446ead208..fa30154c226 100644
--- a/includes/payment-methods/class-klarna-payment-method.php
+++ b/includes/payment-methods/class-klarna-payment-method.php
@@ -30,6 +30,7 @@ public function __construct( $token_service ) {
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = __( 'Klarna', 'woocommerce-payments' );
$this->is_reusable = false;
+ $this->is_bnpl = true;
$this->icon_url = plugins_url( 'assets/images/payment-methods/klarna-pill.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::POUND_STERLING, Currency_Code::EURO, Currency_Code::DANISH_KRONE, Currency_Code::NORWEGIAN_KRONE, Currency_Code::SWEDISH_KRONA ];
$this->accept_only_domestic_payment = true;
diff --git a/includes/payment-methods/class-upe-payment-method.php b/includes/payment-methods/class-upe-payment-method.php
index 2cdd1a9cb01..51d091328fd 100644
--- a/includes/payment-methods/class-upe-payment-method.php
+++ b/includes/payment-methods/class-upe-payment-method.php
@@ -90,6 +90,13 @@ abstract class UPE_Payment_Method {
*/
protected $dark_icon_url;
+ /**
+ * Is the payment method a BNPL (Buy Now Pay Later) method?
+ *
+ * @var boolean
+ */
+ protected $is_bnpl = false;
+
/**
* Supported customer locations for which charges for a payment method can be processed
* Empty if all customer locations are supported
@@ -198,6 +205,16 @@ public function is_reusable() {
return $this->is_reusable;
}
+ /**
+ * Returns boolean dependent on whether payment method
+ * will support BNPL (Buy Now Pay Later) payments
+ *
+ * @return bool
+ */
+ public function is_bnpl() {
+ return $this->is_bnpl;
+ }
+
/**
* Returns boolean dependent on whether payment method will accept charges
* with chosen currency
@@ -258,6 +275,24 @@ public function get_dark_icon( string $account_country = null ) {
return isset( $this->dark_icon_url ) ? $this->dark_icon_url : $this->get_icon( $account_country );
}
+ /**
+ * Gets the theme appropriate icon for the payment method for a given location and context.
+ *
+ * @param string $location The location to get the icon for.
+ * @param boolean $is_blocks Whether the icon is for blocks.
+ * @param string $account_country Optional account country.
+ * @return string
+ */
+ public function get_payment_method_icon_for_location( string $location = 'checkout', bool $is_blocks = true, string $account_country = null ) {
+ $appearance_theme = WC_Payments_Utils::get_active_upe_theme_transient_for_location( $location, $is_blocks ? 'blocks' : 'classic' );
+
+ if ( 'night' === $appearance_theme ) {
+ return $this->get_dark_icon( $account_country );
+ }
+
+ return $this->get_icon( $account_country );
+ }
+
/**
* Returns payment method supported countries
*
diff --git a/includes/wc-payment-api/class-wc-payments-http.php b/includes/wc-payment-api/class-wc-payments-http.php
index ba7c6fe4a52..65081e8be10 100644
--- a/includes/wc-payment-api/class-wc-payments-http.php
+++ b/includes/wc-payment-api/class-wc-payments-http.php
@@ -49,7 +49,7 @@ public function init_hooks() {
* @param array $args - The arguments to passed to Jetpack.
* @param string $body - The body passed on to the HTTP request.
* @param bool $is_site_specific - If true, the site ID will be included in the request url. Defaults to true.
- * @param bool $use_user_token - If true, the request will be signed with the user token rather than blog token. Defaults to false.
+ * @param bool $use_user_token - If true, the request will be signed with the Jetpack connection owner user token rather than blog token. Defaults to false.
*
* @return array HTTP response on success.
* @throws API_Exception - If not connected or request failed.
diff --git a/includes/woopay-user/class-woopay-save-user.php b/includes/woopay-user/class-woopay-save-user.php
index 91b61f5d1c8..78096190fba 100644
--- a/includes/woopay-user/class-woopay-save-user.php
+++ b/includes/woopay-user/class-woopay-save-user.php
@@ -63,7 +63,7 @@ public function register_checkout_page_scripts() {
'WCPAY_WOOPAY',
'woopayCheckout',
[
- 'PRE_CHECK_SAVE_MY_INFO' => $account_data['pre_check_save_my_info']
+ 'PRE_CHECK_SAVE_MY_INFO' => isset( $account_data['pre_check_save_my_info'] ) ? $account_data['pre_check_save_my_info'] : false,
]
);
diff --git a/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php b/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php
index 7d3502e0df9..5bf31255461 100644
--- a/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php
+++ b/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php
@@ -175,9 +175,10 @@ public function set_up() {
$order_service,
$mock_dpps,
$this->mock_localization_service,
- $this->mock_fraud_service
+ $this->mock_fraud_service,
+ $this->mock_duplicates_detection_service
);
- $this->controller = new WC_REST_Payments_Settings_Controller( $this->mock_api_client, $this->gateway, $this->mock_wcpay_account, $this->mock_duplicates_detection_service );
+ $this->controller = new WC_REST_Payments_Settings_Controller( $this->mock_api_client, $this->gateway, $this->mock_wcpay_account );
$this->mock_api_client
->method( 'is_server_connected' )
diff --git a/tests/unit/admin/test-class-wc-rest-payments-survey-controller.php b/tests/unit/admin/test-class-wc-rest-payments-survey-controller.php
index edc7d5aad60..cf0480ec993 100644
--- a/tests/unit/admin/test-class-wc-rest-payments-survey-controller.php
+++ b/tests/unit/admin/test-class-wc-rest-payments-survey-controller.php
@@ -38,7 +38,7 @@ public function setUp(): void {
// Set the user so that we can pass the authentication.
wp_set_current_user( 1 );
- $this->http_client_stub = $this->getMockBuilder( WC_Payments_Http::class )->disableOriginalConstructor()->setMethods( [ 'wpcom_json_api_request_as_user' ] )->getMock();
+ $this->http_client_stub = $this->getMockBuilder( WC_Payments_Http::class )->disableOriginalConstructor()->setMethods( [ 'remote_request' ] )->getMock();
$this->controller = new WC_REST_Payments_Survey_Controller( $this->http_client_stub );
}
@@ -63,33 +63,42 @@ public function test_empty_rating_returns_400_status_code() {
$this->assertEquals( 400, $response->get_status() );
}
+
public function test_valid_request_forwards_data_to_jetpack() {
+ $request_url = WC_Payments_API_Client::ENDPOINT_BASE . '/marketing/survey';
+
$this->http_client_stub
->expects( $this->any() )
- ->method( 'wpcom_json_api_request_as_user' )
+ ->method( 'remote_request' )
->with(
- $this->stringContains( '/marketing/survey' ),
- $this->anything(),
- $this->anything(),
+ // Check the request argument URL is the same.
+ $this->callback(
+ function ( $argument ) use ( $request_url ) {
+ return $request_url === $argument['url'];
+ }
+ ),
$this->logicalAnd(
- $this->arrayHasKey( 'survey_id' ),
- $this->arrayHasKey( 'survey_responses' ),
$this->callback(
function ( $argument ) {
- return 'wcpay-payment-activity' === $argument['survey_id'];
+ $json_body = json_decode( $argument, true );
+ return 'wcpay-payment-activity' === $json_body['survey_id'];
}
),
$this->callback(
function ( $argument ) {
- return 'happy' === $argument['survey_responses']['rating'];
+ $json_body = json_decode( $argument, true );
+ return 'happy' === $json_body['survey_responses']['rating'];
}
),
$this->callback(
function ( $argument ) {
- return 'test comment' === $argument['survey_responses']['comments']['text'];
+ $json_body = json_decode( $argument, true );
+ return 'test comment' === $json_body['survey_responses']['comments']['text'];
}
- )
- )
+ ),
+ ),
+ $this->isTrue(),
+ $this->isTrue(),
)
->willReturn(
[
diff --git a/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php b/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php
index af6c53fd851..804ca19117f 100644
--- a/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php
+++ b/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php
@@ -9,6 +9,7 @@
use WCPay\Core\Server\Request\Add_Account_Tos_Agreement;
use WCPay\Database_Cache;
use WCPay\Duplicate_Payment_Prevention_Service;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Payment_Methods\CC_Payment_Method;
use WCPay\Session_Rate_Limiter;
@@ -55,16 +56,17 @@ public function set_up() {
->disableOriginalConstructor()
->getMock();
- $mock_wcpay_account = $this->createMock( WC_Payments_Account::class );
- $mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
- $mock_db_cache = $this->createMock( Database_Cache::class );
- $mock_session_service = $this->createMock( WC_Payments_Session_Service::class );
- $order_service = new WC_Payments_Order_Service( $this->createMock( WC_Payments_API_Client::class ) );
- $customer_service = new WC_Payments_Customer_Service( $mock_api_client, $mock_wcpay_account, $mock_db_cache, $mock_session_service, $order_service );
- $token_service = new WC_Payments_Token_Service( $mock_api_client, $customer_service );
- $action_scheduler_service = new WC_Payments_Action_Scheduler_Service( $mock_api_client, $order_service );
- $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class );
- $mock_payment_method = $this->createMock( CC_Payment_Method::class );
+ $mock_wcpay_account = $this->createMock( WC_Payments_Account::class );
+ $mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
+ $mock_db_cache = $this->createMock( Database_Cache::class );
+ $mock_session_service = $this->createMock( WC_Payments_Session_Service::class );
+ $order_service = new WC_Payments_Order_Service( $this->createMock( WC_Payments_API_Client::class ) );
+ $customer_service = new WC_Payments_Customer_Service( $mock_api_client, $mock_wcpay_account, $mock_db_cache, $mock_session_service, $order_service );
+ $token_service = new WC_Payments_Token_Service( $mock_api_client, $customer_service );
+ $action_scheduler_service = new WC_Payments_Action_Scheduler_Service( $mock_api_client, $order_service );
+ $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class );
+ $mock_payment_method = $this->createMock( CC_Payment_Method::class );
+ $mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class );
$this->gateway = new WC_Payment_Gateway_WCPay(
$mock_api_client,
@@ -78,7 +80,8 @@ public function set_up() {
$order_service,
$mock_dpps,
$this->createMock( WC_Payments_Localization_Service::class ),
- $mock_fraud_service
+ $mock_fraud_service,
+ $mock_duplicates_detection_service
);
$this->controller = new WC_REST_Payments_Tos_Controller( $mock_api_client, $this->gateway, $mock_wcpay_account );
diff --git a/tests/unit/core/server/request/test-class-list-fraud-outcome-transactions-request.php b/tests/unit/core/server/request/test-class-list-fraud-outcome-transactions-request.php
index 2e08bf04425..9a77afb8537 100644
--- a/tests/unit/core/server/request/test-class-list-fraud-outcome-transactions-request.php
+++ b/tests/unit/core/server/request/test-class-list-fraud-outcome-transactions-request.php
@@ -6,6 +6,7 @@
*/
use PHPUnit\Framework\MockObject\MockObject;
+use WCPay\Core\Exceptions\Server\Request\Invalid_Request_Parameter_Exception;
use WCPay\Core\Server\Request\List_Fraud_Outcome_Transactions;
/**
@@ -68,6 +69,7 @@ public function test_list_fraud_outcome_transactions_request() {
$this->assertSame( 'GET', $request->get_method() );
$this->assertSame( WC_Payments_API_Client::FRAUD_OUTCOMES_API . '/status/' . $status, $request->get_api() );
}
+
public function test_list_fraud_outcome_transactions_request_using_from_rest_request_function() {
$page = 2;
$page_size = 50;
@@ -569,4 +571,29 @@ public function test_list_fraud_outcome_transactions_request_filters_out_non_blo
$this->assertEquals( $expected, $result );
}
+
+ /**
+ * Checks to see if the get_api method throws an exception if an invalid status is passed.
+ *
+ * @param ?string $status The status to check.
+ *
+ * @return void
+ *
+ * @dataProvider provider_get_api_exception_on_invalid_status
+ */
+ public function test_get_api_exception_on_invalid_status( $status ): void {
+ $request = new List_Fraud_Outcome_Transactions( $this->mock_api_client, $this->mock_wc_payments_http_client );
+ $request->set_status( $status );
+
+ $status = $status ?? 'null';
+
+ $this->expectException( Invalid_Request_Parameter_Exception::class );
+ $this->expectExceptionMessage( "Invalid fraud outcome status provided: $status" );
+
+ $request->get_api();
+ }
+
+ public function provider_get_api_exception_on_invalid_status(): array {
+ return [ [ 'invalid' ], [ null ] ];
+ }
}
diff --git a/tests/unit/payment-methods/test-class-upe-payment-gateway.php b/tests/unit/payment-methods/test-class-upe-payment-gateway.php
index 8260f8707b5..137a283a944 100644
--- a/tests/unit/payment-methods/test-class-upe-payment-gateway.php
+++ b/tests/unit/payment-methods/test-class-upe-payment-gateway.php
@@ -33,6 +33,7 @@
use WC_Payments_Localization_Service;
use WCPay\Core\Server\Request\Create_And_Confirm_Intention;
use WCPay\Database_Cache;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Internal\Service\Level3Service;
use WCPay\Internal\Service\OrderService;
@@ -170,6 +171,13 @@ class UPE_Payment_Gateway_Test extends WCPAY_UnitTestCase {
*/
private $mock_fraud_service;
+ /**
+ * Mock Duplicates Detection Service.
+ *
+ * @var Duplicates_Detection_Service
+ */
+ private $mock_duplicates_detection_service;
+
/**
* Pre-test setup
*/
@@ -230,8 +238,9 @@ public function set_up() {
$this->mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class );
- $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
- $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
+ $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
+ $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
+ $this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class );
$this->mock_payment_methods = [];
$payment_method_classes = [
@@ -294,6 +303,7 @@ public function set_up() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
]
)
->setMethods(
@@ -961,7 +971,8 @@ public function test_get_upe_available_payment_methods( $payment_methods, $expec
$this->mock_order_service,
$this->mock_dpps,
$this->mock_localization_service,
- $this->mock_fraud_service
+ $this->mock_fraud_service,
+ $this->mock_duplicates_detection_service
);
$this->assertEquals( $expected_result, $gateway->get_upe_available_payment_methods() );
diff --git a/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php b/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php
index 22653a4cba9..8ac1db139a5 100644
--- a/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php
+++ b/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php
@@ -35,6 +35,7 @@
use WC_Payments_Localization_Service;
use WCPay\Core\Server\Request\Create_And_Confirm_Intention;
use WCPay\Database_Cache;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Internal\Service\Level3Service;
use WCPay\Internal\Service\OrderService;
/**
@@ -158,6 +159,13 @@ class UPE_Split_Payment_Gateway_Test extends WCPAY_UnitTestCase {
*/
private $mock_fraud_service;
+ /**
+ * Mock Duplicates Detection Service.
+ *
+ * @var Duplicates_Detection_Service
+ */
+ private $mock_duplicates_detection_service;
+
/**
* Mapping for payment ID to payment method.
*
@@ -247,8 +255,9 @@ public function set_up() {
$this->mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class );
- $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
- $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
+ $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
+ $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
+ $this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class );
// Arrange: Define a $_POST array which includes the payment method,
// so that get_payment_method_from_request() does not throw error.
@@ -281,6 +290,7 @@ public function set_up() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
]
)
->setMethods(
@@ -1060,6 +1070,7 @@ public function test_get_payment_methods_with_request_context() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
]
)
->setMethods( [ 'get_payment_methods_from_gateway_id' ] )
@@ -1105,6 +1116,7 @@ public function test_get_payment_methods_without_request_context() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
]
)
->setMethods( [ 'get_payment_methods_from_gateway_id' ] )
@@ -1149,6 +1161,7 @@ public function test_get_payment_methods_without_request_context_or_token() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
]
)
->setMethods(
@@ -1202,6 +1215,7 @@ public function test_get_payment_methods_from_gateway_id_upe() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
]
)
->onlyMethods(
diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php b/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php
index 8caaadb9ea4..c4ae5f729ee 100644
--- a/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php
+++ b/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php
@@ -9,6 +9,7 @@
use WCPay\Core\Server\Request\Create_And_Confirm_Intention;
use WCPay\Constants\Payment_Method;
use WCPay\Duplicate_Payment_Prevention_Service;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Session_Rate_Limiter;
use WCPay\Fraud_Prevention\Fraud_Prevention_Service;
use WCPay\Payment_Methods\CC_Payment_Method;
@@ -153,6 +154,7 @@ public function set_up() {
$mock_dpps,
$this->createMock( WC_Payments_Localization_Service::class ),
$this->createMock( WC_Payments_Fraud_Service::class ),
+ $this->createMock( Duplicates_Detection_Service::class ),
]
)
->setMethods(
diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php b/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php
index 49350ffcd7c..48caa5980d2 100644
--- a/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php
+++ b/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php
@@ -15,6 +15,7 @@
use WCPay\Exceptions\Connection_Exception;
use WCPay\Session_Rate_Limiter;
use WCPay\Constants\Payment_Method;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Payment_Methods\CC_Payment_Method;
// Need to use WC_Mock_Data_Store.
@@ -167,6 +168,7 @@ public function set_up() {
$this->mock_dpps,
$this->createMock( WC_Payments_Localization_Service::class ),
$this->createMock( WC_Payments_Fraud_Service::class ),
+ $this->createMock( Duplicates_Detection_Service::class ),
]
)
->setMethods(
diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php b/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php
index 49746ef3ca3..24f06d99933 100644
--- a/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php
+++ b/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php
@@ -12,6 +12,7 @@
use WCPay\Core\Server\Request\Refund_Charge;
use WCPay\Core\Server\Response;
use WCPay\Duplicate_Payment_Prevention_Service;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Exceptions\API_Exception;
use WCPay\Payment_Methods\CC_Payment_Method;
use WCPay\Session_Rate_Limiter;
@@ -104,7 +105,8 @@ public function set_up() {
$this->mock_order_service,
$mock_dpps,
$this->createMock( WC_Payments_Localization_Service::class ),
- $this->createMock( WC_Payments_Fraud_Service::class )
+ $this->createMock( WC_Payments_Fraud_Service::class ),
+ $this->createMock( Duplicates_Detection_Service::class )
);
}
diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php
index 9715d61a193..fd4352ac0b2 100644
--- a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php
+++ b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php
@@ -6,6 +6,7 @@
*/
use WCPay\Duplicate_Payment_Prevention_Service;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Payment_Methods\CC_Payment_Method;
use WCPay\Session_Rate_Limiter;
@@ -139,7 +140,8 @@ public function set_up() {
$this->mock_order_service,
$mock_dpps,
$this->createMock( WC_Payments_Localization_Service::class ),
- $this->createMock( WC_Payments_Fraud_Service::class )
+ $this->createMock( WC_Payments_Fraud_Service::class ),
+ $this->createMock( Duplicates_Detection_Service::class ),
);
$this->wcpay_gateway->init_hooks();
diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php
index 434bbd971fd..622e7cbe1d9 100644
--- a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php
+++ b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php
@@ -10,6 +10,7 @@
use WCPay\Constants\Order_Status;
use WCPay\Constants\Intent_Status;
use WCPay\Duplicate_Payment_Prevention_Service;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Payment_Methods\CC_Payment_Method;
use WCPay\Session_Rate_Limiter;
@@ -160,6 +161,7 @@ public function set_up() {
$mock_dpps,
$this->createMock( WC_Payments_Localization_Service::class ),
$this->createMock( WC_Payments_Fraud_Service::class ),
+ $this->createMock( Duplicates_Detection_Service::class ),
]
)
->setMethods(
diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php
index a5b33c1581c..151b3b919fe 100644
--- a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php
+++ b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php
@@ -8,6 +8,7 @@
use PHPUnit\Framework\MockObject\MockObject;
use WCPay\Core\Server\Request\Create_And_Confirm_Intention;
use WCPay\Duplicate_Payment_Prevention_Service;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Exceptions\API_Exception;
use WCPay\Internal\Service\Level3Service;
use WCPay\Internal\Service\OrderService;
@@ -102,6 +103,13 @@ class WC_Payment_Gateway_WCPay_Subscriptions_Test extends WCPAY_UnitTestCase {
*/
private $mock_fraud_service;
+ /**
+ * Mock Duplicates Detection Service.
+ *
+ * @var Duplicates_Detection_Service
+ */
+ private $mock_duplicates_detection_service;
+
public function set_up() {
parent::set_up();
@@ -136,8 +144,9 @@ public function set_up() {
$this->mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class );
- $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
- $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
+ $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class );
+ $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
+ $this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class );
$mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class )
->setConstructorArgs( [ $this->mock_token_service ] )
@@ -156,7 +165,8 @@ public function set_up() {
$this->order_service,
$this->mock_dpps,
$this->mock_localization_service,
- $this->mock_fraud_service
+ $this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
);
$this->wcpay_gateway->init_hooks();
WC_Payments::set_gateway( $this->wcpay_gateway );
@@ -830,7 +840,8 @@ public function test_adds_custom_payment_meta_input_fallback_until_subs_3_0_7()
$this->order_service,
$this->mock_dpps,
$this->mock_localization_service,
- $this->mock_fraud_service
+ $this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
);
// Ensure the has_attached_integration_hooks property is set to false so callbacks can be attached in maybe_init_subscriptions().
@@ -864,7 +875,8 @@ public function test_does_not_add_custom_payment_meta_input_fallback_for_subs_3_
$this->order_service,
$this->mock_dpps,
$this->mock_localization_service,
- $this->mock_fraud_service
+ $this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
);
$this->assertFalse( has_action( 'woocommerce_admin_order_data_after_billing_address' ) );
diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay.php b/tests/unit/test-class-wc-payment-gateway-wcpay.php
index abf1066b8ec..7a766287e8f 100644
--- a/tests/unit/test-class-wc-payment-gateway-wcpay.php
+++ b/tests/unit/test-class-wc-payment-gateway-wcpay.php
@@ -17,6 +17,7 @@
use WCPay\Constants\Intent_Status;
use WCPay\Constants\Payment_Method;
use WCPay\Duplicate_Payment_Prevention_Service;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Exceptions\Amount_Too_Small_Exception;
use WCPay\Exceptions\API_Exception;
use WCPay\Exceptions\Process_Payment_Exception;
@@ -177,6 +178,13 @@ class WC_Payment_Gateway_WCPay_Test extends WCPAY_UnitTestCase {
*/
private $mock_fraud_service;
+ /**
+ * Mock Duplicates Detection Service.
+ *
+ * @var Duplicates_Detection_Service
+ */
+ private $mock_duplicates_detection_service;
+
/**
* Pre-test setup
*/
@@ -229,7 +237,8 @@ public function set_up() {
'currency_code' => 'usd',
]
);
- $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
+ $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class );
+ $this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class );
$this->mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class )
->setConstructorArgs( [ $this->mock_token_service ] )
@@ -897,6 +906,7 @@ public function test_process_redirect_setup_intent_succeded() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
]
)
->onlyMethods(
@@ -1004,6 +1014,7 @@ public function test_process_redirect_payment_save_payment_token() {
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
]
)
->onlyMethods(
@@ -3302,6 +3313,7 @@ private function get_partial_mock_for_gateway( array $methods = [], array $const
$this->mock_dpps,
$this->mock_localization_service,
$this->mock_fraud_service,
+ $this->mock_duplicates_detection_service,
];
foreach ( $constructor_replacement as $key => $value ) {
@@ -3787,7 +3799,8 @@ private function init_gateways() {
$this->order_service,
$this->mock_dpps,
$this->mock_localization_service,
- $this->mock_fraud_service
+ $this->mock_fraud_service,
+ $this->mock_duplicates_detection_service
);
}
diff --git a/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php b/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php
index 1bd4dbeeafc..8a6a1b7f4f3 100644
--- a/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php
+++ b/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php
@@ -7,6 +7,7 @@
use PHPUnit\Framework\MockObject\MockObject;
use WCPay\Duplicate_Payment_Prevention_Service;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Payment_Methods\CC_Payment_Method;
use WCPay\Session_Rate_Limiter;
use WCPay\WooPay\WooPay_Utilities;
@@ -177,7 +178,8 @@ private function make_wcpay_gateway() {
$mock_order_service,
$mock_dpps,
$this->createMock( WC_Payments_Localization_Service::class ),
- $this->createMock( WC_Payments_Fraud_Service::class )
+ $this->createMock( WC_Payments_Fraud_Service::class ),
+ $this->createMock( Duplicates_Detection_Service::class )
);
}
diff --git a/tests/unit/test-class-wc-payments-express-checkout-button-helper.php b/tests/unit/test-class-wc-payments-express-checkout-button-helper.php
index 8b3312dcf30..3dc7878ba39 100644
--- a/tests/unit/test-class-wc-payments-express-checkout-button-helper.php
+++ b/tests/unit/test-class-wc-payments-express-checkout-button-helper.php
@@ -6,6 +6,7 @@
*/
use WCPay\Duplicate_Payment_Prevention_Service;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Payment_Methods\CC_Payment_Method;
use WCPay\Session_Rate_Limiter;
@@ -91,7 +92,8 @@ private function make_wcpay_gateway() {
$mock_order_service,
$mock_dpps,
$this->createMock( WC_Payments_Localization_Service::class ),
- $this->createMock( WC_Payments_Fraud_Service::class )
+ $this->createMock( WC_Payments_Fraud_Service::class ),
+ $this->createMock( Duplicates_Detection_Service::class )
);
}
diff --git a/tests/unit/test-class-wc-payments-order-success-page.php b/tests/unit/test-class-wc-payments-order-success-page.php
index 20c0edeaf27..df92e94a482 100644
--- a/tests/unit/test-class-wc-payments-order-success-page.php
+++ b/tests/unit/test-class-wc-payments-order-success-page.php
@@ -24,7 +24,7 @@ public function set_up() {
public function test_show_woopay_payment_method_name_empty_order() {
$method_name = 'Credit card';
- $result = $this->payments_order_success_page->show_woopay_payment_method_name( $method_name, null );
+ $result = $this->payments_order_success_page->show_woocommerce_payments_payment_method_name( $method_name, null );
$this->assertSame( $method_name, $result );
}
@@ -34,7 +34,7 @@ public function test_show_woopay_payment_method_name_without_woopay_meta() {
$order->save();
$method_name = 'Credit card';
- $result = $this->payments_order_success_page->show_woopay_payment_method_name( $method_name, $order );
+ $result = $this->payments_order_success_page->show_woocommerce_payments_payment_method_name( $method_name, $order );
$this->assertSame( $method_name, $result );
}
@@ -43,13 +43,14 @@ public function test_show_woopay_payment_method_name_order_with_woopay_meta() {
$order = WC_Helper_Order::create_order();
$order->add_meta_data( 'is_woopay', true );
$order->add_meta_data( 'last4', '1234' );
+ $order->set_payment_method( 'woocommerce_payments' );
$order->save();
add_filter( 'woocommerce_is_order_received_page', '__return_true' );
- $result = $this->payments_order_success_page->show_woopay_payment_method_name( 'Credit card', $order );
+ $result = $this->payments_order_success_page->show_woocommerce_payments_payment_method_name( 'Credit card', $order );
remove_filter( 'woocommerce_is_order_received_page', '__return_true' );
- $this->assertStringContainsString( 'wc-payment-gateway-method-name-woopay-wrapper', $result );
+ $this->assertStringContainsString( 'wc-payment-gateway-method-logo-wrapper woopay', $result );
$this->assertStringContainsString( 'img alt="WooPay"', $result );
$this->assertStringContainsString( sprintf( 'Card ending in %s', $order->get_meta( 'last4' ) ), $result );
}
diff --git a/tests/unit/test-class-wc-payments-payment-request-button-handler.php b/tests/unit/test-class-wc-payments-payment-request-button-handler.php
index fe703f8ee94..672a4cdaeac 100644
--- a/tests/unit/test-class-wc-payments-payment-request-button-handler.php
+++ b/tests/unit/test-class-wc-payments-payment-request-button-handler.php
@@ -7,6 +7,7 @@
use WCPay\Constants\Country_Code;
use WCPay\Duplicate_Payment_Prevention_Service;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Payment_Methods\CC_Payment_Method;
use WCPay\Session_Rate_Limiter;
@@ -223,7 +224,8 @@ private function make_wcpay_gateway() {
$mock_order_service,
$mock_dpps,
$this->createMock( WC_Payments_Localization_Service::class ),
- $this->createMock( WC_Payments_Fraud_Service::class )
+ $this->createMock( WC_Payments_Fraud_Service::class ),
+ $this->createMock( Duplicates_Detection_Service::class )
);
}
diff --git a/tests/unit/test-class-wc-payments-utils.php b/tests/unit/test-class-wc-payments-utils.php
index a1a016a4c14..27c9c8e2c3b 100644
--- a/tests/unit/test-class-wc-payments-utils.php
+++ b/tests/unit/test-class-wc-payments-utils.php
@@ -555,4 +555,53 @@ public function test_get_filtered_error_status_code_with_api_exception() {
public function test_get_filtered_error_status_code_with_api_exception_and_402_status() {
$this->assertSame( 400, WC_Payments_Utils::get_filtered_error_status_code( new \WCPay\Exceptions\API_Exception( 'Error: Your card was declined.', 'card_declined', 402 ) ) );
}
+
+ private function delete_appearance_theme_transients( $transients ) {
+ foreach ( $transients as $location => $contexts ) {
+ foreach ( $contexts as $context => $transient ) {
+ delete_transient( $transient );
+ }
+ }
+ }
+
+ private function set_appearance_theme_transients( $transients ) {
+ foreach ( $transients as $location => $contexts ) {
+ foreach ( $contexts as $context => $transient ) {
+ set_transient( $transient, $location . '_' . $context . '_value', DAY_IN_SECONDS );
+ }
+ }
+ }
+
+ public function test_get_active_upe_theme_transient_for_location() {
+ $theme_transients = \WC_Payment_Gateway_WCPay::APPEARANCE_THEME_TRANSIENTS;
+
+ // Test with no transients set.
+ $this->assertSame( 'stripe', WC_Payments_Utils::get_active_upe_theme_transient_for_location( 'checkout', 'blocks' ) );
+
+ // Set the transients.
+ $this->set_appearance_theme_transients( $theme_transients );
+
+ // Test with transients set.
+ // Test with invalid location.
+ $this->assertSame( 'checkout_blocks_value', WC_Payments_Utils::get_active_upe_theme_transient_for_location( 'invalid_location', 'blocks' ) );
+
+ // Test with valid location and invalid context.
+ $this->assertSame( 'checkout_blocks_value', WC_Payments_Utils::get_active_upe_theme_transient_for_location( 'checkout', 'invalid_context' ) );
+
+ // Test with valid location and context.
+ foreach ( $theme_transients as $location => $contexts ) {
+ foreach ( $contexts as $context => $transient ) {
+ // Our transient for the product page is the same transient for both block and classic.
+ if ( 'product_page' === $location ) {
+ $this->assertSame( 'product_page_classic_value', WC_Payments_Utils::get_active_upe_theme_transient_for_location( $location, 'blocks' ) );
+ $this->assertSame( 'product_page_classic_value', WC_Payments_Utils::get_active_upe_theme_transient_for_location( $location, 'classic' ) );
+ } else {
+ $this->assertSame( $location . '_' . $context . '_value', WC_Payments_Utils::get_active_upe_theme_transient_for_location( $location, $context ) );
+ }
+ }
+ }
+
+ // Remove the transients.
+ $this->delete_appearance_theme_transients( $theme_transients );
+ }
}
diff --git a/tests/unit/test-class-wc-payments-woopay-button-handler.php b/tests/unit/test-class-wc-payments-woopay-button-handler.php
index 1c87f05a4b7..dbb5cefe960 100644
--- a/tests/unit/test-class-wc-payments-woopay-button-handler.php
+++ b/tests/unit/test-class-wc-payments-woopay-button-handler.php
@@ -6,6 +6,7 @@
*/
use WCPay\Duplicate_Payment_Prevention_Service;
+use WCPay\Duplicates_Detection_Service;
use WCPay\Payment_Methods\CC_Payment_Method;
use WCPay\Session_Rate_Limiter;
use WCPay\WooPay\WooPay_Utilities;
@@ -163,7 +164,8 @@ private function make_wcpay_gateway() {
$mock_order_service,
$mock_dpps,
$this->createMock( WC_Payments_Localization_Service::class ),
- $this->createMock( WC_Payments_Fraud_Service::class )
+ $this->createMock( WC_Payments_Fraud_Service::class ),
+ $this->createMock( Duplicates_Detection_Service::class )
);
}