Skip to content

Commit 268b800

Browse files
authored
Merge pull request #5322 from woocommerce/feature/stripe-sdk-2
[Mobile Payments] [SDK 2] Switch to SDK 2
2 parents 49b996d + d3dccae commit 268b800

File tree

85 files changed

+1489
-862
lines changed

Some content is hidden

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

85 files changed

+1489
-862
lines changed

Hardware/Hardware.xcodeproj/project.pbxproj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
D88303D525E44CD200C877F9 /* MockStripeCharge.swift in Sources */ = {isa = PBXBuildFile; fileRef = D88303D425E44CD200C877F9 /* MockStripeCharge.swift */; };
4747
D88303DB25E450E700C877F9 /* PaymentIntentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D88303DA25E450E700C877F9 /* PaymentIntentTests.swift */; };
4848
D88303DF25E4512400C877F9 /* MockStripePaymentIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D88303DE25E4512400C877F9 /* MockStripePaymentIntent.swift */; };
49-
D88ECCD9262091CF0094398A /* CardReaderSoftwareUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D88ECCD8262091CF0094398A /* CardReaderSoftwareUpdate.swift */; };
50-
D88ECCDF2620933D0094398A /* CardReaderSofware+Stripe.swift in Sources */ = {isa = PBXBuildFile; fileRef = D88ECCDE2620933D0094398A /* CardReaderSofware+Stripe.swift */; };
5149
D88ECCE3262095A10094398A /* UpdateTimeEstimate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D88ECCE2262095A10094398A /* UpdateTimeEstimate.swift */; };
5250
D88ECCE7262096BD0094398A /* UpdateTimeEstimate+Stripe.swift in Sources */ = {isa = PBXBuildFile; fileRef = D88ECCE6262096BD0094398A /* UpdateTimeEstimate+Stripe.swift */; };
5351
D88FDB0925DD216B00CB0DBD /* Hardware.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D88FDAFF25DD216B00CB0DBD /* Hardware.framework */; };
@@ -90,6 +88,9 @@
9088
E1CFC1662643EAA30089F86F /* SampleContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1CFC1652643EAA30089F86F /* SampleContent.swift */; };
9189
E1CFC16D2643EBCB0089F86F /* Hardware.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D88FDAFF25DD216B00CB0DBD /* Hardware.framework */; };
9290
E1CFC16E2643EBCB0089F86F /* Hardware.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D88FDAFF25DD216B00CB0DBD /* Hardware.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
91+
E1E125AC26EB582B0068A9B0 /* CardReaderSoftwareUpdateState.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E125AB26EB582B0068A9B0 /* CardReaderSoftwareUpdateState.swift */; };
92+
E1E125AE26EB66B30068A9B0 /* FallibleCancelable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E125AD26EB66B30068A9B0 /* FallibleCancelable.swift */; };
93+
E1E125B026EB66EA0068A9B0 /* Cancelable+Stripe.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E125AF26EB66EA0068A9B0 /* Cancelable+Stripe.swift */; };
9394
E1E4FA2F2653CFD5007B9D4F /* PrintingResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E4FA2E2653CFD5007B9D4F /* PrintingResult.swift */; };
9495
/* End PBXBuildFile section */
9596

@@ -172,8 +173,6 @@
172173
D88303D425E44CD200C877F9 /* MockStripeCharge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStripeCharge.swift; sourceTree = "<group>"; };
173174
D88303DA25E450E700C877F9 /* PaymentIntentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentIntentTests.swift; sourceTree = "<group>"; };
174175
D88303DE25E4512400C877F9 /* MockStripePaymentIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStripePaymentIntent.swift; sourceTree = "<group>"; };
175-
D88ECCD8262091CF0094398A /* CardReaderSoftwareUpdate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardReaderSoftwareUpdate.swift; sourceTree = "<group>"; };
176-
D88ECCDE2620933D0094398A /* CardReaderSofware+Stripe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CardReaderSofware+Stripe.swift"; sourceTree = "<group>"; };
177176
D88ECCE2262095A10094398A /* UpdateTimeEstimate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateTimeEstimate.swift; sourceTree = "<group>"; };
178177
D88ECCE6262096BD0094398A /* UpdateTimeEstimate+Stripe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UpdateTimeEstimate+Stripe.swift"; sourceTree = "<group>"; };
179178
D88FDAFF25DD216B00CB0DBD /* Hardware.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Hardware.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -221,6 +220,9 @@
221220
E1CFC14F2643E9EE0089F86F /* ReceiptSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptSettingsView.swift; sourceTree = "<group>"; };
222221
E1CFC1562643E9EE0089F86F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
223222
E1CFC1652643EAA30089F86F /* SampleContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleContent.swift; sourceTree = "<group>"; };
223+
E1E125AB26EB582B0068A9B0 /* CardReaderSoftwareUpdateState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardReaderSoftwareUpdateState.swift; sourceTree = "<group>"; };
224+
E1E125AD26EB66B30068A9B0 /* FallibleCancelable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FallibleCancelable.swift; sourceTree = "<group>"; };
225+
E1E125AF26EB66EA0068A9B0 /* Cancelable+Stripe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Cancelable+Stripe.swift"; sourceTree = "<group>"; };
224226
E1E4FA2E2653CFD5007B9D4F /* PrintingResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrintingResult.swift; sourceTree = "<group>"; };
225227
E9F0AC202B287C1221EA2C99 /* Pods_Hardware.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Hardware.framework; sourceTree = BUILT_PRODUCTS_DIR; };
226228
F45592A33DEE569C9775EEE7 /* Pods-PrinterPlayground.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PrinterPlayground.release.xcconfig"; path = "Target Support Files/Pods-PrinterPlayground/Pods-PrinterPlayground.release.xcconfig"; sourceTree = "<group>"; };
@@ -379,6 +381,7 @@
379381
D89B8F0725DDC8F60001C726 /* Charge.swift */,
380382
D89B8F0B25DDC9D30001C726 /* ChargeStatus.swift */,
381383
D88FDB2525DD21B000CB0DBD /* PaymentIntent.swift */,
384+
E1E125AD26EB66B30068A9B0 /* FallibleCancelable.swift */,
382385
D89B8F0125DDC7500001C726 /* PaymentIntentStatus.swift */,
383386
D88FDB2325DD21B000CB0DBD /* PaymentIntentParameters.swift */,
384387
D88FDB2025DD21AF00CB0DBD /* PaymentStatus.swift */,
@@ -390,7 +393,7 @@
390393
D845BDB7262D97B300A3E40F /* ReceiptDetails.swift */,
391394
D80B4659260E1E160092EDC0 /* StatementDescriptor.swift */,
392395
D88ECCE2262095A10094398A /* UpdateTimeEstimate.swift */,
393-
D88ECCD8262091CF0094398A /* CardReaderSoftwareUpdate.swift */,
396+
E1E125AB26EB582B0068A9B0 /* CardReaderSoftwareUpdateState.swift */,
394397
D845BDC1262D98C400A3E40F /* CardBrand.swift */,
395398
D845BDD9262DAADB00A3E40F /* PaymentMethod.swift */,
396399
);
@@ -414,10 +417,10 @@
414417
D88FDB3825DD21D300CB0DBD /* DefaultConnectionTokenProvider.swift */,
415418
D81AE85925E6A62800D9CFD3 /* StripeCardReaderDiscoveryCache.swift */,
416419
D854FC21260A34B000A219CD /* UnderlyingError+Stripe.swift */,
417-
D88ECCDE2620933D0094398A /* CardReaderSofware+Stripe.swift */,
418420
D88ECCE6262096BD0094398A /* UpdateTimeEstimate+Stripe.swift */,
419421
D845BDCF262D9C6C00A3E40F /* ReceiptDetails+Stripe.swift */,
420422
D845BDDD262DAB8300A3E40F /* PaymentMethod+Stripe.swift */,
423+
E1E125AF26EB66EA0068A9B0 /* Cancelable+Stripe.swift */,
421424
);
422425
path = StripeCardReader;
423426
sourceTree = "<group>";
@@ -740,10 +743,12 @@
740743
D845BDDE262DAB8300A3E40F /* PaymentMethod+Stripe.swift in Sources */,
741744
D89B8F0C25DDC9D30001C726 /* ChargeStatus.swift in Sources */,
742745
E140F61C2668CDC900FDB5FF /* Logging.swift in Sources */,
746+
E1E125AC26EB582B0068A9B0 /* CardReaderSoftwareUpdateState.swift in Sources */,
743747
D88FDB3125DD21B000CB0DBD /* CardReader.swift in Sources */,
744748
D845BDDA262DAADB00A3E40F /* PaymentMethod.swift in Sources */,
745749
D81AE85A25E6A62800D9CFD3 /* StripeCardReaderDiscoveryCache.swift in Sources */,
746750
D865C61E261CE001006717B8 /* CardReaderEvent+Stripe.swift in Sources */,
751+
E1E125B026EB66EA0068A9B0 /* Cancelable+Stripe.swift in Sources */,
747752
D80B4656260E1B290092EDC0 /* CurrencyCode.swift in Sources */,
748753
D81AE86425E6B77F00D9CFD3 /* CardReaderServiceError.swift in Sources */,
749754
D8DF5F4E25DD9F91008AFE25 /* CardReaderType+Stripe.swift in Sources */,
@@ -759,7 +764,6 @@
759764
D80B464E260E18930092EDC0 /* Email.swift in Sources */,
760765
D89B8F0225DDC7500001C726 /* PaymentIntentStatus.swift in Sources */,
761766
D8652E2A2630520300350F37 /* CardPresentReceiptParameters.swift in Sources */,
762-
D88ECCD9262091CF0094398A /* CardReaderSoftwareUpdate.swift in Sources */,
763767
D89B8F1E25DDCD3D0001C726 /* PaymentIntent+Stripe.swift in Sources */,
764768
D89B8F1625DDCC810001C726 /* ChargeStatus+Stripe.swift in Sources */,
765769
030338102705F7D400764131 /* ReceiptTotalLine.swift in Sources */,
@@ -777,8 +781,8 @@
777781
D88FDB3025DD21B000CB0DBD /* CardReaderService.swift in Sources */,
778782
D88FDB2C25DD21B000CB0DBD /* CardReaderStatus.swift in Sources */,
779783
D89B8F2425DDCD800001C726 /* PaymentIntentStatus+Stripe.swift in Sources */,
784+
E1E125AE26EB66B30068A9B0 /* FallibleCancelable.swift in Sources */,
780785
D88FDB3A25DD21D300CB0DBD /* DefaultConnectionTokenProvider.swift in Sources */,
781-
D88ECCDF2620933D0094398A /* CardReaderSofware+Stripe.swift in Sources */,
782786
);
783787
runOnlyForDeploymentPostprocessing = 0;
784788
};

Hardware/Hardware/CardReader/CardReader.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public struct CardReader {
2424

2525
/// The type of card reader
2626
public let readerType: CardReaderType
27+
28+
/// The CardReader location id
29+
public let locationId: String?
2730
}
2831

2932

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
/// Abstraction provided by Hardware so that clients of this library
22
/// can model a way to provide a connection token.
33
/// It is meant to abstract an implementation of the [adapter pattern](https://en.wikipedia.org/wiki/Adapter_pattern)
4-
public protocol CardReaderConfigProvider {
4+
5+
public protocol ReaderTokenProvider {
56
func fetchToken(completion: @escaping(String?, Error?) -> Void)
67
}
8+
9+
public protocol ReaderLocationProvider {
10+
func fetchDefaultLocationID(completion: @escaping(String?, Error?) -> Void)
11+
}
12+
13+
public protocol CardReaderConfigProvider: ReaderLocationProvider {
14+
func fetchToken(completion: @escaping(String?, Error?) -> Void)
15+
func fetchDefaultLocationID(completion: @escaping(String?, Error?) -> Void)
16+
}

Hardware/Hardware/CardReader/CardReaderEvent.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ public enum CardReaderEvent {
2121
/// Low battery warning resolved.
2222
case lowBatteryResolved
2323

24-
/// A software update is available.
25-
case softwareUpdateNeeded
26-
27-
/// Software is up to date.
28-
case softwareUpToDate
29-
3024
/// The card reader disconnected.
3125
case disconnected
3226
}

Hardware/Hardware/CardReader/CardReaderService.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public protocol CardReaderService {
2222
/// The Publisher that emits reader events
2323
var readerEvents: AnyPublisher<CardReaderEvent, Never> { get }
2424

25-
/// The Publisher that emits software update progress. Values are in the range [0, 1]
26-
var softwareUpdateEvents: AnyPublisher<Float, Never> { get }
25+
/// The Publisher that emits software update state changes
26+
var softwareUpdateEvents: AnyPublisher<CardReaderSoftwareUpdateState, Never> { get }
2727

2828
// MARK: - Commands
2929

@@ -36,7 +36,7 @@ public protocol CardReaderService {
3636

3737
/// Connects to a card reader
3838
/// - Parameter reader: The card reader we want to connect to.
39-
func connect(_ reader: CardReader) -> Future <CardReader, Error>
39+
func connect(_ reader: CardReader) -> AnyPublisher <CardReader, Error>
4040

4141
/// Disconnects from the currently connected reader
4242
func disconnect() -> Future <Void, Error>
@@ -52,13 +52,8 @@ public protocol CardReaderService {
5252
/// Cancels a PaymentIntent
5353
func cancelPaymentIntent() -> Future<Void, Error>
5454

55-
/// Checks for firmware updates.
56-
func checkForUpdate() -> Future<CardReaderSoftwareUpdate?, Error>
57-
58-
/// Triggers a software update. This method requires that checkForUpdates
59-
/// has been completed successfully
55+
/// Triggers a software update.
6056
///
61-
/// The returned publisher will periodically publish the fraction of progress during the software update
62-
/// and it will complete when it's finished, unless there is any error.
63-
func installUpdate() -> AnyPublisher<Float, Error>
57+
/// To check the progress of the update, observe the softwareUpdateEvents publisher.
58+
func installUpdate() -> Void
6459
}

Hardware/Hardware/CardReader/CardReaderServiceError.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public enum CardReaderServiceError: Error {
2828
case paymentCancellation(underlyingError: UnderlyingError = .internalServiceError)
2929

3030
/// Error thrown while updating the reader firmware
31-
case softwareUpdate(underlyingError: UnderlyingError = .internalServiceError)
31+
case softwareUpdate(underlyingError: UnderlyingError = .internalServiceError, batteryLevel: Double?)
3232

3333
/// The user has denied the app permission to use Bluetooth
3434
case bluetoothDenied
@@ -51,7 +51,7 @@ extension CardReaderServiceError: LocalizedError {
5151
return underlyingError.errorDescription
5252
case .paymentCancellation(let underlyingError):
5353
return underlyingError.errorDescription
54-
case .softwareUpdate(let underlyingError):
54+
case .softwareUpdate(let underlyingError, _):
5555
return underlyingError.errorDescription
5656
case .bluetoothDenied:
5757
return NSLocalizedString(
@@ -194,6 +194,23 @@ public enum UnderlyingError: Error {
194194
case internalServiceError
195195
}
196196

197+
extension UnderlyingError {
198+
/// Returns true if the error is related to card reader software updates
199+
///
200+
public var isSoftwareUpdateError: Bool {
201+
switch self {
202+
case .readerSoftwareUpdateFailed,
203+
.readerSoftwareUpdateFailedReader,
204+
.readerSoftwareUpdateFailedServer,
205+
.readerSoftwareUpdateFailedInterrupted,
206+
.readerSoftwareUpdateFailedBatteryLow:
207+
return true
208+
default:
209+
return false
210+
}
211+
}
212+
}
213+
197214
extension UnderlyingError: LocalizedError {
198215
public var errorDescription: String? {
199216
switch self {

Hardware/Hardware/CardReader/CardReaderSoftwareUpdate.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// A type that represents the possible states for software update
2+
public enum CardReaderSoftwareUpdateState {
3+
/// An optional update is available
4+
case available
5+
6+
/// A mandatory update has started
7+
case started(cancelable: FallibleCancelable?)
8+
9+
/// The update is being installed
10+
case installing(progress: Float)
11+
12+
/// The update failed to install
13+
case failed(error: Error)
14+
15+
/// The update has finished installing
16+
case completed
17+
18+
/// No update available
19+
case none
20+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/// Card reader type. Indicates if a reader is meant to be used
22
/// handheld or as a countertop device
33
public enum CardReaderType {
4-
/// Handled reader for use with mobile applications
5-
case mobile
6-
/// Counter top reader
7-
case counterTop
8-
/// Reader not supported
9-
case notSupported
4+
/// Chipper
5+
case chipper
6+
/// Stripe M2
7+
case stripeM2
8+
/// Other
9+
case other
1010
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// A protocol indicating that an activity or action supports cancellation, where that cancelation might fail.
2+
/// Not to be confused with Combine.Cancellable
3+
public protocol FallibleCancelable {
4+
/// Cancel the activity.
5+
func cancel(completion: @escaping (Result<Void, Error>) -> Void)
6+
}

0 commit comments

Comments
 (0)