Skip to content

Commit 6fd8a1a

Browse files
authored
Merge branch 'trunk' into issue/8494-remove-feature-flag
2 parents 43351e7 + b1e3bf3 commit 6fd8a1a

File tree

43 files changed

+510
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+510
-194
lines changed

Hardware/Hardware/CardReader/CardReaderService.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public protocol CardReaderService {
1818

1919
// MARK: - Commands
2020

21+
/// Checks for support of a given reader type and discovery method combination. Does not start discovery.
22+
///
23+
func checkSupport(for cardReaderType: CardReaderType,
24+
configProvider: CardReaderConfigProvider,
25+
discoveryMethod: CardReaderDiscoveryMethod) -> Bool
26+
2127
/// Starts the service.
2228
/// That could imply, for example, that the reader discovery process starts
2329
func start(_ configProvider: CardReaderConfigProvider, discoveryMethod: CardReaderDiscoveryMethod) throws

Hardware/Hardware/CardReader/StripeCardReader/CardReaderType+Stripe.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,20 @@ extension CardReaderType {
1919
return .other
2020
}
2121
}
22+
23+
func toStripe() -> DeviceType? {
24+
switch self {
25+
case .chipper:
26+
return .chipper2X
27+
case .stripeM2:
28+
return .stripeM2
29+
case .wisepad3:
30+
return .wisePad3
31+
case .appleBuiltIn:
32+
return .appleBuiltIn
33+
case .other:
34+
return nil
35+
}
36+
}
2237
}
2338
#endif

Hardware/Hardware/CardReader/StripeCardReader/NoOpCardReaderService.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Combine
2-
/// The adapter wrapping the Stripe Terminal SDK
2+
/// A no-op replacement for the adapter wrapping the Stripe Terminal SDK
33
public struct NoOpCardReaderService: CardReaderService {
44
// MARK: - Queries
55
/// The publisher that emits the list of discovered readers whenever the service discovers a new reader.
@@ -18,6 +18,12 @@ public struct NoOpCardReaderService: CardReaderService {
1818
public init() {}
1919
// MARK: - Commands
2020

21+
public func checkSupport(for cardReaderType: CardReaderType,
22+
configProvider: CardReaderConfigProvider,
23+
discoveryMethod: CardReaderDiscoveryMethod) -> Bool {
24+
return false
25+
}
26+
2127
/// Starts the service.
2228
/// That could imply, for example, that the reader discovery process starts
2329
public func start(_ configProvider: CardReaderConfigProvider, discoveryMethod: CardReaderDiscoveryMethod) throws {

Hardware/Hardware/CardReader/StripeCardReader/StripeCardReaderService.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,27 @@ extension StripeCardReaderService: CardReaderService {
6262

6363
// MARK: - CardReaderService conformance. Commands
6464

65-
public func start(_ configProvider: CardReaderConfigProvider,
66-
discoveryMethod: CardReaderDiscoveryMethod) throws {
65+
public func checkSupport(for cardReaderType: CardReaderType,
66+
configProvider: CardReaderConfigProvider,
67+
discoveryMethod: CardReaderDiscoveryMethod) -> Bool {
68+
guard let deviceType = cardReaderType.toStripe() else {
69+
return false
70+
}
71+
72+
prepare(using: configProvider)
73+
74+
let result = Terminal.shared.supportsReaders(of: deviceType,
75+
discoveryMethod: discoveryMethod.toStripe(),
76+
simulated: shouldUseSimulatedCardReader)
77+
switch result {
78+
case .success:
79+
return true
80+
case .failure:
81+
return false
82+
}
83+
}
84+
85+
func prepare(using configProvider: CardReaderConfigProvider) {
6786
setConfigProvider(configProvider)
6887

6988
Terminal.setLogListener { message in
@@ -75,6 +94,11 @@ extension StripeCardReaderService: CardReaderService {
7594
DDLogDebug("💳 [StripeTerminal] \(message)")
7695
}
7796
Terminal.shared.logLevel = terminalLogLevel
97+
}
98+
99+
public func start(_ configProvider: CardReaderConfigProvider,
100+
discoveryMethod: CardReaderDiscoveryMethod) throws {
101+
prepare(using: configProvider)
78102

79103
if shouldUseSimulatedCardReader {
80104
// You can test with different reader software update scenarios.

Networking/Networking/Extensions/DateFormatter+Woo.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public extension DateFormatter {
107107
/// Date formatter used for creating the properly-formatted date range info. Typically
108108
/// used when setting the end date on `AnalyticsHubTimeRangeGenerator`.
109109
///
110-
public static func createAnalyticsHubDayMonthYearFormatter(timezone: TimeZone) -> DateFormatter {
110+
public static func createDayMonthYearFormatter(timezone: TimeZone) -> DateFormatter {
111111
let formatter = DateFormatter()
112112
formatter.timeZone = timezone
113113
formatter.dateFormat = "MMM d, yyyy"
@@ -117,7 +117,7 @@ public extension DateFormatter {
117117
/// Date formatter used for creating the properly-formatted date range info. Typically
118118
/// used when setting the end date of a same-month range on `AnalyticsHubTimeRangeGenerator`.
119119
///
120-
public static func createAnalyticsHubDayYearFormatter(timezone: TimeZone) -> DateFormatter {
120+
public static func createDayYearFormatter(timezone: TimeZone) -> DateFormatter {
121121
let formatter = DateFormatter()
122122
formatter.timeZone = timezone
123123
formatter.dateFormat = "d, yyyy"
@@ -127,7 +127,7 @@ public extension DateFormatter {
127127
/// Date formatter used for creating the properly-formatted date range info. Typically
128128
/// used when setting the start date on `AnalyticsHubTimeRangeGenerator`.
129129
///
130-
public static func createAnalyticsHubDayMonthFormatter(timezone: TimeZone) -> DateFormatter {
130+
public static func createDayMonthFormatter(timezone: TimeZone) -> DateFormatter {
131131
let formatter = DateFormatter()
132132
formatter.timeZone = timezone
133133
formatter.dateFormat = "MMM d"

RELEASE-NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
11.9
44
-----
55
- [**] Now you can generate all possible variations for a product's attributes [https://github.com/woocommerce/woocommerce-ios/pull/8619]
6-
6+
- [*] Mobile payments: fixed card reader manuals links. [https://github.com/woocommerce/woocommerce-ios/pull/8628]
77

88
11.8
99
-----

WooCommerce/Classes/Extensions/Date+Woo.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,46 @@ extension Date {
5757
return Strings.presentDeicticExpression
5858
}
5959

60+
/// Returns a localized string used for describe a date range string based on two dates. E.g.
61+
///
62+
/// receiver: 2021-01-01
63+
/// other: 2022-12-31
64+
/// returns: Jan 1, 2021 - Dec 31, 2022
65+
///
66+
/// receiver: 2021-01-01
67+
/// other: 2021-01-31
68+
/// returns: Jan 1 - 31, 2022
69+
///
70+
/// receiver: 2021-01-01
71+
/// other: 2022-01-01
72+
/// returns: Jan 1, 2021 - Jan 1, 2022
73+
///
74+
/// receiver: 2022-01-1
75+
/// other: nil
76+
/// returns: Jan 1, 2022
77+
///
78+
func formatAsRange(with other: Date? = nil, timezone: TimeZone, calendar: Calendar) -> String {
79+
guard let other else {
80+
return DateFormatter.Stats.createDayMonthYearFormatter(timezone: timezone).string(from: self)
81+
}
82+
83+
let formattedStart: String
84+
if self.isSameYear(as: other, using: calendar) {
85+
formattedStart = DateFormatter.Stats.createDayMonthFormatter(timezone: timezone).string(from: self)
86+
} else {
87+
formattedStart = DateFormatter.Stats.createDayMonthYearFormatter(timezone: timezone).string(from: self)
88+
}
89+
90+
let formattedEnd: String
91+
if self.isSameMonth(as: other, using: calendar) {
92+
formattedEnd = DateFormatter.Stats.createDayYearFormatter(timezone: timezone).string(from: other)
93+
} else {
94+
formattedEnd = DateFormatter.Stats.createDayMonthYearFormatter(timezone: timezone).string(from: other)
95+
}
96+
97+
return "\(formattedStart) - \(formattedEnd)"
98+
}
99+
60100
/// Returns the next midnight starting from `self`.
61101
///
62102
/// For example, if `self` is 2020-01-03 00:41:09, the returned value will be 2020-01-04 00:00:00.

WooCommerce/Classes/Extensions/UIButton+Helpers.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ extension UIButton {
101101

102102
setTitleColor(.accent, for: .normal)
103103
setTitleColor(.accentDark, for: .highlighted)
104+
setTitleColor(.buttonDisabledTitle, for: .disabled)
104105
}
105106

106107
/// Applies the Modal Cancel Button Style

WooCommerce/Classes/Model/BetaFeature.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private extension BetaFeature {
155155
"phone's built in reader")
156156
static let tapToPayOnIPhoneDescription = NSLocalizedString(
157157
"Test out In-Person Payments using your phone's built-in card reader, as we get ready to launch. " +
158-
"Supported on iPhone XS and newer phones, running iOS 15.5 or above.",
158+
"Supported on iPhone XS and newer phones, running iOS 16 or above, for US-based stores.",
159159
comment: "Cell description on beta features screen to enable in-app purchases")
160160
}
161161
}

WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentPreflightController.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ final class CardPresentPaymentPreflightController {
8282
analyticsTracker: analyticsTracker)
8383
}
8484

85-
func start() {
85+
@MainActor
86+
func start() async {
8687
configureBackend()
8788
observeConnectedReaders()
8889
// If we're already connected to a reader, return it
@@ -94,7 +95,7 @@ final class CardPresentPaymentPreflightController {
9495
// TODO: Run onboarding if needed
9596

9697
// Ask for a Reader type if supported by device/in country
97-
guard localMobileReaderSupported(),
98+
guard await localMobileReaderSupported(),
9899
configuration.supportedReaders.contains(.appleBuiltIn)
99100
else {
100101
// Attempt to find a bluetooth reader and connect
@@ -120,16 +121,16 @@ final class CardPresentPaymentPreflightController {
120121
}))
121122
}
122123

123-
private func localMobileReaderSupported() -> Bool {
124-
#if targetEnvironment(simulator)
125-
return true
126-
#else
127-
if #available(iOS 15.4, *) {
128-
return PaymentCardReader.isSupported
129-
} else {
130-
return false
124+
@MainActor
125+
private func localMobileReaderSupported() async -> Bool {
126+
await withCheckedContinuation { continuation in
127+
let action = CardPresentPaymentAction.checkDeviceSupport(siteID: siteID,
128+
cardReaderType: .appleBuiltIn,
129+
discoveryMethod: .localMobile) { result in
130+
continuation.resume(returning: result)
131+
}
132+
stores.dispatch(action)
131133
}
132-
#endif
133134
}
134135

135136
private func handleConnectionResult(_ result: Result<CardReaderConnectionResult, Error>) {

0 commit comments

Comments
 (0)