Skip to content

Commit 8a7a67d

Browse files
committed
Add support for dispute additional evidence types feature and update related tests
1 parent b6b88c8 commit 8a7a67d

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

includes/class-wc-payments-features.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class WC_Payments_Features {
2727
const WOOPAY_FIRST_PARTY_AUTH_FLAG_NAME = '_wcpay_feature_woopay_first_party_auth';
2828
const WOOPAY_DIRECT_CHECKOUT_FLAG_NAME = '_wcpay_feature_woopay_direct_checkout';
2929
const DISPUTE_ISSUER_EVIDENCE = '_wcpay_feature_dispute_issuer_evidence';
30+
const DISPUTE_ADDITIONAL_EVIDENCE_TYPES = '_wcpay_feature_dispute_additional_evidence_types';
3031
const WOOPAY_GLOBAL_THEME_SUPPORT_FLAG_NAME = '_wcpay_feature_woopay_global_theme_support';
3132
const WCPAY_DYNAMIC_CHECKOUT_PLACE_ORDER_BUTTON_FLAG_NAME = '_wcpay_feature_dynamic_checkout_place_order_button';
3233
const ACCOUNT_DETAILS_FLAG_NAME = '_wcpay_feature_account_details';
@@ -323,6 +324,17 @@ public static function is_dispute_issuer_evidence_enabled(): bool {
323324
return '1' === get_option( self::DISPUTE_ISSUER_EVIDENCE, '0' );
324325
}
325326

327+
/**
328+
* Checks whether Dispute Additional Evidence Types feature should be enabled. Disabled by default.
329+
*
330+
* This gates the new evidence form types (event, booking_reservation, other) for dispute challenges.
331+
*
332+
* @return bool
333+
*/
334+
public static function is_dispute_additional_evidence_types_enabled(): bool {
335+
return '1' === get_option( self::DISPUTE_ADDITIONAL_EVIDENCE_TYPES, '0' );
336+
}
337+
326338
/**
327339
* Checks whether the next deposit notice on the deposits list screen has been dismissed.
328340
*
@@ -363,6 +375,7 @@ public static function to_array() {
363375
'documents' => self::is_documents_section_enabled(),
364376
'woopayExpressCheckout' => self::is_woopay_express_checkout_enabled(),
365377
'isDisputeIssuerEvidenceEnabled' => self::is_dispute_issuer_evidence_enabled(),
378+
'isDisputeAdditionalEvidenceTypesEnabled' => self::is_dispute_additional_evidence_types_enabled(),
366379
'isFRTReviewFeatureActive' => self::is_frt_review_feature_active(),
367380
'isDynamicCheckoutPlaceOrderButtonEnabled' => self::is_dynamic_checkout_place_order_button_enabled(),
368381
'isAccountDetailsEnabled' => self::is_account_details_enabled(),

includes/wc-payment-api/class-wc-payments-api-client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,8 +3000,8 @@ private function determine_suggested_product_type( WC_Order $order ): string {
30003000
}
30013001

30023002
// At this point, we know there's exactly one product.
3003-
// Check for specific product types.
3004-
if ( 'booking' === $product_type ) {
3003+
// Check for specific product types (gated by feature flag).
3004+
if ( WC_Payments_Features::is_dispute_additional_evidence_types_enabled() && 'booking' === $product_type ) {
30053005
return 'booking_reservation';
30063006
}
30073007

tests/unit/wc-payment-api/test-class-wc-payments-api-client.php

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,10 @@ private function create_woocommerce_default_pages(): array {
13041304
*
13051305
* @dataProvider data_determine_suggested_product_type
13061306
*/
1307-
public function test_determine_suggested_product_type( $order_items, $expected_product_type ) {
1307+
public function test_determine_suggested_product_type( $order_items, $expected_product_type, $feature_flag_enabled = true ) {
1308+
// Set the feature flag option.
1309+
update_option( WC_Payments_Features::DISPUTE_ADDITIONAL_EVIDENCE_TYPES, $feature_flag_enabled ? '1' : '0' );
1310+
13081311
// Create a mock order.
13091312
$mock_order = $this->getMockBuilder( 'WC_Order' )
13101313
->disableOriginalConstructor()
@@ -1328,75 +1331,92 @@ public function test_determine_suggested_product_type( $order_items, $expected_p
13281331
*/
13291332
public function data_determine_suggested_product_type() {
13301333
return [
1331-
'empty_order' => [
1334+
'empty_order' => [
13321335
'order_items' => [],
13331336
'expected_product_type' => 'physical_product',
13341337
],
1335-
'single_physical_product' => [
1338+
'single_physical_product' => [
13361339
'order_items' => [
13371340
$this->create_mock_order_item_product( false ), // not virtual.
13381341
],
13391342
'expected_product_type' => 'physical_product',
13401343
],
1341-
'single_virtual_product' => [
1344+
'single_virtual_product' => [
13421345
'order_items' => [
13431346
$this->create_mock_order_item_product( true ), // virtual.
13441347
],
13451348
'expected_product_type' => 'digital_product_or_service',
13461349
],
1347-
'multiple_products_mixed' => [
1350+
'multiple_products_mixed' => [
13481351
'order_items' => [
13491352
$this->create_mock_order_item_product( false ), // physical.
13501353
$this->create_mock_order_item_product( true ), // virtual.
13511354
],
13521355
'expected_product_type' => 'multiple',
13531356
],
1354-
'multiple_physical_products' => [
1357+
'multiple_physical_products' => [
13551358
'order_items' => [
13561359
$this->create_mock_order_item_product( false ), // physical.
13571360
$this->create_mock_order_item_product( false ), // physical.
13581361
],
13591362
'expected_product_type' => 'multiple',
13601363
],
1361-
'multiple_virtual_products' => [
1364+
'multiple_virtual_products' => [
13621365
'order_items' => [
13631366
$this->create_mock_order_item_product( true ), // virtual.
13641367
$this->create_mock_order_item_product( true ), // virtual.
13651368
],
13661369
'expected_product_type' => 'multiple',
13671370
],
1368-
'order_with_non_product_items' => [
1371+
'order_with_non_product_items' => [
13691372
'order_items' => [
13701373
$this->create_mock_order_item_product( true ), // virtual product.
13711374
$this->create_mock_order_item_shipping(), // shipping item (not a product).
13721375
],
13731376
'expected_product_type' => 'digital_product_or_service',
13741377
],
1375-
'order_with_invalid_product' => [
1378+
'order_with_invalid_product' => [
13761379
'order_items' => [
13771380
$this->create_mock_order_item_product( true, false ), // virtual but invalid product.
13781381
],
13791382
'expected_product_type' => 'physical_product',
13801383
],
1381-
'single_booking_product' => [
1384+
'single_booking_product' => [
13821385
'order_items' => [
13831386
$this->create_mock_order_item_product( true, true, 'booking' ), // booking product.
13841387
],
13851388
'expected_product_type' => 'booking_reservation',
1389+
'feature_flag_enabled' => true,
1390+
],
1391+
'single_booking_product_flag_off' => [
1392+
'order_items' => [
1393+
$this->create_mock_order_item_product( true, true, 'booking' ), // booking product (virtual).
1394+
],
1395+
'expected_product_type' => 'digital_product_or_service', // Falls back to virtual detection.
1396+
'feature_flag_enabled' => false,
1397+
],
1398+
'single_booking_product_physical_flag_off' => [
1399+
'order_items' => [
1400+
$this->create_mock_order_item_product( false, true, 'booking' ), // booking product (not virtual).
1401+
],
1402+
'expected_product_type' => 'physical_product', // Falls back to physical detection.
1403+
'feature_flag_enabled' => false,
13861404
],
1387-
'multiple_booking_products' => [
1405+
'multiple_booking_products' => [
13881406
'order_items' => [
13891407
$this->create_mock_order_item_product( true, true, 'booking' ), // booking.
13901408
$this->create_mock_order_item_product( true, true, 'booking' ), // booking.
13911409
],
13921410
'expected_product_type' => 'multiple',
1411+
'feature_flag_enabled' => true,
13931412
],
1394-
'booking_physical_mixed' => [
1413+
'booking_physical_mixed' => [
13951414
'order_items' => [
13961415
$this->create_mock_order_item_product( true, true, 'booking' ), // booking.
13971416
$this->create_mock_order_item_product( false, true, 'simple' ), // physical.
13981417
],
13991418
'expected_product_type' => 'multiple',
1419+
'feature_flag_enabled' => true,
14001420
],
14011421
];
14021422
}

0 commit comments

Comments
 (0)