Skip to content

Commit f91e677

Browse files
authored
[Mobile Payments] Show gateway specific documentation when learn more tapped (#15035)
2 parents fb0134d + ad2e7a8 commit f91e677

23 files changed

+160
-87
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*** Use [*****] to indicate smoke tests of all critical flows should be run on the final IPA before release (e.g. major library or OS update).
33
21.7
44
-----
5+
- [*] Payments: Update learn more links to open Stripe-specific docs when using that gateway [https://github.com/woocommerce/woocommerce-ios/pull/15035]
56
- [x] Now, usernames and emails in text fields across multiple login views are no longer capitalized. [https://github.com/woocommerce/woocommerce-ios/pull/15002]
67

78
21.6
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Foundation
2+
import Yosemite
3+
4+
extension CardPresentPaymentsPlugin {
5+
var manageCardReaderLearnMoreURL: URL {
6+
switch self {
7+
case .wcPay:
8+
return WooConstants.URLs.inPersonPaymentsLearnMoreWCPay.asURL()
9+
case .stripe:
10+
return WooConstants.URLs.inPersonPaymentsLearnMoreStripe.asURL()
11+
}
12+
}
13+
14+
var setUpTapToPayLearnMoreURL: URL {
15+
switch self {
16+
case .wcPay:
17+
return WooConstants.URLs.inPersonPaymentsLearnMoreWCPayTapToPay.asURL()
18+
case .stripe:
19+
return WooConstants.URLs.inPersonPaymentsLearnMoreStripe.asURL()
20+
}
21+
}
22+
}

WooCommerce/Classes/ViewRelated/Dashboard/Settings/CardReadersV2/CardReaderSettingsSearchingViewController.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import SwiftUI
2+
import Yosemite
23

34
/// This view controller is used when no reader is connected. It assists
45
/// the merchant in connecting to a reader.
@@ -37,7 +38,7 @@ final class CardReaderSettingsSearchingViewController: UIHostingController<CardR
3738
}
3839
self.viewModel = viewModel
3940

40-
super.init(rootView: CardReaderSettingsSearchingView())
41+
super.init(rootView: CardReaderSettingsSearchingView(learnMoreURL: viewModel.learnMoreURL))
4142
configureView()
4243
}
4344

@@ -49,7 +50,6 @@ final class CardReaderSettingsSearchingViewController: UIHostingController<CardR
4950
guard let self = self else { return }
5051
WebviewHelper.launch(url, with: self)
5152
}
52-
rootView.learnMoreUrl = viewModel.learnMoreURL
5353
}
5454

5555
required init?(coder: NSCoder) {
@@ -115,7 +115,7 @@ private extension CardReaderSettingsSearchingViewController {
115115
struct CardReaderSettingsSearchingView: View {
116116
var connectClickAction: (() -> Void)? = nil
117117
var showURL: ((URL) -> Void)? = nil
118-
var learnMoreUrl: URL? = nil
118+
var learnMoreURL: URL
119119

120120
@Environment(\.verticalSizeClass) var verticalSizeClass
121121
@Environment(\.sizeCategory) private var sizeCategory
@@ -154,17 +154,11 @@ struct CardReaderSettingsSearchingView: View {
154154
.padding(.bottom, 8)
155155

156156
InPersonPaymentsLearnMore(viewModel: LearnMoreViewModel(
157+
url: learnMoreURL,
157158
tappedAnalyticEvent: .InPersonPayments.learnMoreTapped(source: .manageCardReader)))
158159
.padding(.vertical, 8)
159160
.customOpenURL(action: { url in
160-
switch url {
161-
case LearnMoreViewModel.learnMoreURL:
162-
if let url = learnMoreUrl {
163-
showURL?(url)
164-
}
165-
default:
166-
showURL?(url)
167-
}
161+
showURL?(url)
168162
})
169163
}
170164
.frame(
@@ -221,6 +215,8 @@ private enum Localization {
221215

222216
struct CardReaderSettingsSearchingView_Previews: PreviewProvider {
223217
static var previews: some View {
224-
CardReaderSettingsSearchingView(connectClickAction: {})
218+
CardReaderSettingsSearchingView(
219+
connectClickAction: {},
220+
learnMoreURL: WooConstants.URLs.inPersonPaymentsLearnMoreWCPay.asURL())
225221
}
226222
}

WooCommerce/Classes/ViewRelated/Dashboard/Settings/CardReadersV2/CardReaderSettingsSearchingViewModel.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ final class CardReaderSettingsSearchingViewModel: PaymentSettingsFlowPresentedVi
66
private(set) var shouldShow: CardReaderSettingsTriState = .isUnknown
77
var didChangeShouldShow: ((CardReaderSettingsTriState) -> Void)?
88
var didUpdate: (() -> Void)?
9-
var learnMoreURL: URL? = nil
9+
var learnMoreURL: URL
1010

1111
private(set) var noConnectedReader: CardReaderSettingsTriState = .isUnknown {
1212
didSet {
@@ -43,6 +43,7 @@ final class CardReaderSettingsSearchingViewModel: PaymentSettingsFlowPresentedVi
4343
self.knownReaderProvider = knownReaderProvider
4444
self.configuration = configuration
4545
self.cardReaderConnectionAnalyticsTracker = cardReaderConnectionAnalyticsTracker
46+
self.learnMoreURL = CardPresentPaymentsPlugin.wcPay.setUpTapToPayLearnMoreURL
4647

4748
beginKnownReaderObservation()
4849
beginConnectedReaderObservation()
@@ -108,12 +109,7 @@ final class CardReaderSettingsSearchingViewModel: PaymentSettingsFlowPresentedVi
108109
private func updateLearnMoreUrl(stores: StoresManager) {
109110
let loadLearnMoreUrlAction = CardPresentPaymentAction
110111
.loadActivePaymentGatewayExtension() { [weak self] result in
111-
switch result {
112-
case .wcpay:
113-
self?.learnMoreURL = WooConstants.URLs.inPersonPaymentsLearnMoreWCPay.asURL()
114-
case .stripe:
115-
self?.learnMoreURL = WooConstants.URLs.inPersonPaymentsLearnMoreStripe.asURL()
116-
}
112+
result.manageCardReaderLearnMoreURL
117113
}
118114
stores.dispatch(loadLearnMoreUrlAction)
119115
}

WooCommerce/Classes/ViewRelated/Dashboard/Settings/CardReadersV2/SetUpTapToPayCompleteViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct SetUpTapToPayCompleteView: View {
8383

8484
InPersonPaymentsLearnMore(
8585
viewModel: LearnMoreViewModel(
86+
url: viewModel.learnMoreURL,
8687
formatText: Localization.learnMore,
8788
tappedAnalyticEvent: .InPersonPayments.learnMoreTapped(source: .tapToPaySummary)))
8889
.padding(.vertical, Constants.learnMorePadding)

WooCommerce/Classes/ViewRelated/Dashboard/Settings/CardReadersV2/SetUpTapToPayCompleteViewModel.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ final class SetUpTapToPayCompleteViewModel: PaymentSettingsFlowPresentedViewMode
1818
private let analytics: Analytics = ServiceLocator.analytics
1919

2020
private var subscriptions = Set<AnyCancellable>()
21+
private(set) var learnMoreURL: URL
2122

2223
init(didChangeShouldShow: ((CardReaderSettingsTriState) -> Void)?,
2324
connectionAnalyticsTracker: CardReaderConnectionAnalyticsTracker,
2425
stores: StoresManager = ServiceLocator.stores) {
2526
self.didChangeShouldShow = didChangeShouldShow
2627
self.connectionAnalyticsTracker = connectionAnalyticsTracker
28+
/// The `learnMoreURL` will be updated when a reader connects
29+
self.learnMoreURL = CardPresentPaymentsPlugin.wcPay.setUpTapToPayLearnMoreURL
2730
self.stores = stores
2831

2932
beginConnectedReaderObservation()
@@ -34,11 +37,10 @@ final class SetUpTapToPayCompleteViewModel: PaymentSettingsFlowPresentedViewMode
3437
private func beginConnectedReaderObservation() {
3538
// This completion should be called repeatedly as the list of connected readers changes
3639
let connectedAction = CardPresentPaymentAction.observeConnectedReaders() { [weak self] readers in
37-
guard let self = self else {
38-
return
39-
}
40-
self.connectedReader = readers.isNotEmpty ? .isTrue : .isFalse
41-
self.reevaluateShouldShow()
40+
guard let self else { return }
41+
connectedReader = readers.isNotEmpty ? .isTrue : .isFalse
42+
reevaluateShouldShow()
43+
updateLearnMoreURL()
4244
}
4345
stores.dispatch(connectedAction)
4446
}
@@ -63,6 +65,13 @@ final class SetUpTapToPayCompleteViewModel: PaymentSettingsFlowPresentedViewMode
6365
}
6466
}
6567

68+
private func updateLearnMoreURL() {
69+
let action = CardPresentPaymentAction.loadActivePaymentGatewayExtension { [weak self] paymentGateway in
70+
self?.learnMoreURL = paymentGateway.setUpTapToPayLearnMoreURL
71+
}
72+
stores.dispatch(action)
73+
}
74+
6675
func doneTapped() {
6776
analytics.track(.tapToPaySetupSuccessDoneTapped)
6877
doneWasTapped = true

WooCommerce/Classes/ViewRelated/Dashboard/Settings/CardReadersV2/SetUpTapToPayInformationViewController.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ final class SetUpTapToPayInformationViewController: UIHostingController<SetUpTap
5353
guard let self = self else { return }
5454
WebviewHelper.launch(url, with: self)
5555
}
56-
rootView.learnMoreUrl = viewModel.learnMoreURL
5756
}
5857

5958
required init?(coder: NSCoder) {
@@ -69,7 +68,6 @@ final class SetUpTapToPayInformationViewController: UIHostingController<SetUpTap
6968
struct SetUpTapToPayInformationView: View {
7069
@ObservedObject var viewModel: SetUpTapToPayInformationViewModel
7170
var showURL: ((URL) -> Void)? = nil
72-
var learnMoreUrl: URL? = nil
7371
@State var showingAboutTapToPay: Bool = false
7472

7573
@Environment(\.verticalSizeClass) var verticalSizeClass
@@ -124,6 +122,7 @@ struct SetUpTapToPayInformationView: View {
124122

125123
InPersonPaymentsLearnMore(
126124
viewModel: LearnMoreViewModel(
125+
url: viewModel.learnMoreURL,
127126
formatText: Localization.learnMore,
128127
tappedAnalyticEvent: .InPersonPayments.learnMoreTapped(source: .tapToPaySummary)))
129128
.padding(.vertical, Constants.learnMorePadding)

WooCommerce/Classes/ViewRelated/Dashboard/Settings/CardReadersV2/SetUpTapToPayInformationViewModel.swift

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ final class SetUpTapToPayInformationViewModel: PaymentSettingsFlowPresentedViewM
5050
self.connectionAnalyticsTracker = connectionAnalyticsTracker
5151
self.connectivityObserver = connectivityObserver
5252
self.onboardingStatePublisher = onboardingStatePublisher
53-
self.learnMoreURL = Self.learnMoreURL(for: .wcPay) // this will be updated when the onboarding state is known
53+
/// The `learnMoreURL` will be updated when the onboarding state is known
54+
self.learnMoreURL = CardPresentPaymentsPlugin.wcPay.setUpTapToPayLearnMoreURL
5455
self.tapToPayAwarenessMomentDeterminer = tapToPayAwarenessMomentDeterminer
5556

5657
beginOnboardingStateObservation()
@@ -68,7 +69,7 @@ final class SetUpTapToPayInformationViewModel: PaymentSettingsFlowPresentedViewM
6869
guard case .completed(let plugin) = onboardingState else {
6970
return
7071
}
71-
self?.learnMoreURL = Self.learnMoreURL(for: plugin.preferred)
72+
self?.learnMoreURL = plugin.preferred.setUpTapToPayLearnMoreURL
7273
}.store(in: &subscriptions)
7374
}
7475

@@ -151,17 +152,6 @@ final class SetUpTapToPayInformationViewModel: PaymentSettingsFlowPresentedViewM
151152
didChangeShouldShow?(shouldShow)
152153
}
153154
}
154-
155-
/// Choose learn more url based on the active Payment Gateway extension
156-
///
157-
private static func learnMoreURL(for paymentGateway: CardPresentPaymentsPlugin) -> URL {
158-
switch paymentGateway {
159-
case .wcPay:
160-
return WooConstants.URLs.inPersonPaymentsLearnMoreWCPayTapToPay.asURL()
161-
case .stripe:
162-
return WooConstants.URLs.inPersonPaymentsLearnMoreStripe.asURL()
163-
}
164-
}
165155
}
166156

167157
private extension [CardReader] {

WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/CardPresentPaymentsOnboardingViewController.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ struct CardPresentPaymentsOnboardingView: View {
9797
switch url {
9898
case InPersonPaymentsSupportLink.supportURL:
9999
viewModel.showSupport?()
100-
case LearnMoreViewModel.learnMoreURL:
101-
if let url = viewModel.learnMoreURL {
102-
viewModel.showURL?(url)
103-
}
104100
default:
105101
viewModel.showURL?(url)
106102
}

WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/InPersonPaymentsLearnMore.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct InPersonPaymentsLearnMore: View {
66
@ObservedObject private var viewModel: LearnMoreViewModel
77
private let showInfoIcon: Bool
88

9-
init(viewModel: LearnMoreViewModel = LearnMoreViewModel(),
9+
init(viewModel: LearnMoreViewModel,
1010
showInfoIcon: Bool = true) {
1111
self.viewModel = viewModel
1212
self.showInfoIcon = showInfoIcon
@@ -40,7 +40,9 @@ struct InPersonPaymentsLearnMore: View {
4040

4141
struct InPersonPaymentsLearnMore_Previews: PreviewProvider {
4242
static var previews: some View {
43-
InPersonPaymentsLearnMore()
43+
InPersonPaymentsLearnMore(viewModel: .inPersonPayments(source: .paymentMethods,
44+
paymentGateway: .wcPay),
45+
showInfoIcon: true)
4446
.padding()
4547
}
4648
}

0 commit comments

Comments
 (0)