Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Woo POS - payments onboarding] Enable POS for stores with incomplete payments onboarding #14149

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
2 changes: 2 additions & 0 deletions Experiments/Experiments/DefaultFeatureFlagService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public struct DefaultFeatureFlagService: FeatureFlagService {
return true
case .favoriteProducts:
return buildConfig == .localDeveloper || buildConfig == .alpha
case .paymentsOnboardingInPointOfSale:
return buildConfig == .localDeveloper
default:
return true
}
Expand Down
4 changes: 4 additions & 0 deletions Experiments/Experiments/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,8 @@ public enum FeatureFlag: Int {
/// Allows marking product as favorite
///
case favoriteProducts

/// Supports Woo Payments onboarding in POS so that merchants who have not completed onboarding can access POS.
///
case paymentsOnboardingInPointOfSale
}
4 changes: 0 additions & 4 deletions WooCommerce/Classes/POS/ViewModels/TotalsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ final class TotalsViewModel: ObservableObject, TotalsViewModelProtocol {
case cardPaymentSuccessful
}

@Published private(set) var cardPresentPaymentEvent: CardPresentPaymentEvent = .idle
@Published var cardPresentPaymentAlertViewModel: PointOfSaleCardPresentPaymentAlertType?
@Published private(set) var cardPresentPaymentInlineMessage: PointOfSaleCardPresentPaymentMessageType?
@Published private(set) var isShowingCardReaderStatus: Bool = false
Expand Down Expand Up @@ -88,7 +87,6 @@ final class TotalsViewModel: ObservableObject, TotalsViewModelProtocol {
var orderStatePublisher: Published<OrderState>.Publisher { $orderState }
var paymentStatePublisher: Published<PaymentState>.Publisher { $paymentState }
private var cardPresentPaymentAlertViewModelPublisher: Published<PointOfSaleCardPresentPaymentAlertType?>.Publisher { $cardPresentPaymentAlertViewModel }
private var cardPresentPaymentEventPublisher: Published<CardPresentPaymentEvent>.Publisher { $cardPresentPaymentEvent }
private var connectionStatusPublisher: Published<CardPresentPaymentReaderConnectionStatus>.Publisher { $connectionStatus }
private var formattedCartTotalPricePublisher: Published<String?>.Publisher { $formattedCartTotalPrice }
private var formattedOrderTotalPricePublisher: Published<String?>.Publisher { $formattedOrderTotalPrice }
Expand Down Expand Up @@ -313,8 +311,6 @@ private extension TotalsViewModel {
}

func observeCardPresentPaymentEvents() {
cardPresentPaymentService.paymentEventPublisher.assign(to: &$cardPresentPaymentEvent)

cardPresentPaymentService.paymentEventPublisher
.map { [weak self] event -> PointOfSaleCardPresentPaymentAlertType? in
guard let self else { return nil }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import protocol Yosemite.POSItem

protocol TotalsViewModelProtocol {
var paymentState: TotalsViewModel.PaymentState { get }
var cardPresentPaymentEvent: CardPresentPaymentEvent { get }
var connectionStatus: CardPresentPaymentReaderConnectionStatus { get }

var orderStatePublisher: Published<TotalsViewModel.OrderState>.Publisher { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ final class CardPresentPaymentsOnboardingViewController: UIHostingController<Car

struct CardPresentPaymentsOnboardingView: View {
@StateObject var viewModel: CardPresentPaymentsOnboardingViewModel
var shouldShowMenuOnCompletion: Bool = true

var body: some View {
Group {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ final class POSEligibilityChecker: POSEligibilityCheckerProtocol {
.eraseToAnyPublisher()
}

return Publishers.CombineLatest3(isOnboardingComplete, isWooCommerceVersionSupported, isPointOfSaleFeatureFlagEnabled)
.map { $0 && $1 && $2 }
guard featureFlagService.isFeatureFlagEnabled(.paymentsOnboardingInPointOfSale) else {
return Publishers.CombineLatest3(isOnboardingComplete, isWooCommerceVersionSupported, isPointOfSaleFeatureFlagEnabled)
.map { $0 && $1 && $2 }
.eraseToAnyPublisher()
}
return Publishers.CombineLatest(isWooCommerceVersionSupported, isPointOfSaleFeatureFlagEnabled)
.map { $0 && $1 }
.eraseToAnyPublisher()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct MockFeatureFlagService: FeatureFlagService {
private let revampedShippingLabelCreation: Bool
private let viewEditCustomFieldsInProductsAndOrders: Bool
private let favoriteProducts: Bool
private let paymentsOnboardingInPointOfSale: Bool

init(isInboxOn: Bool = false,
isShowInboxCTAEnabled: Bool = false,
Expand All @@ -42,7 +43,8 @@ struct MockFeatureFlagService: FeatureFlagService {
blazeCampaignObjective: Bool = false,
revampedShippingLabelCreation: Bool = false,
viewEditCustomFieldsInProductsAndOrders: Bool = false,
favoriteProducts: Bool = false) {
favoriteProducts: Bool = false,
paymentsOnboardingInPointOfSale: Bool = false) {
self.isInboxOn = isInboxOn
self.isShowInboxCTAEnabled = isShowInboxCTAEnabled
self.isUpdateOrderOptimisticallyOn = isUpdateOrderOptimisticallyOn
Expand All @@ -63,6 +65,7 @@ struct MockFeatureFlagService: FeatureFlagService {
self.revampedShippingLabelCreation = revampedShippingLabelCreation
self.viewEditCustomFieldsInProductsAndOrders = viewEditCustomFieldsInProductsAndOrders
self.favoriteProducts = favoriteProducts
self.paymentsOnboardingInPointOfSale = paymentsOnboardingInPointOfSale
}

func isFeatureFlagEnabled(_ featureFlag: FeatureFlag) -> Bool {
Expand Down Expand Up @@ -107,6 +110,8 @@ struct MockFeatureFlagService: FeatureFlagService {
return viewEditCustomFieldsInProductsAndOrders
case .favoriteProducts:
return favoriteProducts
case .paymentsOnboardingInPointOfSale:
return paymentsOnboardingInPointOfSale
default:
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,26 @@ final class POSEligibilityCheckerTests: XCTestCase {
XCTAssertFalse(isEligible)
}

func test_is_eligible_when_onboarding_state_is_not_completed_and_onboarding_feature_enabled_then_returns_true() throws {
// Given
let featureFlagService = MockFeatureFlagService(isPointOfSaleEnabled: true, paymentsOnboardingInPointOfSale: true)
setupCountry(country: .us)
accountWhitelistedInBackend(true)
let checker = POSEligibilityChecker(userInterfaceIdiom: .pad,
cardPresentPaymentsOnboarding: onboardingUseCase,
siteSettings: siteSettings,
currencySettings: Fixtures.usdCurrencySettings,
stores: stores,
featureFlagService: featureFlagService)
checker.isEligible.assign(to: &$isEligible)

// When
onboardingUseCase.state = .pluginNotInstalled

// Then
XCTAssertTrue(isEligible)
}

func test_is_eligible_when_WooCommerce_version_is_below_6_6_then_returns_false() throws {
// Given
let featureFlagService = MockFeatureFlagService(isPointOfSaleEnabled: true)
Expand Down